/// <summary> /// Insert infomation for users /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnAddRow_OnClick(object sender, EventArgs e) { try { ltError.Text = string.Empty; DataUser = UserRepository.GetInstance(); var name = txtName.Text.Trim(); var email = txtEmail.Text.Trim(); var password = txtPass.Text.Trim(); var address = txtAddress.Text.Trim(); var role = Convert.ToInt32(ddlRole.SelectedValue); if (DataUser.CheckEmail(email) == false) { DataUser.InsertUser(name, email, password, address, role); gvInfomationUser.EditIndex = -1; BindDataToGridView(); txtEmail.Text = ""; txtName.Text = ""; txtAddress.Text = ""; txtPass.Text = ""; ddlRole.SelectedValue = "none"; ltError.Text = "Insert user successfully"; } else { ltError.Text = "Insert user not successfully"; } } catch (Exception ex) { ltError.Text = ex.Message; } }
/// <summary> /// Update information Users /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void InfomationUser_OnRowUpdating(object sender, GridViewUpdateEventArgs e) { try { ltError.Text = string.Empty; DataUser = UserRepository.GetInstance(); var row = gvInfomationUser.Rows[e.RowIndex]; var lbUserId = (Label)row.FindControl("lbUserID"); var id = Convert.ToInt32(lbUserId.Text); var name = ((TextBox)(row.Cells[1].Controls[0])).Text; var email = ((TextBox)(row.Cells[2].Controls[0])).Text; var password = ((TextBox)(row.Cells[3].Controls[0])).Text; var address = ((TextBox)(row.Cells[4].Controls[0])).Text; var roles = ((TextBox)(row.Cells[5].Controls[0])).Text; var role = Convert.ToInt32(roles); if (DataUser.CheckEmail(email) == false) { DataUser.UpdateUser(id, name, email, password, address, role); gvInfomationUser.EditIndex = -1; BindDataToGridView(); ltError.Text = "Update Successfully"; } else { ltError.Text = "The email already exists or have a used"; } } catch (Exception ex) { ltError.Text = ex.Message; } }