123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- using DBHelper;
- using Microsoft.EntityFrameworkCore;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Linq.Dynamic.Core;
- using System.Reflection;
- using System.Text;
- using System.Threading.Tasks;
- using WCS.Core;
- using WCS.Entity;
- namespace WCS.Service
- {
- public class ProtocolProxy : ProtocolProxyBase
- {
- MethodInfo SetMethod;
- public ProtocolProxy(string id, WCS_DATABLOCK db, ushort start, WCS_DEVICEPROTOCOL protocol) : base(id, db, start, protocol)
- {
- SetMethod = typeof(DbContext).GetMethod("Set", new Type[] { }).MakeGenericMethod(this.ProtocolDataType);
- }
-
- protected override WCS_PROTOCOLDATA GetLastData()
- {
- return DB.Do(db =>
- {
-
- dynamic q= SetMethod.Invoke(db.Default, null);
- try
- {
- q = DynamicQueryableExtensions.Where(q, "ISLAST==@0 && DEVICE.CODE==@1", true, PROTOCOL.DEVICE.CODE);
- var res = Enumerable.FirstOrDefault(q);
- return res;
- }
- catch (Exception ex)
- {
- throw;
- }
- });
- }
- protected override WCS_PROTOCOLDATA SaveNewData(WCS_PROTOCOLDATA last, WCS_PROTOCOLDATA newobj,string user)
- {
- return DB.Do(db =>
- {
- if (last != null)
- {
- db.Default.Attach(last);
- last.ISLAST = false;
- }
- db.Default.Attach(PROTOCOL.DEVICE);
- newobj.DEVICE = PROTOCOL.DEVICE;
- newobj.ISLAST = true;
- newobj.UPDATETIME = DateTime.Now;
- newobj.UPDATEUSER = user;
- newobj.FRAME = LogicHandler.Frame;
- db.Default.Add(newobj);
- db.Default.SaveChanges();
- return newobj;
- });
-
- }
- }
- }
|