public void Delete_report()
        {
            var comment = Generator.Name();
            var payer   = new Payer("Тестовый плательщик");
            var report  = new GeneralReport(payer)
            {
                Comment = comment
            };

            session.Save(payer);
            session.Save(report);

            var reportPage = new Reports_GeneralReports
            {
                DbSession = session,
                UnderTest = true,
            };

            reportPage.SendDeleteAlert(report.Id, comment, "Test", "128.0.0.1");

            var message = reportPage.Messages[0];

            Assert.That(message.To[0].Address, Is.EqualTo("*****@*****.**"));
            Assert.That(message.Body.Contains(report.Comment), Is.True);
            Assert.That(message.Body.Contains(report.Id.ToString()), Is.True);
        }
Exemplo n.º 2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if ((Request["r"] == null))
        {
            Response.Redirect("GeneralReports.aspx");
        }
        else if (Request["r"].Equals(ConfigurationManager.AppSettings["TemplateReportId"], StringComparison.OrdinalIgnoreCase))
        {
            Response.Redirect("TemplateReports.aspx");
        }
        else
        {
            ((HyperLinkField)dgvReports.Columns[3]).DataNavigateUrlFormatString = @"ReportProperties.aspx?rp={0}&r=" + Request["r"];
        }

        SheduleLink.NavigateUrl = "Schedule.aspx?r=" + Request["r"];

        if (!(Page.IsPostBack))
        {
            PostData();
        }
        else
        {
            DS = ((DataSet)Session[DSReports]);
            if (DS == null)             // вероятно, сессия завершилась и все ее данные утеряны
            {
                Reports_GeneralReports.Redirect(this);
            }
        }
    }
        public void CheckTaskDefinitionUpdate()
        {
            var comment = Generator.Name();
            var payer   = new Payer("Тестовый плательщик");
            var report  = new GeneralReport(payer)
            {
                Comment = comment
            };

            session.Save(payer);
            session.Save(report);

            var helper = new ScheduleHelper();

            helper.GetTaskOrCreate(report.Id, report.Comment);

            var reportPage = new Reports_GeneralReports {
                DbSession = session
            };

            comment        = Generator.Name();
            report.Comment = comment;
            session.Save(report);
            session.Flush();

            reportPage.UpdateTasksForGeneralReports(new List <ulong>(),
                                                    new List <ulong> {
                report.Id
            });
            var task = helper.GetTaskOrCreate(report.Id, report.Comment);

            Assert.AreEqual(task.Definition.RegistrationInfo.Description, comment);
        }
Exemplo n.º 4
0
    protected void Page_Load(object sender, EventArgs e)
    {
        decimal?asdf = 0.5m;

        var sdf = $"asdf {asdf.Value} sdff";

        if (String.IsNullOrEmpty(Request["r"]))
        {
            Response.Redirect("GeneralReports.aspx");
        }

        if (String.IsNullOrEmpty(Request["rp"]))
        {
            if (!String.IsNullOrEmpty(Request["r"]))
            {
                Response.Redirect("Reports.aspx?r=" + Request["r"]);
            }
        }

        btnBack.Visible = !String.IsNullOrEmpty(Request["TemporaryId"]);
        btnNext.Visible = btnBack.Visible;

        if (!IsPostBack)
        {
            var report = DbSession.Load <Report>(Convert.ToUInt64(Request["rp"]));
            lblReport.Text     = report.ReportCaption;
            lblReportType.Text = report.ReportType.ReportTypeName;

            PostData();
            var property = report.Properties.FirstOrDefault(x => x.PropertyType.PropertyName == "ReportPeriod");
            if (property != null)
            {
                var value = (ReportPeriod)Convert.ToInt32(property.Value);
                SetRowVisibility("Интервал отчета (дни) от текущей даты", value == ReportPeriod.ByInterval);
            }
            propertiesHelper    = new PropertiesHelper(report.Id, dtNonOptionalParams, dtOptionalParams);
            Session[PropHelper] = propertiesHelper;
        }
        else
        {
            DS = ((DataSet)Session[DSParams]);
            propertiesHelper = (PropertiesHelper)Session[PropHelper];
            if (DS == null || propertiesHelper == null)
            {
                // вероятно, сессия завершилась и все ее данные утеряны
                Reports_GeneralReports.Redirect(this);
            }
        }
        btnApply.Visible = dgvNonOptional.Rows.Count > 0;
    }
Exemplo n.º 5
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!Page.IsPostBack)
     {
         PostData();
     }
     else
     {
         DS = ((DataSet)Session[DSEnums]);
         if (DS == null)             // вероятно, сессия завершилась и все ее данные утеряны
         {
             Reports_GeneralReports.Redirect(this);
         }
     }
     btnApply.Visible = dgvEnums.Rows.Count > 0;
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            ulong.TryParse(System.Configuration.ConfigurationManager.AppSettings["TemplateReportId"], out _templateReportId);
            ((HyperLinkField)dgvReports.Columns[2]).DataNavigateUrlFormatString = @"ReportProperties.aspx?rp={0}&r=" + _templateReportId;

            if (!(Page.IsPostBack))
            {
                PostData();
            }
            else
            {
                DS = ((DataSet)Session[DSReports]);
                if (DS == null)                 // вероятно, сессия завершилась и все ее данные утеряны
                {
                    Reports_GeneralReports.Redirect(this);
                }
            }

            btnApply.Visible = dgvReports.Rows.Count > 0;
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request["rtc"] == null)
        {
            Response.Redirect("ReportTypes.aspx");
        }
        FillTypes();
        if (!(Page.IsPostBack))
        {
            MyCn.Open();
            MyCmd.Connection   = MyCn;
            MyDA.SelectCommand = MyCmd;
            MyCmd.Parameters.Clear();
            MyCmd.Parameters.AddWithValue("rtCode", Request["rtc"]);
            MyCmd.CommandText  = @"
SELECT
    ReportTypeName
FROM
    reports.reporttypes rt
WHERE ReportTypeCode = ?rtCode
";
            lblReportName.Text = MyCmd.ExecuteScalar().ToString();
            MyCn.Close();

            PostData();
        }
        else
        {
            DS = ((DataSet)Session[DSReportTypes]);
            if (DS == null)             // вероятно, сессия завершилась и все ее данные утеряны
            {
                Reports_GeneralReports.Redirect(this);
            }
        }
        btnApply.Visible = dgvProperties.Rows.Count > 0;
    }
Exemplo n.º 8
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if ((Request.UrlReferrer == null || !Request.UrlReferrer.LocalPath.Contains("Schedule.aspx")) && Session["StartTaskTime"] != null)
        {
            Session.Remove("StartTaskTime");
        }

        if (Request["r"] == null)
        {
            Response.Redirect("GeneralReports.aspx");
        }

        _generalReport = GeneralReport.Find(Convert.ToUInt64(Request["r"]));

        taskService           = ScheduleHelper.GetService();
        reportsFolder         = ScheduleHelper.GetReportsFolder(taskService);
        currentTask           = ScheduleHelper.GetTaskOrCreate(taskService, reportsFolder, _generalReport.Id, _generalReport.Comment, "GR");
        currentTaskDefinition = currentTask.Definition;

        tempTask = ScheduleHelper.FindTaskNullable(reportsFolder, _generalReport.Id, "temp_");
        TaskState tempTaskState;
        string    tempTaskDescription = string.Empty;

        if (tempTask != null)
        {
            tempTaskState       = tempTask.State;
            tempTaskDescription = tempTask.Definition.RegistrationInfo.Description;
        }
        else
        {
            tempTaskState = TaskState.Unknown;
        }

        btnExecute.Enabled = currentTask.State != TaskState.Running && tempTaskState != TaskState.Running;
        btnExecute.Text    = (currentTask.State == TaskState.Running) ? StatusNotRunning : StatusRunning;

        var userName = HttpContext.Current.User.Identity.Name.Replace(@"ANALIT\", string.Empty);

        ErrorMassage.Text     = string.Empty;
        ErrorMassage.CssClass = "error";

        var description = tempTaskState == TaskState.Running ? string.Format("(запустил: {0})", tempTaskDescription) : string.Empty;

        if (tempTaskState == TaskState.Running || currentTask.State == TaskState.Running)
        {
            ExecAction action = null;
            var        currentReportNumber = "";
            ulong      runningNumber       = 0;
            if (tempTaskState == TaskState.Running)
            {
                if (tempTask != null)
                {
                    action = (ExecAction)tempTask.Definition.Actions.FirstOrDefault();
                }
            }
            else
            {
                action = (ExecAction)currentTask.Definition.Actions.FirstOrDefault();
            }
            if (action != null)
            {
                var arguments = (action).Arguments;
                if (!String.IsNullOrEmpty(arguments))
                {
                    if (arguments.IndexOf("/gr:") >= 0)
                    {
                        var substring    = arguments.Substring(arguments.IndexOf("/gr:") + 4);
                        var numberLength = substring.IndexOf(@" /");
                        var reportNumber = substring.Substring(0, numberLength != -1 ? numberLength : substring.Length);
                        if (!String.IsNullOrEmpty(reportNumber))
                        {
                            currentReportNumber += " № ";
                            currentReportNumber += reportNumber;
                            ulong.TryParse(reportNumber, out runningNumber);
                        }
                    }
                }
            }
            var startTime = GetStartTime(DbSession, runningNumber != 0 ? runningNumber : _generalReport.Id);

            var prefix = tempTaskState == TaskState.Running ? String.Format("Успешно запущен разовый отчет{0}", currentReportNumber)
                                : String.Format("Отчет запущен ({0})", currentReportNumber);
            if (tempTaskDescription == userName || currentTask.State == TaskState.Running)
            {
                ErrorMassage.Text      = string.Format("{0}, ожидайте окончания выполнения операции. {1}", prefix, startTime);
                ErrorMassage.BackColor = Color.LightGreen;
            }
            else
            {
                ErrorMassage.Text      = String.Format("{1}, выполнение данного отчета отложено {0}. {2}", description, prefix, startTime);
                ErrorMassage.BackColor = Color.Red;
            }
            btn_Mailing.Enabled = false;
            RadioSelf.Enabled   = false;
            RadioMails.Enabled  = false;
        }
        if (tempTaskState == TaskState.Queued || currentTask.State == TaskState.Queued)
        {
            var prefix = tempTaskState == TaskState.Running ? "Запускается разовый отчет" : "Отчет запускается";
            if (tempTaskDescription == userName || currentTask.State == TaskState.Queued)
            {
                ErrorMassage.Text      = string.Format("{0}, ожидайте окончания выполнения операции", prefix);
                ErrorMassage.BackColor = Color.LightGreen;
            }
            else
            {
                ErrorMassage.Text      = string.Format("{1} {0}, выполнение данного отчета отложено)", description, prefix);
                ErrorMassage.BackColor = Color.Red;
            }
            btn_Mailing.Enabled = false;
            RadioSelf.Enabled   = false;
            RadioMails.Enabled  = false;
        }
        if ((tempTaskState == TaskState.Ready && currentTask.State != TaskState.Running && currentTask.State != TaskState.Queued) ||
            (currentTask.State == TaskState.Ready && tempTaskState != TaskState.Running && tempTaskState != TaskState.Queued))
        {
            if (tempTaskDescription == userName || currentTask.State == TaskState.Ready)
            {
                // отчет выполнен
                if (Session["StartTaskTime"] != null)
                {
                    Session.Remove("StartTaskTime");
                    ErrorMassage.Text      = "Операция выполнена";
                    ErrorMassage.BackColor = Color.LightGreen;
                }
                else
                {
                    ErrorMassage.Text = "";
                }
            }
        }

        if ((tempTaskState == TaskState.Disabled && currentTask.State != TaskState.Running && currentTask.State != TaskState.Queued) ||
            (currentTask.State == TaskState.Disabled && tempTaskState != TaskState.Running && tempTaskState != TaskState.Queued))
        {
            if (Session["StartTaskTime"] != null)
            {
                Session.Remove("StartTaskTime");
                ErrorMassage.Text      = "Операция отменена";
                ErrorMassage.BackColor = Color.Red;
            }
            else
            {
                ErrorMassage.Text = "";
            }
        }

        var otherTriggers = new List <Trigger>();

        if (!IsPostBack)
        {
            var selfMail = GetSelfEmails();
            if ((selfMail.Count != 0) && (selfMail[0].Length != 0))
            {
                RadioSelf.Text = "Выполнить и отослать на: " + selfMail[0][0];
            }

            dtFrom.Value   = DateTime.Now.AddDays(-7).ToShortDateString();
            dtTo.Value     = DateTime.Now.ToShortDateString();
            mail_Text.Text = GetMailingAdresses();

            try {
                lblClient.Text        = _generalReport.Payer.Id + " - " + _generalReport.Payer.ShortName;
                lblReportComment.Text = _generalReport.Comment;
                var lastLogTimes = ObjectFromQuery(new[] { new MySqlParameter("?GeneralReportCode", _generalReport.Id) },
                                                   @"
SELECT
  Max(LogTime) as MaxLogTime
FROM
  logs.reportslogs
WHERE
  reportslogs.GeneralReportCode = ?GeneralReportCode
");
                if ((lastLogTimes.Count > 0) && (lastLogTimes[0].Length > 0))
                {
                    if (lastLogTimes[0][0] is DateTime)
                    {
                        MyCn.Open();
                        MyCmd.CommandText = @"
SELECT
  LogTime,
  EMail,
  SMTPID
FROM
  logs.reportslogs
WHERE
	reportslogs.GeneralReportCode = ?GeneralReportCode
and reportslogs.LogTime > ?LastLogTime
order by LogTime desc
";
                        MyCmd.Parameters.AddWithValue("?LastLogTime", ((DateTime)lastLogTimes[0][0]).AddDays(-1).Date);
                        var _logs = new DataTable();
                        MyDA.Fill(_logs);
                        gvLogs.DataSource = _logs;
                    }
                }
                gvLogs.DataBind();

                MyCmd.Parameters.Clear();
                MyCmd.CommandText = @"select
rel.StartTime,
if (not EndError, rel.EndTime, 'Ошибка при формировании отчета') as EndTime
from `logs`.reportexecutelogs rel
where rel.GeneralReportCode = ?GeneralReportCode
order by StartTime desc
limit 15;";
                MyCmd.Parameters.AddWithValue("?GeneralReportCode", _generalReport.Id);

                var startlogs = new DataTable();
                MyDA.Fill(startlogs);
                startLogs.DataSource = startlogs;

                startLogs.DataBind();
            }
            finally {
                MyCn.Close();
            }

            chbAllow.Checked = currentTask.Enabled;
            lblWork.Text     = ((ExecAction)currentTask.Definition.Actions[0]).Path + " " + ((ExecAction)currentTask.Definition.Actions[0]).Arguments;
            lblFolder.Text   = ((ExecAction)currentTask.Definition.Actions[0]).WorkingDirectory;
            if (_generalReport.FirmCode != null)
            {
                var ftpId = _generalReport.FirmCode.ToString().PadLeft(3, '0');
                FtpPath.Text = $"ftp://ftp.analit.net/OptBox/{ftpId}/Reports/";
            }
            else
            {
                FtpPath.Text = "";
            }
            var tl = currentTask.Definition.Triggers;

            for (int i = 0; i < tl.Count; i++)
            {
                if (tl[i] is WeeklyTrigger)
                {
                    var dr      = DS.Tables[dtSchedule.TableName].NewRow();
                    var trigger = ((WeeklyTrigger)tl[i]);
                    dr[SStartHour.ColumnName]   = trigger.StartBoundary.Hour;
                    dr[SStartMinute.ColumnName] = trigger.StartBoundary.Minute;
                    var days = trigger.DaysOfWeek;

                    SetWeekDays(dr, DaysOfTheWeek.Monday, days);
                    SetWeekDays(dr, DaysOfTheWeek.Tuesday, days);
                    SetWeekDays(dr, DaysOfTheWeek.Wednesday, days);
                    SetWeekDays(dr, DaysOfTheWeek.Thursday, days);
                    SetWeekDays(dr, DaysOfTheWeek.Friday, days);
                    SetWeekDays(dr, DaysOfTheWeek.Saturday, days);
                    SetWeekDays(dr, DaysOfTheWeek.Sunday, days);

                    DS.Tables[dtSchedule.TableName].Rows.Add(dr);
                }
                else if (tl[i] is MonthlyTrigger)
                {
                    var dr = DS.Tables[dtScheduleMonth.TableName].NewRow();
                    //очищаем таблицу от значений по умолчанию
                    for (var k = 1; k <= 31; k++)
                    {
                        dr["d" + k] = 0;
                    }
                    for (var k = 1; k <= 12; k++)
                    {
                        dr["m" + k] = 0;
                    }

                    var trigger = ((MonthlyTrigger)tl[i]);
                    dr[MSStartHour.ColumnName]   = trigger.StartBoundary.Hour;
                    dr[MSStartMinute.ColumnName] = trigger.StartBoundary.Minute;
                    var             months = trigger.MonthsOfYear;
                    MonthsOfTheYear month;
                    for (int j = 0; j < 12; j++)
                    {
                        MonthsOfTheYear.TryParse((1 << j).ToString(), true, out month);
                        if (months.HasFlag(month))
                        {
                            dr["m" + (j + 1)] = 1;
                        }
                    }
                    foreach (int em in trigger.DaysOfMonth)
                    {
                        dr["d" + em] = 1;
                    }
                    DS.Tables[dtScheduleMonth.TableName].Rows.Add(dr);
                }
                else
                {
                    otherTriggers.Add(tl[i]);
                }
            }

            DS.Tables[dtSchedule.TableName].AcceptChanges();
            dgvSchedule.DataSource = DS;
            dgvSchedule.DataMember = dtSchedule.TableName;
            dgvSchedule.DataBind();

            dgvScheduleMonth.DataSource = DS;
            dgvScheduleMonth.DataMember = dtScheduleMonth.TableName;
            dgvScheduleMonth.DataBind();

            gvOtherTriggers.DataSource = otherTriggers;
            gvOtherTriggers.DataBind();

            Session[DSSchedule] = DS;

            CloseTaskService();
        }
        else
        {
            DS = ((DataSet)Session[DSSchedule]);
            if (DS == null)             // вероятно, сессия завершилась и все ее данные утеряны
            {
                Reports_GeneralReports.Redirect(this);
            }
        }

        send_created_report.Visible = _generalReport.IsSuccessfulyProcessed;
    }
Exemplo n.º 9
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (String.IsNullOrEmpty(Request["r"]) && String.IsNullOrEmpty(Request["TemporaryId"]))
        {
            Response.Redirect("GeneralReports.aspx");
        }

        if (String.IsNullOrEmpty(Request["rp"]))
        {
            if (!String.IsNullOrEmpty(Request["r"]))
            {
                Response.Redirect("Reports.aspx?r=" + Request["r"]);
            }
            else
            {
                Response.Redirect("TemporaryReport.aspx?TemporaryId=" + Request["TemporaryId"]);
            }
        }

        if (String.IsNullOrEmpty(Request["rpv"]))
        {
            if (!String.IsNullOrEmpty(Request["r"]))
            {
                Response.Redirect(String.Format("ReportProperties.aspx?r={0}&rp={1}", Request["r"], Request["rp"]));
            }
            else
            {
                Response.Redirect(String.Format("ReportProperties.aspx?TemporaryId={0}&rp={1}", Request["TemporaryId"], Request["rp"]));
            }
        }
        if (!String.IsNullOrEmpty(Request["inID"]))
        {
            long id;
            if (long.TryParse(Request["inID"], out id))
            {
                inID = id;
            }
        }

        if (!String.IsNullOrEmpty(Request["inFilter"]))
        {
            inFilter = Request["inFilter"];
        }

        if (!String.IsNullOrEmpty(Request["inTypes"]))
        {
            inTypes = Request["inTypes"];
        }

        var propertyId = Convert.ToUInt64(Request["rpv"]);

        property = DbSession.Load <ReportProperty>(propertyId);

        if (!(IsPostBack))
        {
            try {
                PP = Convert.ToInt32(Request.Cookies[PPCN].Value);
            }
            catch {
                PP = 10;
            }
            dgvListValues.PageSize         = PP;
            ddlPages.Text                  = PP.ToString();
            Response.Cookies[PPCN].Value   = PP.ToString();
            Response.Cookies[PPCN].Expires = DateTime.Now.AddYears(2);

            MyCn.Open();
            MyCmd.Connection   = MyCn;
            MyDA.SelectCommand = MyCmd;
            MyCmd.Parameters.Clear();
            MyCmd.Parameters.AddWithValue("rpv", property.Id);
            MyCmd.Parameters.AddWithValue("rp", Request["rp"]);
            MyCmd.Parameters.AddWithValue("r", (!String.IsNullOrEmpty(Request["r"])) ? Request["r"] : Request["TemporaryId"]);
            MyCmd.CommandText = @"
select
  rtp.displayname as LName,
  rtp.selectstoredprocedure as LProc,
  rp.ID as LReportPropertyID,
  r.ReportCaption LReportCaption,
  rt.ReportTypeName LReportType
from
  reports.report_properties rp,
  reports.report_type_properties rtp,
  reports.reports r,
  reports.general_reports gr,
  reports.reporttypes rt
where
	rtp.ID=rp.PropertyID
and rtp.ReportTypeCode = r.ReportTypeCode
and r.generalreportcode=gr.generalreportcode
and gr.generalreportcode=?r
and rp.ID=?rpv
and r.ReportCode=?rp
and rt.ReportTypeCode = r.ReportTypeCode
";
            MyDA.Fill(DS, dtList.TableName);
            lblListName.Text      = property.PropertyType.DisplayName;
            lblReportCaption.Text = property.Report.ReportCaption;
            lblReportType.Text    = property.Report.ReportType.ReportTypeName;

            MyCn.Close();
            PostData();
        }
        else
        {
            DS = ((DataSet)Session[DSValues]);
            if (DS == null)             // вероятно, сессия завершилась и все ее данные утеряны
            {
                Reports_GeneralReports.Redirect(this);
            }
            dgvListValues.DataSource = DS.Tables[dtProcResult.TableName].DefaultView;
        }
    }