Exemplo n.º 1
0
        private void butLettersPreview_Click(object sender, EventArgs e)
        {
            //Create letters. loop through each row and insert information into sheets,
            //take all the sheets and add to one giant pdf for preview.
            if (gridMain.SelectedIndices.Length == 0)
            {
                MsgBox.Show(this, "Please select patient(s) first.");
                return;
            }
            FormSheetPicker FormS = new FormSheetPicker();

            FormS.SheetType = SheetTypeEnum.PatientLetter;
            FormS.ShowDialog();
            if (FormS.DialogResult != DialogResult.OK)
            {
                return;
            }
            SheetDef     sheetDef;
            Sheet        sheet      = null;
            List <Sheet> listSheets = new List <Sheet>();         //for saving

            for (int i = 0; i < FormS.SelectedSheetDefs.Count; i++)
            {
                PdfDocument document        = new PdfDocument();
                PdfPage     page            = new PdfPage();
                string      filePathAndName = "";
                for (int j = 0; j < gridMain.SelectedIndices.Length; j++)
                {
                    sheetDef = FormS.SelectedSheetDefs[i];
                    sheet    = SheetUtil.CreateSheet(sheetDef, PIn.Long(((DataRow)gridMain.SelectedGridRows[j].Tag)["PatNum"].ToString()));
                    SheetParameter.SetParameter(sheet, "PatNum", PIn.Long(((DataRow)gridMain.SelectedGridRows[j].Tag)["PatNum"].ToString()));
                    SheetFiller.FillFields(sheet);
                    sheet.SheetFields.Sort(SheetFields.SortDrawingOrderLayers);
                    SheetUtil.CalculateHeights(sheet);
                    SheetPrinting.PagesPrinted = 0;                  //Clear out the pages printed variable before printing all pages for this pdf.
                    int pageCount = Sheets.CalculatePageCount(sheet, SheetPrinting.PrintMargin);
                    for (int k = 0; k < pageCount; k++)
                    {
                        page = document.AddPage();
                        SheetPrinting.CreatePdfPage(sheet, page, null);
                    }
                    listSheets.Add(sheet);
                }
                filePathAndName = PrefC.GetRandomTempFile(".pdf");
                document.Save(filePathAndName);
                if (ODBuild.IsWeb())
                {
                    ThinfinityUtils.HandleFile(filePathAndName);
                }
                else
                {
                    Process.Start(filePathAndName);
                }
                DialogResult = DialogResult.OK;
            }
            if (MsgBox.Show(this, MsgBoxButtons.YesNo, "Would you like to save the sheets for the selected patients?"))
            {
                Sheets.SaveNewSheetList(listSheets);
            }
        }