public int AddOption(int ChoiceId, string Option) { Choices.ItemChoicesOptionsDataTable opts = GetOptions("'" + StringUtils.SQLEncode(Option) + "'"); if (opts.Count > 0) { return(opts[0].OptionId); } ChoicesTableAdapters.ItemChoicesOptionsTableAdapter options = new ChoicesTableAdapters.ItemChoicesOptionsTableAdapter(); int?OptionId = 0; options.AddOption(Option, ChoiceId, ref OptionId); return(OptionId.Value); }
public void ItemOptions(int ItemId, HttpRequest req) { Choices.ItemChoicesOptionsDataTable options = GetOptions(); ItemsMgr iMgr = new ItemsMgr(); DataRow item = iMgr.GetItem(ItemId); string folder = Path.Combine(WebContext.Server.MapPath(WebContext.Root + "/" + lw.CTE.Folders.ProductsImages), item["UniqueName"].ToString()); folder = Path.Combine(folder, "Choices"); if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } Config cfg = new Config(); Dimension ThumbSize = new Dimension(cfg.GetKey(Settings.ProductImage_ThumbSize)); Dimension MediumSize = new Dimension(cfg.GetKey(Settings.ProductImage_MediumSize)); Dimension LargeSize = new Dimension(cfg.GetKey(Settings.ProductImage_LargeSize)); foreach (DataRow option in options.Rows) { if (!String.IsNullOrWhiteSpace(req.Form[string.Format("o_{0}", option["OptionId"])])) { string sql = string.Format(@" if not exists (select * from ItemOptions where OptionId={1} and ItemId={0}) Insert into ItemOptions (ItemId, OptionId, DisplayOnSite, Picture, SKU) values ({0}, {1}, {2}, '', '{3}') else update ItemOptions set SKU='{3}',DisplayOnSite={2} where ItemId={0} and OptionId={1};select * from ItemOptions where ItemId={0} and OptionId={1}; ;", ItemId, option["OptionId"], !String.IsNullOrWhiteSpace(req[string.Format("display_o_{0}", option["OptionId"])])? 1: 0, StringUtils.SQLEncode(req[string.Format("sku_o_{0}", option["OptionId"])])); DataRow optionRow = DBUtils.GetDataSet(sql, cte.lib).Tables[0].Rows[0]; bool deleteOldPicture = !String.IsNullOrWhiteSpace(req[string.Format("delete_o_{0}", option["OptionId"])]); string picture = optionRow["Picture"].ToString(); HttpPostedFile pictureFile = req.Files[string.Format("picture_o_{0}", option["OptionId"])]; if (deleteOldPicture || pictureFile.ContentLength > 0) { string temp = Path.Combine(folder, picture).ToLower(); if (File.Exists(temp)) { File.Delete(temp); } temp = temp.Replace(".jpg", "_m.jpg"); if (File.Exists(temp)) { File.Delete(temp); } temp = temp.Replace("_m.jpg", "_s.jpg"); if (File.Exists(temp)) { File.Delete(temp); } } if (pictureFile.ContentLength > 0) { picture = StringUtils.ToURL(option["value"].ToString() + "_" + (new Random().Next(9999999)).ToString()) + ".Jpg"; deleteOldPicture = false; string temp = Path.Combine(folder, picture).ToLower(); pictureFile.SaveAs(temp); string large = temp; temp = temp.Replace(".jpg", "_m.jpg"); if (MediumSize.Valid) { lw.GraphicUtils.ImageUtils.Resize(large, temp, MediumSize.IntWidth, MediumSize.IntHeight); } else { File.Copy(large, temp, true); } temp = temp.Replace("_m.jpg", "_s.jpg"); if (ThumbSize.Valid) { lw.GraphicUtils.ImageUtils.CreateThumb(large, temp, ThumbSize.IntWidth, ThumbSize.IntHeight, true); } else { File.Copy(large, temp, true); } if (LargeSize.Valid) { lw.GraphicUtils.ImageUtils.Resize(large, large, LargeSize.IntWidth, LargeSize.IntHeight); } sql = string.Format("Update ItemOptions set Picture = '{2}' where ItemId={0} and OptionId={1}", ItemId, option["OptionId"], StringUtils.SQLEncode(picture)); DBUtils.ExecuteQuery(sql, cte.lib); } if (deleteOldPicture) { sql = string.Format("Update ItemOptions set Picture = '' where ItemId={0} and OptionId={1}", ItemId, option["OptionId"]); DBUtils.ExecuteQuery(sql, cte.lib); } } } CreateInvntoryRecords(ItemId); }