Beispiel #1
0
        /// <summary>
        /// 用TreeView來顯示使用者
        /// </summary>
        private void runTreeViewUsers()
        {
            SIS.DBClass.DBClsLogin DbLogin = new SIS.DBClass.DBClsLogin();

            DataTable DT = DbLogin.GetLoginDataTable("UserId", "ASC");
            TreeNode  TN;
            string    RoleName = "";

            treeViewUsers.Nodes.Clear();
            treeViewUsers.ImageList = imgListForTreeView;

            //建立root節點
            TN                    = new TreeNode("人員管理子系統");
            TN.Tag                = "";
            TN.ImageIndex         = 0;
            TN.SelectedImageIndex = 0;
            treeViewUsers.Nodes.Add(TN);

            //建立人員分類節點
            TN            = new TreeNode("系統管理者");
            TN.ImageIndex = 1;
            treeViewUsers.Nodes[0].Nodes.Add(TN);
            TN            = new TreeNode("一般使用者");
            TN.ImageIndex = 1;
            treeViewUsers.Nodes[0].Nodes.Add(TN);
            TN            = new TreeNode("進銷存管理者");
            TN.ImageIndex = 1;
            treeViewUsers.Nodes[0].Nodes.Add(TN);
            TN            = new TreeNode("匿名參觀者");
            TN.ImageIndex = 1;
            treeViewUsers.Nodes[0].Nodes.Add(TN);

            foreach (DataRow Rows in DT.Rows)
            {
                RoleName = DbLogin.RoleIdToRoleName(Rows["UserId"].ToString());

                TN                    = new TreeNode(Rows["UserId"].ToString());
                TN.ImageIndex         = 3;
                TN.SelectedImageIndex = 2;
                TN.ToolTipText        = Rows["UserId"].ToString();
                TN.Tag                = Rows["UserId"].ToString();

                switch (RoleName)
                {
                case "系統管理者":
                    treeViewUsers.Nodes[0].Nodes[0].Nodes.Add(TN);
                    break;

                case "一般使用者":
                    treeViewUsers.Nodes[0].Nodes[1].Nodes.Add(TN);
                    break;

                case "進銷存管理者":
                    treeViewUsers.Nodes[0].Nodes[2].Nodes.Add(TN);
                    break;

                case "匿名參觀者":
                    treeViewUsers.Nodes[0].Nodes[3].Nodes.Add(TN);
                    break;

                default:
                    MessageBox.Show(this, "角色編號可能有誤!!", "警告訊息");
                    break;
                }
            }
            treeViewUsers.ShowNodeToolTips = true; //用來設定顯示節點顯示提示字串
        }
Beispiel #2
0
        /// <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);
            }
        }