private void GetDeviceType() { listDevicePlan = TbDeviceplan.FindAll("IsValid=1", "ID ASC", "", 0, 0); if (listDevicePlan != null && listDevicePlan.Count > 0) { listDevicePlan = listDevicePlan.FindAll(p => p.DeviceName == "新风"); if (listDevicePlan != null && listDevicePlan.Count > 0) { foreach (TbDeviceplan tdp in listDevicePlan) { Control[] ctrls = this.gbXF.Controls.Find("ucTimeInterval" + tdp.PlanNo, true); if (ctrls != null && ctrls.Length > 0) { UCTimeInterval ucTime = ctrls[0] as UCTimeInterval; if (ucTime != null) { ucTime.SetEnabled = tdp.IsValid; ucTime.SetStartTime(tdp.StartTime); ucTime.SetStopTime(tdp.StopTime); } } } } } }
private void sbtnOk_Click(object sender, EventArgs e) { foreach (UCTimeInterval uctime in listUCTI) { string starttime = uctime.GetStartTime(); string stoptime = uctime.GetStopTime(); TbDeviceplan tbdp = this.listDevicePlan.Find(p => p.PlanNo == uctime.GroupIndex); tbdp.IsValid = uctime.SetEnabled; if (starttime != "" && stoptime != "") { tbdp.StartTime = starttime; tbdp.StopTime = stoptime; } if (tbdp == null) {//插入 tbdp.Insert(); } else {//修改 tbdp.Update(); } } MessageBox.Show("编辑时间段成功!"); }
private void GetDevicePlan() { try { IList <TbDeviceplan> list = TbDeviceplan.FindAll("IsValid=1", "ID ASC", "", 0, 0); if (list != null && list.Count > 0) { if (dicDeviceplan == null) { dicDeviceplan = new ConcurrentDictionary <int, Dictionary <int, TaskPlan> >(); } list = list.FindAll(p => p.DeviceName == "新风"); if (list != null && list.Count > 0) { foreach (TbDeviceplan tdp in list) { int starthour = Convert.ToInt16(tdp.StartTime.Split(':')[0]); int startmin = Convert.ToInt16(tdp.StartTime.Split(':')[1]); int stophour = Convert.ToInt16(tdp.StopTime.Split(':')[0]); int stopmin = Convert.ToInt16(tdp.StopTime.Split(':')[1]); if (!dicDeviceplan.ContainsKey(tdp.DeviceType)) { dicDeviceplan.TryAdd(tdp.DeviceType, new Dictionary <int, EnvirManage.TaskPlan>()); } if (!dicDeviceplan[tdp.DeviceType].ContainsKey(tdp.PlanNo)) { dicDeviceplan[tdp.DeviceType].Add(tdp.PlanNo, null); TaskPlan tp = new TaskPlan() { DeviceID = tdp.DeviceType, DeviceName = tdp.DeviceName, TaskStartHour = starthour, TaskStartMin = startmin, TaskStopHour = stophour, TaskStopMin = stopmin, IsStart = false, LastExecuteTime = DateTime.Now, }; dicDeviceplan[tdp.DeviceType][tdp.PlanNo] = tp; } else { if (tdp.IsValid == false) { dicDeviceplan[tdp.DeviceType].Remove(tdp.PlanNo); } else { dicDeviceplan[tdp.DeviceType][tdp.PlanNo].TaskStartHour = starthour; dicDeviceplan[tdp.DeviceType][tdp.PlanNo].TaskStartMin = startmin; dicDeviceplan[tdp.DeviceType][tdp.PlanNo].TaskStopHour = stophour; dicDeviceplan[tdp.DeviceType][tdp.PlanNo].TaskStopMin = stopmin; } } } } } } catch (Exception ex) { } }