Esempio n. 1
0
        // This is how you pull the created table from the FileToTable object:
        public Table getTable()
        {
            if (this.stream != null && this.table != null)
            {
                return(this.table);
            }

            else
            {
                var wm = new WarningMessage("Table Error", "Table could not be created.");
                return(null);
            }
        }
Esempio n. 2
0
        // Menu -> Import Table...
        // Import table by choosing .txt/.csv files of a specific format:
        private void importTableToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Stream stream = null;
            // Open the File Select Dialog to choose Table file:
            OpenFileDialog openFile = new OpenFileDialog();

            openFile.InitialDirectory = "C:\\";
            openFile.Filter           = "txt files(*.txt)|*.txt|csv files(*.csv)|*.csv";
            openFile.FilterIndex      = 2;
            openFile.RestoreDirectory = true;
            // If user selects a File:
            if (openFile.ShowDialog() == DialogResult.OK)
            {
                try {
                    if ((stream = openFile.OpenFile()) != null)
                    {
                        using (stream) {
                            string tableName = Path.GetFileNameWithoutExtension(openFile.FileName);
                            // Detect Duplicate Table Before Load:
                            foreach (Table t in tables)
                            {
                                if (tableName == t.getName() || tableName == t.getName().ToUpper() ||
                                    tableName.ToUpper() == t.getName())
                                {
                                    var wm = new WarningMessage("Duplicate Table",
                                                                "A table with this name is already loaded!");
                                    return;
                                }
                            }
                            FileToTable ft       = new FileToTable(stream, tableName);
                            Table       newTable = ft.getTable();
                            newTable.MdiParent = this;
                            this.tables.Add(newTable);
                            // Populate Tables combobox with Table Names:
                            this.tablesBox.Items.Add(newTable.getName());
                            // Populate Tables combobox with Table Names:
                            refreshFields();
                            hideStatementPanel();
                            newTable.Show();
                        }
                    }
                }
                catch (Exception ex) {
                    var wm = new WarningMessage("Error Opening File",
                                                "Exception: " + ex.ToString());
                }
            }
        }
Esempio n. 3
0
        // Helper to read to and from a string in a List, then put each token in another List:
        private void readFromAndTo(string start, string end, List <string> from, List <string> to)
        {
            int startIndex, endIndex;

            try {
                startIndex = from.IndexOf(start); endIndex = from.IndexOf(end);
            }
            catch (Exception ex) {
                var wm = new WarningMessage("SQL Statement Read Failed",
                                            "Error: Start and/or end keys not found in SQL Statement!");
                return;
            }
            for (int i = startIndex + 1; i < endIndex; i++)
            {
                to.Add(from[i]);
            }
        }
Esempio n. 4
0
        // Memu: File -> Import Schema...
        private void importSchemaMenuItem_Click(object sender, EventArgs e)
        {
            Stream stream = null;
            // Open the File Select Dialog to choose Table file:
            OpenFileDialog openFile = new OpenFileDialog();

            openFile.InitialDirectory = "C:\\";
            openFile.Filter           = "SQuilL Schema files(*.sch)|*.sch";
            openFile.FilterIndex      = 2;
            openFile.RestoreDirectory = true;
            // If user selects a File:
            if (openFile.ShowDialog() == DialogResult.OK)
            {
                try {
                    if ((stream = openFile.OpenFile()) != null)
                    {
                        using (stream) {
                            string schemaName = Path.GetFileNameWithoutExtension(openFile.FileName);
                            // Detect Duplicate Table Before Load:
                            foreach (Table t in tables)
                            {
                                tables.Remove(t);
                            }

                            SchemaToTables ft = new SchemaToTables(stream, schemaName);
                            foreach (Table t in ft.getTables())
                            {
                                t.MdiParent = this;
                                this.tables.Add(t);
                                // Populate Tables combobox with Table Names:
                                this.tablesBox.Items.Add(t.getName());
                                // Populate Tables combobox with Table Names:
                                refreshFields();
                                hideStatementPanel();
                                t.Show();
                            }
                        }
                    }
                }
                catch (Exception ex) {
                    var wm = new WarningMessage("Error Opening File",
                                                "Exception: " + ex.ToString());
                }
            }
        }