private void MainForm_Load(object sender, EventArgs e) { listBoxGem.Items.Clear(); servis.FindAll(listBoxGem); comboBoxColor.Items.Clear(); servis.GetExistingColors(comboBoxColor); if (this.comboBoxColor.Items.Count != 0) { if (this.comboBoxColor.SelectedItem != null) { this.comboBoxColor.SelectedIndex = 0; } } }
private void buttonSave_Click(object sender, EventArgs e) { GemDTO packet = new GemDTO { Id = -1, ColorId = -1, ColorName = textBoxColor.Text, Name = textBoxName.Text, Transparency = checkBoxTransparency.Checked, Description = textBoxDescription.Text }; if (comboBoxType.SelectedIndex == 0) { packet.Type = Gem.Types.ORNAMENTAL; } else if (comboBoxType.SelectedIndex == 1) { packet.Type = Gem.Types.SEMIPRECIOUS; } else { packet.Type = Gem.Types.PRECIOUS; } try { if (gem != null) { this.Close(); return; } servis.Save(packet); if (listBoxGem.Items.Count > 0) { listBoxGem.Items.Clear(); } servis.FindAll(listBoxGem); comboBoxColor.Items.Clear(); servis.GetExistingColors(comboBoxColor); this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }