public UsuarioReader(TipoQuery tipo, UsuarioModel usuarioModel) { switch (tipo) { case TipoQuery.Todos: this.DefaultCommad = QueryProcessor.QueryAll(QueryRepo.SelectAll, "UsuarioTBL"); break; case TipoQuery.PorId: this.DefaultCommad = QueryProcessor.QueryByID(QueryRepo.SelectByID, "UsuarioTBL", "IdPersona", usuarioModel.Id_Usuario.ToString()); break; case TipoQuery.TodosConFiltros: this.DefaultCommad = QueryProcessor.QueryAll(QueryRepo.SelectAll, "UsuarioTBL", usuarioModel); break; case TipoQuery.PorIdConFiltro: break; case TipoQuery.AddRow: this.DefaultCommad = QueryProcessor.AddRow(QueryRepo.AddRow, "UsuarioTBL", usuarioModel); break; case TipoQuery.UpdateRow: this.DefaultCommad = QueryProcessor.UpdateRow(QueryRepo.UpdateRow, "UsuarioTBL", usuarioModel); break; default: break; } }
public PersonaReader(TipoQuery tipo, PersonaModel personaModel) { switch (tipo) { case TipoQuery.Todos: this.DefaultCommad = QueryProcessor.QueryAll(QuerysRepo.SelectAll, "PERSONA"); break; case TipoQuery.PorId: this.DefaultCommad = QueryProcessor.QueryByID(QuerysRepo.SelectByID, "PERSONA", "IdPersona", personaModel.IdPersona.ToString()); break; case TipoQuery.TodosConFiltros: this.DefaultCommad = QueryProcessor.QueryAll(QuerysRepo.SelectAll, "PERSONA", personaModel); break; case TipoQuery.PorIdConFiltro: break; case TipoQuery.AddRow: this.DefaultCommad = QueryProcessor.AddRow(QuerysRepo.AddRow, "PERSONA", personaModel); break; case TipoQuery.UpdateRow: this.DefaultCommad = QueryProcessor.UpdateRow(QuerysRepo.UpdateRow, "PERSONA", personaModel); break; default: break; } }
public object executar(string sql, TipoQuery tpo_query) { object objeto = null; openConnection(); _SQLtrans = _conn.BeginTransaction(); OdbcCommand SQLcmd = new OdbcCommand(sql, _conn); SQLcmd.Transaction = _SQLtrans; try { if (tpo_query == TipoQuery.Reader) { objeto = SQLcmd.ExecuteReader(); } else if (tpo_query == TipoQuery.NonQuery) { objeto = SQLcmd.ExecuteNonQuery(); _SQLtrans.Commit(); } else if (tpo_query == TipoQuery.Scalar) { objeto = SQLcmd.ExecuteScalar(); } } catch (OdbcException e) { _SQLtrans.Rollback(); closeConnection(); throw new Exception(e.Message + "\nSQL: " + sql); } closeConnection(); return(objeto); }
public PersonaReader(TipoQuery tipo, PersonaModel personaModel) { switch (tipo) { case TipoQuery.Todos: this.DefaultCommad = QueryProcessor.QueryAll(QuerysRepo.SelectAll, "odeodal.persona"); break; case TipoQuery.PorId: this.DefaultCommad = QueryProcessor.QueryByID(QuerysRepo.SelectByID, "odeodal.persona", "idpersona", personaModel.IdPersona.ToString()); break; case TipoQuery.TodosConFiltros: this.DefaultCommad = QueryProcessor.QueryAll(QuerysRepo.SelectAll, "odeodal.persona", personaModel); break; case TipoQuery.PorIdConFiltro: break; default: break; } }
/// <summary> /// Constroi Intrução Sql /// </summary> /// <param name="tipoQuery">Tipo de Intrução</param> /// <returns></returns> private string MakeSql(TipoQuery tipoQuery) { var fields = new List <string>(); var fieldProp = new List <PropertyInfo>(); var sb = new StringBuilder(); var properties = GetProperties(); foreach (var prop in properties) { var attrDbColumn = GetAttrDbColumn(prop); switch (tipoQuery) { case TipoQuery.Select: #region Select if (attrDbColumn != null) { if (attrDbColumn.ComplexType) { break; } if (attrDbColumn.List == false) { break; } } fields.Add(prop.Name); #endregion break; case TipoQuery.Insert: #region Insert if (attrDbColumn == null) { fields.Add(prop.Name); } else { if (attrDbColumn.PrimaryKey) { if (attrDbColumn.Identity) { break; } fields.Add(prop.Name); } else if (attrDbColumn.ForeignKey) { fields.Add(prop.Name); } else if (attrDbColumn.ComplexType) { /* * { * fields.Add(prop.Name + "ID"); * break; * }*/ break; } else if (attrDbColumn.Required == false) { break; } else { fields.Add(prop.Name); } } #endregion break; case TipoQuery.Update: #region Update if (attrDbColumn != null) { if (attrDbColumn.PrimaryKey) { continue; } if (attrDbColumn.ComplexType) { continue; } fieldProp.Add(prop); } else { fieldProp.Add(prop); } #endregion break; case TipoQuery.Delete: break; default: throw new ArgumentOutOfRangeException(nameof(tipoQuery), tipoQuery, null); } } switch (tipoQuery) { case TipoQuery.Select: case TipoQuery.Insert: for (var i = 0; i < fields.Count; i++) { sb.AppendFormat("{0}{1} ", fields[i], i == (fields.Count - 1) ? "" : ","); } break; case TipoQuery.Update: for (var i = 0; i < fieldProp.Count; i++) { sb.AppendFormat("{0}={1}{2}", fieldProp[i].Name, FormatValue(fieldProp[i]), i == (fieldProp.Count - 1) ? " " : ","); } break; case TipoQuery.Delete: break; default: throw new ArgumentOutOfRangeException(nameof(tipoQuery), tipoQuery, null); } return(sb.ToString()); }