Pie Chart error public static double

1

I have 4 pie charts in ASP.NET C #, I use webservice and Jquery, something is not working properly. The main error is the following:

I have a sliderbar that if I do not slip it in the first 10 minutes, the memory of the information that was saved in STATIC matrix variables disappear or generate some conflict. On the other hand if the trackbar slid it initially before 10 min everything works fine. Slide the trackbar to modify the pastel graphic on the webpage through webmethods.

Now, I explain in detail:

When the webpage loads it shows a bootstrap modal to request the date filter. I choose the year and the month. For this example we will take July 2016, the event is executed and server query values from January 2016 - July 2016. In this event filled the static variables of two-dimensional matrix type, each variable will contain the month and the decimal "Q" value that the consultation of the respective month.

With the code below initially what I do is to initially consult the server from January to July 2016 through SQL commands and then add by a cycle FOR the data of all months to the variables C1, C1_, D1, D1_ , E1, E1_, the last section where KBInfo1_III_B is filled is to throw a JSON and these variables "ROUTE, MONT, a3, CANT" are what the pie will occupy to fill through a jquery. Now that the matrix variables are full, if I slide the trackbar then through webmoth it calls these variables and updates those of the JSON.

//VARIABLES PARA LOS CALLBACKS.
public static decimal[,] C1, C1_, D1, D1_, E1, E1_; 

public class KBInfo1_III_B
{
    public string ruta { get; set; }
    public decimal? a3 { get; set; }
    public decimal? Monto { get; set; }
    public decimal? Cant { get; set; }

}

    public IEnumerable GetER1_B(int ano_, List<int> ddl_mes_int)
    {
        List<KBInfo1_III_B> kbItems = new List<KBInfo1_III_B>();
        string month_s = string.Empty;

        int v = ddl_mes_int.Count;
        Ruta = new decimal[16]; //Num de rutas
        Ruta_ = new decimal[16]; //Monto de rutas
        Name = new string[16]; //Nombre de rutas
        RutaP = new decimal[16]; // Porcentaje de ruta 

        C1 = new decimal[v, 16];
        C1_ = new decimal[v, 16];
        TOT_pie1 = new decimal[v];
        using (SqlConnection sqlcon = new SqlConnection(ConfigurationManager.ConnectionStrings["constrSHALER"].ConnectionString))
        {
             int day;
             //for (int j = 0; j <= month-1; j++)
             //   {
             year = ano_;
             foreach (int j in ddl_mes_int)
             {
                 //j = j - 1;

                day = DateTime.DaysInMonth(year, j);
                if (month < 10)
                {
                    month_s = "0" + j;
                }
                else
                {
                    month_s = j.ToString();
                }
                using (SqlCommand cmd = new SqlCommand("Bonificadas_ruta", sqlcon))
                {
                    //string b = pt[n_].ToString();
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@fechao", (year + month_s + "01").ToString());
                    cmd.Parameters.AddWithValue("@fecha", (year + month_s + day).ToString());
                    cmd.Parameters.AddWithValue("@pt", "PT-001.");
                    using (System.Data.SqlClient.SqlDataAdapter da = new SqlDataAdapter(cmd))
                    { 
                            DataTable dt = new DataTable();
                            da.Fill(dt);

                            // Declare an object variable.
                            object sumObject;
                            sumObject = dt.Compute("Sum(costo)", "");

                            TOT_pie1[j - 1] = Convert.ToDecimal(sumObject);                             
                            foreach (DataRow row in dt.Rows)
                            {
                                if (row["WAREHOUSE_ID"].ToString() == "VEN-01")
                                {
                                    Name[0] = "R1";
                                    Ruta[0] = Convert.ToDecimal(row["CANT"]);  //Cantidad
                                    Ruta_[0] = Convert.ToDecimal(row["COSTO"]); //Monto      
                                    RutaP[0] = Convert.ToDecimal(row["COSTO"]) / Convert.ToDecimal(sumObject);
                                }
                                if (row["WAREHOUSE_ID"].ToString() == "VEN-02")
                                {
                                    Name[1] = "R2";
                                    Ruta[1] = Convert.ToDecimal(row["CANT"]);  //Cantidad
                                    Ruta_[1] = Convert.ToDecimal(row["COSTO"]); //Monto     
                                    RutaP[1] = Convert.ToDecimal(row["COSTO"]) / Convert.ToDecimal(sumObject);
                                }
                                if (row["WAREHOUSE_ID"].ToString() == "VEN-03")
                                {
                                    Name[2] = "R3";
                                    Ruta[2] = Convert.ToDecimal(row["CANT"]);  //Cantidad
                                    Ruta_[2] = Convert.ToDecimal(row["COSTO"]); //Monto   
                                    RutaP[2] = Convert.ToDecimal(row["COSTO"]) / Convert.ToDecimal(sumObject);
                                }
                                if (row["WAREHOUSE_ID"].ToString() == "VEN-04")
                                {
                                    Name[3] = "R4";
                                    Ruta[3] = Convert.ToDecimal(row["CANT"]);  //Cantidad
                                    Ruta_[3] = Convert.ToDecimal(row["COSTO"]); //Monto     
                                    RutaP[3] = Convert.ToDecimal(row["COSTO"]) / Convert.ToDecimal(sumObject);
                                }
                                if (row["WAREHOUSE_ID"].ToString() == "VEN-05")
                                {
                                    Name[4] = "R5";
                                    Ruta[4] = Convert.ToDecimal(row["CANT"]);  //Cantidad
                                    Ruta_[4] = Convert.ToDecimal(row["COSTO"]); //Monto  
                                    RutaP[4] = Convert.ToDecimal(row["COSTO"]) / Convert.ToDecimal(sumObject);
                                }
                                if (row["WAREHOUSE_ID"].ToString() == "VEN-06")
                                {
                                    Name[5] = "R6";
                                    Ruta[5] = Convert.ToDecimal(row["CANT"]);  //Cantidad
                                    Ruta_[5] = Convert.ToDecimal(row["COSTO"]); //Monto  
                                    RutaP[5] = Convert.ToDecimal(row["COSTO"]) / Convert.ToDecimal(sumObject);
                                }
                                if (row["WAREHOUSE_ID"].ToString() == "VEN-07")
                                {
                                    Name[6] = "R7";
                                    Ruta[6] = Convert.ToDecimal(row["CANT"]);  //Cantidad
                                    Ruta_[6] = Convert.ToDecimal(row["COSTO"]); //Monto    
                                    RutaP[6] = Convert.ToDecimal(row["COSTO"]) / Convert.ToDecimal(sumObject);
                                }
                                if (row["WAREHOUSE_ID"].ToString() == "VEN-08")
                                {
                                    Name[7] = "R8";
                                    Ruta[7] = Convert.ToDecimal(row["CANT"]);  //Cantidad
                                    Ruta_[7] = Convert.ToDecimal(row["COSTO"]); //Monto 
                                    RutaP[7] = Convert.ToDecimal(row["COSTO"]) / Convert.ToDecimal(sumObject);
                                }
                                if (row["WAREHOUSE_ID"].ToString() == "VEN-09")
                                {
                                    Name[8] = "R9";
                                    Ruta[8] = Convert.ToDecimal(row["CANT"]);  //Cantidad
                                    Ruta_[8] = Convert.ToDecimal(row["COSTO"]); //Monto   
                                    RutaP[8] = Convert.ToDecimal(row["COSTO"]) / Convert.ToDecimal(sumObject);
                                }
                                if (row["WAREHOUSE_ID"].ToString() == "VEN-10")
                                {
                                    Name[9] = "R10";
                                    Ruta[9] = Convert.ToDecimal(row["CANT"]);  //Cantidad
                                    Ruta_[9] = Convert.ToDecimal(row["COSTO"]); //Monto   
                                    RutaP[9] = Convert.ToDecimal(row["COSTO"]) / Convert.ToDecimal(sumObject);
                                }
                                if (row["WAREHOUSE_ID"].ToString() == "VEN-11")
                                {
                                    Name[10] = "R11";
                                    Ruta[10] = Convert.ToDecimal(row["CANT"]);  //Cantidad
                                    Ruta_[10] = Convert.ToDecimal(row["COSTO"]); //Monto      
                                    RutaP[10] = Convert.ToDecimal(row["COSTO"]) / Convert.ToDecimal(sumObject);
                                }
                                if (row["WAREHOUSE_ID"].ToString() == "VEN-CLIENTE")
                                {
                                    Name[11] = "CLIENTE";
                                    Ruta[11] = Convert.ToDecimal(row["CANT"]);  //Cantidad
                                    Ruta_[11] = Convert.ToDecimal(row["COSTO"]); //Monto   
                                    RutaP[11] = Convert.ToDecimal(row["COSTO"]) / Convert.ToDecimal(sumObject);
                                }
                                if (row["WAREHOUSE_ID"].ToString() == "VEN-INST")
                                {
                                    Name[12] = "INST.";
                                    Ruta[12] = Convert.ToDecimal(row["CANT"]);  //Cantidad
                                    Ruta_[12] = Convert.ToDecimal(row["COSTO"]); //Monto    
                                    RutaP[12] = Convert.ToDecimal(row["COSTO"]) / Convert.ToDecimal(sumObject);
                                }
                                if (row["WAREHOUSE_ID"].ToString() == "VEN-PLANTA")
                                {
                                    Name[13] = "PLANTA";
                                    Ruta[13] = Convert.ToDecimal(row["CANT"]);  //Cantidad
                                    Ruta_[13] = Convert.ToDecimal(row["COSTO"]); //Monto      
                                    RutaP[13] = Convert.ToDecimal(row["COSTO"]) / Convert.ToDecimal(sumObject);
                                }
                                if (row["WAREHOUSE_ID"].ToString() == "VEN-PREV-01")
                                {
                                    Name[14] = "PREV. 1";
                                    Ruta[14] = Convert.ToDecimal(row["CANT"]);  //Cantidad
                                    Ruta_[14] = Convert.ToDecimal(row["COSTO"]); //Monto     
                                    RutaP[14] = Convert.ToDecimal(row["COSTO"]) / Convert.ToDecimal(sumObject);
                                }
                                if (row["WAREHOUSE_ID"].ToString() == "VEN-PREV-02")
                                {
                                    Name[15] = "PREV. 2";
                                    Ruta[15] = Convert.ToDecimal(row["CANT"]);  //Cantidad
                                    Ruta_[15] = Convert.ToDecimal(row["COSTO"]); //Monto    
                                    RutaP[15] = Convert.ToDecimal(row["COSTO"]) / Convert.ToDecimal(sumObject);
                                }

                            }
                    }
                }

                    for (int i = 0; i <= 15; i++)
                    {
                        if (i == 0)
                        {
                            C1[j - 1, i] = Ruta[i];  //Cantidad
                            C1_[j - 1, i] = Ruta_[i]; //Monto
                        }
                        if (i == 1)
                        {
                            C1[j - 1, i] = Ruta[i];  //Cantidad
                            C1_[j - 1, i] = Ruta_[i]; //Monto
                        }
                        if (i == 2)
                        {
                            C1[j - 1, i] = Ruta[i];  //Cantidad
                            C1_[j - 1, i] = Ruta_[i]; //Monto
                        }
                        if (i == 3)
                        {
                            C1[j - 1, i] = Ruta[i];  //Cantidad
                            C1_[j - 1, i] = Ruta_[i]; //Monto
                        }
                        if (i == 4)
                        {
                            C1[j - 1, i] = Ruta[i];  //Cantidad
                            C1_[j - 1, i] = Ruta_[i]; //Monto
                        }
                        if (i == 5)
                        {
                            C1[j - 1, i] = Ruta[i];  //Cantidad
                            C1_[j - 1, i] = Ruta_[i]; //Monto
                        }
                        if (i == 6)
                        {
                            C1[j - 1, i] = Ruta[i];  //Cantidad
                            C1_[j - 1, i] = Ruta_[i]; //Monto
                        }
                        if (i == 7)
                        {
                            C1[j - 1, i] = Ruta[i];  //Cantidad
                            C1_[j - 1, i] = Ruta_[i]; //Monto
                        }
                        if (i == 8)
                        {
                            C1[j - 1, i] = Ruta[i];  //Cantidad
                            C1_[j - 1, i] = Ruta_[i]; //Monto
                        }
                        if (i == 9)
                        {
                            C1[j - 1, i] = Ruta[i];  //Cantidad
                            C1_[j - 1, i] = Ruta_[i]; //Monto
                        }
                        if (i == 10)
                        {
                            C1[j - 1, i] = Ruta[i];  //Cantidad
                            C1_[j - 1, i] = Ruta_[i]; //Monto
                        }
                        if (i == 11)
                        {
                            C1[j - 1, i] = Ruta[i];  //Cantidad
                            C1_[j - 1, i] = Ruta_[i]; //Monto
                        }
                        if (i == 12)
                        {
                            C1[j - 1, i] = Ruta[i];  //Cantidad
                            C1_[j - 1, i] = Ruta_[i]; //Monto
                        }
                        if (i == 13)
                        {
                            C1[j - 1, i] = Ruta[i];  //Cantidad
                            C1_[j - 1, i] = Ruta_[i]; //Monto
                        }
                        if (i == 14)
                        {
                            C1[j - 1, i] = Ruta[i];  //Cantidad
                            C1_[j - 1, i] = Ruta_[i]; //Monto
                        }
                        if (i == 15)
                        {
                            C1[j - 1, i] = Ruta[i];  //Cantidad
                            C1_[j - 1, i] = Ruta_[i]; //Monto
                        }

                        //En el load inicial , mandamos el último mes consultado al jquery.
                        if (j == (month - 1))
                        {

                        kbItems.Add(new KBInfo1_III_B()
                        {
                            ruta = Name[i],
                            a3 = RutaP[i],
                            Cant = Ruta[i],
                            Monto = Ruta_[i]

                        });

                        }
                    }

        }       

            }


        return kbItems;
    }




   [WebMethod]
    public static List<CharItem1> Pie1_WM(string name)
    {
        int month = Convert.ToInt16(name) - 1;
        List<CharItem1> ListPie = new List<CharItem1>();
        ListPie.Add(new CharItem1() { ruta = "R1", Cant = DataHelper3.C1[(month), 0], Monto = DataHelper3.C1_[(month), 0], a3 = (DataHelper3.C1_[(month), 0] / DataHelper3.TOT_pie1[(month)]) });
        ListPie.Add(new CharItem1() { ruta = "R2", Cant = DataHelper3.C1[(month), 1], Monto = DataHelper3.C1_[(month), 1], a3 = (DataHelper3.C1_[(month), 1] / DataHelper3.TOT_pie1[(month)]) });
        ListPie.Add(new CharItem1() { ruta = "R3", Cant = DataHelper3.C1[(month), 2], Monto = DataHelper3.C1_[(month), 2], a3 = (DataHelper3.C1_[(month), 2] / DataHelper3.TOT_pie1[(month)]) });
        ListPie.Add(new CharItem1() { ruta = "R4", Cant = DataHelper3.C1[(month), 3], Monto = DataHelper3.C1_[(month), 3], a3 = (DataHelper3.C1_[(month), 3] / DataHelper3.TOT_pie1[(month)]) });
        ListPie.Add(new CharItem1() { ruta = "R5", Cant = DataHelper3.C1[(month), 4], Monto = DataHelper3.C1_[(month), 4], a3 = (DataHelper3.C1_[(month), 4] / DataHelper3.TOT_pie1[(month)]) });
        ListPie.Add(new CharItem1() { ruta = "R6", Cant = DataHelper3.C1[(month), 5], Monto = DataHelper3.C1_[(month), 5], a3 = (DataHelper3.C1_[(month), 5] / DataHelper3.TOT_pie1[(month)]) });
        ListPie.Add(new CharItem1() { ruta = "R7", Cant = DataHelper3.C1[(month), 6], Monto = DataHelper3.C1_[(month), 6], a3 = (DataHelper3.C1_[(month), 6] / DataHelper3.TOT_pie1[(month)]) });
        ListPie.Add(new CharItem1() { ruta = "R8", Cant = DataHelper3.C1[(month), 7], Monto = DataHelper3.C1_[(month), 7], a3 = (DataHelper3.C1_[(month), 7] / DataHelper3.TOT_pie1[(month)]) });
        ListPie.Add(new CharItem1() { ruta = "R9", Cant = DataHelper3.C1[(month), 8], Monto = DataHelper3.C1_[(month), 8], a3 = (DataHelper3.C1_[(month), 8] / DataHelper3.TOT_pie1[(month)]) });
        ListPie.Add(new CharItem1() { ruta = "R10", Cant = DataHelper3.C1[(month), 9], Monto = DataHelper3.C1_[(month), 9], a3 = (DataHelper3.C1_[(month), 9] / DataHelper3.TOT_pie1[(month)]) });
        ListPie.Add(new CharItem1() { ruta = "R11", Cant = DataHelper3.C1[(month), 10], Monto = DataHelper3.C1_[(month), 10], a3 = (DataHelper3.C1_[(month), 10] / DataHelper3.TOT_pie1[(month)]) });
        ListPie.Add(new CharItem1() { ruta = "CLIENTE", Cant = DataHelper3.C1[(month), 11], Monto = DataHelper3.C1_[(month), 11], a3 = (DataHelper3.C1_[(month), 11] / DataHelper3.TOT_pie1[(month)]) });
        ListPie.Add(new CharItem1() { ruta = "INST.", Cant = DataHelper3.C1[(month), 12], Monto = DataHelper3.C1_[(month), 12], a3 = (DataHelper3.C1_[(month), 12] / DataHelper3.TOT_pie1[(month)]) });
        ListPie.Add(new CharItem1() { ruta = "PLANTA", Cant = DataHelper3.C1[(month), 13], Monto = DataHelper3.C1_[(month), 13], a3 = (DataHelper3.C1_[(month), 13] / DataHelper3.TOT_pie1[(month)]) });
        ListPie.Add(new CharItem1() { ruta = "PREV. 1", Cant = DataHelper3.C1[(month), 14], Monto = DataHelper3.C1_[(month), 14], a3 = (DataHelper3.C1_[(month), 14] / DataHelper3.TOT_pie1[(month)]) });
        ListPie.Add(new CharItem1() { ruta = "PREV. 2", Cant = DataHelper3.C1[(month), 15], Monto = DataHelper3.C1_[(month), 15], a3 = (DataHelper3.C1_[(month), 15] / DataHelper3.TOT_pie1[(month)]) });
        return ListPie;
    }

I understand that the best thing would be to consult the server again, but it was difficult for me to consult it and send the response to the clientside with the help of the webmethod since it did not allow me to use the SQL connection language and commands. Surely here is the problem. Or maybe use variables of type Session.

    
asked by N'oel C'alero 20.09.2016 в 19:56
source

1 answer

1

The truth is that I would not recommend the path you are taking, the static can have problems of concure access and headaches

What I would recommend is for these separate variables to be defined in some entity, that is, to define a class with a more significant structure than simple loose variables

Then by means of the cache options keep the data

Tutorial: Caching application data in ASP.NET

If the webmethod is static you can use the HttpContext.Current.Cache to access it

Basically that the GetER1_B () method would generate the data and, in addition to returning them, it would put them in cache, when you want to access these valid ones if they are in cache, if they are there, but invoke the method to go against the db and retrieve updated data because the cache expired

    
answered by 21.09.2016 в 06:11