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>
<add key="GlobalPaletteMode" value="Professionaloffice2003"/>
<!--<add key="GlobalPaletteMode" value="Professionaloffice2003"/>-->
<add key="LanguageCode" value="zh-CN"/>
<!--<add key="LanguageCode" value="en-US"/>-->
<!--<add key="LanguageCode" value="English"/>-->
<add key="sqlmapConfigPath" value="Config/sqlmap.config"/>
<!--MySql数据库连接字符串-->
<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">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</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">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>

View File

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

View File

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

View File

@@ -189,8 +189,8 @@ namespace CleanMachineHMI
{
if (ThemeLanguage == null || ThemeLanguage.Count == 0)
{
var appPath = System.Windows.Forms.Application.StartupPath.Split(new string[] { @"bin\Debug" }, StringSplitOptions.RemoveEmptyEntries)[0];
var filePath = appPath + $"Lang\\{GlobalHelper.LanguageCode}.json";
// var appPath = System.Windows.Forms.Application.StartupPath.Split(new string[] { @"bin\Debug" }, StringSplitOptions.RemoveEmptyEntries)[0];
var filePath = $"Lang\\{GlobalHelper.LanguageCode}.json";
var str = File.ReadAllText(filePath);
var lstLanguage = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ThemeLanguage>>(str);
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 LeadDataBaseUtility;
@@ -84,7 +90,7 @@ namespace CleanMachineHMI
public bool PlcInit()
{
#if !DEBUG
#if RELEASE
try
{
#endif
@@ -122,8 +128,8 @@ namespace CleanMachineHMI
#endif
return true;
#if !DEBUG
}
#if RELEASE
}
catch (Exception ex)
{
LogHelper.WriteLog($"初始化PLC连接时发生异常:【{ex.Message}】", LogTypeEum.Err);
@@ -147,7 +153,7 @@ namespace CleanMachineHMI
}
public void RefreshPlcItem_M()
{
#if !DEBUG
#if RELEASE
try
{
#endif
@@ -163,8 +169,8 @@ namespace CleanMachineHMI
{
if (!string.IsNullOrEmpty(item.PlcItemDeviationAddress))
{
string PlcItemId = item.PlcItemId.ToString();
string plcdatatype = item.PlcItemDataType.ToString();
//string PlcItemId = item.PlcItemId.ToString();
// string plcdatatype = item.PlcItemDataType.ToString();
int plcItemDeviationAddress = Convert.ToInt32(item.PlcItemDeviationAddress);
item.PlcItemValue = readBytArr_M[plcItemDeviationAddress].ToString();
GlobalHelper.ShowSensorStatus(item, new EventArgs());
@@ -174,8 +180,8 @@ namespace CleanMachineHMI
{
if (!string.IsNullOrEmpty(item.PlcItemDeviationAddress))
{
string PlcItemId = item.PlcItemId.ToString();
string plcdatatype = item.PlcItemDataType.ToString();
//string PlcItemId = item.PlcItemId.ToString();
//string plcdatatype = item.PlcItemDataType.ToString();
int plcItemDeviationAddress = Convert.ToInt32(item.PlcItemDeviationAddress);
item.PlcItemValue = readBytArr_M1[plcItemDeviationAddress].ToString();
GlobalHelper.ShowSensorStatus(item, new EventArgs());
@@ -184,7 +190,7 @@ namespace CleanMachineHMI
}
}
}
#if !DEBUG
#if RELEASE
}
catch (Exception ex)
{
@@ -194,7 +200,7 @@ namespace CleanMachineHMI
}
public void RefreshPlcItem_D()
{
#if !DEBUG
#if RELEASE
try
{
#endif
@@ -210,7 +216,7 @@ namespace CleanMachineHMI
{
string PlcItemId = item.PlcItemId.ToString();
string plcdatatype = item.PlcItemDataType.ToString();
// string plcdatatype = item.PlcItemDataType.ToString();
int plcItemDeviationAddress = Convert.ToInt32(item.PlcItemDeviationAddress);
if (Convert.ToInt32(item.PlcItemPriAddress) < 409)
{
@@ -249,7 +255,7 @@ namespace CleanMachineHMI
}
HandleWaringLog(tmpReadAlarmBytArr_D);
}
#if !DEBUG
#if RELEASE
}
catch (Exception ex)
{
@@ -261,7 +267,7 @@ namespace CleanMachineHMI
//报警信息记录
private void HandleWaringLog(ushort[] tmpReadAlarmBytArr_D)
{
#if !DEBUG
#if RELEASE
try
{
#endif
@@ -587,7 +593,7 @@ namespace CleanMachineHMI
//frmMainNew.Show_ptb_Alarm(false);
GlobalHelper.ShowMainFrmAlarmMsg(false, EventArgs.Empty);
}
#if !DEBUG
#if RELEASE
}
catch (Exception ex)
{
@@ -598,7 +604,7 @@ namespace CleanMachineHMI
public void RefreshPlcItem_X()
{
#if !DEBUG
#if RELEASE
try
{
#endif
@@ -626,7 +632,7 @@ namespace CleanMachineHMI
}
}
}
#if !DEBUG
#if RELEASE
}
catch (Exception ex)
{
@@ -637,7 +643,7 @@ namespace CleanMachineHMI
public void RefreshPlcItem_Y()
{
#if !DEBUG
#if RELEASE
try
{
#endif
@@ -665,7 +671,7 @@ namespace CleanMachineHMI
}
}
}
#if !DEBUG
#if RELEASE
}
catch (Exception ex)
{
@@ -677,7 +683,7 @@ namespace CleanMachineHMI
public object ReadPlcItem(string plcItemCode, PlcItemTypeDesc itemType)
{
#if !DEBUG
#if RELEASE
try
{
#endif
@@ -750,7 +756,7 @@ namespace CleanMachineHMI
break;
}
return retObj;
#if !DEBUG
#if RELEASE
}
catch (Exception ex)
{
@@ -763,7 +769,7 @@ namespace CleanMachineHMI
public bool WritePlcItem(string plcItemCode, string writeValue, PlcItemTypeDesc itemType)
{
#if !DEBUG
#if RELEASE
try
{
#endif
@@ -798,7 +804,7 @@ namespace CleanMachineHMI
default:
return false;
}
#if !DEBUG
#if RELEASE
}
catch (Exception ex)
{
@@ -809,13 +815,13 @@ namespace CleanMachineHMI
}
private int wcsToPlcHeartDataNew = 0;
private DateTime HeartbeatTime = new DateTime();
private int ReConnNum = 1;
/// <summary>
/// 心跳处理
/// </summary>
public void HeartbeatDetection()
{
#if !DEBUG
#if RELEASE
try
{
#endif
@@ -889,7 +895,7 @@ namespace CleanMachineHMI
}
#endif
#if !DEBUG
#if RELEASE
}
catch (Exception ex)
{

View File

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

View File

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

View File

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

View File

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