ahmed elbarbary

ahmed elbarbary

  • NA
  • 1.6k
  • 253.7k

When Display data in datagridview it take too much time alth

Jun 19 2018 5:20 AM
Problem
 
When Display data in datagridview it take too much time although data not more why and how to reduce time .
 
Data Display in datagridview windows form is 325 members only and not big data .
 
It take too much time when press buttonshow click event to show data in datagridview
 
it take may be 45 minutes meaning it take 3/4 hour to show data in datagridview
 
why and how to reduce time
  1. private void GetMemberAccount(string MemberCode)    
  2. {    
  3.     Tax = GetTax();  
  4.     DataTable DTPriceList;  
  5.     Annual = 0; UnderAge = 0; OverAge = 0; BabySitter = 0;  
  6.     TotalUnderAge = 0; TotalOverAge = 0; TotalAnnual = 0; NetTotalAnnual = 0;  
  7.     CridtValue1 = 0; CridtValue2 = 0;  
  8.     string SQL = @"Select * From View_MembersWithPriceList where  (MemberCode = N'" + MemberCode + "') and (RelatedMemberCode  IS NULL) and (Member ='True')  AND (Year = " + txtYear.Text + ")";  
  9.     DTPriceList = DataAccess.ExecuteDataTable(SQL);  
  10.     if (DTPriceList.Rows.Count > 0)  
  11.     {  
  12.         if (!string.IsNullOrEmpty(Convert.ToString(DTPriceList.Rows[0]["Annual"])))  
  13.         {  
  14.             Annual = Convert.ToDouble(DTPriceList.Rows[0]["Annual"]);  
  15.         }  
  16.         if (!string.IsNullOrEmpty(Convert.ToString(DTPriceList.Rows[0]["KidsUnderAge"])))  
  17.         {  
  18.             UnderAge = Convert.ToDouble(DTPriceList.Rows[0]["KidsUnderAge"]);  
  19.         }  
  20.         if (!string.IsNullOrEmpty(Convert.ToString(DTPriceList.Rows[0]["OverAgeChildPrice"])))  
  21.         {  
  22.             OverAge = Convert.ToDouble(DTPriceList.Rows[0]["OverAgeChildPrice"]);  
  23.         }  
  24.         if (!string.IsNullOrEmpty(Convert.ToString(DTPriceList.Rows[0]["OverAgeChildPrice"])))  
  25.         {  
  26.             OverAge = Convert.ToDouble(DTPriceList.Rows[0]["OverAgeChildPrice"]);  
  27.         }  
  28.         if (!string.IsNullOrEmpty(Convert.ToString(DTPriceList.Rows[0]["BabySitter"])))  
  29.         {  
  30.             BabySitter = Convert.ToDouble(DTPriceList.Rows[0]["BabySitter"]);  
  31.         }  
  32.         if (!string.IsNullOrEmpty(Convert.ToString(DTPriceList.Rows[0]["ManagmentFees"])))  
  33.         {  
  34.             ManagmentFees = Convert.ToDouble(DTPriceList.Rows[0]["ManagmentFees"]);  
  35.         }  
  36.         if (!string.IsNullOrEmpty(Convert.ToString(DTPriceList.Rows[0]["CardFees"])))  
  37.         {  
  38.             CardFees = Convert.ToDouble(DTPriceList.Rows[0]["CardFees"]);  
  39.         }  
  40.         TotalUnderAge = ChildUndrAge(MemberCode);  
  41.         TotalOverAge = ChildOverAge(MemberCode);  
  42.         CountCard = GetCountCards(MemberCode);  
  43.         if(CountCard > 0)  
  44.         {  
  45.             TotalCardAmount = CountCard * CardFees;  
  46.         }  
  47.         if (TotalUnderAge > 0)  
  48.         {  
  49.             TotalUnderAge = TotalUnderAge * UnderAge;  
  50.         }  
  51.         if (TotalOverAge > 0)  
  52.         {  
  53.             TotalOverAge = TotalOverAge * OverAge;  
  54.         }  
  55.         if (BabySiter(MemberCode) == false)  
  56.         {  
  57.             BabySitter = 0;  
  58.         }  
  59.         TotalAnnual = (Annual + TotalUnderAge + TotalOverAge + BabySitter + ManagmentFees + TotalCardAmount);  
  60.         NetTotalAnnual = TotalAnnual;  
  61.         int Diff = DiffDate(MemberCode);  
  62.         if (Diff < 12 && Diff !=0)  
  63.         {  
  64.             double CustomAnnual = TotalAnnual / 12;  
  65.             TotalAnnual = Math.Round(CustomAnnual * Diff, 2);  
  66.         }  
  67.         if (Diff ==0)  
  68.         {  
  69.             TotalAnnual = 0;  
  70.         }  
  71.         if (TotalAnnual > 0)  
  72.         {  
  73.             TotalDue= CridtValue1 = Math.Round((TotalAnnual / Tax),2);  
  74.             TotalTax = TotalAnnual - TotalDue;  
  75.             CridtValue2 = Math.Round(TotalAnnual - CridtValue1, 2);  
  76.          }  
  77.     }  
  78. }  
Under button show this code is written
  1. if (!string.IsNullOrEmpty(txtYear.Text))  
  2. {  
  3.     string Sql = "Select * From View_MembersWithPriceList where  (RelatedMemberCode  IS NULL) and (Member ='True') AND (Year = " + txtYear.Text + ")";  
  4.     DT = DataAccess.ExecuteDataTable(Sql);  
  5.     if (DT.Rows.Count > 0)  
  6.     {  
  7.         Grid.DataBinding(DT);  
  8.         for (int i = 0; i < Grid.Rows.Count; i++)  
  9.         {  
  10.             MemberCode = Convert.ToString(Grid.Rows[i].Cells["MemberCode"].Value);  
  11.             if (!string.IsNullOrEmpty(MemberCode))  
  12.             {  
  13.                 GetMemberAccount(MemberCode);  
  14.                 Grid.Rows[i].Cells["AnnualValue"].Value = Annual;  
  15.                 Grid.Rows[i].Cells["OverAge"].Value = TotalOverAge;  
  16.                 Grid.Rows[i].Cells["UnderAge"].Value = TotalUnderAge;  
  17.                 Grid.Rows[i].Cells["BabySitter"].Value = BabySitter;  
  18.                 Grid.Rows[i].Cells["NetTotal"].Value = NetTotalAnnual;  
  19.                 Grid.Rows[i].Cells["TotalDue"].Value = TotalAnnual;  
  20.                 Grid.Rows[i].Cells["Total"].Value = TotalDue;  
  21.                 Grid.Rows[i].Cells["TotalTax"].Value = TotalTax;  
  22.             }  
  23.         }  
  24.     }  
  25. }

Answers (3)