Ejemplo n.º 1
0
        public ActionResult GetTreeJson(string keyword)
        {
            var data = dataItemBLL.GetList().ToList();

            if (!string.IsNullOrEmpty(keyword))
            {
                data = data.TreeWhere(t => t.ItemName.Contains(keyword), "");
            }
            var treeList = new List <TreeEntity>();

            foreach (DataItemEntity item in data)
            {
                TreeEntity tree        = new TreeEntity();
                bool       hasChildren = data.Count(t => t.ParentId == item.ItemId) == 0 ? false : true;
                tree.id             = item.ItemId;
                tree.text           = item.ItemName;
                tree.value          = item.ItemCode;
                tree.parentId       = item.ParentId;
                tree.isexpand       = true;
                tree.complete       = true;
                tree.Attribute      = "isTree";
                tree.AttributeValue = item.IsTree.ToString();
                tree.hasChildren    = hasChildren;
                treeList.Add(tree);
            }
            return(Content(treeList.TreeToJson()));
        }
Ejemplo n.º 2
0
        public string ImportDept()
        {
            int    error        = 0;
            string message      = "请选择格式正确的文件再导入!";
            string falseMessage = "";
            int    count        = HttpContext.Request.Files.Count;

            if (count > 0)
            {
                HttpPostedFileBase file = HttpContext.Request.Files[0];
                if (string.IsNullOrEmpty(file.FileName))
                {
                    return(message);
                }
                if (!(file.FileName.Substring(file.FileName.IndexOf('.')).Contains("xls") || file.FileName.Substring(file.FileName.IndexOf('.')).Contains("xlsx")))
                {
                    return(message);
                }
                string fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + System.IO.Path.GetExtension(file.FileName);
                file.SaveAs(Server.MapPath("~/Resource/temp/" + fileName));
                DataTable dt    = ExcelHelper.ExcelImport(Server.MapPath("~/Resource/temp/" + fileName));
                int       order = 1;

                //先获取字典
                DataItemBLL di          = new DataItemBLL();
                DistrictBLL districtbll = new DistrictBLL();
                IEnumerable <DataItemDetailEntity> ReskList = di.GetList("Risk");
                IEnumerable <DistrictEntity>       AreaList = districtbll.GetOrgList(OperatorProvider.Provider.Current().OrganizeId);

                Expression <Func <UserEntity, bool> > condition;
                if (OperatorProvider.Provider.Current().IsSystem)
                {
                    condition = it => it.Account != "System" && it.IsPresence == "1";//如果是管理员
                }
                else
                {
                    string orgid = OperatorProvider.Provider.Current().OrganizeId;
                    condition = it => it.Account != "System" && it.IsPresence == "1" && it.OrganizeId == orgid;//不是管理员则查到所有本机构下的用户
                }

                //先获取到该用户下可以选择的用户
                List <UserEntity> userlist = new UserBLL().GetListForCon(condition).ToList();

                for (int i = 1; i < dt.Rows.Count; i++)
                {
                    //区域
                    string AreaName  = dt.Rows[i][0].ToString();
                    string AreaValue = "";

                    //危险源
                    string   RiskName = dt.Rows[i][1].ToString();//危险源名称
                    Operator user     = ERCHTMS.Code.OperatorProvider.Provider.Current();
                    //验证同一公司范围内是否有重复数据
                    if (!hazardfactorsbll.ExistDeptJugement(AreaName, user.OrganizeCode, RiskName))
                    {
                        falseMessage += "</br>" + "第" + (i + 2) + "行数据存在重复,未能导入.";
                        error++;
                        continue;
                    }

                    //验证区域是否有匹配项
                    if (!GetAreaIsTrue(AreaList, AreaName.Trim(), out AreaValue))
                    {
                        falseMessage += "</br>" + "第" + (i + 2) + "行值区域值不在可选范围内,未能导入.";
                        error++;
                        continue;
                    }



                    string RiskValue = "";
                    //if (Risks.Length == 0)
                    //{
                    //    falseMessage += "</br>" + "第" + (i + 2) + "行值职业病危害因素名称值为空,未能导入.";
                    //    error++;
                    //    continue;
                    //}
                    if (!GetIsTrue(ReskList, RiskName, out RiskValue))
                    {
                        falseMessage += "</br>" + "第" + (i + 2) + "行值职业病危害因素名称值不在可选范围内,未能导入.";
                        error++;
                        continue;
                    }

                    ////危险源
                    //string Num = dt.Rows[i][2].ToString();//接触人数量

                    //string pattern = "^[0-9]+$";
                    //int Contactnumber = 0;


                    ////验证是否是数字
                    //if (Regex.IsMatch(Num, pattern))
                    //{
                    //    Contactnumber = Convert.ToInt32(Num);
                    //}
                    //else if (Num.Trim() == "")
                    //{

                    //}
                    //else
                    //{
                    //    falseMessage += "</br>" + "第" + (i + 2) + "行值接触人数只能填写数字或者不填,值类型错误,未能导入.";
                    //    error++;
                    //    continue;
                    //}

                    string users = dt.Rows[i][2].ToString();
                    if (users.Trim() == "")
                    {
                        falseMessage += "</br>" + "第" + (i + 2) + "行值接触人员不能为空,未能导入.";
                        error++;
                        continue;
                    }

                    users = users.Replace(',', ',');//把所有大写,替换成小写,

                    string[] uses      = users.Split(',');
                    string   userids   = "";
                    string   errorname = "";
                    for (int j = 0; j < uses.Length; j++)
                    {
                        UserEntity ue = userlist.Where(it => it.RealName == uses[j]).FirstOrDefault();
                        if (ue == null)//如果用户不存在
                        {
                            if (errorname == "")
                            {
                                errorname = uses[j];
                            }
                            else
                            {
                                errorname += "," + uses[j];
                            }
                            continue;
                        }

                        if (j == 0)
                        {
                            userids = ue.UserId;
                        }
                        else
                        {
                            userids += "," + ue.UserId;
                        }
                    }

                    if (errorname.Trim() != "")
                    {
                        falseMessage += "</br>" + "第" + (i + 2) + "行值接触人员:" + errorname + ",值不在可选范围内,未能导入.";
                        error++;
                        continue;
                    }

                    HazardfactorsEntity hf = new HazardfactorsEntity();
                    hf.AreaId    = AreaValue;
                    hf.AreaValue = AreaName;
                    hf.Riskid    = RiskValue;
                    hf.RiskValue = RiskName;
                    if (uses.Length > 0)
                    {
                        hf.ContactNumber = uses.Length;
                    }


                    try
                    {
                        hazardfactorsbll.SaveForm("", hf, users, userids);
                    }
                    catch
                    {
                        error++;
                    }
                }
                count    = dt.Rows.Count - 1;
                message  = "共有" + count + "条记录,成功导入" + (count - error) + "条,失败" + error + "条";
                message += "</br>" + falseMessage;
            }

            return(message);
        }