private void btnEdit_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count > 0) { int index = dataGridView.SelectedRows[0].Index; int id = 0; bool converted = Int32.TryParse(dataGridView[0, index].Value.ToString(), out id); if (converted == false) { return; } IncCategory iCat = context.IncCategoryList.Find(id); IncCtForm incCtForm = new IncCtForm(); incCtForm.txtName.Text = iCat.Name; DialogResult result = incCtForm.ShowDialog(this); if (result == DialogResult.Cancel) { return; } iCat.Name = incCtForm.txtName.Text; context.Entry(iCat).State = EntityState.Modified; context.SaveChanges(); MessageBox.Show("Категория обновлена"); } }
private void btnEdit_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count > 0) { int index = dataGridView.SelectedRows[0].Index; int id = 0; bool converted = Int32.TryParse(dataGridView[0, index].Value.ToString(), out id); if (converted == false) { return; } Income income = context.IncList.Find(id); IncomeAEForm iaeForm = new IncomeAEForm(); iaeForm.dtDate.Value = income.IncDate; iaeForm.txtIncSum.Text = income.IncSum.ToString(); iaeForm.cbCategory.SelectedItem = income.IncCategory; iaeForm.txtDescr.Text = income.Descr; List <IncCategory> incCats = context.IncCategoryList.ToList(); iaeForm.cbCategory.DataSource = incCats; iaeForm.cbCategory.ValueMember = "IncCategoryId"; iaeForm.cbCategory.DisplayMember = "Name"; if (income.IncCategory != null) { iaeForm.cbCategory.SelectedValue = income.IncCategory.IncCategoryId; } DialogResult result = iaeForm.ShowDialog(this); if (result == DialogResult.Cancel) { return; } income.IncDate = (DateTime)iaeForm.dtDate.Value; income.IncSum = decimal.Parse(iaeForm.txtIncSum.Text); income.IncCategory = (IncCategory)iaeForm.cbCategory.SelectedItem; income.Descr = iaeForm.txtDescr.Text; context.Entry(income).State = EntityState.Modified; context.SaveChanges(); MessageBox.Show("Запись обновлен"); } }
private void btnEdit_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count > 0) { int index = dataGridView.SelectedRows[0].Index; int id = 0; bool converted = Int32.TryParse(dataGridView[0, index].Value.ToString(), out id); if (converted == false) { return; } Consum consum = context.ConsList.Find(id); ConsumAEForm caeForm = new ConsumAEForm(); caeForm.dtDate.Value = consum.ConsDate; caeForm.txtIncSum.Text = consum.ConsSum.ToString(); caeForm.cbCategory.SelectedItem = consum.ConsCategory; caeForm.txtDescr.Text = consum.Descr; List <ConsCategory> conCats = context.ConsCategoryList.ToList(); caeForm.cbCategory.DataSource = conCats; caeForm.cbCategory.ValueMember = "ConsCategoryId"; caeForm.cbCategory.DisplayMember = "Name"; if (consum.ConsCategory != null) { caeForm.cbCategory.SelectedValue = consum.ConsCategory.ConsCategoryId; } DialogResult result = caeForm.ShowDialog(this); if (result == DialogResult.Cancel) { return; } consum.ConsDate = (DateTime)caeForm.dtDate.Value; consum.ConsSum = decimal.Parse(caeForm.txtIncSum.Text); consum.ConsCategory = (ConsCategory)caeForm.cbCategory.SelectedItem; consum.Descr = caeForm.txtDescr.Text; context.Entry(consum).State = EntityState.Modified; context.SaveChanges(); MessageBox.Show("Запись обновлен"); } }