1.timer控件默认Enabled属性为False
上机界面的"消费时间"雷打不动,我一遍一遍的查代码,发现逻辑没有错误,最后在CSDN论坛里发现了这一让我哭笑不得的原因
2.程序的几种"退出"
我用到了最后一个,,
3.主窗体关闭时事件的触发
在VS代码窗口,我们不能像VB6.0一样,通过下拉框选择控件A,继而级联选择A的所有事件,再写事件触发代码
只能在窗体设计页面,选中控件,点击属性窗口的闪电符号"事件",双击空白处,这样后台才会生成相应的事件代码,供我们使用
学生上机界面窗体关闭时的代码:
#region 窗体关闭时触发该事件-韩林-2016年3月14日14:25:10 private void frm_GU_Main_FormClosing(object sender, FormClosingEventArgs e) { DialogResult result = MessageBox.Show("关闭该窗体将下机,是否继续?", "提示信息", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (result == DialogResult.OK) { e.Cancel = false; //点击OK //存入数据库T_OnLineInfo表下机信息 Entity.onLineEntity onLineInfo = new onLineEntity(); onLineInfo.outDate = DateTime.Now.ToString("yyyy/MM/dd"); onLineInfo.outTime = DateTime.Now.ToString("HH:mm:ss"); onLineInfo.conTime = txtConsumedLength.Text.ToString().Trim(); onLineInfo.conCash = txtConsumedCash.Text.ToString().Trim(); onLineInfo.cardID = UI.Common.CommonClass.CurrentUserId; onLineInfo.IsOnLine = "正常下机"; //存入卡表下机信息,写入余额 Entity.cardEntity cardInfo = new cardEntity(); cardInfo.leftCash = txtBalance.Text.ToString().Trim(); Facade.LoginFa outFa = new Facade.LoginFa(); outFa.loginOut(cardInfo, onLineInfo); System.Environment.Exit(0);//此语句很重要,结束线程少不了 } else { e.Cancel = true; } } #endregion
4.将泛型的值赋给datagridview,并设置列名
lineHis=queryLineFa.queryLine(lineInfo); dataGridView1.DataSource = (from p in lineHis select new { 上机日期=p.loginDate, 上机时间=p.loginTime, 下机日期=p.outDate, 下机时间=p.outTime, 消费时间=p.conTime, 消费金额=p.conCash }).ToList();
5.操作员、管理员的主窗体,也是实时刷新的
private void timer1_Tick(object sender, EventArgs e) { Facade.QueryLineHistory queryFa = new Facade.QueryLineHistory(); List<onLineEntity> lineList = new List<onLineEntity>(); lineList = queryFa.getLine(); dataGridView1.DataSource = (from p in lineList select new { 卡号 = p.cardID, 上机时间 = p.loginDate, 上机日期 = p.loginTime, 机器号 = p.pcNo }).ToList(); string numStu = lineList.Count.ToString(); string leftNum = (200 - int.Parse(numStu)).ToString().Trim(); lblLineNum.Text = "当前共有 " + numStu + " 个学生上机," + "剩余 " + leftNum + " 台机器可用。"; } private void 显示全部ToolStripMenuItem_Click(object sender, EventArgs e) { timer1_Tick(sender, e); } private void 强制个人下机ToolStripMenuItem1_Click(object sender, EventArgs e) { UI.Common.CommonClass.downStu = dataGridView1.CurrentRow.Cells[0].Value.ToString().Trim(); //存入数据库T_OnLineInfo表下机信息 Entity.onLineEntity onLineInfo = new onLineEntity(); onLineInfo.outDate = DateTime.Now.ToString("yyyy/MM/dd"); onLineInfo.outTime = DateTime.Now.ToString("HH:mm:ss"); onLineInfo.cardID = UI.Common.CommonClass.downStu; Facade.LoginFa outFa = new Facade.LoginFa(); bool flag = outFa.loginOutSingle(onLineInfo); if (flag == false) { MessageBox.Show("下机失败!", "提示"); return; } else { MessageBox.Show("强制下机成功!", "提示"); } } private void 强制所有学生下机ToolStripMenuItem_Click(object sender, EventArgs e) { for (int i = dataGridView1.RowCount - 1; i >= 0; i--) { string downCardId = dataGridView1.Rows[i].Cells[0].Value.ToString().Trim(); UI.Common.CommonClass.downStu = downCardId; //存入数据库T_OnLineInfo表下机信息 Entity.onLineEntity onLineInfo = new onLineEntity(); onLineInfo.outDate = DateTime.Now.ToString("yyyy/MM/dd"); onLineInfo.outTime = DateTime.Now.ToString("HH:mm:ss"); onLineInfo.cardID = UI.Common.CommonClass.downStu; Facade.LoginFa outFa = new Facade.LoginFa(); bool flag = outFa.loginOutSingle(onLineInfo); if (flag == false) { MessageBox.Show("下机失败!", "提示"); return; } } }
6.两行代码解决报表问题
详情点击:http://blog.csdn.net/u010928364/article/details/39808995
希望能给有需要的人一点帮助