예제 #1
0
    private ArrayList GetOrders()
    {
        ContentPlaceHolder      cph = (ContentPlaceHolder)Master.FindControl("ContentPlaceHolder1");
        ControlFinder <TextBox> cf  = new ControlFinder <TextBox>();

        cf.FindControlsRecursive(cph);

        var textBoxList = cf.FoundControls;

        ArrayList orderList = new ArrayList();

        foreach (TextBox textBox in textBoxList)
        {
            if (textBox.Text != "")
            {
                int amountOfOrders = Convert.ToInt32(textBox.Text);

                if (amountOfOrders > 0)
                {
                    _Coffee coffee = ConnectionClass.GetCoffeById(Convert.ToInt32(textBox.ID));
                    Order   order  = new Order(
                        Session["login"].ToString(), coffee.Name, amountOfOrders, coffee.Price, DateTime.Now, false);
                    orderList.Add(order);
                }
            }
        }
        return(orderList);
    }
예제 #2
0
    public static _Coffee GetCoffeById(int id)
    {
        string  query  = string.Format("SELECT * FROM coffee WHERE id = '{0}'", id);
        _Coffee coffee = null;

        try
        {
            conn.Open();
            command.CommandText = query;
            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                string name    = reader.GetString(1);
                string type    = reader.GetString(2);
                double price   = reader.GetDouble(3);
                string roast   = reader.GetString(4);
                string country = reader.GetString(5);
                string image   = reader.GetString(6);
                string review  = reader.GetString(7);

                coffee = new _Coffee(name, type, price, roast, country, image, review);
            }
        }
        finally
        {
            conn.Close();
        }

        return(coffee);
    }
예제 #3
0
    public static void AddCoffee(_Coffee coffee)
    {
        string query = string.Format(
            "INSERT INTO coffee VALUES ('{0}', '{1}', @price, '{2}', '{3}', '{4}', '{5}')",
            coffee.Name, coffee.Type, coffee.Roast, coffee.Country, coffee.Image, coffee.Review);

        command.CommandText = query;
        command.Parameters.Add(new SqlParameter("price", coffee.Price));
        try
        {
            conn.Open();
            command.ExecuteNonQuery();
        }
        finally
        {
            conn.Close();
            command.Parameters.Clear();
        }
    }
예제 #4
0
    public static ArrayList GetCoffeByType(string coffeeType)
    {
        ArrayList list  = new ArrayList();
        string    query = string.Format("SELECT * FROM coffee WHERE type LIKE '{0}'", coffeeType);

        if (coffeeType == "")
        {
            query = string.Format("SELECT * FROM coffee");
        }

        try
        {
            conn.Open();
            command.CommandText = query;
            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                int    id      = reader.GetInt32(0);
                string name    = reader.GetString(1);
                string type    = reader.GetString(2);
                double price   = reader.GetDouble(3);
                string roast   = reader.GetString(4);
                string country = reader.GetString(5);
                string image   = reader.GetString(6);
                string review  = reader.GetString(7);

                _Coffee coffee = new _Coffee(id, name, type, price, roast, country, image, review);
                list.Add(coffee);
            }
        }
        finally
        {
            conn.Close();
        }

        return(list);
    }
예제 #5
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
            string name  = txtName.Text;
            string type  = txtType.Text;
            double price = Convert.ToDouble(txtPrice.Text);
            price = price / 100;
            string roast   = txtRoast.Text;
            string country = txtCountry.Text;
            string image   = "../Images/Coffee/" + ddlImage.SelectedValue;
            string review  = txtReview.Text;

            _Coffee coffee = new _Coffee(name, type, price, roast, country, image, review);
            ConnectionClass.AddCoffee(coffee);
            lblResult.Text = "Upload successfull!";
            ClearTextFields();
        }
        catch (Exception)
        {
            lblResult.Text = "Upload failed!";
        }
    }