private void fillCategorias() { List <Ent_CategoriaProductos> items = new List <Ent_CategoriaProductos>(); items.Add(new Ent_CategoriaProductos { id = "", nombre = "Todos los Productos" }); var categorias = BL_CategoriaProductos.getCategorias(String.Empty, "1"); items.AddRange(categorias); cboCategoria.DataSource = items; cboCategoria.ValueMember = "id"; cboCategoria.DisplayMember = "nombre"; List <Ent_CategoriaProductos> det_items = items.ToList(); det_items[0] = new Ent_CategoriaProductos { id = "", nombre = "Seleccione" }; cboCategoriaDet.DataSource = det_items; cboCategoriaDet.ValueMember = "id"; cboCategoriaDet.DisplayMember = "nombre"; }
private void btnGuardar_Click(object sender, EventArgs e) { string nombre = txtCategoriaDet.Text; string estado = cboEstadoDet.SelectedValue.ToString(); if (nombre.Equals(String.Empty)) { MessageBox.Show("El nombre no puede estar vacío.", "Agregar categoría", MessageBoxButtons.OK, MessageBoxIcon.Error); txtCategoriaDet.Focus(); return; } if (estado.Equals(String.Empty)) { MessageBox.Show("Debe seleccionar un estado.", "Agregar categoría", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var confirm = MessageBox.Show("¿Está seguro que desea registrar la nueva categegoría?.", "Atención", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (confirm == DialogResult.Yes) { Ent_CategoriaProductos categoria = new Ent_CategoriaProductos(); categoria.nombre = nombre; categoria.activo = estado; try { string result = BL_CategoriaProductos.insertarCategoria(categoria); if (result == "1") { MessageBox.Show("¡Categoría guardada exitosamente!", "Agregar categoría", MessageBoxButtons.OK, MessageBoxIcon.Information); fillCategorias(); } else { MessageBox.Show("¡Ocurrió un error al guardar la categoría!", "Agregar categoría", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message, "Agregar categoría", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public static List <Ent_CategoriaProductos> getCategorias(string nombre, string activo) { List <Ent_CategoriaProductos> lstCategorias = new List <Ent_CategoriaProductos>(); con = Conexion.getConnection(); MySqlCommand cmd = new MySqlCommand(); con.Open(); cmd.Connection = con; cmd.CommandText = "SP_SYS_GET_CATEGORIAS"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@PSTR_CATEGORIA", nombre); cmd.Parameters["@PSTR_CATEGORIA"].Direction = ParameterDirection.Input; cmd.Parameters.AddWithValue("@PSTR_ACTIVO", (activo == String.Empty) ? null : activo); cmd.Parameters["@PSTR_ACTIVO"].Direction = ParameterDirection.Input; MySqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { Ent_CategoriaProductos categoria = new Ent_CategoriaProductos(); categoria.id = Convert.ToString(dr["ID"]); categoria.codigo = Convert.ToString(dr["CODIGO"]); categoria.nombre = Convert.ToString(dr["NOMBRE"]); categoria.fecha = Convert.ToString(dr["FECHA_REGISTRO"]); categoria.activo = Convert.ToString(dr["ACTIVO"]); lstCategorias.Add(categoria); } con.Close(); return(lstCategorias); }
public static string insertarCategoria(Ent_CategoriaProductos categoria) { MySqlTransaction tr = null; con = Conexion.getConnection(); string retval = "1"; try { con.Open(); tr = con.BeginTransaction(); MySqlCommand cmd = new MySqlCommand(); cmd.Connection = con; cmd.Transaction = tr; cmd.CommandText = "SP_SYS_SET_CATEGORIA"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@RETVAL", MySqlDbType.VarChar); cmd.Parameters["@RETVAL"].Direction = ParameterDirection.Output; cmd.Parameters.AddWithValue("@PSTR_NOMBRE", categoria.nombre); cmd.Parameters["@PSTR_NOMBRE"].Direction = ParameterDirection.Input; cmd.Parameters.AddWithValue("@PSTR_ACTIVO", categoria.activo); cmd.Parameters["@PSTR_ACTIVO"].Direction = ParameterDirection.Input; cmd.ExecuteNonQuery(); retval = cmd.Parameters["@RETVAL"].Value.ToString(); if (retval == "1") { tr.Commit(); } else { tr.Rollback(); return(retval); } } catch (MySqlException ex) { try { tr.Rollback(); } catch (MySqlException ex1) { return(ex1.ToString()); } return(ex.ToString()); } finally { con.Close(); } return(retval); }
public static string editarCategoria(Ent_CategoriaProductos categoria) { return(DAO_CategoriaProductos.editarCategoria(categoria)); }
public static string insertarCategoria(Ent_CategoriaProductos categoria) { return(DAO_CategoriaProductos.insertarCategoria(categoria)); }