Advertisement
DerSkythe

Untitled

Sep 16th, 2013
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.54 KB | None | 0 0
  1. const string clientAccount = "3801000BL040264";
  2.  
  3.             bool firstRun = true;
  4.             var minMax = OracleInternetBank.OracleDb.Instance.GetMinMax(clientAccount);
  5.             var rawList = OracleInternetBank.OracleDb.Instance.ListBolcardInvoiceLinq(clientAccount);
  6.  
  7.             for (int j = 0; j < 5; j++)
  8.             {
  9.                 var startDate = DateTime.Now.AddYears((-3 - j));
  10.                 var endDate = DateTime.Now;
  11.  
  12.                 GetForeachResult(clientAccount, rawList, minMax);
  13.  
  14.                 if (firstRun)
  15.                 {
  16.                     for (int i = 0; i < 5; i++)
  17.                     {
  18.                         GetForeachResult(clientAccount, rawList, minMax);
  19.                     }
  20.  
  21.                     Console.WriteLine("Warm up finish");
  22.                 }
  23.                 var timerStart = DateTime.Now;
  24.  
  25.                 for (int i = 0; i < 100; i++)
  26.                 {
  27.                     GetForeachResult(clientAccount, rawList, minMax);
  28.                 }
  29.  
  30.                 Console.WriteLine(String.Format("Foreach: {0}", (DateTime.Now - timerStart).Milliseconds));
  31.  
  32.                 if (firstRun)
  33.                 {
  34.                     for (int i = 0; i < 5; i++)
  35.                     {
  36.                         GetLinqResult(clientAccount, rawList, minMax);
  37.                     }
  38.  
  39.                     Console.WriteLine("Warm up finish");
  40.                 }
  41.                 timerStart = DateTime.Now;
  42.  
  43.                 for (int i = 0; i < 100; i++)
  44.                 {
  45.                     GetLinqResult(clientAccount, rawList, minMax);
  46.                 }
  47.  
  48.                 Console.WriteLine(String.Format("LINQ: {0}", (DateTime.Now - timerStart).Milliseconds));
  49.                 firstRun = false;
  50.             }
  51.  
  52.  
  53.             Console.WriteLine("Finished.");
  54.             Console.ReadKey();
  55.  
  56.  
  57.  
  58. private static void GetLinqResult(string clientAccount, IEnumerable<InvoiceInfo> rawList, InvoiceMinMax minMax)
  59.         {            
  60.             var rawUnpeedList = rawList.Where(info => info.Flag == 0);
  61.             var rawPaedList = rawList.Where(info => info.Flag > 0);
  62.  
  63.             var digestList = new List<InvoicePeriod>();
  64.             var curDate = minMax.Min;
  65.             do
  66.             {
  67.                 var list = rawUnpeedList.Where(info => info.Invoice == curDate);
  68.                 var total = 0f;
  69.  
  70.                 var invoiceInfos = list as IList<InvoiceInfo> ?? list.ToList();
  71.                 if (invoiceInfos.Count > 0)
  72.                 {
  73.                     digestList.Add(new InvoicePeriod(invoiceInfos.OrderBy(info => info.TranshDate).ToList(), curDate, total));
  74.                 }
  75.                 curDate = curDate.AddMonths(1);
  76.             } while (curDate <= minMax.Max);
  77.  
  78.  
  79.             var payeedList = new List<InvoicePeriod>();
  80.             curDate = minMax.Min;
  81.             do
  82.             {
  83.                 var list = rawPaedList.Where(info => info.Invoice == curDate);
  84.                 var total = 0f;
  85.  
  86.                 var invoiceInfos = list as IList<InvoiceInfo> ?? list.ToList();
  87.                 if (invoiceInfos.Count > 0)
  88.                 {
  89.                     payeedList.Add(new InvoicePeriod(invoiceInfos.OrderBy(info => info.TranshDate).ToList(), curDate, total));
  90.                 }
  91.                 curDate = curDate.AddMonths(1);
  92.             } while (curDate <= minMax.Max);
  93.         }
  94.  
  95.         private static void GetForeachResult(string clientAccount, IEnumerable<InvoiceInfo> rawList, InvoiceMinMax minMax)
  96.         {
  97.             var rawUnpayedList = new List<InvoiceInfo>();
  98.             var rawPayedList = new List<InvoiceInfo>();
  99.  
  100.             foreach (var row in rawList)
  101.             {
  102.                 if (row.Flag == 0)
  103.                 {
  104.                     rawUnpayedList.Add(row);
  105.                 }
  106.             }
  107.             foreach (var row in rawList)
  108.             {
  109.                 if (row.Flag > 0)
  110.                 {
  111.                     rawPayedList.Add(row);
  112.                 }
  113.             }
  114.  
  115.             var unpayedList = new List<InvoicePeriod>();
  116.             var curDate = minMax.Min;
  117.             do
  118.             {
  119.                 var list = new List<InvoiceInfo>();
  120.  
  121.                 foreach (var row in rawUnpayedList)
  122.                 {
  123.                     if (row.Invoice == curDate)
  124.                     {
  125.                         list.Add(row);
  126.                     }
  127.                 }
  128.                 var total = 0f;
  129.                 if (list.Count > 0)
  130.                 {
  131.                     list.Sort((p1, p2) => p1.TranshDate.CompareTo(p2.TranshDate)
  132.                         );
  133.                     unpayedList.Add(new InvoicePeriod(list, curDate, total));
  134.                 }
  135.                 curDate = curDate.AddMonths(1);
  136.             } while (curDate <= minMax.Max);
  137.  
  138.  
  139.             var payeedList = new List<InvoicePeriod>();
  140.             curDate = minMax.Min;
  141.             do
  142.             {
  143.                 var list = new List<InvoiceInfo>();
  144.  
  145.                 foreach (var row in rawPayedList)
  146.                 {
  147.                     if (row.Invoice == curDate)
  148.                     {
  149.                         list.Add(row);
  150.                     }
  151.                 }
  152.                 var total = 0f;
  153.                 if (list.Count > 0)
  154.                 {
  155.                     list.Sort((p1, p2) => p1.TranshDate.CompareTo(p2.TranshDate)
  156.                         );
  157.                     payeedList.Add(new InvoicePeriod(list, curDate, total));
  158.                 }
  159.                 curDate = curDate.AddMonths(1);
  160.             } while (curDate <= minMax.Max);
  161.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement