Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 3
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);
        }
Esempio n. 4
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);
        }
Esempio n. 5
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);
        }