protected void btnSearch_Click(object sender, EventArgs e) { int orderId = int.Parse(txtMessageId.Text); string custName; string custEmail; string custSubject; string custMessage; VehicleRentalWebDbEntities vehRent = new VehicleRentalWebDbEntities(); { var message = (from mess in vehRent.Messages //join table in vehRent.Tables on book.Id equals table.Id //join car in vehRent.CARs on book.Id equals car.Id where mess.Id == orderId select new { MessageId = mess.Id, CustName = mess.NAME, CustEmail = mess.EMAIL, CustSubject = mess.SUBJECT, CustMessage = mess.MESSAGE1 }).FirstOrDefault(); if (message == null) // error handling if orderId is bad { throw new Exception("No such order found."); } ; custName = message.CustName; custEmail = message.CustEmail; custSubject = message.CustSubject; custMessage = message.CustMessage; } lblName.Text = custName; lblEmail.Text = custEmail; lblSubject.Text = custSubject; lblMessage.Text = custMessage; }
protected void btnDelete_Click(object sender, EventArgs e) { string custName = txtCustName.Text; using (var context = new VehicleRentalWebDbEntities()) { var itemToRemove = context.Tables.SingleOrDefault(x => x.NAME == custName); //returns a single item. if (itemToRemove != null) { context.Tables.Remove(itemToRemove); context.SaveChanges(); } } lblMessage.Text = "Data deleted!"; }
protected void Page_Load(object sender, EventArgs e) { using (VehicleRentalWebDbEntities vehrentModel = new VehicleRentalWebDbEntities()) { try { lblSessionUser.Text = Session["user_name"].ToString(); } catch (Exception ex) { Server.Transfer("login.aspx"); } repeater_class.DataSource = vehrentModel.CARs.ToList(); repeater_class.DataBind(); } }
protected void btnDelete_Click(object sender, EventArgs e) { int carName = int.Parse(txtName.Text); using (var context = new VehicleRentalWebDbEntities()) { var itemToRemove = context.CARs.SingleOrDefault(x => x.Id == carName); //returns a single item. if (itemToRemove != null) { context.CARs.Remove(itemToRemove); context.SaveChanges(); } } lblMessage.Text = "Data deleted!"; }
protected void btnLogin_Click(object sender, EventArgs e) { using (VehicleRentalWebDbEntities context = new VehicleRentalWebDbEntities()) { var user = context.Tables.FirstOrDefault(u => u.NAME == txtEmail.Text); if (user != null) { if (user.PASSWORD == txtPassword.Text) { Session["user_name"] = txtEmail.Text; Response.Redirect("IndexMain.aspx"); } else { lblMessageLogin.Text = "User name or password incorrect!"; } } else { lblMessageLogin.Text = "no user found"; } } }
protected void btnCustSearch_Click(object sender, EventArgs e) { int orderId; string customerName; float cnic; string gender; if (int.TryParse(txtCustId.Text, out orderId)) { using (var myEntities = new VehicleRentalWebDbEntities()) { var orderInfo = ( from Tables in myEntities.Tables where Tables.Id == orderId select new { CustomerName = Tables.NAME, CustomerCnic = Tables.CNIC, CustomerGender = Tables.GENDER } ).SingleOrDefault(); if (orderInfo == null) // error handling if orderId is bad { throw new Exception("no record found"); } customerName = orderInfo.CustomerName; cnic = (float)orderInfo.CustomerCnic; gender = orderInfo.CustomerGender; } // update controls lblCustName.Text = customerName; lblCustCnic.Text = cnic.ToString(); lblCustGender.Text = gender; } else { lblCustSuccess.Text = "Please enter your id and try again!!!"; } }
// linq to joing tables protected void btnSearch_Click1(object sender, EventArgs e) { int orderId = int.Parse(txtBookingId.Text); int bookingId; string rentDate; string returnDate; string customerName; float cnic; string gender; string carName; float carPrice; string carFuel; string carTransmition; VehicleRentalWebDbEntities vehRent = new VehicleRentalWebDbEntities(); { var books = (from book in vehRent.Bookings //join table in vehRent.Tables on book.Id equals table.Id //join car in vehRent.CARs on book.Id equals car.Id where book.Id == orderId select new { BookingId = book.Id, RentDate = book.RENTDATE, ReturnDate = book.RETURNDATE, CustName = book.Table.NAME, CustCnic = book.Table.CNIC, CustGender = book.Table.GENDER, CarName = book.CAR.NAME, CarPrice = book.CAR.Price, CarFuel = book.CAR.FUEL, CarTransmition = book.CAR.TRANSMITION }).FirstOrDefault(); if (books == null) // error handling if orderId is bad { throw new Exception("No such order found."); } ; bookingId = books.BookingId; rentDate = books.RentDate; returnDate = books.ReturnDate; customerName = books.CustName; cnic = (Int32)books.CustCnic; gender = books.CustGender; carName = books.CarName; carPrice = (Int32)books.CarPrice; carFuel = books.CarFuel; carTransmition = books.CarTransmition; } lblID.Text = bookingId.ToString(); lblRentDate.Text = rentDate; lblReturnDate.Text = returnDate; lblCustName.Text = customerName; lblCustCnic.Text = cnic.ToString(); lblCustGender.Text = gender; lblCarName.Text = carName; lblCarPrice.Text = carPrice.ToString(); lblCarFuel.Text = carFuel; lblCarTransmition.Text = carTransmition; }