protected void btnSave_Click(object sender, EventArgs e) { try { int count = userRole.CheckRoleExistance((lblId.Text == string.Empty) ? 0 : int.Parse(lblId.Text), txtRole.Text, isNewEntry); if (count > 0) { Alert.Show("Company name already exists. "); return; } userRole = new UserRole(); userRole.CompanyId = 1; userRole.Id = (lblId.Text == string.Empty) ? 0 : int.Parse(lblId.Text); userRole.Role = txtRole.Text; userRole.Description = txtDescription.Text; int succes = 0; if (isNewEntry) { succes = userRole.InsertUserRole(); } else { userRole.CompanyId = 1; succes = userRole.UpdateUserRole(); } if (succes == 0) { Alert.Show("Create userRole information was not successfull."); return; } else { Alert.Show("UserRole information created succssfully."); this.ClearControls(); this.LoadUserRoleGrid(); } } catch (Exception ex) { Alert.Show("Error during userRole information save. Error: " + ex.Message); } }
protected void dgvUserRole_ItemCommand(object sender, GridCommandEventArgs e) { if (e.CommandName == "btnSelect") { GridDataItem item = (GridDataItem)e.Item; lblId.Text = item["colId"].Text; txtRole.Text = item["colRole"].Text.Trim(); txtDescription.Text = (item["colDesc"].Text == " ") ? "" : item["colDesc"].Text.Trim(); isNewEntry = false; } else if (e.CommandName == "btnDelete") { try { GridDataItem item = (GridDataItem)e.Item; lblId.Text = item["colId"].Text; int id = int.Parse(lblId.Text); UserRole userRolesDelete = new UserRole(); int success = userRolesDelete.DeleteUserRoleById(id); if (success == 0) { Alert.Show("Something is going Wrong!!!!"); } else { Alert.Show("Successfully Deleted!!"); this.LoadUserRoleGrid(); } } catch (Exception ex) { Alert.Show("Error happen during delete attendance data. Error: " + ex.Message); } } }
private void LoadUserRoleGrid() { try { List<UserRole> roleList = new UserRole().GetAllUserRole(0); if (roleList.Count == 0) { roleList.Add(new UserRole()); dgvUserRole.Visible = false; } else { dgvUserRole.Visible = true; dgvUserRole.DataSource = roleList; dgvUserRole.DataBind(); } } catch (Exception ex) { Alert.Show("Error in method 'LoadLeaveDetailsGrid'. Error: " + ex.Message); } }
private void ClearControls() { lblId.Text = ""; txtRole.Text = ""; txtDescription.Text = ""; isNewEntry = true; userRole = new UserRole(); }
private void LoadRoleListCombo() { List<UserRole> lstUserRole = new UserRole().GetAllUserRole(0); lstUserRole.Insert(0, new UserRole()); rdropList.DataTextField = "Role"; rdropList.DataValueField = "Id"; rdropList.DataSource = lstUserRole; rdropList.DataBind(); rdropList.SelectedIndex = 0; }
private void loadRoleListBox() { List<UserRole> roleList = new UserRole().GetAllUserRole(0); lbRole.DataSource = roleList; lbRole.DataTextField = "Role"; lbRole.DataValueField = "Id"; lbRole.DataBind(); }