void Data_GridStockArtic()
    {
        tb_me_stockdiariocabBL BL = new tb_me_stockdiariocabBL();
        tb_me_stockdiariocab BE = new tb_me_stockdiariocab();
        DataTable dt = new DataTable();
        BE.articidold = HdFarticid.Value.ToString();
        dt = BL.GetAll_StockProdDet(Session["ssEmpresaID"].ToString(), BE).Tables[0];
        ArmarTabla02();
        if (dt.Rows.Count > 0)
        {
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataRow dtRow = dtDetalle.NewRow();
                dtRow["colorid"] = dt.Rows[i]["colorid"].ToString();
                dtRow["colorname"] = dt.Rows[i]["colorname"].ToString();
                dtRow["sto01"] = dt.Rows[i]["sto01"].ToString();
                dtRow["sto02"] = dt.Rows[i]["sto02"].ToString();
                dtRow["sto03"] = dt.Rows[i]["sto03"].ToString();
                dtRow["sto04"] = dt.Rows[i]["sto04"].ToString();
                dtRow["sto05"] = dt.Rows[i]["sto05"].ToString();
                dtRow["sto06"] = dt.Rows[i]["sto06"].ToString();
                dtRow["sto07"] = dt.Rows[i]["sto07"].ToString();
                dtRow["sto08"] = dt.Rows[i]["sto08"].ToString();
                dtRow["sto09"] = dt.Rows[i]["sto09"].ToString();
                dtRow["sto10"] = dt.Rows[i]["sto10"].ToString();
                dtRow["sto11"] = dt.Rows[i]["sto11"].ToString();
                dtRow["sto12"] = dt.Rows[i]["sto12"].ToString();
                dtDetalle.Rows.Add(dtRow);
            }
            dgb_stockdisponible.DataSource = dtDetalle;
            dgb_stockdisponible.DataBind();

            lblCod.Text = dt.Rows[0]["articidold"].ToString();
            lblNam.Text = dt.Rows[0]["articname"].ToString();
            dgb_stockdisponible.HeaderRow.Cells[2].Text = dt.Rows[0]["ta01"].ToString();
            dgb_stockdisponible.HeaderRow.Cells[3].Text = dt.Rows[0]["ta02"].ToString();
            dgb_stockdisponible.HeaderRow.Cells[4].Text = dt.Rows[0]["ta03"].ToString();
            dgb_stockdisponible.HeaderRow.Cells[5].Text = dt.Rows[0]["ta04"].ToString();
            dgb_stockdisponible.HeaderRow.Cells[6].Text = dt.Rows[0]["ta05"].ToString();
            dgb_stockdisponible.HeaderRow.Cells[7].Text = dt.Rows[0]["ta06"].ToString();
            dgb_stockdisponible.HeaderRow.Cells[8].Text = dt.Rows[0]["ta07"].ToString();
            dgb_stockdisponible.HeaderRow.Cells[9].Text = dt.Rows[0]["ta08"].ToString();
            dgb_stockdisponible.HeaderRow.Cells[10].Text = dt.Rows[0]["ta09"].ToString();
            dgb_stockdisponible.HeaderRow.Cells[11].Text = dt.Rows[0]["ta10"].ToString();
            dgb_stockdisponible.HeaderRow.Cells[12].Text = dt.Rows[0]["ta11"].ToString();
            dgb_stockdisponible.HeaderRow.Cells[13].Text = dt.Rows[0]["ta12"].ToString();
        }
           // ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "searchPopclick();", true);
    }
 void Act_TablaStockdispHorizontal()
 {
     tb_me_stockdiariocabBL BL = new tb_me_stockdiariocabBL();
     tb_me_stockdiariocab BE = new tb_me_stockdiariocab();
     BE.marcaid = "";
     BE.lineaid = "";
     BE.generoid = "";
     BE.articid = "";
     BL.GetAll_StockDisp(Session["ssEmpresaID"].ToString(), BE);
 }
    public void stkDisponible(string talla, string color)
    {
        string disponible = "";

        DataTable Tablastkdisp;
        tb_me_stockdiariocabBL BL1 = new tb_me_stockdiariocabBL();
        tb_me_stockdiariocab BE1 = new tb_me_stockdiariocab();

        BE1.articid = HdFarticid.Value.ToString();
        BE1.coltall = Equivalencias.Right(cmb_tallaid.SelectedValue.ToString(),2); //talla.ToString();
        BE1.colorid = color.ToString();
        Tablastkdisp = BL1.GetAllStkDisp(Session["ssEmpresaID"].ToString(), BE1).Tables[0];

        if (Tablastkdisp.Rows.Count > 0)
        {
            disponible = Tablastkdisp.Rows[0]["stockdisp"].ToString().Trim();
        }
        else
        {
            disponible = "0";
        }

        txtStkdisp.Text = disponible.ToString();
        validastock();
    }
    void cargar_grillaProd(String valorfind)
    {
        tb_me_stockdiariocabBL BL = new tb_me_stockdiariocabBL();
        tb_me_stockdiariocab BE = new tb_me_stockdiariocab();
        DataTable dt = new DataTable();

        //BE.valorfind = valorfind.ToString();
        BE.filtro = "1";
        TablaProd = BL.GetAll_Grid(Session["ssEmpresaID"].ToString(), BE).Tables[0];

        DataTable dtDatos = new DataTable();
        if (TablaProd.Rows.Count > 0)
        {
            dtDatos.Columns.Add("articid");
            dtDatos.Columns.Add("articidold");
            dtDatos.Columns.Add("articname");
            dtDatos.Columns.Add("stockdisp");
            dtDatos.Columns.Add("pvt_cremenor");

            dtDatos.Columns.Add("prec_etiq");
            dtDatos.Columns.Add("prec_ofer");
            dtDatos.Columns.Add("estadoid");
            dtDatos.Columns.Add("estadoname");

            for (int i = 0; i < TablaProd.Rows.Count; i++)
            {
                DataRow dtRow = dtDatos.NewRow();
                dtRow["articid"] = TablaProd.Rows[i]["articid"].ToString();
                dtRow["articidold"] = TablaProd.Rows[i]["articidold"].ToString();
                dtRow["articname"] = TablaProd.Rows[i]["articname"].ToString();
                dtRow["stockdisp"] = TablaProd.Rows[i]["stockdisp"].ToString();
                dtRow["pvt_cremenor"] = TablaProd.Rows[i]["pvt_cremenor"].ToString();

                dtRow["prec_etiq"] = TablaProd.Rows[i]["prec_etiq"].ToString();
                dtRow["prec_ofer"] = TablaProd.Rows[i]["prec_ofer"].ToString();
                dtRow["estadoid"] = TablaProd.Rows[i]["estadoid"].ToString();
                dtRow["estadoname"] = TablaProd.Rows[i]["estadoname"].ToString();

                dtDatos.Rows.Add(dtRow);
            }
            GridViewProd.DataSource = dtDatos;
            GridViewProd.DataBind();
        }
    }
    private void MetodoCargarLineal(String xcodigo)
    {
        //tb_pt_articuloWebBL BL = new tb_pt_articuloWebBL();
        //tb_pt_articulo BE = new tb_pt_articulo();

        tb_me_stockdiariocabBL BL = new tb_me_stockdiariocabBL();
        tb_me_stockdiariocab BE = new tb_me_stockdiariocab();
        //tb_me_stockdiariocabBL BL = new tb_me_stockdiariocabBL();
        //tb_me_stockdiariocab BE = new tb_me_stockdiariocab();
        DataTable dt = new DataTable();
        BE.articidold = xcodigo.Trim();
        BE.valorfind = txt_filter2.Text.ToUpper();
        dt = BL.GetAll(Session["ssEmpresaID"].ToString(), BE).Tables[0];

        if (dt.Rows.Count > 0)
        {
            string old = dt.Rows[0]["articidold"].ToString();
            Session["bd_marcaid"] = dt.Rows[0]["marcaid"].ToString();
            txt_marcaname.Text = dt.Rows[0]["marcaname"].ToString();
            Session["bd_articid"] = dt.Rows[0]["articid"].ToString();
            txt_articname.Text = dt.Rows[0]["articname"].ToString();
            txt_precventa_cre_menor.Text = dt.Rows[0]["precventa_cre_menor"].ToString();
            Session["bd_tallaid"] = dt.Rows[0]["tallaid"].ToString();
            //Session["bd_coltall"] = dt.Rows[0]["coltall"].ToString();
            Session["bd_fecha"] = dt.Rows[0]["fecha"].ToString();
            HdFarticid.Value = dt.Rows[0]["articid"].ToString();
            // Metodos De Cargar Combos
            CargarComboArticuloColor(dt.Rows[0]["articid"].ToString());
            CargarComboArticuloTallas(dt.Rows[0]["tallaid"].ToString());
            btn_add.Enabled = true;
            btn_add.CssClass = "btn btn-success";

            //HdFtalla.Value = cmb_tallaid.SelectedValue;
            //string talla = HdFtalla.Value.ToString().Substring(5, 2);
            string color = cmb_colorid.SelectedValue;
            cmb_colorid.SelectedIndex = -1;
            //stkDisponible(talla.ToString(),color.ToString());
        }
    }
    private void Insert()
    {
        try
        {
            var BL = new tb_cxc_pedidocabBL();
            var BE = new tb_cxc_pedidocab();

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

            var Detalle2 = new tb_cxc_pedidocab.Crono();
            var ListaCrono = new List<tb_cxc_pedidocab.Crono>();

            #region Datos Cabecera
            BE.tipdoc = txt_tipdoc.Text;
            BE.serdoc = txt_serdoc.Text;
            BE.numdoc = txt_numdoc.Text;
            BE.canalventaid = Session["ssCanalVentaId"].ToString();
            BE.tipventaid = cmb_tipventa.SelectedValue.ToString();
            BE.fechdoc = Convert.ToDateTime(fechdoc.Text);
            BE.fechentrega = Convert.ToDateTime(fechentrega.Text);
            BE.vendorid = txt_vendorid.Text;
            BE.ctacte = txt_ctacte.Text;
            BE.direcnume = "";
            BE.replegal_dni = replegal_dni.Text;
            BE.replegal_name = replegal_name.Text;
            BE.direc_entrega = direc_entrega.Text;
            BE.condventaid = cmb_condventaid.SelectedValue.ToString();
            BE.plazoday = Convert.ToInt32(cmb_plazoday.SelectedValue.ToString());
            BE.impobruto = Convert.ToDecimal(txt_impobruto.Text);
            BE.rangoid = "05";// *****************************************************************
            BE.tasadescto = Convert.ToDecimal(txt_tasadescto.Text);
            BE.imponeto = Convert.ToDecimal(txt_imponeto.Text);
            BE.moneda = cmb_moneda.SelectedValue.ToString();
            if (cmb_igv.Value.ToString() == "S")
            {
                BE.incluye_igv = true;
            }
            else
            {
                BE.incluye_igv = false;
            }
            BE.observacion = txt_obs.Text;
            BE.mediopagoid = cmb_mediopagoid.Value.ToString();
            BE.numdocs = Convert.ToInt32(spe_numdocs.Text);
            BE.aprob_status = AproStatus.ToString() ;//"11";
            //BE.aprob_obser = aprob_obs.Text;
            //if (aprob_fech.Text.Length > 0)
            //{ BE.aprob_fech = Convert.ToDateTime(aprob_fech.Text); }
            BE.usuar = Session["ssUsuar"].ToString().Trim();
            BE.local = Session["ssLocal"].ToString().Trim();
            BE.moduloid = Session["ssModuloId"].ToString().Trim();

            String xmod = Session["ssModo"].ToString();

            switch (Session["ssModo"].ToString())
            {
                case "NEW": BE.accion = "INS"; break;
                case "EDI": BE.accion = "ALT"; break;
                case "DEL": BE.accion = "DEL"; break;
            }
            #endregion

            #region Datos Detalle
            TablaDetalle = (DataTable)Session["TablaDetalle"];
            foreach (DataRow fila in TablaDetalle.Rows)
            {
                Detalle = new tb_cxc_pedidocab.Item();
                Detalle.tipdoc = txt_tipdoc.Text;
                Detalle.serdoc = txt_serdoc.Text;
                Detalle.numdoc = txt_numdoc.Text;

                Detalle.articid = fila["articid"].ToString();
                Detalle.articidold = fila["articidold"].ToString();
                Detalle.colorid = fila["colorid"].ToString();
                Detalle.tallaid = fila["tallaid"].ToString();
                Detalle.coltall = Equivalencias.Right(fila["coltall"].ToString(), 2);
                Detalle.cantidad = Convert.ToDecimal(fila["cantidad"].ToString());
                Detalle.precbruto = Convert.ToDecimal(fila["precbruto"].ToString());
                Detalle.impobruto = Convert.ToDecimal(fila["impobruto"].ToString());
                Detalle.precneto = Convert.ToDecimal(fila["precneto"].ToString());
                Detalle.imponeto = Convert.ToDecimal(fila["imponeto"].ToString());
                Detalle.usuar = Session["ssUsuar"].ToString().Trim();
                Detalle.canalventaid = Session["ssCanalVentaId"].ToString();
                Detalle.local = Session["ssLocal"].ToString();

                if (Convert.ToDecimal(fila["imponeto"].ToString()) > 0)
                {
                    ListaItems.Add(Detalle);
                }
                else
                {
                    ClientMessage("DOCUMENTO DETALLE PROFORMA EN FORMATO INCORRECTO ...!!!");
                    return;
                }
            }
            BE.ListaItems = ListaItems;
            #endregion

            #region Datos Detalle CronoGramaPagos
            TablaCronoPagos = (DataTable)Session["TablaCronoPagos"];
            foreach (DataRow fila in TablaCronoPagos.Rows)
            {
                Detalle2 = new tb_cxc_pedidocab.Crono();
                Detalle2.tipdoc = txt_tipdoc.Text;
                Detalle2.serdoc = txt_serdoc.Text;
                Detalle2.numdoc = txt_numdoc.Text;
                Detalle2.mediopagoid = cmb_mediopagoid.Value.ToString();
                Detalle2.item = fila["item"].ToString();
                Detalle2.num_interno = fila["num_interno"].ToString();
                Detalle2.num_unico = fila["num_unico"].ToString();
                Detalle2.monto = Convert.ToDecimal(fila["monto"].ToString());
                String xfecha = Equivalencias.Left(fila["fechven"].ToString(), 10);
                Detalle2.fechven = Convert.ToDateTime(xfecha);
                Detalle2.usuar = Session["ssUsuar"].ToString().Trim();

                if (Convert.ToDecimal(fila["monto"].ToString()) > 0)
                {
                    ListaCrono.Add(Detalle2);
                }
                else
                {
                    ClientMessage("DOCUMENTO DETALLE CRONOGRAMA PAGOS EN FORMATO INCORRECTO ...!!!");
                    return;
                }
            }
            BE.ListaCrono = ListaCrono;
            #endregion

            #region Inserción de Datos en Tabla Stock diario
            var BLStk = new tb_me_stockdiariocabBL();
            var BEStk = new tb_me_stockdiariocab();
            //var BLStk = new tb_cxc_pedidocabBL();
            //var BEStk = new tb_cxc_pedidocab();

            //switch (Session["ssModo"].ToString())
            //{
            //    case "NEW": BE.accion = "INS"; break;
            //    case "EDIT": BE.accion = "ALT"; break;
            //    case "DEL": BE.accion = "DEL"; break;
            //}

            //BEStk.almacaccionid = "21";
            #endregion

            #region Inserción de Datos en Tabla Stock Diario Detalle
            decimal canti = 0;
            var DetalleStk = new tb_cxc_pedidocab.ItemsStkDeta();
            var ListaStkItems = new List<tb_cxc_pedidocab.ItemsStkDeta>();
            TablaDetalleStk = (DataTable)Session["TablaDetalle"];
            foreach (DataRow fila in TablaDetalleStk.Rows)
            {
                DetalleStk = new tb_cxc_pedidocab.ItemsStkDeta();
                DetalleStk.fecha = Convert.ToDateTime(DateTime.Today.ToString()); //Convert.ToDateTime(Session["bd_fecha"].ToString());
                DetalleStk.articid = fila["articid"].ToString();
                DetalleStk.colorid = fila["colorid"].ToString();
                DetalleStk.coltall = Equivalencias.Right(fila["coltall"].ToString(), 2);
                DetalleStk.almacaccionid = "21";
                DetalleStk.tipodoc = txt_tipdoc.Text;
                DetalleStk.serdoc = txt_serdoc.Text;
                DetalleStk.numdoc = txt_numdoc.Text;
                canti = Convert.ToDecimal(fila["cantidad"].ToString());
                DetalleStk.cantidad = canti;
                DetalleStk.ctacte = txt_ctacte.Text;
                DetalleStk.direcnume = Session["direcnume"].ToString();//direc_entrega.Text;
                DetalleStk.tipoperacionid = "10";
                DetalleStk.tiporef = txt_tipdoc.Text;
                DetalleStk.serref = txt_serdoc.Text;
                DetalleStk.numref = txt_numdoc.Text;
                DetalleStk.estado = 1;
                DetalleStk.atendido = 0;
                DetalleStk.vendorid = txt_vendorid.Text;
                DetalleStk.usuar = Session["ssUsuar"].ToString().Trim();
                DetalleStk.canalventaid = Session["ssCanalVentaId"].ToString();
                DetalleStk.local = Session["ssLocal"].ToString();
                DetalleStk.dominioid = Session["ssDominioid"].ToString();
                DetalleStk.moduloid = Session["ssModuloid"].ToString();

                if (TablaDetalle.Rows.Count > 0)
                {
                    ListaStkItems.Add(DetalleStk);
                }
                else
                {
                    ClientMessage("DOCUMENTO DETALLE INCORRECTO ...!!!");
                    return;
                }
            }
            BE.listaItemsStkDeta = ListaStkItems;
            #endregion

            //BLStk.InsertStk(Session["ssEmpresaID"].ToString(), BEStk);

            // PASAR A LLAMAR AL METODO DE INSERCION DE PEDIDO
            if (BL.Insert(Session["ssEmpresaID"].ToString(), BE))
            {
                ClientMessage("Registros Grabados Correctamente !!!");
                LimpiarDocumento();
                CargarCorrelativoDoc();

                //Lock_or_Unlock_Boton("N", true, "");
                //Lock_or_Unlock_Boton("C", false, "_disabled");
                //Lock_or_Unlock_Boton("G", false, "_disabled");
                //Lock_or_UnLock_Paneles("01", false, "fondo_bloqueo", "_disabled");
                //Lock_or_UnLock_Paneles("02", false, "fondo_bloqueo", "_disabled");
                //Lock_or_UnLock_Paneles("03", false, "fondo_bloqueo", "_disabled");

                btn_Imprimir.Enabled = true;
                btn_Imprimir.CssClass = "btn btn-primary";
                //btn_grabar.Enabled = false;
                //btn_grabar.CssClass = "btn btn-default";
            }
        }
        catch (Exception ex)
        {
            //ClientMessage(ex.Message);
            Response.Redirect("ErrorPage/Frm_PaginaError_405.aspx");
        }
    }
    private void data_gridArticulo()
    {
        //tb_pt_articuloWebBL BL = new tb_pt_articuloWebBL();
        //tb_pt_articulo BE = new tb_pt_articulo();
        tb_me_stockdiariocabBL BL = new tb_me_stockdiariocabBL();
        tb_me_stockdiariocab BE = new tb_me_stockdiariocab();
        DataTable dt = new DataTable();

        //BE.articidold = txt_articidold.Text.ToUpper();
        //BE.top = true;
        BE.valorfind = txt_filter2.Text;
        switch (cbo_filtro2.SelectedValue)
        {
            case "01":
                BE.articidold = txt_filter2.Text.Trim().ToUpper();
                break;
            case "02":
                BE.articname = txt_filter2.Text.Trim().ToUpper();
                break;
            default:
                //**
                break;
        }
        try
        {
            //Eliminar Columnas Actuales(Opcional):
            GridView2.Columns.Clear();
            GridView2.Width = 535;
            //Objeto Columna:
            CommandField image;
            //Crear Columna:
            image = new CommandField();
            image.ButtonType = ButtonType.Image;
            image.SelectImageUrl = "~/Images/go-search.png";
            image.ShowSelectButton = true;
            image.ItemStyle.Width = 10;
            image.ItemStyle.Wrap = true;
            GridView2.Columns.Add(image);

            BoundField ARTICIDOLD;
            ARTICIDOLD = new BoundField();
            ARTICIDOLD.DataField = "articidold";
            ARTICIDOLD.HeaderText = "CODIGO_OLD";
            ARTICIDOLD.ItemStyle.Width = 70;
            GridView2.Columns.Add(ARTICIDOLD);

            BoundField ARTICNAME;
            ARTICNAME = new BoundField();
            ARTICNAME.DataField = "articname";
            ARTICNAME.HeaderText = "ARTICULO";
            ARTICNAME.ItemStyle.Width = 250;
            GridView2.Columns.Add(ARTICNAME);

            dt = BL.GetAll(Session["ssEmpresaID"].ToString(), BE).Tables[0];
            GridView2.DataSource = dt;
            GridView2.DataBind();
            GridView2.Visible = true;
        }
        catch (Exception ex)
        {
            //ClientMessage(ex.Message);
            Response.Redirect("ErrorPage/Frm_PaginaError_405.aspx");
        }
    }
    void stkDisponible()
    {
        string disponible = "";

            DataTable Tablastkdisp;
            tb_me_stockdiariocabBL BL1 = new tb_me_stockdiariocabBL();
            tb_me_stockdiariocab BE1 = new tb_me_stockdiariocab();

            string talla = HdFtalla.Value.ToString();
            BE1.articid = HdFarticid.Value.ToString();
            BE1.coltall = cmb_tallaid.SelectedItem.ToString().Substring(0, 2);
            BE1.colorid = cmb_colorid.Text.ToString();
            Tablastkdisp = BL1.GetAllStkDisp(Session["ssEmpresaID"].ToString(), BE1).Tables[0];

            if (Tablastkdisp.Rows.Count > 0)
            {
                disponible = Tablastkdisp.Rows[0]["stockdisp"].ToString().Trim();
            }
            else
            {
                disponible = "0";
            }

                txtStkdisp.Text = disponible.ToString();
    }
    void cargar_grillaProd(String valorfind)
    {
        tb_me_stockdiariocabBL BL = new tb_me_stockdiariocabBL ();
        tb_me_stockdiariocab BE = new tb_me_stockdiariocab();
        DataTable dt = new DataTable();

        BE.valorfind = valorfind.ToString();
        TablaProd = BL.GetAll(Session["ssEmpresaID"].ToString(), BE).Tables[0];

        DataTable dtDatos = new DataTable();
        if (TablaProd.Rows.Count > 0)
        {
            dtDatos.Columns.Add("articidold");
            dtDatos.Columns.Add("articname");
            dtDatos.Columns.Add("marcaid");
            dtDatos.Columns.Add("marcaname");
            dtDatos.Columns.Add("articid");
            dtDatos.Columns.Add("pvt_cremenor");
            dtDatos.Columns.Add("tallaid");

            string canalid = "";
            string canalname = "";
            for (int i = 0; i < TablaProd.Rows.Count; i++)
            {
                DataRow dtRow = dtDatos.NewRow();
                dtRow["articidold"] = TablaProd.Rows[i]["articidold"].ToString();
                dtRow["articname"] = TablaProd.Rows[i]["articname"].ToString();
                dtRow["marcaid"] = TablaProd.Rows[i]["marcaid"].ToString();
                dtRow["marcaname"] = TablaProd.Rows[i]["marcaname"].ToString();
                dtRow["articid"] = TablaProd.Rows[i]["articid"].ToString();
                dtRow["pvt_cremenor"] = TablaProd.Rows[i]["precventa_cre_menor"].ToString();
                dtRow["tallaid"] = TablaProd.Rows[i]["tallaid"].ToString();

                dtDatos.Rows.Add(dtRow);
            }
            GridViewProd.DataSource = dtDatos;
            GridViewProd.DataBind();
        }
    }