public bool ZoneInProgram_Update(ZoneInProgram Zone) { var Result = false; int rowsAffected = 0; Connector.GetProcedureResultInt32("config.ZoneInProgram_Update", new IDataParameter[] { Connector.CreateParameter("ProgramID", Zone.ProgramID), Connector.CreateParameter("FertQuant", Zone.FertQuant), Connector.CreateParameter("FertTime", Zone.FertTime), Connector.CreateParameter("OrderNumber", Zone.OrderNumber), Connector.CreateParameter("WaterAfter", Zone.WaterAfter), Connector.CreateParameter("WaterBefore", Zone.WaterBefore), Connector.CreateParameter("WaterQuantity", Zone.WaterQuantity), Connector.CreateParameter("WaterDuration", Zone.WaterDuration), Connector.CreateParameter("WaterPrecipitation_Duration", Zone.WaterPrecipitation_Duration), Connector.CreateParameter("WaterPrecipitation_Quantity", Zone.WaterPrecipitation_Quantity), Connector.CreateParameter("ZoneNumber", Zone.ZoneNumber) } , out rowsAffected, out Result); return(Result); }
public ZoneInProgramView(ZoneInProgram z) { if (z == null) { return; } ZoneNumber = z.ZoneNumber; OrderNumber = z.OrderNumber; ID = z.ID; WaterQuantity = z.WaterQuantity; FertQuant = z.FertQuant; FertTime = z.FertTime; WaterBefore = z.WaterBefore; WaterAfter = z.WaterAfter; WaterDuration = z.WaterDuration; Precipitation_Duration = z.WaterPrecipitation_Duration; Precipitation_Quantity = z.WaterPrecipitation_Quantity; }
public int GetDurationTime(WaterMeter_FlowType?FlowTypeID, decimal?FlowValue, WaterMeter_PulseType PulseTypeID, WaterProgramType WaterUnitID, ZoneSetting zoneSetting, ZoneInProgram Zoneitem) { int WaterDuration_Seconds = 0; switch (WaterUnitID) { case WaterProgramType.Duration: WaterDuration_Seconds = Zoneitem.WaterDuration; break; case WaterProgramType.Quantity: WaterDuration_Seconds = ConvertQuantityToDuration(Zoneitem.WaterQuantity, FlowTypeID, FlowValue, PulseTypeID); break; case WaterProgramType.Quantity_Precipitation: var WaterQuantity = ConvertPrecipitationToQuantity(zoneSetting.IrrigrationArea, Zoneitem.WaterPrecipitation_Quantity); WaterDuration_Seconds = ConvertQuantityToDuration(WaterQuantity, FlowTypeID, FlowValue, PulseTypeID); break; case WaterProgramType.Duration_Precipitation: WaterDuration_Seconds = ConvertPrecipitationToDuration(zoneSetting.PrecipitationRate, Zoneitem.WaterPrecipitation_Duration); break; } return(WaterDuration_Seconds); }
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); }
public void ProgramStory4_Test() //one program //Interval in day 2 //StartTime at 7 am //Interval time 3Hour { var SN = "33560133-c6eb-4d66-a"; if (string.IsNullOrEmpty(SN)) { var device = CreateDevice(); SN = device.SN; } var plist = Repository.DevicePrograms_Get(SN); Assert.IsTrue(plist != null && plist.Length > 0); // set only one to be active for (int i = 1; i < plist.Length; i++) { var p_fromList = plist[i]; var ProgramID = p_fromList.ProgramID; var program = Repository.ProgramSetting_Get(ProgramID); program.StatusID = 0; Assert.IsTrue(Repository.ProgramSetting_Update(program)); } var Program = plist[0]; Program.DaysExecutionsTypeID = 1; var CyclicDay = new CyclicDayProgram() { DaysInterval = 3, ProgramID = Program.ProgramID, StartDate = new DateTime(2016, 9, 18) }; Repository.CyclicDayProgram_Update(CyclicDay); Program.HoursExecutionsTypeID = 1; Program.HourlyCyclesPerDay = 2; Program.HourlyCyclesStartTime = 25200; //7 am Program.HourlyCycleTime = 10800; //Interval time 3 Hour Repository.ProgramSetting_Update(Program); var list_zone = new List <ZoneInProgram>(); for (int x = 0; x < 4; x++) { var zone = new ZoneInProgram() { FertQuant = 1.1m, FertTime = 12, OrderNumber = x, ProgramID = Program.ProgramID, WaterAfter = 3, WaterBefore = 5, WaterDuration = 3600, WaterPrecipitation_Duration = 4, WaterPrecipitation_Quantity = 3, WaterQuantity = 6, ZoneNumber = (byte)x, }; list_zone.Add(zone); Assert.IsTrue(Repository.ZoneInProgram_Update(zone)); } }
public void ProgramStory3_Test() //one program //CyclicDay type every3 day, //2 exec time - one cross-midnight { var SN = "c32ad0de-9610-419c-8"; if (string.IsNullOrEmpty(SN)) { var device = CreateDevice(); SN = device.SN; } var plist = Repository.DevicePrograms_Get(SN); Assert.IsTrue(plist != null && plist.Length > 0); // set only one to be active for (int i = 1; i < plist.Length; i++) { var p_fromList = plist[i]; var ProgramID = p_fromList.ProgramID; var program = Repository.ProgramSetting_Get(ProgramID); program.StatusID = 0; Assert.IsTrue(Repository.ProgramSetting_Update(program)); } var Program = plist[0]; Program.DaysExecutionsTypeID = 1; var CyclicDay = new CyclicDayProgram() { DaysInterval = 3, ProgramID = Program.ProgramID, StartDate = new DateTime(2016, 9, 18) }; Repository.CyclicDayProgram_Update(CyclicDay); var ExecutionHours = new ExecutionHours[] { new ExecutionHours() { ExecTime = 28800 }, //8 am new ExecutionHours() { ExecTime = 82800 } //11 pm 23:00 //{ ExecTime = 64800 } 6 pm ,18:00 }; Assert.IsTrue(Repository.ExecutionHoursProgram_Update(Program.ProgramID, ExecutionHours)); Repository.ProgramSetting_Update(Program); var list_zone = new List <ZoneInProgram>(); for (int x = 0; x < 4; x++) { var zone = new ZoneInProgram() { FertQuant = 1.1m, FertTime = 12, OrderNumber = x, ProgramID = Program.ProgramID, WaterAfter = 3, WaterBefore = 5, WaterDuration = 3600, WaterPrecipitation_Duration = 4, WaterPrecipitation_Quantity = 3, WaterQuantity = 6, ZoneNumber = (byte)x, }; list_zone.Add(zone); Assert.IsTrue(Repository.ZoneInProgram_Update(zone)); } }
public void ProgramStory2_Test() //one program //Weekly type , //Interval in day 2 //StartTime at 7 am //Interval time 3Hour { var SN = "ff852d37-cda7-4295-a"; if (string.IsNullOrEmpty(SN)) { var device = CreateDevice(); SN = device.SN; } var plist = Repository.DevicePrograms_Get(SN); Assert.IsTrue(plist != null && plist.Length > 0); // set only one to be active for (int i = 1; i < plist.Length; i++) { var p_fromList = plist[i]; var ProgramID = p_fromList.ProgramID; var program = Repository.ProgramSetting_Get(ProgramID); program.StatusID = 0; Assert.IsTrue(Repository.ProgramSetting_Update(program)); } var Program = plist[0]; Program.DaysExecutionsTypeID = 0; Program.HoursExecutionsTypeID = 1; Program.HourlyCyclesPerDay = 2; Program.HourlyCyclesStartTime = 25200; //7 am Program.HourlyCycleTime = 10800; //Interval time 3 Hour Repository.ProgramSetting_Update(Program); var WeeklyDaysProgram = new WeeklyProgramSetting() { ProgramID = Program.ProgramID }; WeeklyDaysProgram.Sunday = true; WeeklyDaysProgram.Monday = false; WeeklyDaysProgram.Thursday = true; WeeklyDaysProgram.Wednesday = false; WeeklyDaysProgram.Thursday = true; WeeklyDaysProgram.Friday = false; WeeklyDaysProgram.Saturday = true; Assert.IsTrue(Repository.WeeklyProgramSetting_Update(WeeklyDaysProgram)); var list_zone = new List <ZoneInProgram>(); for (int x = 0; x < 4; x++) { var zone = new ZoneInProgram() { FertQuant = 1.1m, FertTime = 12, OrderNumber = x, ProgramID = Program.ProgramID, WaterAfter = 3, WaterBefore = 5, WaterDuration = 3600, WaterPrecipitation_Duration = 4, WaterPrecipitation_Quantity = 3, WaterQuantity = 6, ZoneNumber = (byte)x, }; list_zone.Add(zone); Assert.IsTrue(Repository.ZoneInProgram_Update(zone)); } }
public void ProgramStory1_Test() //one program //Weekly type , //2 exec time - one cross-midnight { var SN = "0da20764-60b2-4081-8"; if (string.IsNullOrEmpty(SN)) { var device = CreateDevice(); SN = device.SN; } var plist = Repository.DevicePrograms_Get(SN); Assert.IsTrue(plist != null && plist.Length > 0); // set only one to be active for (int i = 1; i < plist.Length; i++) { var p_fromList = plist[i]; var ProgramID = p_fromList.ProgramID; var program = Repository.ProgramSetting_Get(ProgramID); program.StatusID = 0; Assert.IsTrue(Repository.ProgramSetting_Update(program)); } var Program = plist[0]; Program.DaysExecutionsTypeID = 0; Repository.ProgramSetting_Update(Program); var WeeklyDaysProgram = new WeeklyProgramSetting() { ProgramID = Program.ProgramID }; WeeklyDaysProgram.Sunday = true; WeeklyDaysProgram.Monday = false; WeeklyDaysProgram.Thursday = true; WeeklyDaysProgram.Wednesday = false; WeeklyDaysProgram.Thursday = true; WeeklyDaysProgram.Friday = false; WeeklyDaysProgram.Saturday = true; Assert.IsTrue(Repository.WeeklyProgramSetting_Update(WeeklyDaysProgram)); var ExecutionHours = new ExecutionHours[] { new ExecutionHours() { ExecTime = 28800 }, //8 am new ExecutionHours() { ExecTime = 82800 } //11 pm 23:00 //{ ExecTime = 64800 } 6 pm ,18:00 }; Assert.IsTrue(Repository.ExecutionHoursProgram_Update(Program.ProgramID, ExecutionHours)); var list_zone = new List <ZoneInProgram>(); for (int x = 0; x < 4; x++) { var zone = new ZoneInProgram() { FertQuant = 1.1m, FertTime = 12, OrderNumber = x, ProgramID = Program.ProgramID, WaterAfter = 3, WaterBefore = 5, WaterDuration = 3600, WaterPrecipitation_Duration = 4, WaterPrecipitation_Quantity = 3, WaterQuantity = 6, ZoneNumber = (byte)x, }; list_zone.Add(zone); Assert.IsTrue(Repository.ZoneInProgram_Update(zone)); } }
public void Program_Test() { var SN = "0b257467-640b-47db-a"; if (string.IsNullOrEmpty(SN)) { var device = CreateDevice(); SN = device.SN; } var plist = Repository.DevicePrograms_Get(SN); Assert.IsTrue(plist != null && plist.Length > 0); for (int i = 0; i < plist.Length; i++) { var p_fromList = plist[i]; var ProgramID = p_fromList.ProgramID; var program = Repository.ProgramSetting_Get(ProgramID); isProgramEqual(program, p_fromList); var now = DateTime.Now; var CyclicDayProgram = new CyclicDayProgram() { ProgramID = ProgramID }; var WeeklyDaysProgram = new WeeklyProgramSetting() { ProgramID = ProgramID }; for (int j = 0; j < 2; j++) { #region setting program.DaysExecutionsTypeID = (byte)(i % 2 == 0 ? 0 : 1); program.FinalEndDateLimit = now.AddMonths(i); program.FinalStartDateLimit = now.AddMonths(-i); program.FinalStartHoursLimit = i % 2 == 0 ? 10 : 100; program.FinalStopHoursLimit = i % 2 == 0 ? 2 : 234; program.HourlyCyclesPerDay = (byte)(i % 2 == 0 ? 11 : 12); program.HourlyCyclesStartTime = i % 2 == 0 ? 12 : 34; program.HourlyCyclesStopTime = i % 2 == 0 ? 34 : 345; program.HourlyCycleTime = i % 2 == 0 ? 34 : 67; program.HoursExecutionsTypeID = (byte)(i % 2 == 0 ? 1 : 0); program.IsFertilizerON = i % 2 == 0; program.Name = "name _" + i.ToString(); program.Priority = (byte)(i % 2 == 0 ? 17 : 0); program.StatusID = (byte)(i % 2 == 0 ? 1 : 0); program.WaterFactor = (byte)(i % 2 == 0 ? 45 : 78); program.WaterUnitID = (byte)(i % 2 == 0 ? 0 : 1); Assert.IsTrue(Repository.ProgramSetting_Update(program)); var program_db = Repository.ProgramSetting_Get(ProgramID); isProgramEqual(program, program_db); #endregion #region CyclicDayProgram CyclicDayProgram.DaysInterval = (byte)(2); CyclicDayProgram.StartDate = now.AddDays(i); Assert.IsTrue(Repository.CyclicDayProgram_Update(CyclicDayProgram)); var c_db = Repository.CyclicDayProgram_Get(ProgramID); Assert.IsTrue(CyclicDayProgram.DaysInterval == c_db.DaysInterval); Assert.IsTrue(EqualsDate(CyclicDayProgram.StartDate, c_db.StartDate)); #endregion #region WeeklyDaysProgram WeeklyDaysProgram.Sunday = (i % 2 == 0); WeeklyDaysProgram.Monday = !(i % 2 == 0); WeeklyDaysProgram.Thursday = (i % 2 == 0); WeeklyDaysProgram.Wednesday = !(i % 2 == 0); WeeklyDaysProgram.Thursday = (i % 2 == 0); WeeklyDaysProgram.Friday = !(i % 2 == 0); WeeklyDaysProgram.Saturday = (i % 2 == 0); Assert.IsTrue(Repository.WeeklyProgramSetting_Update(WeeklyDaysProgram)); var w_db = Repository.WeeklyProgramSetting_Get(ProgramID); Assert.IsTrue(WeeklyDaysProgram.Sunday == w_db.Sunday); Assert.IsTrue(WeeklyDaysProgram.Monday == w_db.Monday); Assert.IsTrue(WeeklyDaysProgram.Tuesday == w_db.Tuesday); Assert.IsTrue(WeeklyDaysProgram.Wednesday == w_db.Wednesday); Assert.IsTrue(WeeklyDaysProgram.Thursday == w_db.Thursday); Assert.IsTrue(WeeklyDaysProgram.Friday == w_db.Friday); Assert.IsTrue(WeeklyDaysProgram.Saturday == w_db.Saturday); #endregion #region ExecutionHours var ExecutionHours = new ExecutionHours[] { new ExecutionHours() { ExecTime = i }, new ExecutionHours() { ExecTime = 10800 }, new ExecutionHours() { ExecTime = 28800 }, new ExecutionHours() { ExecTime = 50400 } }; Assert.IsTrue(Repository.ExecutionHoursProgram_Update(ProgramID, ExecutionHours)); var e_db = Repository.ExecutionHoursProgram_Get(ProgramID); Assert.IsTrue(e_db.Length == ExecutionHours.Length); foreach (var item_db in e_db) { var item = ExecutionHours.Where(e => e.ExecTime == item_db.ExecTime).FirstOrDefault(); Assert.IsTrue(item != null); } #endregion #region ZoneInProgram var list_zone = new List <ZoneInProgram>(); for (int x = 0; x < 4; x++) { var zone = new ZoneInProgram() { FertQuant = (i % 2 == 0 ? 0.9m : 1.1m), FertTime = (i % 2 == 0 ? 11 : 12), OrderNumber = x, ProgramID = ProgramID, WaterAfter = (i % 2 == 0 ? 3 : 4), WaterBefore = (i % 2 == 0 ? 2 : 5), WaterDuration = (i % 2 == 0 ? 23 : 34), WaterPrecipitation_Duration = (i % 2 == 0 ? 3 : 4), WaterPrecipitation_Quantity = (i % 2 == 0 ? 6 : 8), WaterQuantity = (i % 2 == 0 ? 7 : 99), ZoneNumber = (byte)x, }; list_zone.Add(zone); Assert.IsTrue(Repository.ZoneInProgram_Update(zone)); } var list_zone_db = Repository.ZonesInProgram_Get(ProgramID); Assert.IsTrue(list_zone_db.Length == list_zone.Count); foreach (var item_db in list_zone_db) { var item = list_zone.Where(s => s.ZoneNumber == item_db.ZoneNumber).FirstOrDefault(); Assert.IsTrue(item != null); Assert.IsTrue(item.FertQuant == item_db.FertQuant); Assert.IsTrue(item.FertTime == item_db.FertTime); Assert.IsTrue(item.OrderNumber == item_db.OrderNumber); Assert.IsTrue(item.WaterAfter == item_db.WaterAfter); Assert.IsTrue(item.WaterBefore == item_db.WaterBefore); Assert.IsTrue(item.WaterDuration == item_db.WaterDuration); Assert.IsTrue(item.WaterPrecipitation_Duration == item_db.WaterPrecipitation_Duration); Assert.IsTrue(item.WaterPrecipitation_Quantity == item_db.WaterPrecipitation_Quantity); Assert.IsTrue(item.WaterQuantity == item_db.WaterQuantity); } #endregion } } }