8 Commits

Author SHA1 Message Date
gongxh
43fa85e6e8 添加Dapper 2022-05-05 13:35:22 +08:00
gongxh
235f9767a7 修改 2022-05-05 13:14:07 +08:00
gongxh
8cce51203e 1 2022-05-05 09:53:00 +08:00
gongxh
3593c53fbe 修改 2022-05-05 09:38:28 +08:00
gongxh
ff80fe49e3 修改 2022-05-05 09:25:58 +08:00
gongxh
36b3831689 修改 2022-05-05 09:20:32 +08:00
gongxh
b260f034a2 1 2022-05-05 09:15:42 +08:00
gongxh
fe3f0f0f9e 1 2022-05-05 09:12:10 +08:00
10 changed files with 109 additions and 51 deletions

View File

@@ -7,9 +7,9 @@
<appSettings> <appSettings>
<add key="GlobalPaletteMode" value="Professionaloffice2003"/> <!--<add key="GlobalPaletteMode" value="Professionaloffice2003"/>-->
<add key="LanguageCode" value="zh-CN"/> <add key="LanguageCode" value="zh-CN"/>
<!--<add key="LanguageCode" value="en-US"/>--> <!--<add key="LanguageCode" value="English"/>-->
<add key="sqlmapConfigPath" value="Config/sqlmap.config"/> <add key="sqlmapConfigPath" value="Config/sqlmap.config"/>
<!--MySql数据库连接字符串--> <!--MySql数据库连接字符串-->
<add key="LeadMySql" value="Data Source = localhost; Port=3306;Initial Catalog = testasrs; Persist Security Info=True;User ID = root; Password=sa1234567;"/> <add key="LeadMySql" value="Data Source = localhost; Port=3306;Initial Catalog = testasrs; Persist Security Info=True;User ID = root; Password=sa1234567;"/>

View File

@@ -55,6 +55,12 @@
<None Update="DataBase\clearMac.db"> <None Update="DataBase\clearMac.db">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
<None Update="Lang\en-US.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Lang\zh-CN.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Properties\Settings.settings"> <None Update="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator> <Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput> <LastGenOutput>Settings.Designer.cs</LastGenOutput>

View File

@@ -481,7 +481,7 @@ namespace CleanMachineHMI.FrmUserControl
private void FinishWorkingPallet() private void FinishWorkingPallet()
{ {
#if !DEBUG #if RELEASE
try try
{ {
#endif #endif
@@ -575,7 +575,7 @@ namespace CleanMachineHMI.FrmUserControl
})); }));
} }
} }
#if !DEBUG #if RELEASE
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -3144,7 +3144,7 @@ namespace CleanMachineHMI.FrmUserControl
{ {
kbtn_forceFinish.Enabled = false; kbtn_forceFinish.Enabled = false;
#if !DEBUG #if RELEASE
try try
{ {
@@ -3384,7 +3384,7 @@ namespace CleanMachineHMI.FrmUserControl
} }
} }
kryptonGroupBox1.Focus(); kryptonGroupBox1.Focus();
#if !DEBUG #if RELEASE
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@@ -27,7 +27,9 @@ namespace CleanMachineHMI
Application.EnableVisualStyles(); Application.EnableVisualStyles();
//frmUtil.DB2Json();//语言字典从数据库转json //frmUtil.DB2Json();//语言字典从数据库转json
GlobalHelper.LoadTheme(); GlobalHelper.LoadTheme();
#if DEBUG
GlobalHelper.LoadzhCN(); GlobalHelper.LoadzhCN();
#endif
Application.SetCompatibleTextRenderingDefault(false); Application.SetCompatibleTextRenderingDefault(false);
GlobalHelper.LoadAllFormData(); GlobalHelper.LoadAllFormData();
Application.Run(GlobalHelper.LoginForm); Application.Run(GlobalHelper.LoginForm);

View File

@@ -189,8 +189,8 @@ namespace CleanMachineHMI
{ {
if (ThemeLanguage == null || ThemeLanguage.Count == 0) if (ThemeLanguage == null || ThemeLanguage.Count == 0)
{ {
var appPath = System.Windows.Forms.Application.StartupPath.Split(new string[] { @"bin\Debug" }, StringSplitOptions.RemoveEmptyEntries)[0]; // var appPath = System.Windows.Forms.Application.StartupPath.Split(new string[] { @"bin\Debug" }, StringSplitOptions.RemoveEmptyEntries)[0];
var filePath = appPath + $"Lang\\{GlobalHelper.LanguageCode}.json"; var filePath = $"Lang\\{GlobalHelper.LanguageCode}.json";
var str = File.ReadAllText(filePath); var str = File.ReadAllText(filePath);
var lstLanguage = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ThemeLanguage>>(str); var lstLanguage = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ThemeLanguage>>(str);
var tmpThemeLanguage = new Dictionary<string, string>(); var tmpThemeLanguage = new Dictionary<string, string>();

View File

@@ -1,8 +1,14 @@
//使用本地调式 //使用本地调式
#define USE_LOCAL_TCP_DEBUG
//启用心跳检查
// #define UseHeartbeat
#if DEBUG
//#define USE_LOCAL_TCP_DEBUG
#endif
//启用心跳检查
#if RELEASE
#define UseHeartbeat
#endif
using CleanMachine.Model; using CleanMachine.Model;
using LeadDataBaseUtility; using LeadDataBaseUtility;
@@ -84,7 +90,7 @@ namespace CleanMachineHMI
public bool PlcInit() public bool PlcInit()
{ {
#if !DEBUG #if RELEASE
try try
{ {
#endif #endif
@@ -122,8 +128,8 @@ namespace CleanMachineHMI
#endif #endif
return true; return true;
#if !DEBUG #if RELEASE
} }
catch (Exception ex) catch (Exception ex)
{ {
LogHelper.WriteLog($"初始化PLC连接时发生异常:【{ex.Message}】", LogTypeEum.Err); LogHelper.WriteLog($"初始化PLC连接时发生异常:【{ex.Message}】", LogTypeEum.Err);
@@ -147,7 +153,7 @@ namespace CleanMachineHMI
} }
public void RefreshPlcItem_M() public void RefreshPlcItem_M()
{ {
#if !DEBUG #if RELEASE
try try
{ {
#endif #endif
@@ -163,8 +169,8 @@ namespace CleanMachineHMI
{ {
if (!string.IsNullOrEmpty(item.PlcItemDeviationAddress)) if (!string.IsNullOrEmpty(item.PlcItemDeviationAddress))
{ {
string PlcItemId = item.PlcItemId.ToString(); //string PlcItemId = item.PlcItemId.ToString();
string plcdatatype = item.PlcItemDataType.ToString(); // string plcdatatype = item.PlcItemDataType.ToString();
int plcItemDeviationAddress = Convert.ToInt32(item.PlcItemDeviationAddress); int plcItemDeviationAddress = Convert.ToInt32(item.PlcItemDeviationAddress);
item.PlcItemValue = readBytArr_M[plcItemDeviationAddress].ToString(); item.PlcItemValue = readBytArr_M[plcItemDeviationAddress].ToString();
GlobalHelper.ShowSensorStatus(item, new EventArgs()); GlobalHelper.ShowSensorStatus(item, new EventArgs());
@@ -174,8 +180,8 @@ namespace CleanMachineHMI
{ {
if (!string.IsNullOrEmpty(item.PlcItemDeviationAddress)) if (!string.IsNullOrEmpty(item.PlcItemDeviationAddress))
{ {
string PlcItemId = item.PlcItemId.ToString(); //string PlcItemId = item.PlcItemId.ToString();
string plcdatatype = item.PlcItemDataType.ToString(); //string plcdatatype = item.PlcItemDataType.ToString();
int plcItemDeviationAddress = Convert.ToInt32(item.PlcItemDeviationAddress); int plcItemDeviationAddress = Convert.ToInt32(item.PlcItemDeviationAddress);
item.PlcItemValue = readBytArr_M1[plcItemDeviationAddress].ToString(); item.PlcItemValue = readBytArr_M1[plcItemDeviationAddress].ToString();
GlobalHelper.ShowSensorStatus(item, new EventArgs()); GlobalHelper.ShowSensorStatus(item, new EventArgs());
@@ -184,7 +190,7 @@ namespace CleanMachineHMI
} }
} }
} }
#if !DEBUG #if RELEASE
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -194,7 +200,7 @@ namespace CleanMachineHMI
} }
public void RefreshPlcItem_D() public void RefreshPlcItem_D()
{ {
#if !DEBUG #if RELEASE
try try
{ {
#endif #endif
@@ -210,7 +216,7 @@ namespace CleanMachineHMI
{ {
string PlcItemId = item.PlcItemId.ToString(); string PlcItemId = item.PlcItemId.ToString();
string plcdatatype = item.PlcItemDataType.ToString(); // string plcdatatype = item.PlcItemDataType.ToString();
int plcItemDeviationAddress = Convert.ToInt32(item.PlcItemDeviationAddress); int plcItemDeviationAddress = Convert.ToInt32(item.PlcItemDeviationAddress);
if (Convert.ToInt32(item.PlcItemPriAddress) < 409) if (Convert.ToInt32(item.PlcItemPriAddress) < 409)
{ {
@@ -249,7 +255,7 @@ namespace CleanMachineHMI
} }
HandleWaringLog(tmpReadAlarmBytArr_D); HandleWaringLog(tmpReadAlarmBytArr_D);
} }
#if !DEBUG #if RELEASE
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -261,7 +267,7 @@ namespace CleanMachineHMI
//报警信息记录 //报警信息记录
private void HandleWaringLog(ushort[] tmpReadAlarmBytArr_D) private void HandleWaringLog(ushort[] tmpReadAlarmBytArr_D)
{ {
#if !DEBUG #if RELEASE
try try
{ {
#endif #endif
@@ -587,7 +593,7 @@ namespace CleanMachineHMI
//frmMainNew.Show_ptb_Alarm(false); //frmMainNew.Show_ptb_Alarm(false);
GlobalHelper.ShowMainFrmAlarmMsg(false, EventArgs.Empty); GlobalHelper.ShowMainFrmAlarmMsg(false, EventArgs.Empty);
} }
#if !DEBUG #if RELEASE
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -598,7 +604,7 @@ namespace CleanMachineHMI
public void RefreshPlcItem_X() public void RefreshPlcItem_X()
{ {
#if !DEBUG #if RELEASE
try try
{ {
#endif #endif
@@ -626,7 +632,7 @@ namespace CleanMachineHMI
} }
} }
} }
#if !DEBUG #if RELEASE
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -637,7 +643,7 @@ namespace CleanMachineHMI
public void RefreshPlcItem_Y() public void RefreshPlcItem_Y()
{ {
#if !DEBUG #if RELEASE
try try
{ {
#endif #endif
@@ -665,7 +671,7 @@ namespace CleanMachineHMI
} }
} }
} }
#if !DEBUG #if RELEASE
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -677,7 +683,7 @@ namespace CleanMachineHMI
public object ReadPlcItem(string plcItemCode, PlcItemTypeDesc itemType) public object ReadPlcItem(string plcItemCode, PlcItemTypeDesc itemType)
{ {
#if !DEBUG #if RELEASE
try try
{ {
#endif #endif
@@ -750,7 +756,7 @@ namespace CleanMachineHMI
break; break;
} }
return retObj; return retObj;
#if !DEBUG #if RELEASE
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -763,7 +769,7 @@ namespace CleanMachineHMI
public bool WritePlcItem(string plcItemCode, string writeValue, PlcItemTypeDesc itemType) public bool WritePlcItem(string plcItemCode, string writeValue, PlcItemTypeDesc itemType)
{ {
#if !DEBUG #if RELEASE
try try
{ {
#endif #endif
@@ -798,7 +804,7 @@ namespace CleanMachineHMI
default: default:
return false; return false;
} }
#if !DEBUG #if RELEASE
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -809,13 +815,13 @@ namespace CleanMachineHMI
} }
private int wcsToPlcHeartDataNew = 0; private int wcsToPlcHeartDataNew = 0;
private DateTime HeartbeatTime = new DateTime(); private DateTime HeartbeatTime = new DateTime();
private int ReConnNum = 1;
/// <summary> /// <summary>
/// 心跳处理 /// 心跳处理
/// </summary> /// </summary>
public void HeartbeatDetection() public void HeartbeatDetection()
{ {
#if !DEBUG #if RELEASE
try try
{ {
#endif #endif
@@ -889,7 +895,7 @@ namespace CleanMachineHMI
} }
#endif #endif
#if !DEBUG #if RELEASE
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@@ -265,9 +265,10 @@ namespace CleanMachineHMI.Utils
} }
else else
{ {
var control = (KryptonComboBox)form.Controls.Find(controlCode,true)[0]; var control = (KryptonComboBox)form.Controls.Find(controlCode, true)[0];
var str = ""; var str = "";
foreach (var item in control.Items) { foreach (var item in control.Items)
{
str += $"{item},"; str += $"{item},";
} }
@@ -324,7 +325,8 @@ namespace CleanMachineHMI.Utils
/// <param name="txt"></param> /// <param name="txt"></param>
private static void WriteLangFile(string fileName, string txt) private static void WriteLangFile(string fileName, string txt)
{ {
var fileDir = System.Windows.Forms.Application.StartupPath.Split(new string[] { @"bin\Debug" }, StringSplitOptions.RemoveEmptyEntries)[0] + "Lang\\"; // var fileDir = System.Windows.Forms.Application.StartupPath.Split(new string[] { @"bin\Debug" }, StringSplitOptions.RemoveEmptyEntries)[0] + "Lang\\";
var fileDir = "Lang\\";
try try
{ {
if (!Directory.Exists(fileDir))//如果文件夹不存在,就新建一个文件夹。 if (!Directory.Exists(fileDir))//如果文件夹不存在,就新建一个文件夹。
@@ -341,8 +343,9 @@ namespace CleanMachineHMI.Utils
private static void AddzhCN(string key, string name, string options) private static void AddzhCN(string key, string name, string options)
{ {
if (string.IsNullOrEmpty(name) && string.IsNullOrEmpty(options)) { if (string.IsNullOrEmpty(name) && string.IsNullOrEmpty(options))
Console.WriteLine(key+"空"); {
Console.WriteLine(key + "空");
return; return;
} }
var codes = key.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries); var codes = key.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries);

View File

@@ -421,7 +421,7 @@ namespace CleanMachineHMI
{ {
try try
{ {
lbNow.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); lbNow.Text = DateTime.Now.ToString();
} }
catch (Exception) catch (Exception)
{ {
@@ -646,7 +646,7 @@ namespace CleanMachineHMI
PlcOperationHelper.Instance.HeartbeatDetection(); PlcOperationHelper.Instance.HeartbeatDetection();
#endregion #endregion
#if !DEBUG #if RELEASE
} }
catch (Exception ex) catch (Exception ex)

View File

@@ -11,6 +11,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Dapper" Version="2.0.123" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="6.0.0" /> <PackageReference Include="System.Configuration.ConfigurationManager" Version="6.0.0" />
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.115.5" /> <PackageReference Include="System.Data.SQLite.Core" Version="1.0.115.5" />
</ItemGroup> </ItemGroup>

View File

@@ -7,7 +7,7 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Dapper;
namespace LeadDataBaseUtility namespace LeadDataBaseUtility
{ {
/// <summary> /// <summary>
@@ -16,9 +16,27 @@ namespace LeadDataBaseUtility
/// 允许修改、添加满足自己项目的需要。 /// 允许修改、添加满足自己项目的需要。
/// 添加、修改后请详细注释。违者会强制删除不予采用。 /// 添加、修改后请详细注释。违者会强制删除不予采用。
/// </summary> /// </summary>
public abstract class LeadDbHelperSQLite public static class LeadDbHelperSQLite
{ {
public static string connectionString = LeadConfigureConnectionString.getConnectionString("LeadSQLite"); public static string connectionString = LeadConfigureConnectionString.getConnectionString("LeadSQLite");
static LeadDbHelperSQLite()
{
Dapper.DefaultTypeMap.MatchNamesWithUnderscores = true;
}
public static int ExecuteSql(string sql, object param = null)
{
using (SQLiteConnection conn = new SQLiteConnection(connectionString))
{
return conn.Execute(sql, param);
}
}
/// <summary> /// <summary>
/// 对SQLite数据库执行增删改操作,返回受影响的行数。 /// 对SQLite数据库执行增删改操作,返回受影响的行数。
@@ -28,7 +46,7 @@ namespace LeadDataBaseUtility
public static int ExecuteSql(string sql) public static int ExecuteSql(string sql)
{ {
int affectedRows = 0; int affectedRows = 0;
#if !DEBUG #if RELEASE
try try
{ {
#endif #endif
@@ -42,7 +60,7 @@ namespace LeadDataBaseUtility
} }
conn.Close(); conn.Close();
} }
#if !DEBUG #if RELEASE
} }
catch (Exception e) catch (Exception e)
@@ -52,6 +70,18 @@ namespace LeadDataBaseUtility
#endif #endif
return affectedRows; return affectedRows;
} }
public static IEnumerable<T> Query<T>(string Strsql, object Param = null)
{
using (SQLiteConnection connection = new SQLiteConnection(connectionString))
{
return connection.Query<T>(Strsql, Param);
}
}
/// <summary> /// <summary>
/// 执行查询语句,返回DataSet /// 执行查询语句,返回DataSet
/// </summary> /// </summary>
@@ -62,7 +92,7 @@ namespace LeadDataBaseUtility
using (SQLiteConnection connection = new SQLiteConnection(connectionString)) using (SQLiteConnection connection = new SQLiteConnection(connectionString))
{ {
DataSet ds = new DataSet(); DataSet ds = new DataSet();
#if !DEBUG #if RELEASE
try try
{ {
#endif #endif
@@ -70,7 +100,7 @@ namespace LeadDataBaseUtility
SQLiteDataAdapter command = new SQLiteDataAdapter(SQLString, connection); SQLiteDataAdapter command = new SQLiteDataAdapter(SQLString, connection);
command.Fill(ds, "ds"); command.Fill(ds, "ds");
connection.Close(); connection.Close();
#if !DEBUG #if RELEASE
} }
catch (Exception e) catch (Exception e)
{ {
@@ -80,6 +110,16 @@ namespace LeadDataBaseUtility
return ds; return ds;
} }
} }
public static T GetSingle<T>(string SQLString, object Param = null)
{
using (SQLiteConnection connection = new SQLiteConnection(connectionString))
{
return connection.QueryFirstOrDefault<T>(SQLString, Param);
}
}
/// <summary> /// <summary>
/// 执行一条计算查询结果语句,返回查询结果(object)。 /// 执行一条计算查询结果语句,返回查询结果(object)。
/// </summary> /// </summary>
@@ -91,7 +131,7 @@ namespace LeadDataBaseUtility
{ {
using (SQLiteCommand cmd = new SQLiteCommand(SQLString, connection)) using (SQLiteCommand cmd = new SQLiteCommand(SQLString, connection))
{ {
#if !DEBUG #if RELEASE
try try
{ {
#endif #endif
@@ -107,7 +147,7 @@ namespace LeadDataBaseUtility
connection.Close(); connection.Close();
return obj; return obj;
} }
#if !DEBUG #if RELEASE
} }
catch (System.Data.SQLite.SQLiteException e) catch (System.Data.SQLite.SQLiteException e)
{ {