private void btnEliminar_Click(object sender, EventArgs e) { if (lvCI.SelectedItems.Count == 0) { MessageBox.Show("NO HA SELECCIONADO NINGUN ELEMENTO", "SIN SELECCIONAR", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } DialogResult R = MessageBox.Show("¿DESEA ELIMINAR EL CI SELECCIONADO?", "CONFIRMAR", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (R == DialogResult.Yes) { string NU = ""; for (int i = 0; i < lvCI.Items.Count; i++) { if (lvCI.SelectedItems.Contains(lvCI.Items[i])) { NU = lvCI.Items[i].SubItems[2].Text; int IDCI = AdmCI.GetID(NU); AdmCI.UpdateEstatus(IDCI); if (true) { SqlConnection Connection3 = UsoBD.ConectaBD(Utileria.GetConnectionString()); SqlDataReader Lector3 = null; string strComandoC3 = "SELECT ID FROM INCIDENCIA I WHERE I.ID_CI=" + IDCI; Lector3 = UsoBD.Consulta(strComandoC3, Connection3); if (Lector3 == null) { MessageBox.Show("ERROR AL HACER LA CONSULTA"); foreach (SqlError E in UsoBD.ESalida.Errors) { MessageBox.Show(E.Message); } Connection3.Close(); return; } if (Lector3.HasRows) { while (Lector3.Read()) { MessageBox.Show("LA BAJA DEL CI SE HA REALIZADO CORRECTAMENTE", "ELIMINACION REALIZADA", MessageBoxButtons.OK, MessageBoxIcon.Information); lvCI.Items[i].Remove(); Connection3.Close(); return; } } Connection3.Close(); } SqlConnection Connection = UsoBD.ConectaBD(Utileria.GetConnectionString()); if (Connection == null) { MessageBox.Show("ERROR DE CONEXIÓN CON LA BASE DE DATOS"); foreach (SqlError E in UsoBD.ESalida.Errors) { MessageBox.Show(E.Message); } return; } SqlDataReader Lector = null; string strComandoC = "DELETE FROM CI WHERE NumSerie LIKE'" + NU + "'"; Lector = UsoBD.Consulta(strComandoC, Connection); if (Lector == null) { MessageBox.Show("ERROR AL HACER LA CONSULTA"); foreach (SqlError E in UsoBD.ESalida.Errors) { MessageBox.Show(E.Message); } Connection.Close(); return; } Connection.Close(); lvCI.Items[i].Remove(); MessageBox.Show("LA ELIMINACION DEL CI SE HA REALIZADO CORRECTAMENTE", "ELIMINACION REALIZADA", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } } }
private void cmbEncargado_SelectedIndexChanged(object sender, EventArgs e) { cmbProveedor.Items.Clear(); cmbEncargado.Items.Clear(); cmbEdificio.Items.Clear(); string Nombre = cmbNombre.SelectedItem.ToString(); string NumSerie = AdmCI.GetNumSerie(Nombre); txtxNumSerie.Text = NumSerie; string Desc = AdmCI.GetDesc(NumSerie); txtDescripcion.Text = Desc; string Ubi = AdmCI.GetUbi(NumSerie); txtUbicacion.Text = Ubi; string DescUb = AdmCI.GetDescUbi(NumSerie); txtDescUbicacion.Text = DescUb; string Fecha = AdmCI.GetFecha(NumSerie); lblDate.Text = Fecha; int Num = AdmCI.GetPlanta(NumSerie); nudPlanta.Value = Num; string Pro = AdmProv.GetNombreByCI(NumSerie); lblProveedor.Text = Pro; string Enc = AdmEmp.GetIDNameByCI(NumSerie); lblEncargado.Text = Enc; int IDCI = AdmCI.GetID(NumSerie); SqlConnection Connection = UsoBD.ConectaBD(Utileria.GetConnectionString()); if (Connection == null) { MessageBox.Show("ERROR DE CONEXIÓN CON LA BASE DE DATOS"); foreach (SqlError E in UsoBD.ESalida.Errors) { MessageBox.Show(E.Message); } return; } SqlDataReader Lector = null; string strComandoC = "SELECT Nombre FROM EMPLEADO WHERE Estatus=1"; Lector = UsoBD.Consulta(strComandoC, Connection); if (Lector == null) { MessageBox.Show("ERROR AL HACER LA CONSULTA"); foreach (SqlError E in UsoBD.ESalida.Errors) { MessageBox.Show(E.Message); } Connection.Close(); return; } if (Lector.HasRows) { while (Lector.Read()) { cmbEncargado.Items.Add(Lector.GetValue(0).ToString()); } } Connection.Close(); SqlConnection Connection2 = UsoBD.ConectaBD(Utileria.GetConnectionString()); SqlDataReader Lector2 = null; string strComandoC2 = "SELECT Nombre FROM PROVEEDOR"; Lector2 = UsoBD.Consulta(strComandoC2, Connection2); if (Lector2 == null) { MessageBox.Show("ERROR AL HACER LA CONSULTA"); foreach (SqlError E in UsoBD.ESalida.Errors) { MessageBox.Show(E.Message); } Connection2.Close(); return; } if (Lector2.HasRows) { while (Lector2.Read()) { cmbProveedor.Items.Add(Lector2.GetValue(0).ToString()); } } Connection2.Close(); SqlConnection Connection3 = UsoBD.ConectaBD(Utileria.GetConnectionString()); SqlDataReader Lector3 = null; string strComandoC3 = "SELECT Nombre FROM EDIFICIO"; Lector3 = UsoBD.Consulta(strComandoC3, Connection3); if (Lector3 == null) { MessageBox.Show("ERROR AL HACER LA CONSULTA"); foreach (SqlError E in UsoBD.ESalida.Errors) { MessageBox.Show(E.Message); } Connection3.Close(); return; } if (Lector3.HasRows) { while (Lector3.Read()) { cmbEdificio.Items.Add(Lector3.GetValue(0).ToString()); } } Connection3.Close(); SqlConnection Connection4 = UsoBD.ConectaBD(Utileria.GetConnectionString()); SqlDataReader Lector4 = null; string strComandoC4 = "SELECT E.Nombre FROM CI INNER JOIN LOCALIZACION L ON CI.ID_Localizacion = L.ID INNER JOIN EDIFICIO E ON L.ID_Edificio = E.ID WHERE L.ID_Edificio = E.ID AND CI.ID =" + IDCI + ""; Lector4 = UsoBD.Consulta(strComandoC4, Connection4); if (Lector4 == null) { MessageBox.Show("ERROR AL HACER LA CONSULTA"); foreach (SqlError E in UsoBD.ESalida.Errors) { MessageBox.Show(E.Message); } Connection4.Close(); return; } if (Lector4.HasRows) { while (Lector4.Read()) { lblEdificio.Text = Lector4.GetValue(0).ToString(); } } Connection4.Close(); }