private void createClub() { Structs.Club club = new Structs.Club(); club.Country = "SE"; club.Name = "Club1"; club.ClubId = "01-001"; intf.NewClub(club); }
internal Structs.Club GetClub(string clubId) { Trace.WriteLine("CDatabase: Entering getClub(" + clubId + ")"); if (clubId == null) { throw new ArgumentNullException("clubId"); } var club = new Structs.Club(); foreach(DatabaseDataset.ClubsRow row in Database.Clubs.Select( "ClubId='" + clubId + "'", "Name")) { if (row.ClubId != clubId) continue; club.ClubId = row.ClubId; club.Name = row.Name; club.Country = row.Country; club.Automatic = row.Automatic; club.ToAutomatic = row.ToAutomatic; club.Plusgiro = row.IsPlusgiroNull() ? "" : row.Plusgiro; club.Bankgiro = row.IsBankgiroNull() ? "" : row.Bankgiro; return club; } throw new CannotFindIdException("Could not find club" + clubId); }
internal Structs.Club[] getClubs() { Trace.WriteLine("CDatabase: Entering getClubs()"); ArrayList clubs = new ArrayList(); Structs.Club club = new Structs.Club(); foreach(DatabaseDataset.ClubsRow row in Database.Clubs.Select("", "Name")) { club = new Structs.Club(); club.ClubId = row.ClubId; club.Name = row.Name; club.Country = row.Country; club.Automatic = row.Automatic; club.ToAutomatic = row.ToAutomatic; if (row.IsPlusgiroNull()) club.Plusgiro = ""; else club.Plusgiro = row.Plusgiro; if (row.IsBankgiroNull()) club.Bankgiro = ""; else club.Bankgiro = row.Bankgiro; clubs.Add(club); } return (Structs.Club[])clubs.ToArray(club.GetType()); }
private void BtnSaveClick(object sender, EventArgs e) { // Validation if (_txtOfficialName.Text.Length == 0 | _txtName.Text.Length == 0) { MessageBox.Show("Varken den officiella beteckning eller " + "namnet får vara blankt.", "Inmatningsfel", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { int.Parse(_txtOfficialName.Text.Replace("-","")); } catch(Exception) { MessageBox.Show("Den officella beteckningen består endast av tal" + " och 1 minustecken.", "Inmatningsfel", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { if (!PostgiroIsValid(_txtPgInfo.Text.Replace("-", "").Replace(" ", ""))) { MessageBox.Show("Postgiroinformationen verkar vara felaktig.", "Inmatningsfel", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (!BankgiroIsValid(_txtBgInfo.Text.Replace("-", "").Replace(" ", ""))) { MessageBox.Show("Bankgiroinformationen verkar vara felaktig.", "Inmatningsfel", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } catch(Exception) { MessageBox.Show("Postgiro- och/eller Bankgiroinformationen verkar vara felaktig.", "Inmatningsfel", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Save if ((string)_ddClubs.SelectedValue == NewClubValue) { // New club // Check if club exists try { var temp = _commonCode.GetClub(_txtOfficialName.Text); MessageBox.Show("Det finns redan en klubb med det officiella namnet \"" + _txtOfficialName.Text + "\". Den heter \"" + temp.Name + "\"", "Felmeddelande", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } catch (Common.CannotFindIdException) { // Do nothing, continue } var club = new Structs.Club { ClubId = _txtOfficialName.Text, Name = _txtName.Text, Country = (string) _ddCountry.SelectedValue, Automatic = false, ToAutomatic = false, Plusgiro = _txtPgInfo.Text.Replace(" ", ""), Bankgiro = _txtBgInfo.Text.Replace(" ", "") }; if (_commonCode.EnableInternetConnections) { DialogResult res = MessageBox.Show("Vill du lägga till klubben \"" + _txtName.Text + "\" till Internet-databasen?", "Internet-databasen", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (DialogResult.Yes == res) club.ToAutomatic = true; } _commonCode.NewClub(club); } else { // Edit existing club var club = _commonCode.GetClub((string)_ddClubs.SelectedValue); club.Country = (string)_ddCountry.SelectedValue; club.Name = _txtName.Text; club.ToAutomatic = false; club.Plusgiro = _txtPgInfo.Text.Replace(" ", ""); club.Bankgiro = _txtBgInfo.Text.Replace(" ", ""); if (_commonCode.EnableInternetConnections) { var res = MessageBox.Show("Vill du uppdatera klubben \"" + _txtName.Text + "\" i Internet-databasen?", "Internet-databasen", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (DialogResult.Yes == res) club.ToAutomatic = true; } _commonCode.UpdateClub(club); } RestoreWindow(); }