protected void G_DET_PRODUCTOS_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Cells[0].Text = cont_det.ToString();
                cont_det++;
                string where_es = " where vendedor = '" + vendedor.Trim() + "' and nombrecliente like '" + cliente + "'  ";
                for (int i = 4; i < e.Row.Cells.Count; i++)
                {
                    if (header_sum2)
                    {
                        G_DET_PRODUCTOS.HeaderRow.Cells[i].Text = G_DET_PRODUCTOS.HeaderRow.Cells[i].Text + "  (" + Convert.ToDouble(ReporteRNegocio.Facturación_Mes(G_DET_PRODUCTOS.HeaderRow.Cells[i].Text.Substring(0, 6), where_es)).ToString("N0") + ")";
                    }
                    if (i == e.Row.Cells.Count - 1)
                    {
                        header_sum2 = false;
                    }

                    double d;
                    double.TryParse(e.Row.Cells[i].Text, out d);
                    string aux = "";
                    if (d == 0)
                    {
                        aux = "";
                    }
                    else
                    {
                        aux = d.ToString("N0");
                    }
                    e.Row.Cells[i].Text = aux;
                }
            }
        }
        protected void G_PRODUCTOS_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                double sum_por_row = 0;
                string vendedor    = G_PRODUCTOS.DataKeys[e.Row.RowIndex].Values[2].ToString();
                string cliente     = G_PRODUCTOS.DataKeys[e.Row.RowIndex].Values[3].ToString();

                clsCrypto.CL_Crypto encriptador = new clsCrypto.CL_Crypto("thi");

                e.Row.Cells[1].Attributes["onclick"] = "javascript:fuera('" + encriptador.EncryptData(PERIODOS) + "', '" + encriptador.EncryptData(vendedor) + "', '" + encriptador.EncryptData(cliente) + "', '" + encriptador.EncryptData("4") + "');return false;";
                //e.Row.Cells[3].Attributes["onclick"] = "javascript:fuera22('" + encriptador.EncryptData(cliente) + "', '" + encriptador.EncryptData("88") + "');return false;";


                string script1 = string.Format("javascript:fuera22(&#39;{0}&#39;, &#39;{1}&#39;);return false;", encriptador.EncryptData(cliente), encriptador.EncryptData("88"));
                e.Row.Cells[5].Text = "  <a href='javascript:' onclick='" + script1 + "'>" + e.Row.Cells[5].Text + " </a>";


                e.Row.Cells[0].Text = cont_det.ToString();
                cont_det++;
                int colum = productos.Columns.Count;

                e.Row.Cells[2].Visible = false;
                e.Row.Cells[3].Visible = false;
                G_PRODUCTOS.HeaderRow.Cells[2].Visible = false;
                G_PRODUCTOS.HeaderRow.Cells[3].Visible = false;
                for (int i = 5; i <= colum; i++)
                {
                    G_PRODUCTOS.HeaderRow.Cells[i + 1].Attributes["data-sort-method"] = "number";
                    if (e.Row.Cells[i + 1].Text != "0")
                    {
                        double d;
                        double.TryParse(e.Row.Cells[i + 1].Text, out d);
                        string aux = "";
                        if (d == 0)
                        {
                            aux = "";
                        }
                        else
                        {
                            aux = d.ToString("N0");
                        }
                        e.Row.Cells[i + 1].Text = aux;
                        sum_por_row            += d;
                        if (i != colum)
                        {
                            string script = string.Format("javascript:fuera(&#39;{0}&#39;, &#39;{1}&#39;, &#39;{2}&#39;, &#39;{3}&#39;);return false;", encriptador.EncryptData(G_PRODUCTOS.HeaderRow.Cells[i + 1].Text.Substring(0, 6)), encriptador.EncryptData(e.Row.Cells[2].Text), encriptador.EncryptData(e.Row.Cells[3].Text), encriptador.EncryptData("8"));
                            e.Row.Cells[i + 1].Text = "  <a href='javascript:' onclick='" + script + "'>" + e.Row.Cells[i + 1].Text + " </a>";
                        }
                    }
                }
                e.Row.Cells[colum + 1].Text = sum_por_row.ToString("N0");

                if (header_sum)
                {
                    int colum2 = productos.Columns.Count;
                    for (int i = 5; i <= colum2; i++)
                    {
                        try
                        {
                            G_PRODUCTOS.HeaderRow.Cells[i + 1].Text = G_PRODUCTOS.HeaderRow.Cells[i + 1].Text + "  (" + Convert.ToDouble(ReporteRNegocio.Facturación_Mes(G_PRODUCTOS.HeaderRow.Cells[i + 1].Text, where)).ToString("N0") + ")";
                        }
                        catch { }
                    }
                    header_sum = false;
                }
            }
        }
Exemple #3
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);
        }
        public string crear_reporte_correo(DataTable dataTable, DataTable totales, string DESDE, string HASTA, string grupos)
        {
            string    periodo_anterior = "";
            string    periodo_actual   = "";
            DataView  view             = new DataView(totales);
            DataTable distinctValues   = view.ToTable(true, "periodo");
            DataView  dv = distinctValues.DefaultView;

            dv.Sort        = "periodo desc";
            distinctValues = dv.ToTable();
            int co = 1;

            foreach (DataRow r in distinctValues.Rows)
            {
                if (co == 1)
                {
                    periodo_actual = r[0].ToString();
                }
                if (co == 2)
                {
                    periodo_anterior = r[0].ToString();
                }
                co++;
            }
            if (periodo_anterior == "")
            {
                periodo_anterior = periodo_actual;
            }

            double ACUMULADO   = 0;
            int    cant_cliete = 0;
            string var1        = "";

            double total_mes_actual1 = 0;

            foreach (DataRow r2 in dataTable.Rows)
            {
                DateTime hasta_ant      = Convert.ToDateTime(HASTA, new CultureInfo("es-ES"));
                string   anterior_hasta = hasta_ant.AddMonths(-1).ToShortDateString().Replace("-", "/");
                string   where_ant      = " where vendedor = '" + r2[0].ToString() + "' and FechaFactura <= CONVERT(datetime,'" + anterior_hasta + "',103) ";

                ACUMULADO += ReporteRNegocio.Facturación_Mes(periodo_anterior, where_ant);

                total_mes_actual1 += ReporteRNegocio.Facturación_Mes(periodo_actual, " where vendedor = '" + r2[0].ToString() + "' and  periodo = " + periodo_actual);
                cant_cliete       += ReporteRNegocio._cltes_con_vta(periodo_anterior, where_ant);
            }
            var1 = (Math.Round((total_mes_actual1 * 100 / ACUMULADO)) - 100).ToString() + "%";
            if (var1.Contains("-"))
            {
                var1 = "<i style='color:red;'>" + var1 + "</i>";
            }
            //HTML_EXCEL
            string HTML_EXCEL        = "";
            string color_letra_excel = "white";
            string color_fondo_excel = "#428BCA";

            string HTML = "";

            HTML += "<table id='TABLA_REPORTE2' class='table table-advance table-bordered fill-head tablesorter filtrar2'  style='width: 98%; border-collapse: collapse;    border-spacing: 1px !important;'  width:98%;>";
            HTML += "<thead>";
            HTML += " <tr>";

            HTML_EXCEL += "<table id='T_EXCEL2' border=1>";
            HTML_EXCEL += "<tr style='background-color:" + color_fondo_excel + "; color:" + color_letra_excel + "'>";

            bool primer2 = true;

            foreach (DataRow r in distinctValues.Rows)
            {
                if (primer2)
                {
                    HTML       += "<th colspan=4;  class='test sorter-false' style='border-right: 2px solid rgb(50, 48, 48);'></th>";
                    HTML_EXCEL += "<td colspan=4 ></td>";
                    primer2     = false;
                }

                HTML       += "<th colspan=2; class='test sorter-false' style='border-right: 2px solid rgb(50, 48, 48);' > " + r[0].ToString().Trim() + "</th>";
                HTML_EXCEL += "<td colspan=2 > " + r[0].ToString().Trim() + "</td>";
            }
            HTML       += "</tr>";
            HTML_EXCEL += "</tr>";

            HTML       += "<tr>";
            HTML_EXCEL += "<tr style='background-color:" + color_fondo_excel + "; color:" + color_letra_excel + "'>";

            int  cont2   = 1;
            bool primer1 = true;

            foreach (DataRow r in distinctValues.Rows)
            {
                if (primer1)
                {
                    HTML += "<th colspan=1;  class='test' style='font-weight: bold; border-bottom: 2px solid rgb(50, 48, 48);'>Vendedores</th>";
                    HTML += "<th colspan=1;  class='test' style='font-weight: bold; border-bottom: 2px solid rgb(50, 48, 48);'>Acum.Mes Anter. (" + ACUMULADO.ToString("N0") + ")</th>";
                    HTML += "<th colspan=1;  class='test' style='font-weight: bold; border-bottom: 2px solid rgb(50, 48, 48);'>clte# (" + cant_cliete + ")</th>";
                    HTML += "<th colspan=1; id='var' class='test sort-ascending' style='font-weight: bold; border-bottom: 2px solid rgb(50, 48, 48); border-right: 2px solid rgb(50, 48, 48);'  width='95px'>%Var (" + var1 + ")&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>";


                    HTML_EXCEL += "<td>Vendedores</td>";
                    HTML_EXCEL += "<td>Acum.Mes Anter. (" + ACUMULADO.ToString("N0") + ")</td>";
                    HTML_EXCEL += "<td>clte# (" + cant_cliete + ")</td>";
                    HTML_EXCEL += "<td width='95px'>%Var (" + var1 + ")&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";

                    primer1 = false;
                }
                DataRow[]  venta = totales.Select("periodo = '" + r[0].ToString().Trim() + "'");
                DataTable  ta    = new DataTable();
                DataColumn column;
                column            = new DataColumn();
                column.ColumnName = "cont";
                ta.Columns.Add(column);
                double SUM_VENTA = 0;
                int    sum_cont  = 0;
                foreach (DataRow row in venta)
                {
                    SUM_VENTA += double.Parse(row[1].ToString());

                    DataRow row2 = ta.NewRow();
                    row2["cont"] = row[4].ToString().Trim();
                    ta.Rows.Add(row2);
                }
                DataView  view2    = new DataView(ta);
                DataTable clientes = view2.ToTable(true, "cont");
                sum_cont = clientes.Rows.Count;
                //HTML += "<td colspan=2; class='test' style='font-weight: bold; border-bottom: 2px solid rgb(50, 48, 48);'> TOTAL </td>";

                HTML += "<th colspan=1; class='test' style='font-weight: bold; border-bottom: 2px solid rgb(50, 48, 48);'> " + SUM_VENTA.ToString("N0") + " </th>";
                HTML += "<th colspan=1; class='test' style='font-weight: bold; border-bottom: 2px solid rgb(50, 48, 48); border-right: 2px solid rgb(50, 48, 48);'> " + sum_cont + "  </th>";

                HTML_EXCEL += "<td> " + SUM_VENTA.ToString("N0") + " </td>";
                HTML_EXCEL += "<td> " + sum_cont + "  </td>";
                cont2++;
            }
            HTML += "</tr>";
            HTML += "</thead>";

            HTML_EXCEL += "</tr>";

            foreach (DataRow r2 in dataTable.Rows)
            {
                HTML       += "<tr>";
                HTML_EXCEL += "<tr>";
                int cont3 = 1;

                HTML       += "<td colspan=1; style='border-right: 2px solid rgb(50, 48, 48);'> " + r2[0].ToString() + "  </td>";
                HTML_EXCEL += "<td> " + r2[0].ToString() + "  </td>";

                DateTime hasta_ant        = Convert.ToDateTime(HASTA, new CultureInfo("es-ES"));
                string   anterior_hasta   = hasta_ant.AddMonths(-1).ToShortDateString().Replace("-", "/");
                string   where_ant        = " where vendedor = '" + r2[0].ToString() + "' and FechaFactura <= CONVERT(datetime,'" + anterior_hasta + "',103) ";
                string   factur_acumulado = ReporteRNegocio.Facturación_Mes(periodo_anterior, where_ant).ToString("N0");
                double   total_mes_actual = ReporteRNegocio.Facturación_Mes(periodo_actual, " where vendedor = '" + r2[0].ToString() + "' and  periodo = " + periodo_actual);
                string   clntes           = ReporteRNegocio._cltes_con_vta(periodo_anterior, where_ant).ToString();

                HTML += "<td colspan=1;> " + factur_acumulado + "  </td>";
                HTML += "<td colspan=1;'> " + clntes + "  </td>";

                HTML_EXCEL += "<td> " + factur_acumulado + "  </td>";
                HTML_EXCEL += "<td> " + clntes + "  </td>";

                string var_ = (Math.Round((total_mes_actual * 100 / double.Parse(factur_acumulado.Replace(".", "")))) - 100).ToString() + "%";
                if (var_.Contains("∞"))
                {
                    var_ = "100%";
                }
                if (var_.Contains("NaN") || var_.Contains("∞") || var_.Contains("NeuN") || var_.Contains("Infinito"))
                {
                    var_ = "";
                }
                if (var_.Contains("-"))
                {
                    var_ = "<i style='color:red;'> " + var_ + "</i>";
                }

                string var_tool = "(" + total_mes_actual.ToString("N0") + " * 100 / " + factur_acumulado + ") -100";
                HTML       += "<td colspan=1; style='border-right: 2px solid rgb(50, 48, 48);'  width='95px'> <a data-toggle='tooltip' style='color:black;' data-placement='top' title='" + var_tool + "'>" + var_ + " </a> </td>";
                HTML_EXCEL += "<td width='70px'>" + var_ + "  </td>";
                string cod_vendedor = ReporteRNegocio.cod_vendedor(r2[0].ToString().Trim());
                foreach (DataRow r in distinctValues.Rows)
                {
                    DataRow[] venta = totales.Select(r[0].ToString() + " = periodo and vendedor = '" + r2[0].ToString().Trim() + "'");

                    string v = "-";
                    string c = "0";

                    DataTable  ta = new DataTable();
                    DataColumn column;
                    column            = new DataColumn();
                    column.ColumnName = "cont";
                    int sum_cont = 0;
                    ta.Columns.Add(column);
                    double venta_ = 0;
                    int    cont   = 0;
                    foreach (DataRow row in venta)
                    {
                        venta_ += double.Parse(row[1].ToString());
                        DataRow row2 = ta.NewRow();
                        row2["cont"] = row[4].ToString().Trim();
                        ta.Rows.Add(row2);
                    }
                    DataView  view2    = new DataView(ta);
                    DataTable clientes = view2.ToTable(true, "cont");
                    sum_cont = clientes.Rows.Count;
                    clsCrypto.CL_Crypto encriptador = new clsCrypto.CL_Crypto("thi");
                    //encriptador.EncryptData(

                    string bit     = "2";
                    string script2 = string.Format("javascript:fuera(&#39;{0}&#39;, &#39;{1}&#39;, &#39;{2}&#39;, &#39;{3}&#39;)", encriptador.EncryptData(r[0].ToString()), encriptador.EncryptData(cod_vendedor), encriptador.EncryptData(grupos.Trim().Replace("'", "")), encriptador.EncryptData(bit));

                    if (venta_ != 0)
                    {
                        HTML       += "<td colspan=1;> <a data-toggle='tooltip' data-placement='top' title='" + r2[0].ToString().Trim() + "' href='javascript:' onclick='" + script2 + "'>" + venta_.ToString("N0") + " </a> </td>";
                        HTML_EXCEL += "<td>" + venta_.ToString("N0") + "</td>";
                    }
                    else
                    {
                        HTML       += "<td colspan=1;> " + venta_ + "</td>";
                        HTML_EXCEL += "<td> " + venta_ + "</td>";
                    }
                    HTML       += "<td colspan=1; style='border-right: 2px solid rgb(50, 48, 48);'> " + sum_cont + "</td>";
                    HTML_EXCEL += "<td> " + sum_cont + "</td>";
                    cont3++;
                }
                HTML       += "</tr>";
                HTML_EXCEL += "</tr>";
            }


            HTML       += "  </table>";
            HTML_EXCEL += "  </table>";
            HTML       += "</div>";

            R_Excel_2.InnerHtml = HTML_EXCEL;
            return(HTML);
        }
Exemple #5
0
 protected void G_DET_PRODUCTOS_RowDataBound(object sender, GridViewRowEventArgs e)
 {
     if (e.Row.RowType == DataControlRowType.DataRow)
     {
         e.Row.Cells[0].Text = cont_det.ToString();
         cont_det++;
         int colum = 6;
         for (int i = 2; i <= colum; i++)
         {
             try
             {
                 e.Row.Cells[i + 1].Text = Convert.ToInt32(e.Row.Cells[i + 1].Text).ToString("N0");
             }
             catch { }
         }
         string where_es = " where vendedor = '" + vendedor.Trim() + "' and nombrecliente like '" + cliente + "'  ";
         if (header_sum2)
         {
             int colum2 = productos.Columns.Count;
             for (int i = 3; i <= colum2; i++)
             {
                 try
                 {
                     G_DET_PRODUCTOS.HeaderRow.Cells[i + 1].Text = G_DET_PRODUCTOS.HeaderRow.Cells[i + 1].Text + "  (" + Convert.ToDouble(ReporteRNegocio.Facturación_Mes(G_DET_PRODUCTOS.HeaderRow.Cells[i + 1].Text, where_es)).ToString("N0") + ")";
                 }
                 catch { }
             }
             header_sum2 = false;
         }
     }
 }