革博士程序V1仓库
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.

230 lines
10 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. public static void LoadAllConfig()
  63. {
  64. if (string.IsNullOrWhiteSpace(appBasePath))
  65. appBasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
  66. LoadDefectItemList();
  67. LoadColorNameList();
  68. //LoadMaterialNameList();
  69. //----
  70. string lsCmdPath = appBasePath + "\\CMDProcess\\";
  71. if (!Directory.Exists(lsCmdPath))
  72. Directory.CreateDirectory(lsCmdPath);
  73. string fileName;
  74. CMDProcess = new Dictionary<CMDName, JObject>();
  75. foreach (int item in Enum.GetValues(typeof(CMDName)))//item为key值
  76. {
  77. //string name = Enum.GetName(typeof(CMDName), item);//获取名称
  78. fileName = lsCmdPath + item + ".json";
  79. if (File.Exists(fileName))
  80. CMDProcess.Add((CMDName)item, JObject.Parse(File.ReadAllText(fileName)));
  81. //else
  82. // CMDProcess.Add((CMDName)item, null);
  83. }
  84. // ----
  85. IniFile ini = new IniFile(appBasePath + "\\SysConfig.ini");
  86. //[DB]
  87. DBConStr = ini.ReadString("DB", "DBConStr", "");
  88. //[Erp]
  89. ErpDBConStr = ini.ReadString("ErpDB", "ErpDBConStr", "");
  90. ErpSql = ini.ReadString("ErpDB", "ErpSql", "");
  91. //[LOG]
  92. LogPath = ini.ReadString("LOG", "LogPath", "");
  93. //[CONTROL]
  94. defectPauseSkipPhotoCount = ini.ReadInt("CONTROL", "DefectPauseSkipPhotoCount", 0);
  95. //[DEV]
  96. StopCodeScanner = ini.ReadBool("DEV", "StopCodeScanner", false);
  97. StopIO = ini.ReadBool("DEV", "StopIO", false);
  98. StopPLC = ini.ReadBool("DEV", "StopPLC", false);
  99. PlcIPAdrees = ini.ReadString("DEV", "PlcIPAdrees", "");
  100. PlcRackN = ini.ReadShort("DEV", "PlcRackN", PlcRackN);
  101. PlcSolt = ini.ReadShort("DEV", "PlcSolt", PlcSolt);
  102. StopLight = ini.ReadBool("DEV", "StopLight", false);
  103. Carmer1ConfigFilePath = ini.ReadString("DEV", "Carmer1ConfigFilePath", "");
  104. Carmer2ConfigFilePath = ini.ReadString("DEV", "Carmer2ConfigFilePath", "");
  105. IOCard_DeviceNum = ini.ReadString("DEV", "IOCard_DeviceNum", "");
  106. Light_Name = (LightDevNameEnum)ini.ReadInt("DEV", "Light_Name");
  107. Light_PortName = ini.ReadString("DEV", "Light_PortName", "");
  108. Camer_Name = (CamerDevNameEnum)ini.ReadInt("DEV", "Camer_Name");
  109. ScannerReversalX = ini.ReadBool("DEV", "ScannerReversalX", false);
  110. ScannerReversalY = ini.ReadBool("DEV", "ScannerReversalY", false);
  111. //[LIB]
  112. model_path = ini.ReadString("LIB", "model_path", "");
  113. //labels_path = ini.ReadString("LIB", "labels_path", "");
  114. cm2px_x = ini.ReadInt("LIB", "cm2px_x", 1);
  115. cm2px_y = ini.ReadInt("LIB", "cm2px_y", 1);
  116. MarginHoleWidth = ini.ReadInt("LIB", "MarginHoleWidth", 0);
  117. MiddleSuperposition = ini.ReadInt("LIB", "MiddleSuperposition", 0);
  118. expand_pixel=ini.ReadInt("LIB", "expand_pixel", 50);
  119. ImagePath = ini.ReadString("LIB", "ImagePath", "");
  120. IsSaveAllImage = ini.ReadBool("LIB", "IsSaveAllImage", false);
  121. IsSaveDefectSourceImage = ini.ReadBool("LIB", "IsSaveDefectSourceImage", false);
  122. IsSaveDefectCutImage = ini.ReadBool("LIB", "IsSaveDefectCutImage", false);
  123. //
  124. string lsTmp = ini.ReadString("Material", "SuedeList", "").Trim();
  125. if(!string.IsNullOrWhiteSpace(lsTmp))
  126. SuedeList=lsTmp.Split(new char[] { ',',';'});
  127. }
  128. #region defectItemList <=> DefectItemList.json
  129. public static void LoadDefectItemList()
  130. {
  131. if (string.IsNullOrWhiteSpace(appBasePath))
  132. appBasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
  133. string configPath = appBasePath + "\\DefectItemList.json";
  134. string lsTmp = File.ReadAllText(configPath);
  135. defectItemList = JArray.Parse(lsTmp);
  136. }
  137. public static void SaveDefectItemList(JArray newValue)
  138. {
  139. if (string.IsNullOrWhiteSpace(appBasePath))
  140. appBasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
  141. string configPath = appBasePath + "\\DefectItemList.json";
  142. File.WriteAllText(configPath, newValue.ToString());
  143. }
  144. public static JObject getDefectItem(string code)
  145. {
  146. var item=Config.defectItemList.FirstOrDefault(m => m.Value<string>("code")==code);
  147. if(item==null)
  148. return null;
  149. return (JObject)item;
  150. }
  151. public static JObject getDefectItem(int id)
  152. {
  153. var item = Config.defectItemList.FirstOrDefault(m => m.Value<int>("id") == id);
  154. if (item == null)
  155. return null;
  156. return (JObject)item;
  157. }
  158. public static string getDefectCode(int id)
  159. {
  160. var item = Config.defectItemList.FirstOrDefault(m => m.Value<int>("id") == id);
  161. if (item == null)
  162. return "";
  163. return ((JObject)item).Value<string>("code");
  164. }
  165. public static string getDefectName(string code)
  166. {
  167. var item = Config.defectItemList.FirstOrDefault(m => m.Value<string>("code") == code);
  168. if (item == null)
  169. return "";
  170. return ((JObject)item).Value<string>("name");
  171. }
  172. #endregion
  173. #region colorNameList <=> ColorNameList.json
  174. public static void LoadColorNameList()
  175. {
  176. if (string.IsNullOrWhiteSpace(appBasePath))
  177. appBasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
  178. string configPath = appBasePath + "\\ColorNameList.json";
  179. string lsTmp = File.ReadAllText(configPath);
  180. colorNameList = JArray.Parse(lsTmp);
  181. }
  182. public static JObject getColorItem(int code)
  183. {
  184. var item = Config.colorNameList.FirstOrDefault(m => m.Value<int>("code") == code);
  185. if (item == null)
  186. return null;
  187. return (JObject)item;
  188. }
  189. //public static void LoadMaterialNameList()
  190. //{
  191. // if (string.IsNullOrWhiteSpace(appBasePath))
  192. // appBasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
  193. // string configPath = appBasePath + "\\MaterialName.json";
  194. // string lsTmp = File.ReadAllText(configPath);
  195. // materialNameList = JArray.Parse(lsTmp);
  196. //}
  197. //public static JObject getMaterialItem(string code)
  198. //{
  199. // var item = Config.materialNameList.FirstOrDefault(m => m.Value<string>("code") == code);
  200. // if (item == null)
  201. // return null;
  202. // return (JObject)item;
  203. //}
  204. #endregion
  205. }
  206. }