Пример #1
0
        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
            case (Keys.Enter):
                Regex Val = new Regex(@"^[+-]?\d+(\.\d+)?$");
                if (IsNumeric(textBox1.Text) || Val.IsMatch(textBox1.Text))
                {
                    dgv.Rows[Pos].Cells[3].Value = textBox1.Text;
                    var form = new VariablesForm(Prg.Variables, Prg.CustomUnits);

                    form.ExternalSaveValue(Pos, dgv.Rows[Pos]);

                    UpdatePoint up = new UpdatePoint();
                    if (up.Update_point(id, dgv.Rows[Pos].Cells[1].Value.ToString() + " " + textBox1.Text))
                    {
                        Console.WriteLine("Name Update Success");
                    }
                    else
                    {
                        Console.WriteLine("Error");
                    }
                    Prg.Save(PrgPath);
                    MessageBox.Show("Saved");
                    flag         = true;
                    DialogResult = DialogResult.OK;
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Invalid parameter");
                }
                break;
            }
        }
Пример #2
0
        private void textBox1_ClickVars(object sender, MouseEventArgs e)
        {
            Regex Val = new Regex(@"^[+-]?\d+(\.\d+)?$");

            if (IsNumeric(textBox1.Text) || Val.IsMatch(textBox1.Text))
            {
                textBox1.Enabled = true;
            }
            else
            {
                if (textBox1.Text.ToLower().Contains("on") || textBox1.Text.ToLower().Contains("off"))
                {
                    dgv.Rows[Pos].Cells[3].Value = ((textBox1.Text.Equals("On")) ? "Off" : "On");
                }
                else if (textBox1.Text.ToLower().Contains("yes") || textBox1.Text.ToLower().Contains("no"))
                {
                    dgv.Rows[Pos].Cells[3].Value = ((textBox1.Text.Equals("Yes")) ? "No" : "Yes");
                }



                textBox1.Text = dgv.Rows[Pos].Cells[3].Value.ToString();
                var form = new VariablesForm(Prg.Variables, Prg.CustomUnits);

                form.ExternalSaveValue(Pos, dgv.Rows[Pos]);


                UpdatePoint up = new UpdatePoint();
                if (up.Update_point(id, dgv.Rows[Pos].Cells[1].Value.ToString() + " " + textBox1.Text))
                {
                    Console.WriteLine("Name Update Success");
                }
                else
                {
                    Console.WriteLine("Error");
                }
                Prg.Save(PrgPath);
                MessageBox.Show("Saved");
                flag         = true;
                DialogResult = DialogResult.OK;
            }
        }