📄 frmmain.cs
字号:
columnHeader.Text = "班级";
lstClass.Columns.Add(columnHeader);
columnHeader = new ColumnHeader();
columnHeader.Text = "ClassId";
lstClass.Columns.Add(columnHeader);
lstClass.Columns[0].Width = lstClass.Width;
lstClass.Columns[1].Width = 0;
string[] sItems = new string[2];
for(int i = 0; i < dataSet.Tables[0].Rows.Count; i ++)
{
DataRow row = dataSet.Tables[0].Rows[i];
sItems[0] = row["ClassName"].ToString();
sItems[1] = row["ClassId"].ToString();
ListViewItem item = new ListViewItem(sItems, 0);
lstClass.Items.Add(item);
}
classs.Dispose();
this.statusBar1.Panels[1].Text = "ok";
}
private void GetScore()
{
Scores scores = new Scores();
DataSet dataSet = new DataSet();
int iClassId = -1;
int iCourseId = -1;
int iStudentId = -1;
try
{
iClassId = Convert.ToInt32(lstClass.SelectedItems[0].SubItems[1].Text);
}
catch{}
try
{
iCourseId = Convert.ToInt32(lstCourse.SelectedItems[0].SubItems[1].Text);
}
catch{}
try
{
iStudentId = Convert.ToInt32(lstStudent.SelectedItems[0].SubItems[1].Text);
}
catch{}
try
{
dataSet = scores.SelectScore(
iStudentId, //如果iStudentId = -1,则表示不对iStudentId进行限定,别的参数与此类似
iCourseId,
iClassId);
}
catch(Exception e)
{
MessageBox.Show(e.Message);
}
dataGrid1.DataSource = dataSet.Tables[0];
scores.Dispose();
}
private void CreateScoreTemp()
{
DataGridTableStyle tableStyle = new DataGridTableStyle();
DataGridTextBoxColumn columnStyle = new DataGridTextBoxColumn();
columnStyle.MappingName = "StudentId";
columnStyle.HeaderText = "StudentId";
columnStyle.Width = 0;
columnStyle.ReadOnly = true;
tableStyle.GridColumnStyles.Add(columnStyle);
columnStyle = new DataGridTextBoxColumn();
columnStyle.MappingName = "CourseId";
columnStyle.HeaderText = "CourseId";
columnStyle.Width = 0;
columnStyle.ReadOnly = true;
tableStyle.GridColumnStyles.Add(columnStyle);
columnStyle = new DataGridTextBoxColumn();
columnStyle.MappingName = "ScoreId";
columnStyle.HeaderText = "ScoreId";
columnStyle.Width = 0;
columnStyle.ReadOnly = true;
tableStyle.GridColumnStyles.Add(columnStyle);
columnStyle = new DataGridTextBoxColumn();
columnStyle.MappingName = "StudentName";
columnStyle.HeaderText = "姓名";
columnStyle.ReadOnly = true;
columnStyle.Width = dataGrid1.Width/4 -10;
tableStyle.GridColumnStyles.Add(columnStyle);
columnStyle = new DataGridTextBoxColumn();
columnStyle.MappingName = "ClassName";
columnStyle.HeaderText = "班";
columnStyle.ReadOnly = true;
columnStyle.Width = dataGrid1.Width/4 -10;
tableStyle.GridColumnStyles.Add(columnStyle);
columnStyle = new DataGridTextBoxColumn();
columnStyle.MappingName = "SubjectName";
columnStyle.HeaderText = "科目";
columnStyle.ReadOnly = true;
columnStyle.Width = dataGrid1.Width/4 -10;
tableStyle.GridColumnStyles.Add(columnStyle);
columnStyle = new DataGridTextBoxColumn();
columnStyle.MappingName = "Score";
columnStyle.HeaderText = "成绩";
columnStyle.Width = dataGrid1.Width/4 -10;
tableStyle.GridColumnStyles.Add(columnStyle);
tableStyle.RowHeadersVisible = false;
tableStyle.MappingName = "Score";
dataGrid1.TableStyles.Add(tableStyle);
}
private void GetCourse()
{
int iClassId = -1;
try
{
iClassId = Convert.ToInt32(lstClass.SelectedItems[0].SubItems[1].Text);
}
catch{}
lstCourse.Items.Clear();
DataSet dataSet = new DataSet();
Courses courses = new Courses();
try
{
dataSet = courses.SelectCourse(
-1,
iClassId,
-1);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
Application.Exit();
}
for(int i = 0; i < dataSet.Tables[0].Rows.Count; i ++)
{
DataRow row = dataSet.Tables[0].Rows[i];
string[] sItems = new string[2];
sItems[0] = row["SubjectName"].ToString();
sItems[1] = row["CourseId"].ToString();
ListViewItem item = new ListViewItem(sItems, 2);
lstCourse.Items.Add(item);
}
courses.Dispose();
}
private void CreateCourseTemp()
{
ColumnHeader columnHeader = new ColumnHeader();
columnHeader.Text = "课程名称";
lstCourse.Columns.Add(columnHeader);
columnHeader = new ColumnHeader();
columnHeader.Text = "CourseId";
lstCourse.Columns.Add(columnHeader);
}
private void CreateStudentTemp()
{
ColumnHeader columnHeader = new ColumnHeader();
columnHeader.Text = "姓名";
lstStudent.Columns.Add(columnHeader);
columnHeader = new ColumnHeader();
columnHeader.Text = "StudentId";
lstStudent.Columns.Add(columnHeader);
columnHeader = new ColumnHeader();
columnHeader.Text = "学号";
lstStudent.Columns.Add(columnHeader);
columnHeader = new ColumnHeader();
columnHeader.Text = "性别";
lstStudent.Columns.Add(columnHeader);
columnHeader = new ColumnHeader();
columnHeader.Text = "出生年月";
lstStudent.Columns.Add(columnHeader);
columnHeader = new ColumnHeader();
columnHeader.Text = "班级";
lstStudent.Columns.Add(columnHeader);
columnHeader = new ColumnHeader();
columnHeader.Text = "备注";
lstStudent.Columns.Add(columnHeader);
for(int i = 0; i < lstStudent.Columns.Count; i ++)
{
lstStudent.Columns[i].Width = lstStudent.Width / lstStudent.Columns.Count;
}
lstStudent.Columns[1].Width = 0;
}
private void GetStudent()
{
int iClassId = -1;
try
{
iClassId = Convert.ToInt32(lstClass.SelectedItems[0].SubItems[1].Text);
}
catch{}
lstStudent.Items.Clear();
Students students = new Students();
DataSet dataSet = new DataSet();
try
{
dataSet = students.SelectStudent(
-1,
"",
"",
iClassId);
}
catch(Exception e)
{
MessageBox.Show(e.Message);
Application.Exit();
}
for(int i = 0; i < dataSet.Tables[0].Rows.Count; i ++)
{
DataRow row = dataSet.Tables[0].Rows[i];
string[] sItems = new string[7];
sItems[0] = row["StudentName"].ToString();
sItems[1] = row["StudentId"].ToString();
sItems[2] = row["StudentNo"].ToString();
sItems[3] = row["Gender"].ToString() == "0"?"男":"女";
sItems[4] = row["Birthday"].ToString();
sItems[5] = row["ClassName"].ToString();
sItems[6] = row["Remark"].ToString();
ListViewItem item = new ListViewItem(sItems, 1);
lstStudent.Items.Add(item);
}
students.Dispose();
}
private void lstStudent_SelectedIndexChanged(object sender, System.EventArgs e)
{
GetScore();
}
private void lstCourse_SelectedIndexChanged(object sender, System.EventArgs e)
{
GetScore();
}
private void lstStudent_DoubleClick(object sender, System.EventArgs e)
{
int iStudentId = Convert.ToInt32(lstStudent.SelectedItems[0].SubItems[1].Text);
frmUpdateStudent updateStudent = new frmUpdateStudent(iStudentId);
updateStudent.ShowDialog();
GetStudent();
GetScore();
}
private void menuItem6_Click(object sender, System.EventArgs e)
{
frmNewStudent newStudent = new frmNewStudent();
newStudent.ShowDialog();
GetStudent();
}
private void lstClass_Click(object sender, System.EventArgs e)
{
GetStudent();
GetScore();
GetCourse();
}
private void menuItem5_Click(object sender, System.EventArgs e)
{
frmNewClass newClass = new frmNewClass();
newClass.ShowDialog();
GetClass();
}
private void lstClass_DoubleClick(object sender, System.EventArgs e)
{
frmUpdateClass updateClass = new frmUpdateClass(Convert.ToInt32(lstClass.SelectedItems[0].SubItems[1].Text));
updateClass.ShowDialog();
GetClass();
}
private void menuItem7_Click(object sender, System.EventArgs e)
{
frmSubject subject = new frmSubject();
subject.ShowDialog();
}
private void lstCourse_DoubleClick(object sender, System.EventArgs e)
{
int iCourseId = Convert.ToInt32(lstCourse.SelectedItems[0].SubItems[1].Text);
frmUpdateCourse updateCourse = new frmUpdateCourse(iCourseId);
updateCourse.ShowDialog();
GetCourse();
}
private void menuItem2_Click(object sender, System.EventArgs e)
{
Application.Exit();
}
private void menuItem8_Click(object sender, System.EventArgs e)
{
frmNewCourse frmNewCourse = new frmNewCourse();
frmNewCourse.ShowDialog();
GetCourse();
}
private void dataGrid1_Navigate(object sender, System.Windows.Forms.NavigateEventArgs ne)
{
}
private void dataGrid1_MouseLeave(object sender, System.EventArgs e)
{
}
private void dataGrid1_CurrentCellChanged(object sender, System.EventArgs e)
{
DataGridCell newCell = dataGrid1.CurrentCell;
if(m_iCurrentRow != -1 && dataGrid1.CurrentRowIndex != m_iCurrentRow)
{
ChangeScore(m_iCurrentRow);
}
m_iCurrentRow = dataGrid1.CurrentRowIndex;
try
{
m_fCurrentScore = Convert.ToSingle(dataGrid1[m_iCurrentRow, 6]);
}
catch{}
dataGrid1.CurrentCell = newCell;
}
private void ChangeScore(int m_iCurrentRow)
{
try
{
if(dataGrid1[m_iCurrentRow,6].ToString() == m_fCurrentScore.ToString() || dataGrid1[m_iCurrentRow,6].ToString() == "")
{
return;
}
if(dataGrid1[m_iCurrentRow, 2].ToString() == "")
{
this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
this.statusBar1.Text = "正在插入数据...";
Scores scores = new Scores();
scores.InsertScore(
Convert.ToInt32(dataGrid1[m_iCurrentRow,1]),
Convert.ToInt32(dataGrid1[m_iCurrentRow,0]),
Convert.ToSingle(dataGrid1[m_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[m_iCurrentRow, 2]),
Convert.ToSingle(dataGrid1[m_iCurrentRow,6]));
GetScore();
this.Cursor = System.Windows.Forms.Cursors.Default;
this.statusBar1.Text = "";
}
}
catch{}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -