//获取员工人数 public int getPersonCount() { String cmdText = "select count(*) from employee"; SqlParameter[] sprms = new SqlParameter[] {}; int count = DBhelper.GetCountPrm(cmdText, sprms); if (count < 0) { count = 0; } return(count); }
//获取每个时间公告的条数 public int getDateCountAD(String date) { String cmdText = "select count(*) from ad where date=@d"; SqlParameter dsprm = new SqlParameter("@d", date); SqlParameter[] sprms = new SqlParameter[] { dsprm }; int count = DBhelper.GetCountPrm(cmdText, sprms); if (count < 0) { count = 0; } return(count); }
String deptel; //记录部门电话 //获取每个部门的人数 public int getDeptCountPerson(int depid) { String cmdText = "select count(*) from employee where did=@id"; SqlParameter idsprm = new SqlParameter("@id", depid); SqlParameter[] sprms = new SqlParameter[] { idsprm }; int count = DBhelper.GetCountPrm(cmdText, sprms); if (count < 0) { count = 0; } return(count); }
//获取该月正常签到或迟到的次数 public int getCount(String f) { String cmdText = "select count(*) from sign where eid=@id and sflag=@flag"; SqlParameter idsprm = new SqlParameter("@id", numStr); SqlParameter fsprm = new SqlParameter("@flag", f); SqlParameter[] sprms = new SqlParameter[] { idsprm, fsprm }; int count = DBhelper.GetCountPrm(cmdText, sprms); if (count < 0) { count = 0; } return(count); }
//获取该天正常签到或迟到的次数 public int getCount(String str, String f) { String cmdText = "select count(*) from sign where sdate=@date and sflag=@flag"; SqlParameter dsprm = new SqlParameter("@date", str); SqlParameter fsprm = new SqlParameter("@flag", f); SqlParameter[] sprms = new SqlParameter[] { dsprm, fsprm }; int count = DBhelper.GetCountPrm(cmdText, sprms); if (count < 0) { count = 0; } return(count); }
//点击登录,进行验证码验证,和数据库数据验证 private void loginbtn_Click(object sender, EventArgs e) { int flag = 0; //字符串转为小写,进行比较判断 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 (this.number.Text == "" || this.paw.Text == "") { this.nptext.ForeColor = Color.Red; this.nptext.Text = "帐号或密码不能为空!!"; } else { this.nptext.Text = ""; //管理员登录 if (comboBox1.Text == "管理员") { this.nptext.ForeColor = Color.Green; this.nptext.Text = "管理员帐号正在登录中...."; if (this.number.Text == "admin") { if (this.paw.Text == "admin") { if (flag == 1) { MessageBox.Show("管理者,欢迎你的登录!!"); adminMain am = new adminMain(); am.Show(); } else { this.pwdtext.ForeColor = Color.Green; this.pwdtext.Text = "密码正确!!"; } } else { this.pwdtext.ForeColor = Color.Red; this.pwdtext.Text = "密码不正确!!"; } } else { this.nptext.ForeColor = Color.Red; this.nptext.Text = "管理员帐号不正确,应为admin"; } } //用户登录 else { this.nptext.ForeColor = Color.Green; this.nptext.Text = "用户帐号正在登录中...."; String cmdText = "select count(*) from employee where eid=@num"; SqlParameter numsprm = new SqlParameter("@num", number.Text.Trim()); SqlParameter[] sprm = new SqlParameter[] { numsprm }; int count = DBhelper.GetCountPrm(cmdText, sprm); if (count < 1) { this.nptext.ForeColor = Color.Red; this.nptext.Text = "帐号不存在!!"; } else { String cmdText1 = "select count(*) from employee where eid=@number and password=@pwd"; SqlParameter numsprm1 = new SqlParameter("@number", number.Text.Trim()); SqlParameter pwdsprm = new SqlParameter("@pwd", paw.Text.Trim()); SqlParameter[] sprm1 = new SqlParameter[] { numsprm1, pwdsprm }; int count1 = DBhelper.GetCountPrm(cmdText1, sprm1); if (count1 < 1) { this.pwdtext.ForeColor = Color.Red; this.pwdtext.Text = "密码不正确!!"; } else { this.pwdtext.ForeColor = Color.Green; this.pwdtext.Text = "密码正确!!"; if (flag == 1) { MessageBox.Show(number.Text.Trim() + "欢迎你的登录!!"); Constant.number = number.Text.Trim(); Main m = new Main(); m.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("注册失败!"); } } }