屠宰场客户端
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.

89 lines
4.9 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 BO.Utils
{
public interface IAfterLogin
{
string RoleName { get; }
Form Generate();
}
public static class AfterLoginUtil
{
#if DEBUG
// static List<Tuple<string, string>> roleToAssemblies = new List<Tuple<string, string>>(){new Tuple<string,string>("排宰员",@"C:\BwpB3Project\src\B3ButcherManageClient\ButcherOrder\bin\Debug\ButcherOrder"),
// new Tuple<string,string>("过磅员",@"C:\B3\src\B3ButcherManageClient\ButcherWeight\bin\Debug\ButcherWeight"),
// new Tuple<string,string>("验质员",@"C:\B3\src\B3ButcherManageClient\QualityAndOrder\bin\Debug\QualityAndOrder"),
// new Tuple<string,string>("定级员",@"C:\B3\src\B3ButcherManageClient\WeighAndGrading\bin\Debug\WeighAndGrading"),
// new Tuple<string,string>("窒晕员",@"C:\B3\src\B3ButcherManageClient\OrderConfirm\bin\Debug\OrderConfirm"),
// new Tuple<string,string>("胴体白条出入库",@"C:\B3\src\B3ButcherManageClient\TrunksIousOutInStore\bin\Debug\TrunksIousOutInStore"),
// new Tuple<string,string>("掉猪处理员",@"C:\B3\src\B3ButcherManageClient\DropPigReOrder\bin\Debug\DropPigReOrder"),
// new Tuple<string,string>("配货员",@"D:\BWP\BWPB3\src\B3ButcherManageClient\Distribution\bin\Debug\Distribution"),
// new Tuple<string,string>("分割称重",@"C:\B3\src\B3ButcherManageClient\SegmentationWeight\bin\Debug\SegmentationWeight"),
// new Tuple<string,string>("分割入库",@"C:\B3\src\B3ButcherManageClient\SegmentationInStore\bin\Debug\SegmentationInStore"),
// new Tuple<string,string>("定级校验",@"C:\B3\src\B3ButcherManageClient\WeighAndGrading\bin\Debug\WeighAndGrading"),
// };
//luanhui 公司电脑
static List<Tuple<string, string>> roleToAssemblies = new List<Tuple<string, string>>(){
new Tuple<string,string>("排宰员",@"D:\BWP\BWPB3\src\B3ButcherManageClient\ButcherOrder\bin\Debug\ButcherOrder"),
new Tuple<string,string>("过磅员",@"D:\BWP\BWPB3\src\B3ButcherManageClient\ButcherWeight\bin\Debug\ButcherWeight"),
new Tuple<string,string>("验质员",@"D:\BWP\BWPB3\src\B3ButcherManageClient\QualityAndOrder\bin\Debug\QualityAndOrder"),
new Tuple<string,string>("定级员",@"D:\BWP\BWPB3\src\B3ButcherManageClient\WeighAndGrading\bin\Debug\WeighAndGrading"),
new Tuple<string,string>("窒晕员",@"D:\BWP\BWPB3\src\B3ButcherManageClient\OrderConfirm\bin\Debug\OrderConfirm"),
new Tuple<string,string>("胴体白条出入库",@"D:\BWP\BWPB3\src\B3ButcherManageClient\TrunksIousOutInStore\bin\Debug\TrunksIousOutInStore"),
new Tuple<string,string>("掉猪处理员",@"D:\BWP\BWPB3\src\B3ButcherManageClient\DropPigReOrder\bin\Debug\DropPigReOrder"),
new Tuple<string,string>("配货员",@"D:\BWP\BWPB3\src\B3ButcherManageClient\Distribution\bin\Debug\Distribution"),
new Tuple<string,string>("分割称重",@"D:\BWP\BWPB3\src\B3ButcherManageClient\SegmentationWeight\bin\Debug\SegmentationWeight"),
new Tuple<string,string>("分割入库",@"D:\BWP\BWPB3\src\B3ButcherManageClient\SegmentationInStore\bin\Debug\SegmentationInStore"),
new Tuple<string,string>("定级校验",@"D:\BWP\BWPB3\src\B3ButcherManageClient\WeighAndGrading\bin\Debug\WeighAndGrading"),
};
#else
static List<Tuple<string, string>> roleToAssemblies = new List<Tuple<string, string>>()
{
new Tuple<string,string>("排宰员",@"ButcherOrder"),
new Tuple<string,string>("过磅员",@"ButcherWeight"),
new Tuple<string,string>("验质员",@"QualityAndOrder"),
new Tuple<string,string>("定级员",@"WeighAndGrading"),
new Tuple<string,string>("窒晕员",@"OrderConfirm"),
new Tuple<string,string>("掉猪处理员",@"DropPigReOrder"),
new Tuple<string,string>("分割称重",@"SegmentationWeight"),
new Tuple<string,string>("分割入库",@"SegmentationInStore"),
new Tuple<string,string>("定级校验",@"WeighAndGrading"),
};
#endif
public static Form CreateForm(string role)
{
var first = roleToAssemblies.FirstOrDefault(x => x.Item1 == role);
if (first == null)
throw new Exception("未注册的角色:"+role);
#if DEBUG
var filePath = string.Format("{0}.dll", first.Item2);
#else
var filePath = Path.Combine(Application.StartupPath, string.Format("{0}.dll", first.Item2));
#endif
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;
}
}
}