| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543 | 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    {        /// <summary>        /// 主配置文件的model        /// </summary>        private ConfigModel configModel = Program.instance.configModel;        /// <summary>        /// 操作区控件        /// </summary>        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;        /// <summary>        /// 测量的样式        /// </summary>        private MeasureAreaModel measureAreaModel = Program.instance.measureAreaModel;        /// <summary>        /// 另存为弹出框显示        /// </summary>        private CreateNameDialog dialog;        /// <summary>        /// 操作样式下拉数据        /// </summary>        private List<string> files = new List<string>();        /// <summary>        /// 另存为文件名        /// </summary>        private string newName;        /// <summary>        /// 选中的测量类型        /// </summary>        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        /// <summary>        /// 初始化组件        /// </summary>        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        /// <summary>        /// 初始化数据        /// </summary>        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();            }        }        /// <summary>        ///   保存按钮        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        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<MeasureAreaModel>(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<ConfigModel>(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();        }        /// <summary>        ///另存为按钮点击         /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        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();        }        /// <summary>        /// 当前操作样式        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)        {                           measureAreaModel = XmlSerializeHelper.DESerializer<MeasureAreaModel>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + Program.instance.SettingPrefix + "\\MeasureArea\\" + this.comboBox1.SelectedItem.ToString() + ".xml", FileMode.Open));                                    InitializeData();        }        /// <summary>        /// 绑定样式下拉        /// </summary>        private void InitializeStyleName()        {            List<string> 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<MeasureAreaModel>(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);        }        /// <summary>        /// 删除按钮        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        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<MeasureAreaModel>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + Program.instance.SettingPrefix + "\\MeasureArea\\" + this.comboBox1.SelectedItem.ToString() + ".xml", FileMode.Open));                InitializeData();            }            else if (dr == DialogResult.Cancel)            {            }        }        /// <summary>        /// 弹出另存为框点击保存效果        /// </summary>        /// <param name="name"></param>        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();        }        /// <summary>        /// 另存配置文件        /// </summary>        private void CopyConfigAndRename()        {            //另存为            string stageModelXml = XmlSerializeHelper.XmlSerialize<MeasureAreaModel>(this.measureAreaModel);            string filePath = Application.StartupPath + "\\Config\\" + Program.instance.SettingPrefix + "\\MeasureArea\\" + this.newName + ".xml";            FileOperationHelper.WriteStringToFile(stageModelXml, filePath, FileMode.Create);        }        /// <summary>        /// 应用按钮        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void ApplicationSetting()        {            //修改缓存中的样式数据            Program.instance.measureAreaModel = this.measureAreaModel;            //修改主配置文件中的值            configModel.MeasurementArea = this.comboBox1.Text + ".xml";            //修改主配置文件的xml            string configModelXml = XmlSerializeHelper.XmlSerialize<ConfigModel>(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();        }    }}
 |