//[Transactional(TransactionalTypes.TransactionScope)]
        protected void DataPortal_Delete(GlCriteria 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_Gl_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>
        /// Returns a <see cref="GlList"/> object of the specified criteria.
        /// </summary>
        /// <param name="transactionTypeID">No additional detail available.</param>
        /// <returns>A <see cref="GlList"/> object of the specified criteria.</returns>
        public static GlList GetByTransactionTypeID(System.Int32 transactionTypeID)
        {
            var criteria = new GlCriteria {
                TransactionTypeID = transactionTypeID
            };


            return(new GlList().DataPortal_Fetch(criteria));
        }
        /// <summary>
        /// Returns a <see cref="GlList"/> object of the specified criteria.
        /// </summary>
        /// <param name="createdBy">No additional detail available.</param>
        /// <returns>A <see cref="GlList"/> object of the specified criteria.</returns>
        public static GlList GetByCreatedBy(System.Int32 createdBy)
        {
            var criteria = new GlCriteria {
                CreatedBy = createdBy
            };


            return(new GlList().DataPortal_Fetch(criteria));
        }
        public static void DeleteGl(System.Int32 glid)
        {
            var criteria = new GlCriteria {
                Glid = glid
            };


            new Gl().DataPortal_Delete(criteria);
        }
        /// <summary>
        /// Returns a <see cref="GlList"/> object of the specified criteria.
        /// </summary>
        /// <param name="glid">No additional detail available.</param>
        /// <returns>A <see cref="GlList"/> object of the specified criteria.</returns>
        public static GlList GetByGlid(System.Int32 glid)
        {
            var criteria = new GlCriteria {
                Glid = glid
            };


            return(new GlList().DataPortal_Fetch(criteria));
        }
        /// <summary>
        /// CodeSmith generated stub method that is called after the child <see cref="Gl"/> 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 GL table in the database for the specified criteria.
        /// </summary>
        /// <param name="criteria">The criteria parameter is an <see cref="Gl"/> object.</param>
        /// <returns>A boolean value of true is returned if a record is found.</returns>
        public static Gl Exists(GlCriteria criteria)
        {
            try
            {
                return(new Gl().DataPortal_Fetch(criteria));
            }
            catch (Exception ex)
            {
            }
            return(null);
        }
        /// <summary>
        /// Returns a <see cref="GlList"/> object of the specified criteria.
        /// </summary>
        /// <param name="bankTransactionID">No additional detail available.</param>
        /// <returns>A <see cref="GlList"/> object of the specified criteria.</returns>
        public static GlList GetByBankTransactionID(System.Int32?bankTransactionID)
        {
            var criteria = new GlCriteria {
            };

            if (bankTransactionID.HasValue)
            {
                criteria.BankTransactionID = bankTransactionID.Value;
            }

            return(new GlList().DataPortal_Fetch(criteria));
        }
        /// <summary>
        /// Returns a <see cref="GlList"/> object of the specified criteria.
        /// </summary>
        /// <param name="updatedBy">No additional detail available.</param>
        /// <returns>A <see cref="GlList"/> object of the specified criteria.</returns>
        public static GlList GetByUpdatedBy(System.Int32?updatedBy)
        {
            var criteria = new GlCriteria {
            };

            if (updatedBy.HasValue)
            {
                criteria.UpdatedBy = updatedBy.Value;
            }

            return(new GlList().DataPortal_Fetch(criteria));
        }
        /// <summary>
        /// Returns a <see cref="GlList"/> object of the specified criteria.
        /// </summary>
        /// <param name="gLCostCentreEntityID">No additional detail available.</param>
        /// <returns>A <see cref="GlList"/> object of the specified criteria.</returns>
        public static GlList GetByGLCostCentreEntityID(System.Int32?gLCostCentreEntityID)
        {
            var criteria = new GlCriteria {
            };

            if (gLCostCentreEntityID.HasValue)
            {
                criteria.GLCostCentreEntityID = gLCostCentreEntityID.Value;
            }

            return(new GlList().DataPortal_Fetch(criteria));
        }
        /// <summary>
        /// Returns a <see cref="GlList"/> object of the specified criteria.
        /// </summary>
        /// <param name="clientBudgetID">No additional detail available.</param>
        /// <returns>A <see cref="GlList"/> object of the specified criteria.</returns>
        public static GlList GetByClientBudgetID(System.Int32?clientBudgetID)
        {
            var criteria = new GlCriteria {
            };

            if (clientBudgetID.HasValue)
            {
                criteria.ClientBudgetID = clientBudgetID.Value;
            }

            return(new GlList().DataPortal_Fetch(criteria));
        }
        /// <summary>
        /// Returns a <see cref="GlList"/> object of the specified criteria.
        /// </summary>
        /// <param name="houseBudgetID">No additional detail available.</param>
        /// <returns>A <see cref="GlList"/> object of the specified criteria.</returns>
        public static GlList GetByHouseBudgetID(System.Int32?houseBudgetID)
        {
            var criteria = new GlCriteria {
            };

            if (houseBudgetID.HasValue)
            {
                criteria.HouseBudgetID = houseBudgetID.Value;
            }

            return(new GlList().DataPortal_Fetch(criteria));
        }
        private GlList DataPortal_Fetch(GlCriteria 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_Gl_Select]", connection))
                {
                    command.CommandType = CommandType.StoredProcedure;

                    command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag));
                    command.Parameters.AddWithValue("@p_PostingDateHasValue", criteria.PostingDateHasValue);
                    command.Parameters.AddWithValue("@p_GLCostCentreEntityIDHasValue", criteria.GLCostCentreEntityIDHasValue);
                    command.Parameters.AddWithValue("@p_BankTransactionIDHasValue", criteria.BankTransactionIDHasValue);
                    command.Parameters.AddWithValue("@p_CategoryIDHasValue", criteria.CategoryIDHasValue);
                    command.Parameters.AddWithValue("@p_ExGstAMountHasValue", criteria.ExGstAMountHasValue);
                    command.Parameters.AddWithValue("@p_GSTAmountHasValue", criteria.GSTAmountHasValue);
                    command.Parameters.AddWithValue("@p_DRAmountHasValue", criteria.DRAmountHasValue);
                    command.Parameters.AddWithValue("@p_CRAmountHasValue", criteria.CRAmountHasValue);
                    command.Parameters.AddWithValue("@p_HouseBudgetIDHasValue", criteria.HouseBudgetIDHasValue);
                    command.Parameters.AddWithValue("@p_ClientBudgetIDHasValue", criteria.ClientBudgetIDHasValue);
                    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.Gl>();
                            do
                            {
                                this.Add(CFMData.Gl.GetGl(rowParser, reader));
                            }while(reader.Read());
                        }
                        OnFetched();
                        return(this);
                    }
                }
            }

            //RaiseListChangedEvents = true;
        }
        private Gl DataPortal_Fetch(GlCriteria 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_Gl_Select]", connection))
                {
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag));
                    command.Parameters.AddWithValue("@p_PostingDateHasValue", criteria.PostingDateHasValue);
                    command.Parameters.AddWithValue("@p_GLCostCentreEntityIDHasValue", criteria.GLCostCentreEntityIDHasValue);
                    command.Parameters.AddWithValue("@p_BankTransactionIDHasValue", criteria.BankTransactionIDHasValue);
                    command.Parameters.AddWithValue("@p_CategoryIDHasValue", criteria.CategoryIDHasValue);
                    command.Parameters.AddWithValue("@p_ExGstAMountHasValue", criteria.ExGstAMountHasValue);
                    command.Parameters.AddWithValue("@p_GSTAmountHasValue", criteria.GSTAmountHasValue);
                    command.Parameters.AddWithValue("@p_DRAmountHasValue", criteria.DRAmountHasValue);
                    command.Parameters.AddWithValue("@p_CRAmountHasValue", criteria.CRAmountHasValue);
                    command.Parameters.AddWithValue("@p_HouseBudgetIDHasValue", criteria.HouseBudgetIDHasValue);
                    command.Parameters.AddWithValue("@p_ClientBudgetIDHasValue", criteria.ClientBudgetIDHasValue);
                    command.Parameters.AddWithValue("@p_UpdatedByHasValue", criteria.UpdatedByHasValue);
                    command.Parameters.AddWithValue("@p_UpdatedOnHasValue", criteria.UpdatedOnHasValue);
                    using (var reader = command.ExecuteReader())
                    {
                        var rowParser = reader.GetRowParser <Gl>();
                        if (reader.Read())
                        {
                            return(GetGl(rowParser, reader));
                        }
                        else
                        {
                            throw new Exception(String.Format("The record was not found in 'dbo.GL' using the following criteria: {0}.", criteria));
                        }
                    }
                }
            }
            OnFetched();
        }
 /// <summary>
 /// CodeSmith generated stub method that is called when fetching the child <see cref="Gl"/> object.
 /// </summary>
 /// <param name="criteria"><see cref="GlCriteria"/> 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(GlCriteria criteria, ref bool cancel);
        public static GlList GetByCriteria(GlCriteria criteria)
        {
            return(new GlList().DataPortal_Fetch(criteria));
//            return DataPortal.Fetch<GlList>(criteria);
        }
 /// <summary>
 /// CodeSmith generated stub method that is called when deleting the child <see cref="Gl"/> object.
 /// </summary>
 /// <param name="criteria"><see cref="GlCriteria"/> 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(GlCriteria criteria, ref bool cancel);
 /// <summary>
 /// CodeSmith generated stub method that is called when deleting the child <see cref="Gl"/> object.
 /// </summary>
 /// <param name="criteria"><see cref="GlCriteria"/> 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(GlCriteria criteria, SqlConnection connection, ref bool cancel);
 /// <summary>
 /// CodeSmith generated stub method that is called when deleting the <see cref="Gl"/> object.
 /// </summary>
 /// <param name="criteria"><see cref="GlCriteria"/> 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(GlCriteria criteria, ref bool cancel);