CustomRulerDialog.cs 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278
  1. using Resources;
  2. using SmartCoalApplication.Base.SettingModel;
  3. using SmartCoalApplication.Core;
  4. using SmartCoalApplication.Core.DbOpreate.DbBll;
  5. using SmartCoalApplication.Core.DbOpreate.DbModel;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.ComponentModel;
  9. using System.Data;
  10. using System.Drawing;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using System.Windows.Forms;
  15. namespace SmartCoalApplication.Rule
  16. {
  17. /// <summary>
  18. /// 自定义标尺
  19. /// </summary>
  20. internal class CustomRulerDialog : PdnBaseForm
  21. {
  22. private GroupBox groupBox1;
  23. private Button button3;
  24. private Button button2;
  25. private Button button1;
  26. private GroupBox groupBox2;
  27. private Button button4;
  28. private RadioButton radioButton2;
  29. private RadioButton radioButton1;
  30. private Panel panel1;
  31. private Label label3;
  32. private Label label2;
  33. private Label label1;
  34. private TextBox textBox1;
  35. private NumericUpDown numericUpDown2;
  36. private NumericUpDown numericUpDown1;
  37. private Panel panel2;
  38. private NumericUpDown numericUpDown3;
  39. private Label label6;
  40. private Label label5;
  41. private TextBox textBox2;
  42. private Label label4;
  43. private Panel panel3;
  44. private ListView listView1;
  45. private Label label8;
  46. private Label label7;
  47. private ComboBox comboBox1;
  48. /// <summary>
  49. /// 主配置,包含了选定的标尺的配置
  50. /// </summary>
  51. private ConfigModel configModel = Program.instance.configModel;
  52. /// <summary>
  53. /// 工作控件
  54. /// </summary>
  55. private AppWorkspace appWorkspace;
  56. /// <summary>
  57. /// 标尺数据,编辑标尺时使用
  58. /// </summary>
  59. private mic_rulers ruleModel;
  60. /// <summary>
  61. /// 1新增 2编辑
  62. /// </summary>
  63. private int status;
  64. public CustomRulerDialog(AppWorkspace appWorkspace, mic_rulers ruleModel, int status)
  65. {
  66. this.status = status;
  67. this.appWorkspace = appWorkspace;
  68. this.ruleModel = ruleModel;
  69. InitializeComponent();
  70. InitializeLanguageText();
  71. InitOtherInfo();
  72. InitListViewHeader();
  73. InitListViewDate();
  74. if (this.ruleModel != null)
  75. InitializeEditData();
  76. }
  77. private void InitializeLanguageText()
  78. {
  79. this.groupBox1.Text = PdnResources.GetString("Menu.Type.text");
  80. this.button3.Text = PdnResources.GetString("Menu.File.Close.Text");
  81. this.button2.Text = PdnResources.GetString("Menu.Imagement.Rulersetting.Calculatescale.text");
  82. this.button1.Text = PdnResources.GetString("Menu.Imagement.Rulersetting.Anyruler.text");
  83. this.groupBox2.Text = PdnResources.GetString("Menu.Imagement.Rulersetting.Savetype.text");
  84. this.button4.Text = PdnResources.GetString("Menu.File.Save.Text");
  85. this.radioButton2.Text = PdnResources.GetString("Menu.Imagement.Rulersetting.Saveforever.text");
  86. this.radioButton1.Text = PdnResources.GetString("Menu.porarypreservation.Text");
  87. this.label3.Text = PdnResources.GetString("Menu.LabelAction.DrawGainNumber.Text") + ":";
  88. this.label2.Text = PdnResources.GetString("Menu.Imagement.Rulersetting.Micron/pixel.text") + ":";
  89. this.label1.Text = PdnResources.GetString("Menu.Rulername.text") + ":";
  90. this.label8.Text = PdnResources.GetString("Menu.nothing.Text");
  91. this.label7.Text = PdnResources.GetString("Menu.Imagement.Rulersetting.Currentrulercalculated:none.text") + ":";
  92. this.label6.Text = PdnResources.GetString("Menu.Imagement.Rulersetting.Calculatetheunit.text") + ":";
  93. this.label5.Text = PdnResources.GetString("Menu.Totalmagnification.text") + ":";
  94. this.label4.Text = PdnResources.GetString("Menu.Rulername.text") + ":";
  95. this.Text = PdnResources.GetString("Menu.user-definedruler.text");
  96. }
  97. private void InitializeComponent()
  98. {
  99. this.groupBox1 = new System.Windows.Forms.GroupBox();
  100. this.button3 = new System.Windows.Forms.Button();
  101. this.button2 = new System.Windows.Forms.Button();
  102. this.button1 = new System.Windows.Forms.Button();
  103. this.groupBox2 = new System.Windows.Forms.GroupBox();
  104. this.button4 = new System.Windows.Forms.Button();
  105. this.radioButton2 = new System.Windows.Forms.RadioButton();
  106. this.radioButton1 = new System.Windows.Forms.RadioButton();
  107. this.panel1 = new System.Windows.Forms.Panel();
  108. this.numericUpDown2 = new System.Windows.Forms.NumericUpDown();
  109. this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
  110. this.textBox1 = new System.Windows.Forms.TextBox();
  111. this.label3 = new System.Windows.Forms.Label();
  112. this.label2 = new System.Windows.Forms.Label();
  113. this.label1 = new System.Windows.Forms.Label();
  114. this.panel2 = new System.Windows.Forms.Panel();
  115. this.comboBox1 = new System.Windows.Forms.ComboBox();
  116. this.panel3 = new System.Windows.Forms.Panel();
  117. this.label8 = new System.Windows.Forms.Label();
  118. this.label7 = new System.Windows.Forms.Label();
  119. this.listView1 = new System.Windows.Forms.ListView();
  120. this.numericUpDown3 = new System.Windows.Forms.NumericUpDown();
  121. this.label6 = new System.Windows.Forms.Label();
  122. this.label5 = new System.Windows.Forms.Label();
  123. this.textBox2 = new System.Windows.Forms.TextBox();
  124. this.label4 = new System.Windows.Forms.Label();
  125. this.groupBox1.SuspendLayout();
  126. this.groupBox2.SuspendLayout();
  127. this.panel1.SuspendLayout();
  128. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit();
  129. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
  130. this.panel2.SuspendLayout();
  131. this.panel3.SuspendLayout();
  132. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown3)).BeginInit();
  133. this.SuspendLayout();
  134. //
  135. // groupBox1
  136. //
  137. this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  138. | System.Windows.Forms.AnchorStyles.Left)));
  139. this.groupBox1.Controls.Add(this.button3);
  140. this.groupBox1.Controls.Add(this.button2);
  141. this.groupBox1.Controls.Add(this.button1);
  142. this.groupBox1.Location = new System.Drawing.Point(13, 13);
  143. this.groupBox1.Name = "groupBox1";
  144. this.groupBox1.Size = new System.Drawing.Size(98, 462);
  145. this.groupBox1.TabIndex = 0;
  146. this.groupBox1.TabStop = false;
  147. //
  148. // button3
  149. //
  150. this.button3.Location = new System.Drawing.Point(10, 424);
  151. this.button3.Name = "button3";
  152. this.button3.Size = new System.Drawing.Size(75, 23);
  153. this.button3.TabIndex = 2;
  154. this.button3.Text = "关闭";
  155. this.button3.UseVisualStyleBackColor = true;
  156. this.button3.Click += new System.EventHandler(this.button3_Click);
  157. //
  158. // button2
  159. //
  160. this.button2.Location = new System.Drawing.Point(10, 82);
  161. this.button2.Name = "button2";
  162. this.button2.Size = new System.Drawing.Size(75, 23);
  163. this.button2.TabIndex = 1;
  164. this.button2.Text = "推算标尺";
  165. this.button2.UseVisualStyleBackColor = true;
  166. this.button2.Click += new System.EventHandler(this.button2_Click);
  167. //
  168. // button1
  169. //
  170. this.button1.Location = new System.Drawing.Point(10, 41);
  171. this.button1.Name = "button1";
  172. this.button1.Size = new System.Drawing.Size(75, 23);
  173. this.button1.TabIndex = 0;
  174. this.button1.Text = "任意标尺";
  175. this.button1.UseVisualStyleBackColor = true;
  176. this.button1.Click += new System.EventHandler(this.button1_Click);
  177. //
  178. // groupBox2
  179. //
  180. this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  181. | System.Windows.Forms.AnchorStyles.Right)));
  182. this.groupBox2.Controls.Add(this.button4);
  183. this.groupBox2.Controls.Add(this.radioButton2);
  184. this.groupBox2.Controls.Add(this.radioButton1);
  185. this.groupBox2.Location = new System.Drawing.Point(118, 13);
  186. this.groupBox2.Name = "groupBox2";
  187. this.groupBox2.Size = new System.Drawing.Size(563, 54);
  188. this.groupBox2.TabIndex = 1;
  189. this.groupBox2.TabStop = false;
  190. this.groupBox2.Text = "保存类型";
  191. //
  192. // button4
  193. //
  194. this.button4.Location = new System.Drawing.Point(463, 19);
  195. this.button4.Name = "button4";
  196. this.button4.Size = new System.Drawing.Size(75, 23);
  197. this.button4.TabIndex = 2;
  198. this.button4.Text = "保存";
  199. this.button4.UseVisualStyleBackColor = true;
  200. this.button4.Click += new System.EventHandler(this.button4_Click);
  201. //
  202. // radioButton2
  203. //
  204. this.radioButton2.AutoSize = true;
  205. this.radioButton2.Location = new System.Drawing.Point(215, 22);
  206. this.radioButton2.Name = "radioButton2";
  207. this.radioButton2.Size = new System.Drawing.Size(71, 16);
  208. this.radioButton2.TabIndex = 1;
  209. this.radioButton2.TabStop = true;
  210. this.radioButton2.Text = "永久保存";
  211. this.radioButton2.UseVisualStyleBackColor = true;
  212. //
  213. // radioButton1
  214. //
  215. this.radioButton1.AutoSize = true;
  216. this.radioButton1.Checked = true;
  217. this.radioButton1.Location = new System.Drawing.Point(69, 22);
  218. this.radioButton1.Name = "radioButton1";
  219. this.radioButton1.Size = new System.Drawing.Size(71, 16);
  220. this.radioButton1.TabIndex = 0;
  221. this.radioButton1.TabStop = true;
  222. this.radioButton1.Text = "临时保存";
  223. this.radioButton1.UseVisualStyleBackColor = true;
  224. //
  225. // panel1
  226. //
  227. this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  228. | System.Windows.Forms.AnchorStyles.Left)
  229. | System.Windows.Forms.AnchorStyles.Right)));
  230. this.panel1.Controls.Add(this.numericUpDown2);
  231. this.panel1.Controls.Add(this.numericUpDown1);
  232. this.panel1.Controls.Add(this.textBox1);
  233. this.panel1.Controls.Add(this.label3);
  234. this.panel1.Controls.Add(this.label2);
  235. this.panel1.Controls.Add(this.label1);
  236. this.panel1.Location = new System.Drawing.Point(118, 74);
  237. this.panel1.Name = "panel1";
  238. this.panel1.Size = new System.Drawing.Size(563, 401);
  239. this.panel1.TabIndex = 2;
  240. //
  241. // numericUpDown2
  242. //
  243. this.numericUpDown2.DecimalPlaces = 2;
  244. this.numericUpDown2.Increment = new decimal(new int[] {
  245. 1,
  246. 0,
  247. 0,
  248. 65536});
  249. this.numericUpDown2.Location = new System.Drawing.Point(118, 116);
  250. this.numericUpDown2.Maximum = new decimal(new int[] {
  251. 99999,
  252. 0,
  253. 0,
  254. 0});
  255. this.numericUpDown2.Minimum = new decimal(new int[] {
  256. 1,
  257. 0,
  258. 0,
  259. 131072});
  260. this.numericUpDown2.Name = "numericUpDown2";
  261. this.numericUpDown2.Size = new System.Drawing.Size(139, 21);
  262. this.numericUpDown2.TabIndex = 5;
  263. this.numericUpDown2.Value = new decimal(new int[] {
  264. 10,
  265. 0,
  266. 0,
  267. 0});
  268. //
  269. // numericUpDown1
  270. //
  271. this.numericUpDown1.DecimalPlaces = 2;
  272. this.numericUpDown1.Increment = new decimal(new int[] {
  273. 1,
  274. 0,
  275. 0,
  276. 65536});
  277. this.numericUpDown1.Location = new System.Drawing.Point(118, 76);
  278. this.numericUpDown1.Maximum = new decimal(new int[] {
  279. 99999,
  280. 0,
  281. 0,
  282. 0});
  283. this.numericUpDown1.Minimum = new decimal(new int[] {
  284. 1,
  285. 0,
  286. 0,
  287. 131072});
  288. this.numericUpDown1.Name = "numericUpDown1";
  289. this.numericUpDown1.Size = new System.Drawing.Size(139, 21);
  290. this.numericUpDown1.TabIndex = 4;
  291. this.numericUpDown1.Value = new decimal(new int[] {
  292. 1,
  293. 0,
  294. 0,
  295. 0});
  296. //
  297. // textBox1
  298. //
  299. this.textBox1.Location = new System.Drawing.Point(118, 36);
  300. this.textBox1.Name = "textBox1";
  301. this.textBox1.Size = new System.Drawing.Size(139, 21);
  302. this.textBox1.TabIndex = 3;
  303. //
  304. // label3
  305. //
  306. this.label3.AutoSize = true;
  307. this.label3.Location = new System.Drawing.Point(50, 118);
  308. this.label3.Name = "label3";
  309. this.label3.Size = new System.Drawing.Size(0, 12);
  310. this.label3.TabIndex = 2;
  311. //
  312. // label2
  313. //
  314. this.label2.AutoSize = true;
  315. this.label2.Location = new System.Drawing.Point(44, 79);
  316. this.label2.Name = "label2";
  317. this.label2.Size = new System.Drawing.Size(0, 12);
  318. this.label2.TabIndex = 1;
  319. //
  320. // label1
  321. //
  322. this.label1.AutoSize = true;
  323. this.label1.Location = new System.Drawing.Point(48, 40);
  324. this.label1.Name = "label1";
  325. this.label1.Size = new System.Drawing.Size(0, 12);
  326. this.label1.TabIndex = 0;
  327. //
  328. // panel2
  329. //
  330. this.panel2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  331. | System.Windows.Forms.AnchorStyles.Left)
  332. | System.Windows.Forms.AnchorStyles.Right)));
  333. this.panel2.Controls.Add(this.comboBox1);
  334. this.panel2.Controls.Add(this.panel3);
  335. this.panel2.Controls.Add(this.listView1);
  336. this.panel2.Controls.Add(this.numericUpDown3);
  337. this.panel2.Controls.Add(this.label6);
  338. this.panel2.Controls.Add(this.label5);
  339. this.panel2.Controls.Add(this.textBox2);
  340. this.panel2.Controls.Add(this.label4);
  341. this.panel2.Location = new System.Drawing.Point(118, 74);
  342. this.panel2.Name = "panel2";
  343. this.panel2.Size = new System.Drawing.Size(563, 401);
  344. this.panel2.TabIndex = 3;
  345. //
  346. // comboBox1
  347. //
  348. this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  349. this.comboBox1.FormattingEnabled = true;
  350. this.comboBox1.Location = new System.Drawing.Point(106, 76);
  351. this.comboBox1.Name = "comboBox1";
  352. this.comboBox1.Size = new System.Drawing.Size(134, 20);
  353. this.comboBox1.TabIndex = 8;
  354. this.comboBox1.SelectionChangeCommitted += new System.EventHandler(this.comboBox1_SelectionChangeCommitted);
  355. //
  356. // panel3
  357. //
  358. this.panel3.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
  359. | System.Windows.Forms.AnchorStyles.Right)));
  360. this.panel3.BackColor = System.Drawing.Color.DimGray;
  361. this.panel3.Controls.Add(this.label8);
  362. this.panel3.Controls.Add(this.label7);
  363. this.panel3.Location = new System.Drawing.Point(3, 363);
  364. this.panel3.Name = "panel3";
  365. this.panel3.Size = new System.Drawing.Size(557, 35);
  366. this.panel3.TabIndex = 7;
  367. //
  368. // label8
  369. //
  370. this.label8.AutoSize = true;
  371. this.label8.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
  372. this.label8.ForeColor = System.Drawing.Color.White;
  373. this.label8.Location = new System.Drawing.Point(188, 10);
  374. this.label8.Name = "label8";
  375. this.label8.Size = new System.Drawing.Size(0, 16);
  376. this.label8.TabIndex = 1;
  377. //
  378. // label7
  379. //
  380. this.label7.AutoSize = true;
  381. this.label7.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
  382. this.label7.ForeColor = System.Drawing.Color.White;
  383. this.label7.Location = new System.Drawing.Point(38, 10);
  384. this.label7.Name = "label7";
  385. this.label7.Size = new System.Drawing.Size(0, 16);
  386. this.label7.TabIndex = 0;
  387. //
  388. // listView1
  389. //
  390. this.listView1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
  391. | System.Windows.Forms.AnchorStyles.Right)));
  392. this.listView1.FullRowSelect = true;
  393. this.listView1.HideSelection = false;
  394. this.listView1.Location = new System.Drawing.Point(3, 115);
  395. this.listView1.MultiSelect = false;
  396. this.listView1.Name = "listView1";
  397. this.listView1.Size = new System.Drawing.Size(557, 242);
  398. this.listView1.TabIndex = 6;
  399. this.listView1.UseCompatibleStateImageBehavior = false;
  400. this.listView1.SelectedIndexChanged += new System.EventHandler(this.listView1_SelectedIndexChanged);
  401. //
  402. // numericUpDown3
  403. //
  404. this.numericUpDown3.DecimalPlaces = 2;
  405. this.numericUpDown3.Increment = new decimal(new int[] {
  406. 1,
  407. 0,
  408. 0,
  409. 65536});
  410. this.numericUpDown3.Location = new System.Drawing.Point(370, 36);
  411. this.numericUpDown3.Maximum = new decimal(new int[] {
  412. 99999,
  413. 0,
  414. 0,
  415. 0});
  416. this.numericUpDown3.Minimum = new decimal(new int[] {
  417. 1,
  418. 0,
  419. 0,
  420. 131072});
  421. this.numericUpDown3.Name = "numericUpDown3";
  422. this.numericUpDown3.Size = new System.Drawing.Size(134, 21);
  423. this.numericUpDown3.TabIndex = 4;
  424. this.numericUpDown3.Value = new decimal(new int[] {
  425. 10,
  426. 0,
  427. 0,
  428. 0});
  429. this.numericUpDown3.ValueChanged += new System.EventHandler(this.numericUpDown3_ValueChanged);
  430. //
  431. // label6
  432. //
  433. this.label6.AutoSize = true;
  434. this.label6.Location = new System.Drawing.Point(44, 79);
  435. this.label6.Name = "label6";
  436. this.label6.Size = new System.Drawing.Size(65, 12);
  437. this.label6.TabIndex = 3;
  438. this.label6.Text = "推算单位:";
  439. //
  440. // label5
  441. //
  442. this.label5.AutoSize = true;
  443. this.label5.Location = new System.Drawing.Point(309, 39);
  444. this.label5.Name = "label5";
  445. this.label5.Size = new System.Drawing.Size(65, 12);
  446. this.label5.TabIndex = 2;
  447. this.label5.Text = "放大倍数:";
  448. //
  449. // textBox2
  450. //
  451. this.textBox2.Location = new System.Drawing.Point(106, 36);
  452. this.textBox2.Name = "textBox2";
  453. this.textBox2.Size = new System.Drawing.Size(134, 21);
  454. this.textBox2.TabIndex = 1;
  455. //
  456. // label4
  457. //
  458. this.label4.AutoSize = true;
  459. this.label4.Location = new System.Drawing.Point(44, 39);
  460. this.label4.Name = "label4";
  461. this.label4.Size = new System.Drawing.Size(65, 12);
  462. this.label4.TabIndex = 0;
  463. this.label4.Text = "标尺名称:";
  464. //
  465. // CustomRulerDialog
  466. //
  467. this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
  468. this.ClientSize = new System.Drawing.Size(693, 487);
  469. this.Controls.Add(this.panel2);
  470. this.Controls.Add(this.panel1);
  471. this.Controls.Add(this.groupBox2);
  472. this.Controls.Add(this.groupBox1);
  473. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
  474. this.MaximizeBox = false;
  475. this.MinimizeBox = false;
  476. this.Name = "CustomRulerDialog";
  477. this.Text = "自定义标尺";
  478. this.Controls.SetChildIndex(this.groupBox1, 0);
  479. this.Controls.SetChildIndex(this.groupBox2, 0);
  480. this.Controls.SetChildIndex(this.panel1, 0);
  481. this.Controls.SetChildIndex(this.panel2, 0);
  482. this.groupBox1.ResumeLayout(false);
  483. this.groupBox2.ResumeLayout(false);
  484. this.groupBox2.PerformLayout();
  485. this.panel1.ResumeLayout(false);
  486. this.panel1.PerformLayout();
  487. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit();
  488. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
  489. this.panel2.ResumeLayout(false);
  490. this.panel2.PerformLayout();
  491. this.panel3.ResumeLayout(false);
  492. this.panel3.PerformLayout();
  493. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown3)).EndInit();
  494. this.ResumeLayout(false);
  495. }
  496. /// <summary>
  497. /// 初始化其他信息
  498. /// </summary>
  499. private void InitOtherInfo()
  500. {
  501. this.panel2.Visible = false;
  502. this.button1.BackColor = Color.Gray;
  503. this.button1.ForeColor = Color.White;
  504. this.button1.FlatStyle = FlatStyle.Flat;
  505. this.button1.FlatAppearance.BorderSize = 0;
  506. //单位选择
  507. this.comboBox1.DataSource = new BindingSource(InvariantData.unitsDictionary, null);
  508. this.comboBox1.SelectedIndex = 4;//默认选中微米
  509. this.comboBox1.DisplayMember = "Value";
  510. this.comboBox1.ValueMember = "Key";
  511. SystemLayer.SafeNativeMethods.SetCueText(this.textBox1, PdnResources.GetString("Menu.Pleaseenterarulername.text"));
  512. SystemLayer.SafeNativeMethods.SetCueText(this.textBox2, PdnResources.GetString("Menu.Pleaseenterarulername.text"));
  513. }
  514. /// <summary>
  515. /// 初始化标尺列头
  516. /// </summary>
  517. private void InitListViewHeader()
  518. {
  519. this.listView1.View = View.Details;
  520. ColumnHeader header0 = new ColumnHeader();
  521. header0.Text = PdnResources.GetString("Menu.Imagement.Rulersetting.active.text");
  522. header0.Width = 38;
  523. this.listView1.Columns.Add(header0);
  524. ColumnHeader header = new ColumnHeader();
  525. header.Text = PdnResources.GetString("Menu.Rulername.text");
  526. header.Width = 150;
  527. this.listView1.Columns.Add(header);
  528. ColumnHeader header1 = new ColumnHeader();
  529. header1.Text = PdnResources.GetString("Menu.unit.text") + "/" + PdnResources.GetString("MeasurementUnit.Pixel");
  530. header1.Width = 70;
  531. this.listView1.Columns.Add(header1);
  532. ColumnHeader header2 = new ColumnHeader();
  533. header2.Text = PdnResources.GetString("Menu.LabelAction.DrawGainNumber.Text");
  534. this.listView1.Columns.Add(header2);
  535. ColumnHeader header3 = new ColumnHeader();
  536. header3.Text = PdnResources.GetString("Menu.Pixellength.text");
  537. this.listView1.Columns.Add(header3);
  538. ColumnHeader header4 = new ColumnHeader();
  539. header4.Text = PdnResources.GetString("Menu.Physicallength.text");
  540. this.listView1.Columns.Add(header4);
  541. ColumnHeader header5 = new ColumnHeader();
  542. header5.Text = PdnResources.GetString("Menu.Unitsofmeasurement.text");
  543. this.listView1.Columns.Add(header5);
  544. ColumnHeader header6 = new ColumnHeader();
  545. header6.Text = PdnResources.GetString("Menu.ImageResolution.text");
  546. header6.Width = 80;
  547. this.listView1.Columns.Add(header6);
  548. ColumnHeader header7 = new ColumnHeader();
  549. header7.Text = PdnResources.GetString("Menu.magnificationchanger.text");
  550. this.listView1.Columns.Add(header7);
  551. ColumnHeader header8 = new ColumnHeader();
  552. header8.Text = PdnResources.GetString("Menu.interface.text");
  553. this.listView1.Columns.Add(header8);
  554. ColumnHeader header9 = new ColumnHeader();
  555. header9.Text = PdnResources.GetString("Menu.oculars.text");
  556. this.listView1.Columns.Add(header9);
  557. ColumnHeader header10 = new ColumnHeader();
  558. header10.Text = PdnResources.GetString("Menu.thecamera.text");
  559. this.listView1.Columns.Add(header10);
  560. ColumnHeader header11 = new ColumnHeader();
  561. header11.Text = PdnResources.GetString("Menu.Objectlens.text");
  562. this.listView1.Columns.Add(header11);
  563. ColumnHeader header12 = new ColumnHeader();
  564. header12.Text = PdnResources.GetString("Menu.microscope.text");
  565. this.listView1.Columns.Add(header12);
  566. }
  567. /// <summary>
  568. /// 初始化标尺列表
  569. /// </summary>
  570. private void InitListViewDate()
  571. {
  572. this.listView1.Items.Clear();
  573. List<mic_rulers> list = mic_rulers_BLL.FindAll();
  574. if (list != null)
  575. {
  576. for (int i = 0; i < list.Count; i++)
  577. {
  578. mic_rulers rule = list[i];
  579. if (this.ruleModel != null && this.ruleModel.id == rule.id)
  580. {
  581. continue;
  582. }
  583. ListViewItem item = new ListViewItem();
  584. item.Tag = rule.id;
  585. item.Text = "";
  586. if (configModel != null)
  587. {
  588. if (configModel.RulerId == rule.id)
  589. {
  590. //index = i;
  591. item.Text = "√";
  592. }
  593. }
  594. //计算每像素物理长度
  595. double proportion = Math.Round((double)rule.physical_length / rule.pixel_length, 4);
  596. string content = proportion.ToString() + InvariantData.unitsDictionary[(int)((MeasurementUnit)(Enum.ToObject(typeof(MeasurementUnit), rule.ruler_units)))].ToString() + "/" + PdnResources.GetString("MeasurementUnit.Pixel");
  597. item.SubItems.Add(rule.ruler_name);
  598. item.SubItems.Add(content);
  599. item.SubItems.Add(rule.gain_multiple.ToString());
  600. item.SubItems.Add(rule.pixel_length.ToString());
  601. item.SubItems.Add(rule.physical_length.ToString());
  602. item.SubItems.Add(InvariantData.unitsDictionary[(int)((MeasurementUnit)(Enum.ToObject(typeof(MeasurementUnit), rule.ruler_units)))].ToString());
  603. item.SubItems.Add(rule.ruler_width + "*" + rule.ruler_height);
  604. item.SubItems.Add(rule.ruler_zoom);
  605. item.SubItems.Add(rule.ruler_connector);
  606. item.SubItems.Add(rule.ruler_eyepiece);
  607. item.SubItems.Add(rule.ruler_camera);
  608. item.SubItems.Add(rule.objective_lens);
  609. item.SubItems.Add(rule.microscope);
  610. this.listView1.Items.Add(item);
  611. }
  612. }
  613. if (RuleListForm.viewItem != null)
  614. {
  615. //原暂存标尺为静态对象,无法多次添加到不同的listview,固重新new一个
  616. ListViewItem tempItem = new ListViewItem();
  617. tempItem.Text = RuleListForm.viewItem.Text;
  618. tempItem.Tag = RuleListForm.viewItem.Tag;
  619. tempItem.SubItems.Add(RuleListForm.viewItem.SubItems[1]);
  620. tempItem.SubItems.Add(RuleListForm.viewItem.SubItems[2]);
  621. tempItem.SubItems.Add(RuleListForm.viewItem.SubItems[3]);
  622. tempItem.SubItems.Add(RuleListForm.viewItem.SubItems[4]);
  623. tempItem.SubItems.Add(RuleListForm.viewItem.SubItems[5]);
  624. tempItem.SubItems.Add(RuleListForm.viewItem.SubItems[6]);
  625. tempItem.SubItems.Add(RuleListForm.viewItem.SubItems[7]);
  626. tempItem.SubItems.Add(RuleListForm.viewItem.SubItems[8]);
  627. tempItem.SubItems.Add(RuleListForm.viewItem.SubItems[9]);
  628. tempItem.SubItems.Add(RuleListForm.viewItem.SubItems[10]);
  629. tempItem.SubItems.Add(RuleListForm.viewItem.SubItems[11]);
  630. tempItem.SubItems.Add(RuleListForm.viewItem.SubItems[12]);
  631. this.listView1.Items.Add(tempItem);
  632. }
  633. if (RuleListForm.viewItemList != null && RuleListForm.viewItemList.Count > 0)
  634. {
  635. List<ListViewItem> tempListItem = new List<ListViewItem>();
  636. for (int i = 0; i < RuleListForm.viewItemList.Count; i++)
  637. {
  638. ListViewItem tempItem = new ListViewItem();
  639. tempItem.Text = RuleListForm.viewItemList[i].Text;
  640. tempItem.Tag = RuleListForm.viewItemList[i].Tag;
  641. tempItem.SubItems.Add(RuleListForm.viewItemList[i].SubItems[1]);
  642. tempItem.SubItems.Add(RuleListForm.viewItemList[i].SubItems[2]);
  643. tempItem.SubItems.Add(RuleListForm.viewItemList[i].SubItems[3]);
  644. tempItem.SubItems.Add(RuleListForm.viewItemList[i].SubItems[4]);
  645. tempItem.SubItems.Add(RuleListForm.viewItemList[i].SubItems[5]);
  646. tempItem.SubItems.Add(RuleListForm.viewItemList[i].SubItems[6]);
  647. tempItem.SubItems.Add(RuleListForm.viewItemList[i].SubItems[7]);
  648. tempItem.SubItems.Add(RuleListForm.viewItemList[i].SubItems[8]);
  649. tempItem.SubItems.Add(RuleListForm.viewItemList[i].SubItems[9]);
  650. tempItem.SubItems.Add(RuleListForm.viewItemList[i].SubItems[10]);
  651. tempItem.SubItems.Add(RuleListForm.viewItemList[i].SubItems[11]);
  652. tempItem.SubItems.Add(RuleListForm.viewItemList[i].SubItems[12]);
  653. tempListItem.Add(tempItem);
  654. }
  655. foreach (ListViewItem item in tempListItem)
  656. {
  657. this.listView1.Items.Add(item);
  658. }
  659. }
  660. }
  661. /// <summary>
  662. /// 关闭按钮
  663. /// </summary>
  664. /// <param name="sender"></param>
  665. /// <param name="e"></param>
  666. private void button3_Click(object sender, EventArgs e)
  667. {
  668. this.Close();
  669. }
  670. /// <summary>
  671. /// 编辑时初始化数据
  672. /// </summary>
  673. public void InitializeEditData()
  674. {
  675. if (this.ruleModel != null)
  676. {
  677. this.radioButton2.Checked = true;
  678. this.radioButton1.Visible = false;
  679. if (this.ruleModel.ruler_type == 2)
  680. {
  681. this.button2.Visible = false;
  682. this.textBox1.Text = this.ruleModel.ruler_name;
  683. this.numericUpDown2.Value = this.ruleModel.gain_multiple;
  684. this.numericUpDown1.Value = this.ruleModel.physical_length / 100;
  685. }
  686. if (this.ruleModel.ruler_type == 3)
  687. {
  688. this.panel1.Visible = false;
  689. this.panel2.Visible = true;
  690. ChangeButtonStyle(this.button2, this.button1);
  691. this.button1.Visible = false;
  692. this.textBox2.Text = this.ruleModel.ruler_name;
  693. this.numericUpDown3.Value = this.ruleModel.gain_multiple;
  694. this.comboBox1.SelectedIndex = this.ruleModel.ruler_units - 1;
  695. }
  696. }
  697. }
  698. /// <summary>
  699. /// 修改按钮样式
  700. /// </summary>
  701. /// <param name="displayButton">要修改的按钮</param>
  702. /// <param name="hideButton">要恢复的按钮</param>
  703. private void ChangeButtonStyle(Button displayButton, Button hideButton1)
  704. {
  705. hideButton1.BackColor = Color.FromArgb(255, 240, 240, 240);
  706. hideButton1.ForeColor = Color.FromArgb(255, 0, 0, 0);
  707. hideButton1.FlatStyle = FlatStyle.Standard;
  708. hideButton1.FlatAppearance.BorderSize = 1;
  709. displayButton.BackColor = Color.Gray;
  710. displayButton.ForeColor = Color.White;
  711. displayButton.FlatStyle = FlatStyle.Flat;
  712. displayButton.FlatAppearance.BorderSize = 0;
  713. }
  714. /// <summary>
  715. /// 任意标尺按钮
  716. /// </summary>
  717. /// <param name="sender"></param>
  718. /// <param name="e"></param>
  719. private void button1_Click(object sender, EventArgs e)
  720. {
  721. if (this.panel1.Visible)
  722. return;
  723. this.panel2.Visible = false;
  724. this.panel1.Visible = true;
  725. ChangeButtonStyle(this.button1, this.button2);
  726. }
  727. /// <summary>
  728. /// 推算标尺按钮
  729. /// </summary>
  730. /// <param name="sender"></param>
  731. /// <param name="e"></param>
  732. private void button2_Click(object sender, EventArgs e)
  733. {
  734. this.panel1.Visible = false;
  735. this.panel2.Visible = true;
  736. ChangeButtonStyle(this.button2, this.button1);
  737. }
  738. public mic_rulers mic_Rulers;
  739. /// <summary>
  740. /// 保存按钮
  741. /// </summary>
  742. /// <param name="sender"></param>
  743. /// <param name="e"></param>
  744. private void button4_Click(object sender, EventArgs e)
  745. {
  746. //新建
  747. if (this.status == 1)
  748. {
  749. //临时保存
  750. if (this.radioButton1.Checked)
  751. {
  752. //任意标尺
  753. if (this.panel1.Visible)
  754. {
  755. if (string.IsNullOrEmpty(this.textBox1.Text))
  756. {
  757. MessageBox.Show(PdnResources.GetString("Menu.Pleaseenterarulername.text"));
  758. return;
  759. }
  760. try
  761. {
  762. mic_Rulers = new mic_rulers();
  763. int id = 0;
  764. //判断标尺是否存在
  765. for (int i = 0; i < Program.instance.mic_rulersAll.Count; i++)
  766. {
  767. if (Program.instance.mic_rulersAll[i].ruler_name.Equals(this.textBox1.Text + "-" + PdnResources.GetString("Menu.temporary.Text")))
  768. {
  769. MessageBox.Show(PdnResources.GetString("Menu.hecurrentscalenamealreadyexists.Text"));
  770. return;
  771. }
  772. if (Program.instance.mic_rulersAll[i].id < id)
  773. {
  774. id = Program.instance.mic_rulersAll[i].id;
  775. }
  776. }
  777. mic_Rulers.id = id - 1;
  778. mic_Rulers.ruler_name = this.textBox1.Text + "-" + PdnResources.GetString("Menu.temporary.Text");
  779. mic_Rulers.gain_multiple = this.numericUpDown2.Value;
  780. mic_Rulers.pixel_length = 100;//固定1像素,乘以100
  781. mic_Rulers.physical_length = Convert.ToInt32(this.numericUpDown1.Value * 100);
  782. mic_Rulers.ruler_units = Program.instance.companyEnume[PdnResources.GetString("Menu.Micron.text")];
  783. mic_Rulers.ruler_width = 0;
  784. mic_Rulers.ruler_height = 0;
  785. Program.instance.mic_rulersAll.Add(mic_Rulers);
  786. //ListViewItem listViewItem = new ListViewItem();
  787. //listViewItem.SubItems.Add(this.textBox1.Text + "-"+ PdnResources.GetString("Menu.temporary.Text"));
  788. //listViewItem.SubItems.Add(this.numericUpDown2.Value.ToString());//放大倍数
  789. //listViewItem.SubItems.Add("100");//固定1像素,乘以100
  790. //listViewItem.SubItems.Add((Convert.ToInt32(this.numericUpDown1.Value * 100)).ToString());//物理长度
  791. //listViewItem.SubItems.Add(PdnResources.GetString("Menu.Micron.text"));
  792. //listViewItem.SubItems.Add("0*0");
  793. //listViewItem.SubItems.Add("");
  794. //listViewItem.SubItems.Add("");
  795. //listViewItem.SubItems.Add("");
  796. //listViewItem.SubItems.Add("");
  797. //listViewItem.SubItems.Add("");
  798. //listViewItem.SubItems.Add("");
  799. //listViewItem.Tag = "temporaryList";
  800. //RuleListForm.viewItemList.Add(listViewItem);
  801. }
  802. catch (Exception)
  803. {
  804. MessageBox.Show(PdnResources.GetString("Menu.Ruleradditionfaile.Text"));
  805. return;
  806. }
  807. }
  808. //推算标尺
  809. if (this.panel2.Visible)
  810. {
  811. if (string.IsNullOrEmpty(this.textBox2.Text))
  812. {
  813. MessageBox.Show(PdnResources.GetString("Menu.Pleaseenterarulername.text"));
  814. return;
  815. }
  816. if (this.listView1.SelectedItems == null || this.listView1.SelectedItems.Count == 0)
  817. {
  818. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselecarulerfirst.Text"));
  819. return;
  820. }
  821. try
  822. {
  823. mic_Rulers = new mic_rulers();
  824. int id = 0;
  825. //判断标尺是否存在
  826. for (int i = 0; i < Program.instance.mic_rulersAll.Count; i++)
  827. {
  828. if (Program.instance.mic_rulersAll[i].ruler_name.Equals(this.textBox2.Text + "-" + PdnResources.GetString("Menu.temporary.Text")))
  829. {
  830. MessageBox.Show(PdnResources.GetString("Menu.hecurrentscalenamealreadyexists.Text"));
  831. return;
  832. }
  833. if (Program.instance.mic_rulersAll[i].id < id)
  834. {
  835. id = Program.instance.mic_rulersAll[i].id;
  836. }
  837. }
  838. string[] str = this.listView1.SelectedItems[0].SubItems[7].Text.Split('*');//拆分像素
  839. decimal referenceMultiple = decimal.Parse(this.listView1.SelectedItems[0].SubItems[3].Text);//参考标尺放大倍数
  840. mic_Rulers.id = id - 1;
  841. mic_Rulers.ruler_name = this.textBox2.Text + "-" + PdnResources.GetString("Menu.temporary.Text");
  842. mic_Rulers.gain_multiple = this.numericUpDown3.Value;
  843. mic_Rulers.pixel_length = float.Parse(this.listView1.SelectedItems[0].SubItems[4].Text);
  844. mic_Rulers.physical_length = Convert.ToInt32(this.listView1.SelectedItems[0].SubItems[5].Text) * (referenceMultiple / this.numericUpDown3.Value);
  845. mic_Rulers.ruler_units = Program.instance.companyEnume[this.comboBox1.Text];
  846. mic_Rulers.ruler_width = int.Parse(str[0]);
  847. mic_Rulers.ruler_height = int.Parse(str[1]);
  848. mic_Rulers.ruler_zoom = this.listView1.SelectedItems[0].SubItems[8].Text;
  849. mic_Rulers.ruler_connector = this.listView1.SelectedItems[0].SubItems[9].Text;
  850. mic_Rulers.ruler_eyepiece = this.listView1.SelectedItems[0].SubItems[10].Text;
  851. mic_Rulers.ruler_camera = this.listView1.SelectedItems[0].SubItems[11].Text;
  852. mic_Rulers.objective_lens = this.listView1.SelectedItems[0].SubItems[12].Text;
  853. mic_Rulers.microscope = this.listView1.SelectedItems[0].SubItems[13].Text;
  854. Program.instance.mic_rulersAll.Add(mic_Rulers);
  855. //ListViewItem listViewItem = new ListViewItem();
  856. //listViewItem.SubItems.Add(this.textBox2.Text + "-"+ PdnResources.GetString("Menu.temporary.Text"));
  857. //listViewItem.SubItems.Add(this.numericUpDown3.Value.ToString());//放大倍数
  858. //listViewItem.SubItems.Add(this.listView1.SelectedItems[0].SubItems[3]);
  859. //listViewItem.SubItems.Add(this.listView1.SelectedItems[0].SubItems[4]);
  860. //listViewItem.SubItems.Add(this.comboBox1.Text);//单位
  861. ////string[] str = this.listView1.SelectedItems[0].SubItems[6].ToString().Split('*');
  862. //listViewItem.SubItems.Add(this.listView1.SelectedItems[0].SubItems[6]);
  863. //listViewItem.SubItems.Add(this.listView1.SelectedItems[0].SubItems[7]);
  864. //listViewItem.SubItems.Add(this.listView1.SelectedItems[0].SubItems[8]);
  865. //listViewItem.SubItems.Add(this.listView1.SelectedItems[0].SubItems[9]);
  866. //listViewItem.SubItems.Add(this.listView1.SelectedItems[0].SubItems[10]);
  867. //listViewItem.SubItems.Add(this.listView1.SelectedItems[0].SubItems[11]);
  868. //listViewItem.SubItems.Add(this.listView1.SelectedItems[0].SubItems[12]);
  869. //listViewItem.Tag = "temporaryList";
  870. //RuleListForm.viewItemList.Add(listViewItem);
  871. }
  872. catch (Exception ex)
  873. {
  874. MessageBox.Show(ex.Message/*PdnResources.GetString("Menu.Ruleradditionfaile.Text")*/);
  875. return;
  876. }
  877. }
  878. }
  879. //永久保存
  880. if (this.radioButton2.Checked)
  881. {
  882. //任意标尺
  883. if (this.panel1.Visible)
  884. {
  885. if (string.IsNullOrEmpty(this.textBox1.Text))
  886. {
  887. MessageBox.Show(PdnResources.GetString("Menu.Pleaseenterarulername.text"));
  888. return;
  889. }
  890. //判断标尺是否存在
  891. for (int i = 0; i < Program.instance.mic_rulersAll.Count; i++)
  892. {
  893. if (Program.instance.mic_rulersAll[i].ruler_name.Equals(this.textBox1.Text))
  894. {
  895. MessageBox.Show(PdnResources.GetString("Menu.hecurrentscalenamealreadyexists.Text"));
  896. return;
  897. }
  898. }
  899. try
  900. {
  901. //组织数据,保存到数据库
  902. mic_rulers rule = new mic_rulers();
  903. rule.ruler_name = this.textBox1.Text;
  904. rule.gain_multiple = this.numericUpDown2.Value;
  905. rule.pixel_length = 100;
  906. rule.physical_length = this.numericUpDown1.Value * 100;
  907. rule.ruler_units = Program.instance.companyEnume[PdnResources.GetString("Menu.Micron.text")];
  908. rule.ruler_width = 0;
  909. rule.ruler_height = 0;
  910. rule.ruler_zoom = "";
  911. rule.ruler_connector = "";
  912. rule.ruler_eyepiece = "";
  913. rule.ruler_camera = "";
  914. rule.objective_lens = "";
  915. rule.microscope = "";
  916. rule.ruler_type = 2;
  917. mic_rulers_BLL.Add(rule);
  918. Program.instance.mic_rulersAll.Add(rule);
  919. }
  920. catch (Exception)
  921. {
  922. MessageBox.Show(PdnResources.GetString("Menu.Ruleradditionfaile.Text"));
  923. return;
  924. }
  925. }
  926. //推算标尺
  927. if (this.panel2.Visible)
  928. {
  929. if (string.IsNullOrEmpty(this.textBox2.Text))
  930. {
  931. MessageBox.Show(PdnResources.GetString("Menu.Pleaseenterarulername.text"));
  932. return;
  933. }
  934. if (this.listView1.SelectedItems == null || this.listView1.SelectedItems.Count == 0)
  935. {
  936. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselecarulerfirst.Text"));
  937. return;
  938. }
  939. //判断标尺是否存在
  940. for (int i = 0; i < Program.instance.mic_rulersAll.Count; i++)
  941. {
  942. if (Program.instance.mic_rulersAll[i].ruler_name.Equals(this.textBox2.Text))
  943. {
  944. MessageBox.Show(PdnResources.GetString("Menu.hecurrentscalenamealreadyexists.Text"));
  945. return;
  946. }
  947. }
  948. try
  949. {
  950. //组织数据,保存到数据库
  951. mic_rulers rule = new mic_rulers();
  952. decimal referenceMultiple = decimal.Parse(this.listView1.SelectedItems[0].SubItems[3].Text);//参考标尺放大倍数
  953. rule.ruler_name = this.textBox2.Text;
  954. rule.gain_multiple = this.numericUpDown3.Value;
  955. rule.pixel_length = float.Parse(string.IsNullOrEmpty(this.listView1.SelectedItems[0].SubItems[4].Text) ? "0" :
  956. this.listView1.SelectedItems[0].SubItems[4].Text);
  957. rule.physical_length = decimal.Parse(string.IsNullOrEmpty(this.listView1.SelectedItems[0].SubItems[5].Text) ? "0" :
  958. this.listView1.SelectedItems[0].SubItems[5].Text) * (referenceMultiple / this.numericUpDown3.Value);
  959. rule.ruler_units = (int)this.comboBox1.SelectedValue;
  960. rule.ruler_width = Convert.ToInt32(string.IsNullOrEmpty(this.listView1.SelectedItems[0].SubItems[7].Text.Split('*')[0]) ? "0" :
  961. this.listView1.SelectedItems[0].SubItems[7].Text.Split('*')[0]);
  962. rule.ruler_height = Convert.ToInt32(string.IsNullOrEmpty(this.listView1.SelectedItems[0].SubItems[7].Text.Split('*')[1]) ? "0" :
  963. this.listView1.SelectedItems[0].SubItems[7].Text.Split('*')[1]);
  964. rule.ruler_zoom = this.listView1.SelectedItems[0].SubItems[8].Text;
  965. rule.ruler_connector = this.listView1.SelectedItems[0].SubItems[9].Text;
  966. rule.ruler_eyepiece = this.listView1.SelectedItems[0].SubItems[10].Text;
  967. rule.ruler_camera = this.listView1.SelectedItems[0].SubItems[11].Text;
  968. rule.objective_lens = this.listView1.SelectedItems[0].SubItems[12].Text;
  969. rule.microscope = this.listView1.SelectedItems[0].SubItems[13].Text;
  970. rule.ruler_type = 3;
  971. mic_rulers_BLL.Add(rule);
  972. Program.instance.mic_rulersAll.Add(rule);
  973. }
  974. catch (Exception)
  975. {
  976. MessageBox.Show(PdnResources.GetString("Menu.Ruleradditionfaile.Text"));
  977. return;
  978. }
  979. }
  980. }
  981. }
  982. //编辑
  983. if (this.status == 2 && this.ruleModel != null)
  984. {
  985. //任意标尺
  986. if (this.ruleModel.ruler_type == 2)
  987. {
  988. if (string.IsNullOrEmpty(this.textBox1.Text))
  989. {
  990. MessageBox.Show(PdnResources.GetString("Menu.Pleaseenterarulername.text"));
  991. return;
  992. }
  993. try
  994. {
  995. this.ruleModel.ruler_name = this.textBox1.Text;
  996. this.ruleModel.gain_multiple = this.numericUpDown2.Value;
  997. this.ruleModel.pixel_length = 100;
  998. this.ruleModel.physical_length = this.numericUpDown1.Value * 100;
  999. this.ruleModel.ruler_units = Program.instance.companyEnume[PdnResources.GetString("Menu.Micron.text")];
  1000. this.ruleModel.ruler_width = 0;
  1001. this.ruleModel.ruler_height = 0;
  1002. this.ruleModel.ruler_zoom = "";
  1003. this.ruleModel.ruler_connector = "";
  1004. this.ruleModel.ruler_eyepiece = "";
  1005. this.ruleModel.ruler_camera = "";
  1006. this.ruleModel.objective_lens = "";
  1007. this.ruleModel.microscope = "";
  1008. this.ruleModel.ruler_type = 2;
  1009. mic_rulers_BLL.Update(this.ruleModel);
  1010. }
  1011. catch (Exception)
  1012. {
  1013. MessageBox.Show(PdnResources.GetString("Menu.Ruleredifailed.Text"));
  1014. return;
  1015. }
  1016. }
  1017. //推算标尺
  1018. if (this.ruleModel.ruler_type == 3)
  1019. {
  1020. if (string.IsNullOrEmpty(this.textBox2.Text))
  1021. {
  1022. MessageBox.Show(PdnResources.GetString("Menu.Pleaseenterarulername.text"));
  1023. return;
  1024. }
  1025. if (this.listView1.SelectedItems == null || this.listView1.SelectedItems.Count == 0)
  1026. {
  1027. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselecarulerfirst.Text"));
  1028. return;
  1029. }
  1030. try
  1031. {
  1032. decimal referenceMultiple = decimal.Parse(this.listView1.SelectedItems[0].SubItems[3].Text);//参考标尺放大倍数
  1033. this.ruleModel.ruler_name = this.textBox2.Text;
  1034. this.ruleModel.gain_multiple = this.numericUpDown3.Value;
  1035. this.ruleModel.pixel_length = float.Parse(string.IsNullOrEmpty(this.listView1.SelectedItems[0].SubItems[4].Text) ? "0" :
  1036. this.listView1.SelectedItems[0].SubItems[4].Text);
  1037. this.ruleModel.physical_length = decimal.Parse(string.IsNullOrEmpty(this.listView1.SelectedItems[0].SubItems[5].Text) ? "0" :
  1038. this.listView1.SelectedItems[0].SubItems[5].Text) * (referenceMultiple / this.numericUpDown3.Value);
  1039. this.ruleModel.ruler_units = (int)this.comboBox1.SelectedValue;
  1040. this.ruleModel.ruler_width = Convert.ToInt32(string.IsNullOrEmpty(this.listView1.SelectedItems[0].SubItems[7].Text.Split('*')[0]) ? "0" :
  1041. this.listView1.SelectedItems[0].SubItems[7].Text.Split('*')[0]);
  1042. this.ruleModel.ruler_height = Convert.ToInt32(string.IsNullOrEmpty(this.listView1.SelectedItems[0].SubItems[7].Text.Split('*')[1]) ? "0" :
  1043. this.listView1.SelectedItems[0].SubItems[7].Text.Split('*')[1]);
  1044. this.ruleModel.ruler_zoom = this.listView1.SelectedItems[0].SubItems[8].Text;
  1045. this.ruleModel.ruler_connector = this.listView1.SelectedItems[0].SubItems[9].Text;
  1046. this.ruleModel.ruler_eyepiece = this.listView1.SelectedItems[0].SubItems[10].Text;
  1047. this.ruleModel.ruler_camera = this.listView1.SelectedItems[0].SubItems[11].Text;
  1048. this.ruleModel.objective_lens = this.listView1.SelectedItems[0].SubItems[12].Text;
  1049. this.ruleModel.microscope = this.listView1.SelectedItems[0].SubItems[13].Text;
  1050. this.ruleModel.ruler_type = 3;
  1051. mic_rulers_BLL.Update(this.ruleModel);
  1052. }
  1053. catch (Exception)
  1054. {
  1055. MessageBox.Show(PdnResources.GetString("Menu.Ruleredifailed.Text"));
  1056. return;
  1057. }
  1058. }
  1059. this.appWorkspace.RefreshActiveRuler();
  1060. }
  1061. //刷新标尺列表
  1062. this.appWorkspace.RefueshRuleList();
  1063. //刷新预览窗口
  1064. //if (CameraPreviewDialog.cameraPreviewDialog != null)
  1065. // CameraPreviewDialog.cameraPreviewDialog.BindingRule();
  1066. this.Close();
  1067. }
  1068. /// <summary>
  1069. /// 推算标尺的放大倍数改变
  1070. /// </summary>
  1071. /// <param name="sender"></param>
  1072. /// <param name="e"></param>
  1073. private void numericUpDown3_ValueChanged(object sender, EventArgs e)
  1074. {
  1075. GetCalculateRuler();
  1076. }
  1077. /// <summary>
  1078. /// 推算标尺的单位改变
  1079. /// </summary>
  1080. /// <param name="sender"></param>
  1081. /// <param name="e"></param>
  1082. private void comboBox1_SelectionChangeCommitted(object sender, EventArgs e)
  1083. {
  1084. GetCalculateRuler();
  1085. }
  1086. /// <summary>
  1087. /// 计算推算标尺并显示
  1088. /// </summary>
  1089. private void GetCalculateRuler()
  1090. {
  1091. if (this.listView1.SelectedItems == null || this.listView1.SelectedItems.Count == 0)
  1092. return;
  1093. else
  1094. {
  1095. double unitLength = (Convert.ToDouble(this.listView1.SelectedItems[0].SubItems[5].Text) / Convert.ToDouble(this.listView1.SelectedItems[0].SubItems[4].Text));
  1096. double finalUnitLength = unitLength * Convert.ToDouble(this.listView1.SelectedItems[0].SubItems[3].Text) / (double)this.numericUpDown3.Value;
  1097. int oldUnit = InvariantData.unitsDictionary.FirstOrDefault(q => q.Value == this.listView1.SelectedItems[0].SubItems[6].Text).Key;
  1098. int nowUnit = (int)this.comboBox1.SelectedValue;
  1099. switch (oldUnit)
  1100. {
  1101. case 1://英寸
  1102. switch (nowUnit)
  1103. {
  1104. case 1:
  1105. break;
  1106. case 2:
  1107. finalUnitLength = 2.54 * finalUnitLength;
  1108. break;
  1109. case 3:
  1110. finalUnitLength = 25.4 * finalUnitLength;
  1111. break;
  1112. case 4:
  1113. finalUnitLength = 25400 * finalUnitLength;
  1114. break;
  1115. case 5:
  1116. finalUnitLength = 25400000 * finalUnitLength;
  1117. break;
  1118. }
  1119. break;
  1120. case 2://厘米
  1121. switch (nowUnit)
  1122. {
  1123. case 1:
  1124. finalUnitLength = 0.3937008 * finalUnitLength;
  1125. break;
  1126. case 2:
  1127. break;
  1128. case 3:
  1129. finalUnitLength = 10 * finalUnitLength;
  1130. break;
  1131. case 4:
  1132. finalUnitLength = 10000 * finalUnitLength;
  1133. break;
  1134. case 5:
  1135. finalUnitLength = 10000000 * finalUnitLength;
  1136. break;
  1137. }
  1138. break;
  1139. case 3://毫米
  1140. switch (nowUnit)
  1141. {
  1142. case 1:
  1143. finalUnitLength = 0.0393701 * finalUnitLength;
  1144. break;
  1145. case 2:
  1146. finalUnitLength = 0.1 * finalUnitLength;
  1147. break;
  1148. case 3:
  1149. break;
  1150. case 4:
  1151. finalUnitLength = 1000 * finalUnitLength;
  1152. break;
  1153. case 5:
  1154. finalUnitLength = 1000000 * finalUnitLength;
  1155. break;
  1156. }
  1157. break;
  1158. case 4://微米
  1159. switch (nowUnit)
  1160. {
  1161. case 1:
  1162. finalUnitLength = 0.00003937007874 * finalUnitLength;
  1163. break;
  1164. case 2:
  1165. finalUnitLength = 0.0001 * finalUnitLength;
  1166. break;
  1167. case 3:
  1168. finalUnitLength = 0.001 * finalUnitLength;
  1169. break;
  1170. case 4:
  1171. break;
  1172. case 5:
  1173. finalUnitLength = 1000 * finalUnitLength;
  1174. break;
  1175. }
  1176. break;
  1177. case 5://纳米
  1178. switch (nowUnit)
  1179. {
  1180. case 1:
  1181. finalUnitLength = 3.9370e-8 * finalUnitLength;
  1182. break;
  1183. case 2:
  1184. finalUnitLength = 1e-7 * finalUnitLength;
  1185. break;
  1186. case 3:
  1187. finalUnitLength = 1e-6 * finalUnitLength;
  1188. break;
  1189. case 4:
  1190. finalUnitLength = 0.001 * finalUnitLength;
  1191. break;
  1192. case 5:
  1193. break;
  1194. }
  1195. break;
  1196. }
  1197. this.label8.Text = Math.Round(finalUnitLength, 4) + this.comboBox1.Text + "/" + PdnResources.GetString("Menu.Pixel.text");
  1198. }
  1199. }
  1200. /// <summary>
  1201. /// 选择标尺改变
  1202. /// </summary>
  1203. /// <param name="sender"></param>
  1204. /// <param name="e"></param>
  1205. private void listView1_SelectedIndexChanged(object sender, EventArgs e)
  1206. {
  1207. GetCalculateRuler();
  1208. }
  1209. }
  1210. }