Esempio n. 1
0
        /// <summary>
        /// 导出安全惩罚详细
        /// </summary>
        /// <param name="keyValue"></param>
        /// <returns></returns>
        public ActionResult ExportSafePunishInfo(string keyValue)
        {
            HttpResponse resp = System.Web.HttpContext.Current.Response;
            //报告对象

            string fileName   = "安全惩罚审批单_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".doc";
            string strDocPath = Request.PhysicalApplicationPath + @"Resource\ExcelTemplate\安全考核导出模板.docx";

            Aspose.Words.Document doc     = new Aspose.Words.Document(strDocPath);
            DocumentBuilder       builder = new DocumentBuilder(doc);
            DataTable             dt      = new DataTable();

            dt.Columns.Add("PunishCode");   //编号
            dt.Columns.Add("CreateDept");   //所属专业(部门)
            dt.Columns.Add("ApplyTime");    //申请时间
            dt.Columns.Add("BelongDept");   //被考核部门
            dt.Columns.Add("PunishNum");    //考核金额
            dt.Columns.Add("PunishRemark"); //事件描述
            dt.Columns.Add("filed1");       //第一个区域名称
            dt.Columns.Add("filed2");       //第二个区域名称
            dt.Columns.Add("approve1");     //第一步审核意见
            dt.Columns.Add("approvename1"); //第二步审核意见
            dt.Columns.Add("approvetime1"); //第一步审核意见
            dt.Columns.Add("approve2");     //第二步审核意见
            dt.Columns.Add("approvename2"); //第一步审核意见
            dt.Columns.Add("approvetime2"); //第二步审核意见
            DataRow row = dt.NewRow();


            //安全考核信息
            SafepunishEntity safepunishentity = safepunishbll.GetEntity(keyValue);

            row["PunishCode"]   = safepunishentity.SafePunishCode;
            row["PunishRemark"] = safepunishentity.PunishRemark;
            row["CreateDept"]   = safepunishentity.BelongDept;
            row["ApplyTime"]    = safepunishentity.ApplyTime.IsEmpty() ? "" : Convert.ToDateTime(safepunishentity.ApplyTime).ToString("yyyy-MM-dd");
            if (safepunishentity.AmerceType == "1" || safepunishentity.AmerceType == "2")
            {
                row["filed1"] = "部门意见";
                row["filed2"] = "分管领导意见";
            }
            else if (safepunishentity.AmerceType == "3" || safepunishentity.AmerceType == "4")
            {
                row["filed1"] = "专业意见";
                row["filed2"] = "部门意见";
            }

            var flist = fileinfobll.GetImageListByRecid(keyValue);

            builder.MoveToMergeField("PunishImage");
            foreach (FileInfoEntity fmode in flist)
            {
                string path = "";
                if (string.IsNullOrWhiteSpace(fmode.FilePath))
                {
                    path = Server.MapPath("~/content/Images/no_1.png");
                }
                else
                {
                    var filepath = Server.MapPath("~/") + fmode.FilePath.Replace("~/", "").ToString();
                    if (System.IO.File.Exists(filepath))
                    {
                        path = filepath;
                    }
                    else
                    {
                        path = Server.MapPath("~/content/Images/no_1.png");
                    }
                }
                builder.MoveToMergeField("RewardImage");
                builder.InsertImage(path, 200, 160);
            }


            row["approve1"]     = safepunishentity.SpecialtyOpinion;
            row["approvetime1"] = safepunishentity.CreateDate.IsEmpty() ? "" : Convert.ToDateTime(safepunishentity.CreateDate).ToString("yyyy-MM-dd");
            UserEntity createuser = new UserBLL().GetEntity(safepunishentity.CreateUserId);

            if (createuser.SignImg.IsEmpty())
            {
                row["approvename1"] = Server.MapPath("~/content/Images/no_1.png");
            }
            else
            {
                var filepath = Server.MapPath("~/") + createuser.SignImg.ToString().Replace("../../", "").ToString();
                if (System.IO.File.Exists(filepath))
                {
                    row["approvename1"] = filepath;
                }
                else
                {
                    row["approvename1"] = Server.MapPath("~/content/Images/no_1.png");
                }
            }
            builder.MoveToMergeField("approvename1");
            builder.InsertImage(row["approvename1"].ToString(), 80, 35);

            //获取被考核对象
            SafepunishdetailEntity safepunishdetailentity = safepunishdetailbll.GetListByPunishId(keyValue, "0").OrderBy(t => t.CreateDate).FirstOrDefault();

            row["BelongDept"] = departmentbll.GetEntity(safepunishdetailentity.BelongDept) == null ? "" : departmentbll.GetEntity(safepunishdetailentity.BelongDept).FullName;
            row["PunishNum"]  = safepunishdetailentity.PunishNum;
            DataTable dtAptitude = safepunishbll.GetAptitudeInfo(keyValue);

            for (int i = dtAptitude.Rows.Count - 1; i > 0; i--)
            {
                if (i == (dtAptitude.Rows.Count - 2))
                {
                    row["approve2"]     = dtAptitude.Rows[i]["auditremark"];
                    row["approvetime2"] = dtAptitude.Rows[i]["auditdate"].IsEmpty() ? "" : Convert.ToDateTime(dtAptitude.Rows[i]["auditdate"]).ToString("yyyy-MM-dd");
                    if (dtAptitude.Rows[i]["auditsignimg"].IsEmpty())
                    {
                        row["approvename2"] = Server.MapPath("~/content/Images/no_1.png");
                    }
                    else
                    {
                        var filepath = Server.MapPath("~/") + dtAptitude.Rows[i]["auditsignimg"].ToString().Replace("../../", "").ToString();
                        if (System.IO.File.Exists(filepath))
                        {
                            row["approvename2"] = filepath;
                        }
                        else
                        {
                            row["approvename2"] = Server.MapPath("~/content/Images/no_1.png");
                        }
                    }
                    builder.MoveToMergeField("approvename2");
                    builder.InsertImage(row["approvename2"].ToString(), 80, 35);
                }
            }
            dt.Rows.Add(row);
            doc.MailMerge.Execute(dt);
            doc.MailMerge.DeleteFields();

            doc.Save(resp, Server.UrlEncode(fileName), ContentDisposition.Attachment, Aspose.Words.Saving.SaveOptions.CreateSaveOptions(SaveFormat.Doc));
            return(Success("导出成功!"));
        }