protected void btnSave_Click(object sender, EventArgs e)
        {
            //do insert or update
            using (TravelConnection db = new TravelConnection())
            {
                busschedule_master objSchedule = new busschedule_master();

                if (!String.IsNullOrEmpty(Request.QueryString["SCHEDULE_ID"]))
                {
                    Int32 ScheduleId = Convert.ToInt32(Request.QueryString["SCHEDULE_ID"]);

                    objSchedule = (from s in db.busschedule_master
                                  where s.SCHEDULE_ID == ScheduleId
                                  select s).FirstOrDefault();
                }

                //populate the course from the input form
                objSchedule.BUS_ID = Convert.ToInt32(ddlBus.SelectedValue);
                objSchedule.DEPARTURE_TIME =Convert.ToDateTime(cldrDeparture.SelectedDate.ToLongDateString());
                objSchedule.ARRIVAL_TIME= Convert.ToDateTime(cldrArrival.SelectedDate.ToLongDateString());
                objSchedule.SEAT_AVAILABILITY = Convert.ToInt32(txtSeat.Text);

                if (String.IsNullOrEmpty(Request.QueryString["SCHEDULE_ID"]))
                {
                    //add
                    db.busschedule_master.Add(objSchedule);
                }

                //save and redirect
                db.SaveChanges();
                Response.Redirect("busschedule-info.aspx");
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //do insert or update
            using (TravelConnection db = new TravelConnection())
            {
                station_master objStation = new station_master();

                if (!String.IsNullOrEmpty(Request.QueryString["STATION_ID"]))
                {
                    Int32 STATION_ID = Convert.ToInt32(Request.QueryString["STATION_ID"]);

                    objStation = (from s in db.station_master
                            where s.STATION_ID == STATION_ID
                            select s).FirstOrDefault();
                }

                //populate the course from the input form
                objStation.STATION_NAME = txtStation.Text;

                if (String.IsNullOrEmpty(Request.QueryString["STATION_ID"]))
                {
                    //add
                    db.station_master.Add(objStation);
                }

                //save and redirect
                db.SaveChanges();
                Response.Redirect("station-info.aspx");
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //do insert or update
            using (TravelConnection db = new TravelConnection())
            {
                bustype_master objBustype = new bustype_master();

                if (!String.IsNullOrEmpty(Request.QueryString["BUSTYPE_ID"]))
                {
                    Int32 BusTypeId = Convert.ToInt32(Request.QueryString["BUSTYPE_ID"]);

                    objBustype = (from t in db.bustype_master
                                  where t.BUSTYPE_ID == BusTypeId
                                  select t).FirstOrDefault();
                }

                //populate the course from the input form
                objBustype.BUS_TYPE= txtBustype.Text;

                if (String.IsNullOrEmpty(Request.QueryString["BUSTYPE_ID"]))
                {
                    //add
                    db.bustype_master.Add(objBustype);
                }

                //save and redirect
                db.SaveChanges();
                Response.Redirect("bustype-info.aspx");
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //do insert or update
            using (TravelConnection db = new TravelConnection())
            {
                bus_master objBus = new bus_master();

                if (!String.IsNullOrEmpty(Request.QueryString["BUS_ID"]))
                {
                    Int32 BusId = Convert.ToInt32(Request.QueryString["BUS_ID"]);

                    objBus = (from t in db.bus_master
                                  where t.BUS_ID == BusId
                                  select t).FirstOrDefault();
                }

                //populate the course from the input form
                objBus.BUS_NO = txtBusno.Text;
                objBus.BUS_TYPE = Convert.ToInt32(ddlBustype.SelectedValue);
                objBus.SOURCE_STATION = Convert.ToInt32(ddlSource.SelectedValue);
                objBus.DESTINATION_STATION = Convert.ToInt32(ddlDestination.SelectedValue);

                if (String.IsNullOrEmpty(Request.QueryString["BUS_ID"]))
                {
                    //add
                    db.bus_master.Add(objBus);
                }

                //save and redirect
                db.SaveChanges();
                Response.Redirect("busmaster-info.aspx");
            }
        }
        protected void GetBusNo()
        {
            using (TravelConnection db = new TravelConnection())
            {
                var bus = (from b in db.bus_master
                            orderby b.BUS_NO
                            select b);

                ddlBus.DataSource = bus.ToList();
                ddlBus.DataBind();
            }
        }
        protected void GetBusType()
        {
            using (TravelConnection db = new TravelConnection())
            {
                var busType = (from t in db.bustype_master
                            orderby t.BUS_TYPE
                            select t);

                ddlBustype.DataSource = busType.ToList();
                ddlBustype.DataBind();
            }
        }
        protected void GetBus()
        {
            using (TravelConnection db = new TravelConnection())
            {
                var bus = (from b in db.bus_master
                           select new { b.BUS_ID, b.BUS_NO, b.bustype_master.BUS_TYPE , s1 = b.station_master.STATION_NAME, s2 = b.station_master1.STATION_NAME });

                //append the current direction to the Sort Column
                String Sort = Session["SortColumn"].ToString() + " " + Session["SortDirection"].ToString();

                grdBus.DataSource = bus.AsQueryable().OrderBy(Sort).ToList();
                grdBus.DataBind();
            }
        }
        protected void GetStation()
        {
            using (TravelConnection db = new TravelConnection())
            {
                var stations = (from s in db.station_master
                               select new { s.STATION_ID, s.STATION_NAME });

                //append the current direction to the Sort Column
                String Sort = Session["SortColumn"].ToString() + " " + Session["SortDirection"].ToString();

                grdStation.DataSource = stations.AsQueryable().OrderBy(Sort).ToList();
                grdStation.DataBind();
            }
        }
        protected void GetBusType()
        {
            using (TravelConnection db = new TravelConnection())
            {
                var bustype = (from t in db.bustype_master
                                select new { t.BUSTYPE_ID, t.BUS_TYPE});

                //append the current direction to the Sort Column
                String Sort = Session["SortColumn"].ToString() + " " + Session["SortDirection"].ToString();

                grdBustype.DataSource = bustype.AsQueryable().OrderBy(Sort).ToList();
                grdBustype.DataBind();
            }
        }
        protected void GetStation()
        {
            //populate the existing course for editing
            using (TravelConnection db = new TravelConnection())
            {
                Int32 StationID = Convert.ToInt32(Request.QueryString["STATION_ID"]);

                station_master objStation = (from s in db.station_master
                               where s.STATION_ID == StationID
                               select s).FirstOrDefault();

                //populate the form
                txtStation.Text = objStation.STATION_NAME;
            }
        }
        protected void GetBusType()
        {
            //populate the existing course for editing
            using (TravelConnection db = new TravelConnection())
            {
                Int32 BustypeId = Convert.ToInt32(Request.QueryString["BUSTYPE_ID"]);

                bustype_master objBustype = (from t in db.bustype_master
                                             where t.BUSTYPE_ID== BustypeId
                                             select t).FirstOrDefault();

                //populate the form
                txtBustype.Text = objBustype.BUS_TYPE;
            }
        }
        protected void grdBus_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            Int32 BusId = Convert.ToInt32(grdBus.DataKeys[e.RowIndex].Values["BUS_ID"].ToString());

            using (TravelConnection db = new TravelConnection())
            {
                bus_master objBus = (from t in db.bus_master
                                             where t.BUS_ID == BusId
                                             select t).FirstOrDefault();

                db.bus_master.Remove(objBus);
                db.SaveChanges();
            }

            GetBus();
        }
        protected void grdStation_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            Int32 StationID = Convert.ToInt32(grdStation.DataKeys[e.RowIndex].Values["STATION_ID"].ToString());

            using (TravelConnection db = new TravelConnection())
            {
                station_master objStaion = (from s in db.station_master
                               where s.STATION_ID == StationID
                               select s).FirstOrDefault();

                db.station_master.Remove(objStaion);
                db.SaveChanges();
            }

            GetStation();
        }
        protected void GetBus()
        {
            //populate the existing course for editing
            using (TravelConnection db = new TravelConnection())
            {
                Int32 BusId = Convert.ToInt32(Request.QueryString["BUS_ID"]);

                bus_master objBus = (from t in db.bus_master
                                             where t.BUS_ID == BusId
                                             select t).FirstOrDefault();

                //populate the form
                txtBusno.Text = objBus.BUS_NO;
                ddlBustype.SelectedValue = objBus.BUS_TYPE.ToString();
                ddlSource.SelectedValue = objBus.SOURCE_STATION.ToString();
                ddlDestination.SelectedValue = objBus.DESTINATION_STATION.ToString();
            }
        }
        protected void GetBusSchedule()
        {
            //populate the existing course for editing
            using (TravelConnection db = new TravelConnection())
            {
                Int32 ScheduleId = Convert.ToInt32(Request.QueryString["SCHEDULE_ID"]);

                busschedule_master objSchedule = (from s in db.busschedule_master
                                             where s.SCHEDULE_ID == ScheduleId
                                             select s).FirstOrDefault();

                //populate the form
                ddlBus.Text = objSchedule.BUS_ID.ToString();
                cldrDeparture.SelectedDate = Convert.ToDateTime(objSchedule.DEPARTURE_TIME.ToString());
                cldrArrival.SelectedDate = Convert.ToDateTime(objSchedule.ARRIVAL_TIME.ToString());
                txtSeat.Text = objSchedule.SEAT_AVAILABILITY.ToString();

            }
        }
        protected void GetStation()
        {
            using (TravelConnection db = new TravelConnection())
            {
                var station = (from s in db.station_master
                            orderby s.STATION_NAME
                            select s);

                ddlSource.DataSource = station.ToList();
                ddlSource.DataBind();

                ddlDestination.DataSource = station.ToList();
                ddlDestination.DataBind();
            }
        }