Esempio n. 1
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);
        }
Esempio n. 2
0
        public static bool UpdateParam(ParkDeviceParam model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }
            IParkDevice factory = ParkDeviceFactory.GetFactory();

            ParkDeviceParam deviceParam = factory.QueryParkDeviceParamByDevID(model.DevID);

            if (deviceParam != null && deviceParam.DeviceID != model.DeviceID)
            {
                throw new MyException("设备编号不能重复");
            }

            bool result = false;

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

                    result = factory.UpdateParam(model, dbOperator);
                    if (!result)
                    {
                        throw new MyException("修改设备参数失败");
                    }
                    dbOperator.CommitTransaction();
                }
                catch
                {
                    dbOperator.RollbackTransaction();
                    throw;
                }
            }
            if (result)
            {
                OperateLogServices.AddOperateLog <ParkDeviceParam>(model, OperateType.Add);
            }
            return(result);
        }