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 UpdateUserButton_Click(object sender, EventArgs e) { UserVO current = bindingSource1.Current as UserVO; if (current != null) { UserEditForm form = new UserEditForm(current, manager); if (form.ShowDialog() == System.Windows.Forms.DialogResult.OK) { UsersDataGridView.Refresh(); Log(OperationsManager.EDIT_USERS); } } }
private void UsersDataGridView_CellClick(object sender, DataGridViewCellEventArgs e) { switch (e.ColumnIndex) { case 1: // Edit UserControlExtensions.OpenUserControlWithXtraForm(new UserUserControl(ApplicationState, Configuration.Users[e.RowIndex])); break; case 2: //Delete Configuration.Users.RemoveAt(e.RowIndex); // _configuration.Users.Remove(_configuration.Users[e.RowIndex]); Configuration.Save(); ApplicationState.InitializeFaceRecognitionClient(); break; } SetDataGridViewBindingSource_LameWinForms(); UsersDataGridView.Invalidate(); }
private void RemovUserButton_Click(object sender, EventArgs e) { UserVO current = bindingSource1.Current as UserVO; if (current != null) { if (Question("هل أنت متأكد من الحذف؟") == System.Windows.Forms.DialogResult.Yes) { if (manager.Delete(current)) { bindingSource1.Remove(current); UsersDataGridView.Refresh(); Message("تم الحذف بنجاح"); Log(OperationsManager.EDIT_USERS); } else { Error(); } } } }
private void InsertUserButton_Click(object sender, EventArgs e) { UserVO user = new UserVO(); user.Username = UserNametextBox.Text.Trim(); user.Password = manager.GenerateHash(passwordTB.Text); user.IsActive = true; if (UserNametextBox.Text.Trim() == "") { Error("اسم المستخدم لايمكن أن يكون فارغاً"); } else if (!manager.IsUserNew(user)) { Error("اسم المستخدم موجود مسبقاً"); } else if (passwordTB.Text == "") { Error("كلمة المرور لايمكن ان تكون فارغة"); } else { if (manager.Insert(user) < 0) { Error(); } else { bindingSource1.Add(user); UsersDataGridView.Refresh(); Message("تم إضافة المستخدم بنجاح. لا تنس أن تحدد سماحياته"); passwordTB.Text = ""; UserNametextBox.Text = ""; Log(OperationsManager.EDIT_USERS); } } }
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); } }