Esempio n. 1
0
        private void OpenFile(string filename)
        {
            try
            {
                var frmCsvProperties = new Frm_CsvProperties(this, false);

                int numColumns;

                string suspectedDelimiter = CsvFile.DetermineDelimiter(filename, out numColumns);

                frmCsvProperties.CsvProperties.Delimiter = suspectedDelimiter;
                frmCsvProperties.CsvProperties.NumColumns = numColumns;

                if(frmCsvProperties.ShowDialog() == DialogResult.OK)
                {
                    _currentCsv = new CsvFile(frmCsvProperties.CsvProperties);

                    if(_currentCsv.Load(filename))
                    {
                        if(_currentCsv.LoadErrors.Count > 0)
                        {
                            var frmErrors = new Frm_Errors("File has been loaded, but the following errors were found:", _currentCsv.LoadErrors);
                            frmErrors.ShowDialog();
                        }

                        dataGridView_Main.DataSource = _currentCsv.DataSource;
                        _modified = false;

                        UpdateMenuStates();
                        UpdateStatusBar();

                        CurrentFilename = filename;
                    }
                    else
                    {
                        if(_currentCsv.LoadErrors.Count > 0)
                        {
                            var frmErrors = new Frm_Errors("File could not be loaded. The following errors were found:", _currentCsv.LoadErrors);
                            frmErrors.ShowDialog();
                        }
                        else
                        {
                            MessageBox.Show("Could not load file, as it appears to be invalid");
                        }

                        _currentCsv = null;
                    }
                }
            }
            catch(Exception)
            {
                _currentCsv = null;
                MessageBox.Show("Failed to open file - is it in use by another process?", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Esempio n. 2
0
        private void propertiesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            _currentCsv.UpdateProperties();

            var frmProperties = new Frm_CsvProperties(this, true) { CsvProperties = _currentCsv.Properties };

            if(frmProperties.ShowDialog() == DialogResult.OK)
            {
                _currentCsv.Properties = frmProperties.CsvProperties;
            }
        }
Esempio n. 3
0
        private void NewCsvFile()
        {
            var frmProperties = new Frm_CsvProperties(this, false, new CsvProperties { NumColumns = 10, NumRows = 10 });

            if(frmProperties.ShowDialog() == DialogResult.OK)
            {
                _currentCsv = new CsvFile(frmProperties.CsvProperties);

                _currentCsv.CreateNew(frmProperties.CsvProperties.NumColumns, frmProperties.CsvProperties.NumRows);

                dataGridView_Main.DataSource = _currentCsv.DataSource;
                _modified = false;

                UpdateMenuStates();
                UpdateStatusBar();

                CurrentFilename = null;
            }
        }