示例#1
0
        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);
        }
示例#2
0
        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);
        }
        /// <summary>
        /// Call this to display the form and show the available templates.
        /// </summary>
        /// <param name="AReportType"></param>
        public DialogResult SelectTemplate(String AReportType)
        {
            FTemplateTable = TRemote.MReporting.WebConnectors.GetTemplateVariants(AReportType, FCurrentUser, false);
            DataView myDataView = FTemplateTable.DefaultView;

            myDataView.AllowNew        = false;
            grdTemplateList.DataSource = new DevAge.ComponentModel.BoundDataView(myDataView);
            grdTemplateList.Columns.Clear();
            grdTemplateList.AddTextColumn(AReportType, FTemplateTable.ColumnReportVariant);
            grdTemplateList.SelectRowInGrid(1);
            FocusedRowChanged(null, null);

            this.FormClosing += TFrmPetra_Closed; // Apparently I need to do this myself - it's not called automatically.
            return(ShowDialog());
        }
示例#4
0
        public static SReportTemplateTable SaveTemplates(SReportTemplateTable editedTemplates)
        {
            TDBTransaction       Transaction      = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.ReadCommitted);
            SReportTemplateTable ChangedTemplates = editedTemplates.GetChangesTyped();

            SReportTemplateAccess.SubmitChanges(ChangedTemplates, Transaction);
            DBAccess.GDBAccessObj.CommitTransaction();

            foreach (SReportTemplateRow Row in ChangedTemplates.Rows)
            {
                SaveTemplatesToBackupFile(Row);
            }

            return(ChangedTemplates);
        }
示例#5
0
        private bool SaveChanges()
        {
            if (DataChangedFlag)
            {
                SReportTemplateTable Tbl = TRemote.MReporting.WebConnectors.SaveTemplates(FTemplateTable);

                if (Tbl != null)
                {
                    FTemplateTable.Merge(Tbl);
                }

                DataChangedFlag = false;
            }

            return(true);
        }
示例#6
0
        private Boolean LoadDefaultTemplate()
        {
            FInitState = TInitState.LoadTemplate;
            SReportTemplateTable TemplateTable = TRemote.MReporting.WebConnectors.GetTemplateVariants(FReportName,
                                                                                                      UserInfo.GUserInfo.UserID,
                                                                                                      true);

            if (TemplateTable.Rows.Count == 0)
            {
//              TLogging.Log("No FastReports template for " + FReportName);
                return(false);
            }

            SetTemplate(TemplateTable[0]);
            FInitState = TInitState.LoadedOK;
            return(true);
        }
示例#7
0
        /// <summary>Restore a previously saved FastReport Template</summary>
        /// <param name="AParameters"></param>
        /// <returns>true if I think I've loaded something</returns>
        public Boolean SetTemplateFromParameters(TParameterList AParameters)
        {
            if (AParameters.Exists("param_SelectedTemplate"))
            {
                Int32 savedTemplate = AParameters.GetParameter("param_SelectedTemplate").value.ToInt32();
                SReportTemplateTable TemplateTable = TRemote.MReporting.WebConnectors.GetTemplateVariants(FReportName,
                                                                                                          UserInfo.GUserInfo.UserID,
                                                                                                          false);
                TemplateTable.DefaultView.RowFilter = "s_template_id_i=" + savedTemplate;

                if (TemplateTable.DefaultView.Count > 0)
                {
                    SetTemplate((SReportTemplateRow)TemplateTable.DefaultView[0].Row);
                    return(true);
                }
            }

            return(false);
        }
示例#8
0
        public static SReportTemplateTable SaveTemplates(SReportTemplateTable editedTemplates)
        {
            TDBTransaction       Transaction      = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.ReadCommitted);
            SReportTemplateTable ChangedTemplates = editedTemplates.GetChangesTyped();

            if ((ChangedTemplates != null) && (ChangedTemplates.Rows.Count > 0))
            {
                SReportTemplateAccess.SubmitChanges(ChangedTemplates, Transaction);
                DBAccess.GDBAccessObj.CommitTransaction();

                foreach (SReportTemplateRow Row in ChangedTemplates.Rows)
                {
                    if (Row.RowState == DataRowState.Deleted)
                    {
                        // The template was deleted - I'll attempt to delete the backup.
                        Int32  templateId            = Convert.ToInt32(Row["s_template_id_i", DataRowVersion.Original]);
                        String reportType            = Row["s_report_type_c", DataRowVersion.Original].ToString();
                        String deletedBackupFilename = TemplateBackupFilename(reportType, templateId.ToString("D2"));

                        try
                        {
                            File.Delete(deletedBackupFilename);
                        }
                        catch (Exception) // I'm not interested in knowing why this didn't work.
                        {
                        }
                    }
                    else
                    {
                        SaveTemplateToBackupFile(Row);
                    }
                }
            }
            else
            {
                DBAccess.GDBAccessObj.RollbackTransaction();
            }

            return(ChangedTemplates);
        }
示例#9
0
        public static SReportTemplateTable GetTemplateById(int TemplateId)
        {
            TDataBase            dbConnection  = null;
            TDBTransaction       Transaction   = null;
            SReportTemplateTable TemplateTable = null;

            try
            {
                dbConnection = TReportingDbAdapter.EstablishDBConnection(true, "GetTemplateById");
                dbConnection.BeginAutoReadTransaction(
                    ref Transaction,
                    delegate
                {
                    TemplateTable = SReportTemplateAccess.LoadByPrimaryKey(TemplateId, Transaction);
                });
            }
            finally
            {
                dbConnection.CloseDBConnection();
            }
            return(TemplateTable);
        }
示例#10
0
        /// <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>
        /// Call this to display the form and show the available templates.
        /// </summary>
        /// <param name="AReportType"></param>
        public DialogResult SelectTemplate(String AReportType)
        {
            FTemplateTable = TRemote.MReporting.WebConnectors.GetTemplateVariants(AReportType, FCurrentUser, false);
            DataView myDataView = FTemplateTable.DefaultView;
            myDataView.AllowNew = false;
            grdTemplateList.DataSource = new DevAge.ComponentModel.BoundDataView(myDataView);
            grdTemplateList.Columns.Clear();
            grdTemplateList.AddTextColumn(AReportType, FTemplateTable.ColumnReportVariant);
            grdTemplateList.SelectRowInGrid(1);
            FocusedRowChanged(null, null);

            this.FormClosing += TFrmPetra_Closed; // Apparently I need to do this myself - it's not called automatically.
            return ShowDialog();
        }
示例#12
0
        /// <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();
            }
        }
示例#13
0
        public static SReportTemplateTable SaveTemplates(SReportTemplateTable editedTemplates)
        {
            TDBTransaction Transaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.ReadCommitted);
            SReportTemplateTable ChangedTemplates = editedTemplates.GetChangesTyped();

            SReportTemplateAccess.SubmitChanges(ChangedTemplates, Transaction);
            DBAccess.GDBAccessObj.CommitTransaction();

            foreach (SReportTemplateRow Row in ChangedTemplates.Rows)
            {
                SaveTemplatesToBackupFile(Row);
            }

            return ChangedTemplates;
        }
示例#14
0
        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 = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.ReadCommitted);
            Tbl = SReportTemplateAccess.LoadUsingTemplate(TemplateRow, Transaction);
            DBAccess.GDBAccessObj.RollbackTransaction();

            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;
        }