51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

查看: 2341|回复: 0
打印 上一主题 下一主题

做完四个小项目的收获

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2018-5-31 17:24:23 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
  1. 一、员工信息管理系统
  2.     1)绑定下拉列表的知识

  3. 1         private void Form1_Load(object sender, EventArgs e)
  4. 2         {
  5. 3             string sql = "select * from DeptInfo";
  6. 4             this.comboBox1.DataSource = s.CHA(sql);
  7. 5             this.comboBox1.DisplayMember = "Deptname";
  8. 6             this.comboBox1.ValueMember = "DeptID";
  9. 7             int ID = int.Parse(this.comboBox1.SelectedValue.ToString());
  10. 8         }
  11.     2)验证输入框中输入的数字

  12. 1                 foreach (char chr in this.txtAeg.Text)
  13. 2                 {
  14. 3                     if(char.IsDigit(chr))
  15. 4                     {
  16. 5                     }
  17. 6                     else{MessageBox.Show("年龄只能为整数类型");return;};
  18. 7                 }
  19.   

  20.   二、图书管理系统

  21.     1)初始化时间,统计表中的行数

  22. 1         //初始化时的数据
  23. 2         private void groupBox1_Enter(object sender, EventArgs e)
  24. 3         {
  25. 4             string sql = "select BookID,BookName,BookAuthor,BookConcert,BookDates,BookCount,TypeName from TblBookInfo
  26.                   inner join TblBookType on TblBookInfo.BookTypeID=TblBookType.ID";
  27. 5             dataGridView1.DataSource = S.CHA(sql);
  28. 6             this.label3.Text = "共有 " + (dataGridView1.RowCount-1).ToString() + " 条数据";
  29. 7             this.label2.Text = "当前时间为:" + DateTime.Now.ToString();
  30. 8             timer1.Start();
  31. 9         }
  32.     2)精确查找和模糊查找,发挥到极致(用拼接)

  33. 1        //选择精确查找或模糊查找
  34. 2             string tiaojian = this.textBox1.Text;//默认精确
  35. 3             if (radioButton2.Checked)
  36. 4             {
  37. 5                 tiaojian = "%" + this.textBox1.Text + "%";
  38. 6             }
  39. 7             //查找的字段:编号,书名,作者,类型
  40. 8             string ziduan = "";
  41. 9             switch (comboBox1.SelectedIndex)
  42. 10             {
  43. 11                 case 0:
  44. 12                     ziduan = "BookID like'" + tiaojian +"'";
  45. 13                     break;
  46. 14                 case 1:
  47. 15                     ziduan = "BookName like'" + tiaojian + "'";
  48. 16                     break;
  49. 17                 case 2:
  50. 18                     ziduan = "BookAuthor like'" + tiaojian + "'";
  51. 19                     break;
  52. 20                 case 3:
  53. 21                     ziduan = "TypeName like'" + tiaojian + "'";
  54. 22                     break;
  55. 23             }
  56. 24             string sql = "select BookID,BookName,BookAuthor,BookConcert,BookDates,BookCount,TypeName from TblBookInfo
  57.                   inner join TblBookType on TblBookInfo.BookTypeID=TblBookType.ID where "+ziduan;
  58. 25             dataGridView1.DataSource = S.CHA(sql);
  59. 26             this.label3.Text = "共有 " + (dataGridView1.RowCount - 1).ToString() + " 条数据";
  60. 27         }
  61.     三、简易的销售管理系统

  62.       1)时间的模糊查询

  63. 1        if (radioButton3.Checked)
  64. 2             {
  65. 3                 //获得,年,月,日
  66. 4                 string r1 = dateTimePicker3.Value.ToShortDateString();
  67. 5                 string r2 = dateTimePicker2.Value.ToShortDateString();
  68. 6                 //日期的模糊查找
  69. 7                 sqlc = string.Format("select * from biao2 where riqi>='{0}' and riqi<='{1}'", r1,r2);
  70. 8             }
  71.       2)控件是否能使用

  72. 1         //加载时
  73. 2         private void Form3_Load(object sender, EventArgs e)
  74. 3         {
  75. 4             this.textBox3.ReadOnly = true;
  76. 5             this.dateTimePicker3.Enabled = false;
  77. 6             this.dateTimePicker2.Enabled = false;
  78. 7         }
  79.     四、学员信息管理系统

  80.       1)运行程序后过一段时间打开另一个窗体

  81. 1         //加载时打开计时器
  82. 2         private void Form1_Load(object sender, EventArgs e)
  83. 3         {
  84. 4             timer1.Start();
  85. 5         }
  86. 6         //调计时器的Interval属性,每两秒执行一次
  87. 7         private void timer1_Tick(object sender, EventArgs e)
  88. 8         {
  89. 9             frmxx f = new frmxx();   
  90. 10             f.Show();       //打开另一个窗体
  91. 11             timer1.Stop();  //然后关掉计时器
  92. 12         }
  93.       2)第一条,上一条,下一条,最后一条

  94. 1         //上一条,下一条
  95. 2         public void xiayi(int i)
  96. 3         {
  97. 4             this.comboBox1.SelectedIndex = i;  //返回或设置哪个选项被选取,组合框现行选中项,索引
  98. 5             //根据索引,和列取得表中的值
  99. 6             this.textBox2.Text = this.dataGridView1.Rows[i].Cells[1].Value.ToString();
  100. 7             this.textBox3.Text = this.dataGridView1.Rows[i].Cells[2].Value.ToString();
  101. 8             this.textBox4.Text = this.dataGridView1.Rows[i].Cells[6].Value.ToString();
  102. 9             this.textBox5.Text = this.dataGridView1.Rows[i].Cells[7].Value.ToString();
  103. 10             this.textBox6.Text = this.dataGridView1.Rows[i].Cells[3].Value.ToString();
  104. 11             this.textBox7.Text = this.dataGridView1.Rows[i].Cells[5].Value.ToString();
  105. 12             this.textBox8.Text = this.dataGridView1.Rows[i].Cells[4].Value.ToString();
  106. 13         }
  107. 14         //第一条
  108. 15         private void button2_Click(object sender, EventArgs e)
  109. 16         {
  110. 17             xiayi(0);//索引为0
  111. 18         }
  112. 19         //最后一条
  113. 20         private void button5_Click(object sender, EventArgs e)
  114. 21         {
  115. 22             //先获得表中的行数,减去一个无数据行,索引从0开始的所以再减一
  116. 23             int z = dataGridView1.Rows.Count-2;
  117. 24             xiayi(z);
  118. 25         }
  119. 26         //上一条
  120. 27         private void button3_Click(object sender, EventArgs e)
  121. 28         {
  122. 29             //上一条,也就是索引减一
  123. 30             int i = this.comboBox1.SelectedIndex-1;
  124. 31             //当索引减到小于0时,将索引赋值为最大
  125. 32             if (i<0)
  126. 33             {
  127. 34                 i = dataGridView1.Rows.Count-2;
  128. 35             }
  129. 36             xiayi(i);
  130. 37         }
  131. 38         //下一条
  132. 39         private void button4_Click(object sender, EventArgs e)
  133. 40         {
  134. 41             int i = this.comboBox1.SelectedIndex + 1;
  135. 42             //当索引增加到最大值时,将索引赋值为0
  136. 43             if (i > dataGridView1.Rows.Count - 2)
  137. 44             {
  138. 45                 i = 0;
  139. 46             }
  140. 47             xiayi(i);
  141. 48         }
复制代码


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-4-26 18:04 , Processed in 0.064957 second(s), 22 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表