Beispiel #1
0
 protected void grid1_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     if (e.CommandName.Equals("canceled"))
     {
         int            index   = int.Parse(e.CommandArgument.ToString());
         GridViewRow    gr      = (GridViewRow)((Button)e.CommandSource).NamingContainer;
         int            user_id = int.Parse(((HiddenField)gr.FindControl("booking_id")).Value.ToString());
         bus_dbEntities db      = new bus_dbEntities();
         tbl_booking    login   = (from x in db.tbl_booking where x.booking_id == user_id select x).ToList()[0];
         db.tbl_booking.Remove(login);
         //Save to database
         db.SaveChanges();
         var lgs = (from x in db.tbl_booking
                    join y in db.tbl_schedule on x.fk_schedule equals y.schedule_id
                    join b in db.tbl_bus on y.fk_bus equals b.bus_id
                    join r in db.tbl_route on y.fk_route equals r.route_id
                    join s in db.tbl_station on r.route_source equals s.station_id
                    join d in db.tbl_station on r.route_destination equals d.station_id
                    where x.booking_id == user_id
                    select new { x.booking_id, x.booking_datetime, x.booking_seatno, b.bus_name, source = s.station_name, destination = d.station_name }).ToList();
         grid1.DataSource = lgs;
         grid1.DataBind();
     }
     else if (e.CommandName.Equals("print"))
     {
         int         index   = int.Parse(e.CommandArgument.ToString());
         GridViewRow gr      = (GridViewRow)((Button)e.CommandSource).NamingContainer;
         int         user_id = int.Parse(((HiddenField)gr.FindControl("booking_id")).Value.ToString());
         HttpCookie  cook    = new HttpCookie("printData");
         cook.Value = user_id.ToString();
         Response.Cookies.Add(cook);
         Response.Redirect("PrintSlip.aspx");
     }
 }
    protected void submit_Click(object sender, EventArgs e)
    {
        bus_dbEntities db       = new bus_dbEntities();
        String         seatData = seatList.Value;

        foreach (String s in seatData.Split(';'))
        {
            if (!String.IsNullOrEmpty(s))
            {
                tbl_booking d     = new tbl_booking();
                int         bus   = int.Parse(b_bus.SelectedValue.ToString());
                int         dst   = int.Parse(b_arrv.SelectedValue.ToString());
                int         src   = int.Parse(b_dept.SelectedValue.ToString());
                int         route = (from x in db.tbl_route where x.route_source == src && x.route_destination == dst select x).ToList()[0].route_id;
                d.booking_datetime = DateTime.Parse(b_date.Value.ToString() + " " + b_time.SelectedItem.Text.ToString());
                int seat = int.Parse(s);
                d.booking_seatno = seat;
                string cnic = c_cnic.Value.ToString();
                d.fk_user     = (from x in db.tbl_user where x.user_cnic == cnic select x).ToList()[0].user_id;
                d.fk_schedule = (from x in db.tbl_schedule
                                 join y in db.tbl_bus on x.fk_bus equals y.bus_id
                                 join z in db.tbl_route on x.fk_route equals z.route_id
                                 join a in db.tbl_station on z.route_source equals a.station_id
                                 join b in db.tbl_station on z.route_destination equals b.station_id
                                 where a.station_id == src && b.station_id == dst && y.bus_id == bus
                                 select x.schedule_id).ToList()[0];
                db.tbl_booking.Add(d);
                db.SaveChanges();
                ScriptManager.RegisterStartupScript(this, GetType(), "ok", "alert('Seats Reserved Successfully. You can print the receipt from booking history.');", true);
                seatList.Value = "";
                b_date.Value   = "";
            }
        }
    }
Beispiel #3
0
        public HttpResponseMessage addbooking(tbl_booking booking)
        {
            DbContextTransaction transaction = entities.Database.BeginTransaction();

            try
            {
                booking.status = "confirmed";
                entities.tbl_booking.Add(booking);
                entities.SaveChanges();
                transaction.Commit();
                return(Request.CreateResponse(HttpStatusCode.OK, booking));
            }
            catch (Exception)
            {
                transaction.Rollback();
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid data entered"));
            }
        }