public void LoadReport(string reportname, string reportsconfig) { if (reportname.Length > 0) { ReportName = reportname; byte[] image = Data.GetReportData(reportname); if (image != null) { MemIniFile mif = new MemIniFile(String.Empty); mif.FromString(reportsconfig); this.PrintAuto = mif.ReadBool(reportname, "PrintAuto", false); this.PrintTime = mif.ReadDate(reportname, "PrintTime", DateTime.Parse("08:05:00")); this.PrintPeriod = mif.ReadInteger(reportname, "PrintPeriod", 0); //------------------------------------------ SelList.Clear(); PlotList.Clear(); GC.Collect(); string content = Encoding.Unicode.GetString(image); PrinterSettings ps = printDocument.PrinterSettings; string[] lines = content.Split(new string[] { "\r\n" }, StringSplitOptions.None); ImportLines(ref ps, lines); printDocument.PrinterSettings = ps; Update(); } } }
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; } } }