Exemple #1
0
 public PipingDetailInfo()
 {
     PipingPictureInfoes = new List <PipingPictureInfo>();
     PipingDetectionInfo = new PipingDetectionInfo();
 }
        public ResponseMessage Report(string usertoken, string pipingid, string path)
        {
            ResponseMessage          result     = new ResponseMessage();
            List <PipingPictureInfo> pictures   = db.PipingPictureInfoes.ToList().FindAll(p => p.PipingID == pipingid);
            PipingDetectionInfo      pipingInfo = db.PipingDetectionInfoes.ToList().Find(p => p.PipingID == pipingid);
            string mbWord = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "\\" + "PipingInfo.doc";
            Report report = new Report();

            report.CreateNewDocument(mbWord);

            // 检测信息
            report.InsertValue("t1", pipingInfo.VideoFile);
            report.InsertValue("t2", pipingInfo.StartWellNo);
            report.InsertValue("t3", pipingInfo.EndWellNo);
            report.InsertValue("t4", pipingInfo.LayingYear);
            report.InsertValue("t5", pipingInfo.StartPointDepth);
            report.InsertValue("t6", pipingInfo.EndPointDepth);
            report.InsertValue("t7", pipingInfo.TubulationType);
            report.InsertValue("t8", pipingInfo.TubulationMaterial);
            report.InsertValue("t9", pipingInfo.TubulationDiameter);
            report.InsertValue("t10", pipingInfo.DetectionDirect);
            report.InsertValue("t11", pipingInfo.TubulationLength);
            report.InsertValue("t12", pipingInfo.DetectionLength);
            report.InsertValue("t13", pipingInfo.DetectionAddress);
            report.InsertValue("t14", pipingInfo.DetectionTime);
            report.InsertValue("XH", string.Format("{0}→{1}", pipingInfo.StartWellNo, pipingInfo.EndWellNo));
            report.InsertValue("JCFF", pipingInfo.DetectionFun);
            report.InsertValue("remark", pictures.Count > 0 ? pictures[0].Remark : string.Empty);

            pictures.OrderBy(p => p.PictureID);

            // 工程图片信息
            PipingPictureInfo picInfo = pictures.Find(p => p.PictureType == 0);

            if (picInfo != null)
            {
                report.InsertPicture("gcTP", picInfo.PictureFilePath, 220, 220);
                pictures.RemoveAll(p => p.PictureType == 0);
            }

            Table picRemarkTable = report.Document.Content.Tables[2];
            Table remarkTable    = report.Document.Content.Tables[3];
            Table picTable       = report.Document.Content.Tables[4];

            // 添加图片信息描述 + 添加图片
            for (int i = 0; i < pictures.Count; i++)
            {
                if (i > 0)
                {
                    report.AddRow(2, 1);
                }

                report.InsertCell(picRemarkTable, i + 2, 1, pictures[i].Distance);
                report.InsertCell(picRemarkTable, i + 2, 2, pictures[i].DefectCode);
                report.InsertCell(picRemarkTable, i + 2, 3, pictures[i].Score);
                report.InsertCell(picRemarkTable, i + 2, 4, pictures[i].Grade);
                report.InsertCell(picRemarkTable, i + 2, 5, pictures[i].PipingInternalState);
                report.InsertCell(picRemarkTable, i + 2, 6, pictures[i].PictureID);

                if (i == 0)
                {
                    report.InsertPicture("TP1", pictures[i].PictureFilePath, 220, 220);
                    report.InsertValue("TP1MS", pictures[i].PictureRemark);
                }
                else
                {
                    report.InsertPicture(string.Format("TP{0}", i + 1), pictures[i].PictureFilePath, 220, 220);
                    report.InsertValue(string.Format("TP{0}MS", i + 1), pictures[i].PictureRemark);
                }
            }

            // 图片的数量
            int picCount = pictures.Count;

            // 删除多余的行
            for (int i = 0; i < (5 - (picCount) / 2) * 2; i++)
            {
                report.DeleteRow(4, 12 - i);
            }

            report.Application.Visible = true;
            report.Application.Activate();
            report.Application.ShowMe();

            object what    = WdGoToItem.wdGoToBookmark;
            object name    = "KG1";
            object missing = System.Reflection.Missing.Value;

            report.Application.Selection.GoTo(what, missing, missing, name);
            SendKeys.SendWait("{DEL}");

            Thread.Sleep(10);

            name = "KG2";
            report.Application.Selection.GoTo(what, missing, missing, name);
            SendKeys.SendWait("{DEL}");

            Thread.Sleep(10);

            report.SaveDocument(path);
            result.code = "0";
            result.msg  = string.Format("生成成功!文件地址:{0}", path);
            return(result);
        }