protected void btnNewGuest_Click(object sender, EventArgs e) { TreasureLandDataClassesDataContext db = new TreasureLandDataClassesDataContext(); var gu = from g in db.Guests.Where(g => g.GuestFirstName == txtFirstName.Text && g.GuestSurName == txtSurName.Text && g.GuestPhone == txtPhone.Text) select g; gvGuest.DataSource = gu.ToList(); gvGuest.DataBind(); if (gvGuest.Rows.Count == 0) { //USes an linq to sql to insert a guest into the guest table Guest addGuest = new Guest(); addGuest.GuestFirstName = txtFirstName.Text; addGuest.GuestSurName = txtSurName.Text; addGuest.GuestPhone = txtPhone.Text; db.Guests.InsertOnSubmit(addGuest); db.SubmitChanges(); lblResFirstName.Text = txtFirstName.Text; lblResSurName.Text = txtSurName.Text; lblResPhone.Text = txtPhone.Text; reserving.GuestID = addGuest.GuestID; reserving.view = 2; btnNewGuest.CommandArgument = "2"; } else { lblErrorInsertGuest.Text = "Guest already exists please select below or enter a new guest"; btnNewGuest.CommandArgument = "0"; reserving.view = 0; } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnUpdate_Click(object sender, EventArgs e) { try { TreasureLandDataClassesDataContext db = new TreasureLandDataClassesDataContext(); TreasureLand.DBM.Guest guest = new TreasureLand.DBM.Guest(); var query = from guests in db.Guests where guests.GuestID == Convert.ToInt32(gvGuestFolio.SelectedRow.Cells[0].Text) select guests; foreach (var guests in query) { guests.GuestSalutation = txtSalutation.Text; guests.GuestSurName = txtShowSurname.Text; guests.GuestFirstName = txtShowFirstName.Text; guests.GuestAddress = txtAddress.Text; guests.GuestCity = txtCity.Text; guests.GuestRegion = txtState.Text; guests.GuestCountry = txtCountry.Text; guests.GuestEmail = txtEmail.Text; guests.GuestPhone = txtPhone.Text; guests.GuestPostalCode = txtPostalCode.Text; guests.GuestComments = txtComments.Text; guests.GuestIDIssueCountry = txtIssueCountry.Text; guests.GuestID = (short)Convert.ToInt32(gvGuestFolio.SelectedRow.Cells[0].Text); guests.GuestIDNumber = txtGuestID.Text; } db.SubmitChanges(); updateGuestBoxes(); lblError.Text = "Updated successfully"; } catch (Exception) { throw; } }
partial void DeleteGuest(Guest instance);
partial void UpdateGuest(Guest instance);
partial void InsertGuest(Guest instance);