/// <summary> /// 保存具体月份和天的排班数据。 /// </summary> /// <param name="dsParams">包含具体月份和天的排班数据的数据集对象。</param> /// <returns>包含执行结果的数据集对象。</returns> public DataSet SaveShiftOfSchedule(DataSet dsParams) { DataSet dsReturn = new DataSet(); DbConnection dbConn = null; DbTransaction dbTran = null; string sql = ""; string mkey = ""; if (dsParams.Tables.Contains(CAL_SCHEDULE_MONTH.DATABASE_TABLE_NAME)) { try { dbConn = db.CreateConnection(); dbConn.Open(); //Create Transaction dbTran = dbConn.BeginTransaction(); DataTable shiftMonthTable = dsParams.Tables[CAL_SCHEDULE_MONTH.DATABASE_TABLE_NAME]; mkey = shiftMonthTable.Rows[0][CAL_SCHEDULE_MONTH.FIELD_MKEY].ToString(); CAL_SCHEDULE_MONTH schduleMonthFields = new CAL_SCHEDULE_MONTH(); sql = DatabaseTable.BuildInsertSqlStatement(schduleMonthFields, shiftMonthTable, 0, new Dictionary <string, string>() { }, new List <string>()); db.ExecuteNonQuery(dbTran, CommandType.Text, sql); if (dsParams.Tables.Contains(CAL_SCHEDULE_DAY.DATABASE_TABLE_NAME)) { DataTable shiftDayTable = dsParams.Tables[CAL_SCHEDULE_DAY.DATABASE_TABLE_NAME]; CAL_SCHEDULE_DAY shiftDayFields = new CAL_SCHEDULE_DAY(); for (int i = 0; i < shiftDayTable.Rows.Count; i++) { sql = DatabaseTable.BuildInsertSqlStatement(shiftDayFields, shiftDayTable, i, new Dictionary <string, string>() { { CAL_SCHEDULE_DAY.FIELD_MKEY, mkey }, }, new List <string>()); db.ExecuteNonQuery(dbTran, CommandType.Text, sql); } } dbTran.Commit(); } catch (Exception ex) { dbTran.Rollback(); FanHai.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, ex.Message); LogService.LogError("SaveShiftOfSchedule Error: " + ex.Message); } finally { dbTran.Dispose(); dbConn.Close(); dbConn.Dispose(); } } return(dsReturn); }
/// <summary> /// 保存排班计划 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> #region Save Button Click private void tsbSave_Click(object sender, EventArgs e) { if (this.shiftView.State == GridState.Editing && this.shiftView.IsEditorFocused && this.shiftView.EditingValueModified) { this.shiftView.SetFocusedRowCellValue(this.shiftView.FocusedColumn, this.shiftView.EditingValue); } this.shiftView.UpdateCurrentRow(); //系统提示确定要保存吗? if (MessageService.AskQuestion(StringParser.Parse("${res:FanHai.Hemera.Addins.Msg.SaveRemind}"), StringParser.Parse("${res:Global.SystemInfo}"))) { if (shiftView.RowCount > 0) { #region Map Data To Entity for (int i = 1; i < shiftView.Columns.Count; i = i + 3) { for (int j = 0; j < shiftView.RowCount; j++) { if (shiftView.GetRowCellValue(j, shiftView.Columns[i + 2].Name).ToString() == "") { if (shiftView.GetRowCellValue(j, shiftView.Columns[i].Name).ToString() != "") { string shiftValue = shiftView.GetRowCellValue(j, shiftView.Columns[i].Name).ToString(); string day = shiftView.GetRowCellValue(j, shiftView.Columns[0].Name).ToString(); string seqNo = (j + 1).ToString(); string shiftKey = shiftView.GetRowCellValue(j, shiftView.Columns[i + 1].Name).ToString(); string startTime = _shiftDictionary[shiftKey].StartTime; string endTime = _shiftDictionary[shiftKey].EndTime; string endDate = ""; if (Convert.ToInt32(startTime.Substring(0, 2)) > Convert.ToInt32(endTime.Substring(0, 2))) { endDate = Convert.ToDateTime(day).AddDays(1).ToShortDateString() + " " + endTime; } else { endDate = day + " " + endTime; } string startDate = day + " " + startTime; ScheduleDay scheduleDay = new ScheduleDay(); scheduleDay.OperationAction = OperationAction.New; scheduleDay.DKey = CommonUtils.GenerateNewKey(0); scheduleDay.StartTime = startDate; scheduleDay.EndTime = endDate; scheduleDay.ShiftValue = shiftValue; scheduleDay.SeqNo = seqNo; scheduleDay.ShiftKey = shiftKey; scheduleDay.Day = day; _schedule.ScheduleDayList.Add(scheduleDay); shiftView.SetRowCellValue(j, shiftView.Columns[i + 2].Name, scheduleDay.DKey); } } else { string rowKey = shiftView.GetRowCellValue(j, shiftView.Columns[i + 2].Name).ToString(); foreach (ScheduleDay schedule in _schedule.ScheduleDayList) { if (rowKey == schedule.DKey) { if (shiftView.GetRowCellValue(j, shiftView.Columns[i].Name).ToString() != "") { schedule.ShiftValue = shiftView.GetRowCellValue(j, shiftView.Columns[i].Name).ToString(); } else { schedule.OperationAction = OperationAction.Delete; shiftView.SetRowCellValue(j, shiftView.Columns[i + 2].Name, string.Empty); } } if (schedule.IsDirty) { schedule.OperationAction = OperationAction.Modified; } } } } } #endregion if (CtrlState == ControlState.New) { if (_schedule.ScheduleDayList.Count > 0) { #region Add data to shift_month table DataTable shiftMonthTable = CAL_SCHEDULE_MONTH.CreateDataTable(); string monthKey = CommonUtils.GenerateNewKey(0); Dictionary <string, string> rowData = new Dictionary <string, string>() { { CAL_SCHEDULE_MONTH.FIELD_MKEY, monthKey }, { CAL_SCHEDULE_MONTH.FIELD_CUR_YEAR, this.lueYear.Text }, { CAL_SCHEDULE_MONTH.FIELD_CUR_MONTH, this.cbeMonth.Text }, { CAL_SCHEDULE_MONTH.FIELD_SCHEDULE_KEY, this.lueSchedule.EditValue.ToString() } }; FanHai.Hemera.Utils.Common.Utils.AddRowDataToDataTable(ref shiftMonthTable, rowData); #endregion _schedule.SaveShiftOfSchedule(shiftMonthTable); if (_schedule.ErrorMsg == "") { _monthKey = monthKey; //系统提示保存成功 MessageService.ShowMessage("${res:FanHai.Hemera.Addins.Msg.SaveSucceed}", "${res:Global.SystemInfo}"); CtrlState = ControlState.Edit; } else { //系统提示保存失败 MessageService.ShowError("${res:FanHai.Hemera.Addins.Msg.SaveFailed}" + _schedule.ErrorMsg); } } else { //当前没有保存项! MessageService.ShowMessage("${res:FanHai.Hemera.Addins.EMS.ShiftCtrl.MsgNoDataForSave}", "${res:Global.SystemInfo}"); } } else { _schedule.MKey = _monthKey; if (_schedule.UpdateShiftOfSchedule()) { //系统提示更新成功 MessageService.ShowMessage("${res:FanHai.Hemera.Addins.Msg.UpdateSucceed}", "${res:Global.SystemInfo}"); if (CtrlState == ControlState.New) { CtrlState = ControlState.Edit; } } else { MessageService.ShowError(_schedule.ErrorMsg); } } } } }