Esempio n. 1
0
 protected void Grid_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     if (e.CommandName.Equals("Xoa"))
     {
         DBTinh.Delete(e.CommandArgument.ToString());
         alert = new Alert("info", "Thành công", "Xóa thành công");
         BindData();
         ResetForm();
     }
     else if(e.CommandName.Equals("Sua"))
     {
         SqlCommand cmd = new SqlCommand("SELECT MaTinh,TenTinh FROM [Tinh] WHERE MaTinh=@matinh", DB.GetConnection());
         cmd.Parameters.AddWithValue("@matinh", e.CommandArgument.ToString());
         SqlDataReader reader = cmd.ExecuteReader();
         if (reader.Read())
         {
             txtMaTinh.Text = reader["MaTinh"].ToString();
             txtTenTinh.Text = reader["TenTinh"].ToString();
             ViewState["OldID"] = reader["MaTinh"].ToString();
             GridViewRow row = (GridViewRow)((Control)e.CommandSource).NamingContainer;
             selectHandler.SelectRow(row.RowIndex);
             Title = "Selected " + row.RowIndex;
         }
         reader.Close();
         btnAdd.Visible = false;
         btnUpdate.Visible = true;
         btnCancel.Visible = true;
     }
 }
Esempio n. 2
0
 private bool ValidateForm()
 {
     if (txtUsername.Text.Length < 4)
     {
         alert = new Alert("danger", "Lỗi", "Username tối thiểu 4 kí tự");
         return false;
     }
     else if (txtEmail.Text.Length == 0)
     {
         alert = new Alert("danger", "Lỗi", "Không được để trống E-Mail");
         return false;
     }
     else if (txtPassword.Text.Length < 6)
     {
         alert = new Alert("danger", "Lỗi", "Mật khẩu tối thiểu 6 kí tự");
         return false;
     }
     else if (txtPassword.Text != txtRePassword.Text)
     {
         alert = new Alert("danger", "Lỗi", "Mật khẩu nhập lại không khớp");
         return false;
     }
     else if (txtFullName.Text.Length == 0)
     {
         alert = new Alert("danger", "Lỗi", "Không được để trống họ tên");
         return false;
     }
     return true;
 }
Esempio n. 3
0
 private bool ValidateForm()
 {
     if (txtMaSinhVien.Text.Length != 10)
     {
         alert = new Alert("danger", "Lỗi", "Mã sinh viên phải có 10 kí tự");
         return false;
     }
     else if (txtHoTen.Text.Length == 0)
     {
         alert = new Alert("danger", "Lỗi", "Chưa nhập tên sinh viên");
         return false;
     }
     else if (radGioiTinh.SelectedValue == "")
     {
         alert = new Alert("danger", "Lỗi", "Chưa chọn giới tính");
         return false;
     }
     else if (dropTinh.SelectedIndex == -1)
     {
         alert = new Alert("danger", "Lỗi", "Chưa chọn quê quán");
         return false;
     }
     else if (dropKhoa.SelectedIndex == -1)
     {
         alert = new Alert("danger", "Lỗi", "Chưa chọn khoa");
         return false;
     }
     else if (dropLop.SelectedIndex == -1)
     {
         alert = new Alert("danger", "Lỗi", "Chưa chọn lớp");
         return false;
     }
     return true;
 }
Esempio n. 4
0
File: DB.cs Progetto: D8CNPM/ASP.NET
 public static void ExceptionInfo(SqlException exc,ref Alert al)
 {
     switch (exc.Number)
     {
         case ERR_KEYCONFLICT:
             al = new Alert("danger", "Lỗi dữ liệu", "Khóa chính bị trùng!");
             break;
         default:
             al = new Alert("warning", "Lỗi SQL " + exc.Number, exc.Message);
             break;
     }
 }
Esempio n. 5
0
 private bool ValidateForm()
 {
     if (txtMaTinh.Text.Length == 0)
     {
         alert = new Alert("danger", "Lỗi", "Chưa nhập mã tỉnh");
         return false;
     }
     else if (txtTenTinh.Text.Length == 0)
     {
         alert = new Alert("danger", "Lỗi", "Chưa nhập tên tỉnh");
         return false;
     }
     return true;
 }
Esempio n. 6
0
 protected void DoLogin(object sender, EventArgs e)
 {
     String username = Username.Text, password = Password.Text;
     if (!checkLogin(username,password))
     {
         alert = new Alert("warning","Đăng nhập sai", "Thông tin đăng nhập chưa chính xác!");
     }
     else
     {
         
         Response.BufferOutput = true;
         alert = new Alert("success", "Thành công", "Đăng nhập thành công!");
         Session["Username"] = username;
         Response.Redirect("/Default.aspx");
     }
 }
Esempio n. 7
0
 protected void btnAdd_Click(object sender, EventArgs e)
 {
     if (!ValidateForm())
     {
         return;
     }
     try
     {
         DBUser.Insert(txtUsername.Text, txtPassword.Text, txtEmail.Text, txtFullName.Text);
         alert = new Alert("info", "Thành công", "Thêm user thành công");
         BindGrid();
     }catch (SqlException ex)
     {
         DB.ExceptionInfo(ex, ref alert);
     }
 }
Esempio n. 8
0
 protected void btnAdd_Click(object sender, EventArgs e)
 {
     if (!ValidateForm())
     {
         return;
     }
     try
     {
         DBTinh.Insert(txtMaTinh.Text, txtTenTinh.Text);
         alert = new Alert("success", "Thành công", "Tỉnh " + txtTenTinh.Text + " đã được thêm vào");
         BindData();
         ResetForm();
     }catch (SqlException ex)
     {
         DB.ExceptionInfo(ex, ref alert);
     }
     txtMaTinh.Text = "";
     txtTenTinh.Text = "";
 }
Esempio n. 9
0
 protected void btnUpdate_Click(object sender, EventArgs e)
 {
     try {
         DBTinh.Update(ViewState["OldID"].ToString(), txtMaTinh.Text, txtTenTinh.Text);
         alert = new Alert("success", "Thành công", "Tỉnh " + txtTenTinh.Text + " đã được cập nhật");
         ResetForm();
         BindData();
     }
     catch (SqlException ex)
     {
         DB.ExceptionInfo(ex, ref alert);
     }
 }
Esempio n. 10
0
 protected void Grid_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     if (e.CommandName.Equals("Xoa"))
     {
         try { 
             DBUser.Delete(Convert.ToInt32(e.CommandArgument.ToString()));
             alert = new Alert("info", "Thành công", "Xóa thành công");
             BindGrid();
             ResetForm();
         }
         catch (SqlException exc)
         {
             DB.ExceptionInfo(exc, ref alert);
         }
     }
     else if(e.CommandName.Equals("Sua"))
     {
         LoadForm((GridViewRow)((Control)e.CommandSource).NamingContainer,e.CommandArgument.ToString());
     }
 }
Esempio n. 11
0
 protected void btnUpdate_Click(object sender, EventArgs e)
 {
     if (!ValidateForm())
         return;
     try {
         DBUser.Update((int)ViewState["ID"],txtUsername.Text,txtPassword.Text,txtEmail.Text,txtFullName.Text);
         alert = new Alert("success", "Thành công", "User \"" + txtUsername.Text + "\" đã được cập nhật");
         ResetForm();
         BindGrid();
     }
     catch (SqlException ex)
     {
         DB.ExceptionInfo(ex, ref alert);
     }
 }
Esempio n. 12
0
 protected void btnUpdate_Click(object sender, EventArgs e)
 {
     if (!ValidateForm())
         return;
     try {
         DBSinhVien.Update(ViewState["OldID"].ToString(), txtMaSinhVien.Text, txtHoTen.Text, radGioiTinh.SelectedValue, dropTinh.SelectedValue, dropLop.SelectedValue);
         alert = new Alert("success", "Thành công", "Sinh viên \"" + txtHoTen.Text + "\" đã được cập nhật");
         ResetForm();
         BindGrid();
     }
     catch (SqlException ex)
     {
         DB.ExceptionInfo(ex, ref alert);
     }
 }
Esempio n. 13
0
 protected void btnAdd_Click(object sender, EventArgs e)
 {
     if (!ValidateForm())
     {
         return;
     }
     try
     {
         DBSinhVien.Insert(txtMaSinhVien.Text, txtHoTen.Text, radGioiTinh.SelectedValue, dropTinh.SelectedValue, dropLop.SelectedValue);
         alert = new Alert("info", "Thành công", "Thêm sinh viên thành công");
         BindGrid();
         ResetForm();
     }catch (SqlException ex)
     {
         DB.ExceptionInfo(ex, ref alert);
     }
 }