using DevExpress.XtraEditors; using Gs.DevApp.Entity; using Gs.DevApp.ToolBox; using Gs.DevApp.UserControl; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Gs.DevApp.DevFrm.JJGZ { public partial class Frm_MesJjgzSchedule : DevExpress.XtraEditors.XtraForm { string _webServiceName = "MesJjgzSchedule/"; List _filterList = new List(); public Frm_MesJjgzSchedule() { InitializeComponent(); this.toolBarMenu1.btnAddClick += ToolBarMenu1_btnAddClick; this.toolBarMenu1.btnEdtClick += ToolBarMenu1_btnEdtClick; this.toolBarMenu1.btnSaveClick += ToolBarMenu1_btnSaveClick; this.toolBarMenu1.btnLoadClick += ToolBarMenu1_btnLoadClick; this.toolBarMenu1.btnDelClick += ToolBarMenu1_btnDelClick1; this.toolBarMenu1.btnEscClick += ToolBarMenu1_btnEscClick; this.toolBarMenu1.btnQueryClick += ToolBarMenu1_btnQueryClick; toolBarMenu1.btnChkClick += ToolBarMenu1_btnChkClick; toolBarMenu1.btnFChkClick += ToolBarMenu1_btnFChkClick; this.toolBarMenu1.getXmlConfig(); // 配置时间控件 ConfigureTimeControls(); Gs.DevApp.ToolBox.UtilityHelper.SetGridViewParameter(gridView1, picCheckBox, this, "checkStatus", "", (value) => { Gs.DevApp.ToolBox.UtilityHelper.JumpTab(xtraTabControl1, 0); }, tips); Gs.DevApp.ToolBox.UtilityHelper.SetTabParameter(gridView1, xtraTabControl1, pageBar1, (value) => { getModel(value); }, (value) => { getPageList(this.pageBar1.CurrentPage); }, lbGuid); getPageList(1); pageBar1.PagerEvent += PageBar1_PagerEvent; } /// /// 配置时间控件格式和默认值 /// private void ConfigureTimeControls() { var timeControls = new[] { txt_OnWorkTime1, txt_OffWorkTime1, txt_OnWorkTime2, txt_OffWorkTime2, txt_OnWorkTime3, txt_OffWorkTime3 }; foreach (var control in timeControls) { // 设置时间格式 control.Properties.Mask.EditMask = "HH:mm"; control.Properties.Mask.UseMaskAsDisplayFormat = true; control.Properties.DisplayFormat.FormatString = "HH:mm"; control.Properties.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime; // 设置默认值 if (control.EditValue == null) { control.EditValue = TimeSpan.Zero; } } // 设置默认的工作时间 txt_OnWorkTime1.EditValue = TimeSpan.Parse("08:00:00"); // 上午8点上班 txt_OffWorkTime1.EditValue = TimeSpan.Parse("12:00:00"); // 上午12点下班 txt_OnWorkTime2.EditValue = TimeSpan.Parse("13:00:00"); // 下午1点上班 txt_OffWorkTime2.EditValue = TimeSpan.Parse("17:00:00"); // 下午5点下班 } private async void GridView1_ColumnFilterChanged(object sender, EventArgs e) { _filterList = Gs.DevApp.ToolBox.UtilityHelper.GetDilter(gridView1.Columns, gridView1); await Task.Delay(100); getPageList(1); } /// /// 分页事件 /// /// /// private void PageBar1_PagerEvent(int curPage, int pageSize) { getPageList(curPage); } /// /// 查询事件 /// /// /// private void ToolBarMenu1_btnQueryClick(object sender, EventArgs e) { gridView1.ColumnFilterChanged -= GridView1_ColumnFilterChanged; gridView1.ActiveFilter.Clear(); gridView1.ColumnFilterChanged += GridView1_ColumnFilterChanged; var frm = new ShowFilter(gridView1.Columns, _filterList, this.GetType().FullName); frm.UpdateParent += Frm_UpdateParent; frm.ShowDialog(); } /// /// 查询回调 /// /// /// private void Frm_UpdateParent(object sender, UpdateParentEventArgs e) { _filterList = e.FilterList; getPageList(1); } /// /// 审核事件 /// /// /// private void ToolBarMenu1_btnChkClick(object sender, EventArgs e) { _toolCk(1); } /// /// 反审核 /// /// /// /// private void ToolBarMenu1_btnFChkClick(object sender, EventArgs e) { _toolCk(0); } /// /// 取消事件 /// /// /// private void ToolBarMenu1_btnEscClick(object sender, EventArgs e) { Gs.DevApp.ToolBox.UtilityHelper.JumpTab(xtraTabControl1, 1); } /// /// 删除事件 /// /// /// private void ToolBarMenu1_btnDelClick1(object sender, EventArgs e) { string rowGuid = "", rowName = ""; (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1, lbGuid, txt_Guid, gridView1, "scheNo"); if (string.IsNullOrEmpty(rowGuid)) { ToolBox.MsgHelper.Warning("请先选择你要操作的行!"); return; } if (!MsgHelper.AskQuestion("你选择了【" + rowName + "】,确定删除吗?")) return; List lst = new List(); lst.Add(rowGuid); var _obj = new { guid = rowGuid, mxGuid = Guid.Empty.ToString(), }; try { string strJson = UtilityHelper.HttpPost("", _webServiceName + "DeleteModel", JsonConvert.SerializeObject(_obj)); ReturnModel _rtn = ToolBox.UtilityHelper.ReturnToDynamic(strJson); if (_rtn.rtnCode > 0) { if (xtraTabControl1.SelectedTabPageIndex == 0) { } else Gs.DevApp.ToolBox.UtilityHelper.JumpTab(xtraTabControl1, 2); getPageList(this.pageBar1.CurrentPage); } ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg); } catch (Exception ex) { ToolBox.MsgHelper.Warning("提示:" + ex.Message); } } /// /// 刷新事件 /// /// /// private void ToolBarMenu1_btnLoadClick(object sender, EventArgs e) { if (xtraTabControl1.SelectedTabPageIndex == 1) getModel(lbGuid.Text.Trim()); else { getPageList(this.pageBar1.CurrentPage); } } /// /// 新增事件 /// /// /// private void ToolBarMenu1_btnAddClick(object sender, EventArgs e) { lbGuid.Text = ""; Gs.DevApp.ToolBox.UtilityHelper.JumpTab(xtraTabControl1, 4); UtilityHelper.CleanValueByControl(this.layoutMx1.Controls, true); } private void ToolBarMenu1_btnEdtClick(object sender, EventArgs e) { string rowGuid, rowName; (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1, lbGuid, txt_Guid, gridView1); if (string.IsNullOrEmpty(rowGuid)) { MsgHelper.Warning("请先选择你要操作的行!"); return; } Gs.DevApp.ToolBox.UtilityHelper.JumpTab(xtraTabControl1, 3); getModel(rowGuid); } /// /// 保存事件 /// /// /// private void ToolBarMenu1_btnSaveClick(object sender, EventArgs e) { toolBarMenu1.isSetBtn = false; // 基本必填项验证 if (string.IsNullOrWhiteSpace(txt_BeginTime.Text)) { Gs.DevApp.ToolBox.MsgHelper.Warning("请选择生效日期!"); txt_BeginTime.Focus(); return; } if (string.IsNullOrWhiteSpace(txt_EndTime.Text)) { Gs.DevApp.ToolBox.MsgHelper.Warning("请选择失效日期!"); txt_EndTime.Focus(); return; } // 日期逻辑验证 if (!ValidateDateRange()) { return; } if (string.IsNullOrWhiteSpace(txt_OnWorkTime1.Text)) { Gs.DevApp.ToolBox.MsgHelper.Warning("请输入上午上班时间!"); txt_OnWorkTime1.Focus(); return; } if (string.IsNullOrWhiteSpace(txt_OffWorkTime1.Text)) { Gs.DevApp.ToolBox.MsgHelper.Warning("请输入上午下班时间!"); txt_OffWorkTime1.Focus(); return; } // 时间逻辑验证 if (!ValidateTimeLogic()) { return; } try { var _obj = new { guid = UtilityHelper.ToGuid(lbGuid.Text.Trim()), //主建 scheNo = txt_ScheNo.Text.Trim(), //班次号(后台自动生成) onWorkTime1 = txt_OnWorkTime1.Text.Trim(), //上午上班时间 offWorkTime1 = txt_OffWorkTime1.Text.Trim(), //上午下班时间 onWorkTime2 = txt_OnWorkTime2.Text.Trim(), //下午上班时间 offWorkTime2 = txt_OffWorkTime2.Text.Trim(), //下午下班时间 onWorkTime3 = txt_OnWorkTime3.Text.Trim(), //加班上班时间 offWorkTime3 = txt_OffWorkTime3.Text.Trim(), //加班下班时间 beginTime = txt_BeginTime.Text.Trim(), //生效日期 endTime = txt_EndTime.Text.Trim(), //失效日期 remark = txt_Remark.Text.Trim() //备注 }; string strJson = UtilityHelper.HttpPost("", _webServiceName + "EditModel", JsonConvert.SerializeObject(_obj)); ReturnModel _rtn = ToolBox.UtilityHelper.ReturnToDynamic(strJson); ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg); if (_rtn.rtnCode > 0) { lbGuid.Text = _rtn.rtnData.outGuid; toolBarMenu1.isSetBtn = true; UtilityHelper.ChangeEnableByControl(this.layoutMx1.Controls, false); toolBarMenu1.currentAction = ""; Gs.DevApp.ToolBox.UtilityHelper.JumpTab(xtraTabControl1, 6); } } catch (Exception ex) { ToolBox.MsgHelper.Warning("提示:" + ex.Message); } } /// /// 验证日期范围 /// /// private bool ValidateDateRange() { try { DateTime beginTime = DateTime.Parse(txt_BeginTime.Text); DateTime endTime = DateTime.Parse(txt_EndTime.Text); if (endTime <= beginTime) { Gs.DevApp.ToolBox.MsgHelper.Warning("失效日期必须大于生效日期!"); txt_EndTime.Focus(); return false; } return true; } catch (Exception) { Gs.DevApp.ToolBox.MsgHelper.Warning("请输入正确的日期格式!"); return false; } } /// /// 验证时间逻辑 /// /// private bool ValidateTimeLogic() { // 验证上午时间段 if (!ValidateTimeSegment(txt_OnWorkTime1.Text, txt_OffWorkTime1.Text, "上午")) { return false; } // 如果填写了下午时间,验证下午时间段 if (!string.IsNullOrWhiteSpace(txt_OnWorkTime2.Text) || !string.IsNullOrWhiteSpace(txt_OffWorkTime2.Text)) { if (string.IsNullOrWhiteSpace(txt_OnWorkTime2.Text)) { Gs.DevApp.ToolBox.MsgHelper.Warning("请输入下午上班时间!"); txt_OnWorkTime2.Focus(); return false; } if (string.IsNullOrWhiteSpace(txt_OffWorkTime2.Text)) { Gs.DevApp.ToolBox.MsgHelper.Warning("请输入下午下班时间!"); txt_OffWorkTime2.Focus(); return false; } if (!ValidateTimeSegment(txt_OnWorkTime2.Text, txt_OffWorkTime2.Text, "下午")) { return false; } // 验证上午下班时间应早于下午上班时间 if (!ValidateTimeSequence(txt_OffWorkTime1.Text, txt_OnWorkTime2.Text, "上午下班时间", "下午上班时间")) { return false; } } // 如果填写了加班时间,验证加班时间段 if (!string.IsNullOrWhiteSpace(txt_OnWorkTime3.Text) || !string.IsNullOrWhiteSpace(txt_OffWorkTime3.Text)) { if (string.IsNullOrWhiteSpace(txt_OnWorkTime3.Text)) { Gs.DevApp.ToolBox.MsgHelper.Warning("请输入加班上班时间!"); txt_OnWorkTime3.Focus(); return false; } if (string.IsNullOrWhiteSpace(txt_OffWorkTime3.Text)) { Gs.DevApp.ToolBox.MsgHelper.Warning("请输入加班下班时间!"); txt_OffWorkTime3.Focus(); return false; } if (!ValidateTimeSegment(txt_OnWorkTime3.Text, txt_OffWorkTime3.Text, "加班")) { return false; } // 如果有下午时间,验证下午下班时间应早于加班上班时间 if (!string.IsNullOrWhiteSpace(txt_OffWorkTime2.Text)) { if (!ValidateTimeSequence(txt_OffWorkTime2.Text, txt_OnWorkTime3.Text, "下午下班时间", "加班上班时间")) { return false; } } else { // 如果没有下午时间,验证上午下班时间应早于加班上班时间 if (!ValidateTimeSequence(txt_OffWorkTime1.Text, txt_OnWorkTime3.Text, "上午下班时间", "加班上班时间")) { return false; } } } return true; } /// /// 验证单个时间段 /// /// 开始时间 /// 结束时间 /// 时间段名称 /// private bool ValidateTimeSegment(string startTime, string endTime, string periodName) { try { TimeSpan start = TimeSpan.Parse(startTime); TimeSpan end = TimeSpan.Parse(endTime); if (end <= start) { Gs.DevApp.ToolBox.MsgHelper.Warning($"{periodName}下班时间必须晚于上班时间!"); return false; } return true; } catch (Exception) { Gs.DevApp.ToolBox.MsgHelper.Warning($"请输入正确的{periodName}时间格式!"); return false; } } /// /// 验证时间顺序 /// /// 第一个时间 /// 第二个时间 /// 第一个时间名称 /// 第二个时间名称 /// private bool ValidateTimeSequence(string time1, string time2, string time1Name, string time2Name) { try { TimeSpan t1 = TimeSpan.Parse(time1); TimeSpan t2 = TimeSpan.Parse(time2); if (t1 >= t2) { Gs.DevApp.ToolBox.MsgHelper.Warning($"{time1Name}必须早于{time2Name}!"); return false; } return true; } catch (Exception) { Gs.DevApp.ToolBox.MsgHelper.Warning("时间格式错误,请检查输入!"); return false; } } /// /// /// /// 第几页 /// 每页几条 private void getPageList(int curPage) { gcMain1.DataSource = null; var _sbSqlWhere = UtilityHelper.GetSearchWhere(_filterList); var pgq = new PageQueryModel(curPage, this.pageBar1.RowsCount, "", "", "", _sbSqlWhere.ToString()); var json = JsonConvert.SerializeObject(pgq); try { var strReturn = UtilityHelper.HttpPost("", _webServiceName + "GetListPage", json); var dd = UtilityHelper.ReturnToTablePage(strReturn); if (dd.rtnCode > 0) { DataTable dt = dd.rtnData.list; gcMain1.BindingContext = new BindingContext(); gridView1.ColumnFilterChanged -= GridView1_ColumnFilterChanged; if (dt.Rows.Count > 0) { gcMain1.DataSource = dt; gcMain1.ForceInitialize(); gridView1.BestFitColumns(); Gs.DevApp.ToolBox.UtilityHelper.SetGridLayout(gridView1); } else UtilityHelper.SetDefaultTable(gcMain1, gridView1); gridView1.ColumnFilterChanged += GridView1_ColumnFilterChanged; pageBar1.TotalPages = dd.rtnData.pages;//总页 pageBar1.CurrentPage = curPage;//当前页 pageBar1.RecordCount = dd.rtnData.total;//总记录数 } else { ToolBox.MsgHelper.ShowError("提示:" + dd.rtnMsg); } } catch (Exception ex) { MsgHelper.ShowError("提示:" + ex.Message); } } /// /// /// /// 主键 /// 是否可编辑 /// 选项卡序号 private void getModel(string strGuid) { bool isEdit = false; if (toolBarMenu1.currentAction == "add") return; if (toolBarMenu1.currentAction == "edit") isEdit = true; if (string.IsNullOrEmpty(strGuid)) { ToolBox.MsgHelper.Warning("请先选择你要操作的行!"); return; } var _obj = new { guid = strGuid,//主建 }; try { string strJson = UtilityHelper.HttpPost("", _webServiceName + "GetModel", JsonConvert.SerializeObject(_obj)); ReturnModel _rtn = ToolBox.UtilityHelper.ReturnToDynamic(strJson); if (_rtn.rtnCode > 0) { dynamic dy = _rtn.rtnData; lbGuid.Text = strGuid; UtilityHelper.SetValueByObj(this.layoutMx1.Controls, dy, isEdit); } else ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg); } catch (Exception ex) { ToolBox.MsgHelper.Warning("提示:" + ex.Message); } } /// /// 工具条事件 /// /// private void _toolCk(int _inFieldValue) { string strMsg = ""; switch (_inFieldValue) { case 1: strMsg = "审核"; break; case 0: strMsg = "反审核"; break; } ; toolBarMenu1.guidKey = ""; string rowGuid, rowName; (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1, lbGuid, txt_Guid, gridView1, "scheNo"); if (string.IsNullOrEmpty(rowGuid)) { MsgHelper.Warning("请先选择你要操作的行!"); return; } if (!MsgHelper.AskQuestion("你选择了【" + rowName + "】,确定" + strMsg + "吗?")) return; var _obj = new { guid = rowGuid, ckValue = _inFieldValue, parameter = "MES_JJGZ_SCHEDULES,check_Date,check_Status,check_user" }; try { var strJson = UtilityHelper.HttpPost("", "General/GeneralCheck", JsonConvert.SerializeObject(_obj)); var _rtn = UtilityHelper.ReturnToDynamic(strJson); if (_rtn.rtnCode > 0) { MsgHelper.ShowInformation(_rtn.rtnData.outMsg.ToString()); if (xtraTabControl1.SelectedTabPageIndex == 1) { getModel(lbGuid.Text.Trim()); } int rowHandle = gridView1.LocateByValue(1, gridView1.Columns["guid"], rowGuid); gridView1.FocusedRowHandle = rowHandle; UtilityHelper.SetCheckIco(gridView1, "checkStatus", "checkBy", "checkDate", picCheckBox, this, _inFieldValue.ToString()); } else MsgHelper.ShowError(_rtn.rtnData.outMsg.ToString()); } catch (Exception ex) { MsgHelper.ShowError("提示:" + ex.Message); } } } }