コード例 #1
0
ファイル: AddUser.aspx.cs プロジェクト: dsbissett/chonet
 protected void btnLuu_ServerClick(object sender, EventArgs e)
 {
     try
     {
         NguoiDung nguoidung = new NguoiDung();
         if (ACTION == "ADD")
         {
             if (nguoidung.CheckExistTenTruyCap(0, txtTaiKhoan.Value.Trim()) != true)
             {
                 nguoidung.InsertFields(txtHoVaTen.Value, txtTaiKhoan.Value, txtMatKhau.Value,
                                        Convert.ToDateTime(wdcNgaySinh.Value),
                                        (rbtNam.Checked ? true : false), txtEmail.Value, null, chkKichHoat.Checked,
                                        txtDienThoaiDiDong.Value, txtDienThoaiCoDinh.Value,
                                        Convert.ToInt32(ddlLoaiNguoiDung.SelectedValue), null, txtYM.Value, null, 1,
                                        null, null, null, null);
             }
             else
             {
                 lblTonTaiTenTruyCap.Text = "Tên truy cập đã tồn tại";
                 //ValidationSummary1.HeaderText = "Có lỗi xảy ra";
                 return;
             }
         }
         else if (ACTION == "EDIT")
         {
             if (nguoidung.CheckExistTenTruyCap(id, txtTaiKhoan.Value.Trim()) != true)
             {
                 nguoidung.UpdateFields(id, txtHoVaTen.Value, txtTaiKhoan.Value, null, (DateTime) wdcNgaySinh.Value,
                                        rbtNam.Checked ? true : false, txtEmail.Value, null, chkKichHoat.Checked,
                                        txtDienThoaiDiDong.Value, txtDienThoaiCoDinh.Value,
                                        Convert.ToInt32(ddlLoaiNguoiDung.SelectedValue), null, txtYM.Value, null,
                                        null, null, null, null, null);
                 //nguoidung.UpdateFields(id, txtHoVaTen.Value, null, txtMatKhau.Value, null,
                 //    null, txtEmail.Value, txtDienThoaiDiDong.Value, txtDienThoaiCoDinh.Value,
                 //    null, "", chkKichHoat.Checked, 1, "", 0, "", true);
             }
             else
             {
                 lblTonTaiTenTruyCap.Text = "Tên truy cập đã tồn tại";
                 //ValidationSummary1.HeaderText = "Có lỗi xảy ra";
                 return;
             }
         }
         string strScript = "<script language='JavaScript'>" + "window.parent.Refresh();</script>";
         ClientScript.RegisterStartupScript(Type.GetType("System.String"), "Refresh", strScript);
     }
     catch (Exception ex)
     {
         Response.Write(ex.ToString());
     }
 }
コード例 #2
0
ファイル: Register.aspx.cs プロジェクト: dsbissett/chonet
    protected void btnDangKy_Click(object sender, EventArgs e)
    {
        try
        {
            NguoiDung nguoidung = new NguoiDung();
            if (nguoidung.CheckExistTenTruyCap(0, txtTaiKhoan.Text))
            {
                lblErr.Text = "Tên truy cập đã tồn tại!";
            }
            else if (CheckEmail() == false)
            {
                lblEmailError.Text = "Email đã được sử dụng!";
            }
            else
            {
                lblErr.Text = "";
                int intLoaiNguoiDung = rbtUser.Checked ? 1 : 2;
                bool? blGioiTinh = null;
                if (rbtGioiTinhNam.Checked || rbtGioiTinhNu.Checked)
                {
                    blGioiTinh = rbtGioiTinhNam.Checked;
                }

                try
                {
                    //if (intLoaiNguoiDung == 1)
                    //{
                    //    nguoidung.InsertFields(txtHoVaTen.Text, txtTaiKhoan.Text, txtMatKhau.Text, DateTime.Parse(wdcNgaySinh.Value.ToString()),
                    //        blGioiTinh, txtEmail.Text, null, true, txtDienThoaiDiDong.Text,
                    //        null, intLoaiNguoiDung, txtDiaChi.Text, txtYM.Text,
                    //        txtSoChungMinhThu.Text, null, null, null, null, null);
                    //}
                    //else
                    //{
                    randomString = GenerateActiveCode();
                    ndid = nguoidung.InsertFields(txtHoVaTen.Text, txtTaiKhoan.Text, txtMatKhau.Text,
                                                  DateTime.Parse(wdcNgaySinh.Value.ToString()),
                                                  blGioiTinh, txtEmail.Text, randomString, false,
                                                  txtDienThoaiDiDong.Text,
                                                  null, intLoaiNguoiDung, txtDiaChi.Text, txtYM.Text,
                                                  txtSoChungMinhThu.Text, null, null, null, null, null);
                    //}
                }
                catch (Exception ex)
                {
                    Response.Redirect("message.aspx?msg=" + ex.Message);
                    return;
                }

                string template =
                    Common.GetEmailHTMLTemplate(Server.MapPath(".") +
                                                ConfigurationManager.AppSettings["TemplateKichHoat"]);
                string subject = "Kích hoạt tài khoản từ CHONET.VN";
                Common.SendActiveMail(txtEmail.Text, subject, template, txtHoVaTen.Text, ndid.ToString(), randomString,
                                      txtTaiKhoan.Text, txtMatKhau.Text, txtEmail.Text);
                Response.Redirect("Inform.aspx?type=user&name=" + txtHoVaTen.Text + "&email=" + txtEmail.Text, false);
                return;
            }
        }
        catch (Exception ex)
        {
            Response.Redirect("message.aspx?msg=" + ex.Message.Replace("\r\n", ""), false);
            return;
        }
    }