예제 #1
0
    public static void InsertItem(int MenuItemID, string MenuItemType, string ItemSize, int Quantity,
                                  decimal ItemPrice)
    {
        ShoppingCart cart = StoredCart.FetchCart();

        cart.Insert(MenuItemID, MenuItemType, ItemSize, Quantity, ItemPrice);
    }
예제 #2
0
    protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        Repeater    rpt         = (Repeater)source;
        HiddenField IDControl   = (HiddenField)rpt.FindControl("ItemID");
        HiddenField NameControl = (HiddenField)rpt.FindControl("Item");

        int     MenuItemID = Convert.ToInt32(IDControl.Value);
        string  ItemName   = NameControl.Value;
        string  ItemSize   = e.CommandName.ToString();
        decimal Price      = Convert.ToDecimal(e.CommandArgument);

        StoredCart.InsertItem(MenuItemID, ItemName, ItemSize, 1, Price);
        Label1.Text = string.Format("{0} ({1}) added to the shopping cart", ItemName, ItemSize);
    }
예제 #3
0
    protected void Repeater1_ItemCommand(object source, System.Web.UI.WebControls.RepeaterCommandEventArgs e)
    {
        Repeater    rpt         = (Repeater)source;
        HiddenField IDControl   = (HiddenField)rpt.FindControl("ItemID");
        HiddenField NameControl = (HiddenField)rpt.FindControl("ItemName");

        int     GameID  = Convert.ToInt32(IDControl.Value);
        string  Title   = NameControl.Value;
        string  Console = e.CommandName.ToString();
        decimal Price   = Convert.ToDecimal(e.CommandArgument);

        //uncomment the next line once the Cart Classes have been added
        StoredCart.InsertItem(GameID, Title, Console, 1, Price);
        Label5.Text = string.Format("{0} ({1}) added to the shopping cart", Title, Console);
    }
예제 #4
0
    public static void DeleteItem(int MenuItemID, string ItemSize)
    {
        ShoppingCart cart = StoredCart.FetchCart();

        cart.Delete(MenuItemID, ItemSize);
    }
예제 #5
0
    public static void UpdateItem(int MenuItemID, string ItemSize, int Quantity)
    {
        ShoppingCart cart = StoredCart.FetchCart();

        cart.Update(MenuItemID, ItemSize, Quantity);
    }
예제 #6
0
    public static List <CartItem> ReadItems()
    {
        ShoppingCart cart = StoredCart.FetchCart();

        return(cart.Items);
    }
예제 #7
0
    protected void Wizard1_FinishButtonClick(object sender, WizardNavigationEventArgs e)
    {
        //insert the order and order lines into database
        SqlConnection  conn  = null;
        SqlTransaction trans = null;
        SqlCommand     cmd   = default(SqlCommand);
        ShoppingCart   cart  = StoredCart.Read();

        // if there is not shopping cart, then something has gone wrong
        if (cart == null || cart.Items.Count == 0)
        {
            e.Cancel = true;
            return;
        }

        // try / catch protects us against exeptions
        try
        {
            int OrderID = 0;
            // Create and open a new connection to the database
            conn = new SqlConnection(ConfigurationManager.ConnectionStrings
                                     ["ConnectionString"].ConnectionString);
            conn.Open();
            //start a new transaction
            trans = conn.BeginTransaction();
            //create a new command - the stored procedure
            cmd             = new SqlCommand();
            cmd.Connection  = conn;
            cmd.Transaction = trans;
            //set the order details: the name and type of the command
            cmd.CommandText = "AddOrder";
            cmd.CommandType = CommandType.StoredProcedure;
            //Set up the parameters to pass to the database

            cmd.Parameters.Add("@Name", SqlDbType.VarChar, 50);
            cmd.Parameters.Add("@Address", SqlDbType.VarChar, 50);
            cmd.Parameters.Add("@Email", SqlDbType.VarChar, 255);
            cmd.Parameters.Add("@OrderTime", SqlDbType.DateTime);
            cmd.Parameters.Add("@DeliveryCharge", SqlDbType.Money);
            cmd.Parameters.Add("@TotalValue", SqlDbType.Money);
            cmd.Parameters.Add("@CustomerRequest", SqlDbType.VarChar, 50);
            cmd.Parameters.Add("@OrderID", SqlDbType.Int);

            //set the values for the parameters

            cmd.Parameters["@Name"].Value            = ((TextBox)Wizard1.FindControl("txtName")).Text;
            cmd.Parameters["@Address"].Value         = ((TextBox)Wizard1.FindControl("txtAddress")).Text;
            cmd.Parameters["@Email"].Value           = ((TextBox)Wizard1.FindControl("txtEmail")).Text;
            cmd.Parameters["@OrderTime"].Value       = DateTime.Now;
            cmd.Parameters["@DeliveryCharge"].Value  = cart.DeliveryCharge;
            cmd.Parameters["@TotalValue"].Value      = cart.Total;
            cmd.Parameters["@CustomerRequest"].Value = "";
            cmd.Parameters["@OrderID"].Direction     = ParameterDirection.Output;
            //Execute the query and parameters for the Order lines.
            cmd.ExecuteNonQuery();

            OrderID = Convert.ToInt32(cmd.Parameters["@OrderID"].Value);

            cmd.CommandText = "AddOrderItems";
            cmd.Parameters.Clear();
            cmd.Parameters.Add("@fkOrderID", SqlDbType.Int);
            cmd.Parameters.Add("@fkMenuItemID", SqlDbType.Int);
            cmd.Parameters.Add("@fkItemSize", SqlDbType.VarChar, 10);
            cmd.Parameters.Add("@ItemName", SqlDbType.VarChar, 50);
            cmd.Parameters.Add("@Quantity", SqlDbType.Int);
            cmd.Parameters.Add("@SubTotal", SqlDbType.Money);
            cmd.Parameters["@fkOrderID"].Value = OrderID;
            // Loop through the items in the shopping cart adding each one
            foreach (CartItem item in cart.Items)
            {
                cmd.Parameters["@fkMenuItemID"].Value = item.MenuItemID;
                cmd.Parameters["@fkItemSize"].Value   = item.ItemSize;
                cmd.Parameters["@ItemName"].Value     = item.ItemName;
                cmd.Parameters["@Quantity"].Value     = item.Quantity;
                cmd.Parameters["@SubTotal"].Value     = item.SubTotal;

                cmd.ExecuteNonQuery();
            }
            //if no errors save to database and confirm onrder onscreen
            trans.Commit();
            lblSuccess.Visible = true;
        }
        catch (Exception)
        {
            if (trans != null)
            {
                trans.Rollback();
            }

            lblError.Visible = true;
            return;
        }
        finally
        {
            if (conn != null)
            {
                conn.Close();
            }
        }
        cart.Items.Clear();
    }
예제 #8
0
    protected void Wizard2_FinishButtonClick(object sender, WizardNavigationEventArgs e)
    {
        SqlConnection  conn  = null;
        SqlTransaction trans = null;
        SqlCommand     cmd   = default(SqlCommand);
        ShoppingCart   cart  = StoredCart.Read();

        if (cart == null || cart.Items.Count == 0)
        {
            e.Cancel = true;
            return;
        }

        try
        {
            int SaleID = 0;

            conn = new SqlConnection(ConfigurationManager.ConnectionStrings
                                     ["CSConnectionString"].ConnectionString);
            conn.Open();

            trans = conn.BeginTransaction();

            cmd             = new SqlCommand();
            cmd.Connection  = conn;
            cmd.Transaction = trans;

            cmd.CommandText = "spInsertSale";
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add("@OrderDate", SqlDbType.DateTime);
            cmd.Parameters.Add("@CustName", SqlDbType.VarChar, 50);
            cmd.Parameters.Add("@Address", SqlDbType.VarChar, 250);
            cmd.Parameters.Add("@PostCode", SqlDbType.VarChar, 50);
            cmd.Parameters.Add("@DeliveryCharge", SqlDbType.Money);
            cmd.Parameters.Add("@TotalValue", SqlDbType.Money);
            cmd.Parameters.Add("@OrderID", SqlDbType.Int);

            cmd.Parameters["@OrderDate"].Value      = DateTime.Now;
            cmd.Parameters["@CustName"].Value       = ((TextBox)Wizard1.FindControl("txtName")).Text;
            cmd.Parameters["@Address"].Value        = ((TextBox)Wizard1.FindControl("txtAddress")).Text;
            cmd.Parameters["@PostCode"].Value       = ((TextBox)Wizard1.FindControl("txtEmail")).Text;
            cmd.Parameters["@DeliveryCharge"].Value = cart.DeliveryCharge;
            cmd.Parameters["@TotalValue"].Value     = cart.Total;
            cmd.Parameters["@OrderID"].Direction    = ParameterDirection.Output;

            cmd.ExecuteNonQuery();
            OrderID = Convert.ToInt32(cmd.Parameters["@OrderID"].Value);

            cmd.CommandText = "spInsertOrderItems";
            cmd.Parameters.Clear();
            cmd.Parameters.Add("@fkOrderID", SqlDbType.Int);
            cmd.Parameters.Add("@fkMenuItemID", SqlDbType.Int);
            cmd.Parameters.Add("@ItemSize", SqlDbType.VarChar, 10);
            cmd.Parameters.Add("@ItemName", SqlDbType.VarChar, 50);
            cmd.Parameters.Add("@Quantity", SqlDbType.Int);
            cmd.Parameters.Add("@SubTotal", SqlDbType.Money);
            cmd.Parameters["@fkOrderID"].Value = OrderID;


            foreach (CartItem item in cart.Items)
            {
                cmd.Parameters["@fkMenuItemID"].Value = item.OrderID;
                cmd.Parameters["@ItemSize"].Value     = item.Console;
                cmd.Parameters["@ItemSize"].Value     = item.Title;
                cmd.Parameters["@Quantity"].Value     = item.Quantity;
                cmd.Parameters["@SubTotal"].Value     = item.SubTotal;

                cmd.ExecuteNonQuery();
            }

            trans.Commit();
            lblSuccess.Visible = true;
        }
        catch
        {
            if (trans != null)
            {
                trans.Rollback();
            }
            lblError.Visible = true;
            return;
        }
        finally
        {
            if (conn != null)
            {
                conn.Close();
            }
        }
        cart.Items.Clear();
    }