Beispiel #1
0
 private void btnLuu_Click(object sender, EventArgs e)
 {
     ThuVienLamViecFacebook.DangXuat();
     if (txtEmail.Text != "" && txtPassword.Text != "")
     {
         tblAccountFB ac = ThuVienLamViecFacebook.DangNhap(txtEmail.Text, txtPassword.Text);
         ac.TaiKhoan = taikhoan;
         if (radioTichCuc.Checked == true)
         {
             ac.Status = 1;
         }
         else
         {
             ac.Status = -1;
         }
         if (ac.NumberIDAccount != "")
         {
             if (AccountFB.Them(ac))
             {
                 MessageBox.Show("Đã thêm tài khoản");
                 LoadData();
             }
             else
             {
                 MessageBox.Show("Tài khoản đã tồn tại");
             }
         }
         else
         {
             MessageBox.Show("Thông tin đăng nhập không đúng");
         }
     }
 }
Beispiel #2
0
 public static bool Sua(tblAccountFB ac)
 {
     try
     {
         con = DataProvider.KetNoi();
         string sTruyVan = string.Format("Update tblAccountFB set Status='{0}' where Email = '{1}'", ac.Status, ac.Email);
         DataProvider.ThucThiTruyVanNonQuery(sTruyVan, con);
         DataProvider.DongKetNoi(con);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Beispiel #3
0
 public static bool Them(tblAccountFB ac)
 {
     try
     {
         string sTruyVan = string.Format("Insert into tblAccountFB(Email,Password,LinkAccount,NumberIDAccount,Name,Sex,Birthday,Address,AddressNow,Phone,ImageLink,Status,TaiKhoan) values(N'{0}',N'{1}','{2}',N'{3}',N'{4}',N'{5}',N'{6}',N'{7}',N'{8}',N'{9}',N'{10}',N'{11}',N'{12}')", ac.Email, ac.Password, ac.LinkAccount, ac.NumberIDAccount, ac.Name, ac.Sex, ac.Birthday, ac.Address, ac.AddressNow, ac.Phone, ac.ImageLink, ac.Status, ac.TaiKhoan);
         con = DataProvider.KetNoi();
         DataProvider.ThucThiTruyVanNonQuery(sTruyVan, con);
         DataProvider.DongKetNoi(con);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
        // đăng nhập
        public static tblAccountFB DangNhap(string user, string pass)
        {
            tblAccountFB ac   = new tblAccountFB();
            WebBrowser   web1 = new WebBrowser();

            web1.ScriptErrorsSuppressed = true;
            string postdata = "email=" + user + "&pass="******"https://mobile.facebook.com/login.php";

            web1.Navigate(url, string.Empty, bytes, "Content-Type: application/x-www-form-urlencoded");
            while (web1.ReadyState != WebBrowserReadyState.Complete)
            {
                Application.DoEvents();
            }
            web1.Navigate("https://mobile.facebook.com");
            while (web1.ReadyState != WebBrowserReadyState.Complete)
            {
                Application.DoEvents();
            }
            string htmlcontent = web1.DocumentText;

            if (htmlcontent.IndexOf("fb_dtsg") != -1)
            {
                ac.Email    = user;
                ac.Password = pass;
                string id = htmlcontent.Substring(htmlcontent.IndexOf("/composer/mbasic/?av=") + 21);
                id = id.Remove(id.IndexOf("&"));
                ac.NumberIDAccount = id;
                web1.Navigate("https://mobile.facebook.com/profile.php?v=info&id=" + id);
                while (web1.ReadyState != WebBrowserReadyState.Complete)
                {
                    Application.DoEvents();
                }
                htmlcontent = web1.DocumentText;
                string name = htmlcontent.Substring(htmlcontent.LastIndexOf("<TITLE>") + 7);
                name    = name.Remove(name.IndexOf("<"));
                ac.Name = name;
                string current_city = htmlcontent.Substring(htmlcontent.IndexOf("current_city") + 40);
                current_city  = current_city.Substring(current_city.IndexOf("refid=17") + 10);
                current_city  = current_city.Remove(current_city.IndexOf("<"));
                ac.AddressNow = current_city;
                string hometown = htmlcontent.Substring(htmlcontent.IndexOf("hometown") + 40);
                hometown   = hometown.Substring(hometown.IndexOf("refid=17") + 10);
                hometown   = hometown.Remove(hometown.IndexOf("<"));
                ac.Address = hometown;
                string phone = htmlcontent.Substring(htmlcontent.IndexOf("phone") + 40);
                phone    = phone.Substring(phone.IndexOf("refid=17") + 10);
                phone    = phone.Remove(phone.IndexOf("<"));
                ac.Phone = phone;
                string birthday = htmlcontent.Substring(htmlcontent.IndexOf("birthday") + 40);
                birthday    = birthday.Substring(birthday.IndexOf("top") + 10);
                birthday    = birthday.Substring(birthday.IndexOf(">") + 1);
                birthday    = birthday.Remove(birthday.IndexOf("<"));
                ac.Birthday = birthday;
                string gender = htmlcontent.Substring(htmlcontent.IndexOf("gender") + 40);
                gender = gender.Substring(gender.IndexOf("top") + 10);
                gender = gender.Substring(gender.IndexOf(">") + 1);
                gender = gender.Remove(gender.IndexOf("<"));
                ac.Sex = gender;
                string idimagelink = htmlcontent.Substring(htmlcontent.IndexOf("/photo.php?fbid=") + 16);
                idimagelink = idimagelink.Remove(idimagelink.IndexOf("&"));
                web1.Navigate("mobile.facebook.com/" + idimagelink);
                while (web1.ReadyState != WebBrowserReadyState.Complete)
                {
                    Application.DoEvents();
                }
                string htmlcontent1 = web1.DocumentText;
                string imagelink    = htmlcontent1.Substring(htmlcontent1.IndexOf("https://z-p3-scontent"));
                imagelink    = imagelink.Remove(imagelink.IndexOf("\""));
                imagelink    = imagelink.Replace("amp;", "");
                ac.ImageLink = imagelink;
            }
            return(ac);
        }