革博士程序V1仓库
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

322 wiersze
14 KiB

  1. using LeatherApp.Utils;
  2. using Newtonsoft.Json.Linq;
  3. using Sunny.UI;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Reflection;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. namespace LeatherApp
  12. {
  13. public class Config
  14. {
  15. public static string appBasePath;
  16. public static Models.User loginUser;
  17. //对应文件:DefectItemList.json
  18. public static JArray defectItemList;
  19. //
  20. public static JArray colorNameList;//, materialNameList;
  21. //
  22. public static JArray materialNameList;//, materialNameList;
  23. //CMDProcess目录下的命令JSON文件
  24. public static Dictionary<CMDName, JObject> CMDProcess;
  25. //剩余N米提示(M)
  26. public static int residueWarnningLen = 20;
  27. //瑕疵暂停跳过几张图
  28. public static int defectPauseSkipPhotoCount=5;
  29. //DB
  30. //有些服务器防火墙有问题需要加上 min pool size=1 避免认为是恶意请求
  31. //如果用到bulkCopy需要加: AllowLoadLocalInfile=true
  32. //public static string dbMysqlCon = "server=localhost;Database=ProductionDB;Uid=root;Pwd=123456;";
  33. public static string DBConStr = "server=localhost;Database=LeatherDB;Uid=root;Pwd=123456; AllowLoadLocalInfile=true";
  34. public static string ErpDBConStr = "server=localhost;Database=LeatherDB;Uid=root;Pwd=123456; AllowLoadLocalInfile=true";
  35. public static string ErpSql = "select top 1 a,b,c from tableA where code=@code order by id desc";
  36. //LOG
  37. public static string LogPath;
  38. //DEV
  39. public static bool StopCodeScanner = false;
  40. public static bool StopIO = false;
  41. public static bool StopPLC=true;
  42. public static bool StopLight = true;
  43. public static string PlcIPAdrees;
  44. public static short PlcRackN=0, PlcSolt=1;
  45. public static string Carmer1ConfigFilePath,Carmer2ConfigFilePath;
  46. public static string IOCard_DeviceNum = "PCI-1730,BID#0";
  47. public static bool ScannerReversalX = false;
  48. public static bool ScannerReversalY = false;
  49. public static string Light_PortName;//COM端口号
  50. public static LightDevNameEnum Light_Name = LightDevNameEnum.锐视;
  51. public static CamerDevNameEnum Camer_Name = CamerDevNameEnum.海康;
  52. //LIB
  53. public static string model_path = "";//./models/best_0805_bs8.onnx
  54. //public static string labels_path = "./models/hexin.names";
  55. public static int cm2px_x = 1;
  56. public static int cm2px_y = 1;
  57. //边缘孔洞宽(门幅计算包含,识别库去除)
  58. public static int MarginHoleWidth = 120, MiddleSuperposition;
  59. public static int expand_pixel=50;
  60. public static string ImagePath;
  61. public static bool IsSaveAllImage, IsSaveDefectSourceImage, IsSaveDefectCutImage;
  62. //材质Material 1
  63. public static string[] SuedeList1 = new string[0];
  64. //材质Material 2
  65. public static string[] SuedeList2 = new string[0];
  66. //材质Material 3
  67. public static string[] SuedeList3 = new string[0];
  68. //材质Material 4
  69. public static string[] SuedeList4 = new string[0];
  70. //材质Material 5
  71. public static string[] SuedeList5 = new string[0];
  72. //材质Material 6
  73. public static string[] SuedeList6 = new string[0];
  74. //忽略的等级判断项目
  75. public static string[] SkipLabelGrade = new string[0];
  76. //云端
  77. public static string cloud_ip, cloud_username, cloud_password, CloudThisName;
  78. public static int cloud_port, cloud_open;
  79. public static void LoadCloudConfig()
  80. {
  81. if (string.IsNullOrWhiteSpace(appBasePath))
  82. appBasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
  83. IniFile ini = new IniFile(appBasePath + "\\CloudConfig.ini");
  84. cloud_ip = ini.ReadString("Cloud", "cloud_ip", "");
  85. cloud_port = ini.ReadInt("Cloud", "cloud_port", 0);
  86. cloud_open = ini.ReadInt("Cloud", "cloud_open", 0);
  87. cloud_username = ini.ReadString("Cloud", "cloud_username", "");
  88. cloud_password = ini.ReadString("Cloud", "cloud_password", "");
  89. CloudThisName = ini.ReadString("Cloud", "CloudThisName", "");
  90. }
  91. public static void LoadAllConfig()
  92. {
  93. if (string.IsNullOrWhiteSpace(appBasePath))
  94. appBasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
  95. LoadDefectItemList();
  96. LoadColorNameList();
  97. LoadMaterialNameList();
  98. //----
  99. string lsCmdPath = appBasePath + "\\CMDProcess\\";
  100. if (!Directory.Exists(lsCmdPath))
  101. Directory.CreateDirectory(lsCmdPath);
  102. string fileName;
  103. CMDProcess = new Dictionary<CMDName, JObject>();
  104. foreach (int item in Enum.GetValues(typeof(CMDName)))//item为key值
  105. {
  106. //string name = Enum.GetName(typeof(CMDName), item);//获取名称
  107. fileName = lsCmdPath + item + ".json";
  108. if (File.Exists(fileName))
  109. CMDProcess.Add((CMDName)item, JObject.Parse(File.ReadAllText(fileName)));
  110. //else
  111. // CMDProcess.Add((CMDName)item, null);
  112. }
  113. // ----
  114. IniFile ini = new IniFile(appBasePath + "\\SysConfig.ini");
  115. //[DB]
  116. DBConStr = ini.ReadString("DB", "DBConStr", "");
  117. //[Erp]
  118. ErpDBConStr = ini.ReadString("ErpDB", "ErpDBConStr", "");
  119. ErpSql = ini.ReadString("ErpDB", "ErpSql", "");
  120. //[LOG]
  121. LogPath = ini.ReadString("LOG", "LogPath", "");
  122. //[CONTROL]
  123. defectPauseSkipPhotoCount = ini.ReadInt("CONTROL", "DefectPauseSkipPhotoCount", 0);
  124. //[DEV]
  125. StopCodeScanner = ini.ReadBool("DEV", "StopCodeScanner", false);
  126. StopIO = ini.ReadBool("DEV", "StopIO", false);
  127. StopPLC = ini.ReadBool("DEV", "StopPLC", false);
  128. PlcIPAdrees = ini.ReadString("DEV", "PlcIPAdrees", "");
  129. PlcRackN = ini.ReadShort("DEV", "PlcRackN", PlcRackN);
  130. PlcSolt = ini.ReadShort("DEV", "PlcSolt", PlcSolt);
  131. StopLight = ini.ReadBool("DEV", "StopLight", false);
  132. Carmer1ConfigFilePath = ini.ReadString("DEV", "Carmer1ConfigFilePath", "");
  133. Carmer2ConfigFilePath = ini.ReadString("DEV", "Carmer2ConfigFilePath", "");
  134. IOCard_DeviceNum = ini.ReadString("DEV", "IOCard_DeviceNum", "");
  135. Light_Name = (LightDevNameEnum)ini.ReadInt("DEV", "Light_Name");
  136. Light_PortName = ini.ReadString("DEV", "Light_PortName", "");
  137. Camer_Name = (CamerDevNameEnum)ini.ReadInt("DEV", "Camer_Name");
  138. ScannerReversalX = ini.ReadBool("DEV", "ScannerReversalX", false);
  139. ScannerReversalY = ini.ReadBool("DEV", "ScannerReversalY", false);
  140. //[LIB]
  141. model_path = ini.ReadString("LIB", "model_path", "");
  142. //labels_path = ini.ReadString("LIB", "labels_path", "");
  143. cm2px_x = ini.ReadInt("LIB", "cm2px_x", 1);
  144. cm2px_y = ini.ReadInt("LIB", "cm2px_y", 1);
  145. MarginHoleWidth = ini.ReadInt("LIB", "MarginHoleWidth", 0);
  146. MiddleSuperposition = ini.ReadInt("LIB", "MiddleSuperposition", 0);
  147. expand_pixel=ini.ReadInt("LIB", "expand_pixel", 50);
  148. ImagePath = ini.ReadString("LIB", "ImagePath", "");
  149. IsSaveAllImage = ini.ReadBool("LIB", "IsSaveAllImage", false);
  150. IsSaveDefectSourceImage = ini.ReadBool("LIB", "IsSaveDefectSourceImage", false);
  151. IsSaveDefectCutImage = ini.ReadBool("LIB", "IsSaveDefectCutImage", false);
  152. //
  153. string lsTmp = ini.ReadString("Material", "SuedeList", "").Trim();
  154. if (!string.IsNullOrWhiteSpace(lsTmp))
  155. SuedeList1 = lsTmp.Split(new char[] { ',', ';' });
  156. else
  157. SuedeList1 = new string[1] { "" };
  158. lsTmp = ini.ReadString("Material", "SuedeList2", "").Trim();
  159. if (!string.IsNullOrWhiteSpace(lsTmp))
  160. SuedeList2 = lsTmp.Split(new char[] { ',', ';' });
  161. else
  162. SuedeList2 = new string[1] { "" };
  163. lsTmp = ini.ReadString("Material", "SuedeList3", "").Trim();
  164. if (!string.IsNullOrWhiteSpace(lsTmp))
  165. SuedeList3 = lsTmp.Split(new char[] { ',', ';' });
  166. else
  167. SuedeList3 = new string[1] { "" };
  168. lsTmp = ini.ReadString("Material", "SuedeList4", "").Trim();
  169. if (!string.IsNullOrWhiteSpace(lsTmp))
  170. SuedeList4 = lsTmp.Split(new char[] { ',', ';' });
  171. else
  172. SuedeList4 = new string[1] { "" };
  173. lsTmp = ini.ReadString("Material", "SuedeList5", "").Trim();
  174. if (!string.IsNullOrWhiteSpace(lsTmp))
  175. SuedeList5 = lsTmp.Split(new char[] { ',', ';' });
  176. else
  177. SuedeList5 = new string[1] { "" };
  178. lsTmp = ini.ReadString("Material", "SuedeList6", "").Trim();
  179. if (!string.IsNullOrWhiteSpace(lsTmp))
  180. SuedeList6 = lsTmp.Split(new char[] { ',', ';' });
  181. else
  182. SuedeList6 = new string[1] { "" };
  183. lsTmp = ini.ReadString("SkipLabelGrade", "LabelGradeList", "").Trim();
  184. if (!string.IsNullOrWhiteSpace(lsTmp))
  185. SkipLabelGrade = lsTmp.Split(new char[] { ',', ';' });
  186. else
  187. SkipLabelGrade = new string[1] { "" };
  188. }
  189. #region defectItemList <=> DefectItemList.json
  190. public static void LoadDefectItemList()
  191. {
  192. if (string.IsNullOrWhiteSpace(appBasePath))
  193. appBasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
  194. string configPath = appBasePath + "\\DefectItemList.json";
  195. string lsTmp = File.ReadAllText(configPath);
  196. defectItemList = JArray.Parse(lsTmp);
  197. }
  198. public static void SaveDefectItemList(JArray newValue)
  199. {
  200. if (string.IsNullOrWhiteSpace(appBasePath))
  201. appBasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
  202. string configPath = appBasePath + "\\DefectItemList.json";
  203. File.WriteAllText(configPath, newValue.ToString());
  204. }
  205. public static JObject getDefectItem(string code)
  206. {
  207. try
  208. {
  209. var item = Config.defectItemList.FirstOrDefault(m => m.Value<string>("code") == code);
  210. if (item == null)
  211. return null;
  212. return (JObject)item;
  213. }
  214. catch { return null; }
  215. }
  216. public static JObject getDefectItem(int id)
  217. {
  218. try
  219. {
  220. var item = Config.defectItemList.FirstOrDefault(m => m.Value<int>("id") == id);
  221. if (item == null)
  222. return null;
  223. return (JObject)item;
  224. }
  225. catch { return null; }
  226. }
  227. public static string getDefectCode(int id)
  228. {
  229. try
  230. {
  231. var item = Config.defectItemList.FirstOrDefault(m => m.Value<int>("id") == id);
  232. if (item == null)
  233. return "";
  234. return ((JObject)item).Value<string>("code");
  235. }
  236. catch { return ""; }
  237. }
  238. public static string getDefectName(string code)
  239. {
  240. try {
  241. var item = Config.defectItemList.FirstOrDefault(m => m.Value<string>("code") == code);
  242. if (item == null)
  243. return "";
  244. return ((JObject)item).Value<string>("name");
  245. }
  246. catch { return ""; }
  247. }
  248. public static string getDefectCode(string name)
  249. {
  250. try {
  251. var item = Config.defectItemList.FirstOrDefault(m => m.Value<string>("name") == name);
  252. if (item == null)
  253. return "";
  254. return ((JObject)item).Value<string>("code");
  255. }
  256. catch { return ""; }
  257. }
  258. #endregion
  259. #region colorNameList <=> ColorNameList.json
  260. public static void LoadColorNameList()
  261. {
  262. if (string.IsNullOrWhiteSpace(appBasePath))
  263. appBasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
  264. string configPath = appBasePath + "\\ColorNameList.json";
  265. string lsTmp = File.ReadAllText(configPath);
  266. colorNameList = JArray.Parse(lsTmp);
  267. }
  268. public static JObject getColorItem(int code)
  269. {
  270. var item = Config.colorNameList.FirstOrDefault(m => m.Value<int>("code") == code);
  271. if (item == null)
  272. return null;
  273. return (JObject)item;
  274. }
  275. public static void LoadMaterialNameList()
  276. {
  277. if (string.IsNullOrWhiteSpace(appBasePath))
  278. appBasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
  279. string configPath = appBasePath + "\\MaterialName.json";
  280. string lsTmp = File.ReadAllText(configPath);
  281. materialNameList = JArray.Parse(lsTmp);
  282. }
  283. //public static JObject getMaterialItem(string code)
  284. //{
  285. // var item = Config.materialNameList.FirstOrDefault(m => m.Value<string>("code") == code);
  286. // if (item == null)
  287. // return null;
  288. // return (JObject)item;
  289. //}
  290. #endregion
  291. }
  292. }