Beispiel #1
0
 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;
 }