private void buttonInsertPart_Click(object sender, EventArgs e) { if (!_editingPart) { textBoxPartId.Text = "0"; buttonUpdatePart.Enabled = false; buttonInsertPart.Text = "Save"; buttonCancelEditingPart.Enabled = true; _editingPart = true; } else { var id = int.Parse(textBoxPartId.Text); var countryId = LocalDataHolder.Country_Get(comboBoxPartCountry.SelectedIndex).Id; var manufacturerId = LocalDataHolder.Manufacturer_Get(comboBoxPartManufacturer.SelectedIndex).Id; var name = textBoxPartName.Text; string technicalData = ""; try { var technicalDataJson = JToken.Parse(richTextBoxPartTechnicalData.Text); technicalData = technicalDataJson.ToString(Formatting.None); } catch (Exception) { MessageBox.Show("Error Parsing Technical Data JSON"); return; } var lifetime = int.Parse(textBoxPartLifetime.Text); var count = int.Parse(textBoxPartCount.Text); var part = new Part(id, countryId, manufacturerId, name, technicalData, lifetime, count); LocalDataHolder.Part_Insert(part); ClearPartFields(); FillData(); buttonUpdatePart.Enabled = true; buttonInsertPart.Text = "Insert"; buttonCancelEditingPart.Enabled = false; _editingPart = false; } }
private void buttonUpdateCountry_Click(object sender, EventArgs e) { if (!_editingCountry) { if (_selectedCountryIndex == -1) { MessageBox.Show("Select Country"); return; } try { var country = LocalDataHolder.Country_Get(_selectedCountryIndex); textBoxCountryId.Text = country.Id.ToString(); textBoxCountryName.Text = country.Name; } catch (IndexOutOfRangeException) { MessageBox.Show("No Local Country With Index " + _selectedCountryIndex + " Known"); } buttonUpdateCountry.Text = "Save"; buttonInsertCountry.Enabled = false; buttonCancelEditingCountry.Enabled = true; _editingCountry = true; } else { var id = int.Parse(textBoxCountryId.Text); var name = textBoxCountryName.Text; var country = new Country(id, name); LocalDataHolder.Country_Update(country); ClearCountryFields(); FillData(); buttonUpdateCountry.Text = "Update"; buttonInsertCountry.Enabled = true; buttonCancelEditingCountry.Enabled = false; _editingCountry = false; } }