Exemple #1
0
        public static GenerateReportResult Report(string logPath, string directoryName, string dataSource, string reportPath, string exportPath, string reportName, string reportPeriod, string timeFrom,
                                                  string timeTo, string[] exportFormat, string byProg, JuridicalData JuridicalData, BonusClub BonusClub, string date)
        {
            GenerateReportResult GenerateReportResult = GenerateReport(logPath, directoryName, dataSource, reportPath, AppDomain.CurrentDomain.BaseDirectory + "\\" + exportPath + "\\" + reportName, reportPeriod,
                                                                       timeFrom, timeTo, exportFormat, byProg, JuridicalData, BonusClub, date);

            if (!string.IsNullOrEmpty(JuridicalData.jurInnAndTitle) & JuridicalData.jurID != 0)
            {
                if (GenerateReportResult.generateResult == 0)
                {
                    Console.WriteLine(DateTime.Now.ToString("HH:mm:ss") + " В программе " + directoryName + " " + reportName + " за " + reportPeriod + " для ЮЛ "
                                      + JuridicalData.jurInnAndTitle + " сформирован!");
                    AdditionalFunc.LogFile(logPath + "\\" + Variables.fileLog, "В программе " + directoryName + " отчет " + reportName + " за " + reportPeriod + " для ЮЛ "
                                           + JuridicalData.jurInnAndTitle + " сформирован!", false);
                }
                else
                {
                    Console.WriteLine(DateTime.Now.ToString("HH:mm:ss") + " В программе " + directoryName + " " + reportName + " за " + reportPeriod + " для ЮЛ "
                                      + JuridicalData.jurInnAndTitle + " НЕ сформирован!");
                    AdditionalFunc.LogFile(logPath + "\\" + Variables.fileLog, "В программе " + directoryName + " отчет " + reportName + " за " + reportPeriod + " для ЮЛ "
                                           + JuridicalData.jurInnAndTitle + " НЕ сформирован!", false);
                }
            }
            else if (!string.IsNullOrEmpty(BonusClub.title) & BonusClub.clubId != 0)
            {
                if (GenerateReportResult.generateResult == 0)
                {
                    Console.WriteLine(DateTime.Now.ToString("HH:mm:ss") + " В программе " + BonusClub.title + " " + reportName + " за " + reportPeriod + " сформирован!");
                    AdditionalFunc.LogFile(logPath + "\\" + Variables.fileLog, "В программе " + BonusClub.title + " отчет " + reportName + " за " + reportPeriod + " сформирован!", false);
                }
                else
                {
                    Console.WriteLine(DateTime.Now.ToString("HH:mm:ss") + " В программе " + directoryName + " " + reportName + " за " + reportPeriod + " НЕ сформирован!");
                    AdditionalFunc.LogFile(logPath + "\\" + Variables.fileLog, "В программе " + directoryName + " отчет " + reportName + " за " + reportPeriod + " НЕ сформирован!", false);
                }
            }
            else
            {
                if (GenerateReportResult.generateResult == 0)
                {
                    Console.WriteLine(DateTime.Now.ToString("HH:mm:ss") + " В программе " + directoryName + " " + reportName + " за " + reportPeriod + " сформирован!");
                    AdditionalFunc.LogFile(logPath + "\\" + Variables.fileLog, "В программе " + directoryName + " отчет " + reportName + " за " + reportPeriod + " сформирован!", false);
                }
                else
                {
                    Console.WriteLine(DateTime.Now.ToString("HH:mm:ss") + " В программе " + directoryName + " " + reportName + " за " + reportPeriod + " НЕ сформирован!");
                    AdditionalFunc.LogFile(logPath + "\\" + Variables.fileLog, "В программе " + directoryName + " отчет " + reportName + " за " + reportPeriod + " НЕ сформирован!", false);
                }
            }

            return(GenerateReportResult);
        }
Exemple #2
0
        public static GenerateReportResult GenerateReport(string logPath, string directoryName, string dataSource, string reportPath, string reportName, string reportPeriod,
                                                          string timeFrom, string timeTo, string[] exportFormat, string byProg, JuridicalData JuridicalData, BonusClub BonusClub, string date)
        {
            StiExportFormat      StiExportFormat      = StiExportFormat.Pdf;
            GenerateReportResult GenerateReportResult = new GenerateReportResult();
            List <string>        ExportFiles          = new List <string>();

            DateTime monday = AdditionalFunc.GetMonday(date);
            string   numWeek = AdditionalFunc.GetNumWeek(date), exportPath = string.Empty, exportFileName = string.Empty, bonusClubFolder = "\\" + BonusClub.title;

            const string period = "period", periodRequest = "periodRequest", timeReport = "timeReport",
                         juridicalID = "juridicalID", clubID = "clubID", shiftHour = "shiftHour", programDivide = "programDivide",
                         year = "year", month = "month";

            StiReport report = new StiReport();

            try
            {
                StiConfig.Services.Add(new StiOracleODPAdapterService());

                StiOptions.Engine.ReportCache.AmountOfQuickAccessPages = 5;
                StiOptions.Engine.ReportCache.AmountOfProcessedPagesForStartGCCollect = 5;
                report.ReportCacheMode = StiReportCacheMode.On;

                report.Load(reportPath);

                foreach (StiOracleODPDatabase db in report.Dictionary.Databases.OfType <StiOracleODPDatabase>())
                {
                    db.ConnectionString = dataSource;
                }

                foreach (StiOracleODPSource src in report.Dictionary.DataSources.OfType <StiOracleODPSource>())
                {
                    src.CommandTimeout = 12000;
                }

                if (report.Dictionary.Variables != null && report.Dictionary.Variables.Contains(timeReport) && report.Dictionary.Variables.Contains(period) &&
                    report.Dictionary.Variables.Contains(periodRequest))
                {
                    if (report.Dictionary.Variables.Contains(juridicalID))
                    {
                        report.Dictionary.Variables[juridicalID].Value = JuridicalData.jurID.ToString();
                    }

                    if (report.Dictionary.Variables.Contains(clubID))
                    {
                        report.Dictionary.Variables[clubID].Value = BonusClub.clubId.ToString();
                    }

                    if (report.Dictionary.Variables.Contains(shiftHour))
                    {
                        report.Dictionary.Variables[shiftHour].Value = timeFrom;
                    }

                    if (report.Dictionary.Variables.Contains(programDivide))
                    {
                        report.Dictionary.Variables[programDivide].Value = byProg;
                    }

                    if (report.Dictionary.Variables.Contains(year))
                    {
                        report.Dictionary.Variables[year].Value = date.Substring(0, 4);
                    }

                    if (report.Dictionary.Variables.Contains(month))
                    {
                        report.Dictionary.Variables[month].Value = date.Substring(5, 2);
                    }

                    report.Dictionary.Variables[timeReport].Value = date;

                    switch (reportPeriod)
                    {
                    case Variables.periodAllTime:
                        report.Dictionary.Variables[period].Value = "За все время. Смена с " + timeFrom + ":00 до " + timeTo + ":00";

                        /*report.Dictionary.Variables[periodRequest].Value = "and to_char(request_date, 'yyyy.mm.dd hh24:mi:ss')<to_char(to_date('"
                         + date + "', 'yyyy.mm.dd hh24:mi:ss'), 'yyyy.mm.dd hh24:mi:ss')";*/
                        report.Dictionary.Variables[periodRequest].Value = "and request_date < to_date('" + date + "', 'yyyy.mm.dd hh24:mi:ss') ";
                        //    + "and (((to_char(request_date,'HH24') >= " + timeFrom + " or to_char(request_date,'HH24') < " + timeTo + ") and " + timeFrom + " >= " + timeTo + ") "
                        //    + "or ((to_char(request_date, 'HH24') >= " + timeFrom + " and to_char(request_date, 'HH24') < " + timeTo + ") and " + timeFrom + " < " + timeTo + "))";
                        break;

                    case Variables.periodYear:
                        report.Dictionary.Variables[period].Value = "С 01.01." + DateTime.Parse(date).AddDays(-1).ToString("yyyy") + " " + timeFrom + ":00 по "
                                                                    + DateTime.Parse(date).ToString("dd.MM.yyyy") + " " + timeTo + ":00. Смена с " + timeFrom + ":00 до " + timeTo + ":00";

                        /*report.Dictionary.Variables[periodRequest].Value = "and to_char(request_date, 'yyyy.mm.dd hh24:mi:ss') between to_char(to_date('"
                         + date + "', 'yyyy.mm.dd hh24:mi:ss') - 1, 'yyyy')|| '.01.01 " + timeFrom + ":00:00' and to_char(to_date('" + date + "', 'yyyy.mm.dd hh24:mi:ss'), 'yyyy.mm.dd')|| ' " + timeTo + ":00:00'";*/
                        report.Dictionary.Variables[periodRequest].Value = "and request_date between to_date('" + DateTime.Parse(date).AddDays(-1).ToString("yyyy")
                                                                           + ".01.01 " + timeFrom + ":00:00', 'yyyy.mm.dd hh24:mi:ss') and to_date('" + DateTime.Parse(date).ToString("yyyy.MM.dd") + " " + timeTo + ":00:00', 'yyyy.mm.dd hh24:mi:ss') ";
                        //    + "and (((to_char(request_date,'HH24') >= " + timeFrom + " or to_char(request_date,'HH24') < " + timeTo + ") and " + timeFrom + " >= " + timeTo + ") "
                        //    + "or ((to_char(request_date, 'HH24') >= " + timeFrom + " and to_char(request_date, 'HH24') < " + timeTo + ") and " + timeFrom + " < " + timeTo + "))";
                        break;

                    case Variables.periodMonth:
                        report.Dictionary.Variables[period].Value = "С 01." + DateTime.Parse(date).AddDays(-1).ToString("MM.yyyy") + " " + timeFrom + ":00 по "
                                                                    + DateTime.Parse(date).ToString("dd.MM.yyyy") + " " + timeTo + ":00. Смена с " + timeFrom + ":00 до " + timeTo + ":00";

                        /*report.Dictionary.Variables[periodRequest].Value = "and to_char(request_date, 'yyyy.mm.dd hh24:mi:ss') between to_char(to_date('"
                         + date + "', 'yyyy.mm.dd hh24:mi:ss') - 1, 'yyyy.mm')|| '.01 " + timeFrom + ":00:00' and to_char(to_date('" + date + "', 'yyyy.mm.dd hh24:mi:ss'), 'yyyy.mm.dd')|| ' " + timeTo + ":00:00'";*/
                        report.Dictionary.Variables[periodRequest].Value = "and request_date between to_date('" + DateTime.Parse(date).AddDays(-1).ToString("yyyy.MM") + ".01 " + timeFrom + ":00:00', 'yyyy.mm.dd hh24:mi:ss') "
                                                                           + "and to_date('" + DateTime.Parse(date).ToString("yyyy.MM.dd") + " " + timeTo + ":00:00', 'yyyy.mm.dd hh24:mi:ss') ";
                        //    + "and (((to_char(request_date,'HH24') >= " + timeFrom + " or to_char(request_date,'HH24') < " + timeTo + ") and " + timeFrom + " >= " + timeTo + ") "
                        //    + "or ((to_char(request_date, 'HH24') >= " + timeFrom + " and to_char(request_date, 'HH24') < " + timeTo + ") and " + timeFrom + " < " + timeTo + "))";
                        break;

                    case Variables.periodWeek:
                        report.Dictionary.Variables[period].Value = "С " + monday.ToString("dd.MM.yyyy") + " " + timeFrom + ":00 по "
                                                                    + DateTime.Parse(date).ToString("dd.MM.yyyy") + " " + timeTo + ":00. Смена с " + timeFrom + ":00 до " + timeTo + ":00";

                        /*report.Dictionary.Variables[periodRequest].Value = "and to_char(request_date, 'yyyy.mm.dd hh24:mi:ss') between to_char(next_day(to_date('"
                         + date + "', 'yyyy.mm.dd hh24:mi:ss') - 8, 1), 'yyyy.mm.dd')|| ' " + timeFrom + ":00:00' and to_char(to_date('" + date + "', 'yyyy.mm.dd hh24:mi:ss'), 'yyyy.mm.dd')|| ' " + timeTo + ":00:00'";*/
                        report.Dictionary.Variables[periodRequest].Value = "and request_date between to_date('" + monday.ToString("yyyy.MM.dd") + " " + timeFrom + ":00:00', 'yyyy.mm.dd hh24:mi:ss') "
                                                                           + "and to_date('" + DateTime.Parse(date).ToString("yyyy.MM.dd") + " " + timeTo + ":00:00', 'yyyy.mm.dd hh24:mi:ss') ";
                        //    + "and (((to_char(request_date,'HH24') >= " + timeFrom + " or to_char(request_date,'HH24') < " + timeTo + ") and " + timeFrom + " >= " + timeTo + ") "
                        //    + "or ((to_char(request_date, 'HH24') >= " + timeFrom + " and to_char(request_date, 'HH24') < " + timeTo + ") and " + timeFrom + " < " + timeTo + "))";
                        break;

                    case Variables.periodDay:
                        report.Dictionary.Variables[period].Value = "С " + DateTime.Parse(date).AddDays(-1).ToString("dd.MM.yyyy") + " " + timeFrom + ":00 по " + DateTime.Parse(date).ToString("dd.MM.yyyy")
                                                                    + " " + timeTo + ":00. Смена с " + timeFrom + ":00 до " + timeTo + ":00";

                        /*report.Dictionary.Variables[periodRequest].Value = "and to_char(request_date, 'yyyy.mm.dd hh24:mi:ss') between to_char(to_date('"
                         + date + "', 'yyyy.mm.dd hh24:mi:ss') - 1, 'yyyy.mm.dd')|| ' " + timeFrom + ":00:00' and to_char(to_date('" + date + "', 'yyyy.mm.dd hh24:mi:ss'), 'yyyy.mm.dd')|| ' " + timeTo + ":00:00'";*/
                        report.Dictionary.Variables[periodRequest].Value = "and request_date between to_date('" + DateTime.Parse(date).AddDays(-1).ToString("yyyy.MM.dd") + " " + timeFrom + ":00:00', 'yyyy.mm.dd hh24:mi:ss') "
                                                                           + "and to_date('" + DateTime.Parse(date).ToString("yyyy.MM.dd") + " " + timeTo + ":00:00', 'yyyy.mm.dd hh24:mi:ss') ";
                        //    + "and (((to_char(request_date,'HH24') >= " + timeFrom + " or to_char(request_date,'HH24') < " + timeTo + ") and " + timeFrom + " >= " + timeTo + ") "
                        //    + "or ((to_char(request_date, 'HH24') >= " + timeFrom + " and to_char(request_date, 'HH24') < " + timeTo + ") and " + timeFrom + " < " + timeTo + "))";
                        break;

                    default:
                        break;
                    }
                }

                report.Save(reportPath);
                report.Render();

                StiOptions.Export.Csv.ForcedSeparator = ";";

                for (int i = 0; i < exportFormat.Length; i++)
                {
                    string ef = exportFormat[i].ToLower();

                    switch (exportFormat[i].ToLower())
                    {
                    case Variables.formatPDF:
                        StiExportFormat = StiExportFormat.Pdf;
                        break;

                    case Variables.formatCSV:
                        StiExportFormat = StiExportFormat.Csv;
                        break;

                    case Variables.formatDOCX:
                        StiExportFormat = StiExportFormat.Word2007;
                        break;

                    case Variables.formatXLSX:
                        StiExportFormat = StiExportFormat.Excel2007;
                        break;

                    default:
                        break;
                    }

                    switch (reportPeriod)
                    {
                    case Variables.periodAllTime:

                        exportPath = reportName + "\\" + directoryName + bonusClubFolder;

                        if (!String.IsNullOrEmpty(JuridicalData.jurInnAndTitle))
                        {
                            exportFileName = JuridicalData.jurInnAndTitle + "." + ef;
                        }
                        else
                        {
                            exportFileName = "За все время-" + directoryName + "." + ef;
                        }

                        if (!Directory.Exists(exportPath))
                        {
                            Directory.CreateDirectory(exportPath);
                        }

                        report.ExportDocument(StiExportFormat, exportPath + "\\" + exportFileName);
                        break;

                    case Variables.periodYear:

                        exportPath = reportName + "\\" + directoryName + bonusClubFolder + "\\" + DateTime.Parse(date).AddDays(-1).ToString("yyyy") + "-" + directoryName;

                        if (!String.IsNullOrEmpty(JuridicalData.jurInnAndTitle))
                        {
                            exportFileName = JuridicalData.jurInnAndTitle + "." + ef;
                        }
                        else
                        {
                            exportFileName = DateTime.Parse(date).AddDays(-1).ToString("yyyy") + "-" + directoryName + "." + ef;
                        }

                        if (!Directory.Exists(exportPath))
                        {
                            Directory.CreateDirectory(exportPath);
                        }

                        report.ExportDocument(StiExportFormat, exportPath + "\\" + exportFileName);
                        break;

                    case Variables.periodMonth:

                        exportPath = reportName + "\\" + directoryName + bonusClubFolder + "\\" + DateTime.Parse(date).AddDays(-1).ToString("yyyy") + "-" + directoryName
                                     + "\\" + DateTime.Parse(date).AddDays(-1).ToString("yyyy") + "-" + DateTime.Parse(date).AddDays(-1).ToString("MM") + "-" + directoryName;

                        if (!String.IsNullOrEmpty(JuridicalData.jurInnAndTitle))
                        {
                            exportFileName = JuridicalData.jurInnAndTitle + "." + ef;
                        }
                        else
                        {
                            exportFileName = DateTime.Parse(date).AddDays(-1).ToString("yyyy") + "-" + DateTime.Parse(date).AddDays(-1).ToString("MM")
                                             + "-" + directoryName + "." + ef;
                        }

                        if (!Directory.Exists(exportPath))
                        {
                            Directory.CreateDirectory(exportPath);
                        }

                        report.ExportDocument(StiExportFormat, exportPath + "\\" + exportFileName);
                        break;

                    case Variables.periodWeek:

                        exportPath = reportName + "\\" + directoryName + bonusClubFolder + "\\" + AdditionalFunc.GetYearByNumWeek(numWeek, date) + "-" + directoryName + "\\Недели\\"
                                     + numWeek + "." + monday.ToString("yyyy") + "-" + monday.ToString("MM") + "-" + monday.ToString("dd") + " - " + monday.AddDays(6).ToString("yyyy") + "-"
                                     + monday.AddDays(6).ToString("MM") + "-" + monday.AddDays(6).ToString("dd") + "-" + directoryName;

                        if (!String.IsNullOrEmpty(JuridicalData.jurInnAndTitle))
                        {
                            exportFileName = JuridicalData.jurInnAndTitle + "." + ef;
                        }
                        else
                        {
                            exportFileName = monday.ToString("yyyy") + "-" + monday.ToString("MM") + "-" + monday.ToString("dd") + " - "
                                             + monday.AddDays(6).ToString("yyyy") + "-" + monday.AddDays(6).ToString("MM") + "-" + monday.AddDays(6).ToString("dd") + "-" + directoryName + "." + ef;
                        }

                        if (!Directory.Exists(exportPath))
                        {
                            Directory.CreateDirectory(exportPath);
                        }

                        report.ExportDocument(StiExportFormat, exportPath + "\\" + exportFileName);
                        break;

                    case Variables.periodDay:

                        exportPath = reportName + "\\" + directoryName + bonusClubFolder + "\\" + DateTime.Parse(date).AddDays(-1).ToString("yyyy") + "-" + directoryName
                                     + "\\" + DateTime.Parse(date).AddDays(-1).ToString("yyyy") + "-" + DateTime.Parse(date).AddDays(-1).ToString("MM") + "-" + directoryName
                                     + "\\" + DateTime.Parse(date).AddDays(-1).ToString("yyyy") + "-" + DateTime.Parse(date).AddDays(-1).ToString("MM") + "-" + DateTime.Parse(date).AddDays(-1).ToString("dd")
                                     + "-" + directoryName;

                        if (!String.IsNullOrEmpty(JuridicalData.jurInnAndTitle))
                        {
                            exportFileName = JuridicalData.jurInnAndTitle + "." + ef;
                        }
                        else
                        {
                            exportFileName = DateTime.Parse(date).AddDays(-1).ToString("yyyy") + "-" + DateTime.Parse(date).AddDays(-1).ToString("MM")
                                             + "-" + DateTime.Parse(date).AddDays(-1).ToString("dd") + "-" + directoryName + "." + ef;
                        }

                        if (!Directory.Exists(exportPath))
                        {
                            Directory.CreateDirectory(exportPath);
                        }

                        report.ExportDocument(StiExportFormat, exportPath + "\\" + exportFileName);
                        break;

                    default:
                        break;
                    }

                    ExportFiles.Add(exportPath + "\\" + exportFileName);
                    GenerateReportResult.ExportFiles = ExportFiles;
                }

                GenerateReportResult.generateResult = 0;

                return(GenerateReportResult);
            }
            catch (Exception ex)
            {
                AdditionalFunc.LogFile(logPath + "\\" + Variables.fileError, "Отчет: " + reportPath + "\n\n" + "Период: " + reportPeriod + "\n\n" + "ЮЛ: " + JuridicalData.jurInnAndTitle
                                       + " " + JuridicalData.jurID + "\n\n" + "БД: " + dataSource.Remove(dataSource.IndexOf(";")) + "\n\n" + ex.Message, true);
                GenerateReportResult.generateResult = 1;

                return(GenerateReportResult);
            }
            finally
            {
                report.Dictionary.Clear();
                report.RenderedPages.Clear();
                report.Dispose();
            }
        }
Exemple #3
0
 public static GenerateReportResult Report(string logPath, string directoryName, string dataSource, string reportPath, string exportPath, string reportName, string reportPeriod, string timeFrom,
                                           string timeTo, string[] exportFormat, string byProg, BonusClub BonusClub, string date)
 {
     return(Report(logPath, directoryName, dataSource, reportPath, exportPath, reportName, reportPeriod, timeFrom, timeTo, exportFormat, byProg, new JuridicalData {
         jurInnAndTitle = String.Empty, jurID = 0
     },
                   BonusClub, date));
 }