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

企业管理

开发平台:

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. /// ViewScore 的摘要说明。
  12. /// </summary>
  13. public class ViewScore : System.Windows.Forms.Form
  14. {
  15. private string stuID;//保存学生学号
  16. private System.Windows.Forms.GroupBox groupBox1;
  17. private System.Windows.Forms.TextBox txt1;
  18. private System.Windows.Forms.Label label1;
  19. private System.Windows.Forms.TextBox txt2;
  20. private System.Windows.Forms.Label label2;
  21. private System.Windows.Forms.TextBox txt3;
  22. private System.Windows.Forms.Label label4;
  23. private System.Windows.Forms.DataGrid dataGrid1;
  24. private System.Data.SqlClient.SqlDataAdapter da1;
  25. private System.Data.SqlClient.SqlConnection sqlConnection1;
  26. protected System.Windows.Forms.Button btnPrint;
  27. private System.Data.SqlClient.SqlCommand sqlSelectCommand1;
  28. private 教务管理系统.DataSet2 dataSet21;
  29. private System.Windows.Forms.DataGridTableStyle dataGridTableStyle1;
  30. private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn1;
  31. private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn2;
  32. private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn3;
  33. private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn4;
  34. /// <summary>
  35. /// 必需的设计器变量。
  36. /// </summary>
  37. private System.ComponentModel.Container components = null;
  38. public ViewScore()
  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(ViewScore));
  70. this.groupBox1 = new System.Windows.Forms.GroupBox();
  71. this.btnPrint = new System.Windows.Forms.Button();
  72. this.txt1 = new System.Windows.Forms.TextBox();
  73. this.label1 = new System.Windows.Forms.Label();
  74. this.txt2 = new System.Windows.Forms.TextBox();
  75. this.label2 = new System.Windows.Forms.Label();
  76. this.txt3 = new System.Windows.Forms.TextBox();
  77. this.label4 = new System.Windows.Forms.Label();
  78. this.dataGrid1 = new System.Windows.Forms.DataGrid();
  79. this.dataSet21 = new 教务管理系统.DataSet2();
  80. this.dataGridTableStyle1 = new System.Windows.Forms.DataGridTableStyle();
  81. this.dataGridTextBoxColumn1 = new System.Windows.Forms.DataGridTextBoxColumn();
  82. this.dataGridTextBoxColumn2 = new System.Windows.Forms.DataGridTextBoxColumn();
  83. this.dataGridTextBoxColumn3 = new System.Windows.Forms.DataGridTextBoxColumn();
  84. this.dataGridTextBoxColumn4 = new System.Windows.Forms.DataGridTextBoxColumn();
  85. this.da1 = new System.Data.SqlClient.SqlDataAdapter();
  86. this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
  87. this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
  88. this.groupBox1.SuspendLayout();
  89. ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
  90. ((System.ComponentModel.ISupportInitialize)(this.dataSet21)).BeginInit();
  91. this.SuspendLayout();
  92. // 
  93. // groupBox1
  94. // 
  95. this.groupBox1.Controls.Add(this.btnPrint);
  96. this.groupBox1.Controls.Add(this.txt1);
  97. this.groupBox1.Controls.Add(this.label1);
  98. this.groupBox1.Controls.Add(this.txt2);
  99. this.groupBox1.Controls.Add(this.label2);
  100. this.groupBox1.Controls.Add(this.txt3);
  101. this.groupBox1.Controls.Add(this.label4);
  102. this.groupBox1.Location = new System.Drawing.Point(0, 8);
  103. this.groupBox1.Name = "groupBox1";
  104. this.groupBox1.Size = new System.Drawing.Size(616, 53);
  105. this.groupBox1.TabIndex = 2;
  106. this.groupBox1.TabStop = false;
  107. this.groupBox1.Text = "输入学生信息";
  108. // 
  109. // btnPrint
  110. // 
  111. this.btnPrint.Image = ((System.Drawing.Image)(resources.GetObject("btnPrint.Image")));
  112. this.btnPrint.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
  113. this.btnPrint.Location = new System.Drawing.Point(512, 22);
  114. this.btnPrint.Name = "btnPrint";
  115. this.btnPrint.Size = new System.Drawing.Size(72, 23);
  116. this.btnPrint.TabIndex = 2;
  117. this.btnPrint.Text = "打印";
  118. this.btnPrint.Click += new System.EventHandler(this.btnPrint_Click);
  119. // 
  120. // txt1
  121. // 
  122. this.txt1.Location = new System.Drawing.Point(64, 24);
  123. this.txt1.Name = "txt1";
  124. this.txt1.TabIndex = 1;
  125. this.txt1.Text = "";
  126. this.txt1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txt1_KeyPress);
  127. // 
  128. // label1
  129. // 
  130. this.label1.Location = new System.Drawing.Point(16, 28);
  131. this.label1.Name = "label1";
  132. this.label1.Size = new System.Drawing.Size(48, 16);
  133. this.label1.TabIndex = 0;
  134. this.label1.Text = "学号";
  135. this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
  136. // 
  137. // txt2
  138. // 
  139. this.txt2.Location = new System.Drawing.Point(224, 24);
  140. this.txt2.Name = "txt2";
  141. this.txt2.ReadOnly = true;
  142. this.txt2.TabIndex = 1;
  143. this.txt2.Text = "";
  144. // 
  145. // label2
  146. // 
  147. this.label2.Location = new System.Drawing.Point(176, 28);
  148. this.label2.Name = "label2";
  149. this.label2.Size = new System.Drawing.Size(48, 16);
  150. this.label2.TabIndex = 0;
  151. this.label2.Text = "姓名";
  152. this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
  153. // 
  154. // txt3
  155. // 
  156. this.txt3.Location = new System.Drawing.Point(384, 24);
  157. this.txt3.Name = "txt3";
  158. this.txt3.ReadOnly = true;
  159. this.txt3.TabIndex = 1;
  160. this.txt3.Text = "";
  161. // 
  162. // label4
  163. // 
  164. this.label4.Location = new System.Drawing.Point(336, 28);
  165. this.label4.Name = "label4";
  166. this.label4.Size = new System.Drawing.Size(48, 16);
  167. this.label4.TabIndex = 0;
  168. this.label4.Text = "班级";
  169. this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
  170. // 
  171. // dataGrid1
  172. // 
  173. this.dataGrid1.CaptionVisible = false;
  174. this.dataGrid1.DataMember = "成绩表";
  175. this.dataGrid1.DataSource = this.dataSet21;
  176. this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
  177. this.dataGrid1.Location = new System.Drawing.Point(0, 64);
  178. this.dataGrid1.Name = "dataGrid1";
  179. this.dataGrid1.ReadOnly = true;
  180. this.dataGrid1.Size = new System.Drawing.Size(616, 352);
  181. this.dataGrid1.TabIndex = 3;
  182. this.dataGrid1.TableStyles.AddRange(new System.Windows.Forms.DataGridTableStyle[] {
  183.   this.dataGridTableStyle1});
  184. // 
  185. // dataSet21
  186. // 
  187. this.dataSet21.DataSetName = "DataSet2";
  188. this.dataSet21.Locale = new System.Globalization.CultureInfo("zh-CN");
  189. // 
  190. // dataGridTableStyle1
  191. // 
  192. this.dataGridTableStyle1.DataGrid = this.dataGrid1;
  193. this.dataGridTableStyle1.GridColumnStyles.AddRange(new System.Windows.Forms.DataGridColumnStyle[] {
  194.   this.dataGridTextBoxColumn1,
  195.   this.dataGridTextBoxColumn2,
  196.   this.dataGridTextBoxColumn3,
  197.   this.dataGridTextBoxColumn4});
  198. this.dataGridTableStyle1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
  199. this.dataGridTableStyle1.MappingName = "成绩表";
  200. // 
  201. // dataGridTextBoxColumn1
  202. // 
  203. this.dataGridTextBoxColumn1.Format = "";
  204. this.dataGridTextBoxColumn1.FormatInfo = null;
  205. this.dataGridTextBoxColumn1.HeaderText = "课程名称";
  206. this.dataGridTextBoxColumn1.MappingName = "课程名称";
  207. this.dataGridTextBoxColumn1.Width = 200;
  208. // 
  209. // dataGridTextBoxColumn2
  210. // 
  211. this.dataGridTextBoxColumn2.Format = "";
  212. this.dataGridTextBoxColumn2.FormatInfo = null;
  213. this.dataGridTextBoxColumn2.HeaderText = "开课系别";
  214. this.dataGridTextBoxColumn2.MappingName = "开课系别";
  215. this.dataGridTextBoxColumn2.Width = 75;
  216. // 
  217. // dataGridTextBoxColumn3
  218. // 
  219. this.dataGridTextBoxColumn3.Format = "";
  220. this.dataGridTextBoxColumn3.FormatInfo = null;
  221. this.dataGridTextBoxColumn3.HeaderText = "成绩";
  222. this.dataGridTextBoxColumn3.MappingName = "成绩";
  223. this.dataGridTextBoxColumn3.Width = 75;
  224. // 
  225. // dataGridTextBoxColumn4
  226. // 
  227. this.dataGridTextBoxColumn4.Format = "";
  228. this.dataGridTextBoxColumn4.FormatInfo = null;
  229. this.dataGridTextBoxColumn4.HeaderText = "教师";
  230. this.dataGridTextBoxColumn4.MappingName = "教师";
  231. this.dataGridTextBoxColumn4.Width = 75;
  232. // 
  233. // da1
  234. // 
  235. this.da1.SelectCommand = this.sqlSelectCommand1;
  236. this.da1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
  237.   new System.Data.Common.DataTableMapping("Table", "成绩表", new System.Data.Common.DataColumnMapping[] {
  238.  new System.Data.Common.DataColumnMapping("学号", "学号"),
  239.  new System.Data.Common.DataColumnMapping("姓名", "姓名"),
  240.  new System.Data.Common.DataColumnMapping("课程名称", "课程名称"),
  241.  new System.Data.Common.DataColumnMapping("开课系别", "开课系别"),
  242.  new System.Data.Common.DataColumnMapping("教师", "教师"),
  243.  new System.Data.Common.DataColumnMapping("成绩", "成绩")})});
  244. // 
  245. // sqlSelectCommand1
  246. // 
  247. this.sqlSelectCommand1.CommandText = "SELECT a.学号, c.姓名, b.课程名称, b.开课系别, b.教师, a.成绩 FROM 成绩表 a INNER JOIN 课程信息 b ON a.课" +
  248. "程编号 = b.课程编号 INNER JOIN 学生信息 c ON a.学号 = c.学号 WHERE (a.学号 = @Param2)";
  249. this.sqlSelectCommand1.Connection = this.sqlConnection1;
  250. this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Param2", System.Data.SqlDbType.VarChar, 14, "学号"));
  251. // 
  252. // sqlConnection1
  253. // 
  254. this.sqlConnection1.ConnectionString = "workstation id=localhost;packet size=4096;integrated security=SSPI;initial catalo" +
  255. "g=eisbook;persist security info=False";
  256. // 
  257. // ViewScore
  258. // 
  259. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  260. this.ClientSize = new System.Drawing.Size(616, 421);
  261. this.Controls.Add(this.dataGrid1);
  262. this.Controls.Add(this.groupBox1);
  263. this.Name = "ViewScore";
  264. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
  265. this.Text = "【成绩单打印】";
  266. this.groupBox1.ResumeLayout(false);
  267. ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
  268. ((System.ComponentModel.ISupportInitialize)(this.dataSet21)).EndInit();
  269. this.ResumeLayout(false);
  270. }
  271. #endregion
  272. //--------输入学号后回车,显示学生信息和其选课成绩信息---------------
  273. private void txt1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
  274. {
  275. if(e.KeyChar==13)
  276. {
  277. txt2.Clear();//先清空信息 txt3.Clear(); dataSet21.Clear(); string strConn="workstation id=localhost;Integrated Security=SSPI;database=eisbook;"; SqlConnection cn=new SqlConnection(strConn); cn.Open();
  278. SqlCommand cmd=cn.CreateCommand();
  279. cmd.CommandText="select a.姓名,b.班级名称,a.学籍编号 from 学生信息 a,班级信息 b "
  280. +"where(a.班级编号=b.班级编号)and(学号='"+txt1.Text.Trim()+"')";
  281. SqlDataReader dr=cmd.ExecuteReader();
  282. dr.Read();//读入学生的数据
  283. if(!dr.HasRows)//判断学号是否输入正确
  284. {
  285. MessageBox.Show("无此学生,请重新输入学号","提示",MessageBoxButtons.OK,MessageBoxIcon.Stop);
  286. dr.Close();
  287. return;
  288. }
  289. txt2.Text=dr.GetValue(0).ToString().Trim();//显示姓名
  290. txt3.Text=dr.GetValue(1).ToString().Trim();//显示班级名称
  291. dr.Close();
  292. da1.SelectCommand.Parameters[0].Value=txt1.Text.Trim();
  293. da1.Fill(dataSet21);
  294. }
  295. }
  296. //---------显示报表预览窗口------------
  297. private void btnPrint_Click(object sender, System.EventArgs e)
  298. {
  299. if(txt2.Text.Trim()=="")
  300. {
  301. MessageBox.Show("请先输入正确的学号","提示");
  302. return;
  303. }
  304. CrystalReport newfrm=new CrystalReport();
  305. CrystalReport.studentID=txt1.Text.Trim();//向报表预览窗体中传递学号
  306. newfrm.Text=txt2.Text+" 同学成绩表";
  307. newfrm.ShowDialog();
  308. }
  309. }
  310. }