Ejemplo n.º 1
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            config connFirst = new config();
            //测试数据库连接
            string str_Sql     = "SELECT School_Type_ID As 学校类别代码,School_Type_Name As 学校类别名,School_Type_Year As 学校类别学制 FROM School_Type";
            string errorstring = connFirst.Fill(str_Sql);

            if (errorstring != "OK")
            {
                MessageBox.Show("请检查数据库!" + errorstring, "提醒!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                connFirst.Close();
                return;
            }

            //特殊字符不能用
            if (connFirst.Sniffer_In(textBox_User.Text) || connFirst.Sniffer_In(textBox_PassWord.Text))
            {
                MessageBox.Show("用户名或密码不得用空格或者'\"?%=等特殊字符!" + errorstring, "提醒!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                connFirst.Close();
                return;
            }

            //判断用户合法
            str_Sql = "Select * FROM Users WHERE UserName= '******' AND PassWord='******'";
            if (connFirst.GetRowCount(str_Sql) != 1)
            {
                MessageBox.Show("错误的用户名或密码!" + errorstring, "提醒!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                connFirst.Close();

                button1.Enabled = true;
                return;
            }
            else
            {
                str_User_login = textBox_User.Text;
                this.Close();
            }
        }