public void MuestraProductos() { comboProducto.Items.Clear(); try { c = new conexion(); adaptador = new SqlDataAdapter("SELECT * FROM VENTAS.T_PRODUCTOS", c.regresaConexion()); tabla = new DataTable(); adaptador.Fill(tabla); for (int i = 0; i < tabla.Rows.Count; i++) { comboProducto.Items.Add(tabla.Rows[i][0] + " - " + tabla.Rows[i][1] + " - $" + string.Format("{0:0.00}", tabla.Rows[i][2])); } c.cerrarConexion(); if (comboProducto.Items.Count > 0) { comboProducto.SelectedIndex = 0; } } catch (Exception ex) { MessageBox.Show("Error al consultar datos de Productos. Error: " + ex, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); c.cerrarConexion(); } }
//agregar ejercicio a una rutina private void botonAgregarEjercicio_Click(object sender, EventArgs e) { if (numericDuracion.Value == 0) //valida que la duración del ejercicio sea mayor a 0 { MessageBox.Show("Duración invalida"); } else { string idRutina = ""; c = new conexion(); try { cmd = new SqlCommand("SELECT id_Rutina FROM RUTINAS.T_RUTINAS WHERE id_Rutina = '" + dataGridRutina.Rows[dataGridRutina.CurrentRow.Index].Cells[0].Value.ToString() + "'", c.regresaConexion()); //cmd.ExecuteNonQuery(); dr = cmd.ExecuteReader(); if (dr.Read()) { idRutina = (Convert.ToString(dr["id_Rutina"])); } else { c.cerrarConexion(); return; } c.cerrarConexion(); ////// c = new conexion(); string sq = "INSERT INTO RUTINAS.T_EJERCICIOS VALUES ('" + textoNombreEjercicio.Text + "'," + numericDuracion.Value + "," + idRutina + ")"; cmd = new SqlCommand(sq, c.regresaConexion()); cmd.ExecuteNonQuery(); cargarDatosEjercicio(); } catch (Exception ex) { MessageBox.Show("Error"); } c.cerrarConexion(); textoNombreEjercicio.Text = ""; numericDuracion.Value = 0; } }
//modificar rutina private void botonModificarRutina_Click(object sender, EventArgs e) { c = new conexion(); try { string sq = "UPDATE RUTINAS.T_RUTINAS SET nombre_Rutina = '" + textoNombreRutina.Text + "', descripcion = '" + textoDescripcion.Text + "' WHERE id_Rutina = " + dataGridRutina.Rows[dataGridRutina.CurrentRow.Index].Cells[0].Value.ToString(); cmd = new SqlCommand(sq, c.regresaConexion()); cmd.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show("Error"); } c.cerrarConexion(); cargarDatosRutina(); }
//eliminar una rutina private void botonEliminarRutina_Click(object sender, EventArgs e) { c = new conexion(); try { string sq = "DELETE FROM RUTINAS.T_RUTINAS WHERE id_Rutina = " + dataGridRutina.Rows[dataGridRutina.CurrentRow.Index].Cells[0].Value.ToString(); cmd = new SqlCommand(sq, c.regresaConexion()); cmd.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show("Error"); } c.cerrarConexion(); cargarDatosRutina(); }
public void MuestraVentas() { try { c = new conexion(); adaptador = new SqlDataAdapter("SELECT * FROM VENTAS.T_VENTAS", c.regresaConexion()); tabla = new DataTable(); adaptador.Fill(tabla); dataGridVenta.DataSource = tabla; c.cerrarConexion(); } catch (Exception ex) { MessageBox.Show("Error al consultar datos de Ventas. Error: " + ex, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); c.cerrarConexion(); } }
public void MuestraDatos(DataGridView d) { try { c = new conexion(); adaptador = new SqlDataAdapter("SELECT * FROM VENTAS.T_PRODUCTOS", c.regresaConexion()); tabla = new DataTable(); adaptador.Fill(tabla); d.DataSource = tabla; c.cerrarConexion(); } catch (Exception e) { MessageBox.Show("No se pudo consultar datos " + e.ToString()); c.cerrarConexion(); } }
//insertar un nuevo valor private void botonAgregar_Click(object sender, EventArgs e) { c = new conexion(); try { textoMonto.Text = textoMonto.Text.Remove(0, 1); // quitar el $ string sq = "INSERT INTO GENERAL.T_DETALLE_PAGOS VALUES (" + textoMonto.Text + ", GETDATE()," + "'" + comboTipo.SelectedItem + "'," + textoClave.Text + ")"; cmd = new SqlCommand(sq, c.regresaConexion()); cmd.ExecuteNonQuery(); textoMonto.Text.Insert(0, "$"); //agrega el $ cargarDatos(); } catch (Exception ex) { MessageBox.Show("error de insercion"); } c.cerrarConexion(); }
//elimina un ejercicio private void botonEliminarEjercicio_Click(object sender, EventArgs e) { c = new conexion(); try { string sq = "DELETE FROM RUTINAS.T_EJERCICIOS WHERE id_Ejercicio = " + dataGridEjercicio.Rows[dataGridEjercicio.CurrentRow.Index].Cells[0].Value.ToString(); cmd = new SqlCommand(sq, c.regresaConexion()); cmd.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show("Error"); } c.cerrarConexion(); cargarDatosEjercicio(); textoNombreEjercicio.Text = ""; numericDuracion.Value = 0; }
private void botonAgregar_Click(object sender, EventArgs e) { string idSocio = comboSocio.Text; string idRutina = comboRutina.Text.Split('.')[0]; c = new conexion(); try { string sq = "INSERT INTO RUTINAS.T_RUTINAXSOCIO VALUES ('" + idRutina + "','" + idSocio + "')"; cmd = new SqlCommand(sq, c.regresaConexion()); cmd.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show("No se inserto la rutina"); } c.cerrarConexion(); cargarRutinas(); }
private void botonModificar_Click(object sender, EventArgs e) { string idSocio = comboSocio.Text; string idRutina = comboRutina.Text.Split('.')[0]; c = new conexion(); try { string sq = "UPDATE RUTINAS.T_RUTINAXSOCIO SET id_Rutina = " + idRutina + " WHERE id_Rutina = " + dataGridRutina.Rows[dataGridRutina.CurrentRow.Index].Cells[0].Value.ToString() + " AND id_Socio = " + idSocio; cmd = new SqlCommand(sq, c.regresaConexion()); cmd.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show("Error al modificar rutina", ex.ToString()); } c.cerrarConexion(); cargarRutinas(); }
private void botonEliminar_Click(object sender, EventArgs e) { string idSocio = comboSocio.Text; string idRutina = comboRutina.Text.Split('.')[0]; c = new conexion(); try { string sq = "DELETE FROM RUTINAS.T_RUTINAXSOCIO WHERE id_Rutina = '" + idRutina + "' AND id_Socio = '" + idSocio + "'"; cmd = new SqlCommand(sq, c.regresaConexion()); cmd.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show("Error al eliminar"); } c.cerrarConexion(); cargarRutinas(); }
//agregar una rutina private void botonAgregarRutina_Click(object sender, EventArgs e) { string idplan = ""; c = new conexion(); try { /////// cmd = new SqlCommand("SELECT id_Plan FROM RUTINAS.T_PLAN WHERE tipo_Plan = '" + comboPlan.SelectedItem + "'", c.regresaConexion()); //cmd.ExecuteNonQuery(); dr = cmd.ExecuteReader(); if (dr.Read()) { idplan = (Convert.ToString(dr["id_Plan"])); } else { c.cerrarConexion(); return; } ////// c = new conexion(); string sq = "INSERT INTO RUTINAS.T_RUTINAS VALUES ('" + textoNombreRutina.Text + "','" + textoDescripcion.Text + "'," + idplan + ")"; cmd = new SqlCommand(sq, c.regresaConexion()); cmd.ExecuteNonQuery(); cargarDatosRutina(); } catch (Exception ex) { MessageBox.Show("Error"); } c.cerrarConexion(); dataGridEjercicio.DataSource = null; textoDescripcion.Text = textoNombreRutina.Text = ""; }
private void botonModificar_Click(object sender, EventArgs e) { try { c = new conexion(); cmd = new SqlCommand("UPDATE GENERAL.T_SOCIO SET nombre_Socio = '" + textoNombre.Text + "', direccion_Socio = '" + textoDireccion.Text + "', peso_Socio = " + numericPeso.Value.ToString().Replace(",", ".") + ", altura_Socio = " + numericEstatura.Value.ToString().Replace(",", ".") + ", ocupacion_Socio = '" + textoOcupacion.Text + "', vigencia = '" + textoVigencia.Text + "' WHERE id_Socio = " + textoClave.Text + ";", c.regresaConexion()); cmd.ExecuteNonQuery(); c.cerrarConexion(); MessageBox.Show("Socio modificado"); MuestraDatos(dataGridSocio); } catch (Exception ex) { MessageBox.Show("No se pudo modificar" + ex.ToString()); c.cerrarConexion(); } }
//carga la tabla de rutinas public void cargarDatosRutina() { string idplan = ""; c = new conexion(); try { cmd = new SqlCommand("SELECT id_Plan FROM RUTINAS.T_PLAN WHERE tipo_Plan = '" + comboPlan.SelectedItem + "'", c.regresaConexion()); //cmd.ExecuteNonQuery(); dr = cmd.ExecuteReader(); if (dr.Read()) { idplan = (Convert.ToString(dr["id_Plan"])); } else { c.cerrarConexion(); return; } c.cerrarConexion(); c = new conexion(); da = new SqlDataAdapter("SELECT id_Rutina AS Rutina, nombre_Rutina AS Nombre, descripcion AS Descripción FROM RUTINAS.T_RUTINAS WHERE id_Plan = " + idplan, c.regresaConexion()); dt = new DataTable(); da.Fill(dt); dataGridRutina.DataSource = dt; } catch (Exception ex) { MessageBox.Show("No se pudo actualizar. Error: " + ex); } c.cerrarConexion(); }
public void cargarRutinasCompletas() { ds = new DataSet(); c = new conexion(); try { adaptador = new SqlDataAdapter("SELECT id_Rutina,nombre_Rutina FROM RUTINAS.T_RUTINAS ", c.regresaConexion()); adaptador.Fill(ds); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { comboRutina.Items.Add(ds.Tables[0].Rows[i][0].ToString() + ".-" + " " + ds.Tables[0].Rows[i][1].ToString()); } } catch (Exception ex) { MessageBox.Show("No se cargaron las rutinas", ex.ToString()); } c.cerrarConexion(); }
//carga datos de ejericcios public void cargarDatosEjercicio() { string idRutina = ""; c = new conexion(); try { cmd = new SqlCommand("SELECT id_Rutina FROM RUTINAS.T_RUTINAS WHERE id_Rutina = '" + dataGridRutina.Rows[dataGridRutina.CurrentRow.Index].Cells[0].Value.ToString() + "'", c.regresaConexion()); //cmd.ExecuteNonQuery(); dr = cmd.ExecuteReader(); if (dr.Read()) { idRutina = (Convert.ToString(dr["id_Rutina"])); } else { c.cerrarConexion(); return; } c.cerrarConexion(); c = new conexion(); da = new SqlDataAdapter("SELECT id_Ejercicio AS Ejercicio, nombre_Ejercicio AS Nombre, duracion AS Duración FROM RUTINAS.T_EJERCICIOS WHERE id_Rutina = " + idRutina, c.regresaConexion()); dt = new DataTable(); da.Fill(dt); dataGridEjercicio.DataSource = dt; } catch (Exception ex) { MessageBox.Show("Error"); } c.cerrarConexion(); }
private void botonEliminar_Click(object sender, EventArgs e) { try { c = new conexion(); cmd = new SqlCommand("DELETE FROM GENERAL.T_SOCIO WHERE id_Socio = " + textoClave.Text, c.regresaConexion()); cmd.ExecuteNonQuery(); c.cerrarConexion(); MuestraDatos(dataGridSocio); MessageBox.Show("Socio Eliminado"); textoClave.Text = ""; textoDireccion.Text = ""; textoNombre.Text = ""; textoOcupacion.Text = ""; textoVigencia.Text = ""; numericEstatura.Value = 0; numericPeso.Value = 0; } catch (Exception ex) { MessageBox.Show("No se pudo eliminar datos " + ex.ToString()); c.cerrarConexion(); } }
public void CargaDetallesVenta(int idV) { c = new conexion(); for (int i = 0; i < listaProductos.Items.Count; i++) { try { cmd = new SqlCommand("INSERT INTO VENTAS.T_DETALLE_VENTAS(id_Venta, id_Producto, cantidad, subtotal) VALUES(" + idV + ", " + listaProductos.Items[i].SubItems[0].Text + ", " + listaProductos.Items[i].SubItems[3].Text + ", " + (float.Parse(listaProductos.Items[i].SubItems[2].Text) * float.Parse(listaProductos.Items[i].SubItems[3].Text)) + ")", c.regresaConexion()); cmd.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show("No se pudo insertar el detalle. Error: " + ex, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } } c.cerrarConexion(); MuestraVentas(); }
private void botonAgregar_Click(object sender, EventArgs e) { bool existe = false; try { if (dataGridProducto.RowCount == 0) { c = new conexion(); cmd = new SqlCommand("INSERT INTO VENTAS.T_PRODUCTOS(nombre_Producto, precio_Producto, cantidad_Producto) VALUES('" + textoNombre.Text + "', " + numericPrecio.Text.Replace(",", ".") + ", " + numericCantidad.Text.Replace(",", ".") + ")", c.regresaConexion()); cmd.ExecuteNonQuery(); c.cerrarConexion(); MessageBox.Show("Producto insertado"); textoNombre.Text = ""; numericCantidad.Value = 0; numericPrecio.Value = 0; } else { for (int i = 0; i < dataGridProducto.RowCount; i++) { // dataGridProducto.Columns[3]; if (dataGridProducto.Rows[i].Cells[1].Value.ToString() == textoNombre.Text) { existe = true; } } if (existe == false) { c = new conexion(); cmd = new SqlCommand("INSERT INTO VENTAS.T_PRODUCTOS(nombre_Producto, precio_Producto, cantidad_Producto) VALUES('" + textoNombre.Text + "', " + numericPrecio.Text.Replace(",", ".") + ", " + numericCantidad.Text.Replace(",", ".") + ")", c.regresaConexion()); cmd.ExecuteNonQuery(); c.cerrarConexion(); MessageBox.Show("Producto insertado"); textoNombre.Text = ""; numericCantidad.Value = 0; numericPrecio.Value = 0; } else { MessageBox.Show("Nombre del producto existente"); } } MuestraDatos(dataGridProducto); } catch (Exception ex) { MessageBox.Show("No se pudo insertar" + ex.ToString()); c.cerrarConexion(); } }
public void cargarRutinas() { string idSocio = comboSocio.Text; List <string> idRutinas = new List <string>(); c = new conexion(); try { cmd = new SqlCommand("SELECT * FROM RUTINAS.T_RUTINAXSOCIO WHERE id_Socio = " + idSocio + "", c.regresaConexion()); dr = cmd.ExecuteReader(); if (dr.HasRows) { while (dr.Read()) { idRutinas.Add(dr["id_Rutina"].ToString()); } } } catch (Exception ex) { MessageBox.Show("No se cargaron las rutinas"); } c.cerrarConexion(); //..........................................................// c = new conexion(); dt = new DataTable(); for (int i = 0; i < idRutinas.Count; i++) { try { adaptador = new SqlDataAdapter("SELECT * FROM RUTINAS.T_RUTINAS WHERE id_Rutina = '" + idRutinas.ElementAt(i) + "'", c.regresaConexion()); adaptador.Fill(dt); } catch (Exception ex) { MessageBox.Show("No se pudo actualizar"); } } dataGridRutina.DataSource = dt; c.cerrarConexion(); }
private void botonEliminar_Click(object sender, EventArgs e) { if (dataGridVenta.SelectedRows.Count > 0) { int idV = int.Parse(dataGridVenta.CurrentRow.Cells[0].Value.ToString()); try { c = new conexion(); cmd = new SqlCommand("DELETE FROM VENTAS.T_DETALLE_VENTAS WHERE id_Venta = " + idV, c.regresaConexion()); cmd.ExecuteNonQuery(); cmd = new SqlCommand("DELETE FROM VENTAS.T_VENTAS WHERE id_Venta = " + idV, c.regresaConexion()); cmd.ExecuteNonQuery(); MuestraVentas(); FormatoCarrito(); } catch (Exception ex) { MessageBox.Show("No se pudo eliminar. Error: " + ex, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Selecciona la venta que quieres Cancelar", "INFORMACIÓN", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
//buscar socios al teclear id private void textoClave_TextChanged(object sender, EventArgs e) { if (textoClave.Text == "") { textoNombre.Text = ""; botonAgregar.Enabled = false;//evitar mandar datos nulos return; } c = new conexion(); try { textoNombre.Text = ""; cmd = new SqlCommand("SELECT nombre_Socio FROM GENERAL.T_SOCIO WHERE id_Socio = " + textoClave.Text, c.regresaConexion()); //cmd.ExecuteNonQuery(); dr = cmd.ExecuteReader(); if (dr.Read()) { textoNombre.Text = (Convert.ToString(dr["nombre_Socio"])); botonAgregar.Enabled = true;//evitar mandar datos nulos } else { botonAgregar.Enabled = false;//evitar mandar datos nulos } } catch (Exception ex) { botonAgregar.Enabled = false;//evitar mandar datos nulos //MessageBox.Show("no funciona"); } c.cerrarConexion(); }
private void botonAgregarProducto_Click(object sender, EventArgs e) { if (comboProducto.SelectedIndex >= 0 && numericCantidad.Value > 0) { int id = int.Parse(comboProducto.Items[comboProducto.SelectedIndex].ToString().Substring(0, comboProducto.Items[comboProducto.SelectedIndex].ToString().IndexOf(' '))); if (BuscaProducto(id) == false) { try { c = new conexion(); adaptador = new SqlDataAdapter("SELECT * FROM VENTAS.T_PRODUCTOS WHERE id_Producto = " + id, c.regresaConexion()); tabla = new DataTable(); adaptador.Fill(tabla); if (int.Parse(tabla.Rows[0][3].ToString()) >= numericCantidad.Value) { ListViewItem l = new ListViewItem(tabla.Rows[0][0].ToString()); l.SubItems.Add(tabla.Rows[0][1].ToString()); l.SubItems.Add("" + string.Format("{0:0.00}", tabla.Rows[0][2])); l.SubItems.Add(numericCantidad.Value.ToString()); l.SubItems.Add("" + string.Format("{0:0.00}", float.Parse(tabla.Rows[0][2].ToString()) * float.Parse(numericCantidad.Value.ToString()))); listaProductos.Items.Add(l); c.cerrarConexion(); CalculaTotal(); } else { MessageBox.Show("Las existencias del producto seleccionado no cubren la cantidad solicitada. Quedan: " + tabla.Rows[0][3].ToString(), "INFORMACIÓN", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show("Error al consultar datos de Productos. Error: " + ex, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); c.cerrarConexion(); } } else { MessageBox.Show("El producto ya se encuentra en el carrito. Para hacer cambios deberás quitarlo de este y volverlo a agregar", "INFORMACIÓN", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("No se ha seleccionado un producto o su cantidad es 0", "INFORMACIÓN", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void textoClave_TextChanged(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(textoClave.Text) == false) { textoNombre.Text = ""; if (VerificaClave() == true) { try { c = new conexion(); cmd = new SqlCommand("SELECT nombre_Socio FROM GENERAL.T_SOCIO WHERE id_Socio = " + int.Parse(textoClave.Text), c.regresaConexion()); SqlDataReader r = cmd.ExecuteReader(); while (r.Read()) { textoNombre.Text = r.GetString(0); } if (textoNombre.Text == "") { MessageBox.Show("Socio no encontrado.", "INFORMACIÓN", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show("Error al consultar datos del Socio. Error: " + ex, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); c.cerrarConexion(); } } else { MessageBox.Show("La clave es numérica, no puede contener otros caracteres", "INFORMACIÓN", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { if (textoClave.Text != "") { MessageBox.Show("La clave está vacía o sólo contiene espacios en blanco", "INFORMACIÓN", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
public void CargaCarrito(int idV) { DataTable aux; FormatoCarrito(); try { c = new conexion(); adaptador = new SqlDataAdapter("SELECT id_Producto, cantidad FROM VENTAS.T_DETALLE_VENTAS WHERE id_Venta = " + idV, c.regresaConexion()); tabla = new DataTable(); adaptador.Fill(tabla); c.cerrarConexion(); for (int i = 0; i < tabla.Rows.Count; i++) { c = new conexion(); adaptador = new SqlDataAdapter("SELECT * FROM VENTAS.T_PRODUCTOS WHERE id_Producto = " + tabla.Rows[i][0], c.regresaConexion()); aux = new DataTable(); adaptador.Fill(aux); ListViewItem l = new ListViewItem(aux.Rows[0][0].ToString()); l.SubItems.Add(aux.Rows[0][1].ToString()); l.SubItems.Add("" + string.Format("{0:0.00}", aux.Rows[0][2])); l.SubItems.Add(tabla.Rows[i][1].ToString()); l.SubItems.Add("" + string.Format("{0:0.00}", float.Parse(aux.Rows[0][2].ToString()) * float.Parse(tabla.Rows[i][1].ToString()))); listaProductos.Items.Add(l); c.cerrarConexion(); CalculaTotal(); } } catch (Exception ex) { MessageBox.Show("No se ha podiddo leer el detalle de venta Error: " + ex, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void botonModificar_Click(object sender, EventArgs e) { try { c = new conexion(); cmd = new SqlCommand("UPDATE VENTAS.T_PRODUCTOS SET nombre_Producto = '" + textoNombre.Text + "', precio_Producto = " + numericPrecio.Value.ToString().Replace(",", ".") + ", cantidad_Producto = " + numericCantidad.Value.ToString().Replace(",", ".") + " WHERE id_Producto = " + dataGridProducto.CurrentRow.Cells[0].Value.ToString() + ";", c.regresaConexion()); cmd.ExecuteNonQuery(); c.cerrarConexion(); MessageBox.Show("Producto modificado"); MuestraDatos(dataGridProducto); } catch (Exception ex) { MessageBox.Show("No se pudo modificar" + ex.ToString()); c.cerrarConexion(); } }
private void botonEliminar_Click(object sender, EventArgs e) { try { c = new conexion(); cmd = new SqlCommand("DELETE FROM VENTAS.T_PRODUCTOS WHERE id_Producto = " + dataGridProducto.CurrentRow.Cells[0].Value.ToString(), c.regresaConexion()); cmd.ExecuteNonQuery(); c.cerrarConexion(); MuestraDatos(dataGridProducto); MessageBox.Show("Producto Eliminado"); textoNombre.Text = ""; numericCantidad.Value = 0; numericPrecio.Value = 0; } catch (Exception ex) { MessageBox.Show("No se pudo eliminar datos " + ex.ToString()); c.cerrarConexion(); } }
private void botonAgregar_Click(object sender, EventArgs e) { try { c = new conexion(); cmd = new SqlCommand("INSERT INTO GENERAL.T_SOCIO(nombre_Socio, direccion_Socio, peso_Socio, altura_Socio, ocupacion_Socio, vigencia) VALUES('" + textoNombre.Text + "','" + textoDireccion.Text + "', " + numericPeso.Text.Replace(",", ".") + ", " + numericEstatura.Text.Replace(",", ".") + ",'" + textoOcupacion.Text + "','" + textoVigencia.Text + "')", c.regresaConexion()); cmd.ExecuteNonQuery(); c.cerrarConexion(); MessageBox.Show("Socio insertado"); MuestraDatos(dataGridSocio); } catch (Exception ex) { MessageBox.Show("No se pudo insertar" + ex.ToString()); c.cerrarConexion(); } }
private void botonAgregar_Click(object sender, EventArgs e) { if (textoNombre.Text != "") { if (float.Parse(textoTotal.Text) > 0) { try { int id; textoFecha.Text = DateTime.Now.ToString("yyyy-MM-dd"); c = new conexion(); cmd = new SqlCommand("INSERT INTO VENTAS.T_VENTAS(fecha, total, id_Socio) VALUES('" + textoFecha.Text + "', " + 0 + ", " + textoClave.Text + ")", c.regresaConexion()); cmd.ExecuteNonQuery(); c.cerrarConexion(); adaptador = new SqlDataAdapter("SELECT id_Venta FROM VENTAS.T_VENTAS", c.regresaConexion()); tabla = new DataTable(); adaptador.Fill(tabla); id = int.Parse(tabla.Rows[tabla.Rows.Count - 1][0].ToString()); c.cerrarConexion(); MuestraVentas(); CargaDetallesVenta(id); listaProductos.Clear(); textoClave.Text = ""; numericCantidad.Value = 1; textoNombre.Text = ""; } catch (Exception ex) { MessageBox.Show("No se pudo registrar la venta. Error: " + ex, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Seleccione al menos un producto", "INFORMACIÓN", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("Especifique un socio válido para continuar", "INFORMACIÓN", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public void cargarSocio() { ds = new DataSet(); c = new conexion(); try { adaptador = new SqlDataAdapter("SELECT id_Socio FROM GENERAL.T_SOCIO ", c.regresaConexion()); adaptador.Fill(ds); comboSocio.DataSource = ds.Tables[0].DefaultView; comboSocio.ValueMember = "id_Socio"; } catch (Exception ex) { MessageBox.Show("No se cargo el socio"); } }