public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; context.Response.Expires = -1; try { HttpPostedFile postedFile = context.Request.Files["Filedata"]; int inStock = 0; try { inStock = int.Parse(context.Request.QueryString["inStock"].ToString().Trim()); } catch {; } string[] sArrProdID = null; char[] sep = { '?' }; string[] sArrVkey = null; string strUserID = string.Empty; char[] sep2 = { ',' }; sArrProdID = context.Request.QueryString["user"].ToString().Trim().Split(sep); sArrVkey = sArrProdID[0].ToString().Trim().Split(sep2); string chuyenmuc = sArrVkey[sArrVkey.Length - 1]; string _urlSave = string.Empty; string FolderCat = string.Empty; string savepath = string.Empty; string tempPath = string.Empty; string strRootPathVirtual = string.Empty; _user = _userDAL.GetUserByUserName(sArrVkey[0].ToString()); strUserID = _user.UserID.ToString(); string vType = sArrVkey[1].ToString(); if (vType == "1") { if (inStock != 0) { FolderCat = "/InStock/"; } else { FolderCat = "/Article/"; } } else if (vType == "2") { FolderCat = "/Ads/"; } else if (vType == "3") { FolderCat = "/Video/"; } else if (vType == "4") { FolderCat = "/Photo24/"; } else { FolderCat = string.Empty; } tempPath = System.Configuration.ConfigurationManager.AppSettings["UploadPathBDT"] + FolderCat + sArrVkey[0].ToString() + "/"; strRootPathVirtual = tempPath + DateTime.Now.Year.ToString() + "/" + DateTime.Now.Month.ToString() + "/" + DateTime.Now.Day.ToString() + "/"; savepath = context.Server.MapPath(strRootPathVirtual); string filename = getFileNameUnique(savepath + @"\", postedFile.FileName, Path.GetFileNameWithoutExtension(postedFile.FileName), Path.GetExtension(postedFile.FileName.ToString())); string _extenfile = Path.GetExtension(filename.ToString()); string strFileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(postedFile.FileName).Trim(); if (!Directory.Exists(savepath)) { Directory.CreateDirectory(savepath); } if (_extenfile.ToLower().Contains(".jpg") || _extenfile.ToLower().Contains(".gif") || _extenfile.ToLower().Contains(".png") || _extenfile.ToLower().Contains(".bmp") || _extenfile.ToLower().Contains(".jpeg")) { postedFile.SaveAs(savepath + @"\" + filename); } double CATID = 0; try { CATID = double.Parse(chuyenmuc); } catch {; } string _logo = context.Server.MapPath("../DungChung/Images/IconHPC/LoGoBaoNongNghiep.png"); string _imagesEndWatermark = getFileNameUnique(savepath + @"\", postedFile.FileName, Path.GetFileNameWithoutExtension(filename), _extenfile); if (_extenfile.ToLower() != ".flv" && _extenfile.ToLower() != ".swf" && _extenfile.ToLower() != ".mp3" && _extenfile.ToLower() != ".mp4" && _extenfile.ToLower() != ".wmv" && _extenfile.ToLower() != ".doc" && _extenfile.ToLower() != ".docx" && _extenfile.ToLower() != ".xls" && _extenfile.ToLower() != ".rar" && _extenfile.ToLower() != ".txt" && _extenfile.ToLower() != ".pdf") { if (Convert.ToBoolean(Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["WatermarkImages"]))) { //Begin BO CT EDIT Đóng dấu ảnh _imagesEndWatermark = "W_" + filename; HPCImageResize.SaveImage2Server(savepath, filename, "rez_" + filename, _imagesEndWatermark, _logo, Convert.ToInt32(HPCComponents.Global.VNPResizeImages), Convert.ToInt32(HPCComponents.Global.VNPResizeImages)); } else if (Convert.ToBoolean(Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["AutoProcessReszie"])))// Không đóng dấu ảnh //END { HPCImageResize.SaveImage2Server(savepath, filename, _imagesEndWatermark, Convert.ToInt32(HPCComponents.Global.VNPResizeImages), Convert.ToInt32(HPCComponents.Global.VNPResizeImages)); } } else { _imagesEndWatermark = filename; postedFile.SaveAs(Path.Combine(savepath, filename)); } //_urlSave = UrlPathImage_RemoveUpload(strRootPathVirtual + filename); _urlSave = UrlPathImage_RemoveUpload(strRootPathVirtual + _imagesEndWatermark); //phan insert co so du lieu T_ImageFiles _obj = new T_ImageFiles(); ImageFilesDAL _DAL = new ImageFilesDAL(); _obj = SetItem(_imagesEndWatermark, postedFile.ContentLength, _urlSave, _extenfile, Convert.ToInt16(strUserID), Convert.ToInt16(vType), CATID); int _idReturn = _DAL.InsertT_ImageFiles(_obj); if (inStock != 0) { _DAL.UpdateStatusDataByID(" AuthorID =1 Where ID =" + _idReturn); } context.Response.Write(savepath + "/" + filename); context.Response.StatusCode = 200; } catch (Exception ex) { context.Response.Write("Error: " + ex.Message); } }
protected void cmd_watermark_Click(object sender, EventArgs e) { string url1 = txt_UrlImage.Text.Trim(); if (!string.IsNullOrEmpty(url1)) { string url = ConfigurationManager.AppSettings["ServerPathDis"].ToString() + url1; if (File.Exists(url)) { int _instock = Convert.ToInt32(ddlStock.SelectedValue.Trim()); string strPhysLocal = ""; if (strNumberArg == "1") { if (_instock != 0) { strPhysLocal = "/" + "InStock/Thumnail/"; } else { strPhysLocal = "/" + "Article/Thumnail/"; } } if (strNumberArg == "2") { strPhysLocal = "/" + Global.UploadPhotoAlbum + "/"; } if (strNumberArg == "3") { strPhysLocal = "/" + Global.UploadPhotoEvent + "/"; } //string width = DropSize.SelectedValue; System.Drawing.Bitmap sourceImage = new System.Drawing.Bitmap(url); string _extension = Path.GetExtension(url); string filename = "WaterMark_" + DateTime.Now.ToString("ddMMyyyyHHmmss") + DateTime.Now.Millisecond.ToString() + Path.GetExtension(url); Bitmap imgsave = null; string newfolder = strPhysLocal + DateTime.Now.Year.ToString() + "/" + DateTime.Now.Month.ToString() + "/" + DateTime.Now.Day.ToString() + "/"; string pathsave = ConfigurationManager.AppSettings["ServerPathDis"].ToString() + newfolder; string _logo = Server.MapPath("../Images/IconHPC/LoGoBaoAnhDong.png"); Bitmap Imagemark = new Bitmap(_logo); int spacevalues = 0; try { spacevalues = int.Parse(ConfigurationManager.AppSettings["SpaceValue"].ToString()); } catch {; } //imgsave = HPCImages.WatermarkImages(sourceImage, Imagemark, int.Parse(DropStyle.SelectedValue), spacevalues); imgsave = HPCImages.WatermarkImages(sourceImage, Imagemark, int.Parse(X11.Value), int.Parse(Y11.Value)); if (Directory.Exists(pathsave) == false) { Directory.CreateDirectory(pathsave); } imgsave.Save(pathsave + @"\" + filename); imgsave.Dispose(); Imagemark.Dispose(); sourceImage.Dispose(); txt_UrlImage.Text = newfolder + "/" + filename; T_ImageFiles _obj = new T_ImageFiles(); ImageFilesDAL _DAL = new ImageFilesDAL(); _obj = SetItem(filename, 0, txt_UrlImage.Text, _extension, _user.UserID, Convert.ToInt16(strNumberArg), Convert.ToInt32(Drop_Chuyenmuc.SelectedValue)); int _idReturn = _DAL.InsertT_ImageFiles(_obj); if (_instock != 0) { _DAL.UpdateStatusDataByID(" AuthorID =1 Where ID =" + _idReturn); } ListImages(); System.Web.UI.ScriptManager.RegisterStartupScript(this, typeof(string), "Message", "PreviewImage('" + newfolder + "/" + filename + "','" + strNumberArg + "','0','" + _extension + "');", true); } } else { System.Web.UI.ScriptManager.RegisterStartupScript(this, typeof(string), "Message", "alert('Hãy chọn ảnh để đóng dấu ');", true); } }