Ejemplo n.º 1
0
        public void addReaderButton_Click(object sender, EventArgs e)
        {
            AddReaderForm addReaderForm = new AddReaderForm();
            DialogResult  dialogResult  = addReaderForm.ShowDialog(this);

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

            string   name       = addReaderForm.nameTextBox.Text;
            string   surname    = addReaderForm.surnameTextBox.Text;
            string   patronymic = addReaderForm.patronymicTextBox.Text;
            DateTime DoB        = addReaderForm.dateTimePicker.Value;
            string   email      = addReaderForm.emailTextBox.Text;
            string   telNumber  = addReaderForm.telNumberTextBox.Text;

            Reader reader = new Reader
            {
                Name            = name,
                Surname         = surname,
                Patronymic      = patronymic,
                DateOfBirth     = DoB,
                Email           = email,
                TelephoneNumber = telNumber
            };

            ReaderRepository readerRepository = new ReaderRepository();

            readerRepository.Create(reader);

            _db.SaveChanges();
        }
Ejemplo n.º 2
0
        public void changeButton_Click(object sender, EventArgs e)
        {
            if (!(dataGridView1.SelectedRows.Count > 0))
            {
                return;
            }
            AddReaderForm    addReaderForm    = new AddReaderForm();
            ReaderRepository readerRepository = new ReaderRepository();

            int  index     = dataGridView1.SelectedRows[0].Index;
            int  id        = 0;
            bool converted = Int32.TryParse(dataGridView1[0, index].Value.ToString(), out id);

            if (converted == false)
            {
                return;
            }

            Reader reader = readerRepository.FindById(id);

            addReaderForm.nameTextBox.Text       = reader.Name;
            addReaderForm.surnameTextBox.Text    = reader.Surname;
            addReaderForm.patronymicTextBox.Text = reader.Patronymic;
            addReaderForm.dateTimePicker.Value   = reader.DateOfBirth;
            addReaderForm.emailTextBox.Text      = reader.Email;
            addReaderForm.telNumberTextBox.Text  = reader.TelephoneNumber;

            DialogResult dialogResult = addReaderForm.ShowDialog(this);

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

            string   name       = addReaderForm.nameTextBox.Text;
            string   surname    = addReaderForm.surnameTextBox.Text;
            string   patronymic = addReaderForm.patronymicTextBox.Text;
            DateTime DoB        = addReaderForm.dateTimePicker.Value;
            string   email      = addReaderForm.emailTextBox.Text;
            string   telNumber  = addReaderForm.telNumberTextBox.Text;


            reader.Name            = name;
            reader.Surname         = surname;
            reader.Patronymic      = patronymic;
            reader.DateOfBirth     = DoB;
            reader.Email           = email;
            reader.TelephoneNumber = telNumber;


            readerRepository.Update(reader);

            _db.SaveChanges();
            SetDataGridView();
        }