Exemplo n.º 1
0
        private void BtnAdd_Click(object sender, EventArgs e)
        {
            CountryForm addForm = new CountryForm();

            addForm.IsNew      = true;
            addForm.Continents = _continents;
            addForm.Text       = "Новая страна";
            addForm.ShowDialog();
            if (addForm.Model == null)
            {
                return;
            }
            if (string.IsNullOrWhiteSpace(addForm.Model.Code) || string.IsNullOrWhiteSpace(addForm.Model.Name) ||
                string.IsNullOrWhiteSpace(addForm.Model.Continent))
            {
                MessageBox.Show("Не заданы все обязательные значения полей!");
                return;
            }
            AdoNetHelper.AddCountry(addForm.Model);
            ReloadData();
        }
Exemplo n.º 2
0
        private void BtnEdit_Click(object sender, EventArgs e)
        {
            DataGridViewRow currentRow = dgv.CurrentRow;
            string          code       = currentRow?.Cells[0].Value.ToString();

            if (code == null)
            {
                return;
            }
            int    id        = _countries.Where(c => c.Code == code).Select(c => c.Id).First();
            string name      = currentRow.Cells[1].Value.ToString();
            string currency  = currentRow.Cells[2].Value.ToString();
            string capital   = currentRow.Cells[3].Value.ToString();
            string continent = currentRow.Cells[4].Value.ToString();

            CountryForm editForm = new CountryForm();

            editForm.Continents = _continents;
            editForm.Model      = new Country(id, code)
            {
                Name = name, Currency = currency, Capital = capital, Continent = continent
            };
            editForm.Text = "Редакция страны";
            editForm.ShowDialog();
            if (editForm.Model == null)
            {
                return;
            }
            if (string.IsNullOrWhiteSpace(editForm.Model.Name) || string.IsNullOrWhiteSpace(editForm.Model.Continent))
            {
                MessageBox.Show("Не заданы все обязательные значения полей!");
                return;
            }
            AdoNetHelper.UpdateCountry(editForm.Model);
            ReloadData();
        }