public LimitWindow(List <LimitTempView> gui, int min, int max) : this() { views = gui; txtMinTemp.Text = min.ToString(); txtMaxTemp.Text = max.ToString(); for (int i = 0; i < views.Count; i++) { LimitTempView col = views[i]; // Do not add new column on the first iteration // because there is already one if (!(limitSetter.ColumnCount == 1 && i == 0)) { limitSetter.ColumnCount++; limitSetter.Width += COL_WIDTH; } ColumnStyle style = new ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F); limitSetter.ColumnStyles.Add(style); limitSetter.Controls.Add(col.LabName, i, 0); FillCell(col.CbSelected, col.TxtTime, i, 1); } UpdateColumnStyles(); // Copy current model state beginState.Clear(); beginState.AddRange(views.ConvertAll(view => view.Model.Clone())); }
public static List <LimitTempView> Create(List <LimitTempModel> models) { List <LimitTempView> ret = new List <LimitTempView>(); foreach (var model in models) { LimitTempView view = new LimitTempView(model); ret.Add(view); } return(ret); }
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(); }
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); } }