From 9d1660270272180cd71147d6ddd53d1382643d2e Mon Sep 17 00:00:00 2001
From: wenxiangchao <wenxiangchao@ihengxin.com.cn>
Date: 星期一, 02 十一月 2026 18:00:14 +0800
Subject: [PATCH] merge: 并入远程 Initial commit 作为历史根节点
---
SimpleUtil/HMI.Simple.Util/ProductModelHelper.cs | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 106 insertions(+), 0 deletions(-)
diff --git a/SimpleUtil/HMI.Simple.Util/ProductModelHelper.cs b/SimpleUtil/HMI.Simple.Util/ProductModelHelper.cs
new file mode 100644
index 0000000..dd584fb
--- /dev/null
+++ b/SimpleUtil/HMI.Simple.Util/ProductModelHelper.cs
@@ -0,0 +1,106 @@
+锘縰sing System;
+using System.Data;
+using System.IO;
+
+namespace HMI.Simple.Util
+{
+ public class ProductModelHelper
+ {
+ public static bool GetModelBySNR(string snr, out string model, out string msg)
+ {
+ model = string.Empty;
+ msg = string.Empty;
+ SqliteHelper sqliteHelper = null;
+ try
+ {
+ string appFolder = RegUtil.GetLocaltion();
+ string dbFilePath = Path.Combine(appFolder, "Config", "ModelManage", "data.db");
+ if (!File.Exists(dbFilePath))
+ {
+ msg = "鏁版嵁搴撴枃浠朵笉瀛樺湪";
+ return false;
+ }
+ sqliteHelper = new SqliteHelper(dbFilePath);
+
+ int codeLength = snr.Length;
+ var sql = $@"SELECT Model, CodeLength, StartIndex, Fixcode FROM ModelData
+WHERE CodeLength = {codeLength} AND SUBSTR('{snr}', StartIndex, LENGTH(Fixcode) + StartIndex + 1) = Fixcode";
+ //var sql = $@"SELECT Model, CodeLength, StartIndex, Length, Fixcode FROM ModelData WHERE CodeLength={codeLength} AND '{snr}' LIKE '%'||Fixcode||'%'";
+ DataTable dt = sqliteHelper.GetDataTable(sql);
+ if (dt.Rows.Count <= 0)
+ {
+ msg = "娌℃湁鍖归厤鐨勫瀷鍙�";
+ return false;
+ }
+ foreach (DataRow dr in dt.Rows)
+ {
+ var startIndex = int.Parse(dr["StartIndex"].ToString());
+ var fixcode = dr["Fixcode"].ToString();
+ if (string.Equals(snr.Substring(startIndex, fixcode.Length), fixcode, StringComparison.CurrentCultureIgnoreCase))
+ {
+ model = dr["Model"].ToString();
+ return true;
+ }
+ }
+ msg = "娌℃湁鍖归厤鐨勫瀷鍙�";
+ return false;
+ }
+ catch (Exception ex)
+ {
+ msg = ex.Message;
+ return false;
+ }
+ finally
+ {
+ sqliteHelper?.Dispose();
+ }
+ }
+
+ public static bool GetModelBySNR(string dbFilePath, string snr, out string model, out string msg)
+ {
+ model = string.Empty;
+ msg = string.Empty;
+ SqliteHelper sqliteHelper = null;
+ try
+ {
+ if (!File.Exists(dbFilePath))
+ {
+ msg = "鏁版嵁搴撴枃浠朵笉瀛樺湪";
+ return false;
+ }
+ sqliteHelper = new SqliteHelper(dbFilePath);
+
+ int codeLength = snr.Length;
+ var sql = $@"SELECT Model, CodeLength, StartIndex, Fixcode FROM ModelData
+WHERE CodeLength = {codeLength} AND SUBSTR('{snr}', StartIndex, LENGTH(Fixcode) + StartIndex + 1) = Fixcode";
+ DataTable dt = sqliteHelper.GetDataTable(sql);
+ if (dt.Rows.Count <= 0)
+ {
+ msg = "娌℃湁鍖归厤鐨勫瀷鍙�";
+ return false;
+ }
+ foreach (DataRow dr in dt.Rows)
+ {
+ var startIndex = int.Parse(dr["StartIndex"].ToString());
+ var fixcode = dr["Fixcode"].ToString();
+ if (string.Equals(snr.Substring(startIndex, fixcode.Length), fixcode, StringComparison.CurrentCultureIgnoreCase))
+ {
+ model = dr["Model"].ToString();
+ return true;
+ }
+ }
+ msg = "娌℃湁鍖归厤鐨勫瀷鍙�";
+ return false;
+ }
+ catch (Exception ex)
+ {
+ msg = ex.Message;
+ return false;
+ }
+ finally
+ {
+ sqliteHelper?.Dispose();
+ }
+ }
+ }
+}
--
Gitblit v1.9.1