コード例 #1
0
ファイル: RiskController.cs プロジェクト: paddy235/ERCHTMS
        public string GetAreas(string OrgId = "")
        {
            DistrictBLL   districtBLL = new DistrictBLL();
            var           data        = districtBLL.GetList(OrgId);
            StringBuilder sb          = new StringBuilder();

            foreach (DistrictEntity dist in data)
            {
                sb.AppendFormat("<option value='{0}'>{1}</option>", dist.DistrictID, dist.DistrictName);
            }
            return(sb.ToString());
        }
コード例 #2
0
        public ActionResult GetListJson()
        {
            var data = bis_districtbll.GetList();

            return(ToJsonResult(data));
        }
コード例 #3
0
        public string ImportHazardsource()
        {
            //if (OperatorProvider.Provider.Current().IsSystem)
            //{
            //    return "超级管理员无此操作权限";
            //}
            string orgId        = OperatorProvider.Provider.Current().OrganizeId;//所属公司
            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;
                for (int i = 1; i < dt.Rows.Count; i++)
                {
                    order = i;
                    // 所属区域
                    var districtname = dt.Rows[i][0].ToString();
                    var district     = bis_districtbll.GetList().Where(e => e.DistrictName == districtname).FirstOrDefault();
                    if (district == null)
                    {
                        falseMessage += "第" + (i) + "行导入失败,所属区域不存在!</br>";
                        error++;
                        continue;
                    }
                    // 危险源名称/场所
                    var dangersource = dt.Rows[i][1].ToString();
                    //可能导致的事故类型
                    var accidentname = dt.Rows[i][2].ToString();
                    var accidenttype = "";
                    //int checkacc = 0;
                    //var listaccident = accidentname.Split(',');
                    //foreach (var item in listaccident)
                    //{
                    //    var datarow = didbll.GetListByCode("AccidentType").Select(" ItemName='" + item + "'");
                    //    if (datarow == null || datarow.Count() == 0)
                    //    {
                    //        checkacc++;
                    //    }
                    //    else
                    //    {
                    //        if (accidenttype == "")
                    //            accidenttype = datarow[0]["itemvalue"].ToString();
                    //        else
                    //            accidenttype += "," + datarow[0]["itemvalue"].ToString();

                    //    }

                    //}
                    //if (checkacc > 0)
                    //{
                    //    falseMessage += "第" + (i) + "行导入失败,可能导致的事故类型不存在!</br>";
                    //    error++;
                    //    continue;
                    //}


                    //危险源风险等级
                    string grade    = dt.Rows[i][3].ToString();
                    var    gradeval = grade == "一级" ? "1" : (grade == "二级" ? "2" : (grade == "三级" ? "3" : "4"));
                    //安全控制措施
                    var measure     = dt.Rows[i][4].ToString();
                    var listmeasure = measure.Split('&');
                    //责任部门
                    string departname = dt.Rows[i][5].ToString();
                    var    depart     = departBLL.GetList().Where(e => e.FullName == departname && e.OrganizeId == orgId).FirstOrDefault();
                    var    org        = orgBLL.GetList().Where(e => e.FullName == departname).FirstOrDefault();
                    if (depart == null && org == null)
                    {
                        falseMessage += "第" + (i) + "行导入失败,责任部门不存在!</br>";
                        error++;
                        continue;
                    }
                    //监督管理责任人
                    string fullname = dt.Rows[i][6].ToString();
                    Expression <Func <UserEntity, bool> > condition = e => e.RealName == fullname && e.OrganizeId == orgId;
                    var user = userBLL.GetListForCon(condition).FirstOrDefault();
                    if (user == null)
                    {
                        falseMessage += "第" + (i) + "行导入失败,监督管理责任人不存在!</br>";
                        error++;
                        continue;
                    }
                    //风险评价 L,E,C,D
                    string L = dt.Rows[i][7].ToString();
                    string E = dt.Rows[i][8].ToString();
                    string C = dt.Rows[i][9].ToString();
                    string D = dt.Rows[i][10].ToString();
                    //是否重大危险源
                    string isdangername = dt.Rows[i][11].ToString();
                    int?   isdanger     = isdangername == "是" ? 1 : 0;
                    try
                    {
                        var item = new HazardsourceEntity
                        {
                            ID           = Guid.NewGuid().ToString(),
                            MeaSureNum   = listmeasure.Count(),
                            DistrictName = districtname,
                            DistrictId   = district.DistrictID,
                            DangerSource = dangersource,
                            AccidentName = accidentname,
                            AccidentType = accidenttype,
                            Grade        = grade,
                            GradeVal     = Convert.ToInt32(gradeval),

                            DeptName        = departname,
                            DeptCode        = depart.EnCode,
                            JdglzrrFullName = fullname,
                            JdglzrrUserId   = user.UserId,
                            ItemA           = decimal.Parse(L),
                            ItemB           = decimal.Parse(E),
                            ItemC           = decimal.Parse(C),
                            ItemR           = decimal.Parse(D),
                            IsDanger        = isdanger,
                            Way             = "LEC",
                            Status          = 1
                        };
                        item.ID = Guid.NewGuid().ToString();
                        hazardsourcebll.SaveForm("", item);
                        var list = new List <MeasuresEntity>();
                        foreach (var item2 in listmeasure)
                        {
                            if (string.IsNullOrEmpty(item2))
                            {
                                continue;
                            }
                            list.Add(new MeasuresEntity {
                                RiskId = item.ID, Content = item2
                            });
                        }

                        var mbll = new MeasuresBLL();
                        mbll.SaveForm("", list);
                    }
                    catch
                    {
                        error++;
                    }
                }
                count    = dt.Rows.Count - 1;
                message  = "共有" + count + "条记录,成功导入" + (count - error) + "条,失败" + error + "条";
                message += "</br>" + falseMessage;
            }

            return(message);
        }