public List<InvFamiliaDTO> Listar() { List<InvFamiliaDTO> Lista = new List<InvFamiliaDTO>(); Database db = DatabaseFactory.CreateDatabase("ApplicationConnectionString"); DbCommand dbCommand = db.GetSqlStringCommand(C_LISTAR); using (IDataReader dr = db.ExecuteReader(dbCommand)) { while (dr.Read()) { InvFamiliaDTO obj = new InvFamiliaDTO(); if (dr["id_familia"] != System.DBNull.Value) obj.IdFamilia = (int)dr["id_familia"]; if (dr["cod_familia"] != System.DBNull.Value) obj.CodFamilia = (string)dr["cod_familia"]; if (dr["nombre_familia"] != System.DBNull.Value) obj.NombreFamilia = (string)dr["nombre_familia"]; if (dr["estado"] != System.DBNull.Value) obj.Estado = (string)dr["estado"]; Lista.Add(obj); } } return Lista; }
public void Actualizar(InvFamiliaDTO obj) { Database db = DatabaseFactory.CreateDatabase("ApplicationConnectionString"); DbCommand dbCommand = db.GetSqlStringCommand(C_ACTUALIZAR); db.AddInParameter(dbCommand, "@id_familia", DbType.Int32, obj.IdFamilia); db.AddInParameter(dbCommand, "@cod_familia", DbType.String, obj.CodFamilia); db.AddInParameter(dbCommand, "@nombre_familia", DbType.String, obj.NombreFamilia); db.AddInParameter(dbCommand, "@estado", DbType.String, obj.Estado); db.ExecuteNonQuery(dbCommand); }
public int Agregar(InvFamiliaDTO obj) { Database db = DatabaseFactory.CreateDatabase("ApplicationConnectionString"); DbCommand dbCommand = db.GetSqlStringCommand(C_AGREGAR); db.AddInParameter(dbCommand, "@cod_familia", DbType.String, obj.CodFamilia); db.AddInParameter(dbCommand, "@nombre_familia", DbType.String, obj.NombreFamilia); db.AddInParameter(dbCommand, "@estado", DbType.String, obj.Estado); db.ExecuteNonQuery(dbCommand); dbCommand = db.GetSqlStringCommand("SELECT MAX(id_familia) FROM INV_FAMILIA"); int id = Convert.ToInt32(db.ExecuteScalar (dbCommand)); return id; }
protected void btnActualizar_Click(object sender, EventArgs e) { InvFamiliaDTO obj = new InvFamiliaDTO(); obj = objInvFamiliaDAO.ListarPorClave(Convert.ToInt32(this.txtId.Text)); obj.CodFamilia = this.txtCodigo.Text; obj.NombreFamilia = this.txtDescripcion.Text; if (this.chkEstado.Checked) obj.Estado = "1"; else obj.Estado = "0"; objInvFamiliaDAO.Actualizar(obj); }
protected void btnEliminar_Click(object sender, EventArgs e) { InvFamiliaDTO obj = new InvFamiliaDTO(); if (this.txtId.Text != "") { objInvFamiliaDAO.Eliminar(Convert.ToInt32(this.txtId.Text)); this.txtId.Text = ""; this.txtCodigo.Text = ""; this.txtDescripcion.Text = ""; this.chkEstado.Checked = true; } this.panRegistro.Visible = false; this.panLista.Visible = true; Listar(); }
protected void btnGrabar_Click(object sender, EventArgs e) { InvFamiliaDTO obj = new InvFamiliaDTO(); obj.CodFamilia = this.txtCodigo.Text; obj.NombreFamilia = this.txtDescripcion.Text; if (this.chkEstado.Checked) obj.Estado = "1"; else obj.Estado = "0"; int id = objInvFamiliaDAO.Agregar(obj); this.txtId.Text = id.ToString(); this.btnNuevo.Visible = false; this.btnActualizar.Visible = true; this.btnEliminar.Visible = true; this.panRegistro.Visible = true; this.panLista.Visible = false; }
public InvFamiliaDTO ListarPorClave(int IdFamilia) { InvFamiliaDTO obj = null; Database db = DatabaseFactory.CreateDatabase("ApplicationConnectionString"); try { DbCommand dbCommand = db.GetSqlStringCommand(C_LISTAR_POR_CLAVE); db.AddInParameter(dbCommand, "@id_familia", DbType.String, IdFamilia); using (IDataReader dr = db.ExecuteReader(dbCommand)) { if (dr.Read()) { obj = new InvFamiliaDTO(); if (dr["id_familia"] != System.DBNull.Value) obj.IdFamilia = (int)dr["id_familia"]; if (dr["cod_familia"] != System.DBNull.Value) obj.CodFamilia = (string)dr["cod_familia"]; if (dr["nombre_familia"] != System.DBNull.Value) obj.NombreFamilia = (string)dr["nombre_familia"]; if (dr["estado"] != System.DBNull.Value) obj.Estado = (string)dr["estado"]; } } } catch (Exception err) { throw err; } return obj; }