public void resetData() { DataSet dstmp = new DataSet(); //创建虚拟数据表 DataTable table = new DataTable("TAB_NM"); //获取列集合,添加列 DataColumnCollection columns = table.Columns; columns.Add("教工号", typeof(String)); columns.Add("姓名", typeof(String)); columns.Add("基本工资", typeof(float)); columns.Add("津贴", typeof(float)); columns.Add("公积金", typeof(float)); columns.Add("生活费", typeof(float)); columns.Add("所得税", typeof(float)); List<Teacher> list = new TeacherDB().selectAll(); //Teacher mTeacher = new Teacher(); foreach (Teacher mTeacher in list) { //添加一行记录 DataRow row = table.NewRow(); row["教工号"] = mTeacher.Id; row["姓名"] = mTeacher.Name; row["基本工资"] = mTeacher.BaseSalary; row["津贴"] = mTeacher.Allowance; row["公积金"] = mTeacher.Fund; row["生活费"] = mTeacher.Sanitary; row["所得税"] = mTeacher.IncomeTax; table.Rows.Add(row); } dstmp.Tables.Add(table); //把信息表放入DataSet中 dataGridView1.DataSource = dstmp.Tables["TAB_NM"]; }
public void test() { TeacherDB teacherDB = new TeacherDB(); //测试delete Console.WriteLine(teacherDB.delete("teacher")); //测试update /*Teacher t1 = new Teacher(); t1.Id = "ABC111"; t1.Name = "zxcxzczxc"; Console.WriteLine(teacherDB.updata(t1));*/ /* //测试insert Teacher t1 = new Teacher(); t1.Id = "test1"; teacherDB.insert(t1); */ /* //测试selectTeacherByUserName Teacher t1 = new Teacher(); t1 = teacherDB.selectTeacherById("teacher"); MessageBox.Show(t1.ToString()); */ /* //测试selectAll List<Teacher> all = teacherDB.selectAll(); foreach (Teacher t1 in all) { Console.WriteLine(t1.ToString()); } */ }
private void button2_Click(object sender, EventArgs e) { if (b == false) { MessageBox.Show("请先查询!", "警告!"); return; } //判断教工号【是否符合条件,是否被修改】 if (!mTeacher.Id.Equals(textBox1.Text.ToString().Trim())) { if (Util.checkTeacherId(textBox1.Text.ToString().Trim())) mTeacher.Id = textBox1.Text.ToString().Trim();//如果教工号改变则重新为mTeacher的id赋值; else { textBox1.Select(); return; } } int f;//临时变量判断所有值是否全部检查通过; if ((f=Util.checkNum(textBox2.Text.ToString().Trim()))==0) mTeacher.BaseSalary = float.Parse(textBox2.Text.ToString().Trim()); else { if(f==1) MessageBox.Show("请输入正确数值!(基本工资)", "警告!"); else MessageBox.Show("请输入数值!(基本工资)", "警告!"); textBox2.Select(); return; } if ((f=Util.checkNum(textBox3.Text.ToString().Trim()))==0) mTeacher.Allowance = float.Parse(textBox3.Text.ToString().Trim()); else { if (f == 1) MessageBox.Show("请输入正确数值!(津贴)", "警告!"); else MessageBox.Show("请输入数值!(津贴)", "警告!"); textBox3.Select(); return; } if ((f=Util.checkNum(textBox4.Text.ToString().Trim()))==0) mTeacher.Fund = float.Parse(textBox4.Text.ToString().Trim()); else { if (f == 1) MessageBox.Show("请输入正确数值!(公积金)", "警告!"); else MessageBox.Show("请输入数值!(公积金)", "警告!"); textBox4.Select(); return; } if ((f=Util.checkNum(textBox5.Text.ToString().Trim()))==0) mTeacher.Sanitary = float.Parse(textBox5.Text.ToString().Trim()); else { if (f == 1) MessageBox.Show("请输入正确数值!(生活费)", "警告!"); else MessageBox.Show("请输入数值!(生活费)", "警告!"); textBox5.Select(); return; } if ((f=Util.checkNum(textBox6.Text.ToString().Trim()))==0) mTeacher.IncomeTax = float.Parse(textBox6.Text.ToString().Trim()); else { if (f == 1) MessageBox.Show("请输入正确数值!(所得税)", "警告!"); else MessageBox.Show("请输入数值!(所得税)", "警告!"); textBox6.Select(); return; } TeacherDB tdb = new TeacherDB(); if (tdb.updata(mTeacher) == 0) { MessageBox.Show("修改失败!", "警告!"); return; } else { MessageBox.Show("修改成功!", "消息!"); TeacherSelect._getInstance().resetData(); SalarySelect._getInstance().resetData(); } //如果控件已经存在就删除重建; textBox1.Text = ""; Util.checkView(this); }
private void button3_Click(object sender, EventArgs e) { TeacherDB tdb = new TeacherDB(); if ("".Equals(textBox1.Text.ToString().Trim())) { MessageBox.Show("教工号不能为空!","警告!"); return; } if (tdb.delete(textBox1.Text.ToString().Trim())==0) { MessageBox.Show("用户名不存在!","警告!"); return; } TeacherSelect._getInstance().resetData(); SalarySelect._getInstance().resetData(); MessageBox.Show("删除成功!","消息!"); textBox1.Text = ""; //如果控件已经存在就删除重建; Util.checkView(this); }
private void button2_Click(object sender, EventArgs e) { if (b == false) { MessageBox.Show("请先查询!", "警告!"); return; } //判断教工号【是否符合条件,是否被修改】 if (!mTeacher.Id.Equals(textBox1.Text.ToString().Trim())) { if(Util.checkTeacherId(textBox1.Text.ToString().Trim())) mTeacher.Id = textBox1.Text.ToString().Trim();//如果教工号改变则重新为mTeacher的id赋值; else { textBox1.Select(); return; } } //开始为mTeacher赋值 mTeacher.Name = textBox2.Text.ToString().Trim(); if (rb1.Checked) mTeacher.Sex = "男"; else mTeacher.Sex = "女"; mTeacher.Organization = textBox3.Text.ToString().Trim(); mTeacher.Address = textBox4.Text.ToString().Trim(); mTeacher.Phone = textBox5.Text.ToString().Trim(); TeacherDB tdb = new TeacherDB(); tdb.updata(mTeacher); if (tdb.updata(mTeacher) == 0) { MessageBox.Show("修改失败!", "警告!"); return; } else { MessageBox.Show("修改成功!", "消息!"); TeacherSelect._getInstance().resetData(); SalarySelect._getInstance().resetData(); } //如果控件已经存在就删除重建; textBox1.Text = ""; Util.checkView(this); b = false;//查询未完成 }
private void button1_Click(object sender, EventArgs e) { flag = true;//初始化flag //判断教工号格式 if(!Util.checkInputTeacherId(textBox1.Text.ToString().Trim(),label7,1)) flag=false; //判断基本工资 if (!Util.checkSalary(textBox2, label8)) flag = false; //判断津贴 if (!Util.checkSalary(textBox3, label9)) flag = false; //判断公积金 if (!Util.checkSalary(textBox4, label10)) flag = false; //判断生活费 if (!Util.checkSalary(textBox5, label11)) flag = false; //判断所得税 if (!Util.checkSalary(textBox6, label12)) flag = false; if (flag == true) { Teacher mTeacher = new TeacherDB().selectTeacherById(textBox1.Text.ToString().Trim()); mTeacher.BaseSalary = float.Parse(textBox2.Text.ToString().Trim()); mTeacher.Allowance = float.Parse(textBox3.Text.ToString().Trim()); mTeacher.Fund = float.Parse(textBox4.Text.ToString().Trim()); mTeacher.Sanitary = float.Parse(textBox5.Text.ToString().Trim()); mTeacher.IncomeTax = float.Parse(textBox6.Text.ToString().Trim()); TeacherDB tdb = new TeacherDB(); if (tdb.updata(mTeacher) == 0) { MessageBox.Show("插入失败!", "警告!"); return; } else { TeacherSelect._getInstance().resetData(); SalarySelect._getInstance().resetData(); MessageBox.Show("插入成功!", "消息!"); textBox1.Text = ""; textBox2.Text = ""; textBox3.Text = ""; textBox4.Text = ""; textBox5.Text = ""; textBox6.Text = ""; label7.Text = ""; label8.Text = ""; label9.Text = ""; label10.Text = ""; label11.Text = ""; label12.Text = ""; } } }
/* *教工号判断 * */ public static Boolean checkTeacherId(String str) { if ("".Equals(str)) { MessageBox.Show("教工号不能为空!", "警告!"); return false; } else { Regex idReg = new Regex("[A-Z]{3}[0-9]{3}"); if (!idReg.IsMatch(str)) { MessageBox.Show("格式应为:ABC123", "警告!"); return false; } Teacher mTeacher = new TeacherDB().selectTeacherById(str); if (mTeacher == null) { MessageBox.Show("教工号不存在!", "注意!"); return false; } } return true; }
private void button1_Click(object sender, EventArgs e) { flag = true;//初始化flag //判断教工号格式 if (!Util.checkInputTeacherId(textBox1.Text.ToString().Trim(), label7,2)) flag = false; //判断手机号码格式 Regex phoneReg = new Regex("1[3,5,7,8][0,2,3,6,5,7,8][0-9]{8}"); if (phoneReg.IsMatch(textBox5.Text.Trim())) { label8.Text = "通过!"; } else { label8.Text ="手机号输入有误!"; flag = false; } //判断姓名是否为空 if (Util.isEmpty(textBox2.Text)) { label9.Text = "不能为空!"; flag = false; } else { label9.Text = "通过!"; } //判断单位名称是否为空 if (Util.isEmpty(textBox3.Text)) { label10.Text = "不能为空!"; flag = false; } else { label10.Text = "通过!"; } //判断家庭住址是否为空 if (Util.isEmpty(textBox4.Text)) { label11.Text = "不能为空!"; flag = false; } else { label11.Text = "通过!"; } if (flag == true) { Teacher mTeacher = new Teacher(); mTeacher.Id = textBox1.Text.ToString().Trim(); mTeacher.Name = textBox2.Text.ToString().Trim(); if (radioButton1.Checked) mTeacher.Sex = "男"; else mTeacher.Sex = "女"; mTeacher.Organization = textBox3.Text.ToString().Trim(); mTeacher.Address = textBox4.Text.ToString().Trim(); mTeacher.Phone = textBox5.Text.ToString().Trim(); TeacherDB mTeacherDB = new TeacherDB(); mTeacherDB.insert(mTeacher); MessageBox.Show("录入成功!"); TeacherSelect._getInstance().resetData(); SalarySelect._getInstance().resetData(); textBox1.Text = ""; textBox2.Text = ""; textBox3.Text = ""; textBox4.Text = ""; textBox5.Text = ""; radioButton1.Checked = true; label7.Text = ""; label8.Text = ""; label9.Text = ""; label10.Text = ""; label11.Text = ""; } }