123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using IntelligentControlForsx.Service.Control.FormInfo;
- using IntelligentControlForsx.Service.ParameterFormInfo;
- using IntelligentControlForsx.Service.ParameterFormInfo.Domain;
- using IntelligentControlForsx.Template;
- using log4net.Util;
- using StatInfo = IntelligentControlForsx.Service.Control.FormInfo.StatInfo;
- namespace IntelligentControlForsx.ChildForms
- {
- public partial class ParameterForm : TemplateForm
- {
- public bool firstLoad = true;
- public bool IsFirstGridViewLoad = true;
- private int selectRow = 0;
- private bool isUpdateFormOver = true;
- private bool isUpdateDataOver = true;
- private string station = "SBQ_FDC";
- public ParameterForm()
- {
- InitializeComponent();
- }
- public override void Active()
- {
- this.Show();
- //timer1.Enabled = true;
- }
- public override void DeActive()
- {
- this.Hide();
- timer1.Enabled = false;
- }
- private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
- {
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- if (isUpdateFormOver)
- {
- if (firstLoad)
- {
- ParameterFormInfoSvc.Instance.RefreshDataList("SBQ_FDC");
- firstLoad = false;
- }
- else
- {
- Thread updateDataThread =
- new Thread(new ParameterizedThreadStart(ParameterFormInfoSvc.Instance.RefreshDataList));//绑定数据线程
- updateDataThread.Start("SBQ_FDC");
- }
- isUpdateFormOver = false;
- Thread updateFormThread = new Thread(UpdateThread);//绑定数据线程
- updateFormThread.Start();
- }
- }
- private delegate void UpdateFormDataDelegate();
- private void UpdateThread()
- {
- UpdateFormDataDelegate del = new UpdateFormDataDelegate(UpdateFormData);
- this.BeginInvoke(del);
- }
- private void UpdateFormData()
- {
- #region
- if (IsFirstGridViewLoad)
- {
- try
- {
- ParameterFormInfoSvc svc = ParameterFormInfoSvc.Instance;
- DataTable dataTable = svc.GetDataTable(station);
- //控制光标选中行
- gvWindturbine.DataSource = dataTable;
- gvWindturbine.Rows[0].Selected = false;
- if (gvWindturbine.RowCount > 0 && gvWindturbine.RowCount >= selectRow)
- {
- gvWindturbine.CurrentCell = gvWindturbine[0, selectRow];
- gvWindturbine.Rows[selectRow].Selected = true;
- }
- UpdateFormStat();
- isUpdateFormOver = true;
- }
- catch (Exception e)
- {
- MessageBox.Show("数据更新失败,请检查网络或联系维护人员");
- }
- IsFirstGridViewLoad = false;
- }
- #endregion
- else
- {
- //DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1, 0, 0, 0, 0));
- //long tt = (DateTime.Now.Ticks - startTime.Ticks) / 10000; //除10000调整为13位
- ParameterFormInfoSvc svc = ParameterFormInfoSvc.Instance;
- #region
- //DataTable dataTable = svc.GetDataTable(station);
- ////目前双重循环效率低(约为2s),可以考虑改为list进行绑定
- //// 经过测试绑定效率并没有显著提高
- //for (int i = 0; i < gvWindturbine.RowCount; i++)
- //{
- // DataGridViewRow row = gvWindturbine.Rows[i];
- // string windturbineId = row.Cells[0].Value.ToString();
- // for (int j = 0; j < dataTable.Rows.Count; j++)
- // {
- // if (dataTable.Rows[j]["风机名称"].ToString() == windturbineId)
- // {
- // row.Cells[1].Value = dataTable.Rows[j]["冷却风温度"].ToString();
- // row.Cells[2].Value = dataTable.Rows[j]["有功功率"].ToString();
- // row.Cells[3].Value = dataTable.Rows[j]["液压油温度"].ToString();
- // row.Cells[4].Value = dataTable.Rows[j]["U1绕组温度"].ToString();
- // row.Cells[5].Value = dataTable.Rows[j]["U2绕组温度"].ToString();
- // row.Cells[6].Value = dataTable.Rows[j]["V1绕组温度"].ToString();
- // row.Cells[7].Value = dataTable.Rows[j]["V2绕组温度"].ToString();
- // row.Cells[8].Value = dataTable.Rows[j]["W1绕组温度"].ToString();
- // row.Cells[9].Value = dataTable.Rows[j]["W2绕组温度"].ToString();
- // row.Cells[10].Value = dataTable.Rows[j]["轴承A温度"].ToString();
- // row.Cells[11].Value = dataTable.Rows[j]["轴承B温度"].ToString();
- // row.Cells[12].Value = dataTable.Rows[j]["齿轮箱温度"].ToString();
- // row.Cells[13].Value = dataTable.Rows[j]["齿轮箱轴1温度"].ToString();
- // row.Cells[14].Value = dataTable.Rows[j]["齿轮箱轴2温度"].ToString();
- // row.Cells[15].Value = dataTable.Rows[j]["机舱温度"].ToString();
- // row.Cells[16].Value = dataTable.Rows[j]["环境温度"].ToString();
- // }
- // }
- //}
- IList<GridViewData> dataList = svc.GetInfoData(station).OrderBy(s => Convert.ToInt32(Regex.Replace(s.WindturbineId, "[a-zA-Z]", "").Replace("_", ""))).ToList();
- for (int i = 0; i < gvWindturbine.RowCount; i++)
- {
- DataGridViewRow row = gvWindturbine.Rows[i];
- string windturbineId = row.Cells[0].Value.ToString();
- GridViewData data = dataList.Where(s => s.WindturbineId == windturbineId).FirstOrDefault();
- if (data != null)
- {
- row.Cells[1].Value = data.ColdWindTemperature.ToString("f2");
- row.Cells[2].Value = data.Power.ToString("f2");//"有功功率"
- row.Cells[3].Value = data.OilTemperature.ToString("f2");//"液压油温度"
- row.Cells[4].Value = data.U1CirclingTemperature.ToString("f2");//"U1绕组温度"
- row.Cells[5].Value = data.U2CirclingTemperature.ToString("f2");//"U2绕组温度"
- row.Cells[6].Value = data.V1CirclingTemperature.ToString("f2");//"V1绕组温度"
- row.Cells[7].Value = data.V2CirclingTemperature.ToString("f2");//"V2绕组温度"
- row.Cells[8].Value = data.W1CirclingTemperature.ToString("f2");//"W1绕组温度"
- row.Cells[9].Value = data.W2CirclingTemperature.ToString("f2");//"W2绕组温度"
- row.Cells[10].Value = data.AxisATemperature.ToString("f2");//"轴承A温度"
- row.Cells[11].Value = data.AxisBTemperature.ToString("f2");//"轴承B温度"
- row.Cells[12].Value = data.GearBoxTemperature.ToString("f2");//"齿轮箱温度"
- row.Cells[13].Value = data.GearAxis1Temperature.ToString("f2");//"齿轮箱轴1温度"
- row.Cells[14].Value = data.GearAxis2Temperature.ToString("f2");//"齿轮箱轴2温度"
- row.Cells[15].Value = data.RoomTemperature.ToString("f2");//"机舱温度"
- row.Cells[16].Value = data.RoundTemperature.ToString("f2"); //"环境温度"
- }
-
- }
- #endregion
- isUpdateFormOver = true;
- //long ee = (DateTime.Now.Ticks - startTime.Ticks) / 10000; //除10000调整为13位
- //long re = ee - tt;
- //MessageBox.Show("时间差:" + re);
- }
- }
- private void UpdateFormStat()
- {
- StatInfo info = StatInfoSvc.Instance.GetStatInfoByStation(station);
- //prTop.AllCount = info.LinkCount.ToString();
- //prTop.OnlineCount = info.OnlineCount.ToString();
- //prTop.StandByCount = info.StandByCount.ToString();
- //prTop.FaultCount = info.FaultCount.ToString();
- //prTop.MaintainCount = info.MaintainCount.ToString();
- //prTop.StartCount = info.StartCount.ToString();
- //prTop.OfflineCount = info.OfflineCount.ToString();
- //prTop.StopCount = info.StopCount.ToString();
- //prTop.OnPowerCount = info.OnPowerCount.ToString();
- //prTop.PowerSum = info.PowerAll.ToString();
- //prTop.PowerSumYear = info.PowerByYear.ToString();
- //prTop.PowerSumMonth = info.PowerByMonth.ToString();
- //prTop.PowerSumDay = info.PowerByDay.ToString();
- //prTop.Power = info.Power.ToString();
- //prTop.Speed = info.Speed.ToString();
- info.StationName = "石板泉风电场";
- prTop.BindData(info);
- }
- private void gvWindturbine_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
- {
- selectRow = e.RowIndex;
- }
- public DataTable GetDataTable(string stationName)
- {
- DataTable resultTable = GetDataTableHeaders();
- for (int i = 0; i < 120; i++)
- {
- #region 生成GridView信息
- DataRow row = resultTable.NewRow();
- row["风机名称"] = i.ToString();
- row["冷却风温度"] = i.ToString();
- row["有功功率"] = i.ToString();
- row["液压油温度"] = i.ToString();
- row["U1绕组温度"] = i.ToString();
- row["U2绕组温度"] = i.ToString();
- row["V1绕组温度"] = i.ToString();
- row["V2绕组温度"] = i.ToString();
- row["W1绕组温度"] = i.ToString();
- row["W2绕组温度"] = i.ToString();
- row["轴承A温度"] = i.ToString();
- row["轴承B温度"] = i.ToString();
- row["齿轮箱温度"] = i.ToString();
- row["齿轮箱轴1温度"] = i.ToString();
- row["齿轮箱轴2温度"] = i.ToString();
- row["机舱温度"] = i.ToString();
- row["环境温度"] = i.ToString();
- resultTable.Rows.Add(row);
- #endregion
- }
- return resultTable;
- }
- public DataTable GetDataTableHeaders()
- {
- DataTable dataTable = new DataTable();
- dataTable.Columns.Add("风机名称");
- dataTable.Columns.Add("冷却风温度");
- dataTable.Columns.Add("有功功率");
- dataTable.Columns.Add("液压油温度");
- dataTable.Columns.Add("U1绕组温度");
- dataTable.Columns.Add("U2绕组温度");
- dataTable.Columns.Add("V1绕组温度");
- dataTable.Columns.Add("V2绕组温度");
- dataTable.Columns.Add("W1绕组温度");
- dataTable.Columns.Add("W2绕组温度");
- dataTable.Columns.Add("轴承A温度");
- dataTable.Columns.Add("轴承B温度");
- dataTable.Columns.Add("齿轮箱温度");
- dataTable.Columns.Add("齿轮箱轴1温度");
- dataTable.Columns.Add("齿轮箱轴2温度");
- dataTable.Columns.Add("机舱温度");
- dataTable.Columns.Add("环境温度");
- return dataTable;
- }
- }
- }
|