Beispiel #1
0
        private void bbiEditObject_ItemClick(object sender, ItemClickEventArgs e)
        {
            TreeListNode mnode = this.tlSysObject.FocusedNode;

            if (mnode != null)
            {
                CDictObject data = mnode.Tag as CDictObject;
                if (data != null)
                {
                    //  重新获取功能对象信息, 防止对象信息变更。
                    //  TODO:未验证?
                    string   module_obj = this.tlSysObject.FocusedNode.ParentNode.GetValue(this.tlcObject).ToString();
                    Assembly theDll     = Assembly.LoadFrom(EnvInfo.RunPath + module_obj + ".dll");
                    Type     type       = theDll.GetType(module_obj + "." + data.Object);
                    data.IsFunction       = type.IsSubclassOf(typeof(FrmBase)) ? 1 : 0;
                    data.HasFunctionPoint = typeof(IFunctionPoint).IsAssignableFrom(type) ? 1 : 0;
                    if (data.HasFunctionPoint == 1)
                    {
                        List <CDictFunctionPoint> listObjectFp = new List <CDictFunctionPoint>();
                        foreach (Attribute attr in type.GetCustomAttributes(typeof(FunctionPointAttribute)))
                        {
                            FunctionPointAttribute fpattr = attr as FunctionPointAttribute;
                            CDictFunctionPoint     fp     = new CDictFunctionPoint();
                            fp.Code       = data.Code + "-" + fpattr.Code;
                            fp.Name       = fpattr.Name;
                            fp.ObjectCode = data.Code;
                            fp.Describe   = fpattr.Describe;

                            listObjectFp.Add(fp);
                        }
                        if (listObjectFp.Count > 0)
                        {
                            data.FunctionPointList = listObjectFp;
                        }
                        else
                        {
                            data.HasFunctionPoint = 0;      //  没有设置具体功能点认为无功能点
                        }
                    }

                    FrmObjectEdit frm = new FrmObjectEdit();
                    frm.Init(data);
                    if (frm.ShowDialog() == DialogResult.OK)
                    {
                        data = frm.DataObject;
                        mnode.SetValue(tlcName, data.Name);
                        mnode.SetValue(tlcUsedFlag, data.UsedFlag);
                        mnode.Tag = data;
                        this.ucSysObject1.Init(data);
                    }
                    frm.Dispose();
                }
            }
        }
Beispiel #2
0
        private List <CDictObject> getModuleObjectListNew(Assembly theDll, String moduleCode, string moduleObject)
        {
            List <CDictObject> listObject = new List <CDictObject>();

            //  获取模块信息中全部可管理的对象attribute
            object[] attributes = theDll.GetCustomAttributes(typeof(ManagedObjectAttribute), false);
            for (int i = 0; i < attributes.Length; i++)
            {
                ManagedObjectAttribute obj_attr = attributes[i] as ManagedObjectAttribute;

                CDictObject obj = new CDictObject();
                obj.Code       = obj_attr.Code;
                obj.Name       = obj_attr.Name;
                obj.Object     = obj_attr.ObjectName;
                obj.UsedFlag   = 1;
                obj.ModuleCode = moduleCode;

                try
                {
                    Type type = theDll.GetType(moduleObject + "." + obj.Object);
                    obj.IsFunction       = type.IsSubclassOf(typeof(FrmBase)) ? 1 : 0;
                    obj.HasFunctionPoint = typeof(IFunctionPoint).IsAssignableFrom(type) ? 1 : 0;

                    listObject.Add(obj);

                    //  有功能点时自动获取功能点信息
                    if (obj.HasFunctionPoint == 1)
                    {
                        List <CDictFunctionPoint> listObjectFp = new List <CDictFunctionPoint>();
                        try
                        {
                            foreach (Attribute attr in type.GetCustomAttributes(typeof(FunctionPointAttribute)))
                            {
                                FunctionPointAttribute fpattr = attr as FunctionPointAttribute;
                                CDictFunctionPoint     fp     = new CDictFunctionPoint();
                                fp.Code       = obj.Code + "-" + fpattr.Code;
                                fp.Name       = fpattr.Name;
                                fp.ObjectCode = obj.Code;
                                fp.Describe   = fpattr.Describe;

                                listObjectFp.Add(fp);
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageHelper.ShowWarning(moduleObject + "." + obj.Object + "功能点分析出现问题。\r\n" + ex.Message);
                        }
                        if (listObjectFp.Count > 0)
                        {
                            obj.FunctionPointList = listObjectFp;
                        }
                        else
                        {
                            obj.HasFunctionPoint = 0;      //  没有设置具体功能点认为无功能点
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageHelper.ShowWarning(moduleObject + "." + obj.Object + "对象分析出现问题。\r\n" + ex.Message);
                }
            }
            return(listObject);
        }
Beispiel #3
0
        private void bbiAddObject_ItemClick(object sender, ItemClickEventArgs e)
        {
            //  获取模块名称
            TreeListNode rnode = this.tlSysObject.FocusedNode;

            if (rnode == null)
            {
                return;
            }
            if (rnode.ParentNode != null)
            {
                //  选择对象时获取其对应的模块节点
                rnode = rnode.ParentNode;
            }
            string module_obj  = rnode.GetValue(this.tlcObject).ToString();
            string module_code = rnode.GetValue(this.tlcCode).ToString();
            string module_name = rnode.GetValue(this.tlcName).ToString();

            //  获取已经加入的功能
            List <string> existsObjectList = new List <string>();

            foreach (TreeListNode objnode in rnode.Nodes)
            {
                existsObjectList.Add(objnode.GetValue(this.tlcCode).ToString());
            }

            //  获取对应模块可用功能
            List <CDictObject> objectList = new List <CDictObject>();

            try
            {
                Assembly theDll = Assembly.LoadFrom(EnvInfo.RunPath + module_obj + ".dll");

                //  找出未加入的对象到noexistsObjectList
                List <string> noexistsObjectList = new List <string>();       //  未加入的对象列表
                object[]      customs            = theDll.GetCustomAttributes(false);
                foreach (var item in customs)
                {
                    if (item.GetType() == typeof(ManagedObjectAttribute))
                    {
                        ManagedObjectAttribute objAttr = item as ManagedObjectAttribute;

                        string code = objAttr.Code;
                        if (existsObjectList.Find(o => o == code) == null)
                        {
                            noexistsObjectList.Add(objAttr.ObjectName);
                        }
                    }
                }

                //  找出可用对象完整信息到listObject
                //  获取模块信息中全部可管理的对象attribute
                object[] attributes = theDll.GetCustomAttributes(typeof(ManagedObjectAttribute), false);
                for (int i = 0; i < attributes.Length; i++)
                {
                    ManagedObjectAttribute obj_attr = attributes[i] as ManagedObjectAttribute;
                    //  判断是否已经加入
                    if (noexistsObjectList.Find(o => o == obj_attr.ObjectName) != null)
                    {
                        try
                        {
                            if (!string.IsNullOrEmpty(obj_attr.Code))
                            {
                                CDictObject obj = new CDictObject();
                                obj.Code       = obj_attr.Code;
                                obj.Name       = obj_attr.Name;
                                obj.Object     = obj_attr.ObjectName;
                                obj.UsedFlag   = 1;
                                obj.ModuleCode = module_code;

                                Type type = theDll.GetType(module_obj + "." + obj.Object);
                                obj.IsFunction       = type.IsSubclassOf(typeof(FrmBase)) ? 1 : 0;
                                obj.HasFunctionPoint = typeof(IFunctionPoint).IsAssignableFrom(type) ? 1 : 0;

                                objectList.Add(obj);

                                //  有功能点时自动获取功能点信息
                                if (obj.HasFunctionPoint == 1)
                                {
                                    List <CDictFunctionPoint> listObjectFp = new List <CDictFunctionPoint>();
                                    foreach (Attribute attr in type.GetCustomAttributes(typeof(FunctionPointAttribute)))
                                    {
                                        FunctionPointAttribute fpattr = attr as FunctionPointAttribute;
                                        CDictFunctionPoint     fp     = new CDictFunctionPoint();
                                        fp.Code       = obj.Code + "-" + fpattr.Code;
                                        fp.Name       = fpattr.Name;
                                        fp.ObjectCode = obj.Code;
                                        fp.Describe   = fpattr.Describe;

                                        listObjectFp.Add(fp);
                                    }
                                    if (listObjectFp.Count > 0)
                                    {
                                        obj.FunctionPointList = listObjectFp;
                                    }
                                    else
                                    {
                                        obj.HasFunctionPoint = 0;      //  没有设置具体功能点认为无功能点
                                    }
                                }
                            }
                            else
                            {
                                continue;
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageHelper.ShowWarning(ex.Message);
                            continue;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageHelper.ShowWarning(ex.Message);
            }
            finally
            {
                //  选择对象
                if (objectList.Count > 0)
                {
                    //  按代码排序
                    objectList.Sort((left, right) =>
                    {
                        int result = left.Code.CompareTo(right.Code);
                        if (result > 0)
                        {
                            return(1);
                        }
                        else if (result < 0)
                        {
                            return(-1);
                        }
                        return(0);
                    });
                    FrmObjectAdd frm = new FrmObjectAdd();
                    frm.Init(objectList, module_name);
                    if (frm.ShowDialog() == DialogResult.OK)
                    {
                        //  添加节点
                        this.tlSysObject.FocusedNodeChanged -= tlSysObject_FocusedNodeChanged;
                        this.tlSysObject.BeginUpdate();    //  停止控件刷新

                        foreach (CDictObject obj in frm.DataObjectList)
                        {
                            TreeListNode onode = rnode.Nodes.Add(new object[] { obj.Code, obj.Name, obj.Object, obj.UsedFlag, obj.ModuleCode });
                            onode.Tag = obj;
                        }
                        this.tlSysObject.FocusedNodeChanged += tlSysObject_FocusedNodeChanged;
                        this.tlSysObject.EndUpdate();       //  控件刷新从BeginUpdate开始的改变
                    }
                    frm.Dispose();
                }
            }
        }