private void buttonEdit_Click(object sender, EventArgs e) { if (comboBoxProvider.SelectedItem != null && comboBoxMagazine.SelectedItem != null && textBoxPieces.Text != "" && listView_Supply.SelectedItems.Count == 1) { SupplySet supplySet = listView_Supply.SelectedItems[0].Tag as SupplySet; supplySet.IdMagazine = Convert.ToInt32(comboBoxMagazine.SelectedItem.ToString().Split('.')[0]); supplySet.IdProvider = Convert.ToInt32(comboBoxProvider.SelectedItem.ToString().Split('.')[0]); supplySet.Pieces = Convert.ToInt32(textBoxPieces.Text); supplySet.Price = Convert.ToInt64(textBoxPrice.Text); supplySet.Name = textBoxName.Text; Program.bdSKI.SaveChanges(); ShowSupplies(); } }
private void buttonAdd_Click(object sender, EventArgs e) { if (comboBoxProvider.SelectedItem != null && comboBoxMagazine.SelectedItem != null && textBoxPieces.Text != "" && textBoxPrice.Text != "" && textBoxName.Text != "") { SupplySet supplySet = new SupplySet(); supplySet.IdMagazine = Convert.ToInt32(comboBoxMagazine.SelectedItem.ToString().Split('.')[0]); supplySet.IdProvider = Convert.ToInt32(comboBoxProvider.SelectedItem.ToString().Split('.')[0]); supplySet.Pieces = Convert.ToInt32(textBoxPieces.Text); supplySet.Price = Convert.ToInt64(textBoxPrice.Text); supplySet.Name = textBoxName.Text; Program.bdSKI.SupplySet.Add(supplySet); Program.bdSKI.SaveChanges(); ShowSupplies(); } }
private void listView_Supply_SelectedIndexChanged(object sender, EventArgs e) { if (listView_Supply.SelectedItems.Count == 1) { SupplySet supplySet = listView_Supply.SelectedItems[0].Tag as SupplySet; comboBoxProvider.SelectedIndex = comboBoxProvider.FindString(supplySet.IdProvider.ToString()); comboBoxMagazine.SelectedIndex = comboBoxMagazine.FindString(supplySet.IdMagazine.ToString()); textBoxPieces.Text = supplySet.Pieces.ToString(); textBoxPrice.Text = supplySet.Price.ToString(); textBoxName.Text = supplySet.Name; } else { comboBoxProvider.SelectedItem = null; comboBoxMagazine.SelectedItem = null; textBoxPieces.Text = ""; textBoxPrice.Text = ""; textBoxName.Text = ""; } }
private void buttonDel_Click(object sender, EventArgs e) { try { if (listView_Supply.SelectedItems.Count == 1) { SupplySet clientSet = listView_Supply.SelectedItems[0].Tag as SupplySet; Program.bdSKI.SupplySet.Remove(clientSet); Program.bdSKI.SaveChanges(); ShowSupplies(); } comboBoxProvider.SelectedItem = null; comboBoxMagazine.SelectedItem = null; textBoxPieces.Text = ""; textBoxName.Text = ""; textBoxPrice.Text = ""; } catch { MessageBox.Show("Невозможно удалить, эта запись используется!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }