Пример #1
0
        private void BtnSave_Click(object sender, EventArgs e)
        {
            if (sequence /*sequenceList.Count*/ == NTRSbyDB.Layout.sum)//NTRSjudge.Layout.row * NTRSjudge.Layout.col)
            {
                if (sequenceList.Count == NTRSbyDB.Layout.sum)
                {
                    RegistryKey key      = Registry.LocalMachine;
                    RegistryKey software = key.OpenSubKey(@"software\NTRS", true);
                    software.SetValue("Trajectory", sequenceList.ToArray(), RegistryValueKind.MultiString);
                }
                MessageBox.Show("保存成功");
                this.Close();

                if (!Regedit.verifyTrajectory())
                {
                    #region 重启
                    bool isOpen = false;
                    foreach (Form f in Application.OpenForms)
                    {
                        if (f.Name == "Main")
                        {
                            isOpen = true;
                        }
                    }
                    if (isOpen)//主串口打开了,重启
                    {
                        Application.Exit();
                        System.Diagnostics.Process.Start(System.Reflection.Assembly.GetExecutingAssembly().Location);
                    }
                    #endregion
                }
            }
            else
            {
                MessageBox.Show("保存失败,运动轨迹存在空设定");
            }
        }
Пример #2
0
        public Main()
        {
            //CheckForIllegalCrossThreadCalls = false;
            main = this;
            InitializeComponent();

            //显示版本号
            this.Text += "_" + Application.ProductVersion.ToString();
            //新建文件夹(log、pqm、sum)
            Document.CreateDocument();
            //创建注册表文件
            try { Registry.LocalMachine.CreateSubKey(@"software\NTRS"); }
            catch (Exception ex) { MessageBox.Show(ex.Message); Environment.Exit(0); }
            //验证(串口)
            if (!Regedit.verifyPort())
            {
checkPort:
                DialogResult dr = MessageBox.Show("串口验证失败,\n按确定键重新设置串口属性或关闭程序。", "错误", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
                if (dr == DialogResult.No)
                {
                    Environment.Exit(0);
                }
                new Port().ShowDialog();
                if (!Regedit.verifyPort())
                {
                    goto checkPort;
                }
            }
            //验证(运动轨迹)
            if (!Regedit.verifyTrajectory())
            {
checkTrajectory:
                DialogResult dr = MessageBox.Show("运动轨迹验证失败,\n按确定键重新设置运动轨迹或关闭程序。", "错误", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
                if (dr == DialogResult.No)
                {
                    Environment.Exit(0);
                }
                new Trajectory().ShowDialog();
                if (!Regedit.verifyTrajectory())
                {
                    goto checkTrajectory;
                }
            }
            #region 布局
            #region
            string[] items = System.IO.File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + @"DisplayDetail").Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
            int      y     = 0;
            foreach (string item in items)
            {
                y += 40;
                string[] detail = item.Split(',');
                TextBox  txt    = new TextBox()
                {
                    Size = new Size(245, 33)
                };
                txt.Location  = new Point(15, -15 + y);
                txt.Text      = detail[0];
                txt.ForeColor = ColorTranslator.FromHtml(detail[1]);
                txt.BackColor = ColorTranslator.FromHtml(detail[2]);
                gbDetail.Controls.Add(txt);
            }
            #endregion
            #region TlpLayout
            TlpLayout.RowCount    = NTRSbyDB.Layout.row;
            TlpLayout.ColumnCount = NTRSbyDB.Layout.col;

            for (int i = 0; i < NTRSbyDB.Layout.row; i++)
            {
                TlpLayout.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
            }
            for (int i = 0; i < NTRSbyDB.Layout.col; i++)
            {
                TlpLayout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
            }
            #endregion
            #endregion
            TlpLayout_Width = TlpLayout.Width;
        }
Пример #3
0
        public Trajectory()
        {
            InitializeComponent();

            #region 布局
            TlpLayout.RowCount    = NTRSbyDB.Layout.row;
            TlpLayout.ColumnCount = NTRSbyDB.Layout.col;

            for (int i = 0; i < NTRSbyDB.Layout.row; i++)
            {
                TlpLayout.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
            }
            for (int i = 0; i < NTRSbyDB.Layout.col; i++)
            {
                TlpLayout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
            }

            for (int i = 0; i < NTRSbyDB.Layout.row; i++)
            {
                for (int j = 0; j < NTRSbyDB.Layout.col; j++)
                {
                    Label label = new Label();
                    label.Dock      = DockStyle.Fill;
                    label.BackColor = Color.Red;
                    label.Text      = "\r\n\r\n\r\n(" + (j + 1).ToString() + "," + (i + 1).ToString() + ")";
                    label.Click    += new EventHandler(clickMark);
                    TlpLayout.Controls.Add(label, j, i);
                    //下面这句要是在行和列不够的情况下,会建到100行1000列
                    //tableLayoutPanel1.Controls.Add(label1, 100, 1000);
                }
            }

            void clickMark(object sender, EventArgs e)
            {
                Label label = (Label)sender;

                label.Text      = label.Text.Insert(0, (++sequence).ToString());
                label.BackColor = Color.Lime;
                label.Enabled   = false;
                sequenceList.Add((TlpLayout.GetColumn(label) + 1).ToString()
                                 + ","
                                 + (TlpLayout.GetRow(label) + 1).ToString());
            }

            #endregion
            //存在key且通过验证就显示次序顺序
            #region load注册表
            if (Regedit.isRegeditKeyExit("Trajectory"))
            {
                if (!Regedit.verifyTrajectory())
                {
                    return;
                }

                RegistryKey myreg        = Registry.LocalMachine.OpenSubKey(@"software\NTRS");
                String[]    sequenceList = (String[])(myreg.GetValue("Trajectory"));
                //验证:读取的字符串能匹配上布局的定义坐标(1,1\1,2等)
                foreach (string str in sequenceList)
                {
                    //遍历控件对比
                    for (int i = 0; i < TlpLayout.Controls.Count; i++)
                    {
                        if (TlpLayout.Controls[i].Text.Contains(str))
                        {
                            TlpLayout.Controls[i].BackColor = Color.Lime;
                            TlpLayout.Controls[i].Enabled   = false;
                            TlpLayout.Controls[i].Text      = TlpLayout.Controls[i].Text.Insert(0, (++sequence).ToString());
                            break;
                        }
                        #region Regedit.verifyTrajectory()覆盖该过程
                        ////全部验证成功才显示次序(只要有一个验证不了,全部取消)
                        ////Regedit.verifyTrajectory()一定要元素相等且相同才可进这里,所以不需要下面这
                        //if (i == tableLayoutPanel1.Controls.Count-1)
                        //{
                        //    cancel_btn_Click(new object (), new EventArgs ());
                        //    return;
                        //}
                        #endregion
                    }
                    #region 索引(比较复杂,用遍历方法实现)
                    ////tableLayoutPanel1.Controls.Add(label, j, i);
                    ////string test=tableLayoutPanel1.Controls[1].Text;
                    ////string a=tableLayoutPanel1.Controls[0,1].Text;
                    //int row=int.Parse(str.Split(',')[0]);
                    //int col = int.Parse(str.Split(',')[1]);
                    ////2,2
                    //int r=row % NTRSjudge.Layout.row;
                    //int c = col % NTRSjudge.Layout.col;
                    #endregion
                }
            }
            #endregion
        }