예제 #1
0
        public bool SaveSettings(string sN, long programID, ProgramSettingView setting)
        {
            var result = false;

            #region ProgramSetting

            var psetting = new ProgramSetting()
            {
                Name                  = setting.Name,
                WaterUnitID           = (byte)setting.ProgramType,
                ProgramID             = programID,
                ProgramNumber         = setting.ProgramNumber,
                Priority              = setting.Priority,
                IsFertilizerON        = setting.IsFertilizerON,
                StatusID              = (byte)setting.Status,
                FertUnitID            = (byte)setting.FertExecutionType,
                WaterFactor           = setting.WaterFactor,
                HoursExecutionsTypeID = (byte)setting.HoursExecution,
                DaysExecutionsTypeID  = (byte)setting.DaysExecutionType,
                FinalEndDateLimit     = setting.Advanced.FinalEndDateLimit.HasValue ? (DateTime?)TimeConvertor.GetDateTime(setting.Advanced.FinalEndDateLimit.Value) : null,
                FinalStartDateLimit   = setting.Advanced.FinalStartDateLimit.HasValue ? (DateTime?)TimeConvertor.GetDateTime(setting.Advanced.FinalStartDateLimit.Value) : null,
                FinalStartHoursLimit  = setting.Advanced.FinalStartHoursLimit,
                FinalStopHoursLimit   = setting.Advanced.FinalStopHoursLimit,
                HourlyCyclesPerDay    = setting.HourlyCycle.HourlyCyclesPerDay,
                HourlyCyclesStartTime = setting.HourlyCycle.HourlyCyclesStartTime,
                HourlyCyclesStopTime  = setting.HourlyCycle.HourlyCycleTime,
                HourlyCycleTime       = setting.HourlyCycle.HourlyCyclesStopTime
            };

            result = _AdminRepository.ProgramSetting_Update(psetting);

            if (!result)
            {
                return(result);
            }
            #endregion

            #region cyclicsetting

            var cyclicsetting = new CyclicDayProgram()
            {
                ProgramID    = programID,
                DaysInterval = setting.CyclicDayProgram.DaysInterval,
                StartDate    = TimeConvertor.GetDateTime(setting.CyclicDayProgram.StartDate)
            };

            result = _AdminRepository.CyclicDayProgram_Update(cyclicsetting);

            if (!result)
            {
                return(result);
            }
            #endregion

            #region ExecutionHours

            var ExecutionHours = setting.ExecutionHours.Select(e => new ExecutionHours {
                ExecTime = e
            }).ToArray();

            result = _AdminRepository.ExecutionHoursProgram_Update(programID, ExecutionHours);

            if (!result)
            {
                return(result);
            }

            #endregion

            #region WeeklyDaysProgram

            var w_days            = setting.WeeklyDaysProgram.Days;
            var WeeklyDaysProgram = new WeeklyProgramSetting()
            {
                ProgramID = programID,
                Sunday    = w_days[0].IsEnabled,
                Monday    = w_days[1].IsEnabled,
                Tuesday   = w_days[2].IsEnabled,
                Wednesday = w_days[3].IsEnabled,
                Thursday  = w_days[4].IsEnabled,
                Friday    = w_days[5].IsEnabled,
                Saturday  = w_days[6].IsEnabled
            };

            result = _AdminRepository.WeeklyProgramSetting_Update(WeeklyDaysProgram);

            if (!result)
            {
                return(result);
            }

            #endregion

            #region ZoneInProgram
            //GET All zone in program from DB
            var zone_dbList = _AdminRepository.ZonesInProgram_Get(programID).ToList();


            for (int i = 0; i < setting.ZoneInProgram.Length; i++)
            {
                var zone = setting.ZoneInProgram[i];
                zone_dbList.RemoveAll(s => s.ZoneNumber == zone.ZoneNumber);
                var zone_db = new ZoneInProgram()
                {
                    FertQuant     = zone.FertQuant,
                    FertTime      = zone.FertTime,
                    OrderNumber   = zone.OrderNumber,
                    ProgramID     = programID,
                    WaterAfter    = zone.WaterAfter,
                    WaterBefore   = zone.WaterBefore,
                    WaterDuration = zone.WaterDuration,
                    WaterPrecipitation_Duration = zone.Precipitation_Duration,
                    WaterPrecipitation_Quantity = zone.Precipitation_Quantity,
                    WaterQuantity = zone.WaterQuantity,
                    ZoneNumber    = zone.ZoneNumber
                };

                result = _AdminRepository.ZoneInProgram_Update(zone_db);
                if (!result)
                {
                    return(result);
                }
            }

            if (zone_dbList.Count > 0)
            {
                foreach (var item in zone_dbList)
                {
                    result = _AdminRepository.ZoneInProgram_Delete(item.ZoneNumber, programID);
                    if (!result)
                    {
                        return(result);
                    }
                }
            }

            #endregion

            return(true);
        }