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

企业管理

开发平台:

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. /// CourseElect 的摘要说明。
  12. /// </summary>
  13. public class CourseElect : System.Windows.Forms.Form
  14. {
  15. private DataTable electTable=new DataTable();//保存学生的选课信息
  16. private DataTable courseTable=new DataTable();//保存可选课程信息
  17. private DataView dv;//可选课程的视图
  18. private string studentID;//保存选课的学生信息
  19. private string stduentName;//选课的学生的姓名
  20. private System.Windows.Forms.GroupBox groupBox1;
  21. private System.Windows.Forms.DataGrid dataGrid1;
  22. private System.Windows.Forms.GroupBox groupBox2;
  23. private System.Windows.Forms.GroupBox groupBox3;
  24. private System.Windows.Forms.DataGrid dataGrid2;
  25. private System.Windows.Forms.Label label1;
  26. private System.Windows.Forms.TextBox txt1;
  27. private System.Windows.Forms.TextBox txt2;
  28. private System.Windows.Forms.Label label2;
  29. private System.Windows.Forms.TextBox txt3;
  30. private System.Windows.Forms.Label label4;
  31. private System.Windows.Forms.Label label3;
  32. private System.Windows.Forms.Label label5;
  33. private System.Windows.Forms.Label label6;
  34. private System.Windows.Forms.Label label7;
  35. private System.Windows.Forms.TextBox txt4;
  36. private System.Windows.Forms.TextBox txt5;
  37. private System.Windows.Forms.TextBox txt6;
  38. private System.Windows.Forms.TextBox txt7;
  39. private System.Windows.Forms.Button btnSearch;
  40. private System.Windows.Forms.Button btnElect;
  41. private System.Windows.Forms.Button btnDelete;
  42. private System.Windows.Forms.Button btnView;
  43. /// <summary>
  44. /// 必需的设计器变量。
  45. /// </summary>
  46. private System.ComponentModel.Container components = null;
  47. public CourseElect()
  48. {
  49. //
  50. // Windows 窗体设计器支持所必需的
  51. //
  52. InitializeComponent();
  53. //
  54. // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
  55. //
  56. }
  57. /// <summary>
  58. /// 清理所有正在使用的资源。
  59. /// </summary>
  60. protected override void Dispose( bool disposing )
  61. {
  62. if( disposing )
  63. {
  64. if(components != null)
  65. {
  66. components.Dispose();
  67. }
  68. }
  69. base.Dispose( disposing );
  70. }
  71. #region Windows 窗体设计器生成的代码
  72. /// <summary>
  73. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  74. /// 此方法的内容。
  75. /// </summary>
  76. private void InitializeComponent()
  77. {
  78. System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(CourseElect));
  79. this.groupBox1 = new System.Windows.Forms.GroupBox();
  80. this.txt1 = new System.Windows.Forms.TextBox();
  81. this.label1 = new System.Windows.Forms.Label();
  82. this.txt2 = new System.Windows.Forms.TextBox();
  83. this.label2 = new System.Windows.Forms.Label();
  84. this.txt3 = new System.Windows.Forms.TextBox();
  85. this.label4 = new System.Windows.Forms.Label();
  86. this.dataGrid1 = new System.Windows.Forms.DataGrid();
  87. this.groupBox2 = new System.Windows.Forms.GroupBox();
  88. this.dataGrid2 = new System.Windows.Forms.DataGrid();
  89. this.groupBox3 = new System.Windows.Forms.GroupBox();
  90. this.txt4 = new System.Windows.Forms.TextBox();
  91. this.label3 = new System.Windows.Forms.Label();
  92. this.btnSearch = new System.Windows.Forms.Button();
  93. this.btnElect = new System.Windows.Forms.Button();
  94. this.btnDelete = new System.Windows.Forms.Button();
  95. this.btnView = new System.Windows.Forms.Button();
  96. this.label5 = new System.Windows.Forms.Label();
  97. this.txt5 = new System.Windows.Forms.TextBox();
  98. this.label6 = new System.Windows.Forms.Label();
  99. this.txt6 = new System.Windows.Forms.TextBox();
  100. this.txt7 = new System.Windows.Forms.TextBox();
  101. this.label7 = new System.Windows.Forms.Label();
  102. this.groupBox1.SuspendLayout();
  103. ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
  104. this.groupBox2.SuspendLayout();
  105. ((System.ComponentModel.ISupportInitialize)(this.dataGrid2)).BeginInit();
  106. this.groupBox3.SuspendLayout();
  107. this.SuspendLayout();
  108. // 
  109. // groupBox1
  110. // 
  111. this.groupBox1.Controls.Add(this.txt1);
  112. this.groupBox1.Controls.Add(this.label1);
  113. this.groupBox1.Controls.Add(this.txt2);
  114. this.groupBox1.Controls.Add(this.label2);
  115. this.groupBox1.Controls.Add(this.txt3);
  116. this.groupBox1.Controls.Add(this.label4);
  117. this.groupBox1.Location = new System.Drawing.Point(0, 3);
  118. this.groupBox1.Name = "groupBox1";
  119. this.groupBox1.Size = new System.Drawing.Size(696, 53);
  120. this.groupBox1.TabIndex = 0;
  121. this.groupBox1.TabStop = false;
  122. this.groupBox1.Text = "学生信息";
  123. // 
  124. // txt1
  125. // 
  126. this.txt1.Location = new System.Drawing.Point(88, 24);
  127. this.txt1.Name = "txt1";
  128. this.txt1.TabIndex = 1;
  129. this.txt1.Text = "";
  130. this.txt1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txt1_KeyPress);
  131. // 
  132. // label1
  133. // 
  134. this.label1.Location = new System.Drawing.Point(40, 28);
  135. this.label1.Name = "label1";
  136. this.label1.Size = new System.Drawing.Size(48, 16);
  137. this.label1.TabIndex = 0;
  138. this.label1.Text = "学号";
  139. this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
  140. // 
  141. // txt2
  142. // 
  143. this.txt2.Location = new System.Drawing.Point(272, 24);
  144. this.txt2.Name = "txt2";
  145. this.txt2.ReadOnly = true;
  146. this.txt2.TabIndex = 1;
  147. this.txt2.Text = "";
  148. // 
  149. // label2
  150. // 
  151. this.label2.Location = new System.Drawing.Point(224, 28);
  152. this.label2.Name = "label2";
  153. this.label2.Size = new System.Drawing.Size(48, 16);
  154. this.label2.TabIndex = 0;
  155. this.label2.Text = "姓名";
  156. this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
  157. // 
  158. // txt3
  159. // 
  160. this.txt3.Location = new System.Drawing.Point(480, 24);
  161. this.txt3.Name = "txt3";
  162. this.txt3.ReadOnly = true;
  163. this.txt3.TabIndex = 1;
  164. this.txt3.Text = "";
  165. // 
  166. // label4
  167. // 
  168. this.label4.Location = new System.Drawing.Point(432, 28);
  169. this.label4.Name = "label4";
  170. this.label4.Size = new System.Drawing.Size(48, 16);
  171. this.label4.TabIndex = 0;
  172. this.label4.Text = "班级";
  173. this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
  174. // 
  175. // dataGrid1
  176. // 
  177. this.dataGrid1.CaptionVisible = false;
  178. this.dataGrid1.DataMember = "";
  179. this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
  180. this.dataGrid1.Location = new System.Drawing.Point(0, 56);
  181. this.dataGrid1.Name = "dataGrid1";
  182. this.dataGrid1.ReadOnly = true;
  183. this.dataGrid1.Size = new System.Drawing.Size(696, 224);
  184. this.dataGrid1.TabIndex = 1;
  185. // 
  186. // groupBox2
  187. // 
  188. this.groupBox2.Controls.Add(this.dataGrid2);
  189. this.groupBox2.Controls.Add(this.groupBox3);
  190. this.groupBox2.Location = new System.Drawing.Point(0, 280);
  191. this.groupBox2.Name = "groupBox2";
  192. this.groupBox2.Size = new System.Drawing.Size(696, 224);
  193. this.groupBox2.TabIndex = 2;
  194. this.groupBox2.TabStop = false;
  195. this.groupBox2.Text = "课程信息";
  196. // 
  197. // dataGrid2
  198. // 
  199. this.dataGrid2.CaptionVisible = false;
  200. this.dataGrid2.DataMember = "";
  201. this.dataGrid2.HeaderForeColor = System.Drawing.SystemColors.ControlText;
  202. this.dataGrid2.Location = new System.Drawing.Point(216, 16);
  203. this.dataGrid2.Name = "dataGrid2";
  204. this.dataGrid2.ReadOnly = true;
  205. this.dataGrid2.Size = new System.Drawing.Size(472, 200);
  206. this.dataGrid2.TabIndex = 1;
  207. // 
  208. // groupBox3
  209. // 
  210. this.groupBox3.Controls.Add(this.txt4);
  211. this.groupBox3.Controls.Add(this.label3);
  212. this.groupBox3.Controls.Add(this.btnSearch);
  213. this.groupBox3.Controls.Add(this.btnElect);
  214. this.groupBox3.Controls.Add(this.btnDelete);
  215. this.groupBox3.Controls.Add(this.btnView);
  216. this.groupBox3.Controls.Add(this.label5);
  217. this.groupBox3.Controls.Add(this.txt5);
  218. this.groupBox3.Controls.Add(this.label6);
  219. this.groupBox3.Controls.Add(this.txt6);
  220. this.groupBox3.Controls.Add(this.txt7);
  221. this.groupBox3.Controls.Add(this.label7);
  222. this.groupBox3.Location = new System.Drawing.Point(8, 16);
  223. this.groupBox3.Name = "groupBox3";
  224. this.groupBox3.Size = new System.Drawing.Size(200, 200);
  225. this.groupBox3.TabIndex = 0;
  226. this.groupBox3.TabStop = false;
  227. // 
  228. // txt4
  229. // 
  230. this.txt4.Location = new System.Drawing.Point(72, 16);
  231. this.txt4.Name = "txt4";
  232. this.txt4.Size = new System.Drawing.Size(112, 21);
  233. this.txt4.TabIndex = 2;
  234. this.txt4.Text = "";
  235. // 
  236. // label3
  237. // 
  238. this.label3.Location = new System.Drawing.Point(16, 16);
  239. this.label3.Name = "label3";
  240. this.label3.Size = new System.Drawing.Size(56, 16);
  241. this.label3.TabIndex = 1;
  242. this.label3.Text = "课程拼音";
  243. // 
  244. // btnSearch
  245. // 
  246. this.btnSearch.Image = ((System.Drawing.Image)(resources.GetObject("btnSearch.Image")));
  247. this.btnSearch.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
  248. this.btnSearch.Location = new System.Drawing.Point(16, 120);
  249. this.btnSearch.Name = "btnSearch";
  250. this.btnSearch.TabIndex = 0;
  251. this.btnSearch.Text = "查询";
  252. this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click);
  253. // 
  254. // btnElect
  255. // 
  256. this.btnElect.Enabled = false;
  257. this.btnElect.Image = ((System.Drawing.Image)(resources.GetObject("btnElect.Image")));
  258. this.btnElect.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
  259. this.btnElect.Location = new System.Drawing.Point(112, 120);
  260. this.btnElect.Name = "btnElect";
  261. this.btnElect.TabIndex = 0;
  262. this.btnElect.Text = "选课";
  263. this.btnElect.Click += new System.EventHandler(this.btnElect_Click);
  264. // 
  265. // btnDelete
  266. // 
  267. this.btnDelete.Enabled = false;
  268. this.btnDelete.Image = ((System.Drawing.Image)(resources.GetObject("btnDelete.Image")));
  269. this.btnDelete.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
  270. this.btnDelete.Location = new System.Drawing.Point(16, 160);
  271. this.btnDelete.Name = "btnDelete";
  272. this.btnDelete.TabIndex = 0;
  273. this.btnDelete.Text = "删课";
  274. this.btnDelete.Click += new System.EventHandler(this.btnDelete_Click);
  275. // 
  276. // btnView
  277. // 
  278. this.btnView.Enabled = false;
  279. this.btnView.Image = ((System.Drawing.Image)(resources.GetObject("btnView.Image")));
  280. this.btnView.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
  281. this.btnView.Location = new System.Drawing.Point(112, 160);
  282. this.btnView.Name = "btnView";
  283. this.btnView.TabIndex = 0;
  284. this.btnView.Text = "看课表";
  285. this.btnView.Click += new System.EventHandler(this.btnView_Click);
  286. // 
  287. // label5
  288. // 
  289. this.label5.Location = new System.Drawing.Point(16, 40);
  290. this.label5.Name = "label5";
  291. this.label5.Size = new System.Drawing.Size(56, 16);
  292. this.label5.TabIndex = 1;
  293. this.label5.Text = "课程名称";
  294. // 
  295. // txt5
  296. // 
  297. this.txt5.Location = new System.Drawing.Point(72, 40);
  298. this.txt5.Name = "txt5";
  299. this.txt5.Size = new System.Drawing.Size(112, 21);
  300. this.txt5.TabIndex = 2;
  301. this.txt5.Text = "";
  302. // 
  303. // label6
  304. // 
  305. this.label6.Location = new System.Drawing.Point(16, 64);
  306. this.label6.Name = "label6";
  307. this.label6.Size = new System.Drawing.Size(56, 16);
  308. this.label6.TabIndex = 1;
  309. this.label6.Text = "课程编号";
  310. // 
  311. // txt6
  312. // 
  313. this.txt6.Location = new System.Drawing.Point(72, 64);
  314. this.txt6.Name = "txt6";
  315. this.txt6.Size = new System.Drawing.Size(112, 21);
  316. this.txt6.TabIndex = 2;
  317. this.txt6.Text = "";
  318. // 
  319. // txt7
  320. // 
  321. this.txt7.Location = new System.Drawing.Point(72, 88);
  322. this.txt7.Name = "txt7";
  323. this.txt7.Size = new System.Drawing.Size(112, 21);
  324. this.txt7.TabIndex = 2;
  325. this.txt7.Text = "";
  326. // 
  327. // label7
  328. // 
  329. this.label7.Location = new System.Drawing.Point(16, 88);
  330. this.label7.Name = "label7";
  331. this.label7.Size = new System.Drawing.Size(56, 16);
  332. this.label7.TabIndex = 1;
  333. this.label7.Text = "课序号";
  334. // 
  335. // CourseElect
  336. // 
  337. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  338. this.ClientSize = new System.Drawing.Size(696, 509);
  339. this.Controls.Add(this.groupBox2);
  340. this.Controls.Add(this.dataGrid1);
  341. this.Controls.Add(this.groupBox1);
  342. this.Name = "CourseElect";
  343. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
  344. this.Text = "【学生选课】";
  345. this.Load += new System.EventHandler(this.CourseElect_Load);
  346. this.groupBox1.ResumeLayout(false);
  347. ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
  348. this.groupBox2.ResumeLayout(false);
  349. ((System.ComponentModel.ISupportInitialize)(this.dataGrid2)).EndInit();
  350. this.groupBox3.ResumeLayout(false);
  351. this.ResumeLayout(false);
  352. }
  353. #endregion
  354. //----------输入学号后回车,显示学生信息和选课信息-----------
  355. private void txt1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
  356. {
  357. if(e.KeyChar==13&&txt1.Text.Trim()!="")//输入学号后回车,查询学生信息和选课信息
  358. {
  359. this.electTable.Clear();//先清空选课表
  360. txt2.Clear();
  361. txt3.Clear();
  362. //关闭选课,删课等许可
  363. btnElect.Enabled=false;
  364. btnDelete.Enabled=false;
  365. btnView.Enabled=false;
  366. this.ShowInfo();
  367. }
  368. }
  369. //--------窗体新建时,绑定数据集和读入可选课程信息--------
  370. private void CourseElect_Load(object sender, System.EventArgs e)
  371. {
  372. //绑定dataGrid到学生选课信息上
  373. dataGrid1.DataSource=this.electTable;
  374. //读入可选课程数据 string strConn="workstation id=localhost;Integrated Security=SSPI;database=eisbook;"; SqlConnection cn=new SqlConnection(strConn); cn.Open();
  375. string sql="select a.课序号,a.课程编号,b.课程名称,b.教师,b.开课系别,"
  376. +"a.上课地点,a.上课时间天,a.上课时间节,b.拼音码"
  377. +" from 课程表 a,课程信息 b"
  378. +" where (b.本学期课程='Y')and(a.课程编号=b.课程编号)";
  379. SqlDataAdapter da2=new SqlDataAdapter(sql,cn);
  380. da2.Fill(this.courseTable);//可供选择的课程信息
  381. this.dv=courseTable.DefaultView;
  382. dataGrid2.DataSource=dv;//绑定显示可选课程信息
  383. }
  384. //------显示学生信息和选课信息-----
  385. private void ShowInfo()//
  386. {
  387. string strConn="workstation id=localhost;Integrated Security=SSPI;database=eisbook;"; SqlConnection cn=new SqlConnection(strConn); cn.Open();
  388. SqlCommand cmd=cn.CreateCommand();
  389. cmd.CommandText="select a.姓名,b.班级名称,a.学籍编号 from 学生信息 a,班级信息 b "
  390. +"where(a.班级编号=b.班级编号)and(学号='"+txt1.Text.Trim()+"')";
  391. SqlDataReader dr=cmd.ExecuteReader();
  392. dr.Read();//读入数据
  393. if(!dr.HasRows)//判断学号是否输入正确
  394. {
  395. MessageBox.Show("无此学生,请重新输入学号","提示",MessageBoxButtons.OK,MessageBoxIcon.Stop);
  396. dr.Close();
  397. return;
  398. }
  399. if(dr.GetValue(2).ToString().Trim()!="1")//判断是否为在籍学生
  400. {
  401. MessageBox.Show("该学生并非在籍学生,不能选课","提示",MessageBoxButtons.OK,MessageBoxIcon.Stop);                
  402. return;
  403. }
  404. txt2.Text=dr.GetValue(0).ToString().Trim();//姓名
  405. txt3.Text=dr.GetValue(1).ToString().Trim();//班级名称
  406. dr.Close();
  407. //读入选课信息
  408. string sql="select a.学号,a.课序号,b.课程名称,b.教师,"
  409. +"b.开课系别,c.上课时间天,c.上课时间节,c.上课地点"
  410. +" from 选课表 a,课程信息 b,课程表 c"
  411. +" where(a.课序号=c.课序号)and('200400000'+b.课程编号=a.课序号)"
  412. +"and(a.学号='"+txt1.Text.Trim()+"')";
  413. SqlDataAdapter da=new SqlDataAdapter(sql,cn);
  414. da.Fill(this.electTable);//该学生的选课信息
  415. this.studentID=txt1.Text.Trim();//保存获准选课的学生学号
  416. this.stduentName=txt2.Text.Trim();//保存学生姓名
  417. //允许选课,删课
  418. btnElect.Enabled=true;
  419. btnDelete.Enabled=true;
  420. btnView.Enabled=true;
  421.             
  422. }
  423. //-----------筛选课程-------------
  424. private void btnSearch_Click(object sender, System.EventArgs e)
  425. {
  426.             string filter="";
  427. if(txt4.Text.Trim()!="")
  428. {
  429. filter+="拼音码 like '%"+txt4.Text.Trim()+"%' AND ";
  430. }
  431. if(txt5.Text.Trim()!="")
  432. {
  433. filter+="课程名称 like '%"+txt5.Text.Trim()+"%' AND ";
  434. }
  435. if(txt6.Text.Trim()!="")
  436. {
  437. filter+="课程编号='"+txt6.Text.Trim()+"' AND ";
  438. }
  439. if(txt7.Text.Trim()!="")
  440. {
  441. filter+="课序号 like '%"+txt7.Text.Trim()+"%' AND ";
  442. }
  443. if(filter.Length>0)
  444. {
  445. filter=filter.Substring(0,filter.Length-5);
  446. }
  447. dv.RowFilter=filter;
  448. }
  449. //-------------学生选课-----------
  450. private void btnElect_Click(object sender, System.EventArgs e)
  451. {
  452. if(dv.Count==0)//可选课程为空不能选课
  453. {
  454. MessageBox.Show("可选课表为空,无法选课","提示",MessageBoxButtons.OK,MessageBoxIcon.Stop);
  455. return;
  456. }
  457. string courseID=dataGrid2[dataGrid2.CurrentCell.RowNumber,0].ToString().Trim();//当前所选的课序号
  458. string courseDay=dataGrid2[dataGrid2.CurrentCell.RowNumber,6].ToString().Trim();//所选课程的上课时间天
  459. string courseSec=dataGrid2[dataGrid2.CurrentCell.RowNumber,7].ToString().Trim();//所选课程的上课时间节
  460. foreach(DataRow aRow in this.electTable.Rows)
  461. {
  462. if(aRow["课序号"].ToString().Trim()==courseID)
  463. {
  464. MessageBox.Show("所选课程已经在课程表中","课程重复",MessageBoxButtons.OK,MessageBoxIcon.Stop);
  465. return;
  466. }
  467. if(aRow["上课时间天"].ToString().Trim()==courseDay&&aRow["上课时间节"].ToString().Trim()==courseSec)
  468. {
  469. string msg="所选课程和已选课程:"+aRow["课程名称"].ToString().Trim()+" 上课时间冲突";
  470. MessageBox.Show(msg,"时间冲突",MessageBoxButtons.OK,MessageBoxIcon.Stop);
  471. return;
  472. }
  473. }
  474. string strConn="workstation id=localhost;Integrated Security=SSPI;database=eisbook;"; SqlConnection cn=new SqlConnection(strConn); cn.Open();
  475. SqlCommand cmd=cn.CreateCommand();
  476. cmd.CommandText="insert into 选课表([学号],[课序号]) values('"+this.studentID+"','"+courseID+"')";
  477. cmd.ExecuteNonQuery();
  478. //重新读入学生的选课信息
  479. this.electTable.Clear();
  480. string sql="select a.学号,a.课序号,b.课程名称,b.教师,"
  481. +"b.开课系别,c.上课时间天,c.上课时间节,c.上课地点"
  482. +" from 选课表 a,课程信息 b,课程表 c"
  483. +" where(a.课序号=c.课序号)and('200400000'+b.课程编号=a.课序号)"
  484. +"and(a.学号='"+this.studentID+"')";
  485. SqlDataAdapter da=new SqlDataAdapter(sql,cn);
  486. da.Fill(this.electTable);//该学生的选课信息
  487. }
  488. //---------删除原来所选的课程------------
  489. private void btnDelete_Click(object sender, System.EventArgs e)
  490. {
  491. if(this.electTable.Rows.Count==0)
  492. {
  493. return;//无课可删,不作任何动作
  494. }
  495. string deleteID=dataGrid1[dataGrid1.CurrentCell.RowNumber,1].ToString().Trim();//要删除的课序号
  496. string deleteName=dataGrid1[dataGrid1.CurrentCell.RowNumber,2].ToString().Trim();//要删除的课名称
  497. string msg="是否确认删除已选课程:"+deleteName+" ?";
  498. DialogResult result=MessageBox.Show(msg,"删除课程",MessageBoxButtons.OKCancel);
  499. if(result==DialogResult.OK)
  500. {
  501. string strConn="workstation id=localhost;Integrated Security=SSPI;database=eisbook;"; SqlConnection cn=new SqlConnection(strConn); cn.Open();
  502. SqlCommand cmd=cn.CreateCommand();
  503. cmd.CommandText="delete from 选课表 where(学号='"+this.studentID+"')and(课序号='"+deleteID+"')";
  504. cmd.ExecuteNonQuery();
  505. //重新读入学生的选课信息
  506. this.electTable.Clear();
  507. string sql="select a.学号,a.课序号,b.课程名称,b.教师,"
  508. +"b.开课系别,c.上课时间天,c.上课时间节,c.上课地点"
  509. +" from 选课表 a,课程信息 b,课程表 c"
  510. +" where(a.课序号=c.课序号)and('200400000'+b.课程编号=a.课序号)"
  511. +"and(a.学号='"+this.studentID+"')";
  512. SqlDataAdapter da=new SqlDataAdapter(sql,cn);
  513. da.Fill(this.electTable);//该学生的选课信息
  514. }
  515. }
  516. //---------显示当前选课学生的课表------------
  517. private void btnView_Click(object sender, System.EventArgs e)
  518. {
  519. CurriculumSchedule newFrm=new CurriculumSchedule(this.studentID);
  520. newFrm.Text+="学生:"+this.stduentName;
  521. newFrm.ShowDialog();
  522. }
  523. }
  524. }