private void RecibeData(String x1,String x2,String x3,String x4,String x5)
        {
            try
            {
                txt_serop.Text = x1.ToString();
                txt_numop.Text = x2.ToString();
                xarticid = x3.ToString();
                txt_articidold.Text = x4.ToString();
                txt_articname.Text = x5.ToString();

                DataTable dt = new DataTable();
                String Query = " SELECT (CONVERT(VARCHAR, opf.secuencia) + ' = ' + f.fasename) secuencia,opf.faseid,cl.ctactename " +
                               " FROM tb_pp_ordenprodfase opf " +
                               " LEFT JOIN tb_pp_fase f ON opf.faseid = f.faseid " +
                               " LEFT JOIN tb_cliente cl ON opf.ctacte = cl.ctacte " +
                               " WHERE opf.tipop = 'OP'  AND opf.serop = '" + txt_serop.Text + "' AND opf.numop = '" + txt_numop.Text + "'";
                dt = DatosSQL(Query);

                cmb_secuencia.DataSource = dt;
                cmb_secuencia.ValueMember = "faseid";
                cmb_secuencia.DisplayMember = "secuencia";
                cmb_secuencia.SelectedIndex = 0;

                form_bloqueado(true);
                btn_cancelar.Enabled = true;
                btn_grabar.Enabled = true;
                btn_salir.Enabled = true;
                cmb_tipdoc.Enabled = false;
                txt_numop.Enabled = false;

                btn_new.Enabled = true;

                /**********************
                 * CARGAMOS EL COMBO DE COLORES
                 * ******************/
                tb_pp_ordenprodfasemoviBL BL2 = new tb_pp_ordenprodfasemoviBL();
                tb_pp_ordenprodfasemovi BE2 = new tb_pp_ordenprodfasemovi();
                DataTable dt2 = new DataTable();
                BE2.tipop = "OP";
                BE2.serop = txt_serop.Text;
                BE2.numop = txt_numop.Text;
                BE2.filtro = "1";
                dt2 = BL2.GetAll(EmpresaID, BE2).Tables[0];

                cmb_color.DataSource = dt2;
                cmb_color.ValueMember = "colorid";
                cmb_color.DisplayMember = "colorname";
                cmb_color.SelectedIndex = -1;

                /************************
                 * CARGAMOS EL DETALLE
                 * **********************/
                var BL3 = new tb_pp_ordenprodfasemoviBL();
                var BE3 = new tb_pp_ordenprodfasemovi();
                var dt3 = new DataTable();

                BE3.tipop = "OP";
                BE3.serop = txt_serop.Text;
                BE3.numop = txt_numop.Text;
                BE3.filtro = "1";

                dt3 = BL3.GetAllPropColor_PIVOT(EmpresaID, BE3).Tables[0];
                dgv_color.AutoGenerateColumns = false;
                dgv_color.DataSource = dt3;

                ValidaArticulo();
                CalculosTotales();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void Insert()
        {
            try
            {
                tb_pp_ordenprodfasemoviBL BL = new tb_pp_ordenprodfasemoviBL();
                tb_pp_ordenprodfasemovi BE = new tb_pp_ordenprodfasemovi();

                var Item = new tb_pp_ordenprodfasemovi.Item();
                var ListaItems = new List<tb_pp_ordenprodfasemovi.Item>();

                #region Variables de RecetasCab
                BE.tipodoc = cmb_tipdoc.Text;
                BE.serdoc = txt_serdoc.Text;
                BE.numdoc = txt_numdoc.Text;
                BE.fechdoc = Convert.ToDateTime(txt_fechdoc.Text);
                BE.almacaccionid = cmb_tipdoc.SelectedValue.ToString();
                BE.moduloid = modulo;
                BE.mottrasladointid = cmb_motivo.SelectedValue.ToString();
                BE.tipop = "OP";
                BE.serop = txt_serop.Text;
                BE.numop = txt_numop.Text;
                BE.secuencia =  Convert.ToInt32(Equivalencias.Left(cmb_secuencia.Text, 1));
                BE.faseid = Convert.ToInt32(cmb_secuencia.SelectedValue.ToString());
                BE.status = "0";
                BE.usuar = VariablesPublicas.Usuar.ToUpper().Trim();

                #endregion

                var num = 1;
                for (int i = 0; i < dgv_color.RowCount; i++)
                {
                    for (int j = 3; j < dgv_color.Columns.Count - 1; j++)
                    {
                        Item = new tb_pp_ordenprodfasemovi.Item();
                        Boolean dr = Convert.ToBoolean(dgv_color.Rows[i].Cells[0].Value.ToString());
                        Item.primera = Convert.ToBoolean(dgv_color.Rows[i].Cells[0].Value.ToString());
                        Item.colorid = dgv_color.Rows[i].Cells["colorid"].Value.ToString();
                        Item.coltalla = num.ToString().PadLeft(2, '0');
                        Item.cantidad = Convert.ToInt32(dgv_color.Rows[i].Cells[j].Value.ToString());
                        num++;
                        ListaItems.Add(Item);
                    }
                    num = 1;
                }

                if (ListaItems.Count == 0)
                {
                    MessageBox.Show("Documento SIN DETALLE Y/O DETALLE INCORRECTO !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                BE.ListaItems = ListaItems;

                if (BL.Insert(EmpresaID, BE))
                {
                    MessageBox.Show("Datos Grabados Correctamente !!!", "Confirmación", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    procesado = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void Gen_numMov()
        {
            try
            {
                var BL = new tb_pp_ordenprodfasemoviBL();
                var BE = new tb_pp_ordenprodfasemovi();
                var dt = new DataTable();

                BE.dominioid = dominio.ToString();
                BE.moduloid = modulo.ToString();
                BE.tipodoc = cmb_tipdoc.Text.ToString();

                dt = BL.GetAll_num(EmpresaID, BE).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    txt_numdoc.Text = dt.Rows[0]["numero"].ToString();
                }
                else
                {
                    MessageBox.Show("Asignar la Accion del Documento", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void cmb_talla_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmb_talla.SelectedIndex != -1)
            {
                //Segun se Escoge la Talla Cargar el Saldo
                if (cmb_talla.Text != "System.Data.DataRowView" && cmb_talla.SelectedValue.ToString() != "System.Data.DataRowView")
                {
                    tb_pp_ordenprodfasemoviBL BL = new tb_pp_ordenprodfasemoviBL();
                    tb_pp_ordenprodfasemovi BE = new tb_pp_ordenprodfasemovi();
                    DataTable dt2 = new DataTable();
                    BE.tipop = "OP";
                    BE.serop = txt_serop.Text;
                    BE.numop = txt_numop.Text;
                    BE.colorid = cmb_color.SelectedValue.ToString();
                    BE.coltalla = cmb_talla.SelectedValue.ToString();
                    BE.filtro = "3";
                    dt2 = BL.GetAll(EmpresaID, BE).Tables[0];

                    if (dt2.Rows.Count > 0)
                        txt_saldo.Text = dt2.Rows[0]["cantidad"].ToString();
                }

            }
        }
        private void cmb_color_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmb_color.SelectedIndex != -1)
            {
                //Segun se Escoge el Color cargar las tallas
                if (cmb_color.Text != "System.Data.DataRowView" && cmb_color.SelectedValue.ToString() != "System.Data.DataRowView")
                {
                    tb_pp_ordenprodfasemoviBL BL = new tb_pp_ordenprodfasemoviBL();
                    tb_pp_ordenprodfasemovi BE = new tb_pp_ordenprodfasemovi();
                    DataTable dt2 = new DataTable();
                    BE.tipop = "OP";
                    BE.serop = txt_serop.Text;
                    BE.numop = txt_numop.Text;
                    BE.colorid = cmb_color.SelectedValue.ToString();
                    BE.filtro = "2";
                    dt2 = BL.GetAll(EmpresaID, BE).Tables[0];

                    cmb_talla.DataSource = dt2;
                    cmb_talla.ValueMember = "coltalla";
                    cmb_talla.DisplayMember = "tallaname";
                    cmb_talla.SelectedIndex = -1;
                }
            }
        }
        void CargamosColorCmb()
        {
            tb_pp_ordenprodfasemoviBL BL2 = new tb_pp_ordenprodfasemoviBL();
            tb_pp_ordenprodfasemovi BE2 = new tb_pp_ordenprodfasemovi();
            DataTable dt2 = new DataTable();
            BE2.tipop = "OP";
            BE2.serop = txt_serop.Text;
            BE2.numop = txt_numop.Text;
            BE2.filtro = "1";
            dt2 = BL2.GetAll(EmpresaID, BE2).Tables[0];

            cmb_color.DataSource = dt2;
            cmb_color.ValueMember = "colorid";
            cmb_color.DisplayMember = "colorname";
            cmb_color.SelectedIndex = -1;
        }