using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Data;
using System.Configuration;
using System.Web.Security;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using Telerik.Web.UI;
using System.Globalization;

using BE;
using BL;
using Utilitaria;


public partial class List_ProvisionCompras : System.Web.UI.Page
{
    Int32 intMercaderia = 0; 
    Int32 intGastos = 9;
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["Usuario"] == null)
        {
            Response.Redirect(Utilitaria.Cls_Enums.CerrarSesion.Salir);
        }
        if (!IsPostBack)
        {
            Session["DatosArticulos"] = "";
            ViewState["Click"] = "1";

            ViewState["HotelID"] =  Session["HotelID"];
            ViewState["EstablecimientoID"] = Session["EmpresaID"];
        }
    }



    private void listar_Articulos(Int32 Mercaderia,Int32 Gastos)
    {
        BEConfigTransferencias objBEConfigTransferencias = new BEConfigTransferencias();
        BLConfigTransferencias objBLConfigTransferencias = new BLConfigTransferencias();

        if (ViewState["Click"].ToString().Trim() == "1")
        {

            Session["DatosArticulos"] = objBLConfigTransferencias.fnSelArticulosAll(0, Mercaderia, Gastos);
        }
        tk_Articulos.DataSource = ((List<BEConfigTransferencias>)Session["DatosArticulos"]);  

        ViewState["Click"] = "";
        objBEConfigTransferencias = null;
        objBLConfigTransferencias = null;

    }

    protected void Busca_Articulos(object sender, EventArgs e)
    {
        ViewState["Click"] = "1";

        if (this.cbx_Mercaderia.Checked == true && this.cbx_Gastos.Checked == false)
        { 
            intMercaderia=0;
            intGastos = 9;
        }

        if (this.cbx_Mercaderia.Checked == false && this.cbx_Gastos.Checked == true)
        {
            intMercaderia = 9;
            intGastos = 1;
        }

        if (this.cbx_Mercaderia.Checked == true && this.cbx_Gastos.Checked == true)
        {
            intMercaderia = 0;
            intGastos = 1;
        }

        tk_Articulos.Rebind();
    }

    private void listar_SubFamilias()
    {
        BEConfigTransferencias objBEConfigTransferencias = new BEConfigTransferencias();
        BLConfigTransferencias objBLConfigTransferencias = new BLConfigTransferencias();

        tk_SubFamilias.DataSource = objBLConfigTransferencias.fnSelSubFamiliasAll(0);

        objBEConfigTransferencias = null;
        objBLConfigTransferencias = null;

    }

   
  
    protected void showMessage(string strMessage)
    {
        ScriptManager.RegisterStartupScript(this, this.GetType(), "myscript", "alert('" + strMessage + "');", true);


    }

    protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
    {
        if (e.Argument == "Rebind")
        {
            tk_Articulos.MasterTableView.SortExpressions.Clear();
            tk_Articulos.MasterTableView.GroupByExpressions.Clear();
            tk_Articulos.Rebind();

            tk_SubFamilias.MasterTableView.SortExpressions.Clear();
            tk_SubFamilias.MasterTableView.GroupByExpressions.Clear();
            tk_SubFamilias.Rebind();
        }
        else if (e.Argument == "RebindAndNavigate")
        {
            tk_Articulos.MasterTableView.SortExpressions.Clear();
            tk_Articulos.MasterTableView.GroupByExpressions.Clear();
            tk_Articulos.MasterTableView.CurrentPageIndex = tk_Articulos.MasterTableView.PageCount - 1;
            tk_Articulos.Rebind();

            tk_SubFamilias.MasterTableView.SortExpressions.Clear();
            tk_SubFamilias.MasterTableView.GroupByExpressions.Clear();
            tk_SubFamilias.MasterTableView.CurrentPageIndex = tk_SubFamilias.MasterTableView.PageCount - 1;
            tk_SubFamilias.Rebind();

            

        }
    }
    String CurrUrl;
    String par;

    protected void tk_Articulos_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
    {
        listar_Articulos(intMercaderia, intGastos);
    }
    protected void tk_Articulos_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        {

            GridDataItem dataItem = (GridDataItem)e.Item;
            String strTipo = "";

            if (this.cbx_Gastos.Checked == true)
            {
                strTipo = "1";
            }
            else
            {
                strTipo = "2";
            }
            par = "&pc=" + dataItem["articuloID"].Text + "&ck=" + strTipo;
            HyperLink linkItem = new HyperLink();
            linkItem.NavigateUrl = "#";
            linkItem.Text = dataItem["nombre"].Text;
            linkItem.CssClass = "gridtext";
            linkItem.Attributes.Add("OnClick", String.Format("return ShowEditArticulos('{0}','{1}','{2}');", dataItem["articuloID"], e.Item.ItemIndex, par));
            dataItem["nombre"].Controls.Add(linkItem);

        }


    }

    protected void tk_SubFamilias_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
    {
        listar_SubFamilias();
    }
    protected void tk_SubFamilias_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        {

            GridDataItem dataItem = (GridDataItem)e.Item;


            par = "&pc=" + dataItem["SubFamiliaId"].Text + "&ck=0";
            HyperLink linkItem = new HyperLink();
            linkItem.NavigateUrl = "#";
            linkItem.Text = dataItem["nombre"].Text;
            linkItem.CssClass = "gridtext";
            linkItem.Attributes.Add("OnClick", String.Format("return ShowEditSubFamilia('{0}','{1}','{2}');", dataItem["SubFamiliaId"], e.Item.ItemIndex, par));
            dataItem["nombre"].Controls.Add(linkItem);

        }


    }

}
