using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
    public partial class Form121 : Form
    {
        private object sno;
        DataBase mydatabase = new DataBase();
        public Form121(object snumber)
        {
            InitializeComponent();
            sno = snumber;
            string sqlstring = "select cname,degree from student,score,course where student.sno=score.sno and course.cno=score.cno and student.sno="+sno.ToString();
            DataSet ds = mydatabase.GetDataSet(sqlstring);
            dataGridView1.DataSource = ds.Tables[0].DefaultView;
        }

        private void Form121_Load(object sender, EventArgs e)
        {
            dataGridView1.AutoGenerateColumns = false;
            //禁止自动生成行
            dataGridView1.Columns[0].ReadOnly = true;
            dataGridView1.Columns[1].ReadOnly = true;
            //属性项只读
        }
        /// <summary>
        /// 格式化数据项
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            //获取成绩
            if (e.ColumnIndex == dataGridView1.Columns["degree"].Index)
            {
                object studegree = dataGridView1.Rows[e.RowIndex].Cells["degree"].Value;
                int sdegree = Convert.ToInt16(studegree);
                if (sdegree < 60 && studegree != null)
                {
                    e.CellStyle.BackColor = Color.Red;
                    e.CellStyle.SelectionBackColor = Color.Green;
                    e.CellStyle.SelectionForeColor = Color.Black;
                }
            }
        }
    }
}