private void btnInsertar_Click(object sender, EventArgs e) { if (this.editar == false) { try { if (ChequeoCamposCompletos()) { objCNProductos.InsertarProductos(txtNombre.Text, (this.cbSector.SelectedIndex + 1).ToString(), txtPrecio.Text, txtStock.Text); MessageBox.Show("Se insertó correctamente"); MostrarProductos(); LimpiarCampos(); } else { MessageBox.Show("Complete todos los campos", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); } } else { if (ChequeoCamposCompletos()) { try { objCNProductos.EditarProducto(txtNombre.Text, (this.cbSector.SelectedIndex + 1).ToString(), txtPrecio.Text, txtStock.Text, this.idProducto); MessageBox.Show("Se Edito correctamente"); MostrarProductos(); LimpiarCampos(); this.editar = false; } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); } } else { MessageBox.Show("Complete todos los campos", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void btnGuardar_Click(object sender, EventArgs e) { if (Editar == false) { objectCN.InsertarProducto(txtNombre.Text, txtDescripcion.Text, txtMarca.Text, txtPrecio.Text, txtStock.Text); MessageBox.Show("Se registro Correctamente"); Limpiar(); MostrarProductos(); } if (Editar == true) { try { objectCN.EditarProducto(txtNombre.Text, txtDescripcion.Text, txtMarca.Text, txtPrecio.Text, txtStock.Text, idProducto); MessageBox.Show("Se modifico Correctamente"); MostrarProductos(); Limpiar(); Editar = false; }catch (Exception e2) { throw e2; } } }
private void btnEditar_Click(object sender, EventArgs e) { if (dataGridView1.SelectedRows.Count > 0) { //escrito["Nombre"] como en la base de datos //txtClave.Text = dataGridView1.CurrentRow.Cells["Clave"].Value.ToString(); Producto miforma = new Producto(); //miforma.Owner = this; //miforma.StartPosition = FormStartPosition.CenterParent; int X1 = (this.Parent.Parent.Location.X + (this.Parent.Parent.Width / 2)) - miforma.Width / 2; int Y1 = (this.Parent.Parent.Location.Y + (this.Parent.Parent.Height / 2)) - miforma.Height / 2; Point location = new Point(X1, Y1); MessageBox.Show("Resultado " + X1.ToString() + " " + Y1.ToString()); MessageBox.Show("BaseDeDatosForm " + this.Top.ToString() + " " + this.Left.ToString()); MessageBox.Show("Contenedor " + this.Parent.Top.ToString() + " " + this.Parent.Left.ToString()); MessageBox.Show("Form " + this.Parent.Parent.Top.ToString() + " " + this.Parent.Parent.Left.ToString() + " " + this.Parent.Parent.Width + " " + this.Parent.Parent.Height); miforma.Clave = dataGridView1.CurrentRow.Cells["Clave"].Value.ToString(); miforma.Descripcion = dataGridView1.CurrentRow.Cells["Descripcion"].Value.ToString(); miforma.Unidad = dataGridView1.CurrentRow.Cells["Unidad"].Value.ToString(); miforma.Marca = dataGridView1.CurrentRow.Cells["Marca"].Value.ToString(); miforma.PC = dataGridView1.CurrentRow.Cells["Precio_Compra"].Value.ToString(); miforma.PV = dataGridView1.CurrentRow.Cells["Precio_Venta"].Value.ToString(); miforma.Cantidad = dataGridView1.CurrentRow.Cells["Cantidad"].Value.ToString(); miforma.Localizacion = dataGridView1.CurrentRow.Cells["Localizacion"].Value.ToString(); miforma.StartPosition = System.Windows.Forms.FormStartPosition.Manual; miforma.Location = location; DialogResult resultado = miforma.ShowDialog(); if (resultado == DialogResult.OK) { try { //objetoCN.EditarProducto(txtClave.Text, txtDesc.Text, txtMarca.Text, txtPV.Text, txtStock.Text, idProducto); //MessageBox.Show("Se edito Correctamente"); ////MostrarProductos(); //limpiarForm(); //Editar = false; Console.WriteLine("================impresion de txtboxes"); string[] arregloaEscribir; arregloaEscribir = miforma.escrito; foreach (var item in arregloaEscribir) { Console.WriteLine(item.ToString()); } Console.WriteLine("================fin de impresion de txtboxes"); objetoCN.EditarProducto(arregloaEscribir); MessageBox.Show("Se edito Correctamente "); MostrarProductos(); //MessageBox.Show(miforma.escrito); } catch (Exception ex) { MessageBox.Show("No se pudo editar por:" + ex); } } if (resultado == DialogResult.Cancel) { MessageBox.Show("No ejecutaste la operacion"); } } else { MessageBox.Show("seleccionar una fila por favor"); } }