12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using MSWord = Microsoft.Office.Interop.Word;
- using System.IO;
- using System.Reflection;
- namespace WpfTest1.Toolkits
- {
- class ReportGenerator
- {
- /*
- * generateReport:生成报告的方法
- * 参数:
- * patiment:病人对象
- * rcd: 报告对象
- * cfg 系统Config类
- * handFlag:0均没有,1左手,2右手,3双手
- * mw: 主界面引用
- * expressions:各参数值结果
- * rpRecord: RP环节的结果
- * generalExpressionResult: 用于自动评价风险的总表达式结果,double
- * */
- //
- public void generateReport(SQLite.Patient patient, SQLite.Record rcd, Config cfg, int handFlag,MainWindow mw, Dictionary<string,double> expressions, SQLite.doctor doct,RPCalculate rpRecord, string generalExpressionResult)
- {
- String path = Constants.reportPath;
- //String now = System.DateTime.Now.ToString("yyyyMMddHHmmss");
- /* String picName0 = path + "\\" + "0.jpg";
- String picName1 = path + "\\" + "1.jpg";
- String picName2 = path + "\\" + "2.jpg";
- String picName3 = path + "\\" + "3.jpg";
- String picName4 = path + "\\" + "4.jpg";
- */
- String fileName = path + "\\" + patient.p_record_id + "_" + patient.p_name + "_" + rcd.recordTime.ToString("yyyyMMddHHmmss") + ".doc";
- String pdfFileName = path + "\\" + patient.p_record_id + "_" + patient.p_name + "_" + rcd.recordTime.ToString("yyyyMMddHHmmss") + ".pdf";
- if (File.Exists(fileName))
- {
- try
- {
- File.Delete(fileName);
- }
- catch (Exception)
- {
- ;
- }
-
- }
- FileStream fs = new FileStream(fileName, FileMode.CreateNew);
- fs.Close();
- int space = 12;
- Object oMissing = System.Reflection.Missing.Value;
- Microsoft.Office.Interop.Word._Application WordApp = new Microsoft.Office.Interop.Word.Application();
- object filename = fileName;
- Microsoft.Office.Interop.Word._Document WordDoc = null;
- try
- {
-
- WordDoc = WordApp.Documents.Open(ref filename, ref oMissing,
- ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
- ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
- WordApp.Visible = false;
- //页面设置
- WordDoc.PageSetup.PaperSize = MSWord.WdPaperSize.wdPaperA4;//设置纸张样式为A4纸
- WordDoc.PageSetup.Orientation = MSWord.WdOrientation.wdOrientPortrait;//排列方式为垂直方向
- WordDoc.PageSetup.TopMargin = 57.0f;
- WordDoc.PageSetup.BottomMargin = 10.0f;
- WordDoc.PageSetup.LeftMargin = 57.0f;
- WordDoc.PageSetup.RightMargin = 57.0f;
- WordDoc.PageSetup.HeaderDistance = 30.0f;//页眉位置
- WordDoc.PageSetup.FooterDistance = 15.0f;
- //设置页眉
- WordApp.ActiveWindow.View.Type = Microsoft.Office.Interop.Word.WdViewType.wdOutlineView;//视图样式
- WordApp.ActiveWindow.View.SeekView = Microsoft.Office.Interop.Word.WdSeekView.wdSeekPrimaryHeader;//进入页眉设置,其中页眉边距在页面设置中已完成
- WordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight;
- //插入页眉图片(测试结果图片未插入成功)
- WordApp.Selection.ParagraphFormat.Alignment = MSWord.WdParagraphAlignment.wdAlignParagraphCenter;
- string headerfile = Constants.reportHeadPicPath;
- Console.WriteLine(headerfile);
- Microsoft.Office.Interop.Word.InlineShape shape1 = WordApp.ActiveWindow.ActivePane.Selection.InlineShapes.AddPicture(headerfile, ref oMissing, ref oMissing, ref oMissing);
- shape1.Height = 25;
- shape1.Width = 25;
- //页眉修改Test
- object unite = Microsoft.Office.Interop.Word.WdUnits.wdStory;
- object count = WordDoc.Paragraphs.Count;
- object WdLine = Microsoft.Office.Interop.Word.WdUnits.wdParagraph;
- string eyeContent = cfg.organization_name;
- //第一行
- WordApp.Selection.Font.Name = "黑体";
- WordApp.Selection.Font.Bold = 1;
- WordApp.Selection.Font.Color = MSWord.WdColor.wdColorRed;
- WordApp.Selection.Font.Size = 30;
- WordApp.Selection.Font.Spacing = 10;
- WordApp.ActiveWindow.ActivePane.Selection.InsertAfter(" " + eyeContent + "\n");
- WordApp.Selection.MoveDown(ref WdLine, ref count, ref oMissing);
- //第二行
- WordApp.Selection.Font.Name = "黑体";
- WordApp.Selection.Font.Bold = 1;
- WordApp.Selection.Font.Color = MSWord.WdColor.wdColorGray30;
- WordApp.Selection.Font.Size = 20;
- WordApp.Selection.Font.Spacing = 0;
- WordApp.ActiveWindow.ActivePane.Selection.InsertAfter("PIH检测报告单" + "\n");
- //第一行
- WordApp.Selection.MoveDown(ref WdLine, ref count, ref oMissing);
- WordApp.Selection.Font.Name = "黑体";
- WordApp.Selection.Font.Bold = 1;
- WordApp.Selection.Font.Color = MSWord.WdColor.wdColorGray30;
- WordApp.Selection.Font.Size = 10;
- string currentData = DateTime.Now.ToString("yy/MM/dd");
- WordApp.ActiveWindow.ActivePane.Selection.InsertAfter("病案编号:" + rcd.id + " " + "检查日期:" + currentData);
- //去掉页眉的横线
- //WordApp.ActiveWindow.ActivePane.Selection.ParagraphFormat.Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderBottom].LineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleNone;
- //WordApp.ActiveWindow.ActivePane.Selection.Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderBottom].Visible = false;
- WordApp.ActiveWindow.ActivePane.View.SeekView = Microsoft.Office.Interop.Word.WdSeekView.wdSeekMainDocument;//退出页眉设置
- //页脚
- WordApp.ActiveWindow.View.Type = Microsoft.Office.Interop.Word.WdViewType.wdOutlineView;
- WordApp.ActiveWindow.View.SeekView = Microsoft.Office.Interop.Word.WdSeekView.wdSeekPrimaryFooter;
- //移动光标文档末尾
- // object count = WordDoc.Paragraphs.Count;
- // object WdLine = Microsoft.Office.Interop.Word.WdUnits.wdParagraph;
- WordApp.Selection.MoveDown(ref WdLine, ref count, ref oMissing);//移动焦点
- // 去掉页脚的横线
- WordApp.ActiveWindow.ActivePane.Selection.ParagraphFormat.Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderTop].LineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
- WordApp.ActiveWindow.ActivePane.Selection.Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderBottom].Visible = true;
- //为当前页添加页码
- Microsoft.Office.Interop.Word.PageNumbers pns = WordApp.Selection.Sections[1].Headers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterEvenPages].PageNumbers;//获取当前页的号码
- pns.NumberStyle = Microsoft.Office.Interop.Word.WdPageNumberStyle.wdPageNumberStyleNumberInDash;
- pns.HeadingLevelForChapter = 0;
- pns.IncludeChapterNumber = false;
- pns.RestartNumberingAtSection = false;
- pns.StartingNumber = 0;
- object pagenmbetal = Microsoft.Office.Interop.Word.WdPageNumberAlignment.wdAlignPageNumberCenter;//将号码设置在中间
- object first = true;
- WordApp.Selection.Sections[1].Footers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterEvenPages].PageNumbers.Add(ref pagenmbetal, ref first);
- WordApp.ActiveWindow.ActivePane.View.SeekView = Microsoft.Office.Interop.Word.WdSeekView.wdSeekMainDocument;//退出页眉设置
- //插入表格
- // WordApp.Selection.EndKey(ref WdLine, ref oMissing);
- //WordApp.Selection.ParagraphFormat.Alignment = MSWord.WdParagraphAlignment.wdAlignParagraphCenter;
- int tableRow = 6;
- int tableColumn = 6;
- //定义一个word中的表格对象
- MSWord.Table table = WordDoc.Tables.Add(WordApp.Selection.Range, tableRow, tableColumn, ref oMissing, ref oMissing);
- table.Range.Font.Size = 10;
- table.Range.Font.Bold = 0;
- table.Range.ParagraphFormat.Alignment = MSWord.WdParagraphAlignment.wdAlignParagraphCenter;
- //内线
- //table.Borders.InsideLineStyle = MSWord.WdLineStyle.wdLineStyleSingle;
- table.Columns[1].Width = 70;
- table.Columns[2].Width = 120;
- table.Columns[3].Width = 60;
- table.Columns[4].Width = 70;
- table.Columns[5].Width = 80;
- //table.Columns[6].Width = 40;
- for (int i = 1; i <= 6; i = i + 2)
- {
- for (int j = 1; j <= 6; j++)
- {
- table.Cell(j, i).Range.ParagraphFormat.Alignment = MSWord.WdParagraphAlignment.wdAlignParagraphLeft;
- }
- }
- table.Cell(1, 1).Range.Text = "身份证号:";
- table.Cell(1, 2).Range.Text = patient.p_record_id;
- table.Cell(1, 3).Range.Text = "性别:";
- table.Cell(1, 4).Range.Text = "女";
- table.Cell(1, 5).Range.Text = "病例号:";
- table.Cell(1, 6).Range.Text = patient.p_record_id.ToString();
- table.Cell(2, 1).Range.Text = "姓名:";
- table.Cell(2, 2).Range.Text = patient.p_name;
- table.Cell(2, 3).Range.Text = "年龄:";
- if (patient.p_record_id.Length == 18)
- {
- //假设身份证号合法
- string birthday = patient.p_record_id.Substring(6, 8);
- //MessageBox.Show(birthday);
- if (birthday.Substring(0, 2) == "19" || birthday.Substring(0, 2) == "20")
- {
- DateTime birthdayDate = new DateTime(Convert.ToInt32(birthday.Substring(0, 4)), Convert.ToInt32(birthday.Substring(4, 2)), Convert.ToInt32(birthday.Substring(6, 2)));
- int age = Toolkits.OtherSmallFunction.getAgeByBirthDay(birthdayDate);
- table.Cell(2, 4).Range.Text = age.ToString();
- }
- else
- {
- table.Cell(2, 4).Range.Text = "--";
- }
- }
- else
- {
- table.Cell(2, 4).Range.Text = "--";
- }
- table.Cell(2, 5).Range.Text = "床号:";
- table.Cell(2, 6).Range.Text = "--";
- table.Cell(3, 1).Range.Text = "身高:";
- table.Cell(3, 2).Range.Text = patient.p_height.ToString();
- table.Cell(3, 3).Range.Text = "科别:";
- table.Cell(3, 4).Range.Text = "产科";
- table.Cell(3, 5).Range.Text = "检查部位:";
- switch (handFlag)
- {
- case 0:
- table.Cell(3, 6).Range.Text = "□左手 □右手";
- break;
- case 1:
- table.Cell(3, 6).Range.Text = "√左手 □右手";
- break;
- case 2:
- table.Cell(3, 6).Range.Text = "□左手 √右手";
- break;
- default:
- table.Cell(3, 6).Range.Text = "√左手 √右手";
- break;
- }
- table.Cell(4, 1).Range.Text = "体重:";
- table.Cell(4, 2).Range.Text = patient.p_weight.ToString();
- table.Cell(4, 3).Range.Text = "孕周:";
- //table.Cell(4, 4).Range.Text = ((DateTime.Now - patient.pregnancy_date).Days / 7 + 1).ToString(); ;
- table.Cell(4, 5).Range.Text = "孕次:";
- //table.Cell(4, 6).Range.Text = patient.pregnancy_times.ToString();
- table.Cell(5, 1).Range.Text = "科室:";
- table.Cell(5, 2).Range.Text = "--";
- table.Cell(5, 3).Range.Text = "病床号:";
- table.Cell(5, 4).Range.Text = "----";
- table.Cell(5, 5).Range.Text = "单胎/多胎:";
- table.Cell(5, 6).Range.Text = "--";
- table.Cell(6, 1).Range.Text = "病区:";
- table.Cell(6, 2).Range.Text = "--";
- table.Cell(6, 3).Range.Text = "住院号:";
- table.Cell(6, 4).Range.Text = "--";
- table.Cell(6, 5).Range.Text = "设备型号:";
- table.Cell(6, 6).Range.Text = "HC2180-D";
- Microsoft.Office.Interop.Word.Paragraph oPara1 = WordDoc.Content.Paragraphs.Add(ref oMissing);
- oPara1.Range.Text = "____________________________________________________________________________________________";
- oPara1.Range.Font.Bold = 0;
- oPara1.Range.InsertParagraphAfter();
- //分栏测试
- //参数检测部分
- /*
- oPara1.Range.Text = "血液动力学参数检测";
- oPara1.Range.Font.Bold = 0;
- oPara1.Format.SpaceAfter = space;
- oPara1.Range.InsertParagraphAfter();
- */
- //插入表格
- //WordDoc.Content.InsertAfter("\n");
- WordApp.Selection.EndKey(ref unite, ref oMissing);
- //WordApp.Selection.ParagraphFormat.Alignment = MSWord.WdParagraphAlignment.wdAlignParagraphCenter;
- //WordApp.Selection.MoveDown(ref WdLine, ref count, ref oMissing);
- int tableRow2 = 43;
- int tableColumn2 = 5;
- //定义一个word中的表格对象
- MSWord.Table table2 = WordDoc.Tables.Add(WordApp.Selection.Range, tableRow2, tableColumn2, ref oMissing, ref oMissing);
- table2.Range.Font.Size = 8;
- table2.Range.Font.Bold = 0;
- table2.Range.Rows.Height = 13;
- table2.Rows.HeightRule = MSWord.WdRowHeightRule.wdRowHeightExactly;
- table2.Range.ParagraphFormat.Alignment = MSWord.WdParagraphAlignment.wdAlignParagraphLeft;
- //内线
- //table2.Borders.InsideLineStyle = MSWord.WdLineStyle.wdLineStyleSingle;
- table2.Columns[1].Width = 95;
- table2.Columns[2].Width = 40;
- table2.Columns[3].Width = 15;
- table2.Columns[4].Width = 95;
- table2.Columns[5].Width = 250;
- //table2.Columns[6].Width = 40;
- //table2.Columns[7].Width = 15;
- //table2.Columns[8].Width = 95;
- /*for(int i=1;i<=22;i++)
- {
- table2.Rows[i].Height = 60;
- }*/
- //合并表格
- table2.Cell(1, 1).Merge(table2.Cell(1, 4));
- table2.Cell(2, 5).Merge(table2.Cell(43, 5));
- //表格文字
- table2.Cell(1, 1).Range.Text = "血液动力学参数检测结果";
- table2.Cell(2, 1).Range.Text = "收缩压SPB:";
- table2.Cell(2, 2).Range.Text = rpRecord.shousuoya.ToString();
- try
- {
- double hbp = rpRecord.shousuoya;
- if (hbp > 130)
- {
- table2.Cell(2, 3).Range.Text = "↑";
- }
- else if (hbp < 90)
- {
- table2.Cell(2, 3).Range.Text = "↓";
- }
- else
- {
- }
- }
- catch (Exception)
- {
- }
- table2.Cell(2, 4).Range.Text = "90-130mmHg";
- table2.Cell(3, 1).Range.Text = "舒张压DPB:";
- table2.Cell(3, 2).Range.Text = rpRecord.shuzhangya.ToString();
- try
- {
- double hbp = rpRecord.shuzhangya;
- if (hbp > 100)
- {
- table2.Cell(3, 3).Range.Text = "↑";
- }
- else if (hbp < 60)
- {
- table2.Cell(3, 3).Range.Text = "↓";
- }
- else
- {
- }
- }
- catch (Exception)
- {
- }
- table2.Cell(3, 4).Range.Text = "60-100mmHg";
- table2.Cell(4, 1).Range.Text = "脉压PP:";
- table2.Cell(4, 2).Range.Text = rpRecord.maiya.ToString();
- if(rpRecord.maiya > 50)
- {
- table2.Cell(4, 3).Range.Text = "↑";
- }
- else if(rpRecord.maiya < 35)
- {
- table2.Cell(4, 3).Range.Text = "↓";
- }
- table2.Cell(4, 4).Range.Text = "35-50mmHg";
- table2.Cell(5, 1).Range.Text = "平均动脉压MAP:";
- table2.Cell(5, 2).Range.Text = rpRecord.pingjundongmaiya.ToString();
- try
- {
- double hbp = rpRecord.pingjundongmaiya;
- if (hbp > 95)
- {
- table2.Cell(5, 3).Range.Text = "↑";
- }
- else if (hbp < 85)
- {
- table2.Cell(5, 3).Range.Text = "↓";
- }
- else
- {
- }
- }
- catch (Exception)
- {
- }
- table2.Cell(5, 4).Range.Text = "85-95mmHg";
- table2.Cell(6, 1).Range.Text = "血压指数BPI:";
- table2.Cell(6, 2).Range.Text = rpRecord.xueyazhishu.ToString();
- try
- {
- double hbp = rpRecord.xueyazhishu;
- if (hbp > 150)
- {
- table2.Cell(6, 3).Range.Text = "↓";
- }
- else
- {
- }
- }
- catch (Exception)
- {
- }
- table2.Cell(6, 4).Range.Text = "<150";
- table2.Cell(7, 1).Range.Text = "体表面积TBA:";
- table2.Cell(7, 2).Range.Text = rpRecord.tibiaomianji.ToString();
- table2.Cell(7, 4).Range.Text = "m*m";
- table2.Cell(8, 1).Range.Text = "血总容量BV:"; //textBoxRPzongxuerongliangHistory
- table2.Cell(8, 2).Range.Text = rpRecord.zongxuerongliang.ToString();
- table2.Cell(8, 4).Range.Text = "(参考范围)";
- table2.Cell(9, 1).Range.Text = "波形系数K:";
- table2.Cell(9, 2).Range.Text = rpRecord.boxinxishu.ToString();
- try
- {
- double hbp = rpRecord.boxinxishu;
- if (hbp > 0.4)
- {
- table2.Cell(9, 3).Range.Text = "↑";
- }
- else if (hbp < 0.33)
- {
- table2.Cell(9, 3).Range.Text = "↓";
- }
- else
- {
- }
- }
- catch (Exception)
- {
- }
- table2.Cell(9, 4).Range.Text = "0.33-0.4";
- table2.Cell(10, 1).Range.Text = "体重指数WI:";
- table2.Cell(10, 2).Range.Text = rpRecord.tizhongzhishu.ToString();
- try
- {
- double hbp = rpRecord.tizhongzhishu;
- if (hbp > 0.24)
- {
- table2.Cell(10, 3).Range.Text = "↑";
- }
- else
- {
- }
- }
- catch (Exception)
- {
- }
- table2.Cell(10, 4).Range.Text = "<0.24";
- table2.Cell(11, 1).Range.Text = "心输出量CO:";
- table2.Cell(11, 2).Range.Text = rpRecord.xinshuchuliang.ToString();
- try
- {
- double hbp = rpRecord.xinshuchuliang;
- if (hbp > 7)
- {
- table2.Cell(11, 3).Range.Text = "↑";
- }
- else if (hbp < 3)
- {
- table2.Cell(11, 3).Range.Text = "↓";
- }
- else
- {
- }
- }
- catch (Exception)
- {
- }
- table2.Cell(11, 4).Range.Text = "3-7L/min";
- table2.Cell(12, 1).Range.Text = "外周阻力TPR:";
- table2.Cell(12, 2).Range.Text = rpRecord.waizhouzuli.ToString();
- try
- {
- double hbp = rpRecord.waizhouzuli;
- if (hbp > 1.4)
- {
- table2.Cell(12, 3).Range.Text = "↑";
- }
- else if (hbp < 0.9)
- {
- table2.Cell(12, 3).Range.Text = "↓";
- }
- else
- {
- }
- }
- catch (Exception)
- {
- }
- table2.Cell(12, 4).Range.Text = "0.9-1.4PRU";
- table2.Cell(13, 1).Range.Text = "每搏量SV:";
- table2.Cell(13, 2).Range.Text = rpRecord.meiboliang.ToString();
- try
- {
- double hbp = rpRecord.meiboliang;
- if (hbp > 100)
- {
- table2.Cell(13, 3).Range.Text = "↑";
- }
- else if (hbp < 60)
- {
- table2.Cell(13, 3).Range.Text = "↓";
- }
- else
- {
- }
- }
- catch (Exception)
- {
- }
- table2.Cell(13, 4).Range.Text = "60-100ml";
- table2.Cell(14, 1).Range.Text = "心脏指数CI:";
- table2.Cell(14, 2).Range.Text = rpRecord.xinzangzhishu.ToString();
- try
- {
- double hbp = rpRecord.xinzangzhishu;
- if (hbp > 4)
- {
- table2.Cell(14, 3).Range.Text = "↑";
- }
- else if (hbp < 2.5)
- {
- table2.Cell(14, 3).Range.Text = "↓";
- }
- else
- {
- }
- }
- catch (Exception)
- {
- }
- table2.Cell(14, 4).Range.Text = "2.5-4";
- table2.Cell(15, 1).Range.Text = "心搏指数SI:";
- table2.Cell(15, 2).Range.Text = rpRecord.xinbozhishu.ToString();
- try
- {
- double hbp = rpRecord.xinbozhishu;
- if (hbp > 60)
- {
- table2.Cell(15, 3).Range.Text = "↑";
- }
- else if (hbp < 40)
- {
- table2.Cell(15, 3).Range.Text = "↓";
- }
- else
- {
- }
- }
- catch (Exception)
- {
- }
- table2.Cell(15, 4).Range.Text = "40-60ml/m*m";
- table2.Cell(16, 1).Range.Text = "顺应性AC:";
- table2.Cell(16, 2).Range.Text = rpRecord.shunyinxing.ToString();
- try
- {
- double hbp = rpRecord.shunyinxing;
- if (hbp > 2)
- {
- table2.Cell(16, 3).Range.Text = "↑";
- }
- else if (hbp < 1.2)
- {
- table2.Cell(16, 3).Range.Text = "↓";
- }
- else
- {
- }
- }
- catch (Exception)
- {
- }
- table2.Cell(16, 4).Range.Text = "1.2-2ml/mmHg";
- table2.Cell(17, 1).Range.Text = "心率HR:";
- table2.Cell(17, 2).Range.Text = rcd.heartRate.ToString();
- table2.Cell(17, 4).Range.Text = "bpm";
- table2.Cell(18, 1).Range.Text = "中心血流量CBF:";
- table2.Cell(18, 2).Range.Text = rpRecord.zhongxinxueliuliang.ToString();
- table2.Cell(19, 1).Range.Text = "血液黏度V:";
- table2.Cell(19, 2).Range.Text = rpRecord.xueyeniandu.ToString();
- try
- {
- double hbp = rpRecord.xueyeniandu;
- if (hbp > 4.5)
- {
- table2.Cell(19, 3).Range.Text = "↑";
- }
- else if (hbp < 3.8)
- {
- table2.Cell(16, 3).Range.Text = "↓";
- }
- else
- {
- }
- }
- catch (Exception)
- {
- }
- table2.Cell(19, 4).Range.Text = "3.8-4.5CP";
- table2.Cell(20, 1).Range.Text = "平均滞留时间T:";
- table2.Cell(20, 2).Range.Text = rpRecord.pingjunzhiliushijian.ToString();
- try
- {
- double hbp = rpRecord.pingjunzhiliushijian;
- if (hbp > 33)
- {
- table2.Cell(20, 3).Range.Text = "↑";
- }
- else if (hbp < 20)
- {
- table2.Cell(20, 3).Range.Text = "↓";
- }
- else
- {
- }
- }
- catch (Exception)
- {
- }
- table2.Cell(20, 4).Range.Text = "20-33s";
- //21项开始自动生成
- int startIdx = 21;
- /*
- for (int i = 0; i < expressions.Count && i + startIdx < 41; ++i)
- {
- SQLite.Expression oneExpression = SQLite.SQLiteModel.getExpressionByContent(expressions.ElementAt(i).Key);
- table2.Cell(i + startIdx, 1).Range.Text = oneExpression.expression_description;
- if (expressions.ElementAt(i).Value == Double.MinValue)
- {
- table2.Cell(i + startIdx, 2).Range.Text = "--";
- continue;
- }
- table2.Cell(i + startIdx, 2).Range.Text = expressions.ElementAt(i).Value.ToString();
- if (expressions.ElementAt(i).Value > oneExpression.upBound)
- {
- table2.Cell(i + startIdx, 3).Range.Text = "↑";
- }
- else if (expressions.ElementAt(i).Value < (oneExpression.upBound))
- {
- table2.Cell(i + startIdx, 3).Range.Text = "↓";
- }
- table2.Cell(i + startIdx, 4).Range.Text = oneExpression.downBound.ToString() + "-" + oneExpression.upBound.ToString();
- }*/
- //诊断部分
- string pailiangRemark = "";
- string zuliRemark = "";
- if (rpRecord.xpl < 4)
- {
- pailiangRemark = "低排";
- }
- else if(rpRecord.xpl > 5)
- {
- pailiangRemark = "高排";
- }
- else
- {
- pailiangRemark = "中排";
- }
- if (rpRecord.wzzl < 4)
- {
- zuliRemark = "低阻";
- }
- else if (rpRecord.wzzl > 5)
- {
- zuliRemark = "高阻";
- }
- else
- {
- zuliRemark = "中阻";
- }
- table2.Cell(2, 5).Range.Text = "自动分析结果:\n"
- + "一、参考结果\n"
- + rpRecord.cankaojieguo + "\n"
- + "二、参考指数\n"
- + "排量:" + rpRecord.xpl.ToString() + "(" + pailiangRemark + ")\n阻力:" + rpRecord.wzzl.ToString() + "(" + zuliRemark + ")\n"
- + "三、脉搏波形\n" + rcd.waveTpye + "\n"
- + "四、医师建议" + "\n风险等级:" + generalExpressionResult + "\n";// + mw.textBoxDiagnosis.Text;
- table2.Cell(2, 5).Range.Font.Size = 15;
- //自动分析结果
- /*
- oPara1.Range.Text = "______________________________________________________________________________________________________________";
- oPara1.Range.Font.Bold = fontBold;
- oPara1.Range.InsertParagraphAfter();
- */
- //插入分页符
- object oPageBreak = Microsoft.Office.Interop.Word.WdBreakType.wdPageBreak;
- WordApp.Selection.EndKey(ref unite, ref oMissing);
- WordDoc.ActiveWindow.Selection.InsertBreak(ref oPageBreak);
- //图片页
- //图片1
- WordApp.Selection.ParagraphFormat.FirstLineIndent = 80;
- oPara1.Range.Text = "\n桡动脉波形图:";
- oPara1.Range.Font.Bold = 0;
- oPara1.Range.Font.Size = 15;
- oPara1.Format.SpaceAfter = space;
- oPara1.Range.InsertParagraphAfter();
- //插图
- WordApp.Selection.EndKey(ref unite, ref oMissing);
- WordApp.Selection.ParagraphFormat.FirstLineIndent = 0;
- string picture1 = Constants.tmpRPWave;
- //定义要向文档中插入图片的位置
- object range = WordDoc.Paragraphs.Last.Range;
- //定义该图片是否为外部链接
- object linkToFile = false;//默认
- //定义插入的图片是否随word一起保存
- object saveWithDocument = true;
- //向word中写入图片
- try
- {
- WordDoc.InlineShapes.AddPicture(picture1, ref oMissing, ref oMissing, ref oMissing);
- }
- catch (Exception)
- {
- Console.WriteLine("fail to load raodongmai.");
- }
- WordApp.Selection.ParagraphFormat.Alignment = MSWord.WdParagraphAlignment.wdAlignParagraphCenter;//居中显示图片
- WordDoc.InlineShapes[1].Height = 130;
- WordDoc.InlineShapes[1].Width = 490;
- //WordDoc.Content.InsertAfter("\n");
- WordApp.Selection.EndKey(ref unite, ref oMissing);
- WordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
- WordApp.Selection.Font.Size = 10;//字体大小
- WordApp.Selection.TypeText("右侧桡动脉\n");
- WordApp.Selection.EndKey(ref unite, ref oMissing);
- oPara1.Range.Text = "____________________________________________________________________________________________";
- oPara1.Range.Font.Bold = 0;
- oPara1.Range.Font.Size = 10;
- oPara1.Range.InsertParagraphAfter();
- //图片2.3
- WordApp.Selection.EndKey(ref unite, ref oMissing);
- WordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;
- WordApp.Selection.ParagraphFormat.FirstLineIndent = 80;
- oPara1.Range.Text = cfg.report_figure_name + ":";
- oPara1.Range.Font.Bold = 0;
- oPara1.Range.Font.Size = 15;
- oPara1.Format.SpaceAfter = space;
- oPara1.Format.SpaceBefore = 0;
- oPara1.Range.InsertParagraphAfter();
- //插图
- WordApp.Selection.EndKey(ref unite, ref oMissing);
- WordApp.Selection.ParagraphFormat.FirstLineIndent = 0;
- string picture2 = Constants.tmpPPGLeftInfraredWave;
- string picture3 = Constants.tmpPPGLeftRedWave;
- string picture4 = Constants.tmpPPGRightRedWave;
- string picture5 = Constants.tmpPPGRightInfraredWave;
- //向word中写入图片
- try
- {
- WordDoc.InlineShapes.AddPicture(picture2, ref oMissing, ref oMissing, ref oMissing);
- WordDoc.InlineShapes.AddPicture(picture3, ref oMissing, ref oMissing, ref oMissing);
- WordDoc.InlineShapes.AddPicture(picture4, ref oMissing, ref oMissing, ref oMissing);
- WordDoc.InlineShapes.AddPicture(picture5, ref oMissing, ref oMissing, ref oMissing);
- }
- catch (Exception)
- {
- Console.WriteLine("fail to load a image.");
- }
- WordApp.Selection.ParagraphFormat.Alignment = MSWord.WdParagraphAlignment.wdAlignParagraphCenter;//居中显示图片
- for(int i = 2; i < 6; ++i)
- {
- WordDoc.InlineShapes[i].Height = 80;
- WordDoc.InlineShapes[i].Width = 200;
- }
-
- //WordDoc.Content.InsertAfter("\n");
- WordApp.Selection.EndKey(ref unite, ref oMissing);
- WordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
- WordApp.Selection.Font.Size = 10;//字体大小
- WordApp.Selection.TypeText("左手手指 红外光\n");
- //左手红光
- WordApp.Selection.EndKey(ref unite, ref oMissing);
- WordApp.Selection.ParagraphFormat.FirstLineIndent = 0;
- /*
- try
- {
- WordDoc.InlineShapes.AddPicture(picture3, ref oMissing, ref oMissing, ref oMissing);
- }
- catch (Exception)
- {
- Console.WriteLine("fail to load ppg Left2.");
- }
- WordApp.Selection.ParagraphFormat.Alignment = MSWord.WdParagraphAlignment.wdAlignParagraphCenter;//居中显示图片
- WordDoc.InlineShapes[3].Height = 100;
- WordDoc.InlineShapes[3].Width = 245;
- //WordDoc.Content.InsertAfter("\n");
- WordApp.Selection.EndKey(ref unite, ref oMissing);
- WordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
- WordApp.Selection.Font.Size = 10;//字体大小
- WordApp.Selection.TypeText("左手手指 红光\n");
- //右手红外光
- WordApp.Selection.EndKey(ref unite, ref oMissing);
- WordApp.Selection.ParagraphFormat.FirstLineIndent = 0;
-
- //向word中写入图片
- try
- {
- WordDoc.InlineShapes.AddPicture(picture4, ref oMissing, ref oMissing, ref oMissing);
- }
- catch (Exception)
- {
- Console.WriteLine("fail to load ppg right1.");
- }
- WordApp.Selection.ParagraphFormat.Alignment = MSWord.WdParagraphAlignment.wdAlignParagraphCenter;//居中显示图片
- WordDoc.InlineShapes[4].Height = 130;
- WordDoc.InlineShapes[4].Width = 490;
- //WordDoc.Content.InsertAfter("\n");
- WordApp.Selection.EndKey(ref unite, ref oMissing);
- WordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
- WordApp.Selection.Font.Size = 10;//字体大小
- WordApp.Selection.TypeText("右手手指 红外光\n");
- //右手红外光
- WordApp.Selection.EndKey(ref unite, ref oMissing);
- WordApp.Selection.ParagraphFormat.FirstLineIndent = 0;
-
- //向word中写入图片
- try
- {
- WordDoc.InlineShapes.AddPicture(picture5, ref oMissing, ref oMissing, ref oMissing);
- }
- catch (Exception)
- {
- Console.WriteLine("fail to load ppg right1.");
- }
- WordApp.Selection.ParagraphFormat.Alignment = MSWord.WdParagraphAlignment.wdAlignParagraphCenter;//居中显示图片
- WordDoc.InlineShapes[5].Height = 130;
- WordDoc.InlineShapes[5].Width = 490;
- //WordDoc.Content.InsertAfter("\n");
- WordApp.Selection.EndKey(ref unite, ref oMissing);
- WordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
- WordApp.Selection.Font.Size = 10;//字体大小
- WordApp.Selection.TypeText("右手手指 红光\n");
- */
- //插入分页符
- //object oPageBreak = Microsoft.Office.Interop.Word.WdBreakType.wdPageBreak;
- //WordApp.Selection.EndKey(ref unite, ref oMissing);
- // WordDoc.ActiveWindow.Selection.InsertBreak(ref oPageBreak);
- //第三页
- /*
- WordApp.Selection.EndKey(ref unite, ref oMissing);
- WordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;
- WordApp.Selection.ParagraphFormat.FirstLineIndent = 80;
- oPara1.Range.Text = "趋势图:";
- oPara1.Range.Font.Bold = 0;
- oPara1.Range.Font.Size = 15;
- oPara1.Format.SpaceBefore = space;
- oPara1.Format.SpaceAfter = space;
- oPara1.Range.InsertParagraphAfter();
- //插图
- WordApp.Selection.EndKey(ref unite, ref oMissing);
- WordApp.Selection.ParagraphFormat.FirstLineIndent = 0;
- string picture4 = "c:\\picture\\raodongmai.png";
- //定义要向文档中插入图片的位置
- //向word中写入图片
- WordDoc.InlineShapes.AddPicture(picture4, ref oMissing, ref oMissing, ref oMissing);
- WordApp.Selection.ParagraphFormat.Alignment = MSWord.WdParagraphAlignment.wdAlignParagraphCenter;//居中显示图片
- WordDoc.InlineShapes[4].Height = 130;
- WordDoc.InlineShapes[4].Width = 490;
- //WordDoc.Content.InsertAfter("\n");
- WordApp.Selection.EndKey(ref unite, ref oMissing);
- WordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
- WordApp.Selection.Font.Size = 10;//字体大小
- WordApp.Selection.TypeText("IPR 右侧桡动脉\n");
- WordApp.Selection.EndKey(ref unite, ref oMissing);
- oPara1.Range.Text = "________________________________________________________________________________________________________________";
- oPara1.Range.Font.Bold = 0;
- oPara1.Range.Font.Size = 10;
- oPara1.Format.SpaceAfter = 0;
- oPara1.Range.InsertParagraphAfter();
- //图片2.3
- WordApp.Selection.EndKey(ref unite, ref oMissing);
- WordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;
- WordApp.Selection.ParagraphFormat.FirstLineIndent = 80;
- oPara1.Range.Text = "趋势图:";
- oPara1.Range.Font.Bold = 0;
- oPara1.Range.Font.Size = 15;
- oPara1.Format.SpaceAfter = space;
- oPara1.Range.InsertParagraphAfter();
- //插图
- WordApp.Selection.EndKey(ref unite, ref oMissing);
- WordApp.Selection.ParagraphFormat.FirstLineIndent = 0;
- string picture5 = "c:\\picture\\2.png";
- //向word中写入图片
- WordDoc.InlineShapes.AddPicture(picture5, ref oMissing, ref oMissing, ref oMissing);
- WordApp.Selection.ParagraphFormat.Alignment = MSWord.WdParagraphAlignment.wdAlignParagraphCenter;//居中显示图片
- WordDoc.InlineShapes[5].Height = 130;
- WordDoc.InlineShapes[5].Width = 490;
- //WordDoc.Content.InsertAfter("\n");
- WordApp.Selection.EndKey(ref unite, ref oMissing);
- WordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
- WordApp.Selection.Font.Size = 10;//字体大小
- WordApp.Selection.TypeText("RI 左手手指 红外光\n");
- WordApp.Selection.EndKey(ref unite, ref oMissing);
- WordApp.Selection.ParagraphFormat.FirstLineIndent = 0;
- string picture6 = "c:\\picture\\3.png";
- //向word中写入图片
- WordDoc.InlineShapes.AddPicture(picture6, ref oMissing, ref oMissing, ref oMissing);
- WordApp.Selection.ParagraphFormat.Alignment = MSWord.WdParagraphAlignment.wdAlignParagraphCenter;//居中显示图片
- WordDoc.InlineShapes[6].Height = 130;
- WordDoc.InlineShapes[6].Width = 490;
- //WordDoc.Content.InsertAfter("\n");
- WordApp.Selection.EndKey(ref unite, ref oMissing);
- WordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
- WordApp.Selection.Font.Size = 10;//字体大小
- WordApp.Selection.TypeText("RI 右手手指 红外光\n");
- WordApp.Selection.EndKey(ref unite, ref oMissing);
- //*/
- oPara1.Range.Text = "____________________________________________________________________________________________";
- oPara1.Range.Font.Bold = 0;
- oPara1.Range.Font.Size = 10;
- oPara1.Format.SpaceBefore = 0;
- oPara1.Format.SpaceAfter = 0;
- oPara1.Range.InsertParagraphAfter();
- //医师签名
- WordApp.Selection.EndKey(ref unite, ref oMissing);
- WordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;
- WordApp.Selection.ParagraphFormat.FirstLineIndent = 150;
- oPara1.Range.Text = "检查医师:" + doct.name + " 医师签名:";
- oPara1.Range.Font.Bold = 0;
- oPara1.Range.Font.Size = 15;
- oPara1.Format.SpaceAfter = 0;
- oPara1.Format.SpaceBefore = 0;
- oPara1.Range.InsertParagraphAfter();
- // object LinkToFile = false;
- object SaveWithDocument = true;
- // object Anchor = WordDoc.Application.Selection.Range;
- /*
- WordApp.Selection.MoveDown(ref WdLine, ref count, ref oMissing);//移动焦点
- WordDoc.Application.ActiveDocument.InlineShapes.AddPicture(picName4, ref LinkToFile, ref SaveWithDocument, ref Anchor);
- WordApp.Selection.MoveDown(ref WdLine, ref count, ref oMissing);//移动焦点
- WordDoc.Application.ActiveDocument.InlineShapes.AddPicture(picName3, ref LinkToFile, ref SaveWithDocument, ref Anchor);
- WordApp.Selection.MoveDown(ref WdLine, ref count, ref oMissing);//移动焦点
- WordDoc.Application.ActiveDocument.InlineShapes.AddPicture(picName2, ref LinkToFile, ref SaveWithDocument, ref Anchor);
- WordApp.Selection.MoveDown(ref WdLine, ref count, ref oMissing);//移动焦点
- WordDoc.Application.ActiveDocument.InlineShapes.AddPicture(picName1, ref LinkToFile, ref SaveWithDocument, ref Anchor);
- WordApp.Selection.MoveDown(ref WdLine, ref count, ref oMissing);//移动焦点
- WordDoc.Application.ActiveDocument.InlineShapes.AddPicture(picName0, ref LinkToFile, ref SaveWithDocument, ref Anchor);
- */
- //保存
- WordDoc.Save();
- WordDoc.ExportAsFixedFormat(pdfFileName, Microsoft.Office.Interop.Word.WdExportFormat.wdExportFormatPDF, true);
-
- }
- catch (Exception e)
- {
- Console.WriteLine(e.Message);
- Console.WriteLine(e.StackTrace);
-
- }
- finally
- {
- //try
- //{
- WordDoc.Close(ref oMissing, ref oMissing, ref oMissing);
- WordApp.Quit(ref oMissing, ref oMissing, ref oMissing);
- //}
- //catch (Exception)
- //{
- //}
-
- try
- {
- File.Delete(fileName);
- }
- catch (Exception)
- {
- ;
- }
- }
- }
- }
- }
|