Exemplo n.º 1
0
        private void button2_Click(object sender, EventArgs e)//返回主界面
        {
            zhujiemian f = new zhujiemian();

            f.Show();
            this.Close();
        }
Exemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            zhujiemian f   = new zhujiemian();
            string     str = "";

            if (button1.Text == "学员登录")
            {
                str = "select * from login where 用户名='" + textBox1.Text + "' and 密码='" + textBox2.Text + "' and 类型='学员'";
                f.richTextBox2.Text = "欢迎" + textBox1.Text + "学员,有什么宝贵的意见或建议,请联系******@qq.com";
                f.groupBox1.Visible = true;
            }
            if (button1.Text == "教员登录")
            {
                f.richTextBox2.Text = "欢迎" + textBox4.Text + "教员,有什么宝贵的意见或建议,请联系******@qq.com";
                f.groupBox1.Visible = true;
                str = "select * from login where 用户名='" + textBox4.Text + "' and 密码='" + textBox3.Text + "' and 类型='教员'";
            }
            if (button1.Text == "管理员登录")
            {
                if (textBox5.Text == "admin" && textBox6.Text == "admin")
                {
                    this.Hide();
                    f.Show();
                    f.panel_studentin.Visible = true;
                    f.panel_teacherin.Visible = true;
                    f.panel_adminin.Visible   = true;
                    f.panel_admin.Visible     = true;
                    f.dataGridView3.Visible   = false;
                    f.richTextBox2.Visible    = true;
                    f.richTextBox2.Text       = "欢迎您,管理员,有什么宝贵的意见或建议,请联系******@qq.com";
                    f.groupBox1.Visible       = true;
                }
                else
                {
                    MessageBox.Show("输入有误,请重新输入", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    textBox5.Text = "";
                    textBox6.Text = "";
                }
            }
            if (button1.Text == "学员登录" || button1.Text == "教员登录")
            {
                OleDbConnection conn = new OleDbConnection(accesspath);
                try
                {
                    OleDbCommand cmd = new OleDbCommand(str, conn);
                    conn.Open();
                    OleDbDataReader reader = cmd.ExecuteReader();
                    if (reader.Read())//如果输入的数据和数据库中存储的数据匹配,登录成功,跳到主界面
                    {
                        f.label35.Visible = true;
                        f.label36.Visible = true;
                        this.Hide();
                        f.Show();
                        f.richTextBox2.Visible = true;
                        if (button1.Text == "学员登录")
                        {
                            f.label36.Text            = textBox1.Text;
                            f.panel_studentin.Visible = true;
                            f.button11.Text           = "发表帖子";
                        }
                        if (button1.Text == "教员登录")
                        {
                            f.label36.Text            = textBox4.Text;
                            f.panel_studentin.Visible = true;
                            f.panel_teacherin.Visible = true;
                            f.button11.Text           = "查看帖子 ";
                        }
                    }
                    else
                    {
                        MessageBox.Show("登录失败");
                    }
                }
                catch (Exception w)
                {
                    MessageBox.Show(w.Message);
                }
                conn.Close();             //关闭数据库
                conn.Dispose();           //释放资源
            }
            f.button7.Visible     = true; //注销按钮显示
            f.notifyIcon1.Visible = false;
        }
Exemplo n.º 3
0
        private void button1_Click(object sender, EventArgs e)
        {
            OleDbConnection conn = new OleDbConnection(accesspath);

            if (radioButton1.Checked == true)                                               //注册学员
            {
                string       sql = "select * from login where 用户名='" + textBox1.Text + "'"; //sql查询语句
                OleDbCommand cmd = new OleDbCommand(sql, conn);
                conn.Open();
                OleDbDataReader r = cmd.ExecuteReader();
                if (r.Read())//从数据库中查询到了我们即将要注册的用户名
                {
                    MessageBox.Show("该用户已存在,直接登录吧");
                }
                else
                {
                    string str1 = "insert  into login(用户名,密码,类型,姓名) values('" + textBox1.Text + "','" + textBox2.Text + "','学员','" + textBox3.Text + "')";
                    string str2 = "insert  into student values('" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','" + textBox6.Text + "','" + textBox7.Text + "','" + textBox8.Text + "')";

                    if (textBox1.Text != "" && textBox2.Text != "" && textBox3.Text != "")//用户名、密码、姓名不能为空
                    {
                        try
                        {
                            cmd = new OleDbCommand(str1, conn);;
                            if (conn.State == ConnectionState.Closed)
                            {
                                conn.Open();
                            }
                            cmd.ExecuteNonQuery();//往数据库login表中进行写入操作
                            MessageBox.Show("用户名注册成功");
                        }
                        catch (Exception w)
                        {
                            MessageBox.Show("遇到错误,用户名注册失败");
                        }
                        conn.Close();
                        conn.Dispose();

                        try
                        {
                            conn = new OleDbConnection(accesspath);
                            if (conn.State == ConnectionState.Closed)
                            {
                                conn.Open();
                            }
                            cmd = new OleDbCommand(str2, conn);
                            cmd.ExecuteNonQuery();
                            MessageBox.Show("详细信息注册成功");
                        }
                        catch (Exception w)
                        {
                            MessageBox.Show("遇到错误,详细信息注册失败");
                            MessageBox.Show("请重新注册用户");
                            string str = "delete from login where 用户名='" + textBox1.Text + "'";
                            cmd = new OleDbCommand(str, conn);
                            if (conn.State == ConnectionState.Closed)//如果数据库的连接状态为关闭状态
                            {
                                conn.Open();
                            }
                            cmd.ExecuteNonQuery();//往数据库student表中写入数据
                        }

                        conn.Close();
                        conn.Dispose();
                    }
                    else
                    {
                        MessageBox.Show("用户名、密码、姓名都不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
            if (radioButton2.Checked == true)//注册教员
            {
                string       sql  = "select * from login where 用户名='" + textBox9.Text + "'";
                string       str1 = "insert  into login(用户名,密码,类型,编号) values('" + textBox9.Text + "','" + textBox10.Text + "','教员','" + textBox11.Text + "')";;
                string       str2 = "insert  into teacher(教师编号,教师姓名,性别,QQ,学校,年级,专业,价格,电话,自我描述) values('" + textBox11.Text + "','" + textBox12.Text + "','" + textBox13.Text + "','" + textBox14.Text + "','" + textBox15.Text + "','" + textBox16.Text + "','" + textBox17.Text + "','" + textBox18.Text + "','" + textBox19.Text + "','" + textBox20.Text + "')";
                OleDbCommand cmd  = new OleDbCommand(sql, conn);
                conn.Open();
                OleDbDataReader r = cmd.ExecuteReader();
                if (r.Read())
                {
                    MessageBox.Show("该用户已存在,直接登录吧");
                }
                else
                {
                    if (textBox9.Text != "" && textBox10.Text != "" && textBox11.Text != "")//用户名、密码、教师编号不能为空
                    {
                        try
                        {
                            cmd = new OleDbCommand(str1, conn);;
                            if (conn.State == ConnectionState.Closed)
                            {
                                conn.Open();
                            }
                            cmd.ExecuteNonQuery();
                            MessageBox.Show("用户名注册成功");//往数据库login表中进行写入操作
                        }
                        catch (Exception w)
                        {
                            MessageBox.Show("遇到错误,用户名注册失败");
                        }

                        conn.Close();
                        conn.Dispose();
                        try
                        {
                            conn = new OleDbConnection(accesspath);
                            if (conn.State == ConnectionState.Closed)
                            {
                                conn.Open();
                            }
                            cmd = new OleDbCommand(str2, conn);
                            cmd.ExecuteNonQuery();//往数据库teacher表中写入数据
                            MessageBox.Show("详细信息注册成功");
                        }
                        catch (Exception w)
                        {
                            MessageBox.Show("遇到错误,详细信息注册失败");
                            MessageBox.Show("请重新注册用户");
                            string str = "delete from login where 用户名='" + textBox9.Text + "'";
                            cmd = new OleDbCommand(str, conn);
                            if (conn.State == ConnectionState.Closed)
                            {
                                conn.Open();
                            }
                            cmd.ExecuteNonQuery();
                        }

                        conn.Close();   //关闭数据库
                        conn.Dispose(); //释放资源
                    }
                    else
                    {
                        MessageBox.Show("用户名、密码、教师编号都不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
            zhujiemian f = new zhujiemian();

            f.Show();
            this.Hide();
        }