using FineUIPro; using System; using System.Collections; using System.Collections.Generic; using System.Configuration; using System.IO; using System.Linq; namespace BLL { /// /// 人员信息 /// public static class PersonService { public static Model.SUBQHSEDB db = Funs.DB; /// /// 记录数 /// public static int pcount { get; set; } /// /// 定义变量 /// private static IQueryable getDataLists2 = from x in db.SitePerson_Person select x; /// /// 定义变量 /// private static IQueryable getProjectDataLists = from x in db.SitePerson_Person select x; /// /// 数据列表 /// /// /// /// /// /// /// /// /// public static IEnumerable getProjectListData(string projetcId, string unitId, string postId, string name, string idCard, string isPost, string postType, Grid Grid1) { List listPostType = Funs.GetStrListByStr(postType, ','); List listPostIds = new List(); if (listPostType.Count() > 0) { listPostIds = db.Base_WorkPost.Where(x => listPostType.Contains(x.PostType)).Select(x => x.WorkPostId).ToList(); } IQueryable getProjectDataLists = getDataLists2.Where(x => x.ProjectId == projetcId).OrderBy(x => x.UnitId).ThenBy(x => x.WorkPostId); if (listPostIds.Count() > 0) { getProjectDataLists = getProjectDataLists.Where(x => listPostIds.Contains(x.WorkPostId)); } if (!string.IsNullOrEmpty(unitId) && unitId != Const._Null) { getProjectDataLists = getProjectDataLists.Where(e => e.UnitId == unitId); } if (!string.IsNullOrEmpty(postId) && postId != Const._Null) { getProjectDataLists = getProjectDataLists.Where(e => e.WorkPostId == postId); } if (!string.IsNullOrEmpty(name)) { getProjectDataLists = getProjectDataLists.Where(e => e.PersonName.Contains(name)); } if (!string.IsNullOrEmpty(idCard)) { getProjectDataLists = getProjectDataLists.Where(e => e.IdentityCard.Contains(idCard)); } if (isPost == "1") { getProjectDataLists = getProjectDataLists.Where(e => e.OutTime != null); } if (isPost == "0") { getProjectDataLists = getProjectDataLists.Where(e => e.OutTime == null); } pcount = getProjectDataLists.Count(); if (pcount == 0) { return null; } getProjectDataLists = SortConditionHelper.SortingAndPaging(getProjectDataLists, Grid1.SortField, Grid1.SortDirection, Grid1.PageIndex, Grid1.PageSize); return from x in getProjectDataLists select new { x.PersonId, x.PersonName, x.CardNo, x.IdentityCard, Sex = x.Sex ?? "1", x.Birthday, x.UnitId, db.Base_Unit.First(u => u.UnitId == x.UnitId).UnitName, x.DepartId, db.Base_Depart.First(u => u.DepartId == x.DepartId).DepartName, x.WorkPostId, WorkPostName = WorkPostService.getWorkPostNamesWorkPostIds(x.WorkPostId), x.ProjectId, ProjectName = db.Base_Project.First(u => u.ProjectId == x.ProjectId).ShortName, x.InTime, x.OutTime, x.AuditorDate, x.AuditorId, IsPostName = getStatesName(x.PersonStates), }; } /// /// /// /// public static string getStatesName(string states) { switch (states) { case "2": return "离岗"; case "3": return "离职"; case "4": return "退休"; default: return "在岗"; } } #region 劳务人员列表 /// /// 记录数 /// public static int count { get; set; } /// /// 定义变量 /// private static IQueryable getDataLists = from x in db.View_SitePerson_Person select x; /// /// 数据列表 /// /// /// /// /// /// /// /// /// public static IEnumerable getListData(string projetcId, string unitId, string workPostId, string name, string idCard, string states, Grid Grid1) { IQueryable getDataList = getDataLists.OrderBy(x => x.UnitId); if (!string.IsNullOrEmpty(projetcId) && projetcId != Const._Null) { getDataList = getDataList.Where(e => e.ProjectId == projetcId); } else { getDataList = getDataList.Where(e => Equals(e.ProjectId, null)); } if (!string.IsNullOrEmpty(unitId) && unitId != Const._Null) { getDataList = getDataList.Where(e => e.UnitId == unitId); } if (!string.IsNullOrEmpty(workPostId) && workPostId != Const._Null) { getDataList = getDataList.Where(e => e.WorkPostId == workPostId); } if (!string.IsNullOrEmpty(states) && states != "-2") { getDataList = getDataList.Where(e => e.IsUsed == Convert.ToBoolean(states)); } if (!string.IsNullOrEmpty(name)) { getDataList = getDataList.Where(e => e.PersonName.Contains(name)); } if (!string.IsNullOrEmpty(idCard)) { getDataList = getDataList.Where(e => e.IdentityCard.Contains(idCard)); } count = getDataList.Count(); if (count == 0) { return null; } getDataList = SortConditionHelper.SortingAndPaging(getDataList, Grid1.SortField, Grid1.SortDirection, Grid1.PageIndex, Grid1.PageSize); return from x in getDataList select new { x.PersonId, x.PersonName, x.CardNo, x.IdentityCard, x.Sex, x.SexName, x.UnitId, x.UnitName, x.WorkPostId, x.WorkPostName, x.ProjectId, ProjectName = db.Base_Project.First(u => u.ProjectId == x.ProjectId).ProjectName, ShortName = db.Base_Project.First(u => u.ProjectId == x.ProjectId).ShortName, NativePlace = x.CountryName ?? "" + x.ProvinceName ?? "", x.TeamGroupId, x.TeamGroupName, x.InTime, x.OutTime, x.IsUsed, OutName = (x.IsUsed == false ? "是" : "否"), }; } /// /// 七化建 /// /// /// /// /// /// /// /// /// /// /// public static IEnumerable getListData(string companyId, string departId, string projetcId, string unitId, string postId, string name, string idCard, string isPost, Grid Grid1) { IQueryable getDataList = getDataLists.OrderBy(x => x.UnitId).ThenBy(x => x.DepartId); if (!string.IsNullOrEmpty(projetcId) && projetcId != Const._Null) { getDataList = getDataList.Where(e => e.ProjectId == projetcId); if (!string.IsNullOrEmpty(unitId) && unitId != Const._Null) { getDataList = getDataList.Where(e => e.UnitId == unitId); } } else { if (!string.IsNullOrEmpty(companyId) && companyId != Const._Null) { getDataList = getDataList.Where(e => e.UnitId == companyId && e.ProjectId == null); } if (!string.IsNullOrEmpty(departId) && departId != Const._Null) { getDataList = getDataList.Where(e => e.DepartId == departId); } } if (!string.IsNullOrEmpty(postId) && postId != Const._Null) { getDataList = getDataList.Where(e => e.WorkPostId == postId); } if (!string.IsNullOrEmpty(name)) { getDataList = getDataList.Where(e => e.PersonName.Contains(name)); } if (!string.IsNullOrEmpty(idCard)) { getDataList = getDataList.Where(e => e.IdentityCard.Contains(idCard)); } if (isPost == "1") { getDataList = getDataList.Where(e => e.OutTime != null); } if (isPost == "0") { getDataList = getDataList.Where(e => e.OutTime == null); } count = getDataList.Count(); if (count == 0) { return null; } getDataList = SortConditionHelper.SortingAndPaging(getDataList, Grid1.SortField, Grid1.SortDirection, Grid1.PageIndex, Grid1.PageSize); return from x in getDataList select new { x.PersonId, x.PersonName, x.CardNo, x.IdentityCard, Sex = x.Sex ?? "1", x.Birthday, x.UnitId, db.Base_Unit.First(u => u.UnitId == x.UnitId).UnitName, x.DepartId, db.Base_Depart.First(u => u.DepartId == x.DepartId).DepartName, x.WorkPostId, WorkPostName = WorkPostService.getWorkPostNamesWorkPostIds(x.WorkPostId), x.ProjectId, ProjectName = db.Base_Project.First(u => u.ProjectId == x.ProjectId).ShortName, x.InTime, x.OutTime, x.AuditorDate, x.AuditorId, }; } #endregion /// /// 根据主键获取人员信息 /// /// /// public static Model.SitePerson_Person GetPersonById(string personId) { return Funs.DB.SitePerson_Person.FirstOrDefault(e => e.PersonId == personId); } /// /// 根据主键获取人员信息 /// /// /// public static string GetPersonNameById(string personId) { string name = string.Empty; var getp = Funs.DB.SitePerson_Person.FirstOrDefault(e => e.PersonId == personId); if (getp != null) { name = getp.PersonName; } return name; } /// /// 根据UserId主键获取人员信息 /// /// /// public static string GetPersonIdByUserId(string userId) { string personId = userId; var getPerson = GetPersonById(userId); if (getPerson == null) { var getUser = UserService.GetUserByUserId(userId); if (getUser != null) { getPerson = Funs.DB.SitePerson_Person.FirstOrDefault(e => e.IdentityCard == getUser.IdentityCard); if (getPerson != null) { personId = getPerson.PersonId; } } } return personId; } /// /// 根据UserId主键获取人员信息 /// /// /// public static Model.SitePerson_Person GetPersonByUserId(string userId, string projectId, string unitId = "") { var getPerson = GetPersonById(userId); if (getPerson == null) { var getUser = UserService.GetUserByUserId(userId); if (getUser != null) { if (string.IsNullOrEmpty(unitId)) { getPerson = Funs.DB.SitePerson_Person.FirstOrDefault(e => e.IdentityCard == getUser.IdentityCard && e.ProjectId == projectId); } else { getPerson = Funs.DB.SitePerson_Person.FirstOrDefault(e => e.IdentityCard == getUser.IdentityCard && e.UnitId == unitId); } } } return getPerson; } /// /// 根据项目单位获取人员信息 /// /// /// public static List GetPersonLitsByprojectIdUnitId(string projectId, string unitId) { if (!string.IsNullOrEmpty(unitId)) { return (from x in Funs.DB.SitePerson_Person where x.ProjectId == projectId && x.UnitId == unitId orderby x.PersonName select x).ToList(); } else { return (from x in Funs.DB.SitePerson_Person where x.ProjectId == projectId orderby x.PersonName select x).ToList(); } } /// /// 根据项目单位获取人员信息 /// /// /// public static List GetPersonLitsByprojectIdUnitIdTeamGroupId(string projectId, string unitId, string teamGroupId) { var getPersons = GetPersonLitsByprojectIdUnitId(projectId, unitId); if (!string.IsNullOrEmpty(teamGroupId)) { getPersons = getPersons.Where(x => x.TeamGroupId == teamGroupId).OrderBy(x => x.PersonName).ToList(); } return getPersons; } /// /// 获取最大的人员位置 /// /// 最大的人员位置 public static int? GetMaxPersonIndex(string projectId) { return (from x in Funs.DB.SitePerson_Person where x.ProjectId == projectId select x.PersonIndex).Max(); } /// /// 根据单位Id查询所有人员的数量 /// /// 单位Id /// 人员的数量 public static int GetPersonCountByUnitId(string unitId, string projectId) { var q = (from x in Funs.DB.SitePerson_Person where x.UnitId == unitId && x.ProjectId == projectId && x.IsUsed == true select x).ToList(); return q.Count(); } /// /// 根据单位Id查询所有HSE人员的数量 /// /// 单位Id /// HSE人员的数量 public static int GetHSEPersonCountByUnitId(string unitId, string projectId) { var q = (from x in Funs.DB.SitePerson_Person where x.UnitId == unitId && x.ProjectId == projectId && (x.WorkPostId == BLL.Const.WorkPost_HSSEEngineer || x.WorkPostId == BLL.Const.WorkPost_SafetyManager) && x.IsUsed == true select x).ToList(); return q.Count(); } /// /// 获取所有人员位置集合 /// /// 所有人员位置集合 public static List GetPersonIndexs(string projectId) { return (from x in Funs.DB.SitePerson_Person where x.ProjectId == projectId select x.PersonIndex).ToList(); } /// /// 根据卡号查询人员信息 /// /// 卡号 /// 人员实体 public static Model.SitePerson_Person GetPersonByCardNo(string projectId, string cardNo) { return Funs.DB.SitePerson_Person.FirstOrDefault(e => e.ProjectId == projectId && e.CardNo == cardNo); } /// /// 根据卡号查询所有人员的数量 /// /// 卡号 /// 人员的数量 public static int GetPersonCountByCardNo(string projectId, string cardNo) { var q = (from x in Funs.DB.SitePerson_Person where x.ProjectId == projectId && x.CardNo == cardNo select x).ToList(); return q.Count(); } /// /// 根据人员姓名和所在单位判断人员是否存在 /// /// /// /// public static bool IsExistPersonByUnit(string unitId, string personName, string projectId) { var q = from x in Funs.DB.SitePerson_Person where x.UnitId == unitId && x.PersonName == personName && x.ProjectId == projectId select x; if (q.Count() > 0) { return true; } else { return false; } } /// /// 根据身份证号Id获取人员的数量 /// /// 身份证号 /// 人员的数量 public static Model.SitePerson_Person GetPersonCountByIdentityCard(string identityCard, string projectId) { var q = Funs.DB.SitePerson_Person.FirstOrDefault(x => x.IdentityCard == identityCard && x.ProjectId == projectId); return q; } /// /// 获取人员信息列表 /// /// /// public static List GetPersonList(string projectId) { return (from x in Funs.DB.SitePerson_Person where x.ProjectId == projectId select x).ToList(); } /// /// 增加人员信息 /// /// 人员实体 public static void AddPerson(Model.SitePerson_Person person) { using (Model.SUBQHSEDB db = new Model.SUBQHSEDB(Funs.ConnString)) { Model.SitePerson_Person newPerson = new Model.SitePerson_Person { PersonId = person.PersonId, CardNo = person.CardNo, PersonName = person.PersonName, Sex = person.Sex, IdentityCard = person.IdentityCard, Address = person.Address, ProjectId = person.ProjectId, UnitId = person.UnitId, TeamGroupId = person.TeamGroupId, WorkAreaId = person.WorkAreaId, WorkPostId = person.WorkPostId, OutTime = person.OutTime, OutResult = person.OutResult, Telephone = person.Telephone, PositionId = person.PositionId, PostTitleId = person.PostTitleId, PhotoUrl = person.PhotoUrl, HeadImage = person.HeadImage, IsUsed = person.IsUsed, IsCardUsed = person.IsCardUsed, DepartId = person.DepartId, FromPersonId = person.FromPersonId, Password = GetPersonPassWord(person.IdentityCard), AuditorId = person.AuditorId, AuditorDate = person.AuditorDate, IsForeign = person.IsForeign, IsOutside = person.IsOutside, EduLevel = person.EduLevel, MaritalStatus = person.MaritalStatus, Isprint = "0", MainCNProfessionalId = person.MainCNProfessionalId, ViceCNProfessionalId = person.ViceCNProfessionalId, Birthday = person.Birthday, IdcardType = person.IdcardType, IdcardStartDate = person.IdcardStartDate, IdcardEndDate = person.IdcardEndDate, IdcardForever = person.IdcardForever, PoliticsStatus = person.PoliticsStatus, IdcardAddress = person.IdcardAddress, Nation = person.Nation, CountryCode = person.CountryCode, ProvinceCode = person.ProvinceCode, IsSafetyMonitoring = person.IsSafetyMonitoring, IsCardNoOK = IDCardValid.CheckIDCard(person.IdentityCard), WorkingYears = person.WorkingYears, SafeWorkingYears = person.SafeWorkingYears, Major = person.Major, Languages = person.Languages, PersonStates = person.PersonStates, IsUsedType = person.IsUsedType, }; if (person.InTime.HasValue) { newPerson.InTime = person.InTime; } else { newPerson.InTime = Funs.GetNewDateTime(DateTime.Now.ToShortDateString()); } db.SitePerson_Person.InsertOnSubmit(newPerson); db.SubmitChanges(); ////增加一条编码记录 BLL.CodeRecordsService.InsertCodeRecordsByMenuIdProjectIdUnitId(BLL.Const.PersonListMenuId, person.ProjectId, person.UnitId, person.PersonId, person.InTime); // Project_HSSEData_HSSEService.StatisticalData(newPerson.ProjectId, Project_HSSEData_HSSEService.HSSEDateType.ProjectInformation); //Project_HSSEData_HSSEService.StatisticalData(newPerson.ProjectId, Project_HSSEData_HSSEService.HSSEDateType.OfSafetySupervisors); // Project_CQMSDataService.StatisticalData(newPerson.ProjectId, Project_CQMSDataService.CQMSDateType.ManagerData); } } /// /// 修改人员信息 /// /// 人员实体 public static void UpdatePerson(Model.SitePerson_Person person) { using (Model.SUBQHSEDB db = new Model.SUBQHSEDB(Funs.ConnString)) { Model.SitePerson_Person newPerson = db.SitePerson_Person.FirstOrDefault(e => e.PersonId == person.PersonId); if (newPerson != null) { newPerson.FromPersonId = person.FromPersonId; newPerson.CardNo = person.CardNo; newPerson.PersonName = person.PersonName; newPerson.Sex = person.Sex; if (newPerson.IdentityCard != person.IdentityCard) { PersonInOutService.UpdateRealNameInOut(newPerson.PersonId, newPerson.IdentityCard, person.IdentityCard); newPerson.IdentityCard = person.IdentityCard; newPerson.IsCardNoOK = IDCardValid.CheckIDCard(person.IdentityCard); } newPerson.Address = person.Address; newPerson.ProjectId = person.ProjectId; newPerson.UnitId = person.UnitId; newPerson.TeamGroupId = person.TeamGroupId; newPerson.WorkAreaId = person.WorkAreaId; newPerson.WorkPostId = person.WorkPostId; newPerson.InTime = person.InTime; newPerson.OutTime = person.OutTime; newPerson.OutResult = person.OutResult; newPerson.Telephone = person.Telephone; newPerson.PositionId = person.PositionId; newPerson.PostTitleId = person.PostTitleId; newPerson.PhotoUrl = person.PhotoUrl; newPerson.HeadImage = person.HeadImage; newPerson.IsUsed = person.IsUsed; newPerson.IsCardUsed = person.IsCardUsed; newPerson.EduLevel = person.EduLevel; newPerson.MaritalStatus = person.MaritalStatus; newPerson.DepartId = person.DepartId; newPerson.QRCodeAttachUrl = person.QRCodeAttachUrl; newPerson.IsUsedType = person.IsUsedType; newPerson.Password = GetPersonPassWord(person.IdentityCard); if (!newPerson.OutTime.HasValue) { newPerson.OutTime = null; newPerson.ExchangeTime = null; } newPerson.ExchangeTime2 = null; newPerson.RealNameUpdateTime = null; if (!string.IsNullOrEmpty(person.AuditorId)) { newPerson.AuditorId = person.AuditorId; } if (person.AuditorDate.HasValue) { newPerson.AuditorDate = person.AuditorDate; } newPerson.IsForeign = person.IsForeign; newPerson.IsOutside = person.IsOutside; newPerson.Birthday = person.Birthday; newPerson.MainCNProfessionalId = person.MainCNProfessionalId; newPerson.ViceCNProfessionalId = person.ViceCNProfessionalId; newPerson.IdcardType = person.IdcardType; newPerson.IdcardStartDate = person.IdcardStartDate; newPerson.IdcardEndDate = person.IdcardEndDate; newPerson.IdcardForever = person.IdcardForever; newPerson.PoliticsStatus = person.PoliticsStatus; newPerson.IdcardAddress = person.IdcardAddress; newPerson.Nation = person.Nation; newPerson.CountryCode = person.CountryCode; newPerson.ProvinceCode = person.ProvinceCode; newPerson.IsSafetyMonitoring = person.IsSafetyMonitoring; newPerson.WorkingYears = person.WorkingYears; newPerson.SafeWorkingYears = person.SafeWorkingYears; newPerson.Major = person.Major; newPerson.Languages = person.Languages; newPerson.PersonStates = person.PersonStates; db.SubmitChanges(); //Project_HSSEData_HSSEService.StatisticalData(newPerson.ProjectId, Project_HSSEData_HSSEService.HSSEDateType.ProjectInformation); //Project_HSSEData_HSSEService.StatisticalData(newPerson.ProjectId, Project_HSSEData_HSSEService.HSSEDateType.OfSafetySupervisors); //Project_CQMSDataService.StatisticalData(newPerson.ProjectId, Project_CQMSDataService.CQMSDateType.ManagerData); } } } /// /// 人员离岗 /// /// public static void PersonOut(string personId, DateTime date) { using (Model.SUBQHSEDB db = new Model.SUBQHSEDB(Funs.ConnString)) { var person = db.SitePerson_Person.FirstOrDefault(x => x.PersonId == personId); if (person != null) { person.OutTime = date; person.IsUsed = true; person.ExchangeTime = null; person.ExchangeTime2 = null; person.RealNameUpdateTime = null; db.SubmitChanges(); } } } /// /// 根据人员Id删除一个人员信息 /// /// 人员Id public static void DeletePerson(string personId) { Model.SitePerson_Person person = Funs.DB.SitePerson_Person.FirstOrDefault(e => e.PersonId == personId); if (person != null) { string projectId = person.ProjectId; ///删除编码表记录 BLL.CodeRecordsService.DeleteCodeRecordsByDataId(personId); //删除特岗人员资质 var personQuality = PersonQualityService.GetPersonQualityByPersonId(personId); if (personQuality != null) { CodeRecordsService.DeleteCodeRecordsByDataId(personQuality.PersonQualityId);//删除编号 CommonService.DeleteAttachFileById(personQuality.PersonQualityId);//删除附件 Funs.DB.QualityAudit_PersonQuality.DeleteOnSubmit(personQuality); Funs.DB.SubmitChanges(); } //删除安全人员资质 Model.QualityAudit_SafePersonQuality safePersonQuality = Funs.DB.QualityAudit_SafePersonQuality.FirstOrDefault(e => e.PersonId == personId); if (safePersonQuality != null) { CodeRecordsService.DeleteCodeRecordsByDataId(safePersonQuality.SafePersonQualityId); CommonService.DeleteAttachFileById(safePersonQuality.SafePersonQualityId); Funs.DB.QualityAudit_SafePersonQuality.DeleteOnSubmit(safePersonQuality); Funs.DB.SubmitChanges(); } ///违规人员 var getViolation = from x in Funs.DB.Check_ViolationPerson where x.PersonId == person.PersonId select x; if (getViolation.Count() > 0) { Funs.DB.Check_ViolationPerson.DeleteAllOnSubmit(getViolation); Funs.DB.SubmitChanges(); } ///删除考试记录 var getTask = from x in Funs.DB.Training_Task where x.UserId == person.PersonId select x; if (getTask.Count() > 0) { foreach (var item in getTask) { TrainingTaskService.DeleteTaskById(item.TaskId); } } ///删除考试记录 var getTestRecode = from x in Funs.DB.Training_TestRecord where x.TestManId == person.PersonId select x; if (getTestRecode.Count() > 0) { foreach (var item in getTestRecode) { TestRecordService.DeleteTestRecordByTestRecordId(item.TestRecordId); } } ///删除人员绩效 var getPerfomances = from x in Funs.DB.Perfomance_PersonPerfomance where x.PersonId == person.PersonId select x; if (getPerfomances.Count() > 0) { foreach (var item in getPerfomances) { PersonPerfomanceService.DeletePersonPerfomanceById(item.PersonPerfomanceId); } } ///删除人员出入场记录 BLL.PersonInOutService.DeletePersonInOutByPersonId(person.PersonId); BLL.SitePerson_CheckingService.DeletePersonInfoByPersonId(person.PersonId); ///删除编码表记录 BLL.CodeRecordsService.DeleteCodeRecordsByDataId(personId); Funs.DB.SitePerson_Person.DeleteOnSubmit(person); Funs.DB.SubmitChanges(); //Project_HSSEData_HSSEService.StatisticalData(projectId, Project_HSSEData_HSSEService.HSSEDateType.ProjectInformation); //Project_HSSEData_HSSEService.StatisticalData(projectId, Project_HSSEData_HSSEService.HSSEDateType.OfSafetySupervisors); } } /// /// 根据身份证号获取人员信息 /// /// 身份证号 /// 人员信息 public static Model.SitePerson_Person GetPersonByIdentityCard(string projectId, string identityCard) { if (!string.IsNullOrEmpty(identityCard)) { return Funs.DB.SitePerson_Person.FirstOrDefault(e => e.ProjectId == projectId && e.IdentityCard == identityCard); } else { return null; } } /// /// 根据身份证号获取人员信息 /// /// 姓名 /// 人员信息 public static Model.SitePerson_Person GetPersonByName(string projectId, string name) { if (!string.IsNullOrEmpty(name)) { return Funs.DB.SitePerson_Person.FirstOrDefault(e => e.ProjectId == projectId && e.PersonName == name); } else { return null; } } /// /// 保存发卡信息 /// /// /// public static void SaveSendCard(string personId, string cardNo, int personIndex) { using (Model.SUBQHSEDB db = new Model.SUBQHSEDB(Funs.ConnString)) { Model.SitePerson_Person card = db.SitePerson_Person.FirstOrDefault(e => e.CardNo == cardNo); if (card != null) { card.CardNo = null; } else { Model.SitePerson_Person person = db.SitePerson_Person.FirstOrDefault(e => e.PersonId == personId); person.CardNo = cardNo; person.PersonIndex = personIndex; //person.CardNo = sendCardNo; } db.SubmitChanges(); } } /// /// 根据作业区域获取人员 /// /// /// public static List GetPersonListByWorkAreaId(string workAreaId) { return (from x in Funs.DB.SitePerson_Person where x.WorkAreaId == workAreaId select x).ToList(); } #region 表下拉框 /// /// 表下拉框 /// /// 下拉框名字 /// 是否显示请选择 public static void InitPersonByProjectUnitDropDownList(FineUIPro.DropDownList dropName, string projectId, string unitId, bool isShowPlease) { dropName.DataValueField = "PersonId"; dropName.DataTextField = "PersonName"; dropName.DataSource = GetPersonLitsByprojectIdUnitId(projectId, unitId); dropName.DataBind(); if (isShowPlease) { Funs.FineUIPleaseSelect(dropName); } } /// /// 表下拉框 /// /// 下拉框名字 /// 是否显示请选择 public static void InitPersonByProjectUnitTeamGroupDropDownList(FineUIPro.DropDownList dropName, string projectId, string unitId, string teamGroupId, bool isShowPlease) { dropName.DataValueField = "PersonId"; dropName.DataTextField = "PersonName"; dropName.DataSource = GetPersonLitsByprojectIdUnitIdTeamGroupId(projectId, unitId, teamGroupId); dropName.DataBind(); if (isShowPlease) { Funs.FineUIPleaseSelect(dropName); } } #endregion /// /// 获取人员密码 /// /// /// public static string GetPersonPassWord(string idCard) { string passWord = Funs.EncryptionPassword(Const.Password); ////现场人员密码 if (!string.IsNullOrEmpty(idCard)) { if (idCard.Length > 3) { passWord = Funs.EncryptionPassword(idCard.Substring(idCard.Length - 4)); } else { passWord = Funs.EncryptionPassword(idCard); } } return passWord; } #region 在岗人员列表 /// /// 记录数 /// public static int inCount { get; set; } /// /// 定义变量 /// private static IQueryable getInPersonLists = from x in db.SitePerson_Person where x.IsUsed == true && x.InTime <= DateTime.Now && (!x.OutTime.HasValue || x.OutTime > DateTime.Now) select x; /// /// 获取分页列表 /// /// 页码 /// 每页数量 /// public static IEnumerable getInPsersonListData(string projectId, string unitId, string personName, string identityCard, Grid Grid1) { IQueryable getInPersonList = getInPersonLists.Where(x => x.ProjectId == projectId); if (!string.IsNullOrEmpty(unitId) && unitId != Const._Null) { if (unitId == "0") { getInPersonList = getInPersonList.Where(x => x.UnitId == null); } else { getInPersonList = getInPersonList.Where(x => x.UnitId == unitId); } } if (!string.IsNullOrEmpty(personName)) { getInPersonList = getInPersonList.Where(x => x.PersonName.Contains(personName)); } if (!string.IsNullOrEmpty(identityCard)) { getInPersonList = getInPersonList.Where(x => x.IdentityCard.Contains(identityCard)); } inCount = getInPersonList.Count(); if (inCount == 0) { return null; } getInPersonList = SortConditionHelper.SortingAndPaging(getInPersonList, Grid1.SortField, Grid1.SortDirection, Grid1.PageIndex, Grid1.PageSize); return from x in getInPersonList select new { x.PersonId, x.CardNo, x.PersonName, x.UnitId, db.Base_Unit.First(u => u.UnitId == x.UnitId).UnitName, x.IdentityCard, IsInName = "", InOuDate = DateTime.Now.ToShortDateString(), InOutTime = "00:00:00", }; } #endregion public static void AddPersonByPersonItem(Model.PersonItem person) { var getProject = ProjectService.GetProjectByProjectCode(person.ProjectCode); if (getProject == null) return; var getUnit = UnitService.getUnitByCollCropCodeUnitName(person.CollCropCode, person.UnitName); if (getUnit == null) return; var getPerson = PersonService.GetPersonByIdentityCard(getProject.ProjectId, person.IdentityCard); if (getPerson != null) return; Model.SitePerson_Person newPerson = new Model.SitePerson_Person { PersonId = SQLHelper.GetNewID(), ProjectId = getProject.ProjectId, UnitId = getUnit.UnitId, PersonName = person.PersonName, IdentityCard = person.IdentityCard, IdcardType = "SHENFEN_ZHENGJIAN", IdcardAddress = person.IdcardAddress, IdcardForever = "N", IdcardStartDate = Funs.GetNewDateTime(person.IdcardStartDate), IdcardEndDate = Funs.GetNewDateTime(person.IdcardEndDate), Sex = (person.Sex == "女" || person.Sex == "2") ? "2" : "1", Address = person.Address, OutResult = person.OutResult, Birthday = person.Birthday, Telephone = person.Telephone, IsUsed = person.IsUsed == false ? false : true, InTime = Funs.GetNewDateTimeOrNow(person.InTime), Password = BLL.PersonService.GetPersonPassWord(person.IdentityCard), Isprint = "0", }; if (!string.IsNullOrEmpty(person.TeamGroupName) && !string.IsNullOrEmpty(newPerson.UnitId)) { var getTeamGroup = TeamGroupService.getTeamGroupByTeamGroupName(getProject.ProjectId, newPerson.UnitId, person.TeamGroupName); if (getTeamGroup != null) { newPerson.TeamGroupId = getTeamGroup.TeamGroupId; } else { Model.ProjectData_TeamGroup newTeamGroup = new Model.ProjectData_TeamGroup { TeamGroupId = SQLHelper.GetNewID(), ProjectId = getProject.ProjectId, UnitId = newPerson.UnitId, TeamGroupName = person.TeamGroupName, Remark = "来源:门禁对接数据", TeamTypeId = "CANJIAN_TEAM", EntryTime = System.DateTime.Now, RealNamePushTime = null, }; db.ProjectData_TeamGroup.InsertOnSubmit(newTeamGroup); db.SubmitChanges(); newPerson.TeamGroupId = newTeamGroup.TeamGroupId; } } var getWorkArea = UnitWorkService.GetUnitWorkByUnitWorkName(getProject.ProjectId, person.WorkAreaName); if (getWorkArea != null) { newPerson.WorkAreaId = getWorkArea.UnitWorkId; } var getWorkPost = WorkPostService.GetWorkPostByName(person.WorkPostName); if (getWorkPost != null) { newPerson.WorkPostId = getWorkPost.WorkPostId; } var getHsseMan = ProjectService.getHSSEManager(getProject.ProjectId); if (getHsseMan != null) { newPerson.AuditorId = getHsseMan.UserId; newPerson.AuditorDate = DateTime.Now; } newPerson.OutTime = Funs.GetNewDateTime(person.OutTime); if (person.headImage != null) { var image = Convert.FromBase64String(person.headImage); newPerson.HeadImage = image; string rootPath = ConfigurationManager.AppSettings["localRoot"]; string path = "FileUpLoad/PersonBaseInfo/" + DateTime.Now.ToString("yyyy-MM") + "/"; string fileUrl = (rootPath + path).Replace('/', '\\'); string flieName = Funs.GetNewFileName() + "~" + person.PersonName + ".jpg"; if (!Directory.Exists(fileUrl)) { Directory.CreateDirectory(fileUrl); } newPerson.PhotoUrl = path + flieName; System.IO.File.WriteAllBytes((fileUrl + flieName), image); } AddPerson(newPerson); } public static void UpdatePersonByPersonItem(Model.PersonItem person) { var getProject = ProjectService.GetProjectByProjectCode(person.ProjectCode); if (getProject == null) return; var getUnit = UnitService.getUnitByCollCropCodeUnitName(person.CollCropCode, person.UnitName); if (getUnit == null) return; var getPerson = PersonService.GetPersonByIdentityCard(getProject.ProjectId, person.IdentityCard); if (getPerson == null) return; getPerson.UnitId = getUnit.UnitId; getPerson.PersonName = person.PersonName; getPerson.IdentityCard = person.IdentityCard; getPerson.IdcardType = "SHENFEN_ZHENGJIAN"; getPerson.IdcardAddress = person.IdcardAddress; getPerson.IdcardForever = "N"; getPerson.IdcardStartDate = Funs.GetNewDateTime(person.IdcardStartDate); getPerson.IdcardEndDate = Funs.GetNewDateTime(person.IdcardEndDate); getPerson.Sex = (person.Sex == "女" || person.Sex == "2") ? "2" : "1"; getPerson.Address = person.Address; getPerson.OutResult = person.OutResult; getPerson.Birthday = person.Birthday; getPerson.Telephone = person.Telephone; getPerson.IsUsed = person.IsUsed == false ? false : true; getPerson.InTime = Funs.GetNewDateTimeOrNow(person.InTime); getPerson.Password = BLL.PersonService.GetPersonPassWord(person.IdentityCard); getPerson.Isprint = "0"; getPerson.ProjectId = getProject.ProjectId; getPerson.PersonId = SQLHelper.GetNewID(); if (!string.IsNullOrEmpty(person.TeamGroupName) && !string.IsNullOrEmpty(getPerson.UnitId)) { var getTeamGroup = TeamGroupService.getTeamGroupByTeamGroupName(getProject.ProjectId, getPerson.UnitId, person.TeamGroupName); if (getTeamGroup != null) { getPerson.TeamGroupId = getTeamGroup.TeamGroupId; } else { Model.ProjectData_TeamGroup newTeamGroup = new Model.ProjectData_TeamGroup { TeamGroupId = SQLHelper.GetNewID(), ProjectId = getProject.ProjectId, UnitId = getPerson.UnitId, TeamGroupName = person.TeamGroupName, Remark = "来源:门禁对接数据", TeamTypeId = "CANJIAN_TEAM", EntryTime = System.DateTime.Now, RealNamePushTime = null, }; db.ProjectData_TeamGroup.InsertOnSubmit(newTeamGroup); db.SubmitChanges(); getPerson.TeamGroupId = newTeamGroup.TeamGroupId; } } var getWorkArea = UnitWorkService.GetUnitWorkByUnitWorkName(getProject.ProjectId, person.WorkAreaName); if (getWorkArea != null) { getPerson.WorkAreaId = getWorkArea.UnitWorkId; } var getWorkPost = WorkPostService.GetWorkPostByName(person.WorkPostName); if (getWorkPost != null) { getPerson.WorkPostId = getWorkPost.WorkPostId; } var getHsseMan = ProjectService.getHSSEManager(getProject.ProjectId); if (getHsseMan != null) { getPerson.AuditorId = getHsseMan.UserId; getPerson.AuditorDate = DateTime.Now; } getPerson.OutTime = Funs.GetNewDateTime(person.OutTime); if (person.headImage != null) { var image = Convert.FromBase64String(person.headImage); getPerson.HeadImage = image; string rootPath = ConfigurationManager.AppSettings["localRoot"]; string path = "FileUpLoad/PersonBaseInfo/" + DateTime.Now.ToString("yyyy-MM") + "/"; string fileUrl = (rootPath + path).Replace('/', '\\'); string flieName = Funs.GetNewFileName() + "~" + person.PersonName + ".jpg"; if (!Directory.Exists(fileUrl)) { Directory.CreateDirectory(fileUrl); } getPerson.PhotoUrl = path + flieName; System.IO.File.WriteAllBytes((fileUrl + flieName), image); } UpdatePerson(getPerson); if (!string.IsNullOrEmpty(person.OutTime)) { var outTime = Funs.GetNewDateTimeOrNow(person.OutTime); PersonService.PersonOut(getPerson.PersonId, outTime); } } /// /// 添加群安员信息至用户表 /// /// public static void AddSafetyOfficerInUser(Model.PersonItem person) { using (Model.SUBQHSEDB db = new Model.SUBQHSEDB(Funs.ConnString)) { var RawPassword = UserService.getInitialPassword(person.UnitId, person.IdentityCard); var Password = Funs.EncryptionPassword(RawPassword); Model.Sys_User newUser = new Model.Sys_User { UserId = SQLHelper.GetNewID(), Account = Funs.DeleteSpace(person.PersonName), UserName = Funs.DeleteSpace(person.PersonName), //UserCode = user.UserCode, Password = Password, RawPassword = Password, UnitId = person.UnitId, //RoleId = person.RoleId, //IsPost = user.IsPost, IdentityCard = person.IdentityCard, PageSize = 10, //IsOffice = person.IsOffice, Telephone = person.Telephone, //DataSources = person.DataSources, //SignatureUrl = person.SignatureUrl, //DepartId = person.DepartId, //Politicalstatus = person.Politicalstatus, //Hometown = user.Hometown, //Education = user.Education, //Graduate = user.Graduate, //Major = user.Major, //CertificateId = user.CertificateId, //IntoDate = user.IntoDate, //ValidityDate = user.ValidityDate, Sex = person.Sex, //BirthDay = person.BirthDay, //PositionId = person.PositionId, //PostTitleId = person.PostTitleId, WorkPostId = person.WorkPostId, MainCNProfessionalId = person.MainCNProfessionalId, ViceCNProfessionalId = person.ViceCNProfessionalId, //WorkNo = person.WorkNo, }; db.Sys_User.InsertOnSubmit(newUser); db.SubmitChanges(); } } #region 培训人员下拉框 /// /// 表下拉框 /// /// 下拉框名字 /// 是否显示请选择 public static void InitTrainingPersonDropDownList(FineUIPro.DropDownList dropName, string projectId, string unitId, string departId, string workPostId, string trainTypeId, bool isShowPlease) { dropName.DataValueField = "PersonId"; dropName.DataTextField = "PersonName"; dropName.DataSource = APIPersonService.getTrainingPersonListByTrainTypeId2(projectId, unitId, departId, workPostId, trainTypeId, null); dropName.DataBind(); if (isShowPlease) { Funs.FineUIPleaseSelect(dropName); } } #endregion /// /// 根据UserId主键获取人员信息 /// /// /// public static Model.SitePerson_Person GetPersonByProjectIdUserId(string projectId, string userId) { var getPerson = GetPersonById(userId); if (getPerson == null) { var getUser = UserService.GetUserByUserId(userId); if (getUser != null) { getPerson = Funs.DB.SitePerson_Person.FirstOrDefault(e => e.IdentityCard == getUser.IdentityCard && (e.ProjectId == projectId || (projectId == null && e.ProjectId == null))); } } return getPerson; } /// /// 根据UserId主键获取人员信息 /// /// /// public static string GetPersonIdByProjectIdUserId(string projectId, string userId) { string personId = string.Empty; var getPerson = GetPersonById(userId); if (getPerson == null) { var getUser = UserService.GetUserByUserId(userId); if (getUser != null) { getPerson = Funs.DB.SitePerson_Person.FirstOrDefault(e => e.IdentityCard == getUser.IdentityCard && (e.ProjectId == projectId || (projectId == null && e.ProjectId == null))); if (getPerson != null) { personId = getPerson.PersonId; } } } else { personId = getPerson.PersonId; } return personId; } public static string GetPersonIdByUserIdForApi(string userId) { using (Model.SUBQHSEDB db = new Model.SUBQHSEDB(Funs.ConnString)) { string personId = userId; var getPerson = db.SitePerson_Person.FirstOrDefault(e => e.PersonId == userId); if (getPerson == null) { var getUser = db.Sys_User.FirstOrDefault(e => e.UserId == userId); if (getUser != null) { getPerson = db.SitePerson_Person.FirstOrDefault(e => e.IdentityCard == getUser.IdentityCard); if (getPerson != null) { personId = getPerson.PersonId; } } } return personId; } } } }