private void InvoiceBtn_Click(object sender, RibbonControlEventArgs e) { XLForms.ClientForm clientForm = new XLForms.ClientForm(); clientForm.ShowDialog(); if (clientForm.selectedClient != null) { XLMain.Client client = clientForm.selectedClient; XLMain.FPIClient fpiClient = XLMain.FPIClient.GetFPIClientInvoice(client); List <XLMain.FPIClient> clientList = new List <XLMain.FPIClient>(); clientList.Add(fpiClient); XLDocument.MergeFPIData(clientList.OrderBy(c => c.office).ToList()); } }
private void BulkInvoiceButton_Click(object sender, RibbonControlEventArgs e) { DateRangeForm myForm = new DateRangeForm(); myForm.ShowDialog(); if (myForm.ToDate != null && myForm.FromDate != null) { DateTime dateFrom = (DateTime)myForm.FromDate; DateTime dateTo = (DateTime)myForm.ToDate; string query = String.Format("SELECT * FROM dbo.FPIBulkInvoice('{0}', '{1}')", dateFrom.ToString("yyyy-MM-dd"), dateTo.ToString("yyyy-MM-dd")); System.Data.DataTable table = XLSQL.ReturnTable(query); List <XLMain.FPIClient> clients = new List <XLMain.FPIClient>(); foreach (System.Data.DataRow row in table.Rows) { XLMain.FPIClient client = new XLMain.FPIClient(row); clients.Add(client); } XLDocument.MergeFPIData(clients, forceNewDocument: true, asPdf: true, saveLocationForPdf: @"\\milsted-langdon\ml\ML\Facility\Admin\Admin - Common\FPI\FPI VAT Invoices\Bulk Invoices\"); } }
/// <summary> /// Merge an FPI list of clients into the current active document /// </summary> /// <param name="clients">The list of FPIClients you want to merge</param> public static void MergeFPIData(List <XLMain.FPIClient> clients, string templateXML = null, bool forceNewDocument = false, bool asPdf = false, string saveLocationForPdf = "") { UpdateCurrentDoc(); string office = "TAUNTON"; string department = "GPT"; string tempXML = ""; Header header = new Header(); long startPosition = currentDoc.Content.Start; long endPosition = currentDoc.Content.End; if (templateXML == null) { tempXML = CopyRangeToWordXML(currentDoc.Range()); } else { tempXML = templateXML; } long letterLength = endPosition - startPosition; List <PropertyInfo> properties = clients.FirstOrDefault().GetType().GetProperties().ToList(); app.Documents.Add(); UpdateCurrentDoc(); Range endRange = currentDoc.Range(currentDoc.Content.End - 1, currentDoc.Content.End - 1); endRange.InsertXML(tempXML); startPosition = 0; header = MapHeader(office, department); DeployHeader(header); tempXML = CopyRangeToWordXML(currentDoc.Range()); currentDoc.Close(WdSaveOptions.wdDoNotSaveChanges); app.Documents.Add(); UpdateCurrentDoc(); //List<HeaderFooter> headers = CopyHeaders(); //List<HeaderFooter> footers = CopyFooters(); endPosition = currentDoc.Content.End - 1; for (int i = 0; i < clients.Count; i++) { XLMain.FPIClient client = clients[i]; //make the start position the previous end position (less a few to catch all) unless new document if (forceNewDocument) { app.Documents.Add(); UpdateCurrentDoc(); endRange = currentDoc.Range(); } else { if (endPosition > letterLength) { startPosition = endPosition - letterLength; } else { startPosition = 0; } if (i > 0) { currentDoc.Words.Last.InsertBreak(WdBreakType.wdSectionBreakNextPage); } endRange = currentDoc.Range(currentDoc.Content.End - 1, currentDoc.Content.End - 1); } endRange.InsertXML(tempXML); DeployHeader(header); endPosition = currentDoc.Content.End - 1; Range currentRange = currentDoc.Range(startPosition, endPosition); UpdateFieldsFromRange(currentRange, client, properties); if (asPdf) { string pdf = CreatePdf(); AddHeadertoPDF(pdf, fileNamePref: client.clientcode, folderPref: saveLocationForPdf); currentDoc.Close(WdSaveOptions.wdDoNotSaveChanges); } } }