添加项目文件。

This commit is contained in:
Administrator
2026-08-04 18:36:40 +08:00
parent 16fb9e4f5a
commit a2ecbc795d
616 changed files with 149853 additions and 0 deletions
+990
View File
@@ -0,0 +1,990 @@
using HML;
using JinYuan.DAL;
using JinYuan.Helper;
using JinYuan.MES;
using JinYuan.MES.Models;
using JinYuan.Models;
using JinYuan.VirtualDataLibrary.Utlis;
using MiniExcelLibs;
using PLC;
using PLC.PLCAlarm;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Windows.Forms;
using System.Xml.Linq;
namespace JinYuan.VirtualDataLibrary
{
public class CommonMethods
{
public static readonly object SyncRoot = new object();
/// <summary>
/// 本地数据库
/// </summary>
public static ISugarHelper db = new SQLSugarService();
/// <summary>
/// 远程服务段数据库
/// </summary>
public static ISugarHelper dbServer = new SQLSugarService();
/// <summary>
/// 全局的PLC链接
/// </summary>
public static List<PlcReadWriteBase> plcDevices;
/// <summary>
/// plc状态
/// </summary>
public static readonly Dictionary<PlcReadWriteBase, Dictionary<string, object>> plcStatuses = new Dictionary<PlcReadWriteBase, Dictionary<string, object>>();
/// <summary>
/// 报警
/// </summary>
public static AlarmManager alarmManager = new AlarmManager();
/// <summary>
/// MES接口
/// </summary>
public static IMes hbgMes = new MesDataProcess();
/// <summary>
/// 参数
/// </summary>
public static ProductModelParam parRange = new ProductModelParam();
/// <summary>
/// 全局钩子
/// </summary>
public static ScanerHook listener = new ScanerHook();
/// <summary>
/// 创建个全局焊接功率队列数据存储
/// </summary>
public static List<Queue<double>> QWeldingPowerData = new List<Queue<double>>();
/// <summary>
/// 创建个全局入壳推力队列数据存储
/// </summary>
public static List<Queue<double>> QPlanenessData = new List<Queue<double>>();
/// <summary>
/// 创建全局的登录对象
/// </summary>
public static SysAdmin currentAdmin = null;
/// <summary>
/// 创建全局的登录对象
/// </summary>
public static List<NgCodeEntity> listNgCodeEntity = new List<NgCodeEntity>();
/// <summary>
/// 登录是否成功
/// </summary>
public static bool IsLoginOk = false;
//创建一个全局的配置对象
public static SysConfig sysConfig = new SysConfig();
public static int InvadTime;
/// <summary>
/// 智能电表
/// </summary>
public static List<ElectricEnergy> listElectricEnergy = new List<ElectricEnergy>();
/// <summary>
/// 电能表
/// </summary>
public static EnergyMeterHelper energyMeter = new EnergyMeterHelper();
/// <summary>
///是否开启刷新
/// </summary>
public static bool isRefreshTimerWeeding = false;
/// <summary>
/// SQL语句
/// </summary>
public static DBSQL dBSQL { get; } = new DBSQL();
public static M_DBCtrl m_DBCtrl { get; } = new M_DBCtrl();
/// <summary>
/// MES配置文件类
/// </summary>
public static MesConfig mesConfig = new MesConfig();
/// <summary>
/// 打印模板配置文件类
/// </summary>
public static BTWConfig btwConfig = new BTWConfig();
///创建一个全局的连接状态
public static bool connectState = false;
/// <summary>
/// 滴答次数
/// </summary>
public static int tickCount = 0;
/// <summary>
/// QIEHUAN
/// </summary>
public static int tickHomeCount = 0;
/// <summary>
/// 报警信息
/// </summary>
public static string SlideAlarmText = "当前无报警";
/// <summary>
/// 退出
/// </summary>
public static bool IsExit = false;
/// <summary>
/// 是否登出账户
/// </summary>
public static bool LoginOut = false;
/// <summary>
/// 是否上传MES
/// </summary>
public static bool IsUpMes { get; set; }
/// <summary>
/// 是否运行
/// </summary>
public static bool IsRun { get; set; } = false;
/// <summary>
/// 上一次设备状态
/// </summary>
public static int DeviceStatus = 0;
/// <summary>
/// 上一次Guid
/// </summary>
public static string DeviceGuid = "";
/// <summary>
///第一次读取
/// </summary>
public static bool IsFirst = false;
/// <summary>
/// 焊接功率波形图显示条数
/// </summary>
public static int ChatLineCount = 3;
/// <summary>
/// 员工号
/// </summary>
public static string strWorker { get; set; }
/// <summary>
/// 是否开启智能电表
/// </summary>
public static bool IsStartZNDB { get; set; } = false;
/// <summary>
/// 白夜班
/// </summary>
public static string strClass { get; set; } = "白班";
/// <summary>
/// 时间变更
/// </summary>
public static string ChangeClassTime { get; set; } = "20:30:00";
/// <summary>
/// 设备状态
/// </summary>
public static List<bool> Statues { get; set; }
/// <summary>
/// 服务器链接状态
/// </summary>
public static bool EMCStatues { get; set; }
#region 小时产能
/// <summary>
/// 上个时间点的总数
/// </summary>
public static int LastTotalNum { get; set; } = 0;
/// <summary>
/// 上个时间点良品数
/// </summary>
public static int LastOkNum { get; set; } = 0;
/// <summary>
/// 上一次重置计数的时间
/// </summary>
public static string LastResetTime { get; set; }
/// <summary>
/// 上一次的小时
/// </summary>
public static int LastHour { get; set; }
#endregion
/// <summary>
///
/// </summary>
public static List<Group> ListOmronGroups { get; set; }
/// <summary>
/// 12小时产能
/// </summary>
public static List<Chart12HourData> Lst_Prod12HourData = new List<Chart12HourData>();
/// <summary>
/// 不良选项(检测项不良)
/// </summary>
public static List<ChartDataType> Lst_DefectTypeQty = new List<ChartDataType>();
/// <summary>
/// PLC报警前10项
/// </summary>
public static List<ChartDataType> Lst_AlarmTop10_Qty = new List<ChartDataType>();
/// <summary>
/// 参数项设置
/// </summary>
public static List<ParamList> paramlists { get; set; }
/// <summary>
/// 线程控制
/// </summary>
public static ManualResetEvent ResetEventRecv = new ManualResetEvent(true);
#region 计数项
/// <summary>
/// 生产总数
/// </summary>
public static float TotalQty = 0;
public static float ProOKQty = 0;
public static float Ppm = 0;
public static double JiaDL = 0.0;
public static List<float> AntiDustAirSpeed = new List<float>();
/// <summary>
/// PLC开机/运行时间
/// </summary>
public static List<int> PlcOpenAndRunTime = new List<int>();
/// <summary>
/// PLC开机/运行时间地址
/// </summary>
public static List<string> PlcOpenAndRunTimeAdress = new List<string> { "D50", "D52", "D54", "D56", "D58", "D60" };
public static int ProdGaoRFIDNgQty = 0;//高托杯 绑定卷心码
public static int ProdDiRFIDNgQty = 0;//低托杯 绑定钢壳码
public static int ProdGangKeRFIDNgQty = 0;//钢壳托杯 绑定出站钢壳码
public static int ProdJuanBarNgQty = 0;
public static int ProdGangKeBarNgQty = 0;
public static int ProdRuKeTuiliNgQty = 0;
public static int ProdCCDNgQty = 0;
public static int ProdMesOutNGQty = 0;
#endregion
#region 配置信息
/// <summary>
/// 错误日志路径
/// </summary>
public static string strErrorLogspath = "D:\\APILog\\Logs\\ErrorLogs";
public static string strSystemLogspath = "D:\\APILog\\Logs\\SystemLogs";
public static string strAlarmLogspath = "D:\\APILog\\Logs\\AlarmLogs";
public static string strsqlLogspath = "";
/// <summary>
/// 删除路径
/// </summary>
public static string strDeletepath = "";
/// <summary>
/// 能耗保存路径
/// </summary>
public static string strWattrMeterpath = "D:\\APILog\\Logs\\智能电表数据";
/// <summary>
/// MES路径日志
/// </summary>
public static string strMesLogspath = "D:\\APILog\\Logs\\MesLogs";
/// <summary>
/// 主界面下列表绑定数据
/// </summary>
public static DropDownListPlusItemCollection DropDownItemList = new DropDownListPlusItemCollection();
/// <summary>
/// 设备状态信息路径
/// </summary>
public static string strDeviceStatusPath = System.Windows.Forms.Application.StartupPath + "\\Config\\DeviceStatus.cfg";
/// <summary>
/// PLC读取寄存器配置文件路径
/// </summary>
public static string ConfigPath = Path.Combine(System.Windows.Forms.Application.StartupPath, "ini\\PlcConfig.ini");
/// <summary>
/// 系统程序配置文件路径
/// </summary>
//public static string iniFilePath = Path.Combine(System.Windows.Forms.Application.StartupPath, "ini\\Configure.ini");
public static string xmlFilePath = Path.Combine(System.Windows.Forms.Application.StartupPath, "Config\\Configure.xml");
/// <summary>
/// 配置文件字典
/// </summary>
public static Dictionary<string, Dictionary<string, string>> Configxml = new Dictionary<string, Dictionary<string, string>>();
#region 读取配置文件
// 读取 XML 配置文件
public static Dictionary<string, Dictionary<string, string>> ReadXmlConfig(string filePath)
{
var config = new Dictionary<string, Dictionary<string, string>>();
if (!File.Exists(filePath))
{
MessageBox.Show($"配置文件不存在:{filePath}\n请检查Config文件夹是否存在,且包含Configure.xml文件");
return config;
}
XDocument xmlDoc = XDocument.Load(filePath);
foreach (var sectionElement in xmlDoc.Root.Elements())
{
string sectionName = sectionElement.Name.LocalName;
config[sectionName] = new Dictionary<string, string>();
foreach (var keyElement in sectionElement.Elements())
{
string key = keyElement.Name.LocalName;
string value = keyElement.Value;
config[sectionName][key] = value;
}
}
return config;
}
// 获取配置值
public static string GetConfigValue(Dictionary<string, Dictionary<string, string>> config, string section, string key, string defaultValue)
{
if (config.ContainsKey(section) && config[section].ContainsKey(key))
{
return config[section][key];
}
return defaultValue;
}
// 写入 XML 文件
public static void WriteXmlFile(Dictionary<string, Dictionary<string, string>> config, string filePath)
{
XDocument xmlDoc = new XDocument(new XElement("Configuration"));
foreach (var section in config)
{
var sectionElement = new XElement(section.Key);
foreach (var keyValue in section.Value)
{
sectionElement.Add(new XElement(keyValue.Key, keyValue.Value));
}
xmlDoc.Root.Add(sectionElement);
}
xmlDoc.Save(filePath);
}
/// <summary>
/// 单个配置数据保存
/// </summary>
/// <param name="INFO"></param>
/// <param name="Type"></param>
/// <param name="value"></param>
public static void UpdateConfig(string INFO, string Type, string value)
{
// 更新 Configxml 中的 SteelshellCount
CommonMethods.Configxml[INFO][Type] = value;
// 将更新后的 Configxml 写入文件
CommonMethods.WriteXmlFile(CommonMethods.Configxml, CommonMethods.xmlFilePath);
}
/// <summary>
///读取配置文件
/// </summary>
public static SysConfig GetSysConfig()
{
try
{
// 读取配置项
string line_gongwei = GetConfigValue(Configxml, "CONFIG_INFO", "EquipNo", "1-1");
// 安全拆分EquipNo
string[] gongweis = !string.IsNullOrWhiteSpace(line_gongwei) ? line_gongwei.Split('-') : new string[0];
// 安全获取LineNo
string lineNo = gongweis.Length >= 1 && !string.IsNullOrWhiteSpace(gongweis[0]) ? gongweis[0].Trim() : "1";
// 安全获取StationNo
string stationNo = gongweis.Length >= 2 && !string.IsNullOrWhiteSpace(gongweis[1]) ? gongweis[1].Trim() : "1";
#region 系统配置文件
return sysConfig = new SysConfig
{
AutoStart = Convert.ToBoolean(GetConfigValue(Configxml, "CONFIG_INFO", "AutoStart", "true")),
AutoLogin = Convert.ToBoolean(GetConfigValue(Configxml, "CONFIG_INFO", "AutoLogin", "true")),
AutoLock = Convert.ToBoolean(GetConfigValue(Configxml, "CONFIG_INFO", "AutoLockScreen", "false")),
LockPeriod = Convert.ToInt32(GetConfigValue(Configxml, "CONFIG_INFO", "LockIntervalTime", "0")),
AutoQieHuanM = Convert.ToBoolean(GetConfigValue(Configxml, "CONFIG_INFO", "AutoSwitchMonitor", "false")),
QieHuanMPeriod = Convert.ToInt32(GetConfigValue(Configxml, "CONFIG_INFO", "SwitchMonitorInterval", "0")),
ShowSeriesCount = Convert.ToInt32(GetConfigValue(Configxml, "CONFIG_INFO", "CurveDisplayCount", "0")),
SwipeCardMode = Convert.ToBoolean(GetConfigValue(Configxml, "CONFIG_INFO", "EnableCardMode", "false")),
MesModeSwitching = Convert.ToBoolean(GetConfigValue(Configxml, "CONFIG_INFO", "MESModeSwitch", "false")),
FinishSwitching = Convert.ToBoolean(GetConfigValue(Configxml, "CONFIG_INFO", "FinishSwitch", "false")),
GetMesParam = Convert.ToBoolean(GetConfigValue(Configxml, "CONFIG_INFO", "FetchMESParams", "false")),
SaveThreadTime = Convert.ToBoolean(GetConfigValue(Configxml, "CONFIG_INFO", "SaveThreadTimeLog", "false")),
IsDebugMode = Convert.ToBoolean(GetConfigValue(Configxml, "CONFIG_INFO", "IsDebugMode", "true")),
WuLiu = Convert.ToBoolean(GetConfigValue(Configxml, "CONFIG_INFO", "WuLiu", "false")),
GongWei = string.IsNullOrWhiteSpace(line_gongwei) ? "1-1" : line_gongwei,
LineNo = lineNo,
StationNo = stationNo
};
#endregion
}
catch (Exception)
{
return sysConfig = null;
}
}
/// <summary>
/// 获取MES配置文件
/// </summary>
public static MesConfig GetMesConfig()
{
try
{
#region MES配置文件
return mesConfig = new MesConfig
{
siteCode = GetConfigValue(Configxml, "MES_CONFIG", "SiteCode", "57M"),
lineCode = GetConfigValue(Configxml, "MES_CONFIG", "LineCode", "PW-571"),
equipNum = GetConfigValue(Configxml, "MES_CONFIG", "EquipNum", "571VIM01"),
CustomerPartNum = GetConfigValue(Configxml, "MES_CONFIG", "CustomerPartNum", "491VIM01"),
MESURLAddressIP = GetConfigValue(Configxml, "MES_CONFIG", "MESIp", "10.100.111.81"),
MESURLAddressPort = GetConfigValue(Configxml, "MES_CONFIG", "MESPort", "80"),
EmployeeAuthCheck = GetConfigValue(Configxml, "MES_CONFIG", "EmployeeAuthCheck", "571VIM01"),
DeviceParamRequest = GetConfigValue(Configxml, "MES_CONFIG", "DeviceParamRequest", "571VIM01"),
DeviceParamChange = GetConfigValue(Configxml, "MES_CONFIG", "DeviceParamChange", "491581VIM01VIM01"),
DeviceAlarm = GetConfigValue(Configxml, "MES_CONFIG", "DeviceAlarm", "581VIM01"),
DeviceStatus = GetConfigValue(Configxml, "MES_CONFIG", "DeviceStatus", "581VIM01"),
EnergyConsumption = GetConfigValue(Configxml, "MES_CONFIG", "EnergyConsumption", "581VIM01"),
Anemometer = GetConfigValue(Configxml, "MES_CONFIG", "Anemometer", "581VIM01"),
queryTrayUrl = GetConfigValue(Configxml, "MES_CONFIG", "QueryTrayUrl", ""),
queryGradeUrl = GetConfigValue(Configxml, "MES_CONFIG", "QueryGradeUrl", ""),
upResultParamUrl = GetConfigValue(Configxml, "MES_CONFIG", "UpResultParamUrl", ""),
packLoadUrl = GetConfigValue(Configxml, "MES_CONFIG", "PackLoadUrl", ""),
finishedPackUrl = GetConfigValue(Configxml, "MES_CONFIG", "finishedPackUrl", ""),
unbindTrayUrl = GetConfigValue(Configxml, "MES_CONFIG", "unBindTrayUrl", ""),
packLayers = int.Parse(GetConfigValue(Configxml, "MES_CONFIG", "PackLayers", "4")),
rowsPerLayer = int.Parse(GetConfigValue(Configxml, "MES_CONFIG", "RowsPerLayer", "5")),
colsPerLayer = int.Parse(GetConfigValue(Configxml, "MES_CONFIG", "ColsPerLayer", "12")),
};
#endregion
}
catch (Exception)
{
return mesConfig = null;
}
}
public static List<FDConfig> fdConfigs;
public static FDConfig curFdConfig; //垛位分档信息
public static List<FDConfigMapping> FDConfigMappings { get; set; } = new List<FDConfigMapping>();
public static FDConfigMapping CurrentFDConfig { get; set; }
public static void LoadFDConfig()
{
FDConfig fdconfig = null;
string FdConfigFilePath = CommonMethods.FdConfigFilePath; //Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Config/FdConfig.xlsx");
if (File.Exists(FdConfigFilePath))
{
using (var stream = File.OpenRead(FdConfigFilePath))
{
var devices = MiniExcel.Query<FDConfig>(stream).ToList();
CommonMethods.fdConfigs = devices.Select(device => new FDConfig
{
FdNum = device.FdNum,
Grade1 = device.Grade1,
Grade2 = device.Grade2,
Grade3 = device.Grade3,
IsFDActive = device.IsFDActive,
}).ToList();
CommonMethods.curFdConfig = CommonMethods.fdConfigs[CommonMethods.fdConfigs.Count - 1];
}
}
}
/// <summary>
/// 加载分档配置
/// </summary>
public static void LoadFDConfigMappings()
{
try
{
string fdConfigPath = CommonMethods.FdConfigMappingPath;//Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Config", "fd_config.xlsx");
if (File.Exists(fdConfigPath))
{
FDConfigMappings = MiniExcel.Query<FDConfigMapping>(fdConfigPath).ToList();
}
else
{
FDConfigMappings = new List<FDConfigMapping>();
}
}
catch (Exception ex)
{
LogHelper.Instance.WriteError($"加载分档配置失败:{ex.Message}", "SysErrorLog");
FDConfigMappings = new List<FDConfigMapping>();
}
}
/// <summary>
/// 根据机架号获取分档配置
/// </summary>
public static string GetFDConfigByStation(int stationNo)
{
if (stationNo == 1)
return curFdConfig.Grade1;
else if(stationNo == 2)
return curFdConfig.Grade2;
else if (stationNo == 3)
return curFdConfig.Grade3;
return "";
}
/// <summary>
/// 将电池等级转换成下发PLC的等级编号
/// </summary>
/// <param name="strGrade"></param>
/// <returns></returns>
public static int GetGradeNo(string strGrade)
{
if (string.IsNullOrEmpty(strGrade)) return 99;
if (strGrade == "NG" || strGrade == "拦截")
return 99;
if (strGrade == "不设置")
return 90;
var config = FDConfigMappings?.FirstOrDefault(x => x.FDName == strGrade);
return config != null ? (short)config.FDNum : 99;
}
public static List<string> FDGradeTypes = new List<string>();
public static void LoadFDGradeTypes()
{
try
{
string fdConfigPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Config", "FdConfigMapping.xlsx");
if (File.Exists(fdConfigPath))
{
var configs = MiniExcel.Query<FDConfigMapping>(fdConfigPath).ToList();
var types = configs.Select(x => x.FDName).Distinct().ToList();
// 确保包含 "不设置" 和 "NG"
if (!types.Contains("不设置"))
types.Insert(0, "不设置");
if (!types.Contains("NG"))
types.Add("NG");
FDGradeTypes = types;
}
else
{
FDGradeTypes = new List<string> { "不设置", "NG" };
}
}
catch (Exception ex)
{
Console.WriteLine($"LoadFDGradeTypes error: {ex.Message}");
FDGradeTypes = new List<string> { "不设置", "NG" };
}
}
public static List<string> GetValidGrades()
{
List<string> grades = new List<string>();
if (curFdConfig != null)
{
if (curFdConfig.Grade1 != null && curFdConfig.Grade1 != "NG" && curFdConfig.Grade1 != "不设置")
{
grades.Add(curFdConfig.Grade1);
}
if (curFdConfig.Grade2 != null && curFdConfig.Grade2 != "NG" && curFdConfig.Grade2 != "不设置")
{
grades.Add(curFdConfig.Grade2);
}
if (curFdConfig.Grade3 != null && curFdConfig.Grade3 != "NG" && curFdConfig.Grade3 != "不设置")
{
grades.Add(curFdConfig.Grade3);
}
grades = grades.Distinct().ToList();
}
return grades;
}
/// <summary>
/// 获取BTW配置文件
/// </summary>
public static BTWConfig GetBtwConfig()
{
try
{
#region 打印模板路径配置文件
return btwConfig = new BTWConfig
{
containerBTWPath = GetConfigValue(Configxml, "BTW_CONFIG", "ContainerBTWPath", ""),
printerName = GetConfigValue(Configxml, "BTW_CONFIG", "PrinterName", ""),
};
#endregion
}
catch (Exception)
{
return btwConfig = null;
}
}
#endregion
public static string deviceConfigPath = Application.StartupPath + "\\Config\\Device.xlsx";
public static string groupConfigPath = Application.StartupPath + "\\Config\\Group.xlsx";
public static string variableConfigPath = Application.StartupPath + "\\Config\\Variable.xlsx";
public static string FdConfigFilePath = Application.StartupPath + "\\Config\\FdConfig.xlsx";
public static string FdConfigMappingPath = Application.StartupPath + "\\Config\\FdConfigMapping.xlsx";
#region 保存配置文件
/// <summary>
/// 保存启动自动登录
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static bool SaveAutoStart(bool value)
{
Configxml["CONFIG_INFO"]["AutoStart"] = value.ToString(); // 修改自动登录为 True
WriteXmlFile(Configxml, xmlFilePath);
return true;
}
/// <summary>
/// 保存开机自动启动
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static bool SaveAutoLogin(bool value)
{
Configxml["CONFIG_INFO"]["AutoLogin"] = value.ToString();
WriteXmlFile(Configxml, xmlFilePath);
return true;
}
/// <summary>
/// 保存无操作自动锁屏
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static bool SaveAutoLock(bool value)
{
Configxml["CONFIG_INFO"]["AutoLockScreen"] = value.ToString();
WriteXmlFile(Configxml, xmlFilePath);
return true;
}
/// <summary>
/// 保存锁屏间隔时间
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static bool SaveLockPeriod(int value)
{
Configxml["CONFIG_INFO"]["LockIntervalTime"] = value.ToString();
WriteXmlFile(Configxml, xmlFilePath);
return true;
}
/// <summary>
/// 保存无操作自动切换监控界面
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static bool SaveAutoQieHuanM(bool value)
{
Configxml["CONFIG_INFO"]["AutoSwitchMonitor"] = value.ToString();
WriteXmlFile(Configxml, xmlFilePath);
return true;
}
/// <summary>
/// 保存无操作自动切换监控界面
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static bool SaveIsDebug(bool value)
{
Configxml["CONFIG_INFO"]["IsDebugMode"] = value.ToString();
WriteXmlFile(Configxml, xmlFilePath);
return true;
}
/// <summary>
/// 保存物流线分拣
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static bool SaveWuLiu(bool value)
{
Configxml["CONFIG_INFO"]["WuLiu"] = value.ToString();
WriteXmlFile(Configxml, xmlFilePath);
return true;
}
/// <summary>
/// 保存切换监控界面间隔时间
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static bool SaveQieHuanMPeriod(int value)
{
Configxml["CONFIG_INFO"]["SwitchMonitorInterval"] = value.ToString();
WriteXmlFile(Configxml, xmlFilePath);
return true;
}
/// <summary>
/// 保存曲线显示数量
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static bool SaveShowSeriesCount(int value)
{
Configxml["CONFIG_INFO"]["CurveDisplayCount"] = value.ToString();
WriteXmlFile(Configxml, xmlFilePath);
return true;
}
/// <summary>
/// 开启刷卡模式
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static bool SaveSwipeCardMode(bool value)
{
Configxml["CONFIG_INFO"]["EnableCardMode"] = value.ToString();
WriteXmlFile(Configxml, xmlFilePath);
return true;
}
/// <summary>
/// MES/非MES模式
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static bool SaveOpenMesModel(bool value)
{
Configxml["CONFIG_INFO"]["MESModeSwitch"] = value.ToString();
WriteXmlFile(Configxml, xmlFilePath);
return true;
}
/// <summary>
/// 成品/半成品切换
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static bool SaveFinishSwitch(bool value)
{
Configxml["CONFIG_INFO"]["FinishSwitch"] = value.ToString();
WriteXmlFile(Configxml, xmlFilePath);
return true;
}
/// <summary>
/// 保存机架号
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static bool SaveEquipNo(string value)
{
Configxml["CONFIG_INFO"]["EquipNo"] = value.ToString();
WriteXmlFile(Configxml, xmlFilePath);
return true;
}
/// <summary>
/// 获取MES参数
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static bool SaveGetMesParam(bool value)
{
Configxml["CONFIG_INFO"]["FetchMESParams"] = value.ToString();
WriteXmlFile(Configxml, xmlFilePath);
return true;
}
/// <summary>
/// 保存线程耗时操作
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static bool SaveSaveThreadTime(bool value)
{
Configxml["CONFIG_INFO"]["SaveThreadTimeLog"] = value.ToString();
WriteXmlFile(Configxml, xmlFilePath);
return true;
}
#endregion
#endregion
#region 委托信息
//创建委托
// 数据监视委托
public static Action<int, string> AddDataMonitorDelegate;
/// <summary>
/// 系统日志
/// </summary>
public static Action<bool, string> AddLogDelegate;
/// <summary>
/// 操作日志
/// </summary>
public static Action<bool, string> AddOPLogDelegate;
/// <summary>
/// 报警日志
/// </summary>
public static Action<SysLog> AddAlarmDelegate;
/// <summary>
/// 显示报警信息
/// </summary>
public static Action<string> ShowAlarmDelegate;
/// <summary>
/// 参数更新
/// </summary>
public static Action ChangeParamDelegate;
/// <summary>
///
/// </summary>
public static Action<bool> AddHomeDelegate;
/// <summary>
/// 显示组盘信息
/// </summary>
public static Action<List<AGearEntity>> ShowFeedingDelegate;
/// <summary>
/// 显示组盘抽检信息
/// </summary>
public static Action<List<CGearEntity>> ShowReFeedingDelegate;
/// <summary>
/// 显示叠盘数据
/// </summary>
public static Action<List<BGearEntity>> ShowBlankingDelegate;
/// <summary>
/// 显示底托拉板绑定信息
/// </summary>
public static Action<List<DGearEntity>> ShowMaterialDelegate;
/// <summary>
/// 显示料框码进站信息
/// </summary>
public static Action<List<TrayEntity>> ShowTrayDataDelegate;
/// <summary>
/// 电池状态委托
/// </summary>
public static Action<int, List<BatteryEntity>> ShowBatteryStatusDelegate;
/// <summary>
/// 满层后,展示电池二维码
/// </summary>
//public static Action<List<BatteryEntity>> ShowBatteryQRCoderDelegate;
/// <summary>
/// 档位NG原因委托
/// </summary>
public static Action<List<BatteryEntity>> ShowBatteryNGRsnDelegate;
/// <summary>
/// 显示电池替换信息
/// </summary>
public static Action<List<BatteryReplace>> ShowBatteryReplaceDelegate;
/// <summary>
/// 显示卡板打印信息
/// </summary>
public static Action<List<EGearEntity>> ShowLabellingMachineDelegate;
/// <summary>
/// 数据监视委托
/// </summary>
/// <param name="type"></param>
/// <param name="info"></param>
public static void AddDataMonitorLog(int type, string info)
{
//调用委托
if (AddDataMonitorDelegate != null)
{
AddDataMonitorDelegate(type, info);
}
}
/// <summary>
/// 写入系统日志
/// </summary>
/// <param name="isError">是否为错误信息</param>
/// <param name="info">日志信息</param>
public static void AddLog(bool isError, string info)
{
//调用委托
if (AddLogDelegate != null)
{
AddLogDelegate(isError, info);
}
}
/// <summary>
/// 写入操作日志
/// </summary>
/// <param name="isError"></param>
/// <param name="info"></param>
public static void AddOPLog(bool isError, string info)
{
//调用委托
if (AddLogDelegate != null)
{
AddOPLogDelegate(isError, info);
}
}
public static void AddAlarmLog(SysLog sysLog)
{
//调用委托
if (AddAlarmDelegate != null)
{
AddAlarmDelegate(sysLog);
}
}
/// <summary>
/// 显示报警日志
/// </summary>
/// <param name="info"></param>
public static void ShowAlarmLog(string info)
{
//调用委托
if (ShowAlarmDelegate != null)
{
ShowAlarmDelegate(info);
}
}
public static void ChangeParamData()
{
//调用委托
if (ChangeParamDelegate != null)
{
ChangeParamDelegate();
}
}
#endregion
/// <summary>
/// PLC变量集合
/// KEY = VarAddress
/// </summary>
public static ConcurrentDictionary<string, PLCGroupVariable> PLCVariable = new ConcurrentDictionary<string, PLCGroupVariable>();
// 打印机
/// <summary>
/// zebra
/// </summary>
public static BartenderPrinter containerPrint;
}
}
+730
View File
@@ -0,0 +1,730 @@
using JinYuan.Helper;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace JinYuan.VirtualDataLibrary
{
public class DBSQL
{
/// <summary>
/// 获取PLC换型参数绑定值
/// </summary>
/// <param name="modelName"></param>
/// <returns></returns>
public string GetPlcParamSql(string modelName)
{
string strSql = $@"SELECT
'{modelName}' AS `ModelName`,
`pb`.`PLCAddress`,
`pc`.`PLCValue`,
`pc`.`UpdateTime`,
`pb`.`PLCRemark`,
`pb`.`OrderNum`
FROM
`Plcconfigbase` `pb`
LEFT JOIN
(SELECT * FROM `Plcconfig` WHERE `ModelName` = '{modelName}') `pc`
ON
`pb`.`PLCAddress` = `pc`.`PLCAddress`
ORDER BY
`pb`.`OrderNum`";
return strSql;
}
/// <summary>
/// 获取产品型号参数
/// </summary>
/// <param name="strModelType"></param>
/// <returns></returns>
public string GetParamSql(string strModelType)
{
string strSql = $@"SELECT
`pb`.`ParaName`,
'{strModelType}' AS `ModelName`,
`pl`.`ParaValueMin`,
`pl`.`ParaValueMax`,
`pl`.`Uint`,
`pb`.`Remark`,
`pl`.`UpdateTime`
FROM
`Parambase` `pb`
LEFT JOIN
(SELECT * FROM `ParamList` WHERE `ModelName` = '{strModelType}') `pl`
ON
`pb`.`ParaName` = `pl`.`ParaName`
ORDER BY
`pb`.`fNo` ASC";
return strSql;
}
/// <summary>
/// 获取产品型号列表
/// </summary>
/// <param name="strProdType"></param>
/// <returns></returns>
public string GetProdTypeSql(string strProdType = "")
{
string strSql = @"SELECT * FROM ProductModel ";
if (strProdType != "")
{
strSql += string.Format(" where ModelName='{0}'", strProdType);
}
strSql += " order by ModelName";
return strSql;
}
/// <summary>
/// 获取产品型号
/// </summary>
/// <param name="strModelType"></param>
/// <returns></returns>
public string GetProductParaByProdModel(string strModelType)
{
string strSql = $@"SELECT
`pb`.`ParaName`,
'{strModelType}' AS `ModelName`,
`pl`.`ParaValueMin`,
`pl`.`ParaValueMax`,
`pl`.`Uint`,
`pb`.`Remark`,
`pl`.`UpdateTime`
FROM
`Parambase` `pb`
LEFT JOIN
(SELECT * FROM `Paramlist` WHERE `ModelName` = '{strModelType}') `pl`
ON
`pb`.`ParaName` = `pl`.`ParaName`
ORDER BY
`pb`.`fNo` ASC";
return strSql;
}
public string GetPLCConfigBases()
{
string strSql = string.Format(@"SELECT * FROM `Plcconfigbase` ORDER BY `OrderNum`");
return strSql;
}
public string GetSysAdminSql()
{
string strSql = string.Format(@"SELECT
`LoginId`,
`LoginName`,
`LoginPwd`,
`LoginUid`,
`LoginLevel`,
`SystemLog`,
`CpkData`,
`HistoryData`,
`ParamSet`,
`SystemSet`,
`UserManage`
FROM
`SysAdmin`");
return strSql;
}
/// <summary>
/// 查询历史数据
/// </summary>
/// <param name="strBarCode"></param>
/// <param name="strDate1"></param>
/// <param name="strDate2"></param>
/// <returns></returns>
public string SelectHostData(int type, string strRfid, string strBarCode, string strDate1, string strDate2)
{
Dictionary<int, int> outTypes = new Dictionary<int, int>()
{
{ 3, 1 },
{ 4, 2 }
};
string strSql = string.Empty;
if (type == 0)
{
strSql = @"SELECT
DATE_FORMAT(`Time`, '%Y-%m-%d %H:%i:%s') AS `TestTime`,
`BarCode`,
`Location` AS `CellPosition`,
`TrayID` AS `RFID`,
`Model`,
`Grade` AS `CellGrade`,
`Gongwei`,
`Result`,
`Remark`
FROM
`AGearEntity`
WHERE
`Time` >= '" + strDate1 + "' AND `Time` <= '" + strDate2 + "'";
// 2. 安全拼接查询条件:参数化+CONCAT函数
if (!string.IsNullOrEmpty(strRfid))
{
strSql += " AND `TrayID` LIKE '%" + strRfid + "%'";
}
if (!string.IsNullOrEmpty(strBarCode))
{
strSql += " AND `BarCode` LIKE '%" + strBarCode + "%'";
}
}
else if (type == 1) //装箱或者强制出站
{
strSql = @"SELECT
`identification` AS `BarCode`,
DATE_FORMAT(`packTime`, '%Y-%m-%d %H:%i:%s') AS `TestTime`,
`location` AS `CellPosition`,
`grade` AS `CellGrade`,
`containerCode` AS `ContainerCode`,
`packResult` AS `PackResult`,
`packFalseReason` AS `PackFailReason`,
CASE
WHEN `outStationType` = 1 THEN '满箱出站'
ELSE '强制出站'
END AS `OutStationType`
FROM
`BatteryEntity`
WHERE
`packTime` >= '" + strDate1 + "' and `packTime` <= '" + strDate2 + "' ";
// 安全拼接查询条件:参数化+CONCAT函数,
if (!string.IsNullOrEmpty(strRfid))
{
strSql += " AND `containerCode` LIKE '%" + strRfid + "%'";
}
if (!string.IsNullOrEmpty(strBarCode))
{
strSql += " AND `identification` LIKE '%" + strBarCode + "%'";
}
}
else if (type == 2)//电芯替换
{
strSql = @"SELECT
DATE_FORMAT(`ReplaceTime`, '%Y-%m-%d %H:%i:%s') AS `TestTime`,
`NewBarCode`,
`OldBarCode`,
`Location` AS `CellPosition`,
`VassoioID` AS `ContainerCode`,
`GongWei` AS `Gongwei`,
`Grade` AS `CellGrade`,
`Remark`
FROM
`BatteryReplace`
WHERE
`ReplaceTime` >= '" + strDate1 + "' and `ReplaceTime` <= '" + strDate2 + "' ";
if (!string.IsNullOrEmpty(strRfid))
{
strSql += " AND `VassoioID` LIKE '%" + strRfid + "%'";
}
if (!string.IsNullOrEmpty(strBarCode))
{
string safeRfid = strRfid?.Replace("'", "''") ?? "";
string safeBarCode = strBarCode?.Replace("'", "''") ?? "";
strSql += $" AND (`NewBarCode` LIKE '%{safeRfid}%' OR `OldBarCode` LIKE '%{safeBarCode}%')";
}
}
else
{
LogHelper.Instance.WriteError($"不支持的查询类型:{type}", "DataErrorLog");
}
return strSql;
}
/// <summary>
/// 查询报警历史数据
/// </summary>
/// <param name="start"></param>
/// <param name="end"></param>
/// <param name="alarmType"></param>
/// <returns></returns>
public string SelectHostAlarmData(string start, string end, int alarmType)
{
string strSql = "";
switch (alarmType)
{
case 1:
strSql = @"SELECT
DATE_FORMAT(`AlarmTime`, '%Y-%m-%d %H:%i:%s') AS `AlarmTime`,
`PLCAdress`,
`AlarmContent`,
`AlarmCount`,
`Class`
FROM
`AlarmCountEntry`
WHERE
`AlarmTime` >= '" + start + "' AND `AlarmTime` <= '" + end + $"' AND `Class` = '{CommonMethods.strClass}'";
break;
case 2:
strSql = @"SELECT
DATE_FORMAT(`AlarmTime`, '%Y-%m-%d %H:%i:%s') AS `AlarmTime`,
`PLCAdress`,
`AlarmContent`,
`AlarmCount`,
`Class`
FROM
`AlarmCountEntry`
WHERE
`AlarmTime` >= '" + start + "' AND `AlarmTime` <= '" + end + $"' AND `Class` = '{CommonMethods.strClass}'";
break;
default:
case 0:
strSql = @"SELECT
DATE_FORMAT(`AlarmTime`, '%Y-%m-%d %H:%i:%s') AS `AlarmTime`,
`PLCAdress`,
`AlarmContent`,
`AlarmCount`,
`Class`
FROM
`AlarmCountEntry`
WHERE
`AlarmTime` >= '" + start + "' AND `AlarmTime` <= '" + end + "'";
break;
}
#region 旧
//if (alarmType == "全天")
//{
// strSql = @"SELECT
// DATE_FORMAT(`AlarmTime`, '%Y-%m-%d %H:%i:%s') AS `AlarmTime`,
// `PLCAdress`,
// `AlarmContent`,
// `AlarmCount`,
// `Class`
// FROM
// `AlarmCountEntry`
// WHERE
// `AlarmTime` >= '" + start + "' AND `AlarmTime` <= '" + end + "'";
//}
//else if (alarmType == "白班")
//{
// strSql = @"SELECT
// DATE_FORMAT(`AlarmTime`, '%Y-%m-%d %H:%i:%s') AS `AlarmTime`,
// `PLCAdress`,
// `AlarmContent`,
// `AlarmCount`,
// `Class`
// FROM
// `AlarmCountEntry`
// WHERE
// `AlarmTime` >= '" + start + "' AND `AlarmTime` <= '" + end + "' AND `Class` = '白班'";
//}
//else
//{
// strSql = @"SELECT
// DATE_FORMAT(`AlarmTime`, '%Y-%m-%d %H:%i:%s') AS `AlarmTime`,
// `PLCAdress`,
// `AlarmContent`,
// `AlarmCount`,
// `Class`
// FROM
// `AlarmCountEntry`
// WHERE
// `AlarmTime` >= '" + start + "' AND `AlarmTime` <= '" + end + "' AND `Class` = '夜班'";
//}
#endregion
return strSql;
}
/// <summary>
/// 按日统计
/// </summary>
/// <param name="startDateTime"></param>
/// <param name="endDateTime"></param>
/// <returns></returns>
public string GetStaticByDay(string startDateTime, string endDateTime)
{
string strSql = $@"SELECT
DATE_FORMAT(`TestTime`, '%Y-%m-%d %H:00:00') AS `Day`,
`ProdIn`,
`ProdOut`,
`Ppm`,
CONCAT(CAST(ROUND(`JiaDL` * 100, 1) AS CHAR(10)), '%') AS `JiaDL`,
CONCAT(CAST(
CASE
WHEN `ProdIn` > 0 THEN ROUND(COALESCE(`ProdOut`, 0) / COALESCE(`ProdIn`, 0) * 100, 2)
ELSE 0
END AS CHAR(10)), '%') AS `Prod`
FROM
`Hourprod`
WHERE
`TestTime` BETWEEN '{startDateTime}' AND '{endDateTime}'
GROUP BY
`TestTime`, `ProdOut`, `ProdIn`, `Ppm`, `JiaDL`
UNION ALL
SELECT
'Total' AS `Day`,
SUM(`ProdIn`) AS ProdIn,
SUM(`ProdOut`) AS ProdOut,
AVG(`Ppm`) AS Ppm,
CONCAT(CAST(ROUND(AVG(`JiaDL`) * 100, 1) AS CHAR(10)), '%') AS `JiaDL`,
CONCAT(CAST(
CASE
WHEN SUM(`ProdIn`) > 0 THEN ROUND(COALESCE(SUM(`ProdOut`), 0) / COALESCE(SUM(`ProdIn`), 0) * 100, 2)
ELSE 0
END AS CHAR(10)), '%') AS `Prod`
FROM
`Hourprod`
WHERE
`TestTime` BETWEEN '{startDateTime}' AND '{endDateTime}'";
return strSql;
}
/// <summary>
/// 按周查询
/// </summary>
/// <param name="startDateTime"></param>
/// <param name="endDateTime"></param>
/// <returns></returns>
public string GetStaticByWeek(string startDateTime, string endDateTime)
{
string strSql = $@"SELECT
DATE_FORMAT(`TestTime`, '%Y-%m') AS `Week`,
SUM(`ProdIn`) AS ProdIn,
SUM(`ProdOut`) AS ProdOut,
AVG(`Ppm`) AS Ppm,
CONCAT(CAST(ROUND(`JiaDL` * 100, 1) AS CHAR(10)), '%') AS `JiaDL`,
CONCAT(CAST(
CASE
WHEN SUM(`ProdIn`) > 0 THEN ROUND(COALESCE(SUM(`ProdOut`), 0) / COALESCE(SUM(`ProdIn`), 0) * 100, 2)
ELSE 0
END AS CHAR(10)), '%') AS `Prod`
FROM
`Hourprod`
WHERE
`TestTime` BETWEEN '{startDateTime}' AND '{endDateTime}'
GROUP BY
DATE_FORMAT(`TestTime`, '%Y-%m'), `JiaDL`
UNION ALL
SELECT
'Total' AS `Week`,
SUM(`ProdIn`) AS ProdIn,
SUM(`ProdOut`) AS ProdOut,
AVG(`Ppm`) AS Ppm,
CONCAT(CAST(ROUND(AVG(`JiaDL`) * 100, 1) AS CHAR(10)), '%') AS `JiaDL`,
CONCAT(CAST(
CASE
WHEN SUM(`ProdIn`) > 0 THEN ROUND(COALESCE(SUM(`ProdOut`), 0) / COALESCE(SUM(`ProdIn`), 0) * 100, 2)
ELSE 0
END AS CHAR(10)), '%') AS `Prod`
FROM
`Hourprod`
WHERE
`TestTime` BETWEEN '{startDateTime}' AND '{endDateTime}'";
return strSql;
}
/// <summary>
/// 按月查询
/// </summary>
/// <param name="startDateTime"></param>
/// <param name="endDateTime"></param>
/// <returns></returns>
public string GetStaticByMonth(string startDateTime, string endDateTime)
{
string strSql = $@"SELECT
DATE_FORMAT(`TestTime`, '%Y-%m') AS `Month`,
SUM(`ProdIn`) AS ProdIn,
SUM(`ProdOut`) AS ProdOut,
AVG(`Ppm`) AS Ppm,
CONCAT(CAST(ROUND(`JiaDL` * 100, 1) AS CHAR(10)), '%') AS `JiaDL`,
CONCAT(CAST(
CASE
WHEN SUM(`ProdIn`) > 0 THEN ROUND(COALESCE(SUM(`ProdOut`), 0) / COALESCE(SUM(`ProdIn`), 0) * 100, 2)
ELSE 0
END AS CHAR(10)), '%') AS `Prod`
FROM
`Hourprod`
WHERE
`TestTime` BETWEEN '{startDateTime}' AND '{endDateTime}'
GROUP BY
DATE_FORMAT(`TestTime`, '%Y-%m'), `JiaDL`
UNION ALL
SELECT
'Total' AS `Month`,
SUM(`ProdIn`) AS ProdIn,
SUM(`ProdOut`) AS ProdOut,
AVG(`Ppm`) AS Ppm,
CONCAT(CAST(ROUND(AVG(`JiaDL`) * 100, 1) AS CHAR(10)), '%') AS `JiaDL`,
CONCAT(CAST(
CASE
WHEN SUM(`ProdIn`) > 0 THEN ROUND(COALESCE(SUM(`ProdOut`), 0) / COALESCE(SUM(`ProdIn`), 0) * 100, 2)
ELSE 0
END AS CHAR(10)), '%') AS `Prod`
FROM
`Hourprod`
WHERE
`TestTime` BETWEEN '{startDateTime}' AND '{endDateTime}'";
return strSql;
}
/// <summary>
/// 按班次统计
/// </summary>
/// <param name="dateTime"></param>
/// <param name="shift"></param>
/// <param name="changeShiftTime"></param>
/// <returns></returns>
public string GetStaticByShift(DateTime dateTime, int shift, string changeShiftTime)
{
string sDateTime1 = string.Empty;
string sDateTime2 = string.Empty;
if (shift == 0)// 白班
{
DateTime sTempDateTime = Convert.ToDateTime($"{dateTime.ToString("yyyy-MM-dd")} {changeShiftTime}");
sDateTime1 = sTempDateTime.AddHours(-12).ToString("yyyy-MM-dd HH:mm:ss");
sDateTime2 = sTempDateTime.ToString("yyyy-MM-dd HH:mm:ss");
}
else
{
sDateTime1 = $"{dateTime.ToString("yyyy-MM-dd")} {changeShiftTime}";
sDateTime2 = Convert.ToDateTime(sDateTime1).AddHours(12).ToString("yyyy-MM-dd HH:mm:ss");
}
string strsql = $@"SELECT
DATE_FORMAT(`TestTime`, '%Y-%m-%d %H:00:00') AS `TestTime`,
`ProdIn`,
`ProdOut`,
`Ppm`,
CONCAT(CAST(ROUND(`JiaDL` * 100, 1) AS CHAR(10)), '%') AS `JiaDL`,
CONCAT(CAST(
CASE
WHEN `ProdIn` > 0 THEN ROUND(COALESCE(`ProdOut`, 0) / COALESCE(`ProdIn`, 0) * 100, 2)
ELSE 0
END AS CHAR(10)), '%') AS `Prod`
FROM
`Hourprod`
WHERE
`TestTime` BETWEEN '{sDateTime1}' AND '{sDateTime2}'
GROUP BY
`TestTime`, `ProdOut`, `ProdIn`, `Ppm`, `JiaDL`
UNION ALL
SELECT
'Total' AS `Time`,
SUM(`ProdIn`) AS ProdIn,
SUM(`ProdOut`) AS ProdOut,
AVG(`Ppm`) AS Ppm,
CONCAT(CAST(ROUND(AVG(`JiaDL`) * 100, 1) AS CHAR(10)), '%') AS `JiaDL`,
CONCAT(CAST(
CASE
WHEN SUM(`ProdIn`) > 0 THEN ROUND(COALESCE(SUM(`ProdOut`), 0) / COALESCE(SUM(`ProdIn`), 0) * 100, 2)
ELSE 0
END AS CHAR(10)), '%') AS `Prod`
FROM
`Hourprod`
WHERE
`TestTime` BETWEEN '{sDateTime1}' AND '{sDateTime2}'";
return strsql;
}
/// <summary>
/// 获取进站信息
/// </summary>
/// <returns></returns>
public string GetInTime(string strBarCode)
{
string strSql = $@"SELECT TestTime
,BarCode
,Result
,Remark
FROM AGearEntity
WHERE BarCode = '{strBarCode}'
ORDER BY TestTime ASC";
return strSql;
}
/// <summary>
/// 获取最新的数据
/// </summary>
/// <returns></returns>
public string GetStatic(string strDateTime)
{
string strsql = $@" SELECT [FDate]
,[FHour]
,[ProdIn]
,[ProdOut]
,[TestTime]
FROM [dbo].[Hourprod] where FDate='{strDateTime}' order by TestTime desc";
return strsql;
}
/// <summary>
/// 根据条码查询是否存在
/// </summary>
/// <param name="strProdType"></param>
/// <returns></returns>
public string GetBarcode(string barCode)
{
string strSql = $@"SELECT EXISTS(
SELECT 1
FROM `CGearEntity`
WHERE BarCode = '{barCode}') AS barcode_exists";
return strSql;
}
/// 根据条码获取进站时间最新的一条数据
/// </summary>
/// <param name="strProdType"></param>
/// <returns></returns>
public string GetInStationTop1Sql(string barCode)
{
string strSql = $@"SELECT
`ChannelNo`,
`TestTime`,
`RFID`,
`BarCode`,
`Result`,
`Remark`,
`Flag`
FROM
`AGearEntity`
WHERE `BarCode` = '{barCode}' ORDER BY `TestTime` DESC
LIMIT 1";
return strSql;
}
/// <summary>
/// 获取表头注释 按照设计顺序
/// </summary>
/// <returns></returns>
public string GetSqlFields(string tableName)
{
string strSql = $@"SELECT
COLUMN_NAME,
PLC.DataType,
COLUMN_COMMENT
FROM
INFORMATION_SCHEMA.COLUMNS
WHERE
TABLE_SCHEMA = 'largesquareone' AND TABLE_NAME = '{tableName}'
ORDER BY
ORDINAL_POSITION;";
return strSql;
}
/// <summary>
/// 根据档位获取当前档位中的所有电芯数据
/// </summary>
/// <param name="grade"></param>
/// <returns></returns>
public string GetGradeBatterySql(string grade)
{
string strSql = $@"SELECT
`identification`,
`locationBat`,
`grade`,
`innerContainerCode`,
`packResult`,
`packFalseReason`
FROM
`BatteryEntity`
WHERE `grade` = '{grade}' ORDER BY `TestTime` DESC";
return strSql;
}
}
public class M_DBCtrl
{
/// <summary>--本机数据库表名
///
/// </summary>
//public string machineInSQLTable = "agearentity";
public string machineOutSQLTable = "bgearentity";
private string[] headerTextOut;
/// <summary>
/// 出站数据库表头
/// </summary>
public string[] HeaderTextOut
{
get { return headerTextOut; }
set { headerTextOut = value; }
}
/// <summary>查询SQL数据库中的数据,并以string数组列表形式返回
///
/// </summary>
/// <param name="strSql"></param>
/// <returns>所查询到的数据,null表示不存在</returns>
public List<string[]> SQLAllDataSearchToStrArrList(string strSql)
{
List<string[]> strResArrList = new List<string[]>();
List<string> strResList = new List<string>();
try
{
DataTable dt = CommonMethods.db.QueryDataTable(strSql);
if (dt != null)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
for (int j = 0; j < dt.Columns.Count; j++)
{
string resRow = dt.Rows[i][j].ToString();
strResList.Add(resRow);
}
string[] strResArr = strResList.ToArray();
strResList.Clear();
strResArrList.Add(strResArr);
}
}
}
catch (Exception e)
{
return strResArrList = new List<string[]>();
}
return strResArrList;
}
/// <summary>根据下标在返回的数据库表信息 集合中获取相应数据
/// index 0:字段 2:中文注释 1:变量类型int\char等
/// </summary>
/// <param name="SqlList">liststring[]类型的集合</param>
/// <param name="index">string[] 的下标</param>
/// <returns></returns>
public String[] HeaderTextAssignment(List<string[]> SqlList, int index)
{
string[] headStringlist = new string[SqlList.Count];
// int i = 0;
try
{
for (int i = 0; i < SqlList.Count; i++)
{
headStringlist[i] = SqlList[i][index];
}
}
catch (Exception)
{
}
return headStringlist;
}
}
}
+47
View File
@@ -0,0 +1,47 @@
using JinYuan.Models;
using PLCCommunication;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace JinYuan.VirtualDataLibrary
{
public delegate void dgStationFunction(JYResult<byte[]> bArrays, object plcModel);
/// <summary>
/// 显示上料信息
/// </summary>
/// <param name="Msg"></param>
/// <param name="state"></param>
//public delegate void dgShowFeeding(List<AGearEntity> list);
/// <summary>
/// 显示下料信息
/// </summary>
/// <param name="Msg"></param>
/// <param name="state"></param>
//public delegate void dgShowBlanking(List<BlankingEntry> list);
/// <summary>
/// 设备综合效率
/// </summary>
/// <param name="battery"></param>
public delegate void DGShow12HourData(DeviceOEE device12Hour);
/// <summary>
/// 设备综合效率
/// </summary>
/// <param name="battery"></param>
public delegate void DGShowAlarmData(DeviceOEE deviceAlarm);
/// <summary>
/// 焊机功率
/// </summary> Welding machine power
/// <param name="DataList"></param>
public delegate void DGShowWeldingPowerData(List<double> DataList);
}
@@ -0,0 +1,118 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{2AB7E380-7795-448A-933C-0F6A081B5E7E}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>JinYuan.VirtualDataLibrary</RootNamespace>
<AssemblyName>JinYuan.VirtualDataLibrary</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="HML, Version=8.0.0.6, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Libs\HML.dll</HintPath>
</Reference>
<Reference Include="PLCCommunication, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Libs\PLCCommunication.dll</HintPath>
</Reference>
<Reference Include="Seagull.BarTender.Print, Version=11.0.7.3146, Culture=neutral, PublicKeyToken=109ff779a1b4cbc7, processorArchitecture=AMD64">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Libs\2016\Seagull.BarTender.Print.dll</HintPath>
</Reference>
<Reference Include="MiniExcel, Version=1.36.1.0, Culture=neutral, PublicKeyToken=e7310002a53eac39, processorArchitecture=MSIL">
<HintPath>..\packages\MiniExcel.1.36.1\lib\net45\MiniExcel.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="CommonMethods.cs" />
<Compile Include="DBSQL.cs" />
<Compile Include="DelegateLib.cs" />
<Compile Include="MesConfig.cs" />
<Compile Include="MsgshowTip.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="MsgshowTip.Designer.cs">
<DependentUpon>MsgshowTip.cs</DependentUpon>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Utlis\BartenderPrinter.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\JinYuan.DAL\JinYuan.DAL.csproj">
<Project>{114aa012-29c9-418c-a2d6-3173c5341f51}</Project>
<Name>JinYuan.DAL</Name>
</ProjectReference>
<ProjectReference Include="..\JinYuan.Helper\JinYuan.Helper.csproj">
<Project>{258d0ab7-2b4f-4d8f-a3cd-7a8cb4a85360}</Project>
<Name>JinYuan.Helper</Name>
</ProjectReference>
<ProjectReference Include="..\JinYuan.MES\JinYuan.MES.csproj">
<Project>{530b6426-08e7-461c-91dc-787f876620fc}</Project>
<Name>JinYuan.MES</Name>
</ProjectReference>
<ProjectReference Include="..\JinYuan.Models\JinYuan.Models.csproj">
<Project>{4c0bcb84-5cd7-4846-8363-c4c10d46e391}</Project>
<Name>JinYuan.Models</Name>
</ProjectReference>
<ProjectReference Include="..\PLC\PLC.csproj">
<Project>{486aecd0-c2bf-43c5-b7d7-88e565ade4b7}</Project>
<Name>PLC</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="MsgshowTip.resx">
<DependentUpon>MsgshowTip.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="Resources\感叹号提示-块红色.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
+430
View File
@@ -0,0 +1,430 @@
using JinYuan.Models;
using JinYuan.VirtualDataLibrary;
using MiniExcelLibs;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows.Forms;
namespace JinYuan.VirtualDataLibrary
{
public class MesConfig
{
/// <summary>
/// 工厂代码
/// </summary>
public string siteCode = "";
/// <summary>
/// 产线编号
/// </summary>
public string lineCode = "";
/// <summary>
/// 设备编号
/// </summary>
public string equipNum = "";
/// <summary>
/// 客户料号
/// </summary>
public string CustomerPartNum = "";
/// MES密码
/// </summary>
public string mesPwd = "";
/// <summary>
/// MES账户
/// </summary>
public string mesUserName = "";
/// <summary>
/// 将电池等级转换成下发PLC的等级编号
/// </summary>
/// <param name="strGrade"></param>
/// <returns></returns>
public static string GetLocGrade(int stationNo, FDConfig fdconfig)
{
string grade = "";
switch (stationNo)
{
case 1:
grade = fdconfig.Grade1;
break;
case 2:
grade = fdconfig.Grade2;
break;
case 3:
grade = fdconfig.Grade3;
break;
}
return grade;
}
// 组盘PLC 机架-工位对应的寄存器
public Dictionary<int, Dictionary<int, string>> gw_loc_plcAddr =
new Dictionary<int, Dictionary<int, string>>()
{
// 机架1:loc1-loc3 对应PLC地址段D21600-D21602
{
1, new Dictionary<int, string>()
{
{1, "D21600"},
{2, "D21601"},
{3, "D21602"}
}
},
// 机架2:loc1-loc3 对应PLC地址段D23600-D23602
{
2, new Dictionary<int, string>()
{
{1, "D23600"},
{2, "D23601"},
{3, "D23602"}
}
},
// 机架3:loc1-loc3 对应PLC地址段D25600-D25602
{
3, new Dictionary<int, string>()
{
{1, "D25600"},
{2, "D25601"},
{3, "D25602"}
}
}
};
//// 电池等级,PLC等级关系
//private static Dictionary<string, int> gradeDic = new Dictionary<string, int>()
//{
// { "V1", 1 },
// { "A", 2 },
// { "A-", 3 },
// { "B", 4 },
// { "NG", 0},
// { "不设置", 0},
//};
//public static List<string> GetGrades()
//{
// var validGradeKeys = gradeDic.Keys.ToList();
// return validGradeKeys;
//}
/// <summary>
/// 将电池等级转换成下发PLC的等级编号
/// </summary>
/// <param name="strGrade"></param>
/// <returns></returns>
//public int GetGradeNo(string strGrade)
//{
// if (gradeDic.TryGetValue(strGrade, out int result))
// {
// return result; // 键存在,返回对应值
// }
// // 键不存在,返回0
// return 0;
//}
/// <summary>
/// 电表编号
/// </summary>
public List<string> electricMeterNum = new List<string>();
/// <summary>
/// 风速仪个数
/// </summary>
public int AntiDustAirSpeedCount = 0;
/// <summary>
/// 风速仪编号
/// </summary>
public List<string> listAntiDustAirSpeedNum = new List<string>();
/// <summary>
/// 权限
/// </summary>
public string userLevel = "";
/// <summary>
/// mes返回权限
/// </summary>
public string mesUserLevel = "";
/// <summary>
/// 物料编码
/// </summary>
public string MaterialCode = "";
/// <summary>
/// 生产型号
/// </summary>
public string ModelName = "";
// 产品型号转plc值
private Dictionary<string, int> modelMapping = new Dictionary<string, int>()
{
{ "LF350S", 1 }, //MB36
{ "LF314", 2 }, //MB31
{ "LF628", 3 }, //MB56
{ "LF668", 3 }, //MB56
{ "MB36", 1 }, //MB36
{ "MB31", 2 }, //MB31
{ "MB56", 3 }, //MB56
};
/// <summary>
/// 将电池型号转换成下发PLC的型号编号
/// </summary>
/// <param name="strGrade"></param>
/// <returns></returns>
public int GetModel(string modelName)
{
if (modelMapping.TryGetValue(modelName, out int result))
{
return result; // 键存在,返回对应值
}
// 键不存在,返回0
return 0;
}
// 物流线各工位,生产型号写PLC地址
private Dictionary<string, string> modelPLCAddr_Mapping = new Dictionary<string, string>()
{
{ "2-1", "D2009" },
{ "2-2", "D2109" },
{ "2-3", "D2209" },
{ "1-1", "D2309" },
{ "1-2", "D2409" },
{ "1-3", "D2509" }
};
public string GetWuliuModelAddr()
{
if (modelPLCAddr_Mapping.TryGetValue(CommonMethods.sysConfig.GongWei, out string plcAdrr))
{
return plcAdrr; // 键存在,返回对应值
}
// 键不存在,返回""
return "";
}
// 物流线各工位,等级写PLC地址
private Dictionary<string, Dictionary<int, string>> gradePLCAddr_Mapping = new Dictionary<string, Dictionary<int, string>>()
{
{ "2-1", new Dictionary<int, string> {{1, "D2006"}, {2, "D2007"}, {3, "D2008"}} },
{ "2-2", new Dictionary<int, string> {{1, "D2106"}, {2, "D2107"}, {3, "D2108"}} },
{ "2-3", new Dictionary<int, string> {{1, "D2206"}, {2, "D2207"}, {3, "D2208"}} },
{ "1-1", new Dictionary<int, string> {{1, "D2306"}, {2, "D2307"}, {3, "D2308"}} },
{ "1-2", new Dictionary<int, string> {{1, "D2406"}, {2, "D2407"}, {3, "D2408"}} },
{ "1-3", new Dictionary<int, string> {{1, "D2506"}, {2, "D2507"}, {3, "D2508"}} }
};
public Dictionary<int, string> GetWuliuGradeAddr()
{
if (gradePLCAddr_Mapping.TryGetValue(CommonMethods.sysConfig.GongWei, out Dictionary<int, string> plc_addrs))
{
return plc_addrs;
}
return new Dictionary<int, string>();
}
// PLC触摸屏用户名称与权限
private Dictionary<string, Dictionary<string, string>> userPLCAddr_Mapping = new Dictionary<string, Dictionary<string, string>>()
{
{ "1-1", new Dictionary<string, string> {{"user", "D22"}, {"right", "D21"}} },
{ "1-2", new Dictionary<string, string> {{"user", "D22"}, {"right", "D21"}} },
{ "1-3", new Dictionary<string, string> {{"user", "D22"}, {"right", "D21"}} },
{ "2-1", new Dictionary<string, string> {{"user", "D22"}, {"right", "D21"}} },
{ "2-2", new Dictionary<string, string> {{"user", "D22"}, {"right", "D21"}} },
{ "2-3", new Dictionary<string, string> {{"user", "D22"}, {"right", "D21"}} },
};
public Dictionary<string, string> GetHMIUserRightAddr()
{
if (userPLCAddr_Mapping.TryGetValue(CommonMethods.sysConfig.GongWei, out Dictionary<string, string> plc_addrs))
{
return plc_addrs;
}
return new Dictionary<string, string>();
}
/// <summary>
/// 是否上传MES
/// </summary>
public bool isUpMes = false;
/// <summary>
/// MES接口URL地址中的IP地址
/// </summary>
public string MESURLAddressIP = "10.100.111.81";
/// <summary>
/// MES接口URL地址中的端口号
/// </summary>
public string MESURLAddressPort = "80";
/// <summary>
/// 是否连接MES
/// </summary>
public bool isConnected = false;
/// <summary>
/// 是否刷卡?
/// </summary>
public bool Isshuaka = false;
/// <summary>
/// 是否登录成功?
/// </summary>
public bool IsLoginOK = false;
/// <summary>
/// 是否登录MES成功?
/// </summary>
public bool IsLoginMesOK = false;
/// <summary>
/// 获取MES参数
/// </summary>
public bool IsMesParam = false;
/// <summary>
/// MES超时
/// </summary>
public long MesOutTime = 0;
/// <summary>
/// 焊接点个数
/// </summary>
public int weldNum = 0;
/// <summary>
/// 是否2个电表(此功能仅适用于908-6负极焊接两台设备共用一台敢接机只有一个电表)
/// </summary>
public bool IsTwoDianBiao = false;
/// <summary>
/// 电表编号
/// </summary>
public string ElectricMeterNum = "";
/// <summary>
/// 除尘风速
/// </summary>
public decimal antiDustAirSpeed = 0;
/// <summary>
/// 电机旋转速度
/// </summary>
public decimal dianjiXzSpeed = 0;
/// <summary>
/// 设备状态上传时间
/// </summary>
public int EquStatuasTime = 0;
/// <summary>
/// 获取服务器数据
/// </summary>
public bool IsGet_Server = true;
/// <summary>
/// 生成假数据
/// </summary>
public bool IsDebug = true;
/// <summary>
/// 钢壳码计数
/// </summary>
public int SteelshellCount = 0;
///// <summary>
///// 每个档位最大电芯数量
///// </summary>
//public int maxBatteriesPerGrade = 240;
/// <summary>
/// 电芯装箱层数
/// </summary>
public int packLayers = 4;
/// <summary>
/// 电芯装箱每层行数
/// </summary>
public int rowsPerLayer = 5;
/// <summary>
/// 电芯装箱每层列数
/// </summary>
public int colsPerLayer = 12;
/// <summary>
/// 卡板托盘计数
/// </summary>
public int CoreCount = 0;
/// <summary>
/// 卡板托盘生成时间
/// </summary>
public string CardTime = "";
/// <summary>
/// 卡板码是否发送成功
/// </summary>
public bool CardSuccess = false;
/// <summary>
/// 原材料上料位置
/// </summary>
public string materialLotCodeLocator = "";
/// <summary>
/// 存储服务器IP地址
/// </summary>
public string RotueServerIP = "192.168.2.108";
/// <summary>
/// 员工权限校验
/// </summary>
public string EmployeeAuthCheck = "http://10.100.111.81/core/api/public/equipment/base/user/permission/verify";
///// <summary>
///// 原材料投入信息
///// </summary>
//public string MaterialInputInfo = "http://10.100.111.81/core/api/public/raw/material/input/un/first/process";
/// <summary>
/// 设备参数设定值请求
/// </summary>
public string DeviceParamRequest = "http://10.100.111.81/core/api/public/param/setting/request";
/// <summary>
/// 设备参数设定值变更
/// </summary>
public string DeviceParamChange = "http://10.100.111.81/core/api/public/param/setting/change";
/// <summary>
/// 料盘信息获取
/// </summary>
public string queryTrayUrl = "http://10.22.160.9/prod-api/produce/trayQuery/trayComposeInfo";
public string queryGradeUrl = "http://10.22.160.141:8080/core/api/public/equip/auto/gradequery";
public string upResultParamUrl = "http://10.22.160.3/core/api/public/process/param/new/result";
/// <summary>
/// 解绑料框码
/// </summary>
public string unbindTrayUrl = "http://10.22.160.9/prod-api/api/fms/mp/unbindWholeTray";
/// <summary>
/// 半成品电池绑盘
/// </summary>
public string packLoadUrl = "http://10.54.50.1:8082/core/api/public/equip/auto/pack/load";
/// <summary>
/// 成品电池绑盘
/// </summary>
public string finishedPackUrl = "http://10.54.50.1:8082/core/api/public/equip/auto/pack/load";
/// <summary>
/// 设备报警信息
/// </summary>
public string DeviceAlarm = "http://10.100.111.81/core/api/public/equipment/alarm/currency";
/// <summary>
/// 设备运行状态
/// </summary>
public string DeviceStatus = "http://10.100.111.81/core/api/public/eve/pm/eqm/run/status/operation";
/// <summary>
/// 能耗数据
/// </summary>
public string EnergyConsumption = "http://10.100.111.81/core/api/public/eve/pm/energy/consumption/collection/submit";
/// <summary>
/// 设备风速接口
/// </summary>
public string Anemometer = "https://iot.eveportal.com:9470/eve_api/ems/iot/upload_device_collect_data";
///// <summary>
///// 进出站一体模式×
///// </summary>
//public string InAndOutStationMesUrl = "http://10.17.96.73/core/api/public/14j/out/station/process/turn-in-out";
/// <summary>
/// appId
/// </summary>
public string AppID = "e36ef900320d442f850913e2ebc1d7a1";
/// <summary>
/// AppKey
/// </summary>
public string AppKey = "8279ce76217245f48c0cc495c09124a3";
/// <summary>
/// 获取TOKEN
/// </summary>
public string GetTokenUrl = "https://esb.evebattery.com:13502/gateway/ewms-eu/openapi/oauth/token";
}
}
+89
View File
@@ -0,0 +1,89 @@
namespace JinYuan.VirtualDataLibrary
{
partial class MsgshowTip
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.label1 = new System.Windows.Forms.Label();
this.timer1 = new System.Windows.Forms.Timer(this.components);
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout();
//
// pictureBox1
//
this.pictureBox1.Image = global::JinYuan.VirtualDataLibrary.Properties.Resources.感叹号提示_块红色;
this.pictureBox1.Location = new System.Drawing.Point(6, 3);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(87, 80);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("微软雅黑", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label1.ForeColor = System.Drawing.Color.Red;
this.label1.Location = new System.Drawing.Point(95, 29);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(345, 28);
this.label1.TabIndex = 1;
this.label1.Text = "与PLC链接断开,请检查通讯线路!";
//
// timer1
//
this.timer1.Interval = 500;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// MsgshowTip
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.Yellow;
this.ClientSize = new System.Drawing.Size(434, 84);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.label1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Name = "MsgshowTip";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "MsgshowTip";
this.Load += new System.EventHandler(this.MsgshowTip_Load);
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Timer timer1;
}
}
+115
View File
@@ -0,0 +1,115 @@
using System;
using System.Drawing;
using System.Windows.Forms;
namespace JinYuan.VirtualDataLibrary
{
public partial class MsgshowTip : Form
{
/// <summary>
/// 图标和文本之间的间距(像素)
/// </summary>
const int IconTextSpacing = 3;
/// <summary>
/// 显示文字
/// </summary>
string _tipText;
/// <summary>
/// 提示图标
/// </summary>
public Image TipIcon { get; set; }
/// <summary>
/// 提示文本
/// </summary>
public string TipText
{
get { return _tipText ?? string.Empty; }
set { _tipText = value; }
}
public MsgshowTip(string Msg)
{
//双缓冲。有必要
SetStyle(ControlStyles.UserPaint, true);
DoubleBuffered = true;
InitializeComponent();
this._tipText = Msg;
}
private void MsgshowTip_Load(object sender, EventArgs e)
{
//ProcessClientSize();
ProcessLocation();
label1.Text = _tipText;
timer1.Enabled = true;
}
/// <summary>
/// 根据图标和文字处理窗体尺寸
/// </summary>
private void ProcessClientSize()
{
Size size = Size.Empty;
if (TipIcon != null)
{
size += TipIcon.Size;
}
if (TipText.Length != 0)
{
if (TipIcon != null)
{
size.Width += IconTextSpacing;//图标与文字的间距
}
var textSize = TextRenderer.MeasureText(TipText, this.Font);
size.Width += textSize.Width;
if (size.Height < textSize.Height) { size.Height = textSize.Height; }
}
this.ClientSize = size + Padding.Size;
}
private int x, y; //显示的坐标变量
private void timer1_Tick(object sender, EventArgs e)
{
this.Close();
}
private void ProcessLocation()
{
#region 弹窗显示在屏幕中间
this.y = (Screen.PrimaryScreen.Bounds.Height - 30 - this.Height) / 2;
this.x = (Screen.PrimaryScreen.Bounds.Width - 10 - this.Width) / 2;
this.Location = new Point(this.x, this.y);
#endregion
#region 弹窗显示在屏幕右下角
//this.x = Screen.PrimaryScreen.WorkingArea.Width - this.Width + 15;
//this.y = Screen.PrimaryScreen.WorkingArea.Height - this.Height * i - 5 * i;
//this.Location = new Point(this.x, this.y);
#endregion
#region 弹窗跟随鼠标位置
//var p = BasePoint;
//p.X -= Screen.PrimaryScreen.WorkingArea.Width - this.Width - 1000;//Screen.PrimaryScreen.WorkingArea.Width-this.Width / 2;
////横向处理。距离屏幕左右两边太近时的处理
//int screenWidth;
//if (p.X < 10)
//{
// p.X = 10;
//}
//else if (p.X + this.Width > (screenWidth = Screen.PrimaryScreen.Bounds.Width) - 10)
//{
// p.X = screenWidth - 10 - this.Width;
//}
////纵向处理。在鼠标上方显示
//p.Y -= this.Height + 20;
//this.Location = p;
#endregion
}
}
}
+123
View File
@@ -0,0 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>
@@ -0,0 +1,35 @@
using System.Reflection;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("JinYuan.VirtualDataLibrary")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("JinYuan.VirtualDataLibrary")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("2ab7e380-7795-448a-933c-0f6a081b5e7e")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -0,0 +1,73 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本:4.0.30319.42000
//
// 对此文件的更改可能会导致不正确的行为,并且如果
// 重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------
namespace JinYuan.VirtualDataLibrary.Properties {
using System;
/// <summary>
/// 一个强类型的资源类,用于查找本地化的字符串等。
/// </summary>
// 此类是由 StronglyTypedResourceBuilder
// 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
// 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
// (以 /str 作为命令选项),或重新生成 VS 项目。
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// 返回此类使用的缓存的 ResourceManager 实例。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("JinYuan.VirtualDataLibrary.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// 重写当前线程的 CurrentUICulture 属性,对
/// 使用此强类型资源类的所有资源查找执行重写。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
/// </summary>
internal static System.Drawing.Bitmap 感叹号提示_块红色 {
get {
object obj = ResourceManager.GetObject("感叹号提示-块红色", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
}
}
@@ -0,0 +1,124 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="感叹号提示-块红色" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\感叹号提示-块红色.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

@@ -0,0 +1,271 @@
using JinYuan.Helper;
using Seagull.BarTender.Print;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
namespace JinYuan.VirtualDataLibrary.Utlis
{
public class BartenderPrinter
{
LabelFormatDocument print;
Engine engine;
string PrinterName;
string PrintLabelType;
/// <summary>
/// 初始化打印机
/// </summary>
/// <param name="PrinterName">打印机名称通过该名称指定打印机</param>
/// <param name="PrintLabelType">打印机类型</param>
public BartenderPrinter(string PrinterName, string PrintLabelType)
{
this.PrinterName = PrinterName;
this.PrintLabelType = PrintLabelType;
engine = new Engine(true);
}
public BartenderPrinter(string PrinterName)
{
this.PrinterName = PrinterName;
engine = new Engine(true);
}
public string[] read(string path)
{
try
{
LabelFormatDocument print;
//System.Diagnostics.Process.Start("ExpLore", path);
print = engine.Documents.Open(path);
//print.PrintSetup.PrinterName = "Microsoft Print to PDF";
//print.PrintSetup.PrinterName = "TSC MX340F";
XmlDocument xml = new XmlDocument();
xml.LoadXml(print.SubStrings.XML);
//string s = print.SubStrings.XML;
//获取XML中SubStrings/SubString
XmlNodeList nodeList = xml.SelectNodes("SubStrings/SubString");
string[] printColumns = new string[print.SubStrings.Count];
int count = 0;
foreach (XmlNode node in nodeList)
{
printColumns[count] = node.Attributes["Name"].Value;
count++;
}
//获取栏位
return printColumns;
}
catch (Exception ex)
{
throw new Exception(ex.ToString());
}
}
/// <summary>
/// 执行打印
/// </summary>
/// <param name="path">文件地址</param>
/// <param name="printValue">字段栏位映射,key BTname ,value BTValue</param>
/// <returns></returns>
public bool write(string path, string jobName, Dictionary<string, string> printValue)
{
try
{
print = engine.Documents.Open(path);
//print.PrintSetup.PrinterName = "Microsoft Print to PDF";
//print.PrintSetup.PrinterName = "TSC MX340";
//print.PrintSetup.PrinterName = "TSC TTP-346MU";
print.PrintSetup.PrinterName = this.PrinterName;
foreach (var oneItem in printValue)
{
print.SubStrings.SetSubString(oneItem.Key, oneItem.Value);
//log.Debug("[" + oneItem.Key + "]=" + oneItem.Value);
}
//Thread.Sleep(100);
Result result = print.Print(jobName); //print.Print("Label Print");
return result == Result.Success ? true : false;
}
catch (Exception ex)
{
LogHelper.Instance.WriteEX(ex);
return false;
}
}
/// <summary>
/// 读取btw檔 并确认各栏位是否能对应的到
/// </summary>
/// <param name="FileId"></param>
/// <param name="Path"></param>
/// <param name="SourceDataTable"></param>
/// <param name="DtPrintColumn"></param>
/// <returns></returns>
public string LoadColumns(string FileId, string Path, DataTable SourceDataTable, DataTable DtPrintColumn)
{
try
{
string msg = "";
string[] btwColumns = read(Path);
for (int i = 0; i < btwColumns.Length; i++)//版面欄位數量
{
bool flag = false;
foreach (DataColumn dc in SourceDataTable.Columns)//資料庫欄位數量
{
if (btwColumns[i] == dc.ColumnName)
{
flag = true;
}
}
if (flag == false)
{
if (msg == "") { msg = btwColumns[i]; }
else { msg += "," + btwColumns[i]; }
}
}
if (msg == "")
{
DataTable dt = DtPrintColumn;
string Id = FileId;
DataRow[] drAry = dt.Select(" Id='" + Id + "'");
for (int j = 0; j < drAry.Length; j++)
{
dt.Rows.Remove(drAry[j]);
}
dt.AcceptChanges();
DataRow drNew;
for (int j = 0; j < btwColumns.Length; j++)
{
drNew = dt.NewRow();
drNew["Id"] = Id;
drNew["Value"] = btwColumns[j];
dt.Rows.Add(drNew);
}
dt.AcceptChanges();
}
return msg;
}
catch (Exception ex)
{
LogHelper.Instance.WriteEX(ex);
return ex.ToString();
}
}
// 列印 Reel或Box或Carton标签
// 偵測非同步處理
public bool PrintLabel(DataRow dr)
{
try
{
string Id = "";
string fileIdColumnName = "";
string filePathColumnName = "";
if (dr == null)
{
LogHelper.Instance.WriteError("DataRow is NULL");
return false;
}
DataTable columnDT = new DataTable();
if (PrintLabelType == "Box")
{
fileIdColumnName = "FileId";
filePathColumnName = "Path";
}
else if (PrintLabelType == "Reel")
{
fileIdColumnName = "ReelFileId";
filePathColumnName = "ReelFilePath";
}
else if (PrintLabelType == "Carton")
{
fileIdColumnName = "FileId";
filePathColumnName = "Path";
}
else if (PrintLabelType == "Carton2")
{
fileIdColumnName = "FileId2";
filePathColumnName = "Path2";
}
else
{
LogHelper.Instance.WriteError("PrintLabelType =" + PrintLabelType);
return false;
}
Id = dr[fileIdColumnName].ToString();
DataRow[] drAry = columnDT.Select("id='" + Id + "'");
Dictionary<string, string> printValue = new Dictionary<string, string>();
for (int i = 0; i < drAry.Length; i++)
{
string column = drAry[i][1].ToString();
printValue.Add(column, dr[column].ToString().TrimEnd());
}
bool writeResult = write(dr[filePathColumnName].ToString(), PrintLabelType, printValue);
return writeResult;
}
catch (Exception ex)
{
LogHelper.Instance.WriteEX(ex);
throw ex;
}
}
//列印 Interior Label 或 Outer Label
public bool PrintSimpleLabel(string chrCkdh, string jobname, string FilePath)
{
try
{
Dictionary<string, string> printValue = new Dictionary<string, string>();
printValue.Add("chrCkdh", chrCkdh.TrimEnd());
bool writeResult = write(FilePath, jobname, printValue);
return writeResult;
}
catch (Exception ex)
{
LogHelper.Instance.WriteEX(ex);
throw ex;
}
}
public bool Close()
{
try
{
engine.Dispose();
return true;
}
catch (Exception ex)
{
LogHelper.Instance.WriteEX(ex);
return false;
}
}
}
}
+63
View File
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.2" newVersion="4.0.1.2" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.4.0" newVersion="4.1.4.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Text.Encoding.CodePages" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Security.Cryptography.Xml" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.1" newVersion="6.0.0.1" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-9.1.0.0" newVersion="9.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.IO.Pipelines" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Google.Protobuf" publicKeyToken="a7d26565bac4d604" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.23.4.0" newVersion="3.23.4.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="ZstdSharp" publicKeyToken="8d151af33a4ad5cf" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-0.7.2.0" newVersion="0.7.2.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Bcl.AsyncInterfaces" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Configuration.ConfigurationManager" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" /></startup></configuration>