Exemple #1
0
 private void btnSell_Click(object sender, EventArgs e)
 {
     try
     {
         int maxToSell = Int32.Parse(txtStock.Text);
         int newStock  = maxToSell - Convert.ToInt32(nUDQuantity.Value);
         if (txtCustomerName.Text == "" || txtItemName.Text == "" || txtPrice.Text == "")
         {
             MessageBox.Show("Fill all fields correct");
         }
         else if (Convert.ToInt32(nUDQuantity.Value) == 0 || Convert.ToInt32(nUDQuantity.Value) > maxToSell)
         {
             MessageBox.Show("Quantity must be between 1 and  " + txtStock.Text);
         }
         else
         {
             store = Store.StoreInstance;
             Purchase purchase = new Purchase(txtCustomerName.Text, txtItemName.Text, Convert.ToDouble(txtPrice.Text), Convert.ToInt32(nUDQuantity.Value), DateTime.Parse(dateTimePurchase.Text));
             bs.AddPurchase(purchase);
             if (itemType == "Book")
             {
                 bs.SellBook(store.Id, newStock);
             }
             else if (itemType == "Journal")
             {
                 bs.SellJournal(store.Id, newStock);
             }
             MessageBox.Show("You have successfully selled " + txtItemName.Text + " to " + txtCustomerName.Text);
             store.Display();
             ClearFields();
             AddItem add = AddItem.AddItemInstance;
             add.ClearFields();
             this.Hide();
             store.Hide();
             store.Show();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }