コード例 #1
0
        private void pictureBox2_Click(object sender, EventArgs e)
        {
            Boolean flag;

            flag = true;
            student newstu = new student();

            if (textBox3.Text != textBox4.Text)//判密码
            {
                pictureBox3.Show();
                label11.Show();
                flag = false;
                return;
            }
            else
            {
                pictureBox3.Hide();
                label11.Hide();
            }
            if (textBox3.Text == "")
            {
                flag = false;
                pictureBox5.Show();
                label13.Show();
                return;
            }
            else
            {
                pictureBox5.Hide();
                label13.Hide();
            }

            if (textBox5.Text.Length != 11 || textBox5.Text.Substring(0, 1) != "1")//验手机号
            {
                flag = false;
                pictureBox4.Show();
                label12.Show();
                return;
            }
            else
            {
                pictureBox4.Hide();
                label12.Hide();
            }
            string   sql          = $"select * from tb_student where stu_num = '{textBox1.Text}'";;
            selecter selecterDemo = new selecter(CP, sql);

            try
            {
                if (selecterDemo.getNum() != 0)
                {
                    pictureBox7.Show();
                    label10.Show();
                    flag = false;
                    return;
                }
                else
                {
                    pictureBox7.Hide();
                    label10.Hide();//到此成功注册
                    newstu.setClazz_ID(comboBox1.SelectedIndex + 1);
                    newstu.setStu_name(textBox2.Text);
                    newstu.setStu_num(textBox1.Text);
                    newstu.setStu_sex(comboBox2.SelectedIndex);
                    newstu.setStu_password(pw.lockstring(textBox3.Text));
                    newstu.setStu_tel(textBox5.Text);
                    newstu.setStu_addTime(DateTime.Now);
                    newstu.setStu_editTime(DateTime.Now);
                }
            }
            finally
            {
                selecterDemo.end();
            }
            sql_student ss = new sql_student(CP);
            int         j  = ss.insert(newstu);

            this.Hide();
            MessageBox.Show("注册成功!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
        }
コード例 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            Boolean         flag = true;
            MySqlDataReader reader;

            user = textBox1.Text;
            string password;

            if (!radioButton1.Checked && !radioButton2.Checked)
            {
                label4.Show();
                pictureBox9.Show();
                flag = false;
                return;
            }
            else
            {
                label4.Hide();
                pictureBox9.Hide();
            }


            if (radioButton2.Checked)//学生
            {
                string   sql          = $"select * from tb_student where stu_num = '{user}'";
                selecter selecterDemo = new selecter(CP, sql);
                try
                {
                    if (0 == selecterDemo.getNum())
                    {
                        label3.Show();
                        pictureBox7.Show();
                        flag = false;
                        return;
                    }
                    else
                    {
                        label3.Hide();
                        pictureBox7.Hide();
                    }
                    reader = selecterDemo.execute();
                    reader.Read();
                    password = reader.GetString("stu_password");
                    username = reader.GetString("stu_name");
                    reader.Dispose();
                    if (pw.unlockstring(password) != textBox2.Text)
                    {
                        label2.Show();
                        pictureBox8.Show();
                        flag = false;
                        return;
                    }
                    else
                    {
                        label2.Hide();
                        pictureBox8.Hide();//到此学生成功登陆
                    }
                }
                finally
                {
                    selecterDemo.end();
                }
                this.Hide();
                main_student ms = new main_student(CP, user, username);
                ms.ShowDialog(this);
                this.Show();
            }
            if (radioButton1.Checked)//教师
            {
                string   sql          = $"select * from tb_teacher where teacher_num = '{user}'";
                selecter selecterDemo = new selecter(CP, sql);
                try
                {
                    if (0 == selecterDemo.getNum())
                    {
                        label3.Show();
                        pictureBox7.Show();
                        flag = false;
                        return;
                    }
                    else
                    {
                        label3.Hide();
                        pictureBox7.Hide();
                    }
                    reader = selecterDemo.execute();
                    reader.Read();
                    password = reader.GetString("teacher_password");
                    username = reader.GetString("teacher_name");
                    reader.Dispose();
                    if (pw.unlockstring(password) != textBox2.Text)
                    {
                        label2.Show();
                        pictureBox8.Show();
                        flag = false;
                        return;
                    }
                    else
                    {
                        label2.Hide();
                        pictureBox8.Hide();//到此教师成功登陆
                    }
                }
                finally
                {
                    selecterDemo.end();
                }
                this.Hide();
                main_teacher mt = new main_teacher(CP, user, username);
                mt.ShowDialog(this);
                this.Show();
            }
        }