コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }