private void btnLoad_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() == DialogResult.OK) { FileStream fs = null; BinaryFormatter bf = null; try { fs = new FileStream(openFileDialog1.FileName, FileMode.Open, FileAccess.Read); bf = new BinaryFormatter(); lbInfo.Items.Clear(); mc = (ManufacturingCompany)(bf.Deserialize(fs)); btnShowInfo.PerformClick(); } catch (IOException) { MessageBox.Show("I/O Error"); } catch (SerializationException) { MessageBox.Show("serialization Error Maybe wrong file"); } finally { if (fs != null) { fs.Close(); MessageBox.Show("loading Done"); } } } }
private void btnLoad_Click(object sender, EventArgs e) { //todo using (OpenFileDialog ofd = new OpenFileDialog()) { if (ofd.ShowDialog() == DialogResult.OK) { FileStream fs = null; try { fs = new FileStream(ofd.FileName, FileMode.Open, FileAccess.Read); BinaryFormatter bf = new BinaryFormatter(); mc = (ManufacturingCompany)bf.Deserialize(fs); } catch (IOException ex) { MessageBox.Show("Error reading file: " + ex.Message); } catch (SerializationException ex) { MessageBox.Show(ex.Message); } finally { if (fs != null) { fs.Close(); } } } } }
public Form1() { InitializeComponent(); mc = new ManufacturingCompany("VOL"); saveFileDialog1.Filter = "Text Files (*.txt)|*.txt"; saveFileDialog1.DefaultExt = "txt"; saveFileDialog1.AddExtension = true; }
public Form1() { InitializeComponent(); mc = new ManufacturingCompany("VDL assembling Mini Cooper"); Machine machine = new Machine("machine", 12, 12); mc.AddMachine(machine); machine.CriticalState += new Machine.CriticalStateHandler(ShowInListBox); }
private void btnLoad_Click(object sender, EventArgs e) { try { using (FileStream fs = new FileStream("saveFile.bin", FileMode.Open, FileAccess.Read)) { BinaryFormatter bf = new BinaryFormatter(); mc = (ManufacturingCompany)bf.Deserialize(fs); MessageBox.Show("loaded from file"); } } catch (SerializationException ex) { MessageBox.Show(ex.Message); } catch (IOException ex) { MessageBox.Show(ex.Message); } }
private void btnLoad_Click(object sender, EventArgs e) { //todo string fileName = "C:/Users/Ov/Documents/votesFromEindhoven.txt"; FileStream fs = null; BinaryFormatter bf = null; try { fs = new FileStream(fileName, FileMode.Open, FileAccess.Read); bf = new BinaryFormatter(); lbInfo.Items.Clear(); mc = (ManufacturingCompany)(bf.Deserialize(fs)); } catch (IOException) { MessageBox.Show("I/O Error"); } catch (SerializationException) { MessageBox.Show("serialization Error"); } finally { if (fs != null) { fs.Close(); } } }
public Form1() { InitializeComponent(); mc = new ManufacturingCompany("VDL assembling Mini Cooper"); }