private void btnSure_Click(object sender, EventArgs e) { if (CheckField()) //檢查爛位是否無誤 { SIS.DBClass.DBClsLogin Login = new SIS.DBClass.DBClsLogin(); SIS.DBClass.DBClsWinAPEvents WAE = new SIS.DBClass.DBClsWinAPEvents(); string UserID = ""; string OldPwd = ""; string NewPwd = ""; string encryptFormat;//加密格式設定 UserID = My.MyGlobal.GlobalUserID; encryptFormat = "SHA1"; OldPwd = My.MyMethod.HashEncryption(encryptFormat, txtOldPwd.Text); NewPwd = My.MyMethod.HashEncryption(encryptFormat, txtNewPwd.Text); if (Login.UpdatePassword(UserID, OldPwd, NewPwd)) { MessageBox.Show(this, "密碼變更成功!!", "密碼變更"); clearField(); WAE.AddEventData(UserID, "資訊", "密碼變更", "密碼變更成功"); //btn_OK.Click += new System.EventHandler(btn_ClearField_Click); } else { MessageBox.Show(this, "密碼變更失敗!!", "密碼變更"); WAE.AddEventData(UserID, "警告", "密碼變更", "密碼變更失敗"); } } }
//登出 private void TSMI_Logout_Click(object sender, EventArgs e) { foreach (Form childForm in MdiChildren) { childForm.Close(); } SIS.DBClass.DBClsWinAPEvents WAE = new SIS.DBClass.DBClsWinAPEvents(); //將登入結果寫入事件資料庫中 WAE.AddEventData(My.MyGlobal.GlobalUserID, "資訊", "登出", "使用者登出成功"); LoadDefaultValue(); MessageBox.Show(this, "您已經成功登出系統!!", "訊息提示"); }
//刪除 private void tSBDelete_Click(object sender, EventArgs e) { //注意DataGridView的SelectMode只能為 選取欄位 或 選取資料列 不能二者同時存在 //獲取選取資料列(ROW)的總數 int selectedRowCount = dataGridView1.Rows.GetRowCount(DataGridViewElementStates.Selected); ArrayList AList = new ArrayList(); string EventId = ""; DialogResult DR = new DialogResult(); if (selectedRowCount > 0) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); AList.Clear(); for (int i = 0; i < selectedRowCount; i++) { EventId = dataGridView1.SelectedRows[i].Cells["EventId"].Value.ToString(); sb.Append("第 "); sb.Append(dataGridView1.SelectedRows[i].Index.ToString() + "列"); sb.Append(" " + EventId); sb.Append(Environment.NewLine); AList.Add(EventId); } sb.Append("被選取的資料列總數: " + selectedRowCount.ToString() + Environment.NewLine + "是否要刪除上述事件編號資料?"); DR = MessageBox.Show(this, sb.ToString(), "刪除事件資料", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (DR == DialogResult.Yes) { SIS.DBClass.DBClsWinAPEvents WAE = new SIS.DBClass.DBClsWinAPEvents(); if (WAE.MultiDelete(AList)) { MessageBox.Show("完成刪除動作,共刪除" + selectedRowCount.ToString() + "筆資料.", "刪除資訊", MessageBoxButtons.OK, MessageBoxIcon.Information); LoadDefaultValue(); } else { MessageBox.Show(this, "刪除事件失敗!!", "刪除訊息", MessageBoxButtons.OK); } } } }
//查詢 private void tSBQuery_Click(object sender, EventArgs e) { string FieldName = ""; string Keyword = ""; SIS.DBClass.DBClsWinAPEvents WAE = new SIS.DBClass.DBClsWinAPEvents(); switch (tSCBQueryItem.Text) { case "事件類型": FieldName = "EventType"; break; case "使用者編號": FieldName = "UserId"; break; case "執行動作": FieldName = "Action"; break; default: FieldName = ""; break; } Keyword = this.tSCBKeyword.Text; DataView DV = WAE.RunQueryToDataView(FieldName, Keyword); if (DV.Count == 0) { MessageBox.Show("搜尋條件並未找到任何符合資料", "搜尋結果", MessageBoxButtons.OK, MessageBoxIcon.Warning); tSSL_DataCount.Text = DV.Count.ToString(); } else { MessageBox.Show("共找到資料筆數" + DV.Count.ToString(), "搜尋結果"); tSSL_DataCount.Text = DV.Count.ToString(); } this.dataGridView1.DataSource = DV; }
/// <summary> /// 執行登入動作 /// </summary> /// <returns>登入成功回傳True,否則回傳False</returns> public bool RunLogin() { if (CheckField()) { string UserID; string HashPwd; string encryptFormat;//加密格式設定 string RoleName = ""; encryptFormat = "SHA1"; UserID = txtUserID.Text; HashPwd = My.MyMethod.HashEncryption(encryptFormat, txtPwd.Text); SIS.DBClass.DBClsLogin DbLogin = new SIS.DBClass.DBClsLogin(); SIS.DBClass.DBClsWinAPEvents WAE = new SIS.DBClass.DBClsWinAPEvents(); bool VerifyResult = false; try { VerifyResult = DbLogin.VerifyPWD(UserID, HashPwd); if (VerifyResult == false) { My.ErrorType errType = new My.ErrorType(My.MainErrorType.LoginError); errType.loginError = new My.LoginError(); errType.loginError.AccountOrPasswordError = true; throw new My.MyExceptionHandler(errType); } } catch (My.MyExceptionHandler ex) { MessageBox.Show(ex.Message, "MyExceptionHandler"); return(false); } if (VerifyResult) { //MessageBox.Show("驗證成功"); //將登入結果寫入事件資料庫中 WAE.AddEventData(UserID, "資訊", "登入", "身分驗證成功"); RoleName = DbLogin.RoleIdToRoleName(UserID); My.MyGlobal.GlobalUserID = UserID; My.MyGlobal.GlobalPassword = txtPwd.Text; My.MyGlobal.GlobalHashPassword = HashPwd; My.MyGlobal.GlobalRoleName = RoleName; //執行登錄檔處理 if (RegistryProcess(UserID, RoleName)) { //執行使用者授權動作 if (AuthorityProcess(UserID, RoleName)) { return(true); } else { return(false); } } else { MessageBox.Show("登錄檔作業失敗!!", "Registry作業", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } } else { //MessageBox.Show("驗證失敗"); My.MyGlobal.GlobalLoginErrorCounter += 1; if (My.MyGlobal.GlobalLoginErrorCounter >= 3) { MessageBox.Show("[帳號]和[密碼]輸入錯誤超過三次!!,系統將強制關閉", "登入失敗", MessageBoxButtons.OK, MessageBoxIcon.Warning); My.MyGlobal.GlobalSystemShutdown = true; MdiParent.Close(); this.Close(); } //將登入失敗的結果寫入事件資料庫中 WAE.AddEventData(UserID, "警告", "登入", "身分驗證失敗"); MessageBox.Show("[帳號]和[密碼]錯誤!!", "登入失敗", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } } else { return(false); } }