using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; using System.Data.SqlClient; namespace LYFZ.Software.MainBusiness.TimeAndAttendance { public class frmTimeupdate : LYFZ.Software.UI.TimeAndAttendance.frmTimeupdate { LYFZ.BLL.BLL_ErpOrder ordbll = new BLL.BLL_ErpOrder(); LYFZ.BLL.BLL_Lonintimeset lonintimeset = new BLL.BLL_Lonintimeset(); LYFZ.Model.Model_lonintimeset lonintime = new Model.Model_lonintimeset(); public frmTimeupdate() { this.Load += frmTimeupdate_Load; this.btnClassCountAdd.Click += btnClassCountAdd_Click; this.btnClassCountUpdate.Click += btnClassCountUpdate_Click; this.btnClassCountDelete.Click += btnClassCountDelete_Click; this.dgvData.Click += dgvData_Click; } int CurrentRowIndex = 0; /// /// 程序第一次运行 /// /// /// private void frmTimeupdate_Load(object sender, EventArgs e) { this.dgvData.Rows.Clear(); DataTable dt = ordbll.GetView_Custom("lonintimeset", StrWhere: "", ShowColumnName: "ID,name as 工作安排,time1 as 上班时间,time2 as 下班时间,time3 as 上班时间2,time4 as 下班时间2").Tables[0]; this.dgvData.DataSource(dt, strHideField: "ID"); this.dgvData.ClearSelection(); this.GetClear(); } /// /// 添加数据、修改数据 /// /// /// private void btnClassCountAdd_Click(object sender, EventArgs e) { string StrClassName = this.txtClassName.Text.Trim(); string StrFirstTimeStart = ""; string StrFirstTimeEnd = ""; string StrSecondTimeStart = ""; string StrSecondTimeEnd = ""; if (string.IsNullOrEmpty(StrClassName)) { MessageBoxCustom.Show("班次名称不能为空!"); return; } else if (StrClassName.Trim()=="休息") { MessageBoxCustom.Show("班次名称'休息'为系统默认名称,不能取名与系统默认名称重复!"); return; } if (this.mskFirstTimeStart.Text.Trim() != ":") { try { DateTime ssa = Convert.ToDateTime(SDateTime.Now.ToString("yyyy-MM-dd") + " " + this.mskFirstTimeStart.Text.Trim()); } catch { MessageBoxCustom.Show("第一班段的上班时间不是有效时间格式"); this.mskFirstTimeStart.Text = ""; return; } StrFirstTimeStart = this.mskFirstTimeStart.Text.Trim(); } if (this.mskFirstTimeEnd.Text.Trim() != ":") { try { DateTime ssa = Convert.ToDateTime(SDateTime.Now.ToString("yyyy-MM-dd") + " " + this.mskFirstTimeEnd.Text.Trim()); } catch { MessageBoxCustom.Show("第一班段的下班时间不是有效时间格式"); this.mskFirstTimeEnd.Text = ""; return; } StrFirstTimeEnd = this.mskFirstTimeEnd.Text.Trim(); } if (this.mskSecondTimeStart.Text.Trim() != ":") { try { DateTime ssa = Convert.ToDateTime(SDateTime.Now.ToString("yyyy-MM-dd") + " " + this.mskSecondTimeStart.Text.Trim()); } catch { MessageBoxCustom.Show("第二班段的上班时间不是有效时间格式"); this.mskSecondTimeStart.Text = ""; return; } StrSecondTimeStart = this.mskSecondTimeStart.Text.Trim(); } if (this.mskSecondTimeEnd.Text.Trim() != ":") { try { DateTime ssa = Convert.ToDateTime(SDateTime.Now.ToString("yyyy-MM-dd") + " " + this.mskSecondTimeEnd.Text.Trim()); } catch { MessageBoxCustom.Show("第二班段的下班时间不是有效时间格式"); this.mskSecondTimeEnd.Text = ""; return; } StrSecondTimeEnd = this.mskSecondTimeEnd.Text.Trim(); } if (string.IsNullOrEmpty(StrFirstTimeStart) && string.IsNullOrEmpty(StrFirstTimeEnd)) { MessageBoxCustom.Show("第一班段上下班时间不能为空!"); return; } else if (string.IsNullOrEmpty(StrFirstTimeStart) && !string.IsNullOrEmpty(StrFirstTimeEnd)) { MessageBoxCustom.Show("第一班段上班时间不能为空!"); return; } else if (!string.IsNullOrEmpty(StrFirstTimeStart) && string.IsNullOrEmpty(StrFirstTimeEnd)) { MessageBoxCustom.Show("第一班段下班时间不能为空!"); return; } else if (Convert.ToDateTime(SDateTime.Now.ToString("yyyy-MM-dd") + " " + StrFirstTimeStart + ":00") >= Convert.ToDateTime(SDateTime.Now.ToString("yyyy-MM-dd") + " " + StrFirstTimeEnd + ":00")) { MessageBoxCustom.Show("第一班段的下班时间不能早于上班时间"); return; } if (string.IsNullOrEmpty(StrSecondTimeStart) && !string.IsNullOrEmpty(StrSecondTimeEnd)) { MessageBoxCustom.Show("第二班段不能只填上班班时间!"); return; } else if (!string.IsNullOrEmpty(StrSecondTimeStart) && string.IsNullOrEmpty(StrSecondTimeEnd)) { MessageBoxCustom.Show("第二班段不能只填下班时间!"); return; } else if (!string.IsNullOrEmpty(StrSecondTimeStart) && !string.IsNullOrEmpty(StrSecondTimeEnd)) { if (Convert.ToDateTime(SDateTime.Now.ToString("yyyy-MM-dd") + " " + StrSecondTimeStart + ":00") >= Convert.ToDateTime(SDateTime.Now.ToString("yyyy-MM-dd") + " " + StrSecondTimeEnd + ":00")) { MessageBoxCustom.Show("第二班段的下班时间不能早于上班时间"); return; } if (Convert.ToDateTime(SDateTime.Now.ToString("yyyy-MM-dd") + " " + StrSecondTimeStart + ":00") <= Convert.ToDateTime(SDateTime.Now.ToString("yyyy-MM-dd") + " " + StrFirstTimeEnd + ":00")) { MessageBoxCustom.Show("第二班段的上班时间不能早于第一班段的下班时间!"); return; } } if (!string.IsNullOrEmpty(StrFirstTimeStart) && !string.IsNullOrEmpty(StrFirstTimeEnd)) { if (this.CurrentRowIndex > 0) { DataTable dt = ordbll.GetView_Custom("lonintimeset", StrWhere: "ID != '" + this.CurrentRowIndex + "' And name = '" + StrClassName + "'", ShowColumnName: "*").Tables[0]; if (dt.Rows.Count > 0) { MessageBoxCustom.Show("班次名称已存在,不能重复添加班次!"); return; } dt = ordbll.GetView_Custom("lonintimeset", StrWhere: "ID = '" + this.CurrentRowIndex + "'", ShowColumnName: "*").Tables[0]; LYFZ.Model.Model_lonintimeset model = lonintimeset.DataRowToModel(dt.Rows[0]); model.Name = StrClassName; model.Time1 = StrFirstTimeStart; model.Time2 = StrFirstTimeEnd; model.Time3 = StrSecondTimeStart; model.Time4 = StrSecondTimeEnd; if (MessageBoxCustom.Show("您确定要修改吗?", "温馨提示", System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) { if (lonintimeset.Update(model)) { MessageBoxCustom.Show("修改成功!"); this.frmTimeupdate_Load(this, null); } else { MessageBoxCustom.Show("修改失败!"); } } } else { if (!lonintimeset.Exists("name", StrClassName)) { LYFZ.Model.Model_lonintimeset model = new Model.Model_lonintimeset(); model.Name = StrClassName; model.Time1 = StrFirstTimeStart; model.Time2 = StrFirstTimeEnd; model.Time3 = StrSecondTimeStart; model.Time4 = StrSecondTimeEnd; if (MessageBoxCustom.Show("您确定要添加吗?", "温馨提示", System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) { if (lonintimeset.Add(model)) { MessageBoxCustom.Show("添加成功!"); this.frmTimeupdate_Load(this, null); } else { MessageBoxCustom.Show("添加失败!"); } } } else { MessageBoxCustom.Show("班次名称已存在,不能重复添加班次!"); } } } else { MessageBoxCustom.Show("数据不满足条件,数据添加失败!"); } } /// /// 新建 /// /// /// private void btnClassCountUpdate_Click(object sender, EventArgs e) { this.GetClear(); } /// /// 删除数据 /// /// /// private void btnClassCountDelete_Click(object sender, EventArgs e) { if (this.CurrentRowIndex > 0) { if (MessageBoxCustom.Show("您确定要删除吗?", "温馨提示", System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) { if (lonintimeset.Delete(this.CurrentRowIndex)) { MessageBoxCustom.Show("删除成功!"); this.frmTimeupdate_Load(this, null); } else { MessageBoxCustom.Show("删除失败!"); } } } else { MessageBoxCustom.Show("没选中数据,数据删除失败!"); } } /// /// 点击获取数据 /// /// /// private void dgvData_Click(object sender, EventArgs e) { if (this.dgvData.CurrentCell.ColumnIndex >= 0 && this.dgvData.CurrentCell.RowIndex >= 0) { this.CurrentRowIndex = Convert.ToInt32(this.dgvData.CurrentRow.Cells["ID"].Value); ; this.txtClassName.Text = this.dgvData.CurrentRow.Cells["工作安排"].Value.ToString().Trim(); this.mskFirstTimeStart.Text = this.dgvData.CurrentRow.Cells["上班时间"].Value.ToString().Trim(); this.mskFirstTimeEnd.Text = this.dgvData.CurrentRow.Cells["下班时间"].Value.ToString().Trim(); this.mskSecondTimeStart.Text = this.dgvData.CurrentRow.Cells["上班时间2"].Value.ToString().Trim(); this.mskSecondTimeEnd.Text = this.dgvData.CurrentRow.Cells["下班时间2"].Value.ToString().Trim(); this.btnClassCountAdd.Text = " 修改班次"; this.btnClassCountDelete.Enabled = true; } } /// /// 清除值 /// void GetClear() { this.CurrentRowIndex = 0; this.txtClassName.Text = ""; this.mskFirstTimeStart.Text = ""; this.mskSecondTimeStart.Text = ""; this.mskFirstTimeEnd.Text = ""; this.mskSecondTimeEnd.Text = ""; this.btnClassCountAdd.Text = " 添加班次"; this.btnClassCountDelete.Enabled = false; } } }