public void cargarDatos(DataGridView d) { try { c = new conexion(); da = new SqlDataAdapter("SELECT * FROM GENERAL.REPORTE", c.regresaConexion()); dt = new DataTable(); da.Fill(dt); d.DataSource = dt; c.cerrarConexion(); if (dataGridBaseDatos.RowCount == 0) { ModificarBoton.Enabled = false; EliminarBoton.Enabled = false; } if (dataGridBaseDatos.RowCount != 0) { ModificarBoton.Enabled = true; EliminarBoton.Enabled = true; } } catch (Exception ex) { MessageBox.Show("No se cargar los datos"); c.cerrarConexion(); } }
private void ModificarBoton_Click(object sender, EventArgs e) { try { c = new conexion(); cmd = new SqlCommand("UPDATE GENERAL.REPORTE SET folio =" + FolioText.Text + ",turno='" + TurnoCombo.SelectedItem + "',esmalte='" + EsmalteCombo.SelectedItem + "',lote=" + LoteText.Text + ",operador='" + OperadorText.Text + "',molino=" + MolinoCombo.SelectedItem + ",tiempo='" + TiempoText.Text + "',densidad=" + DensidadText.Text + ",residuos=" + ResiduoText.Text + ",viscosidad=" + ViscosidadText.Text + ",cantidadAgua=" + CtdAguaText.Text + " WHERE id_reporte=" + dataGridBaseDatos[0, 0].Value, c.regresaConexion()); cmd.ExecuteNonQuery(); c.cerrarConexion(); MessageBox.Show("Reporte modificado"); ClaveText.Text = ""; FolioText.Text = ""; TurnoCombo.Text = ""; EsmalteCombo.Text = ""; LoteText.Text = ""; OperadorText.Text = ""; MolinoCombo.Text = ""; TiempoText.Text = ""; DensidadText.Text = ""; ResiduoText.Text = ""; ViscosidadText.Text = ""; CtdAguaText.Text = ""; cargarDatos(dataGridBaseDatos); } catch (Exception ex) { MessageBox.Show("No se pudo Modificar" + ex.ToString()); c.cerrarConexion(); } }
private void EliminarBoton_Click(object sender, EventArgs e) { try { c = new conexion(); cmd = new SqlCommand("DELETE FROM GENERAL.REPORTE WHERE id_reporte =" + ClaveText.Text, c.regresaConexion()); cmd.ExecuteNonQuery(); c.cerrarConexion(); cargarDatos(dataGridBaseDatos); MessageBox.Show("Reporte eliminado"); FolioText.Text = ""; TurnoCombo.Text = ""; EsmalteCombo.Text = ""; LoteText.Text = ""; OperadorText.Text = ""; MolinoCombo.Text = ""; TiempoText.Text = ""; DensidadText.Text = ""; ResiduoText.Text = ""; ViscosidadText.Text = ""; CtdAguaText.Text = ""; } catch (Exception ex) { MessageBox.Show("No se pudo eliminar reporte"); c.cerrarConexion(); } }
private void AgregarBoton_Click(object sender, EventArgs e) { bool existe = false; c = new conexion(); try { if (FolioText.Text == "" || LoteText.Text == "" || OperadorText.Text == "" || TiempoText.Text == "" || DensidadText.Text == "" || ResiduoText.Text == "" || ViscosidadText.Text == "" || CtdAguaText.Text == "") { MessageBox.Show("Faltan campos por llenar"); } else { for (int i = 0; i < dataGridBaseDatos.RowCount; i++) { if (dataGridBaseDatos.Rows[i].Cells[1].Value.ToString() == FolioText.Text) { existe = true; if (existe == true) { MessageBox.Show("El reporte ya esta dado de alta"); ClaveText.Text = ""; FolioText.Text = ""; TurnoCombo.Text = ""; EsmalteCombo.Text = ""; LoteText.Text = ""; OperadorText.Text = ""; MolinoCombo.Text = ""; TiempoText.Text = ""; DensidadText.Text = ""; ResiduoText.Text = ""; ViscosidadText.Text = ""; CtdAguaText.Text = ""; } } } if (existe == false) { if (FolioText.Text == "" || LoteText.Text == "" || OperadorText.Text == "" || TiempoText.Text == "" || DensidadText.Text == "" || ResiduoText.Text == "" || ViscosidadText.Text == "" || CtdAguaText.Text == "") { MessageBox.Show("Falatan campos por llenar"); } else { string sq = "INSERT INTO GENERAL.REPORTE(folio, turno, esmalte, lote, operador, molino, tiempo, densidad, residuos, viscosidad, cantidadAgua, fecha) VALUES (" + FolioText.Text + ",'" + TurnoCombo.SelectedItem + "','" + EsmalteCombo.SelectedItem + "'," + LoteText.Text + ",'" + OperadorText.Text + "'," + MolinoCombo.SelectedItem + ", '" + TiempoText.Text + "', " + DensidadText.Text + ", " + ResiduoText.Text + ", " + ViscosidadText.Text + ", " + CtdAguaText.Text + ",GETDATE())"; cmd = new SqlCommand(sq, c.regresaConexion()); MessageBox.Show("Reporte Insertado"); cmd.ExecuteNonQuery(); ClaveText.Text = ""; FolioText.Text = ""; TurnoCombo.Text = ""; EsmalteCombo.Text = ""; LoteText.Text = ""; OperadorText.Text = ""; MolinoCombo.Text = ""; TiempoText.Text = ""; DensidadText.Text = ""; ResiduoText.Text = ""; ViscosidadText.Text = ""; CtdAguaText.Text = ""; cargarDatos(dataGridBaseDatos); } } } } catch (Exception ex) { MessageBox.Show("error de inserccion" + ex); } c.cerrarConexion(); }