Example #1
0
        //设置构造函数的参数
        private void SetMasterControl(DataSet cDataset, ControlType eControlType)
        {
            //1.控件初始化赋值
            this.Controls.Add(ChildView);
            InitializeComponent();
            _cDataset          = cDataset;
            ChildView.CDataset = cDataset;
            CModule.ApplyGridTheme(this);
            Dock                    = DockStyle.Fill;
            _eControlType           = eControlType;
            this.AllowUserToAddRows = false;

            //2.通过读取DataSet里面的Relations得到表的关联关系
            if (cDataset.Relations.Count <= 0)
            {
                return;
            }
            DataRelation oRelates;

            if (eControlType == ControlType.OutSide)
            {
                oRelates = cDataset.Relations[1];
                ChildView.Add(oRelates.ParentTable.TableName, oRelates.ParentColumns[0].ColumnName, oRelates.ChildColumns[0].ColumnName);
            }
            else if (eControlType == ControlType.Middle)
            {
                oRelates = cDataset.Relations[cDataset.Relations.Count - 1];
                ChildView.Add2(oRelates.ChildTable.TableName);
            }

            //3.设置主外键对应关系
            oRelates = cDataset.Relations[0];
            //主表里面的值,副表里面的过滤字段
            SetParentSource(oRelates.ParentTable.TableName, oRelates.ParentColumns[0].ColumnName, oRelates.ChildColumns[0].ColumnName);
        }
Example #2
0
        public void Add2(string tableName)
        {
            //TabPage tPage = new TabPage() { Text = pageCaption };
            //this.Controls.Add(tPage);
            DataGridView newGrid = new DataGridView
            {
                Dock               = DockStyle.Fill,
                DataSource         = new DataView(CDataset.Tables[tableName]),
                AllowUserToAddRows = false
            };

            //tPage.Controls.Add(newGrid);
            this.Controls.Add(newGrid);
            CModule.ApplyGridTheme(newGrid);
            CModule.SetGridRowHeader(newGrid);
            newGrid.RowPostPaint += CModule.rowPostPaint_HeaderCount;
            ChildGrid.Add(newGrid);
        }
Example #3
0
        public void Add(string tableName, string strPrimaryKey, string strForeignKey)
        {
            //TabPage tPage = new TabPage() { Text = pageCaption };
            //this.Controls.Add(tPage);
            MasterControl newGrid = new MasterControl(CDataset, ControlType.Middle)
            {
                Dock       = DockStyle.Fill,
                DataSource = new DataView(CDataset.Tables[tableName])
            };

            newGrid.SetParentSource(tableName, strPrimaryKey, strForeignKey);//设置主外键
            //newGrid.Name = "ChildrenMaster";
            //tPage.Controls.Add(newGrid);
            this.Controls.Add(newGrid);
            //this.BorderStyle = BorderStyle.FixedSingle;
            CModule.ApplyGridTheme(newGrid);
            CModule.SetGridRowHeader(newGrid);
            newGrid.RowPostPaint += CModule.rowPostPaint_HeaderCount;
            ChildGrid.Add(newGrid);
        }