示例#1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        var Ten = Request["Ten"];
        var NoiDung = Request["NoiDung"];
        var P_ID = Request["P_ID"];
        var Anh = Request["Anh"];
        var HoatDong_ID = Request["HoatDong_ID"];
        var NgayViet = Request["NgayViet"];
        CapNhat Item;
        switch (subAct)
        {
            case "add":
                #region add
                Item = new CapNhat();
                Item.ID = Guid.NewGuid();
                Item.Ten = Ten;
                Item.NoiDung = NoiDung;
                Item.NgayTao = DateTime.Now;
                Item.Username = Security.Username;
                if (!string.IsNullOrEmpty(P_ID))
                {
                    Item.P_ID = new Guid(P_ID);
                }
                if (!string.IsNullOrEmpty(HoatDong_ID))
                {
                    Item.HoatDong_ID = new Guid(HoatDong_ID);
                }
                if (!string.IsNullOrEmpty(NgayViet))
                {
                    Item.NgayViet = Convert.ToDateTime(NgayViet, new CultureInfo("vi-Vn"));
                }
                Item.Anh = Anh;
                Item.Loai = 2;// Su kien
                Item = CapNhatDal.Insert(Item);
                rendertext(Item.ID.ToString());
                break;
                #endregion
            case "upload":
                #region upload
                if (Security.IsAuthenticated())
                {
                    var key = Guid.NewGuid().ToString();
                    var img = new linh.controls.ImageProcess(Request.Files[0].InputStream, key);
                    if (img.Width < 300)
                        rendertext("300");
                    img.Resize(520);
                    img.Save(Server.MapPath("~/lib/up/i/") + key + img.Ext);
                    rendertext(key + img.Ext);
                }
                break;
                #endregion
            default:
                break;

        }
    }
示例#2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        var Ten = Request["Ten"];
        var NoiDung = Request["NoiDung"];
        var P_ID = Request["P_ID"];
        var Anh = Request["Anh"];
        var HoatDong_ID = Request["HoatDong_ID"];
        CapNhat Item;
        switch (subAct)
        {
            case "update":
                #region add
                if(Security.IsAuthenticated())
                {
                    MemberDal.UpdateInfoByUsername(Security.Username, Ten, null, null);
                }
                break;
                #endregion
            case "upload":
                #region upload
                if (Security.IsAuthenticated())
                {
                    var key = Guid.NewGuid().ToString();
                    var img = new linh.controls.ImageProcess(Request.Files[0].InputStream, key);
                    if (img.Width < 300)
                        rendertext("300");
                    img.Resize(300);
                    img.Save(Server.MapPath("~/lib/up/i/") + key + img.Ext);
                    MemberDal.UpdateAnh(Security.Username, key + img.Ext);
                    rendertext(key + img.Ext);
                }
                break;
                #endregion
            default:
                break;

        }
    }
示例#3
0
        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
            }
        }
示例#4
0
        public RegularTin(string url)
        {
            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
                            {
                                var gimg = new ImageProcess(new Uri(src), src);
                                if (gimg.Width > 250 && gimg.Heigth > 200)
                                {
                                    _list.Add(src);
                                    break;
                                }
                            }
                            catch (Exception ex)
                            {
                            }

                        }
                    }
                    if (_list.Count == 0) return;
                    Anh = _list[0];
                }
            }

            #endregion
        }
示例#5
0
        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
        }
示例#6
0
    protected void Page_Load(object sender, EventArgs e)
    {
        var Ten = Request["Ten"];
        var Email = Request["Email"];
        var NoiDung = Request["NoiDung"];
        var P_ID = Request["P_ID"];
        var ID = Request["ID"];
        var Anh = Request["Anh"];
        var LOAI_ID = Request["LOAI_ID"];
        GiaDinh Item;
        switch (subAct)
        {
            case "add":
                #region add
                Item = new GiaDinh();
                Item.ID = Guid.NewGuid();
                Item.Anh = Anh;
                Item.Email = Email;
                if (!string.IsNullOrEmpty(LOAI_ID))
                {
                    Item.LOAI_ID = new Guid(LOAI_ID);
                }
                if (!string.IsNullOrEmpty(P_ID))
                {
                    Item.P_ID = new Guid(P_ID);
                }
                Item.NgayTao = DateTime.Now;
                Item.NoiDung = NoiDung;
                Item.Ten = Ten;
                Item.ThuTu = 0;
                Item.Username = Security.Username;
                Item = GiaDinhDal.Insert(Item);
                GiaDinhItem1.item = Item;
                GiaDinhItem1.Visible = true;
                //rendertext(Item.ID.ToString());
                break;
                #endregion
            case "remove":
                #region add
               if(Security.IsAuthenticated())
               {
                   if(!string.IsNullOrEmpty(ID))
                   {
                       Item = GiaDinhDal.SelectById(new Guid(ID));
                       if(Item.Username==Security.Username)
                       {
                           GiaDinhDal.DeleteById(new Guid(ID));
                       }
                   }
               }
                break;
                #endregion
            case "upload":
                #region upload
                if (Security.IsAuthenticated())
                {
                    var key = Guid.NewGuid().ToString();
                    var img = new linh.controls.ImageProcess(Request.Files[0].InputStream, key);
                    if (img.Width < 300)
                        rendertext("300");
                    img.Resize(520);
                    img.Save(Server.MapPath("~/lib/up/i/") + key + img.Ext);
                    rendertext(key + img.Ext);
                }
                break;
                #endregion
            default:
                break;

        }
    }
示例#7
0
        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);
        }
示例#8
0
    protected void Page_Load(object sender, EventArgs e)
    {
        var ID = Request["ID"];
        var P_ID = Request["P_ID"];
        var Ten = Request["Ten"];
        var location = Server.MapPath("~/lib/up/anh/");
        CapNhat Item;
        switch (subAct)
        {
            case "upload":
                #region upload anh
                Response.ContentType = "text/plain";//"application/json";
                var r = new List<ViewDataUploadFilesResult>();
                var js = new JavaScriptSerializer();
                foreach (string file in Request.Files)
                {

                    var hpf = Request.Files[file] as HttpPostedFile;
                    var key = Guid.NewGuid().ToString();

                    var img = new linh.controls.ImageProcess(hpf.InputStream, key);
                    var fileName = key + img.Ext;

                    var item = new Anh();
                    if(!string.IsNullOrEmpty(ID))
                    {
                        item.AB_ID = new Guid(ID);
                    }
                    item.FileAnh = fileName;
                    item.ID = Guid.NewGuid();
                    item.NgayTao = DateTime.Now;
                    if(!string.IsNullOrEmpty(P_ID))
                    {
                        item.P_ID = new Guid(P_ID);
                    }
                    item = AnhDal.Insert(item);

                    if(img.Width > 1000)
                    {
                        img.Resize(1000);
                    }
                    img.Save(location + key + "full" + img.Ext);

                    img.Resize(520);
                    img.Save(location + key + img.Ext);
                    r.Add(new ViewDataUploadFilesResult()
                    {
                        Id = item.ID.ToString(),
                        Thumbnail_url = key + img.Ext,
                        Name = key,
                        Length = hpf.ContentLength,
                        Type = hpf.ContentType
                    });
                    var uploadedFiles = new
                    {
                        files = r.ToArray()
                    };
                    var jsonObj = js.Serialize(uploadedFiles);
                    Response.Write( jsonObj.ToString());
                }
                ;
                break;
                #endregion
            case "xoaAnh":
                #region Xoa anh
                if (Security.IsAuthenticated())
                {
                    var item = AnhDal.SelectById(new Guid(ID));
                    AnhDal.DeleteById(new Guid(ID));
                    try
                    {
                        File.Delete(location + item.FileAnh);
                        File.Delete(location + Lib.imgSize(item.FileAnh,"full"));
                    }
                    catch
                    {

                    }
                }
                break;
                #endregion
            case "editCaption":
                #region Sua tieu de
                if (Security.IsAuthenticated())
                {
                    var item = AnhDal.SelectById(new Guid(ID));
                    item.Ten = Ten;
                    AnhDal.Update(item);
                }
                break;
                #endregion
            case "addAlbum":
                #region Them moi album
                if (Security.IsAuthenticated())
                {
                    var item = new Album();
                    item.ID = new Guid(ID);
                    item.Ten = Ten;
                    item.NgayTao = DateTime.Now;
                    item.NguoiTao = Security.Username;
                    item.P_RowId = new Guid(P_ID);
                    item.Active = true;
                    item = AlbumDal.Insert(item);

                    Item = new CapNhat();
                    Item.ID = Guid.NewGuid();
                    Item.Ten = Ten;
                    Item.NgayTao = DateTime.Now;
                    Item.Username = Security.Username;
                    Item.NgayViet = DateTime.Now;
                    if (!string.IsNullOrEmpty(P_ID))
                    {
                        Item.P_ID = new Guid(P_ID);
                    }

                    Item.Loai = 4;// Album
                    Item.AB_ID = item.ID;
                    Item = CapNhatDal.Insert(Item);
                    rendertext(Item.ID.ToString());
                }
                break;
                #endregion
            case "updateAlbum":
                #region Cap nhat album
                if (Security.IsAuthenticated())
                {
                    var item = AlbumDal.SelectById(new Guid(ID));
                    item.Ten = Ten;
                    item = AlbumDal.Update(item);
                }
                break;
                #endregion
            case "xoaAlbum":
                #region Cap nhat album
                if (Security.IsAuthenticated())
                {
                    AlbumDal.DeleteById(new Guid(ID));
                }
                break;
                #endregion
            default:
                Response.Write("s");
                break;
        }
    }
示例#9
0
    protected void Page_Load(object sender, EventArgs e)
    {
        var Ten = Request["Ten"];
        var NoiDung = Request["NoiDung"];
        var P_ID = Request["P_ID"];
        var Anh = Request["Anh"];
        var NgayViet = Request["NgayViet"];
        var FromDate = Request["FromDate"];
        ID = Request["ID"];
        switch (subAct)
        {
            case "add":
                #region add
                Item = new CapNhat();
                Item.ID = Guid.NewGuid();
                Item.Ten = Ten;
                Item.NoiDung = NoiDung;
                Item.NgayTao = DateTime.Now;
                Item.Username = Security.Username;
                if(!string.IsNullOrEmpty(P_ID))
                {
                    Item.P_ID = new Guid(P_ID);
                }
                if (!string.IsNullOrEmpty(NgayViet))
                {
                    Item.NgayViet = Convert.ToDateTime(NgayViet, new CultureInfo("vi-Vn"));
                }
                Item.Anh = Anh;
                Item.Loai = 1;// Blog
                Item = CapNhatDal.Insert(Item);
                rendertext(Item.ID.ToString());
                break;
                #endregion
            case "remove":
                #region remove
                if(Security.IsAuthenticated())
                {
                    if(!string.IsNullOrEmpty(ID))
                    {
                        var item = CapNhatDal.SelectById(new Guid(ID));
                        if(item.Username==Security.Username)
                        {
                            CapNhatDal.DeleteById(item.ID);
                        }
                    }
                }
                break;
                #endregion
            case "more":
                #region more
                using(var con = DAL.con())
                {
                    var BeItem = BeDal.SelectById(con, new Guid(ID), Security.Username);
                    List = CapNhatDal.WallById(con, "10", ID, Security.Username, FromDate);
                    var _postList = new List<CapNhat>();
                    foreach (var post in List)
                    {
                        post.BeItem = BeItem;
                        _postList.Add(post);
                    }
                    postList.DataSource = _postList;
                    postList.DataBind();
                    postList.Visible = true;
                }

                break;
                #endregion
            case "upload":
            #region upload
                if (Security.IsAuthenticated())
                {
                    var key = Guid.NewGuid().ToString();
                    var img = new linh.controls.ImageProcess(Request.Files[0].InputStream, key);
                    if (img.Width < 300)
                        rendertext("300");
                    img.Resize(520);
                    img.Save(Server.MapPath("~/lib/up/i/") + key + img.Ext);
                    rendertext(key + img.Ext);
                }
                break;
            #endregion
            default:
                break;

        }
        switch (act)
        {
            case "view":
                #region xem post
                using(var con=DAL.con())
                {
                    var Item = CapNhatDal.SelectById(con, new Guid(ID));
                    Item.BeItem = BeDal.SelectById(con, new Guid(ID));
                    Post_PureTemplate1.Visible = true;
                    Post_PureTemplate1.Item = Item;
                }
                break;
                #endregion
            default: break;
        }
    }
示例#10
0
        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;
        }
示例#11
0
        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;
        }
示例#12
0
        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
        }
示例#13
0
 public void insertLink(string link, string _class)
 {
     string domain = "http://" + (new Uri(link)).Host;
     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 = true;
     HttpWebResponse wrp = (HttpWebResponse)wrq.GetResponse();
     HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
     doc.Load(wrp.GetResponseStream(), Encoding.UTF8);
     HtmlNode _n1 = doc.DocumentNode.SelectSingleNode(@"//td[@class='" + _class + "']");
     HtmlNode _n2 = _n1.SelectSingleNode(@"table/tbody");
     HtmlNode _n11 = _n2.ChildNodes[1];
     HtmlNode _n12 = _n2.ChildNodes[5].ChildNodes[1];
     HtmlNode _n13 = _n12.SelectSingleNode("i");
     HtmlNode _n14 = _n12.SelectSingleNode("span[@class='text666666 textnormalbold']");
     _n12.RemoveChild(_n13);
     _n12.RemoveChild(_n14);
     string _anh = string.Empty;
     foreach (HtmlNode _img in _n12.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;
             }
         }
     }
        // insert(_n11.InnerText, _n14.InnerText, _n12.InnerHtml, _anh, link, "1", _n13.InnerText);
     //sb.AppendFormat("{0}<br/>{1}<br/>{2}<br/>{3}<br/>{4}", _n11.InnerText, _n12.InnerHtml, _n13.InnerText, _n14.InnerText, "");
 }
示例#14
0
        protected override void Render(HtmlTextWriter writer)
        {
            StringBuilder sb = new StringBuilder();
            ClientScriptManager cs = this.Page.ClientScript;
            #region Tham số
            string _ID = Request["ID"];
            string _DM_ID = Request["DM_ID"];
            string _Ten = Request["Ten"];
            string _Url = Request["Url"];
            string _MoTa = Request["MoTa"];
            string _YID = Request["YID"];
            string _Views = Request["Views"];
            string _Diem = Request["Diem"];
            string _Active = Request["Active"];
            string _Home = Request["Home"];
            string _Hot = Request["Hot"];
            string _Hot1 = Request["Hot1"];
            string _Hot2 = Request["Hot2"];
            string _Hot3 = Request["Hot3"];
            string _Anh = Request["Anh"];
            Video Item;
            List<jgridRow> ListRow = new List<jgridRow>();
            jgrid grid = new jgrid();
            #endregion

            switch (subAct)
            {
                case "get":
                    #region lấy dữ liệu cho grid
                    if (string.IsNullOrEmpty(jgrsidx)) jgrsidx = "T_ID";
                    if (string.IsNullOrEmpty(jgrsord)) jgrsord = "desc";

                    Pager<Video> PagerGet = VideoDal.pagerNormal("", false, jgrsidx + " " + jgrsord);

                    TopicCollection List = TopicDal.SelectAll();
                    foreach (Video dm in PagerGet.List)
                    {
                        ListRow.Add(new jgridRow(dm.ID.ToString(), new string[] {
                             string.Format("{0}",dm.ID)
                            , string.Format("<img src=\"../up/i/{0}\" />", dm.Anh)
                            , dm.Ten
                            , dm.Url
                            , dm.MoTa
                            , string.Format("{0}/{1}", dm.Views,dm.Diem)
                            , dm.Active.ToString()
                            , dm.Hot.ToString()
                            , dm.Hot1.ToString()
                            , dm.Hot2.ToString()
                            , dm.Hot3.ToString()
                            , dm.Home.ToString()
                        }));
                    }
                    grid = new jgrid(string.IsNullOrEmpty(jgrpage) ? "1" : jgrpage, PagerGet.TotalPages.ToString(), PagerGet.Total.ToString(), ListRow);
                    sb.Append(JavaScriptConvert.SerializeObject(grid));
                    break;
                    #endregion
                case "del":
                    #region xóa
                    if (!string.IsNullOrEmpty(_ID))
                    {
                        VideoDal.DeleteById(Convert.ToInt32(_ID));
                    }
                    break;
                    #endregion
                case "edit":
                    #region chỉnh sửa
                    if (!string.IsNullOrEmpty(_ID))
                    {
                        sb.Append("(" + JavaScriptConvert.SerializeObject(VideoDal.SelectById(Convert.ToInt32(_ID))) + ")");
                    }
                    break;
                    #endregion
                case "save":
                    #region lưu
                    if (!string.IsNullOrEmpty(_ID))
                    {
                        Item = VideoDal.SelectById(Convert.ToInt32(_ID));
                    }
                    else
                    {
                        Item = new Video();
                    }
                    if (!string.IsNullOrEmpty(_DM_ID))
                    {
                        Item.DM_ID = Convert.ToInt32(_DM_ID);
                    }
                    if (!string.IsNullOrEmpty(_Diem))
                    {
                        Item.Diem = Convert.ToInt32(_Diem);
                    }
                    if (!string.IsNullOrEmpty(_Views))
                    {
                        Item.Views = Convert.ToInt32(_Views);
                    }
                    Item.YID = _YID;
                    Item.Url = _Url;
                    Item.Ten = _Ten;
                    Item.Active = Convert.ToBoolean(_Active);
                    Item.Anh = _Anh;
                    Item.Home = Convert.ToBoolean(_Home);
                    Item.Hot = Convert.ToBoolean(_Hot);
                    Item.Hot1 = Convert.ToBoolean(_Hot1);
                    Item.Hot2 = Convert.ToBoolean(_Hot2);
                    Item.Hot3 = Convert.ToBoolean(_Hot3);
                    Item.MoTa = _MoTa;
                    if (!string.IsNullOrEmpty(_ID))
                    {
                        Item = VideoDal.Update(Item);
                    }
                    else
                    {
                        Item = VideoDal.Insert(Item);
                    }
                    sb.Append("1");
                    break;
                    #endregion
                case "wrappUrl":
                    #region wrappUrl: Đọc url
                    if (!string.IsNullOrEmpty(_Url))
                    {
                        youTubeVideo vd = Lib.YouTubeCode(_Url);
                        string imgTen = Guid.NewGuid().ToString();
                        string imgLoc = Server.MapPath(@"~/lib/up/i/");
                        ImageProcess imgVd = new ImageProcess(new Uri(vd.Anh), imgTen);
                        imgVd.Save(imgLoc + imgTen + imgVd.Ext);
                        vd.Anh = imgTen + imgVd.Ext;
                        sb.AppendFormat("({0})", JavaScriptConvert.SerializeObject(vd));
                    }
                    break;
                    #endregion
                case "scpt":
                    #region Nạp js
                    sb.AppendFormat(@"{0}"
                        , cs.GetWebResourceUrl(typeof(Class1), "plugin.rss.youTube.JScript1.js"));
                    break;
                    #endregion
                default:
                    #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-youTuBeMdl"" />
            </span>
            <a class=""mdl-head-btn mdl-head-add"" id=""youTuBeMdl-addBtn"" href=""javascript:youTuBeFn.add();"">Thêm</a>
            <a class=""mdl-head-btn mdl-head-edit"" id=""youTuBeMdl-editBtn"" href=""javascript:youTuBeFn.edit();"">Sửa</a>
            <a class=""mdl-head-btn mdl-head-del"" id=""youTuBeMdl-delBtn"" href=""javascript:youTuBeFn.del();"">Xóa</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-kenhRssFilterByBao""/>
            </span>
            <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-kenhRssFilterByDanhMuc""/>
            </span>
            </div>
            <table id=""youTuBeMdl-List"" class=""mdl-list""></table>
            <div id=""youTuBeMdl-Pager""></div>");
                    sb.AppendFormat(@"<script>$.getScript('{0}',function(){1});</script>"
                        , cs.GetWebResourceUrl(typeof(Class1), "plugin.rss.youTube.JScript1.js")
                        , "{youTuBeFn.loadgrid();}");
                    sb.AppendFormat("<script>adm.validFn('{0}');</script>", JavaScriptConvert.SerializeObject(ListFn));
                    break;
                    #endregion
            }
            writer.Write(sb.ToString());
            base.Render(writer);
        }
示例#15
0
        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
            }
        }
示例#16
0
    protected void Page_Load(object sender, EventArgs e)
    {
        var ID = Request["ID"];
        var ThuTu = Request["ThuTu"];
        var Ten = Request["Ten"];
        var MoTa = Request["MoTa"];
        var Anh = Request["Anh"];
        var AnhDaiDien = Request["AnhDaiDien"];
        var G_ID = Request["G_ID"];
        var Q_ID = Request["Q_ID"];
        var Active = Request["Active"];
        var location = Server.MapPath("~/lib/up/i/");
        CapNhat Item;
        switch (subAct)
        {
            case "uploadAnh":
                #region upload
                if (Security.IsAuthenticated())
                {
                    var key = Guid.NewGuid().ToString();
                    var img = new linh.controls.ImageProcess(Request.Files[0].InputStream, key);
                    img.Resize(320);
                    img.Save(Server.MapPath("~/lib/up/i/") + key + img.Ext);
                    rendertext(key + img.Ext);
                }
                break;
                #endregion
            case "uploadAnhDaiDien":
                #region upload
                if (Security.IsAuthenticated())
                {
                    var key = Guid.NewGuid().ToString();
                    var img = new linh.controls.ImageProcess(Request.Files[0].InputStream, key);
                    img.Resize(1280);
                    img.Save(Server.MapPath("~/lib/up/i/") + key + img.Ext);
                    rendertext(key + img.Ext);
                }
                break;
                #endregion
            case "xoaAnh":
                #region Xoa anh
                if (Security.IsAuthenticated())
                {
                    var item = AnhDal.SelectById(new Guid(ID));
                    AnhDal.DeleteById(new Guid(ID));
                    try
                    {
                        File.Delete(location + item.FileAnh);
                        File.Delete(location + Lib.imgSize(item.FileAnh, "full"));
                    }
                    catch
                    {

                    }
                }
                break;
                #endregion
            case "editGame":
                #region Sua tieu de
                if (Security.IsAuthenticated())
                {
                    var item = GameDal.SelectById(new Guid(ID));
                    rendertext(string.Format("({0})",JavaScriptConvert.SerializeObject(item)));
                }
                break;
                #endregion
            case "addGame":
                #region Them moi game

                if (Security.IsAuthenticated())
                {
                    var item = new Game
                                   {
                                       ID = Guid.NewGuid(),
                                       Ten = Ten,
                                       ThuTu = Convert.ToInt32(ThuTu),
                                       NgayTao = DateTime.Now
                                   };
                    item = GameDal.Insert(item);
                    GameItem1.Visible = true;
                    GameItem1.Item = item;
                }
                break;
                #endregion
            case "saveGame":
                #region save Game

                if (Security.IsAuthenticated())
                {
                    var item = GameDal.SelectById(new Guid(ID));
                    item.Ten = Ten;
                    item.ThuTu = Convert.ToInt32(ThuTu);
                    item = GameDal.Update(item);
                    GameItem1.Visible = true;
                    GameItem1.Item = item;
                }
                break;
                #endregion
            case "saveQuestion":
                #region saveQuestion

                if (Security.IsAuthenticated())
                {
                    var item = string.IsNullOrEmpty(ID) ? new Question() : QuestionDal.SelectById(new Guid(ID));
                    item.Ten = Ten;
                    item.ThuTu = ThuTu;
                    item.MoTa = MoTa;
                    item.Anh = Anh;
                    item.G_ID = new Guid(G_ID);
                    item.AnhDaiDien = AnhDaiDien;
                    item.Active = Convert.ToBoolean(Active);
                    item.ID = string.IsNullOrEmpty(ID) ? Guid.NewGuid() : new Guid(ID);
                    item = string.IsNullOrEmpty(ID) ? QuestionDal.Insert(item) : QuestionDal.Update(item);
                    QuestionItem1.Item = item;
                    QuestionItem1.Visible = true;
                }
                break;
                #endregion
            case "editQuestion":
                #region Sua tieu de
                if (Security.IsAuthenticated())
                {
                    var item = QuestionDal.SelectById(new Guid(ID));
                    rendertext(string.Format("({0})", JavaScriptConvert.SerializeObject(item)));
                }
                break;
                #endregion
            case "updateThuTuAnswer":
                #region Cap nhat updateThuTuAnswer
                if (Security.IsAuthenticated())
                {
                    var item = AnswerDal.SelectById(new Guid(ID));
                    item.ThuTu = Convert.ToInt32(ThuTu);
                    item = AnswerDal.Update(item);
                }
                break;
                #endregion
            case "updateQuestionActive":
                #region Cap nhat updateQuestionActive
                if (!string.IsNullOrEmpty(ID))
                {
                    var item = QuestionDal.SelectById(new Guid(ID));
                    item.Active = Convert.ToBoolean(Active);
                    item = QuestionDal.Update(item);
                }
                break;
                #endregion
            case "uploadAnswerAnh":
                #region upload anh
                Response.ContentType = "text/plain";//"application/json";
                var r = new List<ViewDataUploadFilesResult>();
                var js = new JavaScriptSerializer();
                var ThuTuAnh = 1;
                foreach (string file in Request.Files)
                {

                    var hpf = Request.Files[file] as HttpPostedFile;
                    var key = Guid.NewGuid().ToString();

                    var img = new linh.controls.ImageProcess(hpf.InputStream, key);
                    var fileName = key + img.Ext;

                    var item = new Answer();
                    if (!string.IsNullOrEmpty(Q_ID))
                    {
                        item.Q_ID = new Guid(Q_ID);
                    }
                    item.ThuTu = ThuTuAnh;
                    item.Anh = fileName;
                    item.ID = Guid.NewGuid();
                    item = AnswerDal.Insert(item);

                    if (img.Width > 1280)
                    {
                        img.Resize(1280);
                    }
                    img.Save(location + key + "full" + img.Ext);

                    img.Resize(520);
                    img.Save(location + key + img.Ext);

                    r.Add(new ViewDataUploadFilesResult()
                    {
                        Id = item.ID.ToString(),
                        Thumbnail_url = key + img.Ext,
                        Name = key,
                        Length = hpf.ContentLength,
                        Type = hpf.ContentType
                    });
                    var uploadedFiles = new
                    {
                        files = r.ToArray()
                    };
                    var jsonObj = js.Serialize(uploadedFiles);
                    Response.Write(jsonObj.ToString());
                    ThuTuAnh++;
                }
                ;
                break;
                #endregion
            case "removeQuestion":
                #region Xoa
                if (Security.IsAuthenticated())
                {
                    QuestionDal.DeleteById(new Guid(ID));
                }
                break;
                #endregion
            case "getAnswerList":
                #region Xoa
                if (Security.IsAuthenticated())
                {
                    var List = AnswerDal.SelectByQuestionId(ID);
                    AnswerList1.List = List;
                    AnswerList1.Visible = true;
                }
                break;
                #endregion
            case "xoaAnhAnswer":
                #region Xoa
                if (Security.IsAuthenticated())
                {
                    AnswerDal.DeleteById(new Guid(ID));
                }
                break;
                #endregion
            case "removeGame":
                #region Xoa
                if (Security.IsAuthenticated())
                {
                    GameDal.DeleteById(new Guid(ID));
                }
                break;
                #endregion
            default:
                Response.Write("s");
                break;
        }
    }
示例#17
0
    protected void Page_Load(object sender, EventArgs e)
    {
        var Ten = Request["Ten"];
        var Url = Request["Url"];
        var P_ID = Request["P_ID"];
        var Anh = Request["Anh"];
        var Yid = Request["Yid"];
        var NgayViet = Request["NgayViet"];
        CapNhat Item;
        switch (subAct)
        {
            case "add":
                #region add
                Item = new CapNhat();
                Item.ID = Guid.NewGuid();
                Item.Ten = Ten;
                Item.NgayTao = DateTime.Now;
                Item.Username = Security.Username;
                if (!string.IsNullOrEmpty(P_ID))
                {
                    Item.P_ID = new Guid(P_ID);
                }
                if (!string.IsNullOrEmpty(NgayViet))
                {
                    Item.NgayViet = Convert.ToDateTime(NgayViet, new CultureInfo("vi-Vn"));
                }
                Item.Anh = Anh;
                Item.Loai = 3;// Video
                Item.VideoUrl = Yid;
                Item = CapNhatDal.Insert(Item);
                rendertext(Item.ID.ToString());
                break;
                #endregion
            case "wrappUrl":
                #region wrappUrl: Đọc url
                if (!string.IsNullOrEmpty(Url))
                {
                    youTubeVideo vd = Lib.YouTubeCode(Url);
                    rendertext(string.Format("({0})", JavaScriptConvert.SerializeObject(vd)));
                }
                break;
                #endregion
            case "upload":
                #region upload
                if (Security.IsAuthenticated())
                {
                    var key = Guid.NewGuid().ToString();
                    var img = new linh.controls.ImageProcess(Request.Files[0].InputStream, key);
                    if (img.Width < 300)
                        rendertext("300");
                    img.Resize(520);
                    img.Save(Server.MapPath("~/lib/up/i/") + key + img.Ext);
                    rendertext(key + img.Ext);
                }
                break;
                #endregion
            default:
                break;

        }
    }
示例#18
0
    protected void Page_Load(object sender, EventArgs e)
    {
        var Ten = Request["Ten"];
        var Ho = Request["Ho"];
        var Alias = Request["Alias"];
        var GioiTinh = Request["GioiTinh"];
        var NgaySinh = Request["NgaySinh"];
        var NgayDuSinh = Request["NgayDuSinh"];
        var MangThai = Request["MangThai"];
        var CanNangKhiSinh = Request["CanNang"];
        var Nick = Request["Nick"];
        var ID = Request["ID"];
        var Css = Request["css"];
        var KhongChiaSe = Request["KhongChiaSe"];
        Be Item;
        switch (subAct)
        {
            case "add":
            #region add
                Item = new Be();
                Item.Alias = Alias;
                Item.MangThai = MangThai == "1";
                Item.ID = Guid.NewGuid();
                if(Item.MangThai)
                {
                    if (!string.IsNullOrEmpty(NgayDuSinh))
                    {
                        Item.NgayDuSinh = Convert.ToDateTime(NgayDuSinh, new CultureInfo("vi-Vn"));
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(NgaySinh))
                    {
                        Item.NgaySinh = Convert.ToDateTime(NgaySinh, new CultureInfo("vi-Vn"));
                    }
                    Item.GioiTinh = Convert.ToBoolean(GioiTinh);
                    if (!string.IsNullOrEmpty(CanNangKhiSinh))
                    {
                        Item.CanNangKhiSinh = Convert.ToInt32(CanNangKhiSinh);
                    }
                    Item.Ten = Ten;
                    Item.Ho = Ho;
                    Item.Alias = Alias;
                }
                Item.NgayTao = DateTime.Now;
                Item.Username = Security.Username;
                Item.Khoa = false;
                Item.KhongChiaSe = false;
                Item = BeDal.Insert(Item);
                rendertext(Item.ID.ToString());
                break;
            #endregion
            case "save":
                #region save

                Item = BeDal.SelectById(new Guid(ID));
                Item.Alias = Alias;
                Item.MangThai = MangThai == "1";
                if (Item.MangThai)
                {
                    if (!string.IsNullOrEmpty(NgayDuSinh))
                    {
                        Item.NgayDuSinh = Convert.ToDateTime(NgayDuSinh, new CultureInfo("vi-Vn"));
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(NgaySinh))
                    {
                        Item.NgaySinh = Convert.ToDateTime(NgaySinh, new CultureInfo("vi-Vn"));
                    }
                    Item.GioiTinh = Convert.ToBoolean(GioiTinh);
                    if (!string.IsNullOrEmpty(CanNangKhiSinh))
                    {
                        Item.CanNangKhiSinh = Convert.ToInt32(CanNangKhiSinh);
                    }
                    Item.Ten = Ten;
                    Item.Ho = Ho;
                    Item.Alias = Alias;
                }
                Item = BeDal.Update(Item);
                rendertext(Item.ID.ToString());
                break;
                #endregion
            case "doiAnh":
            #region Doi anh
                if(Security.IsAuthenticated())
                {
                    var key = Guid.NewGuid().ToString();
                    var img = new linh.controls.ImageProcess(Request.Files[0].InputStream, key);
                    if(img.Width < 930)
                        rendertext("930");
                    img.Resize(930);
                    img.Save(Server.MapPath("~/lib/up/avatar/") + key + img.Ext);
                    Item = BeDal.SelectById(new Guid(ID));
                    Item.Cover = key + img.Ext;
                    BeDal.Update(Item);
                    rendertext(key + img.Ext);
                }
                break;
            #endregion
            case "SuaNick":
                #region SuaNick
                if (Security.IsAuthenticated())
                {
                    var be = BeDal.SelectByNick(DAL.con(), Nick, Security.Username);
                    var beId = BeDal.SelectById(new Guid(ID));

                    if(be.ID != Guid.Empty && be.ID!=beId.ID)
                    {
                        rendertext("0");
                    }
                    else
                    {
                        beId.Nick = Nick.ToLower();
                        BeDal.Update(beId);
                        rendertext("1");
                    }

                }
                break;
                #endregion
            case "moveCover":
                #region moveCover
                if (Security.IsAuthenticated())
                {
                    Item = BeDal.SelectById(new Guid(ID));
                    if (Item.Username == Security.Username)
                    {
                        Item.CoverCss = Css;
                        BeDal.Update(Item);
                    }
                    rendertext(Css);
                }
                break;
                #endregion
            case "UpdateChiaSe":
                #region moveCover
                if (Security.IsAuthenticated())
                {
                    Item = BeDal.SelectById(new Guid(ID));
                    if (Item.Username==Security.Username)
                    {
                        Item.KhongChiaSe = Convert.ToBoolean(KhongChiaSe);
                        BeDal.Update(Item);
                    }
                }
                break;
                #endregion
            case "doiAvatar":
                #region Doi Avatar
                if (Security.IsAuthenticated())
                {
                    var key = Guid.NewGuid().ToString();
                    var img = new linh.controls.ImageProcess(Request.Files[0].InputStream, key);
                    img.Resize(400);
                    img.Save(Server.MapPath("~/lib/up/avatar/") + key + img.Ext);
                    Item = BeDal.SelectById(new Guid(ID));
                    Item.Anh = key + img.Ext;
                    BeDal.Update(Item);
                    rendertext(key + img.Ext);
                }
                break;
                #endregion
            default:
                break;

        }
    }