12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235 |
- using PaintDotNet.Base.SettingModel;
- using PaintDotNet.DbOpreate.DbBll;
- using PaintDotNet.DbOpreate.DbModel;
- using PaintDotNet.ImageCollect;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Windows.Markup.Localizer;
- namespace PaintDotNet.Measuring
- {
- /// <summary>
- /// 自定义标尺
- /// </summary>
- internal class CustomRulerDialog : PdnBaseForm
- {
- private GroupBox groupBox1;
- private Button button3;
- private Button button2;
- private Button button1;
- private GroupBox groupBox2;
- private Button button4;
- private RadioButton radioButton2;
- private RadioButton radioButton1;
- private Panel panel1;
- private Label label3;
- private Label label2;
- private Label label1;
- private TextBox textBox1;
- private Panel panel2;
- private Label label6;
- private Label label5;
- private TextBox textBox2;
- private Label label4;
- private Panel panel3;
- private ListView listView1;
- private Label label8;
- private Label label7;
- private ComboBox comboBox1;
- /// <summary>
- /// 主配置,包含了选定的标尺的配置
- /// </summary>
- private ConfigModel configModel = Startup.instance.configModel;
- /// <summary>
- /// 工作控件
- /// </summary>
- private AppWorkspace appWorkspace;
- /// <summary>
- /// 标尺数据,编辑标尺时使用
- /// </summary>
- private mic_rulers ruleModel;
- private TextBox textBox3;
- private TextBox textBox4;
- private TextBox textBox5;
- /// <summary>
- /// 1新增 2编辑
- /// </summary>
- private int status;
- public CustomRulerDialog(AppWorkspace appWorkspace, mic_rulers ruleModel, int status)
- {
- this.status = status;
- this.appWorkspace = appWorkspace;
- this.ruleModel = ruleModel;
- InitializeComponent();
- InitializeLanguageText();
- InitOtherInfo();
- InitListViewHeader();
- InitListViewDate();
- if(this.ruleModel != null)
- InitializeEditData();
- }
- private void InitializeLanguageText()
- {
- this.groupBox1.Text = PdnResources.GetString("Menu.Type.text");
- this.button3.Text = PdnResources.GetString("Menu.File.Close.Text");
- this.button2.Text = PdnResources.GetString("Menu.Imagement.Rulersetting.Calculatescale.text");
- this.button1.Text = PdnResources.GetString("Menu.Imagement.Rulersetting.Anyruler.text");
- this.groupBox2.Text = PdnResources.GetString("Menu.Imagement.Rulersetting.Savetype.text");
- this.button4.Text = PdnResources.GetString("Menu.File.Save.Text");
- this.radioButton2.Text = PdnResources.GetString("Menu.Imagement.Rulersetting.Saveforever.text");
- this.radioButton1.Text = PdnResources.GetString("Menu.porarypreservation.Text");
- this.label3.Text = PdnResources.GetString("Menu.LabelAction.DrawGainNumber.Text") + ":";
- this.label2.Text = PdnResources.GetString("Menu.Imagement.Rulersetting.Micron/pixel.text") + ":";
- this.label1.Text = PdnResources.GetString("Menu.Rulername.text") + ":";
- this.label8.Text = PdnResources.GetString("Menu.nothing.Text");
- this.label7.Text = PdnResources.GetString("Menu.Imagement.Rulersetting.Currentrulercalculated:none.text") + ":";
- this.label6.Text = PdnResources.GetString("Menu.Imagement.Rulersetting.Calculatetheunit.text") + ":";
- this.label5.Text = PdnResources.GetString("Menu.Totalmagnification.text") + ":";
- this.label4.Text = PdnResources.GetString("Menu.Rulername.text") + ":";
- this.Text = PdnResources.GetString("Menu.user-definedruler.text");
- }
- private void InitializeComponent()
- {
- this.groupBox1 = new System.Windows.Forms.GroupBox();
- this.button3 = new System.Windows.Forms.Button();
- this.button2 = new System.Windows.Forms.Button();
- this.button1 = new System.Windows.Forms.Button();
- this.groupBox2 = new System.Windows.Forms.GroupBox();
- this.button4 = new System.Windows.Forms.Button();
- this.radioButton2 = new System.Windows.Forms.RadioButton();
- this.radioButton1 = new System.Windows.Forms.RadioButton();
- this.panel1 = new System.Windows.Forms.Panel();
- this.textBox4 = new System.Windows.Forms.TextBox();
- this.textBox3 = new System.Windows.Forms.TextBox();
- this.panel2 = new System.Windows.Forms.Panel();
- this.textBox5 = new System.Windows.Forms.TextBox();
- this.comboBox1 = new System.Windows.Forms.ComboBox();
- this.panel3 = new System.Windows.Forms.Panel();
- this.label8 = new System.Windows.Forms.Label();
- this.label7 = new System.Windows.Forms.Label();
- this.listView1 = new System.Windows.Forms.ListView();
- this.label6 = new System.Windows.Forms.Label();
- this.label5 = new System.Windows.Forms.Label();
- this.textBox2 = new System.Windows.Forms.TextBox();
- this.label4 = new System.Windows.Forms.Label();
- this.textBox1 = new System.Windows.Forms.TextBox();
- this.label3 = new System.Windows.Forms.Label();
- this.label2 = new System.Windows.Forms.Label();
- this.label1 = new System.Windows.Forms.Label();
- this.groupBox1.SuspendLayout();
- this.groupBox2.SuspendLayout();
- this.panel1.SuspendLayout();
- this.panel2.SuspendLayout();
- this.panel3.SuspendLayout();
- this.SuspendLayout();
- //
- // groupBox1
- //
- this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
- | System.Windows.Forms.AnchorStyles.Left)));
- this.groupBox1.Controls.Add(this.button3);
- this.groupBox1.Controls.Add(this.button2);
- this.groupBox1.Controls.Add(this.button1);
- this.groupBox1.Location = new System.Drawing.Point(13, 13);
- this.groupBox1.Name = "groupBox1";
- this.groupBox1.Size = new System.Drawing.Size(98, 462);
- this.groupBox1.TabIndex = 0;
- this.groupBox1.TabStop = false;
- //
- // button3
- //
- this.button3.Location = new System.Drawing.Point(10, 424);
- this.button3.Name = "button3";
- this.button3.Size = new System.Drawing.Size(75, 23);
- this.button3.TabIndex = 2;
- this.button3.Text = "关闭";
- this.button3.UseVisualStyleBackColor = true;
- this.button3.Click += new System.EventHandler(this.button3_Click);
- //
- // button2
- //
- this.button2.Location = new System.Drawing.Point(10, 82);
- this.button2.Name = "button2";
- this.button2.Size = new System.Drawing.Size(75, 23);
- this.button2.TabIndex = 1;
- this.button2.Text = "推算标尺";
- this.button2.UseVisualStyleBackColor = true;
- this.button2.Click += new System.EventHandler(this.button2_Click);
- //
- // button1
- //
- this.button1.Location = new System.Drawing.Point(10, 41);
- this.button1.Name = "button1";
- this.button1.Size = new System.Drawing.Size(75, 23);
- this.button1.TabIndex = 0;
- this.button1.Text = "任意标尺";
- this.button1.UseVisualStyleBackColor = true;
- this.button1.Click += new System.EventHandler(this.button1_Click);
- //
- // groupBox2
- //
- this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.groupBox2.Controls.Add(this.button4);
- this.groupBox2.Controls.Add(this.radioButton2);
- this.groupBox2.Controls.Add(this.radioButton1);
- this.groupBox2.Location = new System.Drawing.Point(118, 13);
- this.groupBox2.Name = "groupBox2";
- this.groupBox2.Size = new System.Drawing.Size(563, 54);
- this.groupBox2.TabIndex = 1;
- this.groupBox2.TabStop = false;
- this.groupBox2.Text = "保存类型";
- //
- // button4
- //
- this.button4.Location = new System.Drawing.Point(463, 19);
- this.button4.Name = "button4";
- this.button4.Size = new System.Drawing.Size(75, 23);
- this.button4.TabIndex = 2;
- this.button4.Text = "保存";
- this.button4.UseVisualStyleBackColor = true;
- this.button4.Click += new System.EventHandler(this.button4_Click);
- //
- // radioButton2
- //
- this.radioButton2.AutoSize = true;
- this.radioButton2.Location = new System.Drawing.Point(215, 22);
- this.radioButton2.Name = "radioButton2";
- this.radioButton2.Size = new System.Drawing.Size(71, 16);
- this.radioButton2.TabIndex = 1;
- this.radioButton2.TabStop = true;
- this.radioButton2.Text = "永久保存";
- this.radioButton2.UseVisualStyleBackColor = true;
- //
- // radioButton1
- //
- this.radioButton1.AutoSize = true;
- this.radioButton1.Checked = true;
- this.radioButton1.Location = new System.Drawing.Point(69, 22);
- this.radioButton1.Name = "radioButton1";
- this.radioButton1.Size = new System.Drawing.Size(71, 16);
- this.radioButton1.TabIndex = 0;
- this.radioButton1.TabStop = true;
- this.radioButton1.Text = "临时保存";
- this.radioButton1.UseVisualStyleBackColor = true;
- //
- // panel1
- //
- this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
- | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.panel1.Controls.Add(this.textBox4);
- this.panel1.Controls.Add(this.textBox3);
- this.panel1.Controls.Add(this.textBox1);
- this.panel1.Controls.Add(this.label3);
- this.panel1.Controls.Add(this.label2);
- this.panel1.Controls.Add(this.label1);
- this.panel1.Location = new System.Drawing.Point(118, 74);
- this.panel1.Name = "panel1";
- this.panel1.Size = new System.Drawing.Size(563, 401);
- this.panel1.TabIndex = 2;
- //
- // textBox4
- //
- this.textBox4.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
- | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.textBox4.Location = new System.Drawing.Point(118, 118);
- this.textBox4.Name = "textBox4";
- this.textBox4.Size = new System.Drawing.Size(139, 21);
- this.textBox4.TabIndex = 7;
- //
- // textBox3
- //
- this.textBox3.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
- | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.textBox3.Location = new System.Drawing.Point(118, 79);
- this.textBox3.Name = "textBox3";
- this.textBox3.Size = new System.Drawing.Size(139, 21);
- this.textBox3.TabIndex = 6;
- //
- // panel2
- //
- this.panel2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
- | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.panel2.Controls.Add(this.textBox5);
- this.panel2.Controls.Add(this.comboBox1);
- this.panel2.Controls.Add(this.panel3);
- this.panel2.Controls.Add(this.listView1);
- this.panel2.Controls.Add(this.label6);
- this.panel2.Controls.Add(this.label5);
- this.panel2.Controls.Add(this.textBox2);
- this.panel2.Controls.Add(this.label4);
- this.panel2.Location = new System.Drawing.Point(118, 74);
- this.panel2.Name = "panel2";
- this.panel2.Size = new System.Drawing.Size(563, 401);
- this.panel2.TabIndex = 5;
- //
- // textBox5
- //
- this.textBox5.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
- | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.textBox5.Location = new System.Drawing.Point(372, 36);
- this.textBox5.Name = "textBox5";
- this.textBox5.Size = new System.Drawing.Size(139, 21);
- this.textBox5.TabIndex = 9;
- //
- // comboBox1
- //
- this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
- this.comboBox1.FormattingEnabled = true;
- this.comboBox1.Location = new System.Drawing.Point(106, 76);
- this.comboBox1.Name = "comboBox1";
- this.comboBox1.Size = new System.Drawing.Size(134, 20);
- this.comboBox1.TabIndex = 8;
- this.comboBox1.SelectionChangeCommitted += new System.EventHandler(this.comboBox1_SelectionChangeCommitted);
- //
- // panel3
- //
- this.panel3.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.panel3.BackColor = System.Drawing.Color.DimGray;
- this.panel3.Controls.Add(this.label8);
- this.panel3.Controls.Add(this.label7);
- this.panel3.Location = new System.Drawing.Point(3, 363);
- this.panel3.Name = "panel3";
- this.panel3.Size = new System.Drawing.Size(557, 35);
- this.panel3.TabIndex = 7;
- //
- // label8
- //
- this.label8.AutoSize = true;
- this.label8.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
- this.label8.ForeColor = System.Drawing.Color.White;
- this.label8.Location = new System.Drawing.Point(188, 10);
- this.label8.Name = "label8";
- this.label8.Size = new System.Drawing.Size(0, 16);
- this.label8.TabIndex = 1;
- //
- // label7
- //
- this.label7.AutoSize = true;
- this.label7.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
- this.label7.ForeColor = System.Drawing.Color.White;
- this.label7.Location = new System.Drawing.Point(38, 10);
- this.label7.Name = "label7";
- this.label7.Size = new System.Drawing.Size(0, 16);
- this.label7.TabIndex = 0;
- //
- // listView1
- //
- this.listView1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.listView1.FullRowSelect = true;
- this.listView1.HideSelection = false;
- this.listView1.Location = new System.Drawing.Point(3, 115);
- this.listView1.MultiSelect = false;
- this.listView1.Name = "listView1";
- this.listView1.Size = new System.Drawing.Size(557, 242);
- this.listView1.TabIndex = 6;
- this.listView1.UseCompatibleStateImageBehavior = false;
- this.listView1.SelectedIndexChanged += new System.EventHandler(this.listView1_SelectedIndexChanged);
- //
- // label6
- //
- this.label6.AutoSize = true;
- this.label6.Location = new System.Drawing.Point(44, 79);
- this.label6.Name = "label6";
- this.label6.Size = new System.Drawing.Size(65, 12);
- this.label6.TabIndex = 3;
- this.label6.Text = "推算单位:";
- //
- // label5
- //
- this.label5.AutoSize = true;
- this.label5.Location = new System.Drawing.Point(309, 39);
- this.label5.Name = "label5";
- this.label5.Size = new System.Drawing.Size(65, 12);
- this.label5.TabIndex = 2;
- this.label5.Text = "放大倍数:";
- //
- // textBox2
- //
- this.textBox2.Location = new System.Drawing.Point(106, 36);
- this.textBox2.Name = "textBox2";
- this.textBox2.Size = new System.Drawing.Size(134, 21);
- this.textBox2.TabIndex = 1;
- //
- // label4
- //
- this.label4.AutoSize = true;
- this.label4.Location = new System.Drawing.Point(44, 39);
- this.label4.Name = "label4";
- this.label4.Size = new System.Drawing.Size(65, 12);
- this.label4.TabIndex = 0;
- this.label4.Text = "标尺名称:";
- //
- // textBox1
- //
- this.textBox1.Location = new System.Drawing.Point(118, 36);
- this.textBox1.Name = "textBox1";
- this.textBox1.Size = new System.Drawing.Size(139, 21);
- this.textBox1.TabIndex = 3;
- //
- // label3
- //
- this.label3.AutoSize = true;
- this.label3.Location = new System.Drawing.Point(50, 118);
- this.label3.Name = "label3";
- this.label3.Size = new System.Drawing.Size(0, 12);
- this.label3.TabIndex = 2;
- //
- // label2
- //
- this.label2.AutoSize = true;
- this.label2.Location = new System.Drawing.Point(44, 79);
- this.label2.Name = "label2";
- this.label2.Size = new System.Drawing.Size(0, 12);
- this.label2.TabIndex = 1;
- //
- // label1
- //
- this.label1.AutoSize = true;
- this.label1.Location = new System.Drawing.Point(48, 40);
- this.label1.Name = "label1";
- this.label1.Size = new System.Drawing.Size(0, 12);
- this.label1.TabIndex = 0;
- //
- // CustomRulerDialog
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
- this.ClientSize = new System.Drawing.Size(693, 487);
- this.Controls.Add(this.panel1);
- this.Controls.Add(this.panel2);
- this.Controls.Add(this.groupBox2);
- this.Controls.Add(this.groupBox1);
- this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
- this.MaximizeBox = false;
- this.MinimizeBox = false;
- this.Name = "CustomRulerDialog";
- this.Text = "自定义标尺";
- this.Controls.SetChildIndex(this.groupBox1, 0);
- this.Controls.SetChildIndex(this.groupBox2, 0);
- this.Controls.SetChildIndex(this.panel1, 0);
- this.groupBox1.ResumeLayout(false);
- this.groupBox2.ResumeLayout(false);
- this.groupBox2.PerformLayout();
- this.panel1.ResumeLayout(false);
- this.panel1.PerformLayout();
- this.panel2.ResumeLayout(false);
- this.panel2.PerformLayout();
- this.panel3.ResumeLayout(false);
- this.panel3.PerformLayout();
- this.ResumeLayout(false);
- }
- /// <summary>
- /// 初始化其他信息
- /// </summary>
- private void InitOtherInfo()
- {
- this.panel2.Visible = false;
- this.button1.BackColor = Color.Gray;
- this.button1.ForeColor = Color.White;
- this.button1.FlatStyle = FlatStyle.Flat;
- this.button1.FlatAppearance.BorderSize = 0;
- //单位选择
- this.comboBox1.DataSource = new BindingSource(InvariantData.ruleUnitsDictionary, null);
- this.comboBox1.SelectedIndex = 4;//默认选中微米
- this.comboBox1.DisplayMember = "Value";
- this.comboBox1.ValueMember = "Key";
- SystemLayer.SafeNativeMethods.SetCueText(this.textBox1, PdnResources.GetString("Menu.Pleaseenterarulername.text"));
- SystemLayer.SafeNativeMethods.SetCueText(this.textBox2, PdnResources.GetString("Menu.Pleaseenterarulername.text"));
- }
- /// <summary>
- /// 初始化标尺列头
- /// </summary>
- private void InitListViewHeader()
- {
- this.listView1.View = View.Details;
- ColumnHeader header0 = new ColumnHeader();
- header0.Text = PdnResources.GetString("Menu.Imagement.Rulersetting.active.text");
- header0.Width = 38;
- this.listView1.Columns.Add(header0);
- ColumnHeader header = new ColumnHeader();
- header.Text = PdnResources.GetString("Menu.Rulername.text");
- header.Width = 150;
- this.listView1.Columns.Add(header);
- ColumnHeader header1 = new ColumnHeader();
- header1.Text = PdnResources.GetString("Menu.unit.text") + "/" + PdnResources.GetString("MeasurementUnit.Pixel");
- header1.Width = 70;
- this.listView1.Columns.Add(header1);
- ColumnHeader header2 = new ColumnHeader();
- header2.Text = PdnResources.GetString("Menu.LabelAction.DrawGainNumber.Text");
- this.listView1.Columns.Add(header2);
- ColumnHeader header3 = new ColumnHeader();
- header3.Text = PdnResources.GetString("Menu.Pixellength.text");
- this.listView1.Columns.Add(header3);
- ColumnHeader header4 = new ColumnHeader();
- header4.Text = PdnResources.GetString("Menu.Physicallength.text");
- this.listView1.Columns.Add(header4);
- ColumnHeader header5 = new ColumnHeader();
- header5.Text = PdnResources.GetString("Menu.Unitsofmeasurement.text");
- this.listView1.Columns.Add(header5);
- ColumnHeader header6 = new ColumnHeader();
- header6.Text = PdnResources.GetString("Menu.ImageResolution.text");
- header6.Width = 80;
- this.listView1.Columns.Add(header6);
- ColumnHeader header7 = new ColumnHeader();
- header7.Text = PdnResources.GetString("Menu.magnificationchanger.text");
- this.listView1.Columns.Add(header7);
- ColumnHeader header8 = new ColumnHeader();
- header8.Text = PdnResources.GetString("Menu.interface.text");
- this.listView1.Columns.Add(header8);
- ColumnHeader header9 = new ColumnHeader();
- header9.Text = PdnResources.GetString("Menu.oculars.text");
- this.listView1.Columns.Add(header9);
- ColumnHeader header10 = new ColumnHeader();
- header10.Text = PdnResources.GetString("Menu.thecamera.text");
- this.listView1.Columns.Add(header10);
- ColumnHeader header11 = new ColumnHeader();
- header11.Text = PdnResources.GetString("Menu.Objectlens.text");
- this.listView1.Columns.Add(header11);
- ColumnHeader header12 = new ColumnHeader();
- header12.Text = PdnResources.GetString("Menu.microscope.text");
- this.listView1.Columns.Add(header12);
- }
- /// <summary>
- /// 初始化标尺列表
- /// </summary>
- private void InitListViewDate()
- {
- this.listView1.Items.Clear();
- List<mic_rulers> list = mic_rulers_BLL.FindAll();
- if (list != null)
- {
- for (int i = 0; i < list.Count; i++)
- {
- mic_rulers rule = list[i];
- if(this.ruleModel != null && this.ruleModel.id == rule.id)
- {
- continue;
- }
- ListViewItem item = new ListViewItem();
- item.Tag = rule.id;
- item.Text = "";
- if (configModel != null)
- {
- if (configModel.RulerId == rule.id)
- {
- //index = i;
- item.Text = "√";
- }
- }
- //计算每像素物理长度
- double proportion = Math.Round((double)rule.physical_length / rule.pixel_length,4);
- string content = proportion.ToString() + InvariantData.unitsDictionary[(int)((MeasurementUnit)(Enum.ToObject(typeof(MeasurementUnit), rule.ruler_units)))].ToString() + "/" + PdnResources.GetString("MeasurementUnit.Pixel");
- item.SubItems.Add(rule.ruler_name);
- item.SubItems.Add(content);
- item.SubItems.Add(rule.gain_multiple.ToString());
- item.SubItems.Add(rule.pixel_length.ToString());
- item.SubItems.Add(rule.physical_length.ToString());
- item.SubItems.Add(InvariantData.ruleUnitsDictionary[(int)((MeasurementUnit)(Enum.ToObject(typeof(MeasurementUnit), rule.ruler_units)))].ToString());
- item.SubItems.Add(rule.ruler_width + "*" + rule.ruler_height);
- item.SubItems.Add(rule.ruler_zoom);
- item.SubItems.Add(rule.ruler_connector);
- item.SubItems.Add(rule.ruler_eyepiece);
- item.SubItems.Add(rule.ruler_camera);
- item.SubItems.Add(rule.objective_lens);
- item.SubItems.Add(rule.microscope);
- this.listView1.Items.Add(item);
- }
- }
- if (RuleListForm.viewItem != null)
- {
- //原暂存标尺为静态对象,无法多次添加到不同的listview,固重新new一个
- ListViewItem tempItem = new ListViewItem();
- tempItem.Text = RuleListForm.viewItem.Text;
- tempItem.Tag = RuleListForm.viewItem.Tag;
- tempItem.SubItems.Add(RuleListForm.viewItem.SubItems[1]);
- tempItem.SubItems.Add(RuleListForm.viewItem.SubItems[2]);
- tempItem.SubItems.Add(RuleListForm.viewItem.SubItems[3]);
- tempItem.SubItems.Add(RuleListForm.viewItem.SubItems[4]);
- tempItem.SubItems.Add(RuleListForm.viewItem.SubItems[5]);
- tempItem.SubItems.Add(RuleListForm.viewItem.SubItems[6]);
- tempItem.SubItems.Add(RuleListForm.viewItem.SubItems[7]);
- tempItem.SubItems.Add(RuleListForm.viewItem.SubItems[8]);
- tempItem.SubItems.Add(RuleListForm.viewItem.SubItems[9]);
- tempItem.SubItems.Add(RuleListForm.viewItem.SubItems[10]);
- tempItem.SubItems.Add(RuleListForm.viewItem.SubItems[11]);
- tempItem.SubItems.Add(RuleListForm.viewItem.SubItems[12]);
- this.listView1.Items.Add(tempItem);
- }
- if(RuleListForm.viewItemList != null && RuleListForm.viewItemList.Count > 0)
- {
- List<ListViewItem> tempListItem = new List<ListViewItem>();
- for(int i = 0; i < RuleListForm.viewItemList.Count; i++)
- {
- ListViewItem tempItem = new ListViewItem();
- tempItem.Text = RuleListForm.viewItemList[i].Text;
- tempItem.Tag = RuleListForm.viewItemList[i].Tag;
- tempItem.SubItems.Add(RuleListForm.viewItemList[i].SubItems[1]);
- tempItem.SubItems.Add(RuleListForm.viewItemList[i].SubItems[2]);
- tempItem.SubItems.Add(RuleListForm.viewItemList[i].SubItems[3]);
- tempItem.SubItems.Add(RuleListForm.viewItemList[i].SubItems[4]);
- tempItem.SubItems.Add(RuleListForm.viewItemList[i].SubItems[5]);
- tempItem.SubItems.Add(RuleListForm.viewItemList[i].SubItems[6]);
- tempItem.SubItems.Add(RuleListForm.viewItemList[i].SubItems[7]);
- tempItem.SubItems.Add(RuleListForm.viewItemList[i].SubItems[8]);
- tempItem.SubItems.Add(RuleListForm.viewItemList[i].SubItems[9]);
- tempItem.SubItems.Add(RuleListForm.viewItemList[i].SubItems[10]);
- tempItem.SubItems.Add(RuleListForm.viewItemList[i].SubItems[11]);
- tempItem.SubItems.Add(RuleListForm.viewItemList[i].SubItems[12]);
- tempListItem.Add(tempItem);
- }
- foreach (ListViewItem item in tempListItem)
- {
- this.listView1.Items.Add(item);
- }
- }
- }
- /// <summary>
- /// 关闭按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button3_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- /// <summary>
- /// 编辑时初始化数据
- /// </summary>
- public void InitializeEditData()
- {
- if(this.ruleModel != null)
- {
- this.radioButton2.Checked = true;
- this.radioButton1.Visible = false;
- if(this.ruleModel.ruler_type == 2)
- {
- this.button2.Visible = false;
- this.textBox1.Text = this.ruleModel.ruler_name;
- this.textBox4.Text = this.ruleModel.gain_multiple.ToString();
- this.textBox3.Text = (this.ruleModel.physical_length / 100).ToString();
- }
- if (this.ruleModel.ruler_type == 3)
- {
- this.panel1.Visible = false;
- this.panel2.Visible = true;
- ChangeButtonStyle(this.button2, this.button1);
- this.button1.Visible = false;
- this.textBox2.Text = this.ruleModel.ruler_name;
- this.textBox5.Text = this.ruleModel.gain_multiple.ToString();
- this.comboBox1.SelectedIndex = this.ruleModel.ruler_units - 1;
- }
- }
- }
- /// <summary>
- /// 修改按钮样式
- /// </summary>
- /// <param name="displayButton">要修改的按钮</param>
- /// <param name="hideButton">要恢复的按钮</param>
- private void ChangeButtonStyle(Button displayButton, Button hideButton1)
- {
- hideButton1.BackColor = Color.FromArgb(255, 240, 240, 240);
- hideButton1.ForeColor = Color.FromArgb(255, 0, 0, 0);
- hideButton1.FlatStyle = FlatStyle.Standard;
- hideButton1.FlatAppearance.BorderSize = 1;
- displayButton.BackColor = Color.Gray;
- displayButton.ForeColor = Color.White;
- displayButton.FlatStyle = FlatStyle.Flat;
- displayButton.FlatAppearance.BorderSize = 0;
- }
- /// <summary>
- /// 任意标尺按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button1_Click(object sender, EventArgs e)
- {
- if (this.panel1.Visible)
- return;
- this.panel2.Visible = false;
- this.panel1.Visible = true;
- ChangeButtonStyle(this.button1, this.button2);
- }
- /// <summary>
- /// 推算标尺按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button2_Click(object sender, EventArgs e)
- {
- this.panel1.Visible = false;
- this.panel2.Visible = true;
- ChangeButtonStyle(this.button2, this.button1);
- }
- public mic_rulers mic_Rulers;
- /// <summary>
- /// 保存按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button4_Click(object sender, EventArgs e)
- {
- //新建
- if(this.status == 1)
- {
- //临时保存
- if (this.radioButton1.Checked)
- {
- //任意标尺
- if (this.panel1.Visible)
- {
- if (string.IsNullOrEmpty(this.textBox1.Text))
- {
- MessageBox.Show(PdnResources.GetString("Menu.Pleaseenterarulername.text"));
- return;
- }
- try
- {
- mic_Rulers = new mic_rulers();
- int id = 0;
- //判断标尺是否存在
- for (int i = 0; i < Startup.instance.mic_rulersAll.Count; i++)
- {
- if (Startup.instance.mic_rulersAll[i].ruler_name.Equals(this.textBox1.Text + "-" + PdnResources.GetString("Menu.temporary.Text")))
- {
- MessageBox.Show(PdnResources.GetString("Menu.hecurrentscalenamealreadyexists.Text"));
- return;
- }
- if (Startup.instance.mic_rulersAll[i].id < id)
- {
- id = Startup.instance.mic_rulersAll[i].id;
- }
- }
- mic_Rulers.id = id - 1;
- mic_Rulers.ruler_name = this.textBox1.Text + "-" + PdnResources.GetString("Menu.temporary.Text");
- mic_Rulers.gain_multiple = checkStringValue(this.textBox4.Text);
- mic_Rulers.pixel_length = 100;//固定1像素,乘以100
- mic_Rulers.physical_length = Convert.ToInt32(checkStringValue(this.textBox3.Text) * 100);
- mic_Rulers.ruler_units = Startup.instance.companyEnume[PdnResources.GetString("Menu.Micron.text")];
- mic_Rulers.ruler_width = 0;
- mic_Rulers.ruler_height = 0;
- Startup.instance.mic_rulersAll.Add(mic_Rulers);
- //ListViewItem listViewItem = new ListViewItem();
- //listViewItem.SubItems.Add(this.textBox1.Text + "-"+ PdnResources.GetString("Menu.temporary.Text"));
- //listViewItem.SubItems.Add(this.numericUpDown2.Value.ToString());//放大倍数
- //listViewItem.SubItems.Add("100");//固定1像素,乘以100
- //listViewItem.SubItems.Add((Convert.ToInt32(this.numericUpDown1.Value * 100)).ToString());//物理长度
- //listViewItem.SubItems.Add(PdnResources.GetString("Menu.Micron.text"));
- //listViewItem.SubItems.Add("0*0");
- //listViewItem.SubItems.Add("");
- //listViewItem.SubItems.Add("");
- //listViewItem.SubItems.Add("");
- //listViewItem.SubItems.Add("");
- //listViewItem.SubItems.Add("");
- //listViewItem.SubItems.Add("");
- //listViewItem.Tag = "temporaryList";
- //RuleListForm.viewItemList.Add(listViewItem);
- }
- catch(Exception)
- {
- MessageBox.Show(PdnResources.GetString("Menu.Ruleradditionfaile.Text"));
- return;
- }
-
- }
- //推算标尺
- if (this.panel2.Visible)
- {
- if (string.IsNullOrEmpty(this.textBox2.Text))
- {
- MessageBox.Show(PdnResources.GetString("Menu.Pleaseenterarulername.text"));
- return;
- }
- if (this.listView1.SelectedItems == null || this.listView1.SelectedItems.Count == 0)
- {
- MessageBox.Show(PdnResources.GetString("Menu.Pleaseselecarulerfirst.Text"));
- return;
- }
- try
- {
- mic_Rulers = new mic_rulers();
- int id = 0;
- //判断标尺是否存在
- for (int i = 0; i < Startup.instance.mic_rulersAll.Count; i++)
- {
- if (Startup.instance.mic_rulersAll[i].ruler_name.Equals(this.textBox2.Text + "-" + PdnResources.GetString("Menu.temporary.Text")))
- {
- MessageBox.Show(PdnResources.GetString("Menu.hecurrentscalenamealreadyexists.Text"));
- return;
- }
- if (Startup.instance.mic_rulersAll[i].id < id)
- {
- id = Startup.instance.mic_rulersAll[i].id;
- }
- }
- string[] str = this.listView1.SelectedItems[0].SubItems[7].Text.Split('*');//拆分像素
- decimal referenceMultiple = decimal.Parse(this.listView1.SelectedItems[0].SubItems[3].Text);//参考标尺放大倍数
- mic_Rulers.id = id - 1;
- mic_Rulers.ruler_name = this.textBox2.Text + "-" + PdnResources.GetString("Menu.temporary.Text");
- mic_Rulers.gain_multiple = checkStringValue(this.textBox5.Text);
- mic_Rulers.pixel_length = float.Parse(this.listView1.SelectedItems[0].SubItems[4].Text);
- mic_Rulers.physical_length = Convert.ToInt32(this.listView1.SelectedItems[0].SubItems[5].Text) * (referenceMultiple / checkStringValue(this.textBox5.Text));
- mic_Rulers.ruler_units = Startup.instance.companyEnume[this.comboBox1.Text.Split('\\')[0]];
- mic_Rulers.ruler_width = int.Parse(str[0]);
- mic_Rulers.ruler_height = int.Parse(str[1]);
- mic_Rulers.ruler_zoom = this.listView1.SelectedItems[0].SubItems[8].Text;
- mic_Rulers.ruler_connector = this.listView1.SelectedItems[0].SubItems[9].Text;
- mic_Rulers.ruler_eyepiece = this.listView1.SelectedItems[0].SubItems[10].Text;
- mic_Rulers.ruler_camera = this.listView1.SelectedItems[0].SubItems[11].Text;
- mic_Rulers.objective_lens = this.listView1.SelectedItems[0].SubItems[12].Text;
- mic_Rulers.microscope = this.listView1.SelectedItems[0].SubItems[13].Text;
- Startup.instance.mic_rulersAll.Add(mic_Rulers);
- //ListViewItem listViewItem = new ListViewItem();
- //listViewItem.SubItems.Add(this.textBox2.Text + "-"+ PdnResources.GetString("Menu.temporary.Text"));
- //listViewItem.SubItems.Add(this.numericUpDown3.Value.ToString());//放大倍数
- //listViewItem.SubItems.Add(this.listView1.SelectedItems[0].SubItems[3]);
- //listViewItem.SubItems.Add(this.listView1.SelectedItems[0].SubItems[4]);
- //listViewItem.SubItems.Add(this.comboBox1.Text);//单位
- ////string[] str = this.listView1.SelectedItems[0].SubItems[6].ToString().Split('*');
- //listViewItem.SubItems.Add(this.listView1.SelectedItems[0].SubItems[6]);
- //listViewItem.SubItems.Add(this.listView1.SelectedItems[0].SubItems[7]);
- //listViewItem.SubItems.Add(this.listView1.SelectedItems[0].SubItems[8]);
- //listViewItem.SubItems.Add(this.listView1.SelectedItems[0].SubItems[9]);
- //listViewItem.SubItems.Add(this.listView1.SelectedItems[0].SubItems[10]);
- //listViewItem.SubItems.Add(this.listView1.SelectedItems[0].SubItems[11]);
- //listViewItem.SubItems.Add(this.listView1.SelectedItems[0].SubItems[12]);
- //listViewItem.Tag = "temporaryList";
- //RuleListForm.viewItemList.Add(listViewItem);
- }
- catch (Exception ex)
- {
-
- MessageBox.Show(ex.Message/*PdnResources.GetString("Menu.Ruleradditionfaile.Text")*/);
- return;
- }
-
- }
- }
- //永久保存
- if (this.radioButton2.Checked)
- {
- //任意标尺
- if (this.panel1.Visible)
- {
- if (string.IsNullOrEmpty(this.textBox1.Text))
- {
- MessageBox.Show(PdnResources.GetString("Menu.Pleaseenterarulername.text"));
- return;
- }
- //判断标尺是否存在
- for (int i = 0; i < Startup.instance.mic_rulersAll.Count; i++)
- {
- if (Startup.instance.mic_rulersAll[i].ruler_name.Equals(this.textBox1.Text))
- {
- MessageBox.Show(PdnResources.GetString("Menu.hecurrentscalenamealreadyexists.Text"));
- return;
- }
- }
- try
- {
- //组织数据,保存到数据库
- mic_rulers rule = new mic_rulers();
- rule.ruler_name = this.textBox1.Text;
- rule.gain_multiple = checkStringValue(this.textBox4.Text);
- rule.pixel_length = 1;
- rule.physical_length = checkStringValue(this.textBox3.Text);
- rule.ruler_units = Startup.instance.companyEnume[PdnResources.GetString("Menu.Micron.text")];
- rule.ruler_width = 0;
- rule.ruler_height = 0;
- rule.ruler_zoom = "";
- rule.ruler_connector = "";
- rule.ruler_eyepiece = "";
- rule.ruler_camera = "";
- rule.objective_lens = "";
- rule.microscope = "";
- rule.ruler_type = 2;
- mic_rulers_BLL.Add(rule);
- Startup.instance.mic_rulersAll.Add(rule);
- }
- catch(Exception)
- {
- MessageBox.Show(PdnResources.GetString("Menu.Ruleradditionfaile.Text"));
- return;
- }
- }
- //推算标尺
- if (this.panel2.Visible)
- {
- if (string.IsNullOrEmpty(this.textBox2.Text))
- {
- MessageBox.Show(PdnResources.GetString("Menu.Pleaseenterarulername.text"));
- return;
- }
- if (this.listView1.SelectedItems == null || this.listView1.SelectedItems.Count == 0)
- {
- MessageBox.Show(PdnResources.GetString("Menu.Pleaseselecarulerfirst.Text"));
- return;
- }
- //判断标尺是否存在
- for (int i = 0; i < Startup.instance.mic_rulersAll.Count; i++)
- {
- if (Startup.instance.mic_rulersAll[i].ruler_name.Equals(this.textBox2.Text))
- {
- MessageBox.Show(PdnResources.GetString("Menu.hecurrentscalenamealreadyexists.Text"));
- return;
- }
- }
- try
- {
- //组织数据,保存到数据库
- mic_rulers rule = new mic_rulers();
- decimal referenceMultiple = decimal.Parse(this.listView1.SelectedItems[0].SubItems[3].Text);//参考标尺放大倍数
- rule.ruler_name = this.textBox2.Text;
- rule.gain_multiple = checkStringValue(this.textBox5.Text);
- rule.pixel_length = float.Parse(string.IsNullOrEmpty(this.listView1.SelectedItems[0].SubItems[4].Text) ? "0" :
- this.listView1.SelectedItems[0].SubItems[4].Text);
- rule.physical_length = decimal.Parse(string.IsNullOrEmpty(this.listView1.SelectedItems[0].SubItems[5].Text) ? "0" :
- this.listView1.SelectedItems[0].SubItems[5].Text) * (referenceMultiple/ checkStringValue(this.textBox5.Text));
- rule.ruler_units = (int)this.comboBox1.SelectedValue;
- rule.ruler_width = Convert.ToInt32(string.IsNullOrEmpty(this.listView1.SelectedItems[0].SubItems[7].Text.Split('*')[0]) ? "0" :
- this.listView1.SelectedItems[0].SubItems[7].Text.Split('*')[0]);
- rule.ruler_height = Convert.ToInt32(string.IsNullOrEmpty(this.listView1.SelectedItems[0].SubItems[7].Text.Split('*')[1]) ? "0" :
- this.listView1.SelectedItems[0].SubItems[7].Text.Split('*')[1]);
- rule.ruler_zoom = this.listView1.SelectedItems[0].SubItems[8].Text;
- rule.ruler_connector = this.listView1.SelectedItems[0].SubItems[9].Text;
- rule.ruler_eyepiece = this.listView1.SelectedItems[0].SubItems[10].Text;
- rule.ruler_camera = this.listView1.SelectedItems[0].SubItems[11].Text;
- rule.objective_lens = this.listView1.SelectedItems[0].SubItems[12].Text;
- rule.microscope = this.listView1.SelectedItems[0].SubItems[13].Text;
- rule.ruler_type = 3;
- mic_rulers_BLL.Add(rule);
- Startup.instance.mic_rulersAll.Add(rule);
- }
- catch (Exception)
- {
- MessageBox.Show(PdnResources.GetString("Menu.Ruleradditionfaile.Text"));
- return;
- }
- }
- }
- }
- //编辑
- if(this.status == 2 && this.ruleModel != null)
- {
- //任意标尺
- if (this.ruleModel.ruler_type == 2)
- {
- if (string.IsNullOrEmpty(this.textBox1.Text))
- {
- MessageBox.Show(PdnResources.GetString("Menu.Pleaseenterarulername.text"));
- return;
- }
- try
- {
- this.ruleModel.ruler_name = this.textBox1.Text;
- this.ruleModel.gain_multiple = checkStringValue(this.textBox4.Text);
- this.ruleModel.pixel_length = 100;
- this.ruleModel.physical_length = checkStringValue(this.textBox3.Text) * 100;
- this.ruleModel.ruler_units = Startup.instance.companyEnume[PdnResources.GetString("Menu.Micron.text")];
- this.ruleModel.ruler_width = 0;
- this.ruleModel.ruler_height = 0;
- this.ruleModel.ruler_zoom = "";
- this.ruleModel.ruler_connector = "";
- this.ruleModel.ruler_eyepiece = "";
- this.ruleModel.ruler_camera = "";
- this.ruleModel.objective_lens = "";
- this.ruleModel.microscope = "";
- this.ruleModel.ruler_type = 2;
- mic_rulers_BLL.Update(this.ruleModel);
- }
- catch(Exception)
- {
- MessageBox.Show(PdnResources.GetString("Menu.Ruleredifailed.Text"));
- return;
- }
- }
- //推算标尺
- if (this.ruleModel.ruler_type == 3)
- {
- if (string.IsNullOrEmpty(this.textBox2.Text))
- {
- MessageBox.Show(PdnResources.GetString("Menu.Pleaseenterarulername.text"));
- return;
- }
- if (this.listView1.SelectedItems == null || this.listView1.SelectedItems.Count == 0)
- {
- MessageBox.Show(PdnResources.GetString("Menu.Pleaseselecarulerfirst.Text"));
- return;
- }
- try
- {
- decimal referenceMultiple = decimal.Parse(this.listView1.SelectedItems[0].SubItems[3].Text);//参考标尺放大倍数
- this.ruleModel.ruler_name = this.textBox2.Text;
- this.ruleModel.gain_multiple = checkStringValue(this.textBox5.Text);
- this.ruleModel.pixel_length = float.Parse(string.IsNullOrEmpty(this.listView1.SelectedItems[0].SubItems[4].Text) ? "0" :
- this.listView1.SelectedItems[0].SubItems[4].Text);
- this.ruleModel.physical_length = decimal.Parse(string.IsNullOrEmpty(this.listView1.SelectedItems[0].SubItems[5].Text) ? "0" :
- this.listView1.SelectedItems[0].SubItems[5].Text) * (referenceMultiple / checkStringValue(this.textBox5.Text));
- this.ruleModel.ruler_units = (int)this.comboBox1.SelectedValue;
- this.ruleModel.ruler_width = Convert.ToInt32(string.IsNullOrEmpty(this.listView1.SelectedItems[0].SubItems[7].Text.Split('*')[0]) ? "0" :
- this.listView1.SelectedItems[0].SubItems[7].Text.Split('*')[0]);
- this.ruleModel.ruler_height = Convert.ToInt32(string.IsNullOrEmpty(this.listView1.SelectedItems[0].SubItems[7].Text.Split('*')[1]) ? "0" :
- this.listView1.SelectedItems[0].SubItems[7].Text.Split('*')[1]);
- this.ruleModel.ruler_zoom = this.listView1.SelectedItems[0].SubItems[8].Text;
- this.ruleModel.ruler_connector = this.listView1.SelectedItems[0].SubItems[9].Text;
- this.ruleModel.ruler_eyepiece = this.listView1.SelectedItems[0].SubItems[10].Text;
- this.ruleModel.ruler_camera = this.listView1.SelectedItems[0].SubItems[11].Text;
- this.ruleModel.objective_lens = this.listView1.SelectedItems[0].SubItems[12].Text;
- this.ruleModel.microscope = this.listView1.SelectedItems[0].SubItems[13].Text;
- this.ruleModel.ruler_type = 3;
- mic_rulers_BLL.Update(this.ruleModel);
- }
- catch (Exception)
- {
- MessageBox.Show(PdnResources.GetString("Menu.Ruleredifailed.Text"));
- return;
- }
- }
- this.appWorkspace.RefreshActiveRuler();
- }
- //刷新标尺列表
- this.appWorkspace.RefueshRuleList();
- //刷新预览窗口
- if (CameraPreviewDialog.cameraPreviewDialog != null)
- CameraPreviewDialog.cameraPreviewDialog.BindingRule();
- this.Close();
- }
- /// <summary>
- /// 推算标尺的放大倍数改变
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void numericUpDown3_ValueChanged(object sender, EventArgs e)
- {
- GetCalculateRuler();
- }
- /// <summary>
- /// 推算标尺的单位改变
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void comboBox1_SelectionChangeCommitted(object sender, EventArgs e)
- {
- GetCalculateRuler();
- }
- /// <summary>
- /// 计算推算标尺并显示
- /// </summary>
- private void GetCalculateRuler()
- {
- if (this.listView1.SelectedItems == null || this.listView1.SelectedItems.Count == 0)
- return;
- else
- {
- double unitLength = (Convert.ToDouble(this.listView1.SelectedItems[0].SubItems[5].Text) / Convert.ToDouble(this.listView1.SelectedItems[0].SubItems[4].Text));
- double finalUnitLength = unitLength * Convert.ToDouble(this.listView1.SelectedItems[0].SubItems[3].Text) / (double)checkStringValue(this.textBox5.Text);
- int oldUnit = InvariantData.ruleUnitsDictionary.FirstOrDefault(q => q.Value == this.listView1.SelectedItems[0].SubItems[6].Text).Key;
- int nowUnit = (int)this.comboBox1.SelectedValue;
- switch (oldUnit)
- {
- case 1://英寸
- switch (nowUnit)
- {
- case 1:
- break;
- case 2:
- finalUnitLength = 2.54 * finalUnitLength;
- break;
- case 3:
- finalUnitLength = 25.4 * finalUnitLength;
- break;
- case 4:
- finalUnitLength = 25400 * finalUnitLength;
- break;
- case 5:
- finalUnitLength = 25400000 * finalUnitLength;
- break;
- }
- break;
- case 2://厘米
- switch (nowUnit)
- {
- case 1:
- finalUnitLength = 0.3937008 * finalUnitLength;
- break;
- case 2:
- break;
- case 3:
- finalUnitLength = 10 * finalUnitLength;
- break;
- case 4:
- finalUnitLength = 10000 * finalUnitLength;
- break;
- case 5:
- finalUnitLength = 10000000 * finalUnitLength;
- break;
- }
- break;
- case 3://毫米
- switch (nowUnit)
- {
- case 1:
- finalUnitLength = 0.0393701 * finalUnitLength;
- break;
- case 2:
- finalUnitLength = 0.1 * finalUnitLength;
- break;
- case 3:
- break;
- case 4:
- finalUnitLength = 1000 * finalUnitLength;
- break;
- case 5:
- finalUnitLength = 1000000 * finalUnitLength;
- break;
- }
- break;
- case 4://微米
- switch (nowUnit)
- {
- case 1:
- finalUnitLength = 0.00003937007874 * finalUnitLength;
- break;
- case 2:
- finalUnitLength = 0.0001 * finalUnitLength;
- break;
- case 3:
- finalUnitLength = 0.001 * finalUnitLength;
- break;
- case 4:
- break;
- case 5:
- finalUnitLength = 1000 * finalUnitLength;
- break;
- }
- break;
- case 5://纳米
- switch (nowUnit)
- {
- case 1:
- finalUnitLength = 3.9370e-8 * finalUnitLength;
- break;
- case 2:
- finalUnitLength = 1e-7 * finalUnitLength;
- break;
- case 3:
- finalUnitLength = 1e-6 * finalUnitLength;
- break;
- case 4:
- finalUnitLength = 0.001 * finalUnitLength;
- break;
- case 5:
- break;
- }
- break;
- }
- this.label8.Text = Math.Round(finalUnitLength, 4) + this.comboBox1.Text + "/"+ PdnResources.GetString("Menu.Pixel.text");
- }
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="value"></param>
- /// <returns></returns>
- private decimal checkStringValue(string str)
- {
- try
- {
- decimal value = Convert.ToDecimal(str);
- return value;
- }
- catch (Exception)
- {
- return 1;
- }
- }
- /// <summary>
- /// 选择标尺改变
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void listView1_SelectedIndexChanged(object sender, EventArgs e)
- {
- GetCalculateRuler();
- }
- }
- }
|