123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Data;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Threading;
- using IntelligentControlForsx.Service.WindturbineControl.Domain.FormInfo;
- using IntelligentControlForsx.Service.WindturbineControl.Domain;
- using Gyee_Control.Svc.Cache;
- using EntityDataSet;
- using IntelligentControlForsx.Service.WindturbineControl.FormInfoSvc;
- using System.Text.RegularExpressions;
- using IntelligentControlForsx.Service.WindturbineControl.Domain.Cmd;
- using Gyee_Control.View;
- using IntelligentControlForsx.ChildForms;
- using log4net;
- using WisdomClient;
- using WisdomClient.data;
- namespace IntelligentControlForsx.MyControls.kz
- {
- public partial class NSS_Control : UserControl
- {
- private ILog logger = LogManager.GetLogger("AppInfoLog");
- private BindingSource formBindingSource = new BindingSource();
- private bool isNeedInsertCheck = true;
- private string projectId = "NSS01_GC";
- IList<EntityDataSet.windturbine> windturbineList = new List<EntityDataSet.windturbine>();
- public void FormDataBind()
- {
- IList<WindturbinePointData> pointDataList = new List<WindturbinePointData>();
- BindingList<WindturbineFormData> dataList = this.formBindingSource.DataSource as BindingList<WindturbineFormData>;
- IList<string> windturbineIdList = dataList.Select(s => s.WindturbineId).ToList();
- for (int i = 0; i < windturbineIdList.Count; i++)
- {
- if (CacheInfo.CacheWindturbineDataDic.ContainsKey(windturbineIdList[i]))
- pointDataList.Add(CacheInfo.CacheWindturbineDataDic[windturbineIdList[i]]);
- }
- for (int i = 0; i < pointDataList.Count; i++)
- {
- var data =
- dataList.Where(s => s.WindturbineId == pointDataList[i].WindturbineName).FirstOrDefault();
- if (data != null)
- {
- data.WindSpeed = pointDataList[i].WindSpeed.ToString("f2");
- data.Power = pointDataList[i].Power.ToString("f2");
- switch (pointDataList[i].Status)
- {
- case WindturbineStatus.Standby:
- data.StatusString = "待机";
- break;
- case WindturbineStatus.OnPower:
- data.StatusString = "上电";
- break;
- case WindturbineStatus.Maintain:
- data.StatusString = "维护";
- break;
- case WindturbineStatus.Fault:
- data.StatusString = "故障";
- break;
- case WindturbineStatus.Start:
- data.StatusString = "启动";
- break;
- case WindturbineStatus.Online:
- data.StatusString = "并网";
- break;
- case WindturbineStatus.Stop:
- data.StatusString = "停机";
- break;
- case WindturbineStatus.Offline:
- data.StatusString = "离线";
- break;
- }
- switch (pointDataList[i].HungType)
- {
- case HungType.UnLock:
- data.HungTypeString = "正常";
- break;
- case HungType.StationCheckLock:
- data.HungTypeString = "场内受累检修";
- break;
- case HungType.StationFaulLockt:
- data.HungTypeString = "场内受累故障";
- break;
- case HungType.StationPowerLineLock:
- data.HungTypeString = "场外受累电网";
- break;
- case HungType.StationWeatherLock:
- data.HungTypeString = "场外受累天气";
- break;
- case HungType.FaultLock:
- data.HungTypeString = "故障检修";
- break;
- case HungType.CheckLock:
- data.HungTypeString = "检修";
- break;
- }
- data.AlternatorSpeed = pointDataList[i].AlternatorSpeed.ToString("f2");
- data.LaminaSpeed = pointDataList[i].LaminaSpeed.ToString("f2");
- data.LimitSpeed = pointDataList[i].LimitSpeed.ToString("f2");
- data.LaminaAngle1 = pointDataList[i].LaminaAngle1.ToString("f2");
- data.LaminaAngle2 = pointDataList[i].LaminaAngle2.ToString("f2");
- data.LaminaAngle3 = pointDataList[i].LaminaAngle3.ToString("f2");
- data.WindAngle = pointDataList[i].WindAngle.ToString("f2");
- data.YawPosition = pointDataList[i].YawPosition.ToString("f2");
- }
- }
- #region 修改风机状态背景色
- for (int i = 0; i < gvWindturbine.RowCount; i++)
- {
- string statusString = gvWindturbine.Rows[i].Cells[4].Value.ToString();
- string windturbineId = gvWindturbine.Rows[i].Cells[1].Value.ToString().Trim();
- DataGridViewRow row = gvWindturbine.Rows[i];
- switch (statusString)
- {
- case "待机":
- row.Cells[1].Style.BackColor = Color.FromArgb(15, 141, 106);
- break;
- case "上电":
- row.Cells[1].Style.BackColor = Color.FromArgb(177, 14, 126);
- break;
- case "维护":
- row.Cells[1].Style.BackColor = Color.FromArgb(204, 83, 51);
- break;
- case "故障":
- row.Cells[1].Style.BackColor = Color.FromArgb(170, 15, 59);
- break;
- case "启动":
- row.Cells[1].Style.BackColor = Color.FromArgb(14, 72, 91);
- break;
- case "并网":
- row.Cells[1].Style.BackColor = Color.FromArgb(15, 135, 170);
- break;
- case "停机":
- row.Cells[1].Style.BackColor = Color.FromArgb(176, 151, 63);
- break;
- case "离线":
- row.Cells[1].Style.BackColor = Color.FromArgb(134, 150, 165);
- break;
- }
- if (gvWindturbine.Rows[i].Cells[5].Value.ToString().Trim() != "正常" && gvWindturbine.Rows[i].Cells[5].Value.ToString().Trim() != "未知")
- {
- row.Cells[5].Style.BackColor = Color.FromArgb(255, 255, 0);
- row.Cells[5].Style.ForeColor = Color.FromArgb(0, 0, 0);
- }
- else
- {
- row.Cells[5].Style.BackColor = row.Cells[6].Style.BackColor;
- row.Cells[5].Style.ForeColor = row.Cells[6].Style.ForeColor;
- }
- }
- #endregion
- isUpdateOverGv = true;
- }
- private delegate void UpdateGridViewDelegate();
- private static BindingList<WindturbineFormData> formDataList = new BindingList<WindturbineFormData>();
- public void BindFormThread()
- {
- UpdateGridViewDelegate del = new UpdateGridViewDelegate(FormDataBind);
- if (gvWindturbine.InvokeRequired)
- {
- gvWindturbine.BeginInvoke(del, new object[] { });
- }
- else
- {
- FormDataBind();
- }
- }
- //数据是否绑定完毕
- private bool isUpdateOverGv = true;
- private void Init(string projectId)
- {
- gvWindturbine.DataSource = null;
- formDataList = new BindingList<WindturbineFormData>();
- IList<WindturbinePointData> pointDataList = new List<WindturbinePointData>();
- IList<string> windturbineIdList =
- windturbineList.Where(s => s.PROJECTID == projectId).ToList().Select(s => s.ID).ToList();
- for (int i = 0; i < windturbineIdList.Count; i++)
- {
- if (CacheInfo.CacheWindturbineDataDic.ContainsKey(windturbineIdList[i]))
- pointDataList.Add(CacheInfo.CacheWindturbineDataDic[windturbineIdList[i]]);
- }
- if (pointDataList.Count <= 0)
- {
- IList<EntityDataSet.windturbine> list = windturbineList.Where(s => s.WINDPOWERSTATIONID == "NSS_FDC" && s.PROJECTID == projectId).ToList().OrderBy(s => Convert.ToInt32(Regex.Replace(s.ID, "[a-zA-Z]", "").Replace("_", ""))).ToList();
- for (int i = 0; i < list.Count; i++)
- {
- WindturbineFormData data = new WindturbineFormData(list[i].ID,
- "0.0",
- "0.0",
- "未知",
- "未知",
- "0.0",
- "0.0",
- "0.0",
- "0.0",
- "0.0",
- "0.0",
- "0.0",
- "0.0"
- );
- formDataList.Add(data);
- }
- formBindingSource.DataSource = formDataList;
- this.gvWindturbine.DataSource = formBindingSource;
- }
- else
- {
- IList<WindturbinePointData> orderList = pointDataList.OrderBy(s => Convert.ToInt32(Regex.Replace(s.WindturbineName, "[a-zA-Z]", "").Replace("_", ""))).ToList();
- for (int i = 0; i < orderList.Count; i++)
- {
- string statusString = "";
- #region 状态转化字符串
- switch (pointDataList[i].Status)
- {
- case WindturbineStatus.Standby:
- statusString = "待机";
- break;
- case WindturbineStatus.OnPower:
- statusString = "上电";
- break;
- case WindturbineStatus.Maintain:
- statusString = "维护";
- break;
- case WindturbineStatus.Fault:
- statusString = "故障";
- break;
- case WindturbineStatus.Start:
- statusString = "启动";
- break;
- case WindturbineStatus.Online:
- statusString = "并网";
- break;
- case WindturbineStatus.Stop:
- statusString = "停机";
- break;
- case WindturbineStatus.Offline:
- statusString = "离线";
- break;
- }
- #endregion
- string hungTypeString = "";
- switch (pointDataList[i].HungType)
- {
- case HungType.UnLock:
- hungTypeString = "正常";
- break;
- case HungType.StationCheckLock:
- hungTypeString = "场内受累检修";
- break;
- case HungType.StationFaulLockt:
- hungTypeString = "场内受累故障";
- break;
- case HungType.StationPowerLineLock:
- hungTypeString = "场外受累电网";
- break;
- case HungType.StationWeatherLock:
- hungTypeString = "场外受累天气";
- break;
- case HungType.FaultLock:
- hungTypeString = "故障检修";
- break;
- case HungType.CheckLock:
- hungTypeString = "检修";
- break;
- }
- WindturbineFormData data = new WindturbineFormData(orderList[i].WindturbineName,
- orderList[i].WindSpeed.ToString("f2"),
- orderList[i].Power.ToString("f2"),
- statusString,
- hungTypeString,
- orderList[i].AlternatorSpeed.ToString("f2"),
- orderList[i].LaminaSpeed.ToString("f2"),
- orderList[i].LimitSpeed.ToString("f2"),
- orderList[i].LaminaAngle1.ToString("f2"),
- orderList[i].LaminaAngle2.ToString("f2"),
- orderList[i].LaminaAngle3.ToString("f2"),
- orderList[i].WindAngle.ToString("f2"),
- orderList[i].YawPosition.ToString("f2")
- );
- formDataList.Add(data);
- }
- formBindingSource.DataSource = formDataList;
- this.gvWindturbine.DataSource = formBindingSource;
- }
- #region 添加勾选列 -首次加载才会添加
- if (isNeedInsertCheck)
- {
- DataGridViewCheckBoxColumn checkColum = new DataGridViewCheckBoxColumn();
- checkColum.HeaderText = "";
- checkColum.Name = "Select";
- checkColum.DataPropertyName = "Select";
- checkColum.ReadOnly = false;
- checkColum.TrueValue = true;
- checkColum.FalseValue = false;
- gvWindturbine.Columns.Insert(0, checkColum);
- isNeedInsertCheck = false;
- }
- gvWindturbine.Columns[0].Width = 50;
- gvWindturbine.Columns[1].Width = 110;
- #endregion
- #region 修改表头
- gvWindturbine.Columns[1].HeaderText = "风机编号";
- gvWindturbine.Columns[2].HeaderText = "风速 m/s";
- gvWindturbine.Columns[3].HeaderText = "功率 kw";
- gvWindturbine.Columns[4].HeaderText = "状态";
- gvWindturbine.Columns[5].HeaderText = "挂牌";
- gvWindturbine.Columns[6].HeaderText = "发电机转速";
- gvWindturbine.Columns[7].HeaderText = "限速值";
- gvWindturbine.Columns[8].HeaderText = "叶轮转速";
- gvWindturbine.Columns[9].HeaderText = "桨叶角度1";
- gvWindturbine.Columns[10].HeaderText = "桨叶角度2";
- gvWindturbine.Columns[11].HeaderText = "桨叶角度3";
- gvWindturbine.Columns[12].HeaderText = "对风角度";
- gvWindturbine.Columns[13].HeaderText = "偏航位置";
- #endregion
- }
- //第一次加载
- public bool firstLoad = true;
- //数据是否刷新完毕
- private bool isUpdateOverData = true;
- private void UpdatePointData()
- {
- IList<string> pList = new List<string>();
- pList.Add("NSS_FDC");
- pList.Add(projectId);
- WindturbinePointDataSvc.UpdatePointDataByStationAndProject(pList);
- isUpdateOverData = true;
- }
- public NSS_Control()
- {
- InitializeComponent();
- using (wisdom_cs_entity ctx = new wisdom_cs_entity())
- {
- windturbineList = ctx.windturbine.Where(s => s.WINDPOWERSTATIONID == "NSS_FDC").ToList();
- }
- IList<HungTypeSelectItemEntity> selectItemList = new List<HungTypeSelectItemEntity>();
- selectItemList.Add(new HungTypeSelectItemEntity(-1, "请选择"));
- selectItemList.Add(new HungTypeSelectItemEntity((int)HungType.CheckLock, "检修"));
- selectItemList.Add(new HungTypeSelectItemEntity((int)HungType.FaultLock, "故障检修"));
- selectItemList.Add(new HungTypeSelectItemEntity((int)HungType.StationCheckLock, "场内受累检修"));
- selectItemList.Add(new HungTypeSelectItemEntity((int)HungType.StationFaulLockt, "场内受累故障"));
- selectItemList.Add(new HungTypeSelectItemEntity((int)HungType.StationPowerLineLock, "场外受累电网"));
- selectItemList.Add(new HungTypeSelectItemEntity((int)HungType.StationWeatherLock, "场外受累天气"));
- this.cbHungReason.DataSource = selectItemList;
- this.cbHungReason.DisplayMember = "HungName";
- this.cbHungReason.ValueMember = "HungType";
- this.cbHungReason.SelectedValue = -1;
- Init("NSS01_GC");
- }
- public void Active()
- {
- timer1.Enabled = true;
- }
- public void DeActive()
- {
- timer1.Enabled = false;
- }
- private void lblProject1_Click(object sender, EventArgs e)
- {
- projectId = "NSS01_GC";
- Init(projectId);
- firstLoad = true;
- //ThreadInfo();
- lblProject1.BackColor = Color.FromArgb(15, 141, 106);
- lblProject2.BackColor = Color.FromArgb(3, 24, 48);
- lblProject3.BackColor = Color.FromArgb(3, 24, 48);
- btnMaintain.Enabled = true;
- btnUnMaintain.Enabled = true;
- btnRest.Enabled = true;
- }
- private void lblProject2_Click(object sender, EventArgs e)
- {
- projectId = "NSS02_GC";
- Init(projectId);
- firstLoad = true;
- //ThreadInfo();
- lblProject1.BackColor = Color.FromArgb(3, 24, 48);
- lblProject2.BackColor = Color.FromArgb(15, 141, 106);
- lblProject3.BackColor = Color.FromArgb(3, 24, 48);
- btnMaintain.Enabled = true;
- btnUnMaintain.Enabled = true;
- btnRest.Enabled = true;
- }
- private void lblProject3_Click(object sender, EventArgs e)
- {
- projectId = "NSS03_GC";
- Init(projectId);
- firstLoad = true;
- // ThreadInfo();
- lblProject1.BackColor = Color.FromArgb(3, 24, 48);
- lblProject2.BackColor = Color.FromArgb(3, 24, 48);
- lblProject3.BackColor = Color.FromArgb(15, 141, 106);
- btnMaintain.Enabled = true;
- btnUnMaintain.Enabled = true;
- btnRest.Enabled = true;
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- if (isUpdateOverData)
- {
- isUpdateOverData = false;
- Thread getDataThread = new Thread(UpdatePointData);//创建数据更新线程
- getDataThread.Start();
- }
- if (isUpdateOverGv)
- {
- isUpdateOverGv = false;
- Thread t = new Thread(BindFormThread);
- t.IsBackground = true;
- t.Start();
- }
- }
- /// <summary>
- /// 已经勾选的风机
- /// </summary>
- private IList<string> isCheckWindturbineIdList = new List<string>();
- //清除所有勾选风机
- private void ClearCheck()
- {
- for (int i = 0; i < gvWindturbine.RowCount; i++)
- {
- gvWindturbine.Rows[i].Cells["Select"].Value = 0;
- }
- }
- private void btnStart_Click(object sender, EventArgs e)
- {
- string cmdDescribe = null;
- cmdDescribe = "正常启动";
- IList<WindturbineCmdInfo> cmdInfoList = new List<WindturbineCmdInfo>();
- for (int i = 0; i < isCheckWindturbineIdList.Count; i++)
- {
- WindturbineCmdInfo info = new WindturbineCmdInfo();
- info.WindturbineId = isCheckWindturbineIdList[i];
- info.StationId = "NSS_FDC";
- info.CmdType = CmdType.Start;
- cmdInfoList.Add(info);
- }
- Confirm confirm = new Confirm("NSS_FDC", cmdInfoList, cmdDescribe);
- confirm.ShowDialog();
- isCheckWindturbineIdList = new List<string>();
- ClearCheck();
- }
- private void btnStop_Click(object sender, EventArgs e)
- {
- string cmdDescribe = null;
- cmdDescribe = "正常停机";
- IList<WindturbineCmdInfo> cmdInfoList = new List<WindturbineCmdInfo>();
- for (int i = 0; i < isCheckWindturbineIdList.Count; i++)
- {
- WindturbineCmdInfo info = new WindturbineCmdInfo();
- info.WindturbineId = isCheckWindturbineIdList[i];
- info.StationId = "NSS_FDC";
- info.CmdType = CmdType.Stop;
- cmdInfoList.Add(info);
- }
- Confirm confirm = new Confirm("NSS_FDC", cmdInfoList, cmdDescribe);
- confirm.ShowDialog();
- isCheckWindturbineIdList = new List<string>();
- ClearCheck();
- }
- private void btnRest_Click(object sender, EventArgs e)
- {
- string cmdDescribe = null;
- cmdDescribe = "正常复位";
- IList<WindturbineCmdInfo> cmdInfoList = new List<WindturbineCmdInfo>();
- for (int i = 0; i < isCheckWindturbineIdList.Count; i++)
- {
- WindturbineCmdInfo info = new WindturbineCmdInfo();
- info.WindturbineId = isCheckWindturbineIdList[i];
- info.StationId = "NSS_FDC";
- info.CmdType = CmdType.Reset;
- cmdInfoList.Add(info);
- }
- Confirm confirm = new Confirm("NSS_FDC", cmdInfoList, cmdDescribe);
- confirm.ShowDialog();
- isCheckWindturbineIdList = new List<string>();
- ClearCheck();
- }
- private void btnMaintain_Click(object sender, EventArgs e)
- {
- string cmdDescribe = null;
- cmdDescribe = "正常维护";
- IList<WindturbineCmdInfo> cmdInfoList = new List<WindturbineCmdInfo>();
- for (int i = 0; i < isCheckWindturbineIdList.Count; i++)
- {
- WindturbineCmdInfo info = new WindturbineCmdInfo();
- info.WindturbineId = isCheckWindturbineIdList[i];
- info.StationId = "NSS_FDC";
- info.CmdType = CmdType.Maintain;
- cmdInfoList.Add(info);
- }
- Confirm confirm = new Confirm("NSS_FDC", cmdInfoList, cmdDescribe);
- confirm.ShowDialog();
- isCheckWindturbineIdList = new List<string>();
- ClearCheck();
- }
- private void btnUnMaintain_Click(object sender, EventArgs e)
- {
- string cmdDescribe = null;
- cmdDescribe = "正常取消维护";
- IList<WindturbineCmdInfo> cmdInfoList = new List<WindturbineCmdInfo>();
- for (int i = 0; i < isCheckWindturbineIdList.Count; i++)
- {
- WindturbineCmdInfo info = new WindturbineCmdInfo();
- info.WindturbineId = isCheckWindturbineIdList[i];
- info.StationId = "NSS_FDC";
- info.CmdType = CmdType.UnMaintain;
- cmdInfoList.Add(info);
- }
- Confirm confirm = new Confirm("NSS_FDC", cmdInfoList, cmdDescribe);
- confirm.ShowDialog();
- isCheckWindturbineIdList = new List<string>();
- ClearCheck();
- }
- private void gvWindturbine_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
- {
- if (e.RowIndex != -1)
- {
- if (e.ColumnIndex == 0)
- {
- string isCheck = gvWindturbine.Rows[e.RowIndex].Cells["Select"].Value == null ? "0" : gvWindturbine.Rows[e.RowIndex].Cells["Select"].Value.ToString();
- string windturbineId = this.gvWindturbine.Rows[e.RowIndex].Cells[1].Value.ToString();
- if (isCheck == "1")
- {
- gvWindturbine.Rows[e.RowIndex].Cells["Select"].Value = 0;
- int count = isCheckWindturbineIdList.Where(s => s == windturbineId).ToList().Count;
- if (count > 0)
- isCheckWindturbineIdList.Remove(windturbineId);
- }
- else
- {
- gvWindturbine.Rows[e.RowIndex].Cells["Select"].Value = 1;
- int count = isCheckWindturbineIdList.Where(s => s == windturbineId).ToList().Count;
- if (count <= 0)
- isCheckWindturbineIdList.Add(windturbineId);
- }
- }
- }
- else
- {
- if (e.ColumnIndex == 0)
- {
- for (int i = 0; i < gvWindturbine.RowCount; i++)
- {
- string isCheck = gvWindturbine.Rows[i].Cells["Select"].Value == null
- ? "0"
- : gvWindturbine.Rows[i].Cells["Select"].Value.ToString();
- string windturbineId = this.gvWindturbine.Rows[i].Cells[1].Value.ToString();
- if (isCheck == "1")
- {
- gvWindturbine.Rows[i].Cells["Select"].Value = 0;
- int count = isCheckWindturbineIdList.Where(s => s == windturbineId).ToList().Count;
- if (count > 0)
- isCheckWindturbineIdList.Remove(windturbineId);
- }
- else
- {
- gvWindturbine.Rows[i].Cells["Select"].Value = 1;
- int count = isCheckWindturbineIdList.Where(s => s == windturbineId).ToList().Count;
- if (count <= 0)
- isCheckWindturbineIdList.Add(windturbineId);
- }
- }
- }
- }
- }
- private void btnHang_Click(object sender, EventArgs e)
- {
- string hungInfo = cbHungReason.SelectedValue.ToString().Trim();
- if (hungInfo == "-1")
- {
- MessageBox.Show("请选择挂牌原因!");
- return;
- }
- HungType type = (HungType)Enum.Parse(typeof(HungType), hungInfo);
- bool isSuccess = WindturbineLock("NSS_FDC", isCheckWindturbineIdList, type);
- if (isSuccess)
- {
- string message = "";
- for (int i = 0; i < isCheckWindturbineIdList.Count; i++)
- {
- message = message + isCheckWindturbineIdList[i] + ",";
- }
- message = "已针对" + message + "风机进行挂牌操作";
- MessageBox.Show(message);
- }
- isCheckWindturbineIdList = new List<string>();
- ClearCheck();
- cbHungReason.SelectedValue = -1;
- }
- private void btnUnHang_Click(object sender, EventArgs e)
- {
- bool isSuccess = WindturbineLock("NSS_FDC", isCheckWindturbineIdList, HungType.UnLock);
- if (isSuccess)
- {
- string message = "";
- for (int i = 0; i < isCheckWindturbineIdList.Count; i++)
- {
- message = message + isCheckWindturbineIdList[i] + ",";
- }
- message = "已针对" + message + "风机进行取消挂牌操作";
- MessageBox.Show(message);
- }
- isCheckWindturbineIdList = new List<string>();
- ClearCheck();
- }
- private void btnLimitPower_Click(object sender, EventArgs e)
- {
- string limitPower = txtPower.Text.Trim();
- if (string.IsNullOrEmpty(limitPower))
- {
- MessageBox.Show("请输入限定功率");
- return;
- }
- else
- {
- double power = 0.0;
- bool IsNumber = Double.TryParse(limitPower, out power);
- if (!IsNumber)
- {
- MessageBox.Show("输入限定功率不合法");
- return;
- }
- else
- {
- string cmdDescribe = null;
- cmdDescribe = "限定功率";
- IList<WindturbineCmdInfo> cmdInfoList = new List<WindturbineCmdInfo>();
- for (int i = 0; i < isCheckWindturbineIdList.Count; i++)
- {
- WindturbineCmdInfo info = new WindturbineCmdInfo();
- info.WindturbineId = isCheckWindturbineIdList[i];
- info.StationId = "NSS_FDC";
- info.CmdType = CmdType.LimitPower;
- cmdInfoList.Add(info);
- }
- Confirm confirm = new Confirm("NSS_FDC", cmdInfoList, cmdDescribe, power);
- confirm.ShowDialog();
- }
- }
- txtPower.Text = "";
- isCheckWindturbineIdList = new List<string>();
- ClearCheck();
- }
- private void btnLimitSpeed_Click(object sender, EventArgs e)
- {
- string limitSpeed = txtSpeed.Text.Trim();
- if (string.IsNullOrEmpty(limitSpeed))
- {
- MessageBox.Show("请输入限定转速");
- return;
- }
- else
- {
- double speed = 0.0;
- bool IsNumber = Double.TryParse(limitSpeed, out speed);
- if (!IsNumber)
- {
- MessageBox.Show("输入限定转速不合法");
- return;
- }
- else
- {
- string cmdDescribe = null;
- cmdDescribe = "限定转速";
- IList<WindturbineCmdInfo> cmdInfoList = new List<WindturbineCmdInfo>();
- for (int i = 0; i < isCheckWindturbineIdList.Count; i++)
- {
- WindturbineCmdInfo info = new WindturbineCmdInfo();
- info.WindturbineId = isCheckWindturbineIdList[i];
- info.StationId = "NSS_FDC";
- info.CmdType = CmdType.LimitSpeed;
- cmdInfoList.Add(info);
- }
- Confirm confirm = new Confirm("NSS_FDC", cmdInfoList, cmdDescribe, speed);
- confirm.ShowDialog();
- }
- }
- txtSpeed.Text = "";
- isCheckWindturbineIdList = new List<string>();
- ClearCheck();
- }
- private bool WindturbineLock(string pStationId, IList<string> windturbineIdList, HungType type)
- {
- bool isSuccess = false;
- try
- {
- user userData = null;
- FingerCheck2 check = new FingerCheck2();
- check.ShowDialog();
- userData = FingerCheck2.checkSuccessUser;
- if (userData != null)
- {
- for (int i = 0; i < windturbineIdList.Count; i++)
- {
- using (wisdom_cs_entity ctx = new wisdom_cs_entity())
- {
- string wId = windturbineIdList[i];
- view_tspoint point = ctx.view_tspoint.Where(s => s.thing_id == wId && s.thing_type == "windturbine" && s.uniform_code == "XDSL").FirstOrDefault();
- if (point != null)
- {
- #region 将挂牌数据写入实时库
- TsPointData tData = new TsPointData();
- tData.tagName = point.id;
- TsData t = new TsData();
- t.doubleValue = (int)type;
- DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
- TimeSpan sp = DateTime.Now.Subtract(dtStart);
- long time = long.Parse(sp.Ticks.ToString().Substring(0, sp.Ticks.ToString().Length - 4));
- t.ts = time;
- tData.tsData = t;
- RestfulClient.writeLatest(tData);
- #endregion
- #region 写入操作日志
- control_log logData = new control_log();
- logData.windturbine_id = windturbineIdList[i];
- logData.station_id = pStationId;
- logData.control_user_id = userData.id;
- logData.send_control_time = DateTime.Now;
- logData.control_type = (int)CmdType.UnHangLock;
- logData.is_send_control_success = true;
- ctx.Entry(logData).State = EntityState.Added;
- int count = ctx.SaveChanges();
- if (count > 0)
- isSuccess = true;
- #endregion
- }
- }
- }
- }
- }
- catch (Exception ex)
- {
- isSuccess = false;
- logger.Error(ex);
- }
- return isSuccess;
- }
- }
- }
|