public SearchForCastForm(CastMember castMember) { m_CastMember = castMember; InitializeComponent(); NameTextBox.Text = castMember.GetFullName(); }
private void OnAssignCastIdButtonClick(Object sender , EventArgs e) { if (CheckFirstName() == false) { return; } CastMember tempCastMember = new CastMember(); tempCastMember.FirstName = FirstNameTextBox.Text; tempCastMember.MiddleName = MiddleNameTextBox.Text; tempCastMember.LastName = LastNameTextBox.Text; tempCastMember.CastId = m_CastMember.CastId; tempCastMember.Upc = m_CastMember.Upc; using (SearchForCastForm form = new SearchForCastForm(tempCastMember)) { form.ShowDialog(); if (form.DialogResult == DialogResult.OK) { m_CastMember.FirstName = tempCastMember.FirstName; m_CastMember.MiddleName = tempCastMember.MiddleName; m_CastMember.LastName = tempCastMember.LastName; m_CastMember.CastId = tempCastMember.CastId; SetCastIdTextBox(); if (String.IsNullOrEmpty(CreditedAsTextBox.Text)) { CreditedAsTextBox.Text = FirstNameTextBox.Text; if (String.IsNullOrEmpty(MiddleNameTextBox.Text) == false) { CreditedAsTextBox.Text += " " + MiddleNameTextBox.Text; } if (String.IsNullOrEmpty(LastNameTextBox.Text) == false) { CreditedAsTextBox.Text += " " + LastNameTextBox.Text; } } FillName(); } } }
private void OnEditRowButtonClick(Object sender , EventArgs e) { if (CastListView.SelectedIndex != -1) { OLVListItem row = (OLVListItem)(CastListView.Items[CastListView.SelectedIndex]); CastMember castMember = row.RowObject as CastMember; if (castMember != null) { using (EditCastForm form = new EditCastForm(castMember)) { form.ShowDialog(); if (form.DialogResult == DialogResult.OK) { CastListView.RebuildAll(true); } } } else { Episode episode = row.RowObject as Episode; if (episode != null) { using (EditEpisodeForm form = new EditEpisodeForm(episode)) { form.ShowDialog(); if (form.DialogResult == DialogResult.OK) { CastListView.RebuildAll(true); } } } } } else { MessageBox.Show("Please select a row."); } }
public EditCastForm(CastMember castMember) { m_CastMember = castMember; m_PreviousCastId = m_CastMember.CastId; InitializeComponent(); FillName(); RoleTextBox.Text = m_CastMember.Role; VoiceCheckBox.Checked = m_CastMember.Voice; CreditedAsTextBox.Text = m_CastMember.CreditedAs; SetCastIdTextBox(); OnCastIdTextBoxTextChanged(this, EventArgs.Empty); }
private void OnAddCastButtonClick(Object sender , EventArgs e) { CastMember castMember = new CastMember(); castMember.Upc = Upc; castMember.DatabaseCastId = -1; using (EditCastForm editCastForm = new EditCastForm(castMember)) { editCastForm.ShowDialog(); if (editCastForm.DialogResult == DialogResult.OK) { if (CastEntryAdded != null) { AddedEventArgs eventArgs = new AddedEventArgs(castMember); CastEntryAdded(this, eventArgs); } } } }
private void ContributeCastMember(OleDbCommand command , CastMember castMember) { if (String.IsNullOrEmpty(castMember.CastId)) { StringBuilder commandText = new StringBuilder("INSERT INTO tDVDxCast (DVDId, LastName, MiddleName, FirstName, Role, Voice) VALUES ("); commandText.Append(PrepareTextForDb(UpcTextBox.Text)); commandText.Append(", "); commandText.Append(PrepareOptionalTextForDb(castMember.LastName)); commandText.Append(", "); commandText.Append(PrepareOptionalTextForDb(castMember.MiddleName)); commandText.Append(", "); commandText.Append(PrepareTextForDb(castMember.FirstName)); commandText.Append(", "); commandText.Append(PrepareOptionalTextForDb(castMember.Role)); commandText.Append(", "); commandText.Append(castMember.Voice); commandText.Append(")"); command.CommandText = commandText.ToString(); command.ExecuteNonQuery(); } else { StringBuilder commandText; if (castMember.CastId.StartsWith(CastListControl.NewId)) { String newId = castMember.CastId.Substring(CastListControl.NewId.Length); commandText = new StringBuilder("INSERT INTO tCast SELECT Id, LastName, MiddleName, FirstName FROM tPendingContributions WHERE Id = "); commandText.Append(newId); command.CommandText = commandText.ToString(); command.ExecuteNonQuery(); commandText = new StringBuilder("DELETE FROM tPendingContributions WHERE Id = "); commandText.Append(newId); command.CommandText = commandText.ToString(); command.ExecuteNonQuery(); castMember.CastId = newId.ToString(); } commandText = new StringBuilder("INSERT INTO tDVDxCast (DVDId, CastId, Role, CreditedAs, Voice) VALUES ("); commandText.Append(PrepareTextForDb(UpcTextBox.Text)); commandText.Append(", "); commandText.Append(castMember.CastId); commandText.Append(", "); commandText.Append(PrepareOptionalTextForDb(castMember.Role)); commandText.Append(", "); commandText.Append(PrepareOptionalTextForDb(castMember.CreditedAs)); commandText.Append(", "); commandText.Append(castMember.Voice); commandText.Append(")"); command.CommandText = commandText.ToString(); command.ExecuteNonQuery(); } }
private void GetData() { m_RootElements = new List <CastEntry>(); Program.LocalConnection.Open(); using (OleDbCommand command = Program.LocalConnection.CreateCommand()) { command.CommandText = "SELECT * FROM vCast"; using (OleDbDataReader castReader = command.ExecuteReader()) { if (castReader.HasRows) { Int32 previousEpisodeId = -1; Episode episode = null; while (castReader.Read()) { UpcTextBox.Text = castReader.GetString(0); TitleTextBox.Text = castReader.GetString(1); if (castReader.IsDBNull(11)) { //cast member is not assigned to an episode episode = null; } else { Int32 newEpisodeId = castReader.GetInt32(11); if (previousEpisodeId != newEpisodeId) { //next episode episode = null; } if (episode == null) { previousEpisodeId = newEpisodeId; episode = new Episode(); episode.Upc = UpcTextBox.Text; episode.EpisodeNumber = castReader.GetString(2); episode.EpisodeName = castReader.GetString(3); m_RootElements.Add(episode); } } CastMember castMember = new CastMember(); castMember.Upc = UpcTextBox.Text; castMember.FirstName = castReader.GetString(4); if (castReader.IsDBNull(5) == false) { String temp = castReader.GetString(5); ClearNull(ref temp); castMember.MiddleName = temp; } if (castReader.IsDBNull(6) == false) { String temp = castReader.GetString(6); ClearNull(ref temp); castMember.LastName = temp; } if (castReader.IsDBNull(7) == false) { String temp = castReader.GetString(7); ClearNull(ref temp); castMember.Role = temp; } castMember.Voice = castReader.GetBoolean(8); if (castReader.IsDBNull(9) == false) { String temp = castReader.GetString(9); ClearNull(ref temp); castMember.CreditedAs = temp; } if (castReader.IsDBNull(10) == false) { castMember.CastId = castReader.GetString(10); } castMember.DatabaseCastId = castReader.GetInt32(12); if (episode != null) { if (episode.CastList == null) { episode.CastList = new List <CastMember>(); } episode.CastList.Add(castMember); } else { m_RootElements.Add(castMember); } } } } } Program.LocalConnection.Close(); }
private void AddCastMemberToDatabase(OleDbCommand command , Int32 dividerId , ref Int32 orderNumber , CastMember castMember) { StringBuilder commandText; if (castMember.DatabaseCastId == -1) { commandText = new StringBuilder("INSERT INTO tCast (LastName, MiddleName, FirstName) VALUES ("); commandText.Append(PrepareOptionalTextForDb(castMember.LastName)); commandText.Append(", "); commandText.Append(PrepareOptionalTextForDb(castMember.MiddleName)); commandText.Append(", "); commandText.Append(PrepareTextForDb(castMember.FirstName)); commandText.Append(")"); command.CommandText = commandText.ToString(); command.ExecuteNonQuery(); commandText = new StringBuilder("SELECT @@identity FROM tDivider"); command.CommandText = commandText.ToString(); using (OleDbDataReader reader = command.ExecuteReader(CommandBehavior.SingleResult)) { reader.Read(); castMember.DatabaseCastId = reader.GetInt32(0); } } commandText = new StringBuilder("UPDATE tCast SET CastId = "); commandText.Append(PrepareOptionalTextForDb(castMember.CastId)); commandText.Append(" WHERE Id = "); commandText.Append(castMember.DatabaseCastId); command.CommandText = commandText.ToString(); command.ExecuteNonQuery(); orderNumber++; commandText = new StringBuilder("INSERT INTO tDVDxCast (DVDId, CastId, DividerId, Role, CreditedAs, Voice, OrderNumber) VALUES ("); commandText.Append(PrepareTextForDb(UpcTextBox.Text)); commandText.Append(", "); commandText.Append(castMember.DatabaseCastId); commandText.Append(", "); if (dividerId == -1) { commandText.Append(NULL); } else { commandText.Append(dividerId); } commandText.Append(", "); commandText.Append(PrepareOptionalTextForDb(castMember.Role)); commandText.Append(", "); commandText.Append(PrepareOptionalTextForDb(castMember.CreditedAs)); commandText.Append(", "); commandText.Append(castMember.Voice.ToString()); commandText.Append(", "); commandText.Append(orderNumber); commandText.Append(")"); command.CommandText = commandText.ToString(); command.ExecuteNonQuery(); }