private void LoadAllUser() { DataTable dataTable = TableUsersManage.QueryAllUsers(); this.dataGridView1.DataSource = dataTable; FormatDataGridView(this.dataGridView1); }
private void FrmMain_FormClosing(object sender, FormClosingEventArgs e) { if (LoginState.Login == this.LoginState) { TableUsersManage.ModifyUserLogoutById(DateTime.Now.ToLocalTime().ToString(), this.LoginLogId); } }
private void TsmiDelete_Click(object sender, EventArgs e) { try { DialogResult dialogResult = MessageBox.Show(this, "您确定要删除所选账户信息吗,删除后将不可恢复?", this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (DialogResult.Yes == dialogResult) { int count = dataGridView1.SelectedRows.Count; for (int i = 0; i < count; i++) { var row = dataGridView1.SelectedRows[i]; string username = row.Cells["Name"].Value.ToString(); int result = TableUsersManage.DeleteUserByUserName(username); if (result <= 0) { MessageBox.Show(this, "删除账户 " + username + " 失败!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } } LoadAllUser(); } else if (DialogResult.No == dialogResult) { } } catch (Exception ex) { MessageBox.Show(this, ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void BtnExit_Click(object sender, EventArgs e) { try { if (LoginState.Login == this.LoginState) { DialogResult dialogResult = MessageBox.Show(this, "您确定要退出当前账户 " + this.User.Name + " ?", this.Text, MessageBoxButtons.OKCancel, MessageBoxIcon.Information); if (DialogResult.OK == dialogResult) { TableUsersManage.ModifyUserLogoutById(DateTime.Now.ToLocalTime().ToString(), this.LoginLogId); SetLoginState(LoginState.Logout); } else { } } else if (LoginState.Logout == this.LoginState) { Login(); } } catch (Exception ex) { MessageBox.Show(this, ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void LblModifyNickname_Click(object sender, EventArgs e) { if (LblModifyNickname.Text.Equals("修改")) { TxtBoxNickName.Enabled = true; LblModifyNickname.Text = "确定"; } else if (LblModifyNickname.Text.Equals("确定")) { string nickname = TxtBoxNickName.Text.Trim(); if (nickname.Contains("'")) { MessageBox.Show(this, "含有非法字符 \"'\" !", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Stop); TxtBoxNickName.Focus(); return; } else { TxtBoxNickName.Enabled = false; LblModifyNickname.Text = "修改"; TableUsersManage.ModifyNicknameByUserId(this.User.Id, nickname); } } }
private void BtnAccountManage_Click(object sender, EventArgs e) { FrmAccountManager frmAccountManager = new FrmAccountManager { //UserName = this.UserName User = this.User, }; DialogResult dialogResult = frmAccountManager.ShowDialog(this); if (DialogResult.No == dialogResult) { if (LoginState.Login == this.LoginState) { TableUsersManage.ModifyUserLogoutById(DateTime.Now.ToLocalTime().ToString(), this.LoginLogId); SetLoginState(LoginState.Logout); } } DataTable dataTable = TableUsersManage.QueryUserByUserId(this.User.Id); DataRow dataRow = dataTable.Rows[0]; var item = dataRow.ToExpression <UserInfo>(); this.User = item(dataRow); this.LblUserName.Text = this.User.Nickname; }
private void LoginLogs_Load(object sender, EventArgs e) { try { if (LoadAllUsers) { this.TotalCount = TableUsersManage.QueryAllLoginLogsNumber(); //this.TotalPageNumber = this.TotalCount % PageSize == 0 ? this.TotalCount / PageSize : this.TotalCount / PageSize + 1; //this.PageNumber = 1; //DataTable dataTable = TableUsersManage.QueryAllLoginLogs(); //this.dataGridView1.DataSource = dataTable; //FormatDataGridView(this.dataGridView1); } else if (!string.IsNullOrWhiteSpace(this.UserName)) { this.TotalCount = TableUsersManage.QueryLoginLogsNumberByUserName(this.UserName); //DataTable dataTable = TableUsersManage.QueryLoginLogsByUserName(this.UserName); //this.dataGridView1.DataSource = dataTable; //FormatDataGridView(this.dataGridView1); } this.TotalPageNumber = this.TotalCount % PageSize == 0 ? this.TotalCount / PageSize : this.TotalCount / PageSize + 1; this.PageNumber = 1; LoadLoginLogsInPage(this.PageNumber); } catch (Exception ex) { MessageBox.Show(this, ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void LoadLoginLogsInPage(int page) { DataTable dataTable = new DataTable(); if (LoadAllUsers) { dataTable = TableUsersManage.QueryAllLoginLogsByPage(page, PageSize); } else if (!string.IsNullOrWhiteSpace(this.UserName)) { dataTable = TableUsersManage.QueryLoginLogsByUserNameAndPage(this.UserName, page, PageSize); } this.dataGridView1.DataSource = dataTable; FormatDataGridView(this.dataGridView1); LblCurPage.Text = this.PageNumber + "/" + this.TotalPageNumber; }
private void LblOk_Click(object sender, EventArgs e) { Cursor.Current = Cursors.WaitCursor; try { string oPassword = TxtBoxOldPassword.Text; string nPassword = TxtBoxNewPassword.Text; string nqPassword = TxtBoxNewPasswordQuery.Text; if (oPassword.Equals(this.User.Password)) { if (nPassword.Equals(nqPassword)) { int suc = TableUsersManage.ModifyPassword(this.User.Name, nPassword); if (suc > 0) { this.DialogResult = DialogResult.OK; this.Close(); } else { MessageBox.Show(this, "修改密码失败!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { TxtBoxNewPassword.Focus(); MessageBox.Show(this, "新密码不一致!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { TxtBoxOldPassword.Focus(); MessageBox.Show(this, "原密码错误!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show(this, ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } Cursor.Current = Cursors.Default; }
private void LoadAllUsers() { this.Users.Clear(); this.ComboBoxSeller.Items.Clear(); this.ComboBoxSeller.Items.Add(AllUsers); DataTable dataTable = TableUsersManage.QueryAllUsers(); foreach (DataRow dataRow in dataTable.Rows) { var item = dataRow.ToExpression <UserInfo>(); UserInfo user = item(dataRow); this.Users.Add(user); this.ComboBoxSeller.Items.Add(user.Name); } this.ComboBoxSeller.Text = AllUsers; this.UserName = AllUsers; RefreshCustomer(); }
private void btnLogin_Click(object sender, EventArgs e) { Cursor.Current = Cursors.WaitCursor; txtBoxErrMessage.Visible = false; try { string userName = txtBoxUserName.Text.Trim(); if (string.IsNullOrWhiteSpace(userName)) { txtBoxErrMessage.Visible = true; txtBoxErrMessage.Text = "用户名不能为空"; txtBoxUserName.Focus(); Cursor.Current = Cursors.Default; return; } DataTable dataTable = TableUsersManage.QueryUserName(userName); if (dataTable.Rows.Count <= 0) { txtBoxErrMessage.Visible = true; txtBoxErrMessage.Text = "用户不存在"; txtBoxUserName.Focus(); Cursor.Current = Cursors.Default; return; } string password = txtBoxPassword.Text.Trim(); bool isRememberPassword = ckBoxRememberPassword.Checked; DataRow dataRow = dataTable.Rows[0]; var item = dataRow.ToExpression <UserInfo>(); this.User = item(dataRow); if (this.User.Password.Equals(password)) { if (isRememberPassword) { AppConfigHelper.SetConfigValue(userName, password); } string mac = SystemInfo.GetMac(); string lanIp = SystemInfo.GetLanIp(); //string wanIp = SystemInfo.GetWanIp(); //string wanIp = ""; string datetime = DateTime.Now.ToLocalTime().ToString(); string hostName = SystemInfo.GetHostName(); string sysUserName = SystemInfo.GetUserName(); this.LoginLogId = TableUsersManage.AddUserLoginLogAndReturnIdentity(userName, datetime, mac, lanIp, hostName, sysUserName, this.User.Id); if (this.LoginLogId >= 0) { //int suc = TableUsersManage.ModifyUserLastLoginLogByUserName(userName, datetime, mac, lanIp, hostName, sysUserName); //if (suc > 0) //{ this.UserName = userName; this.DialogResult = DialogResult.OK; this.Close(); //} //else //{ // MessageBox.Show(this, "服务器连接错误!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); //} } else { MessageBox.Show(this, "服务器连接错误!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { txtBoxErrMessage.Visible = true; txtBoxErrMessage.Text = "密码错误"; } } catch (Exception ex) { MessageBox.Show(this, ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } Cursor.Current = Cursors.Default; }
private void BtnOk_Click(object sender, EventArgs e) { Cursor.Current = Cursors.WaitCursor; try { string name = TxtBoxUserName.Text.Trim(); if (name.Contains("'")) { MessageBox.Show(this, "含有非法字符 \"'\" !", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Stop); TxtBoxUserName.Focus(); return; } if (WorkingState.Add == this.WorkingState) { DataTable dataTable = TableUsersManage.QueryUserName(name); if (dataTable.Rows.Count > 0) { MessageBox.Show(this, "已存在相同的用户名!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Stop); TxtBoxUserName.Focus(); return; } } string password = TxtBoxPassword.Text.Trim(); if (password.Contains("'")) { MessageBox.Show(this, "含有非法字符 \"'\" !", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Stop); TxtBoxPassword.Focus(); return; } if (string.IsNullOrWhiteSpace(password)) { MessageBox.Show(this, "密码不能为空!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Stop); TxtBoxPassword.Focus(); return; } string nickname = TxtBoxNickname.Text.Trim(); if (nickname.Contains("'")) { MessageBox.Show(this, "含有非法字符 \"'\" !", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Stop); TxtBoxNickname.Focus(); return; } string privilege = ComboBoxPrivilege.Text; if (WorkingState.Add == this.WorkingState) { int identity = TableUsersManage.AddUserAndReturnIdentity(name, password, privilege, nickname, DateTime.Now.ToLocalTime().ToString()); if (identity > 0) { this.DialogResult = DialogResult.OK; this.Close(); } else { MessageBox.Show(this, "添加用户失败!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } } else if (WorkingState.Modify == this.WorkingState) { int suc = TableUsersManage.ModifyUserByUserName(name, password, privilege, nickname); if (suc > 0) { this.DialogResult = DialogResult.OK; this.Close(); } else { MessageBox.Show(this, "修改用户失败!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } } } catch (Exception ex) { MessageBox.Show(this, ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } Cursor.Current = Cursors.Default; }