/*================================================================================================================================== * Public Methods *=================================================================================================================================*/ public questStatus PerformBulkInsert(BulkInsertRequest bulkInsertRequest) { // Initialize questStatus status = null; // Read Filter FilterId filterId = new FilterId(bulkInsertRequest.FilterId); Filter filter = null; FiltersMgr filtersMgr = new FiltersMgr(this.UserSession); status = filtersMgr.Read(filterId, out filter); if (!questStatusDef.IsSuccess(status)) { return(status); } bulkInsertRequest.Filter = filter; // Determine if bulk insert filter procedure exists. FilterProcedure filterProcedure = null; status = _dbBulkInsertMgr.GetFilterProcedure(bulkInsertRequest, "Insert", out filterProcedure); if (!questStatusDef.IsSuccessOrWarning(status)) { return(status); } // Perform bulk insert filter procedure if exists. if (questStatusDef.IsSuccess(status)) { return(PerformBulkInsertFilterProcedure(bulkInsertRequest, filterProcedure)); } // Validate bulk insert request BulkInsertResponse bulkInsertResponse = null; status = ValidateRequest(bulkInsertRequest, out bulkInsertResponse); if (!questStatusDef.IsSuccess(status)) { return(status); } // Generate the SQL status = _dbBulkInsertMgr.GenerateBulkInsertSQL(bulkInsertRequest); if (!questStatusDef.IsSuccess(status)) { return(status); } // Perform bulk insert. status = _dbBulkInsertMgr.PerformBulkInsert(bulkInsertRequest); if (!questStatusDef.IsSuccess(status)) { return(status); } return(new questStatus(Severity.Success)); }
public questStatus Delete(TablesetId tablesetId) { // Initialize questStatus status = null; DbMgrTransaction trans = null; // BEGIN TRANSACTION status = BeginTransaction("DeleteTableset_" + Guid.NewGuid().ToString(), out trans); if (!questStatusDef.IsSuccess(status)) { return(status); } try { // Delete tableset filters FiltersMgr filtersMgr = new FiltersMgr(this.UserSession); status = filtersMgr.Delete(trans, tablesetId); if (!questStatusDef.IsSuccess(status)) { RollbackTransaction(trans); return(status); } // Delete Tableset DbTablesetsMgr dbTablesetsMgr = new DbTablesetsMgr(this.UserSession); status = dbTablesetsMgr.Delete(tablesetId); if (!questStatusDef.IsSuccess(status)) { RollbackTransaction(trans); return(status); } // COMMIT TRANSACTION status = CommitTransaction(trans); if (!questStatusDef.IsSuccess(status)) { return(status); } } 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))); } return(new questStatus(Severity.Success)); }
public questStatus Delete(FilterId filterId) { // Initialize questStatus status = null; // Delete FiltersMgr filtersMgr = new FiltersMgr(this.UserSession); status = filtersMgr.Delete(filterId); if (!questStatusDef.IsSuccess(status)) { return(status); } return(new questStatus(Severity.Success)); }
/*================================================================================================================================== * Public Methods *=================================================================================================================================*/ public questStatus Save(FilterEditorViewModel filterEditorViewModel) { // Initialize questStatus status = null; // Validate if (filterEditorViewModel.TablesetId < BaseId.VALID_ID) { return(new questStatus(Severity.Error, "Invalid Tableset Id")); } // Transfer model Quest.Functional.MasterPricing.Filter filter = new Functional.MasterPricing.Filter(); BufferMgr.TransferBuffer(filterEditorViewModel, filter); // Determine if this is a create or update FiltersMgr filtersMgr = new FiltersMgr(this.UserSession); if (filterEditorViewModel.Id < BaseId.VALID_ID) { // Create FilterId filterId = null; status = filtersMgr.Create(filter, out filterId); if (!questStatusDef.IsSuccess(status)) { FormatErrorMessage(status, filterEditorViewModel); return(status); } filterEditorViewModel.Id = filterId.Id; } else { // Update status = filtersMgr.Update(filter); if (!questStatusDef.IsSuccess(status)) { FormatErrorMessage(status, filterEditorViewModel); return(status); } } return(new questStatus(Severity.Success)); }
/*================================================================================================================================== * Public Methods *=================================================================================================================================*/ #region Options //---------------------------------------------------------------------------------------------------------------------------------- // Options //---------------------------------------------------------------------------------------------------------------------------------- public questStatus GetFilterOptions(TablesetId tablesetId, out List <OptionValuePair> optionsList, string Value = null, string Name = null) { // Initialize questStatus status = null; optionsList = null; // Set up query options. // TEMPORARY: OPTIMIZE THIS SearchField searchField = new SearchField(); searchField.Name = "TablesetId"; searchField.SearchOperation = SearchOperation.Equal; searchField.Type = typeof(int); searchField.Value = tablesetId.Id.ToString(); List <SearchField> searchFieldList = new List <SearchField>(); searchFieldList.Add(searchField); SearchOptions searchOptions = new SearchOptions(); searchOptions.SearchFieldList = searchFieldList; QueryOptions queryOptions = new QueryOptions(1000, 1); queryOptions.SearchOptions = searchOptions; QueryResponse queryResponse = null; // Get filters for given tableset List <Quest.Functional.MasterPricing.Filter> filterList = null; FiltersMgr filtersMgr = new FiltersMgr(this.UserSession); status = filtersMgr.List(queryOptions, out filterList, out queryResponse); if (!questStatusDef.IsSuccess(status)) { return(status); } // Sort filterList.Sort(delegate(Quest.Functional.MasterPricing.Filter i1, Quest.Functional.MasterPricing.Filter i2) { return(i1.Name.CompareTo(i2.Name)); }); // Build options // Set selected if specified. optionsList = new List <OptionValuePair>(); foreach (Quest.Functional.MasterPricing.Filter filter in filterList) { OptionValuePair optionValuePair = new OptionValuePair(); optionValuePair.Id = filter.Id.ToString(); optionValuePair.Label = filter.Name; if (Value != null && Value == filter.Id.ToString()) { optionValuePair.bSelected = true; } else if (Name != null && Name == filter.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 *=================================================================================================================================*/ public questStatus Save(FilterPanelViewModel filterPanelViewModel) { // Initialize questStatus status = null; Quest.Functional.MasterPricing.Filter filter = null; FilterId filterId = null; // Validate if (filterPanelViewModel.Editor.TablesetId < BaseId.VALID_ID) { return(new questStatus(Severity.Error, "Invalid Tableset Id")); } if (filterPanelViewModel.Editor.FilterId < BaseId.VALID_ID) { // For headless agents that want to save all-in-one, not via the Filters panel. filter = new Functional.MasterPricing.Filter(); BufferMgr.TransferBuffer(filterPanelViewModel.Editor, filter); filterId = null; FiltersMgr filtersMgr = new FiltersMgr(this.UserSession); status = filtersMgr.Create(filter, out filterId); if (!questStatusDef.IsSuccess(status)) { return(status); } filterPanelViewModel.Editor.Id = filterId.Id; filterPanelViewModel.Editor.FilterId = filterId.Id; } // Read tableset configuration TablesetId tablesetId = new TablesetId(filterPanelViewModel.Editor.TablesetId); TablesetDataManagement tablesetDataManagement = null; TablesetMgr tablesetMgr = new TablesetMgr(this.UserSession); status = tablesetMgr.ReadTablesetDataManagement(tablesetId, out tablesetDataManagement); if (!questStatusDef.IsSuccess(status)) { return(status); } #region Transfer filter entities // // Transfer filter entities // filter = new Functional.MasterPricing.Filter(); filter.TablesetId = filterPanelViewModel.Editor.TablesetId; filter.Id = filterPanelViewModel.Editor.Id; foreach (BootstrapTreenodeViewModel filterEntity in filterPanelViewModel.Entities) { if (filterEntity.type == "table") { FilterTable filterTable = new FilterTable(); filterTable.FilterId = filterPanelViewModel.Editor.Id; filterTable.Schema = filterEntity.Schema; filterTable.Name = filterEntity.Name; filter.FilterTableList.Add(filterTable); } else if (filterEntity.type == "view") { FilterView filterView = new FilterView(); filterView.FilterId = filterPanelViewModel.Editor.Id; filterView.Schema = filterEntity.Schema; filterView.Name = filterEntity.Name; filter.FilterViewList.Add(filterView); } else if (filterEntity.type == "column") { FilterColumn filterColumn = new FilterColumn(); filterColumn.FilterId = filterPanelViewModel.Editor.Id; filterColumn.Name = filterEntity.Name; filterColumn.TablesetEntityId = filterEntity.ParentId; if (filterEntity.parentType == "table") { TablesetTable parentTablesetTable = tablesetDataManagement.TablesetConfiguration.TablesetTables.Find(delegate(TablesetTable tt) { return(tt.Id == filterEntity.ParentId); }); if (parentTablesetTable == null) { return(new questStatus(Severity.Error, String.Format("ERROR: column filter entity \"{0}\" (Id {1}) table parent Id {2} not found.", filterEntity.text, filterEntity.Id, filterEntity.ParentId))); } filterColumn.FilterEntityTypeId = FilterEntityType.Table; // If column table not in filter entities, add it. BootstrapTreenodeViewModel filterColumnTable = filterPanelViewModel.Entities.Find(delegate(BootstrapTreenodeViewModel n) { return(n.type == "table" && n.Id == filterEntity.ParentId); }); if (filterColumnTable == null) { FilterTable filterTable = filter.FilterTableList.Find(delegate(FilterTable t) { return(filterEntity.ParentId == t.TablesetTable.Id); }); if (filterTable == null) { filterTable = new FilterTable(); filterTable.FilterId = filterPanelViewModel.Editor.Id; filterTable.TablesetTable = parentTablesetTable; filterTable.Schema = parentTablesetTable.Schema; filterTable.Name = parentTablesetTable.Name; filter.FilterTableList.Add(filterTable); } } } else if (filterEntity.parentType == "view") { TablesetView parentTablesetView = tablesetDataManagement.TablesetConfiguration.TablesetViews.Find(delegate(TablesetView tv) { return(tv.Id == filterEntity.ParentId); }); if (parentTablesetView == null) { return(new questStatus(Severity.Error, String.Format("ERROR: column filter entity \"{0}\" (Id {1}) view parent Id {2} not found.", filterEntity.text, filterEntity.Id, filterEntity.ParentId))); } filterColumn.FilterEntityTypeId = FilterEntityType.View; // If column view not in filter entities, add it. BootstrapTreenodeViewModel filterColumnView = filterPanelViewModel.Entities.Find(delegate(BootstrapTreenodeViewModel n) { return(n.type == "view" && n.Id == filterEntity.ParentId); }); if (filterColumnView == null) { FilterView filterView = filter.FilterViewList.Find(delegate(FilterView v) { return(filterEntity.ParentId == v.TablesetView.Id); }); if (filterView == null) { filterView = new FilterView(); filterView.FilterId = filterPanelViewModel.Editor.Id; filterView.TablesetView = parentTablesetView; filterView.Schema = parentTablesetView.Schema; filterView.Name = parentTablesetView.Name; filter.FilterViewList.Add(filterView); } } } else { return(new questStatus(Severity.Error, String.Format("ERROR: column filter entity \"{0}\" (Id {1}) unknown parent parent type: {2}", filterEntity.text, filterEntity.Id, filterEntity.ParentId, (filterEntity.parentType == null ? "null" : filterEntity.parentType)))); } filter.FilterColumnList.Add(filterColumn); } else { return(new questStatus(Severity.Error, String.Format("Invalid filter entity type: {0}", filterEntity.type))); } } #endregion #region Transfer filter items // // Transfer filter items // foreach (FilterItemViewModel filterItemViewModel in filterPanelViewModel.Items) { // Filter Item FilterItem filterItem = new FilterItem(); filterItem.FilterId = filterPanelViewModel.Editor.FilterId; if (filterItemViewModel.Entity.type == "table") { filterItem.FilterEntityTypeId = FilterEntityType.Table; } if (filterItemViewModel.Entity.type == "view") { filterItem.FilterEntityTypeId = FilterEntityType.View; } else if (filterItemViewModel.Entity.type == "column") { filterItem.FilterEntityTypeId = FilterEntityType.Column; } filterItem.TablesetColumnId = filterItemViewModel.Entity.Id; filterItem.Label = filterItemViewModel.Label; filterItem.ParameterName = filterItemViewModel.ParameterName; filterItem.bHidden = filterItemViewModel.bHidden; filterItem.bBulkUpdateValueRequired = filterItemViewModel.bBulkUpdateValueRequired; // Joins foreach (FilterItemJoinViewModel filterItemJoinViewModel in filterItemViewModel.Joins) { FilterItemJoin filterItemJoin = new FilterItemJoin(); filterItemJoin.ColumnId = filterItemJoinViewModel.ColumnId; filterItemJoin.JoinType = filterItemJoinViewModel.JoinType; filterItemJoin.Identifier = filterItemJoinViewModel.Identifier; filterItem.JoinList.Add(filterItemJoin); } // Operations foreach (FilterOperationViewModel filterOperationViewModel in filterItemViewModel.Operations) { FilterOperation filterOperation = new FilterOperation(); filterOperation.FilterOperatorId = filterOperationViewModel.Operator; // Values foreach (FilterValueViewModel filterValueViewModel in filterOperationViewModel.Values) { FilterValue filterValue = new FilterValue(); filterValue.Value = filterValueViewModel.Value; filterOperation.ValueList.Add(filterValue); } filterItem.OperationList.Add(filterOperation); } // Lookup if (filterItemViewModel.Lookup.Id >= BaseId.VALID_ID) { filterItem.LookupId = filterItemViewModel.Lookup.Id; } // TypeList if (filterItemViewModel.TypeList.Id >= BaseId.VALID_ID) { filterItem.TypeListId = filterItemViewModel.TypeList.Id; } filter.FilterItemList.Add(filterItem); } #endregion #region Transfer filter procedures // // Transfer filter procedures // foreach (FilterProcedureViewModel filterProcedureViewModel in filterPanelViewModel.Procedures) { if (filterProcedureViewModel.Id > BaseId.INVALID_ID) { FilterProcedure filterProcedure = new FilterProcedure(); BufferMgr.TransferBuffer(filterProcedureViewModel, filterProcedure); filterProcedure.FilterId = filterPanelViewModel.Editor.FilterId; filter.FilterProcedureList.Add(filterProcedure); } } #endregion #region Save filter // // Save filter // filterId = new FilterId(filterPanelViewModel.Editor.FilterId); FilterMgr filterMgr = new FilterMgr(this.UserSession); status = filterMgr.Save(filterId, filter); if (!questStatusDef.IsSuccess(status)) { if (questStatusDef.IsWarning(status)) { return(status); } return(new questStatus(status.Severity, String.Format("Error saving filter items: {0}", status.Message))); } #endregion #region Return procedure parameters // // Return procedure parameters // // Get filter database Quest.Functional.MasterPricing.Database database = null; filterMgr.GetFilterDatabase(filterId, out database); if (filter.FilterProcedureList.Count > 0) { foreach (FilterProcedureViewModel filterProcedureViewModel in filterPanelViewModel.Procedures) { if ((filterProcedureViewModel.Id == BaseId.INVALID_ID) || (string.IsNullOrEmpty(filterProcedureViewModel.Name))) { continue; } // Get procedure parameters List <Quest.Functional.MasterPricing.FilterProcedureParameter> filterProcedureParameterList = null; status = filterMgr.GetStoredProdecureParameters(database, filterProcedureViewModel.Name, out filterProcedureParameterList); if (!questStatusDef.IsSuccess(status)) { return(status); } foreach (FilterProcedureParameter filterProcedureParameter in filterProcedureParameterList) { FilterProcedureParameterViewModel filterProcedureParameterViewModel = new FilterProcedureParameterViewModel(); BufferMgr.TransferBuffer(filterProcedureParameter, filterProcedureParameterViewModel, true); filterProcedureParameterViewModel.Precision = filterProcedureParameter.Precision[0]; filterProcedureParameterViewModel.Scale = filterProcedureParameter.Scale[0]; filterProcedureViewModel.Parameters.Add(filterProcedureParameterViewModel); } } } #endregion // Return warning if no items in filter. if (filter.FilterItemList.Count == 0) { return(new questStatus(Severity.Warning, "Filter successfully saved, but has no items")); } return(new questStatus(Severity.Success)); }