示例#1
0
        public override void Execute()
        {
            if (Product is Product)
            {
                Product prod = (Product as Product);
                prod.GetStorageStatus();
                if (prod.StorageWithAmount == null)
                {
                    throw new Exception("FAIL!");
                }
                if (!prod.StorageWithAmount.ContainsKey(shopID))
                {
                    prod.StorageWithAmount.TryAdd(shopID, -Amount);
                }
                else
                {
                    prod.StorageWithAmount[shopID] -= Amount;
                }
                UpdateProductEvent?.Invoke(prod);
                if (!HideMessageBox && prod.StorageWithAmount.Where(x => x.Value < 0).Count() > 0)
                {
                    // Hvis det er nogle storageroom med negativ værdi
                    StringBuilder Text = new StringBuilder();

                    Text.Append("Produktet: " + prod.Name + "'s lagerstatus har fejl!\n");

                    foreach (KeyValuePair <int, int> strorageWithAmount in prod.StorageWithAmount)
                    {
                        string AppendString = "";
                        if (strorageWithAmount.Value < 0 && _storageController.StorageRoomDictionary.ContainsKey(strorageWithAmount.Key))
                        {
                            AppendString = " **** - " + _storageController.StorageRoomDictionary[strorageWithAmount.Key].Name + " har " + strorageWithAmount.Value.ToString() + " stk\n";
                        }
                        else
                        {
                            if (_storageController.StorageRoomDictionary.ContainsKey(strorageWithAmount.Key))
                            {
                                AppendString = " - " + _storageController.StorageRoomDictionary[strorageWithAmount.Key].Name + " har " + strorageWithAmount.Value.ToString() + " stk\n";
                            }
                        }
                        Text.Append(AppendString);
                    }
                    string Output = Text.ToString();
                    var    NewBox = MessageBox.Show(Text.ToString());
                }
                prod.UpdateInDatabase();
            }
            else if (Product is TempProduct)
            {
                Product.ID = TempProduct.GetNextID();
                Product.UploadToDatabase();
                _storageController.TempProductDictionary.TryAdd(Product.ID, Product as TempProduct);
            }
        }
示例#2
0
 private BaseProduct _getProduct(int id, string Type)
 {
     if (Type == "product")
     {
         if (_storageController != null)
         {
             return(_storageController.ProductDictionary[id]);
         }
         return(new Product(id));
     }
     else if (Type == "temp_product")
     {
         TempProduct ResultsProduct;
         if (_storageController != null)
         {
             ResultsProduct = _storageController.TempProductDictionary[id];
         }
         else
         {
             ResultsProduct = new TempProduct(id);
         }
         if (ResultsProduct.ResolvedProductID != 0)
         {
             if (_storageController != null)
             {
                 return(_storageController.ProductDictionary[ResultsProduct.ResolvedProductID]);
             }
             return(new Product(ResultsProduct.ResolvedProductID));
         }
         else
         {
             return(ResultsProduct);
         }
     }
     else if (Type == "service_product")
     {
         if (_storageController != null)
         {
             return(_storageController.ServiceProductDictionary[id]);
         }
         return(new ServiceProduct(id));
     }
     else
     {
         throw new UnknownProductTypeException("Dette produkt eksisetere ikke");
     }
 }