private void DoSaveWorkingHistory(WorkingHistoryModel workingHistoryModel) { using (var dbContext = new DataContext()) { var entity = dbContext.WorkingHistories.Find(workingHistoryModel.Id); if (entity == null) { entity = new WorkingHistory(); dbContext.WorkingHistories.Add(entity); } else if (entity.UserId != workingHistoryModel.UserId) { throw new Exception("Bạn không có quyền chỉnh sửa công việc của người khác"); } entity.UserId = workingHistoryModel.UserId; entity.PercentageComplete = workingHistoryModel.PercentageComplete; entity.Problem = workingHistoryModel.Problem; entity.WorkInDay = workingHistoryModel.WorkInDay; entity.WorkingDate = workingHistoryModel.WorkingDate.Date; dbContext.SaveChanges(); } }
private async Task LoginByCodeAsync(string code) { try { await Task.Run(() => { List <Employee> empList = _unitofwork.EmployeeRepository.Get().ToList(); Employee loginEmp = empList.FirstOrDefault(x => x.DecryptedCode.Equals(code)); if (loginEmp != null) { App.Current.Properties["EmpLogin"] = loginEmp; if (loginEmp.EmpRole == (int)EmployeeRole.Stock) { Dispatcher.Invoke(() => { WareHouseWindow wareHouse = new WareHouseWindow(); wareHouse.Show(); }); } else { try { SalaryNote empSalaryNote = _unitofwork.SalaryNoteRepository.Get(sle => sle.EmpId.Equals(loginEmp.EmpId) && sle.ForMonth.Equals(DateTime.Now.Month) && sle.ForYear.Equals(DateTime.Now.Year)).First(); App.Current.Properties["EmpSN"] = empSalaryNote; WorkingHistory empWorkHistory = new WorkingHistory { ResultSalary = empSalaryNote.SnId, EmpId = empSalaryNote.EmpId }; App.Current.Properties["EmpWH"] = empWorkHistory; } catch (Exception ex) { SalaryNote empSalary = new SalaryNote { EmpId = loginEmp.EmpId, SalaryValue = 0, WorkHour = 0, ForMonth = DateTime.Now.Month, ForYear = DateTime.Now.Year, IsPaid = 0 }; _unitofwork.SalaryNoteRepository.Insert(empSalary); _unitofwork.Save(); WorkingHistory empWorkHistory = new WorkingHistory { ResultSalary = empSalary.SnId, EmpId = empSalary.EmpId }; App.Current.Properties["EmpWH"] = empWorkHistory; App.Current.Properties["EmpSN"] = empSalary; } Dispatcher.Invoke(() => { EmpLoginListData.emploglist.Clear(); EmpLoginListData.emploglist.Add(new EmpLoginList { Emp = loginEmp, EmpSal = App.Current.Properties["EmpSN"] as SalaryNote, EmpWH = App.Current.Properties["EmpWH"] as WorkingHistory, TimePercent = 0 }); EmployeeWorkSpace.MainWindow main = new EmployeeWorkSpace.MainWindow(); main.Show(); }); } } else { MessageBox.Show("incorrect username or password"); return; } Dispatcher.Invoke(() => { this.Close(); }); }); } catch (Exception ex) { MessageBox.Show("Something went wrong: \n" + ex.Message); AppLog.Error(ex); } }
/// <summary> /// auto generate id for all entities in Asowell Database /// all id type is 10 character and the sign is depend on the type of entity /// </summary> /// <param name="entity"></param> /// <returns></returns> private TEntity AutoGeneteId_DBAsowell(TEntity entity) { string sign = ""; if (entity is Employee) { sign = "EMP"; // lấy số thứ tự mới nhất string numberWantToset = (this.Get().Count() + 1).ToString(); int blank = ID_SIZE_DBASOWELL - (sign.Length + numberWantToset.Length); string result = sign; for (int i = 0; i < blank; i++) { result += "0"; } result += numberWantToset; Employee emp = entity as Employee; emp.EmpId = result; } else if (entity is AdminRe) { sign = "AD"; // lấy số thứ tự mới nhất string numberWantToset = (this.Get().Count() + 1).ToString(); int blank = ID_SIZE_DBASOWELL - (sign.Length + numberWantToset.Length); string result = sign; for (int i = 0; i < blank; i++) { result += "0"; } result += numberWantToset; AdminRe admin = entity as AdminRe; admin.AdId = result; } else if (entity is Customer) { sign = "CUS"; // lấy số thứ tự mới nhất string numberWantToset = (this.Get().Count() + 1).ToString(); int blank = ID_SIZE_DBASOWELL - (sign.Length + numberWantToset.Length); string result = sign; for (int i = 0; i < blank; i++) { result += "0"; } result += numberWantToset; Customer cus = entity as Customer; cus.CusId = result; } else if (entity is WareHouse) { sign = "WAH"; // lấy số thứ tự mới nhất string numberWantToset = (this.Get().Count() + 1).ToString(); int blank = ID_SIZE_DBASOWELL - (sign.Length + numberWantToset.Length); string result = sign; for (int i = 0; i < blank; i++) { result += "0"; } result += numberWantToset; WareHouse wh = entity as WareHouse; wh.WarehouseId = result; } else if (entity is Ingredient) { sign = "IGD"; // lấy số thứ tự mới nhất string numberWantToset = (this.Get().Count() + 1).ToString(); int blank = ID_SIZE_DBASOWELL - (sign.Length + numberWantToset.Length); string result = sign; for (int i = 0; i < blank; i++) { result += "0"; } result += numberWantToset; Ingredient ign = entity as Ingredient; ign.IgdId = result; } else if (entity is Product) { sign = "P"; // lấy số thứ tự mới nhất string numberWantToset = (this.Get().Count() + 1).ToString(); int blank = ID_SIZE_DBASOWELL - (sign.Length + numberWantToset.Length); string result = sign; for (int i = 0; i < blank; i++) { result += "0"; } result += numberWantToset; Product p = entity as Product; p.ProductId = result; } else if (entity is ProductDetail) { sign = "PD"; // lấy số thứ tự mới nhất string numberWantToset = (this.Get().Count() + 1).ToString(); int blank = ID_SIZE_DBASOWELL - (sign.Length + numberWantToset.Length); string result = sign; for (int i = 0; i < blank; i++) { result += "0"; } result += numberWantToset; ProductDetail pd = entity as ProductDetail; pd.PdetailId = result; } else if (entity is OrderNote) { sign = "ORD"; // lấy số thứ tự mới nhất string numberWantToset = (this.Get().Count() + 1).ToString(); int blank = ID_SIZE_DBASOWELL - (sign.Length + numberWantToset.Length); string result = sign; for (int i = 0; i < blank; i++) { result += "0"; } result += numberWantToset; OrderNote ord = entity as OrderNote; ord.OrdernoteId = result; } else if (entity is ReceiptNote) { sign = "RN"; // lấy số thứ tự mới nhất string numberWantToset = (this.Get().Count() + 1).ToString(); int blank = ID_SIZE_DBASOWELL - (sign.Length + numberWantToset.Length); string result = sign; for (int i = 0; i < blank; i++) { result += "0"; } result += numberWantToset; ReceiptNote rcn = entity as ReceiptNote; rcn.RnId = result; } else if (entity is SalaryNote) { sign = "SAN"; // lấy số thứ tự mới nhất string numberWantToset = (this.Get().Count() + 1).ToString(); int blank = ID_SIZE_DBASOWELL - (sign.Length + numberWantToset.Length); string result = sign; for (int i = 0; i < blank; i++) { result += "0"; } result += numberWantToset; SalaryNote sln = entity as SalaryNote; sln.SnId = result; } else if (entity is WorkingHistory) { sign = "WOH"; // lấy số thứ tự mới nhất string numberWantToset = (this.Get().Count() + 1).ToString(); int blank = ID_SIZE_DBASOWELL - (sign.Length + numberWantToset.Length); string result = sign; for (int i = 0; i < blank; i++) { result += "0"; } result += numberWantToset; WorkingHistory wh = entity as WorkingHistory; wh.WhId = result; } else if (entity is StockOut) { sign = "STO"; // lấy số thứ tự mới nhất string numberWantToset = (this.Get().Count() + 1).ToString(); int blank = ID_SIZE_DBASOWELL - (sign.Length + numberWantToset.Length); string result = sign; for (int i = 0; i < blank; i++) { result += "0"; } result += numberWantToset; StockOut stkout = entity as StockOut; stkout.StockOutId = result; } else if (entity is StockIn) { sign = "STI"; // lấy số thứ tự mới nhất string numberWantToset = (this.Get().Count() + 1).ToString(); int blank = ID_SIZE_DBASOWELL - (sign.Length + numberWantToset.Length); string result = sign; for (int i = 0; i < blank; i++) { result += "0"; } result += numberWantToset; StockIn stkIn = entity as StockIn; stkIn.Si_id = result; } else if (entity is APWareHouse) { sign = "APW"; // lấy số thứ tự mới nhất string numberWantToset = (this.Get().Count() + 1).ToString(); int blank = ID_SIZE_DBASOWELL - (sign.Length + numberWantToset.Length); string result = sign; for (int i = 0; i < blank; i++) { result += "0"; } result += numberWantToset; APWareHouse wh = entity as APWareHouse; wh.APWarehouseId = result; } else if (entity is Stock) { sign = "STK"; // lấy số thứ tự mới nhất string numberWantToset = (this.Get().Count() + 1).ToString(); int blank = ID_SIZE_DBASOWELL - (sign.Length + numberWantToset.Length); string result = sign; for (int i = 0; i < blank; i++) { result += "0"; } result += numberWantToset; Stock stock = entity as Stock; stock.StoId = result; } return(entity); }
private async Task Async(string username, string pass, string code, EmpLoginList empout) { try { await Task.Run(() => { if (empout != null) { if (EmpLoginListData.emploglist.Count == 1) { var orderedTable = _unitofwork.TableRepository.Get(x => x.IsOrdered == 1).ToList(); if (orderedTable.Count != 0) { MessageBox.Show("You can not logout because still have Tables that in the ordering state out there. Please check again!"); return; } } if ((empout.Emp.Username.Equals(username) && (empout.Emp.DecryptedPass.Equals(pass)) || empout.Emp.DecryptedCode.Equals(code))) { empout.EmpWH.EndTime = DateTime.Now; _cloudPosUnitofwork.WorkingHistoryRepository.Insert(empout.EmpWH); _cloudPosUnitofwork.Save(); var workH = empout.EmpWH.EndTime - empout.EmpWH.StartTime; empout.EmpSal = _cloudPosUnitofwork.SalaryNoteRepository.Get(sle => sle.EmpId.Equals(empout.Emp.EmpId) && sle.ForMonth.Equals(DateTime.Now.Month) && sle.ForYear.Equals(DateTime.Now.Year)).First(); empout.EmpSal.WorkHour += workH.Hours + (workH.Minutes / 60.0) + (workH.Seconds / 3600.0); empout.EmpSal.SalaryValue = (decimal)(empout.EmpSal.WorkHour *empout.Emp.HourWage); _cloudPosUnitofwork.SalaryNoteRepository.Update(empout.EmpSal); _cloudPosUnitofwork.Save(); EmpLoginListData.emploglist.Remove(empout); Dispatcher.Invoke(() => { checkEmployeeCount(); }); return; } else { MessageBox.Show("Fail! Please try again!"); return; } } bool isFound = false; foreach (Employee emp in _employee) { if ((emp.Username.Equals(username) && (emp.DecryptedPass.Equals(pass)) || emp.DecryptedCode.Equals(code))) { var chemp = EmpLoginListData.emploglist.Where(x => x.Emp.EmpId.Equals(emp.EmpId)).ToList(); if (chemp.Count != 0) { MessageBox.Show("This employee is already login!"); return; } try { SalaryNote empSalaryNote = _cloudPosUnitofwork.SalaryNoteRepository.Get(sle => sle.EmpId.Equals(emp.EmpId) && sle.ForMonth.Equals(DateTime.Now.Month) && sle.ForYear.Equals(DateTime.Now.Year)).First(); App.Current.Properties["EmpSN"] = empSalaryNote; WorkingHistory empWorkHistory = new WorkingHistory { ResultSalary = empSalaryNote.SnId, EmpId = empSalaryNote.EmpId }; App.Current.Properties["EmpWH"] = empWorkHistory; } catch (Exception ex) { SalaryNote empSalary = new SalaryNote { EmpId = emp.EmpId, SalaryValue = 0, WorkHour = 0, ForMonth = DateTime.Now.Month, ForYear = DateTime.Now.Year, IsPaid = 0 }; _cloudPosUnitofwork.SalaryNoteRepository.Insert(empSalary); _cloudPosUnitofwork.Save(); WorkingHistory empWorkHistory = new WorkingHistory { ResultSalary = empSalary.SnId, EmpId = empSalary.EmpId }; App.Current.Properties["EmpWH"] = empWorkHistory; App.Current.Properties["EmpSN"] = empSalary; } Dispatcher.Invoke(() => { EmpLoginListData.emploglist.Add(new EmpLoginList { Emp = emp, EmpSal = App.Current.Properties["EmpSN"] as SalaryNote, EmpWH = App.Current.Properties["EmpWH"] as WorkingHistory, TimePercent = 0 }); checkEmployeeCount(); setControl(true); }); isFound = true; //end create break; } } if (!isFound) { MessageBox.Show("incorrect username or password"); return; } }); } catch (Exception ex) { } }