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); }
public void EditProduct(int index, Product p) { Products.RemoveAt(index); Products.Insert(index, p); SerializeObject(ConfigurationManager.AppSettings["ProductFilePath"], this); }
public void AddProduct(Product p) { Products.Insert(0, p); SerializeObject(ConfigurationManager.AppSettings["ProductFilePath"], this); }
public static string GetTitleTag(Product p) { string titleText = string.Empty; try { String[] values = ConfigurationManager.AppSettings["LightboxTitleTag"].ToLower().Split(','); if (values.Length > 0) { bool title = false; foreach (string value in values) { switch (value) { case "title": title = true; break; case "shorttext": titleText += p.ShortText + ", "; break; case "longtext": titleText += p.LongText + ", "; break; case "stock": titleText += (p.Stock ? GetText("CommonStockYes") : GetText("CommonStockNo")) + ", "; break; case "price": titleText += GetText("CommonPrice") + p.Price + " " + GetText("CommonPriceSuffix") + ", "; break; case "size": { titleText += GetText("ProductDetailSize"); if (p.CategoryChild && !p.CategoryAdult) titleText += GetText("CommonCategoryChild"); if (p.CategoryAdult && !p.CategoryChild) titleText += GetText("CommonCategoryAdult"); if (p.CategoryChild && p.CategoryAdult) titleText += GetText("CommonCategoryChildAdult"); titleText += ", "; } break; case "fabric": titleText += p.Fabric + ", "; break; } } if(title) titleText = p.Title + " :: " + titleText; titleText = titleText.Substring(0, titleText.Length - 2); } } catch(Exception e) { WriteToLog("GetTitleTag method failed! LightBoxTitleTag setting: " + ConfigurationManager.AppSettings["LightboxTitleTag"] + ", Message: " + e.Message); } return titleText; }
protected void btnProductInputSave_Click(object sender, EventArgs e) { // Validate price input int price; if (!int.TryParse(txtProductInputPrice.Text, out price)) { lblProductInputResult.Text = Common.GetText("AdminProductInputErrorPrice"); lblProductInputResult.CssClass = "failure"; return; } Product p = new Product { Id = (litId.Text.Equals(string.Empty) ? Guid.NewGuid() : new Guid(litId.Text)), Title = txtProductInputTitle.Text, ShortText = txtProductInputShortText.Text, LongText = txtProductInputLongText.Text, Image = fuProductInputImage.FileName != string.Empty ? fuProductInputImage.FileName : litImage.Text, Price = txtProductInputPrice.Text, Stock = cbProductInputStock.Checked, Category = (txtProductInputCategory.Text != string.Empty && txtProductInputCategory.Text != Common.GetText("AdminProductInputCategoryExText")) ? txtProductInputCategory.Text : ddlProductInputCategory.SelectedValue, CategoryChild = cbProductInputCategoryChild.Checked, CategoryAdult = cbProductInputCategoryAdult.Checked, Fabric = (txtProductInputFabric.Text != string.Empty && txtProductInputFabric.Text != Common.GetText("AdminProductInputFabricExText")) ? txtProductInputFabric.Text : ddlProductInputFabric.SelectedValue }; // Save file to disk if (fuProductInputImage.HasFile) p.Image = SaveFile(); if (string.IsNullOrEmpty(p.Image)) p.Image = "noimage.jpg"; if(litEdit.Text.Equals(string.Empty)) pc.AddProduct(p); else pc.EditProduct(Int16.Parse(litEdit.Text), p); Application["ProductCatalog"] = pc; Session["productResult"] = Common.GetText("AdminProductInputAdded"); Response.Redirect("admin.aspx"); }