Main.cs 80 KB

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