public bool isValid(SubGrupoClienteFields fieldInfo) { try { //Field descricaoSubGrupoCliente if (fieldInfo.descricaoSubGrupoCliente != string.Empty) { if (fieldInfo.descricaoSubGrupoCliente.Trim().Length > 150) { throw new Exception("O campo \"descricaoSubGrupoCliente\" deve ter comprimento máximo de 150 caracter(es)."); } } if ((fieldInfo.descricaoSubGrupoCliente == string.Empty) || (fieldInfo.descricaoSubGrupoCliente.Trim().Length < 1)) { throw new Exception("O campo \"descricaoSubGrupoCliente\" não pode ser nulo ou vazio e deve ter comprimento mínimo de 1 caracter(es)."); } //Field fkGrupoCliente if (!(fieldInfo.fkGrupoCliente > 0)) { throw new Exception("O campo \"fkGrupoCliente\" deve ser maior que zero."); } //Field valorIndiceInicial if (!(fieldInfo.valorIndiceInicial > 0)) { throw new Exception("O campo \"valorIndiceInicial\" deve ser maior que zero."); } //Field valorIndiceFinal if (!(fieldInfo.valorIndiceFinal > 0)) { throw new Exception("O campo \"valorIndiceFinal\" deve ser maior que zero."); } return(true); } catch (Exception e) { this._ErrorMessage = e.Message; return(false); } }
public bool isValid( SubGrupoClienteFields fieldInfo ) { try { //Field descricaoSubGrupoCliente if ( fieldInfo.descricaoSubGrupoCliente != string.Empty ) if ( fieldInfo.descricaoSubGrupoCliente.Trim().Length > 150 ) throw new Exception("O campo \"descricaoSubGrupoCliente\" deve ter comprimento máximo de 150 caracter(es)."); if ( ( fieldInfo.descricaoSubGrupoCliente == string.Empty ) || ( fieldInfo.descricaoSubGrupoCliente.Trim().Length < 1 ) ) throw new Exception("O campo \"descricaoSubGrupoCliente\" não pode ser nulo ou vazio e deve ter comprimento mínimo de 1 caracter(es)."); //Field fkGrupoCliente if ( !( fieldInfo.fkGrupoCliente > 0 ) ) throw new Exception("O campo \"fkGrupoCliente\" deve ser maior que zero."); //Field valorIndiceInicial if ( !( fieldInfo.valorIndiceInicial > 0 ) ) throw new Exception("O campo \"valorIndiceInicial\" deve ser maior que zero."); //Field valorIndiceFinal if ( !( fieldInfo.valorIndiceFinal > 0 ) ) throw new Exception("O campo \"valorIndiceFinal\" deve ser maior que zero."); return true; } catch (Exception e) { this._ErrorMessage = e.Message; return false; } }
/// <summary> /// Grava/Persiste um novo objeto SubGrupoClienteFields no banco de dados /// </summary> /// <param name="FieldInfo">Objeto SubGrupoClienteFields a ser gravado.Caso o parâmetro solicite a expressão "ref", será adicionado um novo valor a algum campo auto incremento.</param> /// <returns>"true" = registro gravado com sucesso, "false" = erro ao gravar registro (consulte a propriedade ErrorMessage para detalhes)</returns> public bool Add( ref SubGrupoClienteFields FieldInfo ) { try { this.Conn = new SqlConnection(this.StrConnetionDB); this.Conn.Open(); this.Tran = this.Conn.BeginTransaction(); this.Cmd = new SqlCommand("Proc_SubGrupoCliente_Add", this.Conn, this.Tran); this.Cmd.CommandType = CommandType.StoredProcedure; this.Cmd.Parameters.Clear(); this.Cmd.Parameters.AddRange(GetAllParameters(FieldInfo, SQLMode.Add)); if (!(this.Cmd.ExecuteNonQuery() > 0)) throw new Exception("Erro ao tentar inserir registro!!"); this.Tran.Commit(); FieldInfo.idSubGrupoCliente = (int)this.Cmd.Parameters["@Param_idSubGrupoCliente"].Value; return true; } catch (SqlException e) { this.Tran.Rollback(); //this._ErrorMessage = string.Format(@"Houve um erro imprevisto ao tentar inserir o(s) registro(s) solicitados: Código do erro: {0}, Mensagem: {1}, Procedimento: {2}, Linha do erro {3}.", e.ErrorCode, e.Message, e.Procedure, e.LineNumber); this._ErrorMessage = string.Format(@"Houve um erro imprevisto ao tentar inserir o(s) registro(s) solicitados: {0}.", e.Message); return false; } catch (Exception e) { this.Tran.Rollback(); this._ErrorMessage = e.Message; return false; } finally { if (this.Conn != null) if (this.Conn.State == ConnectionState.Open) { this.Conn.Dispose(); } if (this.Cmd != null) this.Cmd.Dispose(); } }
/// <summary> /// Grava/Persiste um novo objeto SubGrupoClienteFields no banco de dados /// </summary> /// <param name="ConnIn">Objeto SqlConnection responsável pela conexão com o banco de dados.</param> /// <param name="TranIn">Objeto SqlTransaction responsável pela transação iniciada no banco de dados.</param> /// <param name="FieldInfo">Objeto SubGrupoClienteFields a ser gravado.Caso o parâmetro solicite a expressão "ref", será adicionado um novo valor a algum campo auto incremento.</param> /// <returns>"true" = registro gravado com sucesso, "false" = erro ao gravar registro (consulte a propriedade ErrorMessage para detalhes)</returns> public bool Add( SqlConnection ConnIn, SqlTransaction TranIn, ref SubGrupoClienteFields FieldInfo ) { try { this.Cmd = new SqlCommand("Proc_SubGrupoCliente_Add", ConnIn, TranIn); this.Cmd.CommandType = CommandType.StoredProcedure; this.Cmd.Parameters.Clear(); this.Cmd.Parameters.AddRange(GetAllParameters(FieldInfo, SQLMode.Add)); if (!(this.Cmd.ExecuteNonQuery() > 0)) throw new Exception("Erro ao tentar inserir registro!!"); FieldInfo.idSubGrupoCliente = (int)this.Cmd.Parameters["@Param_idSubGrupoCliente"].Value; return true; } catch (SqlException e) { //this._ErrorMessage = string.Format(@"Houve um erro imprevisto ao tentar inserir o(s) registro(s) solicitados: Código do erro: {0}, Mensagem: {1}, Procedimento: {2}, Linha do erro {3}.", e.ErrorCode, e.Message, e.Procedure, e.LineNumber); this._ErrorMessage = string.Format(@"Houve um erro imprevisto ao tentar inserir o(s) registro(s) solicitados: {0}.", e.Message); return false; } catch (Exception e) { this._ErrorMessage = e.Message; return false; } }
/// <summary> /// Retorna um objeto SubGrupoClienteFields preenchido com os valores dos campos do SqlDataReader /// </summary> /// <param name="dr">SqlDataReader - Preenche o objeto SubGrupoClienteFields </param> /// <returns>SubGrupoClienteFields</returns> private SubGrupoClienteFields GetDataFromReader( SqlDataReader dr ) { SubGrupoClienteFields infoFields = new SubGrupoClienteFields(); if (!dr.IsDBNull(0)) { infoFields.idSubGrupoCliente = dr.GetInt32(0); } else { infoFields.idSubGrupoCliente = 0; } if (!dr.IsDBNull(1)) { infoFields.descricaoSubGrupoCliente = dr.GetString(1); } else { infoFields.descricaoSubGrupoCliente = string.Empty; } if (!dr.IsDBNull(2)) { infoFields.fkGrupoCliente = dr.GetInt32(2); } else { infoFields.fkGrupoCliente = 0; } if (!dr.IsDBNull(3)) { infoFields.valorIndiceInicial = dr.GetDecimal(3); } else { infoFields.valorIndiceInicial = 0; } if (!dr.IsDBNull(4)) { infoFields.valorIndiceFinal = dr.GetDecimal(4); } else { infoFields.valorIndiceFinal = 0; } return infoFields; }
/// <summary> /// Retorna um array de parâmetros com campos para atualização, seleção e inserção no banco de dados /// </summary> /// <param name="FieldInfo">Objeto SubGrupoClienteFields</param> /// <param name="Modo">Tipo de oepração a ser executada no banco de dados</param> /// <returns>SqlParameter[] - Array de parâmetros</returns> private SqlParameter[] GetAllParameters( SubGrupoClienteFields FieldInfo, SQLMode Modo ) { SqlParameter[] Parameters; switch (Modo) { case SQLMode.Add: Parameters = new SqlParameter[5]; for (int I = 0; I < Parameters.Length; I++) Parameters[I] = new SqlParameter(); //Field idSubGrupoCliente Parameters[0].SqlDbType = SqlDbType.Int; Parameters[0].Direction = ParameterDirection.Output; Parameters[0].ParameterName = "@Param_idSubGrupoCliente"; Parameters[0].Value = DBNull.Value; break; case SQLMode.Update: Parameters = new SqlParameter[5]; for (int I = 0; I < Parameters.Length; I++) Parameters[I] = new SqlParameter(); //Field idSubGrupoCliente Parameters[0].SqlDbType = SqlDbType.Int; Parameters[0].ParameterName = "@Param_idSubGrupoCliente"; Parameters[0].Value = FieldInfo.idSubGrupoCliente; break; case SQLMode.SelectORDelete: Parameters = new SqlParameter[1]; for (int I = 0; I < Parameters.Length; I++) Parameters[I] = new SqlParameter(); //Field idSubGrupoCliente Parameters[0].SqlDbType = SqlDbType.Int; Parameters[0].ParameterName = "@Param_idSubGrupoCliente"; Parameters[0].Value = FieldInfo.idSubGrupoCliente; return Parameters; default: Parameters = new SqlParameter[5]; for (int I = 0; I < Parameters.Length; I++) Parameters[I] = new SqlParameter(); break; } //Field descricaoSubGrupoCliente Parameters[1].SqlDbType = SqlDbType.VarChar; Parameters[1].ParameterName = "@Param_descricaoSubGrupoCliente"; if (( FieldInfo.descricaoSubGrupoCliente == null ) || ( FieldInfo.descricaoSubGrupoCliente == string.Empty )) { Parameters[1].Value = DBNull.Value; } else { Parameters[1].Value = FieldInfo.descricaoSubGrupoCliente; } Parameters[1].Size = 150; //Field fkGrupoCliente Parameters[2].SqlDbType = SqlDbType.Int; Parameters[2].ParameterName = "@Param_fkGrupoCliente"; Parameters[2].Value = FieldInfo.fkGrupoCliente; //Field valorIndiceInicial Parameters[3].SqlDbType = SqlDbType.Decimal; Parameters[3].ParameterName = "@Param_valorIndiceInicial"; Parameters[3].Value = FieldInfo.valorIndiceInicial; //Field valorIndiceFinal Parameters[4].SqlDbType = SqlDbType.Decimal; Parameters[4].ParameterName = "@Param_valorIndiceFinal"; Parameters[4].Value = FieldInfo.valorIndiceFinal; return Parameters; }
/// <summary> /// Retorna um objeto SubGrupoClienteFields através da chave primária passada como parâmetro /// </summary> /// <param name="Param_idSubGrupoCliente">int</param> /// <returns>Objeto SubGrupoClienteFields</returns> public SubGrupoClienteFields GetItem( int Param_idSubGrupoCliente) { SubGrupoClienteFields infoFields = new SubGrupoClienteFields(); try { using (this.Conn = new SqlConnection(this.StrConnetionDB)) { using (this.Cmd = new SqlCommand("Proc_SubGrupoCliente_Select", this.Conn)) { this.Cmd.CommandType = CommandType.StoredProcedure; this.Cmd.Parameters.Clear(); this.Cmd.Parameters.Add(new SqlParameter("@Param_idSubGrupoCliente", SqlDbType.Int)).Value = Param_idSubGrupoCliente; this.Cmd.Connection.Open(); using (SqlDataReader dr = this.Cmd.ExecuteReader(CommandBehavior.SequentialAccess)) { if (!dr.HasRows) return null; if (dr.Read()) { infoFields = GetDataFromReader( dr ); } } } } return infoFields; } catch (SqlException e) { //this._ErrorMessage = string.Format(@"Houve um erro imprevisto ao tentar selecionar o(s) registro(s) solicitados: Código do erro: {0}, Mensagem: {1}, Procedimento: {2}, Linha do erro {3}.", e.ErrorCode, e.Message, e.Procedure, e.LineNumber); this._ErrorMessage = string.Format(@"Houve um erro imprevisto ao tentar selecionar o(s) registro(s) solicitados: {0}.", e.Message); return null; } catch (Exception e) { this._ErrorMessage = e.Message; return null; } finally { if (this.Conn != null) if (this.Conn.State == ConnectionState.Open) { this.Conn.Dispose(); } } }
/// <summary> /// Exclui um registro da tabela no banco de dados /// </summary> /// <param name="ConnIn">Objeto SqlConnection responsável pela conexão com o banco de dados.</param> /// <param name="TranIn">Objeto SqlTransaction responsável pela transação iniciada no banco de dados.</param> /// <param name="FieldInfo">Objeto SubGrupoClienteFields a ser excluído.</param> /// <returns>"true" = registro excluido com sucesso, "false" = erro ao tentar excluir registro (consulte a propriedade ErrorMessage para detalhes)</returns> public bool Delete( SqlConnection ConnIn, SqlTransaction TranIn, SubGrupoClienteFields FieldInfo ) { return Delete(ConnIn, TranIn, FieldInfo.idSubGrupoCliente); }
/// <summary> /// Exclui um registro da tabela no banco de dados /// </summary> /// <param name="FieldInfo">Objeto SubGrupoClienteFields a ser excluído.</param> /// <returns>"true" = registro excluido com sucesso, "false" = erro ao tentar excluir registro (consulte a propriedade ErrorMessage para detalhes)</returns> public bool Delete( SubGrupoClienteFields FieldInfo ) { return Delete(FieldInfo.idSubGrupoCliente); }