예제 #1
0
        public Stu_Search(LoginIn_Stu parent, string id)
        {
            InitializeComponent();
            pform = parent;
            sid   = id;
            string sql = "select distinct cid from choices where sid = '" + sid + "'";


            if (Ad_ChooseManage.ExecuteSql(sql) != 0)
            {
                this.cbox_cid.DataSource = Ad_ChooseManage.Query(sql).Tables["choices"];
                cbox_cid.DisplayMember   = "cid";
            }

            string sql1 = "select distinct cterm from choices where sid = '" + sid + "'";


            if (Ad_ChooseManage.ExecuteSql(sql1) != 0)
            {
                this.cbox_term.DataSource = Ad_ChooseManage.Query(sql1).Tables["choices"];
                cbox_term.DisplayMember   = "cterm";
            }
        }
예제 #2
0
        private void btn_login_Click(object sender, EventArgs e)
        {
            if (login_id.Text.Trim() == "")
            {
                MessageBox.Show("登陆名不能为空");
            }
            else if (login_pwd.Text.Trim() == "")
            {
                MessageBox.Show("密码不能为空");
            }
            else
            {
                string        id  = login_id.Text.Trim();
                string        pwd = login_pwd.Text.Trim();
                string        sql;
                SqlConnection con = new SqlConnection(connectionString); //创建一个数据库连接
                if (radioButton_ad.Checked)                              //管理员
                {
                    sql = "select * from users where uid = " + id + " and upasswd = " + pwd + " and ugroup = 1";
                }
                else if (radioButton_t.Checked) //教师
                {
                    sql = "select * from users where uid = " + id + " and upasswd = " + pwd + " and ugroup = 2";
                }
                //else if (radioButton_stu.Checked) //学生
                else
                {
                    sql = "select * from users where uid = " + id + " and upasswd = " + pwd + " and ugroup = 3";
                }

                SqlCommand cmd = new SqlCommand(sql, con);//创建一个SqlCommand,用于对数据库进行操作
                try
                {
                    con.Open();//打开连接
                    SqlDataReader reader = cmd.ExecuteReader();
                    if (!reader.Read())
                    {
                        MessageBox.Show("用户名或密码错误,请重试!");
                        login_id.Text  = "";
                        login_pwd.Text = "";
                    }
                    else
                    {
                        string time = DateTime.Now.ToString();
                        if (radioButton_ad.Checked)
                        {
                            LoginIn_Ad childrenForm = new LoginIn_Ad(id, time);
                            childrenForm.Owner = this;
                            this.Hide();
                            childrenForm.Show();
                        }
                        else if (radioButton_stu.Checked)
                        {
                            LoginIn_Stu childrenForm = new LoginIn_Stu(id, time);
                            childrenForm.Owner = this;
                            this.Hide();
                            childrenForm.Show();
                        }
                        else if (radioButton_t.Checked)
                        {
                            LoginIn_Teacher childrenForm = new LoginIn_Teacher(id, time);
                            childrenForm.Owner = this;
                            this.Hide();
                            childrenForm.Show();
                        }
                    }
                }
                catch (SqlException e1)
                {
                    MessageBox.Show(e1.Message);
                }
                finally
                {
                    cmd.Dispose();//cmd处理
                    con.Close();
                }
            }
        }