protected void Page_Load(object sender, EventArgs e) { UserService us = new UserService(); int id = (int) Session["id"]; user u = new user(); u.user_id = id; u = us.getUserById(u); order orderInDb = (order) Session["paidTicket"]; if (orderInDb == null) { Server.Transfer("payment.aspx"); } this.payment.Value = orderInDb.payment.ToString(); this.plane_name.Value = orderInDb.flight.flight_name; this.city_from.Value = orderInDb.flight.air_line.city_from; this.city_to.Value = orderInDb.flight.air_line.city_to; this.departure_time.Value = orderInDb.flight.air_line.schedule_departure.ToString("c"); this.arrival_time.Value = orderInDb.flight.air_line.schedule_arrival.ToString("c"); this.flight_date.Value = orderInDb.flight.arrival_date.ToString("d"); this.user_name.Value = u.user_name; this.card_id.Value = u.id_card_NO; this.phone.Value = u.phone; }
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; }
public user login(user u) { user uInDb = this.getUserByEmail(u); if (u.password == uInDb.password) return uInDb; else return uInDb; }
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!"); } }
public user getUserById(user u) { var ls = from a in userDAO.FindAll() where a.user_id == u.user_id select a; IEnumerable<user> uInDbList = ls; if (uInDbList.ToList().Count > 0) return uInDbList.First(); return null; }
public user register(user u) { var ls = from a in userDAO.FindAll() where a.email == u.email select a; IEnumerable<user> uInDbList = ls; if (uInDbList.ToList().Count > 0) return null; else userDAO.Insert(u); return uInDbList.FirstOrDefault<user>(); }
protected void Page_Load(object sender, EventArgs e) { if (Session["id"] == null) { var response = base.Response; response.Redirect("login.aspx"); } UserService us = new UserService(); user u = new user(); u.user_id = (int)Session["id"]; u = us.getUserById(u); uInDb = u; }
protected void submit_ServerClick(object sender, EventArgs e) { user u = new user(); u.user_id = (int)Session["id"]; u = os.getUserById(u); if (u == null) return; if (!os.pay(u, oInDb)) { ShowPopUpMsg("not enough money"); } else { Server.Transfer("payment-success.aspx"); Session["paidTicket"] = oInDb; } }
protected void loginOnclick(object sender, EventArgs e) { user u = new user(); u.email = this.email.Value; u.password = this.pw.Value; UserService us = new UserService(); if ((u = us.login(u)) != null) { Session["id"] = u.user_id; Server.Transfer("index.aspx"); } else { ShowPopUpMsg("Email or password not right"); } }
protected void Page_Load(object sender, EventArgs e) { if (Session["id"] == null) { var response = base.Response; response.Redirect("login.aspx"); } user u = new user(); u.user_id = (int)Session["id"]; OrderService os = new OrderService(); u = os.getUserById(u); this.email.Value = u.email; this.phone.Value = u.phone; this.mile.Value = u.mileage.ToString(); this.idcard.Value= u.id_card_NO; this.credit.Value = u.credit.ToString(); this.Name.Value = u.user_name; }
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; }
protected void register_ServerClick(object sender, EventArgs e) { user u = new user(); u.email = this.email.Value; u.password = this.pw2.Value; u.phone = this.phone.Value; u.id_card_NO = this.idcard.Value; u.user_name = this.Name.Value; u.credit = 0; u.mileage = 0; u.balance = 0; u.user_level = 0; UserService us = new UserService(); u = us.register(u); if (u == null) this.Page_Load(sender,e); else { Session["id"] = u.user_id; Server.Transfer("index.aspx"); } }
protected void registerOnclick(object sender, EventArgs e) { user userRegister = new user(); userRegister.email = this.EmailBox.Text.Trim(); userRegister.password = this.PasswordBox.Text.Trim(); userRegister.phone = this.PhoneBox.Text.Trim(); userRegister.id_card_NO = this.IdCardBox.Text.Trim(); userRegister.user_name = this.NameBox.Text.Trim(); UserService uService = new UserService(); String result = ""; if(result == "exists") { this.regResult.Text = "Email already exsists!!!"; } else { user uInDB = uService.getUserByEmail(userRegister); Session["UserId"] = uInDB.user_id; this.regResult.Text = "Success!"; } }
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; }
public user getUserById(user u) { var ls = from a in userDAO.FindAll() where a.user_id == u.user_id select a; return ls.FirstOrDefault<user>(); }
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; }