示例#1
0
        /// <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();
            }
        }
示例#2
0
        /// <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);
        }
示例#3
0
        /// <summary>
        /// 更新具体月份和天的排班数据。
        /// </summary>
        /// <param name="dsParams">包含具体月份和天的排班数据的数据集对象。</param>
        /// <returns>包含执行结果的数据集对象。</returns>
        public DataSet UpdateShiftOfSchedule(DataSet dsParams)
        {
            DataSet       dsReturn = new DataSet();
            DbConnection  dbConn   = null;
            DbTransaction dbTran   = null;
            string        sql      = "";

            if (dsParams.Tables.Contains(CAL_SCHEDULE_DAY.DATABASE_TABLE_NAME))
            {
                DataTable        dataTable         = dsParams.Tables[CAL_SCHEDULE_DAY.DATABASE_TABLE_NAME];
                CAL_SCHEDULE_DAY schedukeDayFields = new CAL_SCHEDULE_DAY();
                try
                {
                    dbConn = db.CreateConnection();
                    dbConn.Open();
                    //Create Transaction
                    dbTran = dbConn.BeginTransaction();
                    for (int i = 0; i < dataTable.Rows.Count; i++)
                    {
                        OperationAction action = (OperationAction)Convert.ToInt32(dataTable.Rows[i][COMMON_FIELDS.FIELD_COMMON_OPERATION_ACTION]);
                        switch (action)
                        {
                        case OperationAction.New:
                            sql = DatabaseTable.BuildInsertSqlStatement(schedukeDayFields, dataTable, i,
                                                                        new Dictionary <string, string>()
                            {
                            },
                                                                        new List <string>()
                            {
                                COMMON_FIELDS.FIELD_COMMON_OPERATION_ACTION
                            });

                            db.ExecuteNonQuery(dbTran, CommandType.Text, sql);
                            break;

                        case OperationAction.Delete:
                            sql = @"DELETE FROM CAL_SCHEDULE_DAY WHERE DKEY='" + dataTable.Rows[i][CAL_SCHEDULE_DAY.FIELD_DKEY].ToString().PreventSQLInjection() + "'";
                            db.ExecuteNonQuery(dbTran, CommandType.Text, sql);
                            break;

                        case OperationAction.Modified:
                            sql = @"UPDATE CAL_SCHEDULE_DAY SET SHIFT_VALUE='" + dataTable.Rows[i][CAL_SCHEDULE_DAY.FIELD_SHIFT_VALUE].ToString().PreventSQLInjection() + "' " +
                                  "WHERE DKEY='" + dataTable.Rows[i][CAL_SCHEDULE_DAY.FIELD_DKEY].ToString().PreventSQLInjection() + "'";
                            db.ExecuteNonQuery(dbTran, CommandType.Text, sql);
                            break;
                        }
                    }
                    dbTran.Commit();
                }
                catch (Exception ex)
                {
                    dbTran.Rollback();
                    FanHai.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, ex.Message);
                    LogService.LogError("UpdateShiftOfSchedule Error: " + ex.Message);
                }
                finally
                {
                    dbTran.Dispose();
                    dbConn.Close();
                    dbConn.Dispose();
                }
            }
            else
            {
                FanHai.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, "${res:FanHai.Hemera.Modules.EMS.CalShiftEngine.TableIsNotExist}");
            }
            return(dsReturn);
        }
示例#4
0
        /// <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);
        }