屠宰场客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.6 KiB

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ButcherManageClient
{
public interface IAfterLogin
{
string RoleName { get; }
Form Generate();
}
internal static class AfterLoginUtil
{
static List<Tuple<string, string>> roleToAssemblies = new List<Tuple<string, string>> {
new Tuple<string,string>("1测试",@"C:\B3Service\src\B3ButcherManageClient\ButcherOrder\bin\Debug\ButcherOrder"),
new Tuple<string,string>("_2",@"C:\B3Service\src\B3ButcherManageClient\ButcherWeight\bin\Debug\ButcherWeight"),
new Tuple<string,string>("_1",@"C:\B3Service\src\B3ButcherManageClient\QualityAndOrder\bin\Debug\QualityAndOrder"),
new Tuple<string,string>("小新",""),
};
public static Form CreateForm(string role)
{
var first = roleToAssemblies.FirstOrDefault(x => x.Item1 == role);
if (first == null)
throw new Exception("未注册的角色");
//var filePath = Path.Combine(Application.StartupPath, string.Format("{0}.dll", first.Item2));
var filePath = string.Format("{0}.dll", first.Item2);
if (!File.Exists(filePath))
throw new Exception("相关模块不存在");
var formType = typeof(IAfterLogin);
foreach (var type in Assembly.LoadFile(filePath).GetTypes())
{
if (formType.IsAssignableFrom(type))
{
var instance = (IAfterLogin)Activator.CreateInstance(type);
if (role == instance.RoleName)
return instance.Generate();
}
}
return null;
}
}
}