public async Task <ActionResult <ApiResult <int> > > Save([FromBody] Entity.Employee employee) { try { if (employee == null || string.IsNullOrWhiteSpace(employee.Name) || string.IsNullOrWhiteSpace(employee.IdNumber)) { return(Error <int>("没有传递正确的员工信息")); } if (employee.ID <= 0) { if (employee.CreatedOn.Year <= 1900) { employee.CreatedOn = DateTime.Now; } int newId = await DbHelper.InsertEntity(Connector, employee); return(Success(newId)); } else { await DbHelper.UpdateEntity(Connector, employee); return(Success(employee.ID)); } } catch (Exception ex) { return(Error <int>(ex.Message)); } }
public static Entity.Employee checkForgotPassword(string username, string email) { try { string sqlforgot = " SELECT * FROM Employee WHERE Emp_username=@user AND Emp_Email=@email"; string Addvalue = "@user,@email"; string value = username + "," + email; Entity.Employee empCheck = new Entity.Employee(); ClassConnectDB conn = new ClassConnectDB(); SqlDataReader readCheckRole = conn.SelectWhereSqlDataReader(sqlforgot, Addvalue, value); //SqlDataReader readCheckRole = conn.SelectSqlDataReader(sqlforgot); if (readCheckRole.Read()) { empCheck.Emp_FName = readCheckRole["Emp_FName"].ToString(); empCheck.Emp_LName = readCheckRole["Emp_LName"].ToString(); empCheck.Emp_username = readCheckRole["Emp_username"].ToString(); empCheck.Emp_password = readCheckRole["Emp_password"].ToString(); empCheck.Emp_Email = readCheckRole["Emp_Email"].ToString(); } conn.Close(); return empCheck; } catch (Exception) { return null; } }
private void button1_Click(object sender, EventArgs e) { Entity.Employee employee = new Entity.Employee(); employee.id_employee = Convert.ToInt32(txtID.Text); employee.first = txtFirst.Text; employee.last = txtLast.Text; employee.phone = txtPhone.Text; employee.address = txtAddress.Text; employee.cui = Convert.ToInt32(txtCUI.Text); employee.salary = float.Parse(txtSalary.Text); int idTypeEmployee = type_Employee_Logic.getIdByTypeEmployee(cbxTypeEmployees.Text); employee.type_Employee.id_type_employee = idTypeEmployee; if (employee_Logic.InsertEmployee(employee)) { MessageBox.Show("Se inserto correctamente"); } else { MessageBox.Show("Error"); } }
public int Upsert(Entity.Employee employee) { if (employee.Id == Guid.Empty) { return(_empRepository.Add(employee)); } return(_empRepository.Update(employee)); }
/// <summary> /// 正确初始化一个人员证书清单视图模型类实例 /// </summary> /// <param name="employee">人员实体</param> /// <param name="certifications">该人员拥有的全部证书实体集合</param> /// <param name="references">所有资格类型参照项实体集合</param> /// <returns></returns> public static EmployeeCertsViewModel Create(Entity.Employee employee, Certification[] certifications, Reference[] qulifications) => new EmployeeCertsViewModel { EmployeeId = employee.ID, EmployeeName = employee.Name, Certs = certifications?.Select(c => CertViewModel.Create(c, employee, qulifications)) .ToArray(), QualifList = new SelectList(qulifications, nameof(Reference.ID), nameof(Reference.ReferenceValue)), NewCertQualifId = qulifications?.First()?.ID, NewCertIssueDate = DateTime.Today, NewCertExpireDate = DateTime.Today.AddYears(3), NewCertActive = true, };
public static ProjEmployeeViewModel Create(Entity.Employee employee, Reference[] specialities) => new ProjEmployeeViewModel { DutyId = employee.InDutyID, DutyName = employee.DutyName, EmployeeId = employee.ID, EmployeeName = employee.Name, EnListDate = employee.InDate, ProjectId = employee.InProjectID, ProjectName = employee.ProjectName, SpecialityId = employee.SpecialtyID, SpecialityName = (from s in specialities where s.ID == employee.SpecialtyID select s.ReferenceValue).FirstOrDefault(), IsActive = employee.ActiveStatus, };
public async Task <IActionResult> Edit(EmployeeViewModel model) { if (ModelState.IsValid) { Entity.Employee employee; if (model.EmployeeId > 0) { employee = await _employeeService.GetEmployee(model.EmployeeId); if (employee == null || employee.ID <= 0) { ModelState.AddModelError("", "该人员已经被删除或者其它原因没有找到"); return(View(model)); } } else { employee = new Entity.Employee { CreatedBy = UserHelper.GetUserID(HttpContext), CreatedOn = DateTime.Now, }; } try { employee.ActiveStatus = model.ActiveStatus; employee.IdNumber = model.IdNumber; employee.Name = model.Name; employee.OrganizationID = model.OrganizationID; employee.SN = model.SN; employee.SpecialtyID = model.SpecialtyID; employee.Title = model.Title; var id = await _employeeService.SaveEmployee(employee); return(RedirectToAction(nameof(Edit), new { id = id })); } catch (Exception ex) { ModelState.AddModelError("", "保存人员错误:" + ex.Message); } } return(View(model)); }
public static int InsertEmp(Entity.Employee emp) { String sql = " insert into employee(name,identify_id,dob,gender,phone,address,role,salary,start_date,description)" + " Values (@name, @iden, @dob, @gen,@phone,@address, @role,@salary,SYSDATETIME(),@dess)"; SqlParameter param1 = new SqlParameter("@name", SqlDbType.NVarChar); param1.Value = emp.Name; SqlParameter param2 = new SqlParameter("@iden", SqlDbType.NVarChar); param2.Value = emp.Identity; SqlParameter param3 = new SqlParameter("@dob", SqlDbType.DateTime); param3.Value = emp.Dob; SqlParameter param4 = new SqlParameter("@gen", SqlDbType.Int); param4.Value = emp.Gender; SqlParameter param5 = new SqlParameter("@phone", SqlDbType.VarChar); param5.Value = emp.Phone; SqlParameter param6 = new SqlParameter("@address", SqlDbType.NVarChar); param6.Value = emp.Address; SqlParameter param7 = new SqlParameter("@role", SqlDbType.NVarChar); param7.Value = emp.Role; SqlParameter param8 = new SqlParameter("@salary", SqlDbType.Int); param8.Value = emp.Salary; SqlParameter param9 = new SqlParameter("@dess", SqlDbType.NVarChar); param9.Value = emp.Description; int check = Dao.ExecuteSQLWithParameters(sql, param1, param2, param3, param4, param5, param6, param7, param8, param9); return(check); }
public static Entity.Employee checkRoleLogin(string username, string password) { try { Entity.Employee emp = new Entity.Employee(); string sqlchekRole = " SELECT * FROM Employee WHERE Emp_username=@user AND Emp_password=@pass"; string Addvalue = "@user,@pass"; string value = username + "," + password; ClassConnectDB conn = new ClassConnectDB(); SqlDataReader readCheckRole = conn.SelectWhereSqlDataReader(sqlchekRole, Addvalue, value); if (readCheckRole.Read()) { emp.Emp_ID = readCheckRole["Emp_ID"].ToString(); emp.Emp_Type = readCheckRole["Emp_Type"].ToString(); emp.Emp_LName = readCheckRole["Emp_LName"].ToString(); emp.Emp_FName = readCheckRole["Emp_FName"].ToString(); emp.Emp_username=readCheckRole["Emp_username"].ToString(); emp.Emp_password = readCheckRole["Emp_password"].ToString(); } string iplog = Common.network.showIp(); string logdate = "CONVERT(VARCHAR(10), GETDATE(), 104)"; string logtime = "CONVERT(VARCHAR(8), GETDATE(), 108)"; string tid = readCheckRole["Emp_ID"].ToString(); string insertLog = "INSERT INTO LogLoginEmp(Log_IP, Log_Date, Log_timeStart, Emp_id) VALUES('" + iplog + "'," + logdate + "," + logtime + "," + tid + ")"; conn.QueryExecuteNonQuery(insertLog); conn.Close(); return emp; } catch (Exception) { return null; } }
/// <summary> /// 正确初始化一个证书视图模型类实例。 /// </summary> /// <param name="cert">证书实体</param> /// <param name="employee">人员实体</param> /// <param name="references">全部资格类型集合</param> /// <returns></returns> public static CertViewModel Create(Certification cert, Entity.Employee employee, Reference[] qulifications) => new CertViewModel { ActiveStatus = cert.ActiveStatus, AuthorityUnit = cert.AuthorityUnit, CertId = cert.ID, CertifyingDate = cert.CertifyingDate, CertName = cert.Name, EmployeeId = cert.EmployeeID, EmployeeName = employee.Name, ExpireDate = cert.ExpireDate, QualifID = cert.QualificationID, QualifName = (qulifications.Select(q => new { Id = q.ID, Name = $"{q.ReferenceValue}({q.ReferenceCode})" }) .First(q => q.Id == cert.QualificationID) ).Name };
public static List <Entity.Employee> getAllEmp() { List <Entity.Employee> list = new List <Entity.Employee>(); String sql = "Select * from employee"; DataTable dt = Dao.GetDataBySQL(sql); foreach (DataRow dr in dt.Rows) { Entity.Employee emp = new Entity.Employee(); emp.id = Int32.Parse(Convert.ToString(dr["id"])); emp.Name = Convert.ToString(dr["name"]); emp.Identity = Convert.ToString(dr["identify_id"]); emp.Dob = Convert.ToString(dr["dob"]); emp.Gender = Convert.ToInt32(dr["gender"]); emp.Address = Convert.ToString(dr["address"]); emp.Phone = Convert.ToString(dr["Phone"]); emp.Role = Convert.ToString(dr["role"]); emp.Salary = Int32.Parse(Convert.ToString(dr["salary"])); emp.Start_date = Convert.ToString(dr["start_date"]); list.Add(emp); } return(list); }
public void WriteEmployeeInfoToConsole(Entity.Employee employee) { Console.WriteLine(string.Format(" EmployeeId: {0} \n EmployeeName: {1} \n DepartmentId: {2}", employee.Id, employee.Name, employee.DepartmentId)); }
public static async Task <string> Upload(Stream stream, ExcelMap map, IEmployeeService employeeService = null, IProjectService projectService = null) { IWorkbook workbook = new XSSFWorkbook(stream); ISheet sheet = workbook.GetSheetAt(map.SheetIndex); if (sheet == null) { throw new Exception($"上传的文件没有索引为{map.SheetIndex}的工作表"); } IDictionary <string, int> Indecies = new Dictionary <string, int>(); int startRowIndex; if (map.WithHeader) { IRow header = sheet.GetRow(0); if (header == null) { throw new Exception($"上传的文件第一行必须是符合格式的标题行"); } foreach (var caption in header.Cells) { Indecies.Add(caption.StringCellValue, caption.ColumnIndex); } startRowIndex = 1; } else { IRow firstRow = sheet.GetRow(0); if (firstRow == null) { throw new Exception("上传文件没有数据,必须从第一行开始有数据"); } for (var i = 0; i <= firstRow.LastCellNum; i++) { Indecies.Add(i.ToString(), i); } startRowIndex = 0; } //由于现在仅支持项目和人员导入,因此直接使用一个布尔值来区别类型。 var projectType = typeof(Entity.Project); var staffType = typeof(Entity.Employee); bool isProject; if (map.IsTypeOf(projectType)) { isProject = true; } else if (map.IsTypeOf(staffType)) { isProject = false; } else { throw new Exception("not supported upload entity type"); } int total = 0, success = 0, failure = 0; StringBuilder messageBuilder = new StringBuilder(); for (var rowIndex = startRowIndex; rowIndex <= sheet.LastRowNum; rowIndex++) { total++; IRow data = sheet.GetRow(rowIndex); object entity; if (isProject) { entity = new Entity.Project(); } //{ // ActiveStatus = true, // CreatedOn = DateTime.Now, // CreatedBy = Cnf.CodeBase.Serialize.ValueHelper.DBKEY_NULL //}; else { entity = new Entity.Employee { ActiveStatus = true, CreatedOn = DateTime.Now, CreatedBy = Cnf.CodeBase.Serialize.ValueHelper.DBKEY_NULL, InDate = Cnf.CodeBase.Serialize.ValueHelper.DbDate_Null, InDutyID = Cnf.CodeBase.Serialize.ValueHelper.DBKEY_NULL, InProjectID = Cnf.CodeBase.Serialize.ValueHelper.DBKEY_NULL } }; try { foreach (var propMap in map.Properties) { if (!Indecies.ContainsKey(propMap.ColumnIndex)) { throw new Exception($"上传的文件无法定位到列索引[{propMap.ColumnIndex}]"); } object cellValue = propMap.PropertyType switch { PropertyType.Boolean => data.GetCell(Indecies[propMap.ColumnIndex]).BooleanCellValue, PropertyType.DateTime => data.GetCell(Indecies[propMap.ColumnIndex]).DateCellValue, PropertyType.Int => Convert.ToInt32(data.GetCell(Indecies[propMap.ColumnIndex]).NumericCellValue), PropertyType.Real => data.GetCell(Indecies[propMap.ColumnIndex]).NumericCellValue, PropertyType.Text => data.GetCell(Indecies[propMap.ColumnIndex]).StringCellValue, _ => throw new Exception("not supported property data type"), }; PropertyInfo propertyInfo = isProject ? projectType.GetProperty(propMap.PropertyName, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance) : staffType.GetProperty(propMap.PropertyName, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance); if (propertyInfo == null) { throw new Exception($"Excel映射配置的属性{propMap.PropertyName}不是实体类的成员"); } propertyInfo.SetValue(entity, cellValue); } } catch (Exception ex) { messageBuilder.AppendLine($"行{rowIndex}读文件错:{ex.Message}<br/>"); failure++; continue; //直接开始处理下一行。 } //保存到数据库 try { if (isProject) { await projectService.SaveProject((Entity.Project) entity); } else { await employeeService.SaveEmployee((Entity.Employee) entity); } success++; } catch (Exception ex) { messageBuilder.AppendLine($"行{rowIndex}写数据库错:{ex.Message}<br/>"); failure++; } } messageBuilder.AppendLine($"共处理了{total}行,导入{success}行,错误{failure}行"); return(messageBuilder.ToString()); }
protected void btnLogin_Click(object sender, EventArgs e) { string username = txtusername.Text.ToString().ToLower(); string password = txtpassword.Text.ToString().ToLower(); try { if ((username.Substring(0, 2) + username.Substring(5, 4).ToString()).Equals("020461")) { Entity.Student stdRole = new Entity.Student(); stdRole = BLL.Student.checkRoleLogin(username, password); if (stdRole.Std_Type.Equals("ST")) { Session["userid"] = stdRole.Std_Campus_Code; Session["userType"] = stdRole.Std_Type; Session["username"] = stdRole.Std_FName; Session["name"] = stdRole.Std_FName + " " + stdRole.Std_LName; Session["yearEducate"] = 2552;// stdRole.Std_YearEducate; Session["picturepath"] = stdRole.std_picturepath; if (stdRole.Std_Username.Equals(stdRole.Std_Password)) { Response.Redirect("ChangeNewPassword.aspx?id=1" + stdRole.Std_Username); } else { Response.Redirect("../BackYard/Plane/Education2.aspx"); } } else if (stdRole.Std_Type.Equals("AL")) { Session["username"] = stdRole.Std_FName; Session["userType"] = stdRole.Std_Type; Session["userid"] = stdRole.Std_Campus_Code; Session["name"] = stdRole.Std_FName + " " + stdRole.Std_LName; Session["yearEducate"] = stdRole.Std_YearEducate; Session["picturepath"] = stdRole.std_picturepath; if (stdRole.Std_Username.Equals(stdRole.Std_Password)) { Response.Redirect("ChangeNewPassword.aspx?id=1" + stdRole.Std_Username); } else { // Response.Redirect("../BackYard/Post/Post_all.aspx"); Response.Redirect("../Plane/Education2.aspx"); } } else { ShowMessageWeb("กรุณาตรวจสอบความถูกต้องของ username และ password ! "); } } else if ((username.Substring(username.Length - 5, 5)).Equals("admin")) { Entity.Employee empRole = new Entity.Employee(); empRole = BLL.Employee.checkRoleLogin(username, password); if (empRole.Emp_Type.Equals("AD")) { Session["username"] = empRole.Emp_FName; Session["userType"] = empRole.Emp_Type; Session["userid"] = empRole.Emp_ID; Session["name"] = empRole.Emp_FName + " " + empRole.Emp_LName; if (empRole.Emp_username.Equals(empRole.Emp_password)) { Response.Redirect("ChangeNewPassword.aspx?id=2" + empRole.Emp_username); } else { Response.Redirect("../BackYard/Admin/MainAdmin.aspx"); } } else if (empRole.Emp_Type.Equals("EM")) { Session["username"] = empRole.Emp_FName; Session["userType"] = empRole.Emp_Type; Session["userid"] = empRole.Emp_ID; Session["name"] = empRole.Emp_FName + " " + empRole.Emp_LName; if (empRole.Emp_username.Equals(empRole.Emp_password)) { Response.Redirect("ChangeNewPassword.aspx?id=2" + empRole.Emp_username); } else { Response.Redirect("../BackYard/Admin/MainAdmin.aspx"); } } else { ShowMessageWeb("กรุณาตรวจสอบความถูกต้องของ username และ password ! "); } } else if ((username.Substring(username.Length - 4, 1)).Equals(".")) { Entity.Teacher tchRole = new Entity.Teacher(); tchRole = BLL.Teacher.checkRoleLogin(username, password); if (tchRole.Tch_Type.Equals("TE")) { Session["username"] = tchRole.Tch_FName; Session["userType"] = tchRole.Tch_Type; Session["userid"] = tchRole.Tch_ID; Session["name"] = tchRole.Tch_FName + " " + tchRole.Tch_LName; Session["picturepath"] = tchRole.Tch_picturepath; if (tchRole.Tch_username.Equals(tchRole.Tch_password)) { Response.Redirect("ChangeNewPassword.aspx?id=3" + tchRole.Tch_username); } else { // Response.Redirect("../BackYard/Post/Post_all.aspx"); Response.Redirect("../BackYard/ClassRoom/mainClassroom.aspx"); } } else if (tchRole.Tch_Type.Equals("TS")) { Session["username"] = tchRole.Tch_FName; Session["userType"] = tchRole.Tch_Type; Session["userid"] = tchRole.Tch_ID; Session["name"] = tchRole.Tch_FName + " " + tchRole.Tch_LName; Session["picturepath"] = tchRole.Tch_picturepath; if (tchRole.Tch_username.Equals(tchRole.Tch_password)) { Response.Redirect("ChangeNewPassword.aspx?id=3" + tchRole.Tch_username); } else { // Response.Redirect("../BackYard/Post/Post_all.aspx"); Response.Redirect("../BackYard/ClassRoom/mainClassroom.aspx"); } } else { ShowMessageWeb("กรุณาตรวจสอบความถูกต้องของ username และ password ! "); } } else { ShowMessageWeb("กรุณาตรวจสอบความถูกต้องของ username และ password ! "); } } catch (Exception) { ShowMessageWeb("กรุณาตรวจสอบความถูกต้องของ username และ password ! "); } }
protected void butOK_Click(object sender, EventArgs e) { //Response.Redirect("showNewPasswordVerity.aspx"); string username = txtusername.Text.ToString().ToLower(); string email = txtEmail.Text.ToString(); try { string title = "แจ้งเตือน username และ password เข้าใช้ระบบ "; if ((username.Substring(0, 2) + username.Substring(5, 4).ToString()).Equals("020461")) { Entity.Student std = new Entity.Student(); std = BLL.Student.checkForgotPassword(username, email); if (! std.Std_Password.Equals("") || !std.Std_Password.Equals(null)) { name=std.Std_FName+" "+std.Std_LName; string detail=showMessageMail(name,std.Std_Username,std.Std_Password); string e_mail = std.Std_email.ToString().Trim(); sendMail(std.Std_email.ToString(), "*****@*****.**", title, detail); } else { ShowMessageWeb("ไม่พบ username หรือ email ที่คุณกรอก กรุณาตรวจสอบอีกครั้ง !"); } } else if ((username.Substring(username.Length - 5, 5)).Equals("admin")) { Entity.Employee emp = new Entity.Employee(); emp = BLL.Employee.checkForgotPassword(username, email); if (!emp.Equals("") || !emp.Emp_password.Equals(null)) { name = emp.Emp_FName + " " + emp.Emp_LName; string detail = showMessageMail(name, emp.Emp_username, emp.Emp_password); string e_mail = emp.Emp_Email.ToString().Trim(); sendMail(emp.Emp_Email.ToString(), "*****@*****.**", title, detail); } else { ShowMessageWeb("ไม่พบ username หรือ email ที่คุณกรอก กรุณาตรวจสอบอีกครั้ง !"); } } else if ((username.Substring(username.Length - 4, 1)).Equals(".")) { Entity.Teacher tea = new Entity.Teacher(); tea = BLL.Teacher.checkForgotPassword(username, email); if (!tea.Tch_password.Equals("") || !tea.Tch_password.Equals(null)) { name = tea.Tch_FName + " " + tea.Tch_LName; string detail = showMessageMail(name, tea.Tch_username, tea.Tch_password); string e_mail = tea.Tch_email.ToString().Trim(); sendMail(tea.Tch_email.ToString(), "*****@*****.**", title, detail); } else { ShowMessageWeb("ไม่พบ username หรือ email ที่คุณกรอก กรุณาตรวจสอบอีกครั้ง !"); } } else { ShowMessageWeb("ไม่พบ username หรือ email ที่คุณกรอก กรุณาตรวจสอบอีกครั้ง !"); } } catch (Exception) { ShowMessageWeb("การเชื่อมต่อระหว่างเมล์เซฟเวอร์มีปัญหา อาจเนื่องจากมีการบล็อกพอร์ตเมล์ กรุณาเปลี่ยนการเชื่อมต่ออินเตอร์เน็ต !"); } }
public Entity.Employee ToEntity(Entity.SeedsEntities database) { var result = new Entity.Employee(); ApplyChanges(database, result); return result; }