Example #1
0
        private void button1_Click(object sender, EventArgs e)//添加信息
        {
            string        str  = @"Data Source=desktop-mbupc0n;Initial catalog=学生信息管理系统;integrated Security=True";
            SqlConnection conn = new SqlConnection(str);

            conn.Open();
            string insert1 = "insert into student(学号,姓名,性别,身份证号,学制,班级,专业,入学时间,地址,电话,邮编) values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox11.Text
                             + "','" + textBox4.Text + "','" + textBox5.Text + "','" + textBox6.Text + "','" + textBox10.Text + "','" + textBox8.Text + "','" + textBox9.Text + "','" + textBox7.Text + "')";
            SqlCommand cmd    = new SqlCommand(insert1, conn);//SqlCommand对象允许你指定在数据库上执行的操作的类型。
            int        result = cmd.ExecuteNonQuery();

            if (result > 0)
            {
                MessageBox.Show("添加成功");
                this.Hide();
                Mainform form = new Mainform();
                form.Show();
            }
            else
            {
                MessageBox.Show("添加失败");
            }
        }
Example #2
0
        private void button1_Click(object sender, EventArgs e)//登陆按钮
        {
            if (radioButton1.Checked)
            {
                string        str  = @"Data Source=desktop-mbupc0n;Initial catalog=学生信息管理系统;integrated Security=True";
                SqlConnection conn = new SqlConnection(str);//实例化链接
                conn.Open();
                string     selectsql = "Select * from login where username = '******' and password='******'";
                SqlCommand cmd       = new SqlCommand(selectsql, conn);//SqlCommand对象允许你指定在数据库上执行的操作的类型。
                cmd.CommandType = CommandType.Text;
                SqlDataReader dr;
                dr = cmd.ExecuteReader();
                if (dr.Read())
                {
                    MessageBox.Show("登陆成功");
                    student form = new student();//学生界面
                    form.Owner = this;
                    form.ShowDialog();
                    this.Hide();
                    this.Close();
                }
                else
                {
                    MessageBox.Show("用户名或者密码错误");
                    textBox1.Text        = null;
                    textBox2.Text        = null;
                    radioButton1.Checked = false;
                    radioButton2.Checked = false;
                    return;
                }
                conn.Close();
            }
            else if (radioButton2.Checked)
            {
                string        str  = @"Data Source=desktop-mbupc0n;Initial catalog=学生信息管理系统;integrated Security=True";
                SqlConnection conn = new SqlConnection(str);//实例化链接
                conn.Open();
                string     selectsql = "Select * from teacherlogin where username = '******' and password='******'";
                SqlCommand cmd       = new SqlCommand(selectsql, conn);//SqlCommand对象允许你指定在数据库上执行的操作的类型。
                cmd.CommandType = CommandType.Text;
                SqlDataReader dr;
                dr = cmd.ExecuteReader();
                if (dr.Read())
                {
                    MessageBox.Show("登陆成功");
                    teacher te = new teacher();//教师界面
                    te.ShowDialog();
                    this.Hide();
                    this.Close();
                }
                else
                {
                    MessageBox.Show("用户名或者密码错误");
                    textBox1.Text        = null;
                    textBox2.Text        = null;
                    radioButton1.Checked = false;
                    radioButton2.Checked = false;
                    return;
                }
                conn.Close();
            }
            else if (radioButton3.Checked)
            {
                string        str  = @"Data Source=desktop-mbupc0n;Initial catalog=学生信息管理系统;integrated Security=True";
                SqlConnection conn = new SqlConnection(str);//实例化链接
                conn.Open();
                string     selectsql = "Select * from admain where username = '******' and password='******'";
                SqlCommand cmd       = new SqlCommand(selectsql, conn);//SqlCommand对象允许你指定在数据库上执行的操作的类型。
                cmd.CommandType = CommandType.Text;
                SqlDataReader dr;
                dr = cmd.ExecuteReader();
                if (dr.Read())
                {
                    MessageBox.Show("登陆成功");
                    Mainform form = new Mainform();//管理员界面
                    form.ShowDialog();
                    this.Hide();

                    this.Dispose();
                }
                else
                {
                    MessageBox.Show("用户名或者密码错误");
                    textBox1.Text        = null;
                    textBox2.Text        = null;
                    radioButton1.Checked = false;
                    radioButton2.Checked = false;
                    return;
                }
                conn.Close();
            }
            else
            {
                MessageBox.Show("请选择登陆类型");
            }
        }