コード例 #1
0
        //</Snippet2>


        //---------------------------------------------------------------------
        //<Snippet3>
        private void AddData(System.Data.DataRow row, string companyName)
        {
            object missing = System.Type.Missing;

            // Create a table if it doesn't already exist.
            if (Globals.ThisDocument.Tables.Count == 0)
            {
                try
                {
                    // Create a table.
                    Microsoft.Office.Interop.Word.Table tbl = Globals.ThisDocument.Tables.Add
                                                                  (Globals.ThisDocument.Application.Selection.Range, 1, 4, ref missing, ref missing);

                    // Insert headings.
                    SetHeadings(tbl.Cell(1, 1), "Company Name");
                    SetHeadings(tbl.Cell(1, 2), "Product Name");
                    SetHeadings(tbl.Cell(1, 3), "Quantity");
                    SetHeadings(tbl.Cell(1, 4), "Unit Price");
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Problem creating Products table: " + ex.Message,
                                    "Actions Pane", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            // Add data from data row to the table.
            Microsoft.Office.Interop.Word.Selection selection = Globals.ThisDocument.Application.Selection;

            if (selection.Tables.Count > 0)
            {
                Microsoft.Office.Interop.Word.Row newRow = Globals.ThisDocument.Tables[1].Rows.Add(ref missing);

                newRow.Range.Font.Bold = 0;

                newRow.Range.ParagraphFormat.Alignment =
                    Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;

                newRow.Cells[4].Range.ParagraphFormat.Alignment =
                    Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight;

                newRow.Cells[1].Range.Text = companyName;
                newRow.Cells[2].Range.Text = row["ProductName"].ToString();
                newRow.Cells[3].Range.Text = row["QuantityPerUnit"].ToString();
                newRow.Cells[4].Range.Text = Math.Round(Convert.ToDouble(row["UnitPrice"])).ToString("#,##0.00");
            }
            else
            {
                MessageBox.Show("Cursor must be within a table.",
                                "Actions Pane", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #2
0
        public static void PrintKetQuaCanLamSang(object reportFileName, DataRow patientRow, DataRow[] serviceRows, string printerName, bool isPrint)
        {
            Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
            Microsoft.Office.Interop.Word.Document    doc  = new Microsoft.Office.Interop.Word.Document();
            object missing = System.Type.Missing;

            try
            {
                doc = word.Documents.Open(ref reportFileName,
                                          ref missing, ref missing, ref missing, ref missing,
                                          ref missing, ref missing, ref missing, ref missing,
                                          ref missing, ref missing, ref missing, ref missing,
                                          ref missing, ref missing, ref missing);

                doc.Activate();

                //Fill Services
                Microsoft.Office.Interop.Word.Row dr = null;
                if (serviceRows != null && serviceRows.Length > 0)
                {
                    bool isFirst = true;
                    foreach (DataRow row in serviceRows)
                    {
                        if (isFirst)
                        {
                            dr      = doc.Tables[1].Rows[2];
                            isFirst = false;
                        }
                        else
                        {
                            dr = doc.Tables[1].Rows.Add(ref missing);
                        }

                        string serviceName         = row["Name"].ToString();
                        bool   isNormal_Abnormal   = Convert.ToBoolean(row["Normal_Abnormal"]);
                        bool   isNegative_Positive = Convert.ToBoolean(row["Negative_Positive"]);

                        if (isNormal_Abnormal)
                        {
                            serviceName += "\n Normal (Bình thường)	 Abnormal (Bất thường)";
                        }
                        if (isNegative_Positive)
                        {
                            serviceName += "\n Negative (Âm tính)                   	 Positive (Dương tính)";
                        }

                        dr.Cells[1].Range.Text = serviceName;
                        dr.Cells[1].Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;
                        SetNormalText(dr.Cells[1].Range);
                    }

                    dr = doc.Tables[1].Rows.Add(ref missing);
                    dr.Cells[1].Range.Text = string.Format("Others (Cận lâm sàng khác)");
                    dr.Cells[1].Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;
                    SetNormalText(dr.Cells[1].Range);
                }
                else
                {
                    dr = doc.Tables[1].Rows[2];
                    dr.Cells[1].Range.Text = string.Format("Others (Cận lâm sàng khác)");
                    dr.Cells[1].Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;
                    SetNormalText(dr.Cells[1].Range);
                }

                word.Visible = false;

                if (isPrint)
                {
                    word.ActivePrinter = printerName;

                    doc.PrintOut(ref missing, ref missing, ref missing, ref missing, ref missing,
                                 ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
                                 ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
                }
                else
                {
                    doc.Save();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (doc != null)
                {
                    doc.Close(ref missing, ref missing, ref missing);
                }
                if (word != null)
                {
                    word.Application.Quit(ref missing, ref missing, ref missing);
                }
            }
        }
コード例 #3
0
        public static void PrintChecklist(object reportFileName, DataRow patientRow, DataRow[] serviceRows, string printerName, bool isPrint)
        {
            string fileNum  = patientRow["FileNum"].ToString();
            string fullName = patientRow["FullName"].ToString();
            string dob      = patientRow["DobStr"].ToString();
            string gender   = patientRow["GenderAsStr"].ToString();
            string address  = patientRow["Address"] as string;
            string mobile   = patientRow["Mobile"] as string;
            string email    = patientRow["Email"] as string;

            Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
            Microsoft.Office.Interop.Word.Document    doc  = new Microsoft.Office.Interop.Word.Document();
            object missing = System.Type.Missing;

            try
            {
                doc = word.Documents.Open(ref reportFileName,
                                          ref missing, ref missing, ref missing, ref missing,
                                          ref missing, ref missing, ref missing, ref missing,
                                          ref missing, ref missing, ref missing, ref missing,
                                          ref missing, ref missing, ref missing);

                doc.Activate();

                foreach (Microsoft.Office.Interop.Word.Range tmpRange in doc.StoryRanges)
                {
                    tmpRange.Find.Text             = "#N";
                    tmpRange.Find.Replacement.Text = fullName;
                    tmpRange.Find.Wrap             = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue;
                    object replaceAll = Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll;
                    tmpRange.Find.Execute(ref missing, ref missing, ref missing,
                                          ref missing, ref missing, ref missing, ref missing,
                                          ref missing, ref missing, ref missing, ref replaceAll,
                                          ref missing, ref missing, ref missing, ref missing);

                    tmpRange.Find.Text             = "#S";
                    tmpRange.Find.Replacement.Text = gender;
                    tmpRange.Find.Wrap             = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue;
                    replaceAll = Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll;
                    tmpRange.Find.Execute(ref missing, ref missing, ref missing,
                                          ref missing, ref missing, ref missing, ref missing,
                                          ref missing, ref missing, ref missing, ref replaceAll,
                                          ref missing, ref missing, ref missing, ref missing);

                    tmpRange.Find.Text             = "#D";
                    tmpRange.Find.Replacement.Text = dob;
                    tmpRange.Find.Wrap             = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue;
                    replaceAll = Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll;
                    tmpRange.Find.Execute(ref missing, ref missing, ref missing,
                                          ref missing, ref missing, ref missing, ref missing,
                                          ref missing, ref missing, ref missing, ref replaceAll,
                                          ref missing, ref missing, ref missing, ref missing);

                    tmpRange.Find.Text             = "#A";
                    tmpRange.Find.Replacement.Text = address;
                    tmpRange.Find.Wrap             = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue;
                    replaceAll = Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll;
                    tmpRange.Find.Execute(ref missing, ref missing, ref missing,
                                          ref missing, ref missing, ref missing, ref missing,
                                          ref missing, ref missing, ref missing, ref replaceAll,
                                          ref missing, ref missing, ref missing, ref missing);

                    tmpRange.Find.Text             = "#T";
                    tmpRange.Find.Replacement.Text = mobile;
                    tmpRange.Find.Wrap             = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue;
                    replaceAll = Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll;
                    tmpRange.Find.Execute(ref missing, ref missing, ref missing,
                                          ref missing, ref missing, ref missing, ref missing,
                                          ref missing, ref missing, ref missing, ref replaceAll,
                                          ref missing, ref missing, ref missing, ref missing);

                    tmpRange.Find.Text             = "#E";
                    tmpRange.Find.Replacement.Text = email;
                    tmpRange.Find.Wrap             = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue;
                    replaceAll = Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll;
                    tmpRange.Find.Execute(ref missing, ref missing, ref missing,
                                          ref missing, ref missing, ref missing, ref missing,
                                          ref missing, ref missing, ref missing, ref replaceAll,
                                          ref missing, ref missing, ref missing, ref missing);
                }

                if (doc.Sections != null && doc.Sections.Count > 0)
                {
                    doc.Sections[1].Headers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Text = string.Format("CODE: {0}", fileNum);
                }

                //Fill Services
                int no = 2;
                Microsoft.Office.Interop.Word.Row dr = null;
                if (serviceRows != null && serviceRows.Length > 0)
                {
                    List <string> servicesNameList = new List <string>();
                    Hashtable     htServiceGroup   = new Hashtable();
                    foreach (DataRow row in serviceRows)
                    {
                        string serviceGUID = row["ServiceGUID"].ToString();
                        string serviceName = row["Name"].ToString();

                        Result result = ServiceGroupBus.GetServiceGroup(serviceGUID);
                        if (!result.IsOK)
                        {
                            MsgBox.Show(Application.ProductName, result.GetErrorAsString("ServiceGroupBus.GetServiceGroup"), IconType.Error);
                            Utility.WriteToTraceLog(result.GetErrorAsString("ServiceGroupBus.GetServiceGroup"));
                            return;
                        }
                        else
                        {
                            if (result.QueryResult == null)
                            {
                                servicesNameList.Add(serviceName);
                            }
                            else
                            {
                                ServiceGroup serviceGroup = result.QueryResult as ServiceGroup;
                                string       groupName    = serviceGroup.Name;
                                if (htServiceGroup.ContainsKey(groupName))
                                {
                                    List <string> serviceList = (List <string>)htServiceGroup[groupName];
                                    serviceList.Add(serviceName);
                                }
                                else
                                {
                                    List <string> serviceList = new List <string>();
                                    serviceList.Add(serviceName);
                                    htServiceGroup.Add(groupName, serviceList);
                                }
                            }
                        }
                    }

                    servicesNameList.Sort();
                    foreach (string groupName in htServiceGroup.Keys)
                    {
                        string        text        = string.Format("{0}.  {1}", no++, groupName);
                        List <string> serviceList = (List <string>)htServiceGroup[groupName];
                        int           subNo       = 0;
                        foreach (string serviceName in serviceList)
                        {
                            text += string.Format("\n     {0}. {1}", GetSubNo(subNo++), serviceName);
                        }

                        dr = doc.Tables[1].Rows.Add(ref missing);
                        dr.Cells[1].Range.Text = text;
                        SetNormalText(dr.Cells[1].Range);
                    }

                    foreach (string serviceName in servicesNameList)
                    {
                        dr = doc.Tables[1].Rows.Add(ref missing);
                        dr.Cells[1].Range.Text = string.Format("{0}.  {1}", no++, serviceName);
                        SetNormalText(dr.Cells[1].Range);
                    }
                }

                dr = doc.Tables[1].Rows.Add(ref missing);
                dr.Cells[1].Range.Text = string.Format("Prescription (Toa thuốc) 	 Nội khoa	 Tai Mũi Họng	 Răng Hàm Mặt	 Sản phụ khoa");

                Microsoft.Office.Interop.Word.Row dr2 = doc.Tables[1].Rows.Add(ref missing);
                dr2.Cells[1].Range.Text = string.Format("{0}.  Others (Khác)", no);
                SetNormalText(dr2.Cells[1].Range);

                dr.Cells[1].Merge(dr.Cells[2]);
                dr.Height = dr.Height / 2.5f;
                dr.Cells[1].Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;
                SetNormalText(dr.Cells[1].Range);

                word.Visible = false;

                if (isPrint)
                {
                    word.ActivePrinter = printerName;

                    doc.PrintOut(ref missing, ref missing, ref missing, ref missing, ref missing,
                                 ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
                                 ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
                }
                else
                {
                    doc.Save();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (doc != null)
                {
                    doc.Close(ref missing, ref missing, ref missing);
                }
                if (word != null)
                {
                    word.Application.Quit(ref missing, ref missing, ref missing);
                }
            }
        }
コード例 #4
0
        public static void PrintXetNghiem(object reportFileName, DataRow patientRow, DataRow[] serviceRows, string printerName, bool isPrint)
        {
            string fileNum  = patientRow["FileNum"].ToString();
            string fullName = patientRow["FullName"].ToString();
            string dob      = patientRow["DobStr"].ToString();
            string gender   = patientRow["GenderAsStr"].ToString();
            string address  = patientRow["Address"] as string;
            string mobile   = patientRow["Mobile"] as string;
            string email    = patientRow["Email"] as string;

            Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
            Microsoft.Office.Interop.Word.Document    doc  = new Microsoft.Office.Interop.Word.Document();
            object missing = System.Type.Missing;

            try
            {
                doc = word.Documents.Open(ref reportFileName,
                                          ref missing, ref missing, ref missing, ref missing,
                                          ref missing, ref missing, ref missing, ref missing,
                                          ref missing, ref missing, ref missing, ref missing,
                                          ref missing, ref missing, ref missing);

                doc.Activate();

                foreach (Microsoft.Office.Interop.Word.Range tmpRange in doc.StoryRanges)
                {
                    tmpRange.Find.Text             = "#N";
                    tmpRange.Find.Replacement.Text = fullName;
                    tmpRange.Find.Wrap             = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue;
                    object replaceAll = Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll;
                    tmpRange.Find.Execute(ref missing, ref missing, ref missing,
                                          ref missing, ref missing, ref missing, ref missing,
                                          ref missing, ref missing, ref missing, ref replaceAll,
                                          ref missing, ref missing, ref missing, ref missing);

                    tmpRange.Find.Text             = "#S";
                    tmpRange.Find.Replacement.Text = gender;
                    tmpRange.Find.Wrap             = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue;
                    replaceAll = Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll;
                    tmpRange.Find.Execute(ref missing, ref missing, ref missing,
                                          ref missing, ref missing, ref missing, ref missing,
                                          ref missing, ref missing, ref missing, ref replaceAll,
                                          ref missing, ref missing, ref missing, ref missing);

                    tmpRange.Find.Text             = "#D";
                    tmpRange.Find.Replacement.Text = dob;
                    tmpRange.Find.Wrap             = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue;
                    replaceAll = Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll;
                    tmpRange.Find.Execute(ref missing, ref missing, ref missing,
                                          ref missing, ref missing, ref missing, ref missing,
                                          ref missing, ref missing, ref missing, ref replaceAll,
                                          ref missing, ref missing, ref missing, ref missing);

                    tmpRange.Find.Text             = "#A";
                    tmpRange.Find.Replacement.Text = address;
                    tmpRange.Find.Wrap             = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue;
                    replaceAll = Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll;
                    tmpRange.Find.Execute(ref missing, ref missing, ref missing,
                                          ref missing, ref missing, ref missing, ref missing,
                                          ref missing, ref missing, ref missing, ref replaceAll,
                                          ref missing, ref missing, ref missing, ref missing);

                    tmpRange.Find.Text             = "#T";
                    tmpRange.Find.Replacement.Text = mobile;
                    tmpRange.Find.Wrap             = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue;
                    replaceAll = Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll;
                    tmpRange.Find.Execute(ref missing, ref missing, ref missing,
                                          ref missing, ref missing, ref missing, ref missing,
                                          ref missing, ref missing, ref missing, ref replaceAll,
                                          ref missing, ref missing, ref missing, ref missing);

                    tmpRange.Find.Text             = "#E";
                    tmpRange.Find.Replacement.Text = email;
                    tmpRange.Find.Wrap             = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue;
                    replaceAll = Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll;
                    tmpRange.Find.Execute(ref missing, ref missing, ref missing,
                                          ref missing, ref missing, ref missing, ref missing,
                                          ref missing, ref missing, ref missing, ref replaceAll,
                                          ref missing, ref missing, ref missing, ref missing);
                }

                if (doc.Sections != null && doc.Sections.Count > 0)
                {
                    doc.Sections[1].Headers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Text = string.Format("CODE: {0}", fileNum);
                }

                //Fill Services
                Microsoft.Office.Interop.Word.Row dr = null;
                if (serviceRows != null && serviceRows.Length > 0)
                {
                    foreach (DataRow row in serviceRows)
                    {
                        string serviceName = row["Name"].ToString();
                        dr = doc.Tables[1].Rows.Add(ref missing);
                        dr.Cells[1].Range.Text = serviceName;
                        dr.Cells[1].Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;
                        SetNormalText(dr.Cells[1].Range);
                    }
                }

                dr = doc.Tables[1].Rows.Add(ref missing);
                dr.Cells[1].Range.Text = string.Format("Notes (Ghi chú)\n\n\n\n");
                dr.Cells[1].Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;
                SetNormalText(dr.Cells[1].Range);

                word.Visible = false;

                if (isPrint)
                {
                    word.ActivePrinter = printerName;

                    doc.PrintOut(ref missing, ref missing, ref missing, ref missing, ref missing,
                                 ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
                                 ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
                }
                else
                {
                    doc.Save();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (doc != null)
                {
                    doc.Close(ref missing, ref missing, ref missing);
                }
                if (word != null)
                {
                    word.Application.Quit(ref missing, ref missing, ref missing);
                }
            }
        }