/// <summary> /// 删除每天的排班计划。根据月排班计划主键。调用该函数之前需要先设置<see cref="MKey"/>属性的值。 /// </summary> public void DeleteShiftOfSchedule() { DataSet dsReturn = new DataSet(); try { //远程调用的工厂对象。 IServerObjFactory serverFactory = CallRemotingService.GetRemoteObject(); //工厂对象创建成功。 if (null != serverFactory) { //调用远程函数,根据月排班计划主键。 dsReturn = serverFactory.CreateISchedule().DeleteShiftOfSchedule(MKey); //远程函数执行结果消息。 _errorMsg = FanHai.Hemera.Share.Common.ReturnMessageUtils.GetServerReturnMessage(dsReturn); } } catch (Exception ex) { _errorMsg = ex.Message; } finally { //关闭远程调用信道。 CallRemotingService.UnregisterChannel(); } }
/// <summary> /// 查询排班计划。根据排班计划名称查询。 /// </summary> /// <returns>查询得到的排班计划数据集。</returns> public DataSet SearchSchedule() { DataSet dsReturn = new DataSet(); try { //远程调用的工厂对象。 IServerObjFactory serverFactory = CallRemotingService.GetRemoteObject(); //工厂对象创建成功。 if (null != serverFactory) { //调用远程函数,通过排班计划名称进行搜索查询。 dsReturn = serverFactory.CreateISchedule().SearchSchedule(_scheduleName); //远程函数执行结果消息。 _errorMsg = FanHai.Hemera.Share.Common.ReturnMessageUtils.GetServerReturnMessage(dsReturn); } } catch (Exception ex) { _errorMsg = ex.Message; } finally { //关闭远程调用信道。 CallRemotingService.UnregisterChannel(); } return(dsReturn); }
/// <summary> /// 保存每天排班计划记录。 /// </summary> /// <param name="dataTable">数据表对象。</param> public void SaveShiftOfSchedule(DataTable dataTable) { DataSet dsReturn = new DataSet(); dsReturn.Tables.Add(dataTable); //每天排班计划集合不为空。 if (ScheduleDayList.Count > 0) { DataTable shiftDayTable = CAL_SCHEDULE_DAY.CreateDataTable(); //遍历每天排班计划集合中的记录。 foreach (ScheduleDay scheduleDay in ScheduleDayList) { Dictionary <string, string> rowData = new Dictionary <string, string>() { { CAL_SCHEDULE_DAY.FIELD_DKEY, scheduleDay.DKey }, { CAL_SCHEDULE_DAY.FIELD_STARTTIME, scheduleDay.StartTime }, { CAL_SCHEDULE_DAY.FIELD_ENDTIME, scheduleDay.EndTime }, { CAL_SCHEDULE_DAY.FIELD_SHIFT_VALUE, scheduleDay.ShiftValue }, { CAL_SCHEDULE_DAY.FIELD_SEQNO, scheduleDay.SeqNo }, { CAL_SCHEDULE_DAY.FIELD_SHIFT_KEY, scheduleDay.ShiftKey }, { CAL_SCHEDULE_DAY.FIELD_DAY, scheduleDay.Day } }; FanHai.Hemera.Utils.Common.Utils.AddRowDataToDataTable(ref shiftDayTable, rowData); } dsReturn.Tables.Add(shiftDayTable); } try { //远程调用的工厂对象。 IServerObjFactory serverFactory = CallRemotingService.GetRemoteObject(); //工厂对象创建成功。 if (null != serverFactory) { //调用远程函数 dsReturn = serverFactory.CreateISchedule().SaveShiftOfSchedule(dsReturn); //远程函数执行结果消息。 _errorMsg = FanHai.Hemera.Share.Common.ReturnMessageUtils.GetServerReturnMessage(dsReturn); if (_errorMsg == "")//保存每天排班计划数据成功。 { this.ResetDirtyList(); //遍历日排班计划集合。 foreach (ScheduleDay scheduleDay in ScheduleDayList) { scheduleDay.OperationAction = OperationAction.Update; scheduleDay.IsInitializeFinished = true; } } } } catch (Exception ex) { _errorMsg = ex.Message; } finally { //关闭远程调用信道。 CallRemotingService.UnregisterChannel(); } }
/// <summary> /// 插入排班计划记录到数据库表中。 /// </summary> /// <returns>是否插入成功,true:成功。false:失败。</returns> public override bool Insert() { DataSet dataSet = new DataSet(); //准备插入到数据库中的数据。 DataTable scheduleTable = CAL_SCHEDULE.CreateDataTable(); Dictionary <string, string> dataRow = new Dictionary <string, string>() { { CAL_SCHEDULE.FIELD_SCHEDULE_KEY, _scheduleKey }, { CAL_SCHEDULE.FIELD_SCHEDULE_NAME, _scheduleName }, { CAL_SCHEDULE.FIELD_DESCRIPTIONS, _descriptions }, { CAL_SCHEDULE.FIELD_MAXOVERLAPTIME, _overTime.ToString() }, { CAL_SCHEDULE.FIELD_CREATOR, Creator }, { CAL_SCHEDULE.FIELD_CREATE_TIMEZONE, CreateTimeZone }, { CAL_SCHEDULE.FIELD_EDITOR, Editor }, { CAL_SCHEDULE.FIELD_EDIT_TIMEZONE, EditTimeZone } }; FanHai.Hemera.Utils.Common.Utils.AddRowDataToDataTable(ref scheduleTable, dataRow); //为远程调用函数准备参数。 dataSet.Tables.Add(scheduleTable); try { DataSet dsReturn = null; //创建远程调用的工厂对象。 IServerObjFactory serverFactory = CallRemotingService.GetRemoteObject(); if (null != serverFactory) { //调用远程函数,新增一行排班计划记录。 dsReturn = serverFactory.CreateISchedule().AddSchedule(dataSet); //获取远程函数的执行结果。 _errorMsg = FanHai.Hemera.Share.Common.ReturnMessageUtils.GetServerReturnMessage(dsReturn); if (_errorMsg != "") {//执行不成功。 return(false); } else { //重置脏数据集合。 this.ResetDirtyList(); } } } catch (Exception ex) { _errorMsg = ex.Message; } finally { //注销远程调用信道。 CallRemotingService.UnregisterChannel(); } return(true); }
/// <summary> /// 通过年份和月份查询主键 /// </summary> /// <param name="year"></param> /// <param name="month"></param> private void GetValueOfSchedule(string year, string month) { string scheduleKey = ""; //远程调用 IServerObjFactory serverFactory = CallRemotingService.GetRemoteObject(); //通过年份和月份获取主键 scheduleKey = serverFactory.CreateISchedule().GetScheduleKey(year, month); if (scheduleKey != "") { //如果主键不为空 this.lueSchedule.Properties.ReadOnly = true; //控件可用 this.lueSchedule.EditValue = scheduleKey; //状态ctrlstate修改为edit状态 CtrlState = ControlState.Edit; } else { //如果主键为空 this.lueSchedule.Properties.ReadOnly = false; //控件不可用 this.lueSchedule.EditValue = null; //状态修改为new CtrlState = ControlState.New; } }
/// <summary> /// 生成排班计划单击事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> #region Query Button Click private void btnQuery_Click(object sender, EventArgs e) { DataSet dsShift = new DataSet(); _schedule = new Schedule(); string sYear = lueYear.Text; string sMonth = cbeMonth.Text; object schedule = lueSchedule.EditValue; #region CheckEmpty if (schedule != null) { _schedule.ScheduleKey = schedule.ToString(); } if (string.IsNullOrEmpty(sYear)) { //系统提示 请选择年份 MessageService.ShowMessage("${res:FanHai.Hemera.Addins.EMS.ShiftCtrl.Msg.SelectYear}", "${res:Global.SystemInfo}"); return; } if (string.IsNullOrEmpty(sMonth)) { //系统提示 请选择月份 MessageService.ShowMessage("${res:FanHai.Hemera.Addins.EMS.ShiftCtrl.Msg.SelectMonth}", "${res:Global.SystemInfo}"); return; } if (_schedule.ScheduleKey == string.Empty) { //系统提示 请选择计划 MessageService.ShowMessage("${res:FanHai.Hemera.Addins.EMS.ShiftCtrl.Msg.SelectSchedule}", "${res:Global.SystemInfo}"); return; } #endregion int year = Convert.ToInt32(sYear); int month = Convert.ToInt32(sMonth); #region Create Grid //清空数据表内容 ClearDataOfDataGrid(); _shiftDictionary.Clear(); int days = GetDays(Convert.ToInt32(year), Convert.ToInt32(month)); //根据排班主键获取排班计划 dsShift = _schedule.GetShift(); int index = 0; if (dsShift.Tables.Contains(CAL_SHIFT.DATABASE_TABLE_NAME)) { DataTable dataTable = dsShift.Tables[CAL_SHIFT.DATABASE_TABLE_NAME]; if (dataTable.Rows.Count > 0) { tsbSave.Enabled = true; #region Create Column GridColumn column = new GridColumn(); column.Name = "Date"; column.FieldName = "Date"; column.Caption = StringParser.Parse("${res:FanHai.Hemera.Addins.EMS.ShiftCtrl.ColumnDateName}"); //日期 column.Visible = true; column.OptionsColumn.AllowEdit = false; column.VisibleIndex = index++; shiftView.Columns.Add(column); for (int i = 0; i < dataTable.Rows.Count; i++) { #region Bind data to list Shift shift = new Shift(); shift.ShiftKey = dataTable.Rows[i][CAL_SHIFT.FIELD_SHIFT_KEY].ToString(); shift.ShiftName = dataTable.Rows[i][CAL_SHIFT.FIELD_SHIFT_NAME].ToString(); shift.StartTime = dataTable.Rows[i][CAL_SHIFT.FIELD_START_TIME].ToString(); shift.EndTime = dataTable.Rows[i][CAL_SHIFT.FIELD_END_TIME].ToString(); _shiftDictionary.Add(shift.ShiftKey, shift); #endregion column = new GridColumn(); column.Name = dataTable.Rows[i][CAL_SHIFT.FIELD_SHIFT_NAME].ToString(); column.FieldName = dataTable.Rows[i][CAL_SHIFT.FIELD_SHIFT_NAME].ToString(); column.Caption = dataTable.Rows[i][CAL_SHIFT.FIELD_SHIFT_NAME].ToString(); column.ColumnEdit = cbShift; column.Visible = true; column.VisibleIndex = index++; shiftView.Columns.Add(column); GridColumn columnKey = new GridColumn(); columnKey.Name = dataTable.Rows[i][CAL_SHIFT.FIELD_SHIFT_KEY].ToString(); columnKey.Caption = "Key" + i.ToString(); columnKey.FieldName = dataTable.Rows[i][CAL_SHIFT.FIELD_SHIFT_KEY].ToString(); columnKey.Visible = false; //columnKey.VisibleIndex = index++; shiftView.Columns.Add(columnKey); GridColumn rowKey = new GridColumn(); rowKey.Name = "rowKey" + i.ToString(); rowKey.Caption = "rowKey" + i.ToString(); rowKey.FieldName = "rowKey" + i.ToString(); rowKey.Visible = false; //rowKey.VisibleIndex = index++; shiftView.Columns.Add(rowKey); } #endregion #region Bind Empty DataTable To Grid List <string> fields = new List <string>(); for (int j = 0; j < shiftView.Columns.Count; j++) { if (j == 0) { fields.Add("Date"); } else { fields.Add(shiftView.Columns[j].Name); } } DataTable shiftTable = FanHai.Hemera.Utils.Common.Utils.CreateDataTableWithColumns(CAL_SHIFT.DATABASE_TABLE_NAME, fields); shiftControl.MainView = shiftView; shiftControl.DataSource = shiftTable; #region Add Rows int columnCount = 0; columnCount = shiftTable.Columns.Count; for (int k = 1; k < days + 1; k++) { shiftView.AddNewRow(); DataRow newRow = shiftView.GetDataRow(shiftView.FocusedRowHandle); newRow["Date"] = year.ToString("0000") + "-" + month.ToString("00") + "-" + k.ToString("00"); for (int i = columnCount; i > 2; i = i - 3) { newRow[i - 2] = shiftTable.Columns[i - 2].ColumnName; } newRow.EndEdit(); shiftView.UpdateCurrentRow(); shiftView.ShowEditor(); } #endregion #endregion this.shiftView.FocusedRowHandle = 0; } else { //系统提示请先添加班次信息 MessageService.ShowMessage("${res:FanHai.Hemera.Addins.EMS.ShiftCtrl.Msg.AddShiftFirst}", "${res:Global.SystemInfo}"); return; } } #endregion #region Bind Data To Grid if (CtrlState == ControlState.Edit) { DataSet dataSetShifts = new DataSet(); IServerObjFactory serverObjFactory = CallRemotingService.GetRemoteObject(); dataSetShifts = serverObjFactory.CreateISchedule().GetShiftOfSchedule(lueYear.Text, cbeMonth.Text, lueSchedule.EditValue.ToString()); string errorMsg = FanHai.Hemera.Share.Common.ReturnMessageUtils.GetServerReturnMessage(dataSetShifts); if (errorMsg == "") { if (dataSetShifts.Tables.Contains(CAL_SCHEDULE_DAY.DATABASE_TABLE_NAME)) { originalDataTable = dataSetShifts.Tables[CAL_SCHEDULE_DAY.DATABASE_TABLE_NAME]; //_schedule.MKey=originalDataTable.Rows[0][CAL_SCHEDULE_DAY.FIELD_MKEY].ToString(); _monthKey = originalDataTable.Rows[0][CAL_SCHEDULE_DAY.FIELD_MKEY].ToString(); //bind data to Grid for (int i = 0; i < originalDataTable.Rows.Count; i++) { string day = Convert.ToDateTime(originalDataTable.Rows[i][CAL_SCHEDULE_DAY.FIELD_DAY]).ToString("yyyy-MM-dd"); string shiftValue = originalDataTable.Rows[i][CAL_SCHEDULE_DAY.FIELD_SHIFT_VALUE].ToString(); string shiftKey = originalDataTable.Rows[i][CAL_SCHEDULE_DAY.FIELD_SHIFT_KEY].ToString(); string dKey = originalDataTable.Rows[i][CAL_SCHEDULE_DAY.FIELD_DKEY].ToString(); for (int rowNo = 0; rowNo < shiftView.RowCount; rowNo++) { string columnDay = shiftView.GetRowCellValue(rowNo, shiftView.Columns[0].Name).ToString(); for (int columnNo = 2; columnNo < shiftView.Columns.Count; columnNo = columnNo + 3) { string columnKey = shiftView.GetRowCellValue(rowNo, shiftView.Columns[columnNo].Name).ToString(); if (day == columnDay && shiftKey == columnKey) { shiftView.SetRowCellValue(rowNo, shiftView.Columns[columnNo - 1].Name, shiftValue); shiftView.SetRowCellValue(rowNo, shiftView.Columns[columnNo + 1].Name, dKey); //Map Data To Entity ScheduleDay scheduleDay = new ScheduleDay(); scheduleDay.ShiftValue = shiftValue; scheduleDay.DKey = dKey; scheduleDay.OperationAction = OperationAction.Update; scheduleDay.IsInitializeFinished = true; _schedule.ScheduleDayList.Add(scheduleDay); } } } } } } else { MessageService.ShowError("${res:FanHai.Hemera.Addins.Msg.ReadFailed}!" + errorMsg); } } #endregion }
/// <summary> /// 更新每天排班计划数据。 /// </summary> /// <returns>true:更新成功。false:更新失败。</returns> public bool UpdateShiftOfSchedule() { DataSet dsReturn = new DataSet(); if (IsDirty) //数据有不一致。 { //每天排班计划的数据集合不为空。 if (ScheduleDayList.Count > 0) { DataTable scheduleDayTable = CAL_SCHEDULE_DAY.CreateDataTable(); DataColumn mKeyDataRow = new DataColumn(CAL_SCHEDULE_DAY.FIELD_MKEY); DataColumn actionDataRow = new DataColumn(COMMON_FIELDS.FIELD_COMMON_OPERATION_ACTION); scheduleDayTable.Columns.Add(mKeyDataRow); //每月排班计划主键列。 scheduleDayTable.Columns.Add(actionDataRow); //操作动作列。 foreach (ScheduleDay scheduleDay in ScheduleDayList) { //记录操作动作为None或或者Update,则不需要进行更新。 if (scheduleDay.OperationAction == OperationAction.None || scheduleDay.OperationAction == OperationAction.Update) { continue; } else { //待更新的数据。添加到数据表中。 Dictionary <string, string> rowData = new Dictionary <string, string>() { { CAL_SCHEDULE_DAY.FIELD_DKEY, scheduleDay.DKey }, { CAL_SCHEDULE_DAY.FIELD_STARTTIME, scheduleDay.StartTime }, { CAL_SCHEDULE_DAY.FIELD_ENDTIME, scheduleDay.EndTime }, { CAL_SCHEDULE_DAY.FIELD_SHIFT_VALUE, scheduleDay.ShiftValue }, { CAL_SCHEDULE_DAY.FIELD_SEQNO, scheduleDay.SeqNo }, { CAL_SCHEDULE_DAY.FIELD_SHIFT_KEY, scheduleDay.ShiftKey }, { CAL_SCHEDULE_DAY.FIELD_DAY, scheduleDay.Day }, { CAL_SCHEDULE_DAY.FIELD_MKEY, MKey }, { COMMON_FIELDS.FIELD_COMMON_OPERATION_ACTION, Convert.ToString((int)scheduleDay.OperationAction) } }; FanHai.Hemera.Utils.Common.Utils.AddRowDataToDataTable(ref scheduleDayTable, rowData); } } //数据表中有待更新的记录。 if (scheduleDayTable.Rows.Count > 0) { dsReturn.Tables.Add(scheduleDayTable); } } try { //远程调用的工厂对象。 IServerObjFactory serverFactory = CallRemotingService.GetRemoteObject(); //工厂对象创建成功。 if (null != serverFactory) { if (dsReturn.Tables.Count > 0) { //更新每天排班计划数据。 dsReturn = serverFactory.CreateISchedule().UpdateShiftOfSchedule(dsReturn); //远程函数执行结果消息。 _errorMsg = FanHai.Hemera.Share.Common.ReturnMessageUtils.GetServerReturnMessage(dsReturn); } else { _errorMsg = "${res:Global.UpdateItemDataMessage}"; } if (_errorMsg == "")//成功 { this.ResetDirtyList(); //遍历日排班计划集合。 foreach (ScheduleDay scheduleDay in ScheduleDayList) { scheduleDay.OperationAction = OperationAction.Update; scheduleDay.IsInitializeFinished = true; } } else { return(false); } } } catch (Exception ex) { _errorMsg = ex.Message; } finally { //关闭远程调用信道。 CallRemotingService.UnregisterChannel(); } } return(true); }
/// <summary> /// 更新数据库表中的排班计划数据。 /// </summary> /// <returns>是否更新成功。true:更新成功,false:更新失败。</returns> public override bool Update() { //集合中是否有待更新的数据,通过判断是否有不一致的数据来确定。 if (IsDirty) { DataSet dataSet = new DataSet(); if (this.DirtyList.Count > 0) { //为更新创建数据表对象。 DataTable scheduleTable = DataTableHelper.CreateDataTableForUpdateBasicData(CAL_SCHEDULE.DATABASE_TABLE_NAME); //遍历数据不一致的集合。 foreach (string Key in this.DirtyList.Keys) { //增加一行待更新的数据。 Dictionary <string, string> rowData = new Dictionary <string, string>() { { COMMON_FIELDS.FIELD_COMMON_UPDATE_KEY, _scheduleKey }, { COMMON_FIELDS.FIELD_COMMON_UPDATE_NAME, Key }, { COMMON_FIELDS.FIELD_COMMON_UPDATE_OLD_VALUE, this.DirtyList[Key].FieldOriginalValue }, { COMMON_FIELDS.FIELD_COMMON_UPDATE_NEW_VALUE, this.DirtyList[Key].FieldNewValue } }; FanHai.Hemera.Utils.Common.Utils.AddRowDataToDataTable(ref scheduleTable, rowData); } //如果数据表中有待更新的数据,添加到数据集中。 if (scheduleTable.Rows.Count > 0) { dataSet.Tables.Add(scheduleTable); } } try { DataSet dsReturn = null; //创建远程调用的工厂对象。 IServerObjFactory serverFactory = CallRemotingService.GetRemoteObject(); if (null != serverFactory) { //调用远程函数,更新排班计划记录。 dsReturn = serverFactory.CreateISchedule().UpdateSchedule(dataSet); //获取远程函数的执行结果。 _errorMsg = FanHai.Hemera.Share.Common.ReturnMessageUtils.GetServerReturnMessage(dsReturn); if (_errorMsg != "") {//执行不成功。 return(false); } else { //重置脏数据集合。 this.ResetDirtyList(); } } } catch (Exception ex) { _errorMsg = ex.Message; } finally { //注销远程调用信道。 CallRemotingService.UnregisterChannel(); } } else { _errorMsg = "${res:FanHai.Hemera.Addins.FMM.Msg.UpdateError}"; } return(true); }