protected void btnNext_Click(object sender, EventArgs e) { if (this.IsValid) { GeneralReport _generalReport = GeneralReport.Find(Convert.ToUInt64(Request["TemporaryId"])); ReportType _reportType = ReportType.Find(Convert.ToUInt64(ddlReportTypes.SelectedValue)); Report _newReport = new Report() { GeneralReport = _generalReport, ReportType = _reportType, Enabled = true, ReportCaption = tbReportName.Text }; Report[] _oldReports = Report.FindAll(Expression.Eq("GeneralReport", _generalReport)); using (new TransactionScope()) { foreach (Report _deletedReport in _oldReports) { _deletedReport.Delete(); } _newReport.Save(); } if (ddlTemplates.Visible && (ddlTemplates.SelectedIndex > 0)) { ulong _sourceTemplateReport = Convert.ToUInt64(ddlTemplates.SelectedValue); ReportHelper.CopyReportProperties(_sourceTemplateReport, _newReport.Id); } Response.Redirect(String.Format( "ReportProperties.aspx?TemporaryId={0}&rp={1}", Request["TemporaryId"], _newReport.Id)); } }
public void TestRecipientsList() { var payer = new TestPayer("Тестовый плательщик"); session.Save(payer); var contactGroupOwner = new TestContactGroupOwner(); contactGroupOwner.SaveAndFlush(); var client1 = TestClient.CreateNaked(session); var client2 = TestClient.CreateNaked(session); client1.Payers.Add(payer); client2.Payers.Add(payer); session.CreateSQLQuery(@"INSERT INTO Billing.PayerClients(ClientId, PayerId) VALUES(:clientid1, :payerid); INSERT INTO Billing.PayerClients(ClientId, PayerId) VALUES(:clientid2, :payerid);" ) .SetParameter("clientid1", client1.Id).SetParameter("clientid2", client2.Id).SetParameter("payerid", payer.Id).ExecuteUpdate(); var repPayer = Payer.Find(payer.Id); var new_report = new GeneralReport() { Format = "Excel", Payer = repPayer, Comment = "Тестовый отчет" }; new_report.SaveAndFlush(); var reportId = new_report.Id; var report = GeneralReport.Find(Convert.ToUInt64(reportId)); Assert.That(report.Payer.AllClients.Count, Is.EqualTo(2)); Assert.That(report.Payer.Clients[0].ShortName, Is.EqualTo(client1.Name)); Assert.That(report.Payer.Clients[1].ShortName, Is.EqualTo(client2.Name)); }
protected void Page_Load(object sender, EventArgs e) { if (String.IsNullOrEmpty(Request["TemporaryId"])) { Response.Redirect("base.aspx"); } else { uint contactOwnerId; if (uint.TryParse(ConfigurationManager.AppSettings["ReportsContactGroupOwnerId"], out contactOwnerId)) { try { _reportsContactGroupOwner = ContactGroupOwner.Find(contactOwnerId); } catch (NotFoundException exp) { throw new ReportTunerException("В файле Web.Config параметр ReportsContactGroupOwnerId указывает на несуществующую запись.", exp); } } else { throw new ReportTunerException("В файле Web.Config параметр ReportsContactGroupOwnerId не существует или настроен некорректно."); } _generalReport = GeneralReport.Find(Convert.ToUInt64(Request["TemporaryId"])); _taskService = ScheduleHelper.GetService(); _currentTask = ScheduleHelper.GetTaskOrCreate( _taskService, ScheduleHelper.GetReportsFolder(_taskService), _generalReport.Id, "Временный отчет, созданный " + _generalReport.TemporaryCreationDate.Value.ToString(), "GR"); btnRun.Enabled = _currentTask.Enabled && (_currentTask.State != TaskState.Running); btnRun.Text = (_currentTask.State == TaskState.Running) ? StatusNotRunning : StatusRunning; if ((_generalReport.ContactGroup == null) && btnRun.Enabled) { btnRun.Enabled = false; } if (!IsPostBack) { ClearSearch(); if (_generalReport.ContactGroup != null) { lContactGroupName.Text = _generalReport.ContactGroup.Name; } } } }
protected SiteMapNode ExpandForumPath(Object sender, SiteMapResolveEventArgs e) { SiteMapNode currentNode = e.Provider.CurrentNode.Clone(true); if (currentNode.Key.EndsWith("/reports/reportproperties.aspx", StringComparison.OrdinalIgnoreCase)) { if (!String.IsNullOrEmpty(e.Context.Request["TemporaryId"])) { SiteMapNode _temporaryNode = e.Provider.FindSiteMapNode("~/Reports/TemporaryReport.aspx"); currentNode = _temporaryNode.ChildNodes[0].Clone(true); currentNode.ParentNode.Url += "?TemporaryId=" + e.Context.Request["TemporaryId"]; } else { currentNode.ParentNode.Url += "?r=" + e.Context.Request["r"]; } } if (currentNode.Key.EndsWith("/reports/reportpropertyvalues.aspx", StringComparison.OrdinalIgnoreCase)) { if (!String.IsNullOrEmpty(e.Context.Request["TemporaryId"])) { SiteMapNode _temporaryNode = e.Provider.FindSiteMapNode("~/Reports/TemporaryReport.aspx"); //Здесь это делается не совсем корректно. currentNode = _temporaryNode.ChildNodes[0].ChildNodes[0].Clone(true); currentNode.ParentNode.ParentNode.Url += "?TemporaryId=" + e.Context.Request["TemporaryId"]; currentNode.ParentNode.Url += e.Context.Request["TemporaryId"] + "&rp=" + e.Context.Request["rp"]; } else { currentNode.ParentNode.Url += "?r=" + e.Context.Request["r"] + "&rp=" + e.Context.Request["rp"]; } } if (currentNode.Key.EndsWith("/reports/temporaryreportschedule.aspx", StringComparison.OrdinalIgnoreCase)) { currentNode.ParentNode.ParentNode.Url += "?TemporaryId=" + e.Context.Request["TemporaryId"]; Report _temporaryReport = Report.FindFirst( Expression.Eq("GeneralReport", GeneralReport.Find(Convert.ToUInt64(e.Context.Request["TemporaryId"])))); currentNode.ParentNode.Url += e.Context.Request["TemporaryId"] + "&rp=" + _temporaryReport.Id; } return(currentNode); }
private void BindTemplateReports(ReportType selectedReportType) { Report[] _templateReports = Report.FindAll( Order.Asc("ReportCaption"), Expression.Eq("GeneralReport", GeneralReport.Find(Convert.ToUInt64(ConfigurationManager.AppSettings["TemplateReportId"]))), Expression.Eq("ReportType", selectedReportType)); if (_templateReports.Length > 0) { ddlTemplates.Visible = true; ddlTemplates.DataSource = _templateReports; ddlTemplates.DataTextField = "ReportCaption"; ddlTemplates.DataValueField = "Id"; ddlTemplates.DataBind(); ddlTemplates.Items.Insert(0, new ListItem("не установлен", String.Empty)); } else { ddlTemplates.Visible = false; } }
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; }