protected void DataPortal_Fetch(SupplierCriteria criteria)
        {
            bool cancel = false;

            OnFetching(criteria, ref cancel);
            if (cancel)
            {
                return;
            }

            string commandText = String.Format("SELECT [SuppId], [Name], [Status], [Addr1], [Addr2], [City], [State], [Zip], [Phone] FROM [dbo].[Supplier] {0}", ADOHelper.BuildWhereStatement(criteria.StateBag));

            using (var connection = new SqlConnection(ADOHelper.ConnectionString))
            {
                connection.Open();
                using (var command = new SqlCommand(commandText, connection))
                {
                    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.Supplier' using the following criteria: {0}.", criteria));
                        }
                    }
                }
            }

            OnFetched();
        }
        protected void DataPortal_Delete(SupplierCriteria criteria)
        {
            bool cancel = false;

            OnDeleting(criteria, ref cancel);
            if (cancel)
            {
                return;
            }

            string commandText = String.Format("DELETE FROM [dbo].[Supplier] {0}", ADOHelper.BuildWhereStatement(criteria.StateBag));

            using (var connection = new SqlConnection(ADOHelper.ConnectionString))
            {
                connection.Open();
                using (var command = new SqlCommand(commandText, connection))
                {
                    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();
        }
예제 #3
0
        public static async Task DeleteSupplierAsync(System.Int32 suppId)
        {
            var criteria = new SupplierCriteria {
                SuppId = suppId
            };


            await DataPortal.DeleteAsync <Supplier>(criteria);
        }
예제 #4
0
        public static async Task <Supplier> GetBySuppIdAsync(System.Int32 suppId)
        {
            var criteria = new SupplierCriteria {
                SuppId = suppId
            };


            return(await DataPortal.FetchAsync <Supplier>(criteria));
        }
예제 #5
0
        /// <summary>
        /// Returns a <see cref="Supplier"/> object of the specified criteria.
        /// </summary>
        /// <param name="suppId">No additional detail available.</param>
        /// <returns>A <see cref="Supplier"/> object of the specified criteria.</returns>
        public static Supplier GetBySuppId(System.Int32 suppId)
        {
            var criteria = new SupplierCriteria {
                SuppId = suppId
            };


            return(DataPortal.Fetch <Supplier>(criteria));
        }
예제 #6
0
        public static void DeleteSupplier(System.Int32 suppId)
        {
            var criteria = new SupplierCriteria {
                SuppId = suppId
            };


            DataPortal.Delete <Supplier>(criteria);
        }
        internal static async Task <SupplierList> GetBySuppIdAsync(System.Int32 suppId)
        {
            var criteria = new SupplierCriteria {
                SuppId = suppId
            };


            return(await DataPortal.FetchAsync <AsyncChildLoader <SupplierList> >(criteria).ContinueWith(t => t.Result.Child));
        }
        /// <summary>
        /// Returns a <see cref="SupplierList"/> object of the specified criteria.
        /// </summary>
        /// <param name="suppId">No additional detail available.</param>
        /// <returns>A <see cref="SupplierList"/> object of the specified criteria.</returns>
        internal static SupplierList GetBySuppId(System.Int32 suppId)
        {
            var criteria = new SupplierCriteria {
                SuppId = suppId
            };


            return(DataPortal.FetchChild <SupplierList>(criteria));
        }
        private void Child_Fetch(SupplierCriteria criteria)
        {
            bool cancel = false;

            OnFetching(criteria, ref cancel);
            if (cancel)
            {
                return;
            }

            RaiseListChangedEvents = false;

            // Fetch Child objects.
            string commandText = String.Format("SELECT [SuppId], [Name], [Status], [Addr1], [Addr2], [City], [State], [Zip], [Phone] FROM [dbo].[Supplier] {0}", ADOHelper.BuildWhereStatement(criteria.StateBag));

            using (var connection = new SqlConnection(ADOHelper.ConnectionString))
            {
                connection.Open();
                using (var command = new SqlCommand(commandText, connection))
                {
                    command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag));

                    using (var reader = new SafeDataReader(command.ExecuteReader()))
                    {
                        if (reader.Read())
                        {
                            do
                            {
                                this.Add(PetShop.Business.Supplier.GetSupplier(reader));
                            } while(reader.Read());
                        }
                    }
                }
            }

            RaiseListChangedEvents = true;

            OnFetched();
        }
 internal static async Task <SupplierList> GetByCriteriaAsync(SupplierCriteria criteria)
 {
     return(await DataPortal.FetchAsync <AsyncChildLoader <SupplierList> >(criteria).ContinueWith(t => t.Result.Child));
 }
 internal static SupplierList GetByCriteria(SupplierCriteria criteria)
 {
     return(DataPortal.Fetch <SupplierList>(criteria));
 }
 /// <summary>
 /// Determines if a record exists in the Supplier in the database for the specified criteria.
 /// </summary>
 public static async Task <bool> ExistsAsync(SupplierCriteria criteria)
 {
     return(await PetShop.Business.ExistsCommand.ExecuteAsync(criteria));
 }
 /// <summary>
 /// Determines if a record exists in the Supplier in the database for the specified criteria.
 /// </summary>
 /// <param name="criteria">The criteria parameter is a <see cref="SupplierList"/> object.</param>
 /// <returns>A boolean value of true is returned if a record is found.</returns>
 public static bool Exists(SupplierCriteria criteria)
 {
     return(PetShop.Business.Supplier.Exists(criteria));
 }
 /// <summary>
 /// CodeSmith generated stub method that is called when fetching the child <see cref="Supplier"/> object.
 /// </summary>
 /// <param name="criteria"><see cref="SupplierCriteria"/> object containing the criteria of the object to fetch.</param>
 /// <param name="cancel">Value returned from the method indicating whether the object fetching should proceed.</param>
 partial void OnFetching(SupplierCriteria criteria, ref bool cancel);
예제 #15
0
 /// <summary>
 /// CodeSmith generated stub method that is called when deleting the <see cref="Supplier"/> object.
 /// </summary>
 /// <param name="criteria"><see cref="SupplierCriteria"/> object containing the criteria of the object to delete.</param>
 /// <param name="cancel">Value returned from the method indicating whether the object deletion should proceed.</param>
 partial void OnDeleting(SupplierCriteria criteria, ref bool cancel);
        protected override void DataPortal_Update()
        {
            bool cancel = false;

            OnUpdating(ref cancel);
            if (cancel)
            {
                return;
            }

            if (OriginalSuppId != SuppId)
            {
                // Insert new child.
                Supplier item = new Supplier {
                    SuppId = SuppId, Name = Name, Status = Status, Addr1 = Addr1, Addr2 = Addr2, City = City, State = State, Zip = Zip, Phone = Phone
                };

                item = item.Save();

                // Mark editable child lists as dirty. This code may need to be updated to one-to-one relationships.
                foreach (Item itemToUpdate in Items)
                {
                    itemToUpdate.Supplier = SuppId;
                }

                // Create a new connection.
                using (var connection = new SqlConnection(ADOHelper.ConnectionString))
                {
                    connection.Open();
                    FieldManager.UpdateChildren(this, connection);
                }

                // Delete the old.
                var criteria = new SupplierCriteria {
                    SuppId = OriginalSuppId
                };

                DataPortal_Delete(criteria);

                // Mark the original as the new one.
                OriginalSuppId = SuppId;

                OnUpdated();

                return;
            }

            const string commandText = "UPDATE [dbo].[Supplier] SET [SuppId] = @p_SuppId, [Name] = @p_Name, [Status] = @p_Status, [Addr1] = @p_Addr1, [Addr2] = @p_Addr2, [City] = @p_City, [State] = @p_State, [Zip] = @p_Zip, [Phone] = @p_Phone WHERE [SuppId] = @p_OriginalSuppId; SELECT [SuppId] FROM [dbo].[Supplier] WHERE [SuppId] = @p_OriginalSuppId";

            using (var connection = new SqlConnection(ADOHelper.ConnectionString))
            {
                connection.Open();
                using (var command = new SqlCommand(commandText, connection))
                {
                    command.Parameters.AddWithValue("@p_OriginalSuppId", this.OriginalSuppId);
                    command.Parameters.AddWithValue("@p_SuppId", this.SuppId);
                    command.Parameters.AddWithValue("@p_Name", ADOHelper.NullCheck(this.Name));
                    command.Parameters.AddWithValue("@p_Status", this.Status);
                    command.Parameters.AddWithValue("@p_Addr1", ADOHelper.NullCheck(this.Addr1));
                    command.Parameters.AddWithValue("@p_Addr2", ADOHelper.NullCheck(this.Addr2));
                    command.Parameters.AddWithValue("@p_City", ADOHelper.NullCheck(this.City));
                    command.Parameters.AddWithValue("@p_State", ADOHelper.NullCheck(this.State));
                    command.Parameters.AddWithValue("@p_Zip", ADOHelper.NullCheck(this.Zip));
                    command.Parameters.AddWithValue("@p_Phone", ADOHelper.NullCheck(this.Phone));

                    //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.");
                    }

                    LoadProperty(_originalSuppIdProperty, this.SuppId);
                }

                FieldManager.UpdateChildren(this, connection);
            }

            OnUpdated();
        }
예제 #17
0
 /// <summary>
 /// Determines if a record exists in the Supplier table in the database for the specified criteria.
 /// </summary>
 /// <param name="criteria">The criteria parameter is an <see cref="Supplier"/> object.</param>
 /// <returns>A boolean value of true is returned if a record is found.</returns>
 public static bool Exists(SupplierCriteria criteria)
 {
     return(PetShop.Business.ExistsCommand.Execute(criteria));
 }