using Resources; using SmartCoalApplication.Base; using SmartCoalApplication.Base.CommTool; using SmartCoalApplication.Base.SettingModel; using SmartCoalApplication.Core; using SmartCoalApplication.PluginAssemblys; using SmartCoalApplication.Resources; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace SmartCoalApplication.Measure { internal class MeasureAreaDialog : PdnBaseForm { /// /// 主配置文件的model /// private ConfigModel configModel = Program.instance.configModel; /// /// 操作区控件 /// private GroupBox groupBox1; private Label label1; private ComboBox comboBox1; private Button button4; private Button button3; private Button button2; private GroupBox groupBox2; private ConfigModel config = Program.instance.configModel; private System.Windows.Forms.Panel linePanel; private System.Windows.Forms.Label label41; private System.Windows.Forms.Label label51; private System.Windows.Forms.Label label61; private ComboBox comboBox21; private NumericUpDown numericUpDown11; private Button button5; /// /// 测量的样式 /// private MeasureAreaModel measureAreaModel = Program.instance.measureAreaModel; /// /// 另存为弹出框显示 /// private CreateNameDialog dialog; /// /// 操作样式下拉数据 /// private List files = new List(); /// /// 另存为文件名 /// private string newName; /// /// 选中的测量类型 /// private int selectId; private int initflag = 0; private AppWorkspace appWorkspace; ColorsForm colorsForm1; private DocumentWorkspaceWindow documentWorkspaceWindow; public MeasureAreaDialog(AppWorkspace appWorkspace,DocumentWorkspaceWindow documentWorkspaceWindow = null) { this.appWorkspace = appWorkspace; this.documentWorkspaceWindow = documentWorkspaceWindow; InitializeComponent(); InitializeLanguageText(); InitializeComponent2(); this.Icon = PdnInfo.AppIcon; //绑定线样式数据 this.comboBox21.Items.AddRange(InvariantData.dashStyles); InitializeData(); if (this.documentWorkspaceWindow != null) { this.label1.Visible = false; this.comboBox1.Visible = false; this.button3.Visible = false; this.button4.Visible = false; } else { this.label1.Visible = true; this.comboBox1.Visible = true; this.button3.Visible = true; this.button4.Visible = true; } } private void InitializeLanguageText() { this.label1.Text = PdnResources.GetString("Menu.Currentoperationstyle.text") + ":"; this.button4.Text = PdnResources.GetString("Menu.Edit.Delete.Text"); this.button3.Text = PdnResources.GetString("Menu.File.SaveAs.Text"); this.button2.Text = PdnResources.GetString("Menu.File.Save.Text"); this.groupBox2.Text = PdnResources.GetString("Menu.Setting.Text"); this.label61.Text = PdnResources.GetString("Menu.Linestyle.Text") + ":"; this.label51.Text = PdnResources.GetString("Menu.Set.Rulersettings.Linewidth.text") + ":"; this.label41.Text = PdnResources.GetString("Menu.Set.Rulersettings.Linecolor.text") + ":"; this.Text = PdnResources.GetString("Menu.Setting.MeasureSetting.Text"); this.groupBox1.Text = PdnResources.GetString("Menu.operation.text"); } private void InitializeComponent() { this.groupBox1 = new System.Windows.Forms.GroupBox(); this.label1 = new System.Windows.Forms.Label(); this.comboBox1 = new System.Windows.Forms.ComboBox(); this.button4 = new System.Windows.Forms.Button(); this.button3 = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button(); this.groupBox2 = new System.Windows.Forms.GroupBox(); this.numericUpDown11 = new System.Windows.Forms.NumericUpDown(); this.comboBox21 = new System.Windows.Forms.ComboBox(); this.label61 = new System.Windows.Forms.Label(); this.label51 = new System.Windows.Forms.Label(); this.linePanel = new System.Windows.Forms.Panel(); this.label41 = new System.Windows.Forms.Label(); this.button5 = new System.Windows.Forms.Button(); this.groupBox1.SuspendLayout(); this.groupBox2.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown11)).BeginInit(); this.SuspendLayout(); // // groupBox1 // this.groupBox1.Controls.Add(this.label1); this.groupBox1.Controls.Add(this.comboBox1); this.groupBox1.Controls.Add(this.button4); this.groupBox1.Controls.Add(this.button3); this.groupBox1.Controls.Add(this.button2); this.groupBox1.Location = new System.Drawing.Point(15, 15); this.groupBox1.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.groupBox1.Name = "groupBox1"; this.groupBox1.Padding = new System.Windows.Forms.Padding(4, 4, 4, 4); this.groupBox1.Size = new System.Drawing.Size(639, 72); this.groupBox1.TabIndex = 3; this.groupBox1.TabStop = false; this.groupBox1.Text = "操作"; // // label1 // this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(25, 31); this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(112, 15); this.label1.TabIndex = 5; this.label1.Text = "当前操作样式:"; // // comboBox1 // this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.comboBox1.FormattingEnabled = true; this.comboBox1.Location = new System.Drawing.Point(144, 28); this.comboBox1.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.comboBox1.Name = "comboBox1"; this.comboBox1.Size = new System.Drawing.Size(144, 23); this.comboBox1.TabIndex = 4; this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged); // // button4 // this.button4.Location = new System.Drawing.Point(319, 25); this.button4.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.button4.Name = "button4"; this.button4.Size = new System.Drawing.Size(94, 29); this.button4.TabIndex = 3; this.button4.Text = "删除"; this.button4.UseVisualStyleBackColor = true; this.button4.Click += new System.EventHandler(this.Button4_Click); // // button3 // this.button3.Location = new System.Drawing.Point(422, 25); this.button3.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.button3.Name = "button3"; this.button3.Size = new System.Drawing.Size(94, 29); 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(524, 25); this.button2.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(94, 29); this.button2.TabIndex = 1; this.button2.Text = "保存"; this.button2.UseVisualStyleBackColor = true; this.button2.Click += new System.EventHandler(this.Button2_Click); // // groupBox2 // this.groupBox2.Controls.Add(this.numericUpDown11); this.groupBox2.Controls.Add(this.comboBox21); this.groupBox2.Controls.Add(this.label61); this.groupBox2.Controls.Add(this.label51); this.groupBox2.Controls.Add(this.linePanel); this.groupBox2.Controls.Add(this.label41); this.groupBox2.Location = new System.Drawing.Point(15, 95); this.groupBox2.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.groupBox2.Name = "groupBox2"; this.groupBox2.Padding = new System.Windows.Forms.Padding(4, 4, 4, 4); this.groupBox2.Size = new System.Drawing.Size(639, 136); this.groupBox2.TabIndex = 6; this.groupBox2.TabStop = false; this.groupBox2.Text = "设置"; // // numericUpDown11 // this.numericUpDown11.Location = new System.Drawing.Point(110, 61); this.numericUpDown11.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.numericUpDown11.Name = "numericUpDown11"; this.numericUpDown11.Size = new System.Drawing.Size(190, 25); this.numericUpDown11.TabIndex = 14; // // comboBox21 // this.comboBox21.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.comboBox21.FormattingEnabled = true; this.comboBox21.Location = new System.Drawing.Point(110, 94); this.comboBox21.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.comboBox21.Name = "comboBox21"; this.comboBox21.Size = new System.Drawing.Size(189, 23); this.comboBox21.TabIndex = 13; // // label61 // this.label61.AutoSize = true; this.label61.Location = new System.Drawing.Point(12, 99); this.label61.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label61.Name = "label61"; this.label61.Size = new System.Drawing.Size(82, 15); this.label61.TabIndex = 9; this.label61.Text = "线条样式:"; // // label51 // this.label51.AutoSize = true; this.label51.Location = new System.Drawing.Point(12, 65); this.label51.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label51.Name = "label51"; this.label51.Size = new System.Drawing.Size(82, 15); this.label51.TabIndex = 8; this.label51.Text = "线条宽度:"; // // linePanel // this.linePanel.BackColor = System.Drawing.SystemColors.Window; this.linePanel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.linePanel.Location = new System.Drawing.Point(110, 29); this.linePanel.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.linePanel.Name = "linePanel"; this.linePanel.Size = new System.Drawing.Size(190, 24); this.linePanel.TabIndex = 7; this.linePanel.Click += new System.EventHandler(this.lineColorPanel_Click); // // label41 // this.label41.AutoSize = true; this.label41.Location = new System.Drawing.Point(12, 29); this.label41.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label41.Name = "label41"; this.label41.Size = new System.Drawing.Size(82, 15); this.label41.TabIndex = 6; this.label41.Text = "线条颜色:"; // // button5 // this.button5.Location = new System.Drawing.Point(0, 0); this.button5.Name = "button5"; this.button5.Size = new System.Drawing.Size(75, 23); this.button5.TabIndex = 0; // // MeasureAreaDialog // this.AutoScaleDimensions = new System.Drawing.SizeF(120F, 120F); this.ClientSize = new System.Drawing.Size(672, 244); this.Controls.Add(this.groupBox2); this.Controls.Add(this.groupBox1); this.Margin = new System.Windows.Forms.Padding(5, 5, 5, 5); this.MinimizeBox = false; this.Name = "MeasureAreaDialog"; this.Text = "测量设置"; this.Controls.SetChildIndex(this.groupBox1, 0); this.Controls.SetChildIndex(this.groupBox2, 0); this.groupBox1.ResumeLayout(false); this.groupBox1.PerformLayout(); this.groupBox2.ResumeLayout(false); this.groupBox2.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown11)).EndInit(); this.ResumeLayout(false); } #region InitializeComponent2 /// /// 初始化组件 /// private void InitializeComponent2() { this.colorsForm1 = new ColorsForm(); this.colorsForm1.StartPosition = FormStartPosition.CenterScreen; this.colorsForm1.UserPrimaryColorChanged += new ColorEventHandler(this.colorsFormUserPrimaryColorChanged); } private void colorsFormUserPrimaryColorChanged(object sender, ColorEventArgs ce) { } #endregion /// /// 初始化数据 /// private void InitializeData() { this.linePanel.BackColor = Color.FromArgb(this.measureAreaModel.lineColor); this.numericUpDown11.Value = this.measureAreaModel.lineWidth; this.comboBox21.SelectedIndex = this.measureAreaModel.lineStyle; //this.fzxRBT.Checked = this.measureAreaModel.reportOutput ? true : false; //this.fzxRBF.Checked = this.measureAreaModel.reportOutput ? false : true; //绑定样式下拉 todo if (initflag++ == 0) { InitializeStyleName(); } } /// /// 保存按钮 /// /// /// private void Button2_Click(object sender, EventArgs e) { this.measureAreaModel.lineColor = linePanel.BackColor.ToArgb(); this.measureAreaModel.lineWidth = Convert.ToInt32(numericUpDown11.Value); //this.measureAreaModel.reportOutput = fzxRBT.Checked ? true : false; this.measureAreaModel.lineStyle = this.comboBox21.SelectedIndex; //以下保存xml文件信息 string stageModelXml = XmlSerializeHelper.XmlSerialize(this.measureAreaModel); string filePath = Application.StartupPath + "\\Config\\" + Program.instance.SettingPrefix + "\\MeasureArea\\" + this.comboBox1.Text + ".xml"; FileOperationHelper.WriteStringToFile(stageModelXml, filePath, FileMode.Create); string configModelXml = XmlSerializeHelper.XmlSerialize(config); FileOperationHelper.WriteStringToFile(configModelXml, Application.StartupPath + "\\Config\\" + Program.instance.SettingPrefix + "\\Config.xml", FileMode.Create); MarkPointRect.markPointRectWidth = configModel.MarkpointWidth; if (this.appWorkspace.DocumentWorkspaces != null) { foreach (var item in this.appWorkspace.DocumentWorkspaces) { if (item != null && item.GraphicsList != null) foreach (var graObject in item.GraphicsList.graphicsList) { graObject.smallRectangleWidth = this.config.MarkpointWidth; } item.Refresh(); } } if (this.documentWorkspaceWindow != null) { Program.instance.measureAreaModel = this.measureAreaModel; this.documentWorkspaceWindow.Refresh(); } ApplicationSetting(); } /// ///另存为按钮点击 /// /// /// private void Button3_Click(object sender, EventArgs e) { dialog = new CreateNameDialog(this); dialog.Text = PdnResources.GetString("Menu.Set.Watermarksettings.Newstyle.text"); dialog.StartPosition = FormStartPosition.CenterParent; dialog.ShowDialog(); } /// /// 当前操作样式 /// /// /// private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { measureAreaModel = XmlSerializeHelper.DESerializer(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + Program.instance.SettingPrefix + "\\MeasureArea\\" + this.comboBox1.SelectedItem.ToString() + ".xml", FileMode.Open)); InitializeData(); } /// /// 绑定样式下拉 /// private void InitializeStyleName() { List fileNames = FileOperationHelper.GetFileList(Application.StartupPath + "\\Config\\" + Program.instance.SettingPrefix + "\\MeasureArea\\"); files.Clear(); foreach (string fileName in fileNames) { string name = fileName.Substring(0, fileName.LastIndexOf(".")); files.Add(name); } this.comboBox1.SelectedIndexChanged -= this.comboBox1_SelectedIndexChanged; this.comboBox1.DataSource = null; this.comboBox1.DataSource = files; string nowModelName = Program.instance.configModel.Watermark.Substring(0, Program.instance.configModel.Watermark.LastIndexOf(".")); this.comboBox1.SelectedIndex = files.FindIndex(a => a.Equals(nowModelName)); measureAreaModel = XmlSerializeHelper.DESerializer(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + Program.instance.SettingPrefix + "\\MeasureArea\\" + this.comboBox1.SelectedItem.ToString() + ".xml", FileMode.Open)); // InitializeData(); this.comboBox1.SelectedIndexChanged += new EventHandler(this.comboBox1_SelectedIndexChanged); } /// /// 删除按钮 /// /// /// private void Button4_Click(object sender, EventArgs e) { if ("Default".Equals(this.comboBox1.Text)) { MessageBox.Show(PdnResources.GetString("Menu.efaultstylecannotbedelete.Text"), PdnResources.GetString("Menu.ensure.text"), MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.nfirmthedeleti.Text"), PdnResources.GetString("Menu.ensure.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); if (dr == DialogResult.OK) { int newIndex = 0; int selectIndex = this.comboBox1.SelectedIndex; int tall = files.Count - 1; if (selectIndex < tall) { newIndex = selectIndex; } string filePath = Application.StartupPath + "\\Config\\" + Program.instance.SettingPrefix + "\\MeasureArea\\" + this.comboBox1.Text + ".xml"; FileInfo fileInfo = new FileInfo(filePath); fileInfo.Delete(); InitializeStyleName(); this.comboBox1.SelectedIndex = newIndex; measureAreaModel = XmlSerializeHelper.DESerializer(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + Program.instance.SettingPrefix + "\\MeasureArea\\" + this.comboBox1.SelectedItem.ToString() + ".xml", FileMode.Open)); InitializeData(); } else if (dr == DialogResult.Cancel) { } } /// /// 弹出另存为框点击保存效果 /// /// public override void GetCreateName(string name) { string currentcomboBox = this.comboBox1.Text; this.newName = name; if (files.Contains(this.newName)) { MessageBox.Show(PdnResources.GetString("Menu.Stylenamecannotberepeated.text"), PdnResources.GetString("Menu.ensure.text"), MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } CopyConfigAndRename(); InitializeStyleName(); this.comboBox1.Text = currentcomboBox; dialog.Close(); } /// /// 另存配置文件 /// private void CopyConfigAndRename() { //另存为 string stageModelXml = XmlSerializeHelper.XmlSerialize(this.measureAreaModel); string filePath = Application.StartupPath + "\\Config\\" + Program.instance.SettingPrefix + "\\MeasureArea\\" + this.newName + ".xml"; FileOperationHelper.WriteStringToFile(stageModelXml, filePath, FileMode.Create); } /// /// 应用按钮 /// /// /// private void ApplicationSetting() { //修改缓存中的样式数据 Program.instance.measureAreaModel = this.measureAreaModel; //修改主配置文件中的值 configModel.MeasurementArea = this.comboBox1.Text + ".xml"; //修改主配置文件的xml string configModelXml = XmlSerializeHelper.XmlSerialize(this.configModel); string filePath = Application.StartupPath + "\\Config\\" + Program.instance.SettingPrefix + "\\Config.xml"; FileOperationHelper.WriteStringToFile(configModelXml, filePath, FileMode.Create); MessageBox.Show(PdnResources.GetString("Menu.Successfullysaved.text")); } private void lineColorPanel_Click(object sender, EventArgs e) { this.colorsForm1.UserPrimaryColor = ColorBgra.FromColor(this.linePanel.BackColor); this.colorsForm1.setSaveBtn_Click(new System.EventHandler(this.lineColorChanged)); this.colorsForm1.ShowDialog(); } private void lineColorChanged(object sender, EventArgs e) { this.linePanel.BackColor = this.colorsForm1.UserPrimaryColor.ToColor(); // this.measureStyleModel.backColor = this.colorsForm.UserPrimaryColor.ToColor().ToArgb(); this.colorsForm1.Close(); } } }