예제 #1
0
        public static void actualizarStock(DetallePedido detPedido, SqlConnection con, SqlTransaction trans, Pedido pedido, List<Producto> productosConPocaMP)
        {
            DataTable ProductosIntermedio;
            DataTable MateriaPrima;
            DataTable DetallePlan;
            int idProductoFinal = 0;
            int idProductoIntermedio = 0;
            double cantidad = 0;

            idProductoFinal = detPedido.producto.idProducto;//OBTENEMOS EL ID DEL PRODUCTO FINAL
            cantidad = detPedido.cantidad;//OBTENEMOS LA CANTIDAD DE PRODUCTOS
            if (ProductoDAO.verificarProductoPlanificado(pedido.fechaNecesidad.Date, idProductoFinal, con,trans) == true)//PREGUNTAMOS SI PARA ESE PRODUCTO YA HAY UN DETALLE DEL PLAN PARA ESA FECHA Y ES TRUE
            {
                DetallePlan = DetallePlanProduccionDAO.GetDetallePlanXProducto(idProductoFinal, pedido.fechaNecesidad.Date,con, trans);//OBTENEMOS LOS DATOS DEL DETALLE DEL PLAN

                actualizarDetallePlanYPedidoXPlan(DetallePlan, pedido.idPedido, con, trans, cantidad);

                MateriaPrima = ProductoDAO.GetMateriaPrima(idProductoFinal,trans,con);//CARGAMOS EN LA TABLA LOS DATOS DE LAS MATERIAS PRIMAS
                DataTable MateriaPrimaXIntermedio = new DataTable();
                ProductosIntermedio = ProductoDAO.GetProductoIntermedio(idProductoFinal,con,trans);//CARGAMOS EN LA TABLA LOS DATOS DE LOS PRODUCTOS INTERMEDIO

                obtenerMateriasPrimas(MateriaPrima, MateriaPrimaXIntermedio, ProductosIntermedio, cantidad, idProductoFinal, con, trans, productosConPocaMP);
            }
            else
            {
                if (ProductoDAO.verificarPlanSinProducto(pedido.fechaNecesidad.Date, idProductoFinal, con, trans) == true)//PREGUNTAMOS SI PARA ESE PRODUCTO YA HAY UN DETALLE DEL PLAN PARA ESA FECHA Y ES TRUE
                {
                    Producto prodNuevo = new Producto();
                    prodNuevo.idProducto = idProductoFinal;
                    DetallePlanProduccion detallePlanProduccion = new DetallePlanProduccion()
                    {
                        fechaProduccion = pedido.fechaNecesidad,
                        idPlan = PlanMaestroProduccionDAO.obtenerIdPlan(pedido.fechaNecesidad.Date),
                        cantidadPLan = 0,
                        producto = prodNuevo,
                        cantidadPedido = double.Parse(cantidad.ToString())
                    };

                    cargarNuevoDetallePlanYPedidoXPlan(detallePlanProduccion, con, trans, pedido);

                    MateriaPrima = ProductoDAO.GetMateriaPrima(idProductoFinal,trans,con);//CARGAMOS EN LA TABLA LOS DATOS DE LAS MATERIAS PRIMAS
                    DataTable MateriaPrimaXIntermedio = new DataTable();
                    ProductosIntermedio = ProductoDAO.GetProductoIntermedio(idProductoFinal,con,trans);//CARGAMOS EN LA TABLA LOS DATOS DE LOS PRODUCTOS INTERMEDIO

                    obtenerMateriasPrimas(MateriaPrima, MateriaPrimaXIntermedio, ProductosIntermedio, cantidad, idProductoFinal, con, trans, productosConPocaMP);
                }
            }
        }
        public static void actualizarStock(DetallePlanProduccion detPlan, SqlConnection con, SqlTransaction trans, PlanMaestroProduccion plan, List<Producto> ProductosConPocaMP)
        {
            DataTable ProductosIntermedio;
            DataTable MateriaPrima;

            int idProductoFinal = 0;

            double cantidad = 0;

            idProductoFinal = detPlan.producto.idProducto;//OBTENEMOS EL ID DEL PRODUCTO FINAL
            cantidad = detPlan.cantidadPedido + detPlan.cantidadPLan;//OBTENEMOS LA CANTIDAD DE PRODUCTOS

            MateriaPrima = ProductoDAO.GetMateriaPrima(idProductoFinal,trans,con);//CARGAMOS EN LA TABLA LOS DATOS DE LAS MATERIAS PRIMAS
            DataTable MateriaPrimaXIntermedio = new DataTable();
            ProductosIntermedio = ProductoDAO.GetProductoIntermedio(idProductoFinal,con,trans);//CARGAMOS EN LA TABLA LOS DATOS DE LOS PRODUCTOS INTERMEDIO

            obtenerMateriasPrimas(MateriaPrima, MateriaPrimaXIntermedio, ProductosIntermedio, cantidad, idProductoFinal, con, trans,ProductosConPocaMP);
        }
        private List<DetallePlanProduccion> crearDetalle()
        {
            List<DetallePlanProduccion> detalle = new List<DetallePlanProduccion>();

            foreach (TabPage tab in tab_dias.TabPages)
            {
                foreach (Control ctrl in tab.Controls)
                {

                    if (ctrl is DataGridView)
                    {

                        for (int c = 0; c < ((DataGridView)ctrl).RowCount; c++)
                        {
                            DetallePlanProduccion de = new DetallePlanProduccion();
                            Producto p = new Producto();
                            p.idProducto = (int)((DataGridView)ctrl).Rows[c].Cells[0].Value;
                            de.cantidadPLan = Convert.ToInt32(((DataGridView)ctrl).Rows[c].Cells[3].Value);
                            de.cantidadPedido = Convert.ToInt32(((DataGridView)ctrl).Rows[c].Cells[4].Value);
                            de.producto = p;

                            foreach (Control con in ctrl.Parent.Controls)
                            {
                                if (con is DateTimePicker)
                                {
                                    de.fechaProduccion = ((DateTimePicker)con).Value.Date;
                                }
                            }
                            detalle.Add(de);
                        }

                    }

                }
            }

            return detalle;
        }
 private void cargarGrillaEnTab(DetallePlanProduccion detP, DataGridView grilla)
 {
     grilla.Rows.Add(detP.producto.idProducto, detP.producto.Nombre, detP.fechaProduccion, detP.cantidadPLan, detP.cantidadPedido, detP.cantidadPLan+detP.cantidadPedido, detP.producto.Unidad.Nombre, "Asignar Pedidos");
 }
        private void cmb_productos_SelectionChangeCommitted(object sender, EventArgs e)
        {
            if ((int)cmb_productos.SelectedValue!=0)
            {
                int idProducto = Convert.ToInt32(cmb_productos.SelectedValue);
                Producto p = new Producto();
                infoPlan = new DetallePlanProduccion();
                infoPlan = DetallePlanProduccionDAO.GetDetallePlanXProductoParaOT((int)cmb_productos.SelectedValue, dtp_creacion_OT.Value.Date);

                p = ProductoDAO.GetByIdProd(idProducto, dtp_creacion_OT.Value.Date);
                lbl_cant.Text = p.cantidadAProd.ToString();
                lbl_unidad.Text = p.Unidad.Nombre;
                lbl_tiempo.Text = ((Convert.ToDouble(lbl_cant.Text) * p.tiempoProduccion) / p.cantidadProductos).ToString();
                List<DetalleProducto> dp = new List<DetalleProducto>();

                try
                {
                    dp = EstructuraProductoDAO.GetAll(idProducto);
                }
                catch (ApplicationException ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                }

                cargarGrillaDetalleProducto(dp);
            }
        }
예제 #6
0
 public static void cargarNuevoDetallePlanYPedidoXPlan(DetallePlanProduccion detallePlanProd, SqlConnection con, SqlTransaction trans, Pedido ped)
 {
     DetallePlanProduccionDAO.Insert(detallePlanProd, con, trans, detallePlanProd.idPlan);//ACTUALIZAMOS LA CANTIDAD DE PRODUCTOS EN PEDIDO EN EL DETALLE PLAN PRODUCCION
     //DetallePlanProduccionDAO.insertarPlanProduccionXPedido(ped.idPedido, detallePlanProd.producto.idProducto, detallePlanProd.idPlan, detallePlanProd.fechaProduccion.Date,trans,con);
 }
        public static void Insert(DetallePlanProduccion  det, SqlConnection cn, SqlTransaction tran, int idPlan)
        {
            Acceso ac = new Acceso();

             SqlCommand cmd = new SqlCommand("sp_detalle_planProduccion_insert", cn, tran);

             cmd.Parameters.AddWithValue("@idPlan", idPlan);
             cmd.Parameters.AddWithValue("@fechaProduccion", det.fechaProduccion);
             cmd.Parameters.AddWithValue("@idProducto", det.producto.idProducto);
             cmd.Parameters.AddWithValue("@cantidadPlan", det.cantidadPLan);
             cmd.Parameters.AddWithValue("@cantidadPedido", det.cantidadPedido);

             try
             {
                 cmd.CommandType = CommandType.StoredProcedure;
                 cmd.ExecuteNonQuery();
                 cmd.Dispose();

                 List<int> ids = obtenerPedidosRelacionadosConPlan(det.fechaProduccion, det.producto.idProducto, cn, tran);
                 foreach(int id in ids)
                 {
                     cmd = new SqlCommand("sp_PlanProduccionXPedido_insert", cn);

                     cmd.Parameters.AddWithValue("@idPedido", id);
                     cmd.Parameters.AddWithValue("@fechaProduccion", det.fechaProduccion);
                     cmd.Parameters.AddWithValue("@idProducto", det.producto.idProducto);
                     cmd.Parameters.AddWithValue("@idPlan", idPlan);

                     cmd.Connection = cn;
                     cmd.Transaction = tran;
                     cmd.CommandType = CommandType.StoredProcedure;
                     cmd.ExecuteNonQuery();
                 }

             }
             catch (ArgumentException ex)
             {
                 throw new ApplicationException(ex.Message);
             }
             catch (SqlException ex)
             {
                 throw new ApplicationException("Error en BD: " + ex.Message);
             }
        }
        public static List<DetallePlanProduccion> GetDetalleXPlan(int plan)
        {
            Acceso ac = new Acceso();

             List<DetallePlanProduccion> detalles = new List<DetallePlanProduccion>();

             string sql = "SELECT * from CONSULTA_DETALLE_PLAN_PRODUCCION where idPlan = @plan";
             SqlCommand cmd = new SqlCommand();
             cmd.Parameters.AddWithValue("@plan", plan );
             SqlConnection conexion = new SqlConnection(ac.getCadenaConexion());

             try
             {
                 conexion.Open();

                 cmd.Connection = conexion;
                 cmd.CommandText = sql;
                 cmd.CommandType = CommandType.Text;

                 SqlDataReader dr = cmd.ExecuteReader();

                 DetallePlanProduccion  d;
                 Producto p;
                 UnidadMedida u;
                 Categoria c;

                 while (dr.Read())
                 {

                     u = new UnidadMedida();

                     u.IDUnidad = Convert.ToInt32(dr["idUnidadMedida"]);
                     u.Nombre = dr["unidad"].ToString();

                     p = new Producto();

                     p.CODProducto = Convert.ToInt32(dr["codProducto"]);
                     p.Nombre = dr["nombre"].ToString();
                     p.Unidad = u;
                     p.idProducto = Convert.ToInt16(dr["idProducto"]);

                     d = new DetallePlanProduccion ();

                     d.cantidadPLan = Convert.ToInt32(dr["cantidadPLan"]);
                     d.cantidadPedido = Convert.ToInt32(dr["cantidadPedido"]);
                     d.fechaProduccion = Convert.ToDateTime(dr["fechaProduccion"]);
                     d.producto = p;

                     detalles.Add(d);

                 }

             }
             catch (InvalidOperationException ex)
             {
                 throw new ApplicationException(ex.Message);
             }
             catch (SqlException ex)
             {
                 throw new ApplicationException("Error en BD: " + ex.Message);
             }
             finally
             {
                 conexion.Close();
             }

             return detalles;
        }
        public static DetallePlanProduccion GetDetallePlanXProductoParaOT(int idProd, DateTime fecha)
        {
            Acceso ac = new Acceso();

             DetallePlanProduccion d;

             string sql = "SELECT * from CONSULTA_DETALLE_PLAN_PRODUCCION where idproducto = @idProd and fechaproduccion = @fecha";
             SqlCommand cmd = new SqlCommand();
             cmd.Parameters.AddWithValue("@idProd", idProd);
             cmd.Parameters.AddWithValue("@fecha", fecha);
             SqlConnection conexion = new SqlConnection(ac.getCadenaConexion());

             try
             {
                 conexion.Open();

                 cmd.Connection = conexion;
                 cmd.CommandText = sql;
                 cmd.CommandType = CommandType.Text;

                 SqlDataReader dr = cmd.ExecuteReader();

                 Producto p;

                     dr.Read();

                     p = new Producto();
                     p.Nombre = dr["nombre"].ToString();
                     p.idProducto = Convert.ToInt16(dr["idProducto"]);

                     d = new DetallePlanProduccion();
                     d.idPlan = Convert.ToInt32(dr["idPlan"]);
                     d.cantidadPLan = Convert.ToInt32(dr["cantidadPLan"]);
                     d.cantidadPedido = Convert.ToInt32(dr["cantidadPedido"]);
                     d.fechaProduccion = Convert.ToDateTime(dr["fechaProduccion"]);
                     d.producto = p;

             }
             catch (InvalidOperationException ex)
             {
                 throw new ApplicationException(ex.Message);
             }
             catch (SqlException ex)
             {
                 throw new ApplicationException("Error en BD: " + ex.Message);
             }
             finally
             {
                 conexion.Close();
             }

             return d;
        }