Guest User

Guest User

  • Tech Writer
  • 56
  • 1.9k

Different approach for a repetitive task

Jul 7 2016 12:21 PM
I'm looking for an alternative towards a process that takes too much code and generates significant overhead...
 
This code fills in a Chartview (LineChart) and in order to display the progression of 6 different "Areas" it runs a query 6 times and add the series 6 times... 
 
 
  1. public static void FillLineChart(ChartView chartView, CheckedDropDownList checkedDropDown, string dateFrom, string dateTo)  
  2. {  
  3.     foreach (var i in checkedDropDown.CheckedItems)  
  4.     {  
  5.         var iindex = i.RowIndex + 1;  
  6.   
  7.         if (iindex == 1)  
  8.         {  
  9.             LineSeries crime = new LineSeries();  
  10.             FunctionsDAL cr = new FunctionsDAL();  
  11.             foreach (var caseType in cr.ListCases(1, dateFrom, dateTo))  
  12.             {  
  13.                 crime.DataPoints.Add(new CategoricalDataPoint(caseType.IncrementalTotal,  
  14.                     CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(caseType.MonthNum)));  
  15.             }  
  16.             chartView.Series.Add(crime);  
  17.             crime.LegendTitle = "Crime";  
  18.             crime.Spline = true;  
  19.         }  
  20.         else if (iindex == 2)  
  21.         {  
  22.           
  23.         }  
  24.         else if (iindex == 3)  
  25.         {  
  26.               
  27.         }  
  28.           
  29.         // The same 3 more times  
  30.     }  
  31. }  
 
How could I shorten up this process? or is this the way is supposed to be working?
 
Regards. 

Answers (4)