protected void btn_add_user_Click(object sender, EventArgs e) { string username = txt_add_user.Text; string password = txt_add_pass.Text; string ten = txt_add_ten.Text; string gioitinh = Drop_Gioitinh.SelectedValue.ToString(); int maquyen = 1; string th = Drop_thang.SelectedValue.ToString(); string ng = Drop_ngay.SelectedValue.ToString(); string nam = txt_namsinh.Text; string ns = th + "/" + ng + "/" + nam; string email = txt_add_mail.Text; string mail = Drop_mail.SelectedValue.ToString(); string m = email + "@" + mail; string hochieu = txt_add_chungminh.Text; String filePath = "~/img_user/" + FileUp_hinhuser.FileName; FileUp_hinhuser.SaveAs(MapPath(filePath)); if (password.Length >= 6) { string insert = "insert into UserDaTa (TenDangNhap,MatKhau,MaQuyen,HoTen,CMT,Email,Hinh,Gioitinh,NamSinh) Values (N'" + username + "',N'" + password + "',N'" + maquyen + "',N'" + ten + "',N'" + hochieu + "',N'" + m + "',N'" + FileUp_hinhuser.FileName + "',N'" + gioitinh + "',N'" + ns + "')"; con.Open(); SqlCommand cmdd = new SqlCommand(insert, con); cmdd.ExecuteNonQuery(); con.Close(); Response.Redirect("QL_User.aspx?Us=Xem"); } else { Response.Write("<script>alert('Mật khẩu quá ngắn')</script>"); } }
protected void ImageButton1_Click(object sender, ImageClickEventArgs e) { string select = "select TenDangNhap from UserDaTa where TenDangNhap='" + txt_user.Text + "'"; con.Open(); SqlCommand cmd = new SqlCommand(select, con); SqlDataReader datareader = cmd.ExecuteReader(); if (datareader.HasRows == false) { con.Close(); string username = txt_user.Text; string password = txt_pass.Text; string repassword = txt_repass.Text; string ten = txt_hoten.Text; string gioitinh = Drop_Gioitinh.SelectedValue.ToString(); int maquyen = 1; string th = Drop_thang.SelectedValue.ToString(); string ng = Drop_ngay.SelectedValue.ToString(); string nam = txt_namsinh.Text; string ns = th + "/" + ng + "/" + nam; string email = txt_email.Text; string mail = Drop_mail.SelectedValue.ToString(); string m = email + "@" + mail; string hochieu = txt_hochieu.Text; String filePath = "~/img_user/" + FileUp_hinhuser.FileName; FileUp_hinhuser.SaveAs(MapPath(filePath)); if (password.Length >= 6) { string insert = "insert into UserDaTa (TenDangNhap,MatKhau,MaQuyen,HoTen,CMT,Email,Hinh,Gioitinh,NamSinh) Values (N'" + username + "',N'" + password + "',N'" + maquyen + "',N'" + ten + "',N'" + hochieu + "',N'" + m + "',N'" + FileUp_hinhuser.FileName + "',N'" + gioitinh + "',N'" + ns + "')"; con.Open(); SqlCommand cmdd = new SqlCommand(insert, con); cmdd.ExecuteNonQuery(); con.Close(); Session.Add("DangNhap", txt_user.Text); Response.Redirect("Home.aspx"); } else { Response.Write("<script>alert('Mật khẩu quá ngắn')</script>"); } } else { con.Close(); Response.Write("<script>alert('Tài khoản đã tồn tại')</script>"); txt_user.Text = ""; } }