public Data.EmployeeInfo ConvertToDb(Model.EmployeeInfo employeeInfo) { return(new Data.EmployeeInfo { Id = employeeInfo.Id, FirstName = employeeInfo.FirstName, LastName = employeeInfo.LastName, FatherName = employeeInfo.FatherName, DateOfBirth = employeeInfo.DateOfBirth, CellNumber = employeeInfo.CellNumber, DateOfLeave = employeeInfo.DateOfLeave, MaritalStatus = employeeInfo.MaritalStatus, ProbationPeriod = employeeInfo.ProbationPeriod, ResidencePhoneNumber = employeeInfo.ResidencePhoneNumber, PersonalEmail = employeeInfo.PersonalEmail, CNIC = employeeInfo.CNIC, PermanentAddress = employeeInfo.PermanentAddress, PresentAddress = employeeInfo.PresentAddress, TotalExperience = employeeInfo.ExperienceYears + "," + employeeInfo.ExperienceMonths, DateOfJoin = employeeInfo.DateOfJoin, Position = employeeInfo.Position, EmpCode = employeeInfo.EmpCode, Team = employeeInfo.Team, AccountId = employeeInfo.AccountId, CreatedDate = employeeInfo.CreatedDate, CreatedByAccountId = employeeInfo.CreatedByAccountId, ModifiedDate = employeeInfo.ModifiedDate, ModifiedByAccountId = employeeInfo.ModifiedByAccountId }); }
public void UpdateEmployeeInfo(Model.EmployeeInfo employeeInfo) { Data.EmployeeInfo employee = _context.EmployeeInfoes.Find(employeeInfo.Id); if (employee != null) { employee.FirstName = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(employeeInfo.FirstName.ToLower()); employee.LastName = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(employeeInfo.LastName.ToLower()); employee.FatherName = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(employeeInfo.FatherName.ToLower()); employee.DateOfBirth = employeeInfo.DateOfBirth; employee.CellNumber = employeeInfo.CellNumber; employee.DateOfLeave = employeeInfo.DateOfLeave; employee.MaritalStatus = employeeInfo.MaritalStatus; employee.ProbationPeriod = employeeInfo.ProbationPeriod; employee.ResidencePhoneNumber = employeeInfo.ResidencePhoneNumber; employee.PersonalEmail = employeeInfo.PersonalEmail.ToLower(); employee.CNIC = employeeInfo.CNIC; employee.PermanentAddress = employeeInfo.PermanentAddress; employee.PresentAddress = employeeInfo.PresentAddress; employee.TotalExperience = employeeInfo.ExperienceYears + "," + employeeInfo.ExperienceMonths; employee.Position = employeeInfo.Position; employee.Team = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(employeeInfo.Team.ToLower()); employee.EmpCode = employeeInfo.EmpCode; employee.DateOfJoin = employeeInfo.DateOfJoin; employee.ModifiedDate = employeeInfo.ModifiedDate; employee.ModifiedByAccountId = employeeInfo.ModifiedByAccountId; _context.SaveChanges(); } else { throw new ArgumentNullException(); } }
public int SaveEmployeeInfo(Model.EmployeeInfo employeeInfo) { Data.EmployeeInfo empInfo = ConvertToDb(employeeInfo); _context.EmployeeInfoes.Add(empInfo); _context.SaveChanges(); return(empInfo.Id); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.EmployeeInfo model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update EmployeeInfo set "); strSql.Append("EmployeeName=@EmployeeName,"); strSql.Append("Sex=@Sex,"); strSql.Append("EmployeeBirthday=@EmployeeBirthday,"); strSql.Append("EmployeeDepartment=@EmployeeDepartment,"); strSql.Append("EmployeePost=@EmployeePost,"); strSql.Append("EmployeePhone=@EmployeePhone,"); strSql.Append("EmployeeEmail=@EmployeeEmail,"); strSql.Append("EmployeeAddress=@EmployeeAddress,"); strSql.Append("EmployeeFlag=@EmployeeFlag"); strSql.Append(" where EmployeeID=@EmployeeID "); SqlParameter[] parameters = { new SqlParameter("@EmployeeID", SqlDbType.NVarChar, 50), new SqlParameter("@EmployeeName", SqlDbType.NVarChar, 50), new SqlParameter("@Sex", SqlDbType.NVarChar, 50), new SqlParameter("@EmployeeBirthday", SqlDbType.DateTime), new SqlParameter("@EmployeeDepartment", SqlDbType.NVarChar, 50), new SqlParameter("@EmployeePost", SqlDbType.NVarChar, 50), new SqlParameter("@EmployeePhone", SqlDbType.NVarChar, 20), new SqlParameter("@EmployeeEmail", SqlDbType.NVarChar, 50), new SqlParameter("@EmployeeAddress", SqlDbType.NVarChar, 100), new SqlParameter("@EmployeeFlag", SqlDbType.Int) }; parameters[0].Value = model.EmployeeID; parameters[1].Value = model.EmployeeName; parameters[2].Value = model.Sex; parameters[3].Value = model.EmployeeBirthday; parameters[4].Value = model.EmployeeDepartment; parameters[5].Value = model.EmployeePost; parameters[6].Value = model.EmployeePhone; parameters[7].Value = model.EmployeeEmail; parameters[8].Value = model.EmployeeAddress; parameters[9].Value = model.EmployFalg; int rows = DBHelper.ExecuteSql(strSql.ToString(), CommandType.Text, parameters); if (rows > 0) { return(true); } else { return(false); } }
private void toolSave_Click(object sender, EventArgs e) { if (txtEmployeeID.Text == "" || txtEmployeeName.Text == "" || txtEmail.Text == "" || txtEmployeeAddress.Text == "" || txtPhone.Text == "") { MessageBox.Show("请将信息添加完整!"); return; } Model.EmployeeInfo model = new Model.EmployeeInfo();//实例化model层 model.EmployeeID = txtEmployeeID.Text.Trim(); model.EmployeeName = txtEmployeeName.Text.Trim(); model.Sex = cboSex.Text.Trim(); model.EmployeeBirthday = DateTime.Parse(dateTimePicker1.Text); model.EmployeeDepartment = cmbEmployeeDepartment.Text; model.EmployeePost = cmbEmployeePost.Text; model.EmployeePhone = txtPhone.Text.Trim(); model.EmployeeEmail = txtEmail.Text; model.EmployeeAddress = txtEmployeeAddress.Text; BLL.Employee bll = new BLL.Employee();//实例化BLL层 switch (flag) { case 0: { } break; case 1: { if (bll.Add(model)) //将员工信息添加到数据库中,根据返回值判断是否添加成功 { DataBind(); //窗体登录时绑定数据到DataGridView ControlStatus(); } } break; case 2: { if (bll.Update(model)) //根据返回布尔值判断是否修改数据成功 { DataBind(); //窗体登录时绑定数据到DataGridView ControlStatus(); } } break; case 3: { if (bll.Delete(model)) //根据返回布尔值判断是否删除数据成功 { DataBind(); //窗体登录时绑定数据到DataGridView ControlStatus(); } } break; } }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(Model.EmployeeInfo model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into EmployeeInfo("); strSql.Append("EmployeeID,EmployeeName,Sex,EmployeeBirthday,EmployeeDepartment,EmployeePost,EmployeePhone,EmployeeEmail,EmployeeAddress,EmployeeFlag)"); strSql.Append(" values ("); strSql.Append("@EmployeeID,@EmployeeName,@Sex,@EmployeeBirthday,@EmployeeDepartment,@EmployeePost,@EmployeePhone,@EmployeeEmail,@EmployeeAddress,@EmployeeFlag)"); SqlParameter[] parameters = { new SqlParameter("@EmployeeID", SqlDbType.NVarChar, 50), new SqlParameter("@EmployeeName", SqlDbType.NVarChar, 50), new SqlParameter("@Sex", SqlDbType.NVarChar, 50), new SqlParameter("@EmployeeBirthday", SqlDbType.DateTime), new SqlParameter("@EmployeeDepartment", SqlDbType.NVarChar, 50), new SqlParameter("@EmployeePost", SqlDbType.NVarChar, 50), new SqlParameter("@EmployeePhone", SqlDbType.NVarChar, 20), new SqlParameter("@EmployeeEmail", SqlDbType.NVarChar, 50), new SqlParameter("@EmployeeAddress", SqlDbType.NVarChar, 100), new SqlParameter("@EmployeeFlag", SqlDbType.Int) }; parameters[0].Value = model.EmployeeID; parameters[1].Value = model.EmployeeName; parameters[2].Value = model.Sex; parameters[3].Value = model.EmployeeBirthday; parameters[4].Value = model.EmployeeDepartment; parameters[5].Value = model.EmployeePost; parameters[6].Value = model.EmployeePhone; parameters[7].Value = model.EmployeeEmail; parameters[8].Value = model.EmployeeAddress; parameters[9].Value = model.EmployFalg; int rows = DBHelper.ExecuteSql(strSql.ToString(), CommandType.Text, parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 删除一条数据 /// </summary> public bool Delete(Model.EmployeeInfo model) { StringBuilder strSql = new StringBuilder(); strSql.Append("delete from EmployeeInfo "); strSql.Append(" where EmployeeID=@EmployeeID "); SqlParameter[] parameters = { new SqlParameter("@EmployeeID", SqlDbType.NVarChar, 50) }; parameters[0].Value = model.EmployeeID; int rows = DBHelper.ExecuteSql(strSql.ToString(), CommandType.Text, parameters); if (rows > 0) { return(true); } else { return(false); } }
public ActionResult Create(AccountInfo accountInfo) { try { if (ModelState.IsValid) { var _employeeInfo = new Model.EmployeeInfo(); _employeeInfo.CreatedByAccountId = CurrentUser.AccountId; _employeeInfo.CreatedDate = DateTime.Now; int employeeInfoId; int accountId; string saltValue = RandomPassword.Generate(18, 20); string password = RijndaelCrypt.EncryptPassword(RandomPassword.Generate(), saltValue); accountInfo.CompanyEmail = accountInfo.CompanyEmail.ToLower(); accountInfo.PasswordHash = password; accountInfo.Salt = saltValue; accountInfo.LastLoginDate = DateTime.Now; accountInfo.LastLoginIp = ""; accountInfo.IsActive = true; accountInfo.IsFirstTimeLogin = true; using (var transaction = new System.Transactions.TransactionScope()) { using (AccountRepository Repo = new AccountRepository()) { if (Repo.IsEmailExist(accountInfo.CompanyEmail) == true) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Email already exist."); return(View()); } int roleId = Repo.GetRoleIdByName("Anonymous"); accountInfo.RoleId = roleId; accountId = Repo.CreateAccount(accountInfo); } using (AccountCheckListRepository Repo = new AccountCheckListRepository()) { var _accountCheckList = new AccountCheckListInfo(accountId); Repo.SaveAccountCheckList(_accountCheckList); } using (EmployeeRepository Repo = new EmployeeRepository()) { _employeeInfo.AccountId = accountId; employeeInfoId = Repo.SaveEmployeeInfo(_employeeInfo); } using (LeaveAllowedRepository Repo = new LeaveAllowedRepository()) { LeaveAllowedInfo _leaveAllowed = new LeaveAllowedInfo(0, 0, employeeInfoId, CurrentUser.AccountId); Repo.SaveLeaveAllowed(_leaveAllowed); } using (SalaryRepository Repo = new SalaryRepository()) { var _salaryInfo = new SalaryInfo(CurrentUser.AccountId, employeeInfoId); Repo.SaveSalary(_salaryInfo); } using (FamilyMemberRepository Repo = new FamilyMemberRepository()) { var _familyMember = new FamilyMemberInfo { Name = "Self", Relation = "Selef", EmployeeInfoId = employeeInfoId }; Repo.SaveFamilyMember(_familyMember); } transaction.Complete(); } List <string> To = new List <string>() { accountInfo.CompanyEmail }; string Subject = "LPS Online Account Information"; var LoginUrl = Url.Action("Login", "Auth", new { Area = "" }, protocol: Request.Url.Scheme); string Body = "Dear Employee, <br/><br/>" + "Your account has been created.<br/>" + "Please ensure to save the username and password written below:<br/><br/>" + "Username: <b>" + accountInfo.CompanyEmail + "</b><br/>" + "Password: <b>" + RijndaelCrypt.DecryptPassword(accountInfo.PasswordHash, accountInfo.Salt) + "</b><br/><br/>" + "<a href='" + LoginUrl + "' target='_blank'>" + LoginUrl + "</a><br/>" + "You can login to your account to use LPS online services.<br/><br/>" + "Thanks,<br/>" + "<b>Logic Powered Solutions</b>"; bool result = EmailSender.Send(Subject, Body, To); if (result) { TempData["Msg"] = AlertMessageProvider.SuccessMessage("Account created, email has been sent to employee successfully."); } else { TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong! email not sent, please try again later."); } return(RedirectToAction("Manage", "Account")); } return(View()); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Account", "Create"))); } }
public ActionResult Update(AccountInfo accountInfo) { try { if (ModelState.IsValid) { AccountInfo _accountInfo = null; using (AccountRepository Repo = new AccountRepository()) { _accountInfo = Repo.GetEmployeeAccountById(accountInfo.Id); } if (_accountInfo == null) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong, please try again later."); return(RedirectToAction("Manage", "Account")); } if (CurrentUser.AccountId == accountInfo.Id) { TempData["Msg"] = AlertMessageProvider.FailureMessage("You can't update your own account."); return(RedirectToAction("Manage", "Account")); } if (CurrentUser.Role == "Administrator" && _accountInfo.RoleName == "Administrator" || _accountInfo.RoleName == "SuperAdmin") { TempData["Msg"] = AlertMessageProvider.FailureMessage("You don't have permission for this process."); return(RedirectToAction("Manage", "Account")); } if (CurrentUser.Role != "SuperAdmin") { accountInfo.RoleId = _accountInfo.RoleId; } using (var transaction = new System.Transactions.TransactionScope()) { using (EmployeeRepository Repo = new EmployeeRepository()) { var _employee = new Model.EmployeeInfo(); _employee = Repo.GetEmployeeInfoByAccountId(accountInfo.Id); if (accountInfo.IsActive == false) { _employee.DateOfLeave = DateTime.Now; } else { _employee.DateOfLeave = null; } _employee.ModifiedByAccountId = CurrentUser.AccountId; _employee.ModifiedDate = DateTime.Now; Repo.UpdateEmployeeInfo(_employee); } using (AccountRepository Repo = new AccountRepository()) { Repo.UpdateAccount(accountInfo); } transaction.Complete(); } TempData["Msg"] = AlertMessageProvider.SuccessMessage("Account updated successfully."); return(RedirectToAction("Manage", "Account")); } return(View()); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Account", "Update"))); } }
/// <summary> /// 删除一条数据 /// </summary> public bool Delete(Model.EmployeeInfo model) { return(dal.Delete(model)); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.EmployeeInfo model) { return(dal.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(Model.EmployeeInfo model) { return(dal.Add(model)); }