private void dgv_OTproductosPadres_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (dgv_OTproductosPadres.CurrentCell is DataGridViewButtonCell)
            {
                if (dgv_OTproductosPadres.Rows[dgv_OTproductosPadres.CurrentRow.Index].DefaultCellStyle.BackColor != Color.LightGreen)
                {
                    if (tieneHijosFinalizados() == true)
                    {
                        try
                        {
                            double cant = (double)dgv_OTproductosPadres.Rows[dgv_OTproductosPadres.CurrentRow.Index].Cells["cantidad"].Value;
                            if (dgv_OTproductosPadres.CurrentRow.Cells["cantiReal"].Value != String.Empty)
                            {
                                double cantidadPlan   = 0;
                                double cantidadPedido = DetallePlanProduccionDAO.GetCantidadPedidosParaOT((int)dgv_OTproductosPadres.Rows[dgv_OTproductosPadres.CurrentRow.Index].Cells["idProducto"].Value, Convert.ToDateTime(dgv_OTproductosPadres.Rows[dgv_OTproductosPadres.CurrentRow.Index].Cells["fechaCreacion"].Value));
                                cantidadPlan = cant - cantidadPedido;
                                DateTime fecha = Convert.ToDateTime(dgv_OTproductosPadres.Rows[dgv_OTproductosPadres.CurrentRow.Index].Cells["fechaCreacion"].Value);


                                OrdenDeTrabajo orden = new OrdenDeTrabajo();
                                orden.idOrdenTrabajo = int.Parse(dgv_OTproductosPadres.Rows[dgv_OTproductosPadres.CurrentRow.Index].Cells["idOrden"].Value.ToString());
                                Producto prod = new Producto();
                                prod.idProducto = int.Parse(dgv_OTproductosPadres.Rows[dgv_OTproductosPadres.CurrentRow.Index].Cells["idProducto"].Value.ToString());
                                prod.Nombre     = dgv_OTproductosPadres.Rows[dgv_OTproductosPadres.CurrentRow.Index].Cells["nomProducto"].Value.ToString();
                                UnidadMedida unidad = new UnidadMedida();
                                unidad.Nombre       = dgv_OTproductosPadres.Rows[dgv_OTproductosPadres.CurrentRow.Index].Cells["unidad"].Value.ToString();
                                prod.Unidad         = unidad;
                                orden.fechaCreacion = fecha;
                                orden.producto      = prod;
                                orden.cantidad      = cant;
                                ActualizarStock act = new ActualizarStock(orden, cantidadPedido, cantidadPlan);
                                act.ShowDialog();
                                if (orden.estado != null)
                                {
                                    if (orden.estado.Nombre == "LISTO")
                                    {
                                        MessageBox.Show("Finalizado con éxito", "Exito", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                                        dgv_OTproductosPadres.CurrentRow.DefaultCellStyle.BackColor = Color.LightGreen;
                                        dgv_OTproductosPadres.CurrentRow.Cells["cantiReal"].Value   = orden.cantidadReal;
                                        cargarGrilla();
                                    }
                                }
                            }
                        }
                        catch (FormatException ex)
                        {
                            MessageBox.Show("Ingrese solo números", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                        }
                        catch (ApplicationException ex)
                        {
                            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Primero debe Finalizar las Ordenes de Trabajo de los Productos Intermedios", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                    }
                }
            }
        }
 private void dgv_OTproductosHijos_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     if (dgv_OTproductosHijos.CurrentCell is DataGridViewButtonCell)
     {
         if (dgv_OTproductosHijos.Rows[dgv_OTproductosHijos.CurrentRow.Index].DefaultCellStyle.BackColor != Color.LightGreen)
         {
             try
             {
                 double         canti = (double)dgv_OTproductosHijos.Rows[dgv_OTproductosHijos.CurrentRow.Index].Cells["cant"].Value;
                 OrdenDeTrabajo orden = new OrdenDeTrabajo();
                 orden.idOrdenTrabajo = (int)dgv_OTproductosHijos.Rows[dgv_OTproductosHijos.CurrentRow.Index].Cells["idOT"].Value;
                 Producto prod = new Producto();
                 prod.idProducto = (int)dgv_OTproductosHijos.Rows[dgv_OTproductosHijos.CurrentRow.Index].Cells["idProd"].Value;
                 prod.Nombre     = dgv_OTproductosHijos.Rows[dgv_OTproductosHijos.CurrentRow.Index].Cells["poductoDetalle"].Value.ToString();
                 UnidadMedida unidad = new UnidadMedida();
                 unidad.Nombre  = dgv_OTproductosHijos.Rows[dgv_OTproductosHijos.CurrentRow.Index].Cells["unidadMedida"].Value.ToString();
                 prod.Unidad    = unidad;
                 orden.producto = prod;
                 orden.cantidad = canti;
                 ActualizarStock act = new ActualizarStock(orden);
                 act.ShowDialog();
                 if (orden.estado != null)
                 {
                     if (orden.estado.Nombre == "LISTO")
                     {
                         MessageBox.Show("Finalizado con éxito", "Exito", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                         dgv_OTproductosHijos.CurrentRow.DefaultCellStyle.BackColor = Color.LightGreen;
                         dgv_OTproductosHijos.CurrentRow.Cells["cantReal"].Value    = orden.cantidadReal;
                     }
                 }
             }
             catch (ApplicationException ex)
             {
                 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
             }
             catch (FormatException ex)
             {
                 MessageBox.Show("Ingrese solo números", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
             }
         }
     }
     dgv_OTproductosHijos.ClearSelection();
 }
        private void dgv_OTproductosPadres_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (dgv_OTproductosPadres.CurrentCell is DataGridViewButtonCell)
                {
                    if (dgv_OTproductosPadres.Rows[dgv_OTproductosPadres.CurrentRow.Index].DefaultCellStyle.BackColor != Color.LightGreen)
                    {
                        if (tieneHijosFinalizados() == true)
                        {
                            try
                            {
                                double cant = (double)dgv_OTproductosPadres.Rows[dgv_OTproductosPadres.CurrentRow.Index].Cells["cantidad"].Value;
                                if (dgv_OTproductosPadres.CurrentRow.Cells["cantiReal"].Value != String.Empty)
                                {
                                    double cantidadPlan = 0;
                                    double cantidadPedido = DetallePlanProduccionDAO.GetCantidadPedidosParaOT((int)dgv_OTproductosPadres.Rows[dgv_OTproductosPadres.CurrentRow.Index].Cells["idProducto"].Value, Convert.ToDateTime(dgv_OTproductosPadres.Rows[dgv_OTproductosPadres.CurrentRow.Index].Cells["fechaCreacion"].Value));
                                    cantidadPlan = cant - cantidadPedido;
                                    DateTime fecha = Convert.ToDateTime(dgv_OTproductosPadres.Rows[dgv_OTproductosPadres.CurrentRow.Index].Cells["fechaCreacion"].Value);

                                    OrdenDeTrabajo orden = new OrdenDeTrabajo();
                                    orden.idOrdenTrabajo = int.Parse(dgv_OTproductosPadres.Rows[dgv_OTproductosPadres.CurrentRow.Index].Cells["idOrden"].Value.ToString());
                                    Producto prod = new Producto();
                                    prod.idProducto = int.Parse(dgv_OTproductosPadres.Rows[dgv_OTproductosPadres.CurrentRow.Index].Cells["idProducto"].Value.ToString());
                                    prod.Nombre = dgv_OTproductosPadres.Rows[dgv_OTproductosPadres.CurrentRow.Index].Cells["nomProducto"].Value.ToString();
                                    UnidadMedida unidad = new UnidadMedida();
                                    unidad.Nombre = dgv_OTproductosPadres.Rows[dgv_OTproductosPadres.CurrentRow.Index].Cells["unidad"].Value.ToString();
                                    prod.Unidad = unidad;
                                    orden.fechaCreacion = fecha;
                                    orden.producto = prod;
                                    orden.cantidad = cant;
                                    ActualizarStock act = new ActualizarStock(orden, cantidadPedido,cantidadPlan);
                                    act.ShowDialog();
                                    if (orden.estado != null)
                                    {
                                        if (orden.estado.Nombre == "LISTO")
                                        {
                                            MessageBox.Show("Finalizado con éxito", "Exito", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                                            dgv_OTproductosPadres.CurrentRow.DefaultCellStyle.BackColor = Color.LightGreen;
                                            dgv_OTproductosPadres.CurrentRow.Cells["cantiReal"].Value = orden.cantidadReal;
                                            cargarGrilla();
                                        }
                                    }
                                }
                            }
                            catch (FormatException ex)
                            {

                                MessageBox.Show("Ingrese solo números", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);

                            }
                            catch (ApplicationException ex)
                            {
                                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                            }

                        }
                        else
                        {
                            MessageBox.Show("Primero debe Finalizar las Ordenes de Trabajo de los Productos Intermedios", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);

                        }

                    }

            }
        }
        private void dgv_OTproductosHijos_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (dgv_OTproductosHijos.CurrentCell is DataGridViewButtonCell)
            {
                if (dgv_OTproductosHijos.Rows[dgv_OTproductosHijos.CurrentRow.Index].DefaultCellStyle.BackColor != Color.LightGreen)
                {
                    try
                    {
                        double canti = (double)dgv_OTproductosHijos.Rows[dgv_OTproductosHijos.CurrentRow.Index].Cells["cant"].Value;
                        OrdenDeTrabajo orden = new OrdenDeTrabajo();
                        orden.idOrdenTrabajo = (int)dgv_OTproductosHijos.Rows[dgv_OTproductosHijos.CurrentRow.Index].Cells["idOT"].Value;
                        Producto prod = new Producto();
                        prod.idProducto =(int)dgv_OTproductosHijos.Rows[dgv_OTproductosHijos.CurrentRow.Index].Cells["idProd"].Value;
                        prod.Nombre = dgv_OTproductosHijos.Rows[dgv_OTproductosHijos.CurrentRow.Index].Cells["poductoDetalle"].Value.ToString();
                        UnidadMedida unidad = new UnidadMedida();
                        unidad.Nombre = dgv_OTproductosHijos.Rows[dgv_OTproductosHijos.CurrentRow.Index].Cells["unidadMedida"].Value.ToString();
                        prod.Unidad = unidad;
                        orden.producto = prod;
                        orden.cantidad = canti;
                        ActualizarStock act = new ActualizarStock(orden);
                        act.ShowDialog();
                        if (orden.estado != null)
                        {
                            if (orden.estado.Nombre == "LISTO")
                            {
                                MessageBox.Show("Finalizado con éxito", "Exito", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                                dgv_OTproductosHijos.CurrentRow.DefaultCellStyle.BackColor = Color.LightGreen;
                                dgv_OTproductosHijos.CurrentRow.Cells["cantReal"].Value = orden.cantidadReal;
                            }
                        }
                    }
                    catch (ApplicationException ex)
                    {
                        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                    }
                    catch (FormatException ex)
                    {

                        MessageBox.Show("Ingrese solo números", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);

                    }

                }

             }
            dgv_OTproductosHijos.ClearSelection();
        }