Main.cs 83 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440
  1. using CCWin;
  2. using Newtonsoft.Json;
  3. using Newtonsoft.Json.Linq;
  4. using SufeiUtil;
  5. using SXLibrary;
  6. using System;
  7. using System.Collections;
  8. using System.Collections.Generic;
  9. using System.Data.SQLite;
  10. using System.Drawing;
  11. using System.IO;
  12. using System.IO.Ports;
  13. using System.Linq;
  14. using System.Net;
  15. using System.Threading;
  16. using System.Threading.Tasks;
  17. using System.Windows.Forms;
  18. namespace MOKA_Factory_Tools
  19. {
  20. public delegate void MoveHandler(Point XY, ArrayList formlocationmsg, int num);
  21. public delegate void KeyDownHandler(ArrayList formlocationmsg, IntPtr intPtr);
  22. public partial class Main : Skin_Color
  23. {
  24. MidList midList1 = new MidList();
  25. UpgradeMsgList UpgradeMsgList1 = new UpgradeMsgList();
  26. MidAddress midAddress1 = new MidAddress();
  27. Config_ReadCheck cfg_readcheck = new Config_ReadCheck();
  28. Config_WriteCheck cfg_writecheck = new Config_WriteCheck();
  29. Config_WriteDone cfg_writedone = new Config_WriteDone();
  30. FunctionSetting functionSetting1 = new FunctionSetting();
  31. SQLiteConnection LocalDB = null;
  32. SQLiteConnection ErrorDB = null;
  33. Dictionary<string, string> ChannelMapList = new Dictionary<string, string>();
  34. Dictionary<string, string> LanguageMapList = new Dictionary<string, string>();
  35. string Custom_ProjectID = "";
  36. ArrayList formlocationmsg = new ArrayList();
  37. string ErrorDBPath = AppDomain.CurrentDomain.BaseDirectory + "\\Error.db";
  38. Thread uploadbackground;
  39. bool LocalWrite = false;//离线抄写开关
  40. bool LocationMark = true;//操作窗体换行点
  41. int LocationNum = 0;//一行操作窗体数
  42. public event KeyDownHandler KeyDownEvent;
  43. public event MoveHandler MoveEvent;
  44. public Main(int enable)
  45. {
  46. InitializeComponent();
  47. LockSettingFunction(enable == 0 || enable == 3);
  48. CreateKeyManually.Visible = enable == 1;
  49. LocalWrite = enable == 3;
  50. }
  51. private void Form1_Load(object sender, EventArgs e)
  52. {
  53. uploadbackground = new Thread(UploadBackGround);
  54. uploadbackground.IsBackground = true;
  55. TVCOM.Items.AddRange(SerialPort.GetPortNames());
  56. LoadJsonConfig();
  57. this.StartPosition = FormStartPosition.Manual;
  58. this.Location = new Point(0, 0);
  59. this.Text = CommonMethod.FactoryName + " " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
  60. if (!File.Exists(ErrorDBPath))
  61. {
  62. if (SQLiteHelper.NewDbFile(ErrorDBPath))
  63. {
  64. SQLiteHelper.NewTable(ErrorDBPath, "ErrorReport", "(ID INTEGER PRIMARY KEY AUTOINCREMENT,url varchar,content varvhar,gener_date DATETIME DEFAULT (datetime(CURRENT_TIMESTAMP,'localtime')),report_date DATETIME)");
  65. SQLiteHelper.NewTable(ErrorDBPath, "CopyDelayReport", "(ID INTEGER PRIMARY KEY AUTOINCREMENT,bid varchar,url varchar,content varvhar,copy_date DATETIME DEFAULT (datetime(CURRENT_TIMESTAMP,'localtime')),report_date DATETIME)");
  66. SQLiteHelper.NewTable(ErrorDBPath, "ProductionCount", "(bid varchar,count varchar)");
  67. }
  68. }
  69. if (ErrorDB == null)
  70. {
  71. ErrorDB = new SQLiteConnection("data source=" + ErrorDBPath);
  72. ErrorDB.Open();
  73. }
  74. }
  75. private void SetDSNLimit()
  76. {
  77. #region 试产订单,不需要自动限制条码;
  78. string strValue = CommonMethod.ReadProfileString("MOKAFactoryTools", "OrderType", "");
  79. if (strValue.Equals("TR", StringComparison.OrdinalIgnoreCase))
  80. {
  81. return;
  82. }
  83. #endregion
  84. // 如果抄写PSN,不自动赋值条码限制;
  85. if (BarcodeWrite.Checked)
  86. return;
  87. // 设置条码限制默认打上勾;
  88. if (midList1.keytype != null && midList1.keytype.ContainsKey("DSN"))
  89. {
  90. BarcodeLimit.Checked = true;
  91. BarCodeKeyCodeText.Text = OrderText.Text;
  92. }
  93. }
  94. private void OrderSubmit_Click(object sender, EventArgs e)
  95. {
  96. SQLiteHelper.DeleteOldData(ErrorDB);//删除30天以前已经上报的数据
  97. if (TestMode.serverurl == Serverurl.Testurl)
  98. {// 此软件连接测试服务器,请勿用于生产
  99. MessageBoxButtons messButton = MessageBoxButtons.YesNo;
  100. DialogResult dr = MessageBox.Show(LResource.TestServerUsingError, LResource.Error, messButton);
  101. if (dr == DialogResult.Yes)
  102. {
  103. //
  104. }
  105. else
  106. {
  107. return;
  108. }
  109. }
  110. if (TVCOM.SelectedItem == null)
  111. {
  112. MessageBox.Show(LResource.TVCOMNullError, LResource.Error);
  113. return;
  114. }
  115. if (OrderText.Text.Trim().Length == 0)
  116. {
  117. MessageBox.Show(LResource.OrderNullError, LResource.Error);
  118. return;
  119. }
  120. if (!SQLiteHelper.CheckProductionNum(ErrorDB, OrderText.Text.Trim()))
  121. {
  122. MessageBox.Show(LResource.CheckProductionNumError, LResource.Error);
  123. return;
  124. }
  125. if (timer1.Enabled == false)
  126. timer1.Start();
  127. OrderSubmit.Text = LResource.Waiting;
  128. SaveJsonConfig("LastOrder", OrderText.Text.ToString());
  129. functionSetting1.TVCOM = TVCOM.SelectedItem.ToString();
  130. functionSetting1.TVBaud = TVBaud.SelectedItem.ToString();
  131. functionSetting1.ChannelList = ChannelList.SelectedItem.ToString();
  132. functionSetting1.WriteChannel = WriteChannel.Checked;
  133. functionSetting1.WriteOSD = WriteOSD.Checked;
  134. functionSetting1.OSDList = OSDList.SelectedItem.ToString();
  135. functionSetting1.WriteSHOP = WriteSHOP.Checked;
  136. functionSetting1.SHOPList = SHOPList.SelectedItem.ToString();
  137. functionSetting1.WriteWB = WriteWB.Checked;
  138. functionSetting1.WBInit = WBInit.Checked;
  139. functionSetting1.WBPath = WBPath.Text;
  140. if (!LocalWrite)
  141. {
  142. if (Preload.Checked)
  143. {
  144. string dbPath = AppDomain.CurrentDomain.BaseDirectory + "\\Keys\\" + OrderText.Text.Trim() + ".db";
  145. if (File.Exists(dbPath))
  146. {
  147. if (LocalDB == null)
  148. {
  149. LocalDB = new SQLiteConnection("data source=" + dbPath);
  150. LocalDB.Open();
  151. }
  152. if (SQLiteHelper.WholeCheckDownloadStatus(LocalDB, OrderText.Text.Trim()))
  153. {
  154. try
  155. {
  156. if (SQLiteHelper.GetDBMidInfo(LocalDB, OrderText.Text.Trim(), out midAddress1))
  157. {
  158. if (UsinglocalIDCheck.Checked)
  159. {
  160. midAddress1.pid = Custom_ProjectID;
  161. MessageBox.Show(LResource.WilluseLocalPID, "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  162. }
  163. else if (midAddress1.pid != Custom_ProjectID && Custom_ProjectID.Trim().Length > 0)
  164. {
  165. if (midAddress1.pid != null)
  166. if (midAddress1.pid.Trim().Length > 0)
  167. PID_Num.Value = Convert.ToDecimal(midAddress1.pid);
  168. MessageBox.Show(LResource.WilluseOnlinePID, "", MessageBoxButtons.OK, MessageBoxIcon.Information);
  169. }
  170. if (SQLiteHelper.GetrokuCustomer(LocalDB, OrderText.Text, out RokuCustomer rokuCustomer_1))
  171. {
  172. midList1.rokuCustomer = rokuCustomer_1;
  173. };
  174. if (SQLiteHelper.Getdsn(LocalDB, OrderText.Text, out string firetvdsn))
  175. {
  176. midList1.keytype = new Dictionary<string, string>();
  177. midList1.keytype.Add("DSN", firetvdsn);
  178. };
  179. if (SQLiteHelper.Getwhitebalance(LocalDB, OrderText.Text, out WhiteBalanceInfo whiteBalanceInfo_1))
  180. {
  181. functionSetting1.WBPath = dbPath;
  182. functionSetting1.WriteWB = true;
  183. functionSetting1.NormalRGB = new byte[3];
  184. functionSetting1.CoolRGB = new byte[3];
  185. functionSetting1.WarmRGB = new byte[3];
  186. functionSetting1.NormalRGB[0] = (byte)Convert.ToDouble(whiteBalanceInfo_1.hdmirgain);
  187. functionSetting1.NormalRGB[1] = (byte)Convert.ToDouble(whiteBalanceInfo_1.hdmiggain);
  188. functionSetting1.NormalRGB[2] = (byte)Convert.ToDouble(whiteBalanceInfo_1.hdmibgain);
  189. functionSetting1.CoolRGB[0] = (byte)(Convert.ToDouble(whiteBalanceInfo_1.lrgain) + 256);
  190. functionSetting1.CoolRGB[1] = (byte)(Convert.ToDouble(whiteBalanceInfo_1.lggain) + 256);
  191. functionSetting1.CoolRGB[2] = (byte)(Convert.ToDouble(whiteBalanceInfo_1.lbgain) + 256);
  192. functionSetting1.WarmRGB[0] = (byte)(Convert.ToDouble(whiteBalanceInfo_1.nrgain) + 256);
  193. functionSetting1.WarmRGB[1] = (byte)(Convert.ToDouble(whiteBalanceInfo_1.nggain) + 256);
  194. functionSetting1.WarmRGB[2] = (byte)(Convert.ToDouble(whiteBalanceInfo_1.nbgain) + 256);
  195. };
  196. OperationPanel operationPanel1 = new OperationPanel(this, LocalDB, ErrorDB, midAddress1, functionSetting1, cfg_writecheck, cfg_readcheck, cfg_writedone, Preload.Checked, midList1, OrderText.Text.Trim());
  197. operationPanel1.StartPosition = FormStartPosition.Manual;
  198. if ((this.Right + operationPanel1.Size.Width * formlocationmsg.Count) > Screen.PrimaryScreen.Bounds.Width && LocationMark)
  199. {
  200. LocationMark = false;
  201. LocationNum = formlocationmsg.Count;
  202. }
  203. if (formlocationmsg.Count == 0)
  204. operationPanel1.Location = (Point)new Size(this.Right, this.Top);
  205. else if ((this.Right + operationPanel1.Size.Width * formlocationmsg.Count) > Screen.PrimaryScreen.Bounds.Width)
  206. {
  207. Point point = ((Dictionary<IntPtr, Point>)formlocationmsg[formlocationmsg.Count - 1]).Last().Value;
  208. operationPanel1.Location = (Point)new Size(this.Right + operationPanel1.Size.Width * (formlocationmsg.Count - LocationNum), this.Top + operationPanel1.Size.Height);
  209. }
  210. else
  211. {
  212. Point point = ((Dictionary<IntPtr, Point>)formlocationmsg[formlocationmsg.Count - 1]).Last().Value;
  213. operationPanel1.Location = (Point)new Size(this.Right + operationPanel1.Size.Width * formlocationmsg.Count, this.Top);
  214. }
  215. operationPanel1.DeleteIntptr += new OperationPanel.DisplayUpdateDelegate(DeleteIntptr);
  216. operationPanel1.SNKeyDownEven += new OperationPanel.SNKeyDown(SNKeyDownEven);
  217. operationPanel1.AutoKeyRequire += new OperationPanel.AutoKeyRequireDelegate(AutoKeyRequire);
  218. IntPtr intPtr = operationPanel1.Handle;
  219. Dictionary<IntPtr, Point> part1 = new Dictionary<IntPtr, Point>();
  220. part1.Add(intPtr, (Point)new Size(operationPanel1.Right, operationPanel1.Top));
  221. formlocationmsg.Add(part1);
  222. operationPanel1.Show();
  223. }
  224. else
  225. {
  226. MessageBox.Show("Read LocalDB error,please delete old db file and download a new one");
  227. }
  228. }
  229. catch (Exception ex)
  230. {
  231. Log.WriteErrorLog(ex.Message);
  232. }
  233. // 是否有dsn要抄写;
  234. SetDSNLimit();
  235. }
  236. }
  237. else
  238. {
  239. // 预绑定模式下:没有db数据库时需要下载json包;
  240. if (V2Method.GetMidInfo(OrderText.Text.Trim(), TestMode.MAC, ErrorDB, out midList1))
  241. {
  242. if (V2Method.GetOfflineData(midList1.host, OrderText.Text.Trim(), ErrorDB, out List<MidAddress> midAddress2))
  243. {
  244. WhiteBalanceList WhiteBalanceListNow;
  245. // 如果是抄写EDID,则不获取白平衡数据;
  246. if (CommonMethod.IsEDIDCopy(midList1))
  247. midList1.whiteType = "-1";
  248. switch (midList1.whiteType)//订单白平衡预置状态
  249. {
  250. case "0"://旧订单,默认值
  251. {
  252. CommonMethod.GetWhiteBalanceInfo(TestMode.getWhiteBalanceInfoUrl, OrderText.Text.Trim(), TestMode.MAC, ErrorDB, out WhiteBalanceListNow);
  253. break;
  254. }
  255. case "1"://未预置或预置LR数据
  256. {
  257. CommonMethod.GetWhiteBalanceInfo(TestMode.getWhiteBalanceInfoUrl, OrderText.Text.Trim(), TestMode.MAC, ErrorDB, out WhiteBalanceListNow);
  258. if (WhiteBalanceListNow.whiteBalanceInfo == null)
  259. {
  260. MessageBox.Show("White balance info error, please contact factory engineer!");
  261. return;
  262. }
  263. break;
  264. }
  265. case "2"://已预置PR数据
  266. {
  267. CommonMethod.GetWhiteBalanceInfo(TestMode.getWhiteBalanceInfoUrl, OrderText.Text.Trim(), TestMode.MAC, ErrorDB, out WhiteBalanceListNow);
  268. break;
  269. }
  270. default:
  271. {
  272. WhiteBalanceListNow = null;
  273. break;
  274. }
  275. }
  276. foreach (var midAddress1 in midAddress2)
  277. {
  278. string KeyPath = AppDomain.CurrentDomain.BaseDirectory + "\\download\\" + midAddress1.order + ".json";
  279. if (System.IO.File.Exists(KeyPath))
  280. {
  281. if (GetMD5.GetMD5HashFromFile(KeyPath) == midAddress1.pmd5)
  282. {
  283. if (SQLiteHelper.NewDbFile(dbPath))
  284. {
  285. SQLiteHelper.NewTable(dbPath, "keys", "(sn varchar,keys varvhar,copy_date DATETIME,report_date DATETIME)");
  286. SQLiteHelper.NewTable(dbPath, "mid", "(bid varchar,number varchar, pid varchar,ctype varvhar,version varvhar,host varchar,purl varvhar,psize varvhar,pmd5 varvhar,status varvhar,start_date DATETIME DEFAULT (datetime(CURRENT_TIMESTAMP,'localtime')),finish_date DATETIME,desc varvhar)");
  287. SQLiteHelper.NewTable(dbPath, "report", "(url varchar,content varchar,gener_date DATETIME,report_date DATETIME)");
  288. SQLiteHelper.NewTable(dbPath, "rokuCustomer", "(ordernum varchar,region varchar,brand varchar,oemmodel varchar,supporturl varchar,supportphone varchar,productiondate varchar,remotetype varchar)");
  289. SQLiteHelper.NewTable(dbPath, "whitebalance", "(ordernum varchar,hdmirgain varchar,hdmiggain varchar,hdmibgain varchar,nrgain varchar,nggain varchar,nbgain varchar,lrgain varchar,lggain varchar,lbgain varchar,updatetime DATETIME DEFAULT (datetime(CURRENT_TIMESTAMP,'localtime')))");
  290. SQLiteHelper.NewTable(dbPath, "dsn", "(ordernum varchar,dsn varchar,updatetime DATETIME DEFAULT (datetime(CURRENT_TIMESTAMP,'localtime')))");
  291. SQLiteHelper.AddOneLine(dbPath, new object[] { midAddress1.order, midAddress1.number, midAddress1.pid, midAddress1.ctype, midAddress1.version, midList1.host, midAddress1.purl, midAddress1.psize, midAddress1.pmd5, "1" });
  292. if (midList1.rokuCustomer != null)
  293. SQLiteHelper.AddRokuOneLine(dbPath, new object[] { midList1.rokuCustomer.ordernum, midList1.rokuCustomer.region, midList1.rokuCustomer.brand, midList1.rokuCustomer.oemmodel, midList1.rokuCustomer.supporturl, midList1.rokuCustomer.supportphone, midList1.rokuCustomer.productiondate, midList1.rokuCustomer.remotetype });
  294. if (WhiteBalanceListNow != null)
  295. if (WhiteBalanceListNow.whiteBalanceInfo != null)
  296. SQLiteHelper.AddwbOneLine(dbPath, new object[] { WhiteBalanceListNow.whiteBalanceInfo.ordernum,
  297. WhiteBalanceListNow.whiteBalanceInfo.hdmirgain, WhiteBalanceListNow.whiteBalanceInfo.hdmiggain, WhiteBalanceListNow.whiteBalanceInfo.hdmibgain,
  298. WhiteBalanceListNow.whiteBalanceInfo.nrgain, WhiteBalanceListNow.whiteBalanceInfo.nggain, WhiteBalanceListNow.whiteBalanceInfo.nbgain,
  299. WhiteBalanceListNow.whiteBalanceInfo.lrgain, WhiteBalanceListNow.whiteBalanceInfo.lggain, WhiteBalanceListNow.whiteBalanceInfo.lbgain });
  300. if (midList1.keytype.ContainsKey("DSN"))
  301. {
  302. SQLiteHelper.AdddsnOneLine(dbPath, new object[] { midAddress1.order, midList1.keytype["DSN"] });
  303. }
  304. SQLiteHelper.UpdateTime(dbPath, midAddress1.order);
  305. }
  306. if (File.Exists(dbPath))
  307. {
  308. List<object[]> keyDatas = new List<object[]>();
  309. using (System.IO.StreamReader file = System.IO.File.OpenText(KeyPath))
  310. {
  311. using (JsonTextReader reader = new JsonTextReader(file))
  312. {
  313. JArray o = (JArray)JToken.ReadFrom(reader);
  314. foreach (var ss in o) //查找某个字段与值
  315. {
  316. var sn = ((JObject)ss)["sn"];
  317. var data = ((JObject)ss)["key"];
  318. keyDatas.Add(new object[] { sn, data });
  319. }
  320. }
  321. }
  322. SQLiteHelper.InsertKeys(dbPath, keyDatas);
  323. }
  324. try
  325. {
  326. if (LocalDB == null)
  327. {
  328. LocalDB = new SQLiteConnection("data source=" + dbPath);
  329. LocalDB.Open();
  330. }
  331. OperationPanel operationPanel1 = new OperationPanel(this, LocalDB, ErrorDB, midAddress1, functionSetting1, cfg_writecheck, cfg_readcheck, cfg_writedone, Preload.Checked, midList1, OrderText.Text.Trim());
  332. operationPanel1.StartPosition = FormStartPosition.Manual;
  333. if ((this.Right + operationPanel1.Size.Width * formlocationmsg.Count) > Screen.PrimaryScreen.Bounds.Width && LocationMark)
  334. {
  335. LocationMark = false;
  336. LocationNum = formlocationmsg.Count;
  337. }
  338. if (formlocationmsg.Count == 0)
  339. operationPanel1.Location = (Point)new Size(this.Right, this.Top);
  340. else if ((this.Right + operationPanel1.Size.Width * formlocationmsg.Count) > Screen.PrimaryScreen.Bounds.Width)
  341. {
  342. Point point = ((Dictionary<IntPtr, Point>)formlocationmsg[formlocationmsg.Count - 1]).Last().Value;
  343. operationPanel1.Location = (Point)new Size(this.Right + operationPanel1.Size.Width * (formlocationmsg.Count - LocationNum), this.Top + operationPanel1.Size.Height);
  344. }
  345. else
  346. {
  347. Point point = ((Dictionary<IntPtr, Point>)formlocationmsg[formlocationmsg.Count - 1]).Last().Value;
  348. operationPanel1.Location = (Point)new Size(this.Right + operationPanel1.Size.Width * formlocationmsg.Count, this.Top);
  349. }
  350. operationPanel1.DeleteIntptr += new OperationPanel.DisplayUpdateDelegate(DeleteIntptr);
  351. operationPanel1.SNKeyDownEven += new OperationPanel.SNKeyDown(SNKeyDownEven);
  352. operationPanel1.AutoKeyRequire += new OperationPanel.AutoKeyRequireDelegate(AutoKeyRequire);
  353. IntPtr intPtr = operationPanel1.Handle;
  354. Dictionary<IntPtr, Point> part1 = new Dictionary<IntPtr, Point>();
  355. part1.Add(intPtr, (Point)new Size(operationPanel1.Right, operationPanel1.Top));
  356. formlocationmsg.Add(part1);
  357. operationPanel1.Show();
  358. }
  359. catch (Exception ex)
  360. {
  361. Log.WriteErrorLog(ex.Message);
  362. }
  363. }
  364. else
  365. {
  366. Download DownloadPage = new Download(ErrorDB, midAddress1, -1, midList1, WhiteBalanceListNow);
  367. DownloadPage.ShowDialog();
  368. int gid = GC.GetGeneration(DownloadPage);
  369. DownloadPage = null;
  370. GC.Collect(gid);
  371. }
  372. }
  373. else
  374. {
  375. Download DownloadPage = new Download(ErrorDB, midAddress1, -1, midList1, WhiteBalanceListNow);
  376. DownloadPage.ShowDialog();
  377. int gid = GC.GetGeneration(DownloadPage);
  378. DownloadPage = null;
  379. GC.Collect(gid);
  380. }
  381. }
  382. if (File.Exists(dbPath))
  383. {
  384. if (LocalDB == null)
  385. {
  386. LocalDB = new SQLiteConnection("data source=" + dbPath);
  387. LocalDB.Open();
  388. }
  389. if (SQLiteHelper.WholeCheckDownloadStatus(LocalDB, OrderText.Text.Trim()))
  390. {
  391. if (V2Method.ReportDownloadStatus(midList1.host, OrderText.Text.Trim(), ErrorDB))
  392. MessageBox.Show(LResource.DownloadSuccess);
  393. else
  394. MessageBox.Show(LResource.DownloadReportFail);
  395. }
  396. }
  397. }
  398. else
  399. {
  400. MessageBox.Show(LResource.GetMidAdresserror);
  401. }
  402. }
  403. else
  404. {
  405. MessageBox.Show(LResource.GetMidInfoerror);
  406. }
  407. // 是否有dsn要抄写;
  408. SetDSNLimit();
  409. }
  410. }
  411. else
  412. {
  413. if (V2Method.GetMidInfo(OrderText.Text.Trim(), TestMode.MAC, ErrorDB, out midList1))
  414. {
  415. CommonMethod.CheckKeyType(midList1.keytype, cfg_writedone, out key2Write);
  416. OperationPanel.key2Write = key2Write;
  417. if (UsinglocalIDCheck.Checked)
  418. {
  419. midList1.projectid = Custom_ProjectID;
  420. MessageBox.Show(LResource.WilluseLocalPID, "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  421. }
  422. else if (midList1.projectid != Custom_ProjectID && Custom_ProjectID.Trim().Length > 0)
  423. {
  424. if (midList1.projectid != null)
  425. if (midList1.projectid.Trim().Length > 0)
  426. PID_Num.Value = Convert.ToDecimal(midList1.projectid);
  427. MessageBox.Show(LResource.WilluseOnlinePID, "", MessageBoxButtons.OK, MessageBoxIcon.Information);
  428. }
  429. try
  430. {
  431. OperationPanel operationPanel1 = new OperationPanel(this, LocalDB, ErrorDB, midAddress1, functionSetting1, cfg_writecheck, cfg_readcheck, cfg_writedone, Preload.Checked, midList1, OrderText.Text.Trim());
  432. operationPanel1.StartPosition = FormStartPosition.Manual;
  433. if ((this.Right + operationPanel1.Size.Width * formlocationmsg.Count) > Screen.PrimaryScreen.Bounds.Width && LocationMark)
  434. {
  435. LocationMark = false;
  436. LocationNum = formlocationmsg.Count;
  437. }
  438. if (formlocationmsg.Count == 0)
  439. operationPanel1.Location = (Point)new Size(this.Right, this.Top);
  440. else if ((this.Right + operationPanel1.Size.Width * formlocationmsg.Count) > Screen.PrimaryScreen.Bounds.Width)
  441. {
  442. Point point = ((Dictionary<IntPtr, Point>)formlocationmsg[formlocationmsg.Count - 1]).Last().Value;
  443. operationPanel1.Location = (Point)new Size(this.Right + operationPanel1.Size.Width * (formlocationmsg.Count - LocationNum), this.Top + operationPanel1.Size.Height);
  444. }
  445. else
  446. {
  447. Point point = ((Dictionary<IntPtr, Point>)formlocationmsg[formlocationmsg.Count - 1]).Last().Value;
  448. operationPanel1.Location = (Point)new Size(this.Right + operationPanel1.Size.Width * formlocationmsg.Count, this.Top);
  449. }
  450. operationPanel1.DeleteIntptr += new OperationPanel.DisplayUpdateDelegate(DeleteIntptr);
  451. operationPanel1.SNKeyDownEven += new OperationPanel.SNKeyDown(SNKeyDownEven);
  452. operationPanel1.AutoKeyRequire += new OperationPanel.AutoKeyRequireDelegate(AutoKeyRequire);
  453. IntPtr intPtr = operationPanel1.Handle;
  454. Dictionary<IntPtr, Point> part1 = new Dictionary<IntPtr, Point>();
  455. part1.Add(intPtr, (Point)new Size(operationPanel1.Right, operationPanel1.Top));
  456. formlocationmsg.Add(part1);
  457. operationPanel1.Show();
  458. }
  459. catch (Exception ex)
  460. {
  461. Log.WriteErrorLog(ex.Message);
  462. }
  463. // 是否有dsn要抄写;
  464. SetDSNLimit();
  465. }
  466. else
  467. {
  468. MessageBox.Show(LResource.GetMidInfoerror);
  469. }
  470. }
  471. }
  472. else
  473. {
  474. MessageBox.Show(LResource.LocalKeyMode);
  475. try
  476. {
  477. if (Preload.Checked)
  478. {
  479. string dbPath = AppDomain.CurrentDomain.BaseDirectory + "\\Keys\\" + OrderText.Text.Trim() + ".db";
  480. if (File.Exists(dbPath))
  481. {
  482. if (LocalDB == null)
  483. {
  484. LocalDB = new SQLiteConnection("data source=" + dbPath);
  485. LocalDB.Open();
  486. }
  487. if (SQLiteHelper.WholeCheckDownloadStatus(LocalDB, OrderText.Text.Trim()))
  488. {
  489. if (SQLiteHelper.GetDBMidInfo(LocalDB, OrderText.Text.Trim(), out midAddress1))
  490. {
  491. if (UsinglocalIDCheck.Checked)
  492. {
  493. midAddress1.pid = Custom_ProjectID;
  494. MessageBox.Show(LResource.WilluseLocalPID, "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  495. }
  496. else if (midAddress1.pid != Custom_ProjectID && Custom_ProjectID.Trim().Length > 0)
  497. {
  498. if (midAddress1.pid != null)
  499. if (midAddress1.pid.Trim().Length > 0)
  500. PID_Num.Value = Convert.ToDecimal(midAddress1.pid);
  501. MessageBox.Show(LResource.WilluseOnlinePID, "", MessageBoxButtons.OK, MessageBoxIcon.Information);
  502. }
  503. midList1 = new MidList()
  504. {
  505. keytype = new Dictionary<string, string>(),
  506. clienttype = midAddress1.ctype,
  507. version = midAddress1.version,
  508. projectid = midAddress1.pid,
  509. host = "LocalPC"
  510. };
  511. if (SQLiteHelper.GetrokuCustomer(LocalDB, OrderText.Text, out RokuCustomer rokuCustomer_1))
  512. {
  513. midList1.rokuCustomer = rokuCustomer_1;
  514. };
  515. if (SQLiteHelper.Getdsn(LocalDB, OrderText.Text, out string firetvdsn))
  516. {
  517. midList1.keytype = new Dictionary<string, string>();
  518. midList1.keytype.Add("DSN", firetvdsn);
  519. };
  520. if (SQLiteHelper.Getwhitebalance(LocalDB, OrderText.Text, out WhiteBalanceInfo whiteBalanceInfo_1))
  521. {
  522. functionSetting1.WBPath = dbPath;
  523. functionSetting1.WriteWB = true;
  524. functionSetting1.NormalRGB = new byte[3];
  525. functionSetting1.CoolRGB = new byte[3];
  526. functionSetting1.WarmRGB = new byte[3];
  527. functionSetting1.NormalRGB[0] = (byte)Convert.ToDouble(whiteBalanceInfo_1.hdmirgain);
  528. functionSetting1.NormalRGB[1] = (byte)Convert.ToDouble(whiteBalanceInfo_1.hdmiggain);
  529. functionSetting1.NormalRGB[2] = (byte)Convert.ToDouble(whiteBalanceInfo_1.hdmibgain);
  530. functionSetting1.CoolRGB[0] = (byte)(Convert.ToDouble(whiteBalanceInfo_1.lrgain) + 256);
  531. functionSetting1.CoolRGB[1] = (byte)(Convert.ToDouble(whiteBalanceInfo_1.lggain) + 256);
  532. functionSetting1.CoolRGB[2] = (byte)(Convert.ToDouble(whiteBalanceInfo_1.lbgain) + 256);
  533. functionSetting1.WarmRGB[0] = (byte)(Convert.ToDouble(whiteBalanceInfo_1.nrgain) + 256);
  534. functionSetting1.WarmRGB[1] = (byte)(Convert.ToDouble(whiteBalanceInfo_1.nggain) + 256);
  535. functionSetting1.WarmRGB[2] = (byte)(Convert.ToDouble(whiteBalanceInfo_1.nbgain) + 256);
  536. };
  537. }
  538. else
  539. {
  540. MessageBox.Show(LResource.FailtoReadLocalDB);
  541. return;
  542. }
  543. }
  544. else
  545. {
  546. MessageBox.Show(LResource.LocalDBIncomplete);
  547. return;
  548. }
  549. }
  550. else
  551. {
  552. MessageBox.Show(LResource.NofoundLocalDB);
  553. return;
  554. }
  555. }
  556. else
  557. {
  558. midList1 = new MidList()
  559. {
  560. keytype = new Dictionary<string, string>(),
  561. projectid = Custom_ProjectID,
  562. host = "LocalPC"
  563. };
  564. #region EDID离线模式;
  565. if (functionSetting1.edid_offline)
  566. {
  567. midList1.keytype.Add("edid_pid", functionSetting1.edid_pid);
  568. midList1.keytype.Add("edid_model_name", functionSetting1.edid_model_name);
  569. }
  570. #endregion
  571. }
  572. OperationPanel operationPanel1 = new OperationPanel(this, LocalDB, ErrorDB, null, functionSetting1, cfg_writecheck, cfg_readcheck, cfg_writedone, Preload.Checked, midList1, OrderText.Text.Trim());
  573. operationPanel1.StartPosition = FormStartPosition.Manual;
  574. if ((this.Right + operationPanel1.Size.Width * formlocationmsg.Count) > Screen.PrimaryScreen.Bounds.Width && LocationMark)
  575. {
  576. LocationMark = false;
  577. LocationNum = formlocationmsg.Count;
  578. }
  579. if (formlocationmsg.Count == 0)
  580. operationPanel1.Location = (Point)new Size(this.Right, this.Top);
  581. else if ((this.Right + operationPanel1.Size.Width * formlocationmsg.Count) > Screen.PrimaryScreen.Bounds.Width)
  582. {
  583. Point point = ((Dictionary<IntPtr, Point>)formlocationmsg[formlocationmsg.Count - 1]).Last().Value;
  584. operationPanel1.Location = (Point)new Size(this.Right + operationPanel1.Size.Width * (formlocationmsg.Count - LocationNum), this.Top + operationPanel1.Size.Height);
  585. }
  586. else
  587. {
  588. Point point = ((Dictionary<IntPtr, Point>)formlocationmsg[formlocationmsg.Count - 1]).Last().Value;
  589. operationPanel1.Location = (Point)new Size(this.Right + operationPanel1.Size.Width * formlocationmsg.Count, this.Top);
  590. }
  591. operationPanel1.DeleteIntptr += new OperationPanel.DisplayUpdateDelegate(DeleteIntptr);
  592. operationPanel1.SNKeyDownEven += new OperationPanel.SNKeyDown(SNKeyDownEven);
  593. operationPanel1.AutoKeyRequire += new OperationPanel.AutoKeyRequireDelegate(AutoKeyRequire);
  594. IntPtr intPtr = operationPanel1.Handle;
  595. Dictionary<IntPtr, Point> part1 = new Dictionary<IntPtr, Point>();
  596. part1.Add(intPtr, (Point)new Size(operationPanel1.Right, operationPanel1.Top));
  597. formlocationmsg.Add(part1);
  598. operationPanel1.Show();
  599. }
  600. catch
  601. {
  602. //
  603. }
  604. }
  605. OrderSubmit.Text = LResource.submitbutton;
  606. #if DEBUG
  607. #else
  608. LockSettingFunction(false);
  609. #endif
  610. if (!LocalWrite)
  611. {
  612. if (!uploadbackground.IsAlive)
  613. if (!Preload.Checked || LocalDB != null)
  614. uploadbackground.Start();
  615. }
  616. }
  617. /// <summary>
  618. /// 加载配置
  619. /// </summary>
  620. public void LoadJsonConfig()
  621. {
  622. StreamReader file = File.OpenText(LocalPath.localpath + "\\Config.json");
  623. using (JsonTextReader reader = new JsonTextReader(file))
  624. {
  625. JObject jObject = (JObject)JToken.ReadFrom(reader);
  626. reader.Close();
  627. var COM = jObject["COM"].Value<string>();
  628. var Baudrate = jObject["Baudrate"].Value<string>();
  629. var WriteChannelConfig = jObject["WriteChannel"].Value<string>();
  630. var ChannelSelect = jObject["ChannelSelect"].Value<string>();
  631. var WriteOSDLanguageConfig = jObject["WriteOSDLanguage"].Value<string>();
  632. var OSDLanguageSelect = jObject["OSDLanguageSelect"].Value<string>();
  633. var WriteSHOPLanguageConfig = jObject["WriteSHOPLanguage"].Value<string>();
  634. var SHOPLanguageSelect = jObject["SHOPLanguageSelect"].Value<string>();
  635. var WriteWhiteBalanceConfig = jObject["WriteWhiteBalance"].Value<string>();
  636. var WhiteBalanceInitConfig = jObject["WhiteBalanceInit"].Value<string>();
  637. var WhiteBalancePath = jObject["WhiteBalancePath"].Value<string>();
  638. var LastOrder = jObject["LastOrder"].Value<string>();
  639. var Preloadmode = jObject["Preload"].Value<string>();
  640. var UsingLocalPID = jObject["UsingLocalPID"].Value<string>();
  641. Custom_ProjectID = jObject["Custom_ProjectID"].Value<string>();
  642. functionSetting1.Wait_after_completion = jObject["Wait_after_completion"].Value<int>();
  643. functionSetting1.EnterFactoryRetry = jObject["EnterFactoryRetry"].Value<int>();
  644. functionSetting1.AllowNoScanning = jObject["AllowNoScanning"].Value<bool>();
  645. functionSetting1.ReportTimeOut = jObject["ReportTimeOut"].Value<int>();
  646. if (jObject["Parity"] == null)
  647. SaveJsonConfig("Parity", functionSetting1.TVParity);
  648. functionSetting1.TVParity = jObject["Parity"] != null ? jObject["Parity"].Value<int>() : 0;
  649. //本地离线抄写时key长度设置获取
  650. functionSetting1.LocalDidSize = jObject["LocalSize"]["DID"].Value<int>();
  651. functionSetting1.LocalMacSize = jObject["LocalSize"]["MAC"].Value<int>();
  652. functionSetting1.LocalHdcpSize = jObject["LocalSize"]["HDCP"].Value<int>();
  653. functionSetting1.LocalWidiSize = jObject["LocalSize"]["WIDI"].Value<int>();
  654. functionSetting1.LocalHdcp22Size = jObject["LocalSize"]["HDCP22"].Value<int>();
  655. functionSetting1.LocalEsnSize = jObject["LocalSize"]["ESN"].Value<int>();
  656. functionSetting1.LocalWidevineSize = jObject["LocalSize"]["WIDEVINE"].Value<int>();
  657. functionSetting1.LocalCiSize = jObject["LocalSize"]["CI"].Value<int>();
  658. functionSetting1.LocalMGKSize = jObject["LocalSize"]["MGK"].Value<int>();
  659. functionSetting1.LocalFairplaySize = jObject["LocalSize"]["Fairplay"] == null ? (CommonMethod.InsertJsonConfig("LocalSize", "Fairplay") ? -1 : 0) : jObject["LocalSize"]["Fairplay"].Value<int>();
  660. functionSetting1.LocalECPSize = jObject["LocalSize"]["ECP"] == null ? (CommonMethod.InsertJsonConfig("LocalSize", "ECP") ? -1 : 0) : jObject["LocalSize"]["ECP"].Value<int>();
  661. functionSetting1.LocalWifiMacSize = jObject["LocalSize"]["WifiMac"] == null ? (CommonMethod.InsertJsonConfig("LocalSize", "WifiMac") ? -1 : 0) : jObject["LocalSize"]["WifiMac"].Value<int>();
  662. functionSetting1.LocalBTMacSize = jObject["LocalSize"]["BTMac"] == null ? (CommonMethod.InsertJsonConfig("LocalSize", "BTMac") ? -1 : 0) : jObject["LocalSize"]["BTMac"].Value<int>();
  663. //本地DB离线抄写时是否不允许重复抄写
  664. functionSetting1.NoDoublewrite = jObject["NodoubleWrite"].Value<bool>();
  665. //条码限制
  666. functionSetting1.BarcodeLimit = jObject["BarcodeLimit"].Value<bool>();
  667. functionSetting1.BarcodeWrite = jObject["BarcodeWrite"] == null ? CommonMethod.AddJsonConfig("BarcodeWrite", false) : jObject["BarcodeWrite"].Value<bool>();
  668. functionSetting1.BarcodeLength = jObject["BarcodeLength"].Value<int>();
  669. functionSetting1.BarcodeKeyword = jObject["BarcodeKeyword"].Value<string>();
  670. //串口延迟
  671. //functionSetting1.SerailDelay = jObject["SerailDelay"].Value<int>(); // 名字不易理解,使用NextCommandWaitTime代替;
  672. //SerialCMD.SerialTimeout = jObject["SerialTimeout"].Value<int>(); // 名字不易理解,目前不再使用;
  673. // G客户防呆措施;
  674. functionSetting1.UsingGFoolProofing = jObject["UsingGFoolProofing"] == null ? false : jObject["UsingGFoolProofing"].Value<bool>();
  675. functionSetting1.GFoolProofingCount = jObject["GFoolProofingCount"] == null ? 2 : jObject["GFoolProofingCount"].Value<int>();
  676. functionSetting1.LeaveFactory = jObject["LeaveFactory"] == null ? false : jObject["LeaveFactory"].Value<bool>();
  677. functionSetting1.SNDoubleTips = jObject["SNDoubleTips"] == null ? false : jObject["SNDoubleTips"].Value<bool>();
  678. #region 是否启用墨西哥抄写
  679. if (CommonMethod.GetLoginAccout().Equals("Mexico", StringComparison.OrdinalIgnoreCase) )
  680. {
  681. // NTF;
  682. if (jObject["Mexican_NTF"] == null)
  683. SaveJsonConfig("Mexican_NTF", functionSetting1.Mexican_NTF);
  684. else
  685. functionSetting1.Mexican_NTF = jObject["Mexican_NTF"].Value<bool>();
  686. GMethod.SetMexicanConfig(functionSetting1.Mexican_NTF);
  687. // IDM;
  688. if (jObject["Mexican_IDM"] == null)
  689. SaveJsonConfig("Mexican_IDM", functionSetting1.Mexican_IDM);
  690. else
  691. functionSetting1.Mexican_IDM = jObject["Mexican_IDM"].Value<bool>();
  692. V2Method.SetMexicanConfig(functionSetting1.Mexican_IDM);
  693. }
  694. #endregion
  695. // 导出日规acas与sn;
  696. if (jObject["ExportSNACASID"] == null)
  697. {
  698. SaveJsonConfig("ExportSNACASID", functionSetting1.ExportSNACASID);
  699. }
  700. else
  701. {
  702. functionSetting1.ExportSNACASID = jObject["ExportSNACASID"].Value<bool>();
  703. }
  704. // 获取ReadTimeout值;
  705. if (jObject["ReadTimeout"] == null)
  706. {
  707. SaveJsonConfig("ReadTimeout", SerialCMD.ReadTimeout);
  708. }
  709. else
  710. {
  711. functionSetting1.ReadTimeout = SerialCMD.ReadTimeout = jObject["ReadTimeout"].Value<int>();
  712. }
  713. // 获取NextCommandWaitTime值;
  714. if (jObject["NextCommandWaitTime"] == null)
  715. {
  716. SaveJsonConfig("NextCommandWaitTime", SerialCMD.NextCommandWaitTime);
  717. }
  718. else
  719. {
  720. functionSetting1.NextCommandWaitTime = SerialCMD.NextCommandWaitTime = jObject["NextCommandWaitTime"].Value<int>();
  721. }
  722. #region EDID离线模式,使用offline账号登录;
  723. if (jObject["edid_offline"] == null)
  724. {
  725. SaveJsonConfig("edid_offline", functionSetting1.edid_offline);
  726. }
  727. else
  728. {
  729. functionSetting1.edid_offline = jObject["edid_offline"].Value<bool>();
  730. }
  731. if (jObject["edid_pid"] == null)
  732. {
  733. SaveJsonConfig("edid_pid", functionSetting1.edid_pid);
  734. }
  735. else
  736. {
  737. functionSetting1.edid_pid = jObject["edid_pid"].Value<string>();
  738. }
  739. if (jObject["edid_model_name"] == null)
  740. {
  741. SaveJsonConfig("edid_model_name", functionSetting1.edid_model_name);
  742. }
  743. else
  744. {
  745. functionSetting1.edid_model_name = jObject["edid_model_name"].Value<string>();
  746. }
  747. #endregion
  748. #region 波兰工厂DHA解决方案
  749. if (jObject["CheckDHAWaitTime"] == null)
  750. {
  751. SaveJsonConfig("CheckDHAWaitTime", functionSetting1.CheckDHAWaitTime);
  752. }
  753. else
  754. {
  755. functionSetting1.CheckDHAWaitTime = jObject["CheckDHAWaitTime"].Value<int>();
  756. }
  757. if (jObject["DHA"] == null)
  758. {
  759. SaveJsonConfig("DHA", functionSetting1.DHA);
  760. }
  761. else
  762. {
  763. functionSetting1.DHA = jObject["DHA"].Value<bool>();
  764. }
  765. #endregion
  766. #region G客户NTF功能;
  767. if ( jObject["NTF"] != null )
  768. {
  769. functionSetting1.NTF = jObject["NTF"].Value<bool>();
  770. if (functionSetting1.NTF == true)
  771. Log.WriteInfoLog("开启NTF功能");
  772. }
  773. else
  774. {
  775. SaveJsonConfig("NTF", false);
  776. }
  777. if (jObject["Line"] != null)
  778. {
  779. functionSetting1.Line = jObject["Line"].Value<string>();
  780. }
  781. else
  782. {
  783. SaveJsonConfig("Line", "");
  784. }
  785. #endregion
  786. #region 小米FireTV功能模块启用;
  787. if (jObject["MITVEnable"] != null)
  788. {
  789. functionSetting1.MITVEnable = jObject["MITVEnable"].Value<bool>();
  790. }
  791. else
  792. {
  793. SaveJsonConfig("MITVEnable", false);
  794. }
  795. // 获取key的url;
  796. if (jObject["MIKeyUrl"] != null)
  797. {
  798. functionSetting1.MIKeyUrl = jObject["MIKeyUrl"].Value<string>();
  799. }
  800. else
  801. {
  802. SaveJsonConfig("MIKeyUrl", functionSetting1.MIKeyUrl);
  803. }
  804. // 上报key的url;
  805. if (jObject["MIKeyReportUrl"] != null)
  806. {
  807. functionSetting1.MIKeyReportUrl = jObject["MIKeyReportUrl"].Value<string>();
  808. }
  809. else
  810. {
  811. SaveJsonConfig("MIKeyReportUrl", functionSetting1.MIKeyReportUrl);
  812. }
  813. #endregion
  814. #region 串口重试机制;
  815. if (jObject["EnableRetry"] != null)
  816. {
  817. functionSetting1.EnableRetry = jObject["EnableRetry"].Value<bool>();
  818. }
  819. else
  820. {
  821. SaveJsonConfig("EnableRetry", false);
  822. }
  823. if (jObject["RetryCount"] != null)
  824. {
  825. functionSetting1.RetryCount = jObject["RetryCount"].Value<int>();
  826. }
  827. else
  828. {
  829. SaveJsonConfig("RetryCount", 3);
  830. }
  831. #endregion
  832. foreach (var ss in jObject["Channel"]) //遍历Channel
  833. {
  834. Dictionary<string, string> ChannelValues = JsonConvert.DeserializeObject<Dictionary<string, string>>(ss.ToString());
  835. foreach (string key in ChannelValues.Keys)
  836. {
  837. ChannelMapList.Add(key, ChannelValues[key]);
  838. ChannelList.Items.Add(key);
  839. }
  840. }
  841. foreach (var ss in jObject["Language"]) //遍历Language
  842. {
  843. Dictionary<string, string> LanguageValues = JsonConvert.DeserializeObject<Dictionary<string, string>>(ss.ToString());
  844. foreach (string key in LanguageValues.Keys)
  845. {
  846. OSDList.Items.Add(key);
  847. SHOPList.Items.Add(key);
  848. LanguageMapList.Add(key, LanguageValues[key]);
  849. }
  850. }
  851. foreach (var ss in jObject["CustomCMD"]) //遍历自定义命令表
  852. {
  853. functionSetting1.CustomCMD = JsonConvert.DeserializeObject<Dictionary<string, string>>(ss.ToString());
  854. }
  855. #region ReadCheck配置读取
  856. cfg_readcheck.PIDReadcheck = jObject["ReadCheck"]["PID"].Value<bool>();
  857. cfg_readcheck.OSDReadcheck = jObject["ReadCheck"]["OSD"].Value<bool>();
  858. cfg_readcheck.SHOPReadcheck = jObject["ReadCheck"]["SHOP"].Value<bool>();
  859. cfg_readcheck.DIDReadcheck = jObject["ReadCheck"]["DID"].Value<bool>();
  860. cfg_readcheck.MacReadcheck = jObject["ReadCheck"]["MAC"].Value<bool>();
  861. cfg_readcheck.HDCPReadcheck = jObject["ReadCheck"]["HDCP"].Value<bool>();
  862. cfg_readcheck.HDCP22Readcheck = jObject["ReadCheck"]["HDCP22"].Value<bool>();
  863. cfg_readcheck.WidevineReadcheck = jObject["ReadCheck"]["WIDEVINE"].Value<bool>();
  864. cfg_readcheck.ESNReadcheck = jObject["ReadCheck"]["ESN"].Value<bool>();
  865. cfg_readcheck.CI_plusReadcheck = jObject["ReadCheck"]["CI"].Value<bool>();
  866. cfg_readcheck.AttestationReadcheck = jObject["ReadCheck"]["Attestation"].Value<bool>();
  867. cfg_readcheck.MGKReadcheck = jObject["ReadCheck"]["MGK"].Value<bool>();
  868. cfg_readcheck.FairplayReadcheck = jObject["ReadCheck"]["Fairplay"] == null ? CommonMethod.InsertJsonConfig("ReadCheck", "Fairplay") : jObject["ReadCheck"]["Fairplay"].Value<bool>();
  869. cfg_readcheck.ECPReadcheck = jObject["ReadCheck"]["ECP"] == null ? CommonMethod.InsertJsonConfig("ReadCheck", "ECP") : jObject["ReadCheck"]["ECP"].Value<bool>();
  870. cfg_readcheck.WifiMacReadcheck = jObject["ReadCheck"]["WifiMac"] == null ? CommonMethod.InsertJsonConfig("ReadCheck", "WifiMac") : jObject["ReadCheck"]["WifiMac"].Value<bool>();
  871. cfg_readcheck.BTMacReadcheck = jObject["ReadCheck"]["BTMac"] == null ? CommonMethod.InsertJsonConfig("ReadCheck", "BTMac") : jObject["ReadCheck"]["BTMac"].Value<bool>();
  872. cfg_readcheck.LEKReadcheck = jObject["ReadCheck"]["LEK"] == null ? CommonMethod.InsertJsonConfig("ReadCheck", "LEK") : jObject["ReadCheck"]["LEK"].Value<bool>();
  873. cfg_readcheck.PEKReadcheck = jObject["ReadCheck"]["PEK"] == null ? CommonMethod.InsertJsonConfig("ReadCheck", "PEK") : jObject["ReadCheck"]["PEK"].Value<bool>();
  874. cfg_readcheck.PlayreadyReadcheck = jObject["ReadCheck"]["Playready"] == null ? CommonMethod.InsertJsonConfig("ReadCheck", "Playready") : jObject["ReadCheck"]["Playready"].Value<bool>();
  875. cfg_readcheck.HashReadcheck = jObject["ReadCheck"]["Hash"] == null ? CommonMethod.InsertJsonConfig("ReadCheck", "Hash") : jObject["ReadCheck"]["Hash"].Value<bool>();
  876. cfg_readcheck.DSNReadcheck = jObject["ReadCheck"]["DSN"] == null ? CommonMethod.InsertJsonConfig("ReadCheck", "DSN") : jObject["ReadCheck"]["DSN"].Value<bool>();
  877. cfg_readcheck.YouTubeReadcheck = jObject["ReadCheck"]["YouTube"] == null ? CommonMethod.InsertJsonConfig("ReadCheck", "YouTube") : jObject["ReadCheck"]["YouTube"].Value<bool>();
  878. cfg_readcheck.EDIDPIDReadcheck = jObject["ReadCheck"]["EDIDPID"] == null ? CommonMethod.InsertJsonConfig("ReadCheck", "EDIDPID") : jObject["ReadCheck"]["EDIDPID"].Value<bool>();
  879. cfg_readcheck.EDIDModeNameReadcheck = jObject["ReadCheck"]["EDIDModeName"] == null ? CommonMethod.InsertJsonConfig("ReadCheck", "EDIDModeName") : jObject["ReadCheck"]["EDIDModeName"].Value<bool>();
  880. cfg_readcheck.ACASKeyReadcheck = jObject["ReadCheck"]["ACASKey"] == null ? CommonMethod.InsertJsonConfig("ReadCheck", "ACASKey") : jObject["ReadCheck"]["ACASKey"].Value<bool>();
  881. cfg_readcheck.FVPReadcheck = jObject["ReadCheck"]["FVP"] == null ? CommonMethod.InsertJsonConfig("ReadCheck", "FVP") : jObject["ReadCheck"]["FVP"].Value<bool>();
  882. cfg_readcheck.DAKReadcheck = jObject["ReadCheck"]["DAK"] == null ? CommonMethod.InsertJsonConfig("ReadCheck", "DAK") : jObject["ReadCheck"]["DAK"].Value<bool>();
  883. cfg_readcheck.DolbyReadcheck = jObject["ReadCheck"]["Dolby"] == null ? CommonMethod.InsertJsonConfig("ReadCheck", "Dolby") : jObject["ReadCheck"]["Dolby"].Value<bool>();
  884. #endregion
  885. #region WriteCheck配置读取
  886. cfg_writecheck.DIDCheckcheck = jObject["WriteCheck"]["DID"].Value<bool>();
  887. cfg_writecheck.MacCheckcheck = jObject["WriteCheck"]["MAC"].Value<bool>();
  888. cfg_writecheck.HDCPCheckcheck = jObject["WriteCheck"]["HDCP"].Value<bool>();
  889. cfg_writecheck.HDCP22Checkcheck = jObject["WriteCheck"]["HDCP22"].Value<bool>();
  890. cfg_writecheck.WidevineCheckcheck = jObject["WriteCheck"]["WIDEVINE"].Value<bool>();
  891. cfg_writecheck.ESNCheckcheck = jObject["WriteCheck"]["ESN"].Value<bool>();
  892. cfg_writecheck.CI_plusCheckcheck = jObject["WriteCheck"]["CI"].Value<bool>();
  893. cfg_writecheck.AttestationCheckcheck = jObject["WriteCheck"]["Attestation"].Value<bool>();
  894. cfg_writecheck.MGKCheckcheck = jObject["WriteCheck"]["MGK"].Value<bool>();
  895. cfg_writecheck.FairplayCheckcheck = jObject["WriteCheck"]["Fairplay"] == null ? CommonMethod.InsertJsonConfig("WriteCheck", "Fairplay") : jObject["WriteCheck"]["Fairplay"].Value<bool>();
  896. cfg_writecheck.ECPCheckcheck = jObject["WriteCheck"]["ECP"] == null ? CommonMethod.InsertJsonConfig("WriteCheck", "ECP") : jObject["WriteCheck"]["ECP"].Value<bool>();
  897. cfg_writecheck.WifiMacCheckcheck = jObject["WriteCheck"]["WifiMac"] == null ? CommonMethod.InsertJsonConfig("WriteCheck", "WifiMac") : jObject["WriteCheck"]["WifiMac"].Value<bool>();
  898. cfg_writecheck.BTMacCheckcheck = jObject["WriteCheck"]["BTMac"] == null ? CommonMethod.InsertJsonConfig("WriteCheck", "BTMac") : jObject["WriteCheck"]["BTMac"].Value<bool>();
  899. cfg_writecheck.LEKCheckcheck = jObject["WriteCheck"]["LEK"] == null ? CommonMethod.InsertJsonConfig("WriteCheck", "LEK") : jObject["WriteCheck"]["LEK"].Value<bool>();
  900. cfg_writecheck.PEKCheckcheck = jObject["WriteCheck"]["PEK"] == null ? CommonMethod.InsertJsonConfig("WriteCheck", "PEK") : jObject["WriteCheck"]["PEK"].Value<bool>();
  901. cfg_writecheck.PlayreadyCheckcheck = jObject["WriteCheck"]["Playready"] == null ? CommonMethod.InsertJsonConfig("WriteCheck", "Playready") : jObject["WriteCheck"]["Playready"].Value<bool>();
  902. cfg_writecheck.HashCheckcheck = jObject["WriteCheck"]["Hash"] == null ? CommonMethod.InsertJsonConfig("WriteCheck", "Hash") : jObject["WriteCheck"]["Hash"].Value<bool>();
  903. cfg_writecheck.DSNCheckcheck = jObject["WriteCheck"]["DSN"] == null ? CommonMethod.InsertJsonConfig("WriteCheck", "DSN") : jObject["WriteCheck"]["DSN"].Value<bool>();
  904. cfg_writecheck.YouTubeCheckcheck = jObject["WriteCheck"]["YouTube"] == null ? CommonMethod.InsertJsonConfig("WriteCheck", "YouTube") : jObject["WriteCheck"]["YouTube"].Value<bool>();
  905. cfg_writecheck.ACASKeyCheckcheck = jObject["WriteCheck"]["ACASKey"] == null ? CommonMethod.InsertJsonConfig("WriteCheck", "ACASKey") : jObject["WriteCheck"]["ACASKey"].Value<bool>();
  906. cfg_writecheck.FVPCheckcheck = jObject["WriteCheck"]["FVP"] == null ? CommonMethod.InsertJsonConfig("WriteCheck", "FVP") : jObject["WriteCheck"]["FVP"].Value<bool>();
  907. cfg_writecheck.DAKCheckcheck = jObject["WriteCheck"]["DAK"] == null ? CommonMethod.InsertJsonConfig("WriteCheck", "DAK") : jObject["WriteCheck"]["DAK"].Value<bool>();
  908. cfg_writecheck.DolbyCheckcheck = jObject["WriteCheck"]["Dolby"] == null ? CommonMethod.InsertJsonConfig("WriteCheck", "Dolby") : jObject["WriteCheck"]["Dolby"].Value<bool>();
  909. #endregion
  910. #region WriteDone配置读取
  911. cfg_writedone.PIDWrite_YesNo = jObject["WriteDone"]["PID"].Value<bool>();
  912. cfg_writedone.PIDWriteDelay = jObject["WriteDone"]["PIDWirteDelay"].Value<int>();
  913. cfg_writedone.ClientTypeCheck_YesNo = jObject["WriteDone"]["ClientType"].Value<bool>();
  914. cfg_writedone.SoftwareVersionCheck_YesNo = jObject["WriteDone"]["SoftwareVersion"].Value<bool>();
  915. cfg_writedone.DIDWrite_YesNo = jObject["WriteDone"]["DID"].Value<bool>();
  916. cfg_writedone.MacWrite_YesNo = jObject["WriteDone"]["MAC"].Value<bool>();
  917. cfg_writedone.HDCPWrite_YesNo = jObject["WriteDone"]["HDCP"].Value<bool>();
  918. cfg_writedone.HDCP22Write_YesNo = jObject["WriteDone"]["HDCP22"].Value<bool>();
  919. cfg_writedone.WidevineWrite_YesNo = jObject["WriteDone"]["WIDEVINE"].Value<bool>();
  920. cfg_writedone.ESNWrite_YesNo = jObject["WriteDone"]["ESN"].Value<bool>();
  921. cfg_writedone.CI_plusWrite_YesNo = jObject["WriteDone"]["CI"].Value<bool>();
  922. cfg_writedone.AttestationWrite_YesNo = jObject["WriteDone"]["Attestation"].Value<bool>();
  923. cfg_writedone.MGKWrite_YesNo = jObject["WriteDone"]["MGK"].Value<bool>();
  924. cfg_writedone.FairplayWrite_YesNo = jObject["WriteDone"]["Fairplay"] == null ? CommonMethod.InsertJsonConfig("WriteDone", "Fairplay") : jObject["WriteDone"]["Fairplay"].Value<bool>();
  925. cfg_writedone.ECPWrite_YesNo = jObject["WriteDone"]["ECP"] == null ? CommonMethod.InsertJsonConfig("WriteDone", "ECP") : jObject["WriteDone"]["ECP"].Value<bool>();
  926. cfg_writedone.WifiMacWrite_YesNo = jObject["WriteDone"]["WifiMac"] == null ? CommonMethod.InsertJsonConfig("WriteDone", "WifiMac") : jObject["WriteDone"]["WifiMac"].Value<bool>();
  927. cfg_writedone.BTMacWrite_YesNo = jObject["WriteDone"]["BTMac"] == null ? CommonMethod.InsertJsonConfig("WriteDone", "BTMac") : jObject["WriteDone"]["BTMac"].Value<bool>();
  928. cfg_writedone.LEKWrite_YesNo = jObject["WriteDone"]["LEK"] == null ? CommonMethod.InsertJsonConfig("WriteDone", "LEK") : jObject["WriteDone"]["LEK"].Value<bool>();
  929. cfg_writedone.PEKWrite_YesNo = jObject["WriteDone"]["PEK"] == null ? CommonMethod.InsertJsonConfig("WriteDone", "PEK") : jObject["WriteDone"]["PEK"].Value<bool>();
  930. cfg_writedone.PlayreadyWrite_YesNo = jObject["WriteDone"]["Playready"] == null ? CommonMethod.InsertJsonConfig("WriteDone", "Playready") : jObject["WriteDone"]["Playready"].Value<bool>();
  931. cfg_writedone.HashWrite_YesNo = jObject["WriteDone"]["Hash"] == null ? CommonMethod.InsertJsonConfig("WriteDone", "Hash") : jObject["WriteDone"]["Hash"].Value<bool>();
  932. cfg_writedone.DSNWrite_YesNo = jObject["WriteDone"]["DSN"] == null ? CommonMethod.InsertJsonConfig("WriteDone", "DSN") : jObject["WriteDone"]["DSN"].Value<bool>();
  933. cfg_writedone.AutoWhiteBalance = jObject["WriteDone"]["AutoWhiteBalance"] == null ? CommonMethod.InsertJsonConfig("WriteDone", "AutoWhiteBalance") : jObject["WriteDone"]["AutoWhiteBalance"].Value<bool>();
  934. cfg_writedone.YouTubeWrite_YesNo = jObject["WriteDone"]["YouTube"] == null ? CommonMethod.InsertJsonConfig("WriteDone", "YouTube") : jObject["WriteDone"]["YouTube"].Value<bool>();
  935. cfg_writedone.EDIDPIDWrite_YesNo = jObject["WriteDone"]["EDIDPID"] == null ? CommonMethod.InsertJsonConfig("WriteDone", "EDIDPID") : jObject["WriteDone"]["EDIDPID"].Value<bool>();
  936. cfg_writedone.EDIDModeNameWrite_YesNo = jObject["WriteDone"]["EDIDModeName"] == null ? CommonMethod.InsertJsonConfig("WriteDone", "EDIDModeName") : jObject["WriteDone"]["EDIDModeName"].Value<bool>();
  937. cfg_writedone.ACASKeyWrite_YesNo = jObject["WriteDone"]["ACASKey"] == null ? CommonMethod.InsertJsonConfig("WriteDone", "ACASKey") : jObject["WriteDone"]["ACASKey"].Value<bool>();
  938. cfg_writedone.FVPWrite_YesNo = jObject["WriteDone"]["FVP"] == null ? CommonMethod.InsertJsonConfig("WriteDone", "FVP") : jObject["WriteDone"]["FVP"].Value<bool>();
  939. cfg_writedone.DAKWrite_YesNo = jObject["WriteDone"]["DAK"] == null ? CommonMethod.InsertJsonConfig("WriteDone", "DAK") : jObject["WriteDone"]["DAK"].Value<bool>();
  940. cfg_writedone.DolbyWrite_YesNo = jObject["WriteDone"]["Dolby"] == null ? CommonMethod.InsertJsonConfig("WriteDone", "Dolby") : jObject["WriteDone"]["Dolby"].Value<bool>();
  941. #endregion
  942. file.Close();
  943. if (Custom_ProjectID != null)
  944. if (Custom_ProjectID.Trim().Length > 0)
  945. PID_Num.Value = Convert.ToDecimal(Custom_ProjectID);
  946. if (TVCOM.Items.Contains(COM))
  947. TVCOM.SelectedItem = COM;
  948. if (TVBaud.Items.Contains(Baudrate))
  949. TVBaud.SelectedItem = Baudrate;
  950. if (ChannelList.Items.Contains(ChannelSelect))
  951. {
  952. ChannelList.SelectedItem = ChannelSelect;
  953. functionSetting1.ChannelCode = SerialInit.HexToByte(ChannelMapList[ChannelSelect]);
  954. }
  955. if (OSDList.Items.Contains(OSDLanguageSelect))
  956. {
  957. OSDList.SelectedItem = OSDLanguageSelect;
  958. functionSetting1.OSDLCode = SerialInit.HexToByte(LanguageMapList[OSDLanguageSelect]);
  959. }
  960. if (SHOPList.Items.Contains(SHOPLanguageSelect))
  961. {
  962. SHOPList.SelectedItem = SHOPLanguageSelect;
  963. functionSetting1.ShopLCode = SerialInit.HexToByte(LanguageMapList[SHOPLanguageSelect]);
  964. }
  965. BarcodeLimit.Checked = functionSetting1.BarcodeLimit;
  966. BarcodeWrite.Checked = functionSetting1.BarcodeWrite;
  967. BarCodeKeyCodeText.Text = functionSetting1.BarcodeKeyword;
  968. BarCodeLengthText.Value = functionSetting1.BarcodeLength;
  969. Preload.Checked = Preloadmode == "True";
  970. WriteChannel.Checked = WriteChannelConfig == "True";
  971. WriteOSD.Checked = WriteOSDLanguageConfig == "True";
  972. WriteSHOP.Checked = WriteSHOPLanguageConfig == "True";
  973. WBInit.Checked = WhiteBalanceInitConfig == "True";
  974. UsinglocalIDCheck.Checked = UsingLocalPID == "True";
  975. OrderText.Text = LastOrder;
  976. if (File.Exists(WhiteBalancePath))
  977. {
  978. if (!LoadWBConfig(WhiteBalancePath))
  979. {
  980. MessageBox.Show(LResource.ReadWBError);
  981. WriteWB.Checked = false;
  982. }
  983. else
  984. {
  985. WBPath.Text = WhiteBalancePath;
  986. WriteWB.Checked = WriteWhiteBalanceConfig == "True";
  987. }
  988. }
  989. else
  990. WriteWB.Checked = false;
  991. }
  992. }
  993. /// <summary>
  994. /// 加载本地白平衡配置
  995. /// </summary>
  996. /// <param name="filepath"></param>
  997. /// <returns></returns>
  998. public bool LoadWBConfig(string filepath)
  999. {
  1000. try
  1001. {
  1002. functionSetting1.NormalRGB = new byte[3];
  1003. functionSetting1.CoolRGB = new byte[3];
  1004. functionSetting1.WarmRGB = new byte[3];
  1005. functionSetting1.NormalRGB[0] = (byte)Convert.ToDouble(Iniconfig.OperateIniFile.ReadIniData("WBA value:", "HDMI white R:", null, filepath));
  1006. functionSetting1.NormalRGB[1] = (byte)Convert.ToDouble(Iniconfig.OperateIniFile.ReadIniData("WBA value:", "HDMI white G:", null, filepath));
  1007. functionSetting1.NormalRGB[2] = (byte)Convert.ToDouble(Iniconfig.OperateIniFile.ReadIniData("WBA value:", "HDMI white B:", null, filepath));
  1008. functionSetting1.CoolRGB[0] = (byte)(Convert.ToDouble(Iniconfig.OperateIniFile.ReadIniData("WBA value:", "Cool white R:", null, filepath)) + 256);
  1009. functionSetting1.CoolRGB[1] = (byte)(Convert.ToDouble(Iniconfig.OperateIniFile.ReadIniData("WBA value:", "Cool white G:", null, filepath)) + 256);
  1010. functionSetting1.CoolRGB[2] = (byte)(Convert.ToDouble(Iniconfig.OperateIniFile.ReadIniData("WBA value:", "Cool white B:", null, filepath)) + 256);
  1011. functionSetting1.WarmRGB[0] = (byte)(Convert.ToDouble(Iniconfig.OperateIniFile.ReadIniData("WBA value:", "Warm white R:", null, filepath)) + 256);
  1012. functionSetting1.WarmRGB[1] = (byte)(Convert.ToDouble(Iniconfig.OperateIniFile.ReadIniData("WBA value:", "Warm white G:", null, filepath)) + 256);
  1013. functionSetting1.WarmRGB[2] = (byte)(Convert.ToDouble(Iniconfig.OperateIniFile.ReadIniData("WBA value:", "Warm white B:", null, filepath)) + 256);
  1014. return true;
  1015. }
  1016. catch (Exception ex)
  1017. {
  1018. MessageBox.Show(ex.Message);
  1019. return false;
  1020. }
  1021. }
  1022. private void ChannelList_SelectedIndexChanged(object sender, EventArgs e)
  1023. {
  1024. string ChannelSelect = ChannelList.SelectedItem.ToString();
  1025. string channelcode = ChannelMapList[ChannelSelect];
  1026. functionSetting1.ChannelCode = SerialInit.HexToByte(channelcode);
  1027. SaveJsonConfig("ChannelSelect", ChannelSelect);
  1028. Log.WriteInfoLog("\r\nSet channel setting to " + ChannelSelect + "\r\nchannel code is " + channelcode);
  1029. }
  1030. private void OSDList_SelectedIndexChanged(object sender, EventArgs e)
  1031. {
  1032. string OSDLanguageSelect = OSDList.SelectedItem.ToString();
  1033. string OSDLcode = LanguageMapList[OSDLanguageSelect];
  1034. functionSetting1.OSDLCode = SerialInit.HexToByte(OSDLcode);
  1035. SaveJsonConfig("OSDLanguageSelect", OSDLanguageSelect);
  1036. Log.WriteInfoLog("\r\nSet channel setting to " + OSDLanguageSelect + "\r\nchannel code is " + OSDLcode);
  1037. }
  1038. private void SHOPList_SelectedIndexChanged(object sender, EventArgs e)
  1039. {
  1040. string SHOPLanguageSelect = SHOPList.SelectedItem.ToString();
  1041. string SHOPLcode = LanguageMapList[SHOPLanguageSelect];
  1042. functionSetting1.ShopLCode = SerialInit.HexToByte(SHOPLcode);
  1043. SaveJsonConfig("SHOPLanguageSelect", SHOPLanguageSelect);
  1044. Log.WriteInfoLog("\r\nSet channel setting to " + SHOPLanguageSelect + "\r\nchannel code is " + SHOPLcode);
  1045. }
  1046. private void skinButton1_Click(object sender, EventArgs e)
  1047. {
  1048. SaveJsonConfig("COM", "COM3");
  1049. string strFileName = null;
  1050. openFileDialog1.Filter = "WBConfig file|*.wba";
  1051. openFileDialog1.FileName = "";
  1052. openFileDialog1.Title = "Please select the WB config file";
  1053. if (openFileDialog1.ShowDialog() == DialogResult.OK)
  1054. {
  1055. strFileName = System.IO.Path.GetFullPath(openFileDialog1.FileName);
  1056. WBPath.Text = strFileName;
  1057. if (LoadWBConfig(strFileName))
  1058. {
  1059. functionSetting1.WBFileName = Path.GetFileName(openFileDialog1.FileName);
  1060. SaveJsonConfig("WhiteBalancePath", strFileName);
  1061. MessageBox.Show(LResource.LoadWBsuccess);
  1062. }
  1063. }
  1064. }
  1065. private void WriteWB_CheckedChanged(object sender, EventArgs e)
  1066. {
  1067. if (WriteWB.Checked == true)
  1068. {
  1069. if (WBPath.Text.Trim().Length > 0)
  1070. {
  1071. LoadWBConfig(WBPath.Text.Trim());
  1072. SaveJsonConfig("WriteWhiteBalance", true);
  1073. }
  1074. else
  1075. {
  1076. MessageBox.Show(LResource.SelectWBfirst);
  1077. WriteWB.Checked = false;
  1078. }
  1079. }
  1080. else
  1081. {
  1082. SaveJsonConfig("WriteWhiteBalance", false);
  1083. }
  1084. }
  1085. public void SaveJsonConfig(string node, object value)
  1086. {
  1087. StreamReader file = File.OpenText(LocalPath.localpath + "\\Config.json");
  1088. using (JsonTextReader reader = new JsonTextReader(file))
  1089. {
  1090. JObject jObject = (JObject)JToken.ReadFrom(reader);
  1091. jObject[node] = value.ToString();
  1092. file.Close();
  1093. using (StreamWriter writer = new StreamWriter(LocalPath.localpath + "\\Config.json"))
  1094. {
  1095. writer.Write(jObject.ToString()); //将JToken.ReadFrom(reader)的数据写入文件,这样的数据有空行。
  1096. }
  1097. }
  1098. }
  1099. private void WBInit_CheckedChanged(object sender, EventArgs e)
  1100. {
  1101. if (WBInit.Checked)
  1102. {
  1103. SaveJsonConfig("WhiteBalanceInit", true);
  1104. }
  1105. else
  1106. SaveJsonConfig("WhiteBalanceInit", false);
  1107. }
  1108. private void WriteChannel_CheckedChanged(object sender, EventArgs e)
  1109. {
  1110. if (WriteChannel.Checked)
  1111. {
  1112. SaveJsonConfig("WriteChannel", true);
  1113. }
  1114. else
  1115. SaveJsonConfig("WriteChannel", false);
  1116. }
  1117. private void WriteOSD_CheckedChanged(object sender, EventArgs e)
  1118. {
  1119. if (WriteOSD.Checked)
  1120. {
  1121. SaveJsonConfig("WriteOSDLanguage", true);
  1122. }
  1123. else
  1124. SaveJsonConfig("WriteOSDLanguage", false);
  1125. }
  1126. private void WriteSHOP_CheckedChanged(object sender, EventArgs e)
  1127. {
  1128. if (WriteSHOP.Checked)
  1129. {
  1130. SaveJsonConfig("WriteSHOPLanguage", true);
  1131. }
  1132. else
  1133. SaveJsonConfig("WriteSHOPLanguage", false);
  1134. }
  1135. private void TVCOM_SelectedIndexChanged(object sender, EventArgs e)
  1136. {
  1137. SaveJsonConfig("COM", TVCOM.SelectedItem.ToString());
  1138. }
  1139. private void TVBaud_SelectedIndexChanged(object sender, EventArgs e)
  1140. {
  1141. SaveJsonConfig("Baudrate", TVBaud.SelectedItem.ToString());
  1142. }
  1143. private void Form1_FormClosed(object sender, FormClosedEventArgs e)
  1144. {
  1145. Environment.Exit(0);
  1146. }
  1147. public void LockSettingFunction(bool locksetting)
  1148. {
  1149. ChannelList.Enabled = locksetting;
  1150. WriteOSD.Enabled = locksetting;
  1151. WriteSHOP.Enabled = locksetting;
  1152. WriteChannel.Enabled = locksetting;
  1153. OSDList.Enabled = locksetting;
  1154. SHOPList.Enabled = locksetting;
  1155. skinButton1.Enabled = locksetting;
  1156. WriteOSD.Enabled = locksetting;
  1157. WBInit.Enabled = locksetting;
  1158. WriteWB.Enabled = locksetting;
  1159. OrderText.Enabled = locksetting;
  1160. Preload.Enabled = locksetting;
  1161. PID_Num.Enabled = locksetting;
  1162. BarcodeLimit.Enabled = locksetting;
  1163. BarCodeLengthText.Enabled = locksetting;
  1164. BarCodeKeyCodeText.Enabled = locksetting;
  1165. }
  1166. private void TVCOM_MouseClick(object sender, MouseEventArgs e)
  1167. {
  1168. TVCOM.Items.Clear();
  1169. TVCOM.Items.AddRange(SerialPort.GetPortNames());
  1170. }
  1171. private void CreateKeyManually_Click(object sender, EventArgs e)
  1172. {
  1173. CreateDBManually CreateDBManually1 = new CreateDBManually(TestMode.serverurl, ErrorDB);
  1174. CreateDBManually1.ShowDialog();
  1175. }
  1176. private void Preload_CheckedChanged(object sender, EventArgs e)
  1177. {
  1178. SaveJsonConfig("Preload", Preload.Checked.ToString());
  1179. }
  1180. private void Form1_Move(object sender, EventArgs e)
  1181. {
  1182. if (this.MoveEvent != null)
  1183. {
  1184. Point XY = this.Location;
  1185. XY.X = this.Right;
  1186. XY.Y = this.Top;
  1187. this.MoveEvent(XY, formlocationmsg, LocationNum);
  1188. }
  1189. }
  1190. private void DeleteIntptr(IntPtr intPtr)
  1191. {
  1192. foreach (Dictionary<IntPtr, Point> pairs in formlocationmsg)
  1193. {
  1194. if (pairs.ContainsKey(intPtr))
  1195. {
  1196. formlocationmsg.Remove(pairs);
  1197. if (this.MoveEvent != null)
  1198. {
  1199. Point XY = this.Location;
  1200. XY.X = this.Right;
  1201. XY.Y = this.Top;
  1202. this.MoveEvent(XY, formlocationmsg, LocationNum);
  1203. }
  1204. break;
  1205. }
  1206. }
  1207. }
  1208. private void AutoKeyRequire(IntPtr intPtr, string key, string keytype)
  1209. {
  1210. Task.Run(() =>
  1211. {
  1212. var a = ((Dictionary<IntPtr, Point>)formlocationmsg[0]).First();
  1213. if (a.Key == intPtr)
  1214. {
  1215. ;//start autokey require
  1216. if (CommonMethod.AutoGetKeyStatus(midList1.host, key, keytype, ErrorDB))
  1217. {
  1218. CommonMethod.AutoGetKey(midList1.host, OrderText.Text.Trim(), key, keytype, ErrorDB);
  1219. }
  1220. }
  1221. });
  1222. }
  1223. private void SNKeyDownEven(IntPtr intPtr)
  1224. {
  1225. this.KeyDownEvent(formlocationmsg, intPtr);
  1226. }
  1227. private void timer1_Tick(object sender, EventArgs e)
  1228. {
  1229. string count = SQLiteHelper.GetProductionNum(ErrorDB, OrderText.Text.Trim());
  1230. UpdateCountLabel(ProductionNum_Text, count);
  1231. }
  1232. /// <summary>
  1233. /// 刷新订单数量
  1234. /// </summary>
  1235. /// <param name="label"></param>
  1236. /// <param name="str"></param>
  1237. public void UpdateCountLabel(Label label, string str)
  1238. {
  1239. if (label.InvokeRequired)
  1240. {
  1241. BeginInvoke(new Action<string>(x => { label.Text = x.ToString(); }), str);
  1242. }
  1243. else
  1244. {
  1245. label.Text = str;
  1246. }
  1247. }
  1248. /// <summary>
  1249. /// 后台上报
  1250. /// </summary>
  1251. public void UploadBackGround()
  1252. {
  1253. while (true)
  1254. {
  1255. if (CommonMethod.HTTPChecker(StructList.CheckServerConnectionUrl))
  1256. {
  1257. try
  1258. {
  1259. string url;
  1260. string content;
  1261. string id;
  1262. if (SQLiteHelper.GetDelayReportData(ErrorDB, out url, out content, out id))
  1263. {
  1264. if (content.Contains("@"))
  1265. {
  1266. string[] data = content.Split('@');
  1267. if (V2Method.ReportOfflineData(url, data[1], data[0], LocalDB, ErrorDB, true, id))
  1268. {
  1269. SQLiteHelper.UpdateReportData(ErrorDB, "CopyDelayReport", "ID", id);
  1270. }
  1271. }
  1272. else if (V2Method.ReportOnlineData(url, OrderText.Text.Trim(), content, ErrorDB, true, id, functionSetting1.ReportTimeOut))
  1273. {
  1274. SQLiteHelper.UpdateReportData(ErrorDB, "CopyDelayReport", "ID", id);
  1275. }
  1276. }
  1277. }
  1278. catch (Exception ex)
  1279. {
  1280. Log.WriteErrorLog(ex.Message);
  1281. }
  1282. try
  1283. {
  1284. string url;
  1285. string content;
  1286. string id;
  1287. if (SQLiteHelper.GetErrorReportData(ErrorDB, out url, out content, out id))
  1288. {
  1289. bool mark = false;
  1290. if ( url.EndsWith("smes/RecordKey") )
  1291. {
  1292. GMethod.ReportDataBurningResultToMES(url, content, out mark);
  1293. }
  1294. else
  1295. {
  1296. CommonMethod.ReportErrormsg2(url, content, out mark);
  1297. }
  1298. if (mark)
  1299. {
  1300. SQLiteHelper.UpdateReportData(ErrorDB, "ErrorReport", "ID", id);
  1301. }
  1302. }
  1303. }
  1304. catch (Exception ex)
  1305. {
  1306. Log.WriteErrorLog(ex.Message);
  1307. }
  1308. Thread.Sleep(5000);
  1309. }
  1310. else
  1311. Thread.Sleep(20000);
  1312. }
  1313. }
  1314. private void PID_Num_ValueChanged(object sender, EventArgs e)
  1315. {
  1316. Custom_ProjectID = PID_Num.Value.ToString();
  1317. SaveJsonConfig("Custom_ProjectID", Custom_ProjectID);
  1318. }
  1319. private void BarCodeLengthText_ValueChanged(object sender, EventArgs e)
  1320. {
  1321. functionSetting1.BarcodeLength = Convert.ToInt32(BarCodeLengthText.Value);
  1322. SaveJsonConfig("BarcodeLength", functionSetting1.BarcodeLength);
  1323. }
  1324. private void BarcodeLimit_CheckedChanged(object sender, EventArgs e)
  1325. {
  1326. functionSetting1.BarcodeLimit = BarcodeLimit.Checked;
  1327. SaveJsonConfig("BarcodeLimit", BarcodeLimit.Checked);
  1328. }
  1329. private void BarCodeKeyCodeText_TextChanged(object sender, EventArgs e)
  1330. {
  1331. functionSetting1.BarcodeKeyword = BarCodeKeyCodeText.Text;
  1332. SaveJsonConfig("BarcodeKeyword", BarCodeKeyCodeText.Text);
  1333. }
  1334. private void UsinglocalIDCheck_CheckedChanged(object sender, EventArgs e)
  1335. {
  1336. SaveJsonConfig("UsingLocalPID", UsinglocalIDCheck.Checked);
  1337. }
  1338. private void BarcodeWrite_CheckedChanged(object sender, EventArgs e)
  1339. {
  1340. functionSetting1.BarcodeWrite = BarcodeWrite.Checked;
  1341. SaveJsonConfig("BarcodeWrite", BarcodeWrite.Checked);
  1342. }
  1343. }
  1344. }