public questStatus Read(TablesetId tablesetId, out TablesetEditorViewModel tablesetEditorViewModel)
        {
            // Initialize
            questStatus status = null;

            tablesetEditorViewModel = null;


            // Read
            Quest.Functional.MasterPricing.Tableset tableset = null;
            TablesetsMgr tablesetsMgr = new TablesetsMgr(this.UserSession);

            status = tablesetsMgr.Read(tablesetId, out tableset);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }

            // Transfer model.
            tablesetEditorViewModel = new TablesetEditorViewModel(this.UserSession);
            BufferMgr.TransferBuffer(tableset, tablesetEditorViewModel);


            return(new questStatus(Severity.Success));
        }
        public questStatus GetTablesetOptions(out List <OptionValuePair> optionsList, string Value = null, string Name = null)
        {
            // Initialize
            questStatus status = null;

            optionsList = null;


            // Get tableset
            QueryOptions    queryOptions     = new QueryOptions(100, 1);
            List <Tableset> tablesetTypeList = null;
            QueryResponse   queryResponse    = null;
            TablesetsMgr    tablesetsMgr     = new TablesetsMgr(this.UserSession);

            status = tablesetsMgr.List(queryOptions, out tablesetTypeList, out queryResponse);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }

            // Sort
            tablesetTypeList.Sort(delegate(Tableset i1, Tableset i2) { return(i1.Name.CompareTo(i2.Name)); });


            // Build options
            // Set selected if specified.
            optionsList = new List <OptionValuePair>();
            foreach (Tableset Tableset in tablesetTypeList)
            {
                OptionValuePair optionValuePair = new OptionValuePair();
                optionValuePair.Id    = Tableset.Id.ToString();
                optionValuePair.Label = Tableset.Name;
                if (Value != null && Value == Tableset.Id.ToString())
                {
                    optionValuePair.bSelected = true;
                }
                else if (Name != null && Name == Tableset.Name)
                {
                    optionValuePair.bSelected = true;
                }
                optionsList.Add(optionValuePair);
            }

            // Insert default option
            status = AddDefaultOptions(optionsList, "-1", "Select one ...");
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }
            return(new questStatus(Severity.Success));
        }
Пример #3
0
        public questStatus GetFilterDatabase(Quest.Functional.MasterPricing.FilterId filterId, out Quest.Functional.MasterPricing.Database database)
        {
            // Initialize
            questStatus status = null;

            database = null;


            // Get filter
            Filter     filter     = null;
            FiltersMgr filtersMgr = new FiltersMgr(this.UserSession);

            status = filtersMgr.Read(filterId, out filter);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }


            // Get tableset
            Tableset     tableset     = null;
            TablesetId   tablesetId   = new TablesetId(filter.TablesetId);
            TablesetsMgr tablesetsMgr = new TablesetsMgr(this.UserSession);

            status = tablesetsMgr.Read(tablesetId, out tableset);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }


            // Get database
            DatabaseId   databaseId   = new DatabaseId(tableset.DatabaseId);
            DatabasesMgr databasesMgr = new DatabasesMgr(this.UserSession);

            status = databasesMgr.Read(databaseId, out database);
            if (!questStatusDef.IsSuccessOrWarning(status))
            {
                return(status);
            }
            return(new questStatus(Severity.Success));
        }
        public questStatus List(QueryOptions queryOptions, out TablesetsListViewModel tablesetsListViewModel)
        {
            // Initialize
            questStatus status = null;

            tablesetsListViewModel = null;


            // List
            QueryResponse queryResponse = null;
            List <Quest.Functional.MasterPricing.Tableset> tablesetList = null;
            TablesetsMgr tablesetsMgr = new TablesetsMgr(this.UserSession);

            status = tablesetsMgr.List(queryOptions, out tablesetList, out queryResponse);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }

            // Sort
            tablesetList.Sort(delegate(Quest.Functional.MasterPricing.Tableset i1, Quest.Functional.MasterPricing.Tableset i2) { return(i1.Name.CompareTo(i2.Name)); });


            // Transfer model.
            // TODO: USE BaseListModeler to xfer queryOptions to QueryOptionsViewModel.
            tablesetsListViewModel = new TablesetsListViewModel(this.UserSession);
            QueryResponseViewModel queryResponseViewModel = null;

            status = TransferQueryResponse(queryResponse, out queryResponseViewModel);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }
            tablesetsListViewModel.QueryResponse = queryResponseViewModel;
            foreach (Quest.Functional.MasterPricing.Tableset tableset in tablesetList)
            {
                TablesetLineItemViewModel tablesetLineItemViewModel = new TablesetLineItemViewModel();
                BufferMgr.TransferBuffer(tableset, tablesetLineItemViewModel);
                tablesetsListViewModel.Items.Add(tablesetLineItemViewModel);
            }
            return(new questStatus(Severity.Success));
        }
        public questStatus Page(out TablesetsListViewModel tablesetsListViewModel)
        {
            // Initialize
            questStatus status = null;

            tablesetsListViewModel = null;


            // Set up query options.
            // TEMPORARY: OPTIMIZE THIS
            List <SearchField> searchFieldList = new List <SearchField>();

            SearchOptions searchOptions = new SearchOptions();

            searchOptions.SearchFieldList = searchFieldList;

            QueryOptions queryOptions = new QueryOptions(100, 1);

            queryOptions.SearchOptions = searchOptions;
            QueryResponse queryResponse = null;


            // List
            List <Quest.Functional.MasterPricing.Tableset> tablesetList = null;
            TablesetsMgr tablesetsMgr = new TablesetsMgr(this.UserSession);

            status = tablesetsMgr.List(queryOptions, out tablesetList, out queryResponse);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }

            // Transfer model.
            tablesetsListViewModel = new TablesetsListViewModel(this.UserSession);
            foreach (Quest.Functional.MasterPricing.Tableset tableset in tablesetList)
            {
                TablesetLineItemViewModel tablesetLineItemViewModel = new TablesetLineItemViewModel();
                BufferMgr.TransferBuffer(tableset, tablesetLineItemViewModel);
                tablesetsListViewModel.Items.Add(tablesetLineItemViewModel);
            }
            return(new questStatus(Severity.Success));
        }
Пример #6
0
        public questStatus GetDatabaseStoredProcedures(TablesetId tablesetId, out List <StoredProcedure> storedProcedureList)
        {
            // Initialize
            questStatus status = null;

            storedProcedureList = null;


            // Get tableset
            Tableset     tableset     = null;
            TablesetsMgr tablesetsMgr = new TablesetsMgr(this.UserSession);

            status = tablesetsMgr.Read(tablesetId, out tableset);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }


            // Get database
            Quest.Functional.MasterPricing.Database database = null;
            DatabaseId   databaseId   = new DatabaseId(tableset.DatabaseId);
            DatabasesMgr databasesMgr = new DatabasesMgr(this.UserSession);

            status = databasesMgr.Read(databaseId, out database);
            if (!questStatusDef.IsSuccessOrWarning(status))
            {
                return(status);
            }


            // Get database stored procedures
            DbFilterProceduresMgr dbFilterProceduresMgr = new DbFilterProceduresMgr(this.UserSession);

            status = GetDatabaseStoredProcedures(database, out storedProcedureList);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }
            return(new questStatus(Severity.Success));
        }
Пример #7
0
        public questStatus Verify(FilterId filterId, Filter filter)
        {
            // Initialize
            questStatus status = null;


            // Verify filter Id
            Filter     _filter    = null;
            FiltersMgr filtersMgr = new FiltersMgr(this.UserSession);

            status = filtersMgr.Read(filterId, out _filter);
            if (!questStatusDef.IsSuccess(status))
            {
                return(new questStatus(Severity.Error, String.Format("Error reading FilterId {0} not found: {0}",
                                                                     filterId.Id, status.Message)));
            }

            // Verify tableset Id
            TablesetId   tablesetId   = new TablesetId(filter.TablesetId);
            Tableset     _tableset    = null;
            TablesetsMgr tablesetsMgr = new TablesetsMgr(this.UserSession);

            status = tablesetsMgr.Read(tablesetId, out _tableset);
            if (!questStatusDef.IsSuccess(status))
            {
                return(new questStatus(Severity.Error, String.Format("Error reading TablesetId not found: {0}",
                                                                     tablesetId, status.Message)));
            }


            // Make shift validation for now.
            status = Verify(filter);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }
            return(new questStatus(Severity.Success));
        }
        /*==================================================================================================================================
        * Public Methods
        *=================================================================================================================================*/

        #region CRUD
        //----------------------------------------------------------------------------------------------------------------------------------
        // CRUD
        //----------------------------------------------------------------------------------------------------------------------------------
        public questStatus Save(TablesetEditorViewModel tablesetEditorViewModel)
        {
            // Initialize
            questStatus status = null;


            // Transfer model
            Quest.Functional.MasterPricing.Tableset tableset = new Functional.MasterPricing.Tableset();
            BufferMgr.TransferBuffer(tablesetEditorViewModel, tableset);


            // Determine if this is a create or update
            TablesetsMgr tablesetsMgr = new TablesetsMgr(this.UserSession);

            if (tablesetEditorViewModel.Id < BaseId.VALID_ID)
            {
                // Create
                TablesetId tablesetId = null;
                status = tablesetsMgr.Create(tableset, out tablesetId);
                if (!questStatusDef.IsSuccess(status))
                {
                    FormatErrorMessage(status, tablesetEditorViewModel);
                    return(status);
                }
                tablesetEditorViewModel.Id = tablesetId.Id;
            }
            else
            {
                // Update
                status = tablesetsMgr.Update(tableset);
                if (!questStatusDef.IsSuccess(status))
                {
                    FormatErrorMessage(status, tablesetEditorViewModel);
                    return(status);
                }
            }
            return(new questStatus(Severity.Success));
        }
        /*==================================================================================================================================
        * Public Methods
        *=================================================================================================================================*/
        public questStatus GetFilterProcedureOptions(TablesetId tablesetId, out List <OptionValuePair> optionsList, string Value = null, string Name = null)
        {
            // Initialize
            questStatus status = null;

            optionsList = null;



            ////// Get stored procedures for filter's database.
            ////FilterMgr filterMgr = new FilterMgr(this.UserSession);
            ////List<StoredProcedure> storedProcedureList = null;
            ////status = filterMgr.GetDatabaseStoredProcedures(tablesetId, out storedProcedureList);
            ////if (!questStatusDef.IsSuccess(status))
            ////{
            ////    return (status);
            ////}

            // Get the database Id.
            Tableset     tableset     = null;
            TablesetsMgr tablesetsMgr = new TablesetsMgr(this.UserSession);

            status = tablesetsMgr.Read(tablesetId, out tableset);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }

            // Get the stored procedures.
            DatabaseId             databaseId          = new DatabaseId(tableset.DatabaseId);
            List <StoredProcedure> storedProcedureList = null;
            StoredProceduresMgr    storedProceduresMgr = new StoredProceduresMgr(this.UserSession);

            status = storedProceduresMgr.Read(databaseId, out storedProcedureList);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }


            // Sort
            storedProcedureList.Sort(delegate(StoredProcedure i1, StoredProcedure i2) { return(i1.Name.CompareTo(i2.Name)); });


            // Build options
            // Set selected if specified.
            optionsList = new List <OptionValuePair>();
            foreach (StoredProcedure storedProcedure in storedProcedureList)
            {
                OptionValuePair optionValuePair = new OptionValuePair();
                optionValuePair.Id    = storedProcedure.Id.ToString();
                optionValuePair.Label = storedProcedure.Name;
                if (Value != null && Value == storedProcedure.Id.ToString())
                {
                    optionValuePair.bSelected = true;
                }
                else if (Name != null && Name == storedProcedure.Name)
                {
                    optionValuePair.bSelected = true;
                }
                optionsList.Add(optionValuePair);
            }

            // Insert default option
            status = AddDefaultOptions(optionsList, "-1", "Select one ...");
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }
            return(new questStatus(Severity.Success));
        }
Пример #10
0
        public questStatus Save(TablesetConfigurationViewModel tablesetConfigurationViewModel)
        {
            // Initialize
            questStatus status     = null;
            TablesetId  tablesetId = null;


            // Validate: must have a valid TablesetId
            if (tablesetConfigurationViewModel.Tableset.Id < BaseId.VALID_ID)
            {
                return(new questStatus(Severity.Error, "Invalid Tableset identity"));
            }
            tablesetId = new TablesetId(tablesetConfigurationViewModel.Tableset.Id);
            Tableset     tableset     = null;
            TablesetsMgr tablesetsMgr = new TablesetsMgr(this.UserSession);

            status = tablesetsMgr.Read(tablesetId, out tableset);
            if (!questStatusDef.IsSuccess(status))
            {
                return(new questStatus(Severity.Error, String.Format("Tableset identity not found: {0}", tablesetId.Id)));
            }


            // Transfer model
            if (tablesetConfigurationViewModel.TableList == null)
            {
                tablesetConfigurationViewModel.TableList = new List <BootstrapTreenodeViewModel>();
            }
            TablesetConfiguration tablesetConfiguration = new TablesetConfiguration();

            BufferMgr.TransferBuffer(tablesetConfigurationViewModel, tablesetConfiguration, true);
            foreach (BootstrapTreenodeViewModel _table in tablesetConfigurationViewModel.TableList)
            {
                TablesetTable tablesetTable = new TablesetTable();
                string[]      parts         = _table.text.Split(new[] { '[', '.', ']' }, StringSplitOptions.RemoveEmptyEntries);
                tablesetTable.Schema = parts[0];
                tablesetTable.Name   = parts[1];
                tablesetConfiguration.TablesetTables.Add(tablesetTable);
            }
            foreach (BootstrapTreenodeViewModel _view in tablesetConfigurationViewModel.ViewList)
            {
                TablesetView tablesetView = new TablesetView();
                string[]     parts        = _view.text.Split(new[] { '[', '.', ']' }, StringSplitOptions.RemoveEmptyEntries);
                tablesetView.Schema = parts[0];
                tablesetView.Name   = parts[1];
                tablesetConfiguration.TablesetViews.Add(tablesetView);
            }


            // Save
            tablesetId = null;
            TablesetMgr tablesetMgr = new TablesetMgr(this.UserSession);

            status = tablesetMgr.SaveTablesetConfiguration(tablesetConfiguration, out tablesetId);
            if (!questStatusDef.IsSuccess(status))
            {
                FormatErrorMessage(status, tablesetConfigurationViewModel);
                return(status);
            }
            tablesetConfigurationViewModel.Tableset.Id = tablesetId.Id;

            return(new questStatus(Severity.Success));
        }
Пример #11
0
        public questStatus SaveTablesetConfiguration(TablesetConfiguration tablesetConfiguration, out TablesetId tablesetId)
        {
            // Initialize
            questStatus status = null;

            tablesetId = null;
            DbMgrTransaction trans           = null;
            bool             bFiltersRemoved = false;
            questStatus      status2         = null;

            try
            {
                // BEGIN TRANSACTION
                status = BeginTransaction("SaveTablesetConfiguration" + Guid.NewGuid().ToString(), out trans);
                if (!questStatusDef.IsSuccess(status))
                {
                    return(status);
                }


                /*
                 * Update tableset info.
                 */
                // Read the tableset
                TablesetsMgr tablesetsMgr = new TablesetsMgr(this.UserSession);
                TablesetId   _tablesetId  = new TablesetId(tablesetConfiguration.Tableset.Id);
                Tableset     _tableset    = null;
                status = tablesetsMgr.Read(trans, _tablesetId, out _tableset);
                if (!questStatusDef.IsSuccess(status))
                {
                    RollbackTransaction(trans);
                    return(status);
                }


                /*
                 * Remove all tableset entities.
                 */
                status = ClearTablesetEntities(trans, _tablesetId);
                if (!questStatusDef.IsSuccess(status))
                {
                    RollbackTransaction(trans);
                    return(status);
                }


                // TESTING ONLY:  COMMIT TRANSACTION
                bool bKlugie = false;
                if (bKlugie)
                {
                    status = CommitTransaction(trans);
                    if (!questStatusDef.IsSuccess(status))
                    {
                        return(status);
                    }
                }


                /*
                 * Get database entites.
                 */
                DatabaseId       databaseId       = new DatabaseId(tablesetConfiguration.Database.Id);
                DatabaseMgr      databaseMgr      = new DatabaseMgr(this.UserSession);
                DatabaseEntities databaseEntities = null;
                status = databaseMgr.ReadDatabaseEntities(databaseId, out databaseEntities);
                if (!questStatusDef.IsSuccess(status))
                {
                    RollbackTransaction(trans);
                    return(status);
                }


                #region Save tableset info.

                /*
                 * Save tableset info.
                 */
                DbTablesetColumnsMgr dbTablesetColumnsMgr = new DbTablesetColumnsMgr(this.UserSession);

                // Save table info.
                DbTablesetTablesMgr  dbTablesetTablesMgr = new DbTablesetTablesMgr(this.UserSession);
                List <TablesetTable> tablesetTableList   = new List <TablesetTable>();
                foreach (TablesetTable tablesetTable in tablesetConfiguration.TablesetTables)
                {
                    Table _table = databaseEntities.TableList.Find(delegate(Table t) { return(t.Schema == tablesetTable.Schema && t.Name == tablesetTable.Name); });
                    if (_table == null)
                    {
                        RollbackTransaction(trans);
                        return(new questStatus(Severity.Error, String.Format("ERROR: tableset table [{0}].[{1}] not found in database metainfo.  Try refreshing database schema info",
                                                                             tablesetTable.Schema, tablesetTable.Name)));
                    }
                    tablesetTable.TablesetId = _tableset.Id;
                    tablesetTable.Table      = _table;
                    tablesetTableList.Add(tablesetTable);


                    // Create tableset table.
                    TablesetTableId tablesetTableId = null;
                    status = dbTablesetTablesMgr.Create(trans, tablesetTable, out tablesetTableId);
                    if (!questStatusDef.IsSuccess(status))
                    {
                        RollbackTransaction(trans);
                        return(status);
                    }

                    foreach (Column column in _table.ColumnList)
                    {
                        Column _column = _table.ColumnList.Find(delegate(Column c) { return(c.Name == column.Name); });
                        if (_column == null)
                        {
                            RollbackTransaction(trans);
                            return(new questStatus(Severity.Error, String.Format("ERROR: column [{0}] not found in table [{1}].[{2}] in database metainfo.  Try refreshing database schema info",
                                                                                 column.Name, _table.Schema, _table.Name)));
                        }

                        TablesetColumn tablesetColumn = new TablesetColumn();
                        tablesetColumn.EntityTypeId     = EntityType.Table;
                        tablesetColumn.TableSetEntityId = tablesetTableId.Id;
                        tablesetColumn.Name             = column.Name;

                        TablesetColumnId tablesetColumnId = null;
                        status = dbTablesetColumnsMgr.Create(trans, tablesetColumn, out tablesetColumnId);
                        if (!questStatusDef.IsSuccess(status))
                        {
                            RollbackTransaction(trans);
                            return(status);
                        }
                    }
                }

                // Save view info.
                DbTablesetViewsMgr  dbTablesetViewsMgr = new DbTablesetViewsMgr(this.UserSession);
                List <TablesetView> tablesetViewList   = new List <TablesetView>();
                foreach (TablesetView tablesetView in tablesetConfiguration.TablesetViews)
                {
                    View _view = databaseEntities.ViewList.Find(delegate(View v) { return(v.Schema == tablesetView.Schema && v.Name == tablesetView.Name); });
                    if (_view == null)
                    {
                        RollbackTransaction(trans);
                        return(new questStatus(Severity.Error, String.Format("ERROR: tableset view [{0}].[{1}] not found in database metainfo.  Try refreshing database schema info",
                                                                             tablesetView.Schema, tablesetView.Name)));
                    }
                    tablesetView.TablesetId = _tableset.Id;
                    tablesetView.View       = _view;
                    tablesetViewList.Add(tablesetView);

                    // Create tableset view.
                    TablesetViewId tablesetViewId = null;
                    status = dbTablesetViewsMgr.Create(trans, tablesetView, out tablesetViewId);
                    if (!questStatusDef.IsSuccess(status))
                    {
                        RollbackTransaction(trans);
                        return(status);
                    }

                    foreach (Column column in _view.ColumnList)
                    {
                        Column _column = _view.ColumnList.Find(delegate(Column c) { return(c.Name == column.Name); });
                        if (_column == null)
                        {
                            RollbackTransaction(trans);
                            return(new questStatus(Severity.Error, String.Format("ERROR: column [{0}] not found in view [{1}].[{2}] in database metainfo.  Try refreshing database schema info",
                                                                                 column.Name, _view.Schema, _view.Name)));
                        }

                        TablesetColumn tablesetColumn = new TablesetColumn();
                        tablesetColumn.EntityTypeId     = EntityType.View;
                        tablesetColumn.TableSetEntityId = tablesetViewId.Id;
                        tablesetColumn.Name             = column.Name;

                        TablesetColumnId tablesetColumnId = null;
                        status = dbTablesetColumnsMgr.Create(trans, tablesetColumn, out tablesetColumnId);
                        if (!questStatusDef.IsSuccess(status))
                        {
                            RollbackTransaction(trans);
                            return(status);
                        }
                    }
                }
                #endregion


                // Update tableset.
                bFiltersRemoved      = false;
                _tableset.DatabaseId = tablesetConfiguration.Database.Id;
                status2 = tablesetsMgr.Update(trans, _tableset);
                if (!questStatusDef.IsSuccess(status2))
                {
                    if (questStatusDef.IsWarning(status2))
                    {
                        bFiltersRemoved = true;
                    }
                    else
                    {
                        RollbackTransaction(trans);
                        return(status);
                    }
                }


                // COMMIT TRANSACTION
                status = CommitTransaction(trans);
                if (!questStatusDef.IsSuccess(status))
                {
                    return(status);
                }

                // Return the tableset id
                tablesetId = new TablesetId(tablesetConfiguration.Tableset.Id);
            }
            catch (System.Exception ex)
            {
                if (trans != null)
                {
                    RollbackTransaction(trans);
                }
                return(new questStatus(Severity.Fatal, String.Format("EXCEPTION: {0}.{1}: {2}",
                                                                     this.GetType().Name, MethodBase.GetCurrentMethod().Name,
                                                                     ex.InnerException != null ? ex.InnerException.Message : ex.Message)));
            }
            if (bFiltersRemoved)
            {
                return(status2);
            }
            return(new questStatus(Severity.Success));
        }