示例#1
0
        /// <summary>
        /// Delete registers based on class values informed. MinValues and nulls are skipped.
        /// </summary>
        /// <param name="parCustomerCustomerDemoInfo">Item to delete</param>
        /// <param name="transaction">Transaction context</param>
        /// <param name="errorMessage">Error message</param>
        public virtual void Delete(CustomerCustomerDemoInfo parCustomerCustomerDemoInfo, DbTransaction transaction, out string errorMessage)
        {
            errorMessage = null;
            try
            {
                string        whereClausule = string.Empty;
                var           pks           = GetPrimaryKey();
                List <string> primaryKeys   = new List <string>();
                foreach (var item in pks)
                {
                    primaryKeys.Add(item.Key);
                }

                List <DbParameter> paramList = ParameterBuilder.GetParametersForDelete(primaryKeys, typeof(CustomerCustomerDemoInfo), parCustomerCustomerDemoInfo, motor.Command, out whereClausule);

                motor.CommandText = GetDeleteCommand() + " " + whereClausule;
                motor.ClearCommandParameters();
                motor.AddCommandParameters(paramList);
                motor.AddTransaction(transaction);
                motor.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message;
            }
        }
示例#2
0
        /// <summary>
        /// Performs one "select * from MyTable where [InformedProperties]". MinValues and nulls are skipped from filter.
        /// </summary>
        /// <param name="filter">CustomerCustomerDemoInfo</param>
        /// <returns>List of found records.</returns>
        public virtual List <CustomerCustomerDemoInfo> GetSome(CustomerCustomerDemoInfo filter)
        {
            List <CustomerCustomerDemoInfo> AllInfoList = new List <CustomerCustomerDemoInfo>();
            string             filterWhere = string.Empty;
            List <DbParameter> paramList   = null;

            GenerateWhere(filter, out filterWhere, out paramList);
            motor.ClearCommandParameters();
            motor.AddCommandParameters(paramList);
            motor.CommandText = GetSelectCommand() + " " + filterWhere;
            DbDataReader dbReader    = motor.ExecuteReader();
            ClassFiller  classFiller = new ClassFiller(typeof(CustomerCustomerDemoInfo), dbReader);

            using (dbReader)
            {
                while (dbReader.Read())
                {
                    CustomerCustomerDemoInfo CustomerCustomerDemoInfo = new CustomerCustomerDemoInfo();
                    ///Warning: performance issues with this automation. See method description for details.
                    classFiller.Fill(CustomerCustomerDemoInfo);
                    AllInfoList.Add(CustomerCustomerDemoInfo);
                }
            }
            return(AllInfoList);
        }
示例#3
0
        /// <summary>
        /// Delete registers based on ID informed. Other values are skipped.
        /// </summary>
        /// <param name="parCustomerCustomerDemoInfo">Item to delete</param>
        /// <param name="errorMessage">Error message</param>
        public virtual void DeleteByID(CustomerCustomerDemoInfo parCustomerCustomerDemoInfo, out string errorMessage)
        {
            CustomerCustomerDemoInfo newParam = new CustomerCustomerDemoInfo();

            newParam.CustomerTypeID = parCustomerCustomerDemoInfo.CustomerTypeID;
            this.Delete(newParam, out errorMessage);
        }
示例#4
0
 /// <summary>
 /// Delete registers based on class values informed. MinValues and nulls are skipped.
 /// Must have "MultipleActiveResultSets=True" on connection string.
 /// </summary>
 /// <param name="parCustomerCustomerDemoInfo">Item to delete</param>
 /// <param name="transaction">Transaction context</param>
 /// <param name="errorMessage">Error message</param>
 public virtual void Delete(CustomerCustomerDemoInfo parCustomerCustomerDemoInfo, DbTransaction transaction, out string errorMessage)
 {
     errorMessage = string.Empty;
     CustomerCustomerDemoDAO.Delete(parCustomerCustomerDemoInfo, transaction, out errorMessage);
     //By default, the caller of this method will do the commit.
     //motor.Commit();
     //motor.CloseConnection();
 }
示例#5
0
        public void DeleteData(ModelNotifiedForCustomerCustomerDemo modelNotifiedForCustomerCustomerDemo, out string error)
        {
            CustomerCustomerDemoBsn  bsn    = new CustomerCustomerDemoBsn(wpfConfig);
            CustomerCustomerDemoInfo dbItem = new CustomerCustomerDemoInfo();

            Cloner.CopyAllTo(typeof(ModelNotifiedForCustomerCustomerDemo), modelNotifiedForCustomerCustomerDemo, typeof(CustomerCustomerDemoInfo), dbItem);
            bsn.DeleteByID(dbItem, out error);
        }
示例#6
0
        /// <summary>
        /// Generate the "where" clausule, used for select data using "GetSome" method.
        /// </summary>
        /// <param name="filter">Class used to apply the filter</param>
        /// <param name="whereClausule">Result whith a string that add filter to the select comand</param>
        /// <param name="paramList">Result whith the parameters list</param>
        protected void GenerateWhere(CustomerCustomerDemoInfo filter, out string whereClausule, out List <DbParameter> paramList)
        {
            StringBuilder where = new StringBuilder();
            paramList           = new List <DbParameter>();
            where.Append("where 1=1");

// 1) Adding filter for field CustomerID
            if (filter.CustomerID != null)
            {
                DbParameter param = motor.Command.CreateParameter();
                param.ParameterName = "@param_CustomerID";
                param.Value         = filter.CustomerID;
                paramList.Add(param);
                where.Append(" and CustomerCustomerDemo.CustomerID=@param_CustomerID");
//Hint: use the code below to add a "like" search. Warning: may cause data performance issues.
//param.ParameterName = "@param_CustomerID";
//param.Value = "%" + filter.CustomerID "%";
//paramList.Add(param);
//where.Append(" and CustomerCustomerDemo.CustomerID like @param_CustomerID");
            }

// 2) Adding filter for field CompanyName
            if (filter.FK0_CompanyName != null)
            {
                DbParameter param = motor.Command.CreateParameter();
                param.ParameterName = "@param_FK0_CompanyName";
                param.Value         = filter.FK0_CompanyName;
                paramList.Add(param);
                where.Append(" and FK0_Customers.CompanyName=@param_FK0_CompanyName");
            }
// 3) Adding filter for field CustomerTypeID
            if (filter.CustomerTypeID != null)
            {
                DbParameter param = motor.Command.CreateParameter();
                param.ParameterName = "@param_CustomerTypeID";
                param.Value         = filter.CustomerTypeID;
                paramList.Add(param);
                where.Append(" and CustomerCustomerDemo.CustomerTypeID=@param_CustomerTypeID");
//Hint: use the code below to add a "like" search. Warning: may cause data performance issues.
//param.ParameterName = "@param_CustomerTypeID";
//param.Value = "%" + filter.CustomerTypeID "%";
//paramList.Add(param);
//where.Append(" and CustomerCustomerDemo.CustomerTypeID like @param_CustomerTypeID");
            }

// 4) Adding filter for field CustomerDesc
            if (filter.FK1_CustomerDesc != null)
            {
                DbParameter param = motor.Command.CreateParameter();
                param.ParameterName = "@param_FK1_CustomerDesc";
                param.Value         = filter.FK1_CustomerDesc;
                paramList.Add(param);
                where.Append(" and FK1_CustomerDemographics.CustomerDesc=@param_FK1_CustomerDesc");
            }

            whereClausule = where.ToString();
        }
示例#7
0
        /// <summary>
        /// Performs one "update" database command.
        /// Will commit the transaction and close the connection. Use for independent delete.
        /// </summary>
        /// <param name="CustomerCustomerDemoInfo">Object to update.</param>
        /// <param name="errorMessage">Error message if exception is throwed</param>
        public virtual void UpdateOne(CustomerCustomerDemoInfo parCustomerCustomerDemoInfo, out string errorMessage)
        {
            errorMessage = string.Empty;
            DbTransaction transaction = motor.BeginTransaction();

            this.UpdateOne(parCustomerCustomerDemoInfo, transaction, out errorMessage);
            motor.Commit();
            motor.CloseConnection();
        }
示例#8
0
        public void AddData(ModelNotifiedForCustomerCustomerDemo modelNotifiedForCustomerCustomerDemo, out string error)
        {
            CustomerCustomerDemoBsn  bsn    = new CustomerCustomerDemoBsn(wpfConfig);
            CustomerCustomerDemoInfo dbItem = new CustomerCustomerDemoInfo();

            Cloner.CopyAllTo(typeof(ModelNotifiedForCustomerCustomerDemo), modelNotifiedForCustomerCustomerDemo, typeof(CustomerCustomerDemoInfo), dbItem);
            bsn.InsertOne(dbItem, out error);
            modelNotifiedForCustomerCustomerDemo.NewItem = false;
            Cloner.CopyAllTo(typeof(CustomerCustomerDemoInfo), dbItem, typeof(ModelNotifiedForCustomerCustomerDemo), modelNotifiedForCustomerCustomerDemo);
        }
示例#9
0
        public ModelNotifiedForCustomerCustomerDemo GetCustomerCustomerDemoByID(string CustomerID, string CustomerTypeID, out string error)
        {
            error = null;
            CustomerCustomerDemoBsn              bsn    = new CustomerCustomerDemoBsn(wpfConfig);
            CustomerCustomerDemoInfo             dbItem = bsn.GetValueByID(CustomerID, CustomerTypeID);
            ModelNotifiedForCustomerCustomerDemo item   = new ModelNotifiedForCustomerCustomerDemo();

            Cloner.CopyAllTo(typeof(CustomerCustomerDemoInfo), dbItem, typeof(ModelNotifiedForCustomerCustomerDemo), item);
            return(item);
        }
示例#10
0
        /// <summary>
        /// Delete registers based on class ID informed in transactional context. Other values are skipped.
        /// Must have "MultipleActiveResultSets=True" on connection string.
        /// </summary>
        /// <param name="parCustomerCustomerDemoInfo">Item to delete</param>
        /// <param name="transaction">Transaction context</param>
        /// <param name="errorMessage">Error message</param>
        public virtual void DeleteByID(CustomerCustomerDemoInfo parCustomerCustomerDemoInfo, DbTransaction transaction, out string errorMessage)
        {
            CustomerCustomerDemoInfo newParam = new CustomerCustomerDemoInfo();

            newParam.CustomerTypeID = parCustomerCustomerDemoInfo.CustomerTypeID;
            this.Delete(newParam, transaction, out errorMessage);
            //By default, the caller of this method will do the commit.
            //motor.Commit();
            //motor.CloseConnection();
        }
示例#11
0
        /// <summary>
        /// Retrieves the data using only the primary key ID. Ex.: "Select * from MyTable where id=1"
        /// </summary>
        /// <returns>The class filled if found.</returns>
        public virtual CustomerCustomerDemoInfo GetValueByID(string CustomerID, string CustomerTypeID)
        {
            motor.OpenConnection();
            CustomerCustomerDemoInfo value = CustomerCustomerDemoDAO.GetValueByID(CustomerID, CustomerTypeID);

            if (this.closeConnectionWhenFinish)
            {
                motor.CloseConnection();
            }
            return(value);
        }
示例#12
0
        /// <summary>
        /// Perform one "select" command to database. Filter the data using "filter" class.
        /// </summary>
        /// <param name="filter">Class to use as filter</param>
        /// <returns>List with filtered data</returns>
        public virtual List <CustomerCustomerDemoInfo> GetSome(CustomerCustomerDemoInfo filter)
        {
            motor.OpenConnection();
            List <CustomerCustomerDemoInfo> list = CustomerCustomerDemoDAO.GetSome(filter);

            if (this.closeConnectionWhenFinish)
            {
                motor.CloseConnection();
            }
            return(list);
        }
示例#13
0
 /// <summary>
 /// Performs a "update [FildList] set [FieldList] where id = @id". Must have the ID informed.
 /// </summary>
 /// <param name="parCustomerCustomerDemoInfo">Item to update</param>
 /// <param name="transaction">Transaction context</param>
 /// <param name="errorMessage">Error message</param>
 public virtual void UpdateOne(CustomerCustomerDemoInfo parCustomerCustomerDemoInfo, DbTransaction transaction, out string errorMessage)
 {
     errorMessage = null;
     try
     {
         motor.CommandText = GetUpdateCommand();
         ///Warning: performance issues with this automation. See method description for details.
         List <DbParameter> paramList = ParameterBuilder.GetParametersForUpdate(typeof(CustomerCustomerDemoInfo), parCustomerCustomerDemoInfo, motor.Command);
         motor.ClearCommandParameters();
         motor.AddCommandParameters(paramList);
         motor.AddTransaction(transaction);
         motor.ExecuteNonQuery();
     }
     catch (Exception ex)
     {
         errorMessage = ex.Message;
     }
 }
示例#14
0
        /// <summary>
        /// Use parameters to apply simple filters
        /// </summary>
        /// <param name="filterExpression"></param>
        /// <returns></returns>
        public virtual List <CustomerCustomerDemoInfo> GetAll(List <DataFilterExpressionDB> filterExpression)
        {
            List <CustomerCustomerDemoInfo> AllInfoList = new List <CustomerCustomerDemoInfo>();

            motor.ClearCommandParameters();
            motor.CommandText = GetSelectCommand() + " where 1=1 ";
            List <DbParameter> paramList = new List <DbParameter>();

            string where = "";
            foreach (DataFilterExpressionDB filter in filterExpression)
            {
                DbParameter param = motor.Command.CreateParameter();
                param.ParameterName = "@param_" + filter.FieldName;
                param.Value         = filter.Filter;
                param.DbType        = HelperDBType.GetDBType(typeof(CustomerCustomerDemoInfo), filter.FieldName);
                if (filter.FilterType == DataFilterExpressionDB._FilterType.Equal)
                {
                    param.Value = filter.Filter;
                    where      += string.Format(" and CustomerCustomerDemo.{0} = {1}", filter.FieldName, param.ParameterName);
                }
                else
                {
                    param.Value = "%" + filter.Filter + "%";
                    where      += string.Format(" and CustomerCustomerDemo.{0} like {1}", filter.FieldName, param.ParameterName);
                }
                paramList.Add(param);
            }
            motor.CommandText += where;
            motor.AddCommandParameters(paramList);

            DbDataReader dbReader    = motor.ExecuteReader();
            ClassFiller  classFiller = new ClassFiller(typeof(CustomerCustomerDemoInfo), dbReader);

            using (dbReader)
            {
                while (dbReader.Read())
                {
                    CustomerCustomerDemoInfo classInfo = new CustomerCustomerDemoInfo();
                    classFiller.Fill(classInfo);
                    AllInfoList.Add(classInfo);
                }
            }
            return(AllInfoList);
        }
示例#15
0
        /// <summary>
        /// Performs one "Select * from MyTable". Use wisely.
        /// </summary>
        /// <returns>List of found records.</returns>
        public virtual List <CustomerCustomerDemoInfo> GetAll()
        {
            List <CustomerCustomerDemoInfo> AllInfoList = new List <CustomerCustomerDemoInfo>();

            motor.CommandText = GetSelectCommand();
            DbDataReader dbReader    = motor.ExecuteReader();
            ClassFiller  classFiller = new ClassFiller(typeof(CustomerCustomerDemoInfo), dbReader);

            using (dbReader)
            {
                while (dbReader.Read())
                {
                    CustomerCustomerDemoInfo classInfo = new CustomerCustomerDemoInfo();
                    classFiller.Fill(classInfo);
                    AllInfoList.Add(classInfo);
                }
            }
            return(AllInfoList);
        }
示例#16
0
        /// <summary>
        /// Same as get all but filter the result set
        /// </summary>
        /// <param name="numberOfRowsToSkip">Skip first X rows</param>
        /// <param name="numberOfRows">Like "TOP" in sql server</param>
        /// <returns></returns>
        public List <CustomerCustomerDemoInfo> GetAll(int numberOfRowsToSkip, int numberOfRows)
        {
            List <CustomerCustomerDemoInfo> AllInfoList = new List <CustomerCustomerDemoInfo>();

            motor.CommandText = base.GetFilteredRowNumAndSkipQuery("AttributeLists", "id", numberOfRowsToSkip, numberOfRows);
            DbDataReader dbReader    = motor.ExecuteReader();
            ClassFiller  classFiller = new ClassFiller(typeof(CustomerCustomerDemoInfo), dbReader);

            using (dbReader)
            {
                while (dbReader.Read())
                {
                    CustomerCustomerDemoInfo classInfo = new CustomerCustomerDemoInfo();
                    classFiller.Fill(classInfo);
                    AllInfoList.Add(classInfo);
                }
            }
            return(AllInfoList);
        }
示例#17
0
        /// <summary>
        /// Delete registers based on class values informed. MinValues and nulls are skipped.
        /// </summary>
        /// <param name="parCustomerCustomerDemoInfo">Item to delete</param>
        /// <param name="errorMessage">Error message</param>
        public virtual void Delete(CustomerCustomerDemoInfo parCustomerCustomerDemoInfo, out string errorMessage)
        {
            errorMessage = string.Empty;

            //1) Start the transaction context.
            DbTransaction transaction = motor.BeginTransaction();

            //2) Call the overload of this method, which call the DAO but does not commit.
            this.Delete(parCustomerCustomerDemoInfo, transaction, out errorMessage);

            //3) Commit the transaction.
            motor.Commit();

            //4) Close the conection (if configured to do so).
            if (this.closeConnectionWhenFinish)
            {
                motor.CloseConnection();
            }
        }
示例#18
0
        /// <summary>
        /// Get one register using only ID as key.
        /// </summary>
        /// <returns></returns>
        public virtual CustomerCustomerDemoInfo GetValueByID(string CustomerID, string CustomerTypeID)
        {
            //ToDo: set multiple PK filter
            motor.ClearCommandParameters();
            motor.CommandText = GetSelectCommand() + GetWherePrimaryKey();
            List <DbParameter> paramList = new List <DbParameter>();


            DbParameter paramCustomerID = motor.Command.CreateParameter();

            paramCustomerID.ParameterName = "@param_CustomerID";
            paramCustomerID.Value         = CustomerID;
            paramList.Add(paramCustomerID);


            DbParameter paramCustomerTypeID = motor.Command.CreateParameter();

            paramCustomerTypeID.ParameterName = "@param_CustomerTypeID";
            paramCustomerTypeID.Value         = CustomerTypeID;
            paramList.Add(paramCustomerTypeID);


            motor.AddCommandParameters(paramList);
            CustomerCustomerDemoInfo InfoValue = new CustomerCustomerDemoInfo();

            DbDataReader dbReader    = motor.ExecuteReader();
            ClassFiller  classFiller = new ClassFiller(typeof(CustomerCustomerDemoInfo), dbReader);

            using (dbReader)
            {
                if (dbReader.Read())
                {
                    InfoValue = new CustomerCustomerDemoInfo();
                    classFiller.Fill(InfoValue);
                }
                else
                {
                    return(null);
                }
            }
            return(InfoValue);
        }
示例#19
0
/// <summary>
/// Perform a search to find the class "CustomersInfo" using as key the field "Customers".
/// </summary>
/// <param name="parCustomerCustomerDemoInfo">Main class that contains the aggregation.</param>
/// <returns>Foreing key attched class.</returns>
        public virtual CustomersInfo Get_CustomerIDID_FKCustomers(CustomerCustomerDemoInfo parCustomerCustomerDemoInfo, DbTransaction transaction)
        {
            CustomersInfo filter = new CustomersInfo();

            filter.CompanyName = parCustomerCustomerDemoInfo.FK0_CompanyName;
            CustomersBsn         myClass = new CustomersBsn(false, this.motor);
            List <CustomersInfo> list    = myClass.GetSome(filter);

            if (list.Count == 0)
            {
//This error occurs when try to search for the ID in one table, but it does not find the value.
//Ex.: Select id,SomeField from myTable where SomeField='myValue') If no data return, this error will trigger.
                throw new Exception(string.Format("Can not define ID for parCustomerCustomerDemoInfo.", parCustomerCustomerDemoInfo.FK0_CompanyName));

/* [Hint] The code below do one insert in the table "Customers" informing only the "CustomerID" field.
 * [Warning] The code may crash if other fields are necessary.
 * [Instructions] Comment the exception above. Uncomment the code below.
 */
//string errorMsg = string.Empty;
//myClass.InsertOne(filter, transaction, out errorMsg);
//if (errorMsg != string.Empty)
//{
//throw new Exception(errorMsg);
//}
//else
//{
//return filter;
//}
            }
            if (list.Count > 1)
            {
//This error occurs when try to search for the ID in one table, but it return more then one value.
//Ex.: Select id,SomeField from myTable where SomeField='myValue') If more then one line return, this error will trigger.
                throw new Exception(string.Format("Can not define ID for parCustomerCustomerDemoInfo. Theres more then one ID value for this field. ", parCustomerCustomerDemoInfo.FK0_CompanyName));
            }
            else
            {
//Return the only one class found.
                return(list[0]);
            }
        }
示例#20
0
        public void TryUpdate(UpdateCustomerCustomerDemoView viewToUpdate, out RestExceptionError error)
        {
            error = null;
            CustomerCustomerDemoInfo dbViewToInclude = new CustomerCustomerDemoInfo();

            try
            {
                Cloner.CopyAllTo(typeof(UpdateCustomerCustomerDemoView), viewToUpdate, typeof(CustomerCustomerDemoInfo), dbViewToInclude);
            }
            catch (Exception ex)
            {
                error = new RestExceptionError();
                error.InternalMessage  = "Internal Error parsing data for (CustomerCustomerDemo.TryUpdate/Parsing)";
                error.ExceptionMessage = ex.Message;
                error.SourceError      = RestExceptionError._SourceError.ServerSide;
                error.StackTrace       = ex.StackTrace;
            }

            try
            {
                CustomerCustomerDemoBsn bsn = new CustomerCustomerDemoBsn(restConfig);
                string dbError = null;
                bsn.UpdateOne(dbViewToInclude, out dbError);
                if (dbError != null)
                {
                    error = new RestExceptionError();
                    error.InternalMessage  = "Internal Error Save data for [CustomerCustomerDemo.TryUpdate]";
                    error.ExceptionMessage = dbError;
                    error.SourceError      = RestExceptionError._SourceError.ServerSide;
                    error.StackTrace       = "";
                }
            }
            catch (Exception ex)
            {
                error = new RestExceptionError();
                error.InternalMessage  = "Internal Error Update data for [CustomerCustomerDemo.TryUpdate]";
                error.ExceptionMessage = ex.Message;
                error.SourceError      = RestExceptionError._SourceError.ServerSide;
                error.StackTrace       = ex.StackTrace;
            }
        }
示例#21
0
        /// <summary>
        /// Performs one "update" database command in a transactional context.
        /// * The method uses a transaction object already created and does not close the connection.
        /// * Must have "MultipleActiveResultSets=True" on connection string.
        /// </summary>
        /// <param name="CustomerCustomerDemoInfo">Object to update.</param>
        /// <param name="transaction">Inform "DBTransaction".</param>
        /// <param name="errorMessage">Error message if exception is throwed.</param>
        public virtual void UpdateOne(CustomerCustomerDemoInfo parCustomerCustomerDemoInfo, DbTransaction transaction, out string errorMessage)
        {
            errorMessage = string.Empty;

//If is trying to insert FKValue without the ID but has the unique description,
//the system will try to get the class with the ID and populate it.
            if ((parCustomerCustomerDemoInfo.CustomerID == string.Empty) && (parCustomerCustomerDemoInfo.FK0_CompanyName != null))
            {
                CustomersInfo fkClass = Get_CustomerIDID_FKCustomers(parCustomerCustomerDemoInfo, transaction);
                parCustomerCustomerDemoInfo.CustomerID = fkClass.CustomerID;
            }
            if ((parCustomerCustomerDemoInfo.CustomerTypeID == string.Empty) && (parCustomerCustomerDemoInfo.FK1_CustomerDesc != null))
            {
                CustomerDemographicsInfo fkClass = Get_CustomerTypeIDID_FKCustomerDemographics(parCustomerCustomerDemoInfo, transaction);
                parCustomerCustomerDemoInfo.CustomerTypeID = fkClass.CustomerTypeID;
            }

            CustomerCustomerDemoDAO.UpdateOne(parCustomerCustomerDemoInfo, transaction, out errorMessage);
            //By default, the caller of this method will do the commit.
            //motor.Commit();
            //motor.CloseConnection();
        }