private void RefreshList() { lvwDayStats.Items.Clear(); int total0 = 0, total1 = 0, total2 = 0, total3 = 0, total4 = 0, total5 = 0; foreach (DayStat day in _daystats) { if (day.Date < _dtpFrom.Value || day.Date > _dtpTo.Value) { continue; } DayStatListViewItem item = new DayStatListViewItem(day); lvwDayStats.Items.Add(item); total0 += day.Products[0].Count; total1 += day.Products[1].Count; total2 += day.Products[2].Count; total3 += day.Products[3].Count; total4 += day.Products[4].Count; total5 += day.Products[5].Count; } lblTotalInfo.Text = string.Format( "统计时间段: \n{7} - {8}\n\nPre: {0}({9:0.0})\n1段: {1}({10:0.0})\n2段: {2}({11:0.0})\n3段: {3}({12:0.0})\n1+: {4}({13:0.0})\n2+: {5}({14:0.0})\n\n总计: {6}({15:0.0})", total0, total1, total2, total3, total4, total5, total0 + total1 + total2 + total3 + total4 + total5, ((DayStatListViewItem)lvwDayStats.Items[lvwDayStats.Items.Count - 1]).DayStat.Date.ToString("yyyy/MM/dd"), ((DayStatListViewItem)lvwDayStats.Items[0]).DayStat.Date.ToString("yyyy/MM/dd"), (float)total0 / lvwDayStats.Items.Count, (float)total1 / lvwDayStats.Items.Count, (float)total2 / lvwDayStats.Items.Count, (float)total3 / lvwDayStats.Items.Count, (float)total4 / lvwDayStats.Items.Count, (float)total5 / lvwDayStats.Items.Count, (float)(total0 + total1 + total2 + total3 + total4 + total5) / lvwDayStats.Items.Count); }
private void RefreshList() { try { lvwDayStats.Items.Clear(); int[] totals = new int[_daystats[0].Products.Count]; // total0 = 0, total1 = 0, total2 = 0, total3 = 0, total4 = 0, total5 = 0; foreach (DayStat day in _daystats) { if (day.Date < _dtpFrom.Value || day.Date > _dtpTo.Value) { continue; } DayStatListViewItem item = new DayStatListViewItem(day); lvwDayStats.Items.Add(item); for (int i = 0; i < day.Products.Count; i++) { totals[i] += day.Products[i].Count; } } if (lvwDayStats.Items.Count > 0) { StringBuilder sb = new StringBuilder(); sb.Append(string.Format("统计时间段: \n{0} - {1}\n\n", ((DayStatListViewItem)lvwDayStats.Items[lvwDayStats.Items.Count - 1]).DayStat.Date.ToString("yyyy/MM/dd"), ((DayStatListViewItem)lvwDayStats.Items[0]).DayStat.Date.ToString("yyyy/MM/dd"))); for (int i = 0; i < _daystats[0].Products.Count; i++) { ProductCount pc = _daystats[0].Products[i]; sb.Append(string.Format( "{0}: {1}({2:0.0})\n", ProductInfo.GetProductInfo(pc.Id).ShortName, totals[i], (float)totals[i] / lvwDayStats.Items.Count)); } int periodTotal = 0; foreach (int i in totals) { periodTotal += i; } sb.Append(string.Format("\n总计: {0}({1:0.0})", periodTotal, (float)periodTotal / lvwDayStats.Items.Count)); lblTotalInfo.Text = sb.ToString(); //lblTotalInfo.Text = string.Format( // "统计时间段: \n{7} - {8}\n\nPre: {0}({9:0.0})\n1段: {1}({10:0.0})\n2段: {2}({11:0.0})\n3段: {3}({12:0.0})\n1+: {4}({13:0.0})\n2+: {5}({14:0.0})\n\n总计: {6}({15:0.0})", // total0, total1, total2, total3, total4, total5, // total0 + total1 + total2 + total3 + total4 + total5, // ((DayStatListViewItem)lvwDayStats.Items[lvwDayStats.Items.Count-1]).DayStat.Date.ToString("yyyy/MM/dd"), // ((DayStatListViewItem)lvwDayStats.Items[0]).DayStat.Date.ToString("yyyy/MM/dd"), // (float)total0 / lvwDayStats.Items.Count, (float)total1 / lvwDayStats.Items.Count, (float)total2 / lvwDayStats.Items.Count, // (float)total3 / lvwDayStats.Items.Count, (float)total4 / lvwDayStats.Items.Count, (float)total5 / lvwDayStats.Items.Count, // (float)(total0 + total1 + total2 + total3 + total4 + total5) / lvwDayStats.Items.Count); } } catch (Exception ex) { Trace.WriteLine(ex.ToString()); } }