using DevExpress.XtraEditors; using MQTTnet; using MQTTnet.Client; using MQTTnet.Client.Receiving; using MQTTnet.Protocol; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Web.UI.WebControls; using System.Windows.Forms; using ZJ_BYD.Common; using ZJ_BYD.DB; using ZJ_BYD.ViewModel; namespace ZJ_BYD.UserControls { public partial class ChangeMachineType : XtraUserControl { private int pagesize = 30; //每页显示行数 private int totalCount = 0; //总记录数 private int pageCurrent = 1; //当前页号 public ChangeMachineType() { InitializeComponent(); gridView1.CustomDrawRowIndicator += GridView1_CustomDrawRowIndicator; gridPage1.williamPagerEvent += GridPage1_williamPagerEvent; gridView1.IndicatorWidth = 35; } private void GridMak_Load(object sender, EventArgs e) { BindCombox.BindMachineType(cmbMachineType); GetData(); } private void GetData(int pageCurrent = 1) { var list = DataSource(); this.GridMak.DataSource = list; gridPage1.RefreshPager(pagesize, totalCount, pageCurrent); } /// /// 数据源 /// /// /// private List DataSource() { var selectedMachineType = cmbMachineType.SelectedItem as ListItem; var data = MskCodeHelper.QueryLocalLineStation(); return data.WhereIF(selectedMachineType != null, a => a.MachineTypeCode == selectedMachineType.Value) .ToPageList(pageCurrent, pagesize, ref totalCount); } private void btnsearch_Click(object sender, EventArgs e) { GetData(); } private void btnChangeMachineType_Click(object sender, EventArgs e) { DialogResult dialogResult = XtraMessageBox.Show("切换前请确认机台已切换至手动状态!确认要切换机型吗?", "提示", MessageBoxButtons.OKCancel); if (dialogResult != DialogResult.OK) { return; } var rowsNumber = this.gridView1.GetSelectedRows(); if (rowsNumber.Length <= 0) { XtraMessageBox.Show("请选择数据行!"); return; } var mqttContentVMs = new List(); foreach (var rownumber in rowsNumber) { var data = this.gridView1.GetRow(rownumber) as LineStationVM; if (data.IsUsed) { XtraMessageBox.Show("有机型正在使用中,无法切换!"); return; } else { MqttContentVM mqttContentVM = new MqttContentVM { Id = data.Id, IPC=data.Ipc, Station=data.StationCode, SortIndex = data.SortIndex, Result=false, Category=data.Category }; mqttContentVMs.Add(mqttContentVM); } } if (mqttContentVMs.Count > 0) { var topic = "Wincc_changeMachieType"; string payLoad = JsonConvert.SerializeObject(mqttContentVMs); Program.mqttClient.PublishAsync(topic, payLoad, MqttQualityOfServiceLevel.AtLeastOnce, false); } } /// /// 分页事件 /// /// /// private void GridPage1_williamPagerEvent(int curPage, int pageSize) { pageCurrent = curPage; pagesize = pageSize; GetData(curPage); } /// /// 行号 /// /// /// private void GridView1_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e) { if (e.Info.IsRowIndicator && e.RowHandle > -1) { e.Info.DisplayText = (e.RowHandle + 1).ToString(); } } } }