protected void checkmarkButton_Click(object sender, ImageClickEventArgs e) { myBoard = board_item.productToBoardConversion(p); myBoard.Board_Name = boardName; if (myDB.insertBoardDoc(usersBoardColl, myBoard)) { displayLbl.Text = "Item added successfully."; } else { displayLbl.Text = "Item already exists in current board."; } i++; if (i > queryItems.Count()) { imagePnl.Visible = false; errorPnl.Visible = true; } else { p = queryItems[i]; setImage(p); Session["p"] = p; Session["i"] = i; } }
public bool AddimgProd(product_image imp) { LQDataContext ctxs = new LQDataContext(); ctxs.product_images.InsertOnSubmit(imp); ctxs.SubmitChanges(); return(true); }
public static Photo ToModel(this product_image img, Imgsize size, string externalid = null) { return(new Photo() { id = img.id, bigUrl = img.url, url = Img.by_size(img.url, size), externalid = externalid }); }
public void Insertproduct_images(product_imageinfo pinfo) { using (RMSDataContext db = new RMSDataContext()) { product_image tbl = new product_image(); tbl.Product_imageID = pinfo.Product_imageID; tbl.Images = pinfo.Images; db.product_images.InsertOnSubmit(tbl); db.SubmitChanges(); } }
public static product_image ReadAndSaveProductImageFromUrl(this string url, long subdomainid, long ownerid, long?productid) { var req = WebRequest.Create(url); WebResponse resp = null; try { resp = req.GetResponse(); } catch (Exception ex) { Syslog.Write(ex); } if (resp == null) { return(null); } try { var image = new product_image(); using (var repository = new TradelrRepository()) { var sd = repository.GetSubDomain(subdomainid); var extension = url.ToImageFormat().ToStringExtension(); var filename = BuildFilename(ownerid, extension); var handler = new FileHandler(filename, UploadFileType.IMAGE, sd.uniqueid); image.productid = productid; image.subdomainid = subdomainid; image.url = handler.Save(resp.GetResponseStream()); if (productid.HasValue) { repository.AddProductImage(image); var product = repository.GetProduct(productid.Value, subdomainid); if (product != null && !product.thumb.HasValue) { product.thumb = image.id; } repository.Save("ReadAndSaveProductImageFromUrl"); } } return(image); } catch (Exception ex) { Syslog.Write(ex); return(null); } }
//public product_image getMainimg(int idprod) //{ // LQDataContext ctx = new LQDataContext(); // var azz = (from t in ctx.product_images // where t.id_prod == idprod // where t.sub_img == 1 // select t).SingleOrDefault(); // return azz; //} public void UpdateimgProd(product_image imp) { try { LQDataContext ctxx = new LQDataContext(); var q = ctxx.product_images.Where(d => d.id_img == imp.id_img).SingleOrDefault(); q.img_url = imp.img_url; ctxx.SubmitChanges(); } catch (Exception ex) { } }
protected void del_Command(object sender, CommandEventArgs e) { if (e.CommandName == "delcm") { foreach (RepeaterItem it in grid_product.Items) { Label n1 = (Label)it.FindControl("lblid"); if (n1.Text == e.CommandArgument.ToString()) { int n = Convert.ToInt32(n1.Text); List <product_image> lim = cl.getProdImage(n); foreach (product_image imgpr in lim) { listim.Add(imgpr); cl.DeleteImgProd(imgpr.id_img); } if (cl.DeleteProduct(n)) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Delete Complete')", true); break; } else { foreach (product_image imgpr1 in listim) { product_image imgtam = new product_image(); imgtam.id_prod = imgpr1.id_prod; imgtam.img_url = imgpr1.img_url; imgtam.sub_img = imgpr1.sub_img; cl.AddimgProd(imgtam); } ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Delete Fail')", true); } } } load_Prod(); } }
protected void itemsGrid_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Add_Item") { board_item b = new board_item(); string link = e.CommandArgument.ToString(); p = findItemAddToBoard(link, imgColl); b = board_item.productToBoardConversion(p); b.Board_Name = boardName; myDB.insertBoardDoc(usersBoardColl, b); } }
protected product_image findItemAddToBoard(string link, IMongoCollection<product_image> coll) { product_image p = new product_image(); List<product_image> items = coll.Find(itm => itm.Image_Link == link) .ToListAsync() .Result; foreach (product_image itm in items) { p = itm; } return p; }
public void ud() { foreach (RepeaterItem i in Repeater3.Items) { FileUpload fu = (FileUpload)i.FindControl("FileUpload1"); Label lbl = (Label)i.FindControl("lblIDIMG"); if (fu.HasFile) { if (!ck.CheckFileType(fu.FileName)) { tam = 1; break; } } } if (FileUploadMore.HasFile) { foreach (var file1 in FileUploadMore.PostedFiles) { if (!ck.CheckFileType(file1.FileName)) { tam = 1; break; } } } if (tam == 0) { foreach (RepeaterItem i in Repeater3.Items) { FileUpload fu = (FileUpload)i.FindControl("FileUpload1"); Label lbl = (Label)i.FindControl("lblIDIMG"); if (fu.HasFile) { int n111 = Convert.ToInt32(lbl.Text); string fileName = "images/product-category/" + fu.FileName; string filePath = MapPath(fileName); fu.SaveAs(filePath); product_image ima = cl.getImage(n111); ima.img_url = fu.FileName; cl.UpdateimgProd(ima); } } if (FileUploadMore.HasFile) { foreach (var file1 in FileUploadMore.PostedFiles) { string fileName = "images/product-category/" + file1.FileName; string filePath = MapPath(fileName); file1.SaveAs(filePath); ip1 = new product_image(); ip1.id_prod = p.id_pro; ip1.img_url = file1.FileName; cl.AddimgProd(ip1); } } if ((int)ViewState["bf"] == 1) { p.id_cat = idCate; ViewState["bf"] = 0; } if (ck.checkstringnull(txtName.Text.Trim())) { if (ck.checkstringnull(txtPrice.Text.Trim())) { if (ck.checknumber(txtPrice.Text.Trim())) { if (ck.checkstring(txtName.Text.Trim(), 50)) { if (p.pro_name == txtName.Text.Trim()) { p.pro_name = txtName.Text.Trim(); p.pro_price = float.Parse(txtPrice.Text.Trim()); cl.UpdateProduct(p); load_pro(); } else { if (cl.checkalprod(txtName.Text.Trim())) { p.pro_name = txtName.Text.Trim(); p.pro_price = float.Parse(txtPrice.Text.Trim()); cl.UpdateProduct(p); load_pro(); } else { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Product Name Already Exist')", true); } } } else { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Product Name Too Long')", true); } } else { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Product Price Is Incorrect')", true); } } else { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Please Type Product Price')", true); } } else { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Please Type Product Name')", true); } } else { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Many Images Too Large Or Not Format(.jpg|.png|.gif)')", true); load_pro(); loadCate(); } }
public ActionResult Upload(PhotoType type, long?id) { if (!sessionid.HasValue) { return(SendJsonSessionExpired()); } long ownerid = sessionid.Value; if (Request.Files.Count < 1) { throw new Exception(); } var imageUpload = Request.Files[0]; var extIndex = imageUpload.FileName.LastIndexOf('.'); var ext = imageUpload.FileName.Substring(extIndex); string filename = ImgHelper.BuildFilename(sessionid.Value, ext); var handler = new FileHandler(filename, UploadFileType.IMAGE, MASTERdomain.uniqueid); var url = handler.Save(imageUpload.InputStream); if (string.IsNullOrEmpty(url)) { return(Content("," + GeneralConstants.PHOTO_UPLOAD_ERROR_PATH)); } image image = null; product_image pimage = null; long imageid; switch (type) { case PhotoType.BACKGROUND: case PhotoType.PROFILE: case PhotoType.COMPANY: image = new image { imageType = type.ToString(), url = url, subdomain = subdomainid.Value }; imageid = repository.AddImage(image); break; case PhotoType.PRODUCT: pimage = new product_image { url = url, subdomainid = subdomainid.Value }; repository.AddProductImage(pimage); imageid = pimage.id; break; default: throw new NotImplementedException(); } // depending on image type.... user usr; string retVal = ""; long profileID; string thumbnailUrl; switch (type) { case PhotoType.BACKGROUND: thumbnailUrl = Img.by_size(url, Imgsize.COMPACT); retVal = string.Concat(imageid, ",#background_image,", thumbnailUrl); break; case PhotoType.COMPANY: thumbnailUrl = Img.by_size(url, Imgsize.MEDIUM); profileID = id.HasValue ? id.Value : ownerid; usr = repository.GetUserById(profileID, subdomainid.Value); usr.organisation1.logo = imageid; image.contextID = usr.organisation.Value; repository.Save(); retVal = string.Concat(imageid, ",#company_image,", thumbnailUrl); CacheHelper.Instance.invalidate_dependency(DependencyType.organisation, subdomainid.Value.ToString()); break; case PhotoType.PROFILE: thumbnailUrl = Img.by_size(url, Imgsize.MEDIUM); profileID = id.HasValue ? id.Value : ownerid; usr = repository.GetUserById(profileID, subdomainid.Value); usr.profilePhoto = imageid; image.contextID = usr.id; repository.Save(); retVal = string.Concat(imageid, ",#profile_image,", thumbnailUrl); break; case PhotoType.PRODUCT: thumbnailUrl = Img.by_size(url, Imgsize.MEDIUM); retVal = string.Concat(imageid, ",#product_images,", thumbnailUrl); // for when editing products // when creating new product entry, contextid is only updated when product is saved, it will be 0 if images // uploaded and then product is not saved if (id.HasValue) { var productid = id.Value; pimage.productid = productid; repository.Save(); repository.UpdateProductMainThumbnail(productid, subdomainid.Value, imageid.ToString()); } break; } return(Content(retVal)); }
protected void Page_Load(object sender, EventArgs e) { i = (int)Session["i"]; el = (elements)Session["el"]; myDB = (database)Session["myDB"]; curUser = (user)Session["curUser"]; boardName = (string)Session["boardName"]; queryItems = (List<product_image>)Session["queryItems"]; usersBoardColl = myDB.getUsersBoardCollection(curUser); p = (product_image)Session["p"]; setImage(p); }
public void setImage(product_image p) { Image1.ImageUrl = p.Image_Link; }
protected void xButton_Click(object sender, ImageClickEventArgs e) { displayLbl.Text = ""; i++; if (i > queryItems.Count() - 1) { imagePnl.Visible = false; errorPnl.Visible = true; } else { p = queryItems[i]; setImage(p); Session["p"] = p; Session["i"] = i; } }
protected void elementsBtn_Click(object sender, EventArgs e) { Page page = (Page)HttpContext.Current.Handler; elements.setElements(colorList, lineList, lightList, formList, spaceList, textureList, patternList, massList, balanceList, unityList, harmonyList, rhythmList, proportionList, varietyList, emphasisList, scaleList, typeList, el, page); Session["el"] = el; List<product_image> queryItems = allItems; queryItems = product_image.queryProducts(queryItems, el); p = queryItems[0]; if (p.ID != 0) { int i = 0; Session["i"] = i; Session["p"] = p; Session["queryItems"] = queryItems; Response.Redirect("~/main.aspx"); } else { label1.Text = "No items exist with those elements/principles."; } }
protected void submitItemBtn_Click(object sender, EventArgs e) { newItem = (product_image)Session["newItem"]; myDB.insertProductDoc(imgColl, newItem); myDB.retrieveImagesCollection(); imgColl = myDB.getImagesCollection(); allItems = product_image.getItems(imgColl); Session["allItems"] = allItems; Response.Redirect(Request.RawUrl); }
public void AddProductImage(product_image img) { db.product_images.InsertOnSubmit(img); db.SubmitChanges(); }
protected void btnAddPro_Click(object sender, EventArgs e) { if (FileU.HasFile) { foreach (var file in FileU.PostedFiles) { if (!ck.CheckFileType(file.FileName)) { tam = 1; break; } } if (tam == 0) { int dem = 0; pr = new category_product_detail(); if ((int)ViewState["bf"] == 1) { pr.id_cat = idCate; ViewState["bf"] = 0; } else { drCate.SelectedIndex = 0; pr.id_cat = Convert.ToInt32(drCate.SelectedItem.Value); } if (ck.checkstringnull(tbName1.Text)) { if (ck.checkstringnull(tbPrice1.Text)) { if (ck.checknumber(tbPrice1.Text)) { if (ck.checkstring(tbName1.Text, 50)) { if (cl.checkalprod(tbName1.Text.Trim())) { pr.pro_name = tbName1.Text.Trim(); pr.pro_price = float.Parse(tbPrice1.Text.Trim()); cl.AddProduct(pr); foreach (var file in FileU.PostedFiles) { string fileName = "images/product-category/" + file.FileName; string filePath = MapPath(fileName); file.SaveAs(filePath); ip = new product_image(); ip.id_prod = pr.id_pro; ip.img_url = file.FileName; imgS.ImageUrl = ip.img_url; if (dem == 0) { ip.sub_img = 1; } else { ip.sub_img = 0; } dem++; cl.AddimgProd(ip); } } else { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Product Name Already Exist')", true); } } else { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Product Name Too Long')", true); } } else { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Product Price Is Incorrect')", true); } } else { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Please Type Product Price')", true); } } else { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Please Type Product Name')", true); } } else { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Image File Too Large Or Not Format(.jpg|.png|.gif)')", true); } } else { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Please Choose Image')", true); } load_Prod(); loadCate(); clearall(); }