示例#1
0
        /// <summary>
        /// 根据Id 获取结构信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public JsonResult GetOrganizationalStructureById(string id)
        {
            var retModel = new JsonReturnModel();

            try
            {
                OrganizationalStructureModel model = new OrganizationalStructureModel();
                B_ORGANIZATIONALSTRUCTURE    obj   = OrganizationalStructureBll.GetOrganizationalStructureById(id);
                if (obj != null)
                {
                    model.id               = obj.id;
                    model.b_NodeName       = obj.B_NODENAME;
                    model.b_NodeCode       = obj.B_NODECODE;
                    model.b_ParentNodeCode = obj.B_PARENTNODECODE;
                    model.b_NodePersonName = obj.B_NODEPERSONNAME;
                    model.b_NodeLevel      = obj.B_NODELEVEL;
                    model.b_CostCenter     = obj.B_COSTCENTER;
                    model.b_CompanyCode    = obj.B_COMPANYCODE;
                }
                retModel.data = model;
            }
            catch (Exception ex)
            {
                retModel.AddError("errorMessage", ex.Message);
            }
            return(Json(retModel, JsonRequestBehavior.AllowGet));
        }
示例#2
0
        //上传人员信息
        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));
        }
示例#3
0
        /// <summary>
        /// 上传文件
        /// </summary>
        /// <returns></returns>
        public JsonResult UploadOrganizationalStructureFile()
        {
            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 <B_ORGANIZATIONALSTRUCTURE> list = new List <B_ORGANIZATIONALSTRUCTURE>();
                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;
                    for (int i = 0; i < rowNum; i++)
                    {
                        IRow row = sheet.GetRow(i);
                        if (i != 0)
                        {
                            B_ORGANIZATIONALSTRUCTURE entity = new B_ORGANIZATIONALSTRUCTURE();
                            if (row.GetCell(0) != null)
                            {
                                entity.B_NODENAME = row.GetCell(0) != null?row.GetCell(0).ToString().Trim() : "";

                                entity.B_NODECODE = row.GetCell(1) != null?row.GetCell(1).ToString().Trim() : "";

                                entity.B_PARENTNODECODE = row.GetCell(2) != null?row.GetCell(2).ToString().Trim() : "";

                                entity.B_NODEPERSONNAME = row.GetCell(3) != null?row.GetCell(3).ToString().Trim() : "";

                                string nodeLevelStr = row.GetCell(4) != null?row.GetCell(4).ToString().Trim() : "";

                                entity.B_COMPANYCODE = row.GetCell(5) != null?row.GetCell(5).ToString().Trim() : "";

                                entity.B_COSTCENTER = row.GetCell(6) != null?row.GetCell(6).ToString().Trim() : "";

                                int nodeLevel;
                                if (!int.TryParse(nodeLevelStr, out nodeLevel))
                                {
                                    retModel.AddError("errorMessage", i + 1 + "行5列上传的数据类型不正确!");
                                    return(Json(retModel, JsonRequestBehavior.AllowGet));
                                }
                                entity.B_NODELEVEL = nodeLevel;

                                //判断节点负责人在系统中是否存在
                                if (!string.IsNullOrEmpty(entity.B_NODEPERSONNAME))
                                {
                                    if (!UserDA.ValidLoginNameIsExist(inn, entity.B_NODEPERSONNAME))
                                    {
                                        retModel.AddError("errorMessage", i + 1 + "行4列上传的负责人不正确!");
                                        return(Json(retModel, JsonRequestBehavior.AllowGet));
                                    }
                                }
                                list.Add(entity);
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
                //string strSQL = "";
                //将数据插入数据库
                if (list != null && list.Count > 0)
                {
                    var result = OrganizationalStructureBll.DeleteOrganizationalStructure(inn);
                    if (!result.isError())
                    {
                        for (int i = 0; i < list.Count; i++)
                        {
                            var item = list[i];
                            var OrganizationalStructure = inn.newItem("b_OrganizationalStructure", "add");
                            OrganizationalStructure.setProperty("b_nodename", item.B_NODENAME);
                            OrganizationalStructure.setProperty("b_nodecode", item.B_NODECODE);
                            OrganizationalStructure.setProperty("b_parentnodecode", item.B_PARENTNODECODE);
                            OrganizationalStructure.setProperty("b_nodepersonname", item.B_NODEPERSONNAME);
                            OrganizationalStructure.setProperty("b_nodelevel", item.B_NODELEVEL.ToString());
                            OrganizationalStructure.setProperty("b_costcenter", item.B_COSTCENTER);
                            OrganizationalStructure.setProperty("b_companycode", item.B_COMPANYCODE);
                            OrganizationalStructure.apply();
                        }
                    }
                    else
                    {
                        retModel.AddError("errorMessage", result.getErrorString());
                    }
                }
            }
            catch (Exception ex)
            {
                retModel.AddError("errorMessage", ex.Message);
            }
            return(Json(retModel, JsonRequestBehavior.AllowGet));
        }
示例#4
0
        /// <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));
        }