public static PlanMaestroProduccion  GetById(int id)
        {
            Acceso ac = new Acceso();

            PlanMaestroProduccion p = new PlanMaestroProduccion();

            SqlCommand cmd = new SqlCommand();
            string     sql = "SELECT * from CONSULTA_PLAN_PRODUCCION where idPlanProduccion = @id";

            cmd.Parameters.AddWithValue("@id", id);
            SqlConnection conexion = new SqlConnection(ac.getCadenaConexion());

            try
            {
                conexion.Open();

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

                SqlDataReader dr = cmd.ExecuteReader();

                Estado e;

                while (dr.Read())
                {
                    p = new PlanMaestroProduccion();
                    e = new Estado();

                    e.idEstado = Convert.ToInt32(dr["idEstado"]);
                    e.Nombre   = dr["nombre"].ToString();

                    p.IDPlanProduccion  = Convert.ToInt32(dr["idPlanProduccion"]);
                    p.fechaCreacion     = Convert.ToDateTime(dr["fechaCreacion"]);
                    p.fechaInicio       = Convert.ToDateTime(dr["fechaInicio"]);
                    p.fechaFin          = Convert.ToDateTime(dr["fechaFin"]);
                    p.observaciones     = dr["observaciones"].ToString();
                    p.fechaCancelacion  = Convert.ToDateTime(dr["fechaCancelacion"]);
                    p.motivoCancelacion = dr["motivoCancelacion"].ToString();
                    p.estado            = e;
                }
            }
            catch (InvalidOperationException ex)
            {
                throw new ApplicationException(ex.Message);
            }
            catch (SqlException ex)
            {
                throw new ApplicationException("Error en BD: " + ex.Message);
            }
            finally
            {
                conexion.Close();
            }


            return(p);
        }
        public static void Insert(PlanMaestroProduccion plan, List <Producto> productosConPocaMP)
        {
            Acceso         ac   = new Acceso();
            SqlTransaction tran = null;

            SqlConnection conexion = new SqlConnection(ac.getCadenaConexion());

            SqlCommand cmd = new SqlCommand("sp_PlanProduccion_insert", conexion);

            cmd.Parameters.AddWithValue("@fechaCreacion", plan.fechaCreacion);
            cmd.Parameters.AddWithValue("@fechaInicio", plan.fechaInicio);
            cmd.Parameters.AddWithValue("@fechaFin", plan.fechaFin);
            cmd.Parameters.AddWithValue("@idEstado", plan.estado.idEstado);
            cmd.Parameters.AddWithValue("@observaciones", plan.observaciones);



            try
            {
                conexion.Open();
                tran            = conexion.BeginTransaction();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Transaction = tran;
                cmd.ExecuteNonQuery();
                SqlCommand cmdIdentity = new SqlCommand("select @@Identity", conexion, tran);
                plan.IDPlanProduccion = Convert.ToInt32((cmdIdentity.ExecuteScalar()));

                foreach (DetallePlanProduccion detPlan in plan.detallePlan)
                {
                    //detPed.pedido.idPedido = ped.idPedido;

                    DetallePlanProduccionDAO.Insert(detPlan, conexion, tran, plan.IDPlanProduccion);

                    actualizarStock(detPlan, conexion, tran, plan, productosConPocaMP);
                }

                tran.Commit();
            }
            catch (ArgumentException ex)
            {
                if (conexion.State == ConnectionState.Open)
                {
                    tran.Rollback();
                }
                throw new ApplicationException(ex.Message);
            }
            catch (SqlException ex)
            {
                throw new ApplicationException("Error en BD: " + ex.Message);
            }
            finally
            {
                conexion.Close();
            }
        }
Example #3
0
        public void cargarModificacion()
        {
            PlanMaestroProduccion plan = PlanMaestroProduccionDAO.GetById(planModificar.IDPlanProduccion);

            dtp_creacion_plan.Value = plan.fechaCreacion;
            dtp_fecha_inicio.Value  = plan.fechaInicio;
            dtp_fecha_final.Value   = plan.fechaFin;
            txt_observaciones.Text  = plan.observaciones;

            cargarGrillaDetalle(planModificar.IDPlanProduccion);
        }
Example #4
0
        private void dgv_planes_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            String estado = dgv_planes.Rows[dgv_planes.CurrentRow.Index].Cells["Estado"].Value.ToString();

            if (estado == "Pendiente de fabricaciĆ³n")
            {
                PlanMaestroProduccion plan = new PlanMaestroProduccion();

                plan.IDPlanProduccion = (int)dgv_planes.Rows[dgv_planes.CurrentRow.Index].Cells["nroPlan"].Value;


                GestionPlanMaestroProduccion gestPlan = new GestionPlanMaestroProduccion();
                gestPlan._estado        = estados.modificar;
                gestPlan._planModificar = plan;

                gestPlan.ShowDialog();

                cargarGrilla();
                dgv_detalle_plan.Rows.Clear();
            }
        }
Example #5
0
        private void btn_guardar_Click(object sender, EventArgs e)
        {
            if (estadoFormulario == estados.nuevo)
            {
                if (PlanMaestroProduccionDAO.verificarExistenciaPlanParaPeriodo(dtp_fecha_inicio.Value.Date, dtp_fecha_final.Value.Date) == false)
                {
                    PlanMaestroProduccion plan = new PlanMaestroProduccion()
                    {
                        detallePlan   = crearDetalle(),
                        fechaCreacion = dtp_creacion_plan.Value.Date,
                        fechaInicio   = dtp_fecha_inicio.Value.Date,
                        fechaFin      = dtp_fecha_final.Value.Date,
                        observaciones = txt_observaciones.Text,
                        estado        = new Estado()
                        {
                            idEstado = 17
                        }
                    };

                    try
                    {
                        List <Producto> productosConPocaMP = new List <Producto>();
                        PlanMaestroProduccionDAO.Insert(plan, productosConPocaMP);
                        ////////////// MOSTRAR LOS PRODUCTOS CON BAJO STOCK
                        if (productosConPocaMP.Count > 0)
                        {
                            string          mensaje          = "";
                            List <Producto> prodConPocoStock = new List <Producto>();
                            Boolean         MPRepetida       = false;
                            foreach (Producto Prod in productosConPocaMP)
                            {
                                foreach (Producto P in prodConPocoStock)
                                {
                                    if (P.idProducto == Prod.idProducto)
                                    {
                                        MPRepetida = true;
                                        break;
                                    }
                                }
                                if (MPRepetida == false)
                                {
                                    mensaje += Environment.NewLine + Prod.Nombre.ToString();
                                    prodConPocoStock.Add(Prod);
                                }
                            }
                            MessageBox.Show("Los siguientes productos estan con bajo stock: " + mensaje, "Atencion", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        /////////////////////////////////////////////////////////////

                        MessageBox.Show("Registrado con Exito", "Exito", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                        limpiar();
                        _estado = estados.guardado;
                    }
                    catch (ApplicationException ex)
                    {
                        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                    }
                }
                else
                {
                    MessageBox.Show("Ya Existe un Plan Para ese Periodo", "Atencion", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                }
            }
            else
            {
                PlanMaestroProduccion plan = new PlanMaestroProduccion()
                {
                    IDPlanProduccion = planModificar.IDPlanProduccion,
                    detallePlan      = crearDetalle(),
                    fechaCreacion    = dtp_creacion_plan.Value.Date,
                    fechaInicio      = dtp_fecha_inicio.Value.Date,
                    fechaFin         = dtp_fecha_final.Value.Date,
                    observaciones    = txt_observaciones.Text,
                    estado           = new Estado()
                    {
                        idEstado = 17
                    }
                };
                if (estadoFormulario == estados.modificar)
                {
                    try
                    {
                        List <Producto> productosConPocaMP = new List <Producto>();
                        PlanMaestroProduccionDAO.Update(plan, desreservar, productosConPocaMP);
                        ////////////// MOSTRAR LOS PRODUCTOS CON BAJO STOCK
                        if (productosConPocaMP.Count > 0)
                        {
                            string          mensaje          = "";
                            List <Producto> prodConPocoStock = new List <Producto>();
                            Boolean         MPRepetida       = false;
                            foreach (Producto Prod in productosConPocaMP)
                            {
                                foreach (Producto P in prodConPocoStock)
                                {
                                    if (P.idProducto == Prod.idProducto)
                                    {
                                        MPRepetida = true;
                                        break;
                                    }
                                }
                                if (MPRepetida == false)
                                {
                                    mensaje += Environment.NewLine + Prod.Nombre.ToString();
                                    prodConPocoStock.Add(Prod);
                                }
                            }
                            MessageBox.Show("Los siguientes productos estan con bajo stock: " + mensaje, "Atencion", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        /////////////////////////////////////////////////////////////
                        MessageBox.Show("Registrado con Exito", "Exito", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                        limpiar();
                        _estado = estados.guardado;
                        dtp_fecha_inicio.Enabled = true;
                    }
                    catch (ApplicationException ex)
                    {
                        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                    }
                }
            }
        }
        public static List <PlanMaestroProduccion> GetByFiltros(int est, DateTime?fInicioDesde, DateTime?fFinHasta)
        {
            Acceso ac = new Acceso();

            List <PlanMaestroProduccion> planes = new List <PlanMaestroProduccion>();

            string        sql      = "SELECT * from CONSULTA_PLAN_PRODUCCION where 1=1";
            SqlCommand    cmd      = new SqlCommand();
            SqlConnection conexion = new SqlConnection(ac.getCadenaConexion());

            if (est != -1 && est != 0)
            {
                sql += " and idEstado = @est";
                cmd.Parameters.AddWithValue("@est", est);
            }


            if (fInicioDesde.HasValue)
            {
                sql += " and fechaInicio >= @fInicioDesde";
                cmd.Parameters.AddWithValue("@fInicioDesde", fInicioDesde.Value);
            }
            //if (fInicioHasta.HasValue)
            //{
            //    sql += " and fechaInicio <= @fInicioHasta";
            //    cmd.Parameters.AddWithValue("@fInicioHasta", fInicioHasta.Value);
            //}

            //if (fFinDesde.HasValue)
            //{
            //    sql += " and fechaFin >= @fFinDesde";
            //    cmd.Parameters.AddWithValue("@fFinDesde", fFinDesde.Value);
            //}
            if (fFinHasta.HasValue)
            {
                sql += " and fechaFin <= @fFinHasta";
                cmd.Parameters.AddWithValue("@fFinHasta", fFinHasta.Value);
            }


            try
            {
                conexion.Open();

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

                SqlDataReader dr = cmd.ExecuteReader();

                PlanMaestroProduccion p;

                Estado e;


                while (dr.Read())
                {
                    p = new PlanMaestroProduccion();
                    e = new Estado();

                    e.idEstado = Convert.ToInt32(dr["idEstado"]);
                    e.Nombre   = dr["nombre"].ToString();

                    p.IDPlanProduccion  = Convert.ToInt32(dr["idPlanProduccion"]);
                    p.fechaCreacion     = Convert.ToDateTime(dr["fechaCreacion"]);
                    p.fechaInicio       = Convert.ToDateTime(dr["fechaInicio"]);
                    p.fechaFin          = Convert.ToDateTime(dr["fechaFin"]);
                    p.observaciones     = dr["observaciones"].ToString();
                    p.fechaCancelacion  = Convert.ToDateTime(dr["fechaCancelacion"]);
                    p.motivoCancelacion = dr["motivoCancelacion"].ToString();
                    p.estado            = e;

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


            return(planes);
        }
        public static void Update(PlanMaestroProduccion ped, List <DetallePlanProduccion> desreservar, List <Producto> productosConPocaMP)
        {
            Acceso         ac   = new Acceso();
            SqlTransaction tran = null;

            SqlConnection conexion = new SqlConnection(ac.getCadenaConexion());

            SqlCommand cmd = new SqlCommand("UPDATE [Luiggi].[dbo].[PlanMaestroProduccion] SET [fechaInicio] = @fechaInicio, [fechaFin] = @fechaFin, [observaciones] = @observaciones  WHERE idPlanProduccion = @idPlanProduccion", conexion);

            cmd.Parameters.AddWithValue("@fechaInicio", ped.fechaInicio);
            cmd.Parameters.AddWithValue("@fechaFin", ped.fechaFin);
            cmd.Parameters.AddWithValue("@observaciones", ped.observaciones);
            cmd.Parameters.AddWithValue("@idPlanProduccion", ped.IDPlanProduccion);



            try
            {
                conexion.Open();
                tran            = conexion.BeginTransaction();
                cmd.CommandType = CommandType.Text;
                cmd.Transaction = tran;
                cmd.ExecuteNonQuery();
                //SqlCommand cmdIdentity = new SqlCommand("select @@Identity", conexion, tran);
                //ped.idPedido = Convert.ToInt32((cmdIdentity.ExecuteScalar()));
                DetallePlanProduccionDAO.Delete(ped.IDPlanProduccion, conexion, tran);

                foreach (DetallePlanProduccion det in desreservar)
                {
                    det.cantidadPedido = det.cantidadPedido * -1;
                    det.cantidadPLan   = det.cantidadPLan * -1;

                    actualizarStock(det, conexion, tran, ped, productosConPocaMP);
                }


                foreach (DetallePlanProduccion detPed in ped.detallePlan)
                {
                    //detPed.pedido.idPedido = ped.idPedido;
                    DetallePlanProduccionDAO.Insert(detPed, conexion, tran, ped.IDPlanProduccion);
                    actualizarStock(detPed, conexion, tran, ped, productosConPocaMP);
                }
                tran.Commit();
            }
            catch (ArgumentException ex)
            {
                if (conexion.State == ConnectionState.Open)
                {
                    tran.Rollback();
                }
                throw new ApplicationException(ex.Message);
            }
            catch (SqlException ex)
            {
                if (conexion.State == ConnectionState.Open)
                {
                    tran.Rollback();
                }
                throw new ApplicationException("Error en BD: " + ex.Message);
            }
            finally
            {
                conexion.Close();
            }
        }
        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);
        }