public List <entSector> ListarSector() { SqlCommand cmd = null; List <entSector> list = new List <entSector>(); try { SqlConnection cn = Conexion.Instancia.Conectar(); cmd = new SqlCommand("sp_listarSector", cn); cmd.CommandType = CommandType.StoredProcedure; cn.Open(); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { entSector sec = new entSector(); sec.idSec = Convert.ToInt32(dr["idSec"]); sec.nombre = dr["nombre"].ToString(); sec.id_Ciudad1 = Convert.ToInt32(dr["id_Ciudad1"]); list.Add(sec); } } catch (Exception ex) { throw ex; } finally { cmd.Connection.Close(); } return(list); }
public int RegistrarSector(entSector obj) { int i = 0; SqlCommand cmd = null; try { SqlConnection cn = Conexion.Instancia.Conectar(); cmd = new SqlCommand("sp_registrarSector", cn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@nombre", obj.nombre); cmd.Parameters.AddWithValue("@idCiudad1", obj.id_Ciudad1); cn.Open(); i = cmd.ExecuteNonQuery(); } catch (Exception ex) { throw ex; } finally { cmd.Connection.Close(); } return(i); }
public void ModificarSector(entSector sec) { try { datSector.Instancia.ModificarSector(sec); } catch (Exception ex) { throw ex; } }
public int RegistrarSector(entSector obj) { try { int i = datSector.Instancia.RegistrarSector(obj); return(i); } catch (Exception ex) { throw ex; } }
private void b3_Click(object sender, EventArgs e) { ListarSector(); if (string.IsNullOrEmpty(t1.Text.Trim())) { MessageBox.Show("Ingrese Sector a modificar, por favor"); return; } else if (string.IsNullOrEmpty(t2.Text.Trim())) { MessageBox.Show("Ingrese un Id de Sector, por favor"); return; } entSector aux = new entSector(); aux.nombre = t1.Text.Trim(); aux.idSec = Convert.ToInt32(t2.Text.Trim()); logSector.Instancia.ModificarSector(aux); ListarSector(); }
public void ModificarSector(entSector sec) { SqlCommand cmd = null; try { SqlConnection cn = Conexion.Instancia.Conectar(); cmd = new SqlCommand("sp_modificarSector", cn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@idSec", sec.idSec); cmd.Parameters.AddWithValue("@nombre", sec.nombre); //cmd.Parameters.AddWithValue("@id_Ciudad1", sec.id_Ciudad1); cn.Open(); cmd.ExecuteNonQuery(); } catch (Exception ex) { throw ex; } finally { cmd.Connection.Close(); } }
private void b1_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(t1.Text.Trim())) { MessageBox.Show("Ingrese el nombre de un sector, por favor"); return; } entSector ob = new entSector(); ob.nombre = t1.Text.Trim(); ob.id_Ciudad1 = Convert.ToInt32(cbx1.SelectedValue); int i = logSector.Instancia.RegistrarSector(ob); if (i > 0) { MessageBox.Show("Se registro el sector con exito"); } else { MessageBox.Show("No se pudo registrar"); } }