geboshi_V1/LeatherProject/GeBoShi/SysCtrl/ConfMgr.cs

983 lines
37 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using MaiMuControl.SysStatusMgr.UserMgr;
using Newtonsoft.Json.Linq;
using SqlSugar;
using System;
using System.Collections;
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 ToolKits.Ini;
using ToolKits.mAPI;
namespace GeBoShi.SysCtrl
{
/// <summary>
/// 设备参数
/// </summary>
public class ConfMgr
{
#region
/// <summary>
/// 实例
/// </summary>
private static ConfMgr _instance;
private static readonly object _lock = new object();
public static ConfMgr Instance
{
get
{
if (_instance == null)
{
lock (_lock)
{
if (_instance == null)
{
_instance = new ConfMgr();
}
}
}
return _instance;
}
}
#endregion
#region
private readonly string _rootPath;
private readonly string _configFile;
private readonly string _projectDir;
#endregion
private ConfMgr()
{
_rootPath = Path.Combine(Directory.GetCurrentDirectory(), "ConfigFiles");
_configFile = Path.Combine(_rootPath, "SysParamsConfig.ini");
_devConfigPath = Path.Combine(_rootPath, "DevParamsConfig.ini");
_projectDir = Path.Combine(_rootPath, "Project");
_specificationPath = Path.Combine(_rootPath, "革博士软件操作说明.docx");
DBConStr = "server = localhost; Database = LeatherDB; Uid = root; Pwd = " + ConteolUserDB.GetSqlDBCode() + "; AllowLoadLocalInfile = true;";
}
#region
//DB
//有些服务器防火墙有问题需要加上 min pool size=1 避免认为是恶意请求
//如果用到bulkCopy需要加 AllowLoadLocalInfile=true
public string DBConStr = "server=localhost;Database=LeatherDB;Uid=root;Pwd=123456; AllowLoadLocalInfile=true";
/// <summary>
/// 系统配置参数
/// </summary>
public SysConfigParams SysConfigParams { get; set; }
private string _devConfigPath;
/// <summary>
/// 获取驱动配制文件路径
/// </summary>
public string DevConfigPath { get { return _devConfigPath; } }
//public string ProjectDir { get { return _projectDir; } }
public string ProjectDir { get { return SysConfigParams.ProductPath; } }
/// <summary>
/// 配置文件根路径
/// </summary>
public string ConfigDir { get { return _rootPath; } }
/// <summary>
/// 说明书路径
/// </summary>
public string SpecificationPath { get { return _specificationPath; } }
private string _specificationPath;
#endregion
#region
#region
/// <summary>
/// 写入ini
/// </summary>
/// <param name="SocketParams"></param>
public void WriteSysConfParams(SysConfigParams SysParams)
{
//XmlHelper.Serialize<SysConfParams>(_configFile, sysConfParams);
IniHelper iniHelper = new IniHelper(_configFile);
//iniHelper.WriteBool("SaveAllImg", "SaveAllImg", SysParams.SaveAllImg);
iniHelper.WriteString("DefectSrcImag", "SavePath", SysParams.DefectSrcImag.SavePath);
iniHelper.WriteBool("DefectSrcImag", "AutoSave", SysParams.DefectSrcImag.AutoSave);
iniHelper.WriteBool("DefectSrcImag", "AutoDelete", SysParams.DefectSrcImag.AutoDelete);
iniHelper.WriteDouble("DefectSrcImag", "AutoDeleteDays", SysParams.DefectSrcImag.AutoDeleteDays);
iniHelper.WriteString("DefectSmallImag", "SavePath", SysParams.DefectSmallImag.SavePath);
iniHelper.WriteBool("DefectSmallImag", "AutoSave", SysParams.DefectSmallImag.AutoSave);
iniHelper.WriteBool("DefectSmallImag", "AutoDelete", SysParams.DefectSmallImag.AutoDelete);
iniHelper.WriteDouble("DefectSmallImag", "AutoDeleteDays", SysParams.DefectSmallImag.AutoDeleteDays);
iniHelper.WriteString("DefectSplicImag", "SavePath", SysParams.DefectSplicImag.SavePath);
iniHelper.WriteBool("DefectSplicImag", "AutoSave", SysParams.DefectSplicImag.AutoSave);
iniHelper.WriteBool("DefectSplicImag", "AutoDelete", SysParams.DefectSplicImag.AutoDelete);
iniHelper.WriteDouble("DefectSplicImag", "AutoDeleteDays", SysParams.DefectSplicImag.AutoDeleteDays);
iniHelper.WriteString("Log", "SavePath", SysParams.LogPath);
iniHelper.WriteBool("Log", "AutoDelete", SysParams.AutoDeleteLog);
iniHelper.WriteDouble("Log", "AutoDeleteDays", SysParams.AutoDeleteLogData);
iniHelper.WriteBool("SysFunction", "OpenBuzzer", SysParams.OpenBuzzer);
iniHelper.WriteBool("SysFunction", "OpenDoor", SysParams.OpenDoor);
iniHelper.WriteBool("SysFunction", "OpenIO", SysParams.OpenIO);
iniHelper.WriteBool("SysFunction", "OpenPLC", SysParams.OpenPLC);
iniHelper.WriteString("Dev", "LightCom", SysParams.LightCom);
iniHelper.WriteInteger("Dev", "LightComBaud", SysParams.LightComBaud);
iniHelper.WriteString("Dev", "IODevName", SysParams.IODevName);
iniHelper.WriteString("Dev", "IOCfgPath", SysParams.IOCfgPath);
iniHelper.WriteString("Dev", "PLC_IP", SysParams.PLC_IP);
iniHelper.WriteInteger("Dev", "PLC_Rack", SysParams.PLC_Rack);
iniHelper.WriteInteger("Dev", "PLC_Solt", SysParams.PLC_Solt);
iniHelper.WriteString("Dev", "CamPath_1", SysParams.CamPath_1);
iniHelper.WriteInteger("Dev", "CamDev_1", SysParams.CamDev_1);
iniHelper.WriteInteger("Dev", "CamIndex_1", SysParams.CamIndex_1);
iniHelper.WriteString("Dev", "CamPath_2", SysParams.CamPath_2);
iniHelper.WriteInteger("Dev", "CamDev_2", SysParams.CamDev_2);
iniHelper.WriteInteger("Dev", "CamIndex_2", SysParams.CamIndex_2);
iniHelper.WriteString("Sys", "AIModelPath", SysParams.AIModelPath);
iniHelper.WriteString("Sys", "ProductPath", SysParams.ProductPath);
iniHelper.WriteBool("ShowMainWin", "ShowResetBtn", SysParams.ShowResetBtn);
iniHelper.WriteBool("ShowMainWin", "ShowBuzz", SysParams.ShowBuzz);
iniHelper.WriteBool("ShowMainWin", "ShowDoorAlm", SysParams.ShowDoorAlm);
iniHelper.WriteBool("CloudAndMES", "OpenCloud", SysParams.OpenCloud);
iniHelper.WriteString("CloudAndMES", "CloudThisName", SysParams.CloudThisName);
iniHelper.WriteString("CloudAndMES", "CloudServerIP", SysParams.CloudServerIP);
iniHelper.WriteInteger("CloudAndMES", "CloudServerPort", SysParams.CloudServerPort);
iniHelper.WriteString("CloudAndMES", "CloudUser", SysParams.CloudUser);
iniHelper.WriteString("CloudAndMES", "CloudPassword", SysParams.CloudPassword);
iniHelper.WriteBool("CloudAndMES", "OpenPdtServer", SysParams.OpenPdtServer);
iniHelper.WriteString("CloudAndMES", "PdtServerIP", SysParams.PdtServerIP);
iniHelper.WriteInteger("CloudAndMES", "PdtServerPort", SysParams.PdtServerPort);
iniHelper.WriteBool("CloudAndMES", "IsPdtServer", SysParams.IsPdtServer);
iniHelper.WriteBool("LabelPrint", "EnableLabelPrint", SysParams.EnableLabelPrint);
iniHelper.WriteString("LabelPrint", "LabelPrinterName", SysParams.LabelPrinterName);
iniHelper.WriteBool("ExcelPrint", "EnableExcelPrint", SysParams.EnableExcelPrint);
iniHelper.WriteString("ExcelPrint", "ExcelPrinterName", SysParams.ExcelPrinterName);
iniHelper.WriteString("ERP", "ErpDBConStr", SysParams.ErpDBConStr);
iniHelper.WriteString("ERP", "ErpSql", SysParams.ErpSql);
iniHelper.WriteString("Customer", "CustomerName", SysParams.CustomerName);
iniHelper.WriteBool("FLIP", "Cam1_flipX", SysParams.Cam1_flipX);
iniHelper.WriteBool("FLIP", "Cam1_flipY", SysParams.Cam1_flipY);
iniHelper.WriteBool("FLIP", "Cam2_flipX", SysParams.Cam2_flipX);
iniHelper.WriteBool("FLIP", "Cam2_flipY", SysParams.Cam2_flipY);
iniHelper.WriteInteger("CMPX", "Cm2px_x", SysParams.Cm2px_x);
iniHelper.WriteInteger("CMPX", "Cm2px_y", SysParams.Cm2px_y);
iniHelper.WriteInteger("CMPX", "MidCoin", SysParams.MidCoin);
iniHelper.WriteInteger("CMPX", "HolePx", SysParams.HolePx);
iniHelper.WriteInteger("CMPX", "LCrop", SysParams.LCrop);
iniHelper.WriteInteger("CMPX", "RCrop", SysParams.RCrop);
iniHelper.WriteInteger("CMPX", "Expand_pixel", SysParams.Expand_pixel);
SysConfigParams = SysParams;
}
/// <summary>
/// 读取ini
/// </summary>
/// <returns></returns>
public SysConfigParams ReadSysConfParams()
{
//return XmlHelper.Deserialize<SysConfParams>(_configFile);
SysConfigParams sysParams = new SysConfigParams();
IniHelper iniHelper = new IniHelper(_configFile);
string sValue = "";
int iValue = 0;
double dValue = 0;
bool bValue = false;
//iniHelper.ReadBool("SaveAllImg", "SaveAllImg", out bValue);
//sysParams.SaveAllImg = bValue;
iniHelper.ReadBool("SysFunction", "OpenBuzzer", out bValue);
sysParams.OpenBuzzer = bValue;
iniHelper.ReadBool("SysFunction", "OpenDoor", out bValue);
sysParams.OpenDoor = bValue;
iniHelper.ReadBool("SysFunction", "OpenIO", out bValue);
sysParams.OpenIO = bValue;
iniHelper.ReadBool("SysFunction", "OpenPLC", out bValue);
sysParams.OpenPLC = bValue;
iniHelper.ReadString("Dev", "LightCom", out sValue);
sysParams.LightCom = sValue.Replace("\0", "");
iniHelper.ReadInteger("Dev", "LightComBaud", out iValue);
sysParams.LightComBaud = iValue;
iniHelper.ReadString("Dev", "IODevName", out sValue);
sysParams.IODevName = sValue.Replace("\0", "");
iniHelper.ReadString("Dev", "IOCfgPath", out sValue);
sysParams.IOCfgPath = sValue.Replace("\0", "");
iniHelper.ReadString("Dev", "PLC_IP", out sValue);
sysParams.PLC_IP = sValue.Replace("\0", "");
iniHelper.ReadInteger("Dev", "PLC_Rack", out iValue);
sysParams.PLC_Rack = iValue;
iniHelper.ReadInteger("Dev", "PLC_Solt", out iValue);
sysParams.PLC_Solt = iValue;
iniHelper.ReadString("Dev", "CamPath_1", out sValue);
sysParams.CamPath_1 = sValue.Replace("\0", "");
iniHelper.ReadInteger("Dev", "CamDev_1", out iValue);
sysParams.CamDev_1 = iValue;
iniHelper.ReadInteger("Dev", "CamIndex_1", out iValue);
sysParams.CamIndex_1 = iValue;
iniHelper.ReadString("Dev", "CamPath_2", out sValue);
sysParams.CamPath_2 = sValue.Replace("\0", "");
iniHelper.ReadInteger("Dev", "CamDev_2", out iValue);
sysParams.CamDev_2 = iValue;
iniHelper.ReadInteger("Dev", "CamIndex_2", out iValue);
sysParams.CamIndex_2 = iValue;
iniHelper.ReadBool("CloudAndMES", "OpenCloud", out bValue);
sysParams.OpenCloud = bValue;
iniHelper.ReadString("CloudAndMES", "CloudThisName", out sValue);
sysParams.CloudThisName = sValue.Replace("\0", string.Empty);
iniHelper.ReadString("CloudAndMES", "CloudServerIP", out sValue);
sysParams.CloudServerIP = sValue;
iniHelper.ReadInteger("CloudAndMES", "CloudServerPort", out iValue);
sysParams.CloudServerPort = iValue;
iniHelper.ReadString("CloudAndMES", "CloudUser", out sValue);
sysParams.CloudUser = sValue;
iniHelper.ReadString("CloudAndMES", "CloudPassword", out sValue);
sysParams.CloudPassword = sValue;
iniHelper.ReadBool("CloudAndMES", "OpenPdtServer", out bValue);
sysParams.OpenPdtServer = bValue;
iniHelper.ReadString("CloudAndMES", "PdtServerIP", out sValue);
sysParams.PdtServerIP = sValue;
iniHelper.ReadInteger("CloudAndMES", "PdtServerPort", out iValue);
sysParams.PdtServerPort = iValue;
iniHelper.ReadBool("CloudAndMES", "IsPdtServer", out bValue);
sysParams.IsPdtServer = bValue;
iniHelper.ReadString("DefectSrcImag", "SavePath", out sValue);
sysParams.DefectSrcImag.SavePath = sValue.Replace("\0", "");
iniHelper.ReadBool("DefectSrcImag", "AutoSave", out bValue);
sysParams.DefectSrcImag.AutoSave = bValue;
iniHelper.ReadBool("DefectSrcImag", "AutoDelete", out bValue);
sysParams.DefectSrcImag.AutoDelete = bValue;
iniHelper.ReadDouble("DefectSrcImag", "AutoDeleteDays", out dValue);
sysParams.DefectSrcImag.AutoDeleteDays = dValue;
iniHelper.ReadString("DefectSmallImag", "SavePath", out sValue);
sysParams.DefectSmallImag.SavePath = sValue.Replace("\0", "");
iniHelper.ReadBool("DefectSmallImag", "AutoSave", out bValue);
sysParams.DefectSmallImag.AutoSave = bValue;
iniHelper.ReadBool("DefectSmallImag", "AutoDelete", out bValue);
sysParams.DefectSmallImag.AutoDelete = bValue;
iniHelper.ReadDouble("DefectSmallImag", "AutoDeleteDays", out dValue);
sysParams.DefectSmallImag.AutoDeleteDays = dValue;
iniHelper.ReadString("DefectSplicImag", "SavePath", out sValue);
sysParams.DefectSplicImag.SavePath = sValue.Replace("\0", "");
iniHelper.ReadBool("DefectSplicImag", "AutoSave", out bValue);
sysParams.DefectSplicImag.AutoSave = bValue;
iniHelper.ReadBool("DefectSplicImag", "AutoDelete", out bValue);
sysParams.DefectSplicImag.AutoDelete = bValue;
iniHelper.ReadDouble("DefectSplicImag", "AutoDeleteDays", out dValue);
sysParams.DefectSplicImag.AutoDeleteDays = dValue;
iniHelper.ReadString("Sys", "AIModelPath", out sValue);
sysParams.AIModelPath = sValue.Replace("\0", "");
iniHelper.ReadString("Sys", "ProductPath", out sValue);
sysParams.ProductPath = sValue.Replace("\0", "");
iniHelper.ReadString("Log", "SavePath", out sValue);
sysParams.LogPath = sValue.Replace("\0", "");
iniHelper.ReadBool("Log", "AutoDelete", out bValue);
sysParams.AutoDeleteLog = bValue;
iniHelper.ReadDouble("Log", "AutoDeleteDays", out dValue);
sysParams.AutoDeleteLogData = dValue;
iniHelper.ReadBool("ShowMainWin", "ShowResetBtn", out bValue);
sysParams.ShowResetBtn = bValue;
iniHelper.ReadBool("ShowMainWin", "ShowBuzz", out bValue);
sysParams.ShowBuzz = bValue;
iniHelper.ReadBool("ShowMainWin", "ShowDoorAlm", out bValue);
sysParams.ShowDoorAlm = bValue;
iniHelper.ReadBool("FLIP", "Cam1_flipX", out bValue);
sysParams.Cam1_flipX = bValue;
iniHelper.ReadBool("FLIP", "Cam1_flipY", out bValue);
sysParams.Cam1_flipY = bValue;
iniHelper.ReadBool("FLIP", "Cam2_flipX", out bValue);
sysParams.Cam2_flipX = bValue;
iniHelper.ReadBool("FLIP", "Cam2_flipY", out bValue);
sysParams.Cam2_flipY = bValue;
iniHelper.ReadInteger("CMPX", "Cm2px_x", out iValue);
sysParams.Cm2px_x = iValue;
iniHelper.ReadInteger("CMPX", "Cm2px_y", out iValue);
sysParams.Cm2px_y = iValue;
iniHelper.ReadInteger("CMPX", "MidCoin", out iValue);
sysParams.MidCoin = iValue;
iniHelper.ReadInteger("CMPX", "HolePx", out iValue);
sysParams.HolePx = iValue;
iniHelper.ReadInteger("CMPX", "LCrop", out iValue);
sysParams.LCrop = iValue;
iniHelper.ReadInteger("CMPX", "RCrop", out iValue);
sysParams.RCrop = iValue;
iniHelper.ReadInteger("CMPX", "Expand_pixel", out iValue);
sysParams.Expand_pixel = iValue;
iniHelper.ReadBool("LabelPrint", "EnableLabelPrint", out bValue);
sysParams.EnableLabelPrint = bValue;
iniHelper.ReadString("LabelPrint", "LabelPrinterName", out sValue);
sysParams.LabelPrinterName = sValue;
iniHelper.ReadBool("ExcelPrint", "EnableExcelPrint", out bValue);
sysParams.EnableExcelPrint = bValue;
iniHelper.ReadString("ExcelPrint", "ExcelPrinterName", out sValue);
sysParams.ExcelPrinterName = sValue;
iniHelper.ReadString("ERP", "ErpDBConStr", out sValue);
sysParams.ErpDBConStr = sValue;
iniHelper.ReadString("ERP", "ErpSql", out sValue);
sysParams.ErpSql = sValue;
iniHelper.ReadString("Customer", "CustomerName", out sValue);
sysParams.CustomerName = sValue;
iniHelper.ReadString("Material", "SuedeList", out sValue);
if (!string.IsNullOrWhiteSpace(sValue))
sysParams.SuedeList = sValue.Split(new char[] { ',', ';' });
SysConfigParams = sysParams;
return sysParams;
}
/// <summary>
/// 写入系统默认配置
/// </summary>
public void WriteDefaultSystemConfig()
{
SysConfigParams = new SysConfigParams();
WriteSysConfParams(SysConfigParams);
}
/// <summary>
/// 加载系统配置
/// </summary>
/// <returns></returns>
public bool LoadSystemConfig()
{
bool ret = false;
if (!Directory.Exists(_rootPath))
{
Directory.CreateDirectory(_rootPath);
}
if (!Directory.Exists(_projectDir))
{
Directory.CreateDirectory(_projectDir);
}
if (File.Exists(_configFile))
{
SysConfigParams = ReadSysConfParams();
if (null != SysConfigParams)
{
ret = true;
}
}
else
{
// write default value
WriteDefaultSystemConfig();
ret = true;
}
return ret;
}
#endregion
#region
/// <summary>
/// 选择目录
/// </summary>
/// <returns></returns>
public static string SelectFolder(string defaultPath = "")
{
FolderBrowserDialog dlg = new FolderBrowserDialog();
dlg.SelectedPath = (defaultPath != "" ? defaultPath : Path.GetFullPath("."));
if (dlg.ShowDialog() == DialogResult.OK)
return dlg.SelectedPath;
return "";
}
/// <summary>
/// 选择文件
/// </summary>
/// <param name="filter">如 图像文件|*.jpg|图像文件|*.png|所有文件|*.*</param>
/// <returns></returns>
public static string SelectFile(string filter = "所有文件|*.*", string defaultPath = "")
{
OpenFileDialog fie = new OpenFileDialog();
fie.Title = "选择文件";
//fie.InitialDirectory = (defaultPath != "" ? defaultPath : Path.GetFullPath("."));
fie.Filter = filter; //设置文件类型
if (fie.ShowDialog() == DialogResult.OK)
return fie.FileName;
return "";
}
/// <summary>
/// 删除指定目录下文件
/// </summary>
/// <param name="defaultPath"></param>
/// <param name="fileExtend"></param>
/// <returns></returns>
public static bool DelFilesInFolder(string FolderPath, string fileExtend = "*")
{
if (!Directory.Exists(FolderPath))
return false;
string[] files = Directory.GetFiles(FolderPath, fileExtend, SearchOption.TopDirectoryOnly);
foreach (string file in files)
API.DeleteFile(file);
return true;
}
/// <summary>
/// 另存为
/// </summary>
/// <param name="defaultFileName">默认文件名</param>
/// <param name="filter">如 图像文件|*.jpg|图像文件|*.png|所有文件|*.*</param>
/// <returns></returns>
public static string SaveAsFile(string defaultFileName, string filter = "所有文件|*.*")
{
SaveFileDialog s = new SaveFileDialog();
s.Title = "保存文件";
s.Filter = filter; //"图像文件|*.jpg|图像文件|*.png|所有文件|*.*";
//s.DefaultExt = "图像文件|*.jpg"; //默认扩展名
//s.InitialDirectory = @"C:\Users\Administrator\Desktop"; //保存的初始目录
s.FileName = defaultFileName;//默认文件名
if (s.ShowDialog() == DialogResult.OK)
return s.FileName;
return "";
}
#endregion
#region json操作
//public static void addKey(JObject obj, string key, JToken value)
//{
// if (obj.ContainsKey(key))
// obj[key] = value;
// else
// obj.Add(key, value);
//}
#endregion
#region enum名称
public static ArrayList GetArrayList<T>()
{
ArrayList list = new ArrayList();
Type type = typeof(T);
//list.Add(new DictionaryEntry("start", "启动按钮"));
foreach (int value in Enum.GetValues(type))
{
string strName = Enum.GetName(type, value);//获取名称
list.Add(new DictionaryEntry(value, strName));
}
return list;
}
#endregion
#region
public bool SetDailyOutputAdd(out int tDailyOutput)
{
bool ret = true;
try
{
//读取数据
string tempFile = Path.Combine(_rootPath, "DailyOutput.ini");
IniHelper iniHelper = new IniHelper(tempFile);
int iValue = 0;
iniHelper.ReadInteger("TempData", "DailyOutput", out iValue);
tDailyOutput = iValue;
iniHelper.ReadInteger("TempData", "Date", out iValue);
int dateNum = iValue;
int nowDateNum = int.Parse(DateTime.Now.ToString("yyyyMMdd"));
if (dateNum == nowDateNum)
{
//同一天,生产数量+1
tDailyOutput++;
}
else if (dateNum < nowDateNum)
{
//昨天数据为1
tDailyOutput = 1;
}
//重新记录
iniHelper.WriteInteger("TempData", "DailyOutput", tDailyOutput);
iniHelper.WriteInteger("TempData", "Date", nowDateNum);
}
catch (Exception ex)
{
tDailyOutput = 0;
ret = false;
string tempFile = Path.Combine(_rootPath, "DailyOutput.ini");
IniHelper iniHelper = new IniHelper(tempFile);
int nowDateNum = int.Parse(DateTime.Now.ToString("yyyyMMdd"));
//重新记录
iniHelper.WriteInteger("TempData", "DailyOutput", tDailyOutput);
iniHelper.WriteInteger("TempData", "Date", nowDateNum);
}
return ret;
}
public bool GetDailyOutput(out int tDailyOutput)
{
bool ret = true;
try
{
//读取数据
string tempFile = Path.Combine(_rootPath, "DailyOutput.ini");
IniHelper iniHelper = new IniHelper(tempFile);
int iValue = 0;
iniHelper.ReadInteger("TempData", "DailyOutput", out iValue);
tDailyOutput = iValue;
iniHelper.ReadInteger("TempData", "Date", out iValue);
int dateNum = iValue;
int nowDateNum = int.Parse(DateTime.Now.ToString("yyyyMMdd"));
if (dateNum == nowDateNum)
{
//同一天,生产数量+1
//tDailyOutput++;
}
else if (dateNum < nowDateNum)
{
//昨天数据为1
tDailyOutput = 0;
}
}
catch (Exception ex)
{
tDailyOutput = 0;
ret = false;
}
return ret;
}
#endregion
#region ERP数据库
private SqlSugarClient db;
public SqlSugarClient getErpDBCon(SqlSugar.DbType dbType = SqlSugar.DbType.SqlServer)
{
if (string.IsNullOrEmpty(SysConfigParams.ErpDBConStr))
return null;
if (db != null) return db;
db = new SqlSugarClient(new ConnectionConfig()
{
ConnectionString = SysConfigParams.ErpDBConStr,
DbType = dbType,
IsAutoCloseConnection = true
},
db =>
{
db.Aop.OnLogExecuting = (sql, pars) =>
{
Console.WriteLine(sql);//输出sql,查看执行sql 性能无影响
//获取原生SQL推荐 5.1.4.63 性能OK
//UtilMethods.GetNativeSql(sql,pars)
//获取无参数化SQL 对性能有影响特别大的SQL参数多的调试使用
//UtilMethods.GetSqlString(DbType.SqlServer,sql,pars)
};
});
return db;
}
public DataTable execSql(string sql, List<SugarParameter> parameters, SqlSugar.DbType dbType = SqlSugar.DbType.SqlServer)
{
//查询表的所有
var mydb = getErpDBCon(dbType);
if (mydb == null) return null;
if (!mydb.Ado.IsValidConnection())
mydb.Ado.Open();
return mydb.Ado.GetDataTable(sql, parameters);
}
#endregion
#endregion
}
#region
/// <summary>
/// 图片保存参数
/// </summary>
[Serializable]
public class ImageSaveParam
{
/// <summary>
/// 保存路径
/// </summary>
public string SavePath { get; set; }
/// <summary>
/// 自动保存
/// </summary>
public bool AutoSave { get; set; }
/// <summary>
/// 自动删除
/// </summary>
public bool AutoDelete { get; set; }
/// <summary>
/// 自动删除日期
/// </summary>
public double AutoDeleteDays { get; set; }
public ImageSaveParam()
{
SavePath = "D:\\AllImageSave";
AutoSave = true;
AutoDelete = true;
AutoDeleteDays = 3;
}
public ImageSaveParam(string path)
{
SavePath = path;
AutoSave = true;
AutoDelete = true;
AutoDeleteDays = 3;
}
}
[Serializable]
public class SysConfigParams
{
#region
/// <summary>
/// 缺陷原大图
/// </summary>
public ImageSaveParam DefectSrcImag { get; set; }
/// <summary>
/// 缺陷合并图
/// </summary>
public ImageSaveParam DefectSplicImag { get; set; }
/// <summary>
/// 缺陷小图
/// </summary>
public ImageSaveParam DefectSmallImag { get; set; }
#endregion
#region
/// <summary>
/// 开启蜂鸣器
/// </summary>
public bool OpenBuzzer { get; set; }
/// <summary>
/// 开启门磁
/// </summary>
public bool OpenDoor { get; set; }
/// <summary>
/// 开启IO
/// </summary>
public bool OpenIO { get; set; }
/// <summary>
/// 开启PLC
/// </summary>
public bool OpenPLC { get; set; }
#endregion
#region
/// <summary>
/// 光源串口
/// </summary>
//public LightParams LightCfg { get; set; }
public string LightCom { get; set; }
/// <summary>
/// 光源波特率
/// </summary>
public int LightComBaud { get; set; }
#endregion
#region IO//
/// <summary>
/// 西门子PLC IP
/// </summary>
public string PLC_IP { get; set; }
/// <summary>
/// 西门子PLC 端口
/// </summary>
public int PLC_Rack { get; set; }
/// <summary>
/// 西门子PLC 端口
/// </summary>
public int PLC_Solt { get; set; }
/// <summary>
/// IO驱动名称
/// </summary>
//public IOParams IOCfg { get; set; }
public string IODevName { get; set; }
/// <summary>
/// IO配置文件路径
/// </summary>
public string IOCfgPath { get; set; }
/// <summary>
/// 相机序号
/// </summary>
public int CamIndex_1 { get; set; }
/// <summary>
/// 相机板卡序号
/// </summary>
public int CamDev_1 { get; set; }
/// <summary>
/// 相机配置文件
/// </summary>
public string CamPath_1 { get; set; }
/// <summary>
/// 相机序号
/// </summary>
public int CamIndex_2 { get; set; }
/// <summary>
/// 相机板卡序号
/// </summary>
public int CamDev_2 { get; set; }
/// <summary>
/// 相机配置文件
/// </summary>
public string CamPath_2 { get; set; }
#endregion
#region
public string AIModelPath { get; set; }
public string ProductPath { get; set; }
public string LogPath { get; set; }
public bool AutoDeleteLog { get; set; }
public double AutoDeleteLogData { get; set; }
/// <summary>
/// 调试:主界面显示复位按钮
/// </summary>
public bool ShowResetBtn { get; set; }
/// <summary>
/// 调试:主界面显示蜂鸣器控制
/// </summary>
public bool ShowBuzz { get; set; }
/// <summary>
/// 调试:主界面显示门磁报警控制
/// </summary>
public bool ShowDoorAlm { get; set; }
/// <summary>
/// 1cm X方向像素
/// </summary>
public int Cm2px_x = 1;
/// <summary>
/// 1cm Y方向像素
/// </summary>
public int Cm2px_y = 1;
/// <summary>
/// 对比度范围阔算
/// </summary>
public int Expand_pixel = 50;
/// <summary>
/// 中间重合像素
/// </summary>
public int MidCoin = 100;
/// <summary>
/// 孔位
/// </summary>
public int HolePx = 100;
/// <summary>
/// 左侧裁剪
/// </summary>
public int LCrop = 0;
/// <summary>
/// 右侧裁剪
/// </summary>
public int RCrop = 0;
/// <summary>
/// 相机1X翻转
/// </summary>
public bool Cam1_flipX { get; set; }
/// <summary>
/// 相机1Y翻转
/// </summary>
public bool Cam1_flipY { get; set; }
/// <summary>
/// 相机2X翻转
/// </summary>
public bool Cam2_flipX { get; set; }
/// <summary>
/// 相机2Y翻转
/// </summary>
public bool Cam2_flipY { get; set; }
#endregion
#region Http/MES
#endregion
#region MQTT本地云/
/// <summary>
/// 开启局域网云端
/// </summary>
public bool OpenCloud { get; set; }
public string CloudThisName { get; set; }
public string CloudServerIP { get; set; }
public int CloudServerPort { get; set; }
public string CloudUser { get; set; }
public string CloudPassword { get; set; }
/// <summary>
/// 开启产品转发
/// </summary>
public bool OpenPdtServer { get; set; }
public string PdtServerIP { get; set; }
public int PdtServerPort { get; set; }
/// <summary>
/// 是否作为服务器还是客户端
/// </summary>
public bool IsPdtServer { get; set; }
#endregion
#region BarTender
/// <summary>
/// 开启标签打印
/// </summary>
public bool EnableLabelPrint { get; set; }
/// <summary>
/// 打印机名称
/// </summary>
public string LabelPrinterName { get; set; }
#endregion
#region Excel
/// <summary>
/// 开启Excel打印
/// </summary>
public bool EnableExcelPrint { get; set; }
/// <summary>
/// 打印机名称
/// </summary>
public string ExcelPrinterName { get; set; }
#endregion
#region ERP
/// <summary>
/// 禾欣ERP数据库
/// </summary>
public string ErpDBConStr { get; set; }
/// <summary>
/// 禾欣ERP数据读取
/// </summary>
public string ErpSql { get; set; }
#endregion
#region
/// <summary>
/// 客户名
/// </summary>
public string CustomerName { get; set; }
#endregion
#region
//材质Material
public string[] SuedeList = new string[0];
#endregion
public SysConfigParams()
{
DefectSrcImag = new ImageSaveParam("D:\\Image\\DefectSrcImag");
DefectSmallImag = new ImageSaveParam("D:\\Image\\DefectSmallImag");
DefectSplicImag = new ImageSaveParam("D:\\Image\\DefectSplicImag");
OpenBuzzer = true;
OpenDoor = true;
OpenIO = true;
OpenPLC = true;
IODevName = "";
IOCfgPath = Path.Combine(Directory.GetCurrentDirectory(), "ConfigFiles\\IOCard_default.xml"); ;
LightCom = "";
LightComBaud = 9600;
PLC_IP = "192.168.0.1";
PLC_Rack = 0;
PLC_Solt = 1;
CamIndex_1 = 0;
CamIndex_2 = 0;
CamDev_1 = 0;
CamDev_2 = 1;
CamPath_1 = "";
CamPath_2 = "";
AIModelPath = Path.Combine(Directory.GetCurrentDirectory(), "ConfigFiles\\Models");
ProductPath = Path.Combine(Directory.GetCurrentDirectory(), "ConfigFiles\\Project");
LogPath = Path.Combine(Directory.GetCurrentDirectory(), "LogFiles");
AutoDeleteLog = false;
AutoDeleteLogData = 0;
ShowResetBtn = true;
ShowBuzz = false;
ShowDoorAlm = false;
EnableLabelPrint = false;
LabelPrinterName = "";
EnableExcelPrint = false;
ExcelPrinterName = "";
OpenCloud = false;
CloudThisName = "Test";
CloudServerIP = "127.0.0.1";
CloudServerPort = 1883;
CloudUser = "";
CloudPassword = "";
OpenPdtServer = false;
PdtServerIP = "127.0.0.1";
PdtServerPort = 10573;
IsPdtServer = true;
ErpDBConStr = "";
ErpSql = "";
CustomerName = "";
Cam1_flipX = false;
Cam1_flipY = false;
Cam2_flipX = false;
Cam2_flipY = false;
}
}
#endregion
}