protected void next_ServerClick(object sender, EventArgs e)
        {
            user u = new user();
            u.user_id = (int)Session["id"];
            u = os.getUserById(u);
            int seat_num = (int)Session["seat_num"];

            o.SSR = this.SSR.Value ;
            o.type = type;

            FlightService fs = new FlightService();
            String plane_type_name = searchF.plane.plane_type.name;
            BitArray seat = new BitArray(20);
            seat.SetAll(false);
            seat.Set(seat_num,true);
            o.seat = OrderService.BitArrayToByteArray(seat);

            if ( (o = os.generate(u, searchF, o, seat_num)) != null)
            {
                Session["new_order"] = o;
                Server.Transfer("payment.aspx");
            }
            else
            {
                ShowPopUpMsg("Seat is book by others!");
            }
        }
Beispiel #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["id"] == null)
            {
                var response = base.Response;
                response.Redirect("login.aspx");
            }

            searchF = (flight)Session["searchFlight"];
            type = (String)Session["type"];
            seat_num = (int)Session["seat_num"];
            oInDb = (order)Session["new_order"];

            if (oInDb == null) return;

            user u = new user();
            u.user_id = (int)Session["id"];
            u = os.getUserById(u);
            oInDb.user = u;
            flight f = new flight();
            f.flight_id = oInDb.flight_id;
            f= new FlightService().getFlightById(f);
            oInDb.flight = f;
            this.flight_date.Value = oInDb.flight.arrival_date.ToString("d");
            this.flight_name.Value = oInDb.flight.flight_name;
            this.city_from.Value = searchF.air_line.city_from;
            this.city_to.Value = searchF.air_line.city_to;
            this.user_name.Value = oInDb.user.user_name;
            this.price.Value = oInDb.payment.ToString();
            this.user_balance.Value = oInDb.user.balance.ToString();
            Session["new_order"] = oInDb;
        }
Beispiel #3
0
        public order cancel(user u , order o)
        {
            //更新积分 , 退款 , 退里程
            mutex.WaitOne();

            using (var context = orderDAO.getContext())
            {
                using (var dbContextTransaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        BitArray seat = new BitArray(o.seat);
                        int seat_num = 0;
                        for(int i = 0 ; i < seat.Length ; i++) {
                            if(seat.Get(i) == true)
                                seat_num = i;
                        }

                        flight fInDB = getFlightById(o.flight_id);
                        fInDB = setSeat(fInDB,o,seat_num,false);
                        u.balance += o.payment;
                        u.mileage -= o.flight.air_line.mile;
                        u.credit -= (int)o.payment;
                        if (u.mileage < 10000) u.user_level = 0;
                        o.status = "cancel";
                        userDAO.Update(u);
                        o = orderDAO.Update(o);
                        flightDAO.Update(fInDB);
                        context.SaveChanges();
                        dbContextTransaction.Commit();

                    }
                    catch (Exception)
                    {
                        dbContextTransaction.Rollback();
                    }
                }
            }
            mutex.ReleaseMutex();
            return o;
        }
Beispiel #4
0
        private static flight setSeat(flight f, order o, int seat_num , bool value)
        {
            BitArray deluxe = new BitArray(f.available_deluxe_seats);
            BitArray business = new BitArray(f.available_business_seats);
            BitArray economy = new BitArray(f.available_economy_seats);
            switch (o.type)
            {
                case "deluxe":
                    //seat with seatNum is set to 1 if it is available
                    deluxe.Set(seat_num, value);
                    f.available_deluxe_seats = BitArrayToByteArray(deluxe);
                    o.payment = f.deluxe_fee * f.discount;
                    break;
                case "business":
                    business.Set(seat_num, value);
                    f.available_business_seats = BitArrayToByteArray(business);
                    o.payment = f.business_fee * f.discount;
                    break;
                case "economy":
                    economy.Set(seat_num, value);
                    f.available_economy_seats = BitArrayToByteArray(economy);
                    o.payment = f.econmy_fee * f.discount;
                    break;
            }

            return f;
        }
Beispiel #5
0
 private static bool hasSeat(flight f, order o , int seat_num)
 {
     BitArray deluxe = new BitArray(f.available_deluxe_seats);
     BitArray business = new BitArray(f.available_business_seats);
     BitArray economy = new BitArray(f.available_economy_seats);
     BitArray order_seat = new BitArray(o.seat);
     bool hasSeat = false;
     switch (o.type)
     {
         case "deluxe":
             //seat with seatNum is set to 1 if it is available
             if (deluxe.Get(seat_num) == true) hasSeat = true;
             break;
         case "business":
             if (business.Get(seat_num) == true) hasSeat = true;
             break;
         case "economy":
             if (economy.Get(seat_num) == true) hasSeat = true;
             break;
     }
     return hasSeat;
 }
Beispiel #6
0
 public bool pay(user u ,order o)
 {
     bool paid = false ;
     using (var userContext = userDAO.getContext())
     {
         using (var context = orderDAO.getContext())
         {
             using (var dbContextTransaction = context.Database.BeginTransaction())
             {
                 try
                 {
                     if (u.balance <= o.payment)
                     {
                         throw new Exception();
                     }
                     u.balance -= o.payment;
                     u.mileage += o.flight.air_line.mile;
                     u.credit += (int)o.payment;
                     if (u.mileage > 10000) u.user_level = 1;
                     o.status = "paid";
                     userDAO.Update(u);
                     orderDAO.Update(o);
                     dbContextTransaction.Commit();
                     paid = true;
                 }
                 catch (Exception)
                 {
                     dbContextTransaction.Rollback();
                 }
                 context.SaveChanges();
             }
             userContext.SaveChanges();
         }
     }
     return paid;
 }
Beispiel #7
0
        public order generate(user u, flight f, order o ,int seat_num)
        {
            o.flight_id = f.flight_id;
            u = this.getUserById(u);
            //o.user = u;
            o.user_id = u.user_id;
            o.status = "paid";

            o.PNR = CalculateMD5Hash(u.user_name + seat_num + f.flight_id + DateTime.Now.Date) ;
            mutex.WaitOne();
            if (hasSeat(f, o))
            {
                using (var context = orderDAO.getContext())
                {
                    using (var dbContextTransaction = context.Database.BeginTransaction())
                    {
                        try
                        {
                            flight fInDB = getFlightById(f.flight_id);
                            //o.flight = fInDB;

                            if (fInDB == null) throw new Exception() ;

                            bool buy = true;
                            flight newF = setSeat(fInDB,o,seat_num,buy);
                            flightDAO.Update(newF);
                            if (u.user_level == 1) o.payment = o.payment * (decimal)0.95;
                            o = orderDAO.Insert(o);
                            context.SaveChanges();
                            dbContextTransaction.Commit();
                        }
                        catch (Exception)
                        {
                            dbContextTransaction.Rollback();
                        }
                    }
                }
            }
            mutex.ReleaseMutex();

            //
            return o;
        }