public void LoadAllData(string db) { try { j_Data = JsonConvert.DeserializeObject <ToJSONData>(File.ReadAllText(db)); } catch (Exception) { MessageBox.Show("Banco de dados inválido!"); Environment.Exit(0); } /*if (File.Exists(DBName)) * * else * SaveAllData();*/ }
public Manager() { if (instance != null) { throw new Exception("Instancia Manager já existe!"); } instance = this; j_Data = new ToJSONData(); var result = MessageBox.Show("Deseja carregar um banco de dados existente?", "Ambiente para Sistemas Especialistas", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { using (var fileDialog = new OpenFileDialog()) { fileDialog.DefaultExt = "json"; fileDialog.Filter = "Arquivos JSON (*.json)|*.json"; fileDialog.InitialDirectory = Application.ExecutablePath; var fileResult = fileDialog.ShowDialog(); if (fileResult == DialogResult.OK) { var filename = fileDialog.FileName; FileNameToSave = filename; LoadAllData(filename); } else if (fileResult == DialogResult.Cancel) { Environment.Exit(0); } } } else if (result == DialogResult.No) { using (var fileDialog = new SaveFileDialog()) { fileDialog.DefaultExt = "json"; fileDialog.Filter = "Arquivo JSON (*.json)|*.json"; fileDialog.FileName = FileNameToSave; fileDialog.InitialDirectory = Application.ExecutablePath; var fileResult = fileDialog.ShowDialog(); if (fileResult == DialogResult.OK) { FileNameToSave = fileDialog.FileName; SaveAllData(); } else if (fileResult == DialogResult.Cancel) { Environment.Exit(0); } } } FileInfo file = new FileInfo(FileNameToSave); FileNameToSave = file.Name; }