Пример #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            this.Hide();
            主界面 b = new 主界面();

            this.Hide();
            b.Show();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            txt = textBox1.Text;
            string        connString = @"Data Source=DESKTOP-SFFEEKC\SQLEXPRESS;Initial Catalog=学生信息表;Integrated Security=SSPI";
            SqlConnection conn       = new SqlConnection(connString);

            conn.Open();
            string     strQuery = "SELECT * FROM Table_1 where 密码='" + textBox2.Text + "' and 学号='" + textBox1.Text + "'and 身份='" + comboBox1.Text + "'";
            SqlCommand command  = new SqlCommand(strQuery, conn);

            command.CommandType = CommandType.Text;
            SqlDataReader read = command.ExecuteReader();

            if (read.Read())
            {
                if (comboBox1.Text == "管理员")
                {
                    MessageBox.Show("登录成功");
                    this.Hide();
                    Form6 x = new Form6();
                    x.Show();
                }
                else if (comboBox1.Text == "老师")
                {
                    MessageBox.Show("登录成功");
                    this.Hide();
                    Form2 x = new Form2();
                    x.Show();
                }
                else if (comboBox1.Text == "学生")
                {
                    MessageBox.Show("登录成功");
                    this.Hide();
                    主界面 main = new 主界面();
                    main.Show();
                }
                else
                {
                    MessageBox.Show("请选择身份");
                }
            }
            else
            {
                MessageBox.Show("登录失败,密码错误或身份选择错误!");
            }
        }