示例#1
0
 public override void EndInit()
 {
     base.EndInit();
     AllGridView.ForEach(d => d.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill);
 }
示例#2
0
        public virtual void EndInit()
        {
            //==============================================
            //              创建过滤条件
            //==============================================
            AllFilters = new List <FilterControlBase>();

            foreach (FilterDefinition fd in FilterDefinitions)
            {
                FilterControlBase fc = (FilterControlBase)Activator.CreateInstance(fd.FilterControlType, true);
                fc.DataPropertyName = fd.DataPropertyName;
                fc.Title            = fd.Title;
                if (!fd.FilterOperator.IsNullOrWhiteSpace())
                {
                    fc.FilterOperator = fd.FilterOperator;
                }
                fc.Parent = pFilters;
                AllFilters.Add(fc);
            }
            //==============================================
            //                  创建表格
            //==============================================

            //空白组默认设置为页面标题
            ColumnDefinitions.ForEach(c => { if (c.GroupName.IsNullOrWhiteSpace())
                                             {
                                                 c.GroupName = Text;
                                             }
                                      });

            //创建Tab页
            tabContainer.TabPages.Clear();
            var queryGroups = ColumnDefinitions.Select(c => c.GroupName).Distinct().ToArray();

            foreach (string g in queryGroups)
            {
                tabContainer.TabPages.Add(g);
                //创建表格
                GridViewer dgv = new GridViewer();

                //添加列
                foreach (var col in ColumnDefinitions.Where(c => c.GroupName == g))
                {
                    dgv.CreateColumn(col.ColumnType, col.Title, col.DataPropertyName, col.Name, col.Width, col.SortMode, col.SortOrder, col.Visible, col.Index, col.Frozen);
                }
                dgv.Dock   = DockStyle.Fill;
                dgv.Parent = tabContainer.TabPages[tabContainer.TabCount - 1];

                //TODO: 暂不支持排序
            }

            //只有一个表格则不显示TabControl
            if (tabContainer.TabPages.Count == 1)
            {
                Control dgv = tabContainer.TabPages[0].Controls[0];
                dgv.Parent = this;
                Controls.Remove(tabContainer);
                tabContainer = null; //dispose
                dgv.BringToFront();
            }

            //所有表格
            AllGridView = this.FindChildControl(c => c is DataGridView).OfType <DataGridView>().ToList();

            //==============================================
            //               生成Select语句
            //==============================================
            var query = from dgv in AllGridView
                        from col in dgv.Columns.OfType <DataGridViewColumn>()
                        where !col.DataPropertyName.IsNullOrWhiteSpace()
                        select col.DataPropertyName;

            List <string> fields = new List <string>();

            foreach (string col in query.Distinct())
            {
                fields.Add("[{0}] AS '{1}'".FormatWith(col.Replace(".", "].["), col));
            }

            Sentence_Select = string.Join(", ", fields.ToArray());

            //==============================================
            //          关联表格的选择及滚动
            //==============================================
            if (AllGridView.Count > 1)
            {
                DataGridView dgv = AllGridView[0];

                for (int i = 1; i < AllGridView.Count; i++)
                {
                    DataGridView tmp = AllGridView[i];
                    dgv.SyncSelectedRowIndex(tmp);
                    dgv.SyncRowHeight(tmp);
                    dgv.SyncVerticalScroll(tmp);
                }
            }

            //==============================================
            //                  注册表格事件
            //==============================================
            //注册事件
            AllGridView.ForEach(d =>
            {
                d.ColumnHeaderMouseClick += ColumnHeaderMouseClick;
                d.SelectionChanged       += SelectionChanged;
                d.CellDoubleClick        += CellDoubleClick;
            });
        }