public void TestAddEmployee() { // Insert a role Role role = Role.CreateRole(Guid.NewGuid().ToString()); role.Save(); // Insert an manager. Employee manager = Employee.CreateEmployee(Guid.NewGuid().ToString(), "123", Sex.Male, "Hui", DateTime.Now, "Ji"); manager.IsActive = true; manager.ServiceYears = 10; List <EmployeeRoleRL> employeeRoleList = new List <EmployeeRoleRL>(); employeeRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, role.PKRoleID)); manager.SetRoleList(employeeRoleList); manager.Save(); Guid guid = manager.PKEmployeeID; Employee employee = EmployeeBLL.AddEmployee(Guid.NewGuid().ToString(), "Brandon", "None", "Shen", Sex.Male, 10, DateTime.Now, manager.Email, "5030", 0, ""); Assert.IsTrue(null != employee && employee.FKReportManagerID.Equals(manager.PKEmployeeID)); employee.Delete(); manager.Delete(); role.Delete(); }
private void btnConfirm_Click(object sender, EventArgs e) { if (!InputValidation()) { return; } EmployeeEntity employeeEntity = new EmployeeEntity(); employeeEntity.EmployeeNumber = txtEmployeeNumber.Text; employeeEntity.EmployeeFirstName = txtEmployeeFirstName.Text; employeeEntity.EmployeeLastName = txtEmployeeLastName.Text; employeeEntity.Address = txtAddress.Text; employeeEntity.IDCard = txtIdCard.Text; employeeEntity.DOB = dtpDOB.Value; employeeEntity.Sex = (SexValue)cbxSex.SelectedItem; employeeEntity.JobRankType = (JobRankValue)cbxJobRankType.SelectedItem; employeeEntity.JobRankLevel = (JobRankLevelValue)cbxJobRankLevel.SelectedItem; employeeEntity.SalaryLevel = (SalaryLevelValue)cbxSalaryLevel.SelectedItem; employeeEntity.SalarySubLevel = Convert.ToInt32(txtSalarySubLevel.Text); if (mode == 0) { employeeBLL.AddEmployee(employeeEntity); } if (mode == 1) { employeeBLL.EditEmployee(employeeEntity, ID); } this.Close(); }
//Employee ADD private void button3_Click(object sender, EventArgs e) { string mesaj = EmployeeBLL.AddEmployee(txtEmployeeName.Text, txtEmployeeSirname.Text, txtEmployeeSalary.Text, (int)cmbPozisyon.SelectedItem); MessageBox.Show(mesaj); ListEmployees(EmployeeBLL.GetEmployees()); EmployeeTemizle(); }
/// <summary> /// Register a new employee in system and send an email to hime/her with default password. /// </summary> /// <param name="email">This email should be a valid email address as system will send register email to it.</param> /// <param name="firstName">Not null in database.</param> /// <param name="middleName">Could be null in database.</param> /// <param name="lastName">Not null in database.</param> /// <param name="gender">Not null in database.</param> /// <param name="serviceYear">Count how many years the worker works.</param> /// <param name="dateOfHire">Hired date in our company.</param> /// <param name="supervisorEmail">Could be null in database. The email of his/her manager.</param> /// <returns>Return type is Employee. Returns the employee who is registered just now.</returns> public Employee AddEmployee(string email, string firstName, string middleName, string lastName, string legalName, Sex gender, float serviceYear, DateTime dateOfHire, string supervisorEmail, string costCenterCode, int employeeNum) { Log.Info(GlobalParams.StartAddEmpl); Employee newEmployee = null; try { newEmployee = EmployeeBLL.AddEmployee(email, firstName, middleName, lastName, gender, serviceYear, dateOfHire, supervisorEmail, costCenterCode, employeeNum, legalName); EmailConfig.SetRootPath(System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath); // If add new employee, send a notification email to user. if (newEmployee != null && EmailConfig.EmailTemplates.ContainsKey(EmailType.Register_ToEmployeeSelf.ToString())) { Log.Info(GlobalParams.StartMail); string mEmail = GetEmail(newEmployee.Email); string firstNmae = newEmployee.FirstName; string userName = newEmployee.Email.Replace(GlobalParams.AdventMail, "").ToLower(); EmailContent ec = EmailConfig.EmailTemplates[EmailType.Register_ToEmployeeSelf.ToString()]; // {0} - First Name // {1} - Account (User Name) // {2} - Password // {3} - CARSAddress string emailBody = string.Format(ec.Body, firstName, userName, CryptographyStuff.AES_DecryptString(newEmployee.Password), EmailConfig.CARSAddress); SendMail sender = new SendMail(mEmail, null, EmailConfig.EmailAccount, emailBody, ec.Title, EmailConfig.Password, EmailConfig.Host); sender.Send(); Log.Info(GlobalParams.EndMail); } else { Log.Warn(GlobalParams.MailError); throw new Exception(GlobalParams.MailError); } } catch (SqlException sqlEx) { if (sqlEx.Message.Contains("UniqueKeyEmail")) // try to add duplicate account { Log.Warn("Try to register a duplicate account." + Environment.NewLine + email); throw new Exception(email + " was registered already." + Environment.NewLine + "Try another email account or contact with Administrator."); } else { throw sqlEx; } } catch (Exception ex) { Log.Exception(ex.StackTrace); Log.Exception(ex.Message); throw ex; } Log.Info(GlobalParams.EndAddEmpl); return(newEmployee); }
public void AddEmployee() { employeeBLL.AddEmployee(new Employee() { Id = 3, Nume = Nume, Prenume = Prenume, Email = Email, Telefon = Telefon, Password = Parola }); }
protected void btnAdd_Click(object sender, EventArgs e) { if (Page.IsValid) { EmployeeBLL.AddEmployee( tbNRIC.Text, tbName.Text, Convert.ToDateTime(tbBirthDate.Text), ddlDepartment.SelectedValue, Convert.ToDouble(tbMonthlyWage.Text)); GvEmployee.DataSource = EmployeeBLL.GetAll(); GvEmployee.DataBind(); } }
protected void EmployeeAddButton_Click(object sender, EventArgs e) { if (Page.IsValid) { string connectionString = ConfigurationManager.ConnectionStrings["RideXpressConnectionString"].ToString(); EmployeeBLL bll = new EmployeeBLL(connectionString); EmployeeViewModel employee = new EmployeeViewModel(); employee.FirstName = EmployeeFirstName.Text; employee.LastName = EmployeeLastName.Text; employee.Gender = Convert.ToBoolean(EmployeeGender.SelectedValue); employee.BirthDate = EmployeeBirthDate.Text; employee.JobTitle = EmployeeJobTitle.Text; employee.StartDate = EmployeeStartDate.Text; employee.EndDate = null; bll.AddEmployee(employee); Response.Redirect("~/CurrentEmployees.aspx"); } }
private void btnSave_Click(object sender, EventArgs e) { if (ValidateInput()) { emp.DepartmentID = (int)cboDept.SelectedValue; emp.Name = txtName.Text.Trim(); emp.Sex = rdoMale.Checked ? "男" : "女"; emp.Position = cboPosition.Text; emp.Phone = txtPhone.Text.Trim(); emp.Email = txtEmail.Text.Trim(); emp.Nation = cboNation.Text; emp.Polity = cboPolity.Text; emp.Degree = cboDegree.Text; emp.Salary = Convert.ToDecimal(txtSalary.Text.Trim()); emp.Resume = txtResume.Text; emp.Memo = txtMemo.Text; emp.Status = ckbStatus.Checked; try { if (op == Operator.Add) { if (empbll.AddEmployee(emp)) { this.DialogResult = DialogResult.OK; MessageBox.Show("添加成功!"); op = Operator.Other; } } else if (op == Operator.Edit) { if (empbll.EditEmployee(emp)) { this.DialogResult = DialogResult.OK; MessageBox.Show("修改成功"); op = Operator.Other; } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
private void btnAdd_Click(object sender, EventArgs e) { try { CheckBoxForm(); employees.FirstName = txtName.Text; employees.LastName = txtSurname.Text; employees.Phone = mtbPhone.Text; employees.Address = txtAddress.Text; employees.Email = txtMail.Text; employees.Salary = numUcret.Value; employees.StartDate = DateTime.Now; employees.Description = txtDescription.Text; employees.DepartmanID = Convert.ToInt32(cbDepartment.SelectedValue); _employeeBLL.AddEmployee(employees); MessageBox.Show("KAYIT BAŞARILI"); ListEmployee(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnSave_Click(object sender, EventArgs e) { if (txtUserNo.Text.Trim() == "") { MessageBox.Show("User No is empty!"); } else if (txtPassword.Text.Trim() == "") { MessageBox.Show("User has no password!"); } else if (txtName.Text.Trim() == "") { MessageBox.Show("User Name is empty!"); } else if (txtSurname.Text.Trim() == "") { MessageBox.Show("User Surname is empty!"); } else if (txtSalary.Text.Trim() == "") { MessageBox.Show("User has no salary!"); } else if (cmbDepartment.SelectedIndex == -1) { MessageBox.Show("Select a department!"); } else if (cmbPosition.SelectedIndex == -1) { MessageBox.Show("Select a position!"); } else { if (!isUpdated) { if (!EmployeeBLL.isUnique(Convert.ToInt32(txtUserNo.Text))) { MessageBox.Show("This user No is already taken!"); } else { EMPLOYEE employee = new EMPLOYEE(); employee.UserNo = Convert.ToInt32(txtUserNo.Text); employee.Password = PasswordEncryption.CreateMD5Hash(txtPassword.Text); employee.isAdmin = chAdmin.Checked; employee.Name = txtName.Text; employee.Surname = txtSurname.Text; employee.Salary = Convert.ToInt32(txtSalary.Text); employee.DepartmentID = Convert.ToInt32(cmbDepartment.SelectedValue); employee.PositionID = Convert.ToInt32(cmbPosition.SelectedValue); employee.Address = txtAddress.Text; employee.Birthday = dateTimePicker1.Value; employee.ImagePath = fileName; EmployeeBLL.AddEmployee(employee); File.Copy(txtImagePath.Text, @"Images\\" + fileName); MessageBox.Show("Employee successfuly added!"); txtUserNo.Clear(); txtPassword.Clear(); chAdmin.Checked = false; txtName.Clear(); txtSurname.Clear(); txtSalary.Clear(); txtAddress.Clear(); txtImagePath.Clear(); pictureBox1.Image = null; comboFull = false; cmbDepartment.SelectedIndex = -1; cmbPosition.DataSource = dto.Positions; cmbPosition.SelectedIndex = -1; comboFull = true; dateTimePicker1.Value = DateTime.Today; fileName = ""; } } else { DialogResult dialogResult = MessageBox.Show("Are you sure?", "Warning", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { EMPLOYEE employee = new EMPLOYEE(); if (txtImagePath.Text != imagePath) { if (File.Exists(@"Images\\" + detail.ImagePath)) { File.Delete(@"Images\\" + detail.ImagePath); } File.Copy(txtImagePath.Text, @"Images\\" + fileName); employee.ImagePath = fileName; } else { employee.ImagePath = detail.ImagePath; } employee.ID = detail.EmployeeID; employee.UserNo = Convert.ToInt32(txtUserNo.Text); employee.Address = txtAddress.Text; employee.Birthday = dateTimePicker1.Value; employee.Name = txtName.Text; employee.Surname = txtSurname.Text; employee.Password = txtPassword.Text; employee.isAdmin = chAdmin.Checked; employee.DepartmentID = Convert.ToInt32(cmbDepartment.SelectedValue); employee.PositionID = Convert.ToInt32(cmbPosition.SelectedValue); employee.Salary = Convert.ToInt32(txtSalary.Text); EmployeeBLL.UpdateEmployee(employee); MessageBox.Show("Employee updated!"); this.Close(); } } } }
private void btnSave_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(txtAddress.Text) || String.IsNullOrEmpty(txtCMND.Text) || String.IsNullOrEmpty(txtPhone.Text) || String.IsNullOrEmpty(txtName.Text) || String.IsNullOrEmpty(txtEmail.Text) || String.IsNullOrEmpty(txtShift.Text) || String.IsNullOrEmpty(cbGender.Text) || String.IsNullOrEmpty(dtPkDOB.Text)) { MessageBox.Show("Ban hay nhap day du", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { Employee emp = new Employee(); emp.EmployeeID = dgtEmployeeEdit.RowCount + 1; emp.Name = txtName.Text; emp.CMND = txtCMND.Text; emp.PhoneNumber = txtPhone.Text; emp.Address = txtAddress.Text; if (cbGender.SelectedValue == "Female") { emp.IsFemale = true; } else { emp.IsFemale = false; } emp.Email = txtEmail.Text; emp.Username = "******"; emp.Password = "******"; emp.IsAdmin = true; emp.DateOfBirth = dtPkDOB.Value; employeeBLL.AddEmployee(emp); DialogResult dialog = MessageBox.Show("Saved successfully", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Information); if (dialog == DialogResult.OK) //click ok thì chuyển lại form đầu. { mainform.loadUCEmployeeEdit(); } } /* if (txtName.Text.Trim().Length == 0) //Nếu chưa nhập Name * { * MessageBox.Show("Bạn phải nhập Name", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); * txtName.Focus(); * return; * } * if (txtAddress.Text.Trim().Length == 0) //Nếu chưa nhập tên chất liệu * { * MessageBox.Show("Bạn phải nhập Address", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); * txtShift.Focus(); * return; * } * if (txtShift.Text.Trim().Length == 0) //Nếu chưa nhập tên chất liệu * { * MessageBox.Show("Bạn phải nhập Shift", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); * txtShift.Focus(); * return; * } * if (txtCMND.Text.Trim().Length == 0) * { * MessageBox.Show("Bạn phải nhập lại CMND", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); * txtShift.Focus(); * return; * } * if (txtPhone.Text.Trim().Length == 0 ) * { * MessageBox.Show("Bạn phải nhập lại Phone", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); * txtShift.Focus(); * return; * } */ }
public ActionResult Input(Employee model, HttpPostedFileBase uploadFile) { try { //TODO: Kiểm tra tính hợp le của dự liệu được nhập if (string.IsNullOrEmpty(model.LastName)) { ModelState.AddModelError("LastName", "LastName expected"); } if (string.IsNullOrEmpty(model.FirstName)) { ModelState.AddModelError("FirstName", "FirstName expected"); } if (string.IsNullOrEmpty(model.Title)) { ModelState.AddModelError("Title", "Title expected"); } if (string.IsNullOrEmpty(model.Email)) { ModelState.AddModelError("Email", "Email expected"); } if (string.IsNullOrEmpty(model.Address)) { ModelState.AddModelError("Address", "Address expected"); } if (string.IsNullOrEmpty(model.City)) { model.City = ""; } if (string.IsNullOrEmpty(model.Country)) { model.Country = ""; } if (string.IsNullOrEmpty(model.HomePhone)) { model.HomePhone = ""; } if (string.IsNullOrEmpty(model.Notes)) { model.Notes = ""; } if (string.IsNullOrEmpty(model.PhotoPath)) { model.PhotoPath = ""; } if (string.IsNullOrEmpty(model.Password)) { model.Password = Encode.EncodeMD5("123456"); } if (uploadFile != null) { string folder = Server.MapPath("../Images/Uploads"); //string fileName = uploadfile.FileName; string fileName = $"{DateTime.Now.Ticks}{Path.GetExtension(uploadFile.FileName)}"; string filePath = Path.Combine(folder, fileName); uploadFile.SaveAs(filePath); model.PhotoPath = fileName; } if (!ModelState.IsValid) { ViewBag.Title = model.EmployeeID == 0 ? "Add new employee" : "Edit a employee"; return(View(model)); } //TODO: Lưu dữ liệu vào DB if (model.EmployeeID == 0) { EmployeeBLL.AddEmployee(model); } else { EmployeeBLL.UpdateEmployee(model); } return(RedirectToAction("Index")); } catch (Exception ex) { ModelState.AddModelError("", ex.Message + ":" + ex.StackTrace); return(View(model)); } }
private void btnSave_Click(object sender, EventArgs e) { if (txtUserNo.Text.Trim() == "") { MessageBox.Show("User no is Empty"); } else if (!EmployeeBLL.isUnique(Convert.ToInt32(txtUserNo.Text))) { MessageBox.Show("This User n° is used by another employee please change"); } else if (txtPass.Text.Trim() == "") { MessageBox.Show("Password is Empty"); } else if (txtName.Text.Trim() == "") { MessageBox.Show("Name is Empty"); } else if (txtSurname.Text.Trim() == "") { MessageBox.Show("Surname is Empty"); } else if (txtSalary.Text.Trim() == "") { MessageBox.Show("Salary is Empty"); } else if (cmbDeparment.SelectedIndex == -1) { MessageBox.Show("Select a Department"); } else if (cmbPosition.SelectedIndex == -1) { MessageBox.Show("Select a Position"); } else { EMPLOYEE employee = new EMPLOYEE(); employee.UserNo = Convert.ToInt32(txtUserNo.Text); employee.Password = txtPass.Text; employee.isAdmin = chkAdmin.Checked; employee.Name = txtName.Text; employee.Surname = txtSurname.Text; employee.Salary = Convert.ToInt32(txtSalary.Text); employee.DepartmentID = Convert.ToInt32(cmbDeparment.SelectedValue); employee.PositionID = Convert.ToInt32(cmbPosition.SelectedValue); employee.Adress = txtAdress.Text; employee.BirthDay = dateTimePicker1.Value; employee.ImagePath = fileName; EmployeeBLL.AddEmployee(employee); File.Copy(txtImagePath.Text, @"images\\" + fileName); MessageBox.Show("Employee was added"); txtUserNo.Clear(); txtPass.Clear(); chkAdmin.Checked = false; txtName.Clear(); txtSurname.Clear(); txtSalary.Clear(); txtAdress.Clear(); txtImagePath.Clear(); pictureBox1.Image = null; comboFull = false; cmbDeparment.SelectedIndex = -1; cmbPosition.DataSource = dto.Positions; cmbPosition.SelectedIndex = -1; comboFull = true; dateTimePicker1.Value = DateTime.Today; } }
private void btnSave_Click(object sender, EventArgs e) { if (txtUserNo.Text.Trim() == "") { MessageBox.Show("User is empty"); } else if (txtPassword.Text.Trim() == "") { MessageBox.Show("Password is empty"); } else if (txtName.Text.Trim() == "") { MessageBox.Show("Name is empty"); } else if (txtSalary.Text.Trim() == "") { MessageBox.Show("Salary is empty"); } else if (cmbDepartment.SelectedIndex == -1) { MessageBox.Show("Select a department"); } else if (cmbPosition.SelectedIndex == -1) { MessageBox.Show("Select a position"); } else { if (!isUpdate) { if (!EmployeeBLL.isUnique(Convert.ToInt32(txtUserNo.Text))) { MessageBox.Show("This user number is used, please change"); } else { EMPLOYEE employee = new EMPLOYEE(); employee.UserNo = Convert.ToInt32(txtUserNo.Text); employee.Password = txtPassword.Text; employee.isAdmin = chAdmin.Checked; employee.Name = txtName.Text; employee.Surname = txtSurname.Text; employee.Salary = Convert.ToInt32(txtSalary.Text); employee.DepartmentID = Convert.ToInt32(cmbDepartment.SelectedValue); employee.PositionID = Convert.ToInt32(cmbPosition.SelectedValue); employee.Address = txtAddress.Text; employee.BirthDay = dateTimePicker1.Value; employee.ImagePath = filename; EmployeeBLL.AddEmployee(employee); File.Copy(txtImagePath.Text, @"images\\" + filename); MessageBox.Show("Employee was added"); txtUserNo.Clear(); txtPassword.Clear(); chAdmin.Checked = false; txtName.Clear(); txtSurname.Clear(); txtSalary.Clear(); txtAddress.Clear(); txtImagePath.Clear(); pictureBox1.Image = null; comboFull = false; cmbDepartment.SelectedIndex = -1; cmbDepartment.DataSource = dto.Departments; cmbPosition.DataSource = dto.Positions; cmbPosition.SelectedIndex = -1; comboFull = true; dateTimePicker1.Value = DateTime.Today; } } else { DialogResult result = MessageBox.Show("Are you shure?", "Warning", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { EMPLOYEE employee = new EMPLOYEE(); if (txtImagePath.Text != imagepath) { if (File.Exists(@"images\\" + detail.ImagePath)) { File.Delete(@"images\\" + detail.ImagePath); } File.Copy(txtImagePath.Text, @"images\\" + filename); employee.ImagePath = filename; } else { employee.ImagePath = detail.ImagePath; } employee.ID = detail.EmployeeID; employee.UserNo = Convert.ToInt32(txtUserNo.Text); employee.Name = txtName.Text; employee.Surname = txtSurname.Text; employee.isAdmin = chAdmin.Checked; employee.Password = txtPassword.Text; employee.Address = txtAddress.Text; employee.BirthDay = dateTimePicker1.Value; employee.DepartmentID = Convert.ToInt32(cmbDepartment.SelectedValue); employee.PositionID = Convert.ToInt32(cmbPosition.SelectedValue); employee.Salary = Convert.ToInt32(txtSalary.Text); EmployeeBLL.UpdateEmployee(employee); MessageBox.Show("Employee was updated"); this.Close(); } } } }
public ActionResult Input(Employee model, HttpPostedFileBase uploadFile) { try { //Kiểm tra tính hợp lệ của dữ liệu được nhập if (string.IsNullOrEmpty(model.LastName)) { ModelState.AddModelError("LastName", "Last Name is invalid"); } if (string.IsNullOrEmpty(model.FirstName)) { ModelState.AddModelError("FirstName", "First Name is invalid"); } if (string.IsNullOrEmpty(model.Title)) { model.Title = ""; } if (model.BirthDate == null) { model.BirthDate = Convert.ToDateTime("1800/01/01"); } if (model.HireDate == null) { model.HireDate = Convert.ToDateTime("1818/01/01"); } else { if (model.HireDate.Year - model.BirthDate.Year < 18) { ModelState.AddModelError("HireDate", "Employee must be at least 18 years old"); } } if (string.IsNullOrEmpty(model.Email)) { model.Email = ""; } if (string.IsNullOrEmpty(model.Address)) { model.Address = ""; } if (string.IsNullOrEmpty(model.City)) { model.City = ""; } if (string.IsNullOrEmpty(model.Country)) { model.Country = ""; } if (string.IsNullOrEmpty(model.HomePhone)) { model.HomePhone = ""; } if (string.IsNullOrEmpty(model.Notes)) { model.Notes = ""; } if (string.IsNullOrEmpty(model.PhotoPath)) { Employee existEmployee = EmployeeBLL.GetEmployee(model.EmployeeID); model.PhotoPath = existEmployee != null ? existEmployee.PhotoPath : ""; } if (string.IsNullOrEmpty(model.Password)) { model.Password = MD5.EncodeMD5("123456"); } //Upload ảnh if (uploadFile != null) { string _FileName = Path.GetFileName(uploadFile.FileName); _FileName = DateTime.Now.Ticks.ToString() + Path.GetExtension(_FileName); string _path = Path.Combine(Server.MapPath("~/Uploads/Images"), _FileName); uploadFile.SaveAs(_path); model.PhotoPath = _FileName; } if (ModelState.IsValid) { //Lưu dữ liệu vào DB if (model.EmployeeID == 0) { EmployeeBLL.AddEmployee(model); } else { EmployeeBLL.UpdateEmployee(model); } return(RedirectToAction("Index")); } else { return(View(model)); } } catch (Exception ex) { ModelState.AddModelError("", ex.Message + ": " + ex.StackTrace); } return(View(model)); }
private void btnSave_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(txtUsername.Text) || String.IsNullOrEmpty(txtCMND.Text) || String.IsNullOrEmpty(txtPhone.Text) || String.IsNullOrEmpty(txtName.Text) || String.IsNullOrEmpty(txtEmail.Text) || cbGender.Text == "-select-" || String.IsNullOrEmpty(dtpDOB.Text) || string.IsNullOrEmpty(txtUsername.Text)) { MessageBox.Show("Please insert information fully !", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Information); /*if (cbGender.Text == "-select-") * errorGender.Text = " This need to be chosen"; * if (String.IsNullOrEmpty(txtCMND.Text)) * errorCMND.Text = " This cannot be empty"; * if (String.IsNullOrEmpty(txtEmail.Text)) * errorEmail.Text = " This cannot be empty"; * if (String.IsNullOrEmpty(txtPhone.Text)) * errorPhone.Text = " This cannot be empty"; * if (String.IsNullOrEmpty(txtAddress.Text)) * errorAddress.Text = " This cannot be empty"; * if (String.IsNullOrEmpty(txtName.Text)) * errorName.Text = " This cannot be empty";*/ } else { bool check = true; if (errorUsername.Text != "" || errorCMND.Text != "" || errorEmail.Text != "" || errorGender.Text != "" || errorName.Text != "" || errorPhone.Text != "") { MessageBox.Show("Please correct your mistakes before save changes"); } else { Employee emp = new Employee(); string Name = txtName.Text; while (Name.IndexOf(" ") != -1) { Name = Name.Replace(" ", " "); } Name = Name.Trim(); emp.Name = Name; emp.CMND = txtCMND.Text; emp.PhoneNumber = txtPhone.Text; emp.Address = txtUsername.Text; if (cbGender.Text == "Female") { emp.IsFemale = true; } if (cbGender.Text == "Male") { emp.IsFemale = false; } emp.Email = txtEmail.Text; // emp.Username = Create_Username(Name); emp.Username = txtUsername.Text; emp.Password = Create_Password(Name, dtpDOB.Value); emp.Status = 1; emp.IsAdmin = (cbIsAdmin.Checked == true) ? true : false; emp.DateOfBirth = dtpDOB.Value; if (employeeBLL.AddEmployee(emp) == true) { DialogResult dialog = MessageBox.Show("Saved successfully", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Information); if (dialog == DialogResult.OK) //click ok thì chuyển lại form đầu. { mainform.loadUCEmployee(); } } else { MessageBox.Show("Saved unsuccessfully. Please try again!"); } } } }
public ActionResult Input(Employee model, HttpPostedFileBase PhotoPath, string PhotoPathDraft, string staff = "", string manageaccount = "", string managedata = "") { try { //TODO :Kiểm tra tính hợp lệ của dữ liệu nhập vào if (string.IsNullOrEmpty(model.FirstName)) { ModelState.AddModelError("FirstName", "FirstName expected"); } if (string.IsNullOrEmpty(model.LastName)) { ModelState.AddModelError("LastName", "LastName expected"); } if (string.IsNullOrEmpty(model.Title)) { ModelState.AddModelError("Title", "Title expected"); } if (string.IsNullOrEmpty(model.Password)) { ModelState.AddModelError("Password", "Password expected"); } if (model.BirthDate == DateTime.MinValue) { ModelState.AddModelError("BirthDate", "BirthDate expected"); } if (model.HireDate == DateTime.MinValue) { ModelState.AddModelError("HireDate", "HireDate expected"); } if (Convert.ToDateTime(model.HireDate).CompareTo(Convert.ToDateTime(model.BirthDate)) <= 0) { ModelState.AddModelError("Date", "Date expected"); } if (string.IsNullOrEmpty(model.Email)) { model.Email = ""; } if (string.IsNullOrEmpty(model.Address)) { model.Address = ""; } if (string.IsNullOrEmpty(model.Country)) { model.Country = ""; } if (string.IsNullOrEmpty(model.City)) { model.City = ""; } if (string.IsNullOrEmpty(model.HomePhone)) { model.HomePhone = ""; } if (string.IsNullOrEmpty(model.Notes)) { model.Notes = ""; } if (string.IsNullOrEmpty(model.PhotoPath)) { model.PhotoPath = ""; } model.Password = MD5Helper.EncodeMD5(model.Password); //TODO :upload image if (PhotoPath != null) { string FileName = $"{DateTime.Now.Ticks}{Path.GetExtension(PhotoPath.FileName)}"; string path = Path.Combine(Server.MapPath("~/Images/Uploads"), FileName); PhotoPath.SaveAs(path); model.PhotoPath = FileName; } if (string.IsNullOrEmpty(staff)) { if (string.IsNullOrEmpty(manageaccount) && string.IsNullOrEmpty(managedata)) { model.Roles = ""; } else if (string.IsNullOrEmpty(managedata)) { model.Roles = manageaccount; } else if (string.IsNullOrEmpty(manageaccount)) { model.Roles = managedata; } else { model.Roles = manageaccount + "," + managedata; } } else { if (string.IsNullOrEmpty(manageaccount) && string.IsNullOrEmpty(managedata)) { model.Roles = staff; } else if (string.IsNullOrEmpty(managedata)) { model.Roles = staff + "," + manageaccount; } else if (string.IsNullOrEmpty(manageaccount)) { model.Roles = staff + "," + managedata; } else { model.Roles = staff + "," + manageaccount + "," + managedata; } } //TODO :Lưu dữ liệu nhập vào if (model.EmployeeID == 0) { EmployeeBLL.AddEmployee(model); } else { if (string.IsNullOrEmpty(model.PhotoPath)) { model.PhotoPath = PhotoPathDraft; } EmployeeBLL.UpdateEmployee(model); } return(RedirectToAction("Index")); } catch (Exception ex) { ModelState.AddModelError("", ex.Message + ":" + ex.StackTrace); return(View(model)); } }
private void SaveEmployeeInfo() { EmployeeBLL objBll =new EmployeeBLL(); RailExam.Model.Employee obj = new RailExam.Model.Employee(); obj.EmployeeName = txtEmployeeNameEdit.Text; obj.WorkNo = txtWorkNoEdit.Text; obj.Address = txtAddress.Text; obj.BeginDate = DateTime.Parse(dateBeginDate.DateValue.ToString()); obj.Birthday = DateTime.Parse(dateBirthday.DateValue.ToString()); obj.Folk = txtFolk.Text; obj.PostID = Convert.ToInt32(hfPostID.Value); obj.OrgID = Convert.ToInt32(hfOrgID.Value); obj.Sex = ddlSex.SelectedValue; obj.NativePlace = txtNativePlace.Text; obj.Wedding = Convert.ToInt32(rblWedding.SelectedValue); obj.WorkPhone = txtWorkPhoneEdit.Text; obj.HomePhone = txtHomePhone.Text; obj.MobilePhone = txtMobilePhone.Text; obj.PostCode = txtPostCode.Text; obj.IsOnPost = !chDimission.Checked; obj.Memo = txtMemoEdit.Text; obj.IsGroupLeader = Convert.ToInt32(ddlIsGroup.SelectedValue); obj.TechnicianTypeID = Convert.ToInt32(ddlTech.SelectedValue); obj.PostNo = txtPostNo.Text; obj.PinYinCode = Pub.GetChineseSpell(obj.EmployeeName); SystemUserBLL objSystemBll = new SystemUserBLL(); if (hfType.Value == "Edit") { obj.EmployeeID = Convert.ToInt32(Request.QueryString.Get("id")); objBll.UpdateEmployee(obj); RailExam.Model.SystemUser objSystem = objSystemBll.GetUserByEmployeeID(obj.EmployeeID); if(objSystem != null) { objSystem.RoleID = Convert.ToInt32(ddlRoleNameEdit.SelectedValue); objSystem.UserID = obj.WorkNo; objSystemBll.UpdateUser(objSystem); } else { objSystem = new SystemUser(); objSystem.EmployeeID = obj.EmployeeID; objSystem.Memo = ""; objSystem.Password = "******"; objSystem.RoleID = Convert.ToInt32(ddlRoleNameEdit.SelectedValue); objSystem.UserID = obj.WorkNo; objSystemBll.AddUser(objSystem); } } else { obj.LoginTime = 0; obj.LoginCount = 0; int id = objBll.AddEmployee(obj); RailExam.Model.SystemUser objSystem = new SystemUser(); objSystem.EmployeeID = id; objSystem.Memo = ""; objSystem.Password = "******"; objSystem.RoleID = Convert.ToInt32(ddlRoleNameEdit.SelectedValue); objSystem.UserID = obj.WorkNo; objSystemBll.AddUser(objSystem); } }
private void btnSave_Click(object sender, EventArgs e) { if (txtName.Text.Trim() == "") { MessageBox.Show("You missed the name"); } else if (txtSurname.Text.Trim() == "") { } else if (txtImagePath.Text.Trim() == "") { MessageBox.Show("You missed the Employee Image"); } else if (txtSalary.Text.Trim() == "") { MessageBox.Show("You missed the salary"); } else if (cmbDepartment.SelectedIndex == -1) { MessageBox.Show("You missed the department"); } else if (cmbPosition.SelectedIndex == -1) { MessageBox.Show("You missed the Position"); } else if (txtUserNo.Text.Trim() == "") { MessageBox.Show("You missed the User Number"); } else if (txtPassword.Text.Trim() == "") { MessageBox.Show("You missed the password"); } else { Employee employee = new Employee(); if (!isUpdate) { if (!EmployeeBLL.IsUnique(Convert.ToInt32(txtUserNo.Text))) { MessageBox.Show("This user does not exist"); } else { employee.UserNo = Convert.ToInt32(txtUserNo.Text); employee.Name = txtName.Text; employee.Password = txtPassword.Text; employee.IsAdmin = chAdmin.Checked; employee.Salary = Convert.ToInt32(txtSalary.Text); employee.Surname = txtSurname.Text; employee.DepartmentID = Convert.ToInt32(cmbDepartment.SelectedValue); employee.PositionID = Convert.ToInt32(cmbPosition.SelectedValue); employee.Address = txtAddres.Text; employee.Birthday = dateTimePicker1.Value; employee.ImagePath = filename; EmployeeBLL.AddEmployee(employee); File.Copy(txtImagePath.Text, @"Images\\" + filename); MessageBox.Show("The Employee was created"); txtUserNo.Clear(); txtSurname.Clear(); txtName.Clear(); txtPassword.Clear(); txtSalary.Clear(); txtSalary.Clear(); txtImagePath.Clear(); cmbDepartment.SelectedIndex = -1; cmbPosition.DataSource = dto.Posiiton; cmbPosition.SelectedIndex = -1; combofull = true; dateTimePicker1.Value = DateTime.Today; pictureBox1.Image = null; chAdmin.Checked = false; } } else { DialogResult result = MessageBox.Show("Are you sure,", "Warning", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { if (txtImagePath.Text != imagepath) { if (File.Exists(@"Images\\" + detail.ImagePath)) { File.Delete(@"Images\\" + detail.ImagePath); } File.Copy(txtImagePath.Text, @"Images\\" + filename); employee.ImagePath = filename; } else { employee.ImagePath = detail.ImagePath; } employee.ID = detail.EmployeeID; employee.UserNo = Convert.ToInt32(txtUserNo.Text); employee.Name = txtName.Text; employee.Surname = txtSurname.Text; employee.IsAdmin = chAdmin.Checked; employee.Password = txtPassword.Text; employee.Address = txtAddres.Text; employee.Birthday = dateTimePicker1.Value; employee.DepartmentID = Convert.ToInt32(cmbDepartment.SelectedValue); employee.PositionID = Convert.ToInt32(cmbPosition.SelectedValue); employee.Salary = Convert.ToInt32(txtSalary.Text); EmployeeBLL.UpdateEmployee(employee); MessageBox.Show("The Employee was updated"); this.Close(); } } } }