示例#1
0
 protected void btGuiLienHe_Click(object sender, EventArgs e)
 {
     try
     {
         CaptchaControlLienHe.ValidateCaptcha(txtCapcha.Text.Trim());
         if (CaptchaControlLienHe.UserValidated)
         {
             //Thanh cong xuat ra cai label
             if (Page.IsValid)//If tat ca dATA hop le
             {
                 bool   result = false;
                 LienHe data   = GetData();
                 result = LienHe.Add(data);
                 lbResultThongBao.Text = result ? "Cảm ơn bạn đã góp ý. Chúc các bạn một ngày may mắn" : "Gửi góp ý không thành công";
                 if (result)
                 {
                     Reset();
                 }
             }
         }
         else
         {
             //that bai
             lbResult.Text = "Nhập sai mã bảo vệ";
         }
     }
     catch (SqlException sql)
     {
         lbResult.Text = "" + sql.Message;
     }
     catch (Exception ex)
     {
         lbResult.Text = "" + ex.Message;
     }
 }
示例#2
0
        private void BtnDongY_Click(object sender, EventArgs e)
        {
            String tenGoi      = txtTenGoi.Text;
            String email       = txtEmail.Text;
            String soDienThoai = txtSDT.Text;
            String diaChi      = txtDiaChi.Text;

            if (tenGoi == "")
            {
                errorProvider.SetError(txtTenGoi, "Vui lòng nhập tên liên hệ");
                txtTenGoi.Focus();
                return;
            }
            else if (soDienThoai == "")
            {
                errorProvider.SetError(txtSDT, "Vui lòng nhập số điện thoại");
                txtSDT.Focus();
                return;
            }
            else if (email == "")
            {
                errorProvider.SetError(txtEmail, "Vui lòng nhập email");
                txtEmail.Focus();
                return;
            }
            else if (diaChi == "")
            {
                errorProvider.SetError(txtDiaChi, "Vui lòng nhập địa chỉ");
                txtDiaChi.Focus();
                return;
            }
            else if (!LienHe.IsValidEmail(email))
            {
                errorProvider.SetError(txtEmail, "Email không đúng định dạng");
                txtEmail.Focus();
                return;
            }
            else if (!LienHe.IsValidPhone(soDienThoai))
            {
                errorProvider.SetError(txtSDT, "Số điện thoại không đúng định dạng");
                txtSDT.Focus();
                return;
            }
            else
            {
                LienHe lh = LienHe.GetLienHe(tenGoi);
                if (lh != null)
                {
                    //sua
                    //MessageBox.Show("Tên liên hệ đã tồn tại", "Thông báo", MessageBoxButtons.OK,
                    //MessageBoxIcon.Information);
                    if (MessageBox.Show("Liên hệ này đã tồn tại. Bạn có muốn sửa liên hệ này không?", "Thông báo",
                                        MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                    {
                        LienHe.Edit(new LienHe
                        {
                            TenGoi  = tenGoi,
                            Email   = email,
                            SDT     = soDienThoai,
                            DiaChi  = diaChi,
                            TenNhom = tenNhom
                        });
                        this.Close();
                    }
                }
                else
                {
                    LienHe.Add(new LienHe
                    {
                        TenGoi  = tenGoi,
                        Email   = email,
                        SDT     = soDienThoai,
                        DiaChi  = diaChi,
                        TenNhom = tenNhom
                    });
                    //MessageBox.Show("Đã thêm nhóm thành công", "Thông báo", MessageBoxButtons.OK,
                    //MessageBoxIcon.Information);
                    ThongBaoLienHe f = new ThongBaoLienHe();
                    f.ShowDialog();
                    this.Close();
                }
            }
        }