public static void QuitMsWordApp(bool isSaveDocument)
 {
     try
     {
         object saveOptionsObject = isSaveDocument ? WdSaveOptions.wdSaveChanges : WdSaveOptions.wdDoNotSaveChanges;
         if (_doc != null)
         {
             _doc.Close(ref saveOptionsObject, ref _objMiss, ref _objMiss);
             _doc.Application.Quit(ref _objMiss, ref _objMiss, ref _objMiss);
         }
     }
     catch { }
     finally
     {
         //--Closing the Word Application
         if (_msWord != null)
         {
             _msWord.Quit(ref _objMiss, ref _objMiss, ref _objMiss);
         }
         _doc    = null;
         _msWord = null;
         GC.Collect();
         GC.WaitForPendingFinalizers();
         GC.Collect();
         GC.WaitForPendingFinalizers();
     }
 }
Exemple #2
0
 private void QuitWPS(ref Word.Application wps, ref Document doc)
 {
     try
     {
         if (doc != null)
         {
             //doc.Save();
             doc.Close(false);
         }
         //无论是否成功,都退出
         if (wps != null)
         {
             PrintLog("Convert Word file To PDF end");
             wps.Quit(false);
         }
     }
     catch (Exception ex)
     {
         PrintLog(ex.Message.ToString());
         //m_nConvertStatus = EErrorType.OTP_EXCEPTION_FAILED;
     }
     finally
     {
         doc = null;
         wps = null;
     }
 }
Exemple #3
0
        void dayReport(DateTime dates)
        {
            try
            {
                //if (dates.Year == DateTime.Now.Year && dates.Month == DateTime.Now.Month && dates.Day == DateTime.Now.Day)
                //{
                //    MessageBox.Show("只能选择今天之前的日期查看");
                //    return;
                //}
                string date = Form1.str + "//日报表" + dates.ToShortDateString() + ".doc";
                File.Copy(Form1.str + "//day.doc", date, true);
                this.axFramerControl1.Open(date);
                this.axFramerControl1.set_EnableFileCommand(DSOFramer.dsoFileCommandType.dsoFileSave, false);
                this.axFramerControl1.Toolbars = false;
                this.axFramerControl1.Titlebar = false;
                //写保护,只能读取
                Object myObj = this.axFramerControl1.ActiveDocument;
                if (myObj == null)
                {
                    return;
                }

                Word.Document    wdoc            = (Word.Document)myObj;
                Word.Application ThisApplication = wdoc.Application;
                object           missing         = Type.Missing;
                //wdoc.Protect(Word.WdProtectionType.wdAllowOnlyFormFields, ref missing, ref missing, ref missing, ref missing);
                FillCommonTable(wdoc, _dat_day.Value, "d");
            }
            catch (Exception ex)
            {
                MessageBox.Show("创建日报表出错!" + ex.Message);
            }
        }
Exemple #4
0
 /// <summary>
 /// 写入内容
 /// </summary>
 /// <param name="wordApp"></param>
 /// <param name="content"></param>
 /// <param name="spaceNum"></param>
 protected static void WriteBody(Word.Application wordApp, string content, int spaceNum)
 {
     wordApp.Selection.TypeParagraph();
     wordApp.Selection.ParagraphFormat.LeftIndent = Public.StaticVariable.BodyTitleFontSize * spaceNum;
     wordApp.Selection.Font.Size = Public.StaticVariable.BodyFontSize;
     wordApp.Selection.Font.Bold = Public.StaticVariable.BodyFontBold;
     wordApp.Selection.Font.Name = Public.StaticVariable.BodyFontName;
     wordApp.Selection.TypeText(content);
 }
Exemple #5
0
        public void fSpellCheck(TextBox tBox, Label lLbl)
        {
            int iErrorCount = 0;

            Word.Application app = new Word.Application();
            if (tBox.Text.Length > 0)
            {
                app.Visible = false;
                // Setting these variables is comparable to passing null to the function.
                // This is necessary because the C# null cannot be passed by reference.
                object template     = Missing.Value;
                object newTemplate  = Missing.Value;
                object documentType = Missing.Value;
                object visible      = true;
                object optional     = Missing.Value;

                _Document doc = app.Documents.Add(ref template, ref newTemplate, ref documentType, ref visible);
                doc.Words.First.InsertBefore(tBox.Text);
                Word.ProofreadingErrors we = doc.SpellingErrors;
                iErrorCount = we.Count;

                doc.CheckSpelling(ref optional, ref optional, ref optional, ref optional,
                                  ref optional, ref optional, ref optional,
                                  ref optional, ref optional, ref optional, ref optional, ref optional);

                if (iErrorCount == 0)
                {
                    lLbl.Text = "Spelling OK. No errors corrected ";
                }
                else if (iErrorCount == 1)
                {
                    lLbl.Text = "Spelling OK. 1 error corrected ";
                }
                else
                {
                    lLbl.Text = "Spelling OK. " + iErrorCount + " errors corrected ";
                }
                object first = 0;
                object last  = doc.Characters.Count - 1;

                tBox.Text = doc.Range(ref first, ref last).Text;
            }
            else
            {
                lLbl.Text = "Textbox is empty";
            }

            object saveChanges    = false;
            object originalFormat = Missing.Value;
            object routeDocument  = Missing.Value;

            app.Quit(ref saveChanges, ref originalFormat, ref routeDocument);
        }
Exemple #6
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            /*
             * Excel.Application app = new ApplicationClass();
             * Workbooks workBooks = app.Workbooks;
             * Workbook workBook = (Workbook )workBooks.GetType().InvokeMember("Open",BindingFlags.InvokeMethod,null,workBooks,new object[]{@"C:\Documents and Settings\raghunandanr\Desktop\Template Format for PDF Transcription1.xls"});
             * workBook.PrintOut(Type.Missing,Type.Missing,1,false,Type.Missing,false,true,Type.Missing);
             * workBook.Close(false,Type.Missing,Type.Missing);
             * app.Quit();
             * Marshal.ReleaseComObject(app);
             * app = null;
             * GC.Collect();
             * GC.WaitForPendingFinalizers();
             */
            Word.Application app = null;
            try
            {
                app = new ApplicationClass();
                //Document doc = new DocumentClass();
                Document doc          = (Document)typeof(Documents).InvokeMember("Open", BindingFlags.InvokeMethod, null, app.Documents, new object[] { @"C:\Documents and Settings\raghunandanr\Desktop\Word_template_prototype.doc" });
                object   myTrue       = true;
                object   myFalse      = false;
                object   missingValue = Type.Missing;
                object   range        = WdPrintOutRange.wdPrintCurrentPage;
                object   items        = WdPrintOutItem.wdPrintDocumentContent;
                object   copies       = "1";
                object   pages        = "1";
                object   pageType     = WdPrintOutPages.wdPrintAllPages;

                doc.PrintOut(ref myTrue, ref myFalse, ref range,
                             ref missingValue, ref missingValue, ref missingValue,
                             ref items, ref copies, ref pages, ref pageType, ref myFalse,
                             ref myTrue, ref missingValue, ref myFalse, ref missingValue,
                             ref missingValue, ref missingValue, ref missingValue);
                typeof(Document).InvokeMember("Close", BindingFlags.InvokeMethod, null, doc, new object[] {});
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
                try
                {
                    if (app != null)
                    {
                        typeof(Word.Application).InvokeMember("Quit", BindingFlags.InvokeMethod, null, app, new object[] {});
                        Marshal.ReleaseComObject(app);
                        app = null;
                        GC.Collect();
                        GC.WaitForPendingFinalizers();
                    }
                }
                catch {}
            }
        }
Exemple #7
0
        public void OnStartupComplete(ref Array custom)
        {
            Process[] processes = Process.GetProcesses();
            foreach (Process process in processes)
            {
                if (process.ProcessName.ToLower() == "wps")
                {
                    Console.WriteLine(process.ProcessName + "进程已启动");

                    wpsapp = app as Word.Application;
                    wpsapp.DocumentBeforeClose += new ApplicationEvents4_DocumentBeforeCloseEventHandler(wpsapp_DocumentBeforeClose);

                    break;
                }
            }
        }
        //转化
        public static void WordToHtmlFile(string WordFilePath, string htmlpath)
        {
            try
            {
                Word.Application newApp = new Word.Application();
                // 指定原文件和目标文件
                object Source = WordFilePath;
                //string SaveHtmlPath = WordFilePath.Substring(0, WordFilePath.Length - 3) + "html";
                object Target = htmlpath;

                // 缺省参数
                object Unknown = Type.Missing;

                //为了保险,只读方式打开
                object readOnly = true;

                // 打开doc文件
                Word.Document doc = newApp.Documents.Open(ref Source, ref Unknown,
                                                          ref readOnly, ref Unknown, ref Unknown,
                                                          ref Unknown, ref Unknown, ref Unknown,
                                                          ref Unknown, ref Unknown, ref Unknown,
                                                          ref Unknown, ref Unknown, ref Unknown,
                                                          ref Unknown, ref Unknown);

                // 指定另存为格式(rtf)
                object format = Word.WdSaveFormat.wdFormatHTML;
                // 转换格式
                doc.SaveAs(ref Target, ref format,
                           ref Unknown, ref Unknown, ref Unknown,
                           ref Unknown, ref Unknown, ref Unknown,
                           ref Unknown, ref Unknown, ref Unknown,
                           ref Unknown, ref Unknown, ref Unknown,
                           ref Unknown, ref Unknown);

                // 关闭文档和Word程序
                doc.Close(ref Unknown, ref Unknown, ref Unknown);
                newApp.Quit(ref Unknown, ref Unknown, ref Unknown);
            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show(e.Message);
            }
        }
Exemple #9
0
        void yearReport(DateTime dates)
        {
            try
            {
                if (dates > DateTime.Now)
                {
                    MessageBox.Show("只能选择本月之前的日期查看");
                    return;
                }

                string date = Form1.str + "//年报表" + dates.Year.ToString("d4") + ".doc";
                File.Copy(Form1.str + "//year.doc", date, true);
                this.axFramerControl1.Open(date);
                this.axFramerControl1.set_EnableFileCommand(DSOFramer.dsoFileCommandType.dsoFileSave, false);
                this.axFramerControl1.Toolbars = false;
                this.axFramerControl1.Titlebar = false;
                //写保护,只能读取
                Object myObj = this.axFramerControl1.ActiveDocument;
                if (myObj == null)
                {
                    return;
                }

                Word.Document    wdoc            = (Word.Document)myObj;
                Word.Application ThisApplication = wdoc.Application;
                object           missing         = Type.Missing;
                //wdoc.Protect(Word.WdProtectionType.wdAllowOnlyFormFields, ref missing, ref missing, ref missing, ref missing);
                try
                {
                    FillCommonTable(wdoc, dates, "y");
                }
                catch (Exception ex)
                {
                    MessageBox.Show("adf" + ex.Message + ex.StackTrace);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("创建月报表出错!" + ex.Message);
            }
        }
        /// <summary>

        ///This method creates ms-word from template.

        /// </summary>
        public static void CreateMsWordFromTemplate()
        {
            try
            {
                if (_msWord == null)
                {
                    _msWord = new Word.Application();
                }
                // add blank documnet in word application

                if (_template == null)
                {
                    return;
                }

                _doc = _msWord.Documents.Open(ref _template, ref _objMiss, ref _objMiss, ref _objMiss, ref _objMiss);

                _doc.Activate();
            }

            catch (Exception ex) { MessageBox.Show(ex.ToString()); }
        }
Exemple #11
0
        private void toolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            try
            {
                string dahid = "";
                if (_recordInfo.MediCard != "")
                {
                    dahid = HIS.EMR_BLL.OP_EmrDataUpdate.GetPatFileId(_recordInfo.MediCard, _recordInfo.PatName);
                }
                else
                {
                    FrmPatList form = new FrmPatList(HIS.EMR_BLL.OP_EmrDataUpdate.GetPatFileId(_recordInfo.PatName));
                    form.ShowDialog();
                    if (form.IsSure)
                    {
                        dahid = form.SelectedFileId;
                    }
                }
                if (dahid.Trim() != "")
                {
                    object           oMissing = Missing.Value;
                    Word.Application wordApp  = new Word.Application();
                    wordApp.Visible = true;
                    wordApp.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);

                    //内容
                    wordApp.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
                    wordApp.Selection.Font.Size = 10;
                    wordApp.Selection.TypeText(HIS.EMR_BLL.OP_EmrDataUpdate.GetZhxx(dahid, ((ToolStripMenuItem)sender).Tag.ToString()));
                }
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }
Exemple #12
0
        /// <summary>
        /// 转换DOC到PDF
        /// </summary>
        /// <param name="wpsFilename">原始文件</param>
        /// <param name="pdfFilename">转换后pdf文件</param>
        private void ConvertDocToPdf()
        {
            PrintLog("Start Convert Word Office file To PDF");
            Word.Application wps = new Word.Application();
            Document         doc = null;

            try
            {
                // Is NULL
                if (m_strOfficeName == null || m_strPDFName == null)
                {
                    m_nConvertStatus = EErrorType.OTP_FILENAME_EMPTY;
                }
                else
                {
                    // To PDF
                    //忽略警告提示
                    wps.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone;
                    wps.Visible       = false;
                    doc = wps.Documents.Open(m_strOfficeName, Type.Missing, true);
                    doc.ExportAsFixedFormat(m_strPDFName, WdExportFormat.wdExportFormatPDF /*, false,Word.WdExportOptimizeFor.wdExportOptimizeForPrint, Word.WdExportRange.wdExportAllDocument, 0, 0*/);

                    QuitWPS(ref wps, ref doc);
                    // To JPG
                    ConvertPDF2ImageO2S(m_strPDFName);
                }
            }
            catch (Exception ex)
            {
                PrintLog(ex.Message.ToString());
                m_nConvertStatus = EErrorType.OTP_EXCEPTION_FAILED;
            }
            finally
            {
                QuitWPS(ref wps, ref doc);
            }
        }
Exemple #13
0
        /// <summary>
        /// 读取 word文档 返回内容
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public static string GetWordContent(string filePath)
        {
            try
            {
                Word._Application app   = new Word.Application();
                Type           wordType = app.GetType();
                Word._Document doc      = null;
                object         unknow   = Type.Missing;
                app.Visible = false;
                object file = filePath;
                doc = app.Documents.Open(ref file,
                                         ref unknow, ref unknow, ref unknow, ref unknow,
                                         ref unknow, ref unknow, ref unknow, ref unknow,
                                         ref unknow, ref unknow, ref unknow, ref unknow,
                                         ref unknow, ref unknow, ref unknow);
                int           count = doc.Paragraphs.Count;
                StringBuilder sb    = new StringBuilder();
                for (int i = 1; i <= count; i++)
                {
                    sb.Append(doc.Paragraphs[i].Range.Text.Trim());
                }

                doc.Close(ref unknow, ref unknow, ref unknow);
                wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, app, null);
                doc = null;
                app = null;
                //垃圾回收
                //GC.Collect();
                //GC.WaitForPendingFinalizers();
                return(sb.ToString());
            }
            catch
            {
                return("");
            }
        }
Exemple #14
0
        /// <summary>
        /// 初始化打印控件
        /// </summary>
        /// <param name="wordApp"></param>
        /// <param name="xmlDoc"></param>
        /// <param name="type"></param>
        protected void InitWordApplication(Word.Application wordApp, XmlDocument xmlDoc, Public.EMRType type)
        {
            object oMissing = Missing.Value;

            wordApp.Visible = true;
            wordApp.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
            //设置页边距
            wordApp.ActiveDocument.PageSetup.TopMargin    = wordApp.CentimetersToPoints(float.Parse("1"));   //上页边距
            wordApp.ActiveDocument.PageSetup.BottomMargin = wordApp.CentimetersToPoints(float.Parse("1.5")); //上页边距
            wordApp.ActiveDocument.PageSetup.LeftMargin   = wordApp.CentimetersToPoints(float.Parse("2.5")); //上页边距
            wordApp.ActiveDocument.PageSetup.RightMargin  = wordApp.CentimetersToPoints(float.Parse("2.5")); //上页边距

            //设置边线
            wordApp.ActiveDocument.Sections[1].Borders.DistanceFrom = WdBorderDistanceFrom.wdBorderDistanceFromText;
            wordApp.ActiveDocument.Sections[1].Borders[WdBorderType.wdBorderTop].LineStyle    = WdLineStyle.wdLineStyleNone;
            wordApp.ActiveDocument.Sections[1].Borders[WdBorderType.wdBorderBottom].LineStyle = WdLineStyle.wdLineStyleSingle;
            wordApp.ActiveDocument.Sections[1].Borders[WdBorderType.wdBorderLeft].LineStyle   = WdLineStyle.wdLineStyleSingle;
            wordApp.ActiveDocument.Sections[1].Borders[WdBorderType.wdBorderRight].LineStyle  = WdLineStyle.wdLineStyleNone;

            // 添加页眉
            wordApp.ActiveWindow.View.Type     = WdViewType.wdOutlineView;
            wordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekPrimaryHeader;
            object styleType = "正文";
            object style     = wordApp.ActiveDocument.Styles.get_Item(ref styleType);

            wordApp.Selection.set_Style(ref style);

            //医院名称
            wordApp.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
            wordApp.Selection.Font.Size = 16;//字体加大
            wordApp.Selection.Font.Bold = 1;
            wordApp.Selection.TypeText(HIS.SYSTEM.BussinessLogicLayer.Classes.BaseData.WorkName);
            //标题
            wordApp.Selection.TypeParagraph();
            wordApp.Selection.Font.Size = 22;
            wordApp.Selection.Font.Bold = 1;
            wordApp.Selection.TypeText("病   历   记   录");
            wordApp.Selection.TypeParagraph();
            //wordApp.Selection.TypeText(type == HIS_EMRManager.Public.EMRType.病程记录 ? "病  程  记  录" : "病   历   记   录");

            //病人基本信息
            wordApp.Selection.Font.Size = 12;
            Word.Table table = wordApp.ActiveDocument.Tables.Add(wordApp.Selection.Range, 1, 3, ref oMissing, ref oMissing);
            wordApp.Selection.Borders.OutsideLineStyle = WdLineStyle.wdLineStyleNone;
            wordApp.Selection.Borders.InsideLineStyle  = WdLineStyle.wdLineStyleNone;
            int    columnNo = 1;
            object step     = 1;
            object unit     = Word.WdUnits.wdCharacter;
            object extend   = Word.WdMovementType.wdExtend;

            foreach (XmlNode node in xmlDoc.SelectSingleNode("病人信息/基本信息").ChildNodes)
            {
                wordApp.Selection.Font.Size = 12;
                wordApp.Selection.Font.Bold = 0;
                wordApp.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
                wordApp.Selection.TypeText("    " + (columnNo == 2?"(第     页)":node.InnerText));
                columnNo++;
                if (columnNo <= 3)
                {
                    wordApp.Selection.Move(ref unit, ref step);
                }
                else
                {
                    unit = Word.WdUnits.wdLine;
                    wordApp.Selection.MoveDown(ref unit, ref step, ref oMissing);
                    break;
                }
            }
            //画分隔线
            //wordApp.ActiveDocument.Shapes.AddLine(70, 125, 530, 125, ref oMissing);

            wordApp.ActiveWindow.View.SeekView          = WdSeekView.wdSeekMainDocument; // 跳出页眉设置
            wordApp.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;


            wordApp.Selection.ParagraphFormat.Borders[WdBorderType.wdBorderTop].LineStyle    = WdLineStyle.wdLineStyleSingle;
            wordApp.Selection.ParagraphFormat.Borders[WdBorderType.wdBorderBottom].LineStyle = WdLineStyle.wdLineStyleNone;
            wordApp.Selection.ParagraphFormat.Borders[WdBorderType.wdBorderLeft].LineStyle   = WdLineStyle.wdLineStyleNone;
            wordApp.Selection.ParagraphFormat.Borders[WdBorderType.wdBorderRight].LineStyle  = WdLineStyle.wdLineStyleNone;

            //标题
            //wordApp.Selection.TypeParagraph();
            wordApp.Selection.Font.Size = 14;
            wordApp.Selection.Font.Bold = 1;
            wordApp.Selection.TypeText(type.ToString());
            wordApp.Selection.ParagraphFormat.LineSpacing = 20;
        }
        private void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                object oMissing = System.Reflection.Missing.Value;
                //创建一个word实例
                Word._Application oWord = new Word.Application();
                //设置为不可见
                oWord.Visible = false;

                //模板文件地址,这里假设在程序根目录
                object oTemplate          = System.AppDomain.CurrentDomain.BaseDirectory + "//" + comboBox1.Text + ".dot";
                string pic65Path          = System.AppDomain.CurrentDomain.BaseDirectory + "//出水温度稳定性65℃.jpg";
                string pic50Path          = System.AppDomain.CurrentDomain.BaseDirectory + "//出水温度稳定性50℃.jpg";
                string picSenstivityPath1 = System.AppDomain.CurrentDomain.BaseDirectory + "//保真度曲线.jpg";
                string picSenstivityPath2 = System.AppDomain.CurrentDomain.BaseDirectory + "//灵敏度曲线.jpg";
                //以模板为基础生成文档
                Word._Document oDoc = oWord.Documents.Add(ref oTemplate, ref oMissing, ref oMissing, ref oMissing);
                oWord = oDoc.Application;
                if (isTest)
                {
                    foreach (Bookmark bk in oDoc.Bookmarks)
                    {
                        if (bk.Name == "Tm_65_3")
                        {
                            bk.Range.Text = model.Tm_65_3 + "";
                        }
                        if (bk.Name == "Tm_65_3diff")
                        {
                            bk.Range.Text = model.Tm_65_3diff + "";
                        }
                        if (bk.Name == "Tm_65_6")
                        {
                            bk.Range.Text = model.Tm_65_6 + "";
                        }
                        if (bk.Name == "Tm_65_6diff")
                        {
                            bk.Range.Text = model.Tm_65_6diff + "";
                        }
                        if (bk.Name == "Tm_50_3")
                        {
                            bk.Range.Text = model.Tm_50_3 + "";
                        }
                        if (bk.Name == "Tm_50_3diff")
                        {
                            bk.Range.Text = model.Tm_50_3diff + "";
                        }
                        if (bk.Name == "Tm_50_6")
                        {
                            bk.Range.Text = model.Tm_50_6 + "";
                        }
                        if (bk.Name == "Tm_50_6diff")
                        {
                            bk.Range.Text = model.Tm_50_6diff + "";
                        }
                        if (bk.Name == "tmDiff")
                        {
                            bk.Range.Text = model.Tm_50_3 + "";
                        }
                        if (bk.Name == "G1")
                        {
                            bk.Range.Text = model.Tm_50_3diff + "";
                        }
                        if (bk.Name == "G2")
                        {
                            bk.Range.Text = model.Tm_50_6 + "";
                        }

                        if (bk.Name == "Tm_65_pic" && File.Exists(pic65Path))
                        {
                            bk.Select();
                            Selection sel = oWord.Selection;
                            sel.InlineShapes.AddPicture(pic65Path);
                        }
                        if (bk.Name == "Tm_50_pic" && File.Exists(pic50Path))
                        {
                            bk.Select();
                            Selection sel = oWord.Selection;
                            sel.InlineShapes.AddPicture(pic50Path);
                        }
                        if (bk.Name == "picSenstivity1" && File.Exists(picSenstivityPath1))
                        {
                            bk.Select();
                            Selection sel = oWord.Selection;
                            sel.InlineShapes.AddPicture(picSenstivityPath1);
                        }
                        if (bk.Name == "picSenstivity2" && File.Exists(picSenstivityPath2))
                        {
                            bk.Select();
                            Selection sel = oWord.Selection;
                            sel.InlineShapes.AddPicture(picSenstivityPath2);
                        }
                    }
                    //object[] oBookMark = new object[10];
                    //oBookMark[0] = "Tm_65_3";
                    //oBookMark[1] = "Tm_65_3diff";
                    //oBookMark[2] = "Tm_65_6";
                    //oBookMark[3] = "Tm_65_6diff";
                    //oBookMark[4] = "Tm_65_pic";
                    //oBookMark[5] = "Tm_50_3";
                    //oBookMark[6] = "Tm_50_3diff";
                    //oBookMark[7] = "Tm_50_6";
                    //oBookMark[8] = "Tm_50_6diff";
                    //oBookMark[9] = "Tm_50_pic";

                    ////赋值任意数据到书签的位置
                    //oDoc.Bookmarks.get_Item(ref oBookMark[0]).Range.Text = model.Tm_65_3 + "";
                    //oDoc.Bookmarks.get_Item(ref oBookMark[1]).Range.Text = model.Tm_65_3diff + "";
                    //oDoc.Bookmarks.get_Item(ref oBookMark[2]).Range.Text = model.Tm_65_6 + "";
                    //oDoc.Bookmarks.get_Item(ref oBookMark[3]).Range.Text = model.Tm_65_6diff + "";
                    //oDoc.Bookmarks.get_Item(ref oBookMark[5]).Range.Text = model.Tm_50_3 + "";
                    //oDoc.Bookmarks.get_Item(ref oBookMark[6]).Range.Text = model.Tm_50_3diff + "";
                    //oDoc.Bookmarks.get_Item(ref oBookMark[7]).Range.Text = model.Tm_50_6 + "";
                    //oDoc.Bookmarks.get_Item(ref oBookMark[8]).Range.Text = model.Tm_50_6diff + "";

                    //Bookmark bk_65_pic= oDoc.Bookmarks.get_Item(ref oBookMark[4]);
                    //bk_65_pic.Select();
                    //Selection sel = oWord.Selection;
                    //sel.InlineShapes.AddPicture(pic65Path);


                    //Bookmark bk_50_pic = oDoc.Bookmarks.get_Item(ref oBookMark[9]);
                    //bk_50_pic.Select();
                    //sel.InlineShapes.AddPicture(pic50Path);
                }


                //#region 2806
                //if (testStandardEnum == TestStandardEnum.default2806)
                //{
                //    //声明书签数组
                //    object[] oBookMark = new object[46];
                //    //赋值书签名
                //    oBookMark[0] = "Pc";
                //    oBookMark[1] = "Tc";
                //    oBookMark[2] = "Ph";
                //    oBookMark[3] = "Th";
                //    oBookMark[4] = "Qm";
                //    oBookMark[5] = "Tm";
                //    oBookMark[6] = "A_1_Qc";
                //    oBookMark[7] = "A_1_Tc";
                //    oBookMark[8] = "A_1_Tcdiff";
                //    oBookMark[9] = "A_2_Qc";
                //    oBookMark[10] = "A_2_Tc";
                //    oBookMark[11] = "A_2_Tcdiff";
                //    oBookMark[12] = "B_1_Qh";
                //    oBookMark[13] = "B_1_Th";
                //    oBookMark[14] = "B_2_Qh";
                //    oBookMark[15] = "B_2_Th";
                //    oBookMark[16] = "B_2_Thdiff";

                //    oBookMark[17] = "C_1_Tm";
                //    oBookMark[18] = "C_1_3";
                //    oBookMark[19] = "C_1_5";
                //    oBookMark[20] = "C_1_Tmdiff";
                //    oBookMark[21] = "C_2_Tm";
                //    oBookMark[22] = "C_2_Tmdiff";
                //    oBookMark[23] = "C_3_Tm";
                //    oBookMark[24] = "C_3_3";
                //    oBookMark[25] = "C_3_5";
                //    oBookMark[26] = "C_3_Tmdiff";
                //    oBookMark[27] = "C_4_Tm";
                //    oBookMark[28] = "C_4_Tmdiff";

                //    oBookMark[29] = "H_1_Tm";
                //    oBookMark[30] = "H_1_3";
                //    oBookMark[31] = "H_1_5";
                //    oBookMark[32] = "H_1_Tmdiff";
                //    oBookMark[33] = "H_2_Tm";
                //    oBookMark[34] = "H_2_Tmdiff";
                //    oBookMark[35] = "H_3_Tm";
                //    oBookMark[36] = "H_3_3";
                //    oBookMark[37] = "H_3_5";
                //    oBookMark[38] = "H_3_Tmdiff";
                //    oBookMark[39] = "H_4_Tm";
                //    oBookMark[40] = "H_4_Tmdiff";

                //    oBookMark[41] = "Up_Tm";
                //    oBookMark[42] = "Up_Tmdiff";
                //    oBookMark[43] = "Back_Tm";
                //    oBookMark[44] = "Back_Tmdiff";
                //    oBookMark[45] = "TmMax";

                //    //赋值任意数据到书签的位置
                //    oDoc.Bookmarks.get_Item(ref oBookMark[0]).Range.Text = model_2806.Pc + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[1]).Range.Text = model_2806.Tc + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[2]).Range.Text = model_2806.Ph + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[3]).Range.Text = model_2806.Th + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[4]).Range.Text = model_2806.Qm + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[5]).Range.Text = model_2806.Tm + "";

                //    oDoc.Bookmarks.get_Item(ref oBookMark[6]).Range.Text = model_2806.A_1_Qc + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[7]).Range.Text = model_2806.A_1_Tc + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[8]).Range.Text = model_2806.A_1_Tcdiff + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[9]).Range.Text = model_2806.A_2_Qc + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[10]).Range.Text = model_2806.A_2_Tc + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[11]).Range.Text = model_2806.A_2_Tcdiff + "";

                //    oDoc.Bookmarks.get_Item(ref oBookMark[12]).Range.Text = model_2806.B_1_Qh + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[13]).Range.Text = model_2806.B_1_Th + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[14]).Range.Text = model_2806.B_2_Qh + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[15]).Range.Text = model_2806.B_2_Th + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[16]).Range.Text = model_2806.B_2_Thdiff + "";

                //    oDoc.Bookmarks.get_Item(ref oBookMark[17]).Range.Text = model_2806.C_1_Tm + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[18]).Range.Text = model_2806.C_1_3 + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[19]).Range.Text = model_2806.C_1_5 + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[20]).Range.Text = model_2806.C_1_Tmdiff + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[21]).Range.Text = model_2806.C_2_Tm + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[22]).Range.Text = model_2806.C_2_Tmdiff + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[23]).Range.Text = model_2806.C_3_Tm + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[24]).Range.Text = model_2806.C_3_3 + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[25]).Range.Text = model_2806.C_3_5 + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[26]).Range.Text = model_2806.C_3_Tmdiff + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[27]).Range.Text = model_2806.C_4_Tm + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[28]).Range.Text = model_2806.C_4_Tmdiff + "";

                //    oDoc.Bookmarks.get_Item(ref oBookMark[29]).Range.Text = model_2806.H_1_Tm + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[30]).Range.Text = model_2806.H_1_3 + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[31]).Range.Text = model_2806.H_1_5 + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[32]).Range.Text = model_2806.H_1_Tmdiff + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[33]).Range.Text = model_2806.H_2_Tm + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[34]).Range.Text = model_2806.H_2_Tmdiff + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[35]).Range.Text = model_2806.H_3_Tm + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[36]).Range.Text = model_2806.H_3_3 + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[37]).Range.Text = model_2806.H_3_5 + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[38]).Range.Text = model_2806.H_3_Tmdiff + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[39]).Range.Text = model_2806.H_4_Tm + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[40]).Range.Text = model_2806.H_4_Tmdiff + "";

                //    oDoc.Bookmarks.get_Item(ref oBookMark[41]).Range.Text = model_2806.Up_Tm + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[42]).Range.Text = model_2806.Up_Tmdiff + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[43]).Range.Text = model_2806.Back_Tm + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[44]).Range.Text = model_2806.Back_Tmdiff + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[45]).Range.Text = model_2806.TmMax + "";
                //}
                //#endregion



                //弹出保存文件对话框,保存生成的Word
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Filter     = "Word Document(*.doc)|*.doc";
                sfd.DefaultExt = "Word Document(*.doc)|*.doc";
                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    object filename = sfd.FileName;

                    oDoc.SaveAs(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);
                    oDoc.Close(ref oMissing, ref oMissing, ref oMissing);
                    //关闭word
                    oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
                    MessageBox.Show("保存成功!");
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
                return;
            }
        }
Exemple #16
0
        public override void process(DataRow[] drTables, DataSet dsTableColumns, DataSet dsTablePrimaryKeys)
        {
            try
            {
                base.process(drTables, dsTableColumns, dsTablePrimaryKeys);
                OutPut = FilePathHelper.ExportDBDocPath;
                FileHelper.CreateDirectory(OutPut);


                setEnable(false);
                string    msg = string.Empty;
                Stopwatch sw  = Stopwatch.StartNew();
                FileHelper.DeleteDirectory(FilePathHelper.ExportDBDocPath);
                if (drTables != null && dsTableColumns != null && dsTablePrimaryKeys != null)
                {
                    setStatusBar(string.Format("正在生成{0}数据库文档", dbName));
                    setProgreesEditValue(0);
                    setProgress(0);
                    setProgressMax(drTables.Length);

                    string path = FilePathHelper.ExportDBDocPath + dbName + "_DB_{0}_{1}" + ".doc";

                    FileHelper.CreateDirectory(path);
                    Object           Nothing   = System.Reflection.Missing.Value;
                    Word.Application dbWordApp = new Word.Application();
                    dbWordApp.NormalTemplate.Saved = true;

                    Word.Document dbDoc = dbWordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);
                    dbWordApp.ActiveWindow.View.Type     = WdViewType.wdOutlineView;
                    dbWordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekPrimaryHeader;
                    dbWordApp.ActiveWindow.ActivePane.Selection.InsertAfter(string.Format("{0} {1}数据库文档", dbName, dbType));
                    dbWordApp.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft;
                    dbWordApp.ActiveWindow.View.SeekView          = WdSeekView.wdSeekMainDocument;
                    string tableName = "";
                    int    begin     = 0;
                    int    end       = 0;

                    #region

                    try
                    {
                        for (int j = 0; j < drTables.Length; j++)
                        {
                            try
                            {
                                if ((j + 1) % num == 0 || (j + 1).Equals(drTables.Length))
                                {
                                    begin = end;
                                    end   = j;
                                }

                                #region 样式

                                DataRow drTable = drTables[j];

                                DataRow[] drTableColumns =
                                    dsTableColumns.Tables[dbName + DBtablesColumns].Select(
                                        "TABLE_NAME = '" + drTable["name"].ToString() + "'", "COLUMN_ID ASC");

                                tableName = drTable["name"] as string;                //表名
                                string tableComments = drTable["comments"] as string; //表说明

                                setStatusBar(string.Format("正在生成{0}中{1}表信息,共{2}张表,已生成了{3}张表", dbName, tableName,
                                                           drTables.Length, j));


                                //Word段落
                                Word.Paragraph p;
                                p = dbDoc.Content.Paragraphs.Add(ref Nothing);
                                //设置段落中的内容文本
                                p.Range.Text = "表" + Convert.ToString(j + 1) + ":" + tableName + "(" +
                                               tableComments + ")";
                                //设置为一号标题
                                object style = Word.WdBuiltinStyle.wdStyleHeading1;
                                p.set_Style(ref style);
                                //添加到末尾
                                p.Range.InsertParagraphAfter();

                                style = Word.WdBuiltinStyle.wdStyleBodyText;
                                p.set_Style(ref style);

                                //dbWordApp.Selection.TypeText("表" + Convert.ToString(j + 1) + ":" + tableName + "(" +
                                //                             tableComments + ")");

                                dbWordApp.Selection.ParagraphFormat.LineSpacing = 15f;
                                object count  = 20;
                                object WdLine = Word.WdUnits.wdLine;
                                dbWordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);

                                Word.Table newTable = dbDoc.Tables.Add(dbWordApp.Selection.Range,
                                                                       drTableColumns.Length + 2, 7, ref Nothing,
                                                                       ref Nothing);

                                newTable.Borders.OutsideLineStyle = Word.WdLineStyle.wdLineStyleSingle;
                                newTable.Borders.InsideLineStyle  = Word.WdLineStyle.wdLineStyleSingle;
                                newTable.Columns[1].Width         = 110f; //列明
                                newTable.Columns[2].Width         = 90f;  //数据类型
                                newTable.Columns[3].Width         = 50f;  //是否NULL
                                newTable.Columns[4].Width         = 40f;  //默认值
                                newTable.Columns[5].Width         = 30f;  //主键
                                newTable.Columns[6].Width         = 30f;  //外键
                                newTable.Columns[7].Width         = 130f; //列说明

                                #endregion

                                #region 填充表名称(表格内)

                                newTable.Cell(1, 1).Range.Text = "表名:" + tableName + "(" + tableComments + ")";
                                newTable.Cell(1, 1).Range.Bold = 2; //设置单元格中字体为粗体
                                //合并单元格
                                newTable.Cell(1, 1).Merge(newTable.Cell(1, 7));
                                newTable.Cell(1, 1).Range.Font.Color = Word.WdColor.wdColorRed; //设置单元格内字体颜色
                                newTable.Cell(1, 1).Select();                                   //选中
                                dbWordApp.Selection.Cells.VerticalAlignment =
                                    Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;     //垂直居中
                                dbWordApp.Selection.ParagraphFormat.Alignment =
                                    Word.WdParagraphAlignment.wdAlignParagraphCenter;           //水平居中

                                #endregion

                                #region 填充列标题

                                newTable.Cell(2, 1).Range.Text       = "列名";
                                newTable.Cell(2, 1).Range.Font.Color = Word.WdColor.wdColorBlack; //设置单元格内字体颜色
                                newTable.Cell(2, 2).Range.Font.Bold  = 2;
                                newTable.Cell(2, 2).Range.Font.Size  = 9;
                                newTable.Cell(2, 2).Select(); //选中
                                newTable.Cell(2, 2).VerticalAlignment =
                                    WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                                dbWordApp.Selection.ParagraphFormat.Alignment =
                                    Word.WdParagraphAlignment.wdAlignParagraphCenter; //水平居中

                                newTable.Cell(2, 2).Range.Text       = "数据类型";
                                newTable.Cell(2, 2).Range.Font.Color = Word.WdColor.wdColorBlack; //设置单元格内字体颜色
                                newTable.Cell(2, 2).Range.Font.Bold  = 2;
                                newTable.Cell(2, 2).Range.Font.Size  = 9;
                                newTable.Cell(2, 2).Select(); //选中
                                newTable.Cell(2, 2).VerticalAlignment =
                                    WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                                dbWordApp.Selection.ParagraphFormat.Alignment =
                                    Word.WdParagraphAlignment.wdAlignParagraphCenter; //水平居中

                                newTable.Cell(2, 3).Range.Text        = "是否NULL";
                                newTable.Cell(2, 3).Range.Font.Color  = Word.WdColor.wdColorBlack; //设置单元格内字体颜色
                                newTable.Cell(2, 3).Range.Font.Bold   = 2;
                                newTable.Cell(2, 3).Range.Font.Size   = 9;
                                newTable.Cell(2, 3).VerticalAlignment =
                                    WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                                newTable.Cell(2, 3).Select();                         //选中
                                dbWordApp.Selection.ParagraphFormat.Alignment =
                                    Word.WdParagraphAlignment.wdAlignParagraphCenter; //水平居中

                                newTable.Cell(2, 4).Range.Text        = "默认值";
                                newTable.Cell(2, 4).Range.Font.Color  = Word.WdColor.wdColorBlack; //设置单元格内字体颜色
                                newTable.Cell(2, 4).VerticalAlignment =
                                    WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                                newTable.Cell(2, 4).Range.Font.Bold = 2;
                                newTable.Cell(2, 4).Range.Font.Size = 9;
                                newTable.Cell(2, 4).Select();                         //选中
                                dbWordApp.Selection.ParagraphFormat.Alignment =
                                    Word.WdParagraphAlignment.wdAlignParagraphCenter; //水平居中

                                newTable.Cell(2, 5).Range.Text        = "主键";
                                newTable.Cell(2, 5).Range.Font.Color  = Word.WdColor.wdColorBlack; //设置单元格内字体颜色
                                newTable.Cell(2, 5).VerticalAlignment =
                                    WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                                newTable.Cell(2, 5).Range.Font.Bold = 2;
                                newTable.Cell(2, 5).Range.Font.Size = 9;
                                newTable.Cell(2, 5).Select();                         //选中
                                dbWordApp.Selection.ParagraphFormat.Alignment =
                                    Word.WdParagraphAlignment.wdAlignParagraphCenter; //水平居中

                                newTable.Cell(2, 6).Range.Text        = "外键";
                                newTable.Cell(2, 6).Range.Font.Color  = Word.WdColor.wdColorBlack; //设置单元格内字体颜色
                                newTable.Cell(2, 6).VerticalAlignment =
                                    WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                                newTable.Cell(2, 6).Range.Font.Bold = 2;
                                newTable.Cell(2, 6).Range.Font.Size = 9;
                                newTable.Cell(2, 6).Select();                         //选中
                                dbWordApp.Selection.ParagraphFormat.Alignment =
                                    Word.WdParagraphAlignment.wdAlignParagraphCenter; //水平居中

                                newTable.Cell(2, 7).Range.Text        = "备注";
                                newTable.Cell(2, 7).Range.Font.Color  = Word.WdColor.wdColorBlack; //设置单元格内字体颜色
                                newTable.Cell(2, 7).VerticalAlignment =
                                    WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                                newTable.Cell(2, 7).Range.Font.Bold = 2;
                                newTable.Cell(2, 7).Range.Font.Size = 9;
                                newTable.Cell(2, 7).Select();                         //选中
                                dbWordApp.Selection.ParagraphFormat.Alignment =
                                    Word.WdParagraphAlignment.wdAlignParagraphCenter; //水平居中

                                #endregion

                                #region 填充表格内容

                                for (int i = 0; i < drTableColumns.Length; i++)
                                {
                                    string tableColumnName = drTableColumns[i]["COLUMN_NAME"] as string;         //列名

                                    string tableColumnComments = drTableColumns[i]["COMMENTS"] as string;        //列说明

                                    string tableColumnDataType = drTableColumns[i]["DATA_TYPE"] as string;       //列类型

                                    string tableColumnDataScale = drTableColumns[i]["DATA_SCALE"] + "";          //列精度

                                    string tableColumnDataLength = drTableColumns[i]["DATA_LENGTH"] + "";        //列长度

                                    string tableColumnDataNullAble = drTableColumns[i]["NULLABLE"] as string;    //可空

                                    string tableColumnDataDefault = drTableColumns[i]["DATA_DEFAULT"] as string; //默认值

                                    string tableColumnDataPrecision = drTableColumns[i]["Data_Precision"] + "";

                                    if (string.IsNullOrEmpty(tableColumnDataPrecision)) //字符串、日期等
                                    {
                                        if ("DATE".Equals(tableColumnDataType))
                                        {
                                            tableColumnDataType = tableColumnDataType + "()";
                                        }
                                        else
                                        {
                                            tableColumnDataType = tableColumnDataType + "(" + tableColumnDataLength +
                                                                  ")";
                                        }
                                    }
                                    else //数字类型等
                                    {
                                        if ("0".Equals(tableColumnDataScale))
                                        {
                                            tableColumnDataType = tableColumnDataType + "(" + tableColumnDataPrecision +
                                                                  ")";
                                        }
                                        else
                                        {
                                            tableColumnDataType = tableColumnDataType + "(" + tableColumnDataPrecision +
                                                                  "," + tableColumnDataScale + ")";
                                        }
                                    }

                                    //列名
                                    newTable.Cell(i + 3, 1).Range.Text        = tableColumnName;
                                    newTable.Cell(i + 3, 1).VerticalAlignment =
                                        WdCellVerticalAlignment.wdCellAlignVerticalCenter;

                                    //数据类型
                                    newTable.Cell(i + 3, 2).Range.Text        = tableColumnDataType;
                                    newTable.Cell(i + 3, 2).VerticalAlignment =
                                        WdCellVerticalAlignment.wdCellAlignVerticalCenter;


                                    //是否Null
                                    newTable.Cell(i + 3, 3).Range.Text        = tableColumnDataNullAble;
                                    newTable.Cell(i + 3, 3).VerticalAlignment =
                                        WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                                    newTable.Cell(i + 3, 3).Select();
                                    dbWordApp.Selection.ParagraphFormat.Alignment =
                                        Word.WdParagraphAlignment.wdAlignParagraphCenter; //水平居中

                                    //默认值
                                    newTable.Cell(i + 3, 4).Range.Text        = tableColumnDataDefault;
                                    newTable.Cell(i + 3, 4).VerticalAlignment =
                                        WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                                    newTable.Cell(i + 3, 4).Select();
                                    dbWordApp.Selection.ParagraphFormat.Alignment =
                                        Word.WdParagraphAlignment.wdAlignParagraphCenter; //水平居中


                                    //主键

                                    newTable.Cell(i + 3, 5).Range.Text = "";

                                    DataRow[] dr =
                                        dsTablePrimaryKeys.Tables[dbName + DBtablesPrimaryKeys].Select(
                                            "TABLE_NAME = '" + tableName + "' AND COLUMN_NAME ='" + tableColumnName +
                                            "' and constraint_type='P'");

                                    if (dr != null && dr.Length > 0)
                                    {
                                        newTable.Cell(i + 3, 5).Range.Text = "Y";
                                    }
                                    newTable.Cell(i + 3, 5).VerticalAlignment =
                                        WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                                    newTable.Cell(i + 3, 5).Select();
                                    dbWordApp.Selection.ParagraphFormat.Alignment =
                                        Word.WdParagraphAlignment.wdAlignParagraphCenter; //水平居中

                                    //外键

                                    newTable.Cell(i + 3, 6).Range.Text = "";
                                    DataRow[] dr2 =
                                        dsTablePrimaryKeys.Tables[dbName + DBtablesPrimaryKeys].Select(
                                            "TABLE_NAME = '" + tableName + "' AND COLUMN_NAME ='" + tableColumnName +
                                            "' and constraint_type='R'");
                                    if (dr2 != null && dr2.Length > 0)
                                    {
                                        newTable.Cell(i + 3, 6).Range.Text = "Y";
                                    }
                                    newTable.Cell(i + 3, 6).VerticalAlignment =
                                        WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                                    newTable.Cell(i + 3, 6).Select();
                                    dbWordApp.Selection.ParagraphFormat.Alignment =
                                        Word.WdParagraphAlignment.wdAlignParagraphCenter; //水平居中


                                    //说明
                                    newTable.Cell(i + 3, 7).Range.Text        = tableColumnComments;
                                    newTable.Cell(i + 3, 7).VerticalAlignment =
                                        WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                                }

                                #endregion


                                setProgress(1);
                            }
                            catch (Exception ex)
                            {
                                msg = ex.Message;
                                string str = (string.Format("{0}生成数据库文档丢失{1}表", dbName, tableName));
                                setStatusBar(str);
                                LogHelper.Error(ex);
                                LogHelper.Debug(str);
                            }
                            finally
                            {
                                #region 释放资源

                                if ((j + 1) % num == 0 || (j + 1).Equals(drTables.Length))
                                {
                                    try
                                    {
                                        object fileName = string.Format(path, begin + 1, end + 1);

                                        dbDoc.SaveAs(ref fileName, ref Nothing, ref Nothing, ref Nothing, ref Nothing,
                                                     ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing,
                                                     ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing,
                                                     ref Nothing);
                                    }
                                    catch (Exception ex)
                                    {
                                        msg = ex.Message;
                                        LogHelper.Error(ex);
                                    }
                                    try
                                    {
                                        dbDoc.Close(ref Nothing, ref Nothing, ref Nothing);
                                    }
                                    catch
                                    {
                                    }
                                    if (dbDoc != null)
                                    {
                                        try
                                        {
                                            System.Runtime.InteropServices.Marshal.ReleaseComObject(dbDoc);
                                        }
                                        catch
                                        {
                                        }
                                        dbDoc = null;
                                    }
                                    GC.Collect();
                                    if (!(j + 1).Equals(drTables.Length))
                                    {
                                        dbDoc = dbWordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing,
                                                                        ref Nothing);
                                    }
                                }

                                #endregion
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        msg = ex.Message;
                        LogHelper.Error(ex);
                    }
                    finally
                    {
                        #region 释放资源

                        try
                        {
                            dbWordApp.Quit(ref Nothing, ref Nothing, ref Nothing);
                        }
                        catch
                        {
                        }
                        if (dbWordApp != null)
                        {
                            try
                            {
                                System.Runtime.InteropServices.Marshal.ReleaseComObject(dbWordApp);
                            }
                            catch
                            {
                            }
                            dbWordApp = null;
                        }
                        GC.Collect();


                        #endregion
                    }

                    #endregion
                }
                sw.Stop();

                if (string.IsNullOrEmpty(msg))
                {
                    setStatusBar(string.Format("{0}数据库文档生成成功", dbName));
                    openDialog();
                }
                else
                {
                    setStatusBar(string.Format("{0}数据库文档生成失败[{1}]", dbName, msg));
                }
                setEnable(true);
            }
            catch (Exception ex)
            {
                setStatusBar(string.Format("{0}数据库文档生成失败[{1}]", dbName, ex.Message));
            }
        }
Exemple #17
0
        /// <summary>
        /// Convert Word Document
        /// </summary>
        /// <param name="strPath"></param>
        /// <param name="savePath"></param>
        /// <returns></returns>
        private bool ConvertWordDocument(string strPath,string savePath)
        {
            try
            {
                Word.Application wordApp = new Word.Application();
                object rdOnly=true;//Boolean.TrueString;
                object Source=strPath;
                object Destination= savePath;

                try
                {

                    wordApp.Documents.Open(ref Source,ref Unknown,
                        ref rdOnly,ref Unknown,ref Unknown,
                        ref Unknown,ref Unknown,ref Unknown,
                        ref Unknown,ref Unknown,ref Unknown,
                        ref Unknown,ref Unknown,ref Unknown,ref Unknown);//,ref Unknown);
                }
                catch(Exception ee)
                {
                    Console.Write("Unable to convert Word Document " + ee.Message);
                    return false;
                }

                try
                {

                    object format = Word.WdSaveFormat.wdFormatHTML;//.wdFormatRTF;// kein XML, nutzen?
                    wordApp.ActiveDocument.SaveAs(ref Destination,ref format,
                        ref Unknown,ref Unknown,ref Unknown,
                        ref Unknown,ref Unknown,ref Unknown,
                        ref Unknown,ref Unknown,ref Unknown,
                        ref Unknown,ref Unknown,ref Unknown,
                        ref Unknown, ref Unknown);

                }
                catch(Exception ee)
                {
                    string errorText = "Unable to save specified Document. Access is denied. "+ ee.Message;
                    Console.Write("Unable to convert Word Document " + errorText);
                    return false;

                }
                object fileSave=false;

                wordApp.Quit(ref fileSave, ref Unknown, ref Unknown);

                wordApp = null; //GC
                GC.Collect(); //GC
                return true;
            }
            catch(Exception ee)
            {

            }
            return false;
        }
        private void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (testStandardEnum == TestStandardEnum.default1711 && comboBox1.Text != "EN1111-2017温控报告")
                {
                    MessageBox.Show("请选择正确的模板!");
                    this.Close();
                }
                if (testStandardEnum == TestStandardEnum.default2806 && comboBox1.Text != "2806温控报告")
                {
                    MessageBox.Show("请选择正确的模板!");
                    this.Close();
                }
                object oMissing = System.Reflection.Missing.Value;
                //创建一个word实例
                Word._Application oWord = new Word.Application();
                //设置为不可见
                oWord.Visible = false;
                //模板文件地址,这里假设在程序根目录
                object oTemplate = System.AppDomain.CurrentDomain.BaseDirectory + "//" + comboBox1.Text + ".dot";
                //以模板为基础生成文档
                Word._Document oDoc = oWord.Documents.Add(ref oTemplate, ref oMissing, ref oMissing, ref oMissing);

                #region 2806
                if (testStandardEnum == TestStandardEnum.default2806)
                {
                    //声明书签数组
                    object[] oBookMark = new object[46];
                    //赋值书签名
                    oBookMark[0]  = "Pc";
                    oBookMark[1]  = "Tc";
                    oBookMark[2]  = "Ph";
                    oBookMark[3]  = "Th";
                    oBookMark[4]  = "Qm";
                    oBookMark[5]  = "Tm";
                    oBookMark[6]  = "A_1_Qc";
                    oBookMark[7]  = "A_1_Tc";
                    oBookMark[8]  = "A_1_Tcdiff";
                    oBookMark[9]  = "A_2_Qc";
                    oBookMark[10] = "A_2_Tc";
                    oBookMark[11] = "A_2_Tcdiff";
                    oBookMark[12] = "B_1_Qh";
                    oBookMark[13] = "B_1_Th";
                    oBookMark[14] = "B_2_Qh";
                    oBookMark[15] = "B_2_Th";
                    oBookMark[16] = "B_2_Thdiff";

                    oBookMark[17] = "C_1_Tm";
                    oBookMark[18] = "C_1_3";
                    oBookMark[19] = "C_1_5";
                    oBookMark[20] = "C_1_Tmdiff";
                    oBookMark[21] = "C_2_Tm";
                    oBookMark[22] = "C_2_Tmdiff";
                    oBookMark[23] = "C_3_Tm";
                    oBookMark[24] = "C_3_3";
                    oBookMark[25] = "C_3_5";
                    oBookMark[26] = "C_3_Tmdiff";
                    oBookMark[27] = "C_4_Tm";
                    oBookMark[28] = "C_4_Tmdiff";

                    oBookMark[29] = "H_1_Tm";
                    oBookMark[30] = "H_1_3";
                    oBookMark[31] = "H_1_5";
                    oBookMark[32] = "H_1_Tmdiff";
                    oBookMark[33] = "H_2_Tm";
                    oBookMark[34] = "H_2_Tmdiff";
                    oBookMark[35] = "H_3_Tm";
                    oBookMark[36] = "H_3_3";
                    oBookMark[37] = "H_3_5";
                    oBookMark[38] = "H_3_Tmdiff";
                    oBookMark[39] = "H_4_Tm";
                    oBookMark[40] = "H_4_Tmdiff";

                    oBookMark[41] = "Up_Tm";
                    oBookMark[42] = "Up_Tmdiff";
                    oBookMark[43] = "Back_Tm";
                    oBookMark[44] = "Back_Tmdiff";
                    oBookMark[45] = "TmMax";

                    //赋值任意数据到书签的位置
                    oDoc.Bookmarks.get_Item(ref oBookMark[0]).Range.Text = model_2806.Pc + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[1]).Range.Text = model_2806.Tc + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[2]).Range.Text = model_2806.Ph + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[3]).Range.Text = model_2806.Th + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[4]).Range.Text = model_2806.Qm + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[5]).Range.Text = model_2806.Tm + "";

                    oDoc.Bookmarks.get_Item(ref oBookMark[6]).Range.Text  = model_2806.A_1_Qc + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[7]).Range.Text  = model_2806.A_1_Tc + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[8]).Range.Text  = model_2806.A_1_Tcdiff + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[9]).Range.Text  = model_2806.A_2_Qc + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[10]).Range.Text = model_2806.A_2_Tc + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[11]).Range.Text = model_2806.A_2_Tcdiff + "";

                    oDoc.Bookmarks.get_Item(ref oBookMark[12]).Range.Text = model_2806.B_1_Qh + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[13]).Range.Text = model_2806.B_1_Th + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[14]).Range.Text = model_2806.B_2_Qh + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[15]).Range.Text = model_2806.B_2_Th + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[16]).Range.Text = model_2806.B_2_Thdiff + "";

                    oDoc.Bookmarks.get_Item(ref oBookMark[17]).Range.Text = model_2806.C_1_Tm + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[18]).Range.Text = model_2806.C_1_3 + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[19]).Range.Text = model_2806.C_1_5 + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[20]).Range.Text = model_2806.C_1_Tmdiff + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[21]).Range.Text = model_2806.C_2_Tm + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[22]).Range.Text = model_2806.C_2_Tmdiff + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[23]).Range.Text = model_2806.C_3_Tm + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[24]).Range.Text = model_2806.C_3_3 + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[25]).Range.Text = model_2806.C_3_5 + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[26]).Range.Text = model_2806.C_3_Tmdiff + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[27]).Range.Text = model_2806.C_4_Tm + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[28]).Range.Text = model_2806.C_4_Tmdiff + "";

                    oDoc.Bookmarks.get_Item(ref oBookMark[29]).Range.Text = model_2806.H_1_Tm + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[30]).Range.Text = model_2806.H_1_3 + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[31]).Range.Text = model_2806.H_1_5 + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[32]).Range.Text = model_2806.H_1_Tmdiff + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[33]).Range.Text = model_2806.H_2_Tm + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[34]).Range.Text = model_2806.H_2_Tmdiff + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[35]).Range.Text = model_2806.H_3_Tm + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[36]).Range.Text = model_2806.H_3_3 + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[37]).Range.Text = model_2806.H_3_5 + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[38]).Range.Text = model_2806.H_3_Tmdiff + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[39]).Range.Text = model_2806.H_4_Tm + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[40]).Range.Text = model_2806.H_4_Tmdiff + "";

                    oDoc.Bookmarks.get_Item(ref oBookMark[41]).Range.Text = model_2806.Up_Tm + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[42]).Range.Text = model_2806.Up_Tmdiff + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[43]).Range.Text = model_2806.Back_Tm + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[44]).Range.Text = model_2806.Back_Tmdiff + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[45]).Range.Text = model_2806.TmMax + "";
                }
                #endregion

                #region 1111
                if (testStandardEnum == TestStandardEnum.default1711)
                {
                    //声明书签数组
                    object[] oBookMark = new object[42];
                    //赋值书签名
                    oBookMark[0] = "Pc";
                    oBookMark[1] = "Tc";
                    oBookMark[2] = "Ph";
                    oBookMark[3] = "Th";
                    oBookMark[4] = "Qm";
                    oBookMark[5] = "Tm";

                    oBookMark[6]  = "A_1_Qc";
                    oBookMark[7]  = "A_1_Tc";
                    oBookMark[8]  = "A_1_Tcdiff";
                    oBookMark[9]  = "A_2_Qc";
                    oBookMark[10] = "A_3_Tm";
                    oBookMark[11] = "A_3_Tmdiff";

                    oBookMark[12] = "H_1_Tm";
                    oBookMark[13] = "H_1_3";
                    oBookMark[14] = "H_1_Tmdiff";
                    oBookMark[15] = "H_2_Tm";
                    oBookMark[16] = "H_2_Tmdiff";

                    oBookMark[17] = "C_1_Tm";
                    oBookMark[18] = "C_1_3";
                    oBookMark[19] = "C_1_Tmdiff";
                    oBookMark[20] = "C_2_Tm";
                    oBookMark[21] = "C_2_Tmdiff";

                    oBookMark[22] = "Cool_1_Tm";
                    oBookMark[23] = "Cool_1_3";
                    oBookMark[24] = "Cool_1_Tmdiff";
                    oBookMark[25] = "Cool_2_Tm";
                    oBookMark[26] = "Cool_2_Tmdiff";

                    oBookMark[27] = "Steady_1_Tm";
                    oBookMark[28] = "Steady_1_Tmdiff";
                    oBookMark[29] = "Steady_2_Tm";
                    oBookMark[30] = "Steady_2_Tmdiff";
                    oBookMark[31] = "Steady_2_3";

                    oBookMark[32] = "Steady_3_Tm";
                    oBookMark[33] = "Steady_3_Tmdiff";
                    oBookMark[34] = "Steady_4_Tm";
                    oBookMark[35] = "Steady_4_Tmdiff";
                    oBookMark[36] = "Steady_4_3";

                    oBookMark[37] = "FLow_1_Qm";
                    oBookMark[38] = "FLow_1_Tm";
                    oBookMark[39] = "FLow_1_Tmdiff";
                    oBookMark[40] = "FLow_2_Tm";
                    oBookMark[41] = "FLow_2_Tmdiff";

                    //赋值任意数据到书签的位置
                    oDoc.Bookmarks.get_Item(ref oBookMark[0]).Range.Text = model_1111.Pc + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[1]).Range.Text = model_1111.Tc + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[2]).Range.Text = model_1111.Ph + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[3]).Range.Text = model_1111.Th + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[4]).Range.Text = model_1111.Qm + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[5]).Range.Text = model_1111.Tm + "";

                    oDoc.Bookmarks.get_Item(ref oBookMark[6]).Range.Text  = model_1111.A_1_Qc + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[7]).Range.Text  = model_1111.A_1_Tc + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[8]).Range.Text  = model_1111.A_1_Tcdiff + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[9]).Range.Text  = model_1111.A_2_Qc + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[10]).Range.Text = model_1111.A_3_Tm + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[11]).Range.Text = model_1111.A_3_Tmdiff + "";

                    oDoc.Bookmarks.get_Item(ref oBookMark[12]).Range.Text = model_1111.H_1_Tm + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[13]).Range.Text = model_1111.H_1_3 + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[14]).Range.Text = model_1111.H_1_Tmdiff + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[15]).Range.Text = model_1111.H_2_Tm + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[16]).Range.Text = model_1111.H_2_Tmdiff + "";

                    oDoc.Bookmarks.get_Item(ref oBookMark[17]).Range.Text = model_1111.C_1_Tm + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[18]).Range.Text = model_1111.C_1_3 + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[19]).Range.Text = model_1111.C_1_Tmdiff + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[20]).Range.Text = model_1111.C_2_Tm + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[21]).Range.Text = model_1111.C_2_Tmdiff + "";

                    oDoc.Bookmarks.get_Item(ref oBookMark[22]).Range.Text = model_1111.Cool_1_Tm + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[23]).Range.Text = model_1111.Cool_1_3 + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[24]).Range.Text = model_1111.Cool_1_Tmdiff + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[25]).Range.Text = model_1111.Cool_2_Tm + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[26]).Range.Text = model_1111.Cool_2_Tmdiff + "";

                    oDoc.Bookmarks.get_Item(ref oBookMark[27]).Range.Text = model_1111.Steady_1_Tm + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[28]).Range.Text = model_1111.Steady_1_Tmdiff + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[29]).Range.Text = model_1111.Steady_2_Tm + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[30]).Range.Text = model_1111.Steady_2_Tmdiff + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[31]).Range.Text = model_1111.Steady_2_3 + "";

                    oDoc.Bookmarks.get_Item(ref oBookMark[32]).Range.Text = model_1111.Steady_3_Tm + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[33]).Range.Text = model_1111.Steady_3_Tmdiff + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[34]).Range.Text = model_1111.Steady_4_Tm + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[35]).Range.Text = model_1111.Steady_4_Tmdiff + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[36]).Range.Text = model_1111.Steady_4_3 + "";

                    oDoc.Bookmarks.get_Item(ref oBookMark[37]).Range.Text = model_1111.FLow_1_Qm + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[38]).Range.Text = model_1111.FLow_1_Tm + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[39]).Range.Text = model_1111.FLow_1_Tmdiff + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[40]).Range.Text = model_1111.FLow_2_Tm + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[41]).Range.Text = model_1111.FLow_2_Tmdiff + "";
                }
                #endregion

                //弹出保存文件对话框,保存生成的Word
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Filter     = "Word Document(*.doc)|*.doc";
                sfd.DefaultExt = "Word Document(*.doc)|*.doc";
                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    object filename = sfd.FileName;

                    oDoc.SaveAs(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);
                    oDoc.Close(ref oMissing, ref oMissing, ref oMissing);
                    //关闭word
                    oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
                    MessageBox.Show("保存成功!");
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
                return;
            }
        }
Exemple #19
0
        /// <summary>
        /// 导出审批表word
        /// </summary>
        /// <param name="path">文件路径</param>
        /// <param name="Type">0-首营供货商,1-首营客户,2-首营药品</param>
        /// <returns></returns>
        public bool CreateWord(string Filename, string Name, int Type)
        {
            Word._Application oWord = new Word.Application();
            Word._Document    oDoc  = null;
            try
            {
                object oMissing = System.Reflection.Missing.Value;

                oWord.Visible = false;
                object oTemplate = Filename;
                oDoc = oWord.Documents.Open(ref oTemplate, ref oMissing, ref oMissing, ref oMissing);
                oDoc.Activate();

                #region 这是首营信息们
                if (b != null)
                {
                    this.insertMarks(oDoc, 0);
                    this.insertGsp(oDoc, b.GSPLCID, b.id);
                    this.insertMedicineBussiness(oDoc, b.MedicineBusinessLCID);
                    this.insertBussiness(oDoc, b.BusinessLCID);
                    this.insertOrg(oDoc, b.OrganizationCodeLCID);
                    this.insertTax(oDoc, b.TaxRegisterLCID);
                    this.insertInstB(oDoc, b.InstrumentsBusinessLCID);
                    this.insertInstP(oDoc, b.InstrumentsProductionLCID);
                    this.insertHealth(oDoc, b.HealthLCID);
                    this.InsertGMP(oDoc, b.GMPLCID);
                    this.insertDelegate(oDoc);
                    this.insertSCXKZ(oDoc, b.MedicineProductionLCID);
                    this.insertQualityAgreement(oDoc);
                    this.insertBank(oDoc);

                    Service.Models.QueryApprovalFlowRecordModel aq = new  Service.Models.QueryApprovalFlowRecordModel
                    {
                        FlowId = b.ApprovalFlowId
                    };

                    var c = baseform.PharmacyDatabaseService.SearchApprovalFlowRecordsByQueryModel(out msg, aq).OrderBy(r => r.ApproveTime).ToList();

                    if (oDoc.Bookmarks["flow1"] != null)
                    {
                        for (int i = 0; i < c.Count; i++)
                        {
                            oDoc.Bookmarks["flow" + (i + 1)].Select();
                            oDoc.Bookmarks["flow" + (i + 1)].Range.Text = c[i].Comment;
                            var o = ListUsers.Where(r => r.Id == c[i].ApproveUserId).FirstOrDefault();
                            oDoc.Bookmarks["flowuser" + (i + 1)].Range.Text = o.Employee.Name + "  " + c[i].ApproveTime.ToLongDateString();
                        }
                    }
                }

                if (p != null)
                {
                    this.insertPurchaseBasicInfo(oDoc);
                    this.insertGsp(oDoc, p.GSPLCID, p.Id);
                    this.insertMedicineBussiness(oDoc, p.MedicineBusinessLCID);
                    this.insertBussiness(oDoc, p.BusinessLCID);
                    this.insertOrg(oDoc, p.OrganizationCodeLCID);
                    this.insertTax(oDoc, p.TaxRegisterLCID);
                    this.insertInstB(oDoc, p.InstrumentsBusinessLCID);
                    this.insertInstP(oDoc, p.InstrumentsProductionLCID);
                    this.insertHealth(oDoc, p.HealthLCID);
                    this.InsertGMP(oDoc, p.GMPLCID);
                    this.insertLn(oDoc, p.LnstitutionLegalPersonLCID);
                    this.InsertMMInst(oDoc, p.MmedicalInstitutionLCID);
                    this.insertDelegate(oDoc);
                    this.insertQualityAgreement(oDoc);
                }

                if (d != null)
                {
                    this.InsertDrugInfo(oDoc);
                }

                #region 医疗器械信息
                if (Inst != null)
                {
                    oDoc.Bookmarks["T1"].Select();
                    oDoc.Bookmarks["T1"].Range.Text = BugsBox.Pharmacy.AppClient.Common.PharmacyClientConfig.Config.Store.Name;

                    oDoc.Bookmarks["D1"].Range.Text  = Inst.ProductGeneralName;
                    oDoc.Bookmarks["D2"].Range.Text  = Inst.LicensePermissionNumber;
                    oDoc.Bookmarks["D3"].Range.Text  = Inst.PerformanceStandards;
                    oDoc.Bookmarks["D4"].Range.Text  = Inst.StandardCode;
                    oDoc.Bookmarks["D5"].Range.Text  = Inst.Code;
                    oDoc.Bookmarks["D6"].Range.Text  = Inst.DocCode;
                    oDoc.Bookmarks["D7"].Range.Text  = Inst.Pinyin;
                    oDoc.Bookmarks["D8"].Range.Text  = Inst.BarCode;
                    oDoc.Bookmarks["D11"].Range.Text = Inst.DictionaryMeasurementUnitCode;
                    oDoc.Bookmarks["D12"].Range.Text = Inst.DictionaryDosageCode;
                    oDoc.Bookmarks["D13"].Range.Text = Inst.DictionarySpecificationCode;
                    oDoc.Bookmarks["D14"].Range.Text = Inst.FactoryName;
                    oDoc.Bookmarks["D15"].Range.Text = Inst.Contact;
                    oDoc.Bookmarks["D16"].Range.Text = Inst.BusinessScopeCode;
                    oDoc.Bookmarks["D17"].Range.Text = Inst.IsApproval;
                    oDoc.Bookmarks["D18"].Range.Text = Inst.Valid;
                    oDoc.Bookmarks["D19"].Range.Text = Inst.WareHouses;
                    oDoc.Bookmarks["D20"].Range.Text = Inst.WareHouseZone;
                    oDoc.Bookmarks["D21"].Range.Text = Inst.DrugStorageTypeCode;
                    oDoc.Bookmarks["D22"].Range.Text = Inst.MaxInventoryCount.ToString();
                    oDoc.Bookmarks["D23"].Range.Text = Inst.MinInventoryCount.ToString();
                    oDoc.Bookmarks["D24"].Range.Text = Inst.ValidPeriod.ToString() + "个月";
                    oDoc.Bookmarks["D25"].Range.Text = Inst.DrugCategoryCode;
                    oDoc.Bookmarks["D26"].Range.Text = Inst.Price.ToString();
                    oDoc.Bookmarks["D27"].Range.Text = Inst.SalePrice.ToString();
                    oDoc.Bookmarks["D28"].Range.Text = Inst.LimitedUpPrice.ToString();
                    oDoc.Bookmarks["D29"].Range.Text = Inst.LimitedLowPrice.ToString();
                    oDoc.Bookmarks["D31"].Range.Text = Inst.Description;
                    oDoc.Bookmarks["D48"].Range.Text = Inst.CreateTime.ToString();
                    oDoc.Bookmarks["D49"].Range.Text = Inst.CreateUserName;
                }
                #endregion

                #region 保健食品信息
                if (this.Food != null)
                {
                    oDoc.Bookmarks["T1"].Select();
                    oDoc.Bookmarks["T1"].Range.Text = BugsBox.Pharmacy.AppClient.Common.PharmacyClientConfig.Config.Store.Name;

                    oDoc.Bookmarks["D1"].Range.Text  = Food.ProductGeneralName;
                    oDoc.Bookmarks["D2"].Range.Text  = Food.LicensePermissionNumber;
                    oDoc.Bookmarks["D3"].Range.Text  = Food.PerformanceStandards;
                    oDoc.Bookmarks["D4"].Range.Text  = Food.LicensePermissionOutValidDate.ToShortDateString();
                    oDoc.Bookmarks["D5"].Range.Text  = Food.Code;
                    oDoc.Bookmarks["D6"].Range.Text  = Food.DocCode;
                    oDoc.Bookmarks["D7"].Range.Text  = Food.Pinyin;
                    oDoc.Bookmarks["D8"].Range.Text  = Food.BarCode;
                    oDoc.Bookmarks["D11"].Range.Text = Food.DictionaryMeasurementUnitCode;
                    oDoc.Bookmarks["D12"].Range.Text = Food.DictionaryDosageCode;
                    oDoc.Bookmarks["D13"].Range.Text = Food.DictionarySpecificationCode;
                    oDoc.Bookmarks["D14"].Range.Text = Food.FactoryName;
                    oDoc.Bookmarks["D15"].Range.Text = Food.Contact;
                    oDoc.Bookmarks["D16"].Range.Text = Food.BusinessScopeCode;
                    oDoc.Bookmarks["D17"].Range.Text = Food.IsApproval;
                    oDoc.Bookmarks["D18"].Range.Text = Food.Valid;
                    oDoc.Bookmarks["D19"].Range.Text = Food.WareHouses;
                    oDoc.Bookmarks["D20"].Range.Text = Food.WareHouseZone;
                    oDoc.Bookmarks["D21"].Range.Text = Food.DrugStorageTypeCode;
                    oDoc.Bookmarks["D22"].Range.Text = Food.MaxInventoryCount.ToString();
                    oDoc.Bookmarks["D23"].Range.Text = Food.MinInventoryCount.ToString();
                    oDoc.Bookmarks["D24"].Range.Text = Food.ValidPeriod.ToString() + "个月";
                    oDoc.Bookmarks["D25"].Range.Text = Food.IsImport;



                    oDoc.Bookmarks["D26"].Range.Text = Food.Price.ToString();
                    oDoc.Bookmarks["D27"].Range.Text = Food.SalePrice.ToString();
                    oDoc.Bookmarks["D28"].Range.Text = Food.LimitedUpPrice.ToString();
                    oDoc.Bookmarks["D29"].Range.Text = Food.LimitedLowPrice.ToString();

                    oDoc.Bookmarks["D30"].Range.Text = Food.Origin;
                    oDoc.Bookmarks["D31"].Range.Text = Food.Description;

                    oDoc.Bookmarks["D48"].Range.Text = Food.CreateTime.ToString();
                    oDoc.Bookmarks["D49"].Range.Text = Food.CreateUserName;
                }

                #endregion

                #endregion

                #region word保存
                System.Windows.Forms.SaveFileDialog sfd = new System.Windows.Forms.SaveFileDialog();
                sfd.Filter     = "Word Document(*.doc)|*.doc";
                sfd.DefaultExt = "Word Document(*.doc)|*.doc";
                sfd.FileName   = Name + DateTime.Now.Ticks + ".doc";
                if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    object filename = sfd.FileName;
                    oDoc.SaveAs(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);
                    oDoc.Close(ref oMissing, ref oMissing, ref oMissing);
                    if (oDoc != null)
                    {
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(oDoc);
                        oDoc = null;
                    }
                    if (oWord != null)
                    {
                        oWord.Quit();
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(oWord);
                        oWord = null;
                    }
                    return(true);
                }
                else
                {
                    if (oDoc != null)
                    {
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(oDoc);
                        oDoc = null;
                    }
                    if (oWord != null)
                    {
                        oWord.Quit(Word.WdSaveOptions.wdDoNotSaveChanges);
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(oWord);
                        oWord = null;
                    }
                    return(false);
                }
            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show(Name + ":审批信息表导出失败!");
                if (oWord != null)
                {
                    oWord.Quit(Word.WdSaveOptions.wdDoNotSaveChanges);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(oWord);
                    oWord = null;
                }
                if (oDoc != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(oDoc);
                    oDoc = null;
                }
                return(false);
            }
            finally
            {
                if (oWord != null)
                {
                    oWord.Quit();
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(oWord);
                    oWord = null;
                }
                if (oDoc != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(oDoc);
                    oDoc = null;
                }
            }
            #endregion
        }
Exemple #20
0
        /// <summary>
        /// 打印病历
        /// </summary>
        public void Print(HIS.EMR_BLL.EmrRecord emrRecord)
        {
            XmlDocument xmlDoc = new HIS.EMR_BLL.OperaEmrRecord().GetPatInfo(emrRecord.PatListId, emrRecord.RecordCreateDate);

            object oMissing  = System.Reflection.Missing.Value;
            object oEndOfDoc = "\\endofdoc";

            Word.Application wordApp = new Word.Application();
            base.InitWordApplication(wordApp, xmlDoc, Public.EMRType.手术记录);

            int columnNum = xmlDoc.SelectSingleNode("病人信息/基本信息").ChildNodes.Count;

            Word.Table table = wordApp.ActiveDocument.Tables.Add(wordApp.Selection.Range, columnNum, 1, ref oMissing, ref oMissing);
            wordApp.Selection.Borders.OutsideLineStyle = WdLineStyle.wdLineStyleNone;
            wordApp.Selection.Borders.InsideLineStyle  = WdLineStyle.wdLineStyleNone;
            int    columnNo = 1;
            object step     = 1;
            object unit     = Word.WdUnits.wdCharacter;
            object extend   = Word.WdMovementType.wdExtend;

            foreach (XmlNode node in xmlDoc.SelectSingleNode("病人信息/基本信息").ChildNodes)
            {
                wordApp.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
                wordApp.Selection.Font.Size = Public.StaticVariable.BodyTitleFontSize;
                wordApp.Selection.Font.Bold = Public.StaticVariable.BodyTitleFontBold;
                wordApp.Selection.Font.Name = Public.StaticVariable.BodyTitleFontName;
                wordApp.Selection.TypeText("    " + node.InnerText.Split(':')[0] + ":");
                wordApp.Selection.Font.Size = Public.StaticVariable.BodyFontSize;
                wordApp.Selection.Font.Bold = Public.StaticVariable.BodyFontBold;
                wordApp.Selection.Font.Name = Public.StaticVariable.BodyFontName;
                wordApp.Selection.TypeText(node.InnerText.Split(':')[1]);
                columnNo++;
                //if (columnNo <= columnNum)
                //{
                //    wordApp.Selection.Move(ref unit, ref step);
                //}
                //else
                //{
                unit = Word.WdUnits.wdLine;
                wordApp.Selection.MoveDown(ref unit, ref step, ref oMissing);
                //    break;
                //}
            }

            XElement xe    = XElement.Parse(this.GetValue().InnerXml);
            var      nodes = from e in xe.Descendants()
                             orderby e.Attribute("Code").Value
                             select e;

            foreach (XElement node in nodes)
            {
                if (node.Value.ToString().Trim().Length > 0)
                {
                    wordApp.Selection.TypeParagraph();
                    wordApp.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
                    wordApp.Selection.Font.Size = Public.StaticVariable.BodyTitleFontSize;
                    wordApp.Selection.Font.Bold = Public.StaticVariable.BodyTitleFontBold;
                    wordApp.Selection.Font.Name = Public.StaticVariable.BodyTitleFontName;
                    wordApp.Selection.TypeText("    " + node.Name.ToString().Trim() + ":");
                    wordApp.Selection.Font.Size = Public.StaticVariable.BodyFontSize;
                    wordApp.Selection.Font.Bold = Public.StaticVariable.BodyFontBold;
                    wordApp.Selection.Font.Name = Public.StaticVariable.BodyFontName;
                    wordApp.Selection.TypeText(node.Value.ToString().Trim());
                }
            }

            //医生签名
            wordApp.Selection.TypeParagraph();
            wordApp.Selection.TypeParagraph();
            wordApp.Selection.Font.Size = Public.StaticVariable.BodyFontSize;
            wordApp.Selection.Font.Bold = 0;
            wordApp.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphRight;
            wordApp.Selection.TypeText("手术医师:____________________");
            wordApp.Selection.TypeParagraph();
            wordApp.Selection.TypeText("主治医师:____________________");
            wordApp.Selection.TypeParagraph();
            wordApp.Selection.TypeText("科主任或副主任医师:__________");
            wordApp.Selection.TypeParagraph();
            wordApp.Selection.TypeText("      记录时间:" + emrRecord.RecordCreateDate.Year + "." + emrRecord.RecordCreateDate.Month + "." + emrRecord.RecordCreateDate.Day + "." + emrRecord.RecordCreateDate.Hour + ":" + emrRecord.RecordCreateDate.Minute);
        }
Exemple #21
0
        static void Main(string[] args)
        {
            object
                oMissing = Type.Missing;               //System.Reflection.Missing.Value;

            Word.Application
                WordApp = null;

            Word.Document
                Document = null;

            Word.Table
                Table = null;

            string
                CurrentDirectory = System.IO.Directory.GetCurrentDirectory(),
                tmpString;

            CurrentDirectory = CurrentDirectory.Substring(0, CurrentDirectory.LastIndexOf("bin", CurrentDirectory.Length - 1));

            object
                InputFileName,
                OutputFileName,
                tmpObject;

            try
            {
                try
                {
                    try
                    {
                        WordApp = (Word.Application)Marshal.GetActiveObject("Word.Application");
                    }
                    catch (COMException eException)
                    {
                        if (eException.ErrorCode == -2147221021)
                        {
                            WordApp = new Word.Application();
                        }
                    }

                    WordApp.Visible = true;

                                        #if TEST_BOOKMARK
                    InputFileName = CurrentDirectory + "Word_tst.doc";
                    Document      = WordApp.Documents.Open(ref InputFileName, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
                    if (Document.Bookmarks.Count > 0)
                    {
                        tmpString = "MyBookmark";
                        if (Document.Bookmarks.Exists(tmpString))
                        {
                            tmpObject = tmpString;

                                                                #if TEST_BOOKMARK_BY_BOOKMARKS_COLLECTION
                            Document.Bookmarks.Item(ref tmpObject).Select();
                                                                #else
                            object
                                What = Word.WdGoToItem.wdGoToBookmark;

                            WordApp.Selection.GoTo(/*What*/ ref What, /*Which*/ ref oMissing, /*Count*/ ref oMissing, /*Name*/ ref tmpObject);
                                                                #endif

                            WordApp.Selection.Text = "1234567890";
                        }
                    }
                    OutputFileName = CurrentDirectory + "Word_tst_out.doc";
                    if (File.Exists(OutputFileName.ToString()))
                    {
                        File.Delete(OutputFileName.ToString());
                    }

                    Document.SaveAs(ref OutputFileName, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
                    Document.Close(ref oMissing, ref oMissing, ref oMissing);
                                        #endif

                    Document = WordApp.Documents.Add(ref oMissing, ref oMissing);

                    int
                        index   = 0,
                        rows    = 3,
                        columns = 2;

                    Table = Document.Tables.Add(WordApp.Selection.Range, rows + 1, columns);
                    Table.Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                    Table.Range.Bold = 1;
                    for (int i = 0; i < columns; i++)
                    {
                        Table.Cell(0, i + 1).Range.InsertAfter(i.ToString());
                    }
                    for (int j = 1; j <= rows; j++)
                    {
                        Table.Rows.Item(j + 1).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft;
                        Table.Rows.Item(j + 1).Range.Bold = 0;
                        for (int i = 0; i < columns; i++)
                        {
                            Table.Cell(j + 1, i + 1).Range.InsertAfter(index.ToString());
                            index++;
                        }
                    }

                    OutputFileName = CurrentDirectory + "test_out.doc";
                    if (File.Exists(OutputFileName.ToString()))
                    {
                        File.Delete(OutputFileName.ToString());
                    }

                    Document.SaveAs(ref OutputFileName, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
                    Document.Close(ref oMissing, ref oMissing, ref oMissing);
                }
                catch (COMException eException)
                {
                    string
                        tmp = eException.GetType().FullName + Environment.NewLine + "ErrorCode: " + eException.ErrorCode + Environment.NewLine + "Message: " + eException.Message + Environment.NewLine + "StackTrace:" + Environment.NewLine + eException.StackTrace;

                    Console.WriteLine(tmp);
                }
                catch (ArgumentException eException)
                {
                    string
                        tmp = eException.GetType().FullName + Environment.NewLine + "ParamName: " + eException.ParamName + Environment.NewLine + "Message: " + eException.Message + Environment.NewLine + "StackTrace:" + Environment.NewLine + eException.StackTrace;

                    Console.WriteLine(tmp);
                }
                catch (Exception eException)
                {
                    string
                        tmp = eException.GetType().FullName + Environment.NewLine + "Message: " + eException.Message + Environment.NewLine + "StackTrace:" + Environment.NewLine + eException.StackTrace;

                    Console.WriteLine(tmp);
                }
            }
            finally
            {
                if (Table != null)
                {
                    Marshal.ReleaseComObject(Table);
                    Table = null;
                }
                if (Document != null)
                {
                    Marshal.ReleaseComObject(Document);
                    Document = null;
                }
                if (WordApp != null)
                {
                    WordApp.Quit(ref oMissing, ref oMissing, ref oMissing);
                    Marshal.ReleaseComObject(WordApp);
                    WordApp = null;
                }
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                GC.GetTotalMemory(true);
                //GC.SuppressFinalize(this);
            }
        }
Exemple #22
0
        /// <summary>
        /// 打印病历
        /// </summary>
        public void Print(HIS.EMR_BLL.EmrRecord emrRecord)
        {
            XmlDocument xmlDoc = HIS.EMR_BLL.OP_EmrRecord.GetPatInfo(emrRecord.PatListId, 0, emrRecord.RecordCreateDate);

            object oMissing  = System.Reflection.Missing.Value;
            object oEndOfDoc = "\\endofdoc";

            Word.Application wordApp = new Word.Application();
            base.InitWordApplication(wordApp, xmlDoc, Public.EMRType.入院记录);

            //插入标题
            wordApp.Selection.TypeParagraph();
            wordApp.Selection.Font.Size = Public.StaticVariable.BodyTitleFontSize;
            wordApp.Selection.Font.Bold = 2;
            wordApp.Selection.TypeText(this.Name);

            wordApp.Selection.TypeParagraph();
            wordApp.ActiveDocument.Tables.Add(wordApp.Selection.Range, 6, 2, ref oMissing, ref oMissing);
            wordApp.Selection.Borders.OutsideLineStyle = WdLineStyle.wdLineStyleNone;
            wordApp.Selection.Borders.InsideLineStyle  = WdLineStyle.wdLineStyleNone;
            wordApp.Selection.Cells.Height             = 22;
            int    rowNo    = 1;
            int    columnNo = 1;
            object step     = 1;
            object unit     = Word.WdUnits.wdCharacter;
            object extend   = Word.WdMovementType.wdExtend;

            foreach (XmlNode node in xmlDoc.SelectSingleNode("病人信息/就诊信息").ChildNodes)
            {
                wordApp.Selection.Font.Size = Public.StaticVariable.BodyFontSize;
                wordApp.Selection.Font.Bold = 0;
                wordApp.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
                wordApp.Selection.TypeText("    " + node.InnerText);
                columnNo++;
                if (columnNo > 2)
                {
                    columnNo = 1;
                    rowNo++;
                }
                if (rowNo > 6)
                {
                    unit = Word.WdUnits.wdLine;
                    wordApp.Selection.MoveDown(ref unit, ref step, ref oMissing);
                    break;
                }
                if (columnNo == 1)
                {
                    unit = Word.WdUnits.wdCell;
                    wordApp.Selection.MoveRight(ref unit, ref step, ref oMissing);
                }
                else
                {
                    wordApp.Selection.Move(ref unit, ref step);
                }
            }

            XElement xe    = XElement.Parse(this.GetValue().InnerXml);
            var      nodes = from e in xe.Descendants()
                             orderby e.Attribute("Code").Value
                             select e;

            foreach (XElement node in nodes)
            {
                if (node.Value.ToString().Trim().Length > 0)
                {
                    wordApp.Selection.TypeParagraph();
                    wordApp.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
                    wordApp.Selection.Font.Size = Public.StaticVariable.BodyTitleFontSize;
                    wordApp.Selection.Font.Bold = Public.StaticVariable.BodyTitleFontBold;
                    wordApp.Selection.Font.Name = Public.StaticVariable.BodyTitleFontName;
                    wordApp.Selection.TypeText("    " + node.Name.ToString().Trim() + ":");
                    wordApp.Selection.Font.Size = Public.StaticVariable.BodyFontSize;
                    wordApp.Selection.Font.Bold = Public.StaticVariable.BodyFontBold;
                    wordApp.Selection.Font.Name = Public.StaticVariable.BodyFontName;
                    wordApp.Selection.TypeText(node.Value.ToString().Trim());
                }
            }

            //医生签名
            wordApp.Selection.TypeParagraph();
            wordApp.Selection.TypeParagraph();
            wordApp.Selection.Font.Size = Public.StaticVariable.BodyFontSize;
            wordApp.Selection.Font.Bold = 0;
            wordApp.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphRight;
            //wordApp.Selection.TypeText("医生签名:" + new GWMHIS.BussinessLogicLayer.Classes.Employee((long)emrRecord.RecordCreateEmp).Name + "    ");
            wordApp.Selection.TypeText("医生签名:____________________");
            wordApp.Selection.TypeParagraph();
            wordApp.Selection.TypeText(emrRecord.RecordCreateDate.ToLongDateString() + "    ");
        }
        /// <summary>
        /// 打印病历
        /// </summary>
        public void Print(HIS.EMR_BLL.EmrRecord emrRecord)
        {
            XmlDocument xmlDoc = HIS.EMR_BLL.OP_EmrRecord.GetPatInfo(emrRecord.PatListId, 1, emrRecord.RecordCreateDate);

            Word.Application wordApp = new Word.Application();
            base.InitWordApplication(wordApp, xmlDoc, Public.EMRType.病程记录);

            DataTable tmpTable = HIS.EMR_BLL.OP_EmrRecord.GetDiseaseCourseRecord(emrRecord.PatId, emrRecord.PatListId, Public.PublicStaticFunction.GetEMRTypeCode(Public.EMRType.病程记录));

            for (int index = 0; index < tmpTable.Rows.Count; index++)
            {
                HIS.EMR_BLL.EmrRecord record = new HIS.EMR_BLL.EmrRecord();
                record = (HIS.EMR_BLL.EmrRecord)HIS.SYSTEM.PubicBaseClasses.ApiFunction.DataTableToObject(tmpTable, index, record);

                //病程记录时间
                wordApp.Selection.TypeParagraph();
                wordApp.Selection.Font.Size = Public.StaticVariable.BodyFontSize;
                wordApp.Selection.Font.Bold = 1;
                wordApp.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
                if (index == 0)
                {
                    wordApp.Selection.TypeText(record.RecordCreateDate.ToLongDateString() + " " + record.RecordCreateDate.ToLongTimeString() + ":首次病程记录");
                }
                else
                {
                    wordApp.Selection.TypeText(record.RecordCreateDate.ToLongDateString() + " " + record.RecordCreateDate.ToLongTimeString());
                }

                XElement xe    = XElement.Parse(record.RecordContentXml.InnerXml.ToString());
                var      nodes = from e in xe.Descendants()
                                 orderby e.Attribute("Code").Value
                                 select e;

                int num = -1;
                foreach (XElement node in nodes)
                {
                    num++;
                    if (node.Value.ToString().Trim().Length <= 0)
                    {
                        continue;
                    }
                    switch (num)
                    {
                    case 0:
                        WriteBodyTitle(wordApp, "一、" + node.Name.ToString().Trim() + ":", 2);
                        WriteBody(wordApp, "" + node.Value.ToString().Trim(), 4);
                        WriteBodyTitle(wordApp, "" + "二、拟诊讨论" + ":", 2);
                        break;

                    case 1:
                        WriteBodyTitle(wordApp, "1、" + node.Name.ToString().Trim() + ":", 4);
                        WriteBody(wordApp, "" + node.Value.ToString().Trim(), 6);
                        break;

                    case 2:
                        WriteBodyTitle(wordApp, "2、" + node.Name.ToString().Trim() + ":", 4);
                        WriteBody(wordApp, "" + node.Value.ToString().Trim(), 6);
                        break;

                    case 3:
                        WriteBodyTitle(wordApp, "3、" + node.Name.ToString().Trim() + ":", 4);
                        WriteBody(wordApp, "" + node.Value.ToString().Trim(), 6);
                        break;

                    case 4:
                        WriteBodyTitle(wordApp, "三、" + node.Name.ToString().Trim() + ":", 2);
                        WriteBody(wordApp, "" + node.Value.ToString().Trim(), 4);
                        break;

                    case 5:
                        WriteBodyTitle(wordApp, "四、" + node.Name.ToString().Trim() + ":", 2);
                        WriteBody(wordApp, "" + node.Value.ToString().Trim(), 4);
                        break;
                    }
                }
                wordApp.Selection.TypeParagraph();

                //医生签名
                wordApp.Selection.Font.Size = textFontSize;
                wordApp.Selection.Font.Bold = 0;
                wordApp.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphRight;
                //wordApp.Selection.TypeText("医师签名:" + new GWMHIS.BussinessLogicLayer.Classes.Employee((long)record.RecordCreateEmp).Name);
                wordApp.Selection.TypeText("住院医师:____________________");
                //wordApp.Selection.TypeParagraph();
                //wordApp.Selection.TypeText(emrRecord.RecordCreateDate.ToLongDateString() + "    ");
                wordApp.Selection.TypeParagraph();
            }
        }
Exemple #24
0
 public void OnConnection(object Application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom)
 {
     jjword = Application;
     app    = jjword as Word.Application;
 }
        /// <summary>
        /// 打印病历
        /// </summary>
        public void Print(HIS.EMR_BLL.EmrRecord emrRecord)
        {
            XmlDocument xmlDoc = HIS.EMR_BLL.OP_EmrRecord.GetPatInfo(emrRecord.PatListId, 3, emrRecord.RecordCreateDate);

            object oMissing  = System.Reflection.Missing.Value;
            object oEndOfDoc = "\\endofdoc";

            Word.Application wordApp = new Word.Application();
            base.InitWordApplication(wordApp, xmlDoc, Public.EMRType.死亡记录);

            int columnNo = 1;

            foreach (XmlNode node in xmlDoc.SelectSingleNode("病人信息/基本信息").ChildNodes)
            {
                if (columnNo > 3)
                {
                    wordApp.Selection.TypeParagraph();
                    wordApp.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
                    wordApp.Selection.Font.Size = Public.StaticVariable.BodyTitleFontSize;
                    wordApp.Selection.Font.Bold = Public.StaticVariable.BodyTitleFontBold;
                    wordApp.Selection.Font.Name = Public.StaticVariable.BodyTitleFontName;
                    wordApp.Selection.TypeText("    " + node.Name + ":");
                    wordApp.Selection.ParagraphFormat.SpaceAfter = 3f;
                    wordApp.Selection.Font.Size = Public.StaticVariable.BodyFontSize;
                    wordApp.Selection.Font.Bold = Public.StaticVariable.BodyFontBold;
                    wordApp.Selection.Font.Name = Public.StaticVariable.BodyFontName;
                    wordApp.Selection.TypeText(node.InnerText);
                }
                columnNo++;
            }

            XElement xe    = XElement.Parse(this.GetValue().InnerXml);
            var      nodes = from e in xe.Descendants()
                             orderby e.Attribute("Code").Value
                             select e;

            foreach (XElement node in nodes)
            {
                if (node.Value.ToString().Trim().Length > 0)
                {
                    wordApp.Selection.TypeParagraph();
                    wordApp.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
                    wordApp.Selection.Font.Size = Public.StaticVariable.BodyTitleFontSize;
                    wordApp.Selection.Font.Bold = Public.StaticVariable.BodyTitleFontBold;
                    wordApp.Selection.Font.Name = Public.StaticVariable.BodyTitleFontName;
                    wordApp.Selection.TypeText("    " + node.Name.ToString().Trim() + ":");
                    wordApp.Selection.Font.Size = Public.StaticVariable.BodyFontSize;
                    wordApp.Selection.Font.Bold = Public.StaticVariable.BodyFontBold;
                    wordApp.Selection.Font.Name = Public.StaticVariable.BodyFontName;
                    wordApp.Selection.TypeText(node.Value.ToString().Trim());
                }
            }

            //医生签名
            wordApp.Selection.TypeParagraph();
            wordApp.Selection.TypeParagraph();
            wordApp.Selection.Font.Size = Public.StaticVariable.BodyFontSize;
            wordApp.Selection.Font.Bold = 0;
            wordApp.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphRight;
            //wordApp.Selection.TypeText("医师签名:" + new GWMHIS.BussinessLogicLayer.Classes.Employee((long)emrRecord.RecordCreateEmp).Name + "    ");
            wordApp.Selection.TypeText("医师签名:____________________");
            wordApp.Selection.TypeParagraph();
            wordApp.Selection.TypeText(emrRecord.RecordCreateDate.ToLongDateString() + emrRecord.RecordCreateDate.Hour + "时    ");
        }