예제 #1
0
 /// <summary>
 /// Create a new DueYear object.
 /// </summary>
 /// <param name="dueYearsId">Initial value of the DueYearsId property.</param>
 /// <param name="dueYear1">Initial value of the DueYear1 property.</param>
 /// <param name="duesDueDate">Initial value of the DuesDueDate property.</param>
 /// <param name="duesAmount">Initial value of the DuesAmount property.</param>
 public static DueYear CreateDueYear(global::System.Guid dueYearsId, global::System.String dueYear1, global::System.DateTime duesDueDate, global::System.Decimal duesAmount)
 {
     DueYear dueYear = new DueYear();
     dueYear.DueYearsId = dueYearsId;
     dueYear.DueYear1 = dueYear1;
     dueYear.DuesDueDate = duesDueDate;
     dueYear.DuesAmount = duesAmount;
     return dueYear;
 }
        public void ExportInvoicesToExcel(DueYear dueYear, string exportFile)
        {
            Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
            if (xlApp == null)
            {
                System.Windows.MessageBox.Show("You must have Microsoft Excel 2007 or greater installed and have administrator or power user permissions in order to export to excel.", "Export Error", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
                return;
            }

            Workbooks wbs = xlApp.Workbooks;
            Workbook wb = wbs.Add(XlWBATemplate.xlWBATWorksheet);
            Worksheet ws = (Worksheet)wb.Worksheets[1];

            if (ws != null)
            {
                ws.Cells[1, "A"] = "Year";
                ws.Cells[1, "B"] = "Address";
                ws.Cells[1, "C"] = "BillingAddress";
                ws.Cells[1, "D"] = "TotalDue";
            }
            using (var context = Persistence.Persistence.CreateContext())
            {
                var row = 1;
                foreach (var home in context.Homes)
                {
                    row++;
                    ws.Cells[row, "A"] = dueYear.DueYear1;
                    ws.Cells[row, "B"] = home.PhysicalAddress;
                    ws.Cells[row, "C"] = home.MailingAddress;
                    ws.Cells[row, "D"] = dueYear.DuesAmount.ToString("c");
                }
            }

            ((Microsoft.Office.Interop.Excel.Range)ws.Columns[1]).AutoFit();
            ((Microsoft.Office.Interop.Excel.Range)ws.Columns[2]).AutoFit();
            ((Microsoft.Office.Interop.Excel.Range)ws.Columns[3]).AutoFit();
            ((Microsoft.Office.Interop.Excel.Range)ws.Columns[4]).AutoFit();

            //xlApp.Visible = true;
            wb.SaveAs(exportFile, XlFileFormat.xlWorkbookDefault);
            wb.Close();
            xlApp.Quit();
            NAR(ws);
            NAR(wbs);
            NAR(wb);
            NAR(xlApp);
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }
예제 #3
0
 /// <summary>
 /// Deprecated Method for adding a new object to the DueYears EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToDueYears(DueYear dueYear)
 {
     base.AddObject("DueYears", dueYear);
 }