private void BatchPrint(object sender, DoWorkEventArgs e) { int tick = 0; int total = _items.Count; string signature = ""; string purpose = ""; double fee = 0d; App.Current.Dispatcher.Invoke((Action) delegate // <--- HERE { QueueCounter.Content = tick + "/" + total; QueuePBar.IsIndeterminate = true; signature = Signatory.Text; purpose = Purpose.Text; fee = Convert.ToDouble(PrintingFee.Value); }); for (int i = 0; i < _items.Count; i++) { App.Current.Dispatcher.Invoke((Action) delegate // <--- HERE { QueueCounter.Content = tick + "/" + total; }); RecordEntryBaptismal recordx = (RecordEntryBaptismal)_items[i]; string x1, x2; string[] bspl = DateTime.Parse(recordx.BirthDate).ToString("MM/dd/yyyy").Split('/'); string bsuff = GetDaySuffix(int.Parse(bspl[1])); string bmon = PrepMonth(int.Parse(bspl[0])); if (int.Parse(bspl[2]) > 1999) { x1 = ""; bspl[2] = bspl[2].Remove(0, 2); } else { x1 = "X"; } string[] dspl = DateTime.Parse(recordx.BaptismalDate + "," + recordx.BaptismalYear).ToString("MM/dd/yyyy").Split('/'); string dsuff = GetDaySuffix(int.Parse(dspl[1])); string dmon = PrepMonth(int.Parse(dspl[0])); if (int.Parse(dspl[2]) > 1999) { x2 = ""; dspl[2] = dspl[2].Remove(0, 2); } else { x2 = "X"; } Document doc = new Document(); doc.LoadFromFile("Data\\temp_baptismal.docx"); doc.LoadFromFile("Data\\temp_baptismal.docx"); doc.Replace("name", recordx.FullName, true, true); doc.Replace("father", recordx.Parent1, true, true); doc.Replace("mother", recordx.Parent2, true, true); doc.Replace("born", recordx.PlaceOfBirth, true, true); doc.Replace("day1", int.Parse(bspl[1]) + bsuff, true, true); doc.Replace("month1", bmon, true, true); doc.Replace("X1", x1, true, true); doc.Replace("year1", DateTime.Parse(recordx.BirthDate).ToString("yyyy"), true, true); doc.Replace("day2", int.Parse(dspl[1]) + dsuff, true, true); doc.Replace("month2", dmon, true, true); doc.Replace("X2", x2, true, true); doc.Replace("year2", DateTime.Parse(recordx.BaptismalDate + "," + recordx.BaptismalYear).ToString("yyyy"), true, true); doc.Replace("church", pmsutil.GetChurchName(), true, true); doc.Replace("by", signature, true, true); doc.Replace("sponsor1", recordx.Godparent1, true, true); doc.Replace("sponsor2", recordx.Godparent2, true, true); doc.Replace("book", GetBNum(recordx.RecordID).ToString(), true, true); doc.Replace("page", GetPNum(recordx.RecordID).ToString(), true, true); doc.Replace("no", recordx.EntryNumber.ToString(), true, true); doc.Replace("priest", recordx.Minister, true, true); doc.Replace("purpose", purpose, true, true); doc.Replace("date", DateTime.Now.ToString("MMMM d, yyyy"), true, true); doc.SaveToFile("Data\\print-" + i + ".docx", FileFormat.Docx); //Load Document Document document = new Document(); document.LoadFromFile(@"Data\\print-" + i + ".docx"); //Convert Word to PDF document.SaveToFile("Output\\print_file-" + i + ".pdf", FileFormat.PDF); App.Current.Dispatcher.Invoke((Action) delegate // <--- HERE { if (SkipPreview.IsChecked == true) { Spire.Pdf.PdfDocument docx = new Spire.Pdf.PdfDocument(); docx.LoadFromFile(@"Output\\print_file-" + i + ".pdf"); docx.PrintDocument.Print(); } else { System.Diagnostics.Process.Start("Output\\print_file-" + i + ".pdf"); } if (Purpose.SelectedIndex == 0) { //Reference string tmp = pmsutil.LogRecord(recordx.RecordID, "LOGC-03"); } else { //Marriage string tmp = pmsutil.LogRecord(recordx.RecordID, "LOGC-04"); } }); pmsutil.InsertTransaction("Baptismal Cert.", "Paying", recordx.RecordID, Convert.ToDouble(pmsutil.GetPrintFee("Baptismal"))); tick++; } }
/// <summary> /// Inserts the request to the database. /// </summary> private int PrintEntry() { string x1, x2; string[] bspl = birthDate.Split('/'); string bsuff = GetDaySuffix(int.Parse(bspl[1])); string bmon = PrepMonth(int.Parse(bspl[0])); if (int.Parse(bspl[2]) > 1999) { x1 = ""; bspl[2] = bspl[2].Remove(0, 2); } else { x1 = "X"; } string[] dspl = baptismDate.Split('/'); string dsuff = GetDaySuffix(int.Parse(dspl[1])); string dmon = PrepMonth(int.Parse(dspl[0])); if (int.Parse(dspl[2]) > 1999) { x2 = ""; dspl[2] = dspl[2].Remove(0, 2); } else { x2 = "X"; } Document doc = new Document(); doc.LoadFromFile("Data\\temp_baptismal.docx"); doc.Replace("name", fullName, true, true); doc.Replace("father", parent1, true, true); doc.Replace("mother", parent2, true, true); doc.Replace("born", birthPlace, true, true); doc.Replace("day1", int.Parse(bspl[1]) + bsuff, true, true); doc.Replace("month1", bmon, true, true); doc.Replace("X1", x1, true, true); //doc.Replace("year1", bspl[2], true, true); doc.Replace("year1", DateTime.Parse(birthDate).ToString("yyyy"), true, true); doc.Replace("day2", int.Parse(dspl[1]) + dsuff, true, true); doc.Replace("month2", dmon, true, true); doc.Replace("X2", x2, true, true); doc.Replace("year2", DateTime.Parse(baptismDate).ToString("yyyy"), true, true); doc.Replace("church", pmsutil.GetChurchName(), true, true); doc.Replace("by", Signatory.Text, true, true); doc.Replace("sponsor1", sponsor1, true, true); doc.Replace("sponsor2", sponsor2, true, true); doc.Replace("book", bookNum.ToString(), true, true); doc.Replace("page", pageNum.ToString(), true, true); doc.Replace("no", entryNum.ToString(), true, true); doc.Replace("priest", minister, true, true); doc.Replace("purpose", Purpose.Text, true, true); doc.Replace("date", DateTime.Now.ToString("MMMM d, yyyy"), true, true); doc.SaveToFile("Data\\print.docx", FileFormat.Docx); //Load Document Document document = new Document(); document.LoadFromFile(@"Data\\print.docx"); //Convert Word to PDF document.SaveToFile("Output\\print_file.pdf", FileFormat.PDF); System.Diagnostics.Process.Start("Output\\print_file.pdf"); if (Purpose.SelectedIndex == 0) { //Reference string tmp = pmsutil.LogRecord(recordID, "LOGC-03"); } else { //Marriage string tmp = pmsutil.LogRecord(recordID, "LOGC-04"); } pmsutil.InsertTransaction("Baptismal Cert.", "Unpaid", recordID, Convert.ToDouble(PrintingFee.Value)); return(1); }