using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using WeighBusiness.BL;
|
|
using WeighBusiness.BO;
|
|
|
|
namespace Update.Utils
|
|
{
|
|
/*
|
|
添加新配置的操作:
|
|
1.添加属性(如果set为private,则还要添加对应的设置方法);
|
|
2.在GetSetting方法中,参照方法里的格式(最后几行代码),添加新属性的语句(用于保存);
|
|
3.在InitConfig方法中,参照方法里的格式,添加新属性的语句(用于从数据库中,查询出相应的配置)。
|
|
* */
|
|
/// <summary>
|
|
/// 配置(保存在数据库中)。
|
|
/// <para>登录后,更新上次登录的用户为当前用户</para>
|
|
/// </summary>
|
|
public static class Config
|
|
{
|
|
static Config()
|
|
{
|
|
SetTerminalID(0);//TODO:未完成,用0做测试
|
|
var configFromDatabase = SettingBL.Load();
|
|
ID = configFromDatabase.ID;
|
|
SetRecentUser(configFromDatabase.RecentUserID, configFromDatabase.RecentUserName);
|
|
InitConfig(configFromDatabase.Setting);
|
|
}
|
|
|
|
#if DEBUG
|
|
public static readonly string LoginAddress = "http://localhost:2000/MainSystem/LoginService.svc";
|
|
public static readonly string WeighAddress = "http://localhost:2000/MainSystem/O/Breed/WeighTerminalService.svc";
|
|
#endif
|
|
|
|
private static long ID;//用于保存配置
|
|
|
|
/// <summary>
|
|
/// 终端ID。用于指明是哪个终端
|
|
/// </summary>
|
|
public static long TerminalID { get; private set; }//TODO:未完成,用0做测试
|
|
/// <summary>
|
|
/// 终端管理员
|
|
/// </summary>
|
|
public const string TerminalSystemUserName = "system";//终端管理员
|
|
/// <summary>
|
|
/// 上次登录的用户ID。登录后,设置为当前用户
|
|
/// </summary>
|
|
public static long RecentUserID { get; private set; }//参见登录按钮
|
|
/// <summary>
|
|
/// 上次登录的用户Name。登录后,设置为当前用户
|
|
/// </summary>
|
|
public static string RecentUserName { get; private set; }//参见登录按钮
|
|
/// <summary>
|
|
/// 系统IP。用于同步数据
|
|
/// </summary>
|
|
public static string SystemIP { get; private set; }
|
|
/// <summary>
|
|
/// 默认会计单位ID。
|
|
/// </summary>
|
|
public static long AccountingUnit_ID { get; private set; }
|
|
/// <summary>
|
|
/// 默认会计单位Name。
|
|
/// </summary>
|
|
public static string AccountingUnit_Name { get; private set; }
|
|
/// <summary>
|
|
/// 车间
|
|
/// </summary>
|
|
public static string Workshop { get; private set; }
|
|
|
|
/// <summary>
|
|
/// 登陆信息
|
|
/// </summary>
|
|
public static string Ticket { get; set; }//登陆信息,不保存到数据库中
|
|
|
|
private static void SetRecentUser(long recentUserID, string recentUserName)
|
|
{
|
|
RecentUserID = recentUserID;
|
|
RecentUserName = recentUserName;
|
|
}
|
|
|
|
public static void SetSystemIP(string ip)
|
|
{
|
|
SystemIP = ip;
|
|
}
|
|
|
|
public static void SetAccountingUnit(long accountingUnitID, string accountingUnitName)
|
|
{
|
|
AccountingUnit_ID = accountingUnitID;
|
|
AccountingUnit_Name = accountingUnitName;
|
|
}
|
|
|
|
public static void SetTerminalID(long terminalID)
|
|
{
|
|
TerminalID = terminalID;
|
|
}
|
|
|
|
public static void SetWorkshop(string workshop)
|
|
{
|
|
Workshop = workshop;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 保存当前配置
|
|
/// </summary>
|
|
public static void Save()//保存当前配置
|
|
{
|
|
var setting = GetSetting();
|
|
SettingBL.Save(setting, true);
|
|
}
|
|
|
|
private static SettingData GetSetting()
|
|
{
|
|
var saveSetting = new SettingData();
|
|
saveSetting.ID = ID;
|
|
saveSetting.RecentUserID = RecentUserID;
|
|
saveSetting.RecentUserName = RecentUserName;
|
|
saveSetting.Setting = new Dictionary<string, string>();
|
|
saveSetting.Setting.Add("1", SystemIP);
|
|
saveSetting.Setting.Add("2", AccountingUnit_ID.ToString());
|
|
saveSetting.Setting.Add("3", AccountingUnit_Name);
|
|
saveSetting.Setting.Add("4", TerminalID.ToString());
|
|
saveSetting.Setting.Add("5", Workshop);
|
|
|
|
return saveSetting;
|
|
}
|
|
|
|
private static void InitConfig(Dictionary<string, string> setting)
|
|
{
|
|
if (setting.Keys.Contains("1"))
|
|
SystemIP = setting["1"];
|
|
if (setting.Keys.Contains("2"))
|
|
AccountingUnit_ID = long.Parse(setting["2"]);
|
|
if (setting.Keys.Contains("3"))
|
|
AccountingUnit_Name = setting["3"];
|
|
if (setting.Keys.Contains("4"))
|
|
TerminalID = long.Parse(setting["4"]);
|
|
if (setting.Keys.Contains("5"))
|
|
Workshop = setting["5"];
|
|
|
|
}
|
|
|
|
}
|
|
}
|