| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426 | using PaintDotNet.Base.CommTool;using PaintDotNet.Base.SettingModel;using PaintDotNet.DbOpreate.DbModel;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;using static PaintDotNet.Base.SettingModel.RuleFocusModel;namespace PaintDotNet.Setting{    /// <summary>    /// 聚焦参数    /// </summary>    internal class FocusingParameter : PdnBaseForm    {        private GroupBox groupBox1;        private Button button2;        private Button button1;        private Label label3;        private NumericUpDown numericUpDown2;        private NumericUpDown numericUpDown1;        private Label label2;        private Label label1;        private GroupBox groupBox2;        private GroupBox groupBox_img;        private ListView listView_rule;        private RuleFocusModel ruleFocusModel;        private IContainer components;        private ImageList newImageList;      static  string filePath = Application.StartupPath + "\\RuleFouces\\RuleFoucesConfiguration.xml";        public FocusingParameter()        {            InitializeComponent();            InitializeLanguageText();            InitData();        }        private void InitializeLanguageText()        {            this.groupBox1.Text = PdnResources.GetString("Menu.operation.text");            this.button2.Text = PdnResources.GetString("Menu.cancel.text");            this.button1.Text = "保存";            this.groupBox2.Text = PdnResources.GetString("Menu.Setting.FocusSetting.Text");            this.label3.Text = PdnResources.GetString("Menu.millisecond.text");            this.label2.Text = PdnResources.GetString("Menu.step-size.text") + ":";            this.label1.Text = PdnResources.GetString("Menu.timeinterval.text") + ":";            this.Text = PdnResources.GetString("Menu.Setting.FocusSetting.Text");        }        private void InitializeComponent()        {            this.components = new System.ComponentModel.Container();            this.groupBox1 = new System.Windows.Forms.GroupBox();            this.button2 = new System.Windows.Forms.Button();            this.button1 = new System.Windows.Forms.Button();            this.groupBox2 = new System.Windows.Forms.GroupBox();            this.label3 = new System.Windows.Forms.Label();            this.numericUpDown2 = new System.Windows.Forms.NumericUpDown();            this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();            this.label2 = new System.Windows.Forms.Label();            this.label1 = new System.Windows.Forms.Label();            this.groupBox_img = new System.Windows.Forms.GroupBox();            this.listView_rule = new System.Windows.Forms.ListView();            this.newImageList = new System.Windows.Forms.ImageList(this.components);            this.groupBox1.SuspendLayout();            this.groupBox2.SuspendLayout();            ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit();            ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();            this.groupBox_img.SuspendLayout();            this.SuspendLayout();            //             // groupBox1            //             this.groupBox1.Controls.Add(this.button2);            this.groupBox1.Controls.Add(this.button1);            this.groupBox1.Location = new System.Drawing.Point(123, 12);            this.groupBox1.Name = "groupBox1";            this.groupBox1.Size = new System.Drawing.Size(415, 55);            this.groupBox1.TabIndex = 1;            this.groupBox1.TabStop = false;            this.groupBox1.Text = "操作";            //             // button2            //             this.button2.Location = new System.Drawing.Point(334, 20);            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(253, 20);            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.Controls.Add(this.label3);            this.groupBox2.Controls.Add(this.numericUpDown2);            this.groupBox2.Controls.Add(this.numericUpDown1);            this.groupBox2.Controls.Add(this.label2);            this.groupBox2.Controls.Add(this.label1);            this.groupBox2.Location = new System.Drawing.Point(123, 73);            this.groupBox2.Name = "groupBox2";            this.groupBox2.Size = new System.Drawing.Size(425, 419);            this.groupBox2.TabIndex = 2;            this.groupBox2.TabStop = false;            this.groupBox2.Text = "聚焦参数";            //             // label3            //             this.label3.AutoSize = true;            this.label3.Location = new System.Drawing.Point(232, 43);            this.label3.Name = "label3";            this.label3.Size = new System.Drawing.Size(29, 12);            this.label3.TabIndex = 4;            this.label3.Text = "毫秒";            //             // numericUpDown2            //             this.numericUpDown2.Location = new System.Drawing.Point(126, 81);            this.numericUpDown2.Maximum = new decimal(new int[] {            10000,            0,            0,            0});            this.numericUpDown2.Name = "numericUpDown2";            this.numericUpDown2.Size = new System.Drawing.Size(100, 21);            this.numericUpDown2.TabIndex = 3;            this.numericUpDown2.Value = new decimal(new int[] {            100,            0,            0,            0});            //             // numericUpDown1            //             this.numericUpDown1.Increment = new decimal(new int[] {            10,            0,            0,            0});            this.numericUpDown1.Location = new System.Drawing.Point(126, 40);            this.numericUpDown1.Maximum = new decimal(new int[] {            1000,            0,            0,            0});            this.numericUpDown1.Name = "numericUpDown1";            this.numericUpDown1.Size = new System.Drawing.Size(100, 21);            this.numericUpDown1.TabIndex = 2;            this.numericUpDown1.Value = new decimal(new int[] {            100,            0,            0,            0});            //             // label2            //             this.label2.AutoSize = true;            this.label2.Location = new System.Drawing.Point(35, 84);            this.label2.Name = "label2";            this.label2.Size = new System.Drawing.Size(41, 12);            this.label2.TabIndex = 1;            this.label2.Text = "步长:";            //             // label1            //             this.label1.AutoSize = true;            this.label1.Location = new System.Drawing.Point(35, 43);            this.label1.Name = "label1";            this.label1.Size = new System.Drawing.Size(65, 12);            this.label1.TabIndex = 0;            this.label1.Text = "采图时间:";            //             // groupBox_img            //             this.groupBox_img.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)            | System.Windows.Forms.AnchorStyles.Left)));            this.groupBox_img.Controls.Add(this.listView_rule);            this.groupBox_img.Location = new System.Drawing.Point(13, 13);            this.groupBox_img.Margin = new System.Windows.Forms.Padding(4);            this.groupBox_img.Name = "groupBox_img";            this.groupBox_img.Padding = new System.Windows.Forms.Padding(4);            this.groupBox_img.Size = new System.Drawing.Size(103, 479);            this.groupBox_img.TabIndex = 14;            this.groupBox_img.TabStop = false;            this.groupBox_img.Text = "标尺名称";            //             // listView_rule            //             this.listView_rule.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)));            this.listView_rule.FullRowSelect = true;            this.listView_rule.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None;            this.listView_rule.HideSelection = false;            this.listView_rule.Location = new System.Drawing.Point(9, 19);            this.listView_rule.Margin = new System.Windows.Forms.Padding(4);            this.listView_rule.MultiSelect = false;            this.listView_rule.Name = "listView_rule";            this.listView_rule.Size = new System.Drawing.Size(86, 452);            this.listView_rule.TabIndex = 0;            this.listView_rule.UseCompatibleStateImageBehavior = false;            this.listView_rule.SelectedIndexChanged += new System.EventHandler(this.listView_rule_SelectedIndexChanged);            //             // newImageList            //             this.newImageList.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;            this.newImageList.ImageSize = new System.Drawing.Size(16, 16);            this.newImageList.TransparentColor = System.Drawing.Color.Transparent;            //             // FocusingParameter            //             this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);            this.ClientSize = new System.Drawing.Size(550, 504);            this.Controls.Add(this.groupBox_img);            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 = "FocusingParameter";            this.Text = "聚焦参数";            this.Controls.SetChildIndex(this.groupBox1, 0);            this.Controls.SetChildIndex(this.groupBox2, 0);            this.Controls.SetChildIndex(this.groupBox_img, 0);            this.groupBox1.ResumeLayout(false);            this.groupBox2.ResumeLayout(false);            this.groupBox2.PerformLayout();            ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit();            ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();            this.groupBox_img.ResumeLayout(false);            this.ResumeLayout(false);        }        /// <summary>        /// 初始化数据        /// </summary>        private void InitData()        {            //初始化头            this.listView_rule.View = View.Details;            ColumnHeader header0 = new ColumnHeader();            header0.Text = "";            header0.Width = 180;            this.listView_rule.Columns.Add(header0);            #region [获取标尺]            List<mic_rulers> list = Startup.instance.mic_rulersAll.Where(m => m.id >= 0).ToList();            if (!System.IO.File.Exists(filePath))            {                ruleFocusModel = new RuleFocusModel();                if (list != null && list.Count > 0)                {                    if (ruleFocusModel.ModelList == null)                    {                        ruleFocusModel.ModelList = new List<RuleFocusDetailsModel>();                    }                    for (int i = 0; i < list.Count; i++)                    {                        mic_rulers rule = list[i];                        RuleFocusDetailsModel model = new RuleFocusDetailsModel();                        model.RuleId = rule.id;                        model.RuleName = rule.ruler_name;                        ruleFocusModel.ModelList.Add(model);                    }                }                Directory.CreateDirectory(Application.StartupPath + "\\RuleFouces\\");                XmlSerializeHelper.Save(ruleFocusModel, filePath);            }            else            {                ruleFocusModel = XmlSerializeHelper.Load<RuleFocusModel>(filePath);                foreach (var s in list)                {                    var mod = ruleFocusModel.ModelList.Where(m => m.RuleId == s.id).FirstOrDefault();                    if (mod != null)                    {                        continue;                    }                    var model = new RuleFocusDetailsModel();                    model.RuleId = s.id;                    model.RuleName = s.ruler_name;                    ruleFocusModel.ModelList.Add(model);                }                XmlSerializeHelper.Save(ruleFocusModel, filePath);            }            //listView_rule.AutoResizeColumn(0, ColumnHeaderAutoResizeStyle.ColumnContent);             foreach (var s in ruleFocusModel.ModelList)            {                ListViewItem item = new ListViewItem();                item.Tag = s;                item.Text = s.RuleName;                this.listView_rule.Items.Add(item);            }            #endregion        }        /// <summary>        /// 取消按钮        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void button2_Click(object sender, EventArgs e)        {            this.Close();        }        /// <summary>        /// 确定按钮        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void button1_Click(object sender, EventArgs e)        {            if (this.listView_rule.FocusedItem != null && this.listView_rule.FocusedItem.Selected)            {                RuleFocusDetailsModel model = (RuleFocusDetailsModel)this.listView_rule.FocusedItem.Tag;                var changeModel = this.ruleFocusModel.ModelList.Where(m => m.RuleId == model.RuleId).FirstOrDefault();                if (changeModel != null)                {                    changeModel.TimeLag = (int)this.numericUpDown1.Value;                    changeModel.StepLength = (int)this.numericUpDown2.Value;                    XmlSerializeHelper.Save(ruleFocusModel, filePath);                }            }        }        /// <summary>        /// 选中标尺        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void listView_rule_SelectedIndexChanged(object sender, EventArgs e)        {            if (this.listView_rule.FocusedItem != null && this.listView_rule.FocusedItem.Selected)            {                RuleFocusDetailsModel model = (RuleFocusDetailsModel)this.listView_rule.FocusedItem.Tag;                this.numericUpDown1.Value = model.TimeLag;                this.numericUpDown2.Value = (decimal)model.StepLength;            }        }        #region [获取当前系统激活的标尺]        public static RuleFocusDetailsModel getRuleFocus()        {            #region [获取标尺]            List<mic_rulers> list = Startup.instance.mic_rulersAll.Where(m => m.id >= 0).ToList();            RuleFocusModel modelList = new RuleFocusModel();            if (!System.IO.File.Exists(filePath))            {                Directory.CreateDirectory(Application.StartupPath + "\\RuleFouces\\");                if (list != null && list.Count > 0)                {                    modelList.ModelList = new List<RuleFocusDetailsModel>();                    for (int i = 0; i < list.Count; i++)                    {                        var rule = list[i];                        modelList.ModelList.Add(new RuleFocusDetailsModel(rule.id, rule.ruler_name));                    }                }                XmlSerializeHelper.Save(modelList, filePath);            }            else            {                modelList = XmlSerializeHelper.Load<RuleFocusModel>(filePath);                foreach (var s in list)                {                    if (!modelList.ModelList.Any(m => m.RuleId == s.id))                    {                        modelList.ModelList.Add(new RuleFocusDetailsModel(s.id, s.ruler_name));                    }                }                XmlSerializeHelper.Save(modelList, filePath);            }            var activationRules = Startup.instance.ruleDB;            if (activationRules != null)            {                var thisNum = modelList.ModelList.Where(m => m.RuleId == activationRules.id).FirstOrDefault();                if (thisNum != null)                {                    return thisNum;                }            }            return new RuleFocusDetailsModel();            #endregion        }        #endregion    }}
 |