Example #1
0
        public new questStatus GetStoredProdecureParameters(Quest.Functional.MasterPricing.Database database, string filterProcedureName, out List <FilterProcedureParameter> filterProcedureParameterList)
        {
            // Initialize
            questStatus status = null;

            filterProcedureParameterList = null;


            // Get stored procedure
            DatabaseId          databaseId          = new DatabaseId(database.Id);
            StoredProcedure     storedProcedure     = null;
            StoredProceduresMgr storedProceduresMgr = new StoredProceduresMgr(this.UserSession);

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

            // Get stored procedure parameters
            StoredProcedureId storedProcedureId = new StoredProcedureId(storedProcedure.Id);
            List <StoredProcedureParameter> storedProcedureParameterList = null;
            StoredProcedureParametersMgr    storedProcedureParametersMgr = new StoredProcedureParametersMgr(this.UserSession);

            storedProcedureParametersMgr.Read(storedProcedureId, out storedProcedureParameterList);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }

            // Transfer over to filter procedure.
            filterProcedureParameterList = new List <FilterProcedureParameter>();
            foreach (StoredProcedureParameter storedProcedureParameter in storedProcedureParameterList)
            {
                FilterProcedureParameter filterProcedureParameter = new FilterProcedureParameter();
                BufferMgr.TransferBuffer(storedProcedureParameter, filterProcedureParameter);
                filterProcedureParameterList.Add(filterProcedureParameter);
            }
            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));
        }
        /*==================================================================================================================================
        * Public Methods
        *=================================================================================================================================*/

        #region LIST
        //----------------------------------------------------------------------------------------------------------------------------------
        // LIST
        //----------------------------------------------------------------------------------------------------------------------------------
        public questStatus GetParamerListInfo(ParameterListViewModel viewModel, out ParameterListViewModel parameterListViewModel)
        {
            // Initialize
            questStatus status = null;

            parameterListViewModel = null;
            DatabaseId databaseId = new DatabaseId(viewModel.DatabaseId);


            // Read the database
            DatabaseBaseViewModel databaseBaseViewModel = null;
            DatabaseBaseModeler   databaseBaseModeler   = new DatabaseBaseModeler(this.HttpRequestBase, this.UserSession);

            status = databaseBaseModeler.GetDatabase(databaseId, out databaseBaseViewModel);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }

            // Read the stored procedure
            StoredProceduresListViewModel storedProceduresListViewModel = null;
            StoredProceduresListModeler   storedProceduresListModeler   = new StoredProceduresListModeler(this.HttpRequestBase, this.UserSession);

            status = storedProceduresListModeler.List(databaseId, out storedProceduresListViewModel);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }


            // Get stored procedure info
            StoredProcedureId storedProcedureId = new StoredProcedureId(viewModel.Id);


            // Read the stored procedure info
            StoredProcedure     storedProcedure     = null;
            StoredProceduresMgr storedProceduresMgr = new StoredProceduresMgr(this.UserSession);

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

            // Get stored procedure parameters
            viewModel.StoredProcedureId = viewModel.Id;
            ParameterListViewModel _parameterListViewModel = null;

            status = List(viewModel, out _parameterListViewModel);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }


            // Sort by display order
            // NOTE: ORDER IN DATABASE -SHOULD- BE ORDER IN SPROC.


            // Transfer model.
            parameterListViewModel            = new ParameterListViewModel(this.UserSession, viewModel);
            parameterListViewModel.DatabaseId = databaseId.Id;
            parameterListViewModel.Database   = databaseBaseViewModel;

            foreach (StoredProcedureLineItemViewModel storedProcedureLineItemViewModel in storedProceduresListViewModel.Items)
            {
                OptionValuePair opv = new OptionValuePair();
                opv.Id    = storedProcedureLineItemViewModel.Id.ToString();
                opv.Label = storedProcedureLineItemViewModel.Name;
                parameterListViewModel.StoredProcedureOptions.Add(opv);
            }

            parameterListViewModel.ParentEntityType  = viewModel.ParentEntityType;
            parameterListViewModel.StoredProcedureId = viewModel.StoredProcedureId;

            StoredProcedureViewModel storedProcedureViewModel = new StoredProcedureViewModel();

            BufferMgr.TransferBuffer(storedProcedure, storedProcedureViewModel);
            parameterListViewModel.StoredProcedure = storedProcedureViewModel;
            parameterListViewModel.Items           = _parameterListViewModel.Items;

            return(new questStatus(Severity.Success));
        }
        /*==================================================================================================================================
        * Public Methods
        *=================================================================================================================================*/

        #region LIST
        //----------------------------------------------------------------------------------------------------------------------------------
        // LIST
        //----------------------------------------------------------------------------------------------------------------------------------
        public questStatus List(DatabaseId databaseId, out StoredProceduresListViewModel storedProceduresListViewModel)
        {
            // Initialize
            questStatus status = null;

            storedProceduresListViewModel = null;


            // Get query options from query string
            QueryOptions    queryOptions    = null;
            BaseListModeler baseListModeler = new BaseListModeler(this.HttpRequestBase, new UserSession());

            status = baseListModeler.ParsePagingOptions(this.HttpRequestBase, out queryOptions);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }


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

            searchField.Name            = "DatabaseId";
            searchField.SearchOperation = SearchOperation.Equal;
            searchField.Type            = typeof(int);
            searchField.Value           = databaseId.Id.ToString();
            searchFieldList.Add(searchField);

            SearchOptions searchOptions = new SearchOptions();

            searchOptions.SearchFieldList = searchFieldList;
            queryOptions.SearchOptions    = searchOptions;
            QueryResponse queryResponse = null;


            // Get Database storedProcedures
            List <StoredProcedure> storedProceduresetList = null;
            StoredProceduresMgr    storedProceduresMgr    = new StoredProceduresMgr(this.UserSession);

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


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


            // Transfer model.
            // TODO: USE BaseListModeler to xfer queryOptions to QueryOptionsStoredProcedureModel.
            storedProceduresListViewModel = new StoredProceduresListViewModel(this.UserSession);
            QueryResponseViewModel queryResponseViewModel = null;

            status = TransferQueryResponse(queryResponse, out queryResponseViewModel);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }
            storedProceduresListViewModel.QueryResponse = queryResponseViewModel;
            foreach (Quest.Functional.MasterPricing.StoredProcedure storedProcedure in storedProceduresetList)
            {
                StoredProcedureLineItemViewModel storedProcedureLineItemViewModel = new StoredProcedureLineItemViewModel();
                BufferMgr.TransferBuffer(storedProcedure, storedProcedureLineItemViewModel);
                storedProceduresListViewModel.Items.Add(storedProcedureLineItemViewModel);
            }
            return(new questStatus(Severity.Success));
        }