private void SaveReportsMethod() { var dayreport = DayMonitor.GetDayReport(); if (dayreport.Reports.Count == 0) { return; } var path = DayMonitor.ReportsModel.ReportsRegulator.Save(dayreport, GeneralPageModel.ToType); System.Windows.MessageBox.Show(path); }
// ************************************************************************ private void ExportToExcel() { IWorkbook wb = Factory.GetWorkbook(); IWorksheet workSheet = wb.Worksheets[0]; int col = 1; for (int dayIndex = -30; dayIndex <= 0; dayIndex++) { DateTime day = DateTime.Today + new TimeSpan(dayIndex, 0, 0, 0); Debug.Print(day.ToString("yyyy-MM-dd")); workSheet.Cells[0, col].Value = day.DayOfWeek.ToString(); workSheet.Cells[1, col].Value = day; DayMonitor dayMonitor = Monitor.Instance.DayMonitors.FirstOrDefault(dm => dm.Day == day); if (dayMonitor != null) { workSheet.Cells[2, col].Value = "Last - First"; workSheet.Cells[2, col + 1].Value = dayMonitor.TotalHours; workSheet.Cells[3, col].Value = "Has estimated time (7h00 or 18h00)"; workSheet.Cells[3, col + 1].Value = dayMonitor.HasSomeEstimatedHours; int row = 5; foreach (var state in dayMonitor.SessionLockStateChanges) { workSheet.Cells[row, col].Value = state.SessionSwitchReason.ToString(); workSheet.Cells[row, col + 1].Value = state.DateTime; row++; } } workSheet.Cells[1, col].ColumnWidth = 18; workSheet.Cells[1, col + 1].ColumnWidth = 18; col += 2; } if (wb != null) { if (FileAssociation.IsFileAssociationExistsForExtensionWithDot(".xlsx")) { string path = TempFolderAutoClean.GetTempFileName("xlsx", "Export "); wb.SaveAs(path, FileFormat.OpenXMLWorkbook); Process p = new Process(); p.StartInfo.UseShellExecute = true; p.StartInfo.FileName = path; p.Start(); } else { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.InitialDirectory = Environment.CurrentDirectory; saveFileDialog.Filter = "Excel file (*.xlsx)|*.xlsx"; saveFileDialog.DefaultExt = ".xlsx"; if (saveFileDialog.ShowDialog(Application.Current.MainWindow) == true) { string path = saveFileDialog.FileName; wb.SaveAs(path, FileFormat.OpenXMLWorkbook); } } } }