protected void Page_Load(object sender, EventArgs e) { if (Session["role"].ToString() != "DeliveryPerson") { string s = "Access denied"; Response.Redirect("login.aspx" + s); } carrentalEntities db = new carrentalEntities(); string mail = Session["loginid"].ToString(); chauffer cc = db.chauffers.Where(x => x.email == mail).FirstOrDefault <chauffer>(); int driverid = cc.did; booking bb = db.bookings.Where(x => x.did == driverid).FirstOrDefault <booking>(); DataTable dt = new DataTable(); using (SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString)) { con.Open(); SqlCommand cmd = new SqlCommand("SELECT b.bookingid,b.cid,b.startdate,b.enddate FROM booking AS b where (b.startdate>=@dnow) AND b.did=" + driverid + "", con); cmd.Parameters.AddWithValue("@dnow", DateTime.Now); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(dt); con.Close(); } GridView1.DataSource = dt; GridView1.DataBind(); }
protected void add_Click(object sender, EventArgs e) { carrentalEntities db = new carrentalEntities(); chauffer c = new chauffer(); Login l = new Login(); pass = GetStr(); Session["pwd"] = pass.ToString(); c.firstname = firstname.Text; c.lastname = lastname.Text; c.licenseno = licenceno.Text; c.address = address.Text; c.salary = Int32.Parse(salry.Text); c.email = email.Text; c.phone = mobileno.Text; string r = "DeliveryPerson"; l.Role = r; l.LoginId = email.Text; l.Password = pass; db.Logins.Add(l); db.chauffers.Add(c); //db.SaveChanges(); try { int n = db.SaveChanges(); sendmail("Successfully registered"); msg.Text = "Successfully registered"; msg.ForeColor = System.Drawing.Color.Green; } catch (Exception err) { //msg.Text = "Some Error Occured"; // msg.ForeColor = System.Drawing.Color.Red; Response.Write(err); } }
protected void Button1_Click(object sender, EventArgs e) { Label8.Visible = true; Label9.Visible = true; Label10.Visible = true; Label11.Visible = true; string loginid = Session["loginid"].ToString(); carrentalEntities db = new carrentalEntities(); chauffer cc = db.chauffers.Where(x => x.email == loginid).FirstOrDefault <chauffer>(); int cid = cc.did; int id = Int32.Parse(bookingid.Text); var getdata = from x in db.bookings where x.bookingid == id && x.did == cid select x; if (getdata.Any()) { var a = getdata.First(); carno = a.carno; startdate = a.startdate; enddate = a.enddate; int pay = a.rentalamount; Label3.Text = carno; Label4.Text = startdate.ToString(); Label5.Text = enddate.ToString(); Label6.Text = pay.ToString(); DateTime actenddate = DateTime.Now; TimeSpan ts = actenddate.Subtract(enddate); double hr = ts.TotalHours; var vid = from p in db.cardatas where p.carno == carno select p; int vehicle = 0; if (vid.Any()) { foreach (var y in vid) { vehicle = y.vehicleid; } } var rent = from z in db.vehicles where z.vehicleid == vehicle select z; int renthr = 0; if (rent.Any()) { foreach (var y in rent) { renthr = y.priceperday; } } total = renthr * hr * 1.05; int t = (int)total; if (t >= 0) { Label7.Text = t.ToString(); } else { Label7.Visible = false; } } else { Response.Write("Enter valid booking id"); } }