Main.cs 83 KB

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