protected void Page_Load(object sender, EventArgs e)
        {
          

           /* if (!ContabilidadGlobal.Admin.Permisos.Alta)
            { 
                Session["Mensaje"] = "Usted no tiene los permisos para acceder a esta sección.";
                Session["Titulo"] = "Acceso denegado";
                Response.Redirect("../../Mensaje.aspx");
            }*/
          //  else if (!X.IsAjaxRequest)
           // {
                SelectedItem = null;

                // Datagrid
                Storer st = new Storer(typeof(ItemComprobante));
                st.ObjectToStore(ref StoreItems);
                st.ObjectToGridPanel(ref GridPanelItems);
                ItemsComprobante = new List<ItemComprobante>();
                CargarDatosEnGrid();

                /* Bugfixer [Ver ingreso de asientos]. */
                Session[sessionCanClick] = true;
                //            }

                ComboMonedas.Tipo = typeof(Entidades.Entity_moneda);
                ComboMonedas.Width = 300;
                ComboMonedas.OnShow();

                ComboClasesCliente.Tipo = typeof(Entidades.Entity_cliente);
                ComboClasesCliente.Width = ComboMonedas.Width;
                ComboClasesCliente.Valores = new SqlValor[]
            {
                new SqlValor("Empresa_idempresa", ContabilidadGlobal.Admin.CodEmpresa)
            };
                ComboClasesCliente.OnShow();


                ComboClasesCondicionVenta.Tipo = typeof(Entidades.Entity_condicionesventa);
                ComboClasesCondicionVenta.Width = ComboClasesCondicionVenta.Width;
                ComboClasesCondicionVenta.Valores = new SqlValor[]
            {
            
           new SqlValor ("empresa_idempresa", ContabilidadGlobal.Admin.CodEmpresa) 
            };
                ComboClasesCondicionVenta.OnShow();


                //ComboClasesPunto.Tipo = typeof(Entidades.Entity_puntoregistracion);
                //ComboClasesPunto.Width = ComboMonedas.Width;
                //ComboClasesPunto.OnShow();

                ComboClasesProvincia.Tipo = typeof(Entidades.Entity_provincia);
                ComboClasesProvincia.Width = ComboMonedas.Width;
                ComboClasesProvincia.OnShow();

                ComboClasesTipoOperacion.Width = ComboMonedas.Width;

                ComboTipoLista.Tipo = typeof(Entidades.Entity_tipolista);
                ComboTipoLista.Width = ComboMonedas.Width;
                ComboTipoLista.OnShow();

                // if (Checkbox2.Checked == true) pregunto a la hora de calcular los totales

                ComboClases1.Tipo = typeof(Entidades.Entity_descuentoscomerciales);
                ComboClases1.Width = ComboClases1.Width;
                ComboClases1.OnShow();



                //if (Checkbox1.Checked == true) pregunto a la hora de calcular los totales

                ComboClases2.Tipo = typeof(Entidades.Entity_descuentosfinancieros);
                ComboClases2.Width = ComboClases1.Width;
                ComboClases2.OnShow();

        //    }
        }
        public void OnShow()
        {
            try
            {
                if (StringConnection.Equals(""))
                    StringConnection = CapaDatos.Datos.ConnectionString;

                Storer st = new WebHelper.Storer(Tipo);
                st.Valores = Valores;
                st.ValoresCombo = ValoresCombo;

                if (Insert.Equals(""))
                    Insert = st.GetInsert();
                if (Select.Equals(""))
                    Select = st.GetSelect();
                if (Update.Equals(""))
                    Update = st.GetUpdate();
                if (Delete.Equals(""))
                    Delete = st.GetDelete();

                this.SqlDataSource1.ProviderName = "MySql.Data.MySqlClient";
                this.SqlDataSource1.ConnectionString = StringConnection;
                this.SqlDataSource1.InsertCommand = Insert;
                this.SqlDataSource1.SelectCommand = Select;
                this.SqlDataSource1.UpdateCommand = Update;
                this.SqlDataSource1.DeleteCommand = Delete;

                st.ObjectToSqlDataSource(ref SqlDataSource1);
                st.ObjectToStore(ref Store1);
                st.ObjectToGridPanel(ref GridPanel1);

                // Permisos de la tabla
                if (Permisos == null)
                    Permisos = ContabilidadGlobal.Admin.Permisos;

                if (!Permisos.Alta)
                {
                    this.btnInsert.Enabled = false;
                    this.btnInsert.Hide();
                    if (!Permisos.Modif)
                    {
                        this.btnSave.Enabled = false;
                        this.btnSave.Hide();
                    }
                }
                if (!Permisos.Baja)
                {
                    this.btnDelete.Enabled = false;
                    this.btnDelete.Hide();
                }

                cargarFiltros(st);
            }
            catch (Exception ex)
            {
                UIHelper.MostrarExcepcionSimple(ex, "Error");
            }
        }
        public void OnShowRegimenesEspeciales()
        {
            try
            {
                if (StringConnection.Equals(""))
                    StringConnection = CapaDatos.Datos.ConnectionString;

                Storer st = new WebHelper.Storer(typeof(Entity_regimenesEspeciales));
                st.Valores = Valores;
                //st.ValoresCombo = ValoresCombo;

              //  if (Select.Equals(""))
                    Select = st.GetSelect();

                this.SqlDataSource1.ProviderName = "MySql.Data.MySqlClient";
                this.SqlDataSource1.ConnectionString = StringConnection;
                this.SqlDataSource1.SelectCommand = Select;


                st.ObjectToSqlDataSource(ref SqlDataSource1);
                st.ObjectToStore(ref Store3);
                st.ObjectToGridPanel(ref GridPanelRegimenesEspeciales);
                cargarFiltros(st);
            }
            catch (Exception ex)
            {
                UIHelper.MostrarExcepcionSimple(ex, "Error");
            }
        }
        public void OnShow()
        {
            try
            {
                //Harcoded here
                if (StringConnection.Equals(""))
                    StringConnection = CapaDatos.Datos.ConnectionString;
                //End hard

                Storer st = new WebHelper.Storer(Tipo);
                st.Valores = Valores;
                st.ValoresCombo = ValoresCombo;

                if (Insert.Equals(""))
                    Insert = st.GetInsert();
                if (Select.Equals(""))
                    Select = st.GetSelect();
                if (Update.Equals(""))
                    Update = st.GetUpdate();
                if (Delete.Equals(""))
                    Delete = st.GetDelete();

                this.SqlDataSource1.ProviderName = "MySql.Data.MySqlClient";
                this.SqlDataSource1.ConnectionString = StringConnection;
                this.SqlDataSource1.InsertCommand = Insert;
                this.SqlDataSource1.SelectCommand = Select;
                this.SqlDataSource1.UpdateCommand = Update;
                this.SqlDataSource1.DeleteCommand = Delete;

                st.ObjectToSqlDataSource(ref SqlDataSource1);
                st.ObjectToStore(ref Store1);
                st.ObjectToGridPanel(ref GridPanel1);

                //Aplicar cuestiones de seguridad
                if (Permisos == null)
                {
                    Permisos = Permisos.PermisosAdmin;
                }

                if (!Permisos.Alta)
                {
                    this.btnInsert.Enabled = false;
                    if (!Permisos.Modif)
                    {
                        this.btnSave.Enabled = false;
                    }
                }
                if (!Permisos.Baja)
                {
                    this.btnDelete.Enabled = false;
                }
            }
            catch (Exception ex)
            {
                UIHelper.MostrarExcepcionSimple(ex, "Error");
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
        


           /* if (!ContabilidadGlobal.Admin.Permisos.Alta)
            { 
                Session["Mensaje"] = "Usted no tiene los permisos para acceder a esta sección.";
                Session["Titulo"] = "Acceso denegado";
                Response.Redirect("../../Mensaje.aspx");
            }*/
          //  else 
            if (!X.IsAjaxRequest)
           {
                SelectedItem = null;

                
                TotalDescuentos.Text = "0";
                TotalNeto.Text = "0";
                TotalOtros.Text = "0";
                Total.Text = "0";
                IVA.Text = "0";
                TotalRecargos.Text = "0";

                // Datagrid
                Storer st = new Storer(typeof(Entity_lineaVenta));
                st.ObjectToStore(ref StoreItems);
                st.ObjectToGridPanel(ref GridPanelItems);
                ItemsComprobante = new List<Entity_lineaVenta>();
                CargarDatosEnGrid();

                /* Bugfixer [Ver ingreso de asientos]. */
                Session[sessionCanClick] = true;
                //            }

                ComboMonedas.Tipo = typeof(Entity_moneda);
                ComboMonedas.Width = 300;
                ComboMonedas.OnShow();

                //ComboClientes
                Storer stcli = new Storer(typeof(Entity_cliente));
                OnshowCli(stcli);
                               
                       
                ComboClasesCondicionVenta.Tipo = typeof(Entidades.Entity_condicionesventa);
                ComboClasesCondicionVenta.Width = ComboClasesCondicionVenta.Width;
                ComboClasesCondicionVenta.Valores = new SqlValor[]
            {
            
           new SqlValor ("empresa_idempresa", ContabilidadGlobal.Admin.CodEmpresa) 
            };
                ComboClasesCondicionVenta.OnShow();

                ComboClasesProvincia.Tipo = typeof(Entidades.Entity_provincia);
                ComboClasesProvincia.Width = ComboMonedas.Width;
                ComboClasesProvincia.OnShow();

                ComboClasesTipoOperacion.Width = ComboMonedas.Width;

                ComboTipoLista.Tipo = typeof(Entity_tipolista);
                ComboTipoLista.Width = ComboMonedas.Width;
                ComboTipoLista.OnShow();

                // if (Checkbox2.Checked == true) pregunto a la hora de calcular los totales


                //ComboDescuentoFinanciero
                Storer stdesFinan = new Storer(typeof(Entity_descuentosfinancieros));
                OnshowDescF(stdesFinan);

                //ComboDescuentoComercial
                Storer stdesComercial = new Storer(typeof(Entity_descuentoscomerciales));
                OnshowDescComercial(stdesComercial);

             
               // Datagrid conceptos
                Storer sto = new Storer(typeof(Entity_concepto));
               
                //sto.ObjectToSqlDataSource(ref SqlDataSource1);
                OnShow();
                Store1.DataBind();

                //Datagrid regimenes especiales
                OnShowRegimenesEspeciales();
              


           }
        }