|
- 一、员工信息管理系统
- 1)绑定下拉列表的知识
- 1 private void Form1_Load(object sender, EventArgs e)
- 2 {
- 3 string sql = "select * from DeptInfo";
- 4 this.comboBox1.DataSource = s.CHA(sql);
- 5 this.comboBox1.DisplayMember = "Deptname";
- 6 this.comboBox1.ValueMember = "DeptID";
- 7 int ID = int.Parse(this.comboBox1.SelectedValue.ToString());
- 8 }
- 2)验证输入框中输入的数字
- 1 foreach (char chr in this.txtAeg.Text)
- 2 {
- 3 if(char.IsDigit(chr))
- 4 {
- 5 }
- 6 else{MessageBox.Show("年龄只能为整数类型");return;};
- 7 }
-
- 二、图书管理系统
- 1)初始化时间,统计表中的行数
- 1 //初始化时的数据
- 2 private void groupBox1_Enter(object sender, EventArgs e)
- 3 {
- 4 string sql = "select BookID,BookName,BookAuthor,BookConcert,BookDates,BookCount,TypeName from TblBookInfo
- inner join TblBookType on TblBookInfo.BookTypeID=TblBookType.ID";
- 5 dataGridView1.DataSource = S.CHA(sql);
- 6 this.label3.Text = "共有 " + (dataGridView1.RowCount-1).ToString() + " 条数据";
- 7 this.label2.Text = "当前时间为:" + DateTime.Now.ToString();
- 8 timer1.Start();
- 9 }
- 2)精确查找和模糊查找,发挥到极致(用拼接)
- 1 //选择精确查找或模糊查找
- 2 string tiaojian = this.textBox1.Text;//默认精确
- 3 if (radioButton2.Checked)
- 4 {
- 5 tiaojian = "%" + this.textBox1.Text + "%";
- 6 }
- 7 //查找的字段:编号,书名,作者,类型
- 8 string ziduan = "";
- 9 switch (comboBox1.SelectedIndex)
- 10 {
- 11 case 0:
- 12 ziduan = "BookID like'" + tiaojian +"'";
- 13 break;
- 14 case 1:
- 15 ziduan = "BookName like'" + tiaojian + "'";
- 16 break;
- 17 case 2:
- 18 ziduan = "BookAuthor like'" + tiaojian + "'";
- 19 break;
- 20 case 3:
- 21 ziduan = "TypeName like'" + tiaojian + "'";
- 22 break;
- 23 }
- 24 string sql = "select BookID,BookName,BookAuthor,BookConcert,BookDates,BookCount,TypeName from TblBookInfo
- inner join TblBookType on TblBookInfo.BookTypeID=TblBookType.ID where "+ziduan;
- 25 dataGridView1.DataSource = S.CHA(sql);
- 26 this.label3.Text = "共有 " + (dataGridView1.RowCount - 1).ToString() + " 条数据";
- 27 }
- 三、简易的销售管理系统
- 1)时间的模糊查询
- 1 if (radioButton3.Checked)
- 2 {
- 3 //获得,年,月,日
- 4 string r1 = dateTimePicker3.Value.ToShortDateString();
- 5 string r2 = dateTimePicker2.Value.ToShortDateString();
- 6 //日期的模糊查找
- 7 sqlc = string.Format("select * from biao2 where riqi>='{0}' and riqi<='{1}'", r1,r2);
- 8 }
- 2)控件是否能使用
- 1 //加载时
- 2 private void Form3_Load(object sender, EventArgs e)
- 3 {
- 4 this.textBox3.ReadOnly = true;
- 5 this.dateTimePicker3.Enabled = false;
- 6 this.dateTimePicker2.Enabled = false;
- 7 }
- 四、学员信息管理系统
- 1)运行程序后过一段时间打开另一个窗体
- 1 //加载时打开计时器
- 2 private void Form1_Load(object sender, EventArgs e)
- 3 {
- 4 timer1.Start();
- 5 }
- 6 //调计时器的Interval属性,每两秒执行一次
- 7 private void timer1_Tick(object sender, EventArgs e)
- 8 {
- 9 frmxx f = new frmxx();
- 10 f.Show(); //打开另一个窗体
- 11 timer1.Stop(); //然后关掉计时器
- 12 }
- 2)第一条,上一条,下一条,最后一条
- 1 //上一条,下一条
- 2 public void xiayi(int i)
- 3 {
- 4 this.comboBox1.SelectedIndex = i; //返回或设置哪个选项被选取,组合框现行选中项,索引
- 5 //根据索引,和列取得表中的值
- 6 this.textBox2.Text = this.dataGridView1.Rows[i].Cells[1].Value.ToString();
- 7 this.textBox3.Text = this.dataGridView1.Rows[i].Cells[2].Value.ToString();
- 8 this.textBox4.Text = this.dataGridView1.Rows[i].Cells[6].Value.ToString();
- 9 this.textBox5.Text = this.dataGridView1.Rows[i].Cells[7].Value.ToString();
- 10 this.textBox6.Text = this.dataGridView1.Rows[i].Cells[3].Value.ToString();
- 11 this.textBox7.Text = this.dataGridView1.Rows[i].Cells[5].Value.ToString();
- 12 this.textBox8.Text = this.dataGridView1.Rows[i].Cells[4].Value.ToString();
- 13 }
- 14 //第一条
- 15 private void button2_Click(object sender, EventArgs e)
- 16 {
- 17 xiayi(0);//索引为0
- 18 }
- 19 //最后一条
- 20 private void button5_Click(object sender, EventArgs e)
- 21 {
- 22 //先获得表中的行数,减去一个无数据行,索引从0开始的所以再减一
- 23 int z = dataGridView1.Rows.Count-2;
- 24 xiayi(z);
- 25 }
- 26 //上一条
- 27 private void button3_Click(object sender, EventArgs e)
- 28 {
- 29 //上一条,也就是索引减一
- 30 int i = this.comboBox1.SelectedIndex-1;
- 31 //当索引减到小于0时,将索引赋值为最大
- 32 if (i<0)
- 33 {
- 34 i = dataGridView1.Rows.Count-2;
- 35 }
- 36 xiayi(i);
- 37 }
- 38 //下一条
- 39 private void button4_Click(object sender, EventArgs e)
- 40 {
- 41 int i = this.comboBox1.SelectedIndex + 1;
- 42 //当索引增加到最大值时,将索引赋值为0
- 43 if (i > dataGridView1.Rows.Count - 2)
- 44 {
- 45 i = 0;
- 46 }
- 47 xiayi(i);
- 48 }
复制代码
|
|