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}

}

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

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

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • goland 2021激活码_最新在线免费激活[通俗易懂]

    (goland 2021激活码)好多小伙伴总是说激活码老是失效,太麻烦,关注/收藏全栈君太难教程,2021永久激活的方法等着你。IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/100143.htmlS32PGH0SQB-eyJsaWNlbnNlSWQi…

    2022年3月26日
    68
  • Linux下查看CPU型号,内存大小,硬盘空间的命令(详解)

    Linux下查看CPU型号,内存大小,硬盘空间的命令(详解)

    2021年6月2日
    114
  • 什么叫小字辈_小字辈老电影观后感

    什么叫小字辈_小字辈老电影观后感原题链接本题给定一个庞大家族的家谱,要请你给出最小一辈的名单。输入格式:输入在第一行给出家族人口总数 N(不超过 100 000 的正整数) —— 简单起见,我们把家族成员从 1 到 N 编号。随后第二行给出 N 个编号,其中第 i 个编号对应第 i 位成员的父/母。家谱中辈分最高的老祖宗对应的父/母编号为 -1。一行中的数字间以空格分隔。输出格式:首先输出最小的辈分(老祖宗的辈分为 1,以下逐级递增)。然后在第二行按递增顺序输出辈分最小的成员的编号。编号间以一个空格分隔,行首尾不得有多余空格。

    2022年8月8日
    2
  • pycharm设置项目编码「建议收藏」

    pycharm设置项目编码「建议收藏」pycharm设置项目编码1.pycharm-file-setting2.Editor-FileEncodings3.选择自己想要的编码4.点击确定

    2022年8月26日
    4
  • DHT和一致性哈希算法总结

    DHT和一致性哈希算法总结 Hash算法比较重要的考量点有两个:1.单调性(新增或者减少映射节点时,尽量不影响原有映射关系)2.平衡性(尽量均匀分布) 分布式领域常见负载均衡算法:(1)取余法:%n如果有3个节点,Hash之后取模求余 Hash(x)%3,如果加一个节点,则Hash(x)%4。 这种方法带来的问题:1一个cache服务器mdown掉了(在实际应用中必…

    2022年7月27日
    3
  • 【机器学习详解】SMO算法剖析「建议收藏」

    【机器学习详解】SMO算法剖析「建议收藏」本文力求简化SMO的算法思想,毕竟自己理解有限,无奈还是要拿一堆公式推来推去,但是静下心看完本篇并随手推导,你会迎刃而解的。推荐参看SMO原文中的伪代码。**1.SMO概念**===========上一篇博客已经详细介绍了[SVM原理](http://blog.csdn.net/luoshixian099/article/details/51073885),为了方便求解,把原始最优化问题转化成了其对偶问题,因

    2022年6月16日
    31

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

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