/// <summary> /// 添加时间段数据 /// </summary> /// <param name="objSfWorkTime">班次时段对象</param> /// <returns>返回执行结果</returns> public int AddTimes(SfWorkTime objSfWorkTime) { StringBuilder sqlBuilder = new StringBuilder(); sqlBuilder.Append("insert into SfWorkTime(TimesName,WorkTime,OffDutyTime,StartCheckIn,EndCheckIn,"); sqlBuilder.Append("StartSignBack,EndSignBack,LateTime,LeftEarly)"); sqlBuilder.Append(" values('{0}','{1}','{2}','{3}','{4}','{5}','{6}',{7},{8})"); string sql = string.Format(sqlBuilder.ToString(), objSfWorkTime.TimesName, objSfWorkTime.WorkTime, objSfWorkTime.OffDutyTime, objSfWorkTime.StartCheckIn, objSfWorkTime.EndCheckIn, objSfWorkTime.StartSignBack, objSfWorkTime.EndSignBack, objSfWorkTime.LateTime, objSfWorkTime.LeftEarly); try { return(SQLHelper.Update(sql)); } catch (SqlException ex) { throw new Exception("数据库操作出现异常!具体信息:" + ex.Message); } catch (Exception ex) { throw ex; } }
//添加时间段 private void btnAdd_Click(object sender, EventArgs e) { if (txtTimesName.Text.Trim() == "") { MessageBox.Show("时段名称不能为空!"); txtTimesName.Focus(); return; } if (txtLateTime.Text.Trim() == "") { MessageBox.Show("迟到分种数不能为空!"); txtLateTime.Focus(); return; } if (txtLeftEarly.Text.Trim() == "") { MessageBox.Show("早退分钟数不能为空!"); txtLeftEarly.Focus(); return; } //验证时段名称 if (objTimesService.IsTimesNameExisted(txtTimesName.Text.Trim())) { MessageBox.Show("时段名称重复"); txtTimesName.Focus(); //设置焦点 txtTimesName.SelectAll(); //选定文本 return; } else { SfWorkTime objTimes = new SfWorkTime() { TimesName = txtTimesName.Text.Trim(), WorkTime = dtpWorkTime.Text.Trim(), OffDutyTime = dtpOffDutyTime.Text.Trim(), StartCheckIn = dtpStartCheckIn.Text.Trim(), EndCheckIn = dtpEndCheckIn.Text.Trim(), StartSignBack = dtpStartSignBack.Text.Trim(), EndSignBack = dtpEndSignBack.Text.Trim(), LateTime = Convert.ToInt32(txtLateTime.Text.Trim()), LeftEarly = Convert.ToInt32(txtLeftEarly.Text.Trim()), }; //插入数据 objTimesService.AddTimes(objTimes); //刷新DGV DataTable dtTimesManage = objTimesService.GetTimesDataSet().Tables[0]; //获取TimesManage表 dtTimesManage.Columns.Remove("TimesId"); //移除TimesId列 dgvTimesManage.DataSource = dtTimesManage; //输出过滤后的数据 //清空数据 foreach (Control item in Controls) { if (item is TextBox) { item.Text = ""; } else if (item is ComboBox) { item.Text = ""; } } } }