private TransactionType DataPortal_Fetch(TransactionTypeCriteria criteria)
        {
            bool cancel = false;

            OnFetching(criteria, ref cancel);
            if (cancel)
            {
                return(null);
            }
            using (var connection = new SqlConnection(ADOHelper.ConnectionString))
            {
                connection.Open();
                using (var command = new SqlCommand("[dbo].[spCFM_TransactionType_Select]", connection))
                {
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag));
                    command.Parameters.AddWithValue("@p_UpdatedByHasValue", criteria.UpdatedByHasValue);
                    command.Parameters.AddWithValue("@p_UpdatedOnHasValue", criteria.UpdatedOnHasValue);
                    using (var reader = command.ExecuteReader())
                    {
                        var rowParser = reader.GetRowParser <TransactionType>();
                        if (reader.Read())
                        {
                            return(GetTransactionType(rowParser, reader));
                        }
                        else
                        {
                            throw new Exception(String.Format("The record was not found in 'dbo.TransactionType' using the following criteria: {0}.", criteria));
                        }
                    }
                }
            }
            OnFetched();
        }
        //[Transactional(TransactionalTypes.TransactionScope)]
        protected void DataPortal_Delete(TransactionTypeCriteria 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].[spCFM_TransactionType_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();
        }
        public static void DeleteTransactionType(System.Int32 transactionTypeID)
        {
            var criteria = new TransactionTypeCriteria {
                TransactionTypeID = transactionTypeID
            };


            new TransactionType().DataPortal_Delete(criteria);
        }
예제 #4
0
        /// <summary>
        /// Returns a <see cref="TransactionTypeList"/> object of the specified criteria.
        /// </summary>
        /// <param name="transactionTypeID">No additional detail available.</param>
        /// <returns>A <see cref="TransactionTypeList"/> object of the specified criteria.</returns>
        public static TransactionTypeList GetByTransactionTypeID(System.Int32 transactionTypeID)
        {
            var criteria = new TransactionTypeCriteria {
                TransactionTypeID = transactionTypeID
            };


            return(new TransactionTypeList().DataPortal_Fetch(criteria));
        }
        /// <summary>
        /// CodeSmith generated stub method that is called after the child <see cref="TransactionType"/> object with the specified criteria has been deleted.
        /// </summary>
        //partial void OnDeleted();
        //partial void OnChildLoading(Csla.Core.IPropertyInfo childProperty, ref bool cancel);

        #endregion


        #region Exists Command

        /// <summary>
        /// Determines if a record exists in the TransactionType table in the database for the specified criteria.
        /// </summary>
        /// <param name="criteria">The criteria parameter is an <see cref="TransactionType"/> object.</param>
        /// <returns>A boolean value of true is returned if a record is found.</returns>
        public static TransactionType Exists(TransactionTypeCriteria criteria)
        {
            try
            {
                return(new TransactionType().DataPortal_Fetch(criteria));
            }
            catch (Exception ex)
            {
            }
            return(null);
        }
        private TransactionTypeList DataPortal_Fetch(TransactionTypeCriteria criteria)
        {
            bool cancel = false;

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

            //RaiseListChangedEvents = false;

            // Fetch Child objects.
            using (var connection = new SqlConnection(ADOHelper.ConnectionString))
            {
                connection.Open();
                using (var command = new SqlCommand("[dbo].[spCFM_TransactionType_Select]", connection))
                {
                    command.CommandType = CommandType.StoredProcedure;

                    command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag));
                    command.Parameters.AddWithValue("@p_UpdatedByHasValue", criteria.UpdatedByHasValue);
                    command.Parameters.AddWithValue("@p_UpdatedOnHasValue", criteria.UpdatedOnHasValue);
                    using (var reader = command.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            var rowParser = reader.GetRowParser <CFMData.TransactionType>();
                            do
                            {
                                this.Add(CFMData.TransactionType.GetTransactionType(rowParser, reader));
                            }while(reader.Read());
                        }
                        OnFetched();
                        return(this);
                    }
                }
            }

            //RaiseListChangedEvents = true;
        }
        // [Transactional(TransactionalTypes.TransactionScope)]
        protected void DataPortal_Update()
        {
            bool cancel = false;

            OnUpdating(ref cancel);
            if (cancel)
            {
                return;
            }
            if (OriginalTransactionTypeID != TransactionTypeID)
            {
                // Insert new child.
                TransactionType item = new TransactionType {
                    TransactionTypeID = TransactionTypeID, Code = Code, IsActive = IsActive, CreatedBy = CreatedBy, CreatedOn = CreatedOn
                };
                if (UpdatedBy.HasValue)
                {
                    item.UpdatedBy = UpdatedBy.Value;
                }
                if (UpdatedOn.HasValue)
                {
                    item.UpdatedOn = UpdatedOn.Value;
                }
                item.DataPortal_Update();

                // Mark editable child lists as dirty. This code may need to be updated to one-to-one relationships.
                foreach (Gl itemToUpdate in Gls)
                {
                    itemToUpdate.TransactionTypeID = TransactionTypeID;
                }

                // Create a new connection.
                using (var connection = new SqlConnection(ADOHelper.ConnectionString))
                {
                    connection.Open();
                    SqlTransaction trans = connection.BeginTransaction();
                    try
                    {
                        UpdateChildren(this, connection, trans);
                        trans.Commit();
                    }
                    catch (Exception ex)
                    {
                        trans.Rollback();
                        throw;
                    }

                    //FieldManager.UpdateChildren(this, connection);
                }
                // Delete the old.
                var criteria = new TransactionTypeCriteria {
                    TransactionTypeID = OriginalTransactionTypeID
                };

                DataPortal_Delete(criteria);

                // Mark the original as the new one.
                OriginalTransactionTypeID = TransactionTypeID;
                OnUpdated();

                return;
            }

            using (var connection = new SqlConnection(ADOHelper.ConnectionString))
            {
                connection.Open();
                SqlTransaction trans = connection.BeginTransaction();
                try
                {
                    using (var command = new SqlCommand("[dbo].[spCFM_TransactionType_Update]", connection, trans))
                    {
                        command.CommandType = CommandType.StoredProcedure;
                        command.Parameters.AddWithValue("@p_OriginalTransactionTypeID", this.OriginalTransactionTypeID);
                        command.Parameters.AddWithValue("@p_TransactionTypeID", this.TransactionTypeID);
                        command.Parameters.AddWithValue("@p_Code", this.Code);
                        command.Parameters.AddWithValue("@p_IsActive", this.IsActive);
                        command.Parameters.AddWithValue("@p_CreatedBy", this.CreatedBy);
                        command.Parameters.AddWithValue("@p_CreatedOn", this.CreatedOn);
                        command.Parameters.AddWithValue("@p_UpdatedBy", ADOHelper.NullCheck(this.UpdatedBy));
                        command.Parameters.AddWithValue("@p_UpdatedOn", ADOHelper.NullCheck(this.UpdatedOn));
                        //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.");
                        }

                        _originalTransactionTypeIDProperty = this.TransactionTypeID;
                    }
                    UpdateChildren(this, connection, trans);
                    //FieldManager.UpdateChildren(this, connection);
                    trans.Commit();
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    throw;
                }
            }

            OnUpdated();
        }
예제 #8
0
        public static TransactionTypeList GetByCriteria(TransactionTypeCriteria criteria)
        {
            return(new TransactionTypeList().DataPortal_Fetch(criteria));
//            return DataPortal.Fetch<TransactionTypeList>(criteria);
        }
예제 #9
0
 /// <summary>
 /// CodeSmith generated stub method that is called when fetching the child <see cref="TransactionType"/> object.
 /// </summary>
 /// <param name="criteria"><see cref="TransactionTypeCriteria"/> 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(TransactionTypeCriteria criteria, ref bool cancel);
 /// <summary>
 /// CodeSmith generated stub method that is called when deleting the child <see cref="TransactionType"/> object.
 /// </summary>
 /// <param name="criteria"><see cref="TransactionTypeCriteria"/> 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(TransactionTypeCriteria criteria, ref bool cancel);
 /// <summary>
 /// CodeSmith generated stub method that is called when deleting the child <see cref="TransactionType"/> object.
 /// </summary>
 /// <param name="criteria"><see cref="TransactionTypeCriteria"/> object containing the criteria of the object to delete.</param>
 /// <param name="connection"></param>
 /// <param name="cancel">Value returned from the method indicating whether the object deletion should proceed.</param>
 partial void OnDeleting(TransactionTypeCriteria criteria, SqlConnection connection, ref bool cancel);
 /// <summary>
 /// CodeSmith generated stub method that is called when deleting the <see cref="TransactionType"/> object.
 /// </summary>
 /// <param name="criteria"><see cref="TransactionTypeCriteria"/> 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(TransactionTypeCriteria criteria, ref bool cancel);