Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="id">id ==  wg_jobtemlate - jobid</param>
        /// <returns></returns>
        public ActionResult EditList(string id)
        {
            MeasuresBLL mbll           = new MeasuresBLL();
            var         meetingjoblist = workmeetingbll.GetJobs("", "", "", "", "").Where(x => x.TemplateId == id).Select(x => x.JobId).ToList();
            var         dangers        = new DangerService().GetList("").ToList().Where(x => meetingjoblist.Contains(x.JobId)).ToList();

            foreach (DangerEntity d in dangers)
            {
                var measures        = mbll.GetMeasureList(d.Id).OrderBy(x => x.DangerSource);
                var dangertemplates = workmeetingbll.getdangertemplate(id).OrderBy(x => x.Dangerous);
                int i = 1;
                foreach (MeasuresEntity m in measures)
                {
                    d.newdanger  += "(" + i + ")." + m.DangerSource + "<br />";
                    d.newmeasure += "(" + i + ")." + m.Measure + "<br />";
                    i++;
                }
                i = 1;
                foreach (DangerTemplateEntity t in dangertemplates)
                {
                    d.olddanger  += "(" + i + ")." + t.Dangerous + "<br />";
                    d.oldmeasure += "(" + i + ")." + t.Measure + "<br />";
                    i++;
                }
            }
            ViewData["dangers"] = dangers;
            return(View());
        }
Ejemplo n.º 2
0
        public void Down(string keyValue)
        {
            HazardsourceBLL hazardsourcebll = new HazardsourceBLL();
            //查询数据
            var entity = hazardsourcebll.GetEntity(keyValue);

            //数据合并
            string[] text = new string[] { };
            if (entity.Way == "DEC")
            {
                text = new string[] { "DistrictName", "DangerSource", "AccidentName", "DeptName", "JdglzrrFullName",
                                      "Way",
                                      "ItemDecQ",
                                      "ItemDecQ1", "ItemDecB", "ItemDecB1", "ItemDecR", "IsDanger", "Grade", "MeaSure" }
            }
            ;
            else
            {
                text = new string[] { "DistrictName", "DangerSource", "AccidentName", "DeptName", "JdglzrrFullName",
                                      "Way",
                                      "ItemA",
                                      "ItemB", "ItemC", "ItemR", "IsDanger", "Grade", "MeaSure" }
            };;
            MeasuresBLL measuresbll = new MeasuresBLL();
            var         data        = measuresbll.GetList(" and riskId='" + keyValue + "'");

            var MeaSureShow = "";
            int i           = 1;

            foreach (var item in data)
            {
                MeaSureShow += i + "、" + item.Content + "\r\n";
                i++;
            }


            //if (!string.IsNullOrEmpty(entity.MeaSure))
            //{
            //    var arr = entity.MeaSure.Split(';');

            //    int i = 1;
            //    foreach (var item in arr)
            //    {
            //        MeaSureShow += i + "、" + item + "\r\n";
            //        i++;
            //    }
            //}
            string[] value      = new string[] { };
            var      tempPath   = Server.MapPath("~/Resource/Temp/辨识分级记录.doc");
            var      outputPath = Server.MapPath("~/Resource/ExcelTemplate/辨识分级记录.doc");

            if (entity.Way == "DEC")
            {
                value = new string[] {
                    entity.DistrictName,
                    entity.DangerSource,
                    entity.AccidentName,
                    entity.DeptName,
                    entity.JdglzrrFullName,
                    entity.Way == "DEC" ? "危险化学品重大危险源辨识" : "LEC法风险辨识",
                    entity.ItemDecQ,
                    entity.ItemDecQ1,
                    entity.ItemDecB.ToString(),
                    entity.ItemDecB1,
                    entity.ItemDecR.ToString(),
                    entity.IsDanger == 1 ? "是" : "否",
                    entity.GradeVal > 0 ? entity.Grade : "未定级",
                    MeaSureShow
                };
            }
            else
            {
                tempPath   = Server.MapPath("~/Resource/Temp/辨识分级记录2.doc");
                outputPath = Server.MapPath("~/Resource/ExcelTemplate/辨识分级记录2.doc");
                value      = new string[] {
                    entity.DistrictName,
                    entity.DangerSource,
                    entity.AccidentName,
                    entity.DeptName,
                    entity.JdglzrrFullName,
                    entity.Way == "DEC" ? "危险化学品重大危险源辨识" : "法风险辨识",
                    entity.ItemA.ToString(),
                    entity.ItemB.ToString(),
                    entity.ItemC.ToString(),
                    entity.ItemR.ToString(),
                    entity.IsDanger == 1 ? "是" : "否",
                    entity.GradeVal > 0 ? entity.Grade : "未定级",
                    MeaSureShow
                };
            }



            Aspose.Words.Document doc = new Aspose.Words.Document(tempPath);
            //数据合并
            doc.MailMerge.Execute(text, value);
            doc.Save(outputPath);
            //调用导出方法
            var docStream = new MemoryStream();

            doc.Save(docStream, SaveOptions.CreateSaveOptions(Aspose.Words.SaveFormat.Doc));
            Response.ContentType = "application/msword";
            Response.AddHeader("content-disposition", "attachment;filename=辨识分级记录.doc");
            Response.BinaryWrite(docStream.ToArray());
            Response.End();
        }
Ejemplo n.º 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);
        }