private void ValidateProductCatalog()
 {
     // Validate application object
     if (Application["ProductCatalog"] == null)
         Application["ProductCatalog"] = pc = ProductCatalog.DeserializeObject(ConfigurationManager.AppSettings["ProductFilePath"]);
     else
     {
         pc = (ProductCatalog) Application["ProductCatalog"];
         if(pc.Products == null || pc.Products.Count == 0)
             Application["ProductCatalog"] = pc = ProductCatalog.DeserializeObject(ConfigurationManager.AppSettings["ProductFilePath"]);
     }
 }
 public static void SerializeObject(string filename, ProductCatalog objectToSerialize)
 {
     using (Stream stream = File.Open(filename, FileMode.Create))
     {
         try
         {
             XmlSerializer bFormatter = new XmlSerializer(typeof(ProductCatalog));
             bFormatter.Serialize(stream, objectToSerialize);
         }
         catch (Exception e)
         {
             Common.WriteToLog("ProductCatalog could not be serialized! Message: " + e.Message);
         }
     }
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            ValidateProductCatalog();
            pc = (ProductCatalog)Application["ProductCatalog"];

            SetTextOnPage();

            string id = Request.QueryString["id"];

            foreach (Product item in pc.Products)
            {
                if (item.Id.ToString().Equals(id))
                {
                    p = item;
                    break;
                }
            }

            string imageUrl = ConfigurationManager.AppSettings["ImagePath"] + p.Image;
            imgPicture.ImageUrl = imageUrl;

            #region Lightbox functionality on/off
            if (bool.Parse(ConfigurationManager.AppSettings["Lightbox"]))
            {
                ancPicture.Attributes.Add("class", "lightview");
                ancPicture.HRef = imageUrl;
                ancPicture.Title = Common.GetTitleTag(p);
            }
            else
                ancPicture.Attributes.Add("onclick", "javascript:window.open('" + imageUrl + "')");
            #endregion

            lblTitle.Text = p.Title;
            lblLongText.Text = p.LongText;
            lblPrice.Text = Common.GetText("CommonPrice") + p.Price + " " + Common.GetText("CommonPriceSuffix");
            lblStock.Text = p.Stock ? Common.GetText("CommonStockYes") : Common.GetText("CommonStockNo");

            lblSize.Text = Common.GetText("ProductDetailSize");
            if (p.CategoryChild && !p.CategoryAdult)
                lblSize.Text += Common.GetText("CommonCategoryChild");
            if (p.CategoryAdult && !p.CategoryChild)
                lblSize.Text += Common.GetText("CommonCategoryAdult");
            if (p.CategoryChild && p.CategoryAdult)
                lblSize.Text += Common.GetText("CommonCategoryChildAdult");

            lblFabric.Text = Common.GetText("ProductDetailWash") + p.Fabric + ". " + Common.GetText("ProductDetailWash_" + p.Fabric);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            ValidateProductCatalog();
            pc = (ProductCatalog)Application["ProductCatalog"];

            SetTextOnPage();

            itemsToDisplay = new List<Product>();
            string category = Request.QueryString["category"];
            string size = Request.QueryString["size"];

            if (string.IsNullOrEmpty(category))
                itemsToDisplay = pc.Products;
            else
            {
                foreach (Product item in pc.Products)
                {
                    if (item.Category.Equals(category))
                    {
                        if (!string.IsNullOrEmpty(size))
                        {
                            if (size.Equals("child") && item.CategoryChild)
                                itemsToDisplay.Add(item);

                            if (size.Equals("adult") && item.CategoryAdult)
                                itemsToDisplay.Add(item);
                        }
                        else
                            itemsToDisplay.Add(item);
                    }
                }
            }

            lblNumberOfProducts.Text = Common.GetText("ProductListNumberOfProducts") + itemsToDisplay.Count;

            lvProducts.DataSource = itemsToDisplay;
            lvProducts.DataBind();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                ValidateProductCatalog();
                pc = (ProductCatalog) Application["ProductCatalog"];

                #region Set artist CSS
                HtmlLink cssControl = FindControl("css") as HtmlLink;
                cssControl.Href = ConfigurationManager.AppSettings["CssPath"] + ConfigurationManager.AppSettings["Artist"] + ".css";
                #endregion

                SetTextOnPage();

                #region Build tree node categories

                TreeNodeCollection tnc = new TreeNodeCollection();
                ArrayList addedCategories = new ArrayList();
                int counter = 0;
                foreach (Product item in pc.Products)
                {
                    TreeNode tn = new TreeNode();
                    tn.Text = item.Category;
                    tn.SelectAction = TreeNodeSelectAction.SelectExpand;
                    tn.Value = "ProductList.aspx?category=" + item.Category;

                    if (!addedCategories.Contains(item.Category))
                    {
                        addedCategories.Add(item.Category);

                        bool categoryChild = false;
                        bool categoryAdult = false;
                        foreach (Product subItem in pc.Products)
                        {
                            if (subItem.Category.Equals(item.Category))
                            {
                                if (subItem.CategoryChild)
                                    categoryChild = true;

                                if (subItem.CategoryAdult)
                                    categoryAdult = true;
                            }
                        }

                        tnc.Add(tn);

                        if (categoryChild)
                        {
                            TreeNode categoryChildNode = new TreeNode();
                            categoryChildNode.Text = Common.GetText("CommonCategoryChild");
                            categoryChildNode.Value = "ProductList.aspx?category=" + item.Category + "&size=child";

                            tnc[counter].ChildNodes.Add(categoryChildNode);
                        }

                        if (categoryAdult)
                        {
                            TreeNode categoryAdultNode = new TreeNode();
                            categoryAdultNode.Text = Common.GetText("CommonCategoryAdult");
                            categoryAdultNode.Value = "ProductList.aspx?category=" + item.Category + "&size=adult";

                            tnc[counter].ChildNodes.Add(categoryAdultNode);
                        }

                        counter++;
                    }
                }

                foreach (TreeNode node in tnc)
                {
                    tvProducts.Nodes.Add(node);
                }

                if (Session["treeState"] != null)
                    RestoreTreeState(tvProducts, (Dictionary<string, bool?>) Session["treeState"]);

                tvProducts.DataBind();

                #endregion
            }
        }
        private void ValidateApplicationObjects()
        {
            // Validate productCatalog application object
            if (Application["ProductCatalog"] == null)
                Application["ProductCatalog"] = pc = ProductCatalog.DeserializeObject(ConfigurationManager.AppSettings["ProductFilePath"]);
            else
            {
                pc = (ProductCatalog)Application["ProductCatalog"];
                if (pc.Products == null || pc.Products.Count == 0)
                    Application["ProductCatalog"] = pc = ProductCatalog.DeserializeObject(ConfigurationManager.AppSettings["ProductFilePath"]);
            }

            // Validate guestbook application object
            if (Application["GuestBook"] == null)
                Application["GuestBook"] = g = Library.Guestbook.DeserializeObject(ConfigurationManager.AppSettings["GuestbookFilePath"]);
            else
            {
                g = (Library.Guestbook)Application["GuestBook"];
                if (g.Guests == null || g.Guests.Count == 0)
                    Application["GuestBook"] = g = Library.Guestbook.DeserializeObject(ConfigurationManager.AppSettings["GuestbookFilePath"]);
            }
        }