Esempio n. 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            AddUser addUser = new AddUser();
            DialogResult result = addUser.ShowDialog(this);

            User user = new User();
            if (result == DialogResult.Cancel)
                Hide();
            if (result == DialogResult.OK)
            {

                user.firstname = addUser.textBox1.Text;
                user.name = addUser.textBox2.Text;
                user.lastname = addUser.textBox3.Text;
                user.id_book = listBook.Find(ob => ob.name == addUser.comboBox1.Text).id_book;
                db_lab4Entities db = new db_lab4Entities();
                db.Users.Add(user);
                db.SaveChanges();

                dataGridView1.Refresh();
                Refresh();
                MessageBox.Show("Добавлена новая книга!");
            }
        }
Esempio n. 2
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count > 0)
            {
                int index = dataGridView1.SelectedRows[0].Index;
                int id = 0;
                bool converted = Int32.TryParse(dataGridView1[0, index].Value.ToString(), out id);
                if (converted == false)
                    return;

                User user = db.Users.Find(id);

                AddUser addUser = new AddUser();

                addUser.textBox1.Text = user.firstname;
                addUser.textBox2.Text = user.name;
                addUser.textBox3.Text = user.lastname;
                addUser.comboBox1.Text = listBook.Find(ob => ob.id_book == user.id_book).name;
                                

                DialogResult result = addUser.ShowDialog(this);

                if (result == DialogResult.Cancel)
                    Hide();

                user.firstname = addUser.textBox1.Text;
                user.name = addUser.textBox2.Text;
                user.lastname = addUser.textBox3.Text;
                user.id_book = listBook.Find(ob => ob.name == addUser.comboBox1.Text).id_book;
                db.SaveChanges();
                dataGridView1.Refresh();
                Refresh();
                MessageBox.Show("Объект обновлен");
            }
        }