예제 #1
0
        public string ImportObj(string objname, string objid, string objtype, string qyid, string qyname)
        {
            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);
                }
                objtype = string.IsNullOrEmpty(objtype) ? "3" : objtype;
                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         success     = 0;
                DistrictBLL districtbll = new DistrictBLL();
                //先获取区域
                IEnumerable <DistrictEntity> AreaList = districtbll.GetOrgList(OperatorProvider.Provider.Current().OrganizeId);
                List <SaftyCheckModel>       sclist   = new List <SaftyCheckModel>();
                for (int i = 1; i < dt.Rows.Count; i++)
                {
                    string checkObj = dt.Rows[i][0].ToString(); //检查对象
                    string content  = dt.Rows[i][1].ToString(); //检查内容
                    // string desc = dt.Rows[i][2].ToString();//隐患描述
                    if (!string.IsNullOrEmpty(objname))         //选择了检查对象的情况下区域用对象中的数据
                    {
                        if (!string.IsNullOrEmpty(content))
                        {
                            string[] arrContent = content.TrimEnd('$').Split('$');

                            foreach (string str in arrContent)
                            {
                                if (!string.IsNullOrWhiteSpace(str))
                                {
                                    SaftyCheckModel sc = new SaftyCheckModel();
                                    sc.CheckObject     = objname;
                                    sc.CheckObjectId   = objid;
                                    sc.CheckObjectType = objtype;
                                    sc.CheckContent    = str;
                                    sc.RiskName        = "";
                                    if (AreaList.Where(it => it.DistrictID == qyid).FirstOrDefault() != null)
                                    {
                                        sc.BelongDistrictCode = AreaList.Where(it => it.DistrictID == qyid).FirstOrDefault().DistrictCode;
                                    }
                                    //else
                                    //{
                                    //    falseMessage += "</br>" + "检查对象区域值不在可选范围内,未能导入.";
                                    //    error++;
                                    //    continue;
                                    //}
                                    sc.BelongDistrictID = qyid;
                                    sc.BelongDistrict   = qyname;
                                    sclist.Add(sc);
                                    success++;
                                }
                            }
                        }
                    }
                    else//选择对象情况下用对象的区域  没有对象的情况下 才用导入文档中区域
                    {
                        if (!string.IsNullOrEmpty(content))
                        {
                            string[] arrContent = content.TrimEnd('$').Split('$');
                            objid = Guid.NewGuid().ToString();
                            int j = 0;
                            foreach (string str in arrContent)
                            {
                                if (!string.IsNullOrWhiteSpace(str))
                                {
                                    SaftyCheckModel sc = new SaftyCheckModel();
                                    sc.CheckObject     = checkObj;
                                    sc.CheckObjectId   = objid;
                                    sc.CheckObjectType = "";
                                    sc.CheckContent    = str;
                                    sc.RiskName        = "";
                                    sclist.Add(sc);
                                    success++;
                                }
                            }
                        }
                    }
                }

                //将导入成功的数据存入缓存中
                CacheHelper.SetChache(sclist, "SaftyCheck");
                count    = dt.Rows.Count - 1;
                message  = "共有" + success + "条记录,成功导入" + (success - error) + "条,失败" + error + "条";
                message += "</br>" + falseMessage;
            }

            return(message);
        }
예제 #2
0
        public ActionResult GetCurListJson(string areaId = "", string mode = "", string planId = "", string dataType = "", string objId = "", string areaName = "")
        {
            try
            {
                var curUser = new OperatorProvider().Current();
                List <DistrictEntity> list = new List <DistrictEntity>();
                if (!string.IsNullOrEmpty(objId))
                {
                    list = bis_districtbll.GetOrgList(objId).ToList();
                }
                else
                {
                    list = bis_districtbll.GetList().ToList();
                }
                if (!string.IsNullOrWhiteSpace(areaName))
                {
                    list = list.Where(t => t.DistrictName.Contains(areaName.Trim())).ToList();
                }
                List <DistrictEntity> allList      = bis_districtbll.GetOrgList(curUser.OrganizeId).ToList();
                List <DistrictEntity> districtdata = list;
                if (!curUser.IsSystem && string.IsNullOrEmpty(objId))
                {
                    districtdata = districtdata.Where(p => p.OrganizeId == curUser.OrganizeId).ToList();
                }

                if (string.IsNullOrEmpty(areaId))
                {
                    if (mode == "1")
                    {
                        RiskPlanBLL plan = new RiskPlanBLL();
                        areaId       = plan.GetPlanAreaIds(0, planId);
                        districtdata = districtdata.Where(t => !areaId.Contains(t.DistrictID) && t.DistrictID != "0").ToList();

                        List <DistrictEntity> list1 = districtdata.Where(t => t.DistrictCode.Length > 6).ToList();
                        foreach (DistrictEntity entity in list1)
                        {
                            if (entity.DistrictCode.Length >= 6)
                            {
                                string code = entity.DistrictCode.Substring(0, 6);
                                var    d    = districtdata.Where(t => t.DistrictCode == code);
                                if (districtdata.Where(t => t.DistrictCode == code).Count() == 0)
                                {
                                    DistrictEntity de = list.Where(t => t.DistrictCode == code).FirstOrDefault();
                                    if (!districtdata.Contains(de))
                                    {
                                        districtdata.Add(de);
                                    }
                                }
                            }
                        }
                    }
                    //else
                    //{
                    //    districtdata = districtdata.Where(t => areaId.Contains(t.DistrictID) && t.DistrictID != "0").ToList();
                    //}
                    List <TreeGridEntity> treeList = new List <TreeGridEntity>();

                    string parentId = "0";
                    if (!string.IsNullOrWhiteSpace(areaName) && districtdata.Count > 0)
                    {
                        districtdata = GetParentId(districtdata, allList);
                        // parentId = districtdata[0].ParentID;
                    }
                    districtdata = districtdata.OrderBy(a => a.DistrictCode).ThenBy(a => a.SortCode).ToList();
                    foreach (DistrictEntity item in districtdata)
                    {
                        TreeGridEntity tree        = new TreeGridEntity();
                        int            count       = districtdata.Count(t => t.DistrictCode.StartsWith(item.DistrictCode));
                        int            count1      = districtdata.Count(t => t.DistrictCode.StartsWith(item.DistrictCode) && t.DistrictCode != item.DistrictCode);
                        bool           hasChildren = count1 == 0 ? false : true;
                        tree.id          = item.DistrictID;
                        tree.parentId    = item.ParentID;
                        tree.expanded    = false;
                        tree.hasChildren = hasChildren;
                        tree.childCount  = count;
                        tree.code        = item.DistrictCode;
                        string itemJson = item.ToJson();
                        tree.entityJson = itemJson;
                        treeList.Add(tree);
                    }
                    return(Content(treeList.TreeJson(parentId)));
                }
                else
                {
                    if (mode == "1")
                    {
                        RiskPlanBLL plan = new RiskPlanBLL();
                        string      ids  = plan.GetPlanAreaIds(0, planId);
                        if (!string.IsNullOrEmpty(ids) && dataType.Equals("0"))
                        {
                            areaId       = ids;
                            districtdata = districtdata.Where(t => !areaId.Contains(t.DistrictID) && t.DistrictID != "0").ToList();
                        }
                        else
                        {
                            if (dataType == "0")
                            {
                                districtdata = districtdata.Where(t => t.DistrictID != "0").ToList();
                            }
                            else
                            {
                                districtdata = districtdata.Where(t => areaId.Contains(t.DistrictID) && t.DistrictID != "0").ToList();
                            }
                        }
                        List <DistrictEntity> list1 = districtdata.Where(t => t.DistrictCode.Length > 6).ToList();
                        foreach (DistrictEntity entity in list1)
                        {
                            if (entity.DistrictCode.Length >= 6)
                            {
                                string code = entity.DistrictCode.Substring(0, 6);
                                if (districtdata.Where(t => t.DistrictCode == code).Count() == 0)
                                {
                                    DistrictEntity de = list.Where(t => t.DistrictCode == code).FirstOrDefault();
                                    if (!districtdata.Contains(de))
                                    {
                                        districtdata.Add(de);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        districtdata = districtdata.Where(t => areaId.Contains(t.DistrictID) && t.DistrictID != "0").ToList();
                    }
                    districtdata = districtdata.OrderBy(a => a.DistrictCode).ThenBy(a => a.SortCode).ToList();

                    var JsonData = new
                    {
                        rows    = districtdata,
                        total   = 1,
                        page    = 1,
                        records = districtdata.Count
                    };
                    return(Content(JsonData.ToJson()));
                }
            }
            catch (Exception ex)
            {
                return(Error(ex.ToString()));
            }
        }
예제 #3
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);
        }