SQLHelper.cs 79 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609
  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. Console.WriteLine($"获取载具绑定的PCB码报错:{ex.Message}");
  616. return string.Empty;
  617. }
  618. }
  619. //载具码和产品码解除绑定关系
  620. public static ResponseMessage DelCarrierBind(string carrierCode)
  621. {
  622. // 检查记录是否已经存在
  623. var CarrierBind_exists = Db.Queryable<CarrierBind>().Where(x => x.CarrierCode == carrierCode);
  624. try
  625. {
  626. Db.Deleteable<CarrierBind>().Where(x => x.CarrierCode == carrierCode).ExecuteCommand();
  627. logNet.WriteInfo($"载具码与产品码解绑成功。");
  628. return new ResponseMessage { result = true, text = "载具码与产品码解绑成功" };
  629. }
  630. catch (Exception ex)
  631. {
  632. logNet.WriteError($"载具码与产品码解绑成功,错误" + ex.Message);
  633. return new ResponseMessage { result = false, text = "载具码与产品码解绑成功,错误" + ex.Message };
  634. }
  635. #endregion
  636. }
  637. //载具码和产品码绑定关系
  638. public static ResponseMessage InsertCarrierBind(string carrierCode, string productBarcode)
  639. {
  640. carrierCode = carrierCode.Replace("\r", "");
  641. productBarcode = productBarcode.Replace("\r", "");
  642. #region 新建CarrierBind实体,并将数据插入carrierBind表格
  643. // 创建 CarrierBind 实体,并通过传入的参数设置字段值
  644. var CarrierBind_sumRecord = new CarrierBind
  645. {
  646. CarrierCode = carrierCode,
  647. ProductBarcode = productBarcode
  648. };
  649. // 检查记录是否已经存在
  650. var CarrierBind_exists = Db.Queryable<CarrierBind>().Where(x => x.CarrierCode == carrierCode);
  651. try
  652. {
  653. if (CarrierBind_exists != null)
  654. {
  655. Db.Deleteable<CarrierBind>().Where(x => x.CarrierCode == carrierCode).ExecuteCommand();
  656. logNet.WriteInfo($"载具码与产品码已存在绑定关系,先解绑。");
  657. }
  658. // 插入数据
  659. Db.Insertable(CarrierBind_sumRecord).ExecuteCommand();
  660. logNet.WriteInfo($"载具码与产品码绑定成功。");
  661. return new ResponseMessage { result = true, text = "载具码与产品码绑定成功" };
  662. }
  663. catch (Exception ex)
  664. {
  665. logNet.WriteError($"载具码与产品码绑定失败,错误" + ex.Message);
  666. return new ResponseMessage { result = false, text = "载具码与产品码绑定失败,错误" + ex.Message };
  667. }
  668. #endregion
  669. }
  670. //载具码和产品码绑定关系
  671. public static ResponseMessage PCBCarrierBind(string carrierCode, string pcbBarcode)
  672. {
  673. pcbBarcode = pcbBarcode.Replace("\r", "");
  674. // 检查记录是否已经存在
  675. var CarrierBind_exists = Db.Queryable<CarrierBind>()
  676. .Where(x => x.CarrierCode == carrierCode)
  677. .OrderByDescending(x => x.CreateTime)
  678. .Take(1)
  679. .First();
  680. try
  681. {
  682. if (CarrierBind_exists != null)
  683. {
  684. Db.Updateable<CarrierBind>()
  685. .SetColumns(x=>x.PCBBarcode== pcbBarcode)
  686. .Where(x => x.ID == CarrierBind_exists.ID)
  687. .ExecuteCommand();
  688. logNet.WriteInfo($"载具码{carrierCode}与PCB码{pcbBarcode}绑定成功");
  689. }
  690. else {
  691. return new ResponseMessage { result = true, text = "载具码与PCB码绑定失败!载具码["+ carrierCode + "]没有绑定记录"};
  692. }
  693. // 插入数据
  694. return new ResponseMessage { result = true, text = "载具码与PCB码绑定成功" };
  695. }
  696. catch (Exception ex)
  697. {
  698. logNet.WriteError($"载具码与产品码绑定失败,错误" + ex.Message);
  699. return new ResponseMessage { result = false, text = "载具码与产品码绑定失败,错误" + ex.Message };
  700. }
  701. }
  702. public static ResponseMessage InsertOp10Data(string carrierCode, string productBarcode, int bindOrder,
  703. int throwingAmount, float cleaningPressure, float cleaningSpeed,
  704. float airKnifeHeight, float cleaningTime, int cleaningCount, int remainCount)
  705. {
  706. // 检查记录是否已经存在
  707. bool OP10_exists = Db.Queryable<CarrierBind>().Any(x => x.CarrierCode == carrierCode &&
  708. x.ProductBarcode == productBarcode);
  709. if (OP10_exists)
  710. {
  711. var maxBindOrder = Db.Queryable<TestData>()
  712. .Where(x => x.CarrierCode == carrierCode &&
  713. x.ProductBarcode == productBarcode)
  714. .Max(x => x.BindOrder); ;
  715. bindOrder = maxBindOrder + 1;
  716. }
  717. #region 将OP10数据插入testdata表格
  718. // 创建 Op10 实体,并通过传入的参数设置字段值
  719. var op10 = new TestData
  720. {
  721. CarrierCode = carrierCode, // 载具码
  722. ProductBarcode = productBarcode, // 产品码
  723. BindOrder = bindOrder, // 绑定顺序
  724. OP10_ThrowingAmount = throwingAmount, // 抛料数量
  725. OP10_CleaningPressure = cleaningPressure, // 清洗气压
  726. OP10_CleaningSpeed = cleaningSpeed, // 清洗速度
  727. OP10_AirKnifeHeight = airKnifeHeight, // 风刀高度
  728. OP10_CleaningTime = cleaningTime, // 清洗时间
  729. OP10_CleaningCount = cleaningCount, // 清洗次数
  730. OP10_RemainCount = remainCount // 清洗次数
  731. };
  732. try
  733. {
  734. Db.Insertable(op10).ExecuteCommand();
  735. logNet.WriteError("OP10记录插入成功!");
  736. return new ResponseMessage { result = true, text = "OP10记录插入成功" };
  737. }
  738. catch (Exception ex)
  739. {
  740. logNet.WriteError("OP10记录插入出错!错误码:" + ex.Message);
  741. return new ResponseMessage { result = false, text = "OP10记录插入出错!错误码:" + ex.Message };
  742. }
  743. #endregion
  744. }
  745. // op20绑定部件码
  746. public static ResponseMessage InsertOp20Product(string carrierCode, string productBarcode, string topCover_Barcode)
  747. {
  748. int bindOrder = 1;
  749. try
  750. {
  751. // 检查记录是否已经存在
  752. bool Product_exists = Db.Queryable<ProductBind>().Any(x => x.CarrierCode == carrierCode &&
  753. x.ProductBarcode == productBarcode);
  754. if (Product_exists)
  755. {
  756. var maxBindOrder = Db.Queryable<ProductBind>()
  757. .Where(x => x.CarrierCode == carrierCode &&
  758. x.ProductBarcode == productBarcode)
  759. .Max(x => x.BindOrder); ;
  760. bindOrder = maxBindOrder + 1;
  761. }
  762. #region 新建ProductBind实体,并将数据插入productBind表格
  763. // 创建 ProductBind 实体,并通过传入的参数设置字段值
  764. var ProductBind_sumRecord = new ProductBind
  765. {
  766. CarrierCode = carrierCode,//载具码
  767. ProductBarcode = productBarcode, // 产品条码
  768. BindOrder = bindOrder, // 绑定顺序
  769. TopCover_Barcode = topCover_Barcode, //部件码
  770. };
  771. // 插入数据
  772. Db.Insertable(ProductBind_sumRecord).ExecuteCommand();
  773. return new ResponseMessage { result = true, text = "OP20-产品码绑定部件码成功!" };
  774. }
  775. catch (Exception ex)
  776. {
  777. logNet.WriteError("OP20-产品码绑定部件码出错!错误码:" + ex.Message);
  778. return new ResponseMessage { result = false, text = "OP20-产品码绑定部件码出错!错误码:" + ex.Message };
  779. }
  780. #endregion
  781. }
  782. // op20向testdata表格插入数据
  783. public static ResponseMessage InsertOp20Data(string carrierCode, string productBarcode, int throwCount, int remainCount)
  784. {
  785. ////// 检查上一次插入的记录是否存在
  786. ////var lastRecord = Db.Queryable<TestData>()
  787. //// .Where(x => x.CarrierCode== carrierCode && x.ProductBarcode == productBarcode &&
  788. //// (x.OP10_ThrowingAmount != 0 ||
  789. //// x.OP10_CleaningPressure != 0.0f ||
  790. //// x.OP10_CleaningSpeed != 0.0f ||
  791. //// x.OP10_AirKnifeHeight != 0.0f ||
  792. //// x.OP10_CleaningTime != 0.0f ||
  793. //// x.OP10_CleaningCount != 0 ||
  794. //// x.OP10_RemainCount != 0)) // 看上一次有无记录数据
  795. //// .OrderBy(x => x.ID, OrderByType.Desc) // 按照ID降序查找最新记录
  796. //// .Take(1) // 只取一条记录
  797. //// .First(); // 获取第一条记录,若没有则返回null
  798. ////if (lastRecord == null)
  799. ////{
  800. //// logNet.WriteError("OP20错误:OP10未插入数据!");
  801. ////}
  802. try
  803. {
  804. var lastRecord = Db.Queryable<TestData>()
  805. .Where(x => x.CarrierCode == carrierCode)
  806. .OrderBy(x => x.ID, OrderByType.Desc) // 按照ID降序查找最新记录
  807. .Take(1) // 只取一条记录
  808. .First(); // 获取第一条记录,若没有则返回null
  809. if (lastRecord == null)
  810. {
  811. logNet.WriteError("OP20记录插入出错:MES主数据未成功创建,无法插入OP20数据!");
  812. return new ResponseMessage { result = false, text = "OP20错误:MES主数据未成功创建,无法插入OP20数据!" };
  813. }
  814. //if (lastRecord.OP20_ThrowCount != 0 || lastRecord.OP20_RemainCount != 0)
  815. //{
  816. // logNet.WriteError("OP20记录插入出错:即将插入的行数据已存在,插入失败!");
  817. // return new ResponseMessage { result = false, text = "OP20记录插入出错:即将插入的行数据已存在,插入失败!" };
  818. //}
  819. lastRecord.OP20_ThrowCount = throwCount;
  820. lastRecord.OP20_RemainCount = remainCount;
  821. Db.Updateable(lastRecord)
  822. .UpdateColumns(x => new { x.OP20_ThrowCount, x.OP20_RemainCount })
  823. .ExecuteCommand();
  824. logNet.WriteError("OP20记录插入成功!");
  825. return new ResponseMessage { result = true, text = "OP20记录插入成功!" };
  826. }
  827. catch (Exception ex)
  828. {
  829. logNet.WriteError("OP20记录插入出错!错误码:" + ex.Message);
  830. return new ResponseMessage { result = false, text = "OP20记录插入出错!错误码:" + ex.Message };
  831. }
  832. }
  833. // op301向testdata表格插入数据
  834. public static ResponseMessage InsertOp301Data(string carrierCode, string productBarcode, float gluingSpeed, float pressureAB, float pressureDifferenceAB,
  835. string productHeightInfo, string periodicWeightData, string remainingGlueAmount)
  836. {
  837. ////// 检查上一次插入的记录是否存在
  838. ////var lastRecord = Db.Queryable<TestData>()
  839. //// .Where(x => x.CarrierCode == carrierCode && x.ProductBarcode == productBarcode &&
  840. //// (x.OP20_ThrowCount != 0 || x.OP20_RemainCount != 0)) // 只查找有效插入的数据
  841. //// .OrderBy(x => x.ID, OrderByType.Desc) // 按照ID降序查找最新记录
  842. //// .Take(1) // 只取一条记录
  843. //// .First(); // 获取第一条记录,若没有则返回null
  844. ////if (lastRecord == null)
  845. ////{
  846. //// logNet.WriteError("OP301错误:OP20插入的记录存在值为空!");
  847. //// return new ResponseMessage { result = false, text = "OP301错误:OP20插入的记录存在值为空!" };
  848. ////}
  849. try
  850. {
  851. var lastRecord = Db.Queryable<TestData>()
  852. .Where(x => x.CarrierCode == carrierCode)
  853. .OrderBy(x => x.ID, OrderByType.Desc) // 按照ID降序查找最新记录
  854. .Take(1) // 只取一条记录
  855. .First(); // 获取第一条记录,若没有则返回null
  856. if (lastRecord == null)
  857. {
  858. logNet.WriteError("OP301错误:MES主数据未成功创建,无法插入OP301数据!");
  859. return new ResponseMessage { result = false, text = "OP301错误:MES主数据未成功创建,无法插入OP301数据!" };
  860. }
  861. //if (lastRecord.OP301_GluingSpeed != 0.0f || lastRecord.OP301_PressureAB != 0.0f ||
  862. //lastRecord.OP301_PressureDifferenceAB != 0.0f || lastRecord.OP301_ProductHeightInfo != 0.0f ||
  863. //lastRecord.OP301_PeriodicWeightData != 0.0f || lastRecord.OP301_RemainingGlueAmount != 0.0f)
  864. //{
  865. // logNet.WriteError("OP301记录插入出错:即将插入的行数据已存在,插入失败!");
  866. // return new ResponseMessage { result = false, text = "OP301记录插入出错:即将插入的行数据已存在,插入失败!" };
  867. //}
  868. lastRecord.OP301_GluingSpeed = gluingSpeed; // 供胶速度
  869. lastRecord.OP301_PressureAB = pressureAB; // AB管气压
  870. lastRecord.OP301_PressureDifferenceAB = pressureDifferenceAB; // AB管气压差
  871. lastRecord.OP301_ProductHeightInfo = productHeightInfo; // 产品测高信息
  872. lastRecord.OP301_PeriodicWeightData = periodicWeightData; // 定期称重数据
  873. lastRecord.OP301_RemainingGlueAmount = remainingGlueAmount; // 剩余胶量
  874. Db.Updateable(lastRecord)
  875. .UpdateColumns(x => new
  876. {
  877. x.OP301_GluingSpeed,
  878. x.OP301_PressureAB,
  879. x.OP301_PressureDifferenceAB,
  880. x.OP301_ProductHeightInfo,
  881. x.OP301_PeriodicWeightData,
  882. x.OP301_RemainingGlueAmount
  883. }).ExecuteCommand();
  884. logNet.WriteError("OP301记录插入成功!");
  885. return new ResponseMessage { result = true, text = "OP301记录插入成功" };
  886. }
  887. catch (Exception ex)
  888. {
  889. logNet.WriteError("OP301记录插入出错!错误码:" + ex.Message);
  890. return new ResponseMessage { result = false, text = "OP301记录插入出错!错误码:" + ex.Message };
  891. }
  892. }
  893. // op302向testdata表格插入数据
  894. public static ResponseMessage InsertOp302Data(string carrierCode, string productBarcode, float gluingSpeed, float pressureAB, float pressureDifferenceAB,
  895. string productHeightInfo, string periodicWeightData, string remainingGlueAmount)
  896. {
  897. ////// 检查上一次插入的记录是否存在
  898. ////var lastRecord = Db.Queryable<TestData>()
  899. //// .Where(x => x.OP301_GluingSpeed != 0.0f && x.OP301_PressureA != 0.0f && x.OP301_PressureB != 0.0f &&
  900. //// x.OP301_PressureDifferenceAB != 0.0f && x.OP301_ProductHeightInfo != 0.0f &&
  901. //// x.OP301_PeriodicWeightData != 0.0f && x.OP301_RemainingGlueAmount != 0.0f) // 只查找有效插入的数据
  902. //// .OrderBy(x => x.ID, OrderByType.Desc) // 按照ID降序查找最新记录
  903. //// .Take(1) // 只取一条记录
  904. //// .First(); // 获取第一条记录,若没有则返回null
  905. ////if (lastRecord == null)
  906. ////{
  907. //// logNet.WriteError("OP302错误:OP301插入的记录存在值为空!");
  908. //// return new ResponseMessage { result = false, text = "OP302错误:OP301插入的记录存在值为空!" };
  909. ////}
  910. ///
  911. try
  912. {
  913. var lastRecord = Db.Queryable<TestData>()
  914. .Where(x => x.CarrierCode == carrierCode)
  915. .OrderBy(x => x.ID, OrderByType.Desc) // 按照ID降序查找最新记录
  916. .Take(1) // 只取一条记录
  917. .First(); // 获取第一条记录,若没有则返回null
  918. if (lastRecord == null)
  919. {
  920. logNet.WriteError("OP302记录插入错误:MES主数据未成功创建,无法插入OP302数据!");
  921. return new ResponseMessage { result = false, text = "OP302记录插入错误:MES主数据未成功创建,无法插入OP302数据!" };
  922. }
  923. //if (lastRecord.OP302_GluingSpeed != 0.0f || lastRecord.OP302_PressureAB != 0.0f ||
  924. // lastRecord.OP302_PressureDifferenceAB != 0.0f || lastRecord.OP302_ProductHeightInfo != "" ||
  925. // lastRecord.OP302_PeriodicWeightData !="" || lastRecord.OP302_RemainingGlueAmount != "")
  926. //{
  927. // logNet.WriteError("OP302记录插入出错:即将插入的行数据已存在,插入失败!");
  928. // return new ResponseMessage { result = false, text = "OP302记录插入出错:即将插入的行数据已存在,插入失败!" };
  929. //}
  930. lastRecord.OP302_GluingSpeed = gluingSpeed; // 供胶速度
  931. lastRecord.OP302_PressureAB = pressureAB; // AB管气压
  932. lastRecord.OP302_PressureDifferenceAB = pressureDifferenceAB; // AB管气压差
  933. lastRecord.OP302_ProductHeightInfo = productHeightInfo; // 产品测高信息
  934. lastRecord.OP302_PeriodicWeightData = periodicWeightData; // 定期称重数据
  935. lastRecord.OP302_RemainingGlueAmount = remainingGlueAmount; // 剩余胶量
  936. Db.Updateable(lastRecord)
  937. .UpdateColumns(x => new
  938. {
  939. x.OP302_GluingSpeed,
  940. x.OP302_PressureAB,
  941. x.OP302_PressureDifferenceAB,
  942. x.OP302_ProductHeightInfo,
  943. x.OP302_PeriodicWeightData,
  944. x.OP302_RemainingGlueAmount
  945. }).ExecuteCommand();
  946. logNet.WriteError("OP302记录插入成功!");
  947. return new ResponseMessage { result = true, text = "OP302记录插入成功" };
  948. }
  949. catch (Exception ex)
  950. {
  951. logNet.WriteError("OP302记录插入出错!错误码:" + ex.Message);
  952. return new ResponseMessage { result = false, text = "OP302错误:即将插入的数据存在值不为空,插入失败,请按标准操作!" };
  953. }
  954. }
  955. // op40向testdata表格插入数据
  956. public static ResponseMessage InsertOp40Data(string carrierCode, string productBarcode, string gluePosx, string gluePosy, string glueLineArea,
  957. string glueLineHeight, int result, string inspectionImagePath)
  958. {
  959. //// 检查上一次插入的记录是否存在
  960. //var lastRecord = Db.Queryable<TestData>()
  961. // .Where(x => x.OP302_GluingSpeed != 0.0f && x.OP302_PressureAB != 0.0f &&
  962. // x.OP302_PressureDifferenceAB != 0.0f && x.OP302_ProductHeightInfo != 0.0f &&
  963. // x.OP302_PeriodicWeightData != 0.0f && x.OP302_RemainingGlueAmount != 0.0f) // 只查找有效插入的数据
  964. // .OrderBy(x => x.ID, OrderByType.Desc) // 按照ID降序查找最新记录
  965. // .Take(1) // 只取一条记录
  966. // .First(); // 获取第一条记录,若没有则返回null
  967. //if (lastRecord == null)
  968. //{
  969. // logNet.WriteError("OP40错误:OP302插入的记录存在值为空!");
  970. // return new ResponseMessage { result = false, text = "OP40错误:OP302插入的记录存在值为空!" };
  971. //}
  972. //if (lastRecord.OP40_GluePosition != "" || lastRecord.OP40_GlueLineArea != 0.0f ||
  973. // lastRecord.OP40_GlueLineHeight != 0.0f || lastRecord.OP40_InspectionImagePath != "")
  974. //{
  975. // logNet.WriteError("OP40错误:即将插入的数据存在值不为空,插入失败,请按标准操作!");
  976. // return new ResponseMessage { result = false, text = "OP40错误:即将插入的数据存在值不为空,插入失败,请按标准操作!" };
  977. //}
  978. try
  979. {
  980. var lastRecord = Db.Queryable<TestData>()
  981. .Where(x => x.CarrierCode == carrierCode)
  982. .OrderBy(x => x.ID, OrderByType.Desc) // 按照ID降序查找最新记录
  983. .Take(1) // 只取一条记录
  984. .First(); // 获取第一条记录,若没有则返回null
  985. if (lastRecord == null)
  986. {
  987. logNet.WriteError("OP40记录插入错误:MES主数据未成功创建,无法插入OP40数据!");
  988. return new ResponseMessage { result = false, text = "OP40记录插入错误:MES主数据未成功创建,无法插入OP40数据!" };
  989. }
  990. ////if (lastRecord.OP40_GluePosX != "" || lastRecord.OP40_GluePosY != "" || lastRecord.OP40_GlueLineArea != "" ||
  991. //// lastRecord.OP40_GlueLineHeight != "" || lastRecord.OP40_Result != 0 || lastRecord.OP40_InspectionImagePath != "")
  992. ////{
  993. //// logNet.WriteError("OP40记录插入出错:即将插入的行数据已存在,插入失败!");
  994. //// return new ResponseMessage { result = false, text = "OP40记录插入出错:即将插入的行数据已存在,插入失败!" };
  995. ////}
  996. lastRecord.OP40_GluePosX = gluePosx; // 胶线位置X偏差
  997. lastRecord.OP40_GluePosY = gluePosy; // 胶线位置Y偏差
  998. lastRecord.OP40_GlueLineArea = glueLineArea; // 胶线面积
  999. lastRecord.OP40_GlueLineHeight = glueLineHeight; // 胶线高度
  1000. lastRecord.OP40_Result = result.ToString(); // 胶线检测结果
  1001. lastRecord.OP40_InspectionImagePath = inspectionImagePath; // 检测图片路径
  1002. Db.Updateable(lastRecord)
  1003. .UpdateColumns(x => new
  1004. {
  1005. x.OP40_GluePosX,
  1006. x.OP40_GluePosY,
  1007. x.OP40_GlueLineArea,
  1008. x.OP40_GlueLineHeight,
  1009. x.OP40_Result,
  1010. x.OP40_InspectionImagePath
  1011. }).ExecuteCommand();
  1012. logNet.WriteError("OP40记录插入成功!");
  1013. return new ResponseMessage { result = true, text = "OP40记录插入成功!" };
  1014. }
  1015. catch (Exception ex)
  1016. {
  1017. logNet.WriteError("OP40记录插入出错!错误码:" + ex.Message);
  1018. return new ResponseMessage { result = true, text = "OP40记录插入出错!错误码:" + ex.Message };
  1019. }
  1020. }
  1021. //OP50 往product塞数据
  1022. public static ResponseMessage InsertOp50Product(string carrierCode, string productBarcode, string addPCB_Barcode)
  1023. {
  1024. #region 往productBind表格中插入addPCB_Barcode数据
  1025. // 检查上一次插入的记录是否存在
  1026. try
  1027. {
  1028. var productBind_lastRecord = Db.Queryable<ProductBind>()
  1029. .Where(x => x.CarrierCode == carrierCode && x.ProductBarcode == productBarcode)
  1030. .OrderBy(x => x.ID, OrderByType.Desc) // 按照ID降序查找最新记录
  1031. .Take(1) // 只取一条记录
  1032. .First(); // 获取第一条记录,若没有则返回null
  1033. if (productBind_lastRecord == null)
  1034. {
  1035. logNet.WriteError("OP50-错误:ProductBind表数据为空!");
  1036. return new ResponseMessage { result = false, text = "OP50-错误:ProductBind表数据为空!" };
  1037. }
  1038. //if (productBind_lastRecord.AddPCB_Barcode != "")
  1039. //{
  1040. // logNet.WriteError("OP50-错误:即将插入ProductBind的数据存在值不为空,插入失败,请按标准操作!");
  1041. // return new ResponseMessage { result = false, text = "OP50-错误:即将插入ProductBind的数据存在值不为空,插入失败,请按标准操作!" };
  1042. //}
  1043. productBind_lastRecord.AddPCB_Barcode = addPCB_Barcode;
  1044. Db.Updateable(productBind_lastRecord)
  1045. .UpdateColumns(x => new
  1046. {
  1047. x.AddPCB_Barcode
  1048. }).ExecuteCommand();
  1049. logNet.WriteError("OP50部件码绑定产品码成功!");
  1050. return new ResponseMessage { result = false, text = "OP50部件码绑定产品码成功!" };
  1051. }
  1052. catch (Exception ex)
  1053. {
  1054. logNet.WriteError("OP50部件码绑定产品码失败!错误码:" + ex.Message);
  1055. return new ResponseMessage { result = false, text = "OP50部件码绑定产品码失败!错误码:" + ex.Message };
  1056. }
  1057. #endregion
  1058. }
  1059. // op50向testdata表格插入数据
  1060. public static ResponseMessage InsertOp50Data(string carrierCode, string productBarcode, int assemblyStatus,
  1061. int addBoardStatus, float addBoardPressure, int remainCount, string reinspectionImagePath)
  1062. {
  1063. // 检查上一次插入的记录是否存在
  1064. //var lastRecord = Db.Queryable<TestData>()
  1065. // .Where(x => x.CarrierCode == CarrierCode && x.ProductBarcode == ProductBarcode && x.OP40_GluePosition != "" && x.OP40_GlueLineArea != 0.0f &&
  1066. // x.OP40_GlueLineHeight != 0.0f && x.OP40_InspectionImagePath != "") // 只查找有效插入的数据
  1067. // .OrderBy(x => x.ID, OrderByType.Desc) // 按照ID降序查找最新记录
  1068. // .Take(1) // 只取一条记录
  1069. // .First(); // 获取第一条记录,若没有则返回null
  1070. //if (lastRecord == null)
  1071. //{
  1072. // logNet.WriteError("OP50错误:OP40插入的记录存在值为空!");
  1073. // return new ResponseMessage { result = false, text = "OP50错误:OP40插入的记录存在值为空!!" };
  1074. try
  1075. {
  1076. var lastRecord = Db.Queryable<TestData>()
  1077. .Where(x => x.CarrierCode == carrierCode)
  1078. .OrderBy(x => x.ID, OrderByType.Desc) // 按照ID降序查找最新记录
  1079. .Take(1) // 只取一条记录
  1080. .First(); // 获取第一条记录,若没有则返回null
  1081. if (lastRecord == null)
  1082. {
  1083. logNet.WriteError("OP50记录插入错误:MES主数据未成功创建,无法插入OP50数据!");
  1084. return new ResponseMessage { result = false, text = "OP50记录插入错误:MES主数据未成功创建,无法插入OP50数据!" };
  1085. }
  1086. ////if ( lastRecord.OP50_AssemblyStatus != 2 || lastRecord.OP50_ReinspectionImagePath != "" ||
  1087. //// lastRecord.OP50_AddBoardStatus != 2 || lastRecord.OP50_AddBoardPressure != 0.0f)
  1088. ////{
  1089. //// logNet.WriteError("OP50记录插入错误:即将插入的数据存在值不为空,插入失败,请按标准操作!");
  1090. //// return new ResponseMessage { result = false, text = "OP50记录插入错误:即将插入的数据存在值不为空,插入失败,请按标准操作!" };
  1091. ////}
  1092. lastRecord.OP50_AssemblyStatus = assemblyStatus; // 组装是否到位
  1093. lastRecord.OP50_AddBoardStatus = addBoardStatus; // ADD板有无
  1094. lastRecord.OP50_AddBoardPressure = addBoardPressure; // ADD板压合压力
  1095. lastRecord.OP50_RemainCount = remainCount; // ADD板余料数
  1096. lastRecord.OP50_ReinspectionImagePath = reinspectionImagePath; // ADD板余料数
  1097. Db.Updateable(lastRecord)
  1098. .UpdateColumns(x => new
  1099. {
  1100. x.OP50_AssemblyStatus,
  1101. x.OP50_AddBoardStatus,
  1102. x.OP50_AddBoardPressure,
  1103. x.OP50_RemainCount,
  1104. x.OP50_ReinspectionImagePath
  1105. }).ExecuteCommand();
  1106. logNet.WriteError("OP50记录插入成功!");
  1107. return new ResponseMessage { result = true, text = "OP50记录插入成功!" };
  1108. }
  1109. catch (Exception ex)
  1110. {
  1111. logNet.WriteError("OP50记录插入出错!错误码:" + ex.Message);
  1112. return new ResponseMessage { result = false, text = "OP50记录插入出错!错误码:" + ex.Message };
  1113. }
  1114. }
  1115. // op60向testdata表格插入数据
  1116. public static ResponseMessage InsertOp60Data(string carrierCode, string productBarcode, int assemblyStatus,
  1117. int topCoverStatus, float topCoverPressure, string reinspectionImagePath)
  1118. {
  1119. // 检查上一次插入的记录是否存在
  1120. //var lastRecord = Db.Queryable<TestData>()
  1121. // .Where(x => x.CarrierCode == CarrierCode && x.ProductBarcode == ProductBarcode && x.AddPCB_Barcode != "" && x.OP50_AssemblyStatus != 2 && x.OP50_ReinspectionImagePath != "" &&
  1122. // x.OP50_AddBoardStatus != 2 && x.OP50_AddBoardPressure != 0.0f) // 只查找有效插入的数据
  1123. // .OrderBy(x => x.ID, OrderByType.Desc) // 按照ID降序查找最新记录
  1124. // .Take(1) // 只取一条记录
  1125. // .First(); // 获取第一条记录,若没有则返回null
  1126. //if (lastRecord == null)
  1127. //{
  1128. // logNet.WriteError("OP60错误:OP50插入的记录存在值为空!");
  1129. // return new ResponseMessage { result = false, text = "OP60错误:OP50插入的记录存在值为空!" };
  1130. // }
  1131. try
  1132. {
  1133. var lastRecord = Db.Queryable<TestData>()
  1134. .Where(x => x.CarrierCode == carrierCode)
  1135. .OrderBy(x => x.ID, OrderByType.Desc) // 按照ID降序查找最新记录
  1136. .Take(1) // 只取一条记录
  1137. .First(); // 获取第一条记录,若没有则返回null
  1138. if (lastRecord == null)
  1139. {
  1140. logNet.WriteError("OP60记录插入错误:MES主数据未成功创建,无法插入OP60数据!");
  1141. return new ResponseMessage { result = false, text = "OP60记录插入错误:MES主数据未成功创建,无法插入OP60数据!" };
  1142. }
  1143. //if (lastRecord.OP60_AssemblyStatus != 0 || lastRecord.OP60_ReinspectionImagePath != "" ||
  1144. // lastRecord.OP60_TopCoverStatus != 0 || lastRecord.OP60_TopCoverPressure != 0.0f)
  1145. //{
  1146. // logNet.WriteError("OP50记录插入错误:即将插入的数据存在值不为空,插入失败,请按标准操作!");
  1147. // return new ResponseMessage { result = false, text = "OP50记录插入错误:即将插入的数据存在值不为空,插入失败,请按标准操作!" };
  1148. //}
  1149. lastRecord.OP60_AssemblyStatus = assemblyStatus; // 组装是否到位
  1150. lastRecord.OP60_TopCoverStatus = topCoverStatus; // 上盖板有无
  1151. lastRecord.OP60_TopCoverPressure = topCoverPressure; // 上盖板压合压力
  1152. lastRecord.OP60_ReinspectionImagePath = reinspectionImagePath; // 设备复检图片路径
  1153. Db.Updateable(lastRecord)
  1154. .UpdateColumns(x => new
  1155. {
  1156. x.OP60_AssemblyStatus,
  1157. x.OP60_ReinspectionImagePath,
  1158. x.OP60_TopCoverStatus,
  1159. x.OP60_TopCoverPressure
  1160. }).ExecuteCommand();
  1161. logNet.WriteError("OP60记录插入成功!");
  1162. return new ResponseMessage { result = true, text = "OP60记录插入成功!" };
  1163. }
  1164. catch (Exception ex)
  1165. {
  1166. logNet.WriteError("OP60记录插入出错!错误码:" + ex.Message);
  1167. return new ResponseMessage { result = false, text = "OP60记录插入出错!错误码:" + ex.Message };
  1168. }
  1169. }
  1170. // op701向testdata表格插入数据
  1171. public static ResponseMessage InsertOp701Data(string carrierCode, string productBarcode, string lockTime, string lockOrder, string lockResult, int remainCount)
  1172. {
  1173. // 检查上一次插入的记录是否存在
  1174. //var lastRecord = Db.Queryable<TestData>()
  1175. // .Where(x => x.CarrierCode == CarrierCode && x.ProductBarcode == ProductBarcode && x.OP60_AssemblyStatus != 2 && x.OP60_ReinspectionImagePath != "" &&
  1176. // x.OP60_TopCoverStatus != 2 && x.OP60_TopCoverPressure != 0.0f) // 只查找有效插入的数据
  1177. // .OrderBy(x => x.ID, OrderByType.Desc) // 按照ID降序查找最新记录
  1178. // .Take(1) // 只取一条记录
  1179. // .First(); // 获取第一条记录,若没有则返回null
  1180. //if (lastRecord == null)
  1181. //{
  1182. // logNet.WriteError("OP701错误:OP60插入的记录存在值为空!");
  1183. // return new ResponseMessage { result = false, text = "OP701错误:OP60插入的记录存在值为空!" };
  1184. //}
  1185. try
  1186. {
  1187. var lastRecord = Db.Queryable<TestData>()
  1188. .Where(x => x.CarrierCode == carrierCode)
  1189. .OrderBy(x => x.ID, OrderByType.Desc) // 按照ID降序查找最新记录
  1190. .Take(1) // 只取一条记录
  1191. .First(); // 获取第一条记录,若没有则返回null
  1192. if (lastRecord == null)
  1193. {
  1194. logNet.WriteError("OP701记录插入错误:MES主数据未成功创建,无法插入OP701数据!");
  1195. return new ResponseMessage { result = false, text = "OP701记录插入错误:MES主数据未成功创建,无法插入OP701数据!" };
  1196. }
  1197. //if (lastRecord.OP701_LockTime != "" || lastRecord.OP701_LockOrder != "" || lastRecord.OP701_LockResult != "")
  1198. //{
  1199. // logNet.WriteError("OP701错误:即将插入的数据存在值不为空,插入失败,请按标准操作!");
  1200. // return new ResponseMessage { result = false, text = "OP701错误:即将插入的数据存在值不为空,插入失败,请按标准操作!" };
  1201. //}
  1202. lastRecord.OP701_LockTime = lockTime;
  1203. lastRecord.OP701_LockOrder = lockOrder;
  1204. lastRecord.OP701_LockResult = lockResult;
  1205. lastRecord.OP701_RemainCount = remainCount;
  1206. Db.Updateable(lastRecord)
  1207. .UpdateColumns(x => new
  1208. {
  1209. x.OP701_LockTime,
  1210. x.OP701_LockOrder,
  1211. x.OP701_LockResult,
  1212. x.OP701_RemainCount
  1213. }).ExecuteCommand();
  1214. logNet.WriteError("OP701记录插入成功!");
  1215. return new ResponseMessage { result = true, text = "OP701记录插入成功!" };
  1216. }
  1217. catch (Exception ex)
  1218. {
  1219. logNet.WriteError("OP701记录插入出错!错误码:" + ex.Message);
  1220. return new ResponseMessage { result = false, text = "OP701记录插入出错!错误码:" + ex.Message };
  1221. }
  1222. }
  1223. // op702向testdata表格插入数据
  1224. public static ResponseMessage InsertOp702Data(string carrierCode, string productBarcode, string lockTime, string lockOrder, string lockResult, int remainCount)
  1225. {
  1226. //// 检查上一次插入的记录是否存在
  1227. //var lastRecord = Db.Queryable<TestData>()
  1228. // .Where(x => x.CarrierCode == CarrierCode && x.ProductBarcode == ProductBarcode && x.OP701_TorqueCurveDataPath != "" && x.OP701_ScrewPressure != 0.0f &&
  1229. // x.OP701_Turns != 0 && x.OP701_LockTime != 0 && x.OP701_LockOrder != "" &&
  1230. // x.OP701_LockResult != "") // 只查找有效插入的数据
  1231. // .OrderBy(x => x.ID, OrderByType.Desc) // 按照ID降序查找最新记录
  1232. // .Take(1) // 只取一条记录
  1233. // .First(); // 获取第一条记录,若没有则返回null
  1234. //if (lastRecord == null)
  1235. //{
  1236. // logNet.WriteError("OP702错误:OP701插入的记录存在值为空!");
  1237. // return new ResponseMessage { result = false, text = "OP702错误:OP701插入的记录存在值为空!" };
  1238. //}
  1239. try
  1240. {
  1241. var lastRecord = Db.Queryable<TestData>()
  1242. .Where(x => x.CarrierCode == carrierCode)
  1243. .OrderBy(x => x.ID, OrderByType.Desc) // 按照ID降序查找最新记录
  1244. .Take(1) // 只取一条记录
  1245. .First(); // 获取第一条记录,若没有则返回null
  1246. if (lastRecord == null)
  1247. {
  1248. logNet.WriteError("OP702记录插入错误:MES主数据未成功创建,无法插入OP702数据!");
  1249. return new ResponseMessage { result = false, text = "OP702记录插入错误:MES主数据未成功创建,无法插入OP702数据!" };
  1250. }
  1251. lastRecord.OP702_LockTime = lockTime;
  1252. lastRecord.OP702_LockOrder = lockOrder;
  1253. lastRecord.OP702_LockResult = lockResult;
  1254. lastRecord.OP702_RemainCount = remainCount;
  1255. Db.Updateable(lastRecord)
  1256. .UpdateColumns(x => new
  1257. {
  1258. x.OP702_LockTime,
  1259. x.OP702_LockOrder,
  1260. x.OP702_LockResult,
  1261. x.OP702_RemainCount
  1262. }).ExecuteCommand();
  1263. logNet.WriteError("OP702记录插入成功!");
  1264. return new ResponseMessage { result = true, text = "OP702记录插入成功!" };
  1265. }
  1266. catch (Exception ex)
  1267. {
  1268. logNet.WriteError("OP702记录插入出错!错误码:" + ex.Message);
  1269. return new ResponseMessage { result = false, text = "OP702记录插入出错!错误码:" + ex.Message };
  1270. }
  1271. }
  1272. // op80向testdata表格插入数据
  1273. public static ResponseMessage InsertOp80Data(string carrierCode, string productBarcode, string screwHeights,
  1274. string screwResults)
  1275. {
  1276. try
  1277. {
  1278. var lastRecord = Db.Queryable<TestData>()
  1279. .Where(x => x.CarrierCode == carrierCode)
  1280. .OrderBy(x => x.ID, OrderByType.Desc) // 按照ID降序查找最新记录
  1281. .Take(1) // 只取一条记录
  1282. .First(); // 获取第一条记录,若没有则返回null
  1283. if (lastRecord == null)
  1284. {
  1285. logNet.WriteError("OP80记录插入错误:MES主数据未成功创建,无法插入OP80数据!");
  1286. return new ResponseMessage { result = false, text = "OP80记录插入错误:MES主数据未成功创建,无法插入OP80数据!" };
  1287. }
  1288. lastRecord.OP80_ScrewHeights = screwHeights;
  1289. lastRecord.OP80_ScrewResults = screwResults;
  1290. Db.Updateable(lastRecord)
  1291. .UpdateColumns(x => new
  1292. {
  1293. x.OP80_ScrewHeights,
  1294. x.OP80_ScrewResults
  1295. }).ExecuteCommand();
  1296. logNet.WriteError("OP80记录插入成功!");
  1297. return new ResponseMessage { result = true, text = "OP80记录插入成功!" };
  1298. }
  1299. catch (Exception ex)
  1300. {
  1301. logNet.WriteError("OP80记录插入出错!错误码:" + ex.Message);
  1302. return new ResponseMessage { result = false, text = "OP80记录插入出错!错误码:" + ex.Message };
  1303. }
  1304. }
  1305. // op90向testdata表格插入数据
  1306. public static ResponseMessage InsertOp90Data(string carrierCode, string productBarcode, int throwCount,
  1307. int remainCount)
  1308. {
  1309. try
  1310. {
  1311. var lastRecord = Db.Queryable<TestData>()
  1312. .Where(x => x.CarrierCode == carrierCode)
  1313. .OrderBy(x => x.ID, OrderByType.Desc) // 按照ID降序查找最新记录
  1314. .Take(1) // 只取一条记录
  1315. .First(); // 获取第一条记录,若没有则返回null
  1316. if (lastRecord == null)
  1317. {
  1318. logNet.WriteError("OP90记录插入错误:MES主数据未成功创建,无法插入OP90数据!");
  1319. return new ResponseMessage { result = false, text = "OP90记录插入错误:MES主数据未成功创建,无法插入OP90数据!" };
  1320. }
  1321. lastRecord.OP90_ThrowCount = throwCount;
  1322. lastRecord.OP90_RemainCount = remainCount;
  1323. Db.Updateable(lastRecord)
  1324. .UpdateColumns(x => new
  1325. {
  1326. x.OP80_ScrewHeights,
  1327. x.OP80_ScrewResults
  1328. }).ExecuteCommand();
  1329. logNet.WriteError("OP90记录插入成功!");
  1330. return new ResponseMessage { result = true, text = "OP90记录插入成功!" };
  1331. }
  1332. catch (Exception ex)
  1333. {
  1334. logNet.WriteError("OP80记录插入出错!错误码:" + ex.Message);
  1335. return new ResponseMessage { result = false, text = "OP90记录插入出错!错误码:" + ex.Message };
  1336. }
  1337. }
  1338. #region 实体
  1339. // 定义实体类(对应数据库表)载具绑定表
  1340. public class CarrierBind
  1341. {
  1342. // 主键ID,设置为自增且非空
  1343. [SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
  1344. public int ID { get; set; } // 主键ID
  1345. // 其他列
  1346. public string CarrierCode { get; set; } = ""; // 载具码
  1347. public string ProductBarcode { get; set; } = ""; // 产品码
  1348. public string PCBBarcode { get; set; } = ""; // 产品码
  1349. public DateTime CreateTime { get; set; } = DateTime.Now; // 创建时间
  1350. }
  1351. // 定义ProductBind实体类,表示表格结构
  1352. public class ProductBind
  1353. {
  1354. // 主键ID,设置为自增且非空
  1355. [SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
  1356. public int ID { get; set; } // 主键ID
  1357. // 其他列
  1358. public DateTime CreateTime { get; set; } = DateTime.Now; // 创建时间
  1359. public string CarrierCode { get; set; } = ""; // 载具码
  1360. public string ProductBarcode { get; set; } = ""; // 产品条码
  1361. public string TopCover_Barcode { get; set; } = ""; // 上盖板条码
  1362. public string AddPCB_Barcode { get; set; } = ""; // ADD板条码
  1363. public int BindOrder { get; set; } = 0; // 绑定顺序
  1364. }
  1365. // 定义TestData实体类,表示表格TestData结构
  1366. public class TestData
  1367. {
  1368. // 主键ID,设置为自增且非空
  1369. [SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
  1370. public int ID { get; set; } // 主键ID
  1371. // 其他列
  1372. public DateTime CreateTime { get; set; } = DateTime.Now; // 创建时间
  1373. public string CarrierCode { get; set; } = ""; // 载具码
  1374. public string ProductBarcode { get; set; } = ""; // 产品条码
  1375. public int BindOrder { get; set; } = 0; // 绑定顺序
  1376. //op10
  1377. public int OP10_ThrowingAmount { get; set; } = 0; // 抛料数量 // 清洗功率
  1378. public float OP10_CleaningPressure { get; set; } = 0.0f; // 清洗气压
  1379. public float OP10_CleaningSpeed { get; set; } = 0.0f; // 清洗速度
  1380. public float OP10_AirKnifeHeight { get; set; } = 0.0f; // 风刀高度
  1381. public float OP10_CleaningTime { get; set; } = 0.0f; // 清洗时间
  1382. public int OP10_CleaningCount { get; set; } = 0; // 清洗次数
  1383. public int OP10_RemainCount { get; set; } = 0; // 外壳体余料数
  1384. //op20
  1385. public int OP20_ThrowCount { get; set; } = 0; // 抛料数量
  1386. public int OP20_RemainCount { get; set; } = 0; // 上盖余料数
  1387. //op301
  1388. public float OP301_GluingSpeed { get; set; } = 0.0f; // 供胶速度
  1389. public float OP301_PressureAB { get; set; } = 0.0f; // A管气压
  1390. public float OP301_PressureDifferenceAB { get; set; } = 0.0f; // AB管气压差
  1391. [SqlSugar.SugarColumn(ColumnDataType = "varchar(500)")]
  1392. public string OP301_ProductHeightInfo { get; set; } = ""; // 产品测高信息
  1393. [SqlSugar.SugarColumn(ColumnDataType = "varchar(500)")]
  1394. public string OP301_PeriodicWeightData { get; set; } = ""; // 定期称重数据
  1395. [SqlSugar.SugarColumn(ColumnDataType = "varchar(500)")]
  1396. public string OP301_RemainingGlueAmount { get; set; } = ""; // 剩余胶量
  1397. //op302
  1398. public float OP302_GluingSpeed { get; set; } = 0.0f; // 供胶速度
  1399. public float OP302_PressureAB { get; set; } = 0.0f; // A管气压
  1400. public float OP302_PressureDifferenceAB { get; set; } = 0.0f; // AB管气压差
  1401. [SqlSugar.SugarColumn(ColumnDataType = "varchar(500)")]
  1402. public string OP302_ProductHeightInfo { get; set; } = ""; // 产品测高信息
  1403. [SqlSugar.SugarColumn(ColumnDataType = "varchar(500)")]
  1404. public string OP302_PeriodicWeightData { get; set; } = ""; // 定期称重数据
  1405. [SqlSugar.SugarColumn(ColumnDataType = "varchar(500)")]
  1406. public string OP302_RemainingGlueAmount { get; set; } = ""; // 剩余胶量
  1407. //op40
  1408. [SqlSugar.SugarColumn(ColumnDataType = "varchar(500)")]
  1409. public string OP40_GluePosX { get; set; } = ""; // 胶线位置X偏差
  1410. [SqlSugar.SugarColumn(ColumnDataType = "varchar(500)")]
  1411. public string OP40_GluePosY { get; set; } = ""; // 胶线位置Y偏差
  1412. [SqlSugar.SugarColumn(ColumnDataType = "varchar(500)")]
  1413. public string OP40_GlueLineArea { get; set; } = ""; // 胶线面积
  1414. [SqlSugar.SugarColumn(ColumnDataType = "varchar(500)")]
  1415. public string OP40_GlueLineHeight { get; set; } = ""; // 胶线高度
  1416. public string OP40_Result { get; set; } = ""; // 胶线检测结果 1:OK 非1:NG
  1417. public string OP40_InspectionImagePath { get; set; } = ""; // 检测图片路径
  1418. //op50
  1419. public int OP50_AssemblyStatus { get; set; } = 0; // 组装是否到位
  1420. public string OP50_ReinspectionImagePath { get; set; } = ""; // 设备复检图片路径
  1421. public int OP50_AddBoardStatus { get; set; } = 0; // ADD板有无
  1422. public int OP50_RemainCount { get; set; } = 0; // ADD板余料数
  1423. public float OP50_AddBoardPressure { get; set; } = 0.0f; // ADD板压合压力
  1424. //op60
  1425. public int OP60_AssemblyStatus { get; set; } = 0; // 组装是否到位
  1426. public int OP60_TopCoverStatus { get; set; } = 0; // 上盖板有无
  1427. public float OP60_TopCoverPressure { get; set; } = 0.0f; // 上盖板压合压力
  1428. public string OP60_ReinspectionImagePath { get; set; } = ""; // 设备复检图片路径
  1429. //op701
  1430. [SqlSugar.SugarColumn(ColumnDataType = "varchar(500)")]
  1431. public string OP701_LockTime { get; set; } = ""; // 锁附时间
  1432. [SqlSugar.SugarColumn(ColumnDataType = "varchar(500)")]
  1433. public string OP701_LockOrder { get; set; } = ""; // 锁附顺序
  1434. [SqlSugar.SugarColumn(ColumnDataType = "varchar(500)")]
  1435. public string OP701_LockResult { get; set; } = ""; // 锁附结果
  1436. public int OP701_RemainCount { get; set; } = 0; // 螺丝余料数
  1437. //op702
  1438. [SqlSugar.SugarColumn(ColumnDataType = "varchar(500)")]
  1439. public string OP702_LockTime { get; set; } = ""; // 锁附时间
  1440. [SqlSugar.SugarColumn(ColumnDataType = "varchar(500)")]
  1441. public string OP702_LockOrder { get; set; } = ""; // 锁附顺序
  1442. [SqlSugar.SugarColumn(ColumnDataType = "varchar(500)")]
  1443. public string OP702_LockResult { get; set; } = ""; // 锁附结果
  1444. public int OP702_RemainCount { get; set; } = 0; // 螺丝余料数
  1445. //op80
  1446. [SqlSugar.SugarColumn(ColumnDataType = "varchar(500)")]
  1447. public string OP80_ScrewHeights { get; set; } = ""; // 螺丝高度
  1448. public string OP80_ScrewResults { get; set; } = ""; // 螺丝检测结果
  1449. //op90
  1450. public int OP90_ThrowCount { get; set; } = 0; // 抛料次数
  1451. public int OP90_RemainCount { get; set; } = 0; // 料箱余料数
  1452. }
  1453. #endregion
  1454. }
  1455. }