protected void ButtonSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                //Obtain product code from query string
                string prodcd = Request.QueryString["prodcd"].ToString();

                //Create a product object
                Product prod = new Product();

                //Get existing product by its code
                prod.GetProductByCode(prodcd);

                //Update all fields
                prod.Modified = DateTime.Now;
                prod.IsActive = false;

                //Update the product
                if (prod.UpdateProduct())
                {
                    //ScriptManager.RegisterStartupScript(this, GetType(), "", "parent.location.reload(true);", true);
                    ScriptManager.RegisterStartupScript(this, GetType(), "", "window.top.window.$.fancybox.close();", true);
                }
                else
                {
                    LabelOutput.ForeColor = System.Drawing.Color.Red;
                    LabelOutput.Text = "Error: Deactivation Failed";
                }
            }
            catch (Exception ex)
            {
                LabelOutput.ForeColor = System.Drawing.Color.Red;
                LabelOutput.Text = "Error: " + ex.Message;
            }
        }
        protected void ButtonSubmit_Click(object sender, EventArgs e)
        {
            if (FileUpload1.HasFile)
            {
                try
                {
                    //Get the file extension
                    FileInfo finfo = new FileInfo(FileUpload1.FileName);
                    string fileExtension = finfo.Extension.ToLower();

                    //Save file to server
                    FileUpload1.SaveAs(Server.MapPath("~/Images/Product_Images/") +
                         LabelProductCode.Text + fileExtension);
                }
                catch (Exception ex)
                {
                    LabelOutput.Text = "ERROR: " + ex.Message.ToString();
                    return;
                }
            }

            try
            {
                //Create a product object
                Product prod = new Product();

                //Get existing product by its code
                prod.GetProductByCode(LabelProductCode.Text);

                //Update all fields
                prod.Name = TextBoxName.Text;
                prod.Brand = TextBoxBrand.Text;
                prod.Description = TextBoxDescription.Text;
                prod.CategoryID = Convert.ToInt32(DropDownListCategory.SelectedValue);
                prod.Msrp = Convert.ToDouble(TextBoxMSRP.Text);
                prod.IsFreeShipping = CheckBoxFreeShipping.Checked;
                prod.IsTaxFree = CheckBoxTaxFree.Checked;
                prod.QuantityInStock = Convert.ToInt32(TextBoxQtyInStock.Text);
                prod.IsQuantityUnlimited = CheckBoxQtyUnlimited.Checked;
                prod.Modified = DateTime.Now;

                //Update the product
                if (prod.UpdateProduct())
                {
                    ScriptManager.RegisterStartupScript(this, GetType(), "", "window.top.window.$.fancybox.close();", true);
                    //Response.Redirect("~/Admin/Products.aspx");
                }
                else
                {
                    LabelOutput.ForeColor = System.Drawing.Color.Red;
                    LabelOutput.Text = "Error: Update Failed";
                }
            }
            catch (Exception ex)
            {
                LabelOutput.ForeColor = System.Drawing.Color.Red;
                LabelOutput.Text = "Error: " + ex.Message;
            }
        }
Example #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            prodcd = Request.QueryString["prodcd"].ToString();
            var prod = new Product();
            prod.GetProductByCode(prodcd);
            title.Text = prod.Name.ToString();
            productCode.Text = prod.ProductCode.ToString();
            brand.Text = prod.Brand.ToString();

            //Get configurations
            Configuration config = new Configuration();
            config.GetConfigurationByCode("xCurrencyCode");

            price.Text = "$" + prod.Msrp.ToString() + " " + config.Value;

            LabelDescription.Text = prod.Description.ToString();

            //If the unlimited quantity flag is set...
            if (Convert.ToBoolean(prod.IsQuantityUnlimited) == true)
            {
                quantity.Text = "Quantity Remaining: Unlimited";
            }
            else
            {
                quantity.Text = "Quantity Remaining: " + prod.QuantityInStock.ToString();
            }

            //Attempt to display image (if it is found)
            try
            {
                itemPic.ImageUrl = "~/Images/Product_Images/" + prodcd + ".jpg";
            }
            catch (Exception)
            {
                itemPic.ImageUrl = "";
            }

            //Fill gridview with available delivery types
            ProductDeliveryType pdt = new ProductDeliveryType();
            List<ProductDeliveryType> pdtypes = pdt.GetAllProductDeliveryTypesByProdCode(prodcd);

            List<DeliveryType> deliveryTypes = new List<DeliveryType>();
            foreach (ProductDeliveryType prodDelType in pdtypes)
            {
                DeliveryType dt = new DeliveryType();
                dt.GetDeliveryTypeByID(prodDelType.DeliveryTypeID);
                deliveryTypes.Add(dt);
            }

            GridViewDeliveryTypes.DataSource = deliveryTypes;
            GridViewDeliveryTypes.DataBind();

            //Don't show "Delivery Types" title if there are no delivery types listed
            if (deliveryTypes.Count == 0)
            {
                LabelDeliveryTypesTitle.Visible = false;
            }
        }
Example #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Session["cartList"] != null)
                {
                    foreach (var i in (List<Tuple<string, int>>)(Session["cartList"]))
                    {
                        bool exists = false;

                        foreach (var x in prods)
                        {
                            if (i.Item1 == x.Prodcd)
                            {
                                exists = true;
                                x.Qty++;
                                x.Total = x.Qty * x.Price;
                                break;
                            }
                        }
                        if (!exists)
                        {
                            var prod = new Product();
                            var cartItem = new CartItem();
                            prod.GetProductByCode(i.Item1);
                            cartItem.Prodcd = i.Item1;
                            cartItem.Name = prod.Name.ToString();
                            cartItem.Img = "~/Images/Product_Images/" + i.Item1 + ".jpg";
                            cartItem.Qty = i.Item2;
                            cartItem.Price = cartItem.Total = prod.Msrp;
                            prods.Add(cartItem);
                        }
                    }
                    DataListCartItems.DataSource = prods;
                    DataListCartItems.DataBind();
                }
            }
            //another test
        }
Example #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["AdministratorID"] == null)
                Response.Redirect("~/Admin/Login.aspx");
            else
            {
                if (!Page.IsPostBack)
                {
                    //Populate the featured product dropdowns
                    Product prod = new Product();
                    List<Product> products = prod.GetAllProducts(true);
                    DropDownListFeaturedProduct1.DataSource = products;
                    DropDownListFeaturedProduct1.DataTextField = "ProductCode";
                    DropDownListFeaturedProduct1.DataValueField = "ProductCode";
                    DropDownListFeaturedProduct1.DataBind();
                    Configuration config1 = new Configuration();
                    config1.GetConfigurationByCode("xFeaturedProduct1");
                    DropDownListFeaturedProduct1.SelectedValue = config1.Value.ToString();

                    DropDownListFeaturedProduct2.DataSource = products;
                    DropDownListFeaturedProduct2.DataTextField = "ProductCode";
                    DropDownListFeaturedProduct2.DataValueField = "ProductCode";
                    DropDownListFeaturedProduct2.DataBind();
                    Configuration config2 = new Configuration();
                    config2.GetConfigurationByCode("xFeaturedProduct2");
                    DropDownListFeaturedProduct2.SelectedValue = config2.Value.ToString();

                    DropDownListFeaturedProduct3.DataSource = products;
                    DropDownListFeaturedProduct3.DataTextField = "ProductCode";
                    DropDownListFeaturedProduct3.DataValueField = "ProductCode";
                    DropDownListFeaturedProduct3.DataBind();
                    Configuration config3 = new Configuration();
                    config3.GetConfigurationByCode("xFeaturedProduct3");
                    DropDownListFeaturedProduct3.SelectedValue = config3.Value.ToString();

                    DropDownListFeaturedProduct4.DataSource = products;
                    DropDownListFeaturedProduct4.DataTextField = "ProductCode";
                    DropDownListFeaturedProduct4.DataValueField = "ProductCode";
                    DropDownListFeaturedProduct4.DataBind();
                    Configuration config4 = new Configuration();
                    config4.GetConfigurationByCode("xFeaturedProduct4");
                    DropDownListFeaturedProduct4.SelectedValue = config4.Value.ToString();
                }
            }
        }
Example #6
0
 protected void UpdatePanel1_Load(object sender, EventArgs e)
 {
     //Populate products grid
     Product product = new Product();
     DataTable dataTable = product.ToDataTable(product.GetAllProducts(false));
     GridViewProducts.DataSource = dataTable;
     GridViewProducts.DataBind();
 }
Example #7
0
        protected void ButtonGoToPayInfo_Click(object sender, EventArgs e)
        {
            //Get a reference to the original datasource for the datalist (doesn't take into account DeliveryType changes)
            DataTable dt = new DataTable();
            dt.Columns.Add("Prodcd");
            dt.Columns.Add("Name");
            dt.Columns.Add("Msrp", System.Type.GetType("System.Double"));
            dt.Columns.Add("Quantity");
            dt.Columns.Add("DeliveryTypeID");
            dt.Columns.Add("DeliveryTypeName");
            dt.Columns.Add("DeliveryCost", System.Type.GetType("System.Double"));
            dt.Columns.Add("Taxes", System.Type.GetType("System.Double"));
            dt.Columns.Add("Total", System.Type.GetType("System.Double"));
            dt.Columns.Add("FirstName");
            dt.Columns.Add("LastName");
            dt.Columns.Add("Address1");
            dt.Columns.Add("Address2");
            dt.Columns.Add("City");
            dt.Columns.Add("Country");
            dt.Columns.Add("StateProvinceID");
            dt.Columns.Add("StateProvinceName");
            dt.Columns.Add("ZipPostalCode");
            dt.Columns.Add("Email");

            //For each data list item...
            for (int i = 0; i < DataListCheckout.Items.Count; i++)
            {
                //Get reference to this data list item
                DataListItem item = DataListCheckout.Items[i];
                if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
                {
                    //Get reference to original datarow for this datalist item
                    DataRow dr = dt.NewRow();

                    //Get reference to the product for this datalist item
                    Product prod = new Product();
                    prod.GetProductByCode(DataListCheckout.DataKeys[i].ToString());

                    dr["Prodcd"] = prod.ProductCode;
                    dr["Name"] = prod.Name;
                    dr["Msrp"] = prod.Msrp;
                    dr["Quantity"] = ((Label)(item.FindControl("LabelQuantity"))).Text;
                    dr["DeliveryTypeID"] = ((DropDownList)(item.FindControl("DropDownListDeliveryType"))).SelectedValue;

                    //Get the delivery type name and cost
                    DeliveryType dtype = new DeliveryType();
                    dtype.GetDeliveryTypeByID(Convert.ToInt32(dr["DeliveryTypeID"]));
                    dr["DeliveryTypeName"] = dtype.Name;
                    dr["DeliveryCost"] = dtype.Cost;

                    if (((CheckBox)item.FindControl("CheckBoxUseUserAddress")).Checked == true) //use account delivery info
                    {
                        //Get the current user
                        User user = new User();
                        user.GetUserByID(Convert.ToInt32(Session["UserID"]));
                        dr["FirstName"] = user.FirstName;
                        dr["LastName"] = user.LastName;
                        dr["Address1"] = user.Address1;
                        dr["Address2"] = user.Address2;
                        dr["City"] = user.City;
                        dr["StateProvinceID"] = user.StateProvinceID;
                        //dr["Country"] = user.  MUST DEAL WITH COUNTRY LATER
                        dr["ZipPostalCode"] = user.ZipCodePostal;
                        dr["Email"] = user.Email;
                    }
                    else //use customized delivery info
                    {
                        dr["FirstName"] = ((TextBox)(item.FindControl("txtFName"))).Text;
                        dr["LastName"] = ((TextBox)(item.FindControl("txtLName"))).Text;
                        dr["Address1"] = ((TextBox)(item.FindControl("txtAddress"))).Text;
                        dr["Address2"] = ((TextBox)(item.FindControl("txtAddress2"))).Text;
                        dr["City"] = ((TextBox)(item.FindControl("txtCity"))).Text;
                        //dr["Country"] = ((DropDownList)(item.FindControl("dropCountry"))).SelectedValue; MUST DEAL WITH COUNTRY LATER
                        dr["StateProvinceID"] = ((DropDownList)(item.FindControl("dropStateProv"))).SelectedValue;
                        dr["ZipPostalCode"] = ((TextBox)(item.FindControl("txtZipPostal"))).Text;
                        dr["Email"] = ((TextBox)(item.FindControl("txtEmail"))).Text;
                    }

                    //Get the state/province name and tax cost
                    StateProvince sp = new StateProvince();
                    sp.GetStateProvinceByID(Convert.ToInt32(dr["StateProvinceID"]));
                    dr["StateProvinceName"] = sp.Name;
                    dr["Taxes"] = sp.TaxRatePercentage / 100 * Convert.ToDouble(dr["Msrp"]);

                    //Calculate the total cost
                    dr["Total"] = Convert.ToDouble(dr["Msrp"]) + Convert.ToDouble(dr["DeliveryCost"]) + Convert.ToDouble(dr["Taxes"]);

                    //Add row to datatable
                    dt.Rows.Add(dr);
                }
            }

            //Add checkout list to session
            Session.Add("CheckoutDataTable",dt);

            //Go to next page
            Response.Redirect("~/PaymentInfo.aspx");
        }
Example #8
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //Check if logged in
            if (Session["UserID"] == null)
            {
                //Set a session variable to indicate return to checkout after login
                Session.Add("ReturnToCheckout", true);
                Response.Redirect("~/Login.aspx");
            }

            if (!IsPostBack)
            {
                List<Tuple<string, int>> list = new List<Tuple<string, int>>();
                if (Session["cartList"] != null)
                {
                    list = (List<Tuple<string, int>>)(Session["cartList"]);
                }
                else
                {
                    Response.Redirect("~/Index.aspx");
                }

                //Datatable that will be bound to the checkout datalist
                DataTable dt = new DataTable();
                dt.Columns.Add("Prodcd");
                dt.Columns.Add("Quantity");
                dt.Columns.Add("Name");
                dt.Columns.Add("Msrp");

                foreach (Tuple<string, int> item in list)
                {
                    DataRow dr = dt.NewRow();
                    dr["Prodcd"] = item.Item1;
                    dr["Quantity"] = item.Item2;

                    //Get product info
                    Product prod = new Product();
                    prod.GetProductByCode(item.Item1);
                    dr["Name"] = prod.Name.ToString();
                    dr["Msrp"] = prod.Msrp;

                    //Add checkout item to datasource list
                    dt.Rows.Add(dr);
                }

                //Bind to the datalist
                DataListCheckout.DataSource = dt;
                DataListCheckout.DataBind();
            }
        }
        private void reloadGridView()
        {
            if (DropDownListDBTables.SelectedValue == "Administrators")
            {
                //Get all objects
                Administrator obj = new Administrator();
                List<Administrator> list = obj.GetAllAdministrators(false);

                //Fill a rendered object list
                List<RenderAdministrator> renderedList = new List<RenderAdministrator>();
                foreach (Administrator x in list)
                {
                    renderedList.Add(new RenderAdministrator(x));
                }

                GridViewDBTable.DataSource = renderedList;
            }
            else if (DropDownListDBTables.SelectedValue == "Audits")
            {
                //Get all objects
                Audit obj = new Audit();
                List<Audit> list = obj.GetAllAudits();

                //Fill a rendered object list
                List<RenderAudit> renderedList = new List<RenderAudit>();
                foreach (Audit x in list)
                {
                    renderedList.Add(new RenderAudit(x));
                }

                GridViewDBTable.DataSource = renderedList;
            }
            else if (DropDownListDBTables.SelectedValue == "AuditTypes")
            {
                //Get all objects
                AuditType obj = new AuditType();
                List<AuditType> list = obj.GetAllAuditTypes();

                //Fill a rendered object list
                List<RenderAuditType> renderedList = new List<RenderAuditType>();
                foreach (AuditType x in list)
                {
                    renderedList.Add(new RenderAuditType(x));
                }

                GridViewDBTable.DataSource = renderedList;
            }
            if (DropDownListDBTables.SelectedValue == "Categories")
            {
                //Get all objects
                Category obj = new Category();
                List<Category> list = obj.GetAllCategories(false);

                //Fill a rendered object list
                List<RenderCategory> renderedList = new List<RenderCategory>();
                foreach (Category x in list)
                {
                    renderedList.Add(new RenderCategory(x));
                }

                GridViewDBTable.DataSource = renderedList;
            }
            else if (DropDownListDBTables.SelectedValue == "Configurations")
            {
                //Get all objects
                Configuration obj = new Configuration();
                List<Configuration> list = obj.GetAllConfigurations();

                //Fill a rendered object list
                List<RenderConfiguration> renderedList = new List<RenderConfiguration>();
                foreach (Configuration x in list)
                {
                    renderedList.Add(new RenderConfiguration(x));
                }

                GridViewDBTable.DataSource = renderedList;
            }
            else if (DropDownListDBTables.SelectedValue == "DeliveryType")
            {
                //Get all objects
                DeliveryType obj = new DeliveryType();
                List<DeliveryType> list = obj.GetAllDeliveryTypes();

                //Fill a rendered object list
                List<RenderDeliveryType> renderedList = new List<RenderDeliveryType>();
                foreach (DeliveryType x in list)
                {
                    renderedList.Add(new RenderDeliveryType(x));
                }

                GridViewDBTable.DataSource = renderedList;
            }
            else if (DropDownListDBTables.SelectedValue == "LangLabels")
            {
                //Get all objects
                LangLabel obj = new LangLabel();
                List<LangLabel> list = obj.GetAllLangLabels();

                //Fill a rendered object list
                List<RenderLangLabel> renderedList = new List<RenderLangLabel>();
                foreach (LangLabel x in list)
                {
                    renderedList.Add(new RenderLangLabel(x));
                }

                GridViewDBTable.DataSource = renderedList;
            }
            else if (DropDownListDBTables.SelectedValue == "OrderItems")
            {
                //Get all objects
                OrderItem obj = new OrderItem();
                List<OrderItem> list = obj.GetAllOrderItems();

                //Fill a rendered object list
                List<RenderOrderItem> renderedList = new List<RenderOrderItem>();
                foreach (OrderItem x in list)
                {
                    renderedList.Add(new RenderOrderItem(x));
                }

                GridViewDBTable.DataSource = renderedList;
            }
            else if (DropDownListDBTables.SelectedValue == "Orders")
            {
                //Get all objects
                Order obj = new Order();
                List<Order> list = obj.GetAllOrders();

                //Fill a rendered object list
                List<RenderOrder> renderedList = new List<RenderOrder>();
                foreach (Order x in list)
                {
                    renderedList.Add(new RenderOrder(x));
                }

                GridViewDBTable.DataSource = renderedList;
            }
            else if (DropDownListDBTables.SelectedValue == "ProductDeliveryTypes")
            {
                //Get all objects
                ProductDeliveryType obj = new ProductDeliveryType();
                List<ProductDeliveryType> list = obj.GetAllProductDeliveryTypes();

                //Fill a rendered object list
                List<RenderProductDeliveryType> renderedList = new List<RenderProductDeliveryType>();
                foreach (ProductDeliveryType x in list)
                {
                    renderedList.Add(new RenderProductDeliveryType(x));
                }

                GridViewDBTable.DataSource = renderedList;
            }
            else if (DropDownListDBTables.SelectedValue == "Products")
            {
                //Get all objects
                Product obj = new Product();
                List<Product> list = obj.GetAllProducts(false);

                //Fill a rendered object list
                List<RenderProduct> renderedList = new List<RenderProduct>();
                foreach(Product x in list)
                {
                    renderedList.Add(new RenderProduct(x));
                }

                GridViewDBTable.DataSource = renderedList;
            }
            else if (DropDownListDBTables.SelectedValue == "StatesProvinces")
            {
                //Get all objects
                StateProvince obj = new StateProvince();
                List<StateProvince> list = obj.GetAllStatesProvinces();

                //Fill a rendered object list
                List<RenderStateProvince> renderedList = new List<RenderStateProvince>();
                foreach (StateProvince x in list)
                {
                    renderedList.Add(new RenderStateProvince(x));
                }

                GridViewDBTable.DataSource = renderedList;
            }
            else if (DropDownListDBTables.SelectedValue == "Users")
            {
                //Get all objects
                User obj = new User();
                List<User> list = obj.GetAllUsers();

                //Fill a rendered object list
                List<RenderUser> renderedList = new List<RenderUser>();
                foreach (User x in list)
                {
                    renderedList.Add(new RenderUser(x));
                }

                GridViewDBTable.DataSource = renderedList;
            }

            //Databind the new datasource obtained above
            GridViewDBTable.DataBind();
        }
Example #10
0
        private void categoryChanged()
        {
            //Get the selected category object
            Category cat = new Category();
            cat.GetCategoryByID(Convert.ToInt32(TreeViewLeftNav.SelectedValue));

            //Set the title for content section
            subcategoryTitle.InnerText = cat.Name.ToString();

            //Get all products for this category
            Product prod = new Product();
            List<Product> prods = prod.GetAllProductsByCategoryID(Convert.ToInt32(TreeViewLeftNav.SelectedValue),true);

            DataListProducts.DataSource = prods;
            DataListProducts.DataBind();
        }
Example #11
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //Load the slider images and details
            Configuration config = new Configuration();
            Product prod = new Product();

            //Slide 1
            config.GetConfigurationByCode("xFeaturedProduct1");
            prod.GetProductByCode(config.Value.ToString());

            //Attempt to display image (if it is found)
            try
            {
                ImageFeatured1.Src = "~/Images/Product_Images/" + prod.ProductCode + ".jpg";
            }
            catch (Exception)
            {
                ImageFeatured1.Src = "";
            }

            LabelFeaturedBrand1.Text = prod.Brand.ToString();
            LabelFeaturedName1.Text = prod.Name.ToString();
            LabelFeaturedPrice1.Text = "Only $" + prod.Msrp.ToString();
            LinkButtonFeatured1.PostBackUrl = "~/ProductInfo.aspx?prodcd=" + prod.ProductCode.ToString();

            //Slide 2
            config.GetConfigurationByCode("xFeaturedProduct2");
            prod.GetProductByCode(config.Value.ToString());

            //Attempt to display image (if it is found)
            try
            {
                ImageFeatured2.Src = "~/Images/Product_Images/" + prod.ProductCode + ".jpg";
            }
            catch (Exception)
            {
                ImageFeatured2.Src = "";
            }

            LabelFeaturedBrand2.Text = prod.Brand.ToString();
            LabelFeaturedName2.Text = prod.Name.ToString();
            LabelFeaturedPrice2.Text = "Only $" + prod.Msrp.ToString();

            //Slide 3
            config.GetConfigurationByCode("xFeaturedProduct3");
            prod.GetProductByCode(config.Value.ToString());

            //Attempt to display image (if it is found)
            try
            {
                ImageFeatured3.Src = "~/Images/Product_Images/" + prod.ProductCode + ".jpg";
            }
            catch (Exception)
            {
                ImageFeatured3.Src = "";
            }

            LabelFeaturedBrand3.Text = prod.Brand.ToString();
            LabelFeaturedName3.Text = prod.Name.ToString();
            LabelFeaturedPrice3.Text = "Only $" + prod.Msrp.ToString();

            //Slide 4
            config.GetConfigurationByCode("xFeaturedProduct4");
            prod.GetProductByCode(config.Value.ToString());

            //Attempt to display image (if it is found)
            try
            {
                ImageFeatured4.Src = "~/Images/Product_Images/" + prod.ProductCode + ".jpg";
            }
            catch (Exception)
            {
                ImageFeatured4.Src = "";
            }

            LabelFeaturedBrand4.Text = prod.Brand.ToString();
            LabelFeaturedName4.Text = prod.Name.ToString();
            LabelFeaturedPrice4.Text = "Only $" + prod.Msrp.ToString();

            //Load the data list (THIS IS A TEMPORARY WAY...CHOOSES FIRST 6 PRODUCTS)
            List<Product> allProducts = new List<Product>();
            allProducts = prod.GetAllProducts(true);
            List<Product> frontpageProducts = new List<Product>();
            for (int i = 0; i < 6; i++)
            {
                frontpageProducts.Add(allProducts[i]);
            }
            DataListProducts.DataSource = frontpageProducts;
            DataListProducts.DataBind();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //Obtain product code from query string
                string prodcd = Request.QueryString["prodcd"].ToString();

                //Get product by its code
                Product prod = new Product();
                prod.GetProductByCode(prodcd);

                //Populate categories dropdown list
                Category cat = new Category();
                List<Category> categories = cat.GetAllCategories(true);
                DropDownListCategory.DataSource = categories;
                DropDownListCategory.DataTextField = "Name";
                DropDownListCategory.DataValueField = "CategoryID";
                DropDownListCategory.DataBind();

                //Put product details into fields
                LabelProductCode.Text = Request.QueryString["prodcd"].ToString();
                TextBoxName.Text = prod.Name.ToString();
                TextBoxBrand.Text = prod.Brand.ToString();
                TextBoxDescription.Text = prod.Description.ToString();
                DropDownListCategory.SelectedValue = prod.CategoryID.ToString();
                TextBoxMSRP.Text = prod.Msrp.ToString();
                CheckBoxFreeShipping.Checked = Convert.ToBoolean(prod.IsFreeShipping);
                CheckBoxTaxFree.Checked = Convert.ToBoolean(prod.IsTaxFree);
                TextBoxQtyInStock.Text = prod.QuantityInStock.ToString();
                CheckBoxQtyUnlimited.Checked = Convert.ToBoolean(prod.IsQuantityUnlimited);
                LabelCreated.Text = Convert.ToDateTime(prod.Created).ToShortDateString();
                if (Convert.ToDateTime(prod.Modified) > DateTime.MinValue)
                {
                    LabelModified.Text = Convert.ToDateTime(prod.Modified).ToShortDateString();
                }
                else
                {
                    LabelModified.Text = "N/A";
                }

                //Attempt to display image (if it is found)
                try
                {
                    Image1.ImageUrl = "~/Images/Product_Images/" + LabelProductCode.Text + ".jpg";
                }
                catch (Exception)
                {
                    Image1.ImageUrl = "";
                }
            }
        }
Example #13
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //Check if logged in
            if (Session["UserID"] == null)
            {
                //Set a session variable to indicate return to checkout after login
                Session.Add("ReturnToCheckout", true);
                Response.Redirect("~/Login.aspx");
            }

            if (!IsPostBack)
            {
                List<Tuple<string, int>> list = new List<Tuple<string, int>>();
                if (Session["cartList"] != null)
                {
                    list = (List<Tuple<string, int>>)(Session["cartList"]);
                }
                else
                {
                    Response.Redirect("~/Index.aspx");
                }

                //Collection that will be bound to the checkout datalist
                List<CheckoutItem> coItems = new List<CheckoutItem>();

                foreach (Tuple<string, int> item in list)
                {
                    CheckoutItem coItem = new CheckoutItem();
                    coItem.Prodcd = item.Item1;
                    coItem.Quantity = item.Item2;

                    //Get product info
                    Product prod = new Product();
                    prod.GetProductByCode(item.Item1);
                    coItem.Name = prod.Name.ToString();
                    coItem.Msrp = prod.Msrp;

                    //Get all product delivery types
                    ProductDeliveryType pdt = new ProductDeliveryType();
                    List<ProductDeliveryType> pdtypes = pdt.GetAllProductDeliveryTypesByProdCode(prod.ProductCode.ToString());
                    foreach(ProductDeliveryType pdtype in pdtypes)
                    {
                        DeliveryType dt = new DeliveryType();
                        dt.GetDeliveryTypeByID(pdtype.DeliveryTypeID);
                        coItem.DeliveryTypes.Add(dt);
                    }

                    //Add checkout item to datasource list
                    coItems.Add(coItem);
                }

                //Bind to the datalist
                DataListCheckout.DataSource = coItems;
                DataListCheckout.DataBind();
            }
        }