protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { GridViewRow row = GridView1.SelectedRow; //car c = new car(); cardata cd = new cardata(); vehicle v = new vehicle(); no = row.Cells[1].Text; brand1 = row.Cells[3].Text; model1 = row.Cells[4].Text; color1 = row.Cells[5].Text; capacity1 = Int32.Parse(row.Cells[6].Text); mileage1 = Double.Parse(row.Cells[7].Text); rentp = Int32.Parse(row.Cells[8].Text); image = row.Cells[9].Text; owid = Int32.Parse(row.Cells[13].Text); res = row.Cells[10].Text; carno.Text = no; brand.Text = brand1; model.Text = model1; color.Text = color1; capacity.Text = row.Cells[6].Text; mileage.Text = row.Cells[7].Text; rentprice.Text = row.Cells[8].Text; carimage.Text = image; sdate.Text = row.Cells[11].Text; edate.Text = row.Cells[12].Text; ownid.Text = row.Cells[13].Text; }
protected void book_Click(object sender, EventArgs e) { carrentalEntities db = new carrentalEntities(); booking b = new booking(); cardata cd = new cardata(); string mail = Session["loginid"].ToString(); int custid; var q = from i in db.customers where i.email == mail select i; if (q.Any()) { foreach (var i in q) { b.cid = i.cid; } } DateTime d1 = Convert.ToDateTime(Session["startdate"].ToString()); DateTime d2 = Convert.ToDateTime(Session["enddate"].ToString()); // var a = ((from x in db.carstatus where ((d1 >= x.startdate) && (d1 <= x.enddate)) || ((d2 >= x.startdate) && (d2 <= x.enddate)) select x.did)); //var ab = (from y in db.chauffers select y.did).ToList(); //var ans = ab.Except(a); //Response.Write(ans); string check = "SELECT did FROM chauffer WHERE did NOT IN(SELECT did FROM carstatus AS cs WHERE ((@d1 >= cs.startdate) AND (@d1 <= cs.enddate)) OR ((@d2 >= cs.startdate) AND (@d2 <= cs.enddate)) )"; cmd.Parameters.AddWithValue("@d1", Convert.ToDateTime(Session["startdate"].ToString())); cmd.Parameters.AddWithValue("@d2", Convert.ToDateTime(Session["enddate"].ToString())); myconn.Open(); cmd.CommandText = check; SqlDataReader rdr = cmd.ExecuteReader(); int driverid = 0; while (rdr.Read()) { driverid = Int32.Parse(rdr["did"].ToString()); break; } //Response.Write(driverid); b.startdate = Convert.ToDateTime(one + " " + two); b.enddate = Convert.ToDateTime(three + " " + four); b.rentalamount = Int32.Parse(ppay.Text.ToString()); //b.type = "Rent"; b.carno = Session["carno"].ToString(); b.did = driverid; b.month = mo; b.year = yr; b.address = address.Text; db.bookings.Add(b); string no = Session["carno"].ToString(); /* var q2 = (from p in db.cardatas where p.carno == no select p).ToList(); * if(q2.Any()) * { * foreach(var i in q2.Where(w=>w.carno==no)) * { * //i.status = "booked"; * * } * }*/ carstatu cr = new carstatu(); cr.carno = Session["carno"].ToString(); cr.startdate = Convert.ToDateTime(one + " " + two); cr.enddate = Convert.ToDateTime(three + " " + four); cr.status = "booked"; cr.did = driverid; db.carstatus.Add(cr); db.SaveChanges(); double tot = Double.Parse(ppay.Text); Session["pay"] = (int)tot; int id = (from record in db.bookings orderby record.bookingid descending select record.bookingid).First(); //for generating payslip Session["bookingid"] = id.ToString(); booking bb = db.bookings.Where(x => x.bookingid == id).FirstOrDefault <booking>(); Session["st_date"] = bb.startdate.ToString(); Session["ed_date"] = bb.enddate.ToString(); Session["carno"] = bb.carno.ToString(); cardata cx = db.cardatas.Where(y => y.carno == bb.carno.ToString()).FirstOrDefault <cardata>(); int ve_id = cx.vehicleid; vehicle vv = db.vehicles.Where(yy => yy.vehicleid == ve_id).FirstOrDefault <vehicle>(); Session["model"] = vv.model.ToString(); Session["brand"] = vv.brand.ToString(); Session["color"] = vv.color.ToString(); Session["capacity"] = vv.capacity.ToString(); Session["mileage"] = vv.mileage.ToString(); Session["address"] = bb.address.ToString(); Response.Redirect("applyoffer.aspx"); }
protected void add_Click(object sender, EventArgs e) { string brand2 = brand.Text; string model2 = model.Text; string color2 = color.Text; int capacity2 = Int32.Parse(capacity.Text); double mileage2 = Double.Parse(mileage.Text); string no2 = carno.Text; string image2 = carimage.Text; int sp2 = Int32.Parse(rentprice.Text); int oid2 = Int32.Parse(ownid.Text); vehicle v = new vehicle(); v.brand = brand2; v.model = model2; v.color = color2; v.capacity = capacity2; v.mileage = mileage2; // v.carno = no2; myconn = new SqlConnection(WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString); cmd = new SqlCommand(); cmd.Connection = myconn; myconn.Open(); update = "update vehicle set quantity=quantity+" + 1 + "where model=@model and brand=@brand and color=@color"; cmd.Parameters.AddWithValue("@model", model2); cmd.Parameters.AddWithValue("@brand", brand2); cmd.Parameters.AddWithValue("@color", color2); // myconn.Open(); cmd.CommandText = update; int r = cmd.ExecuteNonQuery(); if (r == 0) { string insert = "insert into vehicle (color,model,brand,capacity,mileage,quantity,priceperday) values(@color2,@model2,@brand2,@capacity2,@mileage2,@quantity2,@priceperday2)"; cmd.Parameters.AddWithValue("@color2", color2); cmd.Parameters.AddWithValue("@model2", model2); cmd.Parameters.AddWithValue("@brand2", brand2); cmd.Parameters.AddWithValue("@capacity2", capacity2); cmd.Parameters.AddWithValue("@mileage2", mileage2); //cmd.Parameters.AddWithValue("@capacit", capacity2); cmd.Parameters.AddWithValue("@quantity2", 1); cmd.Parameters.AddWithValue("@priceperday2", pph.Text); cmd.CommandText = insert; cmd.ExecuteNonQuery(); myconn.Close(); id = (from record in db.vehicles orderby record.vehicleid descending select record.vehicleid).First(); cardata cd = new cardata(); cd.carimage = image2; cd.rentprice = sp2; cd.carno = no2; cd.vehicleid = id; cd.startdate = Convert.ToDateTime(sdate.Text.ToString()); cd.enddate = Convert.ToDateTime(edate.Text.ToString()); cd.oid = oid2; db.cardatas.Add(cd); db.SaveChanges(); try { sendmail("Your car request has been accepted"); } catch (Exception exp) { Response.Write(exp); } } else { id = (from record in db.vehicles where record.brand == brand2 && record.model == model2 && record.color == color2 select record.vehicleid).First(); cardata cd = new cardata(); cd.carimage = image2; cd.rentprice = sp2; cd.carno = no2; cd.vehicleid = id; cd.startdate = Convert.ToDateTime(sdate.Text.ToString()); cd.enddate = Convert.ToDateTime(edate.Text.ToString()); cd.oid = oid2; db.cardatas.Add(cd); db.SaveChanges(); try { sendmail("Your car request has been accepted"); } catch (Exception exp) { Response.Write(exp); } } /* var vid=from x in db.vehicles where x.carno==cd.carno select x.vehicleid; * vlid = int.Parse(vid.ToString()); */ }