Beispiel #1
0
 public JsonResult GetHRInfo(string guid)
 {
     try
     {
         HRInfoManager service = new HRInfoManager();
         HRInfoEntity  entity  = service.GetFirstOrDefault(guid);
         return(new JsonResult {
             Data = new { success = true, msg = "msg", data = entity }, JsonRequestBehavior = JsonRequestBehavior.AllowGet
         });
     }
     catch (Exception ex)
     {
         return(new JsonResult {
             Data = new { success = false, msg = ex.ToString() }, JsonRequestBehavior = JsonRequestBehavior.AllowGet
         });
     }
 }
Beispiel #2
0
        private List <HRInfoEntity> ExcelSheetToEntityList(ISheet sheet, ref string errorLog)
        {
            string[] sexArray = { "男", "女" };
            string[] residencePropertyArray = { "农业户口", "非农业户口" };
            string[] bloodTypeArray         = { "A", "B", "AB", "O" };
            string[] marriageArray          = { "已婚", "未婚" };
            string[] yesnoArray             = { "是", "否" };
            string[] poliArray         = { "群众", "团员", "共产党员", "其它" };
            string[] eduArray          = { "小学", "初中", "中专", "高中", "大专", "本科", "硕士", "博士" };
            string[] empstaArray       = { "在职", "离职" };
            string[] contratypeArray   = { "派遣", "外包" };
            string[] resigntypeArray   = { "自离", "旷工", "辞职", "辞退", "开除" };
            string[] resignressonArray = { "身体原因", "工作原因", "家族原因", "其他" };
            string[] contractsignArray = { "一次签订", "二次签订", "三次签订", "否" };

            Dictionary <string, string[]> checkdic = new Dictionary <string, string[]>();

            checkdic.Add("性别$iSex", sexArray);
            checkdic.Add("户口性质$iResidenceProperty", residencePropertyArray);
            //checkdic.Add("血型$iBloodType", bloodTypeArray);
            checkdic.Add("婚姻状况$iMariage", marriageArray);
            checkdic.Add("体检$iHealthCheck|是否返费$iIsReturnFee|是否缴纳保险$iIsSocialInsurancePaid|是否缴纳公积金$iIsProvidentPaid|是否缴纳商业保险$iIsCommercialInsurancePaid", yesnoArray);
            checkdic.Add("合同签订情况$iContractSignStatus", contractsignArray);
            checkdic.Add("政治面貌$iPolitical", poliArray);
            checkdic.Add("文化水平$iEducationLevel", eduArray);
            checkdic.Add("员工状态$iEmployeeStatus", empstaArray);
            checkdic.Add("合同类型$iContractType", contratypeArray);
            checkdic.Add("离职类型$iResignType", resigntypeArray);
            checkdic.Add("离职原因(公司)$iResignReason", resignressonArray);

            DicManager    dm        = new DicManager();
            var           companies = dm.GetAllCompanies();
            var           projects  = dm.GetAllProjects();
            HRInfoManager service   = new HRInfoManager();

            List <HRInfoEntity> list = new List <HRInfoEntity>();

            Dictionary <string, string> keycolumnp = HRInfoManager.hrDic;
            Dictionary <string, int>    keycolumns = new Dictionary <string, int>();

            for (int co = 0; co < sheet.GetRow(0).LastCellNum; co++)
            {
                if (keycolumnp.ContainsKey(sheet.GetRow(0).GetCell(co).ToString().Trim()))
                {
                    keycolumns.Add(keycolumnp[sheet.GetRow(0).GetCell(co).ToString().Trim()], co);
                }
            }
            //遍历数据行
            for (int i = (sheet.FirstRowNum + 1), len = sheet.LastRowNum + 1; i < len; i++)
            {
                CompanyEntity currentCompany = null;
                ProjectEntity currentProject = null;

                HRInfoEntity en = new HRInfoEntity();
                try
                {
                    if (keycolumns.ContainsKey("iGuid"))
                    {
                        string iguid = sheet.GetRow(i).GetCell(keycolumns["iGuid"]).ToString();
                        if (!string.IsNullOrEmpty(iguid))
                        {
                            en = service.GetFirstOrDefault(iguid);
                        }
                    }
                    if (string.IsNullOrEmpty(en.iGuid))
                    {
                        string project = sheet.GetRow(i).GetCell(keycolumns["iItemName"]).ToString().Trim();
                        string company = sheet.GetRow(i).GetCell(keycolumns["iCompany"]).ToString().Trim();
                        string empcode = sheet.GetRow(i).GetCell(keycolumns["iEmpNo"]).ToString().Trim();
                        string idcard  = sheet.GetRow(i).GetCell(keycolumns["iIdCard"]).ToString().Trim();
                        currentCompany = companies.FirstOrDefault(pj => pj.iName == company);
                        currentProject = projects.FirstOrDefault(pj => pj.iName == project);
                        if (currentCompany == null || currentProject == null)
                        {
                            if (currentCompany == null)
                            {
                                errorLog += "第【" + (i + 1).ToString() + "】行公司名称不存在;";
                            }
                            if (currentProject == null)
                            {
                                errorLog += "第【" + (i + 1).ToString() + "】行项目名称不存在;";
                            }
                            if (SessionHelper.CurrentUser.UserType == "普通用户" && currentProject.iName != SessionHelper.CurrentUser.CurrentProject)
                            {
                                errorLog += "第【" + (i + 1).ToString() + "】行只能导入您当前所在的项目;";
                            }
                        }
                        else
                        {
                            en = service.GetUniqueFirstOrDefault(currentProject.iGuid, currentCompany.iGuid, empcode, idcard);
                            if (en == null)
                            {
                                en = new HRInfoEntity();
                            }
                        }
                    }
                }
                catch
                {
                    errorLog += "第【" + (i + 1).ToString() + "】行所在公司,工号,身份证号不能有缺失;";
                }


                foreach (var kvp in keycolumns)
                {
                    if (sheet.GetRow(i).GetCell(kvp.Value) == null || sheet.GetRow(i).GetCell(kvp.Value).ToString() == "")
                    {
                        //en.GetType().GetProperty(kvp.Key).SetValue(en, null, null);
                        //空的不填写,保持原数据不变
                    }
                    else
                    {
                        object value = null;
                        ICell  cell  = sheet.GetRow(i).GetCell(kvp.Value);
                        if (cell.CellType == CellType.Blank)
                        {
                            value = "";
                        }
                        else
                        {
                            string propertyName = en.GetType().GetProperty(kvp.Key).PropertyType.FullName.ToLower();
                            if (cell.CellType == CellType.Numeric && HSSFDateUtil.IsCellDateFormatted(cell))
                            {
                                try
                                {
                                    value = sheet.GetRow(i).GetCell(kvp.Value).DateCellValue;
                                }
                                catch (Exception ex)
                                {
                                    errorLog += "第【" + (i + 1).ToString() + "】行,第【" + (kvp.Value + 1).ToString() + "】列不是标准日期格式;";
                                }
                                if (!propertyName.Contains("datetime") && value != null)
                                {
                                    value = ((DateTime)value).ToString("yyyy-MM-dd");
                                }
                            }
                            else
                            {
                                value = sheet.GetRow(i).GetCell(kvp.Value).ToString().Trim();
                                if (propertyName.Contains("datetime") && value != null)
                                {
                                    DateTime dt = DateTime.Now;
                                    if (DateTime.TryParse(value.ToString(), out dt))
                                    {
                                        value = dt;
                                    }
                                    else
                                    {
                                        errorLog += "第【" + (i + 1).ToString() + "】行,第【" + (kvp.Value + 1).ToString() + "】列不是标准日期格式;";
                                    }
                                }
                            }
                        }
                        en.GetType().GetProperty(kvp.Key).SetValue(en, value, null);
                    }
                }
                if (currentProject != null)
                {
                    en.iItemName = currentProject.iGuid;
                }
                if (currentCompany != null)
                {
                    en.iCompany = currentCompany.iGuid;
                }

                if (SessionHelper.CurrentUser.UserType == "普通用户" && en.iItemName != SessionHelper.CurrentUser.CurrentProject)
                {
                    errorLog += "第【" + (i + 1).ToString() + "】行项目名称不正确,只能导入当前项目;";
                }
                if (string.IsNullOrEmpty(en.iEmpNo))
                {
                    errorLog += "第【" + (i + 1).ToString() + "】行工号不能为空,临时工用-;";
                }
                if (string.IsNullOrEmpty(en.iName))
                {
                    errorLog += "第【" + (i + 1).ToString() + "】行姓名不能为空;";
                }
                if (!CheckIDCard18(en.iIdCard))
                {
                    errorLog += "第【" + (i + 1).ToString() + "】行身份证号不合法;";
                }
                //是否有效校验

                foreach (var item in checkdic)
                {
                    foreach (var subitem in item.Key.Split('|'))
                    {
                        PropertyInfo property = en.GetType().GetProperty(subitem.Split('$')[1]);
                        if (property.GetValue(en, null) != null && property.GetValue(en, null).ToString() != "" && !item.Value.Contains(property.GetValue(en, null)))
                        {
                            errorLog += "第【" + (i + 1).ToString() + "】行" + subitem.Split('$')[0] + "不合法,只能输入【";
                            foreach (var value in item.Value)
                            {
                                errorLog += value + ",";
                            }
                            errorLog  = errorLog.TrimEnd(',');
                            errorLog += "】;";
                        }
                    }
                }
                list.Add(en);
            }
            return(list);
        }