private void btnSave_Click(object sender, EventArgs e) { telephone = new Telephone(); telephone.Manufacturer = txtManufacturer.Text; telephone.Model = txtModel.Text; telephone.PhoneNumber = txtPhoneNum.Text; numberToDial = txtNumberToDial.Text; // have the user pick a file if they have not done so already if (fileName == "") { if (saveFileDialogTelephoneEntryForm.ShowDialog() == DialogResult.OK) { fileName = saveFileDialogTelephoneEntryForm.FileName; } } // open the file fs = new FileStream(fileName, FileMode.Append, FileAccess.Write); w = new BinaryWriter(fs); // write the data to the file telephone.saveDataTo(w); // close the file in case we need to open for reading w.Close(); fs.Close(); // display the data txtOutput.Text = telephone.ToString() + Environment.NewLine + "Phone # to dial: " + numberToDial; // clear the fields txtManufacturer.Clear(); txtModel.Clear(); txtPhoneNum.Clear(); txtNumberToDial.Clear(); }
private void btnShowPhones_Click(object sender, EventArgs e) { int i = 0; TelephoneListForm showPhonesForm = new TelephoneListForm(); if (openFileDialogTelephoneEntryForm.ShowDialog() == DialogResult.OK) { fs = (FileStream)openFileDialogTelephoneEntryForm.OpenFile(); r = new BinaryReader(fs); while (r.BaseStream.Position < r.BaseStream.Length) { telephone = new Telephone(); telephone.readDataFrom(r); showPhonesForm.txtPhonesEntered.AppendText("=== Telephone " + (i + 1).ToString() + " ===" + Environment.NewLine); showPhonesForm.txtPhonesEntered.AppendText(telephone.ToString() + Environment.NewLine); showPhonesForm.txtPhonesEntered.AppendText(Environment.NewLine); i++; } showPhonesForm.toolStripStatusLabelTelephoneListForm.Text = "A total of " + i.ToString() + " telephones."; } // show the form showPhonesForm.Show(); }