Пример #1
0
        /// <summary>
        /// 绑定数据报表。并为其增加【小计】【总计】行。
        /// </summary>
        /// <typeparam name="T">报表记录对象的类型</typeparam>
        /// <param name="dgw">要绑定的DataGridView</param>
        /// <param name="list">数据行对象列表。执行完成后,将在该列表的最后添加一个【小计】对象。</param>
        /// <param name="statColumns">需要进行统计的列</param>
        /// <param name="totalRow">在有分页的情况下,【总计】的行对象</param>
        /// <param name="abs4Column">对目标列进行统计时,是否取其绝对值进行统计</param>
        /// <param name="isDisplayCol">是否显示列</param>
        /// <param name="DistinguishSize">区分是否是尺码列</param>
        public static void BindSource4Reports <T>(DataGridViewPagingSumCtrl ctrl, DataGridView dgw, IList <T> orgList, string[] statColumns, T totalRow, bool[] abs4Column, bool isPaging, bool isDisplayCol = true, bool DistinguishSize = true) where T : class, new()
        {
            ctrl.ClearSummary();
            ctrl.abs4Column = abs4Column;
            if (orgList == null || orgList.Count == 0)
            {
                orgList = null;
                ctrl.SetDataSource(orgList, isDisplayCol, DistinguishSize);
                return;
            }
            if (statColumns == null || statColumns.Length == 0)
            {
                ctrl.SetDataSource(orgList, isDisplayCol, DistinguishSize);
                return;
            }

            // List<T> list = new List<T>();
            List <T> calList = new List <T>();

            //  list.AddRange(orgList);
            Type type = typeof(T);

            foreach (string column in statColumns)
            {
                PropertyInfo pro = type.GetProperty(column);
                if (pro == null)
                {
                    throw new Exception(string.Format("Class [{0}] does not contain property [{1}] .", CJBasic.Helpers.TypeHelper.GetClassSimpleName(type), column));
                }

                if (!pro.CanRead || !pro.CanWrite)
                {
                    throw new Exception(string.Format("Property [{0}] of class [{1}] must be readable and writable.", column, CJBasic.Helpers.TypeHelper.GetClassSimpleName(type)));
                }
            }

            if (isPaging)
            {
                AddSumRow1(dgw, orgList, calList, statColumns, abs4Column);
            }
            if (totalRow != null)
            {
                IStatisticabled obj = totalRow as IStatisticabled;
                if (obj != null)
                {
                    obj.IsStatistics = true;
                }
                calList.Add(totalRow);
            }

            if (dgw.RowHeadersWidth < 70)
            {
                dgw.RowHeadersWidth = 70;
            }

            ctrl.SetDataSource(orgList, isDisplayCol, DistinguishSize);
            ctrl.ShowSummary(dgw, calList, statColumns);
        }