Main.cs 80 KB

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