private List <Models.Statistic> tinhTiLe_quy(List <Models.Statistic> ds, int quarter1, int year1, int quarter2, int year2) { Models.Statistic d; List <Models.Statistic> tile = new List <Models.Statistic>(); if (ds.Count > 0) { Models.Statistic quy1 = new Models.Statistic(); Models.Statistic quy2 = new Models.Statistic(); quy1.Name = quarter1.ToString() + "/" + year1.ToString(); quy2.Name = quarter2.ToString() + "/" + year2.ToString(); int thang = 0; int nam = 0; string sname = String.Empty; decimal svalue = 0; decimal sreturn = 0; long scount = 0; int vt = 0; int t = 0; int quy = 0; foreach (Models.Statistic item in ds) { vt = item.Name.IndexOf('-'); int vt1 = 0; vt1 = item.Name.IndexOf('/'); if (sname == "") { thang = (int.Parse)(item.Name.Substring(0, vt)); t = thang; nam = (int.Parse)(item.Name.Substring(vt1 + 1, item.Name.Length - vt1 - 1)); quy = (int.Parse)(item.Name.Substring(vt + 1, vt1 - vt - 1)); if (quy == quarter1 && quarter1 > quarter2) { thang = thang + (quarter1 - quarter2) * 3; } if (quy == quarter2 && quarter2 > quarter1) { thang = thang + (quarter2 - quarter1) * 3; } sname = item.Name; svalue = (decimal.Parse)(item.Value.ToString()); sreturn = (decimal.Parse)(item.ReturnAmount.ToString()); scount = (long.Parse)(item.TransactionCount.ToString()); } else { if (t == (int.Parse)(item.Name.Substring(0, vt))) { d = new Models.Statistic(); d.Name = thang.ToString() + '/' + year2.ToString() + " - " + thang.ToString() + "/" + year1.ToString(); if (svalue != 0) { d.Value = Math.Round(((decimal.Parse)(item.Value.ToString()) - svalue) / svalue, 2) * 100; } else { d.Value = 100; } if (sreturn != 0) { d.ReturnAmount = Math.Round(((decimal.Parse)(item.ReturnAmount.ToString()) - sreturn) / sreturn, 2) * 100; } else { d.ReturnAmount = 100; } d.TransactionCount = (long.Parse)(item.TransactionCount.ToString()) - scount; sname = String.Empty; tile.Add(d); quy1.Value += svalue; quy1.ReturnAmount += sreturn; quy1.TransactionCount += scount; quy2.Value += (decimal.Parse)(item.Value.ToString()); quy2.ReturnAmount += (decimal.Parse)(item.ReturnAmount.ToString()); quy2.TransactionCount += (long.Parse)(item.TransactionCount.ToString()); } else { d = new Models.Statistic(); if (quy == quarter1) { d.Name = thang.ToString() + '/' + year2.ToString() + " - " + thang.ToString() + "/" + year1.ToString(); if (svalue != 0) { d.Value = -100; } else { d.Value = 0; } if (sreturn != 0) { d.ReturnAmount = -100; } else { d.ReturnAmount = 0; } d.TransactionCount = scount; tile.Add(d); quy1.Value += svalue; quy1.ReturnAmount += sreturn; quy1.TransactionCount += scount; } else { d.Name = thang.ToString() + '/' + year2.ToString() + " - " + thang.ToString() + "/" + year1.ToString(); if (svalue != 0) { d.Value = 100; } else { d.Value = 0; } if (sreturn != 0) { d.ReturnAmount = 100; } else { d.ReturnAmount = 0; } d.TransactionCount = -scount; tile.Add(d); quy2.Value += svalue; quy2.ReturnAmount += sreturn; quy2.TransactionCount += scount; } thang = (int.Parse)(item.Name.Substring(0, vt)); t = thang; nam = (int.Parse)(item.Name.Substring(vt1 + 1, item.Name.Length - vt1 - 1)); quy = (int.Parse)(item.Name.Substring(vt + 1, vt1)); if (quy == quarter1 && quarter1 > quarter2) { thang = thang + (quarter1 - quarter2) * 3; } if (quy == quarter2 && quarter2 > quarter1) { thang = thang + (quarter2 - quarter1) * 3; } sname = item.Name; svalue = (decimal.Parse)(item.Value.ToString()); sreturn = (decimal.Parse)(item.ReturnAmount.ToString()); scount = (long.Parse)(item.TransactionCount.ToString()); } } } d = new Models.Statistic(); if (sname != "") { if (quy == quarter1) { d.Name = thang.ToString() + '/' + year2.ToString() + " - " + thang.ToString() + "/" + year1.ToString(); if (svalue != 0) { d.Value = -100; } else { d.Value = 0; } if (sreturn != 0) { d.ReturnAmount = -100; } else { d.ReturnAmount = 0; } d.TransactionCount = scount; tile.Add(d); quy1.Value += svalue; quy1.ReturnAmount += sreturn; } else { d.Name = thang.ToString() + '/' + year2.ToString() + " - " + thang.ToString() + "/" + year1.ToString(); if (svalue != 0) { d.Value = 100; } else { d.Value = 0; } if (sreturn != 0) { d.ReturnAmount = 100; } else { d.ReturnAmount = 0; } d.TransactionCount = -scount; tile.Add(d); quy2.Value += svalue; quy2.ReturnAmount += sreturn; } } d = new Models.Statistic(); d.Name = quarter2 + "/" + year2 + " - " + quarter1 + "/" + year1; if (quy1.Value != 0) { d.Value = Math.Round((quy2.Value - quy1.Value) / quy1.Value, 2); } else { if (quy2.Value != 0) { d.Value = 100; } else { d.Value = 0; } } if (quy1.ReturnAmount != 0) { d.ReturnAmount = Math.Round((quy2.ReturnAmount - quy1.ReturnAmount) / quy1.ReturnAmount, 2); } else { if (quy2.ReturnAmount != 0) { d.ReturnAmount = 100; } else { d.ReturnAmount = 0; } } tile.Add(d); } return(tile); }
private List <Models.Statistic> tinhTiLe_nam(List <Models.Statistic> ds, int year1, int year2) { Models.Statistic d; List <Models.Statistic> tile = new List <Models.Statistic>(); if (ds.Count > 0) { if (ds.Count > 0) { int nam = 0; int thang = 0; string sname = String.Empty; decimal svalue = 0; decimal sreturn = 0; long scount = 0; int vt = 0; Models.Statistic nam1 = new Models.Statistic(); Models.Statistic nam2 = new Models.Statistic(); nam1.Name = year1.ToString(); nam2.Name = year2.ToString(); foreach (Models.Statistic item in ds) { vt = item.Name.IndexOf('/'); if (sname == "") { thang = (int.Parse)(item.Name.Substring(0, vt)); nam = (int.Parse)(item.Name.Substring(vt + 1, item.Name.Length - vt - 1)); sname = item.Name; svalue = (decimal.Parse)(item.Value.ToString()); sreturn = (decimal.Parse)(item.ReturnAmount.ToString()); scount = (long.Parse)(item.TransactionCount.ToString()); } else { if (thang == (int.Parse)(item.Name.Substring(0, vt))) { d = new Models.Statistic(); d.Name = thang.ToString() + "/" + year2.ToString() + " - " + thang.ToString() + "/" + year1.ToString(); if (svalue != 0) { d.Value = Math.Round(((decimal.Parse)(item.Value.ToString()) - svalue) / svalue, 2) * 100; } else { d.Value = 100; } if (sreturn != 0) { d.ReturnAmount = Math.Round(((decimal.Parse)(item.ReturnAmount.ToString()) - sreturn) / sreturn, 2) * 100; } else { d.ReturnAmount = 100; } d.TransactionCount = (long.Parse)(item.TransactionCount.ToString()) - scount; sname = String.Empty; tile.Add(d); nam1.Value = svalue; nam1.ReturnAmount = sreturn; nam2.Value = (decimal.Parse)(item.Value.ToString()); nam2.ReturnAmount = (decimal.Parse)(item.ReturnAmount.ToString()); } else { d = new Models.Statistic(); if (nam == year1) { d.Name = thang.ToString() + "/" + year2.ToString() + " - " + thang.ToString() + "/" + year1.ToString(); if (svalue != 0) { d.Value = -100; } else { d.Value = 0; } if (sreturn != 0) { d.ReturnAmount = -100; } else { d.ReturnAmount = 0; } d.TransactionCount = scount; tile.Add(d); nam1.Value = svalue; nam1.ReturnAmount = sreturn; } else { d.Name = thang.ToString() + "/" + year2.ToString() + " - " + thang.ToString() + "/" + year1.ToString(); if (svalue != 0) { d.Value = 100; } else { d.Value = 0; } if (sreturn != 0) { d.ReturnAmount = 100; } else { d.ReturnAmount = 0; } d.TransactionCount = -scount; tile.Add(d); nam2.Value = svalue; nam2.ReturnAmount = sreturn; } thang = (int.Parse)(item.Name.Substring(0, vt)); nam = (int.Parse)(item.Name.Substring(vt + 1, item.Name.Length - vt - 1)); sname = item.Name; svalue = (decimal.Parse)(item.Value.ToString()); sreturn = (decimal.Parse)(item.ReturnAmount.ToString()); scount = (long.Parse)(item.TransactionCount.ToString()); } } } d = new Models.Statistic(); if (sname != "") { if (nam == year1) { d.Name = thang.ToString() + "/" + year2.ToString() + " - " + thang.ToString() + "/" + year1.ToString(); if (svalue != 0) { d.Value = -100; } else { d.Value = 0; } if (sreturn != 0) { d.ReturnAmount = -100; } else { d.ReturnAmount = 0; } d.TransactionCount = scount; tile.Add(d); nam1.Value = svalue; nam1.ReturnAmount = sreturn; } else { d.Name = thang.ToString() + "/" + year2.ToString() + " - " + thang.ToString() + "/" + year1.ToString(); if (svalue != 0) { d.Value = 100; } else { d.Value = 0; } if (sreturn != 0) { d.ReturnAmount = 100; } else { d.ReturnAmount = 0; } d.TransactionCount = -scount; tile.Add(d); nam2.Value = svalue; nam2.ReturnAmount = sreturn; } } d = new Models.Statistic(); d.Name = year2 + " - " + year1; if (nam1.Value != 0) { d.Value = Math.Round((nam2.Value - nam1.Value) / nam1.Value, 2); } else { if (nam2.Value != 0) { d.Value = 100; } else { d.Value = 0; } } if (nam1.ReturnAmount != 0) { d.ReturnAmount = Math.Round((nam2.ReturnAmount - nam1.ReturnAmount) / nam1.ReturnAmount, 2); } else { if (nam2.ReturnAmount != 0) { d.ReturnAmount = 100; } else { d.ReturnAmount = 0; } } tile.Add(d); } } return(tile); }
private List <Models.Statistic> tinhTiLe_thang(List <Models.Statistic> ds, int month1, int year1, int month2, int year2) { Models.Statistic d; List <Models.Statistic> tile = new List <Models.Statistic>(); if (ds.Count > 0) { int ngay = 0; int thang = 0; string sname = String.Empty; decimal svalue = 0; decimal sreturn = 0; long scount = 0; int vt = 0; Models.Statistic thang1 = new Models.Statistic(); Models.Statistic thang2 = new Models.Statistic(); thang1.Name = month1 + "/" + year1; thang2.Name = month2 + "/" + year2; foreach (Models.Statistic item in ds) { vt = item.Name.IndexOf('/'); if (sname == "") { ngay = (int.Parse)(item.Name.Substring(0, vt)); thang = (int.Parse)(item.Name.Substring(vt + 1, item.Name.Length - vt - 1)); sname = item.Name; svalue = (decimal.Parse)(item.Value.ToString()); sreturn = (decimal.Parse)(item.ReturnAmount.ToString()); scount = (long.Parse)(item.TransactionCount.ToString()); } else { if (ngay == (int.Parse)(item.Name.Substring(0, vt))) { d = new Models.Statistic(); d.Name = ngay.ToString() + "/" + month2.ToString() + " - " + ngay.ToString() + "/" + month1.ToString(); if (svalue != 0) { d.Value = Math.Round(((decimal.Parse)(item.Value.ToString()) - svalue) / svalue, 2) * 100; } else { d.Value = 100; } if (sreturn != 0) { d.ReturnAmount = Math.Round(((decimal.Parse)(item.ReturnAmount.ToString()) - sreturn) / sreturn, 2) * 100; } else { d.ReturnAmount = 100; } d.TransactionCount = (long.Parse)(item.TransactionCount.ToString()) - scount; sname = String.Empty; tile.Add(d); thang1.Value += svalue; thang1.ReturnAmount += sreturn; thang1.TransactionCount += scount; thang2.Value += (decimal.Parse)(item.Value.ToString()); thang2.ReturnAmount += (decimal.Parse)(item.ReturnAmount.ToString()); thang2.TransactionCount += (long.Parse)(item.TransactionCount.ToString()); } else { d = new Models.Statistic(); if (thang == month1) { d.Name = ngay.ToString() + "/" + month2.ToString() + " - " + ngay.ToString() + "/" + month1.ToString(); if (svalue != 0) { d.Value = -100; } else { d.Value = 0; } if (sreturn != 0) { d.ReturnAmount = -100; } else { d.ReturnAmount = 0; } d.TransactionCount = scount; tile.Add(d); thang1.Value += svalue; thang1.ReturnAmount += sreturn; thang1.TransactionCount += scount; } else { d.Name = ngay.ToString() + "/" + month2.ToString() + " - " + ngay.ToString() + "/" + month1.ToString(); if (svalue != 0) { d.Value = 100; } else { d.Value = 0; } if (sreturn != 0) { d.ReturnAmount = 100; } else { d.ReturnAmount = 0; } tile.Add(d); thang2.Value += svalue; thang2.ReturnAmount += sreturn; thang2.TransactionCount += scount; } ngay = (int.Parse)(item.Name.Substring(0, vt)); thang = (int.Parse)(item.Name.Substring(vt + 1, item.Name.Length - vt - 1)); sname = item.Name; svalue = (decimal.Parse)(item.Value.ToString()); sreturn = (decimal.Parse)(item.ReturnAmount.ToString()); scount = (long.Parse)(item.TransactionCount.ToString()); } } } d = new Models.Statistic(); if (sname != "") { if (thang == month1) { d.Name = ngay.ToString() + "/" + month2.ToString() + " - " + ngay.ToString() + "/" + month1.ToString(); if (svalue != 0) { d.Value = -100; } else { d.Value = 0; } if (sreturn != 0) { d.ReturnAmount = -100; } else { d.ReturnAmount = 0; } d.TransactionCount = scount; tile.Add(d); thang1.Value += svalue; thang1.ReturnAmount += sreturn; thang1.TransactionCount += scount; } else { d.Name = ngay.ToString() + "/" + month2.ToString() + " - " + ngay.ToString() + "/" + month1.ToString(); if (svalue != 0) { d.Value = 100; } else { d.Value = 0; } if (sreturn != 0) { d.ReturnAmount = 100; } else { d.ReturnAmount = 0; } d.TransactionCount = -scount; tile.Add(d); thang2.Value += svalue; thang2.ReturnAmount += sreturn; thang2.TransactionCount += scount; } } d = new Models.Statistic(); d.Name = month2 + "/" + year2 + " - " + month1 + "/" + year1; if (thang1.Value != 0) { d.Value = Math.Round((thang2.Value - thang1.Value) / thang1.Value, 2); } else { if (thang2.Value != 0) { d.Value = 100; } else { d.Value = 0; } } if (thang1.ReturnAmount != 0) { d.ReturnAmount = Math.Round((thang2.ReturnAmount - thang1.ReturnAmount) / thang1.ReturnAmount, 2); } else { if (thang2.ReturnAmount != 0) { d.ReturnAmount = 100; } else { d.ReturnAmount = 0; } } tile.Add(d); } return(tile); }