Exemple #1
0
        //更新雇员加入系统用户
        public void EmployeeUpdateToUser(S_HR_Employee employee)
        {
            S_A_User user = baseEntities.Set <S_A_User>().Where(t => t.ID == employee.UserID).FirstOrDefault();

            user.WorkNo    = employee.Code;
            user.Code      = employee.Code;
            user.Name      = employee.Name;
            user.IsDeleted = employee.IsDeleted;

            if (employee.Address != null)
            {
                user.Address = employee.Address;
            }
            if (employee.Email != null)
            {
                user.Email = employee.Email;
            }
            if (employee.OfficePhone != null)
            {
                user.Phone = employee.OfficePhone;
            }
            if (employee.MobilePhone != null)
            {
                user.MobilePhone = employee.MobilePhone;
            }


            //修改用户图片
            S_A_UserImg        userImg     = null;
            List <S_A_UserImg> userImgList = baseEntities.Set <S_A_UserImg>().Where(c => c.UserID == user.ID).ToList();

            if (userImgList.Count > 0)
            {
                userImg = userImgList.FirstOrDefault();
            }
            else
            {
                userImg = new S_A_UserImg()
                {
                    ID     = FormulaHelper.CreateGuid(),
                    UserID = user.ID
                };
                baseEntities.Set <S_A_UserImg>().Add(userImg);
            }

            if (employee.Portrait != null)
            {
                userImg.Picture = employee.Portrait;
            }
            if (employee.SignImage != null)
            {
                userImg.SignImg = employee.SignImage;
            }

            SyncUserDeptByEmployee(employee, user);

            baseEntities.SaveChanges();
        }
Exemple #2
0
        /// <summary>
        /// 同步删除的人员到系统用户表
        /// </summary>
        /// <param name="employee"></param>
        public void EmployeeDeleteToUser(S_HR_Employee employee)
        {
            S_A_User user = baseEntities.Set <S_A_User>().Where(t => t.ID == employee.UserID).FirstOrDefault();

            if (user != null)
            {
                user.DeleteTime = DateTime.Now;
                user.IsDeleted  = "1";
                var retiredList = entities.Set <S_HR_EmployeeRetired>().Where(c => c.EmployeeID == employee.ID).OrderBy("RetiredDate", false);
                if (retiredList.Count() > 0)
                {
                    user.OutDate = retiredList.FirstOrDefault().RetiredDate;
                }
                baseEntities.SaveChanges();
            }
        }
Exemple #3
0
        //新添雇员加入系统用户
        public void EmployeeAddToUser(S_HR_Employee employee, string Password)
        {
            if (employee == null || employee.IsDeleted == "1")
            {
                return;
            }
            BaseEntities baseEntities = FormulaHelper.GetEntities <BaseEntities>();
            //添加新用户
            S_A_User user = new S_A_User()
            {
                ID          = FormulaHelper.CreateGuid(),
                Code        = employee.Code,
                Name        = employee.Name,
                WorkNo      = employee.Code,
                Address     = employee.Address,
                Email       = employee.Email,
                Password    = Password,
                Sex         = employee.Sex,
                InDate      = employee.JoinCompanyDate,
                Phone       = employee.OfficePhone,
                MobilePhone = employee.MobilePhone,
                IsDeleted   = "0"
            };

            baseEntities.Set <S_A_User>().Add(user);

            //反写userID
            employee.UserID = user.ID;

            //添加用户图片
            S_A_UserImg userImg = new S_A_UserImg()
            {
                ID      = FormulaHelper.CreateGuid(),
                UserID  = user.ID,
                Picture = employee.Portrait,
                SignImg = employee.SignImage
            };

            baseEntities.Set <S_A_UserImg>().Add(userImg);

            SyncUserDeptByEmployee(employee, user);

            entities.SaveChanges();
            baseEntities.SaveChanges();
        }
Exemple #4
0
        /// <summary>
        /// 同步删除的人员到系统用户表
        /// </summary>
        /// <param name="employee"></param>
        public void EmployeeDeleteToUser(T_Employee employee)
        {
            HREntities   entities     = FormulaHelper.GetEntities <HREntities>();
            BaseEntities baseEntities = FormulaHelper.GetEntities <BaseEntities>();
            S_A_User     user         = baseEntities.Set <S_A_User>().Where(t => t.ID == employee.UserID).FirstOrDefault();

            if (user != null)
            {
                user.DeleteTime = DateTime.Now;
                user.ModifyTime = user.DeleteTime;
                user.IsDeleted  = "1";
                user.Code       = user.ID;
                baseEntities.Set <S_A__RoleUser>().Delete(a => a.UserID == user.ID);
                var retiredList = entities.Set <T_EmployeeRetired>().Where(c => c.EmployeeID == employee.ID).OrderBy("RetiredDate", false);
                if (retiredList.Count() > 0)
                {
                    user.OutDate = retiredList.FirstOrDefault().RetiredDate;
                }
                baseEntities.SaveChanges();
            }
        }
Exemple #5
0
        //更新雇员加入系统用户
        public void EmployeeUpdateToUser(T_Employee employee)
        {
            BaseEntities baseEntities = FormulaHelper.GetEntities <BaseEntities>();
            HREntities   entities     = FormulaHelper.GetEntities <HREntities>();
            var          enumService  = FormulaHelper.GetService <IEnumService>();
            S_A_User     user         = baseEntities.Set <S_A_User>().Find(employee.UserID);

            if (user == null)
            {
                user = baseEntities.Set <S_A_User>().FirstOrDefault(c => c.Code == employee.Code && c.IsDeleted == "0");
            }
            employee.UserID = user.ID;
            user.WorkNo     = employee.Code;
            //user.Code = employee.Code;
            user.Name       = employee.Name;
            user.IsDeleted  = employee.IsDeleted;
            user.Sex        = employee.Sex;
            user.ModifyTime = DateTime.Now;

            if (employee.Address != null)
            {
                user.Address = employee.Address;
            }
            if (employee.Email != null)
            {
                user.Email = employee.Email;
            }
            if (employee.OfficePhone != null)
            {
                user.Phone = employee.OfficePhone;
            }
            if (employee.MobilePhone != null)
            {
                user.MobilePhone = employee.MobilePhone;
            }


            S_A_Org org = null;

            user.S_A__OrgUser.RemoveWhere(c => c.S_A_Org.Type != "Post");
            List <string>  orgIDList = user.S_A__OrgUser.Select(a => a.OrgID).ToList();
            List <S_A_Org> orgList   = baseEntities.Set <S_A_Org>().Where(a => a.IsDeleted == "0").ToList();

            if (employee.DeptID != null)
            {
                org = orgList.Where(c => c.ID == employee.DeptID).FirstOrDefault();
            }

            if (org == null)
            {
                org = orgList.Where(c => c.ParentID == null || c.ParentID == "").FirstOrDefault();
            }

            if (org != null)
            {
                user.DeptID     = org.ID;
                user.DeptName   = org.Name;
                user.DeptFullID = org.FullID;

                string companyID   = "";
                string companyName = "";
                //逆序判断类型是否为集团/公司
                string[] orgIDs = org.FullID.Split('.');
                var      orgs   = orgList.Where(c => orgIDs.Contains(c.ID)).ToDictionary <S_A_Org, string>(d => d.ID);

                for (var i = orgIDs.Length; i > 0; i--)
                {
                    if ((orgs[orgIDs[i - 1]].Type ?? "none").IndexOf("Company") > -1)
                    {
                        companyID   = orgs[orgIDs[i - 1]].ID;
                        companyName = orgs[orgIDs[i - 1]].Name;
                        break;
                    }
                }
                user.CorpID   = companyID;
                user.CorpName = companyName;
            }
            if (!string.IsNullOrEmpty(user.DeptFullID))
            {
                foreach (var id in user.DeptFullID.Split('.'))
                {
                    if (!orgIDList.Contains(id))
                    {
                        S_A__OrgUser orgUser = new S_A__OrgUser();
                        orgUser.OrgID  = id;
                        orgUser.UserID = user.ID;
                        baseEntities.Set <S_A__OrgUser>().Add(orgUser);
                        orgIDList.Add(id);
                    }
                }
            }
            if (!string.IsNullOrEmpty(employee.ParttimeDeptID))
            {
                foreach (var id in employee.ParttimeDeptID.Split(','))
                {
                    var parttimeOrg = orgList.FirstOrDefault(c => c.ID == employee.DeptID);
                    if (parttimeOrg != null)
                    {
                        foreach (var parttimeOrgID in parttimeOrg.FullID.Split('.'))
                        {
                            if (!orgIDList.Contains(parttimeOrgID))
                            {
                                S_A__OrgUser orgUser = new S_A__OrgUser();
                                orgUser.OrgID  = parttimeOrgID;
                                orgUser.UserID = user.ID;
                                baseEntities.Set <S_A__OrgUser>().Add(orgUser);
                                orgIDList.Add(id);
                            }
                        }
                    }
                }
            }
            //修改用户图片
            S_A_UserImg        userImg     = null;
            List <S_A_UserImg> userImgList = baseEntities.Set <S_A_UserImg>().Where(c => c.UserID == user.ID).ToList();

            if (userImgList.Count > 0)
            {
                userImg = userImgList.FirstOrDefault();
            }
            else
            {
                userImg = new S_A_UserImg()
                {
                    ID     = FormulaHelper.CreateGuid(),
                    UserID = user.ID
                };
                baseEntities.Set <S_A_UserImg>().Add(userImg);
            }

            if (employee.Portrait != null)
            {
                userImg.Picture = employee.Portrait;
            }
            if (employee.SignImage != null)
            {
                userImg.SignImg = employee.SignImage;
            }
            if (employee.SignDwg != null)
            {
                userImg.DwgFile = employee.SignDwg;
            }

            entities.SaveChanges();
            baseEntities.SaveChanges();
        }
Exemple #6
0
        //新添雇员加入系统用户
        public void EmployeeAddToUser(T_Employee employee, string Password)
        {
            if (employee.IsDeleted == "1")
            {
                return;
            }
            BaseEntities baseEntities = FormulaHelper.GetEntities <BaseEntities>();
            HREntities   entities     = FormulaHelper.GetEntities <HREntities>();
            //添加新用户
            S_A_User user = new S_A_User()
            {
                ID          = FormulaHelper.CreateGuid(),
                Code        = employee.Code,
                Name        = employee.Name,
                WorkNo      = employee.Code,
                Address     = employee.Address,
                Email       = employee.Email,
                Password    = Password,
                Sex         = employee.Sex,
                InDate      = employee.JoinCompanyDate,
                Phone       = employee.OfficePhone,
                MobilePhone = employee.MobilePhone,
                ModifyTime  = DateTime.Now,
                IsDeleted   = "0"
            };

            baseEntities.Set <S_A_User>().Add(user);

            //反写userID
            employee.UserID = user.ID;

            List <string>  orgIDList = new List <string>();
            List <S_A_Org> orgList   = baseEntities.Set <S_A_Org>().Where(a => a.IsDeleted == "0").ToList();
            S_A_Org        org       = null;

            if (employee.DeptID != null)
            {
                org = orgList.Where(c => c.ID == employee.DeptID && c.IsDeleted == "0").FirstOrDefault();
            }

            if (org == null)
            {
                org = orgList.Where(c => c.ParentID == null || c.ParentID == "").FirstOrDefault();
            }

            if (org != null)
            {
                user.DeptID     = org.ID;
                user.DeptName   = org.Name;
                user.DeptFullID = org.FullID;

                string companyID   = "";
                string companyName = "";
                //逆序判断类型是否为集团/公司
                string[] orgIDs = org.FullID.Split('.');
                var      orgs   = orgList.Where(c => orgIDs.Contains(c.ID)).ToDictionary <S_A_Org, string>(d => d.ID);

                for (var i = orgIDs.Length; i > 0; i--)
                {
                    if ((orgs[orgIDs[i - 1]].Type ?? "none").IndexOf("Company") > -1)
                    {
                        companyID   = orgs[orgIDs[i - 1]].ID;
                        companyName = orgs[orgIDs[i - 1]].Name;
                        break;
                    }
                }
                user.CorpID   = companyID;
                user.CorpName = companyName;
            }
            if (!string.IsNullOrEmpty(user.DeptFullID))
            {
                foreach (var id in user.DeptFullID.Split('.'))
                {
                    if (!orgIDList.Contains(id))
                    {
                        S_A__OrgUser orgUser = new S_A__OrgUser();
                        orgUser.OrgID  = id;
                        orgUser.UserID = user.ID;
                        baseEntities.Set <S_A__OrgUser>().Add(orgUser);
                        orgIDList.Add(id);
                    }
                }
            }
            if (!string.IsNullOrEmpty(employee.ParttimeDeptID))
            {
                foreach (var id in employee.ParttimeDeptID.Split(','))
                {
                    var parttimeOrg = orgList.FirstOrDefault(c => c.ID == employee.DeptID);
                    if (parttimeOrg != null)
                    {
                        foreach (var parttimeOrgID in parttimeOrg.FullID.Split('.'))
                        {
                            if (!orgIDList.Contains(parttimeOrgID))
                            {
                                S_A__OrgUser orgUser = new S_A__OrgUser();
                                orgUser.OrgID  = parttimeOrgID;
                                orgUser.UserID = user.ID;
                                baseEntities.Set <S_A__OrgUser>().Add(orgUser);
                                orgIDList.Add(id);
                            }
                        }
                    }
                }
            }

            //添加用户图片
            S_A_UserImg userImg = new S_A_UserImg()
            {
                ID      = FormulaHelper.CreateGuid(),
                UserID  = user.ID,
                Picture = employee.Portrait,
                SignImg = employee.SignImage
            };

            baseEntities.Set <S_A_UserImg>().Add(userImg);

            entities.SaveChanges();
            baseEntities.SaveChanges();
        }
Exemple #7
0
        /// <summary>
        /// 根据Employee的部门、兼职部门同步系统账户的部门
        /// </summary>
        /// <param name="employee"></param>
        public void SyncUserDeptByEmployee(S_HR_Employee employee, S_A_User user, bool needSaveChange = false)
        {
            //主责部门设置为当前部门
            S_A_Org org = null;

            if (employee.Dept != null)
            {
                org = baseEntities.Set <S_A_Org>().Where(c => c.ID == employee.Dept && c.IsDeleted == "0").FirstOrDefault();
            }

            if (org == null)
            {
                org = baseEntities.Set <S_A_Org>().Where(c => c.ParentID == null || c.ParentID == "").FirstOrDefault();
            }

            List <string> orgIDList = new List <string>();//所属部门列表

            if (org != null)
            {
                user.DeptID     = org.ID;
                user.DeptName   = org.Name;
                user.DeptFullID = org.FullID;

                string[] orgArray = org.FullID.Split('.');
                foreach (string orgID in orgArray)
                {
                    //该组织关系已经添加过则继续下一组织
                    if (orgIDList.Contains(orgID))
                    {
                        continue;
                    }
                    else
                    {
                        orgIDList.Add(orgID);
                    }
                }
            }

            //部门设置为所属部门
            if (!string.IsNullOrEmpty(employee.ParttimeDept))
            {
                foreach (var item in employee.ParttimeDept.Split(','))
                {
                    S_A_Org pOrg = baseEntities.Set <S_A_Org>().Where(c => c.ID == item && c.IsDeleted == "0").FirstOrDefault();;
                    if (pOrg == null)
                    {
                        continue;
                    }
                    string[] pOrgArray = pOrg.FullID.Split('.');
                    foreach (string orgID in pOrgArray)
                    {
                        //该组织关系已经添加过则继续下一组织
                        if (orgIDList.Contains(orgID))
                        {
                            continue;
                        }
                        else
                        {
                            orgIDList.Add(orgID);
                        }
                    }
                }
            }

            //差异更新,删除或增加
            var deleteList = baseEntities.Set <S_A__OrgUser>().Where(a => a.UserID == user.ID).ToList();

            foreach (var orgid in orgIDList)
            {
                var exist = deleteList.FirstOrDefault(a => a.OrgID == orgid);
                if (exist != null)
                {
                    deleteList.Remove(exist);
                }
                else
                {
                    baseEntities.Set <S_A__OrgUser>().Add(new S_A__OrgUser()
                    {
                        OrgID = orgid, UserID = user.ID
                    });
                }
            }
            foreach (var item in deleteList)
            {
                baseEntities.Set <S_A__OrgUser>().Remove(item);
            }

            if (needSaveChange)
            {
                baseEntities.SaveChanges();
            }
        }