SQLHelper.cs 79 KB

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