CustomRulerDialog.cs 59 KB

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