using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using Forks.Utils.IO;
|
|
|
|
namespace B3ButcherWeightClient {
|
|
public class ConfigUtil {
|
|
public static string ConfigFilePath = Application.StartupPath + "\\Config.txt";
|
|
public static string ParametersPath = Application.StartupPath + "\\Parameters.txt";
|
|
public static string LivestockFilePath = Application.StartupPath + "\\Livestock.txt";
|
|
|
|
public static void Init() {
|
|
using (TextReader reader = FS.OpenReader(ConfigFilePath, true)) {
|
|
var nutFile = NutFile.Parse(reader);
|
|
var ser = nutFile.AsString(ConfigItem.Server, "");
|
|
if (!string.IsNullOrEmpty(ser)) {
|
|
var strBuilder = new StringBuilder();
|
|
strBuilder.Append("Server=");
|
|
strBuilder.Append(ser);
|
|
strBuilder.Append(";");
|
|
strBuilder.Append("Database=");
|
|
strBuilder.Append(nutFile.AsString(ConfigItem.Database, ""));
|
|
strBuilder.Append(";");
|
|
strBuilder.Append("User ID=");
|
|
strBuilder.Append(nutFile.AsString(ConfigItem.UserName, ""));
|
|
strBuilder.Append(";");
|
|
strBuilder.Append("Password=");
|
|
var password = nutFile.AsString(ConfigItem.Password, "");
|
|
strBuilder.Append(EncodeString.Encode(password));
|
|
strBuilder.Append(";");
|
|
ConnectionStr = strBuilder.ToString();
|
|
}
|
|
|
|
ser = nutFile.AsString(ConfigItem.RemoteServer, "");
|
|
if (!string.IsNullOrEmpty(ser)) {
|
|
var strBuilder = new StringBuilder();
|
|
strBuilder.Append("Server=");
|
|
strBuilder.Append(nutFile.AsString(ConfigItem.RemoteServer, ""));
|
|
strBuilder.Append(";");
|
|
strBuilder.Append("Database=");
|
|
strBuilder.Append(nutFile.AsString(ConfigItem.RemoteDatabase, ""));
|
|
strBuilder.Append(";");
|
|
strBuilder.Append("User ID=");
|
|
strBuilder.Append(nutFile.AsString(ConfigItem.RemoteUserName, ""));
|
|
strBuilder.Append(";");
|
|
strBuilder.Append("Password=");
|
|
var password = nutFile.AsString(ConfigItem.RemotePassword, "");
|
|
strBuilder.Append(EncodeString.Encode(password));
|
|
strBuilder.Append(";");
|
|
RemoteConStr = strBuilder.ToString();
|
|
}
|
|
|
|
LogFilePath = Application.StartupPath + "\\log\\" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
|
|
|
|
StartTime = nutFile.AsInt32(ConfigItem.StartTime, 12);
|
|
|
|
if (string.IsNullOrEmpty(nutFile.AsString(ConfigItem.Seconds, "1"))) {
|
|
Seconds = 1;
|
|
} else {
|
|
Seconds = (short)nutFile.AsInt32(ConfigItem.Seconds, 1);
|
|
}
|
|
|
|
BaseCount = (short)nutFile.AsInt32(ConfigItem.BaseCount, 6);
|
|
|
|
ComName = nutFile.AsString(ConfigItem.ComName, "COM1");
|
|
BaundRate = nutFile.AsString(ConfigItem.BaundRate, "9600");
|
|
DataBits = nutFile.AsString(ConfigItem.DataBits, "8");
|
|
Assignment = nutFile.AsString(ConfigItem.Assignment, "Continuous");
|
|
ReadType = nutFile.AsString(ConfigItem.ReadType, "0");
|
|
CType = nutFile.AsString(ConfigItem.CType, "");
|
|
MinWeight = nutFile.AsDecimal(ConfigItem.MinWeight, 25m);
|
|
MaxWeight = nutFile.AsDecimal(ConfigItem.MaxWeight, 300m);
|
|
AllowChangeLevel = nutFile.AsBool(ConfigItem.AllowChangeLevel, false);
|
|
SubWeight = nutFile.AsDecimal(ConfigItem.SubWeight, 0m);
|
|
PerDayStartHour = nutFile.AsInt32(ConfigItem.PerDayStartHour, 0);
|
|
Url = nutFile.AsString(ConfigItem.Url, "");
|
|
}
|
|
|
|
using (TextReader reader = FS.OpenReader(ParametersPath, true)) {
|
|
var nutFile = NutFile.Parse(reader);
|
|
var str = nutFile.AsString(ConfigItem.AccID, "");
|
|
if (string.IsNullOrEmpty(str)) {
|
|
AccID = 0;
|
|
} else {
|
|
long.TryParse(str, out AccID);
|
|
}
|
|
str = nutFile.AsString(ConfigItem.DeptID, "");
|
|
if (string.IsNullOrEmpty(str)) {
|
|
DeptID = 0;
|
|
} else {
|
|
long.TryParse(str, out DeptID);
|
|
}
|
|
str = nutFile.AsString(ConfigItem.StoreID, "");
|
|
if (string.IsNullOrEmpty(str)) {
|
|
StoreID = 0;
|
|
} else {
|
|
long.TryParse(str, out StoreID);
|
|
}
|
|
str = nutFile.AsString(ConfigItem.TouruID, "");
|
|
if (string.IsNullOrEmpty(str)) {
|
|
TouruID = 0;
|
|
} else {
|
|
long.TryParse(str, out TouruID);
|
|
}
|
|
str = nutFile.AsString(ConfigItem.ShengchanID, "");
|
|
if (string.IsNullOrEmpty(str)) {
|
|
ShengchanID = 0;
|
|
} else {
|
|
long.TryParse(str, out ShengchanID);
|
|
}
|
|
str = nutFile.AsString(ConfigItem.BanKuaiID, "");
|
|
if (string.IsNullOrEmpty(str)) {
|
|
BanKuaiID = 0;
|
|
} else {
|
|
long.TryParse(str, out BanKuaiID);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public static void SetLivestock(IList<Livestock.Info> dTable) {
|
|
dTable.Clear();
|
|
using (var reader = FS.OpenReader(ConfigUtil.LivestockFilePath, true)) {
|
|
var nutFile = NutFile.Parse(reader);
|
|
var strs = nutFile.AsString("ITEM", "");
|
|
var items = strs.Split(',');
|
|
foreach (var item in items) {
|
|
var s = item.Split('|');
|
|
if (s.Length == 2) {
|
|
var info = new Livestock.Info();
|
|
info.ID = long.Parse(s[0]);
|
|
info.名称 = s[1];
|
|
dTable.Add(info);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public static string ConnectionStr;
|
|
|
|
public static string RemoteConStr;
|
|
|
|
public static string LogFilePath;
|
|
|
|
public static short Seconds;
|
|
public static short BaseCount;
|
|
|
|
public static string ComName;
|
|
public static string BaundRate;
|
|
public static string DataBits;
|
|
public static string ReadType;
|
|
public static string Assignment;
|
|
public static decimal MinWeight;
|
|
public static decimal MaxWeight;
|
|
public static int StartTime;
|
|
public static string CType;
|
|
public static bool AllowChangeLevel;
|
|
public static decimal SubWeight;
|
|
public static int PerDayStartHour;
|
|
public static string Url;
|
|
|
|
public static long AccID;
|
|
public static long DeptID;
|
|
public static long StoreID;
|
|
public static long TouruID;
|
|
public static long ShengchanID;
|
|
public static long BanKuaiID;
|
|
}
|
|
|
|
public class ConfigItem {
|
|
public const string CType = "CType";
|
|
public const string ComName = "ComName";
|
|
public const string BaundRate = "BaundRate";
|
|
public const string DataBits = "DataBits";
|
|
public const string Assignment = "Assignment";
|
|
|
|
public const string Server = "Server";
|
|
public const string Database = "Database";
|
|
public const string UserName = "UserName";
|
|
public const string Password = "Password";
|
|
|
|
public const string RemoteServer = "RemoteServer";
|
|
public const string RemoteDatabase = "RemoteDatabase";
|
|
public const string RemoteUserName = "RemoteUserName";
|
|
public const string RemotePassword = "RemotePassword";
|
|
|
|
public const string RemoteConStr = "RemoteConStr";
|
|
public const string RLoginPassword = "RLoginPassword";
|
|
public const string MinWeight = "MinWeight";
|
|
public const string MaxWeight = "MaxWeight";
|
|
public const string StartTime = "StartTime";
|
|
public const string Seconds = "Seconds";
|
|
public const string BaseCount = "BaseCount";
|
|
public const string ReadType = "ReadType";
|
|
public const string LastUser = "LastUser";
|
|
public const string AllowChangeLevel = "AllowChangeLevel";
|
|
public const string SubWeight = "SubWeight";
|
|
public const string PerDayStartHour = "PerDayStartHour";
|
|
public const string Url = "Url";
|
|
|
|
public const string AccID = "AccID";
|
|
public const string DeptID = "DeptID";
|
|
public const string StoreID = "StoreID";
|
|
public const string TouruID = "TouruID";
|
|
public const string ShengchanID = "ShengchanID";
|
|
public const string BanKuaiID = "BanKuaiID";
|
|
}
|
|
}
|