ай дурачок закоммитить забыл
parent
dbfd519e35
commit
4840a136a1
|
|
@ -117,10 +117,10 @@ impl DBOperator {
|
|||
}
|
||||
Ok(false)
|
||||
}
|
||||
pub async fn add_worker(&self, worker: Worker) -> Result<bool, sqlx::Error> {
|
||||
pub async fn add_worker(&self, worker: WorkerRow) -> Result<bool, sqlx::Error> {
|
||||
// sqlx::query!("INSERT INTO Brewery.worker (id, position_id, hire_date, is_fired, full_name) VALUES(0, ?, ?, ?, ?);",worker.position.id, worker.hire_date ,worker.is_fired,worker.full_name)
|
||||
match sqlx::query("INSERT INTO Brewery.worker (id, position_id, hire_date, is_fired, full_name) VALUES(0, ?, ?, ?, ?);")
|
||||
.bind(worker.position.id)
|
||||
.bind(worker.position_id)
|
||||
.bind(worker.hire_date)
|
||||
.bind(worker.is_fired)
|
||||
.bind(worker.full_name)
|
||||
|
|
|
|||
|
|
@ -3,11 +3,12 @@ use egui::mutex::RwLock;
|
|||
use egui_extras::{Column, TableBuilder};
|
||||
use std::collections::HashMap;
|
||||
use std::default::Default;
|
||||
use std::ops::Deref;
|
||||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::database::*;
|
||||
use crate::models::{ModalStatus, ModalWinState, Position, Worker};
|
||||
use crate::models::{ModalStatus, ModalWinState, Position, Worker, WorkerRow};
|
||||
use crate::tab::*;
|
||||
pub struct WorkerTabViewer {
|
||||
db_oper: DBOperator,
|
||||
|
|
@ -63,8 +64,22 @@ impl WorkerTabViewer {
|
|||
ui.horizontal(|ui| {
|
||||
if ui.button("Добавить").clicked() {
|
||||
self.process_worker_state.is_open = true;
|
||||
self.process_worker_state.data.insert("id".to_string(), "0".to_string());
|
||||
self.process_worker_
|
||||
self.process_worker_state
|
||||
.data
|
||||
.insert("id".to_string(), "0".to_string());
|
||||
self.process_worker_state
|
||||
.data
|
||||
.insert("full_name".to_string(), "".to_string());
|
||||
self.process_worker_state.data.insert(
|
||||
"position_id".to_string(),
|
||||
self.positions.read()[0].name.clone(),
|
||||
);
|
||||
self.process_worker_state
|
||||
.data
|
||||
.insert("is_fired".to_string(), false.to_string());
|
||||
self.process_worker_state
|
||||
.data
|
||||
.insert("hire_date".to_string(), "".to_string());
|
||||
};
|
||||
if ui.button("Обновить").clicked() {
|
||||
self.update_workers();
|
||||
|
|
@ -250,12 +265,122 @@ impl WorkerTabViewer {
|
|||
}
|
||||
});
|
||||
}
|
||||
if self.process_worker_state.is_open{
|
||||
egui::Modal::new(egui::Id::new("process_worker_modal")).show(ui.ctx(), |ui|{
|
||||
if ui.button("Закрыть").clicked(){
|
||||
if self.process_worker_state.is_open {
|
||||
egui::Modal::new(egui::Id::new("process_worker_modal")).show(ui.ctx(), |ui| {
|
||||
if ui.button("Закрыть").clicked() {
|
||||
self.process_worker_state.is_open = false;
|
||||
}
|
||||
if self.process_worker_state.status != ModalStatus::Remove {
|
||||
egui::Grid::new("process_worker_grid").show(ui, |ui| {
|
||||
ui.label("Имя:");
|
||||
ui.add(
|
||||
egui::TextEdit::singleline(
|
||||
self.process_worker_state.data.get_mut("full_name").unwrap(),
|
||||
)
|
||||
.hint_text("Иванов Иван Иванович"),
|
||||
);
|
||||
ui.end_row();
|
||||
|
||||
ui.label("Должность:");
|
||||
let posname = self
|
||||
.positions
|
||||
.read()
|
||||
.clone()
|
||||
.iter()
|
||||
.find(|p| {
|
||||
p.id.to_string()
|
||||
== *self.process_worker_state.data.get("position_id").unwrap()
|
||||
})
|
||||
.map(|m| m.name.clone());
|
||||
egui::ComboBox::new("process_worker_combobox", "")
|
||||
.selected_text(posname.unwrap_or("Выберите".to_string()))
|
||||
.show_ui(ui, |ui| {
|
||||
for pos in self.positions.read().clone().iter() {
|
||||
ui.selectable_value(
|
||||
self.process_worker_state
|
||||
.data
|
||||
.get_mut("position_id")
|
||||
.unwrap(),
|
||||
pos.id.to_string(),
|
||||
pos.name.clone(),
|
||||
);
|
||||
}
|
||||
});
|
||||
ui.end_row();
|
||||
|
||||
let mut size = ui.spacing().interact_size;
|
||||
size.x = 200.0;
|
||||
ui.label("Дата найма:");
|
||||
ui.add_sized(
|
||||
size,
|
||||
egui::TextEdit::singleline(
|
||||
self.process_worker_state.data.get_mut("hire_date").unwrap(),
|
||||
)
|
||||
.hint_text("1970-01-23"),
|
||||
);
|
||||
});
|
||||
|
||||
self.process_worker_state.can_finish = self.check_date(
|
||||
self.process_worker_state
|
||||
.data
|
||||
.get("hire_date")
|
||||
.unwrap()
|
||||
.clone(),
|
||||
);
|
||||
}
|
||||
let btext = match self.process_worker_state.status {
|
||||
ModalStatus::Add => "Добавить",
|
||||
ModalStatus::Edit => "Сохранить",
|
||||
ModalStatus::Remove => "Уволить",
|
||||
};
|
||||
if !self.process_worker_state.can_finish {
|
||||
ui.label("Проверьте правильность всех полей");
|
||||
}
|
||||
let resp = ui.add_enabled(
|
||||
self.process_worker_state.can_finish,
|
||||
egui::Button::new(btext),
|
||||
);
|
||||
if resp.clicked() {
|
||||
match self.process_worker_state.status {
|
||||
ModalStatus::Add => {
|
||||
self.rt.block_on(async {
|
||||
self.db_oper.add_worker(WorkerRow {
|
||||
id: self
|
||||
.process_worker_state
|
||||
.data
|
||||
.get("id")
|
||||
.unwrap()
|
||||
.parse::<i32>()
|
||||
.unwrap(),
|
||||
full_name: *self
|
||||
.process_worker_state
|
||||
.data
|
||||
.get("full_name")
|
||||
.unwrap(),
|
||||
position_id: self
|
||||
.process_worker_state
|
||||
.data
|
||||
.get("position_id")
|
||||
.unwrap()
|
||||
.parse::<i32>()
|
||||
.unwrap(),
|
||||
hire_date: chrono::NaiveDate::parse_from_str(
|
||||
&self.edit_worker_hire_date,
|
||||
"%Y-%m-%d",
|
||||
)
|
||||
.unwrap()
|
||||
.and_hms_opt(0, 0, 0)
|
||||
.unwrap()
|
||||
.and_local_timezone(chrono::Local)
|
||||
.unwrap(),
|
||||
is_fired: false,
|
||||
})
|
||||
});
|
||||
}
|
||||
ModalStatus::Edit => {}
|
||||
ModalStatus::Remove => {}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
TableBuilder::new(ui)
|
||||
|
|
@ -304,7 +429,6 @@ impl WorkerTabViewer {
|
|||
});
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
fn show_position(&mut self, ui: &mut egui::Ui) {
|
||||
|
|
@ -488,6 +612,10 @@ impl WorkerTabViewer {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
fn check_date(&self, date: String) -> bool {
|
||||
chrono::NaiveDate::parse_from_str(&date, "%Y-%m-%d").is_ok()
|
||||
}
|
||||
}
|
||||
|
||||
impl egui_dock::TabViewer for WorkerTabViewer {
|
||||
|
|
|
|||
Loading…
Reference in New Issue