Beispiel #1
0
        public static Toppings GetToppings(string productType)
        {
            int           i    = 0;
            Toppings      tops = null;
            SqlConnection conn = GetConnection();
            SqlCommand    comm = new SqlCommand("SELECT * FROM Toppings WHERE ProductType = @ProductType ORDER BY Name", conn);

            comm.Parameters.AddWithValue("@ProductType", productType);
            try
            {
                tops = new Toppings(6);
                conn.Open();
                SqlDataReader dr = comm.ExecuteReader(CommandBehavior.SingleResult);
                while (true)
                {
                    if (!dr.Read())
                    {
                        break;
                    }
                    tops.ToppingList[i] = false;

                    tops.ToppingNames[i]  = (string)dr["Name"];
                    tops.ToppingPrices[i] = Convert.ToDouble(dr["Price"]);
                    i++;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                tops = null;
            }
            finally
            {
                if (conn.State == System.Data.ConnectionState.Open)
                {
                    conn.Close();
                }
            }
            return(tops);
        }
Beispiel #2
0
 public Product()
 {
     this.tops = null;
 }
Beispiel #3
0
 public Product(Toppings t)
 {
     this.tops = t;
 }
Beispiel #4
0
        public static int InsertLineItem(int orderID, string productName, string productSize, double productBasePrice, double productTotalPrice, Toppings tops)
        {
            int           id         = -1;
            int           lineItemID = -1;
            SqlConnection conn       = GetConnection();
            SqlCommand    comm       = new SqlCommand("INSERT INTO LineItems (OrderID, ProductName, ProductSize, ProductBasePrice, ProductTotalPrice) VALUES (@OrderID, @ProductName, @ProductSize, @ProductBasePrice, @ProductTotalPrice)", conn);

            comm.Parameters.AddWithValue("@OrderID", orderID);
            comm.Parameters.AddWithValue("@ProductName", productName);
            comm.Parameters.AddWithValue("@ProductSize", productSize);
            comm.Parameters.AddWithValue("@ProductBasePrice", productBasePrice);
            comm.Parameters.AddWithValue("@ProductTotalPrice", productTotalPrice);
            try
            {
                conn.Open();
                id = comm.ExecuteNonQuery();
                conn.Close();
                conn.Open();
                lineItemID = GetMaxLineItemID();
                if (tops != null)
                {
                    int i = 0;
                    while (true)
                    {
                        if (i >= tops.ToppingList.Length)
                        {
                            break;
                        }
                        if (tops.ToppingList[i])
                        {
                            InsertLineItemToppings(lineItemID, tops.ToppingNames[i], tops.ToppingPrices[i]);
                        }
                        i++;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                id = -1;
            }
            finally
            {
                if (conn.State == System.Data.ConnectionState.Open)
                {
                    conn.Close();
                }
            }
            return(id);
        }