fleck 客户端_用 Fleck 实现 websocket 通信[通俗易懂]

fleck 客户端_用 Fleck 实现 websocket 通信[通俗易懂]usingDevExpress.XtraBars.Ribbon;usingFleck;usingIMS.DBHelper;usingSystem;usingSystem.Collections.Generic;usingSystem.Data;usingSystem.Linq;usingSystem.Windows.Forms;usingWHC.Framework.Commons;usingRfi…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全家桶1年46,售后保障稳定

usingDevExpress.XtraBars.Ribbon;usingFleck;usingIMS.DBHelper;usingSystem;usingSystem.Collections.Generic;usingSystem.Data;usingSystem.Linq;usingSystem.Windows.Forms;usingWHC.Framework.Commons;usingRfidPositioning.Common;usingIMS.BaseFramework;usingSystem.Threading;namespaceIMS.WfmClient

{public partial classWebMonitor : RibbonForm

{static System.Timers.Timer _refreshDataTimer = newSystem.Timers.Timer();static List _connections = new List();

DataPackage _dataPackage= newDataPackage();

WebSocketServer _wsServer= new WebSocketServer(“ws://0.0.0.0:7181”);publicWebMonitor()

{

InitializeComponent();//启动线程开始从数据库获取页面所需的数据

Thread th = newThread(GetDataForChart);

th.IsBackground= true;

th.Start();//设置监控界面对应的网页

string appPath =AppDomain.CurrentDomain.BaseDirectory;string chartsPath = “file:///” + appPath + “Resources/eCharts/sample.html”;

webBrowser1.Navigate(newUri(chartsPath));//启动webSocket侦听服务

_wsServer.Start(item =>{//与客户端建立连接后触发

item.OnOpen = () =>{

_connections.Add(item);//首次建立连接后立刻发送一次数据,之后由定时器来刷新数据

string jsonData =_dataPackage.ToJson();

_connections.ToList().ForEach(s=>s.Send(jsonData));

};//收到客户端发来的消息后触发

item.OnMessage = message =>{int msg = 0;int.TryParse(message, outmsg);

ClientMessageHandler(msg);

};//客户端关闭连接后触发

item.OnClose = () =>{

_connections.Remove(item);

};

});

}private void FrmIndex_Load(objectsender, EventArgs e)

{//启动定时器

_refreshDataTimer.Enabled = true;

_refreshDataTimer.Interval= 5 * 60 * 1000;

_refreshDataTimer.Elapsed+= newSystem.Timers.ElapsedEventHandler(timersTimer_Elapsed);

_refreshDataTimer.Start();

}private void timersTimer_Elapsed(objectsender, System.Timers.ElapsedEventArgs e)

{

GetDataForChart();string jsonData =_dataPackage.ToJson();

_connections.ToList().ForEach(s=>s.Send(jsonData));

}private void ClientMessageHandler(intmsg)

{if (msg >= 500)

{

SysConfig.FloorNumber= (msg % 100).ToString();this.Invoke(new Action(() =>{

ChildWinManagement.LoadMdiForm(SysConfig.mainform,typeof(frmTracePlayback));

}));

}else if (msg >= 400)

{

SysConfig.FloorNumber= (msg / 10 % 100).ToString();if (msg % 10 == 1)

{

SysConfig.WarningType= “正常”;

}if (msg % 10 == 2)

{

SysConfig.WarningType= “缺失报警”;

}this.Invoke(new Action(() =>{

ChildWinManagement.LoadMdiForm(SysConfig.mainform,typeof(AssetWatchDetail));

}));

}else{

StaticsTypeEnum type=(StaticsTypeEnum)msg;int typeScale = 0;int typeChecks = 0;int typePosition = 0;int typeInstrument = 0;

getStaticsType(out typeScale, out typeChecks, out typePosition, outtypeInstrument);switch(msg)

{case 10:case 11:

SysConfig.ReportByAssetsType= msg == 10 ? false : true;

NavigateToForm(typePosition,typeof(FrmAssetsValueReport));break;case 12:case 13:

SysConfig.ReportByAssetsType= msg == 12 ? false : true;

NavigateToForm(typePosition,typeof(FrmInventoryReport));break;case 30:

webBrowser1.Refresh();break;case 31:this.Invoke(new Action(() =>{

Form form= newSetStaticsType();

form.Owner= this;

form.StartPosition=FormStartPosition.CenterScreen;

form.ShowDialog();

}));break;default:break;

}

}

}private void getStaticsType(out int typeScale, out int typeChecks, out int typePosition, out inttypeInstrument)

{

typeScale= 0;

typeChecks= 0;

typePosition= 0;

typeInstrument= 0;//查询默认选择的统计方式(从数据库获取已设置过的数据)

string strsql = “select * from HT_MonitorStaticsType;”;

DataSet ds=SQLHelper.Query(SQLHelper._connstr, strsql);if (ds != null && ds.Tables != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)

{

typeScale= Convert.ToInt32(ds.Tables[0].Rows[0][“Monitor”].ToString());

typeChecks= Convert.ToInt32(ds.Tables[0].Rows[0][“Checks”].ToString());

typePosition= Convert.ToInt32(ds.Tables[0].Rows[0][“Position”].ToString());

typeInstrument= Convert.ToInt32(ds.Tables[0].Rows[0][“Instrument”].ToString());

}

}private void NavigateToForm(inttype, Type formType)

{if (type == 1) //按月

{

SysConfig.ReportStartDate= DateTime.Now.ToString(“yyyyMM”) + “01”;

SysConfig.ReportEndDate= DateTime.Now.AddMonths(1).ToString(“yyyyMM”) + “01”;

}else{

SysConfig.ReportStartDate= DateTime.Now.AddYears(-1).ToString(“yyyyMMdd”);

SysConfig.ReportEndDate= DateTime.Now.ToString(“yyyyMMdd”);

}this.Invoke(new Action(() =>{

ChildWinManagement.LoadMdiForm(SysConfig.mainform, formType);

}));

}#region 图表数据

classRealTimeMonitor

{public string FloorNo { get; set; }public string MonitorSum { get; set; }public string LossSum { get; set; }public string PositionSum { get; set; }public string LowSum { get; set; }

}classChartAssetWatch

{public string Name { get; set; }public string Value { get; set; }public string StaticsType { get; set; }

}classChartCheck

{public string Name { get; set; }public string Value { get; set; }public string DataType { get; set; }public string StaticsType { get; set; }

}classChartPosition

{public string Name { get; set; }public string Value { get; set; }public string DataType { get; set; }public string StaticsType { get; set; }

}classChartInstrument

{public string Name { get; set; }public string Value { get; set; }public string StaticsType { get; set; }

}classDataPackage

{public ChartOptionForAssetWatch chartOption1 { get; set; }public ChartOptionForAssetWatch chartOption2 { get; set; }public ChartOption chartOption3 { get; set; }public ChartOption chartOption4 { get; set; }public List realTimeMonitors { get; set; }

}voidGetDataForChart()

{int typeScale = 0;int typeChecks = 0;int typePosition = 0;int typeInstrument = 0;

getStaticsType(out typeScale, out typeChecks, out typePosition, outtypeInstrument);

_dataPackage.chartOption1= getChartDataAssetWatch(“HT_ChartAssetWatchDept”, typeScale);

_dataPackage.chartOption2= getChartDataAssetWatch(“HT_ChartAssetWatchType”, typeScale);

_dataPackage.chartOption3= getChartDataCheck(“HT_ChartCheckDept”, typeChecks);

_dataPackage.chartOption4= getChartDataCheck(“HT_ChartCheckType”, typeChecks);

List realTimeMonitors =getRealTimeMonitorData();

_dataPackage.realTimeMonitors=realTimeMonitors;

}

ChartOptionForAssetWatch getChartDataAssetWatch(string tableName, intstaticsType)

{

ChartOptionForAssetWatch chartOption= newChartOptionForAssetWatch();try{string sqlStr = @”SELECT [Name],[Value],[StaticsType] FROM XXX.[dbo].[” + tableName + “] WHERE StaticsType =” + staticsType + “order by Name desc;”;

DataSet ds=SQLHelper.Query(SQLHelper._connstr, sqlStr);

List chartData = ds.Tables[0].ConvertToModel();//截取长度超出5的字符串

chartData.ForEach(item =>{if (item.Name.Length > 5)

{

item.Name= item.Name.Substring(0, 4) + “..”;

}

});//合并数量少的分组

List chartDataNew = new List();

chartDataNew.AddRange(chartData.OrderByDescending(p=> p.Value).Take(5)); //取前5条数据

chartDataNew.ForEach(p =>{ chartData.Remove(p); });

chartDataNew.Add(new ChartAssetWatch { Name = “其他”, Value = chartData.Sum(p =>Convert.ToDecimal(p.Value)).ToString() });

chartOption.tooltip= newtooltip();

chartOption.tooltip.trigger= “item”;

chartOption.tooltip.formatter= “{a}
{b}: {c} ({d}%)”;

chartOption.legend= newlegend();

chartOption.legend.type= “scroll”;

chartOption.legend.orient= “vertical”;

chartOption.legend.left= “0”;

chartOption.legend.top= “0”;

chartOption.legend.data= chartDataNew.Select(p =>p.Name).ToArray();

chartOption.series= new SeriesForAssetWatch[1];

SeriesForAssetWatch series= newSeriesForAssetWatch();

series.name= “”;

series.type= “pie”;

series.radius= new string[] { “60%”, “30%”};

series.center= new string[] { “55%”, “55%”};

series.avoidLabelOverlap= “false”;

series.label= newlabel();

series.label.normal= newnormal();

series.label.normal.show= false;

series.label.normal.position= “center”;

series.label.emphasis= newemphasis();

series.label.emphasis.show= “true”;

series.label.emphasis.textStyle= newtextStyle();

series.label.emphasis.textStyle.fontSize= “20”;

series.labelLine= newlabelLine();

series.labelLine.normal= newnormal();

series.labelLine.normal.show= false;

List d = new List();

chartDataNew.ForEach(p=> { d.Add(new DataNew { name = p.Name, value =p.Value }); });

series.data=d.ToArray();

chartOption.series= new SeriesForAssetWatch[1];

chartOption.series[0] =series;returnchartOption;

}catch { return null; }

}

ChartOption getChartDataCheck(string tableName, intstaticsType)

{

ChartOption chartOption= newChartOption();try{string sqlStr = @”SELECT [Name],[Value],[DataType],[StaticsType] FROM [Lonix_Fas_1].[dbo].[” + tableName + “] WHERE StaticsType =” + staticsType + “order by Name desc;”;

DataSet ds=SQLHelper.Query(SQLHelper._connstr, sqlStr);

List chartData = ds.Tables[0].ConvertToModel();//截取长度超出5的字符串

chartData.ForEach(item =>{if (item.Name.Length > 5)

{

item.Name= item.Name.Substring(0, 4) + “..”;

}

});//合并数量少的分组

List chartInstrumentsNew1 = new List();

chartInstrumentsNew1.AddRange(chartData.Where(p=> p.DataType == “1”).OrderByDescending(p => p.Value).Take(5)); //取前5条数据

chartInstrumentsNew1.ForEach(p =>{ chartData.Remove(p); });

chartInstrumentsNew1.Add(new ChartCheck { Name = “其他”, Value = chartData.Where(p => p.DataType == “1”).Sum(p =>Convert.ToDecimal(p.Value)).ToString() });

List chartInstrumentsNew2 = new List();

chartInstrumentsNew2.AddRange(chartData.Where(p=> p.DataType == “2”).OrderByDescending(p => p.Value).Take(5)); //取前5条数据

chartInstrumentsNew2.ForEach(p =>{ chartData.Remove(p); });

chartInstrumentsNew2.Add(new ChartCheck { Name = “其他”, Value = chartData.Where(p => p.DataType == “2”).Sum(p =>Convert.ToDecimal(p.Value)).ToString() });

chartOption.tooltip= newtooltip();

chartOption.tooltip.trigger= “axis”;

chartOption.tooltip.axisPointer= newaxisPointer();

chartOption.tooltip.axisPointer.type= “shadow”;

chartOption.legend= newlegend();

chartOption.legend.orient= “horizontal”;

chartOption.legend.data= new string[] { “盘亏数”, “已盘数”};

chartOption.grid= newgrid();

chartOption.grid.top= “80”;

chartOption.grid.left= “3%”;

chartOption.grid.right= “6%”;

chartOption.grid.bottom= “30”;

chartOption.grid.containLabel= true;

chartOption.xAxis= newAxis();

chartOption.xAxis.type= “value”;

chartOption.xAxis.axisLabel= newaxisLabel();

chartOption.xAxis.axisLabel.interval= “0”;

chartOption.xAxis.axisLabel.rotate= “0”;

chartOption.yAxis= newAxis();

chartOption.yAxis.type= “category”;

chartOption.yAxis.data= chartInstrumentsNew1.Select(p =>p.Name).ToArray();

chartOption.yAxis.axisLabel= newaxisLabel();

chartOption.yAxis.axisLabel.interval= “0”;

chartOption.yAxis.axisLabel.rotate= “0”;

chartOption.series= new Series[2];

Series s1= newSeries();

s1.name= “盘亏数”;

s1.type= “bar”;

s1.stack= “总量”;

s1.label= newlabel();

s1.label.normal= newnormal();

s1.label.normal.show= true;

s1.label.normal.position= “insideRight”;

s1.data= chartInstrumentsNew1.Select(p =>p.Value).ToArray();

chartOption.series[0] =s1;

Series s2= newSeries();

s2.name= “已盘数”;

s2.type= “bar”;

s2.stack= “总量”;

s2.label= newlabel();

s2.label.normal= newnormal();

s2.label.normal.show= true;

s2.label.normal.position= “insideRight”;

s2.data= chartInstrumentsNew2.Select(p =>p.Value).ToArray();

chartOption.series[1] =s2;returnchartOption;

}catch { return null; }

}

ListgetRealTimeMonitorData()

{string sqlStr = @”select [FloorNo],[MonitorSum],[LossSum],[PositionSum],[LowSum] from XXX.[dbo].[HT_RealTimeMonitor] order by FloorNo desc;”;

DataSet ds=SQLHelper.Query(SQLHelper._connstr, sqlStr);return ds.Tables[0].ConvertToModel();

}#endregion}

}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/213958.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

  • PHP 7.0新增特性详解

    PHP 7.0新增特性详解

    2021年10月15日
  • 时间单位换算表

    时间单位换算表 时间单位换算表   1毫秒=1/1,000秒(s)               1秒=1000毫秒(ms)1微秒(μs)=1/1,000,000秒(s)    1秒=1,000,000微秒(μs)1纳秒=1/1,000,000,000秒(s)       1秒=1,000,000,000纳秒(ns)1皮秒=1/1,000,000,000,000秒(s) 

  • 详解java接口interface

    详解java接口interface引言接口这个词在生活中我们并不陌生。在中国大陆,我们可以将自己的家用电器的插头插到符合它插口的插座上;我们在戴尔,惠普,联想,苹果等品牌电脑之间传输数据时,可以使用U盘进行传输。插座的普适性是

  • ResponseBody浅析[通俗易懂]

    ResponseBody浅析[通俗易懂]@[TOC]ResponseBody浅析欢迎使用Markdown编辑器你好!这是你第一次使用Markdown编辑器所展示的欢迎页。如果你想学习如何使用Markdown编辑器,可以仔细阅读这篇文章,了解一下Markdown的基本语法知识。新的改变我们对Markdown编辑器进行了一些功能拓展与语法支持,除了标准的Markdown编辑器功能,我们增加了如下几点新功能,帮助你用它写博客:…

  • CodeLf–代码变量命名神器

    CodeLf–代码变量命名神器一、CODELF是什么?Codelf通过搜索在线开源平台Github,Bitbucket,GoogleCode,Codeplex,Sourceforge,FedoraProject的项目源码,帮开发者从中找出已有的匹配关键字的变量名,从而帮助开发者命名变量。二、如何使用CODELF?在线地址:https://unbug.github.io/codelf/如图所示:目前,Code

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号