示例#1
0
        public static bool Update(string deviceID, string parkingid, bool connectState)
        {
            if (deviceID.IsEmpty())
            {
                throw new ArgumentNullException("model");
            }

            IParkDeviceDetection factory = ParkDeviceDetectionFactory.GetFactory();

            return(factory.Update(deviceID, parkingid, connectState));
        }
示例#2
0
        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);
        }
示例#3
0
        public static bool Add(ParkDevice model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            IParkDeviceDetection factoryDetection = ParkDeviceDetectionFactory.GetFactory();

            model.DeviceID = GuidGenerator.GetGuid().ToString();
            IParkDevice factory = ParkDeviceFactory.GetFactory();
            bool        result  = false;

            using (DbOperator dbOperator = ConnectionManager.CreateConnection())
            {
                try
                {
                    dbOperator.BeginTransaction();

                    result = factory.Add(model, dbOperator);
                    if (!result)
                    {
                        throw new MyException("添加设备失败");
                    }
                    if (model.DeviceType == DeviceType.NZ_CONTROL)
                    {
                        int devId = 0;
                        if (!int.TryParse(model.DeviceNo, out devId))
                        {
                            throw new MyException("设备编号只能输入纯数字");
                        }
                        AddDefaultParkDeviceParam(model.GateID, model.DeviceID, model.DeviceNo, dbOperator);
                    }
                    dbOperator.CommitTransaction();
                }
                catch
                {
                    dbOperator.RollbackTransaction();
                    throw;
                }
            }
            if (result)
            {
                OperateLogServices.AddOperateLog <ParkDevice>(model, OperateType.Add);
            }
            return(result);
        }
示例#4
0
        public static bool Delete(string recordId)
        {
            if (string.IsNullOrWhiteSpace(recordId))
            {
                throw new ArgumentNullException("recordId");
            }

            IParkDevice          factory          = ParkDeviceFactory.GetFactory();
            IParkDeviceDetection factoryDetection = ParkDeviceDetectionFactory.GetFactory();
            bool result = false;

            using (DbOperator dbOperator = ConnectionManager.CreateConnection())
            {
                try
                {
                    dbOperator.BeginTransaction();

                    result = factory.Delete(recordId, dbOperator);
                    if (!result)
                    {
                        throw new MyException("删除设备失败");
                    }

                    factoryDetection.Delete(recordId, dbOperator);

                    factory.DeleParam(recordId, dbOperator);

                    dbOperator.CommitTransaction();
                }
                catch
                {
                    dbOperator.RollbackTransaction();
                    throw;
                }
            }
            if (result)
            {
                OperateLogServices.AddOperateLog(OperateType.Delete, string.Format("recordId:{0}", recordId));
            }
            return(result);
        }