775 lines
29 KiB
C#
775 lines
29 KiB
C#
|
using MaiMuControl.SysStatusMgr.UserMgr;
|
|||
|
using System;
|
|||
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
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;
|
|||
|
private readonly string _pointsPath;
|
|||
|
private readonly string _markPicPath;
|
|||
|
#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");
|
|||
|
_pointsPath = Path.Combine(_rootPath, "PointsConfig.ini");
|
|||
|
_markPicPath = Path.Combine(_rootPath, "MarkPic");
|
|||
|
_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; } }
|
|||
|
|
|||
|
public string MarkPicPath { get { return _markPicPath; } }
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 说明书路径
|
|||
|
/// </summary>
|
|||
|
public string SpecificationPath { get { return _specificationPath; } }
|
|||
|
private string _specificationPath;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 上料位X1
|
|||
|
/// </summary>
|
|||
|
public double LoadPoint_X1 { get; set; }
|
|||
|
/// <summary>
|
|||
|
/// 上料位X2
|
|||
|
/// </summary>
|
|||
|
public double LoadPoint_X2 { get; set; }
|
|||
|
/// <summary>
|
|||
|
/// 上料位Y
|
|||
|
/// </summary>
|
|||
|
public double LoadPoint_Y { get; set; }
|
|||
|
/// <summary>
|
|||
|
/// 上料位Z
|
|||
|
/// </summary>
|
|||
|
public double LoadPoint_Z { get; set; }
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 测厚气缸到位等待时间
|
|||
|
/// </summary>
|
|||
|
public int HeightDoWait { get; set; }
|
|||
|
/// <summary>
|
|||
|
/// 加紧气缸到位等待时间
|
|||
|
/// </summary>
|
|||
|
public int ProductDoWait { get; set; }
|
|||
|
#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.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("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);
|
|||
|
|
|||
|
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.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("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("SysFunction", "OpenBuzzer", out bValue);
|
|||
|
sysParams.OpenBuzzer = bValue;
|
|||
|
iniHelper.ReadBool("SysFunction", "OpenDoor", out bValue);
|
|||
|
sysParams.OpenDoor = 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("Sys", "AIModelPath", out sValue);
|
|||
|
sysParams.AIModelPath = sValue.Replace("\0", "");
|
|||
|
iniHelper.ReadString("Sys", "ProductPath", out sValue);
|
|||
|
sysParams.ProductPath = sValue.Replace("\0", "");
|
|||
|
iniHelper.ReadString("Sys", "HttpServerIP", out sValue);
|
|||
|
|
|||
|
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("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.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;
|
|||
|
|
|||
|
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
|
|||
|
|
|||
|
#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 bool SaveAllImg { get; set; }
|
|||
|
/// <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; }
|
|||
|
#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代替io
|
|||
|
/// </summary>
|
|||
|
public bool IsPLC { get; set; }
|
|||
|
/// <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; }
|
|||
|
|
|||
|
#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;
|
|||
|
#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
|
|||
|
|
|||
|
public SysConfigParams()
|
|||
|
{
|
|||
|
DefectSrcImag = new ImageSaveParam("D:\\Image\\DefectSrcImag");
|
|||
|
DefectSmallImag = new ImageSaveParam("D:\\Image\\DefectSmallImag");
|
|||
|
DefectSplicImag = new ImageSaveParam("D:\\Image\\DefectSplicImag");
|
|||
|
|
|||
|
OpenBuzzer = true;
|
|||
|
OpenDoor = true;
|
|||
|
|
|||
|
IODevName = "";
|
|||
|
IOCfgPath = Path.Combine(Directory.GetCurrentDirectory(), "ConfigFiles\\IOCard_default.xml"); ;
|
|||
|
LightCom = "";
|
|||
|
LightComBaud = 9600;
|
|||
|
|
|||
|
SaveAllImg = false;
|
|||
|
|
|||
|
AIModelPath = Path.Combine(Directory.GetCurrentDirectory(), "ConfigFiles\\onnxFiles");
|
|||
|
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;
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
}
|