Example #1
0
        /// <summary>
        /// 填充DataGridView数据源
        /// </summary>
        /// <param name="dgv">DataGridView控件</param>
        /// <param name="year">年份</param>
        /// <param name="cats">商品分类列表</param>
        private void AddData(DataGridView dgv, int year, List <Models.GoodsCategory> cats)
        {
            Decimal total = 0;

            this.dgvGoodsRank.Rows.Clear();
            List <ReportGoodsRank> dataSources = bll.GroupStatisticsByYear(year);

            for (int month = 1; month < 13; month++)
            {
                DataGridViewRow row = new DataGridViewRow();
                //添加月份
                row.Cells.Add(this.getDateGridViewCell(month.ToString()));

                decimal cellTotal = 0;
                foreach (GoodsCategory cat in cats)
                {
                    Boolean flag = false;
                    foreach (ReportGoodsRank item in dataSources)
                    {
                        if (item.Id == year &&
                            item.Month == month &&
                            cat.Name.Trim() == item.GoodsName.Trim())
                        {
                            flag       = true;
                            cellTotal += item.Price;
                            row.Cells.Add(this.getDateGridViewCell(cat.Name.Trim() == "刷卡" ? item.Count : item.Price));
                            //统计某类商品年度销售总额
                            GetValue(cat, item);
                            break;
                        }
                    }

                    if (flag)
                    {
                        continue;
                    }

                    row.Cells.Add(this.getDateGridViewCell("0"));
                }

                total += cellTotal;
                //添加月份销售额小计

                row.Cells.Add(this.getDateGridViewCell(cellTotal));

                dgv.Rows.Add(row);
            }
            lastRow.Cells.Add(this.getDateGridViewCell(total));
            dgv.Rows.Add(lastRow);
        }