123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- using IntelligentControlForsx.CodeGenerator;
- using log4net;
- using System;
- using System.Collections;
- using System.ComponentModel;
- using System.Threading;
- using System.Windows.Forms;
- using WisdomClient.data;
- using WisdomClient;
- using System.Collections.Generic;
- namespace IntelligentControlForsx.MyControls
- {
- public partial class WindturbineParams : UserControl
- {
- private ILog logger = LogManager.GetLogger("AppInfoLog");
- #region 数据绑定
- // This BindingSource binds the list to the DataGridView control.
- private BindingSource bindingSource = new BindingSource();
- private IDictionary<string, BindingList<dynamic>> dictBindingList;
- private BindingList<dynamic> getBindingList(string clsName)
- {
- if (dictBindingList == null)
- dictBindingList = new Dictionary<string, BindingList<dynamic>>();
- if (dictBindingList.ContainsKey(clsName) == false)
- {
- BindingList<dynamic> bl = createParamList(clsName);
- dictBindingList.Add(clsName, bl);
- }
- return dictBindingList[clsName];
- }
- private string stationId;
- public string StationId
- {
- get
- {
- return stationId;
- }
- set
- {
- if (value != this.stationId)
- {
- this.stationId = value;
- // Bind the list to the BindingSource.
- this.bindingSource.DataSource = getBindingList(stationId);
- // Attach the BindingSource to the DataGridView.
- this.gvWindturbine.DataSource =
- this.bindingSource;
- }
- }
- }
- public WindturbineParams()
- {
- InitializeComponent();
- }
- private BindingList<dynamic> createParamList(string stationId)
- {
- BindingList<dynamic> paramList = new BindingList<dynamic>();
- ArrayList tmArray = TableModelFactory.Instance.getTableModel(stationId);
- for (int i=0;i<tmArray.Count;i++)
- {
- paramList.Add(tmArray[i]);
- }
- return paramList;
- }
- private void gvWindturbine_DataError(object sender, DataGridViewDataErrorEventArgs e)
- {
- logger.Info(e.RowIndex);
- logger.Info(e.ColumnIndex);
- }
- #endregion
- #region 加载数据
- private void timer1_Tick(object sender, EventArgs e)
- {
- if (isLoadding == true)
- return;
- Thread ayscThread = new Thread(LoadData);
- ayscThread.IsBackground = true;
- ayscThread.Start();
- }
- public void DeActive()
- {
- timer1.Stop();
- }
- public void Active()
- {
- Thread ayscThread = new Thread(LoadData);
- ayscThread.IsBackground = true;
- ayscThread.Start();
- timer1.Start();
- }
- private bool isLoadding = false;
- private void LoadData()
- {
- if (isLoadding == true)
- return;
- isLoadding = true;
- try
- {
- string[] tagNames = TableModelFactory.Instance.getTablePointArray(stationId);
- TsData[] tagValues = RestfulClient2.findLatestByTagNames(tagNames);
- double[] tagDoubleValues = new double[tagNames.Length];
- for(int i=0;i<tagNames.Length;i++)
- {
- tagDoubleValues[i] = tagValues[i].doubleValue.HasValue ? tagValues[i].doubleValue.Value : 0;
- }
- lock (this)
- {
- this.BeginInvoke(
- (Action)delegate
- {
- var bl = getBindingList(stationId);
- int columns = TableModelFactory.Instance.getPointsColumns(stationId);
- int offset = 0;
- foreach (var em in bl)
- {
- double[] tmVals = new double[columns];
- Array.Copy(tagDoubleValues, offset, tmVals, 0, columns);
- TableModel tm = em as TableModel;
- tm.bindingData(tmVals);
-
- offset += columns;
- }
- this.gvWindturbine.Refresh();
- });
- }
- }
- catch (Exception ex)
- {
- logger.Info("绑定数据失败!ex=" + ex.Message);
- }
- finally
- {
- isLoadding = false;
- }
- }
- #endregion
- }
- }
|