Ejemplo n.º 1
0
 // Adds raw material to database with given name and quantity
 public void AddRawMaterial(RawMaterial rawMaterial)
 {
     try
     {
         // Create a SQL command that takes user input -- raw material name, quantity -- and inputs into RawMaterials database
         Cn.Open();
         cmd = new SqlCommand("Insert into RawMaterials(RawMaterialName, Quantity) Values(@RawMaterialName,  @Quantity);", Cn);
         cmd.Parameters.AddWithValue("@RawMaterialName", rawMaterial.rawMaterialName);
         cmd.Parameters.AddWithValue("@Quantity", rawMaterial.quantity);
         cmd.ExecuteNonQuery(); // Execute the sql command
     }
     catch (Exception err)
     {
         MessageBox.Show(err.Message, "Warning!");
     }
     finally
     {
         Cn.Close();
     }
 }
Ejemplo n.º 2
0
        // Function to return a list of products from the product database
        public List <RawMaterial> CreateRawMaterialList()
        {
            // Create a new list of Products
            List <RawMaterial> rawMaterials;

            rawMaterials = new List <RawMaterial>();

            try
            {
                RawMaterial tempMaterial;

                // Create the sql command
                Cn.Open();
                cmd    = new SqlCommand("SELECT TRIM(RawMaterialName) AS RawMaterialName, Quantity FROM RawMaterials", Cn);
                reader = cmd.ExecuteReader();

                // Get the information from the Products databse and add it to the list of Product objects
                while (reader.Read())
                {
                    string name     = (string)reader["RawMaterialName"];
                    int    quantity = (int)reader["Quantity"];
                    tempMaterial = new RawMaterial(name, quantity);
                    rawMaterials.Add(tempMaterial);
                }

                reader.Close();
            }
            catch (Exception err)
            {
                throw;
            }
            finally
            {
                Cn.Close();
            }

            return(rawMaterials);
        }