private void SaveEquipment(object obj) { try { var newObject = SelectedEquipment.Id; SelectedEquipment.CategoryId = SelectedCategory.Id; var stat = _equipmentService.InsertOrUpdate(SelectedEquipment); if (stat != string.Empty) { MessageBox.Show("Can't save" + Environment.NewLine + stat, "Can't save", MessageBoxButton.OK, MessageBoxImage.Error); } else if (newObject == 0) { Equipments.Insert(0, SelectedEquipment); SelectedEquipment.Number = _equipmentService.GetEquipmentNumber(SelectedEquipment.Id); stat = _equipmentService.InsertOrUpdate(SelectedEquipment); if (stat != string.Empty) { MessageBox.Show("Can't save Number" + Environment.NewLine + stat, "Can't save", MessageBoxButton.OK, MessageBoxImage.Error); } } } catch (Exception exception) { MessageBox.Show("Can't save" + Environment.NewLine + exception.Message, "Can't save", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void butOK_Click(object sender, EventArgs e) { if (textDatePurchased.errorProvider1.GetError(textDatePurchased) != "" || textDateSold.errorProvider1.GetError(textDateSold) != "" || textPurchaseCost.errorProvider1.GetError(textPurchaseCost) != "" || textMarketValue.errorProvider1.GetError(textMarketValue) != "") { MsgBox.Show(this, "Please fix data entry errors first."); return; } if (textDescription.Text == "") { MsgBox.Show(this, "Please enter a description."); return; } if (textDatePurchased.Text == "") { MsgBox.Show(this, "Please enter date purchased."); return; } if (PIn.Date(textDatePurchased.Text) > DateTime.Today) { if (!MsgBox.Show(this, MsgBoxButtons.OKCancel, "Date is in the future. Continue anyway?")) { return; } } Equip.Description = textDescription.Text; Equip.SerialNumber = textSerialNumber.Text; Equip.ModelYear = textModelYear.Text; Equip.DatePurchased = PIn.Date(textDatePurchased.Text); Equip.DateSold = PIn.Date(textDateSold.Text); Equip.PurchaseCost = PIn.Double(textPurchaseCost.Text); Equip.MarketValue = PIn.Double(textMarketValue.Text); Equip.Location = textLocation.Text; Equip.Status = textStatus.Text; if (!string.IsNullOrEmpty(textSerialNumber.Text) && Equipments.HasExisting(Equip)) { MsgBox.Show(this, "Serial number already in use. Please enter another."); return; } if (IsNew) { Equipments.Insert(Equip); } else { Equipments.Update(Equip); } DialogResult = DialogResult.OK; }