SQLHelper.cs 76 KB

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