/// <summary> /// 校验考勤数据 /// </summary> /// <param name="objKaoQin"></param> /// <returns></returns> public string CheckKaoQin(KaoQin objKaoQin) { StringBuilder err = new StringBuilder(); if (objKaoQin.出差 > objKaoQin.实际出勤) { err.Append($"人员编号【{objKaoQin.人员编号}】,姓名【{objKaoQin.姓名}】出差天数不应大于实际出勤天数!\r\n"); } if (objKaoQin.打卡签到次数 > objKaoQin.实际出勤) { err.Append($"人员编号【{objKaoQin.人员编号}】,姓名【{objKaoQin.姓名}】打卡签到次数不应大于实际出勤天数!\r\n"); } if (objKaoQin.节假日加班 > 7) { err.Append($"人员编号【{objKaoQin.人员编号}】,姓名【{objKaoQin.姓名}】节假日加班不应大于7天!\r\n"); } if (objKaoQin.正常调休 > objKaoQin.休息日加班 + objKaoQin.节假日加班 + objKaoQin.工作日加班次数 / 2) { err.Append($"人员编号【{objKaoQin.人员编号}】,姓名【{objKaoQin.姓名}】正常调休天数不应大于加班天数!\r\n"); } if (objKaoQin.实际出勤 < objKaoQin.应出勤 + objKaoQin.休息日加班 + objKaoQin.节假日加班 + objKaoQin.休息日出差 - objKaoQin.旷工 - objKaoQin.年假 - objKaoQin.事假 - objKaoQin.病假 - objKaoQin.正常调休 - objKaoQin.产假 - objKaoQin.陪产假 - objKaoQin.婚假 - objKaoQin.丧假) { err.Append($"人员编号【{objKaoQin.人员编号}】,姓名【{objKaoQin.姓名}】实际出勤不能小于【应出勤】+【休息日加班】+【节假日加班】+【休息日出差】-【休假合计】!\r\n"); } return(err.ToString()); }
private void dgvKaoQin_CellClick(object sender, DataGridViewCellEventArgs e) { #region 点击表格中的一行时,把内容送到编辑区 string userid = this.dgvKaoQin.CurrentRow.Cells["人员编号"].Value.ToString(); KaoQin objKaoQin = objKaoQinService.GetKaoQinByUserId(Program.salaryDate.last_year_month, userid); this.txtBuMen.Text = objKaoQin.部门.ToString(); this.txtBanZu.Text = objKaoQin.班组.ToString(); this.txtHnbh.Text = objKaoQin.人员编号.ToString(); this.txtName.Text = objKaoQin.姓名.ToString(); this.txtYingChuQin.Text = objKaoQin.应出勤.ToString(); this.txtShiJiChuQin.Text = objKaoQin.实际出勤.ToString(); this.txtChuChai.Text = objKaoQin.出差.ToString(); this.txtKuangGong.Text = objKaoQin.旷工.ToString(); this.txtNianJia.Text = objKaoQin.年假.ToString(); this.txtShiJia.Text = objKaoQin.事假.ToString(); this.txtBingJia.Text = objKaoQin.病假.ToString(); this.txtZhengChangTiaoXiu.Text = objKaoQin.正常调休.ToString(); this.txtChanJia.Text = objKaoQin.产假.ToString(); this.txtPeiChanJia.Text = objKaoQin.陪产假.ToString(); this.txtHunJian.Text = objKaoQin.婚假.ToString(); this.txtSangJia.Text = objKaoQin.丧假.ToString(); this.txtChiDaoZaoTuiCiShu.Text = objKaoQin.迟到早退次数.ToString(); this.txtQueKaCiShu.Text = objKaoQin.缺卡次数.ToString(); this.txtGongZuoRiJiaBanCiShu.Text = objKaoQin.工作日加班次数.ToString(); this.txtXiuXiRiJiaBan.Text = objKaoQin.休息日加班.ToString(); this.txtJieJiaRiJiaBan.Text = objKaoQin.节假日加班.ToString(); this.txtXiuXiRiChuChai.Text = objKaoQin.休息日出差.ToString(); this.txtYeJianZhiBanCiShu.Text = objKaoQin.夜间值班次数.ToString(); this.txtYeJianZhiBanTiaoXiuCiShu.Text = objKaoQin.夜间值班调休次数.ToString(); this.txtDaKaQianDaoCiShu.Text = objKaoQin.打卡签到次数.ToString(); this.txtGongZuoShiChang.Text = objKaoQin.工作时长.ToString(); this.txtBeiZhu.Text = objKaoQin.备注.ToString(); #endregion }
/// <summary> /// 修改考勤对象 /// </summary> /// <param name="objKaoQin"></param> /// <returns></returns> public int ModifyKaoQin(KaoQin objKaoQin) { //1、编写SQL语句 StringBuilder sqlBuilder = new StringBuilder(); sqlBuilder.Append("update imp_attendance set 应出勤 = {0},实际出勤 = {1},出差 = {2},旷工 = {3},年假 = {4},事假 = {5},病假 = {6},正常调休 = {7},产假 = {8},陪产假 = {9},婚假 = {10},丧假 = {11},迟到早退次数 = {12},缺卡次数 = {13},工作日加班次数 = {14},休息日加班 = {15},节假日加班 = {16},休息日出差 = {17},夜间值班次数 = {18},夜间值班调休次数 = {19},打卡签到次数 = {20},工作时长 = {21},备注 = '{22}',更改者 = '{23}',更改日期 = '{24}',IsSubmit = '{25}'"); sqlBuilder.Append(" where 考勤年月 = '{26}' and 人员编号 = '{27}'"); //2、解析对象 string sql = string.Format(sqlBuilder.ToString(), objKaoQin.应出勤, objKaoQin.实际出勤, objKaoQin.出差, objKaoQin.旷工, objKaoQin.年假, objKaoQin.事假, objKaoQin.病假, objKaoQin.正常调休, objKaoQin.产假, objKaoQin.陪产假, objKaoQin.婚假, objKaoQin.丧假, objKaoQin.迟到早退次数, objKaoQin.缺卡次数, objKaoQin.工作日加班次数, objKaoQin.休息日加班, objKaoQin.节假日加班, objKaoQin.休息日出差, objKaoQin.夜间值班次数, objKaoQin.夜间值班调休次数, objKaoQin.打卡签到次数, objKaoQin.工作时长, objKaoQin.备注, objKaoQin.更改者, objKaoQin.更改日期, objKaoQin.IsSubmit, objKaoQin.考勤年月, objKaoQin.人员编号); //3、执行SQL语句,返回结果 return(SQLHelper.Update(sql)); }
/// <summary> /// 增加考勤对象 /// </summary> /// <param name="objKaoQin"></param> /// <returns></returns> public int InsertKaoQin(KaoQin objKaoQin) { //1、编写SQL语句 StringBuilder sqlBuilder = new StringBuilder(); sqlBuilder.Append("insert into imp_attendance (考勤年月,部门,班组,人员编号,姓名,应出勤,实际出勤,出差,旷工,年假,事假,病假,正常调休,产假,陪产假,婚假,丧假,迟到早退次数,缺卡次数,工作日加班次数,休息日加班,节假日加班,休息日出差,夜间值班次数,夜间值班调休次数,打卡签到次数,工作时长,备注,更改者,更改日期,IsSubmit,排序)"); sqlBuilder.Append(" values ('{0}','{1}','{2}','{3}','{4}',{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15},{16},{17},{18},{19},{20},{21},{22},{23},{24},{25},{26},'{27}','{28}','{29}','{30}',{31})"); //2、解析对象 string sql = string.Format(sqlBuilder.ToString(), objKaoQin.考勤年月, objKaoQin.部门, objKaoQin.班组, objKaoQin.人员编号, objKaoQin.姓名, objKaoQin.应出勤, objKaoQin.实际出勤, objKaoQin.出差, objKaoQin.旷工, objKaoQin.年假, objKaoQin.事假, objKaoQin.病假, objKaoQin.正常调休, objKaoQin.产假, objKaoQin.陪产假, objKaoQin.婚假, objKaoQin.丧假, objKaoQin.迟到早退次数, objKaoQin.缺卡次数, objKaoQin.工作日加班次数, objKaoQin.休息日加班, objKaoQin.节假日加班, objKaoQin.休息日出差, objKaoQin.夜间值班次数, objKaoQin.夜间值班调休次数, objKaoQin.打卡签到次数, objKaoQin.工作时长, objKaoQin.备注, objKaoQin.更改者, objKaoQin.更改日期, objKaoQin.IsSubmit, objKaoQin.排序); //3、执行SQL语句,返回结果 return(SQLHelper.Update(sql)); }
/// <summary> /// 根据人员编号查询考勤对象 /// </summary> /// <param name="userid"></param> /// <returns></returns> public KaoQin GetKaoQinByUserId(string last_year_month, string userid) { string sql = "select id,考勤年月,部门,班组,人员编号,姓名,应出勤,实际出勤,出差,旷工,年假,事假,病假,正常调休,产假,陪产假,婚假,丧假,迟到早退次数,缺卡次数,工作日加班次数,休息日加班,节假日加班,休息日出差,夜间值班次数,夜间值班调休次数,打卡签到次数,工作时长,备注,更改者,更改日期,IsSubmit,排序 from imp_attendance where 考勤年月 = '{0}' and 人员编号 = '{1}'"; sql = string.Format(sql, last_year_month, userid); SqlDataReader objReader = SQLHelper.GetReader(sql); KaoQin objKaoQin = null; if (objReader.Read()) { objKaoQin = new KaoQin() { id = Convert.ToInt32(objReader["id"].ToString()), 考勤年月 = objReader["考勤年月"].ToString(), 部门 = objReader["部门"].ToString(), 班组 = objReader["班组"].ToString(), 人员编号 = objReader["人员编号"].ToString(), 姓名 = objReader["姓名"].ToString(), 应出勤 = Convert.ToDouble(objReader["应出勤"].ToString()), 实际出勤 = Convert.ToDouble(objReader["实际出勤"].ToString()), 出差 = Convert.ToDouble(objReader["出差"].ToString()), 旷工 = Convert.ToDouble(objReader["旷工"].ToString()), 年假 = Convert.ToDouble(objReader["年假"].ToString()), 事假 = Convert.ToDouble(objReader["事假"].ToString()), 病假 = Convert.ToDouble(objReader["病假"].ToString()), 正常调休 = Convert.ToDouble(objReader["正常调休"].ToString()), 产假 = Convert.ToDouble(objReader["产假"].ToString()), 陪产假 = Convert.ToDouble(objReader["陪产假"].ToString()), 婚假 = Convert.ToDouble(objReader["婚假"].ToString()), 丧假 = Convert.ToDouble(objReader["丧假"].ToString()), 迟到早退次数 = Convert.ToDouble(objReader["迟到早退次数"].ToString()), 缺卡次数 = Convert.ToDouble(objReader["缺卡次数"].ToString()), 工作日加班次数 = Convert.ToDouble(objReader["工作日加班次数"].ToString()), 休息日加班 = Convert.ToDouble(objReader["休息日加班"].ToString()), 节假日加班 = Convert.ToDouble(objReader["节假日加班"].ToString()), 休息日出差 = Convert.ToDouble(objReader["休息日出差"].ToString()), 夜间值班次数 = Convert.ToDouble(objReader["夜间值班次数"].ToString()), 夜间值班调休次数 = Convert.ToDouble(objReader["夜间值班调休次数"].ToString()), 打卡签到次数 = Convert.ToDouble(objReader["打卡签到次数"].ToString()), 工作时长 = Convert.ToDouble(objReader["工作时长"].ToString()), 备注 = objReader["备注"].ToString(), 更改者 = objReader["更改者"].ToString(), 更改日期 = Convert.ToDateTime(objReader["更改日期"].ToString()), IsSubmit = objReader["IsSubmit"] is DBNull ? false : (bool)objReader["IsSubmit"], 排序 = objReader["排序"] is DBNull ? 0 : Convert.ToInt32(objReader["排序"].ToString()), }; } objReader.Close(); return(objKaoQin); }
/// <summary> /// 封装对象 /// </summary> private KaoQin FengZhuangDuiXiang() { KaoQin objKaoQin = new KaoQin() { 考勤年月 = Program.salaryDate.last_year_month, 部门 = Program.currentAdmin.dept, 班组 = this.txtBanZu.Text.Trim(), 人员编号 = this.txtHnbh.Text.Trim(), 姓名 = this.txtName.Text.Trim(), 应出勤 = double.Parse(this.txtYingChuQin.Text), 实际出勤 = double.Parse(this.txtShiJiChuQin.Text), 出差 = double.Parse(this.txtChuChai.Text), 旷工 = double.Parse(this.txtKuangGong.Text), 年假 = double.Parse(this.txtNianJia.Text), 事假 = double.Parse(this.txtShiJia.Text), 病假 = double.Parse(this.txtBingJia.Text), 正常调休 = double.Parse(this.txtZhengChangTiaoXiu.Text), 产假 = double.Parse(this.txtChanJia.Text), 陪产假 = double.Parse(this.txtPeiChanJia.Text), 婚假 = double.Parse(this.txtHunJian.Text), 丧假 = double.Parse(this.txtSangJia.Text), 迟到早退次数 = double.Parse(this.txtChiDaoZaoTuiCiShu.Text), 缺卡次数 = double.Parse(this.txtQueKaCiShu.Text), 前夜班次数 = double.Parse(this.txtGongZuoRiJiaBanCiShu.Text), 休息日加班 = double.Parse(this.txtXiuXiRiJiaBan.Text), 节假日加班 = double.Parse(this.txtJieJiaRiJiaBan.Text), 休息日出差 = double.Parse(this.txtXiuXiRiChuChai.Text), 后夜班次数 = double.Parse(this.txtYeJianZhiBanCiShu.Text), 后夜班调休次数 = double.Parse(this.txtYeJianZhiBanTiaoXiuCiShu.Text), 打卡签到次数 = double.Parse(this.txtDaKaQianDaoCiShu.Text), 工作时长 = double.Parse(this.txtGongZuoShiChang.Text), 备注 = this.txtBeiZhu.Text.Trim(), 更改者 = Program.currentAdmin.username, 更改日期 = DateTime.Now, IsSubmit = true }; return(objKaoQin); }
private void btnSave_Click(object sender, EventArgs e) { #region 验证表单输入数据 #endregion #region 封装对象 KaoQin objKaoQin = FengZhuangDuiXiang(); #endregion #region 考勤表间数据校验 string err = objKaoQinService.CheckKaoQin(objKaoQin); if (err.Length > 0) { //((FrmMain)ParentForm).SetToolStripErr(err); //子窗口修改父窗口的控件,对应frmMain表单中的SetToolStripErr方法。 txterr.Text = err; MessageBox.Show("数据有误,请修改后重新提交!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } #endregion #region 修改对象 try { if (objKaoQinService.ModifyKaoQin(objKaoQin) == 1) { MessageBox.Show("修改成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); init_dgvKaoQin(); objControlService.init_GroupBox(gbKaoQin); txterr.Text = ""; } } catch (Exception ex) { MessageBox.Show(ex.Message); } #endregion }
private void btnSave_Click(object sender, EventArgs e) { #region 验证表单输入数据 if (this.txtYingChuQin.Text.Trim().Length == 0) { MessageBox.Show("请填入应出勤天数!", "提示"); return; } if (this.txtShiJiChuQin.Text.Trim().Length == 0) { MessageBox.Show("请填入实际出勤天数!", "提示"); return; } if (this.txtChuChai.Text.Trim().Length == 0) { MessageBox.Show("请填入出差天数!", "提示"); return; } if (this.txtKuangGong.Text.Trim().Length == 0) { MessageBox.Show("请填入旷工天数!", "提示"); return; } if (this.txtNianJia.Text.Trim().Length == 0) { MessageBox.Show("请填入年假天数!", "提示"); return; } if (this.txtShiJia.Text.Trim().Length == 0) { MessageBox.Show("请填入事假天数!", "提示"); return; } if (this.txtBingJia.Text.Trim().Length == 0) { MessageBox.Show("请填入病假天数!", "提示"); return; } if (this.txtZhengChangTiaoXiu.Text.Trim().Length == 0) { MessageBox.Show("请填入正常调休天数!", "提示"); return; } if (this.txtChanJia.Text.Trim().Length == 0) { MessageBox.Show("请填入产假天数!", "提示"); return; } if (this.txtPeiChanJia.Text.Trim().Length == 0) { MessageBox.Show("请填入陪产假天数!", "提示"); return; } if (this.txtHunJian.Text.Trim().Length == 0) { MessageBox.Show("请填入婚假天数!", "提示"); return; } if (this.txtSangJia.Text.Trim().Length == 0) { MessageBox.Show("请填入丧假天数!", "提示"); return; } if (this.txtChiDaoZaoTuiCiShu.Text.Trim().Length == 0) { MessageBox.Show("请填入迟到早退次数!", "提示"); return; } if (this.txtQueKaCiShu.Text.Trim().Length == 0) { MessageBox.Show("请填入缺卡次数!", "提示"); return; } if (this.txtGongZuoRiJiaBanCiShu.Text.Trim().Length == 0) { MessageBox.Show("请填入前夜班次数!", "提示"); return; } if (this.txtXiuXiRiChuChai.Text.Trim().Length == 0) { MessageBox.Show("请填入休息日加班天数!", "提示"); return; } if (this.txtJieJiaRiJiaBan.Text.Trim().Length == 0) { MessageBox.Show("请填入节假日加班天数!", "提示"); return; } if (this.txtXiuXiRiChuChai.Text.Trim().Length == 0) { MessageBox.Show("请填入休息日出差天数!", "提示"); return; } if (this.txtYeJianZhiBanCiShu.Text.Trim().Length == 0) { MessageBox.Show("请填入后夜班次数!", "提示"); return; } if (this.txtYeJianZhiBanTiaoXiuCiShu.Text.Trim().Length == 0) { MessageBox.Show("请填入后夜班调休次数!", "提示"); return; } if (this.txtDaKaQianDaoCiShu.Text.Trim().Length == 0) { MessageBox.Show("请填入打卡签到次数!", "提示"); return; } if (this.txtGongZuoShiChang.Text.Trim().Length == 0) { MessageBox.Show("请填入工作时长!", "提示"); return; } if (this.txtBeiZhu.Text.Trim().Length > 30) { MessageBox.Show("备注信息不能超过30个字符,请修改后重新提交!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); this.txtBeiZhu.Focus(); return; } #endregion #region 封装对象 KaoQin objKaoQin = FengZhuangDuiXiang(); #endregion #region 考勤表间数据校验 string err = objKaoQinService.CheckKaoQin(objKaoQin); if (err.Length > 0) { //((FrmMain)ParentForm).SetToolStripErr(err); //子窗口修改父窗口的控件,对应frmMain表单中的SetToolStripErr方法。 txterr.Text = err; MessageBox.Show("数据有误,请修改后重新提交!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } #endregion #region 修改对象 try { if (objKaoQinService.ModifyKaoQin(objKaoQin, Program.currentAdmin.dept) == 1) { MessageBox.Show("修改成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); init_dgvKaoQin(); init_gbKaoQin(); txterr.Text = ""; } } catch (Exception ex) { MessageBox.Show(ex.Message); } #endregion }