/******************************************************************** * Event handler for the File>Save menu item * will take the records that are currently being accessed and write them * to the file with the name of the media. **********************************************************************/ private void saveToolStripMenuItem_Click(object sender, EventArgs e) { //Gets the active child form to determine if it is already opened or not RecordsForm R = this.ActiveMdiChild as RecordsForm; if (R == null) { MessageBox.Show("No form is currently displayed.", "Error"); } //Since there is a form open, we can now write the records to a file else { //Define variables needed for writing string file; media = R.getMedia(); file = media + ".inv"; Records = R.getRecords(); //Write to file write = new FileStream(file, FileMode.OpenOrCreate, FileAccess.Write); if (Records.Count > 0) { bf.Serialize(write, Records); } write.Close(); MessageBox.Show("Records have been saved to " + file, "Done!"); } }
private void updateToolStripMenuItem_Click(object sender, EventArgs e) { RecordsForm R = this.ActiveMdiChild as RecordsForm; List <int> selected = new List <int>(); if (R == null) { MessageBox.Show("You need an active form to update records.", "Error"); } else { Records = R.getRecords(); selected = R.findIndex(); foreach (int index in selected.OrderByDescending(i => i)) { if (index > 1) { InsertForm I = new InsertForm(media); I.setText(Records[index - 2]); I.ShowDialog(); if (I.canceled == false && I.mismatch == false) { List <Record> temp = I.getRecs(); Records[index - 2] = temp[0]; MessageBox.Show("Record has successfully been updated.", "Done!"); } R.refresh(Records); } } } }
/********************************************************************************* * Event Handler for the Edit>Insert menu item * will allow the user to insert(Add) records to the list of records * *********************************************************************************/ private void insertToolStripMenuItem_Click(object sender, EventArgs e) { //Checks to make sure a form is available RecordsForm R = this.ActiveMdiChild as RecordsForm; if (R == null) { MessageBox.Show("No form available.", "Error"); } //Since ther is an active form, we can now insert to the list else { //Gets the records that are already displayed on the Records Form Records = R.getRecords(); //Creates and displays an insert form, which allows the user to enter record data InsertForm I = new InsertForm(media); I.ShowDialog(); //If the user pressed cancel instead of ok on the insert form, we will not add data. //In the insert method, mismatch is set to true if the number of titles, ratings, released are not consistent. // so if mismatch is true, nothing will be added to the list if (I.canceled == false && I.mismatch == false) { //Gets the list of records created from the InsertForm(list is used for several // entries with common author/director) and adds them to the records we recieved // from the RecordsForm a few instructions ago. Records.AddRange(I.getRecs()); R.refresh(Records); //Refresh method displays the new list of records to the RecordsForm MessageBox.Show("Record has successfully been added.", "Done!"); } } }
private void deleteToolStripMenuItem1_Click(object sender, EventArgs e) { RecordsForm R = this.ActiveMdiChild as RecordsForm; List <int> selected = new List <int>(); bool deleted = false; DialogResult prompt; if (R == null) { MessageBox.Show("You need an active form to delete records.", "Error"); } else { prompt = MessageBox.Show("Are you sure you would like to permanently delete these records?", "Delete?", MessageBoxButtons.YesNo); if (prompt == DialogResult.Yes) { Records = R.getRecords(); selected = R.findIndex(); foreach (int index in selected.OrderByDescending(i => i)) { if (index > 1) { Records.RemoveAt(index - 2); R.refresh(Records); deleted = true; } } if (deleted) { MessageBox.Show("Record has successfully been removed from your library.", "Done!"); } else { MessageBox.Show("Please make a proper selection before deleting", "Error"); } } else { MessageBox.Show("Records were NOT deleted!", "Done!"); } } }