Main.cs 84 KB

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