private void PopulateUpdate() { // Retrieve club object for update ClubService clubService = new ClubService(); _editClub = clubService.GetByID(_editClubID.Value); txtName.Text = _editClub.Name; txtAddressLine1.Text = _editClub.AddressLine1; txtAddressLine2.Text = _editClub.AddressLine2; txtAddressLine3.Text = _editClub.AddressLine3; txtAddressLine4.Text = _editClub.AddressLine4; txtAddressLine5.Text = _editClub.AddressLine5; txtPostcode.Text = _editClub.Postcode; // Just display the HH:mm of the Opening & Closing datetime txtOpeningTime.Text = Convert.ToString(_editClub.OpeningTime.ToString("HH:mm")); txtClosingTime.Text = Convert.ToString(_editClub.ClosingTime.ToString("HH:mm")); cbManager.SelectedValuePath = "ID"; cbManager.DisplayMemberPath = "FullName"; cbManager.SelectedValue = _editClub.ManagerID; ckDeleted.IsChecked = _editClub.Deleted; }
private void btnSave_Click(object sender, RoutedEventArgs e) { // Validate if (Validate()) { // Update the club ClubService clubService = new ClubService(); _editClub.Name = txtName.Text; _editClub.AddressLine1 = txtAddressLine1.Text; _editClub.AddressLine2 = txtAddressLine2.Text; _editClub.AddressLine3 = txtAddressLine3.Text; _editClub.AddressLine4 = txtAddressLine4.Text; _editClub.AddressLine5 = txtAddressLine5.Text; _editClub.Postcode = txtPostcode.Text; // We're not interested in the data part of the datetime // So write the Opening & Closing datetime with a valid but arbituary // date of 01-01-1900 // Could actually use the Time property here also. _editClub.OpeningTime = Convert.ToDateTime("01-01-1900 " + txtOpeningTime.Text); _editClub.ClosingTime = Convert.ToDateTime("01-01-1900 " + txtClosingTime.Text); if (cbManager.SelectedItem != null) { _editClub.ManagerID = ((Manager)cbManager.SelectedItem).ID.Value; } _editClub.Deleted = Convert.ToBoolean(ckDeleted.IsChecked); clubService.Save(_editClub); // Update the parent DataGrid _parent.Refresh(); if (_editClubID == null) { // Reset the club ID after add/update to 'go again' // Save method populates the club ID with last ID that was added // It needs to be null to add another _editClub.ID = _editClubID; } else { this.Close(); } } }