private void DataPortal_Fetch(CategoryCriteria criteria) { bool cancel = false; OnFetching(criteria, ref cancel); if (cancel) { return; } using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand("[dbo].[CSLA_Category_Select]", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag)); command.Parameters.AddWithValue("@p_NameHasValue", criteria.NameHasValue); command.Parameters.AddWithValue("@p_DescnHasValue", criteria.DescriptionHasValue); using (var reader = new SafeDataReader(command.ExecuteReader())) { if (reader.Read()) { Map(reader); } else { throw new Exception(String.Format("The record was not found in 'dbo.Category' using the following criteria: {0}.", criteria)); } } } } OnFetched(); }
protected void DataPortal_Delete(SupplierCriteria criteria) { bool cancel = false; OnDeleting(criteria, ref cancel); if (cancel) { return; } using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand("[dbo].[CSLA_Supplier_Delete]", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag)); //result: The number of rows changed, inserted, or deleted. -1 for select statements; 0 if no rows were affected, or the statement failed. int result = command.ExecuteNonQuery(); if (result == 0) { throw new DBConcurrencyException("The entity is out of date on the client. Please update the entity and try again. This could also be thrown if the sql statement failed to execute."); } } } OnDeleted(); }
/// <summary> /// Retrieves data from the data base into a CSLA editable child business object of type <see cref="OrderStatus"/> /// using the criteria provided. /// </summary> /// <param name="criteria">Object of type <see cref="OrderStatusCriteria"/></param> /// <returns></returns> private void Child_Fetch(OrderStatusCriteria criteria) { bool cancel = false; OnChildFetching(criteria, ref cancel); if (cancel) { return; } using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand("[dbo].[CSLA_OrderStatus_Select]", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag)); using (var reader = new SafeDataReader(command.ExecuteReader())) { if (reader.Read()) { Map(reader); } else { throw new Exception(String.Format("The record was not found in 'dbo.OrderStatus' using the following criteria: {0}.", criteria)); } } } } OnChildFetched(); }
protected override void DataPortal_Execute() { string commandText = string.Format("SELECT COUNT(1) FROM {0} {1}", Criteria.TableFullName, ADOHelper.BuildWhereStatement(Criteria.StateBag)); using (SqlConnection connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (SqlCommand command = new SqlCommand(commandText, connection)) { command.Parameters.AddRange(ADOHelper.SqlParameters(Criteria.StateBag)); Result = (int)command.ExecuteScalar() > 0; } } }
private void Child_Fetch(SupplierCriteria criteria) { bool cancel = false; OnFetching(criteria, ref cancel); if (cancel) { return; } RaiseListChangedEvents = false; // Fetch Child objects. using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand("[dbo].[CSLA_Supplier_Select]", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag)); command.Parameters.AddWithValue("@p_NameHasValue", criteria.NameHasValue); command.Parameters.AddWithValue("@p_Addr1HasValue", criteria.Addr1HasValue); command.Parameters.AddWithValue("@p_Addr2HasValue", criteria.Addr2HasValue); command.Parameters.AddWithValue("@p_CityHasValue", criteria.CityHasValue); command.Parameters.AddWithValue("@p_StateHasValue", criteria.StateHasValue); command.Parameters.AddWithValue("@p_ZipHasValue", criteria.ZipHasValue); command.Parameters.AddWithValue("@p_PhoneHasValue", criteria.PhoneHasValue); using (var reader = new SafeDataReader(command.ExecuteReader())) { if (reader.Read()) { do { this.Add(PetShop.Tests.StoredProcedures.Supplier.GetSupplier(reader)); } while(reader.Read()); } } } } RaiseListChangedEvents = true; OnFetched(); }
private void Child_Fetch(ItemCriteria criteria) { bool cancel = false; OnChildFetching(criteria, ref cancel); if (cancel) { return; } using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand("[dbo].[CSLA_Item_Select]", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag)); command.Parameters.AddWithValue("@p_ListPriceHasValue", criteria.ListPriceHasValue); command.Parameters.AddWithValue("@p_UnitCostHasValue", criteria.UnitCostHasValue); command.Parameters.AddWithValue("@p_SupplierHasValue", criteria.SupplierHasValue); command.Parameters.AddWithValue("@p_StatusHasValue", criteria.StatusHasValue); command.Parameters.AddWithValue("@p_NameHasValue", criteria.NameHasValue); command.Parameters.AddWithValue("@p_ImageHasValue", criteria.ImageHasValue); using (var reader = new SafeDataReader(command.ExecuteReader())) { if (reader.Read()) { Map(reader); } else { throw new Exception(String.Format("The record was not found in 'dbo.Item' using the following criteria: {0}.", criteria)); } } } } OnChildFetched(); MarkAsChild(); }
private void DataPortal_Fetch(CategoryCriteria criteria) { bool cancel = false; OnFetching(criteria, ref cancel); if (cancel) { return; } RaiseListChangedEvents = false; // Fetch Child objects. using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand("[dbo].[CSLA_Category_Select]", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag)); command.Parameters.AddWithValue("@p_NameHasValue", criteria.NameHasValue); command.Parameters.AddWithValue("@p_DescnHasValue", criteria.DescriptionHasValue); using (var reader = new SafeDataReader(command.ExecuteReader())) { if (reader.Read()) { do { this.Add(PetShop.Tests.StoredProcedures.Category.GetCategory(reader)); } while(reader.Read()); } } } } RaiseListChangedEvents = true; OnFetched(); }