private void LoadReportProps() { printReport.LoadReport(internalname, Properties.Settings.Default.ReportsConfig); tsbPrintAuto.Checked = printReport.PrintAuto; tstbPrintDate.Text = DateTime.Today.ToString("dd.MM.yyyy"); tstbPrintTime.Text = printReport.PrintTime.ToString("HH:mm"); int periodindex = printReport.PrintPeriod; if (periodindex < tscbPrintPeriod.Items.Count) { tscbPrintPeriod.SelectedIndexChanged -= tscbPrintPeriod_SelectedIndexChanged; tscbPrintPeriod.SelectedIndex = periodindex; tscbPrintPeriod.SelectedIndexChanged += tscbPrintPeriod_SelectedIndexChanged; } }
private void AutoPrintReports(DateTime now) { MemIniFile mif = new MemIniFile(String.Empty); mif.FromString(Properties.Settings.Default.ReportsConfig); // выбор автозапускаемых отчётов на текущее время в список list List <string> list = new List <string>(); foreach (string section in mif.ReadSections()) { bool auto = mif.ReadBool(section, "PrintAuto", false); if (auto) { string name = mif.ReadString(section, "ReportName", section); DateTime time = mif.ReadDate(section, "PrintTime", DateTime.Parse("08:05:00")); int period = mif.ReadInteger(section, "PrintPeriod", 0); if (period == 0) // ежедневно { if (time.Hour == now.Hour && time.Minute == now.Minute) { list.Add(name); } } else if (period == 1) // ежемесячно 1 числа { if (now.Day == 1 && time.Hour == now.Hour && time.Minute == now.Minute) { list.Add(name); } } } } // отправка на печать отчётов, печатаемых в настоящий момент foreach (string name in list) { using (PrintDocument printDoc = new PrintDocument()) { printDoc.PrintPage += printDoc_PrintPage; printReport = new PrintReport(printDoc); printReport.LoadReport(name, Properties.Settings.Default.ReportsConfig); printDoc.Print(); printDoc.PrintPage -= printDoc_PrintPage; } } }
public static void ExportReportsAs(string path, Action <string> updateMessage, string pathtoconfig) { // pathtoconfig - путь для хранения "reports.ini", с настройками по автозапуску и времени выполнения if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } IDictionary <string, string> reportlist = Data.GetReportsList(); foreach (KeyValuePair <string, string> name in reportlist) { updateMessage("Экспорт отчёта: " + name.Key); using (PrintDocument pd = new PrintDocument()) { PrintReport printReport = new PrintReport(pd); printReport.LoadReport(name.Key, pathtoconfig); string FileName = path + "\\" + name.Key.ToLower() + ".ini"; List <string> lines = printReport.ExportLines(); System.IO.File.WriteAllLines(FileName, lines.ToArray()); } } }