ParentForm.cs
上传用户:yongjiajia
上传日期:2021-01-30
资源大小:686k
文件大小:14k
开发平台:

ASP/ASPX

  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. /// ParentForm 的摘要说明。
  12. /// </summary>
  13. public class ParentForm : System.Windows.Forms.Form
  14. {
  15. protected CurrencyManager cmOrders;//用于数据导航控制
  16. protected DataSet dataSet11;
  17. protected System.Windows.Forms.GroupBox groupBox1;
  18. protected System.Windows.Forms.TextBox txt2;
  19. protected System.Windows.Forms.Label label1;
  20. protected System.Windows.Forms.Button btnSearch;
  21. protected System.Windows.Forms.TextBox txt1;
  22. protected System.Windows.Forms.Label label2;
  23. protected System.Windows.Forms.TextBox txt3;
  24. protected System.Windows.Forms.Label label3;
  25. private System.Windows.Forms.ImageList imageList1;
  26. protected System.Windows.Forms.ToolBar toolBar1;
  27. private System.Windows.Forms.ToolBarButton tBtnFirst;
  28. private System.Windows.Forms.ToolBarButton tBtnPre;
  29. private System.Windows.Forms.ToolBarButton tBtnNext;
  30. private System.Windows.Forms.ToolBarButton tBtnLast;
  31. private System.Windows.Forms.ToolBarButton tBtnNew;
  32. private System.Windows.Forms.ToolBarButton tBtnEdit;
  33. private System.Windows.Forms.ToolBarButton tBtnDelete;
  34. private System.Windows.Forms.ToolBarButton tBtnSubmit;
  35. private System.Windows.Forms.ToolBarButton tBtnCancel;
  36. private System.Windows.Forms.ToolBarButton tBtnQuit;
  37. protected System.Windows.Forms.DataGrid dataGrid1;
  38. protected System.Windows.Forms.GroupBox groupBox2;
  39. private System.Data.SqlClient.SqlCommand sqlSelectCommand1;
  40. private System.Data.SqlClient.SqlCommand sqlInsertCommand1;
  41. private System.Data.SqlClient.SqlCommand sqlUpdateCommand1;
  42. private System.Data.SqlClient.SqlCommand sqlDeleteCommand1;
  43. protected System.Data.SqlClient.SqlDataAdapter da1;
  44. private System.ComponentModel.IContainer components;
  45. public ParentForm()
  46. {
  47. //
  48. // Windows 窗体设计器支持所必需的
  49. //
  50. InitializeComponent();
  51. //
  52. // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
  53. //
  54. }
  55. /// <summary>
  56. /// 清理所有正在使用的资源。
  57. /// </summary>
  58. protected override void Dispose( bool disposing )
  59. {
  60. if( disposing )
  61. {
  62. if(components != null)
  63. {
  64. components.Dispose();
  65. }
  66. }
  67. base.Dispose( disposing );
  68. }
  69. #region Windows 窗体设计器生成的代码
  70. /// <summary>
  71. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  72. /// 此方法的内容。
  73. /// </summary>
  74. private void InitializeComponent()
  75. {
  76. this.components = new System.ComponentModel.Container();
  77. System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(ParentForm));
  78. this.groupBox1 = new System.Windows.Forms.GroupBox();
  79. this.txt2 = new System.Windows.Forms.TextBox();
  80. this.label1 = new System.Windows.Forms.Label();
  81. this.btnSearch = new System.Windows.Forms.Button();
  82. this.txt1 = new System.Windows.Forms.TextBox();
  83. this.label2 = new System.Windows.Forms.Label();
  84. this.txt3 = new System.Windows.Forms.TextBox();
  85. this.label3 = new System.Windows.Forms.Label();
  86. this.imageList1 = new System.Windows.Forms.ImageList(this.components);
  87. this.toolBar1 = new System.Windows.Forms.ToolBar();
  88. this.tBtnFirst = new System.Windows.Forms.ToolBarButton();
  89. this.tBtnPre = new System.Windows.Forms.ToolBarButton();
  90. this.tBtnNext = new System.Windows.Forms.ToolBarButton();
  91. this.tBtnLast = new System.Windows.Forms.ToolBarButton();
  92. this.tBtnNew = new System.Windows.Forms.ToolBarButton();
  93. this.tBtnEdit = new System.Windows.Forms.ToolBarButton();
  94. this.tBtnDelete = new System.Windows.Forms.ToolBarButton();
  95. this.tBtnSubmit = new System.Windows.Forms.ToolBarButton();
  96. this.tBtnCancel = new System.Windows.Forms.ToolBarButton();
  97. this.tBtnQuit = new System.Windows.Forms.ToolBarButton();
  98. this.dataGrid1 = new System.Windows.Forms.DataGrid();
  99. this.groupBox2 = new System.Windows.Forms.GroupBox();
  100. this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
  101. this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand();
  102. this.sqlUpdateCommand1 = new System.Data.SqlClient.SqlCommand();
  103. this.sqlDeleteCommand1 = new System.Data.SqlClient.SqlCommand();
  104. this.da1 = new System.Data.SqlClient.SqlDataAdapter();
  105. this.groupBox1.SuspendLayout();
  106. ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
  107. this.SuspendLayout();
  108. // 
  109. // groupBox1
  110. // 
  111. this.groupBox1.Controls.Add(this.txt2);
  112. this.groupBox1.Controls.Add(this.label1);
  113. this.groupBox1.Controls.Add(this.btnSearch);
  114. this.groupBox1.Controls.Add(this.txt1);
  115. this.groupBox1.Controls.Add(this.label2);
  116. this.groupBox1.Controls.Add(this.txt3);
  117. this.groupBox1.Controls.Add(this.label3);
  118. this.groupBox1.Location = new System.Drawing.Point(0, 40);
  119. this.groupBox1.Name = "groupBox1";
  120. this.groupBox1.Size = new System.Drawing.Size(728, 56);
  121. this.groupBox1.TabIndex = 28;
  122. this.groupBox1.TabStop = false;
  123. // 
  124. // txt2
  125. // 
  126. this.txt2.Location = new System.Drawing.Point(368, 24);
  127. this.txt2.Name = "txt2";
  128. this.txt2.TabIndex = 2;
  129. this.txt2.Text = "";
  130. // 
  131. // label1
  132. // 
  133. this.label1.Location = new System.Drawing.Point(304, 28);
  134. this.label1.Name = "label1";
  135. this.label1.Size = new System.Drawing.Size(64, 16);
  136. this.label1.TabIndex = 1;
  137. this.label1.Text = "查询条件2";
  138. // 
  139. // btnSearch
  140. // 
  141. this.btnSearch.Image = ((System.Drawing.Image)(resources.GetObject("btnSearch.Image")));
  142. this.btnSearch.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
  143. this.btnSearch.Location = new System.Drawing.Point(16, 24);
  144. this.btnSearch.Name = "btnSearch";
  145. this.btnSearch.Size = new System.Drawing.Size(72, 23);
  146. this.btnSearch.TabIndex = 0;
  147. this.btnSearch.Text = " 搜索";
  148. // 
  149. // txt1
  150. // 
  151. this.txt1.Location = new System.Drawing.Point(168, 24);
  152. this.txt1.Name = "txt1";
  153. this.txt1.TabIndex = 2;
  154. this.txt1.Text = "";
  155. // 
  156. // label2
  157. // 
  158. this.label2.Location = new System.Drawing.Point(104, 28);
  159. this.label2.Name = "label2";
  160. this.label2.Size = new System.Drawing.Size(64, 16);
  161. this.label2.TabIndex = 1;
  162. this.label2.Text = "查询条件1";
  163. // 
  164. // txt3
  165. // 
  166. this.txt3.Location = new System.Drawing.Point(571, 24);
  167. this.txt3.Name = "txt3";
  168. this.txt3.TabIndex = 2;
  169. this.txt3.Text = "";
  170. // 
  171. // label3
  172. // 
  173. this.label3.Location = new System.Drawing.Point(512, 28);
  174. this.label3.Name = "label3";
  175. this.label3.Size = new System.Drawing.Size(64, 16);
  176. this.label3.TabIndex = 1;
  177. this.label3.Text = "查询条件3";
  178. // 
  179. // imageList1
  180. // 
  181. this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
  182. this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
  183. this.imageList1.TransparentColor = System.Drawing.SystemColors.ControlLightLight;
  184. // 
  185. // toolBar1
  186. // 
  187. this.toolBar1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
  188. this.tBtnFirst,
  189. this.tBtnPre,
  190. this.tBtnNext,
  191. this.tBtnLast,
  192. this.tBtnNew,
  193. this.tBtnEdit,
  194. this.tBtnDelete,
  195. this.tBtnSubmit,
  196. this.tBtnCancel,
  197. this.tBtnQuit});
  198. this.toolBar1.DropDownArrows = true;
  199. this.toolBar1.ImageList = this.imageList1;
  200. this.toolBar1.Location = new System.Drawing.Point(0, 0);
  201. this.toolBar1.Name = "toolBar1";
  202. this.toolBar1.ShowToolTips = true;
  203. this.toolBar1.Size = new System.Drawing.Size(728, 41);
  204. this.toolBar1.TabIndex = 29;
  205. this.toolBar1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar1_ButtonClick);
  206. // 
  207. // tBtnFirst
  208. // 
  209. this.tBtnFirst.ImageIndex = 0;
  210. this.tBtnFirst.Text = "首记录";
  211. this.tBtnFirst.ToolTipText = "首记录";
  212. // 
  213. // tBtnPre
  214. // 
  215. this.tBtnPre.ImageIndex = 1;
  216. this.tBtnPre.Text = "上一记录";
  217. this.tBtnPre.ToolTipText = "上一记录";
  218. // 
  219. // tBtnNext
  220. // 
  221. this.tBtnNext.ImageIndex = 2;
  222. this.tBtnNext.Text = "下一记录";
  223. this.tBtnNext.ToolTipText = "下一记录";
  224. // 
  225. // tBtnLast
  226. // 
  227. this.tBtnLast.ImageIndex = 3;
  228. this.tBtnLast.Text = "尾记录";
  229. this.tBtnLast.ToolTipText = "尾记录";
  230. // 
  231. // tBtnNew
  232. // 
  233. this.tBtnNew.ImageIndex = 4;
  234. this.tBtnNew.Text = "新增";
  235. this.tBtnNew.ToolTipText = "新增";
  236. // 
  237. // tBtnEdit
  238. // 
  239. this.tBtnEdit.ImageIndex = 5;
  240. this.tBtnEdit.Text = "修改";
  241. this.tBtnEdit.ToolTipText = "修改";
  242. // 
  243. // tBtnDelete
  244. // 
  245. this.tBtnDelete.ImageIndex = 6;
  246. this.tBtnDelete.Text = "删除";
  247. this.tBtnDelete.ToolTipText = "删除";
  248. // 
  249. // tBtnSubmit
  250. // 
  251. this.tBtnSubmit.ImageIndex = 7;
  252. this.tBtnSubmit.Text = "提交";
  253. this.tBtnSubmit.ToolTipText = "提交";
  254. // 
  255. // tBtnCancel
  256. // 
  257. this.tBtnCancel.ImageIndex = 8;
  258. this.tBtnCancel.Text = "取消";
  259. this.tBtnCancel.ToolTipText = "取消";
  260. // 
  261. // tBtnQuit
  262. // 
  263. this.tBtnQuit.ImageIndex = 9;
  264. this.tBtnQuit.Text = "退出";
  265. this.tBtnQuit.ToolTipText = "退出";
  266. // 
  267. // dataGrid1
  268. // 
  269. this.dataGrid1.CaptionVisible = false;
  270. this.dataGrid1.DataMember = "";
  271. this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
  272. this.dataGrid1.Location = new System.Drawing.Point(0, 96);
  273. this.dataGrid1.Name = "dataGrid1";
  274. this.dataGrid1.ReadOnly = true;
  275. this.dataGrid1.Size = new System.Drawing.Size(728, 280);
  276. this.dataGrid1.TabIndex = 30;
  277. // 
  278. // groupBox2
  279. // 
  280. this.groupBox2.Location = new System.Drawing.Point(0, 368);
  281. this.groupBox2.Name = "groupBox2";
  282. this.groupBox2.Size = new System.Drawing.Size(728, 128);
  283. this.groupBox2.TabIndex = 31;
  284. this.groupBox2.TabStop = false;
  285. // 
  286. // da1
  287. // 
  288. this.da1.DeleteCommand = this.sqlDeleteCommand1;
  289. this.da1.InsertCommand = this.sqlInsertCommand1;
  290. this.da1.SelectCommand = this.sqlSelectCommand1;
  291. this.da1.UpdateCommand = this.sqlUpdateCommand1;
  292. // 
  293. // ParentForm
  294. // 
  295. this.AcceptButton = this.btnSearch;
  296. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  297. this.ClientSize = new System.Drawing.Size(728, 502);
  298. this.Controls.Add(this.groupBox2);
  299. this.Controls.Add(this.dataGrid1);
  300. this.Controls.Add(this.toolBar1);
  301. this.Controls.Add(this.groupBox1);
  302. this.Name = "ParentForm";
  303. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
  304. this.Text = "ParentForm";
  305. this.groupBox1.ResumeLayout(false);
  306. ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
  307. this.ResumeLayout(false);
  308. }
  309. #endregion
  310. //-----------工具栏控制代码-------------
  311. protected void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
  312. {
  313. if (e.Button.ToolTipText == "首记录")
  314. {
  315. this.dataGrid1.UnSelect(cmOrders.Position); //取消原选中的行
  316. cmOrders.Position = 0;
  317. this.dataGrid1.Select(cmOrders.Position); //选中当前行
  318. this.dataGrid1.CurrentRowIndex = cmOrders.Position; //移动表头指示图标
  319. return;
  320. }
  321. if (e.Button.ToolTipText == "上一记录")
  322. {
  323. if (cmOrders.Position >= 0)
  324. {
  325. this.dataGrid1.UnSelect(cmOrders.Position); 
  326. cmOrders.Position--;
  327. this.dataGrid1.Select(cmOrders.Position);      
  328. this.dataGrid1.CurrentRowIndex = cmOrders.Position; 
  329. }
  330. return;
  331. }
  332. if (e.Button.ToolTipText == "下一记录")
  333. {
  334. if (cmOrders.Position <= cmOrders.Count-1)
  335. {
  336. this.dataGrid1.UnSelect(cmOrders.Position); 
  337. cmOrders.Position++;
  338. this.dataGrid1.Select(cmOrders.Position);       
  339. this.dataGrid1.CurrentRowIndex = cmOrders.Position; 
  340. }
  341. return;
  342. }
  343. if (e.Button.ToolTipText == "尾记录")
  344. {
  345. this.dataGrid1.UnSelect(cmOrders.Position); 
  346. cmOrders.Position = cmOrders.Count-1;
  347. this.dataGrid1.Select(cmOrders.Position);       
  348. this.dataGrid1.CurrentRowIndex = cmOrders.Position; 
  349. return;
  350. }
  351. if(e.Button.ToolTipText=="新增")
  352. {
  353. cmOrders.AddNew();//新增一条记录
  354.                 SetDefaultValue();//设置默认值
  355. SetModifyMode(true);//设置控件只读等属性
  356. }
  357. if(e.Button.ToolTipText=="修改")
  358. {
  359. SetModifyMode(true);
  360. }
  361. if(e.Button.ToolTipText=="删除")
  362. {
  363. DialogResult result=MessageBox.Show("确认删除?","删除数据",MessageBoxButtons.OKCancel);
  364. if(result==DialogResult.OK)
  365. if(cmOrders.Count>0)//立即从数据集中删除
  366. {
  367. cmOrders.RemoveAt(cmOrders.Position);
  368. da1.Update(dataSet11);
  369. }
  370. else
  371. MessageBox.Show("表中为空,已无可删除数据","提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
  372. }
  373. if(e.Button.ToolTipText=="提交")
  374. {
  375. bool canSubmit;
  376. canSubmit=this.CheckNotNull();
  377. if(canSubmit==false)//有非空值字段为空,不允许提交
  378. {
  379. return;
  380. }
  381. cmOrders.EndCurrentEdit();
  382. if(dataSet11.GetChanges()!=null)
  383. {
  384. try
  385. {
  386. da1.Update(dataSet11);
  387. SetModifyMode(false);
  388. }
  389. catch(Exception express)
  390. {
  391. MessageBox.Show(express.ToString(),"提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
  392. dataSet11.RejectChanges();
  393. }
  394. }
  395. return;
  396. }
  397. if (e.Button.ToolTipText == "取消")
  398. {
  399. try
  400. {
  401. cmOrders.CancelCurrentEdit();  //取消编辑
  402. SetModifyMode(false);
  403. }
  404. catch(Exception express)
  405. {
  406. MessageBox.Show(express.ToString(),"提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
  407. }
  408. return;
  409. }
  410. if(e.Button.ToolTipText=="退出")
  411. {
  412. this.Close();
  413. }
  414. }
  415. protected virtual void SetModifyMode(bool blnEdit)
  416. {
  417. btnSearch.Enabled=!blnEdit;
  418. }
  419. protected virtual void SetDefaultValue()
  420. {
  421. return;
  422. }
  423. protected virtual bool CheckNotNull()
  424. {
  425. return(true);
  426. }
  427. }
  428. }