private void alterbtn_Click(object sender, EventArgs e) { //密码不为空 if (this.pwd.Text == "") { this.pwdtext.ForeColor = Color.Red; this.pwdtext.Text = "请设置密码!"; this.pwd.Focus(); } else { this.pwdtext.ForeColor = Color.Green; this.pwdtext.Text = "OK"; } //须二次输入密码 if (this.againpwd.Text == "") { this.apwdtext.ForeColor = Color.Red; this.apwdtext.Text = "请再次输入密码!"; this.againpwd.Focus(); } else { //两次密码须一致 if (this.pwd.Text == this.againpwd.Text) { this.apwdtext.ForeColor = Color.Green; this.apwdtext.Text = "OK"; String cmdText = "update employee set password=@pwd where eid=@eid"; SqlParameter pwdsprm = new SqlParameter("@pwd", pwd.Text.Trim()); SqlParameter eidsprm = new SqlParameter("@eid", strnum); SqlParameter[] sprms = new SqlParameter[] { pwdsprm, eidsprm }; int count = DBhelper.Add(cmdText, sprms); if (count > 0) { MessageBox.Show("修改成功!"); } else { MessageBox.Show("修改失败!"); } } else { this.apwdtext.ForeColor = Color.Red; this.apwdtext.Text = "两次密码不一致!!"; this.againpwd.Focus(); } } }
private void updatebtn_Click(object sender, EventArgs e) { int id = getEmpId(comboBox1.Text); String cmdText = "select id from employee where eid=@num"; SqlParameter numsprm = new SqlParameter("@num", num.Text.Trim()); SqlParameter[] sprms = new SqlParameter[] { numsprm }; SqlDataReader dr = DBhelper.GetDR(cmdText, sprms); dr.Read(); if (!dr.HasRows || (int)dr["id"] == id) { //进行更新数据库操作操作 String cmdText1 = "update employee set eid=@eid,ename=@name,eage=@age,etel=@tel,ecreatedate=@cd,did=@did where id=@id"; SqlParameter eidsprm = new SqlParameter("@eid", num.Text.Trim()); SqlParameter nasprm = new SqlParameter("@name", name.Text.Trim()); SqlParameter agesprm = new SqlParameter("@age", age.Text.Trim()); SqlParameter telsprm = new SqlParameter("@tel", tel.Text.Trim()); SqlParameter cdsprm = new SqlParameter("@cd", date.Value); SqlParameter idsprm = new SqlParameter("@id", id); //根据输入的部门名获取部门id int did = getDeptId(dept.Text); SqlParameter didsprm = new SqlParameter("@did", did); SqlParameter[] sprms1 = new SqlParameter[] { eidsprm, nasprm, agesprm, telsprm, cdsprm, didsprm, idsprm }; int count = DBhelper.Add(cmdText1, sprms1); if (count > 0) { MessageBox.Show("更新成功!"); //更新之前要clear一下,否则重复 comboBox1.Items.Clear(); //更新comboBox列表 setPersonName(); } else { MessageBox.Show("更新失败!"); } //更新修改后的员工名字 comboBox1.Text = name.Text; } else { MessageBox.Show("该员工工号已经存在" + "\n" + "请再次填写"); } }
private void addbtn_Click(object sender, EventArgs e) { System.DateTime currentTime = new System.DateTime(); currentTime = System.DateTime.Now; String strYMD = currentTime.ToLongDateString(); String cmdText = "insert into ad(cont,date) values(@con,@date)"; SqlParameter consprm = new SqlParameter("@con", richTextBox1.Text.Trim()); SqlParameter datesprm = new SqlParameter("@date", strYMD); SqlParameter[] sprm = new SqlParameter[] { consprm, datesprm }; int count = DBhelper.Add(cmdText, sprm); if (count > 0) { MessageBox.Show("添加成功"); } else { MessageBox.Show("添加失败"); } }
private void btn_Click(object sender, EventArgs e) { int day = getDate(); if (day == 1) { } else { //超过9点,视为迟到 if (strH < 9) { flag = 1; } else { flag = 0; } String name = getPersonName(); String cmdText = "insert into sign(eid,sflag,sdate,stime) values(@eid,@sflag,@sdate,@stime)"; SqlParameter eidsprm = new SqlParameter("@eid", numStr); SqlParameter sflagsprm = new SqlParameter("@sflag", flag); SqlParameter sdatesprm = new SqlParameter("@sdate", strYMD); SqlParameter stimesprm = new SqlParameter("@stime", strT); SqlParameter[] sprms = new SqlParameter[] { eidsprm, sflagsprm, sdatesprm, stimesprm }; int count = DBhelper.Add(cmdText, sprms); if (count > 0) { MessageBox.Show(name + "签到成功!!"); btn.Text = "已签到"; btn.Enabled = false; } else { MessageBox.Show("签到失败!"); } } }
private void registerbtn_Click(object sender, EventArgs e) { //帐号不为空 if (this.num.Text == "") { this.numtext.ForeColor = Color.Red; this.numtext.Text = "请输入你的员工号!"; this.num.Focus(); } else { //账号不能在数据库中已存在 String cmdText = "select count(*) from employee where eid=@num"; SqlParameter numsprm = new SqlParameter("@num", num.Text.Trim()); SqlParameter[] sprm = new SqlParameter[] { numsprm }; int count = DBhelper.GetCountPrm(cmdText, sprm); if (count >= 1) { this.numtext.ForeColor = Color.Red; this.numtext.Text = "帐号已经注册过了了!!"; } else { this.numtext.ForeColor = Color.Green; this.numtext.Text = "OK"; flag1 = 1; } } //密码不为空 if (this.pwd.Text == "") { this.pwdtext.ForeColor = Color.Red; this.pwdtext.Text = "请设置密码!"; this.pwd.Focus(); } else { this.pwdtext.ForeColor = Color.Green; this.pwdtext.Text = "OK"; } //须二次输入密码 if (this.againpwd.Text == "") { this.apwdtext.ForeColor = Color.Red; this.apwdtext.Text = "请再次输入密码!"; this.againpwd.Focus(); } else { //两次密码须一致 if (this.pwd.Text == this.againpwd.Text) { this.apwdtext.ForeColor = Color.Green; this.apwdtext.Text = "OK"; flag2 = 1; } else { this.apwdtext.ForeColor = Color.Red; this.apwdtext.Text = "两次密码不一致!!"; this.againpwd.Focus(); } } //须填写真实姓名 if (this.name.Text == "") { this.nametext.ForeColor = Color.Red; this.nametext.Text = "请输入你的真实姓名!"; this.name.Focus(); } else { this.nametext.ForeColor = Color.Green; this.nametext.Text = "OK"; } //字符串转为小写,进行比较判断 if (yzc.Check.ToLower() == this.check.Text.ToLower()) { //验证码正确,输入框变绿 this.checktext.ForeColor = Color.Green; this.checktext.Text = "验证码输入正确!"; flag = 1; } else { //验证码错误,有红色字体提示 this.checktext.ForeColor = Color.Red; this.checktext.Text = "验证码输入错误!"; this.check.Focus(); flag = 0; } if (flag == 1 && flag1 == 1 && flag2 == 1 && this.name.Text != "") { //验证通过,数据插入数据库中 String cmdText = "insert into employee(eid,password,ename) values(@num,@pwd,@name)"; SqlParameter numsprm = new SqlParameter("@num", num.Text); SqlParameter pwdsprm = new SqlParameter("@pwd", pwd.Text); SqlParameter namesprm = new SqlParameter("@name", name.Text); SqlParameter[] sprms = new SqlParameter[] { numsprm, pwdsprm, namesprm }; int count = DBhelper.Add(cmdText, sprms); if (count > 0) { MessageBox.Show(num.Text.Trim() + "注册成功!!"); Main m = new Main(); m.Show(); } else { MessageBox.Show("注册失败!"); } } }
private void alterbtn_Click(object sender, EventArgs e) { //点击按钮编辑信息 if (this.alterbtn.Text == "编辑资料") { num.ReadOnly = false; name.ReadOnly = false; age.Enabled = true; tel.ReadOnly = false; createdate.Enabled = true; dept.Enabled = true; lookbtn.Enabled = true; this.alterbtn.Text = "保存资料"; } //点击按钮保存信息 else if (this.alterbtn.Text == "保存资料") { num.ReadOnly = true; name.ReadOnly = true; age.Enabled = false; tel.ReadOnly = false; createdate.Enabled = false; dept.Enabled = false; lookbtn.Enabled = false; MessageBox.Show("save"); this.alterbtn.Text = "编辑资料"; //查询修改后的部门id int deid = getDeptId(dept.Text.Trim()); //要保证员工号的唯一性, //两种情况,第一种员工号未修改的情况,保证查找id是对应原来的id //第二种员工号修改了,保证查找的id是不存在 String cmdText = "select id from employee where eid=@num"; SqlParameter numsprm = new SqlParameter("@num", num.Text.Trim()); SqlParameter[] sprms = new SqlParameter[] { numsprm }; SqlDataReader dr = DBhelper.GetDR(cmdText, sprms); dr.Read(); if (!dr.HasRows || (int)dr["id"] == id) { this.numtext.ForeColor = Color.Green; this.numtext.Text = "OK"; //进行更新操作 MessageBox.Show("更新中。。。。"); byte[] byteImage; if (strImage == null) { byteImage = imgname; } else { FileStream FStream = new FileStream(strImage, FileMode.Open, FileAccess.Read); BinaryReader BReader = new BinaryReader(FStream); byteImage = BReader.ReadBytes((int)FStream.Length); } String cmdText1 = "update employee set eid=@eid,ename=@name,eage=@age,etel=@tel,ecreatedate=@cd,did=@did,img=@img where id=@id"; SqlParameter imgsprm = new SqlParameter("@img", byteImage); SqlParameter eidsprm = new SqlParameter("@eid", num.Text.Trim()); SqlParameter nasprm = new SqlParameter("@name", name.Text.Trim()); SqlParameter agesprm = new SqlParameter("@age", age.Text.Trim()); SqlParameter telsprm = new SqlParameter("@tel", tel.Text.Trim()); SqlParameter cdsprm = new SqlParameter("@cd", createdate.Value); SqlParameter idsprm = new SqlParameter("@id", id); SqlParameter didsprm = new SqlParameter("@did", deid); SqlParameter[] sprms1 = new SqlParameter[] { eidsprm, nasprm, agesprm, telsprm, cdsprm, didsprm, imgsprm, idsprm }; int count = DBhelper.Add(cmdText1, sprms1); if (count > 0) { MessageBox.Show("更新成功!"); } else { MessageBox.Show("更新失败!"); } } else { this.numtext.ForeColor = Color.Red; this.numtext.Text = "已存在"; MessageBox.Show("该工号属于他人,请检查是否填错"); } dr.Close(); } else { } }