ScoreInput.cs
上传用户:hjieqiu
上传日期:2013-05-11
资源大小:16494k
文件大小:14k
源码类别:

企业管理

开发平台:

C#

  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. using System.Data;
  7. using System.Data.SqlClient;
  8. namespace 教务管理系统
  9. {
  10. /// <summary>
  11. /// ScoreInput 的摘要说明。
  12. /// </summary>
  13. public class ScoreInput : System.Windows.Forms.Form
  14. {
  15. private string courseID;//当前所列成绩课程的课程编号
  16. private DataTable scoreTable=new DataTable();//保存某一门课的成绩单
  17. private SqlDataAdapter da;//用来填充成绩表的数据适配器
  18. private System.Windows.Forms.GroupBox groupBox1;
  19. private System.Windows.Forms.Label label1;
  20. private System.Windows.Forms.GroupBox groupBox2;
  21. private System.Windows.Forms.GroupBox groupBox3;
  22. private System.Windows.Forms.DataGrid dataGrid1;
  23. private System.Windows.Forms.Button btnEndElect;
  24. private System.Windows.Forms.Button btnQuery;
  25. private System.Windows.Forms.Button btnSubmit;
  26. private System.Windows.Forms.TextBox txt1;
  27. private System.Windows.Forms.Label label2;
  28. private System.Windows.Forms.Label label3;
  29. private System.Windows.Forms.TextBox txt2;
  30. private System.Windows.Forms.Label label4;
  31. private System.Windows.Forms.TextBox txt3;
  32. private System.Windows.Forms.Button btnModify;
  33. private System.Windows.Forms.TextBox txt4;
  34. /// <summary>
  35. /// 必需的设计器变量。
  36. /// </summary>
  37. private System.ComponentModel.Container components = null;
  38. public ScoreInput()
  39. {
  40. //
  41. // Windows 窗体设计器支持所必需的
  42. //
  43. InitializeComponent();
  44. //
  45. // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
  46. //
  47. }
  48. /// <summary>
  49. /// 清理所有正在使用的资源。
  50. /// </summary>
  51. protected override void Dispose( bool disposing )
  52. {
  53. if( disposing )
  54. {
  55. if(components != null)
  56. {
  57. components.Dispose();
  58. }
  59. }
  60. base.Dispose( disposing );
  61. }
  62. #region Windows 窗体设计器生成的代码
  63. /// <summary>
  64. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  65. /// 此方法的内容。
  66. /// </summary>
  67. private void InitializeComponent()
  68. {
  69. System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(ScoreInput));
  70. this.groupBox1 = new System.Windows.Forms.GroupBox();
  71. this.label1 = new System.Windows.Forms.Label();
  72. this.groupBox2 = new System.Windows.Forms.GroupBox();
  73. this.groupBox3 = new System.Windows.Forms.GroupBox();
  74. this.dataGrid1 = new System.Windows.Forms.DataGrid();
  75. this.btnEndElect = new System.Windows.Forms.Button();
  76. this.btnQuery = new System.Windows.Forms.Button();
  77. this.btnSubmit = new System.Windows.Forms.Button();
  78. this.txt1 = new System.Windows.Forms.TextBox();
  79. this.label2 = new System.Windows.Forms.Label();
  80. this.label3 = new System.Windows.Forms.Label();
  81. this.txt2 = new System.Windows.Forms.TextBox();
  82. this.label4 = new System.Windows.Forms.Label();
  83. this.txt3 = new System.Windows.Forms.TextBox();
  84. this.btnModify = new System.Windows.Forms.Button();
  85. this.txt4 = new System.Windows.Forms.TextBox();
  86. this.groupBox1.SuspendLayout();
  87. this.groupBox2.SuspendLayout();
  88. this.groupBox3.SuspendLayout();
  89. ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
  90. this.SuspendLayout();
  91. // 
  92. // groupBox1
  93. // 
  94. this.groupBox1.Controls.Add(this.label2);
  95. this.groupBox1.Controls.Add(this.txt1);
  96. this.groupBox1.Controls.Add(this.btnSubmit);
  97. this.groupBox1.Controls.Add(this.btnQuery);
  98. this.groupBox1.Controls.Add(this.label1);
  99. this.groupBox1.Controls.Add(this.label3);
  100. this.groupBox1.Controls.Add(this.txt2);
  101. this.groupBox1.Controls.Add(this.label4);
  102. this.groupBox1.Controls.Add(this.txt3);
  103. this.groupBox1.Location = new System.Drawing.Point(0, 64);
  104. this.groupBox1.Name = "groupBox1";
  105. this.groupBox1.Size = new System.Drawing.Size(632, 144);
  106. this.groupBox1.TabIndex = 0;
  107. this.groupBox1.TabStop = false;
  108. this.groupBox1.Text = "选择课程";
  109. // 
  110. // label1
  111. // 
  112. this.label1.Location = new System.Drawing.Point(280, 24);
  113. this.label1.Name = "label1";
  114. this.label1.Size = new System.Drawing.Size(312, 88);
  115. this.label1.TabIndex = 0;
  116. this.label1.Text = "选择一门课,列出选该课的所有学生名单,教师对各个学生的成绩输入,并保存,最终提交之前还可以修改。最终提交是指老师提交该门课所有学生的最终成绩,提交后的成绩不可修改" +
  117. ",课程拼音和名称是模糊查询,课程编号必须输入准确,实际中由教师登录时的名称查询得到,不必手工输入";
  118. // 
  119. // groupBox2
  120. // 
  121. this.groupBox2.Controls.Add(this.btnEndElect);
  122. this.groupBox2.Location = new System.Drawing.Point(0, 0);
  123. this.groupBox2.Name = "groupBox2";
  124. this.groupBox2.Size = new System.Drawing.Size(632, 64);
  125. this.groupBox2.TabIndex = 1;
  126. this.groupBox2.TabStop = false;
  127. this.groupBox2.Text = "结束选课,生成空成绩单";
  128. // 
  129. // groupBox3
  130. // 
  131. this.groupBox3.Controls.Add(this.txt4);
  132. this.groupBox3.Controls.Add(this.dataGrid1);
  133. this.groupBox3.Controls.Add(this.btnModify);
  134. this.groupBox3.Location = new System.Drawing.Point(0, 216);
  135. this.groupBox3.Name = "groupBox3";
  136. this.groupBox3.Size = new System.Drawing.Size(632, 296);
  137. this.groupBox3.TabIndex = 2;
  138. this.groupBox3.TabStop = false;
  139. this.groupBox3.Text = "课程成绩输入";
  140. // 
  141. // dataGrid1
  142. // 
  143. this.dataGrid1.CaptionVisible = false;
  144. this.dataGrid1.DataMember = "";
  145. this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
  146. this.dataGrid1.Location = new System.Drawing.Point(8, 16);
  147. this.dataGrid1.Name = "dataGrid1";
  148. this.dataGrid1.ReadOnly = true;
  149. this.dataGrid1.Size = new System.Drawing.Size(512, 272);
  150. this.dataGrid1.TabIndex = 0;
  151. // 
  152. // btnEndElect
  153. // 
  154. this.btnEndElect.Image = ((System.Drawing.Image)(resources.GetObject("btnEndElect.Image")));
  155. this.btnEndElect.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
  156. this.btnEndElect.Location = new System.Drawing.Point(216, 16);
  157. this.btnEndElect.Name = "btnEndElect";
  158. this.btnEndElect.Size = new System.Drawing.Size(120, 40);
  159. this.btnEndElect.TabIndex = 0;
  160. this.btnEndElect.Text = "结束选课";
  161. this.btnEndElect.Click += new System.EventHandler(this.btnEndElect_Click);
  162. // 
  163. // btnQuery
  164. // 
  165. this.btnQuery.Image = ((System.Drawing.Image)(resources.GetObject("btnQuery.Image")));
  166. this.btnQuery.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
  167. this.btnQuery.Location = new System.Drawing.Point(24, 112);
  168. this.btnQuery.Name = "btnQuery";
  169. this.btnQuery.Size = new System.Drawing.Size(104, 23);
  170. this.btnQuery.TabIndex = 1;
  171. this.btnQuery.Text = "查询";
  172. this.btnQuery.Click += new System.EventHandler(this.btnQuery_Click);
  173. // 
  174. // btnSubmit
  175. // 
  176. this.btnSubmit.Image = ((System.Drawing.Image)(resources.GetObject("btnSubmit.Image")));
  177. this.btnSubmit.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
  178. this.btnSubmit.Location = new System.Drawing.Point(152, 112);
  179. this.btnSubmit.Name = "btnSubmit";
  180. this.btnSubmit.Size = new System.Drawing.Size(96, 23);
  181. this.btnSubmit.TabIndex = 2;
  182. this.btnSubmit.Text = "最终提交";
  183. this.btnSubmit.Click += new System.EventHandler(this.btnSubmit_Click);
  184. // 
  185. // txt1
  186. // 
  187. this.txt1.Location = new System.Drawing.Point(112, 22);
  188. this.txt1.Name = "txt1";
  189. this.txt1.TabIndex = 3;
  190. this.txt1.Text = "";
  191. // 
  192. // label2
  193. // 
  194. this.label2.Location = new System.Drawing.Point(56, 26);
  195. this.label2.Name = "label2";
  196. this.label2.Size = new System.Drawing.Size(56, 16);
  197. this.label2.TabIndex = 4;
  198. this.label2.Text = "课程拼音";
  199. // 
  200. // label3
  201. // 
  202. this.label3.Location = new System.Drawing.Point(56, 52);
  203. this.label3.Name = "label3";
  204. this.label3.Size = new System.Drawing.Size(56, 16);
  205. this.label3.TabIndex = 4;
  206. this.label3.Text = "课程编号";
  207. // 
  208. // txt2
  209. // 
  210. this.txt2.Location = new System.Drawing.Point(112, 48);
  211. this.txt2.Name = "txt2";
  212. this.txt2.TabIndex = 3;
  213. this.txt2.Text = "";
  214. // 
  215. // label4
  216. // 
  217. this.label4.Location = new System.Drawing.Point(56, 78);
  218. this.label4.Name = "label4";
  219. this.label4.Size = new System.Drawing.Size(56, 16);
  220. this.label4.TabIndex = 4;
  221. this.label4.Text = "课程名称";
  222. // 
  223. // txt3
  224. // 
  225. this.txt3.Location = new System.Drawing.Point(112, 74);
  226. this.txt3.Name = "txt3";
  227. this.txt3.TabIndex = 3;
  228. this.txt3.Text = "";
  229. // 
  230. // btnModify
  231. // 
  232. this.btnModify.Image = ((System.Drawing.Image)(resources.GetObject("btnModify.Image")));
  233. this.btnModify.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
  234. this.btnModify.Location = new System.Drawing.Point(528, 104);
  235. this.btnModify.Name = "btnModify";
  236. this.btnModify.Size = new System.Drawing.Size(96, 23);
  237. this.btnModify.TabIndex = 2;
  238. this.btnModify.Text = "修改成绩";
  239. this.btnModify.Click += new System.EventHandler(this.btnModify_Click);
  240. // 
  241. // txt4
  242. // 
  243. this.txt4.Location = new System.Drawing.Point(528, 64);
  244. this.txt4.Name = "txt4";
  245. this.txt4.TabIndex = 3;
  246. this.txt4.Text = "";
  247. this.txt4.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txt4_KeyPress);
  248. // 
  249. // ScoreInput
  250. // 
  251. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  252. this.ClientSize = new System.Drawing.Size(632, 517);
  253. this.Controls.Add(this.groupBox3);
  254. this.Controls.Add(this.groupBox2);
  255. this.Controls.Add(this.groupBox1);
  256. this.Name = "ScoreInput";
  257. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
  258. this.Text = "【成绩输入】";
  259. this.Load += new System.EventHandler(this.ScoreInput_Load);
  260. this.groupBox1.ResumeLayout(false);
  261. this.groupBox2.ResumeLayout(false);
  262. this.groupBox3.ResumeLayout(false);
  263. ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
  264. this.ResumeLayout(false);
  265. }
  266. #endregion
  267. //-------------绑定dataGrid显示成绩表数据----------
  268. private void ScoreInput_Load(object sender, System.EventArgs e)
  269. {
  270. //绑定数据表显示
  271. dataGrid1.DataSource=this.scoreTable;
  272. }
  273. //---------调用储存过程,结束选课并生成新的空成绩单---------
  274. private void btnEndElect_Click(object sender, System.EventArgs e)
  275. {
  276. string conStr="workstation id=localhost;Integrated Security=SSPI;Database=eisbook";
  277. SqlConnection cn=new SqlConnection(conStr);
  278. cn.Open();
  279. SqlCommand cmd=cn.CreateCommand();
  280. cmd.CommandText="exec sf_终止选课";
  281. try
  282. {
  283. cmd.ExecuteNonQuery();
  284. MessageBox.Show("终止选课成功,将生成新的空成绩单","操作成功",MessageBoxButtons.OK,MessageBoxIcon.Information);
  285. }
  286. catch(Exception express)
  287. {
  288. MessageBox.Show(express.ToString(),"操作失败",MessageBoxButtons.OK,MessageBoxIcon.Information);
  289. }
  290. }
  291. //------------根据输入查询某门课程,并将选该课的学生成绩列于表中---------
  292. private void btnQuery_Click(object sender, System.EventArgs e)
  293. {
  294.             string sql="select a.编号,a.课程编号,b.课程名称,a.学号,c.姓名,a.成绩 from 成绩表 a,课程信息 b,学生信息 c "
  295. +"where(a.课程编号=b.课程编号)and(a.学号=c.学号)and(a.是否已确定成绩='N')"
  296. +"and(a.课程编号 like '%"+txt2.Text.Trim()+"%')and(b.拼音码 like '%"+txt1.Text.Trim()
  297. +"%')and(b.课程名称 like '%"+txt3.Text.Trim()+"%')";
  298. string conStr="workstation id=localhost;Integrated Security=SSPI;Database=eisbook";
  299. SqlConnection cn=new SqlConnection(conStr);
  300. cn.Open();
  301. da=new SqlDataAdapter(sql,cn);
  302. this.scoreTable.Clear();//清空表格,重新填充数据
  303. da.Fill(this.scoreTable);
  304. if(scoreTable.Rows.Count>0)//表格不为空时,开始允许设置学生成绩
  305. {
  306. //保存该课程的课程编号,用来为最终提交成绩的储存过程提供参数
  307. this.courseID=this.scoreTable.Rows[0][1].ToString().Trim();
  308. }
  309. else
  310. {
  311. string msg="该表中没有数据,可能原因有:n"+"1.本学期没有该门课程n"+"2.该课程无学生选课n"
  312. +"3.该课程所有学生成绩已经被最终提交,不可再修改";
  313. MessageBox.Show(msg,"操作失败",MessageBoxButtons.OK,MessageBoxIcon.Information);
  314. return;
  315. }
  316. txt4.DataBindings.Clear();
  317. //绑定成绩显示
  318. txt4.DataBindings.Add("Text",this.scoreTable,"成绩");
  319. }
  320. //--------------修改表中学生的成绩--------------
  321. private void btnModify_Click(object sender, System.EventArgs e)
  322. {
  323. if(this.scoreTable.Rows.Count==0)//检查成绩单中是否有学生名单
  324. {
  325. MessageBox.Show("该门课程成绩单为空","提示",MessageBoxButtons.OK,MessageBoxIcon.Stop);
  326. return;
  327. }
  328. if(txt4.Text.Trim()=="")//检查成绩字段
  329. {
  330. MessageBox.Show("必须输入学生成绩","提示",MessageBoxButtons.OK,MessageBoxIcon.Stop);
  331. return;
  332. }
  333. //更新学生成绩
  334. string conStr="workstation id=localhost;Integrated Security=SSPI;Database=eisbook";
  335. SqlConnection cn=new SqlConnection(conStr);
  336. cn.Open();
  337. SqlCommand cmd=cn.CreateCommand();
  338. string studentNum=dataGrid1[dataGrid1.CurrentCell.RowNumber,0].ToString().Trim();
  339. cmd.CommandText="update 成绩表 set 成绩='"+txt4.Text.Trim()+"' where 编号='"+studentNum+"'";
  340. cmd.ExecuteNonQuery();
  341. //更新表中的显示
  342. this.scoreTable.Clear();
  343. da.Fill(this.scoreTable);
  344.             
  345. }
  346. //------------在【成绩】文本框中只允许输入数字和小数点------------
  347. private void txt4_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
  348. {
  349. if(!((e.KeyChar<='9'&&e.KeyChar>='0')||e.KeyChar=='.'||e.KeyChar==8))//如果按下键不是数字或者小数点或者删除键,则不响应
  350. e.Handled=true;
  351. }
  352. //------------最终提交成绩------------
  353. private void btnSubmit_Click(object sender, System.EventArgs e)
  354. {
  355. string conStr="workstation id=localhost;Integrated Security=SSPI;Database=eisbook";
  356. SqlConnection cn=new SqlConnection(conStr);
  357. cn.Open();
  358. SqlCommand cmd=cn.CreateCommand();
  359. cmd.CommandText="exec sf_成绩提交 "+this.courseID;
  360. DialogResult result;
  361. result=MessageBox.Show("最终提交后学生成绩即不可修改,是否确定提交","提交成绩",MessageBoxButtons.OKCancel,MessageBoxIcon.Information);
  362. if(result==DialogResult.OK)
  363. {
  364. try
  365. {
  366. cmd.ExecuteNonQuery();
  367. MessageBox.Show("成绩最终提交成功","操作成功",MessageBoxButtons.OK,MessageBoxIcon.Information);
  368. }
  369. catch(Exception express)
  370. {
  371. MessageBox.Show(express.ToString(),"操作失败",MessageBoxButtons.OK,MessageBoxIcon.Information);
  372. }
  373. //更新表中的显示
  374. this.scoreTable.Clear();
  375. da.Fill(this.scoreTable);
  376. }
  377. }
  378. }
  379. }