private void listViewExtra_SelectedIndexChanged(object sender, EventArgs e) { if (listViewExtra.SelectedItems.Count == 1) { Extradition extra = listViewExtra.SelectedItems[0].Tag as Extradition; comboBoxMaterial.SelectedIndex = comboBoxMaterial.FindString(extra.Id_shipment.ToString()); comboBoxAgent.SelectedIndex = comboBoxAgent.FindString(extra.Id_agent.ToString()); dateTimePickerEx.Value = extra.DateOfUssue.GetValueOrDefault(); textBoxQuant.Text = extra.Quantity.ToString(); } else { comboBoxMaterial.SelectedItem = null; comboBoxAgent.SelectedItem = null; dateTimePickerEx.Value = DateTime.Now; textBoxQuant.Text = ""; } }
private void buttonDel_Click(object sender, EventArgs e) { try { if (listViewExtra.SelectedItems.Count == 1) { Extradition extra = listViewExtra.SelectedItems[0].Tag as Extradition; Program.kv.Extradition.Remove(extra); Program.kv.SaveChanges(); ShowExtradit(); } comboBoxMaterial.SelectedItem = null; comboBoxAgent.SelectedItem = null; dateTimePickerEx.Value = DateTime.Now; textBoxQuant.Text = ""; } catch { MessageBox.Show("Невозможно удалить, эта запись используется!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void buttonAdd_Click(object sender, EventArgs e) { try { if (comboBoxMaterial.SelectedItem != null && comboBoxAgent.SelectedItem != null && textBoxQuant.Text != "") { Extradition extra = new Extradition(); extra.Id_shipment = Convert.ToInt32(comboBoxMaterial.SelectedItem.ToString().Split('.')[0]); extra.Id_agent = Convert.ToInt32(comboBoxAgent.SelectedItem.ToString().Split('.')[0]); extra.DateOfUssue = dateTimePickerEx.Value; extra.Quantity = Convert.ToInt32(textBoxQuant.Text); Program.kv.Extradition.Add(extra); Program.kv.SaveChanges(); ShowExtradit(); } } catch (Exception a) { MessageBox.Show("" + a.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } }