Ejemplo n.º 1
0
        //retrieved product information to be displayed on the product page
        public List <PRODUTCT_DATA> retrieve_product(string search, string userid)
        {
            List <PRODUTCT_DATA> product_list = new List <PRODUTCT_DATA>();

            Database_Connection con = new Database_Connection();

            string query = "SELECT * FROM DBO.PRODUCT_DISPLAY_INFO"; //he base query

            //checking if the user is search for anything
            if (search != "")
            {
                query += " WHERE PROUCT_NAME LIKE '%" + search + "%'";
            }

            SqlDataReader reader;

            //checking if the user has a user id
            if (userid == "")
            {
                reader = con.ExecuteQueries(query);
            }
            else
            {
                reader = con.ExecuteQueries(query, userid);
            }

            //reading data that has been returned from the executed process
            while (reader.Read())
            {
                //storing the data that has been received into an model
                PRODUTCT_DATA temp = new PRODUTCT_DATA
                                     (
                    reader[2].ToString(), decimal.Parse(reader[5].ToString()),
                    reader[4].ToString(), reader[6].ToString(),
                    reader[0].ToString(),
                    int.Parse(reader[7].ToString())
                    , 0,
                    reader[3].ToString()
                                     );

                //adding each row of data that has been read to data model list
                product_list.Add(temp);
            }

            con.closeSqlData();   //closing sql data stream

            return(product_list); //returning the data model list of data
        }
        public System.Web.UI.HtmlControls.HtmlGenericControl generate_product(PRODUTCT_DATA data)
        {
            Process_Executor exec = new Process_Executor();
            List <System.Web.UI.HtmlControls.HtmlGenericControl> all_prod_display = new List <System.Web.UI.HtmlControls.HtmlGenericControl>();


            System.Web.UI.HtmlControls.HtmlGenericControl newdiv = new System.Web.UI.HtmlControls.HtmlGenericControl("DIV");
            newdiv.Attributes.Add("Style", "border:1px; border-color:blue; padding-bottom:2%");
            newdiv.Attributes.Add("class", "col-md-4");
            newdiv.ID = "cart_info_" + data.get_id();


            string prod_image  = "<img style='width:60%; height:200px;' src='" + data.get_product_image() + "'/>";
            string price       = "<p>" + "Unit Cost: " + data.get_unit_price_display() + "</p>";
            string prod_name   = "<p> Item Name: " + data.get_prod_name() + "<p>";
            string description = "<p> Item Description: " + data.get_description() + "</p>";
            string quantity    = "<p style = 'flex:1'> Amount Available: </p>";

            //creating the section that holds the amount of available quantity is there per product
            System.Web.UI.HtmlControls.HtmlGenericControl avail_amt_host = new System.Web.UI.HtmlControls.HtmlGenericControl("DIV");
            avail_amt_host.ID = "amt_avail" + data.get_id();
            avail_amt_host.Attributes.Add("runat", "server");
            avail_amt_host.InnerHtml = (data.get_available_amt() - 1).ToString();

            //configuring the add to cart button
            add_to_cart.Text     = "ADD TO CART >>";
            add_to_cart.CssClass = "btn btn-default";
            add_to_cart.ID       = "cart_" + data.get_id();


            newdiv.InnerHtml = prod_image + prod_name + price + description;


            System.Web.UI.HtmlControls.HtmlGenericControl quan_host = new System.Web.UI.HtmlControls.HtmlGenericControl("DIV");

            System.Web.UI.HtmlControls.HtmlGenericControl avail_host = new System.Web.UI.HtmlControls.HtmlGenericControl("DIV");
            avail_host.Attributes.Add("Style", "display:flex; width:50%");

            avail_host.InnerHtml = quantity;

            quan_host.Attributes.Add("Style", "display:flex; width:50%");
            TextBox quan = new TextBox();     //text box that will display the amount of quantity that is being selected

            //button that will lessen the quantity of the product customer would like to order
            lessen_quantity.Text     = "-";
            lessen_quantity.CssClass = "btn btn-default";
            lessen_quantity.Attributes.Add("Style", "flex:0.2");
            lessen_quantity.ID = "lessen_" + data.get_id();


            //button that will increase the quantity of the product customer would like to order
            add_quantity.Text     = "+";
            add_quantity.CssClass = "btn btn-default";
            add_quantity.Attributes.Add("Style", "flex:0.2");
            add_quantity.ID = "add_" + data.get_id();

            //box that handles the displaying of the quantity
            quan.Attributes.Add("Style", "width:20%; flex:1");
            quan.ReadOnly = true;
            quan.Text     = "1";
            quan.ID       = "box" + data.get_id();

            quan_host.Controls.Add(lessen_quantity);
            quan_host.Controls.Add(quan);
            quan_host.Controls.Add(add_quantity);

            avail_host.Controls.Add(avail_amt_host);
            newdiv.Controls.Add(avail_host);
            newdiv.Controls.Add(quan_host);
            newdiv.Controls.Add(add_to_cart);

            return(newdiv);
        }