private void btnAdd_Click(object sender, EventArgs e) { FormToModel(); EmployeeEventArgs eventArgs = new EmployeeEventArgs(); EmployeeInfo employeeInfo = new EmployeeInfo(); Employee employee = new Employee(); employee.Department = SalePointController.DepartmentModel; //employee.DepartmentId = SalePointController.DepartmentModel.DepartmentId; employee.EmployeeInfo = employeeInfo; employeeInfo.Employee = employee; //employeeInfo.DepartmentId = (int)SalePointController.DepartmentModel.DepartmentId; EmployeePK employeePK = new EmployeePK(); employeePK.DepartmentId = SalePointController.DepartmentModel.DepartmentId; employeeInfo.EmployeePK = employeePK; employee.EmployeePK = employeePK; eventArgs.EmployeeInfo = employeeInfo; eventArgs.SelectedEmployee = -1; this.Enabled = false; EventUtility.fireEvent(AddEmployeeEvent,this,eventArgs); if(eventArgs.AddedEmployee!=null) { bdsEmployeeSource.Add(eventArgs.AddedEmployee); bdsEmployeeSource.EndEdit(); dgvEmployees.Refresh(); dgvEmployees.Invalidate(); } this.Enabled = true; employeeController.EmployeeInfoModel = null; }
private void SaveEmployees(IList employees,long departmentId) { /*var maxId = EmployeeDetailDAO.SelectSpecificType(null, Projections.Max("EmployeePK.EmployeeId")); var employeeId = maxId == null ? 0 : (Int64.Parse(maxId.ToString()));*/ if(employees == null) { return; } foreach (EmployeeInfo employeeInfo in employees) { if(string.IsNullOrEmpty(employeeInfo.EmployeePK.EmployeeId)) { string employeeId = ConvertEmployeeNameToId(employeeInfo.EmployeeName); //employeeInfo.EmployeePK.DepartmentId = departmentId; var employeePK = new EmployeePK { DepartmentId = departmentId, EmployeeId = employeeId }; employeeInfo.EmployeePK = employeePK; //employeeInfo.EmployeeId = employeeId; employeeInfo.Employee.EmployeePK = employeePK; /*employeeInfo.Employee.EmployeeId = employeeId; employeeInfo.Employee.DepartmentId = departmentId;*/ employeeInfo.CreateDate = DateTime.Now; employeeInfo.CreateId = ClientInfo.getInstance().LoggedUser.Name; employeeInfo.Employee.CreateDate = DateTime.Now; employeeInfo.Employee.CreateId = ClientInfo.getInstance().LoggedUser.Name; EmployeeDAO.Add(employeeInfo.Employee); EmployeeDetailDAO.Add(employeeInfo); } else { employeeInfo.UpdateDate = DateTime.Now; employeeInfo.UpdateId = ClientInfo.getInstance().LoggedUser.Name; employeeInfo.Employee.UpdateDate = DateTime.Now; employeeInfo.Employee.UpdateId = ClientInfo.getInstance().LoggedUser.Name; EmployeeDetailDAO.Update(employeeInfo); EmployeeDAO.Update(employeeInfo.Employee); } } }
public EmployeeInfo Add(EmployeeInfo employeeInfo) { ObjectCriteria crit = new ObjectCriteria(); crit.AddOrder("Barcode", false); crit.MaxResult = 3; IList list = EmployeeDetailDAO.FindAll(crit); string barCode = "NV000001"; if(list!=null && list.Count > 0 ) { EmployeeInfo info = (EmployeeInfo) list[0]; barCode = "NV" + string.Format("{0:000000}",Int32.Parse(info.Barcode.Substring(2))+1); } if (employeeInfo.Employee==null) // create new { string employeeId = ConvertEmployeeNameToId(employeeInfo.EmployeeName); //employeeInfo.EmployeePK.DepartmentId = departmentId; var employeePK = new EmployeePK { DepartmentId = 0, EmployeeId = employeeId }; employeeInfo.EmployeePK = employeePK; //employeeInfo.EmployeeId = employeeId; if(employeeInfo.Employee == null) { employeeInfo.Employee = new Employee(); } employeeInfo.Employee.EmployeePK = employeePK; employeeInfo.Employee.CreateDate = DateTime.Now; employeeInfo.Employee.CreateId = ClientInfo.getInstance().LoggedUser.Name; employeeInfo.DelFlg = 0; employeeInfo.ExclusiveKey = 1; employeeInfo.Employee.DelFlg = 0; employeeInfo.Employee.ExclusiveKey = 1; employeeInfo.Employee.Department = new Department {DepartmentId = 0}; employeeInfo.Department = new Department{DepartmentId = 0}; /*employeeInfo.Employee.EmployeeId = employeeId; employeeInfo.Employee.DepartmentId = departmentId;*/ employeeInfo.CreateDate = DateTime.Now; employeeInfo.CreateId = ClientInfo.getInstance().LoggedUser.Name; employeeInfo.Barcode = barCode; employeeInfo.Employee.CreateDate = DateTime.Now; employeeInfo.Employee.CreateId = ClientInfo.getInstance().LoggedUser.Name; EmployeeDAO.Add(employeeInfo.Employee); EmployeeDetailDAO.Add(employeeInfo); } else // update { employeeInfo.UpdateDate = DateTime.Now; employeeInfo.UpdateId = ClientInfo.getInstance().LoggedUser.Name; employeeInfo.Employee.UpdateDate = DateTime.Now; employeeInfo.Employee.UpdateId = ClientInfo.getInstance().LoggedUser.Name; EmployeeDetailDAO.Update(employeeInfo); //EmployeeDAO.Update(employeeInfo.Employee); } //EmployeeDetailDAO.Add(data); return employeeInfo; }