📄 frmmain.cs
字号:
try
{
dataset = scores.SelectScore(
iStudentId, //如果iStudentId = -1,则表示不对iStudentId进行限定,别的参数与此类似
iCourseId,
iClassId);
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
}
dataGrid1.DataSource = dataset.Tables[0].DefaultView;
}
//获取课程信息
private void GetCourse()
{
int iClassId = -1;
try
{
iClassId = Convert.ToInt32(lstClass.SelectedItems[0].SubItems[1].Text.ToString());
}
catch
{
}
lstCourse.Items.Clear();
Courses course = new Courses();
DataSet dataset = new DataSet();
try
{
dataset = course.SelectCourse(-1, iClassId, -1);
}
catch(SqlException ex)
{
MessageBox.Show(ex.Message);
}
for(int i=0;i<dataset.Tables[0].Rows.Count;i++)
{
DataRow row=dataset.Tables[0].Rows[i];
string [] slive=new string[2];
slive[0]=row["SubjectName"].ToString();
slive[1]=row["CourseId"].ToString();
ListViewItem lvl=new ListViewItem(slive,2);
lstCourse.Items.Add(lvl);
}
course.Dispose();
}
private void lstClass_SelectedIndexChanged(object sender, EventArgs e)
{
GetStudent();
GetScore();
GetCourse();
}
private void lstClass_DoubleClick(object sender, EventArgs e)
{
frmUpdateClass objUpdateClass = new frmUpdateClass(Convert.ToInt32(lstClass.SelectedItems[0].SubItems[1].Text.ToString()));
objUpdateClass.ShowDialog();
GetClass();
}
private void 新建班级ToolStripMenuItem_Click(object sender, EventArgs e)
{
frmNewClass objnc = new frmNewClass();
objnc.ShowDialog();
GetClass();
}
private void 更新班级ToolStripMenuItem_Click(object sender, EventArgs e)
{
frmSelectClasss objsc = new frmSelectClasss();
objsc.ShowDialog();
int ClassId = objsc.ClassId;
MessageBox.Show(ClassId.ToString());
frmUpdateClass objUC = new frmUpdateClass(ClassId);
objUC.ShowDialog();
GetClass();
GetStudent();
}
private void 添加学生ToolStripMenuItem_Click(object sender, EventArgs e)
{
frmNewStudent objNS = new frmNewStudent();
objNS.ShowDialog();
GetStudent();
}
private void 更新学生ToolStripMenuItem_Click(object sender, EventArgs e)
{
frmUpdateStudent objUS = new frmUpdateStudent();
objUS.ShowDialog();
GetStudent();
}
private void 添加科目ToolStripMenuItem_Click(object sender, EventArgs e)
{
frmNewCourse objNC = new frmNewCourse();
objNC.ShowDialog();
}
private void 更新科目ToolStripMenuItem_Click(object sender, EventArgs e)
{
//frmUpdateCourse objUC = new frmUpdateCourse();
//objUC.ShowDialog();
}
private void 退出ToolStripMenuItem1_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void lstStudent_SelectedIndexChanged(object sender, EventArgs e)
{
GetScore();
}
private void lstStudent_MouseDoubleClick(object sender, MouseEventArgs e)
{
int iStudentId = Convert.ToInt32(lstStudent.SelectedItems[0].SubItems[1].Text);
frmUpdateStudent updateStudent = new frmUpdateStudent(iStudentId);
updateStudent.ShowDialog();
GetStudent();
GetScore();
}
private void dataGrid1_CurrentCellChanged(object sender, EventArgs e)
{
DataGridCell newCell = dataGrid1.CurrentCell;
if (iCurrentRow != -1 && dataGrid1.CurrentRowIndex != iCurrentRow)
{
ChangeScore(iCurrentRow);
}
iCurrentRow = dataGrid1.CurrentRowIndex;
try
{
fCurrentScore = Convert.ToSingle(dataGrid1[iCurrentRow, 6]);
}
catch { }
dataGrid1.CurrentCell = newCell;
}
private void ChangeScore(int iCurrentRow)
{
try
{
if (dataGrid1[iCurrentRow, 6].ToString() == fCurrentScore.ToString() || dataGrid1[iCurrentRow, 6].ToString() == "")
{
return;
}
if (dataGrid1[iCurrentRow, 2].ToString() == "")
{
this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
this.statusBar1.Text = "正在插入数据...";
Scores scores = new Scores();
scores.InsertScore(
Convert.ToInt32(dataGrid1[iCurrentRow, 1]),
Convert.ToInt32(dataGrid1[iCurrentRow, 0]),
Convert.ToSingle(dataGrid1[iCurrentRow, 6]));
scores.Dispose();
GetScore();
this.Cursor = System.Windows.Forms.Cursors.Default;
this.statusBar1.Text = "";
}
else
{
this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
this.statusBar1.Text = "正在更新数据...";
Scores scores = new Scores();
scores.UpdateScore(
Convert.ToInt32(dataGrid1[iCurrentRow, 2]),
Convert.ToSingle(dataGrid1[iCurrentRow, 6]));
GetScore();
this.Cursor = System.Windows.Forms.Cursors.Default;
this.statusBar1.Text = "";
}
}
catch { }
}
private void 关于ToolStripMenuItem_Click(object sender, EventArgs e)
{
Help.ShowHelp(this, "Help.chm");
}
private void 查询学生ToolStripMenuItem_Click(object sender, EventArgs e)
{
frmSearchStudent objfrSS = new frmSearchStudent();
objfrSS.ShowDialog();
}
private void 成绩查询ToolStripMenuItem_Click(object sender, EventArgs e)
{
int iClassId = -1;
int iCourseId = -1;
int iStudentId = -1;
Scores scores = new Scores();
DataSet dataset = new DataSet();
frmSearchScore objSS = new frmSearchScore();
objSS.ShowDialog();
string byway = objSS.ByWay;
string Id = objSS.Information;
if (byway == "ClassId")
{
iClassId = Convert.ToInt32(Id);
}
else if (byway == "StudentId")
{
iStudentId = Convert.ToInt32(Id);
}
else
{
iCourseId = Convert.ToInt32(Id);
}
try
{
dataset = scores.SelectScore(
iStudentId, //如果iStudentId = -1,则表示不对iStudentId进行限定,别的参数与此类似
iCourseId,
iClassId);
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
}
lstCourse.Items.Clear();
lstStudent.Items.Clear();
dataGrid1.DataSource = dataset.Tables[0].DefaultView;
}
private void lstCourse_SelectedIndexChanged(object sender, EventArgs e)
{
GetScore();
}
private void lstCourse_DoubleClick(object sender, EventArgs e)
{
int iCourseId = Convert.ToInt32(lstCourse.SelectedItems[0].SubItems[1].Text);
frmUpdateCourse updateCourse = new frmUpdateCourse(iCourseId);
updateCourse.ShowDialog();
GetCourse();
}
private void 打印信息ToolStripMenuItem1_Click(object sender, EventArgs e)
{
DataGridPrinter objdataPrinter = new DataGridPrinter(this.dataGrid1);
objdataPrinter.Print();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -