Beispiel #1
0
 private void trvControl_AfterSelect(object sender, TreeViewEventArgs e)
 {
     try
     {
         if (e.Node.Tag.ToString() == "Root")
         {
             return;
         }
         if (this.PanelControl.Controls.Count > 0)
         {
             this.PanelControl.Controls.Clear();
         }
         Control c = null;
         c      = (Control)e.Node.Tag;
         c.Dock = DockStyle.Fill;
         this.PanelControl.Controls.Add(c);
         Icpm = (Neusoft.HISFC.BizProcess.Interface.Common.IControlParamMaint)c;
         Icpm.IsShowOwnButtons = false;
         if (Icpm.Init() < 0)
         {
             MessageBox.Show(Icpm.Description + "模块初始话失败!", "错误");
         }
     }
     catch { }
 }
Beispiel #2
0
        /// <summary>
        /// 初始化TreeView
        /// </summary>
        private void InitTreeControl()
        {
            #region 变量
            //程序集
            System.Reflection.Assembly assembly;
            //根据文件扩展名判断是否是dll
            FileInfo fi;
            //程序集中所有类型
            Type[] t;
            #endregion

            #region 初始化treeview

            //清空Treeview的node
            this.trvControl.Nodes.Clear();
            this.trvControl.ImageList = this.trvControl.deptImageList;
            //加载根节点
            TreeNode rnode = new TreeNode();

            rnode.Text               = "系统模块";
            rnode.Tag                = "Root";
            rnode.ImageIndex         = 2;
            rnode.SelectedImageIndex = 2;
            //当前his.exe下所有文件的路径
            string[] s = Directory.GetFiles(Application.StartupPath);
            foreach (string file in s)
            {
                #region 加载程序集,得到该程序集中所有类型
                //判断该文件是否是.dll文件
                fi = new FileInfo(file);
                if (fi.Extension.ToLower() != ".dll")
                {
                    continue;
                }
                try
                {
                    //加载程序集
                    assembly = System.Reflection.Assembly.LoadFrom(file);
                    if (assembly == null)
                    {
                        continue;
                    }
                    //获取该程序集中所有类型
                    t = assembly.GetTypes();
                    if (t == null)
                    {
                        continue;
                    }
                }
                catch
                {
                    continue;
                }
                #endregion

                #region 反射得到该对象
                foreach (Type type in t)
                {
                    //判断该类型中是否继承IControlParamMaint接口
                    if (type.GetInterface("IControlParamMaint") != null)
                    {
                        //通过反射得到objectHandle
                        System.Runtime.Remoting.ObjectHandle o = System.Activator.CreateInstance(type.Assembly.ToString(), type.Namespace + "." + type.Name);
                        if (o != null)
                        {
                            //得到该被封装的对象,并转化为Conrol
                            Icpm = o.Unwrap() as Neusoft.HISFC.BizProcess.Interface.Common.IControlParamMaint;
                            TreeNode node = new TreeNode(Icpm.Description);
                            node.Tag        = Icpm;
                            node.ImageIndex = 0;
                            node.ImageIndex = 1;
                            rnode.Nodes.Add(node);
                        }
                    }
                }

                #endregion
            }
            this.trvControl.Nodes.Add(rnode);
            this.trvControl.ExpandAll();
            #endregion
        }