7.2 设计状态栏
状态栏的运行效果如图:
图:
第八章.其它各模块的设计
其他各模块的设计下面以宿舍检查窗体和添加宿舍的设计作为示范。
8.1 宿舍检查窗体如下:
31
8.2 宿社检查窗体的部分代码实现
private void btQuery_Click(object sender, System.EventArgs e) { oleConnection1.Open(); ds = new DataSet(); string sql=\dormID as 宿舍号,CDate as 检查日期,CState as 检查情况,CRemark as 备注,CheckID as 检查编号 from checkinfo\ if (textDormID.Text.Trim()==\ sql=sql; else sql=sql+\ OleDbDataAdapter adp = new OleDbDataAdapter(sql,oleConnection1); ds.Clear(); adp.Fill(ds,\ dataGrid1.DataSource = ds.Tables[0].DefaultView; dataGrid1.CaptionText = \共有\条记录\ oleConnection1.Close(); } CheckModify checkModify; private void btAdd_Click(object sender, System.EventArgs e) { if
(dataGrid1.DataSource!=null&&dataGrid1.CurrentRowIndex>=0&&dataGrid1[dataGrid1.CurrentCell]!=null) { checkModify = new CheckModify(); checkModify.textDormID.Text=
ds.Tables[0].Rows[dataGrid1.CurrentCell.RowNumber][0].ToString().Trim(); checkModify.date1.Text=
ds.Tables[0].Rows[dataGrid1.CurrentCell.RowNumber][1].ToString().Trim(); checkModify.comboState.Text=
ds.Tables[0].Rows[dataGrid1.CurrentCell.RowNumber][2].ToString().Trim(); checkModify.textRemark.Text=
ds.Tables[0].Rows[dataGrid1.CurrentCell.RowNumber][3].ToString().Trim();
32
checkModify.Tag=
ds.Tables[0].Rows[dataGrid1.CurrentCell.RowNumber][4].ToString().Trim(); checkModify.ShowDialog(); } } private void btDel_Click(object sender, System.EventArgs e) { if
(dataGrid1.DataSource!=null&&dataGrid1.CurrentRowIndex>=0&&dataGrid1[dataGrid1.CurrentCell]!=null) { oleConnection1.Open(); string sql = \* from checkinfo where CheckID=\ OleDbCommand cmd = new OleDbCommand(sql,oleConnection1); cmd.ExecuteNonQuery();
}
}
MessageBox.Show(\删除成功\提示\oleConnection1.Close();
private void btClose_Click(object sender, System.EventArgs e) { this.Close(); }
8.3 添加宿舍的窗体如下:
33
8.4 宿舍添加的部分代码实现
private void btAdd_Click(object sender, System.EventArgs e) { if (textDormID.Text.Trim()==\ MessageBox.Show(\填写完整信息\提示\ else { oleConnection1.Open(); string sql = \* from dorm where dormID='\ OleDbCommand cmd = new OleDbCommand(sql,oleConnection1); if (null == cmd.ExecuteScalar()) { sql = \into dorm values ('\\ \
34
xtRemark.Text.Trim()+\ cmd.CommandText=sql; cmd.ExecuteNonQuery(); MessageBox.Show(\添加成功\提示\ clear(); } else MessageBox.Show(\宿舍号重复\提示\ oleConnection1.Close(); } } private void btClose_Click(object sender, System.EventArgs e) { this.Close(); } private void clear() { textDormID.Text=\ textPhone.Text=\ textMoney.Text=\ textBed.Text=\ textChair.Text=\ textDesk.Text=\ textRemark.Text=\ }
35