private void addUserToolStripButton_Click(object sender, EventArgs e) { try { if (!this.Validate( )) { return; } if (UsersDataGridView.Rows.Count > 0) { if ((UsersBindingSource.Count < UsersDataGridView.Rows.Count) || (( DataRowView )UsersBindingSource [UsersDataGridView.Rows.Count - 1]).IsNew) { return; } } UsersBindingSource.AddNew( ); if (UsersDataGridView.Rows.Count > 0) { if ((( DataRowView )UsersBindingSource [UsersDataGridView.Rows.Count - 1]).IsNew) { UsersDataGridView.CurrentCell = UsersDataGridView.Rows [UsersDataGridView.Rows.Count - 1].Cells [0]; UsersDataGridView.ShowEditingIcon = true; UsersDataGridView.BeginEdit(false); } } } catch (Exception exception) { MessageBox.Show(this, exception.Message, "User Access", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void bindingNavigatorMoveLastItem_Click(object sender, EventArgs e) { if (move()) { UsersBindingSource.MoveLast(); } }
private void grdvUsers_CellContentClick(object sender, DataGridViewCellEventArgs e) { try { UsersSource.UsersRow editedRow; if (e.RowIndex < 0 || e.ColumnIndex < 0) { return; } editedRow = (UsersSource.UsersRow)(( DataRowView )UsersBindingSource [e.RowIndex]).Row; _SelectedUser = UsersDataGridView.Rows[e.RowIndex].Cells[UserNameDataGridViewTextBoxColumn.Index].Value.ToString(); if (e.ColumnIndex == NewPasswordDataGridViewButtonColumn.Index) { PasswordRequestEventArgs ea = new PasswordRequestEventArgs(); PasswordRequest(this, ea); if (!ea.Cancel) { UsersDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = ea.Password; if (ea.Expires.HasValue) { UsersDataGridView.Rows[e.RowIndex].Cells[ExpiresColumn.Index].Value = ea.Expires; } else { UsersDataGridView.Rows[e.RowIndex].Cells[ExpiresColumn.Index].Value = DBNull.Value; } UsersBindingSource.EndEdit(); } } else if (e.ColumnIndex == Permissions.Index) { EditUserPermissionsEventArgs ea = new EditUserPermissionsEventArgs(_SelectedUser); UsersSource.UserPermissionsRow[] permissions = (from p in Source.UserPermissions where p.RowState != DataRowState.Deleted && p.UserName == _SelectedUser select p).ToArray(); foreach (UsersSource.UserPermissionsRow permission in permissions) { ea.Permissions.Add(permission.Permission); } EditUserPermissions(this, ea); } } catch (Exception exception) { MessageBox.Show(this, exception.Message, "User Access", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void grdvUsers_CellContentClick(object sender, DataGridViewCellEventArgs e) { try { UsersSource.UsersRow editedRow; if (e.RowIndex < 0 || e.ColumnIndex < 0) { return; } editedRow = (UsersSource.UsersRow)(( DataRowView )UsersBindingSource [e.RowIndex]).Row; if (e.ColumnIndex == NewPasswordDataGridViewButtonColumn.Index) { PasswordDialog passDlg; passDlg = new PasswordDialog( ); if (passDlg.ShowDialog( ) == DialogResult.OK) { UsersDataGridView.Rows [e.RowIndex].Cells [e.ColumnIndex].Value = passDlg.Password; UsersBindingSource.EndEdit( ); //if ( editedRow.RowState != DataRowState.Detached ) //{ // OnValueChanged ( true ) ; //} } } else if (e.ColumnIndex == AdministratorDataGridViewCheckBoxColumn.Index) { bool defaultChceked; defaultChceked = ( bool )UsersDataGridView.Rows [e.RowIndex].Cells [e.ColumnIndex].EditedFormattedValue; if (defaultChceked != editedRow.IsAdmin && editedRow.RowState != DataRowState.Detached) { OnValueChanged(true); } } } catch (Exception exception) { MessageBox.Show(this, exception.Message, "User Access", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e) { if (modified || newRec) { DialogResult select = DevExpress.XtraEditors.XtraMessageBox.Show("Do you want to confirm these changes?", Text, MessageBoxButtons.YesNoCancel); if (select == DialogResult.Cancel) { return; } if (select == DialogResult.Yes) { if (!SaveRecord()) { return; } } if (select == DialogResult.No) { if (newRec) { RemoveRecord(); } else { RefreshRecord(); } } } GridViewUsers.ClearColumnsFilter(); if (UsersBindingSource.Current == null) { //fake query in order to create a link between the database table and the binding source UsersBindingSource.DataSource = from opt in context.ExtranetUser where opt.UserID == "KJM9" select opt; } CheckEditAgent.Focus(); GridViewUsers.CloseEditor(); newRec = true; ignoreLeaveRow = true; //so that when the grid row changes it doesn't try to save again UsersBindingSource.AddNew(); if (GridViewUsers.FocusedRowHandle == GridControl.AutoFilterRowHandle) { GridViewUsers.FocusedRowHandle = GridViewUsers.RowCount - 1; } CheckEditAgent.Focus(); setReadOnly(false); ignoreLeaveRow = false; }
private void RemoveRecord() { PermissionsBindingSource.Clear(); UsersBindingSource.RemoveCurrent(); }
private void addUserToolStripButton_Click(object sender, EventArgs e) { try { if (!this.Validate()) { return; } if (UsersDataGridView.Rows.Count > 0) { if ((UsersBindingSource.Count < UsersDataGridView.Rows.Count) || ((DataRowView)UsersBindingSource[UsersDataGridView.Rows.Count - 1]).IsNew) { return; } } _newCardUserEdiNumber = string.Empty; if (this.LoginType == LoginType.SmartcardPin) { LoginDialog dlgLogin = new LoginDialog(Medical.Winforms.LoginType.SmartcardPin); dlgLogin.Options = LoginDialogOptions.AddUser; dlgLogin.Text = "Add Card User"; dlgLogin.Info = string.Empty; dlgLogin.RegularUsername = string.Empty; dlgLogin.CanSetUserName = true; dlgLogin.AuthenticateUser += new EventHandler <AuthenticateUserEventArgs>(Program.dlgLogin_AuthenticateUser); if (dlgLogin.ShowDialog(/*new WindowWrapper(process.MainWindowHandle)*/) == DialogResult.OK) { _newCardUserEdiNumber = dlgLogin.EdiNumber; _newCardUserFriendlyName = dlgLogin.GetSelectedCacCardUser(); } else { return; } } // Default the UserName to the CAC card name in the AddingNew event DataRowView rowView = UsersBindingSource.AddNew() as DataRowView; if (UsersDataGridView.Rows.Count > 0) { if (((DataRowView)UsersBindingSource[UsersDataGridView.Rows.Count - 1]).IsNew) { if (this.LoginType == LoginType.UsernamePassword) { UsersDataGridView.CurrentCell = UsersDataGridView.Rows[UsersDataGridView.Rows.Count - 1].Cells[0]; UsersDataGridView.ShowEditingIcon = true; UsersDataGridView.BeginEdit(false); } else { int lastIndex = UsersDataGridView.Rows.Count - 1; UsersDataGridView.CurrentCell = UsersDataGridView.Rows[lastIndex].Cells[0]; UsersDataGridView.Rows[lastIndex].Selected = true; // if (UsersDataGridView.IsCurrentCellDirty || UsersDataGridView.IsCurrentRowDirty) { // This code makes it so I don't have to leave the data grid row to commit the changes! UsersDataGridView.CurrentRow.DataGridView.EndEdit(); UsersDataGridView.EndEdit(); CurrencyManager cm = (CurrencyManager)UsersDataGridView.BindingContext[UsersDataGridView.DataSource, UsersDataGridView.DataMember]; cm.EndCurrentEdit(); } } } } } catch (Exception exception) { MessageBox.Show(this, exception.Message, "User Access", MessageBoxButtons.OK, MessageBoxIcon.Error); } }