Exemplo n.º 1
0
        public void Insert(AuthorityManagent authorityManagent, string TableName)
        {
            SqlConnection _SqlConnection = new SqlConnection(SqlConnectionStringBuilder.ToString());

            try
            {
                string     TestComm   = string.Format("INSERT INTO dbo.{0}({1}) VALUES({2})", TableName, "UserName,Password,Authority", string.Format("'{0}','{1}','{2}'", authorityManagent.UserName, authorityManagent.Password, authorityManagent.Auth));
                SqlCommand InsertComm = new SqlCommand(TestComm, _SqlConnection);
                if (_SqlConnection.State == ConnectionState.Closed)
                {
                    _SqlConnection.Open();
                }
                InsertComm.ExecuteNonQuery();
            }
            catch (Exception)
            {
                return;
            }
            finally
            {
                if (_SqlConnection != null && _SqlConnection.State == ConnectionState.Open)
                {
                    _SqlConnection.Close();
                }
            }
        }
Exemplo n.º 2
0
        public AuthorityManagent Login(string UserName, string Password)
        {
            SqlConnection     _SqlConnection = new SqlConnection(SqlConnectionStringBuilder.ToString());
            AuthorityManagent managent       = null;

            try
            {
                string     TextComm   = "SELECT * FROM dbo.Authority";
                SqlCommand SelectComm = new SqlCommand(TextComm, _SqlConnection);
                if (_SqlConnection.State == ConnectionState.Closed)
                {
                    _SqlConnection.Open();
                }
                SqlDataReader reader = SelectComm.ExecuteReader();

                while (reader.Read())
                {
                    managent = new AuthorityManagent(reader["UserName"].ToString().Trim(), reader["Password"].ToString().Trim(), (AuthorityManagent.Authority)Enum.Parse(typeof(AuthorityManagent.Authority), reader["Authority"].ToString().Trim()));
                    if (managent.UserName == UserName && managent.Password == Password)
                    {
                        managent.CheckAuthority = true;
                        break;
                    }
                }
                return(managent);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (_SqlConnection != null && _SqlConnection.State == ConnectionState.Open)
                {
                    _SqlConnection.Close();
                }
            }
        }
Exemplo n.º 3
0
 private void Btn_Login_Click(object sender, EventArgs e)
 {
     if (Btn_Login.Text == "登入")
     {
         AuthorityManagent managent = MainForm.broker.Login(Txt_UserName.Text, Txt_Password.Text); //抓取sql server中儲存的登入權限
         if (managent.CheckAuthority)                                                              // 如果輸入的帳號密碼符合sql server中登錄的資訊,則將此form關閉
         {
             CheckAuthoruty(this, new AuthorityCheckEvent()
             {
                 UserName = managent.UserName, Password = managent.Password, AuthorityManagent = managent.Auth.ToString()
             });                                                                                                                                                            //觸發事件,告知form1當前的登入者是誰
             this.Close();
         }
         else if (Txt_UserName.Text == "WhosYourDaddy")  //開啟創造者模式
         {
             CheckAuthoruty(this, new AuthorityCheckEvent()
             {
                 UserName = "******", Password = "", AuthorityManagent = "創造者"
             });
             this.Close();
         }
         else
         {
             MessageBox.Show("請確認輸入的帳號及密碼");
         }
     }
     else
     {
         CheckAuthoruty(this, new AuthorityCheckEvent()
         {
             UserName = "", Password = "", AuthorityManagent = ""
         });
         Btn_Login.Text    = "登入";
         Txt_Password.Text = "";
         this.Authority    = "";
     }
 }