public override void EditForm(object id) { int daybookId = (int)id; DaybookModel job = daybookId == 0 ? new DaybookModel { JobID = 0, dtFrom = DateTime.Now, dtTo = DateTime.Now } : _daybookService.GetDayBook(daybookId); addDaybookControl.PopulateData(job); base.EditForm(id); }
private void gridView1_DoubleClick(object sender, EventArgs e) { var gridView = (GridView)sender; int rowIndex = gridView.FocusedRowHandle; if (rowIndex > -1) { int id = (int)gridView.GetRowCellValue(rowIndex, colJobID); var job = _daybookService.GetDayBook(id); string fileName = string.Format("{0}/Docs/InvoiceTemplate.xls", AppDomain.CurrentDomain.BaseDirectory); object oMissing = Missing.Value; Microsoft.Office.Interop.Excel.Application ExcelObj = new Microsoft.Office.Interop.Excel.Application(); Microsoft.Office.Interop.Excel.Workbook WBook; Microsoft.Office.Interop.Excel.Worksheet WSheet1; Microsoft.Office.Interop.Excel.Worksheet WSheet2; Microsoft.Office.Interop.Excel.Worksheet WSheet3; Microsoft.Office.Interop.Excel.Worksheet WSheet4; Microsoft.Office.Interop.Excel.Worksheet WSheet5; WBook = ExcelObj.Workbooks.Open(fileName, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing); WSheet1 = (Microsoft.Office.Interop.Excel.Worksheet)WBook.Sheets.get_Item(1); WSheet1.Cells[1, 2] = job.JobRef; WSheet1.Cells[2, 2] = job.DriverName; WSheet1.Cells[3, 2] = Convert.ToDateTime(job.dtFrom).ToShortDateString(); WSheet1.Cells[4, 2] = Convert.ToDateTime(job.dtTo).ToShortDateString(); WSheet1.Cells[5, 2] = job.CustRef; WSheet1.Cells[1, 5] = job.Journey; WSheet2 = (Microsoft.Office.Interop.Excel.Worksheet)WBook.Sheets.get_Item(2); WSheet2.Cells[1, 2] = job.JobRef; WSheet2.Cells[2, 2] = job.DriverName; WSheet2.Cells[3, 2] = Convert.ToDateTime(job.dtFrom).ToShortDateString(); WSheet2.Cells[4, 2] = Convert.ToDateTime(job.dtTo).ToShortDateString(); WSheet2.Cells[5, 2] = job.CustRef; WSheet2.Cells[1, 5] = job.Journey; WSheet3 = (Microsoft.Office.Interop.Excel.Worksheet)WBook.Sheets.get_Item(3); WSheet3.Cells[1, 2] = job.JobRef; WSheet3.Cells[2, 2] = job.DriverName; WSheet3.Cells[3, 2] = Convert.ToDateTime(job.dtFrom).ToShortDateString(); WSheet3.Cells[4, 2] = Convert.ToDateTime(job.dtTo).ToShortDateString(); WSheet3.Cells[5, 2] = job.CustRef; WSheet3.Cells[1, 5] = job.Journey; WSheet4 = (Microsoft.Office.Interop.Excel.Worksheet)WBook.Sheets.get_Item(4); WSheet4.Cells[1, 2] = job.JobRef; WSheet4.Cells[2, 2] = job.DriverName; WSheet4.Cells[3, 2] = Convert.ToDateTime(job.dtFrom).ToShortDateString(); WSheet4.Cells[4, 2] = Convert.ToDateTime(job.dtTo).ToShortDateString(); WSheet4.Cells[5, 2] = job.CustRef; WSheet4.Cells[1, 5] = job.Journey; WSheet5 = (Microsoft.Office.Interop.Excel.Worksheet)WBook.Sheets.get_Item(5); WSheet5.Cells[1, 2] = job.JobRef; WSheet5.Cells[2, 2] = job.DriverName; WSheet5.Cells[3, 2] = Convert.ToDateTime(job.dtFrom).ToShortDateString(); WSheet5.Cells[4, 2] = Convert.ToDateTime(job.dtTo).ToShortDateString(); WSheet5.Cells[5, 2] = job.CustRef; WSheet5.Cells[1, 5] = job.Journey; // save //WBook.Save();// or use SaveAs() method to save in a different path. ExcelObj.Visible = true; Marshal.ReleaseComObject(WSheet1); Marshal.ReleaseComObject(WSheet2); Marshal.ReleaseComObject(WSheet3); Marshal.ReleaseComObject(WSheet4); Marshal.ReleaseComObject(WSheet5); Marshal.ReleaseComObject(WBook); Marshal.ReleaseComObject(ExcelObj); WSheet1 = null; WBook = null; ExcelObj = null; GC.Collect(); } }