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 { /// /// 自定义标尺 /// 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; /// /// 主配置,包含了选定的标尺的配置 /// private ConfigModel configModel = Startup.instance.configModel; /// /// 工作控件 /// private AppWorkspace appWorkspace; /// /// 标尺数据,编辑标尺时使用 /// private mic_rulers ruleModel; private TextBox textBox3; private TextBox textBox4; private TextBox textBox5; /// /// 1新增 2编辑 /// 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); } /// /// 初始化其他信息 /// 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")); } /// /// 初始化标尺列头 /// 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); } /// /// 初始化标尺列表 /// private void InitListViewDate() { this.listView1.Items.Clear(); List 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 tempListItem = new List(); 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); } } } /// /// 关闭按钮 /// /// /// private void button3_Click(object sender, EventArgs e) { this.Close(); } /// /// 编辑时初始化数据 /// 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; } } } /// /// 修改按钮样式 /// /// 要修改的按钮 /// 要恢复的按钮 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; } /// /// 任意标尺按钮 /// /// /// 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); } /// /// 推算标尺按钮 /// /// /// 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; /// /// 保存按钮 /// /// /// 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(); } /// /// 推算标尺的放大倍数改变 /// /// /// private void numericUpDown3_ValueChanged(object sender, EventArgs e) { GetCalculateRuler(); } /// /// 推算标尺的单位改变 /// /// /// private void comboBox1_SelectionChangeCommitted(object sender, EventArgs e) { GetCalculateRuler(); } /// /// 计算推算标尺并显示 /// 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"); } } /// /// /// /// /// private decimal checkStringValue(string str) { try { decimal value = Convert.ToDecimal(str); return value; } catch (Exception) { return 1; } } /// /// 选择标尺改变 /// /// /// private void listView1_SelectedIndexChanged(object sender, EventArgs e) { GetCalculateRuler(); } } }