|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- using LeatherApp.Utils;
- using Newtonsoft.Json.Linq;
- using Sunny.UI;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Threading.Tasks;
-
- namespace LeatherApp
- {
- public class Config
- {
- public static string appBasePath;
- public static Models.User loginUser;
-
- //对应文件:DefectItemList.json
- public static JArray defectItemList;
- //
- public static JArray colorNameList;//, materialNameList;
-
- //CMDProcess目录下的命令JSON文件
- public static Dictionary<CMDName, JObject> CMDProcess;
-
- //剩余N米提示(M)
- public static int residueWarnningLen = 10;
- //瑕疵暂停跳过几张图
- public static int defectPauseSkipPhotoCount=5;
-
- //DB
- //有些服务器防火墙有问题需要加上 min pool size=1 避免认为是恶意请求
- //如果用到bulkCopy需要加: AllowLoadLocalInfile=true
- //public static string dbMysqlCon = "server=localhost;Database=ProductionDB;Uid=root;Pwd=123456;";
- public static string DBConStr = "server=localhost;Database=LeatherDB;Uid=root;Pwd=123456; AllowLoadLocalInfile=true";
-
- public static string ErpDBConStr = "server=localhost;Database=LeatherDB;Uid=root;Pwd=123456; AllowLoadLocalInfile=true";
- public static string ErpSql = "select top 1 a,b,c from tableA where code=@code order by id desc";
-
- //LOG
- public static string LogPath;
-
- //DEV
- public static bool StopCodeScanner = false;
- public static bool StopIO = false;
- public static bool StopPLC=true;
- public static bool StopLight = true;
- public static string PlcIPAdrees;
- public static short PlcRackN=0, PlcSolt=1;
-
- public static string Carmer1ConfigFilePath,Carmer2ConfigFilePath;
- public static string IOCard_DeviceNum = "PCI-1730,BID#0";
- public static bool ScannerReversalX = false;
- public static bool ScannerReversalY = false;
-
- public static string Light_PortName;//COM端口号
- public static LightDevNameEnum Light_Name = LightDevNameEnum.锐视;
- public static CamerDevNameEnum Camer_Name = CamerDevNameEnum.海康;
- //LIB
- public static string model_path = "";//./models/best_0805_bs8.onnx
- //public static string labels_path = "./models/hexin.names";
- public static int cm2px_x = 1;
- public static int cm2px_y = 1;
- //边缘孔洞宽(门幅计算包含,识别库去除)
- public static int MarginHoleWidth = 120, MiddleSuperposition;
- public static int expand_pixel=50;
- public static string ImagePath;
- public static bool IsSaveAllImage, IsSaveDefectSourceImage, IsSaveDefectCutImage;
-
- //材质Material
- public static string[] SuedeList = new string[0];
-
- public static void LoadAllConfig()
- {
- if (string.IsNullOrWhiteSpace(appBasePath))
- appBasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
-
- LoadDefectItemList();
- LoadColorNameList();
- //LoadMaterialNameList();
- //----
- string lsCmdPath = appBasePath + "\\CMDProcess\\";
- if (!Directory.Exists(lsCmdPath))
- Directory.CreateDirectory(lsCmdPath);
-
- string fileName;
- CMDProcess = new Dictionary<CMDName, JObject>();
- foreach (int item in Enum.GetValues(typeof(CMDName)))//item为key值
- {
- //string name = Enum.GetName(typeof(CMDName), item);//获取名称
- fileName = lsCmdPath + item + ".json";
- if (File.Exists(fileName))
- CMDProcess.Add((CMDName)item, JObject.Parse(File.ReadAllText(fileName)));
- //else
- // CMDProcess.Add((CMDName)item, null);
- }
-
- // ----
- IniFile ini = new IniFile(appBasePath + "\\SysConfig.ini");
-
- //[DB]
- DBConStr = ini.ReadString("DB", "DBConStr", "");
- //[Erp]
- ErpDBConStr = ini.ReadString("ErpDB", "ErpDBConStr", "");
- ErpSql = ini.ReadString("ErpDB", "ErpSql", "");
-
- //[LOG]
- LogPath = ini.ReadString("LOG", "LogPath", "");
- //[CONTROL]
- defectPauseSkipPhotoCount = ini.ReadInt("CONTROL", "DefectPauseSkipPhotoCount", 0);
- //[DEV]
- StopCodeScanner = ini.ReadBool("DEV", "StopCodeScanner", false);
- StopIO = ini.ReadBool("DEV", "StopIO", false);
- StopPLC = ini.ReadBool("DEV", "StopPLC", false);
- PlcIPAdrees = ini.ReadString("DEV", "PlcIPAdrees", "");
- PlcRackN = ini.ReadShort("DEV", "PlcRackN", PlcRackN);
- PlcSolt = ini.ReadShort("DEV", "PlcSolt", PlcSolt);
-
- StopLight = ini.ReadBool("DEV", "StopLight", false);
- Carmer1ConfigFilePath = ini.ReadString("DEV", "Carmer1ConfigFilePath", "");
- Carmer2ConfigFilePath = ini.ReadString("DEV", "Carmer2ConfigFilePath", "");
- IOCard_DeviceNum = ini.ReadString("DEV", "IOCard_DeviceNum", "");
- Light_Name = (LightDevNameEnum)ini.ReadInt("DEV", "Light_Name");
- Light_PortName = ini.ReadString("DEV", "Light_PortName", "");
- Camer_Name = (CamerDevNameEnum)ini.ReadInt("DEV", "Camer_Name");
- ScannerReversalX = ini.ReadBool("DEV", "ScannerReversalX", false);
- ScannerReversalY = ini.ReadBool("DEV", "ScannerReversalY", false);
-
- //[LIB]
- model_path = ini.ReadString("LIB", "model_path", "");
- //labels_path = ini.ReadString("LIB", "labels_path", "");
- cm2px_x = ini.ReadInt("LIB", "cm2px_x", 1);
- cm2px_y = ini.ReadInt("LIB", "cm2px_y", 1);
- MarginHoleWidth = ini.ReadInt("LIB", "MarginHoleWidth", 0);
- MiddleSuperposition = ini.ReadInt("LIB", "MiddleSuperposition", 0);
- expand_pixel=ini.ReadInt("LIB", "expand_pixel", 50);
-
- ImagePath = ini.ReadString("LIB", "ImagePath", "");
- IsSaveAllImage = ini.ReadBool("LIB", "IsSaveAllImage", false);
- IsSaveDefectSourceImage = ini.ReadBool("LIB", "IsSaveDefectSourceImage", false);
- IsSaveDefectCutImage = ini.ReadBool("LIB", "IsSaveDefectCutImage", false);
-
- //
- string lsTmp = ini.ReadString("Material", "SuedeList", "").Trim();
- if(!string.IsNullOrWhiteSpace(lsTmp))
- SuedeList=lsTmp.Split(new char[] { ',',';'});
- }
-
- #region defectItemList <=> DefectItemList.json
- public static void LoadDefectItemList()
- {
- if (string.IsNullOrWhiteSpace(appBasePath))
- appBasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
- string configPath = appBasePath + "\\DefectItemList.json";
- string lsTmp = File.ReadAllText(configPath);
- defectItemList = JArray.Parse(lsTmp);
- }
- public static void SaveDefectItemList(JArray newValue)
- {
- if (string.IsNullOrWhiteSpace(appBasePath))
- appBasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
- string configPath = appBasePath + "\\DefectItemList.json";
- File.WriteAllText(configPath, newValue.ToString());
- }
- public static JObject getDefectItem(string code)
- {
- var item=Config.defectItemList.FirstOrDefault(m => m.Value<string>("code")==code);
- if(item==null)
- return null;
- return (JObject)item;
- }
- public static JObject getDefectItem(int id)
- {
- var item = Config.defectItemList.FirstOrDefault(m => m.Value<int>("id") == id);
- if (item == null)
- return null;
- return (JObject)item;
- }
- public static string getDefectCode(int id)
- {
- var item = Config.defectItemList.FirstOrDefault(m => m.Value<int>("id") == id);
- if (item == null)
- return "";
- return ((JObject)item).Value<string>("code");
- }
- public static string getDefectName(string code)
- {
- var item = Config.defectItemList.FirstOrDefault(m => m.Value<string>("code") == code);
- if (item == null)
- return "";
- return ((JObject)item).Value<string>("name");
- }
- #endregion
-
- #region colorNameList <=> ColorNameList.json
- public static void LoadColorNameList()
- {
- if (string.IsNullOrWhiteSpace(appBasePath))
- appBasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
- string configPath = appBasePath + "\\ColorNameList.json";
- string lsTmp = File.ReadAllText(configPath);
- colorNameList = JArray.Parse(lsTmp);
- }
- public static JObject getColorItem(int code)
- {
- var item = Config.colorNameList.FirstOrDefault(m => m.Value<int>("code") == code);
- if (item == null)
- return null;
- return (JObject)item;
- }
- //public static void LoadMaterialNameList()
- //{
- // if (string.IsNullOrWhiteSpace(appBasePath))
- // appBasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
- // string configPath = appBasePath + "\\MaterialName.json";
- // string lsTmp = File.ReadAllText(configPath);
- // materialNameList = JArray.Parse(lsTmp);
- //}
- //public static JObject getMaterialItem(string code)
- //{
- // var item = Config.materialNameList.FirstOrDefault(m => m.Value<string>("code") == code);
- // if (item == null)
- // return null;
- // return (JObject)item;
- //}
- #endregion
- }
- }
|