Ejemplo n.º 1
0
 public static void TraverseFormControls(DockContent DockContentFormN, Control ctlTmp)
 {
     foreach (Control n in ctlTmp.Controls)
     {
         if (n is Button)
         {
             //MessageBox.Show(DockContentFormN.Name + "==>" + n.Text + "==>" + n.Name);
             FrmRightDAO.AddSqlStatement(DockContentFormN.Name, n.Name, n.Text);
         }
         else if (n is SimpleButton)
         {
             FrmRightDAO.AddSqlStatement(DockContentFormN.Name, n.Name, n.Text);
         }
         else if (n is ToolStrip)
         {
             ToolStrip tsTmp = (ToolStrip)n;
             for (int i = 0; i < tsTmp.Items.Count; i++)
             {
                 if (tsTmp.Items[i].GetType().ToString() == "System.Windows.Forms.ToolStripButton")//判断是否为ToolStripButton
                 {
                     //MessageBox.Show(DockContentFormN.Name + "==>" + tsTmp.Items[i].Text + "==>" + tsTmp.Items[i].Name);
                     FrmRightDAO.AddSqlStatement(DockContentFormN.Name, tsTmp.Items[i].Name, tsTmp.Items[i].Text);
                 }
             }
         }
         if (n.Controls.Count > 0)
         {
             TraverseFormControls(DockContentFormN, n);
         }
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 遍历窗口及其中控件,并将结果加至数据库表中
        /// </summary>
        public static void TraverseFormControlToTable()
        {
            DockContent DockContentFormN = new DockContent();
            Assembly    a = Assembly.LoadFile(Application.ExecutablePath);//.net中的反射

            Type[] types = a.GetTypes();
            FrmRightDAO.CreateButtonsTempTable();//在数据库中建button临时表
            foreach (Type t in types)
            {
                if (t.BaseType.Name == "DockContent")
                {
                    //DockContentFormN = (DockContent)Activator.CreateInstance(t, true);
                    DockContentFormN = FormHandler.DynamicCreateDockContent(t);
                    //MessageHandler.ShowMessageBox(DockContectFormN.Text + " | " + DockContectFormN.Name);
                    foreach (Control ctl in DockContentFormN.Controls)//遍历所有“DockContent”窗口
                    {
                        if (ctl is Button)
                        {
                            FrmRightDAO.AddSqlStatement(DockContentFormN.Name, ctl.Name, ctl.Text);
                        }
                        else if (ctl is SimpleButton)
                        {
                            FrmRightDAO.AddSqlStatement(DockContentFormN.Name, ctl.Name, ctl.Text);
                        }
                        else if (ctl is ToolStrip)
                        {
                            ToolStrip tsTmp = (ToolStrip)ctl;
                            for (int i = 0; i < tsTmp.Items.Count; i++)
                            {
                                if (tsTmp.Items[i].GetType().ToString() == "System.Windows.Forms.ToolStripButton")//判断是否为ToolStripButton
                                {
                                    FrmRightDAO.AddSqlStatement(DockContentFormN.Name, tsTmp.Items[i].Name, tsTmp.Items[i].Text);
                                }
                            }
                        }
                        if (ctl.Controls.Count > 0)
                        {
                            TraverseFormControls(DockContentFormN, ctl);
                        }
                    }
                }
            }
            FrmRightDAO.RunSqlStatement();//以事务方式执行拼接好的sql语句组
        }