public LimitTempModel Clone() { LimitTempModel model = new LimitTempModel(this.Name); model.selected = this.selected; model.time = this.time; return(model); }
public static List <LimitTempModel> Create(List <string> names) { List <LimitTempModel> ret = new List <LimitTempModel>(); foreach (var name in names) { LimitTempModel model = new LimitTempModel(name); ret.Add(model); } return(ret); }
public LimitTempView(LimitTempModel model) { this.model = model; labName.Text = model.Name; labName.Anchor = AnchorStyles.None; LabName.TextAlign = ContentAlignment.MiddleCenter; cbSelected.Checked = model.Selected; txtTime.Text = model.Time.ToString(); txtTime.TextChanged += txtTime_TextChanged; cbSelected.CheckedChanged += cbSelected_CheckedChanged; }
private void btnLimits_Click(object sender, EventArgs e) { List <string> names = DeviceManager.GetNames(); List <LimitTempModel> models = (views == null) ? LimitTempModel.Create(names) : LimitTempModel.Create(names, views.ConvertAll(view => view.Model)); views = LimitTempView.Create(models); LimitWindow window = new LimitWindow(views, minTempLimit, maxTempLimit); window.FormClosing += window_FormClosing; window.ShowDialog(); }
public static List <LimitTempModel> Create(List <string> names, List <LimitTempModel> models) { List <LimitTempModel> ret = new List <LimitTempModel>(); for (int i = 0; i < names.Count; i++) { LimitTempModel model; if (i < models.Count) { model = models[i].Clone(); model.Name = names[i]; } else { model = new LimitTempModel(names[i]); } ret.Add(model); } return(ret); }
private void btnRead_Click(object sender, EventArgs e) { try { string json = null; if (OFFLINE) { json = rx; } else { if (link.Connect()) { Console.WriteLine("Read config"); link.Send("TER_READ"); json = link.Receive(); link.Close(); } } Console.WriteLine("offline read"); var data = JObject.Parse(json); Console.WriteLine(data); var devices = data["Devices"].ToObject <Dictionary <string, JObject> >(); var config = data["Config"]; DeviceManager.Clear(); TimelineClear(); List <Event> temp = new List <Event>(); foreach (var entry in devices) { string devName = entry.Key; DeviceType devType = (DeviceType)Enum.Parse(typeof(DeviceType), (string)entry.Value["Type"]); RGB rgb = entry.Value["Color"].ToObject <RGB>(); eCalendarColor color = CalendarUtils.ConvertColor(rgb); int slot = (int)entry.Value["Slot"]; List <Event> events = new List <Event>(); foreach (var evData in entry.Value["Events"]) { Event ev = evData.ToObject <Event>(); events.Add(ev); } DeviceManager.AddDevice(devName, devType, slot, color); devName += getSlotFormat(slot); TimelineAddNewRow(devName, color); FillTimeline(events, devName); } /////////////////////////////////////////////////////// minTempLimit = (int)config["Limits"]["Min"]; maxTempLimit = (int)config["Limits"]["Max"]; List <LimitTempView> _views = new List <LimitTempView>(); foreach (var limit in config["Limits"]["Events"]) { LimitTempModel model = limit.ToObject <LimitTempModel>(); _views.Add(new LimitTempView(model)); } // Create views for Limit Temp window List <string> names = DeviceManager.GetNames(); List <LimitTempModel> models = (views == null) ? LimitTempModel.Create(names) : LimitTempModel.Create(names, views.ConvertAll(view => view.Model)); views = LimitTempView.Create(models); // Update those views with received data foreach (var _view in _views) { foreach (var view in views) { if (view.Model.Name == _view.Model.Name) { view.Model = _view.Model; } } } } catch (Exception ex) { Console.WriteLine(ex); } }