Example #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("user_id")).Value.ToString());
            bus_dbEntities db      = new bus_dbEntities();
            tbl_login      login   = (from x in db.tbl_login where x.fk_user == user_id select x).ToList()[0];
            db.tbl_login.Remove(login);
            //Save to database
            db.SaveChanges();
            var original = db.tbl_user.Find(user_id);

            if (original != null)
            {
                db.Entry(original).State = EntityState.Modified;
                original.user_status     = "not verified";
                db.SaveChanges();
            }

            var lgs = (from x in db.tbl_user select x).ToList();
            grid1.DataSource = lgs;
            grid1.DataBind();
        }
        else if (e.CommandName.Equals("verify"))
        {
            int            index    = int.Parse(e.CommandArgument.ToString());
            GridViewRow    gr       = (GridViewRow)((Button)e.CommandSource).NamingContainer;
            int            user_id  = int.Parse(((HiddenField)gr.FindControl("user_id")).Value.ToString());
            String         username = gr.Cells[8].Text.ToString();
            String         password = gr.Cells[9].Text.ToString();
            bus_dbEntities db       = new bus_dbEntities();
            tbl_login      login    = new tbl_login();
            login.login_password = password;
            login.login_user     = username;
            login.fk_user        = user_id;
            db.tbl_login.Add(login);
            db.SaveChanges();

            var original = db.tbl_user.Find(user_id);

            if (original != null)
            {
                db.Entry(original).State = EntityState.Modified;
                original.user_status     = "verified";
                db.SaveChanges();
            }

            var lgs = (from x in db.tbl_user select x).ToList();
            grid1.DataSource = lgs;
            grid1.DataBind();
        }
    }
Example #2
0
    protected void btn_add_User_Click(object sender, EventArgs e)
    {
        if (!String.IsNullOrEmpty(User_name.Value.ToString()) && !String.IsNullOrEmpty(User_contact.Value.ToString()))
        {
            bus_dbEntities db = new bus_dbEntities();
            //Create new instance and assign values to columns
            tbl_user user = new tbl_user();

            user.user_name    = User_name.Value.ToString();
            user.user_contact = User_contact.Value.ToString();
            user.user_email   = User_email.Value.ToString();
            user.user_address = User_address.Value.ToString();
            user.fk_type      = Int32.Parse(user_type.SelectedValue.ToString());
            //Add instance in db
            db.tbl_user.Add(user);
            db.SaveChanges();

            List <tbl_user> lgs      = (from x in db.tbl_user select x).ToList();
            var             userType = (from x in db.tbl_usertype select x).ToList();
            grid1.DataSource = lgs;
            grid1.DataBind();
            user_type.DataSource     = userType;
            user_type.DataTextField  = "type_name";
            user_type.DataValueField = "type_id";
            user_type.DataBind();
        }
        else
        {
            //Show alert
            ScriptManager.RegisterStartupScript(this, GetType(), "errorAlert", "alert('Please Enter usermane or password');", true);
        }
    }
Example #3
0
    protected void btn_add_Station_Click(object sender, EventArgs e)
    {
        if (!String.IsNullOrEmpty(Bus_name.Value.ToString()) && !String.IsNullOrEmpty(Bus_capacity.Value.ToString()))
        {
            bus_dbEntities db = new bus_dbEntities();
            //Create new instance and assign values to columns
            tbl_bus bus = new tbl_bus();
            bus.bus_name     = Bus_name.Value.ToString();
            bus.bus_capacity = int.Parse(Bus_capacity.Value.ToString());
            bus.bus_driver   = Bus_driver.Value.ToString();
            bus.bus_contact  = Bus_contact.Value.ToString();
            //Add instance in db
            db.tbl_bus.Add(bus);
            db.SaveChanges();

            List <tbl_bus> lgs = (from x in db.tbl_bus select x).ToList();
            grid1.DataSource = lgs;
            grid1.DataBind();
        }
        else
        {
            //Show alert
            ScriptManager.RegisterStartupScript(this, GetType(), "errorAlert", "alert('Please Enter bus name and capcaity');", true);
        }
    }
Example #4
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");
     }
 }
Example #5
0
    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   = "";
            }
        }
    }
Example #6
0
    protected void btn_add_Route_Click(object sender, EventArgs e)
    {
        bus_dbEntities db = new bus_dbEntities();
        //Create new instance and assign values to columns
        tbl_route route = new tbl_route
        {
            route_source      = int.Parse(Route_Source.SelectedValue),
            route_destination = int.Parse(Route_Destination.SelectedValue)
        };

        //Add instance in db
        db.tbl_route.Add(route);
        db.SaveChanges();

        var lgs = (from x in db.tbl_route join y in db.tbl_station on x.route_source equals y.station_id join z in db.tbl_station on x.route_destination equals z.station_id select new { ID = x.route_id, Source = y.station_name, Destination = z.station_name }).ToList();

        grid1.DataSource = lgs;
        grid1.DataBind();
    }
Example #7
0
    protected void btn_add_Schedule_Click(object sender, EventArgs e)
    {
        bus_dbEntities db = new bus_dbEntities();
        //Create new instance and assign values to columns
        tbl_schedule route  = new tbl_schedule();
        int          source = int.Parse(Schedule_Source.SelectedValue.ToString());
        int          dest   = int.Parse(Schedule_Destination.SelectedValue.ToString());

        route.fk_route      = (from x in db.tbl_route where x.route_source == source && x.route_destination == dest select x).ToList()[0].route_id;
        route.schedule_time = TimeSpan.Parse(Schedule_timming.SelectedItem.Text.ToString());
        route.fk_bus        = int.Parse(Schedule_bus.SelectedValue.ToString());
        //Add instance in db
        db.tbl_schedule.Add(route);
        db.SaveChanges();

        var lgs = (from x in db.tbl_route join y in db.tbl_station on x.route_source equals y.station_id join z in db.tbl_station on x.route_destination equals z.station_id select new { ID = x.route_id, Source = y.station_name, Destination = z.station_name }).ToList();

        grid1.DataSource = lgs;
        grid1.DataBind();
    }
Example #8
0
    protected void btn_add_Station_Click(object sender, EventArgs e)
    {
        if (!String.IsNullOrEmpty(time_name.Value.ToString()))
        {
            bus_dbEntities db = new bus_dbEntities();
            //Create new instance and assign values to columns
            tbl_time time = new tbl_time();
            time.time_value = TimeSpan.Parse(time_name.Value.ToString());
            //Add instance in db
            db.tbl_time.Add(time);
            db.SaveChanges();

            List <tbl_time> lgs = (from x in db.tbl_time select x).ToList();
            grid1.DataSource = lgs;
            grid1.DataBind();
        }
        else
        {
            //Show alert
            ScriptManager.RegisterStartupScript(this, GetType(), "errorAlert", "alert('Please Select a proper Timming');", true);
        }
    }
Example #9
0
    protected void btn_add_Station_Click(object sender, EventArgs e)
    {
        if (!String.IsNullOrEmpty(Station_name.Value.ToString()))
        {
            bus_dbEntities db = new bus_dbEntities();
            //Create new instance and assign values to columns
            tbl_station station = new tbl_station {
                station_name = Station_name.Value.ToString()
            };

            //Add instance in db
            db.tbl_station.Add(station);
            db.SaveChanges();

            List <tbl_station> lgs = (from x in db.tbl_station select x).ToList();
            grid1.DataSource = lgs;
            grid1.DataBind();
        }
        else
        {
            //Show alert
            ScriptManager.RegisterStartupScript(this, GetType(), "errorAlert", "alert('Please Enter station name');", true);
        }
    }
Example #10
0
    protected void btn_signup_Click(object sender, EventArgs e)
    {
        nameErr.Visible         = false;
        contactErr.Visible      = false;
        cnicErr.Visible         = false;
        usernameErr.Visible     = false;
        passwordErr.Visible     = false;
        signupErrorMsg.Visible  = false;
        signupErrorMsg2.Visible = false;
        signupErrorMsg3.Visible = false;
        String name = s_name.Value.ToString();

        if (String.IsNullOrEmpty(name))
        {
            nameErr.Visible = true;
        }
        String contact = s_contact.Value.ToString();

        if (String.IsNullOrEmpty(contact))
        {
            contactErr.Visible = true;
        }
        String cnic = s_cnic.Value.ToString();

        if (String.IsNullOrEmpty(cnic))
        {
            cnicErr.Visible = true;
        }
        String email   = s_email.Value.ToString();
        String address = s_address.Value.ToString();
        String user    = s_user.Value.ToString();

        if (String.IsNullOrEmpty(user))
        {
            usernameErr.Visible = true;
        }
        String pass = s_password.Value.ToString();

        if (String.IsNullOrEmpty(pass))
        {
            passwordErr.Visible = true;
        }
        if (!String.IsNullOrEmpty(name) && !String.IsNullOrEmpty(contact) && !String.IsNullOrEmpty(cnic) && !String.IsNullOrEmpty(user) && !String.IsNullOrEmpty(pass))
        {
            bus_dbEntities  db      = new bus_dbEntities();
            List <tbl_user> usrList = (from x in db.tbl_user where x.user_cnic == cnic select x).ToList();
            if (usrList.Count > 0)
            {
                signupErrorMsg3.Visible = true;
            }
            else
            {
                usrList = (from x in db.tbl_user where x.user_duser == user select x).ToList();

                if (usrList.Count > 0)
                {
                    signupErrorMsg2.Visible = true;
                }
                else
                {
                    tbl_user usr = new tbl_user();
                    usr.user_name      = name;
                    usr.user_contact   = contact;
                    usr.user_cnic      = cnic;
                    usr.user_email     = email;
                    usr.user_status    = "not verified";
                    usr.user_address   = address;
                    usr.user_duser     = user;
                    usr.user_dpassword = pass;
                    db.tbl_user.Add(usr);
                    db.SaveChanges();
                    ScriptManager.RegisterStartupScript(this, GetType(), "ok", "alert('Data Sent for Verification From Admin');", true);
                    s_name.Value     = "";
                    s_contact.Value  = "";
                    s_cnic.Value     = "";
                    s_email.Value    = "";
                    s_address.Value  = "";
                    s_user.Value     = "";
                    s_password.Value = "";
                }
            }
        }
        else
        {
            signupErrorMsg.Visible = true;
        }
    }