private void btnEliminar_Click(object sender, EventArgs e) { DialogResult result = MessageBox.Show("¿Esta seguro que desea ELIMINAR el registro?", "¿Eliminar?", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { lblEstado.Text = "<<<ELIMINANDO>>>"; lblEstado.ForeColor = Color.FromArgb(255, 255, 255); sector pSector = new sector(); pSector.id = int.Parse(txtIdSec.Text.Trim()); pSector.idCiu = int.Parse(cbCiudad.SelectedValue.ToString()); pSector.nomSector = txtNomSector.Text.Trim(); int delResul = sectorDal.delSector(pSector); if (delResul > 0) { MessageBox.Show("¡Registro ELIMINADO con exito!", "¡Eliminando!", MessageBoxButtons.OK, MessageBoxIcon.Information); rNew(); } else { MessageBox.Show("¡Registro no fue encontrado!", "¡Error!", MessageBoxButtons.OK, MessageBoxIcon.Information); } rNew(); } }
private void btnSalvar_Click(object sender, EventArgs e) { sector pSector = new sector(); pSector.id = int.Parse(txtIdSec.Text.Trim()); pSector.idCiu = int.Parse(cbCiudad.SelectedValue.ToString()); pSector.nomSector = txtNomSector.Text.Trim(); int updResul = sectorDal.updSector(pSector); if (updResul > 0) { MessageBox.Show("Ciudad Modificado con exito!!", "Modificando", MessageBoxButtons.OK, MessageBoxIcon.Information); rNew(); } else { int resultado = sectorDal.addSector(pSector); if (resultado > 0) { MessageBox.Show("Ciudad Guardada con exito!!", "Guardado", MessageBoxButtons.OK, MessageBoxIcon.Information); rNew(); } else { MessageBox.Show("No se pudo guardad la Ciudad", "Fallo!!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } }
public static int updSector(sector pSector) { int retorno = 0; MySqlConnection conexion = Conectando.conectando(); using (MySqlCommand cmd = new MySqlCommand()) { try { cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Connection = conexion; cmd.CommandText = "updateSector"; cmd.Parameters.AddWithValue("pId", pSector.id); cmd.Parameters.AddWithValue("pIdCiu", pSector.idCiu); cmd.Parameters.AddWithValue("pNomSec", pSector.nomSector); retorno = cmd.ExecuteNonQuery(); } catch (Exception Ex) { MessageBox.Show(Ex.ToString(), "Error en actualizar el registro"); } finally { conexion.Close(); } } return(retorno); }
public static List <sector> buscar(string filtroCiudad) { List <sector> _lista = new List <sector>(); MySqlCommand _comando = new MySqlCommand(string.Format( "SELECT idsector, nomsector FROM sector where idciudad=" + filtroCiudad), Conectando.conectando()); try { MySqlDataReader _reader = _comando.ExecuteReader(); while (_reader.Read()) { sector pSector = new sector(); pSector.id = _reader.GetInt32(0); //pSector.idCiu = _reader.GetInt32(1); pSector.nomSector = _reader.GetString(1); _lista.Add(pSector); } } catch (Exception ex) { MessageBox.Show(ex.ToString(), "ERROR AL BUSCAR REGISTRO"); } return(_lista); }
public static int addSector(sector pSector) { int retorno = 0; MySqlConnection conexion = Conectando.conectando(); using (MySqlCommand cmd = new MySqlCommand()) { try { cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Connection = conexion; cmd.CommandText = "insertSector"; cmd.Parameters.AddWithValue("pIdCiu", pSector.idCiu); cmd.Parameters.AddWithValue("pNomSec", pSector.nomSector); retorno = cmd.ExecuteNonQuery(); } catch (Exception Ex) { MessageBox.Show(Ex.ToString(), "ERROR AL INSERTAR EL REGISTRO"); } finally { conexion.Close(); } } return(retorno); }
private void dgvSector_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { sector modSec = new sector(); modSec = sectorDal.ObtenerSec((int)dgvSector.CurrentRow.Cells["ID"].Value); lblEstado.Text = "<<<Consultando>>>"; lblEstado.ForeColor = Color.FromArgb(65, 105, 225); txtIdSec.Text = modSec.id.ToString(); txtNomSector.Text = modSec.nomSector; cbCiudad.SelectedValue = modSec.idCiu; ctrlInicio(true); txtNomSector.Enabled = false; }
public static sector ObtenerSec(int pId) { sector pSector = new sector(); MySqlConnection conexion = Conectando.conectando(); MySqlCommand _comando = new MySqlCommand(string.Format( "SELECT idsector, idciudad, nomsector FROM sector where idsector={0}", pId), conexion); MySqlDataReader _reader = _comando.ExecuteReader(); while (_reader.Read()) { pSector.id = _reader.GetInt32(0); pSector.idCiu = _reader.GetInt32(1); pSector.nomSector = _reader.GetString(2); } conexion.Close(); return(pSector); }