using CompressorXN_Log; using CompressorXN_Model; using CompressorXN_Model.ViewModel.Response; using System; namespace CompressorXN_Service { /// /// 通讯协议报文 /// public class AgreementMsgService : DbContext { /// /// 根据机型名称查询通讯协议信息 /// /// /// public AgreementMsgVM GetAgreementMsgByProductTypeName(string productTypeName) { try { AgreementMsgVM agreementMsgVM = new AgreementMsgVM { ReciveDetailRules = new T_Agreement_Detail_Rule() }; agreementMsgVM = db.Queryable() .InnerJoin((a, b) => a.AgreementName == b.AgreementName) .InnerJoin((a, b, c) => a.ProductTypeName == c.ProductTypeName) .Where((a, b, c) => a.ProductTypeName == productTypeName) .Select((a, b, c) => new AgreementMsgVM { ProductTypeName = a.ProductTypeName, AgreementName = a.AgreementName, StartType = a.StartType, MsgFormat = b.MsgFormat, FrameType = b.FrameType, Bps = b.Bps, SendPeriod = b.SendPeriod, SendId = b.SendId, FrameLen = b.FrameLen, RecivePeriod = b.RecivePeriod, ReciveId = b.ReciveId, ReciveSignalVal = b.ReciveSignalVal, IdlingSpeed = c.IdlingSpeed, IdlingHex = c.IdlingHex, Speed1 = c.Speed1, Speed1Hex = c.Speed1Hex, Speed2 = c.Speed2, Speed2Hex = c.Speed2Hex, Speed3 = c.Speed3, Speed3Hex = c.Speed3Hex, EndoleadSpeed = c.EndoleadSpeed, EndoleadHex = c.EndoleadHex, SingleDriverSpeed = c.SingleDriverSpeed, SingleDriverHex = c.SingleDriverHex }).First(); agreementMsgVM.ReciveDetailRules = db.Queryable().First(m => m.AgreementName == agreementMsgVM.AgreementName && m.MsgType == "recive"); agreementMsgVM.SendAdditionalRules = db.Queryable().First(m => m.AgreementName == agreementMsgVM.AgreementName); return agreementMsgVM; } catch (Exception ex) { LogHelper.Error(ex, "执行AgreementMsgService下GetAgreementMsgByProductTypeName时异常"); return null; } } /// /// 保存通讯协议 /// /// /// 机型名称 /// public bool SaveAgreementMsg(T_Agreement_Msg t_Agreement_Msg, string productTypeName) { try { db.Ado.BeginTran(); db.Deleteable().Where(m => m.ProductTypeName == productTypeName).ExecuteCommand(); db.Insertable(t_Agreement_Msg).ExecuteCommand(); db.Ado.CommitTran(); return true; } catch (Exception ex) { db.Ado.RollbackTran(); LogHelper.Error(ex, "执行AgreementMsgService下SaveAgreementMsg时异常"); return false; } } } }