123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Data;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using EntityDataSet;
- using IntelligentControlForsx.ChildForms;
- using IntelligentControlForsx.Service.ControlLog.Domain;
- using IntelligentControlForsx.Service.WindturbineControl.Domain;
- using IntelligentControlForsx.Service.WindturbineControl.Domain.Cmd;
- using IntelligentControlForsx.Service.WindturbineControl.Domain.FormInfo;
- using IntelligentControlForsx.Service.WindturbineControl.FormInfoSvc;
- using Golden.DotNetSDK.Model.Base;
- using Gyee_Control.Svc.Cache;
- using Gyee_Control.View;
- using log4net;
- using WisdomClient;
- using WisdomClient.data;
- namespace IntelligentControlForsx.MyControls.kz
- {
- public partial class SBQ_Control : UserControl
- {
- private ILog logger = LogManager.GetLogger("AppInfoLog");
- IList<EntityDataSet.windturbine> windturbineList = new List<EntityDataSet.windturbine>();
- private BindingSource formBindingSource = new BindingSource();
- private static BindingList<WindturbineFormData> formDataList = new BindingList<WindturbineFormData>();
- //数据是否刷新完毕
- private bool isUpdateOverData = true;
- //数据是否绑定完毕
- private bool isUpdateOverGv = true;
- private string projectId = "SBQ01_GC";
- private bool isNeedInsertCheck = true;
- /// <summary>
- /// 已经勾选的风机
- /// </summary>
- private IList<string> isCheckWindturbineIdList = new List<string>();
- private int OldSelectRow = -1;
- public SBQ_Control()
- {
- InitializeComponent();
- using (wisdom_cs_entity ctx = new wisdom_cs_entity())
- {
- windturbineList = ctx.windturbine.Where(s => s.WINDPOWERSTATIONID == "SBQ_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("SBQ01_GC");
- }
- public void Active()
- {
- timer1.Enabled = true;
- }
- public void DeActive()
- {
- timer1.Enabled = false;
- }
- private void lblProject1_Click(object sender, EventArgs e)
- {
- Init("SBQ01_GC");
- projectId = "SBQ01_GC";
- lblProject1.BackColor = Color.FromArgb(15, 141, 106);
- lblProject2.BackColor = Color.FromArgb(3, 24, 48);
- lblProject3.BackColor = Color.FromArgb(3, 24, 48);
- lblProject4.BackColor = Color.FromArgb(3, 24, 48);
- isCheckWindturbineIdList = new List<string>();
- btnMaintain.Enabled = true;
- btnUnMaintain.Enabled = true;
- btnRest.Enabled = true;
- }
- private void lblProject2_Click(object sender, EventArgs e)
- {
- Init("SBQ02_GC");
- projectId = "SBQ02_GC";
- lblProject1.BackColor = Color.FromArgb(3, 24, 48);
- lblProject2.BackColor = Color.FromArgb(15, 141, 106);
- lblProject3.BackColor = Color.FromArgb(3, 24, 48);
- lblProject4.BackColor = Color.FromArgb(3, 24, 48);
- isCheckWindturbineIdList = new List<string>();
- btnMaintain.Enabled = true;
- btnUnMaintain.Enabled = true;
- btnRest.Enabled = true;
- }
- private void lblProject3_Click(object sender, EventArgs e)
- {
- Init("SBQ03_GC");
- projectId = "SBQ03_GC";
- lblProject1.BackColor = Color.FromArgb(3, 24, 48);
- lblProject2.BackColor = Color.FromArgb(3, 24, 48);
- lblProject3.BackColor = Color.FromArgb(15, 141, 106);
- lblProject4.BackColor = Color.FromArgb(3, 24, 48);
- isCheckWindturbineIdList = new List<string>();
- btnMaintain.Enabled = false;
- btnUnMaintain.Enabled = false;
- btnRest.Enabled = false;
- }
- private void lblProject4_Click(object sender, EventArgs e)
- {
- Init("SBQ04_GC");
- projectId = "SBQ04_GC";
- lblProject1.BackColor = Color.FromArgb(3, 24, 48);
- lblProject2.BackColor = Color.FromArgb(3, 24, 48);
- lblProject3.BackColor = Color.FromArgb(3, 24, 48);
- lblProject4.BackColor = Color.FromArgb(15, 141, 106);
- isCheckWindturbineIdList = new List<string>();
- btnMaintain.Enabled = false;
- btnUnMaintain.Enabled = false;
- btnRest.Enabled = false;
- }
- 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 = "SBQ_FDC";
- info.CmdType = CmdType.Start;
- cmdInfoList.Add(info);
- }
- Confirm confirm = new Confirm("SBQ_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 = "SBQ_FDC";
- info.CmdType = CmdType.Stop;
- cmdInfoList.Add(info);
- }
- Confirm confirm = new Confirm("SBQ_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 = "SBQ_FDC";
- info.CmdType = CmdType.Reset;
- cmdInfoList.Add(info);
- }
- Confirm confirm = new Confirm("SBQ_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 = "SBQ_FDC";
- info.CmdType = CmdType.Maintain;
- cmdInfoList.Add(info);
- }
- Confirm confirm = new Confirm("SBQ_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 = "SBQ_FDC";
- info.CmdType = CmdType.UnMaintain;
- cmdInfoList.Add(info);
- }
- Confirm confirm = new Confirm("SBQ_FDC", cmdInfoList, cmdDescribe);
- confirm.ShowDialog();
- isCheckWindturbineIdList = new List<string>();
- ClearCheck();
- }
- private delegate void UpdateGridViewDelegate();
- 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();
- }
- }
- 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 == "SBQ_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
- }
- /// <summary>
- /// 后台更新数据
- /// </summary>
- private void UpdatePointData()
- {
- IList<string> pList = new List<string>();
- pList.Add("SBQ_FDC");
- pList.Add(projectId);
- WindturbinePointDataSvc.UpdatePointDataByStationAndProject(pList);
- isUpdateOverData = true;
- }
- public void BindFormThread()
- {
- UpdateGridViewDelegate del = new UpdateGridViewDelegate(FormDataBind);
- if (gvWindturbine.InvokeRequired)
- {
- gvWindturbine.BeginInvoke(del, new object[] { });
- }
- else
- {
- FormDataBind();
- }
- }
- 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;
- }
- if (pointDataList[i].ModelId != "UP105-2000-S")
- data.AlternatorSpeed = pointDataList[i].AlternatorSpeed.ToString("f2");
- else
- data.AlternatorSpeed = (pointDataList[i].AlternatorSpeed*9.55).ToString("f2");
- data.LaminaSpeed = pointDataList[i].LaminaSpeed.ToString("f2");
- data.LimitSpeed = pointDataList[i].LimitSpeed.ToString("f2");
- if (projectId == "SBQ03_GC" || projectId == "SBQ04_GC")
- {
- data.LaminaAngle1 = (pointDataList[i].LaminaAngle1 * 57.3).ToString("f2");
- data.LaminaAngle2 = (pointDataList[i].LaminaAngle2 * 57.3).ToString("f2");
- data.LaminaAngle3 = (pointDataList[i].LaminaAngle3 * 57.3).ToString("f2");
- }
- else
- {
- 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 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 (OldSelectRow != -1)
- //{
- // gvWindturbine.Rows[OldSelectRow].Cells[2].Style.BackColor = gvWindturbine.Rows[OldSelectRow].Cells[0].Style.BackColor;
- // gvWindturbine.Rows[OldSelectRow].Cells[3].Style.BackColor = gvWindturbine.Rows[OldSelectRow].Cells[0].Style.BackColor;
- // gvWindturbine.Rows[OldSelectRow].Cells[4].Style.BackColor = gvWindturbine.Rows[OldSelectRow].Cells[0].Style.BackColor;
- // gvWindturbine.Rows[OldSelectRow].Cells[5].Style.BackColor = gvWindturbine.Rows[OldSelectRow].Cells[0].Style.BackColor;
- // gvWindturbine.Rows[OldSelectRow].Cells[6].Style.BackColor = gvWindturbine.Rows[OldSelectRow].Cells[0].Style.BackColor;
- // gvWindturbine.Rows[OldSelectRow].Cells[7].Style.BackColor = gvWindturbine.Rows[OldSelectRow].Cells[0].Style.BackColor;
- // gvWindturbine.Rows[OldSelectRow].Cells[8].Style.BackColor = gvWindturbine.Rows[OldSelectRow].Cells[0].Style.BackColor;
- // gvWindturbine.Rows[OldSelectRow].Cells[9].Style.BackColor = gvWindturbine.Rows[OldSelectRow].Cells[0].Style.BackColor;
- // gvWindturbine.Rows[OldSelectRow].Cells[10].Style.BackColor = gvWindturbine.Rows[OldSelectRow].Cells[0].Style.BackColor;
- // gvWindturbine.Rows[OldSelectRow].Cells[11].Style.BackColor = gvWindturbine.Rows[OldSelectRow].Cells[0].Style.BackColor;
- // gvWindturbine.Rows[OldSelectRow].Cells[12].Style.BackColor = gvWindturbine.Rows[OldSelectRow].Cells[0].Style.BackColor;
- //}
- //gvWindturbine.Rows[e.RowIndex].Cells[2].Style.BackColor = Color.FromArgb(0, 120, 215);
- //gvWindturbine.Rows[e.RowIndex].Cells[3].Style.BackColor = Color.FromArgb(0, 120, 215);
- //gvWindturbine.Rows[e.RowIndex].Cells[4].Style.BackColor = Color.FromArgb(0, 120, 215);
- //gvWindturbine.Rows[e.RowIndex].Cells[5].Style.BackColor = Color.FromArgb(0, 120, 215);
- //gvWindturbine.Rows[e.RowIndex].Cells[6].Style.BackColor = Color.FromArgb(0, 120, 215);
- //gvWindturbine.Rows[e.RowIndex].Cells[7].Style.BackColor = Color.FromArgb(0, 120, 215);
- //gvWindturbine.Rows[e.RowIndex].Cells[8].Style.BackColor = Color.FromArgb(0, 120, 215);
- //gvWindturbine.Rows[e.RowIndex].Cells[9].Style.BackColor = Color.FromArgb(0, 120, 215);
- //gvWindturbine.Rows[e.RowIndex].Cells[10].Style.BackColor = Color.FromArgb(0, 120, 215);
- //gvWindturbine.Rows[e.RowIndex].Cells[11].Style.BackColor = Color.FromArgb(0, 120, 215);
- //gvWindturbine.Rows[e.RowIndex].Cells[12].Style.BackColor = Color.FromArgb(0, 120, 215);
- //OldSelectRow = e.RowIndex;
- }
- }
- 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 ClearCheck()
- {
- for (int i = 0; i < gvWindturbine.RowCount; i++)
- {
- gvWindturbine.Rows[i].Cells["Select"].Value = 0;
- }
- }
- 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("SBQ_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("SBQ_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 btnUserEdit_Click(object sender, EventArgs e)
- {
- FingerCheck2 check = new FingerCheck2();
- check.ShowDialog();
- user user = FingerCheck2.checkSuccessUser;
- if (user != null)
- {
- UserEdit addFinger = new UserEdit(user);
- addFinger.ShowDialog();
- }
- else
- {
- MessageBox.Show("管理员验证失败");
- }
- }
- private void btnRegister_Click(object sender, EventArgs e)
- {
- MessageBox.Show("管理员验证指纹");
- FingerCheck2 check = new FingerCheck2();
- check.ShowDialog();
- user adminUser = FingerCheck2.checkSuccessUser;
- if (adminUser != null && adminUser.user_name == "admin")
- {
- Register register = new Register();
- register.ShowDialog();
- }
- else
- {
- MessageBox.Show("管理员验证失败");
- }
- }
- private void gvWindturbine_SelectionChanged(object sender, EventArgs e)
- {
- //DataGridView dgv = sender as DataGridView;
- //dgv.ClearSelection();
- }
- 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 = "SBQ_FDC";
- info.CmdType = CmdType.LimitPower;
- cmdInfoList.Add(info);
- }
- Confirm confirm = new Confirm("SBQ_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 = "SBQ_FDC";
- info.CmdType = CmdType.LimitSpeed;
- cmdInfoList.Add(info);
- }
- Confirm confirm = new Confirm("SBQ_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;
- }
- }
- }
|