示例#1
0
 // Main method.
 public Form1()
 {
     InitializeComponent();
     InitializeForm();
     currentSaveFilePath = "";
     Estates             = new EstateManager();
     newFile             = true;
     UpdateEstateList();
 }
示例#2
0
文件: Gui.cs 项目: riomontana/CSharp
        // Button handler for open file button in menu
        // Opens file with saved estates
        private void mnuFileOpen_Click(object sender, EventArgs e)
        {
            string errorMessage = null;

            openFileDialog1.Filter = ".dat |*.dat";
            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                estateManager.DeleteAll();
                fileName = openFileDialog1.FileName;
                try
                {
                    if (!File.Exists(fileName))
                    {
                        errorMessage = $"The file {fileName} was not found. ";
                        throw (new FileNotFoundException(errorMessage));
                    }
                    estateManager = dataController.DeSerializeFile <EstateManager>(fileName);
                    ClearGuiFields();
                    listBoxViewEstates.DataSource = null;
                    listBoxViewEstates.DataSource = estateManager.ToStringList();
                    fileIsSaved = true;
                    id          = estateManager.Count + 1;
                }
                catch (Exception ex)
                {
                    if (errorMessage != null)
                    {
                        errorMessage = ex.ToString();
                        MessageBox.Show("Error opening file: " + errorMessage);
                    }
                }

                if (estateManager.Count > 0)
                {
                    btnDelete.Enabled = true;
                    btnEdit.Enabled   = true;
                }
            }
        }
示例#3
0
 public void SerializeFile(EstateManager estateManager, string fileName)
 {
     fileHandler.BinaryFileSerialize(estateManager, fileName);
 }