Esempio n. 1
0
        private void cargar_bodegas()
        {
            DateTime t  = DateTime.Now;
            DateTime t2 = DateTime.Now;

            t = new DateTime(t.Year, t.Month, 1);
            string DESDE = t.ToShortDateString();
            string HASTA = t2.ToShortDateString();

            DESDE = DESDE.Replace("-", "/");
            HASTA = HASTA.Replace("-", "/");

            string where = " where FechaFactura >= CONVERT(datetime,'" + DESDE + "', 103) " +
                           " and FechaFactura <= CONVERT(datetime,'" + HASTA + "',103) and user1 in (" + grupos + ")";

            DataTable dt; DataView dtv = new DataView();

            dt  = ReporteRNegocio.carga_grupos(DESDE, HASTA, grupos);
            dtv = dt.DefaultView;
            d_grupos_usuario.DataSource     = dtv;
            d_grupos_usuario.DataTextField  = "user1";
            d_grupos_usuario.DataValueField = "user1";
            //d_vendedor_.SelectedIndex = -1;
            d_grupos_usuario.DataBind();
        }
Esempio n. 2
0
        protected void b_Click(object sender, ImageClickEventArgs e)
        {
            string grupos_del_usuario = "";

            grupos_del_usuario = agregra_comillas(ReporteRNegocio.grupos_usuario(User.Identity.Name.ToString()));

            if (grupos_del_usuario == "")
            {
                grupos_del_usuario = agregra_comillas(ReporteRNegocio.grupos_usuario_v_report(User.Identity.Name.ToString()));
            }



            DataTable dt; DataView dtv = new DataView();

            dt = ReporteRNegocio.carga_grupos(txt_desde.Text, txt_hasta.Text, grupos_del_usuario);
            if (dt.Rows.Count <= 0)
            {
                ScriptManager.RegisterStartupScript(Page, this.GetType(), "teeee", "<script language='javascript'>NO_GRUPOS();</script>", false);
            }
            else
            {
                cargar_combo_Grupo(dt, dtv);
                string es_vend = ReporteRNegocio.esvendedor(User.Identity.Name.ToString());
                if (es_vend != "2")
                {
                    string where = " where FechaFactura >= CONVERT(datetime,'" + txt_desde.Text + "', 103) " +
                                   " and FechaFactura <= CONVERT(datetime,'" + txt_hasta.Text + "',103) ";
                    where += "and user1 in (" + grupos_del_usuario + ")";

                    cargar_combo_VENDEDOR(ReporteRNegocio.listar_ALL_vendedores(where), dtv);
                    //cargar_combo_clientes(ReporteRNegocio.listar_ALL_cliente2(where), dtv);
                }
                else
                {
                    string where = " where FechaFactura >= CONVERT(datetime,'" + txt_desde.Text + "', 103) " +
                                   " and FechaFactura <= CONVERT(datetime,'" + txt_hasta.Text + "',103) ";
                    where += "and user1 in (" + grupos_del_usuario + ")";

                    cargar_combo_VENDEDOR(ReporteRNegocio.listar_ALL_vendedores(where + " and codvendedor = '" + USER + "' "), dtv);
                    //cargar_combo_clientes(ReporteRNegocio.listar_ALL_cliente2(where + " and codvendedor = '" + USER + "' "), dtv);
                }
            }
        }
Esempio n. 3
0
 protected void G_usuarios_RowDataBound(object sender, GridViewRowEventArgs e)
 {
     if (e.Row.RowType == DataControlRowType.DataRow)
     {
         if (e.Row.Cells[5].Text == "1")
         {
             e.Row.Cells[5].Text = "ADMIN";
         }
         else if (e.Row.Cells[5].Text == "2")
         {
             e.Row.Cells[5].Text = "VENDEN";
             //e.Row.Cells[2].Text = "(" + ReporteRNegocio.nombre_vendedor(e.Row.Cells[2].Text) + ")   " + e.Row.Cells[2].Text;
         }
         else
         {
             e.Row.Cells[5].Text = "OTRO";
         }
     }
     if (e.Row.Cells[7].Text.Split(',').ToList().Count == ReporteRNegocio.carga_grupos().Rows.Count)
     {
         e.Row.Cells[7].Text = "TODOS";
     }
 }
        protected void btn_productos_Click(object sender, EventArgs e)
        {
            //if (l_vendedores.Text != "" && l_clientes.Text != "" && txt_desde.Text != "" && txt_hasta.Text != "" && l_grupos.Text != "")
            //{
            string vendedores = agregra_comillas(l_vendedores.Text);
            string clientes   = agregra_comillas(l_clientes.Text);
            string desde      = txt_desde.Text;
            string hasta      = txt_hasta.Text;
            string grupos     = agregra_comillas(l_grupos.Text);;

            string grupos_del_usuario = agregra_comillas(ReporteRNegocio.grupos_usuario(User.Identity.Name.ToString()));

            if (grupos_del_usuario == "")
            {
                grupos_del_usuario = agregra_comillas(ReporteRNegocio.grupos_usuario_v_report(User.Identity.Name.ToString()));
            }


            DataTable dt2; DataView dtv = new DataView();

            dt2 = ReporteRNegocio.carga_grupos(txt_desde.Text, txt_hasta.Text, grupos_del_usuario);
            if (dt2.Rows.Count <= 0)
            {
                ScriptManager.RegisterStartupScript(Page, this.GetType(), "teeee", "<script language='javascript'>NO_GRUPOS();</script>", false);
            }
            else
            {
                string es_vendedor = ReporteRNegocio.esvendedor(USER);
                where = " where FechaFactura >= CONVERT(datetime,'" + desde + "', 103)  and FechaFactura <= CONVERT(datetime,'" + hasta + "',103) ";
                if (grupos != "")
                {
                    where = where + " and user1 in (" + grupos + ") ";
                }
                else if (es_vendedor != "2")
                {
                    where = where + " and user1 in (" + agregra_comillas(ReporteRNegocio.grupos_usuario(USER)) + ")";
                }
                else if (es_vendedor == "2")
                {
                    where = where + " and user1 in (" + agregra_comillas(ReporteRNegocio.grupos_usuario_v_report(USER)) + ")";
                }

                if (clientes != "")
                {
                    where = where + " and rutcliente in (" + clientes + ") ";
                }
                if (vendedores != "")
                {
                    where = where + " and codvendedor in (" + vendedores + ") ";
                }
                if (es_vendedor == "2")
                {
                    where += " and codvendedor in ('" + USER + "')";
                }

                div_productos.Visible = true;
                string periodos = ReporteRNegocio.listar_periodos_(" where FechaFactura >= CONVERT(datetime,'" + desde + "', 103)  and FechaFactura <= CONVERT(datetime,'" + hasta + "',103)");
                productos = ReporteRNegocio.listar_resumen_productos(periodos, where);
                PERIODOS  = periodos;
                DataView  view           = new DataView(productos);
                DataTable distinctValues = view.ToTable(true, "NombreCliente");

                productos.Columns.Add("Total");

                int colum = productos.Columns.Count;

                DataView dv = productos.DefaultView;
                dv.Sort   = "NombreCliente ASC";
                productos = dv.ToTable();

                Session["TaskTable"] = productos;

                header_sum             = true;
                cont_det               = 1;
                G_PRODUCTOS.DataSource = productos;
                //G_PRODUCTOS.Columns[colum - 1].Visible = false;
                //G_PRODUCTOS.Columns[colum - 2].Visible = false;
                G_PRODUCTOS.DataBind();

                //VOLVER A CARGAR LOS MULTISELECT

                DataTable dt = new DataTable();

                try
                {
                    dt = ReporteRNegocio.carga_grupos(desde, hasta, grupos_del_usuario);
                    //dt.Rows.Add(new Object[] { "-1", "-- Todos --" });
                    DataView dv2 = dt.DefaultView;
                    dv2.Sort = "user1";
                    dt       = dv2.ToTable();
                    d_grupos_usuario.DataSource     = dt;
                    d_grupos_usuario.DataTextField  = "user1";
                    d_grupos_usuario.DataValueField = "user1";
                    //d_vendedor_.SelectedIndex = -1;
                    d_grupos_usuario.DataBind();


                    foreach (ListItem item in d_grupos_usuario.Items)
                    {
                        if (l_grupos.Text.Contains(item.Value.ToString()))
                        {
                            item.Selected = true;
                        }
                    }
                }
                catch { }

                string where2 = " where FechaFactura >= CONVERT(datetime,'" + desde + "', 103) " +
                                " and FechaFactura <= CONVERT(datetime,'" + hasta + "',103) ";

                if (grupos != "")
                {
                    where2 = where2 + " and user1 in (" + grupos + ") ";
                }
                else if (es_vendedor != "2")
                {
                    where2 = where2 + " and user1 in (" + agregra_comillas(ReporteRNegocio.grupos_usuario(USER)) + ")";
                }
                else if (es_vendedor == "2")
                {
                    where2 = where2 + " and user1 in (" + agregra_comillas(ReporteRNegocio.grupos_usuario_v_report(USER)) + ")";
                }

                if (es_vendedor == "2")
                {
                    where2 += " and codvendedor in ('" + USER + "')";
                }

                try
                {
                    dt = ReporteRNegocio.listar_ALL_vendedores(where2);
                    //dt.Rows.Add(new Object[] { "-1", "-- Todos --" });
                    DataView dv2 = dt.DefaultView;
                    dv2.Sort = "cod_vend";
                    dt       = dv2.ToTable();
                    d_vendedor_.DataSource     = dt;
                    d_vendedor_.DataTextField  = "nom_vend";
                    d_vendedor_.DataValueField = "cod_vend";
                    //d_vendedor_.SelectedIndex = -1;
                    d_vendedor_.DataBind();


                    foreach (ListItem item in d_vendedor_.Items)
                    {
                        if (l_vendedores.Text.Contains(item.Value.ToString()))
                        {
                            item.Selected = true;
                        }
                    }
                }
                catch { }
                where2 = "";
                where2 = " where FechaFactura >= CONVERT(datetime,'" + desde + "', 103) " +
                         " and FechaFactura <= CONVERT(datetime,'" + hasta + "',103) ";

                if (grupos != "")
                {
                    where2 = where2 + " and user1 in (" + grupos + ") ";
                }
                else if (es_vendedor != "2")
                {
                    where2 = where2 + " and user1 in (" + agregra_comillas(ReporteRNegocio.grupos_usuario(USER)) + ")";
                }
                else if (es_vendedor == "2")
                {
                    where2 = where2 + " and user1 in (" + agregra_comillas(ReporteRNegocio.grupos_usuario_v_report(USER)) + ")";
                }
                if (vendedores != "")
                {
                    where2 += " and codvendedor in (" + vendedores + ")";
                }
                if (es_vendedor == "2")
                {
                    where2 += " and codvendedor in ('" + USER + "')";
                }

                try
                {
                    dt = ReporteRNegocio.listar_ALL_cliente2(where2);
                    //dt.Rows.Add(new Object[] { "-1", "-- Todos --" });
                    DataView dv3 = dt.DefaultView;
                    dv3.Sort                 = "nom_cliente";
                    dt                       = dv3.ToTable();
                    d_cliente.DataSource     = dt;
                    d_cliente.DataTextField  = "nom_cliente";
                    d_cliente.DataValueField = "rut_cliente";
                    //d_vendedor_.SelectedIndex = -1;
                    d_cliente.DataBind();


                    foreach (ListItem item in d_cliente.Items)
                    {
                        if (l_clientes.Text.Contains(item.Value.ToString()))
                        {
                            item.Selected = true;
                        }
                    }
                }
                catch { }

                ScriptManager.RegisterStartupScript(Page, this.GetType(), "teeee", "<script> new Tablesort(document.getElementById('ContentPlaceHolder_Contenido_G_PRODUCTOS')); </script>", false);
            }
        }
Esempio n. 5
0
        protected void btn_productos_Click(object sender, EventArgs e)
        {
            string vendedores = agregra_comillas(l_vendedores.Text);
            //string clientes = agregra_comillas(l_clientes.Text);
            string desde  = txt_desde.Text;
            string hasta  = txt_hasta.Text;
            string grupos = agregra_comillas(l_grupos.Text);;


            string grupos_del_usuario = agregra_comillas(ReporteRNegocio.grupos_usuario(User.Identity.Name.ToString()));

            if (grupos_del_usuario == "")
            {
                grupos_del_usuario = agregra_comillas(ReporteRNegocio.grupos_usuario_v_report(User.Identity.Name.ToString()));
            }

            string where = "";

            DataTable dt2; DataView dtv = new DataView();

            dt2 = ReporteRNegocio.carga_grupos(txt_desde.Text, txt_hasta.Text, grupos_del_usuario);
            if (dt2.Rows.Count <= 0)
            {
                ScriptManager.RegisterStartupScript(Page, this.GetType(), "teeee", "<script language='javascript'>NO_GRUPOS();</script>", false);
            }
            else
            {
                string es_vendedor = ReporteRNegocio.esvendedor(USER);
                where = " where FechaFactura >= CONVERT(datetime,'" + desde + "', 103)  and FechaFactura <= CONVERT(datetime,'" + hasta + "',103) ";
                if (grupos != "")
                {
                    where = where + " and user1 in (" + grupos + ") ";
                }
                else if (es_vendedor != "2")
                {
                    where = where + " and user1 in (" + agregra_comillas(ReporteRNegocio.grupos_usuario(USER)) + ")";
                }
                else if (es_vendedor == "2")
                {
                    where = where + " and user1 in (" + agregra_comillas(ReporteRNegocio.grupos_usuario_v_report(USER)) + ")";
                }
                //if (clientes != "")
                //{
                //    where = where + " and rutcliente in (" + clientes + ") ";
                //}
                if (vendedores != "")
                {
                    where = where + " and codvendedor in (" + vendedores + ") ";
                }
                if (es_vendedor == "2")
                {
                    where += " and codvendedor in ('" + USER + "')";
                }
            }


            if (l_grupos.Text != "")
            {
                where += " and user1 in (" + agregra_comillas(l_grupos.Text) + ")";
            }
            if (l_vendedores.Text != "")
            {
                where += " and codvendedor in (" + agregra_comillas(l_vendedores.Text) + ")";
            }

            DataTable table_totales = ReporteRNegocio.table_totales_c(where);
            DataView  view          = new DataView(table_totales);
            DataTable vendedores2   = view.ToTable(true, "vendedor");
            DataView  dv3           = vendedores2.DefaultView;

            dv3.Sort    = "vendedor";
            vendedores2 = dv3.ToTable();


            //PERIODOS
            string html_header = crear_reporte_correo(vendedores2, table_totales, desde, hasta, l_grupos.Text);
            string html_body   = html_header;

            DivMainContent.InnerHtml = html_body;


            DateTime t  = DateTime.Now;
            DateTime t2 = DateTime.Now;

            t = new DateTime(t.Year, t.Month, 1);
            string DESDE = t.ToShortDateString();
            string HASTA = t2.ToShortDateString();

            DESDE = DESDE.Replace("-", "/");
            HASTA = HASTA.Replace("-", "/");


            string where2 = "";

            DataTable dt3; DataView dtv3 = new DataView();

            dt3 = ReporteRNegocio.carga_grupos(DESDE, HASTA, grupos_del_usuario);
            if (dt3.Rows.Count <= 0)
            {
                ScriptManager.RegisterStartupScript(Page, this.GetType(), "teeee", "<script language='javascript'>NO_GRUPOS();</script>", false);
            }
            else
            {
                string es_vendedor = ReporteRNegocio.esvendedor(USER);
                where2 = " where FechaFactura >= CONVERT(datetime,'" + DESDE + "', 103)  and FechaFactura <= CONVERT(datetime,'" + HASTA + "',103) ";
                if (grupos != "")
                {
                    where2 = where2 + " and user1 in (" + grupos + ") ";
                }
                else if (es_vendedor != "2")
                {
                    where2 = where2 + " and user1 in (" + agregra_comillas(ReporteRNegocio.grupos_usuario(USER)) + ")";
                }
                else if (es_vendedor == "2")
                {
                    where2 = where2 + " and user1 in (" + agregra_comillas(ReporteRNegocio.grupos_usuario_v_report(USER)) + ")";
                }

                if (vendedores != "")
                {
                    where2 = where2 + " and codvendedor in (" + vendedores + ") ";
                }
                if (es_vendedor == "2")
                {
                    where2 += " and codvendedor in ('" + USER + "')";
                }
            }


            if (l_grupos.Text != "")
            {
                where2 += " and user1 in (" + agregra_comillas(l_grupos.Text) + ")";
            }
            if (l_vendedores.Text != "")
            {
                where2 += " and codvendedor in (" + agregra_comillas(l_vendedores.Text) + ")";
            }


            DataTable table_totales2 = ReporteRNegocio.table_totales(where2);
            DataView  view2          = new DataView(table_totales2);
            DataTable vendedores3    = view2.ToTable(true, "vendedor");
            DataView  dv4            = vendedores3.DefaultView;

            dv4.Sort    = "vendedor";
            vendedores3 = dv4.ToTable();

            DateTime desde_2 = Convert.ToDateTime(DESDE, new CultureInfo("es-ES"));

            DESDE = desde_2.AddDays(-1).ToShortDateString().Replace("-", "/");
            //MENSUAL
            string html_header2 = crear_reporte_correo2(vendedores3, table_totales2, DESDE, HASTA, l_grupos.Text);
            string html_body2   = html_header2;

            Div5.Visible = true;
            div3.Visible = true;
            div4.Visible = true;

            DivMainContent1.InnerHtml = html_body2;

            filtro_memoria_div.InnerHtml  = "<div class='btn-toolbar pull-left'><input type='text' id='t_filtro_memoria' style='width: 200px; margin-right: 7px; padding: 5px;' placeholder='Filtrar...' class='form-control' /></div>";
            filtro_memoria_div2.InnerHtml = "<div class='btn-toolbar pull-left'><input type='text' id='t_filtro_memoria2' style='width: 200px; margin-right: 7px; padding: 5px;' placeholder='Filtrar...' class='form-control' /></div>";

            //volver a cargar

            DataTable dt = new DataTable();

            string where3 = " where FechaFactura >= CONVERT(datetime,'" + desde + "', 103) " +
                            " and FechaFactura <= CONVERT(datetime,'" + hasta + "',103)  and user1 in (" + grupos2 + ")";


            if (l_grupos.Text != "")
            {
                where3 += " and user1 in (" + agregra_comillas(l_grupos.Text) + ")";
            }


            try
            {
                dt = ReporteRNegocio.listar_ALL_vendedores(where3);
                //dt.Rows.Add(new Object[] { "-1", "-- Todos --" });
                DataView dv2 = dt.DefaultView;
                dv2.Sort = "cod_vend";
                dt       = dv2.ToTable();
                d_vendedor_.DataSource     = dt;
                d_vendedor_.DataTextField  = "nom_vend";
                d_vendedor_.DataValueField = "cod_vend";
                //d_vendedor_.SelectedIndex = -1;
                d_vendedor_.DataBind();


                foreach (ListItem item in d_vendedor_.Items)
                {
                    if (l_vendedores.Text.Contains(item.Value.ToString()))
                    {
                        item.Selected = true;
                    }
                }
            }
            catch { }


            foreach (ListItem item in d_grupos_usuario.Items)
            {
                if (l_grupos.Text.Contains(item.Value.ToString()))
                {
                    item.Selected = true;
                }
            }


            //ScriptManager.RegisterStartupScript(Page, this.GetType(), "teeee", "<script> new Tablesort(document.getElementById('ContentPlaceHolder_Contenido_G_PRODUCTOS')); </script>", false);

            ScriptManager.RegisterStartupScript(Page, this.GetType(), "teasdasdsaeee", "<script> SortPrah(); </script>", false);
            ScriptManager.RegisterStartupScript(Page, this.GetType(), "teasdasdsaeee", "<script> superfiltro(); </script>", false);
            ScriptManager.RegisterStartupScript(Page, this.GetType(), "1dsa123das", "<script> superfiltro2(); </script>", false);

            //ScriptManager.RegisterStartupScript(Page, this.GetType(), "teeee", "<script language='javascript'>MakeStaticHeader('headertable', 100, 100, 42, false);</script>", false);
        }
Esempio n. 6
0
        protected void btn_informe_Click(object sender, EventArgs e)
        {
            //ScriptManager.RegisterStartupScript(Page, this.GetType(), "teeee", "<script> new Tablesort(document.getElementById('ContentPlaceHolder_Contenido_G_PRODUCTOS')); </script>", false);

            //if (l_vendedores.Text != "" && l_clientes.Text != "" && txt_desde.Text != "" && txt_hasta.Text != "" && l_grupos.Text != "")
            //{
            string vendedores = agregra_comillas(l_vendedores.Text);
            string clientes   = agregra_comillas(l_clientes.Text);
            string desde      = txt_desde.Text;
            string hasta      = txt_hasta.Text;
            string grupos     = agregra_comillas(l_grupos.Text);;

            string grupos_del_usuario = agregra_comillas(ReporteRNegocio.grupos_usuario(User.Identity.Name.ToString()));

            if (grupos_del_usuario == "")
            {
                grupos_del_usuario = agregra_comillas(ReporteRNegocio.grupos_usuario_v_report(User.Identity.Name.ToString()));
            }


            DataTable dt2; DataView dtv = new DataView();

            dt2 = ReporteRNegocio.carga_grupos(txt_desde.Text, txt_hasta.Text, grupos_del_usuario);
            if (dt2.Rows.Count <= 0)
            {
                ScriptManager.RegisterStartupScript(Page, this.GetType(), "teeee", "<script language='javascript'>NO_GRUPOS();</script>", false);
            }
            else
            {
                string es_vendedor = ReporteRNegocio.esvendedor(USER);
                string where = " where FechaFactura >= CONVERT(datetime,'" + desde + "', 103)  and FechaFactura <= CONVERT(datetime,'" + hasta + "',103) ";
                if (grupos != "")
                {
                    where = where + " and user1 in (" + grupos + ") ";
                }
                else if (es_vendedor != "2")
                {
                    where = where + " and user1 in (" + agregra_comillas(ReporteRNegocio.grupos_usuario(USER)) + ")";
                }
                else if (es_vendedor == "2")
                {
                    where = where + " and user1 in (" + agregra_comillas(ReporteRNegocio.grupos_usuario_v_report(USER)) + ")";
                }

                if (clientes != "")
                {
                    where = where + " and rutcliente in (" + clientes + ") ";
                }
                if (vendedores != "")
                {
                    where = where + " and codvendedor in (" + vendedores + ") ";
                }
                if (es_vendedor == "2")
                {
                    where += " and codvendedor in ('" + USER + "')";
                }
                div_report.Visible               = true;
                cont_periodos                    = 0;
                G_INFORME_VENDEDOR.Visible       = false;
                G_INFORME_TOTAL_VENDEDOR.Visible = true;
                string periodos = ReporteRNegocio.listar_periodos_(where);
                //aux = ReporteRNegocio.listar_resumen_periodo(where + " and periodo in ("+agregra_comillas(periodos)+")");
                totales = new DataTable();

                List <string> periodos_list = periodos.Split(',').ToList();

                totales.Columns.Add("FACTORES/Periodos");
                int colum = periodos_list.Count;

                foreach (string r in periodos_list)
                {
                    totales.Columns.Add(r);
                }
                DataRow       row;
                List <string> nombre_factores = get_factores();

                // CAPI
                //totales.Columns.Add("Total general");

                for (int i = 0; i <= 6; i++)
                {
                    row = totales.NewRow();
                    if (nombre_factores[i].ToString().Contains("Percentil "))
                    {
                        row["FACTORES/Periodos"] = nombre_factores[i] + t_percentil.Text + "%";
                    }
                    else
                    {
                        row["FACTORES/Periodos"] = nombre_factores[i];
                    }
                    totales.Rows.Add(row);

                    // CAPI
                    for (int y = 0; y < colum; y++)
                    {
                        if (i == 0)
                        {
                            if (y == colum)
                            {
                                // CAPI
                                // totales.Rows[i][y + 1] = ReporteRNegocio.Facturación_Mes(agregra_comillas(periodos), where).ToString("N0");
                            }
                            else
                            {
                                string periodo = totales.Columns[y + 1].ColumnName;
                                totales.Rows[i][y + 1] = ReporteRNegocio.Facturación_Mes(periodo, where).ToString("N0");
                            }
                        }
                        if (i == 1)
                        {
                            if (y == colum)
                            {
                                // CAPI
                                //totales.Rows[i][y + 1] = ReporteRNegocio._cltes_con_vta(agregra_comillas(periodos), where).ToString("N0");
                            }
                            else
                            {
                                string periodo = totales.Columns[y + 1].ColumnName;
                                totales.Rows[i][y + 1] = ReporteRNegocio._cltes_con_vta(periodo, where).ToString("N0");
                            }
                        }
                        if (i == 2)
                        {
                            totales.Rows[i][y + 1] = (+(Double.Parse(totales.Rows[0][y + 1].ToString().Replace(".", ""))) / (Double.Parse(totales.Rows[1][y + 1].ToString().Replace(".", "")))).ToString("N0");
                        }
                        if (i == 3)
                        {
                            if (y == colum)
                            {
                                // CAPI
                                //List<int> percen = (ReporteRNegocio.Datos_para_percentil(agregra_comillas(periodos), where)).ToList();
                                //if (percen.Count == 0) { totales.Rows[i][y + 1] = "0"; }
                                //else
                                //{
                                //    Double por_percentil;
                                //    if (t_percentil.Text == "") { por_percentil = 0.5; }
                                //    else
                                //    {
                                //        por_percentil = Math.Round(Double.Parse(t_percentil.Text) / 100, 2);
                                //    }
                                //    totales.Rows[i][y + 1] = Math.Round(Percentile(percen.ToArray(), por_percentil)).ToString("N0");
                                //}
                            }
                            else
                            {
                                string      periodo = totales.Columns[y + 1].ColumnName;
                                List <long> percen  = ReporteRNegocio.Datos_para_percentil(periodo, where);
                                if (percen.Count == 0)
                                {
                                    totales.Rows[i][y + 1] = "0";
                                }
                                else
                                {
                                    Double por_percentil;
                                    if (t_percentil.Text == "")
                                    {
                                        por_percentil = 0.5;
                                    }
                                    else
                                    {
                                        por_percentil = Math.Round(Double.Parse(t_percentil.Text) / 100, 2);
                                    }
                                    totales.Rows[i][y + 1] = Math.Round(Percentile(percen.ToArray(), por_percentil)).ToString("N0");
                                }
                            }
                        }

                        if (i == 4)
                        {
                            if (y == colum)
                            {
                                // CAPI
                                //totales.Rows[i][y + 1] = ReporteRNegocio.sum_sobre_este_percentil(agregra_comillas(periodos), where, Double.Parse(totales.Rows[3][y + 1].ToString().Replace(".", ""))).ToString("N0");
                            }
                            else
                            {
                                string periodo = totales.Columns[y + 1].ColumnName;
                                totales.Rows[i][y + 1] = ReporteRNegocio.sum_sobre_este_percentil(periodo, where, Double.Parse(totales.Rows[3][y + 1].ToString().Replace(".", ""))).ToString("N0");
                            }
                        }

                        if (i == 5)
                        {
                            Double sumatoria             = (Double.Parse(totales.Rows[0][y + 1].ToString().Replace(".", "")));
                            Double sum_vent_sobre_percen = (Double.Parse(totales.Rows[4][y + 1].ToString().Replace(".", "")));
                            totales.Rows[i][y + 1] = Math.Round((sum_vent_sobre_percen / sumatoria * 100)).ToString() + " %";
                        }

                        if (i == 6)
                        {
                            if (y <= colum - 2)
                            {
                                Double sum_mes          = (Double.Parse(totales.Rows[0][y + 1].ToString().Replace(".", "")));
                                Double sum_mes_anterior = (Double.Parse(totales.Rows[0][y + 2].ToString().Replace(".", "")));
                                totales.Rows[i][y + 1] = (Math.Round((sum_mes * 100 / sum_mes_anterior)) - 100).ToString() + " %";
                            }
                        }
                    }
                }

                G_INFORME_TOTAL_VENDEDOR.DataSource = totales;
                G_INFORME_TOTAL_VENDEDOR.DataBind();

                //VOLVER A CARGAR LOS MULTISELECT

                DataTable dt = new DataTable();

                try
                {
                    dt = ReporteRNegocio.carga_grupos(desde, hasta, grupos_del_usuario);
                    //dt.Rows.Add(new Object[] { "-1", "-- Todos --" });
                    DataView dv2 = dt.DefaultView;
                    dv2.Sort = "user1";
                    dt       = dv2.ToTable();
                    d_grupos_usuario.DataSource     = dt;
                    d_grupos_usuario.DataTextField  = "user1";
                    d_grupos_usuario.DataValueField = "user1";
                    //d_vendedor_.SelectedIndex = -1;
                    d_grupos_usuario.DataBind();


                    foreach (ListItem item in d_grupos_usuario.Items)
                    {
                        if (l_grupos.Text.Contains(item.Value.ToString()))
                        {
                            item.Selected = true;
                        }
                    }
                }
                catch { }

                string where2 = " where FechaFactura >= CONVERT(datetime,'" + desde + "', 103) " +
                                " and FechaFactura <= CONVERT(datetime,'" + hasta + "',103) ";

                if (grupos != "")
                {
                    where2 = where2 + " and user1 in (" + grupos + ") ";
                }
                else if (es_vendedor != "2")
                {
                    where2 = where2 + " and user1 in (" + agregra_comillas(ReporteRNegocio.grupos_usuario(USER)) + ")";
                }
                else if (es_vendedor == "2")
                {
                    where2 = where2 + " and user1 in (" + agregra_comillas(ReporteRNegocio.grupos_usuario_v_report(USER)) + ")";
                }

                if (es_vendedor == "2")
                {
                    where2 += " and codvendedor in ('" + USER + "')";
                }

                try
                {
                    dt = ReporteRNegocio.listar_ALL_vendedores(where2);
                    //dt.Rows.Add(new Object[] { "-1", "-- Todos --" });
                    DataView dv2 = dt.DefaultView;
                    dv2.Sort = "cod_vend";
                    dt       = dv2.ToTable();
                    d_vendedor_.DataSource     = dt;
                    d_vendedor_.DataTextField  = "nom_vend";
                    d_vendedor_.DataValueField = "cod_vend";
                    //d_vendedor_.SelectedIndex = -1;
                    d_vendedor_.DataBind();


                    foreach (ListItem item in d_vendedor_.Items)
                    {
                        if (l_vendedores.Text.Contains(item.Value.ToString()))
                        {
                            item.Selected = true;
                        }
                    }
                }
                catch { }
                where2 = "";
                where2 = " where FechaFactura >= CONVERT(datetime,'" + desde + "', 103) " +
                         " and FechaFactura <= CONVERT(datetime,'" + hasta + "',103) ";

                if (grupos != "")
                {
                    where2 = where2 + " and user1 in (" + grupos + ") ";
                }
                else if (es_vendedor != "2")
                {
                    where2 = where2 + " and user1 in (" + agregra_comillas(ReporteRNegocio.grupos_usuario(USER)) + ")";
                }
                else if (es_vendedor == "2")
                {
                    where2 = where2 + " and user1 in (" + agregra_comillas(ReporteRNegocio.grupos_usuario_v_report(USER)) + ")";
                }
                if (vendedores != "")
                {
                    where2 += " and codvendedor in (" + vendedores + ")";
                }
                if (es_vendedor == "2")
                {
                    where2 += " and codvendedor in ('" + USER + "')";
                }

                try
                {
                    dt = ReporteRNegocio.listar_ALL_cliente2(where2);
                    //dt.Rows.Add(new Object[] { "-1", "-- Todos --" });
                    DataView dv3 = dt.DefaultView;
                    dv3.Sort                 = "nom_cliente";
                    dt                       = dv3.ToTable();
                    d_cliente.DataSource     = dt;
                    d_cliente.DataTextField  = "nom_cliente";
                    d_cliente.DataValueField = "rut_cliente";
                    //d_vendedor_.SelectedIndex = -1;
                    d_cliente.DataBind();


                    foreach (ListItem item in d_cliente.Items)
                    {
                        if (l_clientes.Text.Contains(item.Value.ToString()))
                        {
                            item.Selected = true;
                        }
                    }
                }
                catch { }
            }
            ScriptManager.RegisterStartupScript(Page, this.GetType(), "teeee", "<script> new Tablesort(document.getElementById('ContentPlaceHolder_Contenido_G_PRODUCTOS')); </script>", false);
        }