Esempio n. 1
0
        /// <summary>
        /// 针对不同的角色检查登录名和密码,并作出应答
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonLogin_Click(object sender, EventArgs e)
        {
            if (comboBox1.Text == "学生")
            {
                sqlcom.CommandText = "select * from students where sno='" +
                                     textBox1.Text + "' and spwd='" + textBox2.Text + "'";
                sqlcon.Open();
                sqldr = sqlcom.ExecuteReader(CommandBehavior.CloseConnection);

                if (sqldr.Read())//datareader中有记录说明
                {
                    //MessageBox.Show("login successfully");
                    FormStu FS = new FormStu();
                    FS.father = this;
                    FS.sno    = sqldr[0].ToString(); FS.sname = sqldr[1].ToString();
                    FS.Show();
                    this.Visible = false;
                }
                else
                {
                    MessageBox.Show("用户名或密码不对");
                }
                sqldr.Close();
            }
            else if (comboBox1.Text == "教师")
            {
                sqlcom.CommandText = "select * from Teachers where Tno='" +
                                     textBox1.Text + "' and Tpwd='" + textBox2.Text + "'";
                sqlcon.Open();
                sqldr = sqlcom.ExecuteReader(CommandBehavior.CloseConnection);

                if (sqldr.Read())//datareader中有记录说明
                {
                    //MessageBox.Show("login successfully");
                    FormTea FT = new FormTea();
                    FT.father = this;
                    FT.Tno    = sqldr[0].ToString();
                    FT.Tname  = sqldr[1].ToString();
                    FT.Show();
                    this.Visible = false;
                }
                else
                {
                    MessageBox.Show("用户名或密码不对");
                }
                sqlcon.Close();
            }
            else
            {
                if (textBox1.Text == "Admin" && textBox2.Text == "123456")
                {
                    //MessageBox.Show("login successfully");
                    FormAdm FA = new FormAdm();
                    FA.father    = this; FA.Show();
                    this.Visible = false;
                }
                else
                {
                    MessageBox.Show("登录失败");
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 针对不同的角色检查登录名和密码,并作出应答
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonLogin_Click(object sender, EventArgs e)
        {
            if (comboBox1.Text == "学生")
            {
                sqlcom.CommandText = "select * from students where sno='" +
                textBox1.Text + "' and spwd='" + textBox2.Text+"'";
                sqlcon.Open();
                sqldr = sqlcom.ExecuteReader(CommandBehavior.CloseConnection);

                if (sqldr.Read())//datareader中有记录说明
                {
                    //MessageBox.Show("login successfully");
                    FormStu FS = new FormStu();
                    FS.father = this;
                    FS.sno = sqldr[0].ToString(); FS.sname = sqldr[1].ToString();
                    FS.Show();
                    this.Visible = false;
                }
                else
                {
                    MessageBox.Show("用户名或密码不对");
                }
                sqldr.Close();
            }
            else if (comboBox1.Text == "教师")
            {
                sqlcom.CommandText = "select * from Teachers where Tno='" +
                textBox1.Text + "' and Tpwd='" + textBox2.Text+"'";
                sqlcon.Open();
                sqldr = sqlcom.ExecuteReader(CommandBehavior.CloseConnection);

                if (sqldr.Read())//datareader中有记录说明
                {
                    //MessageBox.Show("login successfully");
                    FormTea FT = new FormTea();
                    FT.father = this;
                    FT.Tno = sqldr[0].ToString();
                    FT.Tname = sqldr[1].ToString();
                    FT.Show();
                    this.Visible = false;
                }
                else
                {
                    MessageBox.Show("用户名或密码不对");
                }
                sqlcon.Close();
            }
            else
            {
                if (textBox1.Text=="Admin" && textBox2.Text=="123456")
                {
                    //MessageBox.Show("login successfully");
                    FormAdm FA = new FormAdm();
                    FA.father = this; FA.Show();
                    this.Visible = false;
                }
                else
                {
                    MessageBox.Show("登录失败");
                }
            }
        }