Exemple #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                string        sql;
                string        flags = "1";
                SqlConnection conn  = new SqlConnection(updatepswd.connectionString);
                conn.Open();

                string select_id = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();//选择的当前行第一列的值,也就是课程号
                sql = "select sctime from sctime where claid =" + select_id;
                SqlCommand     cmd = new SqlCommand(sql, conn);
                SqlDataAdapter adp = new SqlDataAdapter(sql, conn);
                DataSet        ds  = new DataSet();
                adp.Fill(ds);
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    string  term = comboBox1.Text.Trim();
                    DataRow dr   = ds.Tables[0].Rows[i];
                    string  time = dr[0].ToString();//第一列
                    sql = "select * from sc,sctime,class where class.claid = sc.claid and class.claid = sctime.claid and sctime = '" + time + "' and sc.stuxuehao='" + FrmLogin.getStudent() + "'and class.term='" + term + "'";
                    SqlDataAdapter adp1 = new SqlDataAdapter(sql, conn);
                    DataSet        ds1  = new DataSet();
                    adp1.Fill(ds1);
                    if (ds1.Tables[0].Rows.Count > 0)
                    {
                        flags = "2";
                        MessageBox.Show("课程上课时间冲突!");
                        break;
                    }
                    if (flags == "1")
                    {
                        sql             = "insert into sc(claid,stuxuehao,term) values(" + select_id + "," + FrmLogin.getStudent() + ",'" + term + "')";
                        cmd.CommandText = sql;
                        if (cmd.ExecuteNonQuery() > 0)
                        {
                            MessageBox.Show("选课成功!");
                        }
                    }

                    sql = "select class.claname  from sc,class where sc.claid = class.claid and stuxuehao='" + FrmLogin.getStudent() + "'";
                    SqlDataAdapter adp2 = new SqlDataAdapter(sql, conn);
                    DataSet        ds2  = new DataSet();
                    adp2.Fill(ds2);

                    conn.Close();
                }
            }
            catch {
                MessageBox.Show("请正确点击!");
            }
        }
Exemple #2
0
 private void button1_Click(object sender, EventArgs e)
 {
     while (dataGridView1.Rows.Count != 0)
     {
         dataGridView1.DataSource = null;
     }
     if (comboBox1.Text == "" && textBox1.Text == "")
     {
         MessageBox.Show("请输入查询信息!");
     }
     else if (comboBox1.Text != "" && textBox1.Text == "")
     {
         SqlConnection conn = new SqlConnection(updatepswd.connectionString);
         conn.Open();
         string         sql  = "select claid as 课程号,claname as 课程名,sctime as 上课时间,term as 学期,location as 上课地点,teachername as 任课老师 from mycourse5 where term='" + comboBox1.Text.Trim() + "'and stuxuehao='" + FrmLogin.getStudent() + "'";
         SqlDataAdapter adp1 = new SqlDataAdapter(sql, conn);
         DataSet        ds   = new DataSet();
         adp1.Fill(ds);
         //载入基本信息
         dataGridView1.DataSource = ds.Tables[0].DefaultView;
         conn.Close();
     }
     else if (textBox1.Text != "" && comboBox1.Text == "")
     {
         SqlConnection conn = new SqlConnection(updatepswd.connectionString);
         conn.Open();
         //textBox1.Text.Trim()  textBox2.Text.Trim()
         string         sql  = "select claid as 课程号,claname as 课程名,sctime as 上课时间,term as 学期,location as 上课地点,teachername as 任课老师 from mycourse5 where claname='" + textBox1.Text.Trim() + "'and stuxuehao='" + FrmLogin.getStudent() + "'";
         SqlDataAdapter adp1 = new SqlDataAdapter(sql, conn);
         DataSet        ds   = new DataSet();
         adp1.Fill(ds);
         //载入基本信息
         dataGridView1.DataSource = ds.Tables[0].DefaultView;
         conn.Close();
     }
     else if (textBox1.Text != "" && comboBox1.Text != "")
     {
         SqlConnection conn = new SqlConnection(updatepswd.connectionString);
         conn.Open();
         //textBox1.Text.Trim()  textBox2.Text.Trim()
         string         sql  = "select claid as 课程号,claname as 课程名,sctime as 上课时间,term as 学期,location as 上课地点,teachername as 任课老师 from mycourse5 where claname='" + textBox1.Text.Trim() + "'and stuxuehao='" + FrmLogin.getStudent() + "'and term='" + comboBox1.Text.Trim() + "'";
         SqlDataAdapter adp1 = new SqlDataAdapter(sql, conn);
         DataSet        ds   = new DataSet();
         adp1.Fill(ds);
         //载入基本信息
         dataGridView1.DataSource = ds.Tables[0].DefaultView;
         conn.Close();
     }
 }
Exemple #3
0
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                SqlConnection conn    = new SqlConnection(updatepswd.connectionString);
                String        strterm = comboBox1.SelectedItem.ToString();
                conn.Open();
                // string select_by_term = "select * from class where term="+strsort;


                string         sql  = "select claname as 课程名,grades as 成绩,teachername as 任课老师,term as 学期 from mygrades where term='" + strterm + "'and stuxuehao='" + FrmLogin.getStudent() + "'";
                SqlDataAdapter adp1 = new SqlDataAdapter(sql, conn);
                DataSet        ds   = new DataSet();
                adp1.Fill(ds);
                //载入基本信息
                dataGridView1.DataSource = ds.Tables[0].DefaultView;
                conn.Close();
            }
            catch
            {
                MessageBox.Show("查询语句有误!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemple #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            string        passwd    = textBox2.Text;
            string        quepasswd = textBox3.Text;
            SqlConnection sqlCnt    = new SqlConnection(connectionString);

            sqlCnt.Open();

            if (passwd == "" || quepasswd == "")
            {
                MessageBox.Show("请将信息填写完整!");
            }
            else
            {
                if (quepasswd != passwd)
                {
                    MessageBox.Show("两次输入的密码不一致!");
                }
                else
                {
                    if (FrmLogin.getRole() == "学生")
                    {
                        SqlCommand command = new SqlCommand();
                        command.Connection = sqlCnt;
                        string sql = "update student set stupasswd ='" + passwd + "' where stuxuehao = '" + FrmLogin.getStudent() + "'";
                        command.CommandText = sql;
                        command.ExecuteNonQuery();
                        MessageBox.Show("修改密码成功!");
                        this.Close();
                    }
                    else if (FrmLogin.getRole() == "教师")
                    {
                        SqlCommand command = new SqlCommand();
                        command.Connection = sqlCnt;
                        string sql = "update Teacher set teachpasswd ='" + passwd + "' where teachbm = '" + FrmLogin.gettid() + "'";
                        command.CommandText = sql;
                        command.ExecuteNonQuery();
                        MessageBox.Show("修改密码成功!");
                        this.Close();
                    }
                    else
                    {
                        SqlCommand command = new SqlCommand();
                        command.Connection = sqlCnt;
                        string sql = "update Users set userpassword ='******' where userid = '" + FrmLogin.getid() + "'";
                        command.CommandText = sql;
                        command.ExecuteNonQuery();
                        MessageBox.Show("修改密码成功!");
                        this.Close();
                    }
                }
                sqlCnt.Close();
            }
        }