Beispiel #1
0
        public static bool AddOrUpdateIOTime(List <ParkGateIOTime> list)
        {
            if (list == null || list.Count == 0)
            {
                throw new ArgumentNullException("list");
            }

            IParkGate             factory      = ParkGateFactory.GetFactory();
            List <ParkGateIOTime> models       = factory.QueryGateIOTime(list.First().GateID);
            List <ParkGateIOTime> updateModels = new List <ParkGateIOTime>();
            List <ParkGateIOTime> addModels    = new List <ParkGateIOTime>();

            using (DbOperator dbOperator = ConnectionManager.CreateConnection())
            {
                try
                {
                    dbOperator.BeginTransaction();
                    foreach (var item in list)
                    {
                        ParkGateIOTime model = models.FirstOrDefault(p => p.RuleType == 0 && p.WeekIndex == item.WeekIndex);
                        if (model != null)
                        {
                            model.StartTime  = item.StartTime;
                            model.EndTime    = item.EndTime;
                            model.InOutState = item.InOutState;
                            bool result = factory.UpdateIOTime(model, dbOperator);
                            if (!result)
                            {
                                throw new MyException("修改星期规则失败");
                            }
                            updateModels.Add(model);
                        }
                        else
                        {
                            item.RecordID = GuidGenerator.GetGuid().ToString();
                            bool result = factory.AddIOTime(item, dbOperator);
                            if (!result)
                            {
                                throw new MyException("添加星期规则失败");
                            }
                            addModels.Add(item);
                        }
                    }
                    dbOperator.CommitTransaction();
                }
                catch {
                    dbOperator.RollbackTransaction();
                    throw;
                }
            }
            if (updateModels.Count > 0)
            {
                OperateLogServices.AddOperateLog <List <ParkGateIOTime> >(updateModels, OperateType.Update);
            }
            if (addModels.Count > 0)
            {
                OperateLogServices.AddOperateLog <List <ParkGateIOTime> >(addModels, OperateType.Add);
            }
            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// 根据通道获取进出规则
        /// </summary>
        /// <param name="gateId"></param>
        /// <returns></returns>
        public static List <ParkGateIOTime> QueryGateIOTime(string gateId)
        {
            if (string.IsNullOrWhiteSpace(gateId))
            {
                throw new ArgumentNullException("gateId");
            }

            IParkGate factory = ParkGateFactory.GetFactory();

            return(factory.QueryGateIOTime(gateId));
        }