コード例 #1
0
        // Gets a turmite from an "Addform", checks whether it uses the same number of colors as is set and whether it is in the bounds of the board.
        private void AddButton_Click(object sender, EventArgs e)
        {
            paused = true;
            AddForm addDialog = new AddForm();

            addDialog.ShowDialog();
            if (addDialog.DialogResult == DialogResult.OK)
            {
                if (addDialog.toAdd.stateTable.GetUpperBound(1) + 1 > turmites.colors.Count)
                {
                    MessageBox.Show("Not enough colors defined for selected turmite.");
                }
                else
                if (addDialog.toAdd.stateTable.GetUpperBound(1) + 1 < turmites.colors.Count)
                {
                    MessageBox.Show("Selected turmite is unable to handle all defined colors.");
                }
                else
                {
                    addDialog.toAdd.controller = turmites;
                    addDialog.toAdd.x          = pictureBox1.Image.Width < addDialog.toAdd.x ? pictureBox1.Image.Width : addDialog.toAdd.x;
                    addDialog.toAdd.y          = pictureBox1.Image.Height < addDialog.toAdd.y ? pictureBox1.Image.Height : addDialog.toAdd.y;
                    turmites.turmites.Add(addDialog.toAdd);
                }
            }
            addDialog.Dispose();
        }
コード例 #2
0
 private void button4_Click(object sender, EventArgs e)
 {
     AddForm = new AddForm(3);
     if (AddForm.ShowDialog() == DialogResult.OK)
     {
         RefreshTree();
     }
 }
コード例 #3
0
        //Add
        private void button1_Click(object sender, EventArgs e)
        {
            AddForm      addForm = new AddForm();
            DialogResult result  = addForm.ShowDialog(this);

            if (result == DialogResult.Cancel)
            {
                return;
            }

            Regex regexPhone = new Regex(@"((8|\+7)[\- ]?)?(\(?\d{3}\)?[\- ]?)?[\d\- ]{7,10}");

            List <Phone> list = new List <Phone>();

            string Firstname  = addForm.textBox1.Text;
            string Secondname = addForm.textBox2.Text;
            string Patronymic = addForm.textBox3.Text;
            string Info       = addForm.textBox4.Text;

            MatchCollection matchesPhone = regexPhone.Matches(addForm.textBox5.Text);

            if (matchesPhone.Count > 0)
            {
                int i = 0;
                foreach (Match match in matchesPhone)
                {
                    list.Add(new Phone(match.Value, i));
                    i++;
                }
            }
            else
            {
                MessageBox.Show("Некорректный ввод телефона");
            }

            Person p = new Person(Firstname, Secondname, Patronymic, Info);

            foreach (Phone phone in list)
            {
                p.Phones.Add(phone);
            }

            db.People.Add(p);
            db.SaveChanges();
            MessageBox.Show("Новый объект добавлен");
        }
コード例 #4
0
        //Edit
        private void button3_Click(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count > 0)
            {
                int  index     = dataGridView1.SelectedRows[0].Index;
                bool converted = Int32.TryParse(dataGridView1[0, index].Value.ToString(), out int id);
                if (converted == false)
                {
                    return;
                }

                Person  person  = db.People.Find(id);
                AddForm addForm = new AddForm();

                addForm.textBox1.Text = person.FirstName;
                addForm.textBox2.Text = person.SecondName;
                addForm.textBox3.Text = person.Patronymic;
                addForm.textBox4.Text = person.Info;
                StringBuilder phones = new StringBuilder("");
                foreach (Phone number in person.Phones)
                {
                    phones.Append(number.Number);
                }
                addForm.textBox5.Text = phones.ToString();

                DialogResult result = addForm.ShowDialog(this);

                if (result == DialogResult.Cancel)
                {
                    return;
                }

                person.FirstName  = addForm.textBox1.Text;
                person.SecondName = addForm.textBox2.Text;
                person.Patronymic = addForm.textBox3.Text;
                person.Info       = addForm.textBox4.Text;

                Regex           regexPhone   = new Regex(@"((8|\+7)[\- ]?)?(\(?\d{3}\)?[\- ]?)?[\d\- ]{7,10}");
                List <Phone>    list         = new List <Phone>();
                MatchCollection matchesPhone = regexPhone.Matches(addForm.textBox5.Text);
                if (matchesPhone.Count > 0)
                {
                    int i = 0;
                    foreach (Match match in matchesPhone)
                    {
                        list.Add(new Phone(match.Value, i));
                        i++;
                    }
                }
                else
                {
                    MessageBox.Show("Некорректный ввод телефона");
                }
                person.Phones = new List <Phone>();
                foreach (Phone phone in list)
                {
                    person.Phones.Add(phone);
                }

                db.SaveChanges();
                dataGridView1.Refresh();
                MessageBox.Show("Объект обновлен");
            }
        }