protected void Page_Load(object sender, EventArgs e) { var ten = Request["Ten"]; var moTa = Request["MoTa"]; var id = Request["Id"]; var cUrl = Request["cUrl"]; var gioiThieu = Request["GioiThieu"]; var anh = Request["Anh"]; var duyet = Request["Duyet"]; var active = Request["Active"]; var logged = Security.IsAuthenticated(); var idNull = string.IsNullOrEmpty(id) || id == "0"; var adminKey = Request["AdminKey"]; var dic = Server.MapPath("~/lib/up/nhom/"); var joined = Request["Joined"]; var approved = Request["approved"]; var loai = Request["loai"]; switch (subAct) { case "save": #region save Nhom if (logged && !string.IsNullOrEmpty(ten)) { var item = idNull ? new Nhom() : NhomDal.SelectById(Convert.ToInt32(id)); item.Ten = ten; item.MoTa = moTa; item.GioiThieu = gioiThieu; item.Anh = anh; item.NgayCapNhat = DateTime.Now; if (!string.IsNullOrEmpty(duyet)) { duyet = !string.IsNullOrEmpty(duyet) ? "true" : "false"; item.Duyet = Convert.ToBoolean(duyet); item.NguoiDuyet = Security.Username; item.NgayDuyet = DateTime.Now; } if (!string.IsNullOrEmpty(active)) { active = !string.IsNullOrEmpty(active) ? "true" : "false"; item.Active = Convert.ToBoolean(active); } if (idNull) { item.NguoiTao = Security.Username; item.NgayTao = DateTime.Now; item.RowId = Guid.NewGuid(); item = NhomDal.Insert(item); NhomThanhVienDal.Insert(new NhomThanhVien() { NHOM_ID = item.Id , Accepted = true ,AcceptedDate = DateTime.Now , Admin = true , Approved = true , ApprovedDate = DateTime.Now , ID = Guid.NewGuid() , NgayTao = DateTime.Now , NguoiTao = Security.Username , Username = Security.Username , IsMod = true , ModLoai = 5 }); ObjMemberDal.Insert(new ObjMember() { PRowId = item.RowId , Username = Security.Username , Owner = true , NgayTao = DateTime.Now , RowId = Guid.NewGuid() }); var obj = ObjDal.Insert(new Obj() { Id = Guid.NewGuid() , Kieu = typeof(Nhom).FullName , NgayTao = DateTime.Now , RowId = item.RowId , Ten = item.Ten , Url = string.Format("{0}", item.Url) , Username = Security.Username }); } else { item.NguoiCapNhat = Security.Username; item = NhomDal.Update(item); } rendertext(item.Url); } rendertext("0"); break; #endregion case "remove": #region remove Nhom if (!string.IsNullOrEmpty(id) && logged) { var item = NhomDal.SelectById(Convert.ToInt32(id)); if (item.NguoiTao == Security.Username || !string.IsNullOrEmpty(adminKey)) { ObjDal.DeleteByRowId(item.RowId); ObjMemberDal.DeleteByPRowId(item.RowId.ToString()); ThichDal.DeleteByPId(item.RowId); NhomDal.DeleteById(item.Id); } } break; #endregion case "join": #region Tham gia nhom if (!string.IsNullOrEmpty(id) && logged) { var item = NhomDal.SelectById(DAL.con(), Convert.ToInt32(id), Security.Username); var isJoined = joined == "1"; var itemTv = NhomThanhVienDal.SelectByNhomIdUsername(id, Security.Username); if (isJoined && itemTv.ID != Guid.Empty && !itemTv.Admin) // remove { NhomThanhVienDal.DeleteById(itemTv.ID); } else // add { NhomThanhVienDal.Insert(new NhomThanhVien() { Accepted = true , AcceptedDate = DateTime.Now , Admin = false , Approved = false , ID = Guid.NewGuid() , NgayTao = DateTime.Now , NguoiTao = Security.Username , NHOM_ID = item.Id , Username = Security.Username , IsMod = false , ModLoai = 0 }); } } break; #endregion case "duyetThanhVien": #region Duyệt thành viên tham gia nhóm if (!string.IsNullOrEmpty(id) && logged) { var nhomTv = NhomThanhVienDal.SelectById(new Guid(id)); var mem = Security.Username; var memTv = NhomThanhVienDal.SelectByNhomIdUsername(nhomTv.NHOM_ID.ToString(), mem); var nhom = NhomDal.SelectById(nhomTv.NHOM_ID); var Approved = approved == "1"; if(memTv.ModLoai==5 ) { if(Approved) { nhomTv.Approved = true; nhomTv.ApprovedDate = DateTime.Now; NhomThanhVienDal.Update(nhomTv); ObjMemberDal.Insert(new ObjMember() { PRowId = nhom.RowId , Username = nhomTv.Username , Owner = false , NgayTao = DateTime.Now , RowId = Guid.NewGuid() }); } else { NhomThanhVienDal.DeleteById(nhomTv.ID); ObjMemberDal.DeleteByPRowIdUsername(nhom.RowId.ToString(), nhomTv.Username); } rendertext("1"); } rendertext("0"); } break; #endregion case "phanQuyenThanhVien": #region Phân quyền thành viên if (!string.IsNullOrEmpty(id) && logged) { var nhomTv = NhomThanhVienDal.SelectById(new Guid(id)); var mem = Security.Username; var memTv = NhomThanhVienDal.SelectByNhomIdUsername(nhomTv.NHOM_ID.ToString(), mem); if (memTv.ModLoai == 5) { nhomTv.ModLoai = Convert.ToInt32(loai); nhomTv.IsMod = nhomTv.ModLoai != 0; if(!nhomTv.Approved) { nhomTv.Approved = true; nhomTv.ApprovedDate = DateTime.Now; } NhomThanhVienDal.Update(nhomTv); rendertext("1"); } rendertext("0"); } break; #endregion case "changeAvatar": #region change avatar if (logged) { if (Request.Files.Count > 0) { var img = new ImageProcess(Request.Files[0].InputStream, Guid.NewGuid().ToString()); if (img.Width > img.Heigth) { img.ResizeHeight(180); } else { img.Resize(180); } img.Crop(180, 180); var anhNew = string.Format("{0}{1}", Guid.NewGuid().ToString(), img.Ext); img.Save(dic + anhNew); rendertext(anhNew); } } rendertext("0"); break; #endregion } }
public void ProcessRequest(HttpContext context) { StringBuilder sb = new StringBuilder(); string act = context.Request["act"]; string rqPlug = context.Request["rqPlug"]; string imgSaveLoc = context.Server.MapPath("~/lib/up/i/"); string imgTemp = context.Server.MapPath("~/lib/up/temp/"); string docTemp = context.Server.MapPath("~/lib/up/d/"); string imgSaveTintuc = context.Server.MapPath("~/lib/up/tintuc/"); string imgSaveSanPham = context.Server.MapPath("~/lib/up/sanpham/"); string imgSaveQuangCao = context.Server.MapPath("~/lib/up/quangcao/"); string imgSaveKTNN = context.Server.MapPath("~/lib/up/KTNN/"); string _height = context.Request["height"]; string _width = context.Request["width"]; string _PRowIdSP = context.Request["PRowIdSP"]; switch (act) { case "loadPlug": #region loadPlug: nap plug if (rqPlug != null) { sb.Append(PlugHelper.RenderHtml(rqPlug)); } rendertext(sb); break; #endregion case "upload": #region upload ?nh if (context.Request.Files[0] != null) { string imgten = Guid.NewGuid().ToString(); if (!string.IsNullOrEmpty(context.Request["oldFile"])) { } var img = new ImageProcess(context.Request.Files[0].InputStream, imgten); context.Request.Files[0].SaveAs(imgSaveLoc + imgten + "full" + img.Ext); img.Resize(326); context.Request.Files[0].SaveAs(imgSaveLoc + imgten + "326" + img.Ext); img.Crop(50, 50); img.Save(imgSaveLoc + imgten + img.Ext); rendertext(imgten + img.Ext); } break; #endregion case "uploadQuangCao": #region upload ?nh if (context.Request.Files[0] != null) { string imgten = Guid.NewGuid().ToString(); if (!string.IsNullOrEmpty(context.Request["oldFile"])) { try { imgten = Path.GetFileNameWithoutExtension(context.Request["oldFile"]); if (File.Exists(imgSaveQuangCao + context.Request["oldFile"])) { File.Delete(imgSaveQuangCao + context.Request["oldFile"]); } } finally { } } ImageProcess img = new ImageProcess(context.Request.Files[0].InputStream, Guid.NewGuid().ToString()); img.Save(imgSaveQuangCao + imgten + "source" + img.Ext); img.Crop(int.Parse(_width), int.Parse(_height)); img.Save(imgSaveQuangCao + imgten + img.Ext); rendertext(imgten + img.Ext); } break; #endregion case "uploadSanPham": #region upload ?nh if (context.Request.Files[0] != null) { string imgten = Guid.NewGuid().ToString(); if (!string.IsNullOrEmpty(context.Request["oldFile"])) { try { imgten = Path.GetFileNameWithoutExtension(context.Request["oldFile"]); if (File.Exists(imgSaveSanPham + context.Request["oldFile"])) { File.Delete(imgSaveSanPham + context.Request["oldFile"]); } } finally { } } ImageProcess img = new ImageProcess(context.Request.Files[0].InputStream, Guid.NewGuid().ToString()); img.Save(imgSaveSanPham + imgten + "full" + img.Ext); img.Crop(400, 300); img.Save(imgSaveSanPham + imgten + "400x300" + img.Ext); img.Crop(200, 200); img.Save(imgSaveSanPham + imgten + "200x200" + img.Ext); img.Crop(90, 90); img.Save(imgSaveSanPham + imgten + img.Ext); rendertext(imgten + img.Ext); } break; #endregion case "uploadTintuc": #region upload ?nh if (Security.IsAuthenticated()) { if (context.Request.Files[0] != null) { string imgten = Guid.NewGuid().ToString(); if (!string.IsNullOrEmpty(context.Request["oldFile"])) { try { imgten = Path.GetFileNameWithoutExtension(context.Request["oldFile"]); if (File.Exists(imgSaveTintuc + context.Request["oldFile"])) { File.Delete(imgSaveTintuc + context.Request["oldFile"]); } } finally { } } ImageProcess img = new ImageProcess(context.Request.Files[0].InputStream, Guid.NewGuid().ToString()); context.Request.Files[0].SaveAs(imgSaveTintuc + imgten + "full" + img.Ext); img.Crop(730, 600); img.Save(imgSaveTintuc + imgten + "990x340" + img.Ext); img.Crop(420, 280); img.Save(imgSaveTintuc + imgten + "420x280" + img.Ext); img.Crop(130, 100); img.Save(imgSaveTintuc + imgten + img.Ext); rendertext(imgten + img.Ext); } } break; #endregion case "uploadKTNN": #region upload ?nh if (Security.IsAuthenticated()) { if (context.Request.Files[0] != null) { string imgten = Guid.NewGuid().ToString(); if (!string.IsNullOrEmpty(context.Request["oldFile"])) { try { imgten = Path.GetFileNameWithoutExtension(context.Request["oldFile"]); if (File.Exists(imgSaveKTNN + context.Request["oldFile"])) { File.Delete(imgSaveKTNN + context.Request["oldFile"]); } } finally { } } ImageProcess img = new ImageProcess(context.Request.Files[0].InputStream, Guid.NewGuid().ToString()); img.Crop(730, 600); img.Save(imgSaveKTNN + imgten + "730x600" + img.Ext); img.Crop(420, 280); img.Save(imgSaveKTNN + imgten + "420x280" + img.Ext); img.Crop(130, 100); img.Save(imgSaveKTNN + imgten + img.Ext); rendertext(imgten + img.Ext); } } break; #endregion case "uploadFlash": #region upload flash if (context.Request.Files[0] != null) { string imgten = Guid.NewGuid().ToString(); if (!string.IsNullOrEmpty(context.Request["oldFile"])) { try { imgten = Path.GetFileNameWithoutExtension(context.Request["oldFile"]); if (File.Exists(imgSaveLoc + context.Request["oldFile"])) { File.Delete(imgSaveLoc + context.Request["oldFile"]); } } finally { } } if (Path.GetExtension(context.Request.Files[0].FileName).ToLower() == ".swf") { string flash = Guid.NewGuid().ToString(); context.Request.Files[0].SaveAs(context.Server.MapPath("~/lib/up/v/") + flash + Path.GetExtension(context.Request.Files[0].FileName)); rendertext(flash + Path.GetExtension(context.Request.Files[0].FileName)); } else { ImageProcess img = new ImageProcess(context.Request.Files[0].InputStream, Guid.NewGuid().ToString()); img.Crop(420, 280); img.Save(imgSaveLoc + imgten + "420x280" + img.Ext); img.Crop(130, 100); img.Save(imgSaveLoc + imgten + img.Ext); img.Crop(370, 90); img.Save(imgSaveLoc + imgten + "370x90" + img.Ext); rendertext(imgten + img.Ext); } } break; #endregion case "uploadFull": #region upload ?nh if (context.Request.Files[0] != null) { string imgten = Guid.NewGuid().ToString(); if (!string.IsNullOrEmpty(context.Request["oldFile"])) { try { imgten = Path.GetFileNameWithoutExtension(context.Request["oldFile"]); if (File.Exists(imgSaveLoc + context.Request["oldFile"])) { File.Delete(imgSaveLoc + context.Request["oldFile"]); } } finally { } } ImageProcess img = new ImageProcess(context.Request.Files[0].InputStream, Guid.NewGuid().ToString()); img.Save(imgSaveLoc + imgten + img.Ext); rendertext(imgten + img.Ext); } break; #endregion case "loadPlugDirect": if (!string.IsNullOrEmpty(rqPlug)) { string _IPlugType = rqPlug; Type type = Type.GetType(_IPlugType); IPlug _IPlug = (IPlug)(Activator.CreateInstance(type)); _IPlug.ImportPlugin(); UserControl uc = (UserControl)(_IPlug); Page page = new Page(); page.EnableViewState = false; HtmlForm form = new HtmlForm(); form.ID = "__t"; page.Controls.Add(form); form.Controls.Add(uc); StringWriter tw = new StringWriter(); HttpContext.Current.Server.Execute(page, tw, true); } break; case "capcha": #region capcha string _capchaCode = CaptchaImage.GenerateRandomCode(CaptchaType.AlphaNumeric, 3); context.Session["capcha"] = _capchaCode; CaptchaImage c = new CaptchaImage(_capchaCode, 200, 50, "Tahoma", Color.White, Color.Orange); context.Response.ClearContent(); context.Response.ContentType = "image/jpeg"; MemoryStream ms = new MemoryStream(); c.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); context.Response.OutputStream.Write(ms.ToArray(), 0, Convert.ToInt32(ms.Length)); ms.Close(); context.Response.End(); break; #endregion default: #region macdinh context.Response.Write(DateTime.Now.ToString("hh:mm")); break; #endregion } }
public void ProcessRequest(HttpContext context) { StringBuilder sb = new StringBuilder(); string act = context.Request["act"]; string rqPlug = context.Request["rqPlug"]; string imgSaveLoc = context.Server.MapPath("~/lib/up/i/"); string imgTemp = context.Server.MapPath("~/lib/up/temp/"); string docTemp = context.Server.MapPath("~/lib/up/d/"); string imgSaveTintuc = context.Server.MapPath("~/lib/up/tintuc/"); string imgSaveSanPham = context.Server.MapPath("~/lib/up/sanpham/"); string imgSaveQuangCao = context.Server.MapPath("~/lib/up/quangcao/"); string imgSaveKTNN = context.Server.MapPath("~/lib/up/KTNN/"); string _height = context.Request["height"]; string _width = context.Request["width"]; string _PRowIdSP = context.Request["PRowIdSP"]; switch (act) { case "loadPlug": #region loadPlug: nap plug if (rqPlug != null) { sb.Append(PlugHelper.RenderHtml(rqPlug)); } rendertext(sb); break; #endregion case "upload": #region upload ?nh if (context.Request.Files[0] != null) { string imgten = Guid.NewGuid().ToString(); if (!string.IsNullOrEmpty(context.Request["oldFile"])) { try { imgten = Path.GetFileNameWithoutExtension(context.Request["oldFile"]); if (File.Exists(imgSaveLoc + context.Request["oldFile"])) { File.Delete(imgSaveLoc + context.Request["oldFile"]); } } finally { } } imgten = Guid.NewGuid().ToString(); ImageProcess img = new ImageProcess(context.Request.Files[0].InputStream, imgten); img.Save(imgSaveLoc + imgten + "full" + img.Ext); img.Crop(400, 400); img.Save(imgSaveLoc + imgten + "400x400" + img.Ext); img.Crop(170, 150); img.Save(imgSaveLoc + imgten + "170x150" + img.Ext); img.Crop(150, 115); img.Save(imgSaveLoc + imgten + "150x115" + img.Ext); img.Crop(50, 50); img.Save(imgSaveLoc + imgten + img.Ext); rendertext(imgten + img.Ext); } break; #endregion case "uploadQuangCao": #region upload ?nh if (context.Request.Files[0] != null) { string imgten = Guid.NewGuid().ToString(); if (!string.IsNullOrEmpty(context.Request["oldFile"])) { try { imgten = Path.GetFileNameWithoutExtension(context.Request["oldFile"]); if (File.Exists(imgSaveQuangCao + context.Request["oldFile"])) { File.Delete(imgSaveQuangCao + context.Request["oldFile"]); } } finally { } } ImageProcess img = new ImageProcess(context.Request.Files[0].InputStream, Guid.NewGuid().ToString()); img.Save(imgSaveQuangCao + imgten + "source" + img.Ext); img.Crop(int.Parse(_width), int.Parse(_height)); img.Save(imgSaveQuangCao + imgten + img.Ext); rendertext(imgten + img.Ext); } break; #endregion case "uploadSanPham": #region upload ?nh if (context.Request.Files[0] != null) { string imgten = Guid.NewGuid().ToString(); if (!string.IsNullOrEmpty(context.Request["oldFile"])) { try { imgten = Path.GetFileNameWithoutExtension(context.Request["oldFile"]); if (File.Exists(imgSaveSanPham + context.Request["oldFile"])) { File.Delete(imgSaveSanPham + context.Request["oldFile"]); } } finally { } } ImageProcess img = new ImageProcess(context.Request.Files[0].InputStream, Guid.NewGuid().ToString()); img.Save(imgSaveSanPham + imgten + "full" + img.Ext); img.Crop(400, 400); img.Save(imgSaveSanPham + imgten + "400x400" + img.Ext); img.Crop(400, 300); img.Save(imgSaveSanPham + imgten + "400x300" + img.Ext); img.Crop(200, 200); img.Save(imgSaveSanPham + imgten + "200x200" + img.Ext); img.Crop(90, 90); img.Save(imgSaveSanPham + imgten + img.Ext); rendertext(imgten + img.Ext); } break; #endregion case "uploadTintuc": #region upload ?nh if (Security.IsAuthenticated()) { if (context.Request.Files[0] != null) { string imgten = Guid.NewGuid().ToString(); if (!string.IsNullOrEmpty(context.Request["oldFile"])) { try { imgten = Path.GetFileNameWithoutExtension(context.Request["oldFile"]); if (File.Exists(imgSaveTintuc + context.Request["oldFile"])) { File.Delete(imgSaveTintuc + context.Request["oldFile"]); } } finally { } } imgten = Guid.NewGuid().ToString(); ImageProcess img = new ImageProcess(context.Request.Files[0].InputStream, Guid.NewGuid().ToString()); img.Save(imgSaveTintuc + imgten + "full" + img.Ext); img.Crop(990, 340); img.Save(imgSaveTintuc + imgten + "990x340" + img.Ext); img.Crop(280, 210); img.Save(imgSaveTintuc + imgten + "280x210" + img.Ext); img.Crop(240, 180); img.Save(imgSaveTintuc + imgten + "240x180" + img.Ext); img.Crop(160, 120); img.Save(imgSaveTintuc + imgten + "160x120" + img.Ext); img.Crop(120, 90); img.Save(imgSaveTintuc + imgten + "120x90" + img.Ext); img.Crop(100, 100); img.Save(imgSaveTintuc + imgten + img.Ext); rendertext(imgten + img.Ext); } } break; #endregion case "uploadKTNN": #region upload ?nh if (Security.IsAuthenticated()) { if (context.Request.Files[0] != null) { string imgten = Guid.NewGuid().ToString(); if (!string.IsNullOrEmpty(context.Request["oldFile"])) { try { imgten = Path.GetFileNameWithoutExtension(context.Request["oldFile"]); if (File.Exists(imgSaveKTNN + context.Request["oldFile"])) { File.Delete(imgSaveKTNN + context.Request["oldFile"]); } } finally { } } ImageProcess img = new ImageProcess(context.Request.Files[0].InputStream, Guid.NewGuid().ToString()); img.Crop(730, 600); img.Save(imgSaveKTNN + imgten + "730x600" + img.Ext); img.Crop(420, 280); img.Save(imgSaveKTNN + imgten + "420x280" + img.Ext); img.Crop(130, 100); img.Save(imgSaveKTNN + imgten + img.Ext); rendertext(imgten + img.Ext); } } break; #endregion case "uploadFlash": #region upload flash if (context.Request.Files[0] != null) { string imgten = Guid.NewGuid().ToString(); if (!string.IsNullOrEmpty(context.Request["oldFile"])) { try { imgten = Path.GetFileNameWithoutExtension(context.Request["oldFile"]); if (File.Exists(imgSaveLoc + context.Request["oldFile"])) { File.Delete(imgSaveLoc + context.Request["oldFile"]); } } finally { } } if (Path.GetExtension(context.Request.Files[0].FileName).ToLower() == ".swf") { string flash = Guid.NewGuid().ToString(); context.Request.Files[0].SaveAs(context.Server.MapPath("~/lib/up/v/") + flash + Path.GetExtension(context.Request.Files[0].FileName)); rendertext(flash + Path.GetExtension(context.Request.Files[0].FileName)); } else { ImageProcess img = new ImageProcess(context.Request.Files[0].InputStream, Guid.NewGuid().ToString()); img.Crop(420, 280); img.Save(imgSaveLoc + imgten + "420x280" + img.Ext); img.Crop(130, 100); img.Save(imgSaveLoc + imgten + img.Ext); img.Crop(370, 90); img.Save(imgSaveLoc + imgten + "370x90" + img.Ext); rendertext(imgten + img.Ext); } } break; #endregion case "uploadFull": #region upload ?nh if (context.Request.Files[0] != null) { string imgten = Guid.NewGuid().ToString(); if (!string.IsNullOrEmpty(context.Request["oldFile"])) { try { imgten = Path.GetFileNameWithoutExtension(context.Request["oldFile"]); if (File.Exists(imgSaveLoc + context.Request["oldFile"])) { File.Delete(imgSaveLoc + context.Request["oldFile"]); } } finally { } } ImageProcess img = new ImageProcess(context.Request.Files[0].InputStream, Guid.NewGuid().ToString()); img.Save(imgSaveLoc + imgten + img.Ext); rendertext(imgten + img.Ext); } break; #endregion case "uploadfileDkLuong": #region upload tài li?u //if (!loggedIn) rendertext("403"); if (context.Request.Files[0] != null) { string foldername = Guid.NewGuid().ToString().Replace("-", ""); string filename = Path.GetFileNameWithoutExtension(context.Request.Files[0].FileName); string fileType = Path.GetExtension(context.Request.Files[0].FileName); Directory.CreateDirectory(docTemp + foldername); context.Request.Files[0].SaveAs(docTemp + foldername + "/" + filename + fileType); //context.Request.Files[0].SaveAs(docTemp + filename + fileType); Files item = new Files(); item.Download = 0; item.MimeType = fileType; item.NgayTao = DateTime.Now; item.NguoiTao = Security.Username; item.Path = filename; item.PID = Guid.NewGuid(); item.RowId = Guid.NewGuid(); item.Size = context.Request.Files[0].ContentLength; item.Ten = filename; item.ThuMuc = foldername; item.VB_ID = 0; item = FilesDal.Insert(item); rendertext(item.ID.ToString()); } break; #endregion case "download": string _F_ID = context.Request["ID"]; if (!string.IsNullOrEmpty(_F_ID)) { Files item = FilesDal.SelectById(Convert.ToInt32(_F_ID)); context.Response.Buffer = true; context.Response.Clear(); context.Response.AddHeader("content-disposition", "attachment; filename=\"" + item.Ten + item.MimeType + "\""); context.Response.ContentType = "octet/stream"; //Response.ContentType = "application/ms-word"; context.Response.WriteFile(context.Server.MapPath("~/lib/up/d/") + item.ThuMuc + "/" + item.Path + item.MimeType); } break; case "DelOldFlash": System.IO.File.Delete(context.Server.MapPath("~/lib/up/v/") + Path.GetExtension(context.Request.Files[0].FileName)); System.IO.File.Delete(context.Server.MapPath("~/lib/up/i/") + Path.GetExtension(context.Request.Files[0].FileName)); break; case "MultiuploadImg": #region UploadAnh if (context.Request.Files[0] != null) { ImageProcess img = new ImageProcess(context.Request.Files[0].InputStream, Guid.NewGuid().ToString()); string foldername = Guid.NewGuid().ToString().Replace("-", ""); string imgten = Guid.NewGuid().ToString(); Directory.CreateDirectory(imgSaveSanPham + foldername); img.Crop(400, 400); img.Save(imgSaveSanPham + foldername + "/" + imgten + "400x400" + img.Ext); img.Crop(75, 75); img.Save(imgSaveSanPham + foldername + "/" + imgten + img.Ext); Files item = new Files(); item.Download = 0; item.MimeType = img.Ext; item.NgayTao = DateTime.Now; item.NguoiTao = Security.Username; item.Path = imgten + img.Ext; item.PID = new Guid(_PRowIdSP); item.RowId = Guid.NewGuid(); item.Size = context.Request.Files[0].ContentLength; item.Ten = imgten; item.ThuMuc = foldername; item.VB_ID = 0; item = FilesDal.Insert(item); rendertext(sb.AppendFormat("({0})", JavaScriptConvert.SerializeObject(item))); } break; #endregion case "loadPlugDirect": if (!string.IsNullOrEmpty(rqPlug)) { string _IPlugType = rqPlug; Type type = Type.GetType(_IPlugType); IPlug _IPlug = (IPlug)(Activator.CreateInstance(type)); _IPlug.ImportPlugin(); UserControl uc = (UserControl)(_IPlug); Page page = new Page(); page.EnableViewState = false; HtmlForm form = new HtmlForm(); form.ID = "__t"; page.Controls.Add(form); form.Controls.Add(uc); StringWriter tw = new StringWriter(); HttpContext.Current.Server.Execute(page, tw, true); } break; case "capcha": #region capcha string _capchaCode = CaptchaImage.GenerateRandomCode(CaptchaType.AlphaNumeric, 3); context.Session["capcha"] = _capchaCode; CaptchaImage c = new CaptchaImage(_capchaCode, 200, 50, "Tahoma", Color.White, Color.Orange); context.Response.ClearContent(); context.Response.ContentType = "image/jpeg"; MemoryStream ms = new MemoryStream(); c.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); context.Response.OutputStream.Write(ms.ToArray(), 0, Convert.ToInt32(ms.Length)); ms.Close(); context.Response.End(); break; #endregion default: #region macdinh context.Response.Write(DateTime.Now.ToString("hh:mm")); break; #endregion } }
public RegularTin(string url, string uploadDir, List<ImageSize> images) { var host = new Uri(url).Host.ToLower(); var doc = loadDoc(url); var list = QuyTacDal.SelectByHost(host).ToList(); WrapperClean(host, url, doc); #region Lấy Ten,Mota, Noi Dung foreach (var item in list) { var c = doc.DocumentNode.SelectSingleNode(@item.Xpath); switch (item.Loai) { case 0:// renew doc if (c != null) { doc = new HtmlAgilityPack.HtmlDocument(); doc.LoadHtml(c.InnerHtml); } break; case 1:// Title if (c != null) { Ten = c.InnerText; } else { c = doc.DocumentNode.SelectNodes(@"//title | //TITLE")[0]; if (c != null) { Ten = c.InnerText; } } break; case 2: if (c != null) { MoTa = c.InnerHtml; } else { c = doc.DocumentNode.SelectNodes(@"//meta[@name='description'] | //meta[@name='DESCRIPTION'] | //meta[@name='Description']")[0]; if (c != null) { MoTa = c.InnerText; } } break; case 3: if (item.Xoa) { if (c != null) { c.ParentNode.RemoveChild(c, false); } } else { if (c != null) { NoiDung = c.InnerHtml; } } break; default: break; } } #endregion #region Images if (string.IsNullOrEmpty(NoiDung)) return; var doc1 = new HtmlAgilityPack.HtmlDocument(); doc1.LoadHtml(NoiDung); #region Keywords using (var linkKeyword = new LinkKeyword(doc1.DocumentNode.InnerText)) { if (linkKeyword.ListKeyWord != null) { KeyWords = linkKeyword.ListKeyWord; } } #endregion var domain = "http://" + host; var saveLocation = HostingEnvironment.MapPath("~/lib/up/"); List<string> _list = new List<string>(); if (doc1.DocumentNode.SelectNodes("//img | //IMG") != null) { foreach (var img in doc1.DocumentNode.SelectNodes("//img | //IMG")) { if (img.Attributes["src"] != null) { string src = img.Attributes["src"].Value; if (src.ToLower().IndexOf("http://", System.StringComparison.Ordinal) != 0) { if (src.IndexOf("/", System.StringComparison.Ordinal) != 0) src = "/" + src; src = domain + src; } try { var gimg = new ImageProcess(new Uri(src), src); if (gimg.Width > 250 && gimg.Heigth > 200) { var imgTen = Guid.NewGuid().ToString().Replace("-", ""); foreach (var imageSize in images) { gimg.Crop(imageSize.Width, imageSize.Height); gimg.Save(Path.Combine(uploadDir, string.Format("{0}{1}.{2}", imgTen, imageSize.DefaultImage ? "" : string.Format("{0}x{1}", imageSize.Width, imageSize.Height), gimg.Ext))); } break; } } catch (Exception ex) { } } } if (_list.Count == 0) return; Anh = _list[0]; } #endregion }
protected void Page_Load(object sender, EventArgs e) { StringBuilder sb = new StringBuilder(); string imgSaveLoc = Server.MapPath("~/lib/up/i/"); string imgSaveTintuc = Server.MapPath("~/lib/up/tintuc/"); string imgTemp = Server.MapPath("~/lib/up/temp/"); string docTemp = Server.MapPath("~/lib/up/d/"); bool loggedIn = Security.IsAuthenticated(); insertLog("0", Security.Username, Request.UserHostAddress, Request.Url.PathAndQuery); switch (act) { case "loadPlug": if (rqPlug != null) { sb.Append(PlugHelper.RenderHtml(rqPlug)); } rendertext(sb); break; case "upload": #region upload ảnh if (Security.IsAuthenticated()) { if (Request.Files[0] != null) { string imgten = Guid.NewGuid().ToString(); if (!string.IsNullOrEmpty(Request["oldFile"])) { try { imgten = Path.GetFileNameWithoutExtension(Request["oldFile"]); if (File.Exists(imgSaveLoc + Request["oldFile"])) { File.Delete(imgSaveLoc + Request["oldFile"]); } } finally { } } ImageProcess img = new ImageProcess(Request.Files[0].InputStream, Guid.NewGuid().ToString()); img.Crop(730, 600); img.Save(imgSaveLoc + imgten + "730x600" + img.Ext); img.Crop(420, 280); img.Save(imgSaveLoc + imgten + "420x280" + img.Ext); img.Crop(130, 100); img.Save(imgSaveLoc + imgten + img.Ext); rendertext(imgten + img.Ext); } } break; #endregion case "uploadTintuc": #region upload ảnh if (Security.IsAuthenticated()) { if (Request.Files[0] != null) { string imgten = Guid.NewGuid().ToString(); if (!string.IsNullOrEmpty(Request["oldFile"])) { try { imgten = Path.GetFileNameWithoutExtension(Request["oldFile"]); if (File.Exists(imgSaveLoc + Request["oldFile"])) { File.Delete(imgSaveLoc + Request["oldFile"]); } } finally { } } ImageProcess img = new ImageProcess(Request.Files[0].InputStream, Guid.NewGuid().ToString()); img.Crop(730, 600); img.Save(imgSaveTintuc + imgten + "730x600" + img.Ext); img.Crop(420, 280); img.Save(imgSaveTintuc + imgten + "420x280" + img.Ext); img.Crop(130, 100); img.Save(imgSaveTintuc + imgten + img.Ext); rendertext(imgten + img.Ext); } } break; #endregion case "uploadFull": #region upload ảnh if (Security.IsAuthenticated()) { if (Request.Files[0] != null) { string imgten = Guid.NewGuid().ToString(); if (!string.IsNullOrEmpty(Request["oldFile"])) { try { imgten = Path.GetFileNameWithoutExtension(Request["oldFile"]); if (File.Exists(imgSaveLoc + Request["oldFile"])) { File.Delete(imgSaveLoc + Request["oldFile"]); } } finally { } } ImageProcess img = new ImageProcess(Request.Files[0].InputStream, Guid.NewGuid().ToString()); img.Save(imgSaveLoc + imgten + img.Ext); rendertext(imgten + img.Ext); } } break; #endregion case "uploadfileDkLuong": #region upload tài liệu if (!loggedIn) rendertext("403"); if (Request.Files[0] != null) { string foldername = Guid.NewGuid().ToString().Replace("-", ""); string filename = Path.GetFileNameWithoutExtension(Request.Files[0].FileName); string fileType = Path.GetExtension(Request.Files[0].FileName); Directory.CreateDirectory(docTemp + foldername); Request.Files[0].SaveAs(docTemp + foldername + "/" + filename + fileType); Files item = new Files(); item.Download = 0; item.MimeType = fileType; item.NgayTao = DateTime.Now; item.NguoiTao = Security.Username; item.Path = filename; item.PID = Guid.NewGuid(); item.RowId = Guid.NewGuid(); item.Size = Request.Files[0].ContentLength; item.Ten = filename; item.ThuMuc = foldername; item.VB_ID = 0; item = FilesDal.Insert(item); rendertext(item.ID.ToString()); } break; #endregion case "download": string _F_ID = Request["ID"]; if (!string.IsNullOrEmpty(_F_ID)) { Files item = FilesDal.SelectById(Convert.ToInt32(_F_ID)); Response.Buffer = true; Response.Clear(); Response.AddHeader("content-disposition", "attachment; filename=\"" + item.Ten + item.MimeType + "\""); Response.ContentType = "octet/stream"; //Response.ContentType = "application/ms-word"; Response.WriteFile(Server.MapPath("~/lib/up/d/") + item.ThuMuc + "/" + item.Path + item.MimeType); } break; case "loadPlugDirect": if (!string.IsNullOrEmpty(rqPlug)) { string _IPlugType = rqPlug; Type type = Type.GetType(_IPlugType); IPlug _IPlug = (IPlug)(Activator.CreateInstance(type)); _IPlug.ImportPlugin(); Page pageHolder = new Page(); UserControl uc = (UserControl)(_IPlug); this.Controls.Add(uc); } break; case "uploadvideo": break; default: string d = "12/9/2010"; //DateTime da = Convert.ToDateTime(d, new System.Globalization.CultureInfo("vi-Vn")); //Response.Write(da.Month.ToString()); Response.Write(maHoa.EncryptString("111", "phatcd")); break; } }
protected void Page_Load(object sender, EventArgs e) { StringBuilder sb = new StringBuilder(); string imgSaveLoc = Server.MapPath("~/lib/up/i/"); string imgSaveTintuc = Server.MapPath("~/lib/up/tintuc/"); string imgTemp = Server.MapPath("~/lib/up/temp/"); string docTemp = Server.MapPath("~/lib/up/d/"); bool loggedIn = Security.IsAuthenticated(); insertLog("0", Security.Username, Request.UserHostAddress, Request.Url.PathAndQuery); switch (act) { case "loadPlug": if (rqPlug != null) { sb.Append(PlugHelper.RenderHtml(rqPlug)); } rendertext(sb); break; case "loadPlugContent": if (rqPlug != null) { Type type = Type.GetType(rqPlug); IPlug plug = (IPlug)Activator.CreateInstance(type); plug.ImportPlugin(); using (SqlConnection con = linh.core.dal.DAL.con()) { plug.KhoiTao(con); rendertext(plug.Html); } } rendertext(sb); break; case "upload": #region upload ảnh if (Security.IsAuthenticated()) { if (Request.Files[0] != null) { string imgten = Guid.NewGuid().ToString(); if (!string.IsNullOrEmpty(Request["oldFile"])) { try { imgten = Path.GetFileNameWithoutExtension(Request["oldFile"]); if (File.Exists(imgSaveLoc + Request["oldFile"])) { File.Delete(imgSaveLoc + Request["oldFile"]); } } finally { } } ImageProcess img = new ImageProcess(Request.Files[0].InputStream, Guid.NewGuid().ToString()); img.Crop(730, 600); img.Save(imgSaveLoc + imgten + "730x600" + img.Ext); img.Crop(420, 280); img.Save(imgSaveLoc + imgten + "420x280" + img.Ext); img.Crop(130, 100); img.Save(imgSaveLoc + imgten + img.Ext); rendertext(imgten + img.Ext); } } break; #endregion case "uploadTintuc": #region upload ảnh if (Security.IsAuthenticated()) { if (Request.Files[0] != null) { string imgten = Guid.NewGuid().ToString(); if (!string.IsNullOrEmpty(Request["oldFile"])) { try { imgten = Path.GetFileNameWithoutExtension(Request["oldFile"]); if (File.Exists(imgSaveLoc + Request["oldFile"])) { File.Delete(imgSaveLoc + Request["oldFile"]); } } finally { } } ImageProcess img = new ImageProcess(Request.Files[0].InputStream, Guid.NewGuid().ToString()); img.Crop(730, 600); img.Save(imgSaveTintuc + imgten + "730x600" + img.Ext); img.Crop(420, 280); img.Save(imgSaveTintuc + imgten + "420x280" + img.Ext); img.Crop(130, 100); img.Save(imgSaveTintuc + imgten + img.Ext); rendertext(imgten + img.Ext); } } break; #endregion case "uploadFull": #region upload ảnh if (Security.IsAuthenticated()) { if (Request.Files[0] != null) { string imgten = Guid.NewGuid().ToString(); if (!string.IsNullOrEmpty(Request["oldFile"])) { try { imgten = Path.GetFileNameWithoutExtension(Request["oldFile"]); if (File.Exists(imgSaveLoc + Request["oldFile"])) { File.Delete(imgSaveLoc + Request["oldFile"]); } } finally { } } ImageProcess img = new ImageProcess(Request.Files[0].InputStream, Guid.NewGuid().ToString()); img.Save(imgSaveLoc + imgten + img.Ext); rendertext(imgten + img.Ext); } } break; #endregion case "loadPlugDirect": if (!string.IsNullOrEmpty(rqPlug)) { string _IPlugType = rqPlug; Type type = Type.GetType(_IPlugType); IPlug _IPlug = (IPlug)(Activator.CreateInstance(type)); _IPlug.ImportPlugin(); Page pageHolder = new Page(); UserControl uc = (UserControl)(_IPlug); this.Controls.Add(uc); } break; default: string d = "12/9/2010"; //DateTime da = Convert.ToDateTime(d, new System.Globalization.CultureInfo("vi-Vn")); //Response.Write(da.Month.ToString()); Response.Write(maHoa.EncryptString("111", "phatcd")); break; } }
public RegularTin(string url, string uploadDir) { string _host = string.Empty; _host = new Uri(url).Host.ToLower(); HtmlAgilityPack.HtmlDocument doc = loadDoc(url); List<QuyTac> List = QuyTacDal.SelectByHost(_host).ToList(); WrapperClean(_host, url, doc); #region Lấy Ten,Mota, Noi Dung foreach (QuyTac item in List) { HtmlNode _c = doc.DocumentNode.SelectSingleNode(@item.Xpath); switch (item.Loai) { case 0:// renew doc if (_c != null) { doc = new HtmlAgilityPack.HtmlDocument(); doc.LoadHtml(_c.InnerHtml); } break; case 1:// Title if (_c != null) { Ten = _c.InnerText; } else { _c = doc.DocumentNode.SelectNodes(@"//title | //TITLE")[0]; if (_c != null) { Ten = _c.InnerText; } } break; case 2: if (_c != null) { MoTa = _c.InnerHtml; } else { _c = doc.DocumentNode.SelectNodes(@"//meta[@name='description'] | //meta[@name='DESCRIPTION'] | //meta[@name='Description']")[0]; if (_c != null) { MoTa = _c.InnerText; } } break; case 3: if (item.Xoa) { if (_c != null) { _c.ParentNode.RemoveChild(_c, false); } } else { if (_c != null) { NoiDung = _c.InnerHtml; } } break; default: break; } } #endregion #region Images if (!string.IsNullOrEmpty(NoiDung)) { HtmlAgilityPack.HtmlDocument _doc1 = new HtmlAgilityPack.HtmlDocument(); _doc1.LoadHtml(NoiDung); #region Keywords using (LinkKeyword _linkKeyword = new LinkKeyword(_doc1.DocumentNode.InnerText)) { if (_linkKeyword.ListKeyWord != null) { KeyWords = _linkKeyword.ListKeyWord; } } #endregion string domain = "http://" + _host; string saveLocation = HostingEnvironment.MapPath("~/lib/up/"); //string uploadDir = @"D:\Work\linh\ktt_x1\web\lib\up\rss\"; //string uploadDir = @"C:\inetpub\wwwroot\kttvn\web\lib\up\rss\"; if (_doc1.DocumentNode.SelectNodes("//img | //IMG") != null) { List<string> _list = new List<string>(); foreach (HtmlNode _img in _doc1.DocumentNode.SelectNodes("//img | //IMG")) { if (_img.Attributes["src"] != null) { string src = _img.Attributes["src"].Value; if (src.ToLower().IndexOf("http://") != 0) { if (src.IndexOf("/") != 0) src = "/" + src; src = domain + src; } try { ImageProcess gimg = new ImageProcess(new Uri(src), src); if (gimg.Width > 250 && gimg.Heigth > 200) { var gimg_t = Guid.NewGuid().ToString().Replace("-", ""); var gimg_ten = gimg_t + gimg.Ext; _list.Add(gimg_ten); gimg_ten = gimg_t + "420x290" + gimg.Ext; gimg.Crop(420, 300); saveLocation = Path.Combine(uploadDir, gimg_ten); gimg.Save(saveLocation); _list.Add(gimg_ten); gimg_ten = gimg_t + "150x160" + gimg.Ext; gimg.Crop(150, 160); saveLocation = Path.Combine(uploadDir, gimg_ten); gimg.Save(saveLocation); _list.Add(gimg_ten); gimg_ten = gimg_t + "105x70" + gimg.Ext; gimg.Crop(105, 70); saveLocation = Path.Combine(uploadDir, gimg_ten); gimg.Save(saveLocation); _list.Add(gimg_ten); gimg_ten = gimg_t + "100x100" + gimg.Ext; gimg.Crop(100, 100); saveLocation = Path.Combine(uploadDir, gimg_ten); gimg.Save(saveLocation); _list.Add(gimg_ten); gimg_ten = gimg_t + "50x50" + gimg.Ext; gimg.Crop(50, 50); saveLocation = Path.Combine(uploadDir, gimg_ten); gimg.Save(saveLocation); _list.Add(gimg_ten); break; } } catch (Exception ex) { } } } if (_list.Count == 0) return; Anh = _list[0]; } } #endregion }
public LinkGrap(string link, bool extractLink, bool isRss, string _title, string _mota, string _detail) { #region xử lý Link HttpWebRequest wrq; if (link.IndexOf("http://222.255.31.205/") == 0) link = link.Substring("http://222.255.31.205/".Length); wrq = (HttpWebRequest)(WebRequest.Create(link)); string host = new Uri(link).Host; wrq.Credentials = CredentialCache.DefaultCredentials; wrq.Method = "GET"; wrq.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; vi; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3"; wrq.SendChunked = true; if (link.IndexOf("zing.vn") != -1) { wrq.Referer = "http://mp3.zing.vn"; } HttpWebResponse wrp = (HttpWebResponse)wrq.GetResponse(); HtmlDocument doc = new HtmlDocument(); contentType = wrp.ContentType; try { if (contentType.ToLower().IndexOf("html") != -1) { doc.Load(wrp.GetResponseStream(), Encoding.UTF8); string domain = "http://" + (new Uri(link)).Host; #region Title HtmlNode titleNodes = doc.DocumentNode.SelectSingleNode("//*[@" + _title + "]"); ///if (doc.DocumentNode.SelectNodes(@"//class='title_bai'")!=null) //if (doc.DocumentNode.SelectNodes("//title | //TITLE") != null) { // HtmlNode titleNode = doc.DocumentNode.SelectSingleNode(@"//class='title_bai'");//doc.DocumentNode.SelectNodes("//title | //TITLE")[0]; Title = titleNodes.InnerText; // Title = doc.DocumentNode.SelectSingleNode("//div[@class='newTitle']").InnerHtml; } #endregion #region Desc //if (doc.documentnode.selectnodes("//meta[@name='description'] | //meta[@name='description']") != null) //{ // htmlnode titlenode = doc.documentnode.selectnodes("//meta[@name='description'] | //meta[@name='description']")[0]; // if (titlenode.attributes["content"] != null) // { // description = titlenode.attributes["content"].value; // } //} //Content = ""; //Description = ""; HtmlNode titleNodett = doc.DocumentNode.SelectSingleNode("//*[@" + _mota + "]"); Description = titleNodett.InnerHtml; // HtmlNode titleNode = doc.DocumentNode.SelectSingleNode("//*[@" + _detail + "]"); // Content = titleNode.InnerHtml; #endregion #region Content // ContentRawHtml = doc.DocumentNode.InnerHtml; // ContentRawText = doc.DocumentNode.InnerText; //string _anh = string.Empty; //foreach (HtmlNode _img in doc.DocumentNode.SelectNodes("//img | //IMG")) //{ // if (_img.Attributes["src"] != null) // { // string src = _img.Attributes["src"].Value; // if (src.ToLower().IndexOf("http://") != 0) // { // if (src.IndexOf("/") != 0) src = "/" + src; // src = domain + src; // } // ImageProcess gimg = new ImageProcess(new Uri(src), src); // if (gimg.Width > 200 && gimg.Heigth > 120) // { // string newsrc = Guid.NewGuid().ToString() + gimg.Ext; // // string saveLocation = Path.Combine(@"C:\inetpub\wwwroot\choNongNghiep\web\lib\up\rss", newsrc); // string saveLocation = Path.Combine(@"C:\inetpub\wwwroot\images", newsrc); // gimg.Save(saveLocation); // _img.Attributes["src"].Value = "http://www.agromart.com.vn/Upload/images/" + newsrc; // _anh = newsrc; // break; // } // } //} //Images.Add(_anh);// = _anh; // Content = Wrapper(host, link, doc); #endregion HtmlNode _c = doc.DocumentNode.SelectSingleNode("//*[@" + _detail + "]"); // MatchCollection m1 = Regex.Matches(Content, @"(<img([^>]+)>)", RegexOptions.Singleline); Regex reImg = new Regex(@"<img\s[^>]*>", RegexOptions.IgnoreCase); List<string> imgScrs = new List<string>(); MatchCollection mc = reImg.Matches(_c.InnerHtml); Regex reSrc = new Regex(@"src=(?:(['""])(?<src>(?:(?!\1).)*)\1|(?<src>\S+))", RegexOptions.IgnoreCase | RegexOptions.Singleline); foreach (Match mImg in mc) { // if (reHeight.IsMatch(HTML)) { Match mSrc = reSrc.Match(_c.InnerHtml); // Console.WriteLine(" src is: {0}", mSrc.Groups["src"].Value); string src = mSrc.Groups["src"].Value; // Title = src; if (src.ToLower().IndexOf("http://") != 0) { string saveLocation = string.Empty; if (src.IndexOf("/") != 0) src = "/" + src; src = domain + src; ImageProcess gimg = new ImageProcess(new Uri(src), src); string gimg_t = Guid.NewGuid().ToString().Replace("-", ""); string gimg_ten = gimg_t + gimg.Ext; saveLocation = Path.Combine(@"C:\inetpub\wwwroot\choNongNghiep\web\lib\up\tintuc\rss", gimg_ten); // saveLocation = Path.Combine(@"C:\inetpub\wwwroot\PM\Upload\images", gimg_ten); gimg.Save(saveLocation); string gimg_ten_400 = gimg_t + "400x400" + gimg.Ext; gimg.Resize(400); saveLocation = Path.Combine(@"C:\inetpub\wwwroot\choNongNghiep\web\lib\up\tintuc\rss", gimg_ten_400); gimg.Save(saveLocation); string gimg_ten_100 = gimg_t + "100x100" + gimg.Ext; gimg.Crop(100, 100); saveLocation = Path.Combine(@"C:\inetpub\wwwroot\choNongNghiep\web\lib\up\tintuc\rss", gimg_ten_100); gimg.Save(saveLocation); imgScrs.Add(gimg_ten); // Title = _c.InnerHtml; } else { string saveLocation = string.Empty; // if (src.IndexOf("/") != 0) src = "/" + src; // src = domain + src; ImageProcess gimg = new ImageProcess(new Uri(src), src); string gimg_t = Guid.NewGuid().ToString().Replace("-", ""); string gimg_ten = gimg_t + gimg.Ext; //saveLocation = Path.Combine(@"C:\inetpub\wwwroot\choNongNghiep\web\lib\up\tintuc\rss", gimg_ten); saveLocation = Path.Combine(@"C:\inetpub\wwwroot\choNongNghiep\web\lib\up\tintuc\rss", gimg_ten); gimg.Save(saveLocation); string gimg_ten_400 = gimg_t + "400x400" + gimg.Ext; gimg.Resize(400); saveLocation = Path.Combine(@"C:\inetpub\wwwroot\choNongNghiep\web\lib\up\tintuc\rss", gimg_ten_400); gimg.Save(saveLocation); string gimg_ten_100 = gimg_t + "100x100" + gimg.Ext; gimg.Crop(100, 100); saveLocation = Path.Combine(@"C:\inetpub\wwwroot\choNongNghiep\web\lib\up\tintuc\rss", gimg_ten_100); gimg.Save(saveLocation); imgScrs.Add(gimg_ten); // Regex reImg = new Regex(@"<img\s[^>]*>", RegexOptions.IgnoreCase); // List<string> imgScrs = new List<string>(); // MatchCollection mc = reImg.Matches(_content); // Regex reSrc = new Regex(@"src=(?:(['""])(?<src>(?:(?!\1).)*)\1|(?<src>\S+))", RegexOptions.IgnoreCase | RegexOptions.Singleline); /* foreach (Match mImg1 in mc) { // if (reHeight.IsMatch(HTML)) { Match mSrc1 = reSrc.Match(_c.InnerHtml); // Console.WriteLine(" src is: {0}", mSrc.Groups["src"].Value); string src1 = mSrc1.Groups["src"].Value; if (src.ToLower().IndexOf("http://") != 0) { string pattern = @"src=['](?!http[:]//.*)([^']*)[']"; _c.InnerHtml = Regex.Replace(_c.InnerHtml, pattern, "src='" + host.ToLower() + src1 + "'"); } } } */ } } } Images = imgScrs; Content = WrapperNormal(host, _detail, link, doc); // Content = WrapperNormal(host, _detail, link, doc); // 2. // Loop over each match. //foreach (Match m in m1) //{ // string value = m.Groups[1].Value; // // LinkItem i = new LinkItem(); // // 3. // // Get href attribute. // Match m2 = Regex.Match(value, @"src=\""(.*?)\""", // RegexOptions.Singleline); // if (m2.Success) // { // string src = m2.Groups[1].Value; // if (src.ToLower().IndexOf("http://") != 0) // { // if (src.IndexOf("/") != 0) src = "/" + src; // src = domain + src; // ImageProcess gimg = new ImageProcess(new Uri(src), src); // string gimg_t = Guid.NewGuid().ToString().Replace("-", ""); // string gimg_ten = gimg_t + gimg.Ext; // imgScrs.Add(gimg_ten); // // Title = src; // } // // item.Link = String.Format(hosting, m2.Groups[1].Value); // break; // } // // 4. // // Remove inner tags from text. // //string t = Regex.Replace(value, @"\s*<.*?>\s*", "", // //RegexOptions.Singleline); // //i.Text = t; // //list.Add(i); //} /* List<string> imgScrs = new List<string>(); HtmlDocument docs = new HtmlDocument(); docs.LoadHtml(doc.DocumentNode.SelectSingleNode("//*[@" + _detail + "]").InnerHtml);//or doc.Load(htmlFileStream) var nodes = docs.DocumentNode.SelectNodes(@"//img[@src]"); // Title = doc.DocumentNode.SelectSingleNode("//*[@class='detail']").InnerHtml; foreach (var imgs in nodes) { HtmlAttribute att = imgs.Attributes["src"]; //imgScrs.Add(att.Value); if (att != null) { string src = att.Value; if (src.ToLower().IndexOf("http://") != 0) { if (src.IndexOf("/") != 0) src = "/" + src; src = domain + src; // Title = src; } ImageProcess gimg = new ImageProcess(new Uri(src), src); if (gimg.Width > 150 && gimg.Heigth > 100) { string saveLocation = string.Empty; string gimg_t = Guid.NewGuid().ToString().Replace("-", ""); string gimg_ten = gimg_t + gimg.Ext; // saveLocation = Path.Combine(@"C:\inetpub\wwwroot\choNongNghiep\web\lib\up\tintuc\rss", gimg_ten); saveLocation = Path.Combine(@"C:\inetpub\wwwroot\PM\Upload\images", gimg_ten); gimg.Save(saveLocation); string gimg_ten_400 = gimg_t + "400x400" + gimg.Ext; gimg.Resize(400); saveLocation = Path.Combine(@"C:\inetpub\wwwroot\PM\Upload\images", gimg_ten_400); gimg.Save(saveLocation); string gimg_ten_100 = gimg_t + "100x100" + gimg.Ext; gimg.Crop(100, 100); saveLocation = Path.Combine(@"C:\inetpub\wwwroot\PM\Upload\images", gimg_ten_100); gimg.Save(saveLocation); imgScrs.Add(gimg_ten); break; } } } Images = imgScrs;*/ //#region Images //if (!string.IsNullOrEmpty(Content)) //{ // doc = new HtmlDocument(); // doc.LoadHtml(Content); // //if (doc.DocumentNode.SelectNodes("//img | //IMG") != null) // // _n1.SelectNodes(".//table"); // if (doc.DocumentNode.SelectNodes(".//img") != null) // { // List<string> _list = new List<string>(); // foreach (HtmlNode _img in doc.DocumentNode.SelectNodes(".//img")) // { // if (_img.Attributes["src"] != null) // { // string src = _img.Attributes["src"].Value; // if (src.ToLower().IndexOf("http://") != 0) // { // if (src.IndexOf("/") != 0) src = "/" + src; // src = domain + src; // } // ImageProcess gimg = new ImageProcess(new Uri(src), src); // if (gimg.Width > 150 && gimg.Heigth > 100) // { // string saveLocation = string.Empty; // string gimg_t = Guid.NewGuid().ToString().Replace("-", ""); // string gimg_ten = gimg_t + gimg.Ext; // saveLocation = Path.Combine(@"C:\inetpub\wwwroot\choNongNghiep\web\lib\up\rss", gimg_ten); // gimg.Save(saveLocation); // string gimg_ten_400 = gimg_t + "400" + gimg.Ext; // gimg.Resize(400); // saveLocation = Path.Combine(@"C:\inetpub\wwwroot\choNongNghiep\web\lib\up\rss", gimg_ten_400); // gimg.Save(saveLocation); // string gimg_ten_100 = gimg_t + "100" + gimg.Ext; // gimg.Crop(100, 100); // saveLocation = Path.Combine(@"C:\inetpub\wwwroot\PM\agromart\images", gimg_ten_100); // gimg.Save(saveLocation); // _list.Add(gimg_ten); // break; // } // } // } // Images = _list; // } //} //#endregion } else { if (contentType.ToLower().IndexOf("xml") != -1) { } } } catch (WebException ex) { } #endregion // Title = Description; }
protected void Page_Load(object sender, EventArgs e) { var logged = Security.IsAuthenticated(); var dic = Server.MapPath("~/lib/up/users/"); var Ten = Request["Ten"]; var MoTa = Request["MoTa"]; var Mobile = Request["Mobile"]; var Tinh_ID = Request["Tinh_ID"]; var Alias = Request["Alias"]; var rowId = Request["RowId"]; switch (subAct) { case "changeAvatar": #region change avatar if(logged) { if(Request.Files.Count > 0) { var img = new ImageProcess(Request.Files[0].InputStream, Guid.NewGuid().ToString()); if(img.Width > img.Heigth) { img.ResizeHeight(180); } else { img.Resize(180); } img.Crop(180, 180); var user = MemberDal.SelectByUser(Security.Username); var anh = dic + user.Anh; if(!string.IsNullOrEmpty(anh)) { if(File.Exists(anh)) File.Delete(anh); } var anhNew = string.Format("{0}{1}", user.Id, img.Ext); img.Save(dic + anhNew); MemberDal.UpdateAnh(Security.Username,anhNew); rendertext(anhNew); } } rendertext("0"); break; #endregion case "validateAlias": #region validate object alias if (logged && !string.IsNullOrEmpty(rowId) && !string.IsNullOrEmpty(Alias)) { var RowId = new Guid(rowId); var obj = ObjDal.SelectByAlias(Alias); if(obj.Id == Guid.Empty) { rendertext("1"); } else { if (obj.RowId == RowId) { rendertext("1"); } else { rendertext("0"); } } rendertext("0"); } rendertext("0"); break; #endregion case "saveAlias": #region validate object alias if (logged && !string.IsNullOrEmpty(rowId) && !string.IsNullOrEmpty(Alias)) { var RowId = new Guid(rowId); var obj = ObjDal.SelectByAlias(Alias); if (obj.Id == Guid.Empty) { obj = ObjDal.SelectByRowId(RowId); obj.Alias = Alias; ObjDal.Update(obj); rendertext("1"); } else { if (obj.RowId == RowId) { rendertext("1"); } else { rendertext("0"); } } rendertext("0"); } rendertext("0"); break; #endregion case "GetVcard": #region change avatar vcard.Visible = true; break; #endregion case "saveInformation": #region Store information if (logged && !string.IsNullOrEmpty(Ten)) { var user = MemberDal.SelectByUser(Security.Username); if(!string.IsNullOrEmpty(Tinh_ID)) { user.Tinh = new Guid(Tinh_ID); } user.Ten = Ten; user.Mota = MoTa; user.Mobile = Mobile; user.NgayCapNhat = DateTime.Now; user = MemberDal.Update(user); Security.Login(user.Username, "true"); MemberDal.UpdateVcard(DAL.con(), user.Username); rendertext("1"); } rendertext("0"); break; #endregion } }
public LinkGrap(string link, bool extractLink) { LinkGrap Item = null; string saveLocation = HostingEnvironment.MapPath("~/lib/up/"); //string uploadDir = @"D:\InetPub\tintucme\wwwroot\lib\up\"; //C:\inetpub\wwwroot\choNongNghiep\web\lib\up\rss string uploadDir = @"C:\inetpub\wwwroot\choNongNghiep\web\lib\up\tintuc\rss\"; Item = (LinkGrap)HttpRuntime.Cache[string.Format(cacheKey, link)]; Item = null; if (Item == null) { #region xử lý Link HttpWebRequest wrq; wrq = (HttpWebRequest)(WebRequest.Create(link)); string host = new Uri(link).Host; wrq.Credentials = CredentialCache.DefaultCredentials; wrq.Method = "GET"; wrq.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; vi; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3"; wrq.SendChunked = false; if (link.IndexOf("zing.vn") != -1) { wrq.Referer = "http://mp3.zing.vn"; } try { HttpWebResponse wrp = (HttpWebResponse)wrq.GetResponse(); HtmlDocument doc = new HtmlDocument(); contentType = wrp.ContentType; if (contentType.ToLower().IndexOf("html") != -1) { doc.Load(wrp.GetResponseStream(), Encoding.UTF8); string domain = "http://" + (new Uri(link)).Host; #region Title if (doc.DocumentNode.SelectNodes("//title | //TITLE") != null) { HtmlNode titleNode = doc.DocumentNode.SelectNodes("//title | //TITLE")[0]; Title = titleNode.InnerText; } #endregion #region Desc if (doc.DocumentNode.SelectNodes("//meta[@name='description'] | //meta[@name='DESCRIPTION']") != null) { HtmlNode titleNode = doc.DocumentNode.SelectNodes("//meta[@name='description'] | //meta[@name='DESCRIPTION']")[0]; Description = titleNode.Attributes["content"].Value; } #endregion #region Content ContentRawHtml = doc.DocumentNode.InnerHtml; ContentRawText = doc.DocumentNode.InnerText; Content = Wrapper(host, link, doc); if (string.IsNullOrEmpty(Content)) return; string contentTokeyword = Giga.Common.Lib._string.getHTML(Content); if (!string.IsNullOrEmpty(contentTokeyword)) { using (LinkKeyword _linkKeyword = new LinkKeyword(contentTokeyword)) { if (_linkKeyword.ListKeyWord != null) { KeyWords = _linkKeyword.ListKeyWord; } } } //if (string.IsNullOrEmpty(contentTokeyword)) contentTokeyword = ContentRawText; //List<LinkKeyword> _ListKeyword = new List<LinkKeyword>(); #endregion #region Images HtmlDocument _doc1 = new HtmlDocument(); _doc1.LoadHtml(Content); if (_doc1.DocumentNode.SelectNodes("//img | //IMG") != null) { List<string> _list = new List<string>(); foreach (HtmlNode _img in _doc1.DocumentNode.SelectNodes("//img | //IMG")) { if (_img.Attributes["src"] != null) { string src = _img.Attributes["src"].Value; if (src.ToLower().IndexOf("http://") != 0) { if (src.IndexOf("/") != 0) src = "/" + src; src = domain + src; } try { ImageProcess gimg = new ImageProcess(new Uri(src), src); if (gimg.Width > 250 && gimg.Heigth > 200) { #region ảnh cũ //string _newid = Guid.NewGuid().ToString(); //string _ten = saveLocation + _newid; //gimg.Save(_ten + gimg.Ext); //gimg.Crop(320, 188); //gimg.Save(_ten + "320x188" + gimg.Ext); //gimg.Crop(150, 160); //gimg.Save(_ten + "150x160" + gimg.Ext); //gimg.Crop(101, 58); //gimg.Save(_ten + "101x58" + gimg.Ext); //gimg.Crop(62, 36); //gimg.Save(_ten + "62x36" + gimg.Ext); //_list.Add(_newid + gimg.Ext); //HttpRuntime.Cache.Remove(src); #endregion string gimg_t = Guid.NewGuid().ToString().Replace("-", ""); string gimg_ten = gimg_t + gimg.Ext; //saveLocation = Path.Combine(uploadDir, gimg_ten); //gimg.Save(saveLocation); _list.Add(gimg_ten); string gimg_ten_430x300 = gimg_t + "430x300" + gimg.Ext; gimg.Crop(430, 300); saveLocation = Path.Combine(uploadDir, gimg_ten_430x300); gimg.Save(saveLocation); _list.Add(gimg_ten_430x300); //string gimg_ten_100 = gimg_t + "200x150" + gimg.Ext; //gimg.Crop(200, 150); //saveLocation = Path.Combine(uploadDir, gimg_ten_100); //gimg.Save(saveLocation); //_list.Add(gimg_ten_100); string gimg_ten_101_58 = gimg_t + "100x100" + gimg.Ext; gimg.Crop(100, 100); saveLocation = Path.Combine(uploadDir, gimg_ten_101_58); gimg.Save(saveLocation); _list.Add(gimg_ten_101_58); string gimg_ten_62_36 = gimg_t + "50x50" + gimg.Ext; gimg.Crop(50, 50); saveLocation = Path.Combine(uploadDir, gimg_ten_62_36); gimg.Save(saveLocation); _list.Add(gimg_ten_62_36); break; } } catch (Exception ex) { } } } if (_list.Count == 0) return; Images = _list; } #endregion #region Link //List<string> _inLink = new List<string>(); //List<string> _outLink = new List<string>(); //foreach (HtmlNode a in doc.DocumentNode.SelectNodes("//a|//A")) //{ // string href = string.Empty; // if (a.Attributes["href"] != null) // { // href = a.Attributes["href"].Value; // } // else if (a.Attributes["HREF"] != null) // { // href = a.Attributes["HREF"].Value; // } // if (!string.IsNullOrEmpty(href)) // { // if (href.ToLower().IndexOf("javascrip") != 0 && href.ToLower().IndexOf("#") != 0) // { // if (href.ToLower().IndexOf("http://") == 0)//HTTPLink // { // Uri _href = new Uri(href); // if (_href.Host.ToLower().IndexOf(host.ToLower()) != -1) // { // _inLink.Add(href); // } // else // { // _outLink.Add(href); // } // } // else // { // if (href.ToLower().IndexOf("/") == -1) href = "/" + href; // if (href.ToLower().IndexOf("../") == 0) href = href.Substring(href.LastIndexOf("../") + 3); // href = "http://" + host + href; // _inLink.Add(href); // } // } // } // InLink = _inLink; // OutLink = _outLink; //} #endregion } else { if (contentType.IndexOf("image") != -1) { Title = link; Description = link; List<string> _list = new List<string>(); ImageProcess gimg = new ImageProcess(new Uri(link), link); if (gimg.Width > 100 && gimg.Heigth > 75) { _list.Add(link); } Images = _list; } } LinkGrap _obj = new LinkGrap(); _obj.Title = Title; _obj.Description = Description; _obj.Images = Images; _obj.contentType = contentType; _obj.InLink = InLink; _obj.OutLink = OutLink; _obj.contentType = Content; _obj.ContentRawText = ContentRawText; _obj.ContentRawHtml = ContentRawHtml; HttpRuntime.Cache.Insert(string.Format(cacheKey, link), _obj); Item = _obj; } catch (WebException ex) { LinkGrap _obj2 = new LinkGrap(); _obj2.Title = "0"; HttpRuntime.Cache.Remove(string.Format(cacheKey, link)); Item = _obj2; } #endregion } Title = Item.Title; Description = Item.Description; Images = Item.Images; contentType = Item.contentType; KeyWordsIEnum = Item.KeyWordsIEnum; }
public LinkGrap(string link, bool extractLink, bool isRss) { #region xử lý Link HttpWebRequest wrq; if (link.IndexOf("http://222.255.31.205/") == 0) link = link.Substring("http://222.255.31.205/".Length); wrq = (HttpWebRequest)(WebRequest.Create(link)); string host = new Uri(link).Host; wrq.Credentials = CredentialCache.DefaultCredentials; wrq.Method = "GET"; wrq.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; vi; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3"; wrq.SendChunked = true; if (link.IndexOf("zing.vn") != -1) { wrq.Referer = "http://mp3.zing.vn"; } try { HttpWebResponse wrp = (HttpWebResponse)wrq.GetResponse(); HtmlDocument doc = new HtmlDocument(); contentType = wrp.ContentType; if (contentType.ToLower().IndexOf("html") != -1) { doc.Load(wrp.GetResponseStream(), Encoding.UTF8); string domain = "http://" + (new Uri(link)).Host; #region Title if (doc.DocumentNode.SelectNodes("//title | //TITLE") != null) { HtmlNode titleNode = doc.DocumentNode.SelectNodes("//title | //TITLE")[0]; Title = titleNode.InnerText; } #endregion #region Desc if (doc.DocumentNode.SelectNodes("//meta[@name='description'] | //meta[@name='DESCRIPTION']") != null) { HtmlNode titleNode = doc.DocumentNode.SelectNodes("//meta[@name='description'] | //meta[@name='DESCRIPTION']")[0]; if (titleNode.Attributes["content"] != null) { Description = titleNode.Attributes["content"].Value; } } #endregion #region Content ContentRawHtml = doc.DocumentNode.InnerHtml; ContentRawText = doc.DocumentNode.InnerText; Content = Wrapper(host, link, doc); #endregion #region Images if (!string.IsNullOrEmpty(Content)) { doc = new HtmlDocument(); doc.LoadHtml(Content); if (doc.DocumentNode.SelectNodes("//img | //IMG") != null) { List<string> _list = new List<string>(); foreach (HtmlNode _img in doc.DocumentNode.SelectNodes("//img | //IMG")) { if (_img.Attributes["src"] != null) { string src = _img.Attributes["src"].Value; if (src.ToLower().IndexOf("http://") != 0) { if (src.IndexOf("/") != 0) src = "/" + src; src = domain + src; } ImageProcess gimg = new ImageProcess(new Uri(src), src); if (gimg.Width > 150 && gimg.Heigth > 100) { string saveLocation = string.Empty; string gimg_t = Guid.NewGuid().ToString().Replace("-", ""); string gimg_ten = gimg_t + gimg.Ext; saveLocation = Path.Combine(@"C:\inetpub\wwwroot\choNongNghiep\web\lib\up\rss", gimg_ten); gimg.Save(saveLocation); string gimg_ten_400 = gimg_t + "400" + gimg.Ext; gimg.Resize(400); saveLocation = Path.Combine(@"C:\inetpub\wwwroot\choNongNghiep\web\lib\up\rss", gimg_ten_400); gimg.Save(saveLocation); string gimg_ten_100 = gimg_t + "100" + gimg.Ext; gimg.Crop(100, 100); saveLocation = Path.Combine(@"C:\inetpub\wwwroot\choNongNghiep\web\lib\up\rss", gimg_ten_100); gimg.Save(saveLocation); _list.Add(gimg_ten); break; } } } Images = _list; } } #endregion } else { if (contentType.ToLower().IndexOf("xml") != -1) { } } } catch (WebException ex) { } #endregion }
void SaveAvatar(int id, string fbid, string dic) { var url = string.Format("http://graph.facebook.com/{0}/picture?type=large", fbid); var rq = (HttpWebRequest)(WebRequest.Create(url)); rq.UserAgent = uAgent; rq.Timeout = 20000; var rp = (HttpWebResponse)(rq.GetResponse()); var newUri = rp.ResponseUri; var img = new ImageProcess(newUri, url); img.Crop(180, 180); var ten = string.Format("{0}{1}", id, img.Ext); img.Save(dic + ten); var user = MemberDal.SelectById(id); MemberDal.UpdateAnh(user.Username, ten); }
protected override void Render(HtmlTextWriter writer) { StringBuilder sb = new StringBuilder(); ClientScriptManager cs = this.Page.ClientScript; #region Tham số string _ID = Request["ID"]; string _CQ_ID = Request["CQ_ID"]; string _Username = Request["Username"]; string _Password = Request["Password"]; string _Pwd = Request["Pwd"]; string _Ten = Request["Ten"]; string _Khoa = Request["Khoa"]; string _q = Request["q"]; string _Anh = Request["Anh"]; string _Loai = Request["Loai"]; string _ThuKy = Request["ThuKy"]; string _refUsername = Request["refUsername"]; string _Email = Request["Email"]; string _Captcha = Request["Captcha"]; string _Mobile = Request["Mobile"]; string _DiaChi = Request["DiaChi"]; string _MoTa = Request["MoTa"]; string _Loai_Ten = Request["Loai_Ten"]; string _CQ_Ma = Request["CQ_Ma"]; #endregion //if (!Security.IsAuthenticated()) //{ // Response.End(); //} switch (subAct) { case "get": #region lấy danh sách if (string.IsNullOrEmpty(jgrsidx)) jgrsidx = "ID"; if (string.IsNullOrEmpty(jgrsord)) jgrsord = "asc"; Pager<Member> PagerGet = MemberDal.pagerAllChildByUsername("", false, "MEM_" + jgrsidx + " " + jgrsord, Security.Username, _CQ_ID, _q, Request["rows"]); List<jgridRow> ListRow = new List<jgridRow>(); foreach (Member item in PagerGet.List) { ListRow.Add(new jgridRow(item.ID.ToString(), new string[]{ item.ID.ToString() ,item.Ten , item._CoQuan.Ten , item.Loai_Ten ,item.Email ,item.Mobile , item.Username ,item.Password.Length > 2 ? item.Password.Substring(0,item.Password.Length-2) : "" , item.Active.ToString() , item.NguoiTao })); } jgrid grid = new jgrid(string.IsNullOrEmpty(jgrpage) ? "1" : jgrpage, PagerGet.TotalPages.ToString(), PagerGet.Total.ToString(), ListRow); sb.Append(JavaScriptConvert.SerializeObject(grid)); break; #endregion case "getpid": #region lấy danh sách cho autocomplete Pager<Member> PagerGetPid = MemberDal.pagerAllChildByUsername("", true, null, Security.Username, null, _q,"20"); sb.Append(JavaScriptConvert.SerializeObject(PagerGetPid.List)); break; #endregion case "createFb": #region createFb if (!string.IsNullOrEmpty(_Password) && !string.IsNullOrEmpty(_Email)) { if (MemberDal.SelectByUsername(_Email).ID != 0) { sb.Append("0"); } else { var memFb = new Member(); memFb.CQ_ID = 1; memFb.Username = _Email; memFb.Ten = _Ten; if (!string.IsNullOrEmpty(_Anh)) { if (_Anh.IndexOf("http") != -1) { try { //TODO: Fix in server _Anh = getRealFacebookPicture(_ID); var imgten = Guid.NewGuid().ToString(); var img = new ImageProcess(new Uri(_Anh), imgten); string imgSaveLoc = HttpContext.Current.Server.MapPath("~/lib/up/i/"); img.Save(imgSaveLoc + imgten + "full" + img.Ext); img.Crop(100, 100); img.Save(imgSaveLoc + imgten + img.Ext); memFb.Anh = imgten + img.Ext; } finally { } } else { memFb.Anh = _Anh; } } memFb.NgayCapNhat = DateTime.Now; memFb.NgayTao = DateTime.Now; memFb.NgayXacNhan = false; memFb.XacNhan = false; memFb.RowId = Guid.NewGuid(); memFb.Email = _Email; memFb.Ho = _ID; memFb.Mobile = _Mobile; memFb.Password = maHoa.EncryptString(_Password, _Email); memFb = MemberDal.Insert(memFb); var BaseUrl = "~/lib/up/user/" + _Email + "/"; if (!Directory.Exists(Server.MapPath(BaseUrl))) { Directory.CreateDirectory(Server.MapPath(BaseUrl)); } var dele = new sendEmailSingleDelegate(sendMailSingle); var emailTemp = Lib.GetResource(Assembly.GetExecutingAssembly(), "mail-welcome.htm"); dele.BeginInvoke(_Email, "Tạp chí spa.com - Kich hoat tai khoan", string.Format(emailTemp, memFb.Ten, memFb.ID), null, null); Security.Login(_Email, _Password, "true"); sb.Append("1"); } } break; #endregion case "saveInfo": #region saveInfo var memFbs = MemberDal.SelectByUser(Security.Username); //memFb.Truong_ID = new Guid(_Truong); //memFb.Que_ID = new Guid(_Que); //memFb.Lop = _Lop; memFbs.Anh = _Anh; memFbs.Ten = _Ten; memFbs = MemberDal.Update(memFbs); sb.Append("1"); break; #endregion case "getpuse": #region lấy danh sách cho autocomplete Pager<Member> PagerGetPues = MemberDal.pagerAllByUsername("", true, null, Security.Username, null, _q, "20"); sb.Append(JavaScriptConvert.SerializeObject(PagerGetPues.List)); break; #endregion case "SelectByNodeAndWfId": #region lấy danh sách cho autocomplete string Username = Security.Username; //if (Request["WF_ID"] == "4" && string.IsNullOrEmpty(Request["NODE_ID"])) //{ // sb.Append(JavaScriptConvert.SerializeObject(MemberDal.SelectLanhDaoByCQMa("1"))); //} //else //{ // if (!string.IsNullOrEmpty(_CQ_ID)) // { // MemberCollection mem = MemberDal.SelectLanhDaoByCQMa(_CQ_ID); // foreach (Member m in mem) // { // Username = m.Username; // break; // } // } sb.Append(JavaScriptConvert.SerializeObject(MemberDal.SelectByNodeAndWfId(Request["NODE_ID"], Request["WF_ID"], _q, "20", Username))); //} break; #endregion case "del": #region xóa MemberDal.DeleteByIdList(Request["ID"]); break; #endregion case "edit": #region chỉnh sửa if (!string.IsNullOrEmpty(_ID)) { sb.Append("(" + JavaScriptConvert.SerializeObject(MemberDal.SelectById(Convert.ToInt32(_ID))) + ")"); } break; #endregion case "editUsr": #region chỉnh sửa if (Security.IsAuthenticated()) { sb.Append("(" + JavaScriptConvert.SerializeObject(MemberDal.SelectByUser(Security.Username)) + ")"); } break; #endregion case "editUsrByUser": #region chỉnh sửa if (Security.IsAuthenticated()) { sb.Append("(" + JavaScriptConvert.SerializeObject(MemberDal.SelectByUser(_Email)) + ")"); } break; #endregion case "editX": #region editX if (!string.IsNullOrEmpty(_ID)) { sb.Append(MemberDal.SelectById(Convert.ToInt32(_ID)).Loai.ToString()); } break; #endregion case "save": #region lưu Member ItemSave = new Member(); if (string.IsNullOrEmpty(_Username)) { sb.Append("0"); break; } if (!string.IsNullOrEmpty(_ID)) { ItemSave = MemberDal.SelectById(Convert.ToInt32(_ID)); } else { if (MemberDal.ValidEmailUsername(_Email, _Username) != "-1" || MemberDal.ValidEmailUsername(_Email, _Username) != (string.IsNullOrEmpty(_ID) ? "-1" : _ID)) { sb.Append("0"); break; } } ItemSave.Anh = _Anh; ItemSave.CQ_ID = Convert.ToInt32(_CQ_ID); ItemSave.DiaChi = string.Empty; ItemSave.Email = _Email; ItemSave.Ho = string.Empty; ItemSave.Khoa = Convert.ToBoolean(_Khoa); ItemSave.Loai = Convert.ToInt32(_Loai); ItemSave.Mobile = _Mobile; ItemSave.Mota = string.Empty; ItemSave.NgayCapNhat = DateTime.Now; ItemSave.NguoiTao = Security.Username; ItemSave.RefUsername = _refUsername; ItemSave.Ten = _Ten; ItemSave.Loai_Ten = _Loai_Ten; ItemSave.ThuKy = Convert.ToBoolean(_ThuKy); ItemSave.XacNhan = false; if (!string.IsNullOrEmpty(_ID)) { if (!string.IsNullOrEmpty(_Password)) { //ItemSave.Password = maHoa.EncryptString(_Password, _Username); ItemSave.Password = maHoa.MD5Encrypt(_Password); } ItemSave = MemberDal.Update(ItemSave); } else { ItemSave.NgayTao = DateTime.Now; //ItemSave.Password = maHoa.EncryptString(_Password, _Username); ItemSave.Password = maHoa.MD5Encrypt(_Password); ItemSave.RowId = Guid.NewGuid(); ItemSave.Username = _Username; ItemSave = MemberDal.Insert(ItemSave); } sb.Append("1"); break; #endregion case "sendmail": #region gửi email if (!string.IsNullOrEmpty(_Email)) { string[] _email = _Email.Split(new char[] { ',' }); sendEmailDelegate _send = new sendEmailDelegate(sendMail); //_send.BeginInvoke(_email, _Ten, _MoTa, null, null); sb.Append("1"); } else { sb.Append("0"); } break; #endregion case "getRoles": #region lấy quyền của thành viên if (!string.IsNullOrEmpty(_Username)) { sb.AppendFormat(getRoleByUsername(_Username)); } break; #endregion case "saveRoles": #region lưu quyền if (!string.IsNullOrEmpty(_Username)) { string roleList = Request["roleList"]; if (!string.IsNullOrEmpty(roleList)) { MemberRoleDal.UpdateRoleListUsername(roleList, _Username); } } break; #endregion case "SelectLanhDaoByCQID": #region lấy lãnh đạo theo cơ quan if (!string.IsNullOrEmpty(_CQ_ID)) { MemberCollection PG = MemberDal.SelectLanhDaoByCQID(_CQ_ID); sb.Append(JavaScriptConvert.SerializeObject(PG)); } break; #endregion case "SelectLanhDaoVanBanDi": #region lấy lãnh đạo theo cơ quan MemberCollection _SelectLanhDaoVanBanDi = MemberDal.SelectLanhDaoVanBanDi(); sb.Append(JavaScriptConvert.SerializeObject(_SelectLanhDaoVanBanDi)); break; #endregion case "SelectLanhDaoByMaCQ": #region tim lanh dao theo ma co quan MemberCollection _SelectLanhDaoByMaCoQuan = MemberDal.SelectLanhDaoByCQMa(_CQ_Ma); sb.Append(JavaScriptConvert.SerializeObject(_SelectLanhDaoByMaCoQuan)); break; #endregion case "ValidateEmail": #region tim lanh dao theo ma co quan if (!string.IsNullOrEmpty(_Email)) { if (MemberDal.ValidEmail(_Email)) { sb.Append("1"); } else { sb.Append("0"); } } break; #endregion case "ValidateCaptcha": #region tim lanh dao theo ma co quan if (!string.IsNullOrEmpty(_Captcha)) { if (Session["capcha"] != null) { if (Session["capcha"].ToString() == _Captcha) { sb.Append("1"); } else { sb.Append("0"); } } else { sb.Append("0"); } } else { sb.Append("0"); } break; #endregion case "cungDonVi": #region cungDonVi : Lấy thành viên cùng đơn vị sb.Append(JavaScriptConvert.SerializeObject(MemberDal.SelectCungDonVi(Security.Username))); break; #endregion case "dangKyCaNhan": #region dangKyCaNhan using (SqlConnection con = DAL.con()) { con.Open(); SqlTransaction tran = con.BeginTransaction(); try { CoQuan ItemCq = CoQuanDal.SelectByMa(tran, "RAOVAT"); //Member ItemMe = MemberDal.Insert(tran, ItemCq.ID, _Ten, _Email, _Mobile, _DiaChi, maHoa.EncryptString(_Pwd, _Email)); Member ItemMe = MemberDal.Insert(tran, ItemCq.ID, _Ten, _Email, _Mobile, _DiaChi, maHoa.MD5Encrypt(_Password)); MemberRole ItemMR = MemberRoleDal.InsertDangKyCaNhan(tran, ItemCq.ID, _Email); Security.Login(_Email, "true"); sb.Append("1"); tran.Commit(); } catch (Exception ex) { tran.Rollback(); Security.LogOut(); sb.Append(ex.ToString()); } finally { con.Close(); } } break; #endregion case "dangKyGh": #region dangKyGh using (SqlConnection con = DAL.con()) { con.Open(); SqlTransaction tran = con.BeginTransaction(); try { CoQuan ItemCqP = CoQuanDal.SelectByMa(tran, "GIANHANG"); CoQuan ItemCq = CoQuanDal.Insert(tran, ItemCqP.ID, _Ten, _Email); //Member ItemMe = MemberDal.Insert(tran, ItemCq.ID, _Ten, _Email, _Mobile, _DiaChi, maHoa.EncryptString(_Pwd, _Email)); Member ItemMe = MemberDal.Insert(tran, ItemCq.ID, _Ten, _Email, _Mobile, _DiaChi, maHoa.MD5Encrypt(_Pwd)); MemberRoleDal.InsertDangKyGianHang(tran, ItemCq.ID, _Email, _Ten); LienHe itemLH = LienHeDal.InsertLH(tran, ItemMe.RowId.ToString()); Security.Login(_Email, "true"); sb.Append("1"); tran.Commit(); } catch (Exception ex) { tran.Rollback(); Security.LogOut(); sb.Append(ex.ToString()); } finally { con.Close(); } } break; #endregion case "scpt": #region Nạp js sb.AppendFormat(@"{0}" , cs.GetWebResourceUrl(typeof(Class1), "docsoft.plugin.hethong.thanhvien.JScript1.js")); break; #endregion default://Session["capcha"] #region nạp FunctionCollection ListFn = FunctionDal.SelectByUserAndFNID(Security.Username, fnId); sb.Append(@"<div class=""mdl-head""> <span class=""mdl-head-searchPnl ui-state-default ui-corner-all""> <a href=""javascript:;"" class=""mdl-head-clearSearch""></a> <input type=""text"" class=""mdl-head-txt mdl-head-search mdl-head-search-thanhvien"" /> </span> <a class=""mdl-head-btn mdl-head-add"" id=""thanhvienmdl-addBtn"" href=""javascript:thanhvien.add();"">Thêm</a> <a class=""mdl-head-btn mdl-head-edit"" id=""thanhvienmdl-editBtn"" href=""javascript:thanhvien.edit();"">Sửa</a> <a class=""mdl-head-btn mdl-head-del"" id=""thanhvienmdl-delBtn"" href=""javascript:thanhvien.del();"">Xóa</a> <a class=""mdl-head-btn mdl-head-sendmail"" id=""thanhvienmdl-emailBtn"" href=""javascript:thanhvien.sendmail();"">Email</a> <a class=""mdl-head-btn mdl-head-resetPwd"" id=""thanhvienmdl-reSendPwdBtn"" href=""javascript:thanhvien.resendPwd();"">Cấp mật khẩu</a> <span class=""mdl-head-filterPnl ui-state-default ui-corner-all""> <a href=""javascript:;"" class=""mdl-head-clearSearch""></a> <input type=""text"" _value="""" class=""mdl-head-filter mdl-head-filterThanhVienByCQID""/> </span> </div> <table id=""thanhvienmdl-List"" class=""mdl-list""> </table> <div id=""thanhvienmdl-Pager""></div><div class=""sub-mdl""><ul><li><a id=""thanhvienmdl-rolemdl-subMdlBtn"" href=""#mdl-1"">Quyền</a></li></ul><div id=""mdl-1""> <div class=""sub-mdl-list"" id=""thanhvienmdl-rolemdl-mdl""></div> </div></div>"); sb.AppendFormat(@"<script>$.getScript('{0}',function(){1});</script>" , cs.GetWebResourceUrl(typeof(Class1), "docsoft.plugin.hethong.thanhvien.JScript1.js") , "{thanhvien.loadgrid();}"); sb.AppendFormat("<script>adm.validFn('{0}');</script>", JavaScriptConvert.SerializeObject(ListFn)); break; #endregion } writer.Write(sb.ToString()); base.Render(writer); }
protected void Page_Load(object sender, EventArgs e) { var x = Request["x"]; var y = Request["y"]; var x1 = Request["x1"]; var y1 = Request["y1"]; var w = Request["w"]; var h = Request["h"]; var Key = Request["key"]; var Id = Request["Id"]; var dic = Server.MapPath("~/lib/up/crop/"); var newDic = Server.MapPath("~/lib/up/car/"); var DM_PID = Request["DM_PID"]; var logged = Security.IsAuthenticated(); var js = new JavaScriptSerializer(); switch (subAct) { case "upload": #region upload image if (!string.IsNullOrEmpty(Id)) { Response.ContentType = "text/plain";//"application/json"; var r = new List<ViewDataUploadFilesResult>(); foreach (string file in Request.Files) { var hpf = Request.Files[file] as HttpPostedFile; var key = Guid.NewGuid().ToString(); var img = new ImageProcess(hpf.InputStream, key); var fileName = key + img.Ext; img.Resize(960); img.Save(dic + key + "full" + img.Ext); img.Save(dic + key + img.Ext); var anh = new Anh() { Id = Guid.NewGuid() , P_ID = new Guid(Id) , FileAnh = fileName , NgayTao = DateTime.Now }; anh = AnhDal.Insert(anh); r.Add(new ViewDataUploadFilesResult() { Id = anh.Id.ToString(), Thumbnail_url = key + img.Ext, Name = key + "full" + img.Ext, Length = hpf.ContentLength, Type = hpf.ContentType }); var uploadedFiles = new { files = r.ToArray() }; var jsonObj = js.Serialize(uploadedFiles); rendertext(jsonObj); } } rendertext("Id is missing", HttpStatusCode.BadRequest); break; #endregion case "GetImage": #region get image if (Key != null) { var fileName = dic + Lib.imgSize(Key, "full"); var src = new Bitmap(fileName); var cropRect = new Rectangle(Convert.ToInt32(x), Convert.ToInt32(y), Convert.ToInt32(w), Convert.ToInt32(h)); var cropted = Lib.CropBitmap(src, cropRect); var img = new ImageProcess(cropted, Key); File.Delete(dic + Key); if (img.Width < 960) img.Resize(960); Response.ClearContent(); Response.ContentType = img.Mime; img.Save(newDic + Key); img.Save(); Response.End(); } break; #endregion case "RemoveImage": #region remove image if (Id != null) { var item = AnhDal.SelectById(new Guid(Id)); var file = newDic + item.FileAnh; if (File.Exists(file)) { File.Delete(newDic + item.FileAnh); } AnhDal.DeleteById(item.Id); } break; #endregion case "SetAnhChinh": #region Set Anh Chinh if (Id != null) { var item = AnhDal.SelectById(new Guid(Id)); AnhDal.UpdateAnhBia(item.Id); var xe = XeDal.SelectByRowId(item.P_ID); if (xe.Id != 0) { xe.Anh = item.FileAnh; XeDal.Update(xe); } var blog = BlogDal.SelectByRowId(item.P_ID); if (blog.Id != 0) { blog.Anh = item.FileAnh; BlogDal.Update(blog); } } break; #endregion case "GetImageMobile": #region get image in mobile if (Key != null) { var fileName = dic + Lib.imgSize(Key, "full"); var img = new ImageProcess(fileName, Key); File.Delete(dic + Key); if (img.Heigth < 540) img.ResizeHeight(540); img.Crop(960, 540); Response.ClearContent(); Response.ContentType = img.Mime; img.Save(newDic + Key); if(!string.IsNullOrEmpty(w)) { img.Resize(Convert.ToInt32(w)); if(!string.IsNullOrEmpty(h)) { img.Crop(Convert.ToInt32(w), Convert.ToInt32(h)); } } img.Save(); Response.End(); } break; #endregion } }