SQLHelper.cs 78 KB

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