Main.cs 83 KB

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