public static bool DiscardInputMaterial(DiscardedInputMaterial discardedInputMaterial, int inputMaterialId, int productMaterialId)
 {
     db = new BMAEntities();
     InputMaterial inputMaterial = db.InputMaterials.FirstOrDefault(m => m.InputMaterialId == inputMaterialId);
     ProductMaterial productMaterial = db.ProductMaterials.FirstOrDefault(m => m.ProductMaterialId == productMaterialId);
     if (discardedInputMaterial == null)
     {
         return false;
     }
     try
     {
         db.DiscardedInputMaterials.Add(discardedInputMaterial);
         inputMaterial.RemainQuantity = inputMaterial.RemainQuantity - discardedInputMaterial.DiscardQuantity;
         int changeMaterial = productMaterial.CurrentQuantity - discardedInputMaterial.DiscardQuantity;
         productMaterial.CurrentQuantity = changeMaterial;
         db.SaveChanges();
     }
     catch (Exception e)
     {
         string s = e.ToString();
         return false;
     }
     finally
     {
         db.Dispose();
     }
     return true;
 }
        public int DiscardInputMaterial(FormCollection f)
        {
            try
            {
                db = new BMAEntities();
                String discardQuantityString = f["discardQuantity"];
                String discardNote = f["discardNote"];
                String inputMaterialIdString = f["InputMaterialId"];
                String productMaterialIdString = f["ProductMaterialId"];

                int inputMaterialId = Convert.ToInt32(inputMaterialIdString);
                int discardQuantity = Convert.ToInt32(discardQuantityString);
                int productMaterialId = Convert.ToInt32(productMaterialIdString);

                InputMaterial inputMaterial = db.InputMaterials.FirstOrDefault(m => m.InputMaterialId == inputMaterialId);
                int checkQuantity = discardQuantity - inputMaterial.RemainQuantity;

                DiscardedInputMaterial discardedInputMaterial = new DiscardedInputMaterial();
                if (checkQuantity > 0)
                {
                    return -1;
                }
                else
                {
                    try
                    {
                        discardedInputMaterial.DiscardDate = DateTime.Now;
                        discardedInputMaterial.InputMaterialId = inputMaterialId;
                        discardedInputMaterial.DiscardNote = discardNote;
                        discardedInputMaterial.DiscardQuantity = discardQuantity;

                    }
                    catch (Exception)
                    {
                        return 0;

                    }

                    bool result = DiscardInputMaterialBusiness.DiscardInputMaterial(discardedInputMaterial, inputMaterialId,
                        productMaterialId);
                    if (result)
                    {
                        return 1;
                    }
                    else
                    {
                        return 0;
                    }

                }
            }
            catch (Exception)
            {
                return 0;
            }
        }