private void buttonComposerTrack_Click(object sender, EventArgs e) { PersonGroupDataSet.PersonGroupRow row = DataBase.GetPersonGroupByName(textBoxComposerTrack.Text, true); FormArtistProperties formComposerProperties = new FormArtistProperties(DataBase, PersonType.Composer, row); if (formComposerProperties.ShowDialog(this) == DialogResult.OK) { try { Big3.Hitbase.DataBaseEngine.PersonGroupDataSetTableAdapters.PersonGroupTableAdapter personGroupAdapter = new Big3.Hitbase.DataBaseEngine.PersonGroupDataSetTableAdapters.PersonGroupTableAdapter(this.DataBase); personGroupAdapter.Update(row); } catch (Exception ex) { MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
/// <summary> /// Speichert die Person/Gruppe. /// </summary> /// <param name="db"></param> public void Save(DataBase dataBase) { SqlCeTransaction trans = dataBase.Connection.BeginTransaction(IsolationLevel.ReadCommitted); Big3.Hitbase.DataBaseEngine.PersonGroupDataSetTableAdapters.PersonGroupTableAdapter pgta = new Big3.Hitbase.DataBaseEngine.PersonGroupDataSetTableAdapters.PersonGroupTableAdapter(dataBase); pgta.Transaction = trans; PersonGroupDataSet.PersonGroupDataTable dt = pgta.GetDataById(id); PersonGroupDataSet.PersonGroupRow row = null; bool isNew = false; int personGroupId = 0; if (dt.Rows.Count == 1) { row = dt[0]; personGroupId = dt[0].PersonGroupID; } else { row = dt.NewPersonGroupRow(); isNew = true; } row.Name = Name; row.SaveAs = SaveAs; row.Type = (int)Type; row.Sex = (int)Sex; row.Country = Country; row.BirthDay = Birthday; row.DayOfDeath = DayOfDeath; row.ImageFilename = ImageFilename; row.URL = Homepage; row.Comment = Comment; if (isNew) { dt.AddPersonGroupRow(row); } pgta.Update(dt); if (isNew) { personGroupId = (int)(decimal)dataBase.ExecuteScalar("SELECT @@IDENTITY", trans); } // Urls speichern string sql = string.Format("DELETE FROM Url Where ReferenceID = {0}", personGroupId); dataBase.ExecuteScalar(sql); UrlDataSetTableAdapters.UrlTableAdapter urlta = new UrlDataSetTableAdapters.UrlTableAdapter(dataBase); urlta.Transaction = trans; UrlDataSet.UrlDataTable urlDataTable = new UrlDataSet.UrlDataTable(); foreach (Url url in Urls) { urlDataTable.AddUrlRow(personGroupId, 0, url.UrlType, url.Link); } urlta.Update(urlDataTable); // Jetzt noch die Mitwirkenden der Gruppe sql = string.Format("DELETE FROM GroupParticipant Where PersonGroupID = {0}", personGroupId); dataBase.ExecuteScalar(sql); GroupParticipantDataSetTableAdapters.GroupParticipantTableAdapter participantTableAdapter = new GroupParticipantDataSetTableAdapters.GroupParticipantTableAdapter(dataBase); participantTableAdapter.Transaction = trans; GroupParticipantDataSet.GroupParticipantDataTable participantsDataTable = new GroupParticipantDataSet.GroupParticipantDataTable(); foreach (GroupParticipant gp in this.Participants) { if (!string.IsNullOrEmpty(gp.Name)) { int participantId = dataBase.GetPersonGroupByName(gp.Name, true).ID; int roleId = dataBase.GetRoleByName(gp.Role, true).RoleID; participantsDataTable.AddGroupParticipantRow(personGroupId, participantId, roleId, gp.Begin == null ? "" : gp.Begin, gp.End == null ? "" : gp.End); } } participantTableAdapter.Update(participantsDataTable); trans.Commit(); }