Main.cs 71 KB

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