private void btnOpen_Click(object sender, EventArgs e) { if (openFileDialog.ShowDialog() == DialogResult.OK) { //make sure we're actually reading from a file if (openFileDialog.FileName != null) { //create serialization object SerializeObject openMe = new SerializeObject(openFileDialog.FileName); //attempt to read the file if (openMe.readFile()) { try { //create new show from read data aShow openedShow = (aShow)openMe.obj; frmSeatingChart chart = new frmSeatingChart(openedShow, openFileDialog.FileName); //display that form chart.Show(); //hide this form this.Visible = false; }//end try catch { MessageBox.Show("Error while opening file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }//end catch }//end if else { //otherwise, throw error MessageBox.Show("Unable to open file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }//end else }//end inner if }//end outer if }
//save directly to file without prompting private void saveFile(string path) { //create serialization object SerializeObject writeMe = new SerializeObject(path, CurrentShow); //write data and get result code string result = writeMe.writeFile(true); //handle according to result if (result == "success") { Changed = false; } else { MessageBox.Show("Unable to save file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
//display save prompt before saving private void saveFile() { if (saveFileDialog.ShowDialog() == DialogResult.OK) { if (saveFileDialog.FileName != null) { //create serialization object SerializeObject writeMe = new SerializeObject(saveFileDialog.FileName, this.CurrentShow); //write data and get result code string result = writeMe.writeFile(); //handle according to result if (result == "success") { Changed = false; //set global path this.Path = saveFileDialog.FileName; //enable save button saveToolStripMenuItem.Enabled = true; }//end if else if (result == "error") { MessageBox.Show("Unable to open file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }//end else if }//end inner if }//end main if }
private void openFile() { //show file dialog if (openFileDialog.ShowDialog() == DialogResult.OK) { //make sure we're actually reading from a file if (openFileDialog.FileName != null) { //create serialization object SerializeObject openMe = new SerializeObject(openFileDialog.FileName); //attempt to read the file if (openMe.readFile()) { try { //create new show from read data aShow openedShow = (aShow)openMe.obj; //set the current show to the opened show this.CurrentShow = openedShow; //update the form updateNight(1); //reset the changes flag this.Changed = false; }//end try catch { //throw error MessageBox.Show("Unable to open file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }//end catch }//end if else { //otherwise, throw error MessageBox.Show("Unable to open file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }//end else }//end inner if }//end outer if }