
本文共 16777 字,大约阅读时间需要 55 分钟。
������������������������������������������winform������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������B/S���������������������������������������������������������������������������������������������ERP������������������������������������ERP���������������������������������������������������������������������������������������������������������������������������WEB������������������������������������������������������������������������WINFORM���������������������������������������������������������������������������ERP������������������������������������������������������������������������������������������������������������������������������������������������������������������WINFORM������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������SVN������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������ASP.NET ������������������������������������������
public static class WebApiConfig { public static void Register(HttpConfiguration config) { config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); } }
������������������������������������������config������������������������������������������������������������������������������������������������������������������������
1.���������������������������������PlugIn������������������������������������������������������������������������������������������������������������������������������������������������������������
IAppContext���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace PlugIn{ ////// ��������������������������������� /// ������������������������������������������������������������������������������������������������������������������������������������������������ /// ���������Zuowenjun /// 2016-3-26 /// public interface IAppContext { ////// ������������������ /// string AppName { get;} ////// ������������������ /// string AppVersion { get; } ////// ������������������������������������STRING������������������������������������ /// string SessionUserInfo { get; } ////// ������������������������������������������STRING������������������������������������ /// string PermissionInfo { get; } ////// ��������������������������������������������������������������������������������������������������� /// DictionaryAppCache { get; } /// /// ��������������������������������������������������������������������������������������� /// Form AppFormContainer { get; } ////// ��������������������������������������������������� /// /// ///Form CreatePlugInForm(Type formType); /// /// ��������������������������������������������������� /// /// ///Form CreatePlugInForm(string formTypeName); }}
ICompoent���������������������������������������������������������������������������������������������������������������������������������������������������������������������������
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace PlugIn{ ////// ������������������������ /// ��������������������������������������������������������������������������������������������������������������������������������� /// ���������Zuowenjun /// 2016-3-26 /// public interface ICompoent { ////// ������������ /// string CompoentName { get;} ////// ��������������������������������������� /// string CompoentVersion { get; } ////// ��������������������������������������������� /// IEnumerableFormTypes { get; } }}
ICompoentConfig���������������������������������������������������������������������������������������������������������������������������CompoentRegister������������������������������������������������������
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace PlugIn{ ////// ������������������������ /// ���������������������������������������������������������������������������������������������CompoentRegister������������������������������������������������������ /// ���������Zuowenjun /// 2016-3-26 /// public interface ICompoentConfig { void CompoentRegister(IAppContext context, out ICompoent compoent); }}
Compoent���������������������������������������������������������������������������ICompoent������������������������������������������������������
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using PlugIn;using System.Windows.Forms;namespace PlugIn{ ////// ��������������������� /// ���������Zuowenjun /// 2016-3-26 /// public class Compoent : ICompoent { private ListformTypeList = new List (); public string CompoentName { get; private set; } public string CompoentVersion { get; private set; } public IEnumerable FormTypes { get { return formTypeList.AsEnumerable(); } } public Compoent(string compoentName, string compoentVersion) { this.CompoentName = compoentName; this.CompoentVersion = compoentVersion; } public void AddFormTypes(params Type[] formTypes) { Type targetFormType = typeof(Form); foreach (Type formType in formTypes) { if (targetFormType.IsAssignableFrom(formType) && !formTypeList.Contains(formType)) { formTypeList.Add(formType); } } } }}
2.������������������������������������������������������������������IAppContext���������������AppContext
using PlugIn;using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace WinFormPlugin{ ////// ������������������������������ /// ���������Zuowenjun /// 2016-3-26 /// public class AppContext : IAppContext { internal static AppContext Current; internal DictionaryAppFormTypes { get; set; } public string AppName { get; private set; } public string AppVersion { get; private set; } public string SessionUserInfo { get; private set; } public string PermissionInfo { get; private set; } public Dictionary AppCache { get; private set; } public System.Windows.Forms.Form AppFormContainer { get; private set; } public AppContext(string appName, string appVersion, string sessionUserInfo, string permissionInfo, Form appFormContainer) { this.AppName = appName; this.AppVersion = appVersion; this.SessionUserInfo = sessionUserInfo; this.PermissionInfo = permissionInfo; this.AppCache = new Dictionary (); this.AppFormContainer = appFormContainer; } public System.Windows.Forms.Form CreatePlugInForm(Type formType) { if (this.AppFormTypes.ContainsValue(formType)) { return Activator.CreateInstance(formType) as Form; } else { throw new ArgumentOutOfRangeException(string.Format("���������������{0}������������������������������������������������������������", formType.FullName), "formType"); } } public System.Windows.Forms.Form CreatePlugInForm(string formTypeName) { Type type = Type.GetType(formTypeName); return CreatePlugInForm(type); } }}
���������AppContext���������������������������������������������AppContext���������������������������������������������������������Load���������������������
private void ParentForm_Load(object sender, EventArgs e) { AppContext.Current = new AppContext("������������������������", "V16.3.26.1", "admin", "administrator", this); AppContext.Current.AppCache["loginDatetime"] = DateTime.Now; AppContext.Current.AppCache["baseDir"] = AppDomain.CurrentDomain.BaseDirectory; AppContext.Current.AppFormTypes = new Dictionary(); LoadComponents(); LoadMenuNodes(); } private void LoadComponents() { string path = AppContext.Current.AppCache["baseDir"] + "com\\"; Type targetFormType = typeof(Form); foreach (string filePath in Directory.GetFiles(path, "*.dll")) { var asy = Assembly.LoadFile(filePath); var configType = asy.GetTypes().FirstOrDefault(t => t.GetInterface("ICompoentConfig") != null); if (configType != null) { ICompoent compoent=null; var config = (ICompoentConfig)Activator.CreateInstance(configType); config.CompoentRegister(AppContext.Current,out compoent);//������������������������������������������������compoent if (compoent != null) { foreach (Type formType in compoent.FormTypes)//������������������������������������AppContext���AppFormTypes��� { if (targetFormType.IsAssignableFrom(formType)) { AppContext.Current.AppFormTypes.Add(formType.FullName, formType); } } } } } } private void LoadMenuNodes() //������������������������������������������������������������������������������ { this.treeView1.Nodes.Clear(); var root = this.treeView1.Nodes.Add("Root"); foreach (var formType in AppContext.Current.AppFormTypes) { var node = new TreeNode(formType.Key) { Tag = formType.Value }; root.Nodes.Add(node); } }
������������������������������������������������������������
private void treeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) { if (e.Node.Nodes.Count <= 0)//������������������������������������������������ { ShowChildForm(e.Node.Tag as Type); } } private void ShowChildForm(Type formType) { var childForm= Application.OpenForms.Cast
3.������������������������������������������������������������������������WINDOWS������������������������������������������������������������������������������������������������������������FORM������������������Com.First���������������������������������������������PlugIn���������������ICompoentConfig���������������CompoentConfig
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using PlugIn;namespace Com.First{ ////// ���������������������������������������������������������������ICompoentConfig��� /// ���������Zuowenjun /// 2016-3-26 /// public class CompoentConfig : ICompoentConfig { public static IAppContext AppContext; public void CompoentRegister(IAppContext context,out ICompoent compoent) { AppContext = context; var compoentInfo = new Compoent("Com.First", "V16.3.26.1.1"); compoentInfo.AddFormTypes(typeof(Form1), typeof(Form2));//��������������������������������������������������������������� compoent = compoentInfo;//������Compoent��������� } }}
���������������������������������������������������������������������������������������������������������DLL���Com.First.Dll���������������������������������������com������������������������������������������������������������������������������������������������
������������������������������������������������������������������������������������Com.First������������������������Form1������������������Form1���������������������������������������������������������������������������
private void Form1_Load(object sender, EventArgs e) { CompoentConfig.AppContext.AppFormContainer.FormClosing += AppFormContainer_FormClosing; } void AppFormContainer_FormClosing(object sender, FormClosingEventArgs e) { MessageBox.Show(label1.Text + ",���������������������������������������������������"); e.Cancel = true; } private void Form1_FormClosed(object sender, FormClosedEventArgs e) { CompoentConfig.AppContext.AppFormContainer.FormClosing -= AppFormContainer_FormClosing; }
���������������������
������������������������������������Form2���������������������������������������������������������������������������������������������������������������
private void button1_Click(object sender, EventArgs e) { if (CompoentConfig.AppContext.PermissionInfo.Equals("user",StringComparison.OrdinalIgnoreCase)) { MessageBox.Show(this.Name); } else { MessageBox.Show("������������" + CompoentConfig.AppContext.SessionUserInfo + "���������������������" + CompoentConfig.AppContext.PermissionInfo + "���������������������user���������������������"); } }
���������������������
���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
���������������������������������������������������������������������������������������������������������������������������
发表评论
最新留言
关于作者
