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"); } }
private void btnNuevo_Click(object sender, EventArgs e) { 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 = ""; miforma.Descripcion = ""; miforma.Unidad = ""; miforma.Marca = ""; miforma.PC = ""; miforma.PV = ""; miforma.Cantidad = ""; miforma.Localizacion = ""; 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.InsertarProducto(arregloaEscribir); MessageBox.Show("Se guardo Correctamente "); MostrarProductos(); //MessageBox.Show(miforma.escrito); } catch (Exception ex) { if (ex.Message.ToLower().Contains("duplicate entry")) { MessageBox.Show("Existe un producto con la clave indicada.", "Producto Duplicado", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { MessageBox.Show("No se pudo insertar por:" + ex.Message.ToLower()); } } } if (resultado == DialogResult.Cancel) { MessageBox.Show("No ejecutaste la operacion"); } }