/// <summary> /// 获取组织架构列表 /// </summary> /// <returns></returns> public JsonResult GetOrganizationalStructureList() { var retModel = new JsonReturnModel(); try { List <OrganizationalStructureModel> list = new List <OrganizationalStructureModel>(); //获取组织架构 List <B_ORGANIZATIONALSTRUCTURE> dataList = OrganizationalStructureBll.GetOrganizationalStructureList(); //获取树形结构的数据 List <B_ORGANIZATIONALSTRUCTURE> data = new List <B_ORGANIZATIONALSTRUCTURE>(); OrganizationalStructureBll.GetChildByParent(inn, "", data, dataList); if (data != null && data.Count > 0) { for (int i = 0; i < data.Count; i++) { OrganizationalStructureModel model = new OrganizationalStructureModel(); var item = data[i]; model.id = item.id; model.b_NodeName = item.B_NODENAME; model.b_NodeCode = item.B_NODECODE; model.b_ParentNodeCode = item.B_PARENTNODECODE; model.b_NodePersonName = item.B_NODEPERSONNAME; model.b_NodeLevel = item.B_NODELEVEL; model.b_CostCenter = string.IsNullOrEmpty(item.B_COSTCENTER) ? "" : item.B_COSTCENTER; model.b_CompanyCode = string.IsNullOrEmpty(item.B_COMPANYCODE) ? "" : item.B_COMPANYCODE; model.Number = i + 1; if (!string.IsNullOrEmpty(model.b_ParentNodeCode)) { var parentNode = list.Where(x => x.b_NodeCode == model.b_ParentNodeCode).FirstOrDefault(); model.ParentNumber = parentNode.Number; } list.Add(model); } } retModel.data = list; } catch (Exception ex) { retModel.AddError("errorMessage", ex.Message); } return(Json(retModel, JsonRequestBehavior.AllowGet)); }
//上传人员信息 public JsonResult UploadUserFile() { var retModel = new JsonReturnModel(); try { if (Request.Files == null || Request.Files.Count == 0) { retModel.AddError("errorMessage", Common.GetLanguageValueByParam("请选择您要上传的附件!", "PRCommon", "PRItemType", Userinfo.language)); return(Json(retModel, JsonRequestBehavior.AllowGet)); } HttpPostedFileBase prfile = Request.Files[0]; string fileName = prfile.FileName.Substring(prfile.FileName.LastIndexOf("\\") + 1, prfile.FileName.Length - (prfile.FileName.LastIndexOf("\\")) - 1); if (!fileName.ToLower().Contains(".xls") && !fileName.ToLower().Contains(".xlsx")) { retModel.AddError("errorMessage", "只能上传Excel文件!"); return(Json(retModel, JsonRequestBehavior.AllowGet)); } string filePath = ConfigurationManager.AppSettings["UploadPath"] + fileName; prfile.SaveAs(filePath); //获取数据库 所有的用户信息 List <USER> allUser = UserBll.GetAllUserInfo(); List <USER> list = new List <USER>(); using (FileStream fs = new FileStream(filePath, FileMode.Open)) { IWorkbook workbook = null; if (fileName.ToLower().Contains(".xlsx")) { workbook = new XSSFWorkbook(fs); } else { workbook = new HSSFWorkbook(fs); } ISheet sheet = workbook.GetSheetAt(0); int rowNum = sheet.PhysicalNumberOfRows; //获取整个组织架构 List <B_ORGANIZATIONALSTRUCTURE> dataList = OrganizationalStructureBll.GetOrganizationalStructureList(); for (int i = 0; i < rowNum; i++) { IRow row = sheet.GetRow(i); if (i != 0) { USER model = new USER(); if (row.GetCell(0) != null) { model.B_JOBNUMBER = row.GetCell(0) != null?row.GetCell(0).ToString().Trim() : ""; model.B_CHINESENAME = row.GetCell(1) != null?row.GetCell(1).ToString().Trim() : ""; model.B_ENGLISHNAME = row.GetCell(2) != null?row.GetCell(2).ToString().Trim() : ""; model.B_CENTRE = row.GetCell(3) != null?row.GetCell(3).ToString().Trim() : ""; model.B_DEPARTMENT = row.GetCell(4) != null?row.GetCell(4).ToString().Trim() : ""; model.B_SENIORMANAGER = row.GetCell(5) != null?row.GetCell(5).ToString().Trim() : ""; model.B_DIRECTOR = row.GetCell(6) != null?row.GetCell(6).ToString().Trim() : ""; model.B_VP = row.GetCell(7) != null?row.GetCell(7).ToString().Trim() : ""; model.B_AFFILIATEDCOMPANY = row.GetCell(8) != null?row.GetCell(8).ToString().Trim() : ""; //根据用户名称判断用户是否存在 int count = allUser.Where(x => x.LOGIN_NAME.ToUpper() == model.B_ENGLISHNAME.ToUpper()).Count(); if (count == 0) { retModel.AddError("errorMessage", i + 1 + "行上传的用户不存在!"); return(Json(retModel, JsonRequestBehavior.AllowGet)); } //判断中心是否存在 B_ORGANIZATIONALSTRUCTURE centreObj = dataList.Where(x => x.B_NODENAME == model.B_CENTRE && x.B_NODELEVEL == 2).FirstOrDefault(); if (centreObj == null) { retModel.AddError("errorMessage", i + 1 + "行上传的中心不存在!"); return(Json(retModel, JsonRequestBehavior.AllowGet)); } //判断部门是否存在 List <B_ORGANIZATIONALSTRUCTURE> organizationalStructureList = new List <B_ORGANIZATIONALSTRUCTURE>(); if (!string.IsNullOrEmpty(model.B_DEPARTMENT)) { OrganizationalStructureBll.GetChildByParent(inn, centreObj.B_NODECODE, organizationalStructureList, dataList); int countDepartment = organizationalStructureList.Where(x => x.B_NODENAME == model.B_DEPARTMENT).Count(); if (countDepartment == 0) { retModel.AddError("errorMessage", i + 1 + "行上传的部门不存在!"); return(Json(retModel, JsonRequestBehavior.AllowGet)); } } //判断上传的高级经理是否存在 if (!string.IsNullOrEmpty(model.B_SENIORMANAGER)) { var itemSeniorManager = allUser.Where(x => x.LOGIN_NAME.ToUpper() == model.B_SENIORMANAGER.ToUpper()).FirstOrDefault(); if (itemSeniorManager == null) { retModel.AddError("errorMessage", i + 1 + "行上传的高级经理不存在!"); return(Json(retModel, JsonRequestBehavior.AllowGet)); } model.B_SENIORMANAGER = itemSeniorManager.FIRST_NAME; } //判断上传的总监是否存在 if (!string.IsNullOrEmpty(model.B_DIRECTOR)) { var itemDirector = allUser.Where(x => x.LOGIN_NAME.ToUpper() == model.B_DIRECTOR.ToUpper()).FirstOrDefault(); if (itemDirector == null) { retModel.AddError("errorMessage", i + 1 + "行上传的总监不存在!"); return(Json(retModel, JsonRequestBehavior.AllowGet)); } model.B_DIRECTOR = itemDirector.FIRST_NAME; } //判断上传的VP是否存在 if (!string.IsNullOrEmpty(model.B_VP)) { var itemVP = allUser.Where(x => x.LOGIN_NAME.ToUpper() == model.B_VP.ToUpper()).FirstOrDefault(); if (itemVP == null) { retModel.AddError("errorMessage", i + 1 + "行上传的VP不存在!"); return(Json(retModel, JsonRequestBehavior.AllowGet)); } model.B_VP = itemVP.FIRST_NAME; } //判断上传所属公司是否正确 if (!string.IsNullOrEmpty(model.B_AFFILIATEDCOMPANY)) { List <string> arrList = model.B_AFFILIATEDCOMPANY.Split(';').Where(x => x != "").ToList(); foreach (var item in arrList) { if (item != "博郡" && item != "思致") { retModel.AddError("errorMessage", i + 1 + "行上传的所属公司不正确!"); return(Json(retModel, JsonRequestBehavior.AllowGet)); } } } list.Add(model); } } } Innovator adminInn = WorkFlowBll.GetAdminInnovator(); //修改数据库中的数据 if (list != null && list.Count > 0 && adminInn != null) { for (int i = 0; i < list.Count; i++) { var item = list[i]; //string userName = item.B_ENGLISHNAME.ToUpper() + " " + "(" + item.B_CHINESENAME + ")"; USER userObj = allUser.Where(x => x.LOGIN_NAME.ToUpper() == item.B_ENGLISHNAME.ToUpper()).First(); var user = adminInn.newItem("User", "edit"); user.setAttribute("id", userObj.ID); user.setProperty("b_jobnumber", item.B_JOBNUMBER); user.setProperty("b_chinesename", item.B_CHINESENAME); user.setProperty("b_englishname", item.B_ENGLISHNAME); user.setProperty("b_centre", item.B_CENTRE); user.setProperty("b_department", item.B_DEPARTMENT); user.setProperty("b_seniormanager", item.B_SENIORMANAGER); user.setProperty("b_director", item.B_DIRECTOR); user.setProperty("b_vp", item.B_VP); user.setProperty("b_affiliatedcompany", item.B_AFFILIATEDCOMPANY); var result = user.apply(); } } } } catch (Exception ex) { retModel.AddError("errorMessage", ex.Message); } return(Json(retModel, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 上传项目信息 /// </summary> /// <returns></returns> public JsonResult UploadProjectManageFile() { var retModel = new JsonReturnModel(); try { if (Request.Files == null || Request.Files.Count == 0) { retModel.AddError("errorMessage", Common.GetLanguageValueByParam("请选择您要上传的附件!", "PRCommon", "PRItemType", Userinfo.language)); return(Json(retModel, JsonRequestBehavior.AllowGet)); } HttpPostedFileBase prfile = Request.Files[0]; string fileName = prfile.FileName.Substring(prfile.FileName.LastIndexOf("\\") + 1, prfile.FileName.Length - (prfile.FileName.LastIndexOf("\\")) - 1); if (!fileName.ToLower().Contains(".xls") && !fileName.ToLower().Contains(".xlsx")) { retModel.AddError("errorMessage", "只能上传Excel文件!"); return(Json(retModel, JsonRequestBehavior.AllowGet)); } //保存上传文件到指定目录 string filePath = ConfigurationManager.AppSettings["UploadPath"] + fileName; prfile.SaveAs(filePath); //获取数据库 所有用户信息 List <USER> allUser = UserBll.GetAllUserInfo(); List <B_PROJECTMANAGE> allProject = ProjectManageBll.GetAllProjectInfo(); List <B_PROJECTMANAGE> list = new List <B_PROJECTMANAGE>(); using (FileStream fs = new FileStream(filePath, FileMode.Open)) { IWorkbook workbook = null; if (fileName.ToLower().Contains(".xlsx")) { workbook = new XSSFWorkbook(fs); } else { workbook = new HSSFWorkbook(fs); } ISheet sheet = workbook.GetSheetAt(0); int rowNum = sheet.PhysicalNumberOfRows; //获取整个项目信息 List <B_ORGANIZATIONALSTRUCTURE> dataList = OrganizationalStructureBll.GetOrganizationalStructureList(); for (int i = 0; i < rowNum; i++) { IRow row = sheet.GetRow(i); if (i != 0) { B_PROJECTMANAGE model = new B_PROJECTMANAGE(); model.B_PROJECTRECORDNO = row.GetCell(0) != null?row.GetCell(0).ToString().Trim() : ""; model.B_PROJECTNAME = row.GetCell(1) != null?row.GetCell(1).ToString().Trim() : ""; model.B_PMTORPATLEADER = row.GetCell(2) != null?row.GetCell(2).ToString().Trim() : ""; model.B_PROJECTMANAGER = row.GetCell(3) != null?row.GetCell(3).ToString().Trim() : ""; model.B_PROJECTDIRECTOR = row.GetCell(4) != null?row.GetCell(4).ToString().Trim() : ""; model.B_PROJECTVP = row.GetCell(5) != null?row.GetCell(5).ToString().Trim() : ""; model.B_ISINUSE = row.GetCell(6) != null?row.GetCell(6).ToString().Trim() : ""; //判断输入的项目编号是否存在 if (ProjectManageDA.isExistProjectRecordNo(inn, model.B_PROJECTRECORDNO, model.id)) { retModel.AddError("errorMessage", i + 1 + "行1列输入的项目编号已经存在!"); return(Json(retModel, JsonRequestBehavior.AllowGet)); } //验证输入的项目名称是否已经存在 if (ProjectManageDA.GetProjectManageByName(inn, model.B_PROJECTNAME, model.id)) { retModel.AddError("errorMessage", i + 1 + "行2列输入的项目名称已经存在!"); return(Json(retModel, JsonRequestBehavior.AllowGet)); } //判断的PMT/PAT Leader是否存在 if (!string.IsNullOrEmpty(model.B_PMTORPATLEADER)) { var Leader = allUser.Where(x => x.LOGIN_NAME.ToUpper() == model.B_PMTORPATLEADER.ToUpper()).FirstOrDefault(); if (Leader == null) { retModel.AddError("errorMessage", i + 1 + "行3列上传的PMT/PAT经理不存在!"); return(Json(retModel, JsonRequestBehavior.AllowGet)); } else { model.B_PMTORPATLEADER = Leader.FIRST_NAME; var itemLeader = IdentityDA.GetIdentityByKeyedName(inn, model.B_PMTORPATLEADER); model.B_PMTORPATLEADERID = itemLeader.getProperty("id"); } } //判断项目经理是否存在 if (!string.IsNullOrEmpty(model.B_PROJECTMANAGER)) { var Leader = allUser.Where(x => x.LOGIN_NAME.ToUpper() == model.B_PROJECTMANAGER.ToUpper()).FirstOrDefault(); if (Leader == null) { retModel.AddError("errorMessage", i + 1 + "行4列上传的项目经理不存在!"); return(Json(retModel, JsonRequestBehavior.AllowGet)); } else { model.B_PROJECTMANAGER = Leader.FIRST_NAME; var itemManager = IdentityDA.GetIdentityByKeyedName(inn, model.B_PROJECTMANAGER); model.B_PROJECTMANAGERID = itemManager.getProperty("id"); } } //判断上传的总监是否存在 if (!string.IsNullOrEmpty(model.B_PROJECTDIRECTOR)) { var Leader = allUser.Where(x => x.LOGIN_NAME.ToUpper() == model.B_PROJECTDIRECTOR.ToUpper()).FirstOrDefault(); if (Leader == null) { retModel.AddError("errorMessage", i + 1 + "行5列上传的总监不存在!"); return(Json(retModel, JsonRequestBehavior.AllowGet)); } else { model.B_PROJECTDIRECTOR = Leader.FIRST_NAME; var itemDirector = IdentityDA.GetIdentityByKeyedName(inn, model.B_PROJECTDIRECTOR); model.B_PROJECTDIRECTORID = itemDirector.getProperty("id"); } } //判断上传的VP是否存在 if (!string.IsNullOrEmpty(model.B_PROJECTVP)) { var Leader = allUser.Where(x => x.LOGIN_NAME.ToUpper() == model.B_PROJECTVP.ToUpper()).FirstOrDefault(); if (Leader == null) { retModel.AddError("errorMessage", i + 1 + "行6列上传的VP不存在!"); return(Json(retModel, JsonRequestBehavior.AllowGet)); } else { model.B_PROJECTVP = Leader.FIRST_NAME; } } list.Add(model); } } list = list.Distinct().ToList(); //把数据添加到数据库中 if (list != null && list.Count > 0) { for (int i = 0; i < list.Count; i++) { var item = list[i]; B_PROJECTMANAGE ProManagerObj = allProject.Where(x => item.B_PROJECTRECORDNO.ToUpper() == item.B_PROJECTNAME.ToUpper()).First(); var promanager = inn.newItem("b_ProjectManage", "add"); promanager.setProperty("b_projectrecordno", item.B_PROJECTRECORDNO); promanager.setProperty("b_projectname", item.B_PROJECTNAME); promanager.setProperty("b_pmtorpatleaderid", item.B_PMTORPATLEADERID); promanager.setProperty("b_pmtorpatleader", item.B_PMTORPATLEADER); promanager.setProperty("b_projectmanagerid", item.B_PROJECTMANAGERID); promanager.setProperty("b_projectmanager", item.B_PROJECTMANAGER); promanager.setProperty("b_projectdirectorid", item.B_PROJECTDIRECTORID); promanager.setProperty("b_projectdirector", item.B_PROJECTDIRECTOR); promanager.setProperty("b_projectvp", item.B_PROJECTVP); promanager.setProperty("b_isinuse", item.B_ISINUSE); var result = promanager.apply(); } } } } catch (Exception ex) { retModel.AddError("errorMessage", ex.Message); } return(Json(retModel, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 保存用户信息 /// </summary> /// <param name="model"></param> /// <returns></returns> public JsonResult SaveUser(UserModel model) { var retModel = new JsonReturnModel(); try { //判断中心部门是否存在 if (!string.IsNullOrEmpty(model.b_Centre)) { var centreItem = OrganizationalStructureDA.GetOrganizationalStructureByParam(inn, model.b_Centre, 2); if (!centreItem.isError() && centreItem.getItemCount() <= 0) { retModel.AddError("errorMessage", "填写的中心不存在!"); return(Json(retModel, JsonRequestBehavior.AllowGet)); } if (!string.IsNullOrEmpty(model.b_Department)) { //获取中心部门节点代号 string centreNodeCode = centreItem.getProperty("b_nodecode"); //判断部门是否在中心部门下存在 List <B_ORGANIZATIONALSTRUCTURE> organizationalStructureList = new List <B_ORGANIZATIONALSTRUCTURE>(); //获取组织架构 List <B_ORGANIZATIONALSTRUCTURE> dataList = OrganizationalStructureBll.GetOrganizationalStructureList(); OrganizationalStructureBll.GetChildByParent(inn, centreNodeCode, organizationalStructureList, dataList); int count = organizationalStructureList.Where(x => x.B_NODENAME == model.b_Department).Count(); if (count <= 0) { retModel.AddError("errorMessage", "填写的部门在中心下不存在!"); return(Json(retModel, JsonRequestBehavior.AllowGet)); } } } //判断输入的高级经理是否存在 if (!string.IsNullOrEmpty(model.b_SeniorManager)) { var itemSeniorManager = IdentityDA.GetIdentityByKeyedName(inn, model.b_SeniorManager); if (itemSeniorManager.isError()) { retModel.AddError("errorMessage", "输入的高级经理不存在!"); return(Json(retModel, JsonRequestBehavior.AllowGet)); } } //判断输入的总监是否存在 if (!string.IsNullOrEmpty(model.b_Director)) { var itemDirector = IdentityDA.GetIdentityByKeyedName(inn, model.b_Director); if (itemDirector.isError()) { retModel.AddError("errorMessage", "输入的总监不存在!"); return(Json(retModel, JsonRequestBehavior.AllowGet)); } } //判断输入的VP是否存在 if (!string.IsNullOrEmpty(model.b_VP)) { var itemVP = IdentityDA.GetIdentityByKeyedName(inn, model.b_VP); if (itemVP.isError()) { retModel.AddError("errorMessage", "输入的VP不存在!"); return(Json(retModel, JsonRequestBehavior.AllowGet)); } } Innovator adminInn = WorkFlowBll.GetAdminInnovator(); if (adminInn != null) { var item = adminInn.newItem("User", "edit"); item.setAttribute("id", model.Id); item.setProperty("b_jobnumber", model.b_JobNumber); item.setProperty("b_chinesename", model.b_ChineseName); item.setProperty("b_englishname", model.b_EnglishName); item.setProperty("email", model.Email); item.setProperty("telephone", model.Telephone); item.setProperty("b_centre", model.b_Centre); item.setProperty("b_department", model.b_Department); item.setProperty("b_idnumber", model.b_IdNumber); item.setProperty("b_seniormanager", model.b_SeniorManager); item.setProperty("b_director", model.b_Director); item.setProperty("b_vp", model.b_VP); item.setProperty("b_affiliatedcompany", model.b_AffiliatedCompany); var result = item.apply(); if (result.isError()) { retModel.AddError("errorMessage", result.getErrorString()); } } } catch (Exception ex) { retModel.AddError("errorMessage", ex.Message); } return(Json(retModel, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 根据名称获取用户信息 /// </summary> /// <param name="name"></param> /// <returns></returns> public JsonResult GetUserByName(string name) { var retModel = new JsonReturnModel(); try { using (InnovatorSolutionsEntities db = new InnovatorSolutionsEntities()) { USER item = db.USER.Where(x => x.FIRST_NAME == name).FirstOrDefault(); if (item != null) { UserModel model = new UserModel(); model.Id = item.ID; model.first_Name = item.FIRST_NAME; model.Email = item.EMAIL; model.Telephone = item.TELEPHONE; model.b_JobNumber = item.B_JOBNUMBER; model.b_ChineseName = item.B_CHINESENAME; model.b_EnglishName = item.B_ENGLISHNAME; model.b_Centre = item.B_CENTRE; model.b_Department = item.B_DEPARTMENT; model.b_SeniorManager = item.B_SENIORMANAGER; model.b_Director = item.B_DIRECTOR; model.b_VP = item.B_VP; if (!string.IsNullOrEmpty(model.b_Centre)) { //根据中心名称获取中心领导 var structure = OrganizationalStructureDA.GetOrganizationalStructureByParam(inn, model.b_Centre, 2); if (!structure.isError() && structure.getItemCount() > 0) { string b_nodepersonname = structure.getItemByIndex(0).getProperty("b_nodepersonname"); string b_NodeCode = structure.getItemByIndex(0).getProperty("b_nodecode"); string b_ParentNodeCode = structure.getItemByIndex(0).getProperty("b_parentnodecode"); string b_CompanyCode = structure.getItemByIndex(0).getProperty("b_companycode"); string b_CostCenter = structure.getItemByIndex(0).getProperty("b_costcenter"); USER centreUser = UserDA.GetUserByLoginName(b_nodepersonname); if (centreUser != null && centreUser.FIRST_NAME != name) { model.b_CentreLeader = centreUser.FIRST_NAME; } else if (centreUser != null && centreUser.FIRST_NAME == name) { //获取上级节点 var parentNode = OrganizationalStructureDA.GetOrganizationalStructureByNodeCode(inn, b_ParentNodeCode); if (!parentNode.isError() && parentNode.getItemCount() > 0) { string lineLeader = parentNode.getItemByIndex(0).getProperty("b_nodepersonname"); USER lineLeaderUser = UserDA.GetUserByLoginName(lineLeader); if (lineLeaderUser != null && lineLeaderUser.FIRST_NAME != name) { model.b_LineLeader = lineLeaderUser.FIRST_NAME; } } } if (!string.IsNullOrEmpty(model.b_Department)) { //获取结构数据 List <B_ORGANIZATIONALSTRUCTURE> list = OrganizationalStructureBll.GetOrganizationalStructureList(); //获取中心下的组织结构 List <B_ORGANIZATIONALSTRUCTURE> childNodeList = new List <B_ORGANIZATIONALSTRUCTURE>(); OrganizationalStructureBll.GetChildByParent(inn, b_NodeCode, childNodeList, list); if (childNodeList != null && childNodeList.Count > 0) { B_ORGANIZATIONALSTRUCTURE departObj = childNodeList.Where(x => x.B_NODENAME == model.b_Department).FirstOrDefault(); if (departObj != null) { b_CompanyCode = departObj.B_COMPANYCODE; b_CostCenter = departObj.B_COSTCENTER; USER departUser = UserDA.GetUserByLoginName(departObj.B_NODEPERSONNAME); if (departUser != null && departUser.FIRST_NAME != name) { model.b_DepartmentLeader = departUser.FIRST_NAME; } } } } model.b_CompanyCode = b_CompanyCode; model.b_CostCenter = b_CostCenter; if (!string.IsNullOrEmpty(model.b_CompanyCode)) { //根据公司代码 获取公司信息 string companyName = CompanyInfoBll.GetCompanyNameByCode(inn, model.b_CompanyCode); if (!string.IsNullOrEmpty(companyName)) { model.b_CompanyCode = model.b_CompanyCode + " (" + companyName + ")"; } } } } retModel.data = model; } } } catch (Exception ex) { retModel.AddError("errorMessage", ex.Message); } return(Json(retModel, JsonRequestBehavior.AllowGet)); }