Esempio n. 1
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();
        }