可以用的版本

1114
nodyang@aliyun.com 5 days ago
parent 8fb29d7ca7
commit adfcd624fa

@ -34,10 +34,9 @@ namespace RfidWeb
public FormMain()
{
cache=Cache.Default;
var currentPlcIp = RfidSetting.Current.PlcIp;
DbInfo.Init(typeof(UserInfo).Assembly);
var rfidSetting = RfidSetting.Current;
InitializeComponent();
if (this.FormBorderStyle == FormBorderStyle.None)
{
@ -67,12 +66,12 @@ namespace RfidWeb
buttons.Clear();
buttons.Add(btnShow);
buttons.Add(btnArgument);
buttons.Add(btnAlarm);
buttons.Add(btnAccount);
buttons.Add(btnMes);
buttons.Add(buttonUpdateLog);
buttons.Add(btnBarCode);
btnShow_Click(new object(), EventArgs.Empty);
}
@ -82,32 +81,32 @@ namespace RfidWeb
/// <summary>移除过期的缓存项</summary>
void TimeState(Object state)
{
labTime.Text = DateTime.Now.ToFullString();
bool isExit = UserManager.IsExit();
this.Invoke(() =>
{
this.Invoke(() =>
labTime.Text = DateTime.Now.ToFullString();
//不存在
if (!isExit)
{
//不存在
if (!isExit)
{
labUser.ForeColor= System.Drawing.SystemColors.Window;
labUser.Text = "未登录(未授权)";
PlcConnect.Instance.Write(HmiPointInfo.Safety_level, int.Parse("0"));
}
else
labUser.ForeColor = System.Drawing.SystemColors.Window;
labUser.Text = "未登录(未授权)";
CacheManager.Act(CacheKeyManager.FormMain, () =>
{
var dto = UserManager.GetUser();
labUser.Text = $"{dto.UserName}({dto.RoleName})";
labUser.ForeColor = Color.FromArgb(21, 182, 173);
}
ThreadPoolX.QueueUserWorkItem(() =>
{
PlcConnect.Instance.Write(HmiPointInfo.Safety_level, int.Parse("0"));
});
});
});
}
else
{
var dto = UserManager.GetUser();
labUser.Text = $"{dto.UserName}({dto.RoleName})";
labUser.ForeColor = Color.FromArgb(21, 182, 173);
}
});
@ -122,38 +121,40 @@ namespace RfidWeb
private void ShowLed()
{
if (cache.ContainsKey(CacheKeyManager.Home)) return;
cache.Set(CacheKeyManager.Home, DateTime.Now, TimeSpan.FromSeconds(10));
bool result =PlcConnect.Instance.ReadPlcType().IsSuccess;
hslLanternSimplePlc.LanternBackground = result ? Color.LimeGreen : Color.Red;
cache.Remove(CacheKeyManager.Home);
CacheManager.Act(CacheKeyManager.Home, () =>
{
bool result = PlcConnect.IsSuccess;
hslLanternSimplePlc.LanternBackground = result ? Color.LimeGreen : Color.Red;
});
}
private void ReadBufLog()
{
if (cache.ContainsKey(CacheKeyManager.ReadBufLog)) return;
cache.Set(CacheKeyManager.ReadBufLog, DateTime.Now, TimeSpan.FromSeconds(10));
var barCodea = HmiPointInfo.GetBufA();
if (barCodea.Item1)
CacheManager.Act(CacheKeyManager.ReadBufLog, () =>
{
readBufService.Insert("A",barCodea.Item2);
}
var barCodeb = HmiPointInfo.GetBufB();
if (barCodeb.Item1)
{
readBufService.Insert("B", barCodeb.Item2);
}
var barCodea = HmiPointInfo.GetBufA();
if (barCodea.Item1)
{
readBufService.Insert("A", barCodea.Item2);
}
var barCodec = HmiPointInfo.GetBufC();
if (barCodec.Item1)
{
readBufService.Insert("C", barCodec.Item2);
}
var barCodeb = HmiPointInfo.GetBufB();
if (barCodeb.Item1)
{
readBufService.Insert("B", barCodeb.Item2);
}
var barCodec = HmiPointInfo.GetBufC();
if (barCodec.Item1)
{
readBufService.Insert("C", barCodec.Item2);
}
});
cache.Remove(CacheKeyManager.ReadBufLog);
}
/// <summary>
@ -164,23 +165,26 @@ namespace RfidWeb
if (UserManager.IsExit())
{
var dic = pointService.GetValueName();
if (cache.ContainsKey(CacheKeyManager.UpdateLog)) return;
cache.Set(CacheKeyManager.UpdateLog, DateTime.Now, TimeSpan.FromSeconds(5));
var plc = PlcConnect.Instance;
var userDto = UserManager.GetUser();
var strings = dic.Keys;
foreach (var se in strings)
CacheManager.Act(CacheKeyManager.UpdateLog, () =>
{
var res = plc.ReadInt32(se);
if (res.IsSuccess)
var dic = pointService.GetValueName();
var plc = PlcConnect.Instance;
var userDto = UserManager.GetUser();
var strings = dic.Keys;
foreach (var se in strings)
{
string name = dic[se];
updateLogService.AddOrUpdateLog(userDto, name, res.Content);
var res = plc.ReadInt32(se);
if (res.IsSuccess)
{
string name = dic[se];
updateLogService.AddOrUpdateLog(userDto, name, res.Content);
}
}
}
cache.Remove(CacheKeyManager.UpdateLog);
});
}
@ -339,14 +343,6 @@ namespace RfidWeb
panContent.Controls.Clear();
panContent.Controls.Add(new FrmBarCodeGridView());
CheckButton(btnBarCode);
// CheckLogin();
//var isLogin = UserManager.IsExit();
//if (isLogin)
//{
//}
}
}
}

@ -1,4 +1,6 @@
using DB.Service;
using ClosedXML.Excel;
using DB.Service;
using HZH_Controls.Controls;
@ -20,13 +22,14 @@ namespace RfidWeb.Frm
public partial class FrmBarCodeGridView : UserControl
{
private ReadBufLogService readBufLogService = new ReadBufLogService();
public FrmBarCodeGridView()
{
InitializeComponent();
this.dataGridView1.Columns["CreateTime"].DefaultCellStyle.Format = "yyyy-MM-dd HH:mm:ss";
var keyValue= new List<KeyValuePair<string, string>>();
var keyValue = new List<KeyValuePair<string, string>>();
keyValue.Add(new KeyValuePair<string, string>("A", "收料1"));
keyValue.Add(new KeyValuePair<string, string>("B", "收料2"));
keyValue.Add(new KeyValuePair<string, string>("C", "废料"));
@ -48,7 +51,8 @@ namespace RfidWeb.Frm
this.ucPagerControl21.ShowSourceChanged +=
new HZH_Controls.Controls.PageControlEventHandler(this.ucPagerControl21_ShowSourceChanged);
this.ucHorizontalList1.SelectedItemEvent += new System.EventHandler(this.ucHorizontalList1_SelectedItemEvent);
this.ucHorizontalList1.SelectedItemEvent +=
new System.EventHandler(this.ucHorizontalList1_SelectedItemEvent);
ucPagerControl21_ShowSourceChanged(new object());
}
@ -70,7 +74,7 @@ namespace RfidWeb.Frm
int index = ucPagerControl21.PageIndex;
var page = readBufLogService.GetPagedList(ucPagerControl21.PageIndex,
ucPagerControl21.PageSize, key,beginTime,endTime);
ucPagerControl21.PageSize, key, beginTime, endTime);
ucPagerControl21.PageCount = page.TotalPages;
this.dataGridView1.DataSource = page.Items;
}
@ -100,11 +104,41 @@ namespace RfidWeb.Frm
Console.WriteLine("目录已创建。");
}
string file = directoryPath + "\\" + DateTime.Now.ToFullString(true) + "_" + val + ".xlsx";
string suiji = Guid.NewGuid().ToString().Substring(0, 5);
string file = directoryPath + "\\" + DateTime.Now.ToString("yyyyMMddHHmmss") + suiji + "_" + val + ".xlsx";
var dt = readBufLogService.GetDtaTable(key, beginTime, endTime);
ExcelHelper.Export(dt,val,file);
ExportDataTableToExcel(dt, file);
MessageBox.Show("OK");
}
void ExportDataTableToExcel(DataTable table, string filePath)
{
using (var workbook = new XLWorkbook())
{
table.TableName = "Shell1";
var worksheet = workbook.Worksheets.Add(table.TableName);
// 写入列头
for (int col = 0; col < table.Columns.Count; col++)
{
worksheet.Cell(1, col + 1).Value = table.Columns[col].ColumnName;
}
// 写入行数据
for (int row = 0; row < table.Rows.Count; row++)
{
for (int col = 0; col < table.Columns.Count; col++)
{
worksheet.Cell(row + 2, col + 1).Value = table.Rows[row][col].ToString();
}
}
// 保存为文件
workbook.SaveAs(filePath);
}
}
}
}

@ -28,11 +28,11 @@
/// </summary>
private void InitializeComponent()
{
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle6 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle7 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle8 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle9 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle10 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle5 = new System.Windows.Forms.DataGridViewCellStyle();
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.dataGridView2 = new System.Windows.Forms.DataGridView();
this.dataGridViewTextBoxColumn1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
@ -63,6 +63,7 @@
this.hslA3 = new HslControls.HslLanternSimple();
this.hslA2 = new HslControls.HslLanternSimple();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.btnStatus = new System.Windows.Forms.Button();
this.panel3 = new System.Windows.Forms.Panel();
this.hslLabelCombofeedingMotorSpeed = new HslControls.HslLabelCombo();
this.hslLabelComboReceiving = new HslControls.HslLabelCombo();
@ -79,7 +80,6 @@
this.hslB9 = new HslControls.HslLanternSimple();
this.hslB10 = new HslControls.HslLanternSimple();
this.hslB11 = new HslControls.HslLanternSimple();
this.btnStatus = new System.Windows.Forms.Button();
this.tableLayoutPanel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView2)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
@ -110,37 +110,37 @@
this.dataGridView2.AllowUserToAddRows = false;
this.dataGridView2.AllowUserToDeleteRows = false;
this.dataGridView2.ColumnHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.Single;
dataGridViewCellStyle6.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle6.BackColor = System.Drawing.SystemColors.Control;
dataGridViewCellStyle6.Font = new System.Drawing.Font("宋体", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
dataGridViewCellStyle6.ForeColor = System.Drawing.SystemColors.WindowText;
dataGridViewCellStyle6.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle6.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle6.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
this.dataGridView2.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle6;
dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Control;
dataGridViewCellStyle1.Font = new System.Drawing.Font("宋体", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText;
dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
this.dataGridView2.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1;
this.dataGridView2.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView2.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.dataGridViewTextBoxColumn1,
this.dataGridViewTextBoxColumn2});
dataGridViewCellStyle7.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle7.BackColor = System.Drawing.Color.Red;
dataGridViewCellStyle7.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
dataGridViewCellStyle7.ForeColor = System.Drawing.SystemColors.ControlText;
dataGridViewCellStyle7.SelectionBackColor = System.Drawing.Color.Red;
dataGridViewCellStyle7.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle7.WrapMode = System.Windows.Forms.DataGridViewTriState.False;
this.dataGridView2.DefaultCellStyle = dataGridViewCellStyle7;
dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle2.BackColor = System.Drawing.Color.Red;
dataGridViewCellStyle2.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
dataGridViewCellStyle2.ForeColor = System.Drawing.SystemColors.ControlText;
dataGridViewCellStyle2.SelectionBackColor = System.Drawing.Color.Red;
dataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle2.WrapMode = System.Windows.Forms.DataGridViewTriState.False;
this.dataGridView2.DefaultCellStyle = dataGridViewCellStyle2;
this.dataGridView2.Dock = System.Windows.Forms.DockStyle.Fill;
this.dataGridView2.Location = new System.Drawing.Point(458, 3);
this.dataGridView2.Name = "dataGridView2";
this.dataGridView2.ReadOnly = true;
dataGridViewCellStyle8.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle8.BackColor = System.Drawing.Color.Red;
dataGridViewCellStyle8.Font = new System.Drawing.Font("宋体", 15F);
dataGridViewCellStyle8.ForeColor = System.Drawing.Color.White;
dataGridViewCellStyle8.SelectionBackColor = System.Drawing.Color.Red;
dataGridViewCellStyle8.SelectionForeColor = System.Drawing.Color.White;
this.dataGridView2.RowsDefaultCellStyle = dataGridViewCellStyle8;
dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle3.BackColor = System.Drawing.Color.Yellow;
dataGridViewCellStyle3.Font = new System.Drawing.Font("宋体", 15F);
dataGridViewCellStyle3.ForeColor = System.Drawing.Color.Black;
dataGridViewCellStyle3.SelectionBackColor = System.Drawing.Color.Yellow;
dataGridViewCellStyle3.SelectionForeColor = System.Drawing.Color.Black;
this.dataGridView2.RowsDefaultCellStyle = dataGridViewCellStyle3;
this.dataGridView2.RowTemplate.Height = 23;
this.dataGridView2.Size = new System.Drawing.Size(449, 270);
this.dataGridView2.TabIndex = 1;
@ -165,14 +165,14 @@
//
this.dataGridView1.AllowUserToAddRows = false;
this.dataGridView1.AllowUserToDeleteRows = false;
dataGridViewCellStyle9.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle9.BackColor = System.Drawing.SystemColors.Control;
dataGridViewCellStyle9.Font = new System.Drawing.Font("宋体", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
dataGridViewCellStyle9.ForeColor = System.Drawing.SystemColors.WindowText;
dataGridViewCellStyle9.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle9.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle9.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
this.dataGridView1.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle9;
dataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle4.BackColor = System.Drawing.SystemColors.Control;
dataGridViewCellStyle4.Font = new System.Drawing.Font("宋体", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
dataGridViewCellStyle4.ForeColor = System.Drawing.SystemColors.WindowText;
dataGridViewCellStyle4.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle4.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle4.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
this.dataGridView1.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle4;
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.al,
@ -181,13 +181,13 @@
this.dataGridView1.Location = new System.Drawing.Point(3, 3);
this.dataGridView1.Name = "dataGridView1";
this.dataGridView1.ReadOnly = true;
dataGridViewCellStyle10.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle10.BackColor = System.Drawing.Color.Red;
dataGridViewCellStyle10.Font = new System.Drawing.Font("宋体", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
dataGridViewCellStyle10.ForeColor = System.Drawing.Color.White;
dataGridViewCellStyle10.SelectionBackColor = System.Drawing.Color.Red;
dataGridViewCellStyle10.SelectionForeColor = System.Drawing.Color.White;
this.dataGridView1.RowsDefaultCellStyle = dataGridViewCellStyle10;
dataGridViewCellStyle5.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle5.BackColor = System.Drawing.Color.Red;
dataGridViewCellStyle5.Font = new System.Drawing.Font("宋体", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
dataGridViewCellStyle5.ForeColor = System.Drawing.Color.White;
dataGridViewCellStyle5.SelectionBackColor = System.Drawing.Color.Red;
dataGridViewCellStyle5.SelectionForeColor = System.Drawing.Color.White;
this.dataGridView1.RowsDefaultCellStyle = dataGridViewCellStyle5;
this.dataGridView1.RowTemplate.Height = 23;
this.dataGridView1.Size = new System.Drawing.Size(449, 270);
this.dataGridView1.TabIndex = 0;
@ -486,6 +486,16 @@
this.groupBox2.TabStop = false;
this.groupBox2.Text = "料盘侧(收料2)";
//
// btnStatus
//
this.btnStatus.BackColor = System.Drawing.Color.Chartreuse;
this.btnStatus.Location = new System.Drawing.Point(252, 92);
this.btnStatus.Name = "btnStatus";
this.btnStatus.Size = new System.Drawing.Size(112, 28);
this.btnStatus.TabIndex = 32;
this.btnStatus.Text = "状态";
this.btnStatus.UseVisualStyleBackColor = false;
//
// panel3
//
this.panel3.BackColor = System.Drawing.SystemColors.ButtonFace;
@ -653,16 +663,6 @@
this.hslB11.TabIndex = 12;
this.hslB11.Text = "hslLanternSimple1";
//
// btnStatus
//
this.btnStatus.BackColor = System.Drawing.Color.Chartreuse;
this.btnStatus.Location = new System.Drawing.Point(252, 92);
this.btnStatus.Name = "btnStatus";
this.btnStatus.Size = new System.Drawing.Size(112, 28);
this.btnStatus.TabIndex = 32;
this.btnStatus.Text = "状态";
this.btnStatus.UseVisualStyleBackColor = false;
//
// UserAlarmShow
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);

@ -23,6 +23,7 @@ using Tool;
using Tool.Model;
using HslCommunication.LogNet;
using Chloe;
using DocumentFormat.OpenXml.Wordprocessing;
namespace RfidWeb.Frm
{
@ -46,24 +47,31 @@ namespace RfidWeb.Frm
void TimeState(Object state)
{
if(cache.ContainsKey("UserAlarmShow")) return;
cache.Set("UserAlarmShow", DateTime.Now.ToString(), TimeSpan.FromSeconds(20));
stopwatc.Restart();
var stateText = HmiPointInfo.GetStateText();
this.Invoke(() =>
CacheManager.Act("UserAlarmShow", () =>
{
btnStatus.Text = stateText;
var isSuccess = PlcConnect.IsSuccess;
if (isSuccess)
{
stopwatc.Restart();
var stateText = HmiPointInfo.GetStateText();
this.Invoke(() => { btnStatus.Text = stateText; });
FillAlarmGrid();
FillPromptGrid();
FillAlartLed();
FillhslLabelCombo();
stopwatc.Stop();
logNet.WriteInfo("首页运行时间:" + stopwatc.Elapsed.TotalMilliseconds);
}
else
{
this.Invoke(() => { btnStatus.Text = "plc连接失败"; });
logNet.WriteWarn("plc连接失败");
}
});
FillAlarmGrid();
FillPromptGrid();
FillAlartLed();
FillhslLabelCombo();
stopwatc.Stop();
cache.Remove("UserAlarmShow");
logNet.WriteInfo("运行时间:"+stopwatc.Elapsed.TotalMilliseconds);
}
/// <summary>
@ -334,9 +342,9 @@ namespace RfidWeb.Frm
{
foreach (var simple in simples)
{
if (simple.LanternBackground != Color.Red)
if (simple.LanternBackground != System.Drawing.Color.Red)
{
simple.LanternBackground = Color.Red;
simple.LanternBackground = System.Drawing.Color.Red;
}
}
}
@ -344,9 +352,9 @@ namespace RfidWeb.Frm
{
foreach (var simple in simples)
{
if (simple.LanternBackground != Color.Chartreuse)
if (simple.LanternBackground != System.Drawing.Color.Chartreuse)
{
simple.LanternBackground = Color.Chartreuse;
simple.LanternBackground = System.Drawing.Color.Chartreuse;
}
}

@ -225,7 +225,6 @@
<Compile Include="Tool\BaseManager.cs" />
<Compile Include="Tool\HimAlarmManager.cs" />
<Compile Include="Tool\PromptAlarmManager.cs" />
<Compile Include="Tool\TestFactory.cs" />
<Compile Include="Tool\UserManager.cs" />
<EmbeddedResource Include="FormLogin.resx">
<DependentUpon>FormLogin.cs</DependentUpon>

@ -1,39 +0,0 @@
using DB.Dto;
using DB.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualBasic.ApplicationServices;
namespace RfidWeb
{
public class TestFactory
{
public static UserDto dto;
public static UserDto TestUser()
{
if (dto != null)
{
return dto;
}
long id = 7254397083167133696;
var userInfo = new UserService().Query(id);
UserDto user = new UserDto
{
Id = userInfo.ID,
UserName = userInfo.UserName,
RoleId = userInfo.RoleId,
RoleName ="管理员",
RoleLevel =1
};
dto = user;
return user;
}
}
}

@ -5,14 +5,14 @@ namespace Tool
{
public class CacheManager
{
public static void Act(string key,Action action)
{
ICache _cache=Cache.Default;
if(_cache.ContainsKey(key)) return;
try
{
_cache.Set(key, TimeSpan.FromSeconds(300));
_cache.Set(key, TimeSpan.FromSeconds(3000));
action();
}
finally

@ -1,243 +1 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
namespace Tool
{
public class ExcelHelper
{
/// <summary>
/// Excel行高Height的单位是1/20个点。例设置高度为25个点
/// </summary>
private static short rowHeight = 25 * 20;
#region 导出Excel
#region 导出
/// <summary>
/// 导出
/// </summary>
/// <param name="dt">数据源</param>
/// <param name="strHeader">列名</param>
/// <param name="fileName">绝对路径</param>
/// <param name="sheetName">sheet页名</param>
public static void Export(DataTable dt, string strHeader, string fileName, string sheetName = "Sheet1")
{
// 使用 NPOI 组件导出 Excel 文件
//XSSFWorkbook:是操作Excel2007的版本扩展名是.xlsx
XSSFWorkbook workbook = new XSSFWorkbook();
//HSSFWorkbook:是操作Excel2003以前包括2003的版本扩展名是.xls
//HSSFWorkbook workbook = new HSSFWorkbook();
//创建Sheet
ISheet sheet = workbook.CreateSheet(sheetName);
//对列名拆分
string[] strArry = strHeader.Split(',');
//设置单元格样式
ICellStyle style = SetCellStyle(workbook);
//创建表格
NPOICreateTable(dt, strArry, sheet, style, 0);
// 将 Excel 文件保存到磁盘
NPOISaveFile(workbook, fileName);
// 释放资源
//workbook.Dispose();
}
#endregion
#region 自定义框架,导出
/// <summary>
/// 自定义顶部,导出
/// </summary>
/// <param name="dt">数据源</param>
/// <param name="strArry">拆分后列名</param>
/// <param name="fileName">绝对路径,路径+文件名+后缀</param>
/// <param name="num">新一行索引,开始</param>
/// <param name="workbook"></param>
/// <param name="sheet"></param>
public static void Export(DataTable dt, string[] strArry, string fileName, int num, XSSFWorkbook workbook, ISheet sheet)
{
//设置单元格样式
ICellStyle style = SetCellStyle(workbook);
//创建表格
NPOICreateTable(dt, strArry, sheet, style, num);
// 将 Excel 文件保存到磁盘
NPOISaveFile(workbook, fileName);
// 释放资源
//workbook.Dispose();
}
#endregion
#endregion
#region 保存文件
private static string NPOISaveFile(XSSFWorkbook workbook, string fileName)
{
try
{
// 将 Excel 文件保存到磁盘
using (FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write))
{
workbook.Write(fs);
}
return "";
}
catch (Exception err)
{
return err.Message;
}
}
#endregion
#region 创建表格
/// <summary>
/// 创建表格
/// </summary>
/// <param name="dt">数据源</param>
/// <param name="strArry">拆分后的列名</param>
/// <param name="sheet">Sheet页</param>
/// <param name="style">样式</param>
/// <param name="num">行索引</param>
private static void NPOICreateTable(DataTable dt, string[] strArry, ISheet sheet, ICellStyle style, int num)
{
IRow row = null;//声明行
#region 创建列名
//在索引 num 的位置 创建一行
row = sheet.CreateRow(num);
row.Height = rowHeight;//设置行高
//循环列名数组,创建单元格并赋值、样式
for (int i = 0; i < strArry.Length; i++)
{
row.CreateCell(i).SetCellValue(strArry[i]);
row.GetCell(i).CellStyle = style;
}
#endregion
#region 创建行
//循环数据源 创建行
for (int i = 0; i < dt.Rows.Count; i++)
{
//创建行
row = sheet.CreateRow(num + 1);
row.Height = rowHeight;//设置行高
num++;//行索引自增
//循环数据源列集合,创建单元格
for (int j = 0; j < dt.Columns.Count; j++)
{
string ValueType = "";//值类型
string Value = "";//值
//类型 和 值,赋值
if (dt.Rows[i][j].ToString() != null)
{
ValueType = dt.Rows[i][j].GetType().ToString();
Value = dt.Rows[i][j].ToString();
}
//根据不同数据类型,对数据处理。处理后创建单元格并赋值 和 样式
switch (ValueType)
{
case "System.String"://字符串类型
row.CreateCell(j).SetCellValue(Value);
break;
case "System.DateTime"://日期类型
System.DateTime dateV;
System.DateTime.TryParse(Value, out dateV);
row.CreateCell(j).SetCellValue(dateV.ToString("yyyy-MM-dd"));
break;
case "System.Boolean"://布尔型
bool boolV = false;
bool.TryParse(Value, out boolV);
row.CreateCell(j).SetCellValue(boolV);
break;
case "System.Int16"://整型
case "System.Int32":
case "System.Int64":
case "System.Byte":
int intV = 0;
int.TryParse(Value, out intV);
row.CreateCell(j).SetCellValue(intV);
break;
case "System.Decimal"://浮点型
case "System.Double":
double doubV = 0;
double.TryParse(Value, out doubV);
row.CreateCell(j).SetCellValue(doubV);
break;
case "System.DBNull"://空值处理
row.CreateCell(j).SetCellValue("");
break;
default:
row.CreateCell(j).SetCellValue("");
break;
}
row.GetCell(j).CellStyle = style;
//设置宽度
//sheet.SetColumnWidth(j, (Value.Length + 10) * 256);
}
}
#endregion
//循环列名数组,多所有列 设置 自动列宽
for (int i = 0; i < strArry.Length; i++)
{
sheet.AutoSizeColumn(i);
}
}
#endregion
#region 设置单元格样式
public static ICellStyle SetCellStyle(XSSFWorkbook workbook)
{
#region 单元格样式
//创建一个样式
ICellStyle style = workbook.CreateCellStyle();
style.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;//水平对齐
style.VerticalAlignment = VerticalAlignment.Center;//垂直对齐
style.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;//下边框为细线边框
style.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;//左边框
style.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;//上边框
style.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;//右边框
#endregion
return style;
}
#endregion
}
}


Binary file not shown.

@ -0,0 +1,414 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using HslCommunication;
namespace Tool.Model
{
public class HmiPointInfo
{
/// <summary>
/// DInt 供料电机速度
/// </summary>
public static readonly string feeding_motor_speed = "feeding_motor_speed";
public static Int32 GetFeedingMotorSpeed => GetValue(feeding_motor_speed);
/// <summary>
/// DInt 层合电机速度
/// </summary>
public static readonly string Laminated_motor_speed = "Laminated_motor_speed";
public static Int32 GetLaminatedMotorSpeed => GetValue(Laminated_motor_speed);
/// <summary>
/// DInt 毛毡带电机速度
/// </summary>
public static readonly string Felt_belt_motor_speed = "Felt_belt_motor_speed";
public static Int32 GetFeltBeltMotorSpeed => GetValue(Felt_belt_motor_speed);
/// <summary>
/// DInt 收料电机1速度
/// </summary>
public static readonly string Receiving_Electric_motor_speed = "Receiving_Electric_motor_speed";
public static Int32 GeReceivingMotorSpeed => GetValue(Receiving_Electric_motor_speed);
/// <summary>
/// 层合生产数量
/// </summary>
public static readonly string Product_counter2 = "Product_counter2";
public static Int32 GetProduct_counter2 => GetValue(Product_counter2);
/// <summary>
/// 裁切1生产数量
/// </summary>
public static readonly string CQ_Chip1_counter = "CQ_Chip1_counter";
public static Int32 GetCQ_Chip1_counter => GetValue(CQ_Chip1_counter);
/// <summary>
/// 裁切2生产数量
/// </summary>
public static readonly string CQ_Chip2_counter = "CQ_Chip2_counter";
public static Int32 GetCQ_Chip2_counter => GetValue(CQ_Chip2_counter);
/// <summary>
/// 裁刀1温度
/// </summary>
public static readonly string QDWD1SS = "QDWD1SS";
public static Int32 GetQDWD1SS => GetValue(QDWD1SS);
/// <summary>
/// 裁刀1温度
/// </summary>
public static readonly string QDWD2SS = "QDWD2SS";
public static Int32 GetQDWD2SS => GetValue(QDWD2SS);
/// <summary>
/// 设备内部温度
/// </summary>
public static readonly string SWSS = "SWSS";
public static Int32 GetSWSS => GetValue(SWSS);
private static Int32 GetValue(string key)
{
var plc = PlcConnect.Instance;
var result = plc.ReadInt32(key);
return result.IsSuccess ? result.Content : 0;
}
private static Boolean GetBoolValue(string key)
{
var plc = PlcConnect.Instance;
var result = plc.ReadBool(key);
return result.Content;
}
public static readonly string CUTTING_SET_TEMPERATURE1_1 = "CUTTING_SET_TEMPERATURE1_1";
public static Int32 GetCUTTING_SET_TEMPERATURE1_1 => GetValue(CUTTING_SET_TEMPERATURE1_1);
public static readonly string CUTTING_SET_TEMPERATURE1_2 = "CUTTING_SET_TEMPERATURE1_2";
public static Int32 GetCUTTING_SET_TEMPERATURE1_2 => GetValue(CUTTING_SET_TEMPERATURE1_2);
public static readonly string CUTTING_SET_TEMPERATURE1_3 = "CUTTING_SET_TEMPERATURE1_3";
public static Int32 GetCUTTING_SET_TEMPERATURE1_3 => GetValue(CUTTING_SET_TEMPERATURE1_3);
public static readonly string CUTTING_SET_TEMPERATURE1_4 = "CUTTING_SET_TEMPERATURE1_4";
public static Int32 GetCUTTING_SET_TEMPERATURE1_4 => GetValue(CUTTING_SET_TEMPERATURE1_4);
public static readonly string CUTTING_SET_TEMPERATURE2_1 = "CUTTING_SET_TEMPERATURE2_1";
public static Int32 GetCUTTING_SET_TEMPERATURE2_1 => GetValue(CUTTING_SET_TEMPERATURE2_1);
public static readonly string CUTTING_SET_TEMPERATURE2_2 = "CUTTING_SET_TEMPERATURE2_2";
public static Int32 GetCUTTING_SET_TEMPERATURE2_2 => GetValue(CUTTING_SET_TEMPERATURE2_2);
public static readonly string CUTTING_SET_TEMPERATURE2_3 = "CUTTING_SET_TEMPERATURE2_3";
public static Int32 GetCUTTING_SET_TEMPERATURE2_3 => GetValue(CUTTING_SET_TEMPERATURE2_3);
public static readonly string CUTTING_SET_TEMPERATURE2_4 = "CUTTING_SET_TEMPERATURE2_4";
public static Int32 GetCUTTING_SET_TEMPERATURE2_4 => GetValue(CUTTING_SET_TEMPERATURE2_4);
public static readonly string CUTTING_SET_TIME1_1 = "CUTTING_SET_TIME1_1";
public static Int32 GetCUTTING_SET_TIME1_1 => GetValue(CUTTING_SET_TIME1_1);
public static readonly string CUTTING_SET_TIME1_2 = "CUTTING_SET_TIME1_2";
public static Int32 GetCUTTING_SET_TIME1_2 => GetValue(CUTTING_SET_TIME1_2);
public static readonly string CUTTING_SET_TIME1_3 = "CUTTING_SET_TIME1_3";
public static Int32 GetCUTTING_SET_TIME1_3 => GetValue(CUTTING_SET_TIME1_3);
public static readonly string CUTTING_SET_TIME1_4 = "CUTTING_SET_TIME1_4";
public static Int32 GetCUTTING_SET_TIME1_4 => GetValue(CUTTING_SET_TIME1_4);
public static readonly string CUTTING_SET_TIME2_1 = "CUTTING_SET_TIME2_1";
public static Int32 GetCUTTING_SET_TIME2_1 => GetValue(CUTTING_SET_TIME2_1);
public static readonly string CUTTING_SET_TIME2_2 = "CUTTING_SET_TIME2_2";
public static Int32 GetCUTTING_SET_TIME2_2 => GetValue(CUTTING_SET_TIME2_2);
public static readonly string CUTTING_SET_TIME2_3 = "CUTTING_SET_TIME2_3";
public static Int32 GetCUTTING_SET_TIME2_3 => GetValue(CUTTING_SET_TIME2_3);
public static readonly string CUTTING_SET_TIME2_4 = "CUTTING_SET_TIME2_4";
public static Int32 GetCUTTING_SET_TIME2_4 => GetValue(CUTTING_SET_TIME2_4);
/// <summary>
/// 计划的数量
/// </summary>
public static readonly string Product_counter_CH = "Product_counter_CH";
/// <summary>
/// 安全级别
/// </summary>
public static readonly string Safety_level = "Safety_level";
/// <summary>
/// 1盘料选择0卷料选择
/// </summary>
public static readonly string CH_Mode_selection = "CH_Mode_selection";
/// <summary>
/// 裁刀1屏蔽
/// </summary>
public static readonly string HMI_Cutting1_pass = "HMI_Cutting1_pass";
/// <summary>
/// 裁刀2屏蔽
/// </summary>
public static readonly string HMI_Cutting2_pass = "HMI_Cutting2_pass";
/// <summary>
/// 裁刀1屏蔽
/// </summary>
public static readonly string Cutting1_passad = "Cutting1_passad";
/// <summary>
/// 裁刀2屏蔽
/// </summary>
public static readonly string Cutting2_passad = "Cutting2_passad";
/// <summary>
/// 切刀1到达使用上限清除计数按钮
/// </summary>
public static readonly string CQ_QD1_counter_reset = "CQ_QD1_counter_reset";
/// <summary>
/// 切刀2到达使用上限清除计数按钮
/// </summary>
public static readonly string CQ_QD2_counter_reset = "CQ_QD2_counter_reset";
/// <summary>
/// 毛毡带到达使用上限清除计数按钮
/// </summary>
public static readonly string CQ_MZD_counter_reset = "CQ_MZD_counter_reset";
public static String GetStateText()
{
string text = "";
var plc = PlcConnect.Instance;
var result = plc.ReadInt32("status_indicator");
if (result.IsSuccess)
{
var context = result.Content;
switch (context)
{
case 0:
text = "异常停机";
break;
case 1:
text = "手动模式";
break;
case 2:
text = "自动模式";
break;
case 3:
text = "自动运行中";
break;
case 4:
text = "停止";
break;
case 5:
text = "安全回路异常";
break;
}
}
return text;
}
public static Dictionary<string, string> BufDictionary = new Dictionary<string, string>();
public static (bool, string) GetBufA()
{
string key = "CHIP0_OK_For_SWJ";
string kye = "READ_CHIP0.BUF";
var plc = PlcConnect.Instance;
var result =plc.ReadInt32(key);
if (result.IsSuccess && result.Content==1)
{
OperateResult<ushort, byte[]> read = plc.ReadTag(kye, ushort.Parse("23"));
if (read.IsSuccess)
{
var stringBuilder = read.Content2.ToHexString();
if (stringBuilder.Length > 22)
{
stringBuilder = stringBuilder.Substring(22);
plc.Write(key, Int32.Parse("0"));
return (true,stringBuilder);
}
}
}
return (false, "");
}
public static (bool, string) GetBufB()
{
string key = "CHIP1_OK_For_SWJ";
string kye = "READ_CHIP1.BUF";
var plc = PlcConnect.Instance;
var result = plc.ReadInt32(key);
if (result.IsSuccess && result.Content == 1)
{
OperateResult<ushort, byte[]> read = plc.ReadTag(kye, ushort.Parse("23"));
if (read.IsSuccess)
{
var stringBuilder = read.Content2.ToHexString();
if (stringBuilder.Length > 22)
{
stringBuilder = stringBuilder.Substring(22);
plc.Write(key, Int32.Parse("0"));
return (true, stringBuilder);
}
}
}
return (false, "");
}
public static (bool, string) GetBufC()
{
var plc = PlcConnect.Instance;
string kye = "READ_CHIP2.BUF";
string stringBuilder = "";
OperateResult<ushort, byte[]> read = plc.ReadTag(kye, ushort.Parse("25"));
if (read.IsSuccess)
{
stringBuilder = read.Content2.ToHexString();
if (stringBuilder.StartsWith("024E6F52", StringComparison.OrdinalIgnoreCase))
{
return (false, "");
}
if (stringBuilder.Length > 2)
{
stringBuilder = stringBuilder.Substring(2);
return (true, stringBuilder);
}
}
return (false, "");
}
public static (bool, string) GetBufABC(string key2)
{
string[] str = new string[] { "READ_CHIP0.BUF", "READ_CHIP1.BUF", "READ_CHIP2.BUF" };
string kye = "";
switch (key2)
{
case "A":
kye = str[0];
break;
case "B":
kye = str[1];
break;
case "C":
kye = str[2];
break;
}
var plc = PlcConnect.Instance;
string stringBuilder = "";
OperateResult<ushort, byte[]> read = plc.ReadTag(kye, ushort.Parse("25"));
if (read.IsSuccess)
{
stringBuilder = read.Content2.ToHexString();
}
if (stringBuilder.Trim().Length == 0)
{
return (false, stringBuilder);
}
if (stringBuilder.StartsWith("000000000") || stringBuilder.StartsWith("024E6F52".ToLower()))
{
return (false, stringBuilder);
}
if (BufDictionary.TryGetValue(key2, out var val))
{
if (val == stringBuilder)
{
return (false, stringBuilder);
}
else
{
BufDictionary[key2] = stringBuilder;
return (true, stringBuilder);
}
}
else
{
BufDictionary[key2] = stringBuilder;
return (true, stringBuilder);
}
}
}
}

@ -21,6 +21,9 @@ namespace Tool
}
private AllenBradleyNet CreateAb()
{
var rfidSetting = RfidSetting.Current;
@ -101,6 +104,14 @@ namespace Tool
}
public static bool IsSuccess
{
get
{
bool result = PlcConnect.Instance.ReadPlcType().IsSuccess;
return result;
}
}
public static OperateResult WriteTag(string address, UInt32 num)

Binary file not shown.

@ -0,0 +1,21 @@
using NewLife.Configuration;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Tool
{
[DisplayName("核心设置")]
[Config("Core")]
public class RfidSetting : Config<RfidSetting>
{
public string Db { get; set; } = "server=127.0.0.1;database=gaosu;uid=postgres;pwd=123456";
public string PlcIp { get; set; } = "192.168.1.100";
public int Port { get; set; } = 44818;
public string HslKey { get; set; } = "4b133324-fea4-4766-b066-857279c92f5d";
}
}

@ -36,6 +36,9 @@
<HintPath>..\Src\HslCommunication.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualBasic" />
<PackageReference Include="ClosedXML">
<Version>0.104.2</Version>
</PackageReference>
<PackageReference Include="NewLife.Core">
<Version>11.0.2024.1101</Version>
</PackageReference>
@ -46,9 +49,6 @@
<Reference Include="System.Core" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.Management" />
<PackageReference Include="NPOI">
<Version>2.7.2</Version>
</PackageReference>
<PackageReference Include="RestSharp">
<Version>112.1.0</Version>
</PackageReference>
@ -81,14 +81,14 @@
<Compile Include="Model\HmiCqAlarm.cs" />
<Compile Include="Model\HmiCqModel.cs" />
<Compile Include="Model\HmiLpModel.cs" />
<Compile Include="Model\HmiPoint.cs" />
<Compile Include="Model\HmiPointInfo.cs" />
<Compile Include="Model\PlcBoolModel.cs" />
<Compile Include="Model\PromptAlarm.cs" />
<Compile Include="PagedList.cs" />
<Compile Include="Result.cs" />
<Compile Include="RfidSetting.cs" />
<Compile Include="PlcConnect.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RfidSetting2.cs" />
<Compile Include="SnowflakeFactory.cs" />
</ItemGroup>
<ItemGroup />

Loading…
Cancel
Save