Ejemplo n.º 1
0
        private void salvarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string path = string.Empty;

            using (var file = new SaveFileDialog())
            {
                file.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";

                DialogResult resultado = file.ShowDialog();

                if (resultado == DialogResult.OK && !string.IsNullOrWhiteSpace(file.FileName))
                {
                    path = file.FileName;
                }
                else if (resultado == DialogResult.Cancel)
                {
                    return;
                }
            }

            if (string.IsNullOrWhiteSpace(path))
            {
                AlertaErro("Não foi possível salvar o documento!");
                return;
            }

            try
            {
                Util.Saves    save     = new Util.Saves();
                List <string> comandos = new List <string>();

                foreach (var comando in listComandos.Items)
                {
                    comandos.Add(comando.ToString());
                }

                save.SalvarArquivo(path, comandos);
            }
            catch (Exception ex)
            {
                AlertaErro(ex.ToString());
            }
            finally
            {
                AlertaSucesso("Documento salvo!");
            }
        }
Ejemplo n.º 2
0
        private void carregarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            List <string> comandos = new List <string>();

            using (var file = new OpenFileDialog())
            {
                file.Filter = "txt files (*.txt)|*.txt";

                DialogResult resultado = file.ShowDialog();

                if (resultado == DialogResult.OK && !string.IsNullOrWhiteSpace(file.FileName))
                {
                    Util.Saves save = new Util.Saves();

                    comandos = save.LerArquivo(file.FileName);
                }
                else if (resultado == DialogResult.Cancel)
                {
                    return;
                }
            }

            try
            {
                listComandos.Items.Clear();

                foreach (string comando in comandos)
                {
                    listComandos.Items.Add(comando);
                }
            }
            catch (Exception ex)
            {
                AlertaErro(ex.ToString());
            }
        }