public void CopyReport(ulong?destId, [DataBind("filter")] GeneralReportsFilter filter)
        {
            if (destId == null || filter.Report == null)
            {
                RedirectToUrl("../Reports/Reports.aspx?r=" + filter.GeneralReport);
            }
            var sourceReport = DbSession.Query <Report>().FirstOrDefault(r => r.Id == filter.Report);

            if (sourceReport == null)
            {
                return;
            }

            var destReport = new Report {
                Enabled       = sourceReport.Enabled,
                ReportCaption = String.Concat("Копия ", sourceReport.ReportCaption),
                ReportType    = sourceReport.ReportType,
                GeneralReport = DbSession.Query <GeneralReport>().First(r => r.Id == destId)
            };

            using (new TransactionScope()) {
                DbSession.Save(destReport);
                DbSession.Flush();
            }
            ReportHelper.CopyReportProperties(sourceReport.Id, destReport.Id);
            RedirectToUrl("../Reports/Reports.aspx?r=" + destId);
        }
Пример #2
0
        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));
            }
        }
Пример #3
0
    protected void dgvReports_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Add")
        {
            SetupFilter();
            CopyChangesToTable();
            DataRow dr = DS.Tables[dtReports.TableName].NewRow();
            dr[REnabled.ColumnName]       = 0;
            dr[RReportCaption.ColumnName] = string.Empty;
            DS.Tables[dtReports.TableName].Rows.Add(dr);
            dgvReports.DataBind();
        }
        else if (e.CommandName == "Copy")
        {
            CopyChangesToTable();

            UInt64 sourceReportId = Convert.ToUInt64(((((Button)e.CommandSource).Parent).Controls.OfType <HiddenField>().First()).Value);
            UInt64 destReportId   = 0;
            using (var conn = MyCn) {
                conn.Open();
                var command = new MySqlCommand(
                    @"insert into reports.reports
						 (GeneralReportCode, ReportCaption, ReportTypeCode, Enabled)
					  select
						 GeneralReportCode, Concat('Копия ',ReportCaption), ReportTypeCode, Enabled
						from reports.reports
					   where ReportCode = ?reportCode;
					 select last_insert_id() as ReportCode;"                    , conn);
                command.Parameters.AddWithValue("?reportCode", sourceReportId);
                destReportId = Convert.ToUInt64(command.ExecuteScalar());
                conn.Close();
            }

            ReportHelper.CopyReportProperties(sourceReportId, destReportId);

            PostData();
        }
        else if (e.CommandName == "CopyTo")
        {
            UInt64 sourceReportId = Convert.ToUInt64(((((Button)e.CommandSource).Parent).Controls.OfType <HiddenField>().First()).Value);
            Response.Redirect(String.Format("../CopyReport/SelectReport?filter.Report={0}&filter.GeneralReport={1}", sourceReportId, Request["r"]));
        }
    }