public void SetDataSource(ISeriesContext context) { var ss = new List <Series>(); for (var type = context.GetType().BaseType; type != null; type = type.BaseType) { if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(SeriesContext <>)) { var tdata = type.GetGenericArguments()[0]; foreach (var prop in tdata.GetProperties(BindingFlags.Instance | BindingFlags.Public)) { if (prop.Name == nameof(CHS24B.Time)) { continue; } var series1 = new Series(); series1.ArgumentDataMember = nameof(CHS24B.Time); series1.ArgumentScaleType = ScaleType.DateTime; series1.Name = prop.Name; series1.ValueDataMembersSerializable = prop.Name; ss.Add(series1); } } } chartControl1.DataSource = null; chartControl1.SeriesSerializable = ss.ToArray(); chartControl1.DataSource = ((dynamic)context).DataSource; }
private void 打开设备(object sender, EventArgs e) { if (lookUpEdit1.GetSelectedDataRow() is MapType map) { SeriesContext = (ISeriesContext)Activator.CreateInstance(map.Type); view1.SetDataSource(SeriesContext); } else { return; } btnOpenClose.Click -= 打开设备; btnOpenClose.Click += 关闭设备; serialPort1.DataReceived += serialPort1_DataReceived; btnOpenClose.Text = "关闭"; try { serialPort1.Open(); propertyGridControl1.OptionsBehavior.Editable = false; } catch (Exception ex) { XtraMessageBox.Show(ex.Message); } }