예제 #1
0
        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);
            }
        }
예제 #2
0
        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);
            }
        }