Пример #1
0
        private void button4_Click(object sender, EventArgs e)
        {
            int flag = 0;

            try
            {
                conn.Open();
                string fenshu    = watermarkTextBox2.Text.Trim();
                string select_id = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();                                                      //选择的当前行第一列的值,也就是学号

                string     classid      = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();                                               //当前行第二列的值
                string     update_by_id = "update sc set grades='" + fenshu + "'where stuxuehao='" + select_id + "'and claid='" + classid + "'"; //sql更新语句
                SqlCommand cmd          = new SqlCommand(update_by_id, conn);
                cmd.ExecuteNonQuery();                                                                                                           //执行命令

                String        select_by_chose = "select stuxuehao as 学号,claid as 课程号,stuname as 姓名,stugrade as 年级, stubanji as 班级,stusex as 性别,claname as 课程,grades as 成绩,term as 学期 from ownstu2 where teacherid='" + FrmLogin.gettid() + "'";
                SqlCommand    sqlCommand      = new SqlCommand(select_by_chose, conn);
                SqlDataReader sqlDataReader   = sqlCommand.ExecuteReader();
                BindingSource bindingSource   = new BindingSource();
                bindingSource.DataSource = sqlDataReader;
                dataGridView1.DataSource = bindingSource;
            }
            catch
            {
                flag = 1;
                MessageBox.Show("请正确选择行!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                conn.Close();
            }

            if (flag == 0)
            {
                MessageBox.Show("录入成绩成功!", "Tips", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
        }
Пример #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            string        classes = textBox1.Text;
            string        term    = comboBox1.SelectedItem.ToString();
            string        flags   = "1";
            SqlConnection conn    = new SqlConnection(updatepswd.connectionString);

            conn.Open();
            SqlCommand cmd = new SqlCommand();

            cmd.Connection = conn;
            //将开课信息插入到开课表里


            string sql = "";

            string didian = comboBox2.SelectedItem.ToString(); //得到上课的地点

            for (int i = 0; i < checkedListBox1.Items.Count; i++)
            {
                if (checkedListBox1.GetItemChecked(i))
                {
                    string time = checkedListBox1.GetItemText(checkedListBox1.Items[i]);
                    sql = "select * from sctime where sctime = '" + time + "'and location = '" + didian + "'and term='" + term + "'";
                    SqlDataAdapter adp = new SqlDataAdapter(sql, conn);
                    DataSet        ds  = new DataSet();
                    adp.Fill(ds);
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        flags = "2";
                        MessageBox.Show("该时间该教室已经有课!");
                        break;
                    }
                    else
                    {
                        flags = "1";
                        break;
                    }
                }
            }
            if (flags == "1")
            {
                string teachername = string.Empty;
                //conn = new SqlConnection();
                //     conn.Open();
                SqlCommand getValueCom = conn.CreateCommand();
                getValueCom.CommandText = "select tname from teacher where teachbm=" + FrmLogin.gettid();
                SqlDataReader getValueReader = getValueCom.ExecuteReader();
                if (getValueReader.Read())
                {
                    teachername = getValueReader[0].ToString().Trim();
                }
                getValueReader.Close();


                sql             = "insert into class (claname,term,teacherid,teachername) values ('" + classes + "','" + term + "','" + FrmLogin.gettid() + "','" + teachername + "')";
                cmd.CommandText = sql;
                cmd.ExecuteNonQuery();



                for (int i = 0; i < checkedListBox1.Items.Count; i++)
                {
                    if (checkedListBox1.GetItemChecked(i))
                    {
                        string time = checkedListBox1.GetItemText(checkedListBox1.Items[i]);
                        //将上课时间得到
                        sql             = "select claid from class where claname = '" + classes + "' and term = '" + term + "' and teacherid = '" + FrmLogin.gettid() + "'";
                        cmd.CommandText = sql;
                        String id1 = cmd.ExecuteScalar().ToString();
                        int    id  = 0;
                        int.TryParse(id1, out id);


                        sql             = "insert into sctime values(" + id + ",'" + FrmLogin.gettid() + "','" + time + "','" + didian + "','" + term + "')";
                        cmd.CommandText = sql;
                        cmd.ExecuteNonQuery();
                    }
                }
                MessageBox.Show("开设课程成功!");
            }

            conn.Close();
        }
Пример #3
0
        private void tmanas_Load(object sender, EventArgs e)
        {
            try {
                conn.Open();
                string     jiancha = "IF (EXISTS(SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME=N'mycourse4')) DROP VIEW mycourse4";
                SqlCommand cmd     = new SqlCommand(jiancha, conn);
                cmd.ExecuteNonQuery();  //执行命令

                string     cj   = "CREATE VIEW ownstu2 AS SELECT student.stuxuehao,student.stuname,student.stugrade,student.stubanji,student.stusex,class.claname,class.teacherid,sc.grades,class.term,class.claid FROM class,sc,student where class.claid=sc.claid and sc.stuxuehao=student.stuxuehao and teacherid='" + FrmLogin.gettid() + "'";
                SqlCommand cmd2 = new SqlCommand(cj, conn);
                cmd.ExecuteNonQuery();  //执行命令
            }
            catch { }
            finally { conn.Close(); }
        }
Пример #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();
            }
        }