private void comboBoxNeed_SelectedIndexChanged(object sender, EventArgs e) { if (comboBoxNeed.SelectedItem != null) { Needs needs = Program.csr.Needs.Find(Convert.ToInt32(comboBoxNeed.SelectedItem.ToString().Split('.')[0])); textBoxPrice.Text = needs.Total_Price.ToString(); } }
private void buttonAdd_Click(object sender, EventArgs e) { if (textBoxItem.Text != "" && textBoxTotalItems.Text != "" && textBoxPrice.Text != "" && textBoxTotalPrice.Text != "" && textBoxJustification.Text != "" && comboBoxDepartment.SelectedItem != null) { Needs needs = new Needs(); needs.Item = textBoxItem.Text; needs.Total_items = Convert.ToInt32(textBoxTotalItems.Text); needs.Price = Convert.ToInt32(textBoxPrice.Text); needs.Total_Price = Convert.ToInt32(textBoxTotalPrice.Text); needs.Justification = textBoxJustification.Text; needs.Comment = textBoxComment.Text; needs.id_Department = Convert.ToInt32(comboBoxDepartment.SelectedItem.ToString().Split('.')[0]); Program.csr.Needs.Add(needs); Program.csr.SaveChanges(); ShowNeeds(); } else { MessageBox.Show("Заполните все необходимые поля", "Невозможно внести данные!", MessageBoxButtons.OK); } }
private void listViewNeeds_SelectedIndexChanged(object sender, EventArgs e) { if (listViewNeeds.SelectedItems.Count == 1) { Needs needs = listViewNeeds.SelectedItems[0].Tag as Needs; textBoxItem.Text = needs.Item; textBoxTotalItems.Text = needs.Total_items.ToString(); textBoxPrice.Text = needs.Price.ToString(); textBoxTotalPrice.Text = needs.Total_Price.ToString(); textBoxJustification.Text = needs.Justification; textBoxComment.Text = needs.Comment; comboBoxDepartment.SelectedIndex = comboBoxDepartment.FindString(needs.id_Department.ToString()); } else { if (AutorizationForm.users.typeDep != "1" && AutorizationForm.users.typeDep != "4") { textBoxItem.Text = ""; textBoxTotalItems.Text = ""; textBoxPrice.Text = ""; textBoxTotalPrice.Text = ""; textBoxJustification.Text = ""; textBoxComment.Text = ""; } else { textBoxItem.Text = ""; textBoxTotalItems.Text = ""; textBoxPrice.Text = ""; textBoxTotalPrice.Text = ""; textBoxJustification.Text = ""; textBoxComment.Text = ""; comboBoxDepartment.SelectedItem = null; } } }
private void buttonDel_Click(object sender, EventArgs e) { try { if (listViewNeeds.SelectedItems.Count == 1) { Needs needs = listViewNeeds.SelectedItems[0].Tag as Needs; Program.csr.Needs.Remove(needs); Program.csr.SaveChanges(); ShowNeeds(); } if (AutorizationForm.users.typeDep != "1" && AutorizationForm.users.typeDep != "4") { textBoxItem.Text = ""; textBoxTotalItems.Text = ""; textBoxPrice.Text = ""; textBoxTotalPrice.Text = ""; textBoxJustification.Text = ""; textBoxComment.Text = ""; } else { textBoxItem.Text = ""; textBoxTotalItems.Text = ""; textBoxPrice.Text = ""; textBoxTotalPrice.Text = ""; textBoxJustification.Text = ""; textBoxComment.Text = ""; comboBoxDepartment.SelectedItem = null; } } catch { MessageBox.Show("Невозможно удалить, эта запись используется!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }