Esempio n. 1
0
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            Managerment_PageEntities db = new Managerment_PageEntities();
            string      sTenFile;
            int         idAccount     = Convert.ToInt32(Request.Params["idAccount"].ToString());
            User_Detail getOldNameImg = db.User_Detail.FirstOrDefault(x => x.idAccount == idAccount);
            string      imgAccountOld = getOldNameImg.imgAccount.ToString();

            if (imgAccountOld.Equals("default-avatar.jpg") == false)
            {
                string filePath = MapPath("~/img/customer/" + imgAccountOld);
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }
            }
            //Tách lấy tên tập tin
            sTenFile = FileUpload1.FileName;
            //Thực hiện chép tập tin lên thư mục Upload
            FileUpload1.SaveAs(MapPath("~/img/customer/" + sTenFile));
            lblNotice.Text = "Đã upload thành công";
            User_Detail acc_detail = db.User_Detail.FirstOrDefault(x => x.idAccount == idAccount);

            acc_detail.imgAccount = sTenFile;
            db.SaveChanges();
            LoadData();
        }
        protected void imbLogin_Click(object sender, ImageClickEventArgs e)
        {
            if (txtName.Text != "" && txtPass.Text != "")
            {
                string taikhoan             = txtName.Text;
                string matkhau              = getMd5Hash(txtPass.Text);
                Managerment_PageEntities db = new Managerment_PageEntities();
                int check = db.Users.Count(x => x.username == taikhoan && x.password == matkhau);

                if (check == 1)
                {
                    User        acc         = db.Users.FirstOrDefault(x => x.username == taikhoan);
                    int         idAccount   = Convert.ToInt32(acc.idAccount.ToString());
                    User_Detail acc_detail  = db.User_Detail.FirstOrDefault(x => x.idAccount == idAccount);
                    Boolean     checkStatus = Convert.ToBoolean(acc_detail.status.ToString());
                    if (checkStatus == true)
                    {
                        Session["idKhachHang"] = idAccount;
                        Response.Redirect("index.aspx");
                    }
                    else
                    {
                        txtError.Text = "Tài khoản của bạn đã bị Vô hiệu hóa!";
                    }
                }
                else
                {
                    txtError.Text = "Tài khoản và mật khẩu sai!";
                }
            }
            else
            {
                lbThongBao.Text = "Tên đăng nhập hoặc mật khẩu trống!";
            }
        }
Esempio n. 3
0
 protected void btnEditAccount_Click(object sender, EventArgs e)
 {
     try
     {
         int    idAccount            = Convert.ToInt32(Request.Params["idAccount"].ToString());
         string fullname             = txtFullname.Text;
         string DOB                  = txtDOB.Text;
         string Address              = txtAddress.Text;
         string Email                = txtEmail.Text;
         Managerment_PageEntities db = new Managerment_PageEntities();
         User_Detail user_detail     = db.User_Detail.FirstOrDefault(x => x.idAccount == idAccount);
         user_detail.fullname = fullname;
         user_detail.DOB      = Convert.ToDateTime(DOB);
         user_detail.Address  = Address;
         user_detail.Email    = Email;
         db.SaveChanges();
         lblNotice.Text = "Đã Cập nhật thông tin thành công!";
         LoadData();
     }
     catch
     {
         lblNotice.Text = "Thất Bại!";
         LoadData();
     }
 }
Esempio n. 4
0
        void LoadData()
        {
            int idAccount = Convert.ToInt32(Request.Params["idAccount"].ToString());
            Managerment_PageEntities db = new Managerment_PageEntities();
            User        acc             = db.Users.FirstOrDefault(x => x.idAccount == idAccount);
            User_Detail acc_detail      = db.User_Detail.FirstOrDefault(x => x.idAccount == idAccount);

            txtusername.Text = acc.username;
            txtFullname.Text = acc_detail.fullname;
            DateTime date      = Convert.ToDateTime(acc_detail.DOB);
            string   formatted = date.ToString("yyyy-MM-dd");

            txtDOB.Text     = formatted;
            txtAddress.Text = acc_detail.Address;
            txtEmail.Text   = acc_detail.Email;
            img.ImageUrl    = "img/customer/" + acc_detail.imgAccount;
            List <ListFavourite> listidFavourties = db.ListFavourites.Where(x => x.idAccount == idAccount).ToList();
            List <Comic>         viewList         = new List <Comic>();

            foreach (ListFavourite items in listidFavourties)
            {
                int   idComic = Convert.ToInt32(items.idComic.ToString());
                Comic comic   = db.Comics.FirstOrDefault(x => x.idComic == idComic);
                viewList.Add(comic);
            }
            dgvListFavourite.DataSource = viewList;
            dgvListFavourite.DataBind();
        }
        protected void CreateUser_Click(object sender, EventArgs e)
        {
            string username             = txtusername.Text;
            string password             = getMd5Hash(txtpassword.Text);
            string fullname             = txtFullname.Text;
            string DOB                  = txtDOB.Text;
            string Address              = txtAddress.Text;
            string Email                = txtEmail.Text;
            Managerment_PageEntities db = new Managerment_PageEntities();
            User newUser                = new User();

            newUser.username = username;
            newUser.password = password;
            db.Users.Add(newUser);
            db.SaveChanges();
            User        acc            = db.Users.FirstOrDefault(x => x.username == username);
            int         idAccount      = acc.idAccount;
            User_Detail newuser_Detail = new User_Detail();

            newuser_Detail.idAccount  = idAccount;
            newuser_Detail.fullname   = fullname;
            newuser_Detail.DOB        = Convert.ToDateTime(DOB);
            newuser_Detail.Address    = Address;
            newuser_Detail.Email      = Email;
            newuser_Detail.status     = false;
            newuser_Detail.imgAccount = "default-avatar.jpg";
            db.User_Detail.Add(newuser_Detail);
            db.SaveChanges();
            LoadData();
        }
        protected void btnXoa_Command(object sender, CommandEventArgs e)
        {
            int idAccount = int.Parse(e.CommandArgument.ToString());
            Managerment_PageEntities db = new Managerment_PageEntities();
            User_Detail obj             = db.User_Detail.FirstOrDefault(x => x.idAccount == idAccount);

            db.User_Detail.Remove(obj);
            db.SaveChanges();
            User objAcc = db.Users.FirstOrDefault(x => x.idAccount == idAccount);

            db.Users.Remove(objAcc);
            db.SaveChanges();
            LoadData();
        }
        protected void btnUpdateStatus_Command(object sender, CommandEventArgs e)
        {
            int idAccount = int.Parse(e.CommandArgument.ToString());
            Managerment_PageEntities db   = new Managerment_PageEntities();
            User_Detail acc_detail        = db.User_Detail.FirstOrDefault(x => x.idAccount == idAccount);
            Boolean     status            = Convert.ToBoolean(acc_detail.status.ToString());
            Boolean     statusafterupdate = true;

            if (status == true)
            {
                statusafterupdate = false;
            }
            else
            {
                statusafterupdate = true;
            }
            acc_detail.status = statusafterupdate;
            db.SaveChanges();
            LoadData();
        }