/// <summary> /// Delete registers based on ID informed. Other values are skipped. /// </summary> /// <param name="parCustomerDemographicsInfo">Item to delete</param> /// <param name="errorMessage">Error message</param> public virtual void DeleteByID(CustomerDemographicsInfo parCustomerDemographicsInfo, out string errorMessage) { CustomerDemographicsInfo newParam = new CustomerDemographicsInfo(); newParam.CustomerTypeID = parCustomerDemographicsInfo.CustomerTypeID; this.Delete(newParam, out errorMessage); }
/// <summary> /// Performs one "select * from MyTable where [InformedProperties]". MinValues and nulls are skipped from filter. /// </summary> /// <param name="filter">CustomerDemographicsInfo</param> /// <returns>List of found records.</returns> public virtual List <CustomerDemographicsInfo> GetSome(CustomerDemographicsInfo filter) { List <CustomerDemographicsInfo> AllInfoList = new List <CustomerDemographicsInfo>(); 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(CustomerDemographicsInfo), dbReader); using (dbReader) { while (dbReader.Read()) { CustomerDemographicsInfo CustomerDemographicsInfo = new CustomerDemographicsInfo(); ///Warning: performance issues with this automation. See method description for details. classFiller.Fill(CustomerDemographicsInfo); AllInfoList.Add(CustomerDemographicsInfo); } } return(AllInfoList); }
/// <summary> /// Delete registers based on class values informed. MinValues and nulls are skipped. /// </summary> /// <param name="parCustomerDemographicsInfo">Item to delete</param> /// <param name="transaction">Transaction context</param> /// <param name="errorMessage">Error message</param> public virtual void Delete(CustomerDemographicsInfo parCustomerDemographicsInfo, 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(CustomerDemographicsInfo), parCustomerDemographicsInfo, motor.Command, out whereClausule); motor.CommandText = GetDeleteCommand() + " " + whereClausule; motor.ClearCommandParameters(); motor.AddCommandParameters(paramList); motor.AddTransaction(transaction); motor.ExecuteNonQuery(); } catch (Exception ex) { errorMessage = ex.Message; } }
/// <summary> /// Get one register using only ID as key. /// </summary> /// <returns></returns> public virtual CustomerDemographicsInfo GetValueByID(string CustomerTypeID) { //ToDo: set multiple PK filter motor.ClearCommandParameters(); motor.CommandText = GetSelectCommand() + GetWherePrimaryKey(); List <DbParameter> paramList = new List <DbParameter>(); DbParameter paramCustomerTypeID = motor.Command.CreateParameter(); paramCustomerTypeID.ParameterName = "@param_CustomerTypeID"; paramCustomerTypeID.Value = CustomerTypeID; paramList.Add(paramCustomerTypeID); motor.AddCommandParameters(paramList); CustomerDemographicsInfo InfoValue = new CustomerDemographicsInfo(); DbDataReader dbReader = motor.ExecuteReader(); ClassFiller classFiller = new ClassFiller(typeof(CustomerDemographicsInfo), dbReader); using (dbReader) { if (dbReader.Read()) { InfoValue = new CustomerDemographicsInfo(); classFiller.Fill(InfoValue); } else { return(null); } } return(InfoValue); }
/// <summary> /// Delete registers based on class values informed. MinValues and nulls are skipped. /// Must have "MultipleActiveResultSets=True" on connection string. /// </summary> /// <param name="parCustomerDemographicsInfo">Item to delete</param> /// <param name="transaction">Transaction context</param> /// <param name="errorMessage">Error message</param> public virtual void Delete(CustomerDemographicsInfo parCustomerDemographicsInfo, DbTransaction transaction, out string errorMessage) { errorMessage = string.Empty; CustomerDemographicsDAO.Delete(parCustomerDemographicsInfo, transaction, out errorMessage); //By default, the caller of this method will do the commit. //motor.Commit(); //motor.CloseConnection(); }
public void DeleteData(ModelNotifiedForCustomerDemographics modelNotifiedForCustomerDemographics, out string error) { CustomerDemographicsBsn bsn = new CustomerDemographicsBsn(wpfConfig); CustomerDemographicsInfo dbItem = new CustomerDemographicsInfo(); Cloner.CopyAllTo(typeof(ModelNotifiedForCustomerDemographics), modelNotifiedForCustomerDemographics, typeof(CustomerDemographicsInfo), dbItem); bsn.DeleteByID(dbItem, out error); }
/// <summary> /// Performs one "update" database command. /// Will commit the transaction and close the connection. Use for independent delete. /// </summary> /// <param name="CustomerDemographicsInfo">Object to update.</param> /// <param name="errorMessage">Error message if exception is throwed</param> public virtual void UpdateOne(CustomerDemographicsInfo parCustomerDemographicsInfo, out string errorMessage) { errorMessage = string.Empty; DbTransaction transaction = motor.BeginTransaction(); this.UpdateOne(parCustomerDemographicsInfo, transaction, out errorMessage); motor.Commit(); motor.CloseConnection(); }
public void AddData(ModelNotifiedForCustomerDemographics modelNotifiedForCustomerDemographics, out string error) { CustomerDemographicsBsn bsn = new CustomerDemographicsBsn(wpfConfig); CustomerDemographicsInfo dbItem = new CustomerDemographicsInfo(); Cloner.CopyAllTo(typeof(ModelNotifiedForCustomerDemographics), modelNotifiedForCustomerDemographics, typeof(CustomerDemographicsInfo), dbItem); bsn.InsertOne(dbItem, out error); modelNotifiedForCustomerDemographics.NewItem = false; Cloner.CopyAllTo(typeof(CustomerDemographicsInfo), dbItem, typeof(ModelNotifiedForCustomerDemographics), modelNotifiedForCustomerDemographics); }
/// <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="parCustomerDemographicsInfo">Item to delete</param> /// <param name="transaction">Transaction context</param> /// <param name="errorMessage">Error message</param> public virtual void DeleteByID(CustomerDemographicsInfo parCustomerDemographicsInfo, DbTransaction transaction, out string errorMessage) { CustomerDemographicsInfo newParam = new CustomerDemographicsInfo(); newParam.CustomerTypeID = parCustomerDemographicsInfo.CustomerTypeID; this.Delete(newParam, transaction, out errorMessage); //By default, the caller of this method will do the commit. //motor.Commit(); //motor.CloseConnection(); }
public ModelNotifiedForCustomerDemographics GetCustomerDemographicsByID(string CustomerTypeID, out string error) { error = null; CustomerDemographicsBsn bsn = new CustomerDemographicsBsn(wpfConfig); CustomerDemographicsInfo dbItem = bsn.GetValueByID(CustomerTypeID); ModelNotifiedForCustomerDemographics item = new ModelNotifiedForCustomerDemographics(); Cloner.CopyAllTo(typeof(CustomerDemographicsInfo), dbItem, typeof(ModelNotifiedForCustomerDemographics), item); return(item); }
/// <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 <CustomerDemographicsInfo> GetSome(CustomerDemographicsInfo filter) { motor.OpenConnection(); List <CustomerDemographicsInfo> list = CustomerDemographicsDAO.GetSome(filter); if (this.closeConnectionWhenFinish) { motor.CloseConnection(); } return(list); }
/// <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 CustomerDemographicsInfo GetValueByID(string CustomerTypeID) { motor.OpenConnection(); CustomerDemographicsInfo value = CustomerDemographicsDAO.GetValueByID(CustomerTypeID); if (this.closeConnectionWhenFinish) { motor.CloseConnection(); } return(value); }
/// <summary> /// Performs a "update [FildList] set [FieldList] where id = @id". Must have the ID informed. /// </summary> /// <param name="parCustomerDemographicsInfo">Item to update</param> /// <param name="transaction">Transaction context</param> /// <param name="errorMessage">Error message</param> public virtual void UpdateOne(CustomerDemographicsInfo parCustomerDemographicsInfo, 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(CustomerDemographicsInfo), parCustomerDemographicsInfo, motor.Command); motor.ClearCommandParameters(); motor.AddCommandParameters(paramList); motor.AddTransaction(transaction); motor.ExecuteNonQuery(); } catch (Exception ex) { errorMessage = ex.Message; } }
/// <summary> /// Use parameters to apply simple filters /// </summary> /// <param name="filterExpression"></param> /// <returns></returns> public virtual List <CustomerDemographicsInfo> GetAll(List <DataFilterExpressionDB> filterExpression) { List <CustomerDemographicsInfo> AllInfoList = new List <CustomerDemographicsInfo>(); 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(CustomerDemographicsInfo), filter.FieldName); if (filter.FilterType == DataFilterExpressionDB._FilterType.Equal) { param.Value = filter.Filter; where += string.Format(" and CustomerDemographics.{0} = {1}", filter.FieldName, param.ParameterName); } else { param.Value = "%" + filter.Filter + "%"; where += string.Format(" and CustomerDemographics.{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(CustomerDemographicsInfo), dbReader); using (dbReader) { while (dbReader.Read()) { CustomerDemographicsInfo classInfo = new CustomerDemographicsInfo(); classFiller.Fill(classInfo); AllInfoList.Add(classInfo); } } return(AllInfoList); }
/// <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 <CustomerDemographicsInfo> GetAll(int numberOfRowsToSkip, int numberOfRows) { List <CustomerDemographicsInfo> AllInfoList = new List <CustomerDemographicsInfo>(); motor.CommandText = base.GetFilteredRowNumAndSkipQuery("AttributeLists", "id", numberOfRowsToSkip, numberOfRows); DbDataReader dbReader = motor.ExecuteReader(); ClassFiller classFiller = new ClassFiller(typeof(CustomerDemographicsInfo), dbReader); using (dbReader) { while (dbReader.Read()) { CustomerDemographicsInfo classInfo = new CustomerDemographicsInfo(); classFiller.Fill(classInfo); AllInfoList.Add(classInfo); } } return(AllInfoList); }
/// <summary> /// Delete registers based on class values informed. MinValues and nulls are skipped. /// </summary> /// <param name="parCustomerDemographicsInfo">Item to delete</param> /// <param name="errorMessage">Error message</param> public virtual void Delete(CustomerDemographicsInfo parCustomerDemographicsInfo, 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(parCustomerDemographicsInfo, transaction, out errorMessage); //3) Commit the transaction. motor.Commit(); //4) Close the conection (if configured to do so). if (this.closeConnectionWhenFinish) { motor.CloseConnection(); } }
/// <summary> /// Performs one "Select * from MyTable". Use wisely. /// </summary> /// <returns>List of found records.</returns> public virtual List <CustomerDemographicsInfo> GetAll() { List <CustomerDemographicsInfo> AllInfoList = new List <CustomerDemographicsInfo>(); motor.CommandText = GetSelectCommand(); DbDataReader dbReader = motor.ExecuteReader(); ClassFiller classFiller = new ClassFiller(typeof(CustomerDemographicsInfo), dbReader); using (dbReader) { while (dbReader.Read()) { CustomerDemographicsInfo classInfo = new CustomerDemographicsInfo(); classFiller.Fill(classInfo); AllInfoList.Add(classInfo); } } return(AllInfoList); }
public void TryUpdate(UpdateCustomerDemographicsView viewToUpdate, out RestExceptionError error) { error = null; CustomerDemographicsInfo dbViewToInclude = new CustomerDemographicsInfo(); try { Cloner.CopyAllTo(typeof(UpdateCustomerDemographicsView), viewToUpdate, typeof(CustomerDemographicsInfo), dbViewToInclude); } catch (Exception ex) { error = new RestExceptionError(); error.InternalMessage = "Internal Error parsing data for (CustomerDemographics.TryUpdate/Parsing)"; error.ExceptionMessage = ex.Message; error.SourceError = RestExceptionError._SourceError.ServerSide; error.StackTrace = ex.StackTrace; } try { CustomerDemographicsBsn bsn = new CustomerDemographicsBsn(restConfig); string dbError = null; bsn.UpdateOne(dbViewToInclude, out dbError); if (dbError != null) { error = new RestExceptionError(); error.InternalMessage = "Internal Error Save data for [CustomerDemographics.TryUpdate]"; error.ExceptionMessage = dbError; error.SourceError = RestExceptionError._SourceError.ServerSide; error.StackTrace = ""; } } catch (Exception ex) { error = new RestExceptionError(); error.InternalMessage = "Internal Error Update data for [CustomerDemographics.TryUpdate]"; error.ExceptionMessage = ex.Message; error.SourceError = RestExceptionError._SourceError.ServerSide; error.StackTrace = ex.StackTrace; } }
/// <summary> /// Perform a search to find the class "CustomerDemographicsInfo" using as key the field "CustomerDemographics". /// </summary> /// <param name="parCustomerCustomerDemoInfo">Main class that contains the aggregation.</param> /// <returns>Foreing key attched class.</returns> public virtual CustomerDemographicsInfo Get_CustomerTypeIDID_FKCustomerDemographics(CustomerCustomerDemoInfo parCustomerCustomerDemoInfo, DbTransaction transaction) { CustomerDemographicsInfo filter = new CustomerDemographicsInfo(); filter.CustomerDesc = parCustomerCustomerDemoInfo.FK1_CustomerDesc; CustomerDemographicsBsn myClass = new CustomerDemographicsBsn(false, this.motor); List <CustomerDemographicsInfo> 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.FK1_CustomerDesc)); /* [Hint] The code below do one insert in the table "CustomerDemographics" informing only the "CustomerTypeID" 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.FK1_CustomerDesc)); } else { //Return the only one class found. return(list[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(); }
/// <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(CustomerDemographicsInfo 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 CustomerTypeID if (filter.CustomerTypeID != null) { DbParameter param = motor.Command.CreateParameter(); param.ParameterName = "@param_CustomerTypeID"; param.Value = filter.CustomerTypeID; paramList.Add(param); where.Append(" and CustomerDemographics.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 CustomerDemographics.CustomerTypeID like @param_CustomerTypeID"); } // 2) Adding filter for field CustomerDesc if (filter.CustomerDesc != null) { DbParameter param = motor.Command.CreateParameter(); param.ParameterName = "@param_CustomerDesc"; param.Value = filter.CustomerDesc; paramList.Add(param); where.Append(" and CustomerDemographics.CustomerDesc=@param_CustomerDesc"); //Hint: use the code below to add a "like" search. Warning: may cause data performance issues. //param.ParameterName = "@param_CustomerDesc"; //param.Value = "%" + filter.CustomerDesc "%"; //paramList.Add(param); //where.Append(" and CustomerDemographics.CustomerDesc like @param_CustomerDesc"); } whereClausule = where.ToString(); }