예제 #1
0
        public void Create(Thanhvien_Model model)
        {
            var data = Connect_Enttity.Thanhviens.FirstOrDefault(x => x.id == model.id);

            if (data == null)
            {
                var entity = new Thanhvien();

                entity.Taikhoan   = model.Taikhoan;
                entity.Matkhau    = model.Matkhau;
                entity.Hoten      = model.Hoten;
                entity.Ngaysinh   = model.Ngaysinh;
                entity.Gioitinh   = model.Gioitinh;
                entity.Diachi     = model.Diachi;
                entity.SDT        = model.SDT;
                entity.Email      = model.Email;
                entity.Actice     = (bool)(model.Actice);
                entity.thutu      = (int)(model.thutu);
                entity.CreateDate = DateTime.Now;

                Connect_Enttity.Thanhviens.Add(entity);
                Connect_Enttity.SaveChanges();
                Dispose();
            }
        }
예제 #2
0
        public static int Insert(Thanhvien tv)
        {
            using (SqlConnection cnn = ConnectDataBase())
            {
                SqlCommand cmd = new SqlCommand("sp_Thanhvien_Insert", cnn);
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("@email", tv.Email);
                cmd.Parameters.AddWithValue("@matkhau", tv.Matkhau);
                cmd.Parameters.AddWithValue("@hoten", tv.Hoten);
                cmd.Parameters.AddWithValue("@diachi", tv.Diachi);
                cmd.Parameters.AddWithValue("@sdt", tv.Sdt);
                cmd.Parameters.AddWithValue("@kichhoat", tv.Kichhoat);
                cmd.Parameters.AddWithValue("@makichhoat", tv.Makichhoat);
                cmd.Parameters.AddWithValue("@diemtichluy", tv.Diemtichluy);

                cmd.Parameters.Add("@check", SqlDbType.Int).Direction = ParameterDirection.ReturnValue;

                try
                {
                    cmd.ExecuteNonQuery();
                }
                catch (Exception)
                {
                }
                int check = (int)cmd.Parameters["@check"].Value;
                return(check);
            }
        }
예제 #3
0
    public static void SendMail(Thanhvien tv)
    {
        MailMessage mail = new MailMessage();

        mail.To.Add(tv.Email);
        mail.From       = new MailAddress("*****@*****.**");
        mail.Subject    = "Kích hoạt tài khoản của bạn tại Men's Shop";
        mail.Body       = "Mã kích hoạt của bạn là : http://mens.somee.com/kich-hoat.aspx?key=" + HttpContext.Current.Server.UrlEncode(tv.Makichhoat);
        mail.IsBodyHtml = true;

        SmtpClient client = new SmtpClient("smtp.gmail.com", 587);

        client.EnableSsl = true;
        NetworkCredential credent = new NetworkCredential("*****@*****.**", "/?id=g00gle.");

        client.UseDefaultCredentials = true;
        client.Credentials           = credent;

        try
        {
            client.Send(mail);
        }
        catch (Exception)
        {
            throw;
        }
    }
예제 #4
0
    protected void btn_chinhsua_submit_Click(object sender, EventArgs e)
    {
        if (txt_matkhau.Value.Length < 8)
        {
            check_matkhau.Visible = true;
        }

        if (Regex.IsMatch(txt_hoten.Value.ToString(), @"[`1234567890-=;',./~!@#$%^&*()_+{}:|<>?]") || txt_hoten.Value == "")
        {
            check_hoten.Visible = true;
        }

        if (!Regex.IsMatch(txt_sdt.Value, @"^[0-9]+$") || txt_sdt.Value == "")
        {
            if (txt_sdt.Value.Length == 10 || txt_sdt.Value.Length == 11)
            {
                check_sdt.Visible = false;
            }
            else
            {
                check_sdt.Visible = true;
            }
        }

        if (txt_diachi.Value == "")
        {
            check_diachi.Visible = true;
        }

        if (check_matkhau.Visible == false && check_hoten.Visible == false && check_sdt.Visible == false && check_diachi.Visible == false)
        {
            Thanhvien tv = new Thanhvien();
            tv.Email   = function.email;
            tv.Matkhau = function.Mahoa(txt_matkhau.Value);
            tv.Hoten   = txt_hoten.Value;
            tv.Diachi  = txt_diachi.Value;
            tv.Sdt     = txt_sdt.Value;

            try
            {
                ThanhvienBUS.Thanhvien_Update(tv);
                Response.Write("<script>alert('Cập nhật tài khoản thành công')</script>");
                function.hoten  = txt_hoten.Value;
                function.diachi = txt_diachi.Value;
                function.sdt    = txt_sdt.Value;
            }
            catch (Exception)
            {
                Response.Write("<script>alert('Cập nhật tài khoản thất bại')</script>");
            }
        }
    }
예제 #5
0
        private void btnXoa_Click(object sender, EventArgs e)
        {
            DialogResult xoa = MessageBox.Show("Đồng ý xóa?", "Cảnh báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

            if (xoa == DialogResult.Yes)
            {
                var context = new Dtb_NhaSachContext();
                var delete  = new Thanhvien()
                {
                    MaTv = int.Parse(this.dgvMember.CurrentRow.Cells[0].Value.ToString().Trim()),
                };
                context.Remove <Thanhvien>(delete);
                context.SaveChanges();
                refreshControl();
                loadMember();
            }
        }
예제 #6
0
        private void btnSua_Click(object sender, EventArgs e)
        {
            if (loiNhap())
            {
                return;
            }
            var context = new Dtb_NhaSachContext();
            var edit    = new Thanhvien()
            {
                MaTv = int.Parse(this.dgvMember.CurrentRow.Cells[0].Value.ToString().Trim()),
            };

            edit.TenTv       = this.txtTentv.Text.Trim();
            edit.NgaySinh    = this.dtpNgaySinh.Value;
            edit.DiaChi      = this.txtDiaChi.Text.Trim();
            edit.DiemTichLuy = int.Parse(this.txtDiem.Text.Trim());
            edit.Sdt         = this.txtSdt.Text.Trim();
            context.Update <Thanhvien>(edit);
            context.SaveChanges();
            refreshControl();
            loadMember();
        }
예제 #7
0
        public static void Update(Thanhvien tv)
        {
            using (SqlConnection cnn = ConnectDataBase())
            {
                SqlCommand cmd = new SqlCommand("sp_Thanhvien_Update", cnn);
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("@email", tv.Email);
                cmd.Parameters.AddWithValue("@matkhau", tv.Matkhau);
                cmd.Parameters.AddWithValue("@hoten", tv.Hoten);
                cmd.Parameters.AddWithValue("@diachi", tv.Diachi);
                cmd.Parameters.AddWithValue("@sdt", tv.Sdt);

                try
                {
                    cmd.ExecuteNonQuery();
                }
                catch (Exception)
                {
                }
            }
        }
예제 #8
0
        private void btnThem_Click(object sender, EventArgs e)
        {
            if (loiNhap())
            {
                return;
            }

            var context = new Dtb_NhaSachContext();
            int i       = this.dgvMember.Rows.Count;
            var tv      = new Thanhvien()
            {
                MaTv        = int.Parse(this.dgvMember.Rows[i - 1].Cells[0].Value.ToString().Trim()) + 1,
                TenTv       = this.txtTentv.Text.Trim(),
                Sdt         = this.txtSdt.Text.Trim(),
                NgaySinh    = this.dtpNgaySinh.Value,
                DiaChi      = this.txtDiaChi.Text.Trim(),
                DiemTichLuy = int.Parse(this.txtDiem.Text.Trim()),
            };

            context.Thanhviens.Add(tv);
            context.SaveChanges();
            refreshControl();
            loadMember();
        }
예제 #9
0
 public static void Thanhvien_Update(Thanhvien tv)
 {
     ThanhvienDAO.Update(tv);
 }
예제 #10
0
 public static int Thanhvien_Insert(Thanhvien tv)
 {
     return(ThanhvienDAO.Insert(tv));
 }
예제 #11
0
    protected void btn_dangki_submit_Click(object sender, EventArgs e)
    {
        if (Regex.IsMatch(txt_hoten.Value.ToString(), @"[`1234567890-=;',./~!@#$%^&*()_+{}:|<>?]") || txt_hoten.Value == "")
        {
            check_hoten.Visible = true;
        }
        if (!Regex.IsMatch(txt_email.Value, @"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$"))
        {
            check_email.Visible = true;
        }
        if (txt_matkhau.Value.Length < 8)
        {
            check_matkhau.Visible = true;
        }
        if (txt_nhaplaimatkhau.Value.Equals(txt_matkhau.Value) == false)
        {
            check_nhaplaimatkhau.Visible = true;
        }
        if (!Regex.IsMatch(txt_sdt.Value, @"^[0-9]+$") || txt_sdt.Value == "")
        {
            if (txt_sdt.Value.Length == 10 || txt_sdt.Value.Length == 11)
            {
                check_sdt.Visible = false;
            }
            else
            {
                check_sdt.Visible = true;
            }
        }
        if (txt_diachi.Value == "")
        {
            check_diachi.Visible = true;
        }

        if (check_email.Visible == false && check_hoten.Visible == false && check_matkhau.Visible == false && check_nhaplaimatkhau.Visible == false && check_sdt.Visible == false && check_diachi.Visible == false)
        {
            Thanhvien tv = new Thanhvien();
            tv.Email       = txt_email.Value;
            tv.Matkhau     = function.Mahoa(txt_matkhau.Value).ToString();
            tv.Hoten       = txt_hoten.Value;
            tv.Diachi      = txt_diachi.Value;
            tv.Sdt         = txt_sdt.Value;
            tv.Kichhoat    = "chua kich hoat";
            tv.Makichhoat  = function.Mahoa(txt_email.Value);
            tv.Diemtichluy = 0;

            try
            {
                int check = ThanhvienBUS.Thanhvien_Insert(tv);
                if (check == 0)
                {
                    function.SendMail(tv);
                    Response.Write("<script>alert('Đăng kí thành công. Bạn cần truy cập và mail để kích hoạt tài khoản và sử dụng')</script>");
                }
                else
                {
                    Response.Write("<script>alert('Email này đã có người sử dụng')</script>");
                }
            }
            catch (Exception ex)
            {
                Response.Write("<script>" + ex.Message + "</script>");
            }
        }
    }