public JsonResult GetParkDeviceParam(string deviceId) { try { ParkDevice device = ParkDeviceServices.QueryParkDeviceByRecordId(deviceId); if (device == null) { throw new MyException("获取设备失败"); } if (device.DeviceType != DeviceType.NZ_CONTROL) { throw new MyException("设备类型不正确"); } ParkDeviceParam deviceParam = ParkDeviceServices.QueryParkDeviceParamByDID(deviceId); return(Json(MyResult.Success("获取成功", deviceParam))); } catch (MyException ex) { return(Json(MyResult.Error(ex.Message))); } catch (Exception ex) { ExceptionsServices.AddExceptions(ex, "删除设备信息失败"); return(Json(MyResult.Error("删除设备信息失败"))); } }
private static ParkDeviceParam CreateDefualtParam(string DeviceID, int DeviceNo, int CarbitNum, int Iostate) { ParkDeviceParam model = new ParkDeviceParam(); model.RecordID = GuidGenerator.GetGuid().ToString(); model.VipMode = 1; model.TempMode = 1; model.NetOffMode = 1; model.VipDevMultIn = 1; model.PloicFree = 1; model.VipDutyDay = 7; model.OverDutyYorN = 1; model.OverDutyDay = 0; model.SysID = 1; model.DevID = DeviceNo; model.SysInDev = 1; model.SysOutDev = 1; model.SysParkNumber = CarbitNum; model.SwipeInterval = 10; model.UnKonwCardType = 1; model.LEDNumber = 4; model.DevInorOut = Iostate - 1; model.DeviceID = DeviceID; return(model); }
public static bool Update(ParkDevice model) { if (model == null) { throw new ArgumentNullException("model"); } IParkDevice factory = ParkDeviceFactory.GetFactory(); IParkDeviceDetection factoryDetection = ParkDeviceDetectionFactory.GetFactory(); bool result = false; using (DbOperator dbOperator = ConnectionManager.CreateConnection()) { try { dbOperator.BeginTransaction(); result = factory.Update(model, dbOperator); if (!result) { throw new MyException("修改设备失败"); } if (model.DeviceType == DeviceType.NZ_CONTROL) { ParkDeviceParam deviceParam = factory.QueryParkDeviceParamByDID(model.DeviceID); if (deviceParam == null) { AddDefaultParkDeviceParam(model.GateID, model.DeviceID, model.DeviceNo, dbOperator); } else { factory.UpdateParam(model.DeviceID, model.DeviceNo, dbOperator); } } dbOperator.CommitTransaction(); } catch { dbOperator.RollbackTransaction(); throw; } } if (result) { OperateLogServices.AddOperateLog <ParkDevice>(model, OperateType.Update); } return(result); }
public static bool AddParam(ParkDeviceParam model) { if (model == null) { throw new ArgumentNullException("model"); } model.RecordID = GuidGenerator.GetGuid().ToString(); IParkDevice factory = ParkDeviceFactory.GetFactory(); ParkDeviceParam deviceParam = factory.QueryParkDeviceParamByDevID(model.DevID); if (deviceParam != null) { throw new MyException("设备编号不能重复"); } bool result = false; using (DbOperator dbOperator = ConnectionManager.CreateConnection()) { try { dbOperator.BeginTransaction(); result = factory.AddParam(model, dbOperator); if (!result) { throw new MyException("添加设备参数失败"); } dbOperator.CommitTransaction(); } catch { dbOperator.RollbackTransaction(); throw; } } if (result) { OperateLogServices.AddOperateLog <ParkDeviceParam>(model, OperateType.Add); } return(result); }
public JsonResult SaveParkDeviceParam(ParkDeviceParam model) { try { bool result = ParkDeviceServices.UpdateParam(model); if (!result) { throw new MyException("保存设备参数失败!"); } return(Json(MyResult.Success())); } catch (MyException ex) { return(Json(MyResult.Error(ex.Message))); } catch (Exception ex) { ExceptionsServices.AddExceptions(ex, "保存设备参数失败"); return(Json(MyResult.Error("保存设备参数失败"))); } }
private static bool AddDefaultParkDeviceParam(string gateId, string deviceId, string deviceNo, DbOperator dbOperator) { ParkGate gate = ParkGateServices.QueryByRecordId(gateId); ParkBox box = ParkBoxServices.QueryByRecordId(gate.BoxID); ParkArea area = ParkAreaServices.QueryByRecordId(box.AreaID); ParkDeviceParam param = CreateDefualtParam(deviceId, int.Parse(deviceNo), area.CarbitNum, (int)gate.IoState); IParkDevice factory = ParkDeviceFactory.GetFactory(); ParkDeviceParam deviceParam = factory.QueryParkDeviceParamByDevID(param.DevID); if (deviceParam != null) { throw new MyException("设备编号不能重复"); } bool result = factory.AddParam(param, dbOperator); if (!result) { throw new MyException("添加设备默认参数失败"); } return(result); }
/// <summary> /// 修改设备参数 /// </summary> /// <param name="model"></param> /// <param name="dbOperator"></param> /// <returns></returns> public bool UpdateParam(ParkDeviceParam model, DbOperator dbOperator) { model.DataStatus = (int)DataStatus.Normal; model.LastUpdateTime = DateTime.Now; model.HaveUpdate = SystemDefaultConfig.DataUpdateFlag; StringBuilder strSql = new StringBuilder(); strSql.Append("update ParkDeviceParam set DeviceID=@DeviceID,VipMode=@VipMode,TempMode=@TempMode,NetOffMode=@NetOffMode,VipDevMultIn=@VipDevMultIn,PloicFree=@PloicFree,VipDutyDay=@VipDutyDay,OverDutyYorN=@OverDutyYorN,OverDutyDay=@OverDutyDay,SysID=@SysID,"); strSql.Append(" DevID=@DevID,SysInDev=@SysInDev,SysOutDev=@SysOutDev,SysParkNumber=@SysParkNumber,DevInorOut=@DevInorOut,SwipeInterval=@SwipeInterval,UnKonwCardType=@UnKonwCardType,LEDNumber=@LEDNumber,DataStatus=@DataStatus,LastUpdateTime=@LastUpdateTime,HaveUpdate=@HaveUpdate "); strSql.Append(" where RecordID=@RecordID"); dbOperator.ClearParameters(); dbOperator.AddParameter("RecordID", model.RecordID); dbOperator.AddParameter("DeviceID", model.DeviceID); dbOperator.AddParameter("VipMode", model.VipMode); dbOperator.AddParameter("TempMode", model.TempMode); dbOperator.AddParameter("NetOffMode", model.NetOffMode); dbOperator.AddParameter("VipDevMultIn", model.VipDevMultIn); dbOperator.AddParameter("PloicFree", model.PloicFree); dbOperator.AddParameter("VipDutyDay", model.VipDutyDay); dbOperator.AddParameter("OverDutyYorN", model.OverDutyYorN); dbOperator.AddParameter("OverDutyDay", model.OverDutyDay); dbOperator.AddParameter("SysID", model.SysID); dbOperator.AddParameter("DevID", model.DevID); dbOperator.AddParameter("SysInDev", model.SysInDev); dbOperator.AddParameter("SysOutDev", model.SysOutDev); dbOperator.AddParameter("SysParkNumber", model.SysParkNumber); dbOperator.AddParameter("DevInorOut", model.DevInorOut); dbOperator.AddParameter("SwipeInterval", (int)model.SwipeInterval); dbOperator.AddParameter("UnKonwCardType", model.UnKonwCardType); dbOperator.AddParameter("LEDNumber", model.LEDNumber); dbOperator.AddParameter("DataStatus", model.DataStatus); dbOperator.AddParameter("LastUpdateTime", model.LastUpdateTime); dbOperator.AddParameter("HaveUpdate", model.HaveUpdate); return(dbOperator.ExecuteNonQuery(strSql.ToString()) > 0); }