Exemplo n.º 1
0
        public static bool Add(BaseEmployee employee, EmployeePlate plate, BaseCard card, ParkGrant parkGrant, DbOperator dbOperator)
        {
            if (employee == null)
            {
                throw new ArgumentNullException("employee");
            }
            if (plate == null)
            {
                throw new ArgumentNullException("plate");
            }
            if (card == null)
            {
                throw new ArgumentNullException("card");
            }
            if (parkGrant == null)
            {
                throw new ArgumentNullException("parkGrant");
            }

            bool result = BaseEmployeeServices.AddOrUpdateBaseEmployee(employee, dbOperator);

            if (!result)
            {
                throw new MyException("保存人员信息失败");
            }

            result = BaseCardServices.AddOrUpdateCard(card, dbOperator);
            if (!result)
            {
                throw new MyException("保存卡信息失败");
            }

            result = EmployeePlateServices.AddOrUpdateEmployeePlate(plate, dbOperator);
            if (!result)
            {
                throw new MyException("保存车牌信息失败");
            }

            parkGrant.PlateID = plate.PlateID;
            parkGrant.CardID  = card.CardID;
            result            = AddOrderUpdateParkGrant(parkGrant, dbOperator);
            if (!result)
            {
                throw new MyException("保存授权失败");
            }
            if (result)
            {
                OperateLogServices.AddOperateLog <BaseEmployee>(employee, OperateType.Add);
                OperateLogServices.AddOperateLog <EmployeePlate>(plate, OperateType.Add);
                OperateLogServices.AddOperateLog <BaseCard>(card, OperateType.Add);
                OperateLogServices.AddOperateLog <ParkGrant>(parkGrant, OperateType.Add);
            }
            return(result);
        }
Exemplo n.º 2
0
        public static bool DAAdd(List <DAAddMonth> listmonth)
        {
            if (listmonth.Count == 0)
            {
                throw new ArgumentNullException("employee");
            }
            using (DbOperator dbOperator = ConnectionManager.CreateConnection())
            {
                dbOperator.BeginTransaction();
                try
                {
                    foreach (var obj in listmonth)
                    {
                        bool result = BaseEmployeeServices.AddOrUpdateBaseEmployee(obj.employye, dbOperator);
                        if (!result)
                        {
                            throw new MyException("保存人员信息失败");
                        }

                        result = BaseCardServices.AddOrUpdateCard(obj.card, dbOperator);
                        if (!result)
                        {
                            throw new MyException("保存卡信息失败");
                        }

                        result = EmployeePlateServices.AddOrUpdateEmployeePlate(obj.plate, dbOperator);
                        if (!result)
                        {
                            throw new MyException("保存车牌信息失败");
                        }

                        obj.grant.PlateID = obj.plate.PlateID;
                        obj.grant.CardID  = obj.card.CardID;
                        result            = AddOrderUpdateParkGrant(obj.grant, dbOperator);
                        if (!result)
                        {
                            throw new MyException("保存授权失败");
                        }
                        dbOperator.CommitTransaction();
                    }

                    return(true);
                }
                catch
                {
                    dbOperator.RollbackTransaction();
                    throw;
                }
            }
        }