private void btnAgregar_Click(object sender, EventArgs e) { if (txtCantidad.Text == "") { MessageBox.Show("Falta cantidad", "Atencion", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } DetalleProducto det; Categoria cat; UnidadMedida u; UnidadMedida uT; if (DGVEstructuraProductos.Rows.Count == 0) { det = new DetalleProducto(); cat = new Categoria(); u = new UnidadMedida(); uT = new UnidadMedida(); det.idProductoPadre = int.Parse(DGVProductos.SelectedRows[0].Cells["idProduct"].Value.ToString()); det.idProducto = int.Parse(DGVProductosAAgregar.SelectedRows[0].Cells["idProd"].Value.ToString()); det.Nombre = DGVProductosAAgregar.SelectedRows[0].Cells["nombreProductoAAgregar"].Value.ToString(); cat.IDCategoria = int.Parse(DGVProductosAAgregar.SelectedRows[0].Cells["idCategoriaAAgregar"].Value.ToString()); cat.Nombre = DGVProductosAAgregar.SelectedRows[0].Cells["categoriaAAgregar"].Value.ToString(); det.cantidad = double.Parse(txtCantidad.Text); u.IDUnidad = int.Parse(DGVProductosAAgregar.SelectedRows[0].Cells["idUnidadAAgregar"].Value.ToString()); u.Nombre = DGVProductosAAgregar.SelectedRows[0].Cells["unidadMedidaAAgregar"].Value.ToString(); det.cantidadProductos = double.Parse(DGVProductosAAgregar.SelectedRows[0].Cells["cantidadDeProductos1"].Value.ToString()); det.tiempoProduccion = double.Parse(DGVProductosAAgregar.SelectedRows[0].Cells["tiempoProduccion1"].Value.ToString()); uT.Nombre = DGVProductosAAgregar.SelectedRows[0].Cells["unidadTiempo1"].Value.ToString(); DGVEstructuraProductos.Rows.Add(det.idProductoPadre, det.idProducto, det.Nombre, det.cantidad, cat.Nombre, det.cantidadProductos, u.Nombre, det.tiempoProduccion, uT.Nombre); } else { int band = 0; if (estructuraProductoSeleccionado == false) { for (int i = 0; i < DGVEstructuraProductos.Rows.Count; i++) { if (int.Parse(DGVEstructuraProductos.Rows[i].Cells["idProducto"].Value.ToString()) == int.Parse(DGVProductosAAgregar.SelectedRows[0].Cells["idProd"].Value.ToString())) { band = 1; DGVEstructuraProductos.Rows[i].Cells["cantidad"].Value = txtCantidad.Text; break; } } if (band == 0) { det = new DetalleProducto(); cat = new Categoria(); u = new UnidadMedida(); uT = new UnidadMedida(); det.idProductoPadre = int.Parse(DGVProductos.SelectedRows[0].Cells["idProduct"].Value.ToString()); det.idProducto = int.Parse(DGVProductosAAgregar.SelectedRows[0].Cells["idProd"].Value.ToString()); det.Nombre = DGVProductosAAgregar.SelectedRows[0].Cells["nombreProductoAAgregar"].Value.ToString(); cat.IDCategoria = int.Parse(DGVProductosAAgregar.SelectedRows[0].Cells["idCategoriaAAgregar"].Value.ToString()); cat.Nombre = DGVProductosAAgregar.SelectedRows[0].Cells["categoriaAAgregar"].Value.ToString(); det.cantidad = double.Parse(txtCantidad.Text); u.IDUnidad = int.Parse(DGVProductosAAgregar.SelectedRows[0].Cells["idUnidadAAgregar"].Value.ToString()); u.Nombre = DGVProductosAAgregar.SelectedRows[0].Cells["unidadMedidaAAgregar"].Value.ToString(); det.cantidadProductos = double.Parse(DGVProductosAAgregar.SelectedRows[0].Cells["cantidadDeProductos1"].Value.ToString()); det.tiempoProduccion = double.Parse(DGVProductosAAgregar.SelectedRows[0].Cells["tiempoProduccion1"].Value.ToString()); uT.Nombre = DGVProductosAAgregar.SelectedRows[0].Cells["unidadTiempo1"].Value.ToString(); DGVEstructuraProductos.Rows.Add(det.idProductoPadre, det.idProducto, det.Nombre, det.cantidad, cat.Nombre, det.cantidadProductos, u.Nombre, det.tiempoProduccion, uT.Nombre); } } else { DGVEstructuraProductos.SelectedRows[0].Cells["cantidad"].Value = txtCantidad.Text; } } btnAgregar.Enabled = false; DGVEstructuraProductos.Enabled = true; DGVProductosAAgregar.Enabled = true; }
public static void Insert(DetalleProducto det, SqlConnection cn, SqlTransaction tran) { Acceso ac = new Acceso(); //SqlConnection conexion = new SqlConnection(ac.getCadenaConexion()); SqlCommand cmd = new SqlCommand("Insert into DetalleProducto (idProducto, idProductoDetalle, cantidad) VALUES (@idprodpadre,@idprod,@cantida)", cn); cmd.Parameters.AddWithValue("@idprodpadre", det.idProductoPadre); cmd.Parameters.AddWithValue("@idprod", det.idProducto); cmd.Parameters.AddWithValue("@cantida", det.cantidad); try { cmd.Connection = cn; cmd.Transaction = tran; cmd.CommandType = CommandType.Text; cmd.ExecuteNonQuery(); } catch (ArgumentException ex) { throw new ApplicationException(ex.Message); } catch (SqlException ex) { throw new ApplicationException("Error en BD: " + ex.Message); } }
private void btnGuardar_Click(object sender, EventArgs e) { List<DetalleProducto> lista = new List<DetalleProducto>(); //if (eliminarEstructura == false) //{ if (lblDetalle.Text == "") { MessageBox.Show(this, "Falta seleccionar Producto", "Atencion", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (DGVEstructuraProductos.RowCount == 0) { MessageBox.Show(this, "Falta asignarle al menos un producto al detalle", "Atencion", MessageBoxButtons.OK, MessageBoxIcon.Information); txtCantidad.Focus(); return; } for (int i = 0; i < DGVEstructuraProductos.RowCount; i++) { DetalleProducto detalleProducto = new DetalleProducto(); detalleProducto.idProductoPadre = int.Parse(DGVEstructuraProductos.Rows[i].Cells["idProductoPadre"].Value.ToString()); detalleProducto.idProducto = int.Parse(DGVEstructuraProductos.Rows[i].Cells["idProducto"].Value.ToString()); detalleProducto.cantidad = double.Parse(DGVEstructuraProductos.Rows[i].Cells["cantidad"].Value.ToString()); lista.Add(detalleProducto); } //} if (lblAccion.Text == "NUEVA ESTRUCTURA") { try { if (MessageBox.Show(this, "¿Desea confirmar nueva estructura?", "Confirmar Nueva Estructura", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes ) { gestor.tomarDetalleProductos(lista); gestor.nuevaEstructura(); MessageBox.Show("Nueva Estructura Registrada con Exito", "Exito", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); DGVEstructuraProductos.Enabled = false; } else return; } catch (ApplicationException ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); } } if (lblAccion.Text == "MODIFICAR ESTRUCTURA") { gestor.tomarDetalleProductos(lista); gestor.tomarIdProductoPadre(int.Parse(DGVEstructuraProductos.Rows[0].Cells["idProductoPadre"].Value.ToString())); try { gestor.modificacionConfirmada(); MessageBox.Show("Modificacion de Estructura Registrada con Exito", "Exito", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); DGVEstructuraProductos.Enabled = false; } catch (ApplicationException ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); } } //if (lblAccion.Text == "ELIMINAR ESTRUCTURA") //{ // gestor.tomarIdProductoPadre(int.Parse(DGVProductos.SelectedRows[0].Cells[7].Value.ToString())); // try // { // gestor.eliminacionConfirmada(); // MessageBox.Show("Eliminada Estructura con Exito", "Exito", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); // } // catch (ApplicationException ex) // { // MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); // } //} cargarGrillaProductos("todo"); txtCantidad.Text = ""; btnNuevo.Enabled = true; btnModificar.Enabled = true; btn_eliminar.Enabled = true; btnGuardar.Enabled = false; btnCancelar.Enabled = false; btnAgregar.Enabled = false; btnSacar.Enabled = false; lblAccion.Text = "SELECCIONE OPCION"; lblProductos.Text = "TODOS LOS PRODUCTOS"; lblDetalle.Text = ""; lblUnidad.Text = ""; lblSeleccionado.Text = ""; DGVProductosAAgregar.Enabled = false; DGVProductos.Enabled = true; DGVEstructuraProductos.Rows.Clear(); }
public static List<DetalleProducto> GetAllInsumosDeProductoFinal(int id,SqlTransaction tran, SqlConnection con) { Acceso ac = new Acceso(); List<DetalleProducto> productos = new List<DetalleProducto>(); string sql = "SELECT idProducto, idProductoDetalle, ProductoDetalle, cantidad, Producto, idCategoria, categoria, descCategoria, idUnidad, unidad, descUnidad, codProducto, idUnidadTiempo, UnidadTiempo, descUnidadTiempo, cantidadProductos, tiempoProduccion, tipoMaquinaria, idTipoMaquinaria from CONSULTA_ESTRUCTURA_PRODUCTOS where idcategoria = 4 and idProducto =" + id ; SqlCommand cmd = new SqlCommand(); SqlConnection conexion = new SqlConnection(ac.getCadenaConexion()); try { cmd.Connection = con; cmd.Transaction = tran; cmd.CommandText = sql; cmd.CommandType = CommandType.Text; SqlDataReader dr = cmd.ExecuteReader(); DetalleProducto p; Categoria c; UnidadMedida u; UnidadMedida uT; TipoMaquinaria TM; while (dr.Read()) { u = new UnidadMedida(); u.IDUnidad = Convert.ToInt32(dr["idUnidad"]); u.Nombre = dr["unidad"].ToString(); u.Descripcion = dr["descUnidad"].ToString(); c = new Categoria(); c.IDCategoria = Convert.ToInt32(dr["idCategoria"]); c.Nombre = dr["categoria"].ToString(); c.Descripcion = dr["descCategoria"].ToString(); uT = new UnidadMedida(); uT.IDUnidad = Convert.ToInt32(dr["idUnidadTiempo"]); uT.Nombre = dr["unidadTiempo"].ToString(); uT.Descripcion = dr["descUnidadTiempo"].ToString(); TM = new TipoMaquinaria(); TM.idTipoMaquinaria = Convert.ToInt32(dr["idTipoMaquinaria"].ToString()); TM.Nombre = dr["tipoMaquinaria"].ToString(); p = new DetalleProducto(); p.CODProducto = Convert.ToInt32(dr["codProducto"]); p.Nombre = dr["ProductoDetalle"].ToString(); p.Categoria = c; p.Unidad = u; p.cantidad = double.Parse(dr["cantidad"].ToString()); p.idProducto = Convert.ToInt32(dr["idProductoDetalle"]); p.idProductoPadre = Convert.ToInt32(dr["idProducto"]); p.tiempoProduccion = double.Parse(dr["tiempoProduccion"].ToString()); p.cantidadProductos = double.Parse(dr["cantidadProductos"].ToString()); p.UnidadTiempo = uT; p.TipoMaquinaria = TM; //p.foto = (Image)(dr["foto"]); productos.Add(p); } dr.Close(); } catch (InvalidOperationException ex) { throw new ApplicationException(ex.Message); } catch (SqlException ex) { throw new ApplicationException("Error en BD: " + ex.Message); } finally { } return productos; }