Ejemplo n.º 1
0
        private void RecursiveForm(ComponentDataGrid parentGrid, DataTable dtRelation, string mainName)
        {
            DataRow[] drs = dtRelation.Select($"fFatherName ='{mainName}'");

            //第二级是否有多个gird
            bool bSecondOnly = drs?.Count() > 1
                ? true
                : false;

            ComponentPanel tmpMain = new ComponentPanel();


            var rows = parentGrid.SelectedRows;
            var row  = rows[0];

            //二级存在多个
            if (bSecondOnly)
            {
                MainTab.SelectedTab.Controls.Add(tmpMain);
                tmpMain.Dock = DockStyle.Fill;
                tmpMain.BringToFront();

                foreach (DataRow dr in drs)
                {
                    string    smainSql      = $@"select * from t_program where fname ='{dr["fchildname"] + "" }'";
                    DataTable dtProgramInfo = DBHelper.GetDataTable(smainSql);
                    DataRow   drProgramInfo = dtProgramInfo.Rows[0];

                    string smainSql1 = drProgramInfo["fSql"].ToString().TrimEnd();

                    DataTable dtMain = DBHelper.GetDataTable(smainSql1);
                    dtMain.TableName = drProgramInfo["fTable"] + "";
                    dtMain.Namespace = $"select * from (\r\n{smainSql1}\r\n) tfinal \r\nwhere 1=1";

                    ComponentDataGrid childGrid = tmpMain.InitializeNewTabPage(drProgramInfo["fcnname"] + "", drProgramInfo["fname"] + "", dtMain);

                    var Keys = GetPrimary(dr);
                    childGrid.PreGrid       = parentGrid;
                    childGrid.PrimaryKey    = Keys.ChildKeys;
                    childGrid.PrePrimaryKey = Keys.ParentKeys;

                    parentGrid.AddNextGrid(childGrid);
                }
            }
            else
            {
                //从属表数据
                DataRow drRelation = drs[0];

                var Keys = GetPrimary(drRelation);

                string    smainSql      = $@"select * from t_program where fname ='{drRelation["fchildname"] + "" }'";
                DataTable dtProgramInfo = DBHelper.GetDataTable(smainSql);
                DataRow   drProgramInfo = dtProgramInfo.Rows[0];

                string    smainSql1 = drProgramInfo["fSql"] + "";
                DataTable dtMain    = DBHelper.GetDataTable(smainSql1);
                dtMain.TableName = drProgramInfo["fTable"] + "";
                dtMain.Namespace = $"select * from (\r\n{smainSql1}\r\n) tfinal \r\nwhere 1=1";

                ComponentDataGrid childGrid = tmpMain.InitializeNewTabPage(drProgramInfo["fcnname"] + "", drProgramInfo["fname"] + "", dtMain);
                MainTab.SelectedTab.Controls.Add(tmpMain);
                tmpMain.BringToFront();

                childGrid.PreGrid       = parentGrid;
                childGrid.PrimaryKey    = Keys.ChildKeys;
                childGrid.PrePrimaryKey = Keys.ParentKeys;

                parentGrid.AddNextGrid(childGrid);

                DataRow[] drNeedRecursive = dtRelation.Select($"ffathername='{drProgramInfo["fname"] + ""}'");

                if (drNeedRecursive.Count() > 0)
                {
                    tmpMain.Dock = DockStyle.Top;
                    SplitterControl splitter = new SplitterControl();
                    MainTab.SelectedTab.Controls.Add(splitter);
                    splitter.Dock = DockStyle.Top;
                    splitter.BringToFront();

                    RecursiveForm(childGrid, dtRelation, drProgramInfo["fname"] + "");
                }
                else
                {
                    tmpMain.Dock = DockStyle.Fill;
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 初始化窗体
        /// </summary>
        /// <param name="SourceFormName">窗体Name</param>
        private void InitForm(string SourceFormName)
        {
            string    smainSql      = $@"select * from t_program where fname ='{SourceFormName}'";
            DataTable dtProgramInfo = DBHelper.GetDataTable(smainSql);
            DataRow   drProgramInfo = dtProgramInfo.Rows[0];

            string    smainSql1 = $"select * from (\r\n {drProgramInfo["fSql"] + ""}\r\n)t1 where 1=1";
            DataTable dtMain    = DBHelper.GetDataTable(smainSql1);

            dtMain.TableName = drProgramInfo["fTable"] + "";
            dtMain.Namespace = smainSql1;

            ComponentPanel panel = new ComponentPanel(true);

            ComponentDataGrid grid = panel.InitializeNewTabPage(drProgramInfo["fCNName"] + "", SourceFormName, dtMain);

            panel.Dock = DockStyle.Top;
            MainTab.SelectedTab.Controls.Add(panel);
            panel.BringToFront();

            string    srelationSql   = $@"select * from T_FormRelationships with(nolock) where fmainname = '{SourceFormName}'";
            DataTable dtRelationShip = DBHelper.GetDataTable(srelationSql);

            //无从属关系
            if (dtRelationShip == null || dtRelationShip.Rows.Count == 0)
            {
                panel.Dock = DockStyle.Fill;
                EventHelper eventHelperOnly = new EventHelper();

                eventHelperOnly.BindingCellClickEvent(grid);
                return;
            }

            SplitterControl splitter = new SplitterControl();

            MainTab.SelectedTab.Controls.Add(splitter);
            splitter.Dock = DockStyle.Top;
            splitter.BringToFront();

            RecursiveForm(grid, dtRelationShip, SourceFormName);


            #region 设置高度
            int ictrlCount = MainTab.SelectedTab.Controls.OfType <ComponentPanel>().Count();
            int ipageHeigh = MainTab.SelectedTab.Height;
            int iResult    = ipageHeigh / ictrlCount;

            foreach (Control ctrl in MainTab.SelectedTab.Controls)
            {
                if (!(ctrl is ComponentPanel))
                {
                    continue;
                }

                ComponentPanel frm = ctrl as ComponentPanel;
                frm.Height = iResult;
            }
            #endregion

            #region 点击事件绑定

            EventHelper eventHelper = new EventHelper();

            eventHelper.BindingCellClickEvent(grid);

            #endregion
        }