예제 #1
0
        private void BtnScoreAdd_Click(object sender, EventArgs e)
        {
            if (CboSno.Text == "")
            {
                MessageBox.Show("请选择学号!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                CboSno.Focus();
            }
            else if (CboCourse.Text == "")
            {
                MessageBox.Show("请选择课程号!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                CboCourse.Focus();
            }
            else if (CboYear.Text == "")
            {
                MessageBox.Show("请选择学年!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                CboYear.Focus();
            }
            else if (CboTeam.Text == "")
            {
                MessageBox.Show("请选择学期!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                CboTeam.Focus();
            }
            else if (TxtGrade.Text == "")
            {
                MessageBox.Show("请输入成绩!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                TxtGrade.Focus();
            }
            else
            {
                try
                {
                    string str = string.Format(" insert into tbscore(studentNo,courseID,score,term,Year) values('{0}','{1}','{2}','{3}','{4}')", CboSno.Text, Status.sql, int.Parse(TxtGrade.Text), CboTeam.Text, CboYear.Text);
                    DBHelper.conn.Open();
                    SqlCommand command = new SqlCommand(str, DBHelper.conn);
                    int        result  = command.ExecuteNonQuery();

                    if (result < 1)
                    {
                        MessageBox.Show("成绩录入失败!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("成绩录入成功!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("数据库操作错误:" + ex.Message, "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    DBHelper.conn.Close();
                    this.ViewInfo();
                }
            }
        }
        public void BindCombo()
        {
            string ymd = bbl.GetDate();

            cboWarehouse.Bind(string.Empty, "");
            CboYear.Bind(ymd);
            cboSeason.Bind(ymd);
            cboReservation.Bind(ymd);
            cboNotices.Bind(ymd);
            cboOrder.Bind(ymd);
            cboPostage.Bind(ymd);
            cboTag1.Bind(ymd);
            cboTag2.Bind(ymd);
            cboTag3.Bind(ymd);
            cboTag4.Bind(ymd);
            cboTag5.Bind(ymd);
        }
예제 #3
0
        private void BtnSelect_Click(object sender, EventArgs e)
        {
            if (CboSearchType.Text == "")
            {
                MessageBox.Show("请选择查询类型!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                CboSearchType.Focus();
            }
            else if (CboSearchType.Text == "按学号")
            {
                if (TxtSno.Text == "")
                {
                    MessageBox.Show("请输入学号!", "查询提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    TxtSno.Focus();
                }
                string sql = string.Format("select distinct studentNo 学号,courseID 课程号,score 成绩,term 学期,Year 学年 from tbscore where studentNo='{0}'", TxtSno.Text);
                DBHelper.conn.Open();
                SqlCommand     command = new SqlCommand(sql, DBHelper.conn);
                DataSet        ds      = new DataSet();
                SqlDataAdapter sda     = new SqlDataAdapter();
                sda.SelectCommand = command;
                sda.Fill(ds);
                DataView dv = new DataView(ds.Tables[0]);
                DGVScoreList.DataSource = dv;
                DBHelper.conn.Close();
            }
            else if (CboSearchType.Text == "按课程")
            {
                if (CboCourse.Text == "")
                {
                    MessageBox.Show("请选择课程!", "查询提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    CboCourse.Focus();
                }
                else
                {
                    string sql1 = string.Format("select courseID from tbcourse where courseName='{0}'", CboCourse.Text);
                    if (DBHelper.conn.State == ConnectionState.Closed)
                    {
                        DBHelper.conn.Open();
                    }
                    else
                    {
                        DBHelper.conn.Close(); DBHelper.conn.Open();
                    }

                    SqlCommand    command    = new SqlCommand(sql1, DBHelper.conn);
                    SqlDataReader datareader = command.ExecuteReader();
                    while (datareader.Read())
                    {
                        Status.sql1 = (string)datareader["courseID"];
                    }
                    DBHelper.conn.Close();

                    string str = string.Format("select distinct studentNo 学号,courseID 课程号,score 成绩,term 学期,Year 学年 from tbscore where courseID='{0}'", Status.sql1);
                    DBHelper.conn.Open();
                    SqlCommand     cmd = new SqlCommand(str, DBHelper.conn);
                    DataSet        ds  = new DataSet();
                    SqlDataAdapter sda = new SqlDataAdapter();
                    sda.SelectCommand = cmd;
                    sda.Fill(ds);
                    DataView dv = new DataView(ds.Tables[0]);
                    DGVScoreList.DataSource = dv;
                    DBHelper.conn.Close();
                }
            }
            else if (CboSearchType.Text == "按学期")
            {
                if (CboTeam.Text == "")
                {
                    MessageBox.Show("请选择学期", "查询提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    CboTeam.Focus();
                }
                else
                {
                    Status.sql2 = "select distinct studentNo 学号,courseID 课程号,score 成绩,term 学期,Year 学年 from tbscore where term='" + CboTeam.Text.Trim() + "'";

                    DBHelper.conn.Open();
                    SqlCommand     command = new SqlCommand(Status.sql2, DBHelper.conn);
                    DataSet        ds      = new DataSet();
                    SqlDataAdapter sda     = new SqlDataAdapter();
                    sda.SelectCommand = command;
                    sda.Fill(ds);
                    DataView dv = new DataView(ds.Tables[0]);
                    DGVScoreList.DataSource = dv;
                    DBHelper.conn.Close();
                }
            }
            else if (CboSearchType.Text == "按学年")
            {
                if (CboYear.Text == "")
                {
                    MessageBox.Show("请选择学年!", "查询提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    CboYear.Focus();
                }
                else
                {
                    Status.sql3 = "select distinct studentNo 学号,courseID 课程号,score 成绩,term 学期,Year 学年 from tbscore where Year='" + CboYear.Text.Trim() + "'";

                    DBHelper.conn.Open();
                    SqlCommand     command = new SqlCommand(Status.sql3, DBHelper.conn);
                    DataSet        ds      = new DataSet();
                    SqlDataAdapter sda     = new SqlDataAdapter();
                    sda.SelectCommand = command;
                    sda.Fill(ds);
                    DataView dv = new DataView(ds.Tables[0]);
                    DGVScoreList.DataSource = dv;
                    DBHelper.conn.Close();
                }
            }
        }