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)
上一篇 2025年7月16日 下午5:15
下一篇 2025年7月16日 下午5:43


相关推荐

  • lvs keepalived「建议收藏」

    lvs keepalived「建议收藏」集群是一种并行或分布式系统,该系统包括一个互联的整体计算机集合作为一种单一统一的计算资源使用。通过集群技术。我们可以在付出较低成本的情况下获得在性能可靠性灵活性更高的收益。计算机集群简称集群。是一组计算机系统。通过松散集成的计算软件和硬件连接起来。高度紧密的协作完成计算相关工作。集群是指一组互相独立的计算机,利用高速通信网络组成的一个计算机系统。每个集群节点(每个计算机)都是运行其自己进

    2022年7月23日
    21
  • 如何修改用户名linux_linux修改hostname

    如何修改用户名linux_linux修改hostnameLinux下如何修改用户名(同时修改用户组名和家目录)有时候,由于某些原因,我们可能会需要重命名用户名。我们可以很容易地修改用户名以及对应的家目录和UID。本教程将会讨论这些东西。让我们先从修改用户名开始。修改用户名我们使用usermod来修改用户名。其语法为,$…在linux中如何增加修改删除暂停和冻结用户名在linux中,如何增加、修改、删除、暂停和冻结用户名在linux…

    2025年12月8日
    7
  • Linux上安装JDK

    Linux上安装JDK1 在安装前 需要先关掉 linux 的防火墙查看防火墙状态命令 systemctlsta service2 关闭防火墙 systemctlsto service3 再次查看防火墙 4 切换到 root 用户并输入相应的密码 不然会提示用户权限不够 suroot5 在 usr local 中创建 java 目录 mkdir usr local java6 使用 filezilla 工具连接 linux 主机 IP

    2025年8月2日
    6
  • html怎么添加左侧点虚线,css虚线样式,怎么在css里添加虚线

    html怎么添加左侧点虚线,css虚线样式,怎么在css里添加虚线css 虚线样式 怎么在 css 里添加虚线内容导读 控制 div 线框的是 border 我们可以具体设置四条边的线框是否显示 也可以去设置虚线框的颜色和粗细 线框的设置可以让 div 的块状更加明显 至于是用虚线还是实线 大家可以根据具体情况而定 不知道怎么在 css 里添加虚线的朋友 可以拿本文的代码去看看效果 自己再去修改修改 体会下变化 进而更审核的掌握 css 虚线样式 本文给大家介绍的是 css 虚线样式 给大

    2025年8月29日
    4
  • SSH Secure Shell Client连接Linux时总是会遇到Server responded “connection closed”

    SSH Secure Shell Client连接Linux时总是会遇到Server responded “connection closed”当我们在用 SSHSecureShe 连接 Linux 时输入命令时 网络断开了总是会遇到 Serverrespon connectioncl 我们就操作不了 很是烦人 需要再去关闭软件再重启 Centos 系统 这里有一招可以解决这个烦恼 我们把网络适配器改成自定义模式 选择如下图选项即可 最后再确定 再重启虚拟机

    2026年3月26日
    2
  • java中含中文字符串的编码和解码问题。

    java中含中文字符串的编码和解码问题。1、在Java开发中经常被文字乱码的问题困扰。下面全面解释下字符串的编码和解码。如Stringstr=”中国”编码:byte[]bts=str.getBytes(“编码方式”);//常用编码方式gbk、utf-8、gb2312、iso-8859-1等等。解码:Stringb=newString(bts,”解码方式”);//解码方式对应常用编码方式。2

    2022年7月8日
    26

发表回复

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

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