コード例 #1
0
        public IList <Station> queryIdleStation()
        {
            IList <Station> stations = new List <Station>();

            //查询有空闲车的租赁点
            using (DataContext db = new SqlserverContext())
            {
                Table <Station> T_Station  = db.GetTable <Station>();
                Table <Car>     T_Car      = db.GetTable <Car>();
                Table <Piles>   T_Piles    = db.GetTable <Piles>();
                Table <CarStat> T_CarStat  = db.GetTable <CarStat>();
                IList <Station> allStation = T_Station.ToList <Station>();
                if (allStation != null && allStation.Count() > 0)
                {
                    foreach (var i in allStation)
                    {
                        IList <Piles> allPiles = T_Piles.Where <Piles>(o => o.StationID == i.id).ToList <Piles>();
                        if (allPiles != null && allPiles.Count() > 0)
                        {
                            foreach (var m in allPiles)
                            {
                                CarStat stat = T_CarStat.Where <CarStat>(o => o.PilesID == m.id).OrderByDescending(x => x.CreateTime).First();
                                if (stat != null && stat.stat == (int)Commons.CatStatus.idle)
                                {
                                    stations.Add(i);
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            return(stations);
        }
コード例 #2
0
        //订单撤销
        //return  true:成功  false:失败
        public bool cancelOrder(string orderid)
        {
            if (!String.IsNullOrWhiteSpace(orderid))
            {
                using (DataContext db = new SqlserverContext())
                {
                    Table <Order>             T_order      = db.GetTable <Order>();
                    Table <OrderLog>          T_orderLog   = db.GetTable <OrderLog>();
                    Table <CarStat>           carStatTable = db.GetTable <CarStat>();
                    IEnumerable <OrderLog>    orders       = T_orderLog.Where <OrderLog>(o => o.OrderID.Equals(orderid));
                    IList <UserAuthorization> list         = null;
                    Table <UserAuthorization> AuthTable    = db.GetTable <UserAuthorization>();
                    if (orders != null && orders.Count() > 0)
                    {
                        return(false);
                    }
                    //如果当前时间可以取消,修改该订单状态
                    Order order = T_order.FirstOrDefault <Order>(x => x.ID.Equals(orderid));
                    // DateTime t1 = DateTime.ParseExact(order.Time,"yyyy-MM-dd HH:mm:ss",System.Globalization.CultureInfo.CurrentCulture);
                    if (order != null && order.State == (int)Commons.Type.BOOK)
                    {//在订单状态为预约状态,车状态为预定状态,可以取消订单
                        CarStat carStat = (from m in carStatTable where m.CarID == order.CarID orderby m.CreateTime descending select m).FirstOrDefault();
                        if (carStat.stat == (int)Commons.CatStatus.book)
                        {
                            order.State = (int)Commons.Type.CANCEL;
                            CarStat stat = new CarStat();
                            stat.id         = Guid.NewGuid().ToString().Replace("-", "");
                            stat.stat       = (int)Commons.CatStatus.idle;
                            stat.UserID     = order.UserID;
                            stat.CarID      = order.CarID;
                            stat.PilesID    = carStat.PilesID;
                            stat.CreateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

                            carStatTable.InsertOnSubmit(stat);

                            //收回授权状态
                            list = (from c in AuthTable
                                    where c.OrderId.Equals(orderid) &&
                                    c.Status == (int)Commons.Authorized.AUTHORIZE
                                    select c).ToList();
                            foreach (UserAuthorization item in list)
                            {
                                item.Status = (int)Commons.Authorized.UNAUTHORIZE;
                            }
                            db.SubmitChanges();
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
コード例 #3
0
        public CarStat findCarStat(string userId, string carId)
        {
            using (DataContext db = new SqlserverContext())
            {
                Table <CarStat> T_CarStat = db.GetTable <CarStat>();
                CarStat         carstat   = T_CarStat.FirstOrDefault <CarStat>(o => o.UserID.Equals(userId) && o.CarID.Equals(carId) && o.stat == (int)Commons.CatStatus.idle);
                if (carstat != null)
                {
                    return(carstat);
                }
            }

            return(null);
        }
コード例 #4
0
        public Station queryLocation(string carId, string userId)
        {
            //根据车id查询租赁点位置
            //1.找到充电桩
            //2.找到租赁点
            CarStat carstat = zsc_manager.findCarStat(carId, userId);

            if (carstat != null)
            {
                return(zsc_manager.findStaByPileId(carstat.PilesID.ToString()));;
            }

            return(null);
        }
コード例 #5
0
        public CarStat addCarStat(OrderLog order)
        {
            LogerHelper.DefaultInfo("addCarStat:" + order.OrderID);
            //增加车状态
            using (DataContext db = new SqlserverContext())
            {
                Table <CarStat> T_PILE = db.GetTable <CarStat>();
                CarStat         stat   = new CarStat();

                CarStat c = (from m in T_PILE where m.CarID == order.CarID select m).FirstOrDefault();
                stat.id         = Guid.NewGuid().ToString().Replace("-", "");
                stat.stat       = (int)Commons.CatStatus.idle;
                stat.UserID     = order.UserID;
                stat.CarID      = order.CarID;
                stat.PilesID    = c.PilesID;
                stat.CreateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                T_PILE.InsertOnSubmit(stat);
                db.SubmitChanges();
                LogerHelper.debug("还车 Add CarStat 成功!");
                return(stat);
            }
        }