Example #1
0
 private void AddCommandExecute()
 {
     try
     {
         if (EntryValidation.ValidateProductName(WarehouseItem.ProductName) == false)
         {
             MessageBox.Show("Product name can only contain letters and numbers. Please try again", "Invalid input");
             return;
         }
         if (EntryValidation.ValidateProductNumber(WarehouseItem.ProductNumber) == false)
         {
             MessageBox.Show("Product number can only contain numbers. Please try again", "Invalid input");
             return;
         }
         if (EntryValidation.ValidateAmount((int)WarehouseItem.Amount) == false)
         {
             MessageBox.Show("Amount must be greated than 0 and less or equat to 100. Please try again", "Invalid input");
             return;
         }
         if (EntryValidation.ValidatePriceFormat(WarehouseItem.Price) == false)
         {
             MessageBox.Show("Price can contain only decimal numbers (numbers, comma and dot is allowed). Please try again", "Invalid input");
             return;
         }
         if (EntryValidation.ValidatePriceAmount(WarehouseItem.Price) == false)
         {
             MessageBox.Show("Price must be a positive number. Please try again", "Invalid input");
             return;
         }
         WarehouseItem.InStock = false;
         dataBaseService.AddWarehouseItem(WarehouseItem);
         IsUpdateWarehouseItem = true;
         string logMessage = string.Format("Warehouse Item: {0}, Item number: {1}, Item amount: {2}, Item price: {3} was added to database.", WarehouseItem.ProductName,
                                           WarehouseItem.ProductNumber, WarehouseItem.Amount, WarehouseItem.Price);
         actionEventObject.OnActionPerformed(logMessage);
         MessageBox.Show("New Warehouse Item Added Successfully!", "Info");
         addItem.Close();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }