我是一名学生 最近在做一个课程设计 要求内容:
1、建立一个学生成绩管理系统数据库(一个学生信息表,一个学生成绩表,一个课程信息表)
2、对每个表都有增、删、改、查功能
3、对学生成绩有计算总分和平均分的功能
4、显示学生成绩表时,对成绩<60用红色字体显示
(1)60<=成绩<70 :显示1个星图标
(2)70<=成绩<80 :显示2个星图标
(3)80<=成绩<90 :显示3个星图标
(4)90<=成绩<100 :显示4个星图标
(5)成绩=100 :显示5个星图标
5、成绩<60,显示“补考”button,并实现“补考功能”(把相应成绩改为60以上)
成绩>60,显示“通过”button,并实现“通过”功能(统计该学生平均成绩);
给怎么做学生成绩表的功能
//代码如下
public scmanage()
{
InitializeComponent();
string str = "select * from tb_score";
GetDB(str);
}
private void GetDB(string str)
{
con = new SqlConnection("Data Source=.;Initial Catalog=StuManage;Integrated Security=True");
con.Open();
cmd = new SqlCommand(str, con);
sdr = new SqlDataAdapter();
sdb = new SqlCommandBuilder(sdr);
sdr.SelectCommand = cmd;
ds = new DataSet();
sdr.Fill(ds);
DataTable te=ds.Tables[0];
sdr.TableMappings.Add("tb_score", "tb_score");
sdr.TableMappings[0].ColumnMappings.Add("sno", "学号");
sdr.TableMappings[0].ColumnMappings.Add("sname", "姓名");
sdr.TableMappings[0].ColumnMappings.Add("cname", "科目");
sdr.TableMappings[0].ColumnMappings.Add("score", "成绩");
ds.Tables[0].Columns["sno"].ColumnName = "学号";
ds.Tables[0].Columns["sname"].ColumnName = "姓名";
ds.Tables[0].Columns["cname"].ColumnName = "科目";
ds.Tables[0].Columns["score"].ColumnName = "成绩";
dataGridView1.DataSource = ds.Tables[0];
data_Bind(ds.Tables["tb_score"]);
con.Close();
} public void data_Bind(DataTable table)
{
foreach (DataRow row1 in ds.Tables[0].Rows)
{
DataGridViewRow gridRow = new DataGridViewRow();
DataGridViewButtonCell btn_cell = new DataGridViewButtonCell();
DataGridViewTextBoxCell txt_star = new DataGridViewTextBoxCell();
btn_cell.Value = "通过";
for (int col_index = 0; col_index < ds.Tables[0].Columns.Count;col_index++ )
{
DataGridViewTextBoxCell cell = new DataGridViewTextBoxCell();
cell.Value = row1[col_index];
gridRow.Cells.Add(cell);
if (col_index == 5)
{
try
{
txt_star.Value = get_starPath(Convert.ToInt32(row1[5]));
}
catch { MessageBox.Show("图片不存在"); }
if (Convert.ToDecimal(row1[5]) < 60)
{
DataGridViewCellStyle cellStyle = new DataGridViewCellStyle();
cellStyle.ForeColor = Color.Red;
cell.Style = cellStyle;
btn_cell.Value = "补考";
}
}
}
gridRow.Cells.Add(txt_star);
gridRow.Cells.Add(btn_cell);
dataGridView1.Rows.Add(gridRow);
}
}
public string get_starPath(int score)
{
int s = (score / 10);
switch (s)
{
case 6: return " * ";
case 7: return "* *";
case 8: return "* * *";
case 9: return "* * * *";
case 10: return "* * * * *";
default: return "";
}
}DataGridView编程控件
1、建立一个学生成绩管理系统数据库(一个学生信息表,一个学生成绩表,一个课程信息表)
2、对每个表都有增、删、改、查功能
3、对学生成绩有计算总分和平均分的功能
4、显示学生成绩表时,对成绩<60用红色字体显示
(1)60<=成绩<70 :显示1个星图标
(2)70<=成绩<80 :显示2个星图标
(3)80<=成绩<90 :显示3个星图标
(4)90<=成绩<100 :显示4个星图标
(5)成绩=100 :显示5个星图标
5、成绩<60,显示“补考”button,并实现“补考功能”(把相应成绩改为60以上)
成绩>60,显示“通过”button,并实现“通过”功能(统计该学生平均成绩);
给怎么做学生成绩表的功能
//代码如下
public scmanage()
{
InitializeComponent();
string str = "select * from tb_score";
GetDB(str);
}
private void GetDB(string str)
{
con = new SqlConnection("Data Source=.;Initial Catalog=StuManage;Integrated Security=True");
con.Open();
cmd = new SqlCommand(str, con);
sdr = new SqlDataAdapter();
sdb = new SqlCommandBuilder(sdr);
sdr.SelectCommand = cmd;
ds = new DataSet();
sdr.Fill(ds);
DataTable te=ds.Tables[0];
sdr.TableMappings.Add("tb_score", "tb_score");
sdr.TableMappings[0].ColumnMappings.Add("sno", "学号");
sdr.TableMappings[0].ColumnMappings.Add("sname", "姓名");
sdr.TableMappings[0].ColumnMappings.Add("cname", "科目");
sdr.TableMappings[0].ColumnMappings.Add("score", "成绩");
ds.Tables[0].Columns["sno"].ColumnName = "学号";
ds.Tables[0].Columns["sname"].ColumnName = "姓名";
ds.Tables[0].Columns["cname"].ColumnName = "科目";
ds.Tables[0].Columns["score"].ColumnName = "成绩";
dataGridView1.DataSource = ds.Tables[0];
data_Bind(ds.Tables["tb_score"]);
con.Close();
} public void data_Bind(DataTable table)
{
foreach (DataRow row1 in ds.Tables[0].Rows)
{
DataGridViewRow gridRow = new DataGridViewRow();
DataGridViewButtonCell btn_cell = new DataGridViewButtonCell();
DataGridViewTextBoxCell txt_star = new DataGridViewTextBoxCell();
btn_cell.Value = "通过";
for (int col_index = 0; col_index < ds.Tables[0].Columns.Count;col_index++ )
{
DataGridViewTextBoxCell cell = new DataGridViewTextBoxCell();
cell.Value = row1[col_index];
gridRow.Cells.Add(cell);
if (col_index == 5)
{
try
{
txt_star.Value = get_starPath(Convert.ToInt32(row1[5]));
}
catch { MessageBox.Show("图片不存在"); }
if (Convert.ToDecimal(row1[5]) < 60)
{
DataGridViewCellStyle cellStyle = new DataGridViewCellStyle();
cellStyle.ForeColor = Color.Red;
cell.Style = cellStyle;
btn_cell.Value = "补考";
}
}
}
gridRow.Cells.Add(txt_star);
gridRow.Cells.Add(btn_cell);
dataGridView1.Rows.Add(gridRow);
}
}
public string get_starPath(int score)
{
int s = (score / 10);
switch (s)
{
case 6: return " * ";
case 7: return "* *";
case 8: return "* * *";
case 9: return "* * * *";
case 10: return "* * * * *";
default: return "";
}
}DataGridView编程控件
4、显示学生成绩表时,对成绩<60用红色字体显示
(1)60<=成绩<70 :显示1个星图标
(2)70<=成绩<80 :显示2个星图标
(3)80<=成绩<90 :显示3个星图标
(4)90<=成绩<100 :显示4个星图标
(5)成绩=100 :显示5个星图标
5、成绩<60,显示“补考”button,并实现“补考功能”(把相应成绩改为60以上)
成绩>60,显示“通过”button,并实现“通过”功能(统计该学生平均成绩);public scmanage()
{
InitializeComponent();
string str = "select * from tb_score";
GetDB(str);
} private void GetDB(string str)
{
con = new SqlConnection("Data Source=.;Initial Catalog=StuManage;Integrated Security=True");
con.Open();
cmd = new SqlCommand(str, con);
sdr = new SqlDataAdapter();
sdb = new SqlCommandBuilder(sdr);
sdr.SelectCommand = cmd;
ds = new DataSet();
sdr.Fill(ds);
DataTable te=ds.Tables[0];
sdr.TableMappings.Add("tb_score", "tb_score");
sdr.TableMappings[0].ColumnMappings.Add("sno", "学号");
sdr.TableMappings[0].ColumnMappings.Add("sname", "姓名");
sdr.TableMappings[0].ColumnMappings.Add("cname", "科目");
sdr.TableMappings[0].ColumnMappings.Add("score", "成绩"); ds.Tables[0].Columns["sno"].ColumnName = "学号";
ds.Tables[0].Columns["sname"].ColumnName = "姓名";
ds.Tables[0].Columns["cname"].ColumnName = "科目";
ds.Tables[0].Columns["score"].ColumnName = "成绩";
dataGridView1.DataSource = ds.Tables[0];
DataGridViewButtonColumn col_btn_state = new DataGridViewButtonColumn();
col_btn_state.HeaderText = "通过";
col_btn_state.UseColumnTextForButtonValue = true;
dataGridView1.Columns.Add(col_btn_state);
con.Close();
}
改成这样以后 怎么正确的显示上面所说的功能 让星型正常显示 补考和通过也正常显示
代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;namespace WindowsFormsApplication1
{
public partial class scmanage : Form
{
public SqlConnection con;
public SqlDataAdapter sdr;
public SqlCommandBuilder sdb;
public SqlCommand cmd;
public DataSet ds;
public scmanage()
{
InitializeComponent();
string str = "select * from tb_score";
GetDB(str);
} private void btndele_Click(object sender, EventArgs e)
{
//MessageBox.Show("你点击了删除按钮");
if (MessageBox.Show("确定要删除当前行数据?", "信息提示", MessageBoxButtons.OKCancel) == DialogResult.OK)
{
//此方法直接从数据库中删除在绑定数据库
//string no = this.dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString(); //SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=StuManage;Integrated Security=True");
//con.Open(); //SqlCommand cmd = new SqlCommand("delete from tb_course where cno='" + no + "'", con);
//int o = cmd.ExecuteNonQuery();
//if (o > 0)
//{
// MessageBox.Show("删除数据成功", "信息提示", MessageBoxButtons.OK);
//}
//else
//{
// MessageBox.Show("删除数据不成功", "信息提示", MessageBoxButtons.OK);
//} //string str = "select * from tb_course";
//GetDB(str);
//此方法直接在绑定的数据源中删除并更新到数据库中
try
{
ds.Tables[0].Rows[dataGridView1.CurrentRow.Index].Delete();
sdr.Update(ds.Tables[0].GetChanges());
MessageBox.Show("数据删除成功");
ds.Tables[0].AcceptChanges();
}
catch (SqlException ex)
{
MessageBox.Show(ex.ToString());
}
}
else
{
MessageBox.Show("你点击了取消按钮");
}
} private void btnup_Click(object sender, EventArgs e)
{
//MessageBox.Show("你点击了修改按钮");
if (MessageBox.Show("确定要修改当前行数据?", "信息提示", MessageBoxButtons.OKCancel) == DialogResult.OK)
{
try
{ // sdr.Update(ds.Tables["tb_course"].GetChanges());
//cmd = new SqlCommand("update tb_course set cno='"+no+"',cname='"+name+"',ccredit='"+credit+"'",con);
//sdr.UpdateCommand = cmd;
//sdr.Update(ds.Tables[0]);
//sdb = new SqlCommandBuilder(sdr);
//sdr.Update(ds.Tables["tb_course"].GetChanges());
//sdr.Update(ds, "tb_course");
//sdr.Update(ds.Tables[0]);
//sdr.Update(ds.Tables["tb_sinfo"].GetChanges()); sdr.Update(ds.Tables[0].GetChanges());
MessageBox.Show("数据修改成功");
// sdr.Update(ds.Tables[0].GetChanges()); //ds.Tables[0].GetChanges();
ds.Tables[0].AcceptChanges();
//ds.Tables["tb_sinfo"].AcceptChanges(); }
catch (SqlException ex)
{
MessageBox.Show(ex.ToString());
}
}
} private void btninser_Click(object sender, EventArgs e)
{
// MessageBox.Show("你点击了增添按钮");
if (MessageBox.Show("确定要增添当前行数据?", "信息提示", MessageBoxButtons.OKCancel) == DialogResult.OK)
{
try
{ //sdr.Update(ds.Tables[0]);
sdr.Update(ds.Tables[0].GetChanges());
MessageBox.Show("增加数据成功");
ds.Tables[0].AcceptChanges();
}
catch (SqlException ex)
{
MessageBox.Show(ex.ToString());
}
}
} private void btnsele_Click(object sender, EventArgs e)
{
if (comboBox1.Text == "学号")
{
string str = "select * from tb_score where sno='" + textBox1.Text.Trim() + "'";
GetDB(str);
}
if (comboBox1.Text == "姓名")
{
string str = "select * from tb_score where sname='" + textBox1.Text.Trim() + "'";
GetDB(str); }
if (comboBox1.Text == "成绩")
{
string str = "select * from tb_score where score='"+textBox1.Text.Trim()+"'";
GetDB(str);
}
if (comboBox1.Text == "科目")
{
string str = "select * from tb_score where cname='"+textBox1.Text.Trim()+"'";
GetDB(str);
}
if (comboBox1.Text == "" || textBox1.Text == "")
{ MessageBox.Show("请选择查询的方式并且在输入框中输入相应的查询信息", "查询提示");
return;
}
} private void GetDB(string str)
{
con = new SqlConnection("Data Source=.;Initial Catalog=StuManage;Integrated Security=True");
con.Open();
cmd = new SqlCommand(str, con);
sdr = new SqlDataAdapter();
sdb = new SqlCommandBuilder(sdr);
sdr.SelectCommand = cmd;
ds = new DataSet();
sdr.Fill(ds);
DataTable te=ds.Tables[0]; sdr.TableMappings.Add("tb_score", "tb_score");
sdr.TableMappings[0].ColumnMappings.Add("sno", "学号");
sdr.TableMappings[0].ColumnMappings.Add("sname", "姓名");
sdr.TableMappings[0].ColumnMappings.Add("cname", "科目");
sdr.TableMappings[0].ColumnMappings.Add("score", "成绩"); ds.Tables[0].Columns["sno"].ColumnName = "学号";
ds.Tables[0].Columns["sname"].ColumnName = "姓名";
ds.Tables[0].Columns["cname"].ColumnName = "科目";
ds.Tables[0].Columns["score"].ColumnName = "成绩";
dataGridView1.DataSource = ds.Tables[0];
DataGridViewButtonColumn col_btn_st = new DataGridViewButtonColumn();
col_btn_st.HeaderText = "状态"; col_btn_st.UseColumnTextForButtonValue = true;
dataGridView1.Columns.Add(col_btn_st); DataGridViewButtonColumn col_btn_state = new DataGridViewButtonColumn();
col_btn_state.HeaderText = "等级";
col_btn_state.UseColumnTextForButtonValue = true;
dataGridView1.Columns.Add(col_btn_state);
foreach (DataRow row1 in ds.Tables[0].Rows)
{ //通过和补考不能正常显示
for (int col_index = 0; col_index < ds.Tables[0].Columns.Count; col_index++)
{
if (col_index == 3)
{
try
{
//调用显示星型的函数时 星型不能正常显示
col_btn_st.Text = get_starPath(Convert.ToInt32(row1[3])); }
catch { MessageBox.Show("图片不存在"); }
if (Convert.ToDecimal(row1[3]) < 60)
{
DataGridViewCellStyle cellStyle = new DataGridViewCellStyle();
cellStyle.ForeColor = Color.Red;
col_btn_state.Text = "补考"; }
if (Convert.ToDecimal(row1[3]) >= 60)
{
col_btn_state.Text = "通过";
}
}
} }
con.Close();
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{ //违反主键约束
string id=dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
//if (dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString() == "补考")
if (dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString() == "通过")
{
con = new SqlConnection("Data Source=.;Initial Catalog=StuManage;Integrated Security=True");
con.Open();
cmd = new SqlCommand("update tb_score set score='" + 60 + "' where sno='" + id + "'", con);
//object o = cmd.ExecuteScalar();
int o = cmd.ExecuteNonQuery();
if (o > 0)
{
//if(cmd.ExecuteNonQuery()==1)
MessageBox.Show("成功!");
}
con.Close();
//init_grid();
string str = "select * from tb_score";
GetDB(str);
}
} public string get_starPath(int score)
{
int s = (score / 10);
switch (s)
{
//星型不能正常显示
case 6: return " * ";
case 7: return "* *";
case 8: return "* * *";
case 9: return "* * * *";
case 10: return "* * * * *";
default: return "";
}
}
}}