SettingDialog.cs 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Data.SQLite;
  6. using System.Drawing;
  7. using System.IO.Ports;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. using PaintDotNet.Base.CommTool;
  13. namespace PaintDotNet.GeneralAnalysis.Countometer
  14. {
  15. public class SettingDialog : PdnBaseForm
  16. {
  17. #region
  18. /// <summary>
  19. /// Required designer variable.
  20. /// </summary>
  21. private System.ComponentModel.IContainer components = null;
  22. /// <summary>
  23. /// Clean up any resources being used.
  24. /// </summary>
  25. /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
  26. protected override void Dispose(bool disposing)
  27. {
  28. if (disposing && (components != null))
  29. {
  30. components.Dispose();
  31. }
  32. base.Dispose(disposing);
  33. }
  34. #region Windows Form Designer generated code
  35. private void InitializeLanguageText()
  36. {
  37. this.label17.Text = PdnResources.GetString("Menu.Generalanalysis.Integrator.ensure.text") + PdnResources.GetString("Menu.range.text") + ":";
  38. this.lblRange.Text = "2000*2000" + PdnResources.GetString("Menu.Micron.text");
  39. this.Text = PdnResources.GetString("Menu.paramssettings.text");
  40. this.label9.Text = PdnResources.GetString("Menu.Generalanalysis.Integrator.Horizontal.text") + ":";
  41. this.chkPoint.Text = PdnResources.GetString("Menu.keepthehorizoalproportion.text");
  42. this.groupBox5.Text = PdnResources.GetString("Menu.Generalanalysis.Integrator.Traveldistance.text");
  43. this.label13.Text = PdnResources.GetString("Menu.Micron.text");
  44. this.label14.Text = PdnResources.GetString("Menu.Micron.text");
  45. this.label15.Text = PdnResources.GetString("Menu.Generalanalysis.Integrator.Ydirection.text") + ":";
  46. this.label16.Text = PdnResources.GetString("Menu.Generalanalysis.Integrator.Xdirection.text") + ":";
  47. this.chkRange.Text = PdnResources.GetString("Menu.keepthehorizoalproportion.text");
  48. this.groupBox3.Text = PdnResources.GetString("Menu.Generalanalysis.Integrator.Deviceparamssetting.text");
  49. this.label18.Text = PdnResources.GetString("Menu.step-size.text") + ":";
  50. this.label8.Text = PdnResources.GetString("Menu.Generalanalysis.Integrator.Databit.text") + ":";
  51. this.label7.Text = PdnResources.GetString("Menu.Baudrate.text") + ":";
  52. this.label6.Text = PdnResources.GetString("Menu.Deviceport.text") + ":";
  53. this.groupBox4.Text = PdnResources.GetString("Menu.Generalanalysis.Integrator.Measurementpoints.text");
  54. this.label12.Text = PdnResources.GetString("Menu.Generalanalysis.Integrator.point.text");
  55. this.label11.Text = PdnResources.GetString("Menu.Generalanalysis.Integrator.point.text");
  56. this.label10.Text = PdnResources.GetString("Menu.Generalanalysis.Integrator.Vertical.text") + ":";
  57. this.groupBox1.Text = PdnResources.GetString("Menu.operation.text");
  58. this.btnClose.Text = PdnResources.GetString("Menu.File.Close.Text");
  59. this.btnSave.Text = PdnResources.GetString("Menu.File.Save.Text");
  60. this.groupBox2.Text = PdnResources.GetString("Menu.Generalanalysis.Integrator.imitatelensparams.text");
  61. this.label4.Text = PdnResources.GetString("Menu.Gridcolor.text") + ":";
  62. this.label5.Text = PdnResources.GetString("Menu.Generalanalysis.Integrator.Lensbackgroundcolor.text") + ":";
  63. this.label3.Text = PdnResources.GetString("Menu.Generalanalysis.Integrator.Emptypieceofcolor.text") + ":";
  64. this.label2.Text = PdnResources.GetString("Menu.Generalanalysis.Integrator.Lenscolor.text") + ":";
  65. this.label1.Text = PdnResources.GetString("Menu.Generalanalysis.Integrator.Backgroundcolor.text") + ":";
  66. }
  67. /// <summary>
  68. /// Required method for Designer support - do not modify
  69. /// the contents of this method with the code editor.
  70. /// </summary>
  71. private void InitializeComponent()
  72. {
  73. this.groupBox1 = new System.Windows.Forms.GroupBox();
  74. this.btnClose = new System.Windows.Forms.Button();
  75. this.btnSave = new System.Windows.Forms.Button();
  76. this.groupBox2 = new System.Windows.Forms.GroupBox();
  77. this.gridGridsColor = new System.Windows.Forms.Panel();
  78. this.gridLensBgColor = new System.Windows.Forms.Panel();
  79. this.label4 = new System.Windows.Forms.Label();
  80. this.label5 = new System.Windows.Forms.Label();
  81. this.gridBlocksColor = new System.Windows.Forms.Panel();
  82. this.gridLensColor = new System.Windows.Forms.Panel();
  83. this.gridBgColor = new System.Windows.Forms.Panel();
  84. this.label3 = new System.Windows.Forms.Label();
  85. this.label2 = new System.Windows.Forms.Label();
  86. this.label1 = new System.Windows.Forms.Label();
  87. this.groupBox3 = new System.Windows.Forms.GroupBox();
  88. this.txtStep = new System.Windows.Forms.TextBox();
  89. this.label18 = new System.Windows.Forms.Label();
  90. this.txtBits = new System.Windows.Forms.TextBox();
  91. this.label8 = new System.Windows.Forms.Label();
  92. this.txtBaseBps = new System.Windows.Forms.TextBox();
  93. this.label7 = new System.Windows.Forms.Label();
  94. this.cmbPort = new System.Windows.Forms.ComboBox();
  95. this.label6 = new System.Windows.Forms.Label();
  96. this.groupBox4 = new System.Windows.Forms.GroupBox();
  97. this.label12 = new System.Windows.Forms.Label();
  98. this.nudPointY = new System.Windows.Forms.NumericUpDown();
  99. this.label11 = new System.Windows.Forms.Label();
  100. this.nudPointX = new System.Windows.Forms.NumericUpDown();
  101. this.label10 = new System.Windows.Forms.Label();
  102. this.label9 = new System.Windows.Forms.Label();
  103. this.chkPoint = new System.Windows.Forms.CheckBox();
  104. this.groupBox5 = new System.Windows.Forms.GroupBox();
  105. this.label13 = new System.Windows.Forms.Label();
  106. this.nudRangeY = new System.Windows.Forms.NumericUpDown();
  107. this.label14 = new System.Windows.Forms.Label();
  108. this.nudRangeX = new System.Windows.Forms.NumericUpDown();
  109. this.label15 = new System.Windows.Forms.Label();
  110. this.label16 = new System.Windows.Forms.Label();
  111. this.chkRange = new System.Windows.Forms.CheckBox();
  112. this.label17 = new System.Windows.Forms.Label();
  113. this.lblRange = new System.Windows.Forms.Label();
  114. this.groupBox1.SuspendLayout();
  115. this.groupBox2.SuspendLayout();
  116. this.groupBox3.SuspendLayout();
  117. this.groupBox4.SuspendLayout();
  118. ((System.ComponentModel.ISupportInitialize)(this.nudPointY)).BeginInit();
  119. ((System.ComponentModel.ISupportInitialize)(this.nudPointX)).BeginInit();
  120. this.groupBox5.SuspendLayout();
  121. ((System.ComponentModel.ISupportInitialize)(this.nudRangeY)).BeginInit();
  122. ((System.ComponentModel.ISupportInitialize)(this.nudRangeX)).BeginInit();
  123. this.SuspendLayout();
  124. //
  125. // groupBox1
  126. //
  127. this.groupBox1.Controls.Add(this.btnClose);
  128. this.groupBox1.Controls.Add(this.btnSave);
  129. this.groupBox1.Location = new System.Drawing.Point(12, 12);
  130. this.groupBox1.Name = "groupBox1";
  131. this.groupBox1.Size = new System.Drawing.Size(669, 71);
  132. this.groupBox1.TabIndex = 1;
  133. this.groupBox1.TabStop = false;
  134. this.groupBox1.Text = "操作";
  135. //
  136. // btnClose
  137. //
  138. this.btnClose.Location = new System.Drawing.Point(477, 24);
  139. this.btnClose.Name = "btnClose";
  140. this.btnClose.Size = new System.Drawing.Size(84, 31);
  141. this.btnClose.TabIndex = 1;
  142. this.btnClose.Text = "关闭";
  143. this.btnClose.UseVisualStyleBackColor = true;
  144. this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
  145. //
  146. // btnSave
  147. //
  148. this.btnSave.Location = new System.Drawing.Point(567, 24);
  149. this.btnSave.Name = "btnSave";
  150. this.btnSave.Size = new System.Drawing.Size(84, 31);
  151. this.btnSave.TabIndex = 0;
  152. this.btnSave.Text = "保存";
  153. this.btnSave.UseVisualStyleBackColor = true;
  154. this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
  155. //
  156. // groupBox2
  157. //
  158. this.groupBox2.Controls.Add(this.gridGridsColor);
  159. this.groupBox2.Controls.Add(this.gridLensBgColor);
  160. this.groupBox2.Controls.Add(this.label4);
  161. this.groupBox2.Controls.Add(this.label5);
  162. this.groupBox2.Controls.Add(this.gridBlocksColor);
  163. this.groupBox2.Controls.Add(this.gridLensColor);
  164. this.groupBox2.Controls.Add(this.gridBgColor);
  165. this.groupBox2.Controls.Add(this.label3);
  166. this.groupBox2.Controls.Add(this.label2);
  167. this.groupBox2.Controls.Add(this.label1);
  168. this.groupBox2.Location = new System.Drawing.Point(12, 89);
  169. this.groupBox2.Name = "groupBox2";
  170. this.groupBox2.Size = new System.Drawing.Size(669, 161);
  171. this.groupBox2.TabIndex = 2;
  172. this.groupBox2.TabStop = false;
  173. this.groupBox2.Text = "模拟镜头参数";
  174. //
  175. // gridGridsColor
  176. //
  177. this.gridGridsColor.BackColor = System.Drawing.Color.Black;
  178. this.gridGridsColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  179. this.gridGridsColor.Location = new System.Drawing.Point(371, 77);
  180. this.gridGridsColor.Name = "gridGridsColor";
  181. this.gridGridsColor.Size = new System.Drawing.Size(97, 26);
  182. this.gridGridsColor.TabIndex = 19;
  183. this.gridGridsColor.BackColorChanged += new System.EventHandler(this.gridGridsColor_BackColorChanged);
  184. this.gridGridsColor.Click += new System.EventHandler(this.gridColor_Click);
  185. //
  186. // gridLensBgColor
  187. //
  188. this.gridLensBgColor.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
  189. this.gridLensBgColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  190. this.gridLensBgColor.Location = new System.Drawing.Point(370, 33);
  191. this.gridLensBgColor.Name = "gridLensBgColor";
  192. this.gridLensBgColor.Size = new System.Drawing.Size(97, 26);
  193. this.gridLensBgColor.TabIndex = 18;
  194. this.gridLensBgColor.BackColorChanged += new System.EventHandler(this.gridLensBgColor_BackColorChanged);
  195. this.gridLensBgColor.Click += new System.EventHandler(this.gridColor_Click);
  196. //
  197. // label4
  198. //
  199. this.label4.AutoSize = true;
  200. this.label4.Location = new System.Drawing.Point(282, 77);
  201. this.label4.Name = "label4";
  202. this.label4.Size = new System.Drawing.Size(65, 12);
  203. this.label4.TabIndex = 17;
  204. this.label4.Text = "网格颜色:";
  205. //
  206. // label5
  207. //
  208. this.label5.AutoSize = true;
  209. this.label5.Location = new System.Drawing.Point(267, 40);
  210. this.label5.Name = "label5";
  211. this.label5.Size = new System.Drawing.Size(77, 12);
  212. this.label5.TabIndex = 16;
  213. this.label5.Text = "镜头背景色:";
  214. //
  215. // gridBlocksColor
  216. //
  217. this.gridBlocksColor.BackColor = System.Drawing.Color.Transparent;
  218. this.gridBlocksColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  219. this.gridBlocksColor.Location = new System.Drawing.Point(105, 117);
  220. this.gridBlocksColor.Name = "gridBlocksColor";
  221. this.gridBlocksColor.Size = new System.Drawing.Size(97, 26);
  222. this.gridBlocksColor.TabIndex = 15;
  223. this.gridBlocksColor.BackColorChanged += new System.EventHandler(this.gridBlocksColor_BackColorChanged);
  224. this.gridBlocksColor.Click += new System.EventHandler(this.gridColor_Click);
  225. //
  226. // gridLensColor
  227. //
  228. this.gridLensColor.BackColor = System.Drawing.Color.White;
  229. this.gridLensColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  230. this.gridLensColor.Location = new System.Drawing.Point(105, 77);
  231. this.gridLensColor.Name = "gridLensColor";
  232. this.gridLensColor.Size = new System.Drawing.Size(97, 26);
  233. this.gridLensColor.TabIndex = 14;
  234. this.gridLensColor.BackColorChanged += new System.EventHandler(this.gridLensColor_BackColorChanged);
  235. this.gridLensColor.Click += new System.EventHandler(this.gridColor_Click);
  236. //
  237. // gridBgColor
  238. //
  239. this.gridBgColor.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(192)))));
  240. this.gridBgColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  241. this.gridBgColor.Location = new System.Drawing.Point(105, 37);
  242. this.gridBgColor.Name = "gridBgColor";
  243. this.gridBgColor.Size = new System.Drawing.Size(97, 26);
  244. this.gridBgColor.TabIndex = 13;
  245. this.gridBgColor.BackColorChanged += new System.EventHandler(this.gridBgColor_BackColorChanged);
  246. this.gridBgColor.Click += new System.EventHandler(this.gridColor_Click);
  247. //
  248. // label3
  249. //
  250. this.label3.AutoSize = true;
  251. this.label3.Location = new System.Drawing.Point(29, 122);
  252. this.label3.Name = "label3";
  253. this.label3.Size = new System.Drawing.Size(53, 12);
  254. this.label3.TabIndex = 2;
  255. this.label3.Text = "空块色:";
  256. //
  257. // label2
  258. //
  259. this.label2.AutoSize = true;
  260. this.label2.Location = new System.Drawing.Point(29, 77);
  261. this.label2.Name = "label2";
  262. this.label2.Size = new System.Drawing.Size(53, 12);
  263. this.label2.TabIndex = 1;
  264. this.label2.Text = "镜头色:";
  265. //
  266. // label1
  267. //
  268. this.label1.AutoSize = true;
  269. this.label1.Location = new System.Drawing.Point(29, 43);
  270. this.label1.Name = "label1";
  271. this.label1.Size = new System.Drawing.Size(53, 12);
  272. this.label1.TabIndex = 0;
  273. this.label1.Text = "背景色:";
  274. //
  275. // groupBox3
  276. //
  277. this.groupBox3.Controls.Add(this.txtStep);
  278. this.groupBox3.Controls.Add(this.label18);
  279. this.groupBox3.Controls.Add(this.txtBits);
  280. this.groupBox3.Controls.Add(this.label8);
  281. this.groupBox3.Controls.Add(this.txtBaseBps);
  282. this.groupBox3.Controls.Add(this.label7);
  283. this.groupBox3.Controls.Add(this.cmbPort);
  284. this.groupBox3.Controls.Add(this.label6);
  285. this.groupBox3.Location = new System.Drawing.Point(12, 256);
  286. this.groupBox3.Name = "groupBox3";
  287. this.groupBox3.Size = new System.Drawing.Size(669, 126);
  288. this.groupBox3.TabIndex = 3;
  289. this.groupBox3.TabStop = false;
  290. this.groupBox3.Text = "设备参数设置";
  291. //
  292. // txtStep
  293. //
  294. this.txtStep.Location = new System.Drawing.Point(104, 84);
  295. this.txtStep.Name = "txtStep";
  296. this.txtStep.Size = new System.Drawing.Size(100, 21);
  297. this.txtStep.TabIndex = 7;
  298. this.txtStep.Text = "0.381";
  299. //
  300. // label18
  301. //
  302. this.label18.AutoSize = true;
  303. this.label18.Location = new System.Drawing.Point(38, 87);
  304. this.label18.Name = "label18";
  305. this.label18.Size = new System.Drawing.Size(41, 12);
  306. this.label18.TabIndex = 6;
  307. this.label18.Text = "步长:";
  308. //
  309. // txtBits
  310. //
  311. this.txtBits.Location = new System.Drawing.Point(525, 36);
  312. this.txtBits.Name = "txtBits";
  313. this.txtBits.Size = new System.Drawing.Size(100, 21);
  314. this.txtBits.TabIndex = 5;
  315. //
  316. // label8
  317. //
  318. this.label8.AutoSize = true;
  319. this.label8.Location = new System.Drawing.Point(452, 41);
  320. this.label8.Name = "label8";
  321. this.label8.Size = new System.Drawing.Size(53, 12);
  322. this.label8.TabIndex = 4;
  323. this.label8.Text = "数据位:";
  324. //
  325. // txtBaseBps
  326. //
  327. this.txtBaseBps.Location = new System.Drawing.Point(308, 36);
  328. this.txtBaseBps.Name = "txtBaseBps";
  329. this.txtBaseBps.Size = new System.Drawing.Size(100, 21);
  330. this.txtBaseBps.TabIndex = 3;
  331. this.txtBaseBps.Text = "9600";
  332. //
  333. // label7
  334. //
  335. this.label7.AutoSize = true;
  336. this.label7.Location = new System.Drawing.Point(235, 41);
  337. this.label7.Name = "label7";
  338. this.label7.Size = new System.Drawing.Size(53, 12);
  339. this.label7.TabIndex = 2;
  340. this.label7.Text = "波特率:";
  341. //
  342. // cmbPort
  343. //
  344. this.cmbPort.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  345. this.cmbPort.FormattingEnabled = true;
  346. this.cmbPort.Location = new System.Drawing.Point(106, 38);
  347. this.cmbPort.Name = "cmbPort";
  348. this.cmbPort.Size = new System.Drawing.Size(98, 20);
  349. this.cmbPort.TabIndex = 1;
  350. //
  351. // label6
  352. //
  353. this.label6.AutoSize = true;
  354. this.label6.Location = new System.Drawing.Point(17, 41);
  355. this.label6.Name = "label6";
  356. this.label6.Size = new System.Drawing.Size(65, 12);
  357. this.label6.TabIndex = 0;
  358. this.label6.Text = "设备端口:";
  359. //
  360. // groupBox4
  361. //
  362. this.groupBox4.Controls.Add(this.label12);
  363. this.groupBox4.Controls.Add(this.nudPointY);
  364. this.groupBox4.Controls.Add(this.label11);
  365. this.groupBox4.Controls.Add(this.nudPointX);
  366. this.groupBox4.Controls.Add(this.label10);
  367. this.groupBox4.Controls.Add(this.label9);
  368. this.groupBox4.Controls.Add(this.chkPoint);
  369. this.groupBox4.Location = new System.Drawing.Point(12, 388);
  370. this.groupBox4.Name = "groupBox4";
  371. this.groupBox4.Size = new System.Drawing.Size(315, 214);
  372. this.groupBox4.TabIndex = 4;
  373. this.groupBox4.TabStop = false;
  374. this.groupBox4.Text = "测定点数";
  375. //
  376. // label12
  377. //
  378. this.label12.AutoSize = true;
  379. this.label12.Location = new System.Drawing.Point(265, 129);
  380. this.label12.Name = "label12";
  381. this.label12.Size = new System.Drawing.Size(29, 12);
  382. this.label12.TabIndex = 3;
  383. this.label12.Text = "微米";
  384. //
  385. // nudPointY
  386. //
  387. this.nudPointY.Location = new System.Drawing.Point(100, 123);
  388. this.nudPointY.Maximum = new decimal(new int[] {
  389. 20,
  390. 0,
  391. 0,
  392. 0});
  393. this.nudPointY.Minimum = new decimal(new int[] {
  394. 1,
  395. 0,
  396. 0,
  397. 0});
  398. this.nudPointY.Name = "nudPointY";
  399. this.nudPointY.Size = new System.Drawing.Size(160, 21);
  400. this.nudPointY.TabIndex = 4;
  401. this.nudPointY.Value = new decimal(new int[] {
  402. 10,
  403. 0,
  404. 0,
  405. 0});
  406. this.nudPointY.ValueChanged += new System.EventHandler(this.nudPointY_ValueChanged);
  407. //
  408. // label11
  409. //
  410. this.label11.AutoSize = true;
  411. this.label11.Location = new System.Drawing.Point(265, 88);
  412. this.label11.Name = "label11";
  413. this.label11.Size = new System.Drawing.Size(29, 12);
  414. this.label11.TabIndex = 1;
  415. this.label11.Text = "微米";
  416. //
  417. // nudPointX
  418. //
  419. this.nudPointX.Location = new System.Drawing.Point(100, 82);
  420. this.nudPointX.Maximum = new decimal(new int[] {
  421. 20,
  422. 0,
  423. 0,
  424. 0});
  425. this.nudPointX.Minimum = new decimal(new int[] {
  426. 1,
  427. 0,
  428. 0,
  429. 0});
  430. this.nudPointX.Name = "nudPointX";
  431. this.nudPointX.Size = new System.Drawing.Size(160, 21);
  432. this.nudPointX.TabIndex = 1;
  433. this.nudPointX.Value = new decimal(new int[] {
  434. 10,
  435. 0,
  436. 0,
  437. 0});
  438. this.nudPointX.ValueChanged += new System.EventHandler(this.nudPointX_ValueChanged);
  439. //
  440. // label10
  441. //
  442. this.label10.AutoSize = true;
  443. this.label10.Location = new System.Drawing.Point(29, 128);
  444. this.label10.Name = "label10";
  445. this.label10.Size = new System.Drawing.Size(41, 12);
  446. this.label10.TabIndex = 2;
  447. this.label10.Text = "纵向:";
  448. //
  449. // label9
  450. //
  451. this.label9.AutoSize = true;
  452. this.label9.Location = new System.Drawing.Point(29, 86);
  453. this.label9.Name = "label9";
  454. this.label9.Size = new System.Drawing.Size(41, 12);
  455. this.label9.TabIndex = 1;
  456. this.label9.Text = "横向:";
  457. //
  458. // chkPoint
  459. //
  460. this.chkPoint.AutoSize = true;
  461. this.chkPoint.Location = new System.Drawing.Point(32, 36);
  462. this.chkPoint.Name = "chkPoint";
  463. this.chkPoint.Size = new System.Drawing.Size(84, 16);
  464. this.chkPoint.TabIndex = 1;
  465. this.chkPoint.Text = "保持纵横比";
  466. this.chkPoint.UseVisualStyleBackColor = true;
  467. //
  468. // groupBox5
  469. //
  470. this.groupBox5.Controls.Add(this.label13);
  471. this.groupBox5.Controls.Add(this.nudRangeY);
  472. this.groupBox5.Controls.Add(this.label14);
  473. this.groupBox5.Controls.Add(this.nudRangeX);
  474. this.groupBox5.Controls.Add(this.label15);
  475. this.groupBox5.Controls.Add(this.label16);
  476. this.groupBox5.Controls.Add(this.chkRange);
  477. this.groupBox5.Location = new System.Drawing.Point(344, 388);
  478. this.groupBox5.Name = "groupBox5";
  479. this.groupBox5.Size = new System.Drawing.Size(337, 214);
  480. this.groupBox5.TabIndex = 5;
  481. this.groupBox5.TabStop = false;
  482. this.groupBox5.Text = "走行距离";
  483. //
  484. // label13
  485. //
  486. this.label13.AutoSize = true;
  487. this.label13.Location = new System.Drawing.Point(282, 125);
  488. this.label13.Name = "label13";
  489. this.label13.Size = new System.Drawing.Size(29, 12);
  490. this.label13.TabIndex = 9;
  491. this.label13.Text = "微米";
  492. //
  493. // nudRangeY
  494. //
  495. this.nudRangeY.Location = new System.Drawing.Point(117, 119);
  496. this.nudRangeY.Maximum = new decimal(new int[] {
  497. 99999,
  498. 0,
  499. 0,
  500. 0});
  501. this.nudRangeY.Minimum = new decimal(new int[] {
  502. 1,
  503. 0,
  504. 0,
  505. 0});
  506. this.nudRangeY.Name = "nudRangeY";
  507. this.nudRangeY.Size = new System.Drawing.Size(160, 21);
  508. this.nudRangeY.TabIndex = 10;
  509. this.nudRangeY.Value = new decimal(new int[] {
  510. 100,
  511. 0,
  512. 0,
  513. 0});
  514. this.nudRangeY.ValueChanged += new System.EventHandler(this.nudRangeY_ValueChanged);
  515. //
  516. // label14
  517. //
  518. this.label14.AutoSize = true;
  519. this.label14.Location = new System.Drawing.Point(282, 84);
  520. this.label14.Name = "label14";
  521. this.label14.Size = new System.Drawing.Size(29, 12);
  522. this.label14.TabIndex = 5;
  523. this.label14.Text = "微米";
  524. //
  525. // nudRangeX
  526. //
  527. this.nudRangeX.Location = new System.Drawing.Point(117, 78);
  528. this.nudRangeX.Maximum = new decimal(new int[] {
  529. 99999,
  530. 0,
  531. 0,
  532. 0});
  533. this.nudRangeX.Minimum = new decimal(new int[] {
  534. 1,
  535. 0,
  536. 0,
  537. 0});
  538. this.nudRangeX.Name = "nudRangeX";
  539. this.nudRangeX.Size = new System.Drawing.Size(160, 21);
  540. this.nudRangeX.TabIndex = 6;
  541. this.nudRangeX.Value = new decimal(new int[] {
  542. 100,
  543. 0,
  544. 0,
  545. 0});
  546. this.nudRangeX.ValueChanged += new System.EventHandler(this.nudRangeX_ValueChanged);
  547. //
  548. // label15
  549. //
  550. this.label15.AutoSize = true;
  551. this.label15.Location = new System.Drawing.Point(43, 124);
  552. this.label15.Name = "label15";
  553. this.label15.Size = new System.Drawing.Size(47, 12);
  554. this.label15.TabIndex = 8;
  555. this.label15.Text = "Y方向:";
  556. //
  557. // label16
  558. //
  559. this.label16.AutoSize = true;
  560. this.label16.Location = new System.Drawing.Point(43, 82);
  561. this.label16.Name = "label16";
  562. this.label16.Size = new System.Drawing.Size(47, 12);
  563. this.label16.TabIndex = 7;
  564. this.label16.Text = "X方向:";
  565. //
  566. // chkRange
  567. //
  568. this.chkRange.AutoSize = true;
  569. this.chkRange.Location = new System.Drawing.Point(43, 36);
  570. this.chkRange.Name = "chkRange";
  571. this.chkRange.Size = new System.Drawing.Size(84, 16);
  572. this.chkRange.TabIndex = 0;
  573. this.chkRange.Text = "保持纵横比";
  574. this.chkRange.UseVisualStyleBackColor = true;
  575. //
  576. // label17
  577. //
  578. this.label17.AutoSize = true;
  579. this.label17.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
  580. this.label17.Location = new System.Drawing.Point(12, 620);
  581. this.label17.Name = "label17";
  582. this.label17.Size = new System.Drawing.Size(0, 16);
  583. this.label17.TabIndex = 6;
  584. //
  585. // lblRange
  586. //
  587. this.lblRange.AutoSize = true;
  588. this.lblRange.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
  589. this.lblRange.Location = new System.Drawing.Point(138, 620);
  590. this.lblRange.Name = "lblRange";
  591. this.lblRange.Size = new System.Drawing.Size(0, 16);
  592. this.lblRange.TabIndex = 7;
  593. //
  594. // SettingDialog
  595. //
  596. this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
  597. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  598. this.ClientSize = new System.Drawing.Size(693, 653);
  599. this.Controls.Add(this.lblRange);
  600. this.Controls.Add(this.label17);
  601. this.Controls.Add(this.groupBox5);
  602. this.Controls.Add(this.groupBox4);
  603. this.Controls.Add(this.groupBox3);
  604. this.Controls.Add(this.groupBox2);
  605. this.Controls.Add(this.groupBox1);
  606. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
  607. this.MaximizeBox = false;
  608. this.Name = "SettingDialog";
  609. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
  610. this.Text = "参数设置";
  611. this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.SettingDialog_FormClosing);
  612. this.Controls.SetChildIndex(this.groupBox1, 0);
  613. this.Controls.SetChildIndex(this.groupBox2, 0);
  614. this.Controls.SetChildIndex(this.groupBox3, 0);
  615. this.Controls.SetChildIndex(this.groupBox4, 0);
  616. this.Controls.SetChildIndex(this.groupBox5, 0);
  617. this.Controls.SetChildIndex(this.label17, 0);
  618. this.Controls.SetChildIndex(this.lblRange, 0);
  619. this.groupBox1.ResumeLayout(false);
  620. this.groupBox2.ResumeLayout(false);
  621. this.groupBox2.PerformLayout();
  622. this.groupBox3.ResumeLayout(false);
  623. this.groupBox3.PerformLayout();
  624. this.groupBox4.ResumeLayout(false);
  625. this.groupBox4.PerformLayout();
  626. ((System.ComponentModel.ISupportInitialize)(this.nudPointY)).EndInit();
  627. ((System.ComponentModel.ISupportInitialize)(this.nudPointX)).EndInit();
  628. this.groupBox5.ResumeLayout(false);
  629. this.groupBox5.PerformLayout();
  630. ((System.ComponentModel.ISupportInitialize)(this.nudRangeY)).EndInit();
  631. ((System.ComponentModel.ISupportInitialize)(this.nudRangeX)).EndInit();
  632. this.ResumeLayout(false);
  633. this.PerformLayout();
  634. }
  635. #endregion
  636. private System.Windows.Forms.GroupBox groupBox1;
  637. private System.Windows.Forms.Button btnClose;
  638. private System.Windows.Forms.Button btnSave;
  639. private System.Windows.Forms.GroupBox groupBox2;
  640. private System.Windows.Forms.Label label3;
  641. private System.Windows.Forms.Label label2;
  642. private System.Windows.Forms.Label label1;
  643. private System.Windows.Forms.Panel gridGridsColor;
  644. private System.Windows.Forms.Panel gridLensBgColor;
  645. private System.Windows.Forms.Label label4;
  646. private System.Windows.Forms.Label label5;
  647. private System.Windows.Forms.Panel gridBlocksColor;
  648. private System.Windows.Forms.Panel gridLensColor;
  649. private System.Windows.Forms.Panel gridBgColor;
  650. private System.Windows.Forms.GroupBox groupBox3;
  651. private System.Windows.Forms.TextBox txtBits;
  652. private System.Windows.Forms.Label label8;
  653. private System.Windows.Forms.TextBox txtBaseBps;
  654. private System.Windows.Forms.Label label7;
  655. private System.Windows.Forms.ComboBox cmbPort;
  656. private System.Windows.Forms.Label label6;
  657. private System.Windows.Forms.GroupBox groupBox4;
  658. private System.Windows.Forms.Label label12;
  659. private System.Windows.Forms.NumericUpDown nudPointY;
  660. private System.Windows.Forms.Label label11;
  661. private System.Windows.Forms.NumericUpDown nudPointX;
  662. private System.Windows.Forms.Label label10;
  663. private System.Windows.Forms.Label label9;
  664. private System.Windows.Forms.CheckBox chkPoint;
  665. private System.Windows.Forms.GroupBox groupBox5;
  666. private System.Windows.Forms.Label label13;
  667. private System.Windows.Forms.NumericUpDown nudRangeY;
  668. private System.Windows.Forms.Label label14;
  669. private System.Windows.Forms.NumericUpDown nudRangeX;
  670. private System.Windows.Forms.Label label15;
  671. private System.Windows.Forms.Label label16;
  672. private System.Windows.Forms.CheckBox chkRange;
  673. private System.Windows.Forms.Label label17;
  674. private System.Windows.Forms.Label lblRange;
  675. private System.Windows.Forms.TextBox txtStep;
  676. private System.Windows.Forms.Label label18;
  677. #endregion
  678. /// <summary>
  679. /// 网格调色板
  680. /// </summary>
  681. PaintDotNet.ColorsForm colorsFormGrid;
  682. /// <summary>
  683. /// 矩形调色板
  684. /// </summary>
  685. PaintDotNet.ColorsForm colorsFormRect;
  686. /// <summary>
  687. /// 圆形调色板
  688. /// </summary>
  689. PaintDotNet.ColorsForm colorsFormCircular;
  690. private string m_bgColor = "#ffffffff";
  691. private string m_lensColor = "#ffffffff";
  692. private string m_lensBgColor = "#ffffffff";
  693. private string m_gridsColor = "#ffffffff";
  694. private string m_blocksColor = "#ffffffff";
  695. private string m_port;
  696. private int m_bps;
  697. private string m_checkBits;
  698. private int m_pointRatio;
  699. private decimal m_pointX;
  700. private decimal m_pointY;
  701. private int m_rangeRatio;
  702. private decimal m_rangeX;
  703. private decimal m_rangeY;
  704. private int m_step;
  705. private SQLiteHelper m_sqlHelper;
  706. private object currentSender;
  707. private string[] m_serialLst;
  708. private Form m_parentForm;
  709. public SettingDialog(Form form)
  710. {
  711. m_parentForm = form;
  712. InitializeComponent();
  713. InitializeLanguageText();
  714. InitializeData();
  715. GetSerialLst();
  716. this.colorsFormGrid = new ColorsForm();
  717. this.colorsFormGrid.StartPosition = FormStartPosition.CenterScreen;
  718. this.colorsFormGrid.UserPrimaryColorChanged += new ColorEventHandler(this.colorsFormUserPrimaryColorChanged);
  719. this.colorsFormRect = new ColorsForm();
  720. this.colorsFormRect.StartPosition = FormStartPosition.CenterScreen;
  721. this.colorsFormRect.UserPrimaryColorChanged += new ColorEventHandler(this.colorsFormUserPrimaryColorChanged);
  722. this.colorsFormCircular = new ColorsForm();
  723. this.colorsFormCircular.StartPosition = FormStartPosition.CenterScreen;
  724. this.colorsFormCircular.UserPrimaryColorChanged += new ColorEventHandler(this.colorsFormUserPrimaryColorChanged);
  725. }
  726. private void GetSerialLst()
  727. {
  728. //清除cmbPort显示
  729. cmbPort.SelectedIndex = -1;
  730. cmbPort.Items.Clear();
  731. //获取串口列表
  732. m_serialLst = SerialPort.GetPortNames();
  733. if (m_serialLst.Length > 0)
  734. {
  735. //取串口列表进行排序
  736. Array.Sort(m_serialLst);
  737. //将串口列表输出到comboBox
  738. cmbPort.Items.AddRange(m_serialLst);
  739. cmbPort.SelectedIndex = 0;
  740. if (!string.IsNullOrEmpty(m_port))
  741. {
  742. for (int i = 0; i < m_serialLst.Length; ++i)
  743. {
  744. if (m_serialLst[i].Equals(m_port))
  745. {
  746. cmbPort.SelectedIndex = i;
  747. }
  748. }
  749. }
  750. }
  751. }
  752. public const int WM_DEVICE_CHANGE = 0x219; //设备改变
  753. public const int DBT_DEVICEARRIVAL = 0x8000; //设备插入
  754. public const int DBT_DEVICE_REMOVE_COMPLETE = 0x8004; //设备移除
  755. //消息处理
  756. protected override void WndProc(ref Message m)
  757. {
  758. switch (m.Msg) //判断消息类型
  759. {
  760. case WM_DEVICE_CHANGE: //设备改变消息
  761. {
  762. GetSerialLst(); //设备改变时重新获取串口列表
  763. }
  764. break;
  765. }
  766. base.WndProc(ref m);
  767. }
  768. private void InitializeData()
  769. {
  770. m_sqlHelper = new SQLiteHelper(); //连接数据库
  771. m_sqlHelper.Connect();
  772. string select_sql = "select * from mic_countometer_setting "; //查询的SQL语句
  773. DataTable dt = m_sqlHelper.ExecuteDataTable(select_sql, null); //执行查询操作,结果存放在dt中
  774. if(dt != null && dt.Rows.Count > 0)
  775. {
  776. m_bgColor = dt.Rows[0]["bg_color"].ToString();
  777. m_lensColor = dt.Rows[0]["lens_color"].ToString();
  778. m_lensBgColor = dt.Rows[0]["lens_bg_color"].ToString();
  779. m_gridsColor = dt.Rows[0]["grids_color"].ToString();
  780. m_blocksColor = dt.Rows[0]["blocks_color"].ToString();
  781. m_port = dt.Rows[0]["com_port"].ToString();
  782. m_bps = int.Parse(dt.Rows[0]["base_bps"].ToString());
  783. m_checkBits = dt.Rows[0]["base_check_bits"].ToString();
  784. m_step = int.Parse(dt.Rows[0]["step"].ToString());
  785. m_pointRatio = int.Parse(dt.Rows[0]["point_ratio"].ToString());
  786. m_pointX = int.Parse(dt.Rows[0]["point_x"].ToString());
  787. m_pointY = int.Parse(dt.Rows[0]["point_y"].ToString());
  788. m_rangeRatio = int.Parse(dt.Rows[0]["range_ratio"].ToString());
  789. m_rangeX = int.Parse(dt.Rows[0]["range_x"].ToString());
  790. m_rangeY = int.Parse(dt.Rows[0]["range_y"].ToString());
  791. this.txtStep.Text = m_step.ToString();
  792. this.txtBaseBps.Text = m_bps.ToString();
  793. this.txtBits.Text = m_checkBits.ToString();
  794. if (m_pointRatio == 1)
  795. {
  796. this.chkPoint.Checked = true;
  797. }
  798. this.nudPointX.Value = m_pointX;
  799. this.nudPointY.Value = m_pointY;
  800. if (m_rangeRatio == 1)
  801. {
  802. this.chkRange.Checked = true;
  803. }
  804. this.nudRangeX.Value = m_rangeX;
  805. this.nudRangeY.Value = m_rangeY;
  806. }
  807. this.gridBgColor.BackColor = ColorTranslator.FromHtml(m_bgColor);
  808. this.gridLensBgColor.BackColor = ColorTranslator.FromHtml(m_lensBgColor);
  809. this.gridLensColor.BackColor = ColorTranslator.FromHtml(m_lensColor);
  810. this.gridGridsColor.BackColor = ColorTranslator.FromHtml(m_gridsColor);
  811. this.gridBlocksColor.BackColor = ColorTranslator.FromHtml(m_blocksColor);
  812. }
  813. /// <summary>
  814. /// 调色板回调函数
  815. /// </summary>
  816. /// <param name="sender"></param>
  817. /// <param name="ce"></param>
  818. private void colorsFormUserPrimaryColorChanged(object sender, ColorEventArgs ce)
  819. {
  820. }
  821. private void ShowColorsForm(object sender)
  822. {
  823. Panel panel = (Panel)sender;
  824. this.colorsFormGrid.UserPrimaryColor = ColorBgra.FromColor(panel.BackColor);
  825. this.colorsFormGrid.setSaveBtn_Click(new System.EventHandler(this.gridColorChanged));
  826. this.colorsFormGrid.ShowDialog();
  827. }
  828. /// <summary>
  829. /// 网格Panel的调色板颜色改变
  830. /// </summary>
  831. /// <param name="sender"></param>
  832. /// <param name="e"></param>
  833. private void gridColorChanged(object sender, EventArgs e)
  834. {
  835. Panel panel = (Panel)currentSender;
  836. Color color = this.colorsFormGrid.UserPrimaryColor.ToColor();
  837. panel.BackColor = color;
  838. this.colorsFormGrid.Close();
  839. }
  840. private void gridColor_Click(object sender, EventArgs e)
  841. {
  842. currentSender = sender;
  843. ShowColorsForm(sender);
  844. }
  845. private void gridBgColor_BackColorChanged(object sender, EventArgs e)
  846. {
  847. m_bgColor = ColorTranslator.ToHtml(this.gridBgColor.BackColor);
  848. }
  849. private void gridLensBgColor_BackColorChanged(object sender, EventArgs e)
  850. {
  851. m_lensBgColor = ColorTranslator.ToHtml(this.gridLensBgColor.BackColor);
  852. }
  853. private void gridLensColor_BackColorChanged(object sender, EventArgs e)
  854. {
  855. m_lensColor = ColorTranslator.ToHtml(this.gridLensColor.BackColor);
  856. }
  857. private void gridGridsColor_BackColorChanged(object sender, EventArgs e)
  858. {
  859. m_gridsColor = ColorTranslator.ToHtml(this.gridGridsColor.BackColor);
  860. }
  861. private void gridBlocksColor_BackColorChanged(object sender, EventArgs e)
  862. {
  863. m_blocksColor = ColorTranslator.ToHtml(this.gridBlocksColor.BackColor);
  864. }
  865. private void UpdateLblRange()
  866. {
  867. lblRange.Text = (nudPointX.Value * nudRangeX.Value).ToString() + "*" + (nudPointY.Value * nudRangeY.Value).ToString() + PdnResources.GetString("Menu.Micron.text");
  868. }
  869. private void nudRangeX_ValueChanged(object sender, EventArgs e)
  870. {
  871. UpdateLblRange();
  872. }
  873. private void nudRangeY_ValueChanged(object sender, EventArgs e)
  874. {
  875. UpdateLblRange();
  876. }
  877. private void nudPointX_ValueChanged(object sender, EventArgs e)
  878. {
  879. UpdateLblRange();
  880. }
  881. private void nudPointY_ValueChanged(object sender, EventArgs e)
  882. {
  883. UpdateLblRange();
  884. }
  885. private void btnClose_Click(object sender, EventArgs e)
  886. {
  887. this.Close();
  888. }
  889. /// <summary>
  890. /// 保存
  891. /// </summary>
  892. /// <param name="sender"></param>
  893. /// <param name="e"></param>
  894. private void btnSave_Click(object sender, EventArgs e)
  895. {
  896. string bps = txtBaseBps.Text.Trim();
  897. if (string.IsNullOrEmpty(bps) || string.IsNullOrWhiteSpace(bps))
  898. {
  899. MessageBox.Show(PdnResources.GetString("Menu.Baudrempty.text"));
  900. return;
  901. }
  902. string step = txtStep.Text.Trim();
  903. if (string.IsNullOrEmpty(step) || string.IsNullOrWhiteSpace(step))
  904. {
  905. MessageBox.Show(PdnResources.GetString("Menu.Step-sizbeempty.text"));
  906. return;
  907. }
  908. m_port = cmbPort.Text;
  909. m_bps = int.Parse(bps);
  910. m_checkBits = txtBits.Text.Trim();
  911. m_step = int.Parse(step);
  912. m_pointRatio = chkPoint.Checked ? 1 : 0;
  913. m_pointX = nudPointX.Value;
  914. m_pointY = nudPointY.Value;
  915. m_rangeRatio = chkRange.Checked ? 1 : 0;
  916. m_rangeX = nudRangeX.Value;
  917. m_rangeY = nudRangeY.Value;
  918. string update_sql = "update mic_countometer_setting set bg_color = ?, lens_color = ?, lens_bg_color = ?, grids_color = ?, blocks_color = ?, com_port = ?, base_bps = ?, base_check_bits = ?, step = ?, point_ratio = ?, point_x = ?, point_y = ?, range_ratio = ?, range_x = ?, range_y = ?"; //插入的SQL语句(带参数)
  919. SQLiteParameter[] para = new SQLiteParameter[15]; //构造并绑定参数
  920. string[] tag = { "bg_color", "lens_color", "lens_bg_color", "grids_color", "blocks_color", "com_port", "base_bps", "base_check_bits", "step", "point_ratio", "point_x", "point_y", "range_ratio", "range_x", "range_y" };
  921. Object[] value = { m_bgColor, m_lensColor, m_lensBgColor, m_gridsColor, m_blocksColor, m_port, m_bps, m_checkBits, m_step, m_pointRatio, m_pointX, m_pointY, m_rangeRatio, m_rangeX, m_rangeY };
  922. for (int i = 0; i < 15; i++)
  923. {
  924. para[i] = new SQLiteParameter(tag[i], value[i]);
  925. }
  926. m_sqlHelper.ExecuteNonQuery(update_sql, para); //执行插入操作
  927. // 父窗口重新加载配置信息
  928. ((GeneralCountometerDialog)m_parentForm).SettingLoad();
  929. //MessageBox.Show(PdnResources.GetString("Menu.Successfullysaved.text"));
  930. this.Close();
  931. }
  932. private void SettingDialog_FormClosing(object sender, FormClosingEventArgs e)
  933. {
  934. m_sqlHelper.DisConnect();
  935. }
  936. }
  937. }