革博士V2程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

248 строки
11 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. //CMDProcess目录下的命令JSON文件
  22. public static Dictionary<CMDName, JObject> CMDProcess;
  23. //剩余N米提示(M)
  24. public static int residueWarnningLen = 10;
  25. //瑕疵暂停跳过几张图
  26. public static int defectPauseSkipPhotoCount=5;
  27. //DB
  28. //有些服务器防火墙有问题需要加上 min pool size=1 避免认为是恶意请求
  29. //如果用到bulkCopy需要加: AllowLoadLocalInfile=true
  30. //public static string dbMysqlCon = "server=localhost;Database=ProductionDB;Uid=root;Pwd=123456;";
  31. public static string DBConStr = "server=localhost;Database=LeatherDB;Uid=root;Pwd=123456; AllowLoadLocalInfile=true";
  32. public static string ErpDBConStr = "server=localhost;Database=LeatherDB;Uid=root;Pwd=123456; AllowLoadLocalInfile=true";
  33. public static string ErpSql = "select top 1 a,b,c from tableA where code=@code order by id desc";
  34. //LOG
  35. public static string LogPath;
  36. //DEV
  37. public static bool StopCodeScanner = false;
  38. public static bool StopIO = false;
  39. public static bool StopPLC=true;
  40. public static bool StopLight = true;
  41. public static string PlcIPAdrees;
  42. public static short PlcRackN=0, PlcSolt=1;
  43. public static string Carmer1ConfigFilePath,Carmer2ConfigFilePath;
  44. public static string IOCard_DeviceNum = "PCI-1730,BID#0";
  45. public static bool ScannerReversalX = false;
  46. public static bool ScannerReversalY = false;
  47. public static string Light_PortName;//COM端口号
  48. public static LightDevNameEnum Light_Name = LightDevNameEnum.锐视;
  49. public static CamerDevNameEnum Camer_Name = CamerDevNameEnum.海康;
  50. //LIB
  51. public static string model_path = "";//./models/best_0805_bs8.onnx
  52. //public static string labels_path = "./models/hexin.names";
  53. public static int cm2px_x = 1;
  54. public static int cm2px_y = 1;
  55. //边缘孔洞宽(门幅计算包含,识别库去除)
  56. public static int MarginHoleWidth = 120, MiddleSuperposition;
  57. public static int expand_pixel=50;
  58. public static string ImagePath;
  59. public static bool IsSaveAllImage, IsSaveDefectSourceImage, IsSaveDefectCutImage;
  60. //材质Material
  61. public static string[] SuedeList = new string[0];
  62. //云端
  63. public static string cloud_ip, cloud_username, cloud_password, CloudThisName;
  64. public static int cloud_port, cloud_open;
  65. public static void LoadCloudConfig()
  66. {
  67. if (string.IsNullOrWhiteSpace(appBasePath))
  68. appBasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
  69. IniFile ini = new IniFile(appBasePath + "\\CloudConfig.ini");
  70. cloud_ip = ini.ReadString("Cloud", "cloud_ip", "");
  71. cloud_port = ini.ReadInt("Cloud", "cloud_port", 0);
  72. cloud_open = ini.ReadInt("Cloud", "cloud_open", 0);
  73. cloud_username = ini.ReadString("Cloud", "cloud_username", "");
  74. cloud_password = ini.ReadString("Cloud", "cloud_password", "");
  75. CloudThisName = ini.ReadString("Cloud", "CloudThisName", "");
  76. }
  77. public static void LoadAllConfig()
  78. {
  79. if (string.IsNullOrWhiteSpace(appBasePath))
  80. appBasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
  81. LoadDefectItemList();
  82. LoadColorNameList();
  83. //LoadMaterialNameList();
  84. //----
  85. string lsCmdPath = appBasePath + "\\CMDProcess\\";
  86. if (!Directory.Exists(lsCmdPath))
  87. Directory.CreateDirectory(lsCmdPath);
  88. string fileName;
  89. CMDProcess = new Dictionary<CMDName, JObject>();
  90. foreach (int item in Enum.GetValues(typeof(CMDName)))//item为key值
  91. {
  92. //string name = Enum.GetName(typeof(CMDName), item);//获取名称
  93. fileName = lsCmdPath + item + ".json";
  94. if (File.Exists(fileName))
  95. CMDProcess.Add((CMDName)item, JObject.Parse(File.ReadAllText(fileName)));
  96. //else
  97. // CMDProcess.Add((CMDName)item, null);
  98. }
  99. // ----
  100. IniFile ini = new IniFile(appBasePath + "\\SysConfig.ini");
  101. //[DB]
  102. DBConStr = ini.ReadString("DB", "DBConStr", "");
  103. //[Erp]
  104. ErpDBConStr = ini.ReadString("ErpDB", "ErpDBConStr", "");
  105. ErpSql = ini.ReadString("ErpDB", "ErpSql", "");
  106. //[LOG]
  107. LogPath = ini.ReadString("LOG", "LogPath", "");
  108. //[CONTROL]
  109. defectPauseSkipPhotoCount = ini.ReadInt("CONTROL", "DefectPauseSkipPhotoCount", 0);
  110. //[DEV]
  111. StopCodeScanner = ini.ReadBool("DEV", "StopCodeScanner", false);
  112. StopIO = ini.ReadBool("DEV", "StopIO", false);
  113. StopPLC = ini.ReadBool("DEV", "StopPLC", false);
  114. PlcIPAdrees = ini.ReadString("DEV", "PlcIPAdrees", "");
  115. PlcRackN = ini.ReadShort("DEV", "PlcRackN", PlcRackN);
  116. PlcSolt = ini.ReadShort("DEV", "PlcSolt", PlcSolt);
  117. StopLight = ini.ReadBool("DEV", "StopLight", false);
  118. Carmer1ConfigFilePath = ini.ReadString("DEV", "Carmer1ConfigFilePath", "");
  119. Carmer2ConfigFilePath = ini.ReadString("DEV", "Carmer2ConfigFilePath", "");
  120. IOCard_DeviceNum = ini.ReadString("DEV", "IOCard_DeviceNum", "");
  121. Light_Name = (LightDevNameEnum)ini.ReadInt("DEV", "Light_Name");
  122. Light_PortName = ini.ReadString("DEV", "Light_PortName", "");
  123. Camer_Name = (CamerDevNameEnum)ini.ReadInt("DEV", "Camer_Name");
  124. ScannerReversalX = ini.ReadBool("DEV", "ScannerReversalX", false);
  125. ScannerReversalY = ini.ReadBool("DEV", "ScannerReversalY", false);
  126. //[LIB]
  127. model_path = ini.ReadString("LIB", "model_path", "");
  128. //labels_path = ini.ReadString("LIB", "labels_path", "");
  129. cm2px_x = ini.ReadInt("LIB", "cm2px_x", 1);
  130. cm2px_y = ini.ReadInt("LIB", "cm2px_y", 1);
  131. MarginHoleWidth = ini.ReadInt("LIB", "MarginHoleWidth", 0);
  132. MiddleSuperposition = ini.ReadInt("LIB", "MiddleSuperposition", 0);
  133. expand_pixel=ini.ReadInt("LIB", "expand_pixel", 50);
  134. ImagePath = ini.ReadString("LIB", "ImagePath", "");
  135. IsSaveAllImage = ini.ReadBool("LIB", "IsSaveAllImage", false);
  136. IsSaveDefectSourceImage = ini.ReadBool("LIB", "IsSaveDefectSourceImage", false);
  137. IsSaveDefectCutImage = ini.ReadBool("LIB", "IsSaveDefectCutImage", false);
  138. //
  139. string lsTmp = ini.ReadString("Material", "SuedeList", "").Trim();
  140. if(!string.IsNullOrWhiteSpace(lsTmp))
  141. SuedeList=lsTmp.Split(new char[] { ',',';'});
  142. }
  143. #region defectItemList <=> DefectItemList.json
  144. public static void LoadDefectItemList()
  145. {
  146. if (string.IsNullOrWhiteSpace(appBasePath))
  147. appBasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
  148. string configPath = appBasePath + "\\DefectItemList.json";
  149. string lsTmp = File.ReadAllText(configPath);
  150. defectItemList = JArray.Parse(lsTmp);
  151. }
  152. public static void SaveDefectItemList(JArray newValue)
  153. {
  154. if (string.IsNullOrWhiteSpace(appBasePath))
  155. appBasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
  156. string configPath = appBasePath + "\\DefectItemList.json";
  157. File.WriteAllText(configPath, newValue.ToString());
  158. }
  159. public static JObject getDefectItem(string code)
  160. {
  161. var item=Config.defectItemList.FirstOrDefault(m => m.Value<string>("code")==code);
  162. if(item==null)
  163. return null;
  164. return (JObject)item;
  165. }
  166. public static JObject getDefectItem(int id)
  167. {
  168. var item = Config.defectItemList.FirstOrDefault(m => m.Value<int>("id") == id);
  169. if (item == null)
  170. return null;
  171. return (JObject)item;
  172. }
  173. public static string getDefectCode(int id)
  174. {
  175. var item = Config.defectItemList.FirstOrDefault(m => m.Value<int>("id") == id);
  176. if (item == null)
  177. return "";
  178. return ((JObject)item).Value<string>("code");
  179. }
  180. public static string getDefectName(string code)
  181. {
  182. var item = Config.defectItemList.FirstOrDefault(m => m.Value<string>("code") == code);
  183. if (item == null)
  184. return "";
  185. return ((JObject)item).Value<string>("name");
  186. }
  187. #endregion
  188. #region colorNameList <=> ColorNameList.json
  189. public static void LoadColorNameList()
  190. {
  191. if (string.IsNullOrWhiteSpace(appBasePath))
  192. appBasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
  193. string configPath = appBasePath + "\\ColorNameList.json";
  194. string lsTmp = File.ReadAllText(configPath);
  195. colorNameList = JArray.Parse(lsTmp);
  196. }
  197. public static JObject getColorItem(int code)
  198. {
  199. var item = Config.colorNameList.FirstOrDefault(m => m.Value<int>("code") == code);
  200. if (item == null)
  201. return null;
  202. return (JObject)item;
  203. }
  204. //public static void LoadMaterialNameList()
  205. //{
  206. // if (string.IsNullOrWhiteSpace(appBasePath))
  207. // appBasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
  208. // string configPath = appBasePath + "\\MaterialName.json";
  209. // string lsTmp = File.ReadAllText(configPath);
  210. // materialNameList = JArray.Parse(lsTmp);
  211. //}
  212. //public static JObject getMaterialItem(string code)
  213. //{
  214. // var item = Config.materialNameList.FirstOrDefault(m => m.Value<string>("code") == code);
  215. // if (item == null)
  216. // return null;
  217. // return (JObject)item;
  218. //}
  219. #endregion
  220. }
  221. }