/// <summary> /// For Development only, templates are also kept in disc files. /// This means that Bazaar will do the internal update management for us. /// /// For the backup to work, the XmlReports\FastReportsBackup.sql file must be present, /// but it doesn't need to contain anything specifically. /// </summary> private static void SaveTemplatesToBackupFile(SReportTemplateRow Row) { String BackupFilename = TemplateBackupFilename(Row.ReportType, Row.TemplateId.ToString("D2")); if (File.Exists(Path.GetDirectoryName(BackupFilename) + "\\FastReportsBackup.sql")) { String FinalQuery = "DELETE FROM s_report_template WHERE s_template_id_i=" + Row.TemplateId + ";\r\n"; FinalQuery += ( "INSERT INTO s_report_template (s_template_id_i,s_report_type_c,s_report_variant_c,s_author_c,s_default_l,s_readonly_l,s_private_l,s_private_default_l,s_xml_text_c)\r\nVALUES(" + Convert.ToInt32(Row["s_template_id_i"]) + ",'" + escape(Row["s_report_type_c"]) + "','" + escape(Row["s_report_variant_c"]) + "','" + escape(Row["s_author_c"]) + "'," + Row["s_default_l"] + "," + Row["s_readonly_l"] + "," + Row["s_private_l"] + "," + Row["s_private_default_l"] + ",\r\n'" + escape(Row["s_xml_text_c"]) + "');\r\n"); FinalQuery += "\r\nSELECT TRUE;"; File.WriteAllText(BackupFilename, FinalQuery); } }
public static SReportTemplateTable GetTemplateVariants(String AReportType, String AAuthor, Boolean ADefaultOnly = false) { LoadTemplatesFromBackupFile(AReportType); SReportTemplateTable Tbl = new SReportTemplateTable(); SReportTemplateRow TemplateRow = Tbl.NewRowTyped(false); TemplateRow.ReportType = AReportType; TDBTransaction Transaction = null; DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted, TEnforceIsolationLevel.eilMinimum, ref Transaction, delegate { Tbl = SReportTemplateAccess.LoadUsingTemplate(TemplateRow, Transaction); }); String filter = String.Format("(s_author_c ='{0}' OR s_private_l=false)", AAuthor); if (ADefaultOnly) { filter += " AND (s_default_l=true OR s_private_default_l=true)"; } Tbl.DefaultView.RowFilter = filter; Tbl.DefaultView.Sort = (ADefaultOnly) ? "s_private_default_l DESC, s_default_l DESC" : "s_readonly_l DESC, s_default_l DESC, s_private_default_l DESC"; SReportTemplateTable Ret = new SReportTemplateTable(); Ret.Merge(Tbl.DefaultView.ToTable()); Ret.AcceptChanges(); return(Ret); }
/// <summary> /// Use This template for the report /// </summary> /// <param name="ATemplate"></param> public void SetTemplate(SReportTemplateRow ATemplate) { FSelectedTemplate = ATemplate; if (FPetraUtilsObject != null) { FPetraUtilsObject.SetWindowTitle(); } }
public static SReportTemplateTable GetTemplateVariants(String AReportType, String AAuthor, Boolean ADefaultOnly = false) { SReportTemplateTable Tbl = new SReportTemplateTable(); SReportTemplateTable Ret = new SReportTemplateTable(); TDBTransaction Transaction = null; TDataBase dbConnection = new TDataBase(); try { dbConnection = TReportingDbAdapter.EstablishDBConnection(true, "GetTemplateVariants"); LoadTemplatesFromBackupFile(AReportType, dbConnection); dbConnection.BeginAutoReadTransaction( ref Transaction, delegate { SReportTemplateRow TemplateRow = Tbl.NewRowTyped(false); TemplateRow.ReportType = AReportType; Tbl = SReportTemplateAccess.LoadUsingTemplate(TemplateRow, Transaction); }); String filter = String.Format("(s_author_c ='{0}' OR s_private_l=false)", AAuthor); if (ADefaultOnly) { filter += " AND (s_default_l=true OR s_private_default_l=true)"; } Tbl.DefaultView.RowFilter = filter; if (Tbl.DefaultView.Count > 0) { Tbl.DefaultView.Sort = (ADefaultOnly) ? "s_private_default_l DESC, s_default_l DESC" : "s_readonly_l DESC, s_default_l DESC, s_private_default_l DESC"; } else // Something went wrong, but I'll try not to return empty-handed. { Tbl.DefaultView.RowFilter = ""; } Ret.Merge(Tbl.DefaultView.ToTable()); Ret.AcceptChanges(); } finally { dbConnection.CloseDBConnection(); } return(Ret); }
private void DuplicateRecord(object sender, EventArgs e) { GetDataFromControls(); SReportTemplateRow NewRow = FTemplateTable.NewRowTyped(); DataUtilities.CopyAllColumnValues(FSelectedRow, NewRow); NewRow.TemplateId = -1; NewRow.Author = FCurrentUser; NewRow.Default = false; NewRow.Readonly = false; NewRow.ReportVariant = String.Format(Catalog.GetString("Copy of {0}"), NewRow.ReportVariant); FTemplateTable.Rows.Add(NewRow); DataChangedFlag = true; }
private void DeleteRecord(object sender, EventArgs e) { if (FSelectedRow.Default) { MessageBox.Show(Catalog.GetString( "There must always be a default Template.\r\nSet another template as the default before deleting this."), Catalog.GetString("Default Template"), MessageBoxButtons.OK, MessageBoxIcon.Hand); return; } FSelectedRow.Delete(); DataChangedFlag = true; FSelectedRow = null; FocusedRowChanged(null, null); }
/// <summary> /// For Development only, templates are also kept in disc files. /// This means that Bazaar will do the internal update management for us. /// /// For the backup to work, the XmlReports\FastReportsBackup.sql file must be present, /// but it doesn't need to contain anything specifically. /// </summary> private static void SaveTemplateToBackupFile(SReportTemplateRow Row) { if (File.Exists(TAppSettingsManager.GetValue("Reporting.PathStandardReports") + "\\FastReportsBackup.sql") && (Row.RowState != DataRowState.Deleted)) { String BackupFilename = TemplateBackupFilename(Row.ReportType, Row.TemplateId.ToString("D2")); String sqlQuery = "DELETE FROM s_report_template WHERE s_template_id_i=" + Row.TemplateId + ";\r\n" + "INSERT INTO s_report_template (s_template_id_i,s_report_type_c,s_report_variant_c,s_author_c,s_default_l,s_readonly_l,s_private_l,s_private_default_l,s_xml_text_c)\r\nVALUES(" + Convert.ToInt32(Row["s_template_id_i"]) + ",'" + escape(Row["s_report_type_c"]) + "','" + escape(Row["s_report_variant_c"]) + "','" + escape(Row["s_author_c"]) + "'," + Row["s_default_l"] + "," + Row["s_readonly_l"] + "," + Row["s_private_l"] + "," + Row["s_private_default_l"] + ",\r\n'" + escape(Row["s_xml_text_c"]) + "');\r\n"; sqlQuery += "\r\nSELECT TRUE;"; File.WriteAllText(BackupFilename, sqlQuery); } }
private void FocusedRowChanged(System.Object sender, SourceGrid.RowEventArgs e) { FInChangeEvent = true; DataRowView[] SelectedRows = grdTemplateList.SelectedDataRowsAsDataRowView; if (SelectedRows.Length > 0) { GetDataFromControls(); FSelectedRow = (SReportTemplateRow)SelectedRows[0].Row; txtDescription.Text = FSelectedRow.ReportVariant; chkDefault.Checked = FSelectedRow.Default; chkPrivate.Checked = FSelectedRow.Private; chkPrivateDefault.Checked = FSelectedRow.PrivateDefault; chkReadonly.Checked = FSelectedRow.Readonly; } else { FSelectedRow = null; } SetControlsVisible(); FInChangeEvent = false; }
/// <summary> /// Called from a delegate set up by my constructor. /// Or if you're not using a reporting UI, you can call this directly, once the data and params have been set up. /// </summary> /// <param name="ACalc"></param> public void DesignReport(TRptCalculator ACalc) { ACalc.GetParameters().Add("param_design_template", true); if (FSelectedTemplate != null) { if (FDataGetter != null) { if (!FDataGetter(ACalc)) { return; } } FFastReportType.GetMethod("LoadFromString", new Type[] { FSelectedTemplate.XmlText.GetType() }).Invoke(FfastReportInstance, new object[] { FSelectedTemplate.XmlText }); LoadReportParams(ACalc); FFastReportType.GetMethod("Design", new Type[0]).Invoke(FfastReportInstance, null); // // The user can change the report template - if it's changed I'll update the server // (unless the template is read-only, in which case I'll need to make a copy.) object ret = FFastReportType.GetMethod("SaveToString", new Type[0]).Invoke(FfastReportInstance, null); String XmlString = (String)ret; // // I only want to check part of the report to assess whether it's changed, otherwise it always detects a change // (the modified date is changed, and the parameters may also be different.) Boolean TemplateChanged = false; Int32 Page1Pos = XmlString.IndexOf("<ReportPage"); Int32 PrevPage1Pos = FSelectedTemplate.XmlText.IndexOf("<ReportPage"); if ((Page1Pos < 1) || (PrevPage1Pos < 1)) { TemplateChanged = true; } else { if (XmlString.Substring(Page1Pos) != FSelectedTemplate.XmlText.Substring(PrevPage1Pos)) { TemplateChanged = true; } } if (TemplateChanged) { Boolean MakeACopy = false; if (FSelectedTemplate.Readonly) { if (MessageBox.Show( String.Format(Catalog.GetString("{0} cannot be ovewritten.\r\nMake a copy instead?"), FSelectedTemplate.ReportVariant), Catalog.GetString("Design Template"), MessageBoxButtons.YesNo) == DialogResult.No) { return; } MakeACopy = true; } else { if (MessageBox.Show( String.Format(Catalog.GetString("Save changes to {0}?"), FSelectedTemplate.ReportVariant), Catalog.GetString("Design Template"), MessageBoxButtons.YesNo) == DialogResult.No) { return; } } SReportTemplateTable TemplateTable = new SReportTemplateTable(); SReportTemplateRow NewRow = TemplateTable.NewRowTyped(); DataUtilities.CopyAllColumnValues(FSelectedTemplate, NewRow); TemplateTable.Rows.Add(NewRow); if (MakeACopy) { NewRow.TemplateId = -1; // The value will come from the sequence NewRow.ReportVariant = "Copy of " + TemplateTable[0].ReportVariant; NewRow.Readonly = false; NewRow.Default = false; NewRow.PrivateDefault = false; } else { TemplateTable.AcceptChanges(); // Don't allow this one-row table to be seen as "new" } NewRow.XmlText = XmlString; SReportTemplateTable Tbl = TRemote.MReporting.WebConnectors.SaveTemplates(TemplateTable); Tbl.AcceptChanges(); SetTemplate(Tbl[0]); } } if (FPetraUtilsObject != null) { FPetraUtilsObject.UpdateParentFormEndOfReport(); } }
/// <summary> /// For Development only, templates are also kept in disc files. /// This means that Bazaar will do the internal update management for us. /// /// For the backup to work, the XmlReports\FastReportsBackup.sql file must be present, /// but it doesn't need to contain anything specifically. /// </summary> private static void SaveTemplatesToBackupFile(SReportTemplateRow Row) { String BackupFilename = TemplateBackupFilename(Row.ReportType, Row.TemplateId.ToString()); if (File.Exists(Path.GetDirectoryName(BackupFilename) + "\\FastReportsBackup.sql")) { String FinalQuery = "DELETE FROM s_report_template WHERE s_template_id_i=" + Row.TemplateId + ";\r\n"; FinalQuery += ( "INSERT INTO s_report_template (s_template_id_i,s_report_type_c,s_report_variant_c,s_author_c,s_default_l,s_readonly_l,s_private_l,s_private_default_l,s_xml_text_c)\r\nVALUES(" + Convert.ToInt32(Row["s_template_id_i"]) + ",'" + escape(Row["s_report_type_c"]) + "','" + escape(Row["s_report_variant_c"]) + "','" + escape(Row["s_author_c"]) + "'," + Row["s_default_l"] + "," + Row["s_readonly_l"] + "," + Row["s_private_l"] + "," + Row["s_private_default_l"] + ",\r\n'" + escape(Row["s_xml_text_c"]) + "');\r\n"); FinalQuery += "\r\nSELECT TRUE;"; File.WriteAllText(BackupFilename, FinalQuery); } }