/// <summary> /// Performs one "select * from MyTable where [InformedProperties]". MinValues and nulls are skipped from filter. /// </summary> /// <param name="filter">TagEmployeeInfo</param> /// <returns>List of found records.</returns> public virtual List <TagEmployeeInfo> GetSome(TagEmployeeInfo filter) { List <TagEmployeeInfo> AllInfoList = new List <TagEmployeeInfo>(); 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(TagEmployeeInfo), dbReader); using (dbReader) { while (dbReader.Read()) { TagEmployeeInfo TagEmployeeInfo = new TagEmployeeInfo(); ///Warning: performance issues with this automation. See method description for details. classFiller.Fill(TagEmployeeInfo); AllInfoList.Add(TagEmployeeInfo); } } return(AllInfoList); }
/// <summary> /// Delete registers based on class values informed. MinValues and nulls are skipped. /// </summary> /// <param name="parTagEmployeeInfo">Item to delete</param> /// <param name="transaction">Transaction context</param> /// <param name="errorMessage">Error message</param> public virtual void Delete(TagEmployeeInfo parTagEmployeeInfo, 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(TagEmployeeInfo), parTagEmployeeInfo, 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 TagEmployeeInfo GetValueByID(int TagEmployeeID) { //ToDo: set multiple PK filter motor.ClearCommandParameters(); motor.CommandText = GetSelectCommand() + GetWherePrimaryKey(); List <DbParameter> paramList = new List <DbParameter>(); DbParameter paramTagEmployeeID = motor.Command.CreateParameter(); paramTagEmployeeID.ParameterName = "@param_TagEmployeeID"; paramTagEmployeeID.Value = TagEmployeeID; paramList.Add(paramTagEmployeeID); motor.AddCommandParameters(paramList); TagEmployeeInfo InfoValue = new TagEmployeeInfo(); DbDataReader dbReader = motor.ExecuteReader(); ClassFiller classFiller = new ClassFiller(typeof(TagEmployeeInfo), dbReader); using (dbReader) { if (dbReader.Read()) { InfoValue = new TagEmployeeInfo(); classFiller.Fill(InfoValue); } else { return(null); } } return(InfoValue); }
/// <summary> /// Delete registers based on ID informed. Other values are skipped. /// </summary> /// <param name="parTagEmployeeInfo">Item to delete</param> /// <param name="errorMessage">Error message</param> public virtual void DeleteByID(TagEmployeeInfo parTagEmployeeInfo, out string errorMessage) { TagEmployeeInfo newParam = new TagEmployeeInfo(); newParam.TagEmployeeID = parTagEmployeeInfo.TagEmployeeID; this.Delete(newParam, out errorMessage); }
/// <summary> /// Insert one register in database. /// </summary> /// <param name="parTagEmployeeInfo">Item to delete</param> /// <param name="transaction">Transaction context</param> /// <param name="errorMessage">Error message</param> public virtual void InsertOne(TagEmployeeInfo parTagEmployeeInfo, DbTransaction transaction, out string errorMessage) { errorMessage = null; try { motor.CommandText = GetInsertCommand(); ///Warning: performance issues with this automation. See method description for details. List <DbParameter> paramList = ParameterBuilder.GetParametersForInsert(typeof(TagEmployeeInfo), parTagEmployeeInfo, motor.Command); motor.ClearCommandParameters(); motor.AddCommandParameters(paramList); motor.AddTransaction(transaction); if (GetIdentity == true) { parTagEmployeeInfo.TagEmployeeID = motor.ExecuteScalar(); } else { motor.ExecuteNonQuery(); } } catch (Exception ex) { errorMessage = ex.Message; } }
public void DeleteData(ModelNotifiedForTagEmployee modelNotifiedForTagEmployee, out string error) { TagEmployeeBsn bsn = new TagEmployeeBsn(wpfConfig); TagEmployeeInfo dbItem = new TagEmployeeInfo(); Cloner.CopyAllTo(typeof(ModelNotifiedForTagEmployee), modelNotifiedForTagEmployee, typeof(TagEmployeeInfo), dbItem); bsn.DeleteByID(dbItem, out error); }
/// <summary> /// Delete registers based on class values informed. MinValues and nulls are skipped. /// Must have "MultipleActiveResultSets=True" on connection string. /// </summary> /// <param name="parTagEmployeeInfo">Item to delete</param> /// <param name="transaction">Transaction context</param> /// <param name="errorMessage">Error message</param> public virtual void Delete(TagEmployeeInfo parTagEmployeeInfo, DbTransaction transaction, out string errorMessage) { errorMessage = string.Empty; TagEmployeeDAO.Delete(parTagEmployeeInfo, transaction, out errorMessage); //By default, the caller of this method will do the commit. //motor.Commit(); //motor.CloseConnection(); }
/// <summary> /// Performs one "update" database command. /// Will commit the transaction and close the connection. Use for independent delete. /// </summary> /// <param name="TagEmployeeInfo">Object to update.</param> /// <param name="errorMessage">Error message if exception is throwed</param> public virtual void UpdateOne(TagEmployeeInfo parTagEmployeeInfo, out string errorMessage) { errorMessage = string.Empty; DbTransaction transaction = motor.BeginTransaction(); this.UpdateOne(parTagEmployeeInfo, transaction, out errorMessage); motor.Commit(); motor.CloseConnection(); }
public void AddData(ModelNotifiedForTagEmployee modelNotifiedForTagEmployee, out string error) { TagEmployeeBsn bsn = new TagEmployeeBsn(wpfConfig); TagEmployeeInfo dbItem = new TagEmployeeInfo(); Cloner.CopyAllTo(typeof(ModelNotifiedForTagEmployee), modelNotifiedForTagEmployee, typeof(TagEmployeeInfo), dbItem); bsn.InsertOne(dbItem, out error); modelNotifiedForTagEmployee.NewItem = false; Cloner.CopyAllTo(typeof(TagEmployeeInfo), dbItem, typeof(ModelNotifiedForTagEmployee), modelNotifiedForTagEmployee); }
/// <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="parTagEmployeeInfo">Item to delete</param> /// <param name="transaction">Transaction context</param> /// <param name="errorMessage">Error message</param> public virtual void DeleteByID(TagEmployeeInfo parTagEmployeeInfo, DbTransaction transaction, out string errorMessage) { TagEmployeeInfo newParam = new TagEmployeeInfo(); newParam.TagEmployeeID = parTagEmployeeInfo.TagEmployeeID; this.Delete(newParam, transaction, out errorMessage); //By default, the caller of this method will do the commit. //motor.Commit(); //motor.CloseConnection(); }
public ModelNotifiedForTagEmployee GetTagEmployeeByID(int TagEmployeeID, out string error) { error = null; TagEmployeeBsn bsn = new TagEmployeeBsn(wpfConfig); TagEmployeeInfo dbItem = bsn.GetValueByID(TagEmployeeID); ModelNotifiedForTagEmployee item = new ModelNotifiedForTagEmployee(); Cloner.CopyAllTo(typeof(TagEmployeeInfo), dbItem, typeof(ModelNotifiedForTagEmployee), item); return(item); }
/// <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 TagEmployeeInfo GetValueByID(int TagEmployeeID) { motor.OpenConnection(); TagEmployeeInfo value = TagEmployeeDAO.GetValueByID(TagEmployeeID); if (this.closeConnectionWhenFinish) { motor.CloseConnection(); } return(value); }
/// <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 <TagEmployeeInfo> GetSome(TagEmployeeInfo filter) { motor.OpenConnection(); List <TagEmployeeInfo> list = TagEmployeeDAO.GetSome(filter); if (this.closeConnectionWhenFinish) { motor.CloseConnection(); } return(list); }
/// <summary> /// Use parameters to apply simple filters /// </summary> /// <param name="filterExpression"></param> /// <returns></returns> public virtual List <TagEmployeeInfo> GetAll(List <DataFilterExpressionDB> filterExpression) { List <TagEmployeeInfo> AllInfoList = new List <TagEmployeeInfo>(); 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(TagEmployeeInfo), filter.FieldName); if (filter.FilterType == DataFilterExpressionDB._FilterType.Equal) { param.Value = filter.Filter; where += string.Format(" and TagEmployee.{0} = {1}", filter.FieldName, param.ParameterName); } else { param.Value = "%" + filter.Filter + "%"; where += string.Format(" and TagEmployee.{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(TagEmployeeInfo), dbReader); using (dbReader) { while (dbReader.Read()) { TagEmployeeInfo classInfo = new TagEmployeeInfo(); classFiller.Fill(classInfo); AllInfoList.Add(classInfo); } } return(AllInfoList); }
/// <summary> /// Delete registers based on class values informed. MinValues and nulls are skipped. /// </summary> /// <param name="parTagEmployeeInfo">Item to delete</param> /// <param name="errorMessage">Error message</param> public virtual void Delete(TagEmployeeInfo parTagEmployeeInfo, 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(parTagEmployeeInfo, 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 <TagEmployeeInfo> GetAll() { List <TagEmployeeInfo> AllInfoList = new List <TagEmployeeInfo>(); motor.CommandText = GetSelectCommand(); DbDataReader dbReader = motor.ExecuteReader(); ClassFiller classFiller = new ClassFiller(typeof(TagEmployeeInfo), dbReader); using (dbReader) { while (dbReader.Read()) { TagEmployeeInfo classInfo = new TagEmployeeInfo(); 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 <TagEmployeeInfo> GetAll(int numberOfRowsToSkip, int numberOfRows) { List <TagEmployeeInfo> AllInfoList = new List <TagEmployeeInfo>(); motor.CommandText = base.GetFilteredRowNumAndSkipQuery("AttributeLists", "id", numberOfRowsToSkip, numberOfRows); DbDataReader dbReader = motor.ExecuteReader(); ClassFiller classFiller = new ClassFiller(typeof(TagEmployeeInfo), dbReader); using (dbReader) { while (dbReader.Read()) { TagEmployeeInfo classInfo = new TagEmployeeInfo(); classFiller.Fill(classInfo); AllInfoList.Add(classInfo); } } return(AllInfoList); }
public void TryUpdate(UpdateTagEmployeeView viewToUpdate, out RestExceptionError error) { error = null; TagEmployeeInfo dbViewToInclude = new TagEmployeeInfo(); try { Cloner.CopyAllTo(typeof(UpdateTagEmployeeView), viewToUpdate, typeof(TagEmployeeInfo), dbViewToInclude); } catch (Exception ex) { error = new RestExceptionError(); error.InternalMessage = "Internal Error parsing data for (TagEmployee.TryUpdate/Parsing)"; error.ExceptionMessage = ex.Message; error.SourceError = RestExceptionError._SourceError.ServerSide; error.StackTrace = ex.StackTrace; } try { TagEmployeeBsn bsn = new TagEmployeeBsn(restConfig); string dbError = null; bsn.UpdateOne(dbViewToInclude, out dbError); if (dbError != null) { error = new RestExceptionError(); error.InternalMessage = "Internal Error Save data for [TagEmployee.TryUpdate]"; error.ExceptionMessage = dbError; error.SourceError = RestExceptionError._SourceError.ServerSide; error.StackTrace = ""; } } catch (Exception ex) { error = new RestExceptionError(); error.InternalMessage = "Internal Error Update data for [TagEmployee.TryUpdate]"; error.ExceptionMessage = ex.Message; error.SourceError = RestExceptionError._SourceError.ServerSide; error.StackTrace = ex.StackTrace; } }
/// <summary> /// Perform a search to find the class "TagInfo" using as key the field "Tag". /// </summary> /// <param name="parTagEmployeeInfo">Main class that contains the aggregation.</param> /// <returns>Foreing key attched class.</returns> public virtual TagInfo Get_TagFKID_FKTag(TagEmployeeInfo parTagEmployeeInfo, DbTransaction transaction) { TagInfo filter = new TagInfo(); filter.TextDesc = parTagEmployeeInfo.FK1_TextDesc; TagBsn myClass = new TagBsn(false, this.motor); List <TagInfo> 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 parTagEmployeeInfo.", parTagEmployeeInfo.FK1_TextDesc)); /* [Hint] The code below do one insert in the table "Tag" informing only the "TagID" 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 parTagEmployeeInfo. Theres more then one ID value for this field. ", parTagEmployeeInfo.FK1_TextDesc)); } 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="TagEmployeeInfo">Object to update.</param> /// <param name="transaction">Inform "DBTransaction".</param> /// <param name="errorMessage">Error message if exception is throwed.</param> public virtual void UpdateOne(TagEmployeeInfo parTagEmployeeInfo, 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 ((parTagEmployeeInfo.EmployeeIDFK == null) && (parTagEmployeeInfo.FK0_LastName != null)) { EmployeesInfo fkClass = Get_EmployeeIDFKID_FKEmployees(parTagEmployeeInfo, transaction); parTagEmployeeInfo.EmployeeIDFK = fkClass.EmployeeID; } if ((parTagEmployeeInfo.TagFK == null) && (parTagEmployeeInfo.FK1_TextDesc != null)) { TagInfo fkClass = Get_TagFKID_FKTag(parTagEmployeeInfo, transaction); parTagEmployeeInfo.TagFK = fkClass.TagID; } TagEmployeeDAO.UpdateOne(parTagEmployeeInfo, 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(TagEmployeeInfo 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 TagEmployeeID if (filter.TagEmployeeID != Int32.MinValue) { DbParameter param = motor.Command.CreateParameter(); param.ParameterName = "@param_TagEmployeeID"; param.Value = filter.TagEmployeeID; paramList.Add(param); where.Append(" and TagEmployee.TagEmployeeID=@param_TagEmployeeID"); } // 2) Adding filter for field EmployeeIDFK if (filter.EmployeeIDFK != null) { DbParameter param = motor.Command.CreateParameter(); param.ParameterName = "@param_EmployeeIDFK"; param.Value = filter.EmployeeIDFK; paramList.Add(param); where.Append(" and TagEmployee.EmployeeIDFK=@param_EmployeeIDFK"); } // 3) Adding filter for field LastName if (filter.FK0_LastName != null) { DbParameter param = motor.Command.CreateParameter(); param.ParameterName = "@param_FK0_LastName"; param.Value = filter.FK0_LastName; paramList.Add(param); where.Append(" and FK0_Employees.LastName=@param_FK0_LastName"); } // 4) Adding filter for field TagFK if (filter.TagFK != null) { DbParameter param = motor.Command.CreateParameter(); param.ParameterName = "@param_TagFK"; param.Value = filter.TagFK; paramList.Add(param); where.Append(" and TagEmployee.TagFK=@param_TagFK"); } // 5) Adding filter for field TextDesc if (filter.FK1_TextDesc != null) { DbParameter param = motor.Command.CreateParameter(); param.ParameterName = "@param_FK1_TextDesc"; param.Value = filter.FK1_TextDesc; paramList.Add(param); where.Append(" and FK1_Tag.TextDesc=@param_FK1_TextDesc"); } // 6) Adding filter for field TagEmployeeTextDesc if (filter.TagEmployeeTextDesc != null) { DbParameter param = motor.Command.CreateParameter(); param.ParameterName = "@param_TagEmployeeTextDesc"; param.Value = filter.TagEmployeeTextDesc; paramList.Add(param); where.Append(" and TagEmployee.TagEmployeeTextDesc=@param_TagEmployeeTextDesc"); //Hint: use the code below to add a "like" search. Warning: may cause data performance issues. //param.ParameterName = "@param_TagEmployeeTextDesc"; //param.Value = "%" + filter.TagEmployeeTextDesc "%"; //paramList.Add(param); //where.Append(" and TagEmployee.TagEmployeeTextDesc like @param_TagEmployeeTextDesc"); } whereClausule = where.ToString(); }