SQLHelper.cs 79 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Data.SqlClient;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Windows.Forms;
  8. using HslCommunication.LogNet;
  9. using SqlSugar;
  10. namespace MainForm
  11. {
  12. public class SQLHelper
  13. {
  14. public static string DBDir = GlobalContext.DBDir;
  15. //用于数据库日志记录
  16. private static ILogNet logNet = new LogNetDateTime(GlobalContext.SQLLogDir, GenerateMode.ByEveryDay);
  17. /// <summary>
  18. /// 使用锁防止多线程同时操作数据库表
  19. /// </summary>
  20. private static readonly object sqlLock = new object();
  21. public class ResponseMessage
  22. {
  23. public bool result { get; set; }
  24. public string text { get; set; }
  25. }
  26. /// <summary>
  27. /// SQL连接
  28. /// </summary>
  29. private static SqlConnection connection = null;
  30. public static string connString = "";
  31. public static SqlSugarClient Db
  32. {
  33. get { return _db; }
  34. }
  35. public static void DatabaseConnection()
  36. {
  37. _db = new SqlSugarClient(new ConnectionConfig
  38. {
  39. ConnectionString = connString, // 请确保connString在此作用域内已定义或作为参数传递进来
  40. DbType = SqlSugar.DbType.SqlServer,
  41. IsAutoCloseConnection = true,
  42. InitKeyType = InitKeyType.Attribute
  43. });
  44. }
  45. //连接本地数据库
  46. public static SqlSugarClient _db = new SqlSugarClient(new ConnectionConfig
  47. {
  48. ConnectionString = connString, // 连接到 SqlServer(不指定数据库)
  49. DbType = SqlSugar.DbType.SqlServer, // 数据库类型:SqlServer
  50. IsAutoCloseConnection = true, // 自动关闭连接
  51. InitKeyType = InitKeyType.Attribute // 使用实体类属性来初始化表结构
  52. });
  53. public static void DBInitWork()
  54. {
  55. //以月为单位存
  56. string subDir = DateTime.Now.ToString("yyyyMM");
  57. string dataBaseName = "Db" + subDir;
  58. connString =
  59. @"server= " + GlobalContext.Server +
  60. ";database= " + dataBaseName +
  61. ";uid=" + GlobalContext.User +
  62. ";pwd=" + GlobalContext.PassWord;
  63. //判断路径是否存在,不存在则创建路径
  64. if (!Directory.Exists(DBDir + subDir)) Directory.CreateDirectory(DBDir + subDir);
  65. DatabaseConnection();
  66. //创建数据库和表
  67. SQLHelper.CreateDataBase(DBDir, subDir, dataBaseName);
  68. SQLHelper.CreateDataBase();
  69. }
  70. /// <summary>
  71. /// 查询
  72. /// </summary>
  73. /// <param name="SQLString"></param>
  74. /// <param name="cmdParms"></param>
  75. /// <returns></returns>
  76. /// <exception cref="Exception"></exception>
  77. public static DataSet Query(string SQLString, List<SqlParameter> cmdParms, string connectionString)
  78. {
  79. using (SqlConnection connection = new SqlConnection(connectionString))
  80. {
  81. SqlCommand cmd = new SqlCommand();
  82. PrepareCommand(cmd, connection, null, SQLString, cmdParms);
  83. using (SqlDataAdapter da = new SqlDataAdapter(cmd))
  84. {
  85. DataSet ds = new DataSet();
  86. try
  87. {
  88. da.Fill(ds, "ds");
  89. cmd.Parameters.Clear();
  90. }
  91. catch (System.Data.SqlClient.SqlException ex)
  92. {
  93. throw new Exception(ex.Message);
  94. }
  95. return ds;
  96. }
  97. }
  98. }
  99. /// <summary>
  100. /// 执行SQL语句,返回影响的记录数
  101. /// </summary>
  102. /// <param name="SQLString">SQL语句</param>
  103. /// <returns>影响的记录数</returns>
  104. public static int ExecuteSQL(string SQLString, List<SqlParameter> cmdParms, string connectionString)
  105. {
  106. using (SqlConnection connection = new SqlConnection(connectionString))
  107. {
  108. using (SqlCommand cmd = new SqlCommand())
  109. {
  110. try
  111. {
  112. PrepareCommand(cmd, connection, null, SQLString, cmdParms);
  113. int rows = cmd.ExecuteNonQuery();
  114. cmd.Parameters.Clear();
  115. return rows;
  116. }
  117. catch (System.Data.SqlClient.SqlException e)
  118. {
  119. throw e;
  120. }
  121. }
  122. }
  123. }
  124. private static void PrepareCommand(SqlCommand cmd, SqlConnection conn, SqlTransaction trans, string cmdText, List<SqlParameter> cmdParms)
  125. {
  126. if (conn.State != ConnectionState.Open)
  127. conn.Open();
  128. cmd.Connection = conn;
  129. cmd.CommandText = cmdText;
  130. if (trans != null)
  131. cmd.Transaction = trans;
  132. cmd.CommandType = CommandType.Text;//cmdType;
  133. if (cmdParms != null)
  134. {
  135. foreach (SqlParameter parameter in cmdParms)
  136. {
  137. if ((parameter.Direction == ParameterDirection.InputOutput || parameter.Direction == ParameterDirection.Input) &&
  138. (parameter.Value == null))
  139. {
  140. parameter.Value = DBNull.Value;
  141. }
  142. cmd.Parameters.Add(parameter);
  143. }
  144. }
  145. }
  146. /// <summary>
  147. /// 创建SQL连接属性
  148. /// </summary>
  149. public static SqlConnection Connection
  150. {
  151. get
  152. {
  153. //DBInitWork();
  154. try
  155. {
  156. if (connection == null)//如果没有创建连接,则先创建
  157. {
  158. //从配置文件中获取SQL连接字段
  159. //string connStr = ConfigurationManager.ConnectionStrings["ConnetcionNmae"].ToString();
  160. connection = new SqlConnection(connString);//创建连接
  161. connection.Open();//打开连接
  162. }
  163. else if (connection.State == ConnectionState.Broken)//如果连接中断,则重现打开
  164. {
  165. connection.Close();
  166. connection.Open();
  167. }
  168. else if (connection.State == ConnectionState.Closed)//如果关闭,则打开
  169. {
  170. connection.Open();
  171. }
  172. return connection;
  173. }
  174. catch (Exception ex)
  175. {
  176. if (connection != null)
  177. {
  178. connection.Close();
  179. connection.Dispose();
  180. }
  181. logNet.WriteError(ex.Message.ToString());
  182. return null;
  183. }
  184. }
  185. }
  186. /// <summary>
  187. /// 重置连接
  188. /// </summary>
  189. public static void ResetConnection()
  190. {
  191. if (connection != null)
  192. {
  193. connection.Close();
  194. connection.Dispose();
  195. connection = null;
  196. }
  197. }
  198. /// <summary>
  199. /// 获取数据集
  200. /// </summary>
  201. /// <param name="str">执行字符串</param>
  202. /// <returns></returns>
  203. public static DataSet GetDataSet(string str)
  204. {
  205. lock (sqlLock)
  206. {
  207. try
  208. {
  209. SqlDataAdapter sda = new SqlDataAdapter(str, Connection);
  210. DataSet ds = new DataSet();
  211. sda.Fill(ds);
  212. return ds;
  213. }
  214. catch (Exception ex)
  215. {
  216. ResetConnection();
  217. logNet.WriteError(ex.Message.ToString());
  218. return null;
  219. }
  220. }
  221. }
  222. /// <summary>
  223. /// 获取表格
  224. /// </summary>
  225. /// <param name="str">执行字符串</param>
  226. /// <returns></returns>
  227. public static DataTable GetDataTable(string str)
  228. {
  229. return GetDataSet(str).Tables[0] ?? null;
  230. }
  231. /// <summary>
  232. /// 执行SQL语句
  233. /// </summary>
  234. /// <param name="str"></param>
  235. public static string ExecuteNonQuery(string str)
  236. {
  237. string ret = string.Empty;
  238. try
  239. {
  240. SqlCommand cmd = new SqlCommand();
  241. cmd.Connection = Connection;
  242. cmd.CommandType = CommandType.Text;
  243. cmd.CommandText = str;
  244. cmd.ExecuteNonQuery();
  245. ret = "成功";
  246. }
  247. catch (Exception ex)
  248. {
  249. ret = ex.Message.ToString();
  250. logNet.WriteError(ex.Message.ToString());
  251. }
  252. return ret;
  253. }
  254. /////////////////////////////////////////////////////////////////////////
  255. ///创建数据库和表
  256. /////////////////////////////////////////////////////////////////////////
  257. /// <summary>
  258. /// 判断数据库是否存在
  259. /// </summary>
  260. /// <param name="Db">数据库名称</param>
  261. /// <returns></returns>
  262. public static bool IsDBExist(string Db)
  263. {
  264. string createDbStr = " select * from master.dbo.sysdatabases where name " + "= '" + Db + "'";
  265. DataTable dt = GetDataTable(createDbStr);
  266. if (dt?.Rows.Count > 0)
  267. {
  268. return true;
  269. }
  270. return false;
  271. }
  272. /// <summary>
  273. /// 判断数据库中指定表格是否存在
  274. /// </summary>
  275. /// <param name="Db"></param>
  276. /// <param name="tb"></param>
  277. /// <returns></returns>
  278. public static bool IsTableExist(string Db, string tb)
  279. {
  280. string createTbStr = "USE " + Db + " select 1 from sysobjects where id =object_id('" + tb + "') and type = 'U'";
  281. DataTable dt = GetDataTable(createTbStr);
  282. if (dt?.Rows.Count > 0)
  283. {
  284. return true;
  285. }
  286. return false;
  287. }
  288. /// <summary>
  289. /// 判断数据库中指定表格是否存在
  290. /// </summary>
  291. /// <param name="Db"></param>
  292. /// <param name="tb"></param>
  293. /// <returns></returns>
  294. public static bool IsTableExist(string Db, string tb, string connString)
  295. {
  296. string createTbStr = "USE " + Db + " select 1 from sysobjects where id =object_id('" + tb + "') and type = 'U'";
  297. DataSet ds = Query(createTbStr, null, connString);
  298. if (ds?.Tables["ds"]?.Rows.Count > 0)
  299. {
  300. return true;
  301. }
  302. return false;
  303. }
  304. /// <summary>
  305. /// 创建数据库表
  306. /// </summary>
  307. /// <param name="Db">数据库名</param>
  308. /// <param name="tb">表名</param>
  309. public static void CreateDataTable(string Db, string tb, string content)
  310. {
  311. if (IsDBExist(Db) == false)
  312. {
  313. throw new Exception("数据库不存在!");
  314. }
  315. if (IsTableExist(Db, tb))
  316. {
  317. throw new Exception("数据库表已经存在!");
  318. }
  319. else
  320. {
  321. string createTableStr = "USE " + Db + " Create table " + tb + "(" + content + ")";
  322. ExecuteNonQuery(createTableStr);
  323. }
  324. }
  325. public static void CreateDataBase(string dbDir, string subDir, string dataBaseName)
  326. {
  327. string fileMDF = dbDir + subDir + @"\" + dataBaseName + @".mdf";
  328. string fileLDF = dbDir + subDir + @"\" + dataBaseName + @".ldf";
  329. if ((!File.Exists(fileMDF)) && (!File.Exists(fileLDF)))
  330. {
  331. SqlConnection myConn = new SqlConnection("Server=" + GlobalContext.Server
  332. + ";Integrated security=SSPI;database=master");
  333. String strSQL;
  334. strSQL = @"CREATE DATABASE " + dataBaseName +
  335. " ON PRIMARY " +
  336. "(NAME = " + dataBaseName + "_Data, " +
  337. "FILENAME = '" + fileMDF + "', " +
  338. "SIZE = 64MB, " +
  339. "MAXSIZE = UNLIMITED," +
  340. "FILEGROWTH = 64MB)" +
  341. "LOG ON (NAME = " + dataBaseName + "_Log, " +
  342. "FILENAME = '" + fileLDF + "', " +
  343. "SIZE = 64MB, " +
  344. "MAXSIZE = UNLIMITED, " +
  345. "FILEGROWTH = 64MB)";
  346. SqlCommand myCommand = new SqlCommand(strSQL, myConn);
  347. try
  348. {
  349. myConn.Open();
  350. myCommand.ExecuteNonQuery();
  351. logNet.WriteInfo("DataBase is Created Successfully");
  352. //创建StationIn表
  353. string content = @"[GUID] [nvarchar](36) NOT NULL,
  354. [Workorder_code] [nvarchar](50) NOT NULL,
  355. [Mtltmrk] [nvarchar](50) NOT NULL,
  356. [Sn] [nvarchar](64) NOT NULL,
  357. [StationIn_body] [nvarchar](MAX) NOT NULL,
  358. [StationInReturn_body] [nvarchar](MAX) NULL,
  359. [Parameter_values] [nvarchar](MAX) NULL,
  360. [Write_user] [nvarchar](20) NOT NULL,
  361. [Test_time] [varchar](23) NOT NULL,
  362. [Upload] [nvarchar](10) NOT NULL";
  363. CreateDataTable(dataBaseName, "StationIn", content);
  364. //创建ProcessData表
  365. content = @"[ID] [nvarchar](50) NOT NULL,
  366. [Equipment_code] [nvarchar](50) NOT NULL,
  367. [Workorder_code] [nvarchar](50) NOT NULL,
  368. [Batch_number] [nvarchar](32) NULL,
  369. [Sn] [nvarchar](64) NULL,
  370. [Testitem] [varchar](50) NULL,
  371. [Parameter_values] [nvarchar](MAX) NOT NULL,
  372. [StationOut_body] [nvarchar](MAX) NULL,
  373. [StationOutReturn_body] [nvarchar](MAX) NULL,
  374. [Write_user] [nvarchar](20) NOT NULL,
  375. [Test_time] [varchar](23) NOT NULL,
  376. [Upload] [nvarchar](10) NOT NULL";
  377. CreateDataTable(dataBaseName, "ProcessData", content);
  378. //创建OneCheckData表
  379. content = @" [ID] [nvarchar](50) NOT NULL,
  380. [Line_code] [nvarchar](50) NOT NULL,
  381. [Line_name] [nvarchar](50) NOT NULL,
  382. [Equipment_code] [nvarchar](50) NOT NULL,
  383. [Equipment_name] [nvarchar](50) NOT NULL,
  384. [Workorder_code] [nvarchar](50) NOT NULL,
  385. [Procedure_code] [nvarchar](32) NOT NULL,
  386. [Procedure_name] [nvarchar](32) NOT NULL,
  387. [Oneckeck_values] [nvarchar](MAX) NOT NULL,
  388. [Onecheck_empcode] [nvarchar](32) NULL,
  389. [Onecheck_empname] [nvarchar](32) NULL,
  390. [Onecheck_time] [varchar](20) NOT NULL,
  391. [Upload] [nvarchar](10) NOT NULL";
  392. CreateDataTable(dataBaseName, "OneCheckData", content);
  393. //创建WorkingData表-单机
  394. content = @"
  395. [Date] [nvarchar](10) NOT NULL,
  396. [Equipment_code] [nvarchar](32) NOT NULL,
  397. [BootTime] [varchar](20) NOT NULL,
  398. [Bootmoment] [nvarchar](20) NOT NULL,
  399. [RunTime] [varchar](20) NOT NULL,
  400. [WoringTime] [varchar](20) NOT NULL,
  401. [RepairTime] [varchar](20) NOT NULL,
  402. [StopTime] [varchar](20) NOT NULL,
  403. [WoringNum] [nvarchar](20) NOT NULL,
  404. [NeedTime] [varchar](20) NOT NULL,
  405. [PlanStopMoment] [nvarchar](20) NOT NULL,
  406. [Equipment_status] [nvarchar](20) NOT NULL,
  407. [WorkingQty] [nchvarcharar](20) NOT NULL,
  408. [QualifiedQty] [nvarchar](20) NOT NULL,
  409. [TotalQty] [nvarchar](20) NOT NULL,
  410. [NGset] [nvarchar](20) NOT NULL,
  411. [QualifiedRateSet] [nvarchar](20) NOT NULL,
  412. [RhySet] [nvarchar](20) NOT NULL,
  413. [Update_time] [varchar](20) NOT NULL";
  414. CreateDataTable(dataBaseName, "WorkingData", content);
  415. //创建LineWorkingData表-整线
  416. content = @" [GUID] [nvarchar](36) NOT NULL,
  417. [LineName] [nvarchar](36) NOT NULL,
  418. [BootTimeLong] [float] NULL,
  419. [NormalTimeLong] [float] NULL,
  420. [StandbyTimeLong] [float] NULL,
  421. [FaultTimeLong] [float] NULL,
  422. [MaterialShortageTimeLong] [float] NULL,
  423. [MaintenanceTimeLong] [float] NULL,
  424. [FaultNumber] [int] NULL,
  425. [OutputNumber] [int] NULL,
  426. [QualifiedNumber] [int] NULL,
  427. [QualifiedRate] [float] NULL,
  428. [DesignRhythm] [float] NULL,
  429. [RealityRhythm] [float] NULL,
  430. [CreateTime] [datetime] NULL";
  431. CreateDataTable(dataBaseName, "LineWorkingData", content);
  432. //创建AlarmData表
  433. content = @" [GUID] [nvarchar](36) NOT NULL,
  434. [LineName] [nvarchar](36) NOT NULL,
  435. [AlarmType] [nvarchar](36) NOT NULL,
  436. [AlarmDesc] [nvarchar](64) NOT NULL,
  437. [StartTime] [datetime] NOT NULL,
  438. [EndTime] [datetime] NULL,
  439. [PersistTime] [int] NULL";
  440. CreateDataTable(dataBaseName, "AlarmData", content);
  441. }
  442. catch (System.Exception ex)
  443. {
  444. logNet.WriteError(ex.Message.ToString());
  445. }
  446. finally
  447. {
  448. if (myConn.State == ConnectionState.Open)
  449. {
  450. myConn.Close();
  451. }
  452. }
  453. }
  454. }
  455. #region
  456. /// <summary>
  457. /// 检验并创建工单信息表
  458. /// </summary>
  459. public static void CreateDataBase_DBMain()
  460. {
  461. try
  462. {
  463. // 数据库链接
  464. string connString =
  465. "server=" + GlobalContext.Server +
  466. ";database=DBMain" +
  467. ";uid=" + GlobalContext.User +
  468. ";pwd=" + GlobalContext.PassWord;
  469. // 创建OrderTable表
  470. if (!IsTableExist("DBMain", "OrderTable", connString))
  471. {
  472. string content =
  473. @"
  474. CREATE TABLE [dbo].[OrderTable](
  475. [WorkOrderNum] [nvarchar](150) NOT NULL,
  476. [WorkOrderStatus] [nvarchar](32) NOT NULL,
  477. [BatchNumber] [nvarchar](36) NULL,
  478. [ProductMtltmrk] [nvarchar](32) NULL,
  479. [ProductNo] [nvarchar](32) NULL,
  480. [ProductName] [nvarchar](32) NULL,
  481. [SupplierCode] [nvarchar](32) NULL,
  482. [PlannedQuantity] [nvarchar](32) NULL,
  483. [CompletedQuantity] [int] NULL,
  484. [Plnsign] [nvarchar](32) NULL,
  485. [Soreqdat] [nvarchar](32) NULL,
  486. [Process] [nvarchar](32) NULL,
  487. [CreatedTime] [datetime] NOT NULL,
  488. CONSTRAINT [PK__OrderTab__33E32040C02E055A] PRIMARY KEY CLUSTERED
  489. (
  490. [WorkOrderNum] ASC
  491. )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  492. ) ON [PRIMARY]
  493. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'车间订单号' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'OrderTable', @level2type=N'COLUMN',@level2name=N'WorkOrderNum'
  494. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'订单状态' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'OrderTable', @level2type=N'COLUMN',@level2name=N'WorkOrderStatus'
  495. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'批次号' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'OrderTable', @level2type=N'COLUMN',@level2name=N'BatchNumber'
  496. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'产品型号' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'OrderTable', @level2type=N'COLUMN',@level2name=N'ProductMtltmrk'
  497. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'产品代号' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'OrderTable', @level2type=N'COLUMN',@level2name=N'ProductNo'
  498. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'产品名称' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'OrderTable', @level2type=N'COLUMN',@level2name=N'ProductName'
  499. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'供应商代码' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'OrderTable', @level2type=N'COLUMN',@level2name=N'SupplierCode'
  500. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'计划数量' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'OrderTable', @level2type=N'COLUMN',@level2name=N'PlannedQuantity'
  501. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'已完成数量' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'OrderTable', @level2type=N'COLUMN',@level2name=N'CompletedQuantity'
  502. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'计划标记' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'OrderTable', @level2type=N'COLUMN',@level2name=N'Plnsign'
  503. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'需求日期' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'OrderTable', @level2type=N'COLUMN',@level2name=N'Soreqdat'
  504. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'所属流程' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'OrderTable', @level2type=N'COLUMN',@level2name=N'Process'
  505. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'订单创建时间' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'OrderTable', @level2type=N'COLUMN',@level2name=N'CreatedTime'
  506. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'订单信息表' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'OrderTable'";
  507. ExecuteSQL(content, null, connString);
  508. }
  509. }
  510. catch (System.Exception ex)
  511. {
  512. logNet.WriteError(ex.Message.ToString());
  513. }
  514. }
  515. #endregion
  516. #region 进出站相关数据记录
  517. // 提供静态属性来访问 SqlSugarClient 实例
  518. //连网数据库
  519. public static SqlSugarClient dbmain = new SqlSugarClient(new ConnectionConfig
  520. {
  521. ConnectionString = "server=" + GlobalContext.Server +
  522. ";database=DBMain" +
  523. ";uid=" + GlobalContext.User +
  524. ";pwd=" + GlobalContext.PassWord, // 连接到 SqlServer(不指定数据库)
  525. DbType = SqlSugar.DbType.SqlServer, // 数据库类型:SqlServer
  526. IsAutoCloseConnection = true, // 自动关闭连接
  527. InitKeyType = InitKeyType.Attribute // 使用实体类属性来初始化表结构
  528. });
  529. // 判断表格是否存在
  530. public static bool CheckTableExists(SqlSugarClient Db, string tableName)
  531. {
  532. //判断表是否存在
  533. var result = Db.Ado.SqlQuery<int>($@"
  534. SELECT COUNT(*)
  535. FROM INFORMATION_SCHEMA.TABLES
  536. WHERE TABLE_NAME = @tableName", new { tableName }).FirstOrDefault() > 0;
  537. return result;
  538. }
  539. //创建 载具绑定物料码表、物料码绑定部件码表、PLC返回MES数据记录表
  540. public static void CreateDataBase()
  541. {
  542. try
  543. {
  544. // 3. 判断并创建表格
  545. if (!CheckTableExists(Db, "carrierbind"))
  546. {
  547. CreateTables<CarrierBind>(Db);
  548. }
  549. if (!CheckTableExists(Db, "productbind"))
  550. {
  551. CreateTables<ProductBind>(Db);
  552. }
  553. if (!CheckTableExists(Db, "testdata"))
  554. {
  555. CreateTables<TestData>(Db);
  556. }
  557. logNet.WriteInfo("表格已创建或已存在。");
  558. }
  559. catch (Exception ex)
  560. {
  561. logNet.WriteError("表格创建失败,错误原因:" + ex.Message);
  562. MessageBox.Show("表格创建失败,错误码:" + ex.Message);
  563. }
  564. }
  565. public static void CreateTables<T>(SqlSugarClient Db) where T : class, new()
  566. {
  567. Db.CodeFirst.InitTables<T>(); // 根据传入的实体类类型来创建表格
  568. logNet.WriteInfo($"表格 {typeof(T).Name} 已创建。");
  569. }
  570. //获取载具绑定的产品码
  571. public static string GetProductBarcodeByCarrierCode(string carrierCode)
  572. {
  573. try
  574. {
  575. var Carrierdt = Db.Queryable<CarrierBind>()
  576. .Where(x => x.CarrierCode == carrierCode)
  577. .OrderByDescending(x => x.ID)
  578. .Take(1)
  579. .ToList();
  580. if (Carrierdt != null && Carrierdt.Count > 0)
  581. {
  582. return Carrierdt.First().ProductBarcode;
  583. }
  584. else
  585. {
  586. return string.Empty;
  587. }
  588. }
  589. catch (Exception ex)
  590. {
  591. return string.Empty;
  592. }
  593. }
  594. //获取载具绑定的PCB码
  595. public static string GetPCBBarcodeByCarrierCode(string carrierCode)
  596. {
  597. try
  598. {
  599. var Carrierdt = Db.Queryable<CarrierBind>()
  600. .Where(x => x.CarrierCode == carrierCode)
  601. .OrderByDescending(x => x.ID)
  602. .Take(1)
  603. .ToList();
  604. if (Carrierdt != null && Carrierdt.Count > 0)
  605. {
  606. return Carrierdt.First().PCBBarcode;
  607. }
  608. else
  609. {
  610. return string.Empty;
  611. }
  612. }
  613. catch (Exception ex)
  614. {
  615. return string.Empty;
  616. }
  617. }
  618. //载具码和产品码解除绑定关系
  619. public static ResponseMessage DelCarrierBind(string carrierCode)
  620. {
  621. // 检查记录是否已经存在
  622. var CarrierBind_exists = Db.Queryable<CarrierBind>().Where(x => x.CarrierCode == carrierCode);
  623. try
  624. {
  625. Db.Deleteable<CarrierBind>().Where(x => x.CarrierCode == carrierCode).ExecuteCommand();
  626. logNet.WriteInfo($"载具码与产品码解绑成功。");
  627. return new ResponseMessage { result = true, text = "载具码与产品码解绑成功" };
  628. }
  629. catch (Exception ex)
  630. {
  631. logNet.WriteError($"载具码与产品码解绑成功,错误" + ex.Message);
  632. return new ResponseMessage { result = false, text = "载具码与产品码解绑成功,错误" + ex.Message };
  633. }
  634. #endregion
  635. }
  636. //载具码和产品码绑定关系
  637. public static ResponseMessage InsertCarrierBind(string carrierCode, string productBarcode)
  638. {
  639. #region 新建CarrierBind实体,并将数据插入carrierBind表格
  640. // 创建 CarrierBind 实体,并通过传入的参数设置字段值
  641. var CarrierBind_sumRecord = new CarrierBind
  642. {
  643. CarrierCode = carrierCode,
  644. ProductBarcode = productBarcode
  645. };
  646. // 检查记录是否已经存在
  647. var CarrierBind_exists = Db.Queryable<CarrierBind>().Where(x => x.CarrierCode == carrierCode);
  648. try
  649. {
  650. if (CarrierBind_exists != null)
  651. {
  652. Db.Deleteable<CarrierBind>().Where(x => x.CarrierCode == carrierCode).ExecuteCommand();
  653. logNet.WriteInfo($"载具码与产品码已存在绑定关系,先解绑。");
  654. }
  655. // 插入数据
  656. Db.Insertable(CarrierBind_sumRecord).ExecuteCommand();
  657. logNet.WriteInfo($"载具码与产品码绑定成功。");
  658. return new ResponseMessage { result = true, text = "载具码与产品码绑定成功" };
  659. }
  660. catch (Exception ex)
  661. {
  662. logNet.WriteError($"载具码与产品码绑定失败,错误" + ex.Message);
  663. return new ResponseMessage { result = false, text = "载具码与产品码绑定失败,错误" + ex.Message };
  664. }
  665. #endregion
  666. }
  667. //载具码和产品码绑定关系
  668. public static ResponseMessage PCBCarrierBind(string carrierCode, string pcbBarcode)
  669. {
  670. // 检查记录是否已经存在
  671. var CarrierBind_exists = Db.Queryable<CarrierBind>()
  672. .Where(x => x.CarrierCode == carrierCode)
  673. .OrderByDescending(x => x.CreateTime)
  674. .Take(1)
  675. .First();
  676. try
  677. {
  678. if (CarrierBind_exists != null)
  679. {
  680. Db.Updateable<CarrierBind>()
  681. .SetColumns(x=>x.PCBBarcode== pcbBarcode)
  682. .Where(x => x.ID == CarrierBind_exists.ID)
  683. .ExecuteCommand();
  684. logNet.WriteInfo($"载具码与PCB码绑定成功");
  685. }
  686. else {
  687. return new ResponseMessage { result = true, text = "载具码与PCB码绑定失败!载具码["+ carrierCode + "]没有绑定记录"};
  688. }
  689. // 插入数据
  690. return new ResponseMessage { result = true, text = "载具码与PCB码绑定成功" };
  691. }
  692. catch (Exception ex)
  693. {
  694. logNet.WriteError($"载具码与产品码绑定失败,错误" + ex.Message);
  695. return new ResponseMessage { result = false, text = "载具码与产品码绑定失败,错误" + ex.Message };
  696. }
  697. }
  698. public static ResponseMessage InsertOp10Data(string carrierCode, string productBarcode, int bindOrder,
  699. int throwingAmount, float cleaningPressure, float cleaningSpeed,
  700. float airKnifeHeight, float cleaningTime, int cleaningCount, int remainCount)
  701. {
  702. // 检查记录是否已经存在
  703. bool OP10_exists = Db.Queryable<CarrierBind>().Any(x => x.CarrierCode == carrierCode &&
  704. x.ProductBarcode == productBarcode);
  705. if (OP10_exists)
  706. {
  707. var maxBindOrder = Db.Queryable<TestData>()
  708. .Where(x => x.CarrierCode == carrierCode &&
  709. x.ProductBarcode == productBarcode)
  710. .Max(x => x.BindOrder); ;
  711. bindOrder = maxBindOrder + 1;
  712. }
  713. #region 将OP10数据插入testdata表格
  714. // 创建 Op10 实体,并通过传入的参数设置字段值
  715. var op10 = new TestData
  716. {
  717. CarrierCode = carrierCode, // 载具码
  718. ProductBarcode = productBarcode, // 产品码
  719. BindOrder = bindOrder, // 绑定顺序
  720. OP10_ThrowingAmount = throwingAmount, // 抛料数量
  721. OP10_CleaningPressure = cleaningPressure, // 清洗气压
  722. OP10_CleaningSpeed = cleaningSpeed, // 清洗速度
  723. OP10_AirKnifeHeight = airKnifeHeight, // 风刀高度
  724. OP10_CleaningTime = cleaningTime, // 清洗时间
  725. OP10_CleaningCount = cleaningCount, // 清洗次数
  726. OP10_RemainCount = remainCount // 清洗次数
  727. };
  728. try
  729. {
  730. Db.Insertable(op10).ExecuteCommand();
  731. logNet.WriteError("OP10记录插入成功!");
  732. return new ResponseMessage { result = true, text = "OP10记录插入成功" };
  733. }
  734. catch (Exception ex)
  735. {
  736. logNet.WriteError("OP10记录插入出错!错误码:" + ex.Message);
  737. return new ResponseMessage { result = false, text = "OP10记录插入出错!错误码:" + ex.Message };
  738. }
  739. #endregion
  740. }
  741. // op20绑定部件码
  742. public static ResponseMessage InsertOp20Product(string carrierCode, string productBarcode, string topCover_Barcode)
  743. {
  744. int bindOrder = 1;
  745. try
  746. {
  747. // 检查记录是否已经存在
  748. bool Product_exists = Db.Queryable<ProductBind>().Any(x => x.CarrierCode == carrierCode &&
  749. x.ProductBarcode == productBarcode);
  750. if (Product_exists)
  751. {
  752. var maxBindOrder = Db.Queryable<ProductBind>()
  753. .Where(x => x.CarrierCode == carrierCode &&
  754. x.ProductBarcode == productBarcode)
  755. .Max(x => x.BindOrder); ;
  756. bindOrder = maxBindOrder + 1;
  757. }
  758. #region 新建ProductBind实体,并将数据插入productBind表格
  759. // 创建 ProductBind 实体,并通过传入的参数设置字段值
  760. var ProductBind_sumRecord = new ProductBind
  761. {
  762. CarrierCode = carrierCode,//载具码
  763. ProductBarcode = productBarcode, // 产品条码
  764. BindOrder = bindOrder, // 绑定顺序
  765. TopCover_Barcode = topCover_Barcode, //部件码
  766. };
  767. // 插入数据
  768. Db.Insertable(ProductBind_sumRecord).ExecuteCommand();
  769. return new ResponseMessage { result = true, text = "OP20-产品码绑定部件码成功!" };
  770. }
  771. catch (Exception ex)
  772. {
  773. logNet.WriteError("OP20-产品码绑定部件码出错!错误码:" + ex.Message);
  774. return new ResponseMessage { result = false, text = "OP20-产品码绑定部件码出错!错误码:" + ex.Message };
  775. }
  776. #endregion
  777. }
  778. // op20向testdata表格插入数据
  779. public static ResponseMessage InsertOp20Data(string carrierCode, string productBarcode, int throwCount, int remainCount)
  780. {
  781. ////// 检查上一次插入的记录是否存在
  782. ////var lastRecord = Db.Queryable<TestData>()
  783. //// .Where(x => x.CarrierCode== carrierCode && x.ProductBarcode == productBarcode &&
  784. //// (x.OP10_ThrowingAmount != 0 ||
  785. //// x.OP10_CleaningPressure != 0.0f ||
  786. //// x.OP10_CleaningSpeed != 0.0f ||
  787. //// x.OP10_AirKnifeHeight != 0.0f ||
  788. //// x.OP10_CleaningTime != 0.0f ||
  789. //// x.OP10_CleaningCount != 0 ||
  790. //// x.OP10_RemainCount != 0)) // 看上一次有无记录数据
  791. //// .OrderBy(x => x.ID, OrderByType.Desc) // 按照ID降序查找最新记录
  792. //// .Take(1) // 只取一条记录
  793. //// .First(); // 获取第一条记录,若没有则返回null
  794. ////if (lastRecord == null)
  795. ////{
  796. //// logNet.WriteError("OP20错误:OP10未插入数据!");
  797. ////}
  798. try
  799. {
  800. var lastRecord = Db.Queryable<TestData>()
  801. .Where(x => x.CarrierCode == carrierCode)
  802. .OrderBy(x => x.ID, OrderByType.Desc) // 按照ID降序查找最新记录
  803. .Take(1) // 只取一条记录
  804. .First(); // 获取第一条记录,若没有则返回null
  805. if (lastRecord == null)
  806. {
  807. logNet.WriteError("OP20记录插入出错:MES主数据未成功创建,无法插入OP20数据!");
  808. return new ResponseMessage { result = false, text = "OP20错误:MES主数据未成功创建,无法插入OP20数据!" };
  809. }
  810. //if (lastRecord.OP20_ThrowCount != 0 || lastRecord.OP20_RemainCount != 0)
  811. //{
  812. // logNet.WriteError("OP20记录插入出错:即将插入的行数据已存在,插入失败!");
  813. // return new ResponseMessage { result = false, text = "OP20记录插入出错:即将插入的行数据已存在,插入失败!" };
  814. //}
  815. lastRecord.OP20_ThrowCount = throwCount;
  816. lastRecord.OP20_RemainCount = remainCount;
  817. Db.Updateable(lastRecord)
  818. .UpdateColumns(x => new { x.OP20_ThrowCount, x.OP20_RemainCount })
  819. .ExecuteCommand();
  820. logNet.WriteError("OP20记录插入成功!");
  821. return new ResponseMessage { result = true, text = "OP20记录插入成功!" };
  822. }
  823. catch (Exception ex)
  824. {
  825. logNet.WriteError("OP20记录插入出错!错误码:" + ex.Message);
  826. return new ResponseMessage { result = false, text = "OP20记录插入出错!错误码:" + ex.Message };
  827. }
  828. }
  829. // op301向testdata表格插入数据
  830. public static ResponseMessage InsertOp301Data(string carrierCode, string productBarcode, float gluingSpeed, float pressureAB, float pressureDifferenceAB,
  831. string productHeightInfo, string periodicWeightData, string remainingGlueAmount)
  832. {
  833. ////// 检查上一次插入的记录是否存在
  834. ////var lastRecord = Db.Queryable<TestData>()
  835. //// .Where(x => x.CarrierCode == carrierCode && x.ProductBarcode == productBarcode &&
  836. //// (x.OP20_ThrowCount != 0 || x.OP20_RemainCount != 0)) // 只查找有效插入的数据
  837. //// .OrderBy(x => x.ID, OrderByType.Desc) // 按照ID降序查找最新记录
  838. //// .Take(1) // 只取一条记录
  839. //// .First(); // 获取第一条记录,若没有则返回null
  840. ////if (lastRecord == null)
  841. ////{
  842. //// logNet.WriteError("OP301错误:OP20插入的记录存在值为空!");
  843. //// return new ResponseMessage { result = false, text = "OP301错误:OP20插入的记录存在值为空!" };
  844. ////}
  845. try
  846. {
  847. var lastRecord = Db.Queryable<TestData>()
  848. .Where(x => x.CarrierCode == carrierCode)
  849. .OrderBy(x => x.ID, OrderByType.Desc) // 按照ID降序查找最新记录
  850. .Take(1) // 只取一条记录
  851. .First(); // 获取第一条记录,若没有则返回null
  852. if (lastRecord == null)
  853. {
  854. logNet.WriteError("OP301错误:MES主数据未成功创建,无法插入OP301数据!");
  855. return new ResponseMessage { result = false, text = "OP301错误:MES主数据未成功创建,无法插入OP301数据!" };
  856. }
  857. //if (lastRecord.OP301_GluingSpeed != 0.0f || lastRecord.OP301_PressureAB != 0.0f ||
  858. //lastRecord.OP301_PressureDifferenceAB != 0.0f || lastRecord.OP301_ProductHeightInfo != 0.0f ||
  859. //lastRecord.OP301_PeriodicWeightData != 0.0f || lastRecord.OP301_RemainingGlueAmount != 0.0f)
  860. //{
  861. // logNet.WriteError("OP301记录插入出错:即将插入的行数据已存在,插入失败!");
  862. // return new ResponseMessage { result = false, text = "OP301记录插入出错:即将插入的行数据已存在,插入失败!" };
  863. //}
  864. lastRecord.OP301_GluingSpeed = gluingSpeed; // 供胶速度
  865. lastRecord.OP301_PressureAB = pressureAB; // AB管气压
  866. lastRecord.OP301_PressureDifferenceAB = pressureDifferenceAB; // AB管气压差
  867. lastRecord.OP301_ProductHeightInfo = productHeightInfo; // 产品测高信息
  868. lastRecord.OP301_PeriodicWeightData = periodicWeightData; // 定期称重数据
  869. lastRecord.OP301_RemainingGlueAmount = remainingGlueAmount; // 剩余胶量
  870. Db.Updateable(lastRecord)
  871. .UpdateColumns(x => new
  872. {
  873. x.OP301_GluingSpeed,
  874. x.OP301_PressureAB,
  875. x.OP301_PressureDifferenceAB,
  876. x.OP301_ProductHeightInfo,
  877. x.OP301_PeriodicWeightData,
  878. x.OP301_RemainingGlueAmount
  879. }).ExecuteCommand();
  880. logNet.WriteError("OP301记录插入成功!");
  881. return new ResponseMessage { result = true, text = "OP301记录插入成功" };
  882. }
  883. catch (Exception ex)
  884. {
  885. logNet.WriteError("OP301记录插入出错!错误码:" + ex.Message);
  886. return new ResponseMessage { result = false, text = "OP301记录插入出错!错误码:" + ex.Message };
  887. }
  888. }
  889. // op302向testdata表格插入数据
  890. public static ResponseMessage InsertOp302Data(string carrierCode, string productBarcode, float gluingSpeed, float pressureAB, float pressureDifferenceAB,
  891. string productHeightInfo, string periodicWeightData, string remainingGlueAmount)
  892. {
  893. ////// 检查上一次插入的记录是否存在
  894. ////var lastRecord = Db.Queryable<TestData>()
  895. //// .Where(x => x.OP301_GluingSpeed != 0.0f && x.OP301_PressureA != 0.0f && x.OP301_PressureB != 0.0f &&
  896. //// x.OP301_PressureDifferenceAB != 0.0f && x.OP301_ProductHeightInfo != 0.0f &&
  897. //// x.OP301_PeriodicWeightData != 0.0f && x.OP301_RemainingGlueAmount != 0.0f) // 只查找有效插入的数据
  898. //// .OrderBy(x => x.ID, OrderByType.Desc) // 按照ID降序查找最新记录
  899. //// .Take(1) // 只取一条记录
  900. //// .First(); // 获取第一条记录,若没有则返回null
  901. ////if (lastRecord == null)
  902. ////{
  903. //// logNet.WriteError("OP302错误:OP301插入的记录存在值为空!");
  904. //// return new ResponseMessage { result = false, text = "OP302错误:OP301插入的记录存在值为空!" };
  905. ////}
  906. ///
  907. try
  908. {
  909. var lastRecord = Db.Queryable<TestData>()
  910. .Where(x => x.CarrierCode == carrierCode)
  911. .OrderBy(x => x.ID, OrderByType.Desc) // 按照ID降序查找最新记录
  912. .Take(1) // 只取一条记录
  913. .First(); // 获取第一条记录,若没有则返回null
  914. if (lastRecord == null)
  915. {
  916. logNet.WriteError("OP302记录插入错误:MES主数据未成功创建,无法插入OP302数据!");
  917. return new ResponseMessage { result = false, text = "OP302记录插入错误:MES主数据未成功创建,无法插入OP302数据!" };
  918. }
  919. //if (lastRecord.OP302_GluingSpeed != 0.0f || lastRecord.OP302_PressureAB != 0.0f ||
  920. // lastRecord.OP302_PressureDifferenceAB != 0.0f || lastRecord.OP302_ProductHeightInfo != "" ||
  921. // lastRecord.OP302_PeriodicWeightData !="" || lastRecord.OP302_RemainingGlueAmount != "")
  922. //{
  923. // logNet.WriteError("OP302记录插入出错:即将插入的行数据已存在,插入失败!");
  924. // return new ResponseMessage { result = false, text = "OP302记录插入出错:即将插入的行数据已存在,插入失败!" };
  925. //}
  926. lastRecord.OP302_GluingSpeed = gluingSpeed; // 供胶速度
  927. lastRecord.OP302_PressureAB = pressureAB; // AB管气压
  928. lastRecord.OP302_PressureDifferenceAB = pressureDifferenceAB; // AB管气压差
  929. lastRecord.OP302_ProductHeightInfo = productHeightInfo; // 产品测高信息
  930. lastRecord.OP302_PeriodicWeightData = periodicWeightData; // 定期称重数据
  931. lastRecord.OP302_RemainingGlueAmount = remainingGlueAmount; // 剩余胶量
  932. Db.Updateable(lastRecord)
  933. .UpdateColumns(x => new
  934. {
  935. x.OP302_GluingSpeed,
  936. x.OP302_PressureAB,
  937. x.OP302_PressureDifferenceAB,
  938. x.OP302_ProductHeightInfo,
  939. x.OP302_PeriodicWeightData,
  940. x.OP302_RemainingGlueAmount
  941. }).ExecuteCommand();
  942. logNet.WriteError("OP302记录插入成功!");
  943. return new ResponseMessage { result = true, text = "OP302记录插入成功" };
  944. }
  945. catch (Exception ex)
  946. {
  947. logNet.WriteError("OP302记录插入出错!错误码:" + ex.Message);
  948. return new ResponseMessage { result = false, text = "OP302错误:即将插入的数据存在值不为空,插入失败,请按标准操作!" };
  949. }
  950. }
  951. // op40向testdata表格插入数据
  952. public static ResponseMessage InsertOp40Data(string carrierCode, string productBarcode, string gluePosx, string gluePosy, string glueLineArea,
  953. string glueLineHeight, int result, string inspectionImagePath)
  954. {
  955. //// 检查上一次插入的记录是否存在
  956. //var lastRecord = Db.Queryable<TestData>()
  957. // .Where(x => x.OP302_GluingSpeed != 0.0f && x.OP302_PressureAB != 0.0f &&
  958. // x.OP302_PressureDifferenceAB != 0.0f && x.OP302_ProductHeightInfo != 0.0f &&
  959. // x.OP302_PeriodicWeightData != 0.0f && x.OP302_RemainingGlueAmount != 0.0f) // 只查找有效插入的数据
  960. // .OrderBy(x => x.ID, OrderByType.Desc) // 按照ID降序查找最新记录
  961. // .Take(1) // 只取一条记录
  962. // .First(); // 获取第一条记录,若没有则返回null
  963. //if (lastRecord == null)
  964. //{
  965. // logNet.WriteError("OP40错误:OP302插入的记录存在值为空!");
  966. // return new ResponseMessage { result = false, text = "OP40错误:OP302插入的记录存在值为空!" };
  967. //}
  968. //if (lastRecord.OP40_GluePosition != "" || lastRecord.OP40_GlueLineArea != 0.0f ||
  969. // lastRecord.OP40_GlueLineHeight != 0.0f || lastRecord.OP40_InspectionImagePath != "")
  970. //{
  971. // logNet.WriteError("OP40错误:即将插入的数据存在值不为空,插入失败,请按标准操作!");
  972. // return new ResponseMessage { result = false, text = "OP40错误:即将插入的数据存在值不为空,插入失败,请按标准操作!" };
  973. //}
  974. try
  975. {
  976. var lastRecord = Db.Queryable<TestData>()
  977. .Where(x => x.CarrierCode == carrierCode)
  978. .OrderBy(x => x.ID, OrderByType.Desc) // 按照ID降序查找最新记录
  979. .Take(1) // 只取一条记录
  980. .First(); // 获取第一条记录,若没有则返回null
  981. if (lastRecord == null)
  982. {
  983. logNet.WriteError("OP40记录插入错误:MES主数据未成功创建,无法插入OP40数据!");
  984. return new ResponseMessage { result = false, text = "OP40记录插入错误:MES主数据未成功创建,无法插入OP40数据!" };
  985. }
  986. ////if (lastRecord.OP40_GluePosX != "" || lastRecord.OP40_GluePosY != "" || lastRecord.OP40_GlueLineArea != "" ||
  987. //// lastRecord.OP40_GlueLineHeight != "" || lastRecord.OP40_Result != 0 || lastRecord.OP40_InspectionImagePath != "")
  988. ////{
  989. //// logNet.WriteError("OP40记录插入出错:即将插入的行数据已存在,插入失败!");
  990. //// return new ResponseMessage { result = false, text = "OP40记录插入出错:即将插入的行数据已存在,插入失败!" };
  991. ////}
  992. lastRecord.OP40_GluePosX = gluePosx; // 胶线位置X偏差
  993. lastRecord.OP40_GluePosY = gluePosy; // 胶线位置Y偏差
  994. lastRecord.OP40_GlueLineArea = glueLineArea; // 胶线面积
  995. lastRecord.OP40_GlueLineHeight = glueLineHeight; // 胶线高度
  996. lastRecord.OP40_Result = result.ToString(); // 胶线检测结果
  997. lastRecord.OP40_InspectionImagePath = inspectionImagePath; // 检测图片路径
  998. Db.Updateable(lastRecord)
  999. .UpdateColumns(x => new
  1000. {
  1001. x.OP40_GluePosX,
  1002. x.OP40_GluePosY,
  1003. x.OP40_GlueLineArea,
  1004. x.OP40_GlueLineHeight,
  1005. x.OP40_Result,
  1006. x.OP40_InspectionImagePath
  1007. }).ExecuteCommand();
  1008. logNet.WriteError("OP40记录插入成功!");
  1009. return new ResponseMessage { result = true, text = "OP40记录插入成功!" };
  1010. }
  1011. catch (Exception ex)
  1012. {
  1013. logNet.WriteError("OP40记录插入出错!错误码:" + ex.Message);
  1014. return new ResponseMessage { result = true, text = "OP40记录插入出错!错误码:" + ex.Message };
  1015. }
  1016. }
  1017. //OP50 往product塞数据
  1018. public static ResponseMessage InsertOp50Product(string carrierCode, string productBarcode, string addPCB_Barcode)
  1019. {
  1020. #region 往productBind表格中插入addPCB_Barcode数据
  1021. // 检查上一次插入的记录是否存在
  1022. try
  1023. {
  1024. var productBind_lastRecord = Db.Queryable<ProductBind>()
  1025. .Where(x => x.CarrierCode == carrierCode && x.ProductBarcode == productBarcode)
  1026. .OrderBy(x => x.ID, OrderByType.Desc) // 按照ID降序查找最新记录
  1027. .Take(1) // 只取一条记录
  1028. .First(); // 获取第一条记录,若没有则返回null
  1029. if (productBind_lastRecord == null)
  1030. {
  1031. logNet.WriteError("OP50-错误:ProductBind表数据为空!");
  1032. return new ResponseMessage { result = false, text = "OP50-错误:ProductBind表数据为空!" };
  1033. }
  1034. //if (productBind_lastRecord.AddPCB_Barcode != "")
  1035. //{
  1036. // logNet.WriteError("OP50-错误:即将插入ProductBind的数据存在值不为空,插入失败,请按标准操作!");
  1037. // return new ResponseMessage { result = false, text = "OP50-错误:即将插入ProductBind的数据存在值不为空,插入失败,请按标准操作!" };
  1038. //}
  1039. productBind_lastRecord.AddPCB_Barcode = addPCB_Barcode;
  1040. Db.Updateable(productBind_lastRecord)
  1041. .UpdateColumns(x => new
  1042. {
  1043. x.AddPCB_Barcode
  1044. }).ExecuteCommand();
  1045. logNet.WriteError("OP50部件码绑定产品码成功!");
  1046. return new ResponseMessage { result = false, text = "OP50部件码绑定产品码成功!" };
  1047. }
  1048. catch (Exception ex)
  1049. {
  1050. logNet.WriteError("OP50部件码绑定产品码失败!错误码:" + ex.Message);
  1051. return new ResponseMessage { result = false, text = "OP50部件码绑定产品码失败!错误码:" + ex.Message };
  1052. }
  1053. #endregion
  1054. }
  1055. // op50向testdata表格插入数据
  1056. public static ResponseMessage InsertOp50Data(string carrierCode, string productBarcode, int assemblyStatus,
  1057. int addBoardStatus, float addBoardPressure, int remainCount, string reinspectionImagePath)
  1058. {
  1059. // 检查上一次插入的记录是否存在
  1060. //var lastRecord = Db.Queryable<TestData>()
  1061. // .Where(x => x.CarrierCode == CarrierCode && x.ProductBarcode == ProductBarcode && x.OP40_GluePosition != "" && x.OP40_GlueLineArea != 0.0f &&
  1062. // x.OP40_GlueLineHeight != 0.0f && x.OP40_InspectionImagePath != "") // 只查找有效插入的数据
  1063. // .OrderBy(x => x.ID, OrderByType.Desc) // 按照ID降序查找最新记录
  1064. // .Take(1) // 只取一条记录
  1065. // .First(); // 获取第一条记录,若没有则返回null
  1066. //if (lastRecord == null)
  1067. //{
  1068. // logNet.WriteError("OP50错误:OP40插入的记录存在值为空!");
  1069. // return new ResponseMessage { result = false, text = "OP50错误:OP40插入的记录存在值为空!!" };
  1070. try
  1071. {
  1072. var lastRecord = Db.Queryable<TestData>()
  1073. .Where(x => x.CarrierCode == carrierCode)
  1074. .OrderBy(x => x.ID, OrderByType.Desc) // 按照ID降序查找最新记录
  1075. .Take(1) // 只取一条记录
  1076. .First(); // 获取第一条记录,若没有则返回null
  1077. if (lastRecord == null)
  1078. {
  1079. logNet.WriteError("OP50记录插入错误:MES主数据未成功创建,无法插入OP50数据!");
  1080. return new ResponseMessage { result = false, text = "OP50记录插入错误:MES主数据未成功创建,无法插入OP50数据!" };
  1081. }
  1082. ////if ( lastRecord.OP50_AssemblyStatus != 2 || lastRecord.OP50_ReinspectionImagePath != "" ||
  1083. //// lastRecord.OP50_AddBoardStatus != 2 || lastRecord.OP50_AddBoardPressure != 0.0f)
  1084. ////{
  1085. //// logNet.WriteError("OP50记录插入错误:即将插入的数据存在值不为空,插入失败,请按标准操作!");
  1086. //// return new ResponseMessage { result = false, text = "OP50记录插入错误:即将插入的数据存在值不为空,插入失败,请按标准操作!" };
  1087. ////}
  1088. lastRecord.OP50_AssemblyStatus = assemblyStatus; // 组装是否到位
  1089. lastRecord.OP50_AddBoardStatus = addBoardStatus; // ADD板有无
  1090. lastRecord.OP50_AddBoardPressure = addBoardPressure; // ADD板压合压力
  1091. lastRecord.OP50_RemainCount = remainCount; // ADD板余料数
  1092. lastRecord.OP50_ReinspectionImagePath = reinspectionImagePath; // ADD板余料数
  1093. Db.Updateable(lastRecord)
  1094. .UpdateColumns(x => new
  1095. {
  1096. x.OP50_AssemblyStatus,
  1097. x.OP50_AddBoardStatus,
  1098. x.OP50_AddBoardPressure,
  1099. x.OP50_RemainCount,
  1100. x.OP50_ReinspectionImagePath
  1101. }).ExecuteCommand();
  1102. logNet.WriteError("OP50记录插入成功!");
  1103. return new ResponseMessage { result = true, text = "OP50记录插入成功!" };
  1104. }
  1105. catch (Exception ex)
  1106. {
  1107. logNet.WriteError("OP50记录插入出错!错误码:" + ex.Message);
  1108. return new ResponseMessage { result = false, text = "OP50记录插入出错!错误码:" + ex.Message };
  1109. }
  1110. }
  1111. // op60向testdata表格插入数据
  1112. public static ResponseMessage InsertOp60Data(string carrierCode, string productBarcode, int assemblyStatus,
  1113. int topCoverStatus, float topCoverPressure, string reinspectionImagePath)
  1114. {
  1115. // 检查上一次插入的记录是否存在
  1116. //var lastRecord = Db.Queryable<TestData>()
  1117. // .Where(x => x.CarrierCode == CarrierCode && x.ProductBarcode == ProductBarcode && x.AddPCB_Barcode != "" && x.OP50_AssemblyStatus != 2 && x.OP50_ReinspectionImagePath != "" &&
  1118. // x.OP50_AddBoardStatus != 2 && x.OP50_AddBoardPressure != 0.0f) // 只查找有效插入的数据
  1119. // .OrderBy(x => x.ID, OrderByType.Desc) // 按照ID降序查找最新记录
  1120. // .Take(1) // 只取一条记录
  1121. // .First(); // 获取第一条记录,若没有则返回null
  1122. //if (lastRecord == null)
  1123. //{
  1124. // logNet.WriteError("OP60错误:OP50插入的记录存在值为空!");
  1125. // return new ResponseMessage { result = false, text = "OP60错误:OP50插入的记录存在值为空!" };
  1126. // }
  1127. try
  1128. {
  1129. var lastRecord = Db.Queryable<TestData>()
  1130. .Where(x => x.CarrierCode == carrierCode)
  1131. .OrderBy(x => x.ID, OrderByType.Desc) // 按照ID降序查找最新记录
  1132. .Take(1) // 只取一条记录
  1133. .First(); // 获取第一条记录,若没有则返回null
  1134. if (lastRecord == null)
  1135. {
  1136. logNet.WriteError("OP60记录插入错误:MES主数据未成功创建,无法插入OP60数据!");
  1137. return new ResponseMessage { result = false, text = "OP60记录插入错误:MES主数据未成功创建,无法插入OP60数据!" };
  1138. }
  1139. //if (lastRecord.OP60_AssemblyStatus != 0 || lastRecord.OP60_ReinspectionImagePath != "" ||
  1140. // lastRecord.OP60_TopCoverStatus != 0 || lastRecord.OP60_TopCoverPressure != 0.0f)
  1141. //{
  1142. // logNet.WriteError("OP50记录插入错误:即将插入的数据存在值不为空,插入失败,请按标准操作!");
  1143. // return new ResponseMessage { result = false, text = "OP50记录插入错误:即将插入的数据存在值不为空,插入失败,请按标准操作!" };
  1144. //}
  1145. lastRecord.OP60_AssemblyStatus = assemblyStatus; // 组装是否到位
  1146. lastRecord.OP60_TopCoverStatus = topCoverStatus; // 上盖板有无
  1147. lastRecord.OP60_TopCoverPressure = topCoverPressure; // 上盖板压合压力
  1148. lastRecord.OP60_ReinspectionImagePath = reinspectionImagePath; // 设备复检图片路径
  1149. Db.Updateable(lastRecord)
  1150. .UpdateColumns(x => new
  1151. {
  1152. x.OP60_AssemblyStatus,
  1153. x.OP60_ReinspectionImagePath,
  1154. x.OP60_TopCoverStatus,
  1155. x.OP60_TopCoverPressure
  1156. }).ExecuteCommand();
  1157. logNet.WriteError("OP60记录插入成功!");
  1158. return new ResponseMessage { result = true, text = "OP60记录插入成功!" };
  1159. }
  1160. catch (Exception ex)
  1161. {
  1162. logNet.WriteError("OP60记录插入出错!错误码:" + ex.Message);
  1163. return new ResponseMessage { result = false, text = "OP60记录插入出错!错误码:" + ex.Message };
  1164. }
  1165. }
  1166. // op701向testdata表格插入数据
  1167. public static ResponseMessage InsertOp701Data(string carrierCode, string productBarcode, string lockTime, string lockOrder, string lockResult, int remainCount)
  1168. {
  1169. // 检查上一次插入的记录是否存在
  1170. //var lastRecord = Db.Queryable<TestData>()
  1171. // .Where(x => x.CarrierCode == CarrierCode && x.ProductBarcode == ProductBarcode && x.OP60_AssemblyStatus != 2 && x.OP60_ReinspectionImagePath != "" &&
  1172. // x.OP60_TopCoverStatus != 2 && x.OP60_TopCoverPressure != 0.0f) // 只查找有效插入的数据
  1173. // .OrderBy(x => x.ID, OrderByType.Desc) // 按照ID降序查找最新记录
  1174. // .Take(1) // 只取一条记录
  1175. // .First(); // 获取第一条记录,若没有则返回null
  1176. //if (lastRecord == null)
  1177. //{
  1178. // logNet.WriteError("OP701错误:OP60插入的记录存在值为空!");
  1179. // return new ResponseMessage { result = false, text = "OP701错误:OP60插入的记录存在值为空!" };
  1180. //}
  1181. try
  1182. {
  1183. var lastRecord = Db.Queryable<TestData>()
  1184. .Where(x => x.CarrierCode == carrierCode)
  1185. .OrderBy(x => x.ID, OrderByType.Desc) // 按照ID降序查找最新记录
  1186. .Take(1) // 只取一条记录
  1187. .First(); // 获取第一条记录,若没有则返回null
  1188. if (lastRecord == null)
  1189. {
  1190. logNet.WriteError("OP701记录插入错误:MES主数据未成功创建,无法插入OP701数据!");
  1191. return new ResponseMessage { result = false, text = "OP701记录插入错误:MES主数据未成功创建,无法插入OP701数据!" };
  1192. }
  1193. //if (lastRecord.OP701_LockTime != "" || lastRecord.OP701_LockOrder != "" || lastRecord.OP701_LockResult != "")
  1194. //{
  1195. // logNet.WriteError("OP701错误:即将插入的数据存在值不为空,插入失败,请按标准操作!");
  1196. // return new ResponseMessage { result = false, text = "OP701错误:即将插入的数据存在值不为空,插入失败,请按标准操作!" };
  1197. //}
  1198. lastRecord.OP701_LockTime = lockTime;
  1199. lastRecord.OP701_LockOrder = lockOrder;
  1200. lastRecord.OP701_LockResult = lockResult;
  1201. lastRecord.OP701_RemainCount = remainCount;
  1202. Db.Updateable(lastRecord)
  1203. .UpdateColumns(x => new
  1204. {
  1205. x.OP701_LockTime,
  1206. x.OP701_LockOrder,
  1207. x.OP701_LockResult,
  1208. x.OP701_RemainCount
  1209. }).ExecuteCommand();
  1210. logNet.WriteError("OP701记录插入成功!");
  1211. return new ResponseMessage { result = true, text = "OP701记录插入成功!" };
  1212. }
  1213. catch (Exception ex)
  1214. {
  1215. logNet.WriteError("OP701记录插入出错!错误码:" + ex.Message);
  1216. return new ResponseMessage { result = false, text = "OP701记录插入出错!错误码:" + ex.Message };
  1217. }
  1218. }
  1219. // op702向testdata表格插入数据
  1220. public static ResponseMessage InsertOp702Data(string carrierCode, string productBarcode, string lockTime, string lockOrder, string lockResult, int remainCount)
  1221. {
  1222. //// 检查上一次插入的记录是否存在
  1223. //var lastRecord = Db.Queryable<TestData>()
  1224. // .Where(x => x.CarrierCode == CarrierCode && x.ProductBarcode == ProductBarcode && x.OP701_TorqueCurveDataPath != "" && x.OP701_ScrewPressure != 0.0f &&
  1225. // x.OP701_Turns != 0 && x.OP701_LockTime != 0 && x.OP701_LockOrder != "" &&
  1226. // x.OP701_LockResult != "") // 只查找有效插入的数据
  1227. // .OrderBy(x => x.ID, OrderByType.Desc) // 按照ID降序查找最新记录
  1228. // .Take(1) // 只取一条记录
  1229. // .First(); // 获取第一条记录,若没有则返回null
  1230. //if (lastRecord == null)
  1231. //{
  1232. // logNet.WriteError("OP702错误:OP701插入的记录存在值为空!");
  1233. // return new ResponseMessage { result = false, text = "OP702错误:OP701插入的记录存在值为空!" };
  1234. //}
  1235. try
  1236. {
  1237. var lastRecord = Db.Queryable<TestData>()
  1238. .Where(x => x.CarrierCode == carrierCode)
  1239. .OrderBy(x => x.ID, OrderByType.Desc) // 按照ID降序查找最新记录
  1240. .Take(1) // 只取一条记录
  1241. .First(); // 获取第一条记录,若没有则返回null
  1242. if (lastRecord == null)
  1243. {
  1244. logNet.WriteError("OP702记录插入错误:MES主数据未成功创建,无法插入OP702数据!");
  1245. return new ResponseMessage { result = false, text = "OP702记录插入错误:MES主数据未成功创建,无法插入OP702数据!" };
  1246. }
  1247. lastRecord.OP702_LockTime = lockTime;
  1248. lastRecord.OP702_LockOrder = lockOrder;
  1249. lastRecord.OP702_LockResult = lockResult;
  1250. lastRecord.OP702_RemainCount = remainCount;
  1251. Db.Updateable(lastRecord)
  1252. .UpdateColumns(x => new
  1253. {
  1254. x.OP702_LockTime,
  1255. x.OP702_LockOrder,
  1256. x.OP702_LockResult,
  1257. x.OP702_RemainCount
  1258. }).ExecuteCommand();
  1259. logNet.WriteError("OP702记录插入成功!");
  1260. return new ResponseMessage { result = true, text = "OP702记录插入成功!" };
  1261. }
  1262. catch (Exception ex)
  1263. {
  1264. logNet.WriteError("OP702记录插入出错!错误码:" + ex.Message);
  1265. return new ResponseMessage { result = false, text = "OP702记录插入出错!错误码:" + ex.Message };
  1266. }
  1267. }
  1268. // op80向testdata表格插入数据
  1269. public static ResponseMessage InsertOp80Data(string carrierCode, string productBarcode, string screwHeights,
  1270. string screwResults)
  1271. {
  1272. try
  1273. {
  1274. var lastRecord = Db.Queryable<TestData>()
  1275. .Where(x => x.CarrierCode == carrierCode)
  1276. .OrderBy(x => x.ID, OrderByType.Desc) // 按照ID降序查找最新记录
  1277. .Take(1) // 只取一条记录
  1278. .First(); // 获取第一条记录,若没有则返回null
  1279. if (lastRecord == null)
  1280. {
  1281. logNet.WriteError("OP80记录插入错误:MES主数据未成功创建,无法插入OP80数据!");
  1282. return new ResponseMessage { result = false, text = "OP80记录插入错误:MES主数据未成功创建,无法插入OP80数据!" };
  1283. }
  1284. lastRecord.OP80_ScrewHeights = screwHeights;
  1285. lastRecord.OP80_ScrewResults = screwResults;
  1286. Db.Updateable(lastRecord)
  1287. .UpdateColumns(x => new
  1288. {
  1289. x.OP80_ScrewHeights,
  1290. x.OP80_ScrewResults
  1291. }).ExecuteCommand();
  1292. logNet.WriteError("OP80记录插入成功!");
  1293. return new ResponseMessage { result = true, text = "OP80记录插入成功!" };
  1294. }
  1295. catch (Exception ex)
  1296. {
  1297. logNet.WriteError("OP80记录插入出错!错误码:" + ex.Message);
  1298. return new ResponseMessage { result = false, text = "OP80记录插入出错!错误码:" + ex.Message };
  1299. }
  1300. }
  1301. // op90向testdata表格插入数据
  1302. public static ResponseMessage InsertOp90Data(string carrierCode, string productBarcode, int throwCount,
  1303. int remainCount)
  1304. {
  1305. try
  1306. {
  1307. var lastRecord = Db.Queryable<TestData>()
  1308. .Where(x => x.CarrierCode == carrierCode)
  1309. .OrderBy(x => x.ID, OrderByType.Desc) // 按照ID降序查找最新记录
  1310. .Take(1) // 只取一条记录
  1311. .First(); // 获取第一条记录,若没有则返回null
  1312. if (lastRecord == null)
  1313. {
  1314. logNet.WriteError("OP90记录插入错误:MES主数据未成功创建,无法插入OP90数据!");
  1315. return new ResponseMessage { result = false, text = "OP90记录插入错误:MES主数据未成功创建,无法插入OP90数据!" };
  1316. }
  1317. lastRecord.OP90_ThrowCount = throwCount;
  1318. lastRecord.OP90_RemainCount = remainCount;
  1319. Db.Updateable(lastRecord)
  1320. .UpdateColumns(x => new
  1321. {
  1322. x.OP80_ScrewHeights,
  1323. x.OP80_ScrewResults
  1324. }).ExecuteCommand();
  1325. logNet.WriteError("OP90记录插入成功!");
  1326. return new ResponseMessage { result = true, text = "OP90记录插入成功!" };
  1327. }
  1328. catch (Exception ex)
  1329. {
  1330. logNet.WriteError("OP80记录插入出错!错误码:" + ex.Message);
  1331. return new ResponseMessage { result = false, text = "OP90记录插入出错!错误码:" + ex.Message };
  1332. }
  1333. }
  1334. #region 实体
  1335. // 定义实体类(对应数据库表)载具绑定表
  1336. public class CarrierBind
  1337. {
  1338. // 主键ID,设置为自增且非空
  1339. [SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
  1340. public int ID { get; set; } // 主键ID
  1341. // 其他列
  1342. public string CarrierCode { get; set; } = ""; // 载具码
  1343. public string ProductBarcode { get; set; } = ""; // 产品码
  1344. public string PCBBarcode { get; set; } = ""; // 产品码
  1345. public DateTime CreateTime { get; set; } = DateTime.Now; // 创建时间
  1346. }
  1347. // 定义ProductBind实体类,表示表格结构
  1348. public class ProductBind
  1349. {
  1350. // 主键ID,设置为自增且非空
  1351. [SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
  1352. public int ID { get; set; } // 主键ID
  1353. // 其他列
  1354. public DateTime CreateTime { get; set; } = DateTime.Now; // 创建时间
  1355. public string CarrierCode { get; set; } = ""; // 载具码
  1356. public string ProductBarcode { get; set; } = ""; // 产品条码
  1357. public string TopCover_Barcode { get; set; } = ""; // 上盖板条码
  1358. public string AddPCB_Barcode { get; set; } = ""; // ADD板条码
  1359. public int BindOrder { get; set; } = 0; // 绑定顺序
  1360. }
  1361. // 定义TestData实体类,表示表格TestData结构
  1362. public class TestData
  1363. {
  1364. // 主键ID,设置为自增且非空
  1365. [SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
  1366. public int ID { get; set; } // 主键ID
  1367. // 其他列
  1368. public DateTime CreateTime { get; set; } = DateTime.Now; // 创建时间
  1369. public string CarrierCode { get; set; } = ""; // 载具码
  1370. public string ProductBarcode { get; set; } = ""; // 产品条码
  1371. public int BindOrder { get; set; } = 0; // 绑定顺序
  1372. //op10
  1373. public int OP10_ThrowingAmount { get; set; } = 0; // 抛料数量 // 清洗功率
  1374. public float OP10_CleaningPressure { get; set; } = 0.0f; // 清洗气压
  1375. public float OP10_CleaningSpeed { get; set; } = 0.0f; // 清洗速度
  1376. public float OP10_AirKnifeHeight { get; set; } = 0.0f; // 风刀高度
  1377. public float OP10_CleaningTime { get; set; } = 0.0f; // 清洗时间
  1378. public int OP10_CleaningCount { get; set; } = 0; // 清洗次数
  1379. public int OP10_RemainCount { get; set; } = 0; // 外壳体余料数
  1380. //op20
  1381. public int OP20_ThrowCount { get; set; } = 0; // 抛料数量
  1382. public int OP20_RemainCount { get; set; } = 0; // 上盖余料数
  1383. //op301
  1384. public float OP301_GluingSpeed { get; set; } = 0.0f; // 供胶速度
  1385. public float OP301_PressureAB { get; set; } = 0.0f; // A管气压
  1386. public float OP301_PressureDifferenceAB { get; set; } = 0.0f; // AB管气压差
  1387. [SqlSugar.SugarColumn(ColumnDataType = "varchar(500)")]
  1388. public string OP301_ProductHeightInfo { get; set; } = ""; // 产品测高信息
  1389. [SqlSugar.SugarColumn(ColumnDataType = "varchar(500)")]
  1390. public string OP301_PeriodicWeightData { get; set; } = ""; // 定期称重数据
  1391. [SqlSugar.SugarColumn(ColumnDataType = "varchar(500)")]
  1392. public string OP301_RemainingGlueAmount { get; set; } = ""; // 剩余胶量
  1393. //op302
  1394. public float OP302_GluingSpeed { get; set; } = 0.0f; // 供胶速度
  1395. public float OP302_PressureAB { get; set; } = 0.0f; // A管气压
  1396. public float OP302_PressureDifferenceAB { get; set; } = 0.0f; // AB管气压差
  1397. [SqlSugar.SugarColumn(ColumnDataType = "varchar(500)")]
  1398. public string OP302_ProductHeightInfo { get; set; } = ""; // 产品测高信息
  1399. [SqlSugar.SugarColumn(ColumnDataType = "varchar(500)")]
  1400. public string OP302_PeriodicWeightData { get; set; } = ""; // 定期称重数据
  1401. [SqlSugar.SugarColumn(ColumnDataType = "varchar(500)")]
  1402. public string OP302_RemainingGlueAmount { get; set; } = ""; // 剩余胶量
  1403. //op40
  1404. [SqlSugar.SugarColumn(ColumnDataType = "varchar(500)")]
  1405. public string OP40_GluePosX { get; set; } = ""; // 胶线位置X偏差
  1406. [SqlSugar.SugarColumn(ColumnDataType = "varchar(500)")]
  1407. public string OP40_GluePosY { get; set; } = ""; // 胶线位置Y偏差
  1408. [SqlSugar.SugarColumn(ColumnDataType = "varchar(500)")]
  1409. public string OP40_GlueLineArea { get; set; } = ""; // 胶线面积
  1410. [SqlSugar.SugarColumn(ColumnDataType = "varchar(500)")]
  1411. public string OP40_GlueLineHeight { get; set; } = ""; // 胶线高度
  1412. public string OP40_Result { get; set; } = ""; // 胶线检测结果 1:OK 非1:NG
  1413. public string OP40_InspectionImagePath { get; set; } = ""; // 检测图片路径
  1414. //op50
  1415. public int OP50_AssemblyStatus { get; set; } = 0; // 组装是否到位
  1416. public string OP50_ReinspectionImagePath { get; set; } = ""; // 设备复检图片路径
  1417. public int OP50_AddBoardStatus { get; set; } = 0; // ADD板有无
  1418. public int OP50_RemainCount { get; set; } = 0; // ADD板余料数
  1419. public float OP50_AddBoardPressure { get; set; } = 0.0f; // ADD板压合压力
  1420. //op60
  1421. public int OP60_AssemblyStatus { get; set; } = 0; // 组装是否到位
  1422. public int OP60_TopCoverStatus { get; set; } = 0; // 上盖板有无
  1423. public float OP60_TopCoverPressure { get; set; } = 0.0f; // 上盖板压合压力
  1424. public string OP60_ReinspectionImagePath { get; set; } = ""; // 设备复检图片路径
  1425. //op701
  1426. [SqlSugar.SugarColumn(ColumnDataType = "varchar(500)")]
  1427. public string OP701_LockTime { get; set; } = ""; // 锁附时间
  1428. [SqlSugar.SugarColumn(ColumnDataType = "varchar(500)")]
  1429. public string OP701_LockOrder { get; set; } = ""; // 锁附顺序
  1430. [SqlSugar.SugarColumn(ColumnDataType = "varchar(500)")]
  1431. public string OP701_LockResult { get; set; } = ""; // 锁附结果
  1432. public int OP701_RemainCount { get; set; } = 0; // 螺丝余料数
  1433. //op702
  1434. [SqlSugar.SugarColumn(ColumnDataType = "varchar(500)")]
  1435. public string OP702_LockTime { get; set; } = ""; // 锁附时间
  1436. [SqlSugar.SugarColumn(ColumnDataType = "varchar(500)")]
  1437. public string OP702_LockOrder { get; set; } = ""; // 锁附顺序
  1438. [SqlSugar.SugarColumn(ColumnDataType = "varchar(500)")]
  1439. public string OP702_LockResult { get; set; } = ""; // 锁附结果
  1440. public int OP702_RemainCount { get; set; } = 0; // 螺丝余料数
  1441. //op80
  1442. [SqlSugar.SugarColumn(ColumnDataType = "varchar(500)")]
  1443. public string OP80_ScrewHeights { get; set; } = ""; // 螺丝高度
  1444. public string OP80_ScrewResults { get; set; } = ""; // 螺丝检测结果
  1445. //op90
  1446. public int OP90_ThrowCount { get; set; } = 0; // 抛料次数
  1447. public int OP90_RemainCount { get; set; } = 0; // 料箱余料数
  1448. }
  1449. #endregion
  1450. }
  1451. }