Main.cs 72 KB

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