コード例 #1
0
 private void SetCultureTexts()
 {
     Text          = GlobalText.GetValue("Password");
     label1.Text   = GlobalText.GetValue("PasswordNote");
     btOK.Text     = GlobalText.GetValue("Ok");
     btCancel.Text = GlobalText.GetValue("Cancel");
 }
コード例 #2
0
        private void btCreate_Click(object sender, EventArgs e)
        {
            bool ok = false;

            Cursor = Cursors.WaitCursor;
            try
            {
                ok = db.CreateDatabase(tbFileName.Text, tbPassword.Text.Trim(), (Version)cbVersion.SelectedItem);
                if (ok)
                {
                    GlobalText.ShowInfo("CreateDone");
                }
                else
                {
                    GlobalText.ShowError("CreateError", db.LastError);
                }
            }
            catch (Exception ex)
            {
                GlobalText.ShowError("CreateError", ex.Message);
            }
            Cursor = Cursors.Default;

            if (ok)
            {
                LoadDatabase(tbFileName.Text, tbPassword.Text.Trim());
            }
            SetActiveButtons();
        }
コード例 #3
0
        private void btVerify_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            try
            {
                if (db.Verify(tbFileName.Text, tbPassword.Text.Trim()))
                {
                    GlobalText.ShowInfo("VerifyDone");
                }
                else if (db.LastError == "")
                {
                    GlobalText.ShowError("VerifyFault");
                }
                else
                {
                    GlobalText.ShowError("VerifyError", db.LastError);
                }
            }
            catch (Exception ex)
            {
                GlobalText.ShowError("VerifyError", ex.Message);
            }
            db.Close();
            this.Cursor = Cursors.Default;

            LoadDatabase(tbFileName.Text, tbPassword.Text.Trim());
        }
コード例 #4
0
        private void btShrink_Click(object sender, EventArgs e)
        {
            if (!CreateBackup())
            {
                return;
            }

            bool ok = false;

            Cursor = Cursors.WaitCursor;
            try
            {
                ok = db.Shrink(tbFileName.Text, openPassword, tbPassword.Text.Trim());
                if (ok)
                {
                    GlobalText.ShowInfo("ShrinkDone");
                }
                else
                {
                    GlobalText.ShowError("ShrinkError", db.LastError);
                }
            }
            catch (Exception ex)
            {
                GlobalText.ShowError("ShrinkError", ex.Message);
            }
            Cursor = Cursors.Default;

            if (ok)
            {
                LoadDatabase(tbFileName.Text, tbPassword.Text.Trim());
            }
            SetActiveButtons();
        }
コード例 #5
0
        /// <summary>
        /// Open the specified database file
        /// </summary>
        /// <param name="databaseFile">Database file name to open</param>
        /// <param name="password">Password of database file</param>
        public bool Open(string databaseFile, string password)
        {
            Close();
            FileName = Path.GetFullPath(databaseFile);
            Password = password;

            bool    ok      = false;
            Version version = GetSdfVersion(FileName);

            if (version == null)
            {
                foreach (Version ver in AvailableVersions.Reverse <Version>())
                {
                    ok = OpenConnection(ver, databaseFile, password);
                    if (ok || BadPassword)
                    {
                        break;
                    }
                }
            }
            else
            {
                ok = OpenConnection(version, databaseFile, password);
                if (!ok && (!BadPassword || password != null))
                {
                    GlobalText.ShowError("UnableToOpen", LastError);
                }
            }
            return(ok);
        }
コード例 #6
0
 private void SetCultureTexts()
 {
     this.Text      = GlobalText.GetValue("Tools");
     groupBox1.Text = GlobalText.GetValue("Database");
     label1.Text    = GlobalText.GetValue("FileName") + ":";
     label2.Text    = GlobalText.GetValue("Password") + ":";
     label4.Text    = GlobalText.GetValue("Version") + ":";
     toolTip2.SetToolTip(tbFileName, GlobalText.GetValue("FileNameTip"));
     toolTip2.SetToolTip(tbPassword, GlobalText.GetValue("PasswordTip"));
     toolTip2.SetToolTip(btSelect, GlobalText.GetValue("SelectTip"));
     label5.Text    = GlobalText.GetValue("UpgradeToVersion") + ":";
     groupBox2.Text = GlobalText.GetValue("Action");
     btCreate.Text  = GlobalText.GetValue("Create");
     btCompact.Text = GlobalText.GetValue("Compact");
     btRepair.Text  = GlobalText.GetValue("Repair");
     btShrink.Text  = GlobalText.GetValue("Shrink");
     btUpgrade.Text = GlobalText.GetValue("Upgrade");
     btVerify.Text  = GlobalText.GetValue("Verify");
     toolTip1.SetToolTip(btCreate, GlobalText.GetValue("CreateTip"));
     toolTip1.SetToolTip(btCompact, GlobalText.GetValue("CompactTip"));
     toolTip1.SetToolTip(btRepair, GlobalText.GetValue("RepairTip"));
     toolTip1.SetToolTip(btShrink, GlobalText.GetValue("ShrinkTip"));
     toolTip1.SetToolTip(btUpgrade, GlobalText.GetValue("UpgradeTip"));
     toolTip1.SetToolTip(btVerify, GlobalText.GetValue("VerifyTip"));
     label3.Text  = GlobalText.GetValue("ToolsNote");
     btClose.Text = GlobalText.GetValue("Close");
 }
コード例 #7
0
ファイル: MainForm.cs プロジェクト: olejorgensen/CompactView
        private DataTable DatabaseInfoLocale(DataTable table)
        {
            if (table.Columns.Count != 2)
            {
                return(table);
            }

            table.Columns[0].ColumnName = GlobalText.GetValue("Property");
            table.Columns[1].ColumnName = GlobalText.GetValue("Value");

            foreach (DataRow row in table.Rows)
            {
                string key = row[0].ToString().Replace(" ", string.Empty);
                string s   = GlobalText.GetValue(key);
                if (!string.IsNullOrEmpty(s))
                {
                    row[0] = s;
                }
                if (key == "CaseSensitive")
                {
                    s = GlobalText.GetValue(row[1].ToString());
                    if (!string.IsNullOrEmpty(s))
                    {
                        row[1] = s;
                    }
                }
            }
            return(table);
        }
コード例 #8
0
 private void SetCultureTexts()
 {
     Text           = GlobalText.GetValue("Import");
     btnImport.Text = GlobalText.GetValue("Import");
     cbSchema.Text  = GlobalText.GetValue("Schema");
     cbData.Text    = GlobalText.GetValue("Data");
 }
コード例 #9
0
        private void treeDb_BeforeCheck(object sender, TreeViewCancelEventArgs e)
        {
            if (e.Node.Parent == null || !e.Node.Checked)
            {
                return;
            }
            TreeNode[] nodes = treeDb.Nodes.Find(e.Node.Parent.Text + "@" + e.Node.Text, true);
            if (nodes.Length <= 0 || nodes[0].Parent == null)
            {
                return;
            }

            bool used = false;

            for (int i = 0; i < nodes.Length; i++)
            {
                if (nodes[i].Checked)
                {
                    used = true;
                }
            }
            if (!used)
            {
                return;
            }

            string txt = string.Format("[{0}]-[{1}] {2}{3}[{4}]-[{5}].",
                                       e.Node.Parent.Text, e.Node.Text, GlobalText.GetValue("UsedAsAForeignKey"), Environment.NewLine, nodes[0].Parent.Text, nodes[0].Text);

            GlobalText.ShowWarning(txt);
        }
コード例 #10
0
        private void treeDb_BeforeCheck(object sender, TreeViewCancelEventArgs e)
        {
            if (e.Node.Parent == null || !e.Node.Checked)
            {
                return;
            }
            TreeNode[] nodes = treeDb.Nodes.Find($"{e.Node.Parent.Text}@{e.Node.Text}", true);
            if (nodes.Length <= 0 || nodes[0].Parent == null)
            {
                return;
            }

            bool used = false;

            for (int i = 0; i < nodes.Length; i++)
            {
                if (nodes[i].Checked)
                {
                    used = true;
                }
            }
            if (!used)
            {
                return;
            }

            string txt = $"[{e.Node.Parent.Text}]-[{e.Node.Text}] {GlobalText.GetValue("UsedAsAForeignKey")}{Environment.NewLine}[{nodes[0].Parent.Text}]-[{nodes[0].Text}].";

            GlobalText.ShowWarning(txt);
        }
コード例 #11
0
        private void btUpgrade_Click(object sender, EventArgs e)
        {
            if (!CreateBackup())
            {
                return;
            }

            bool ok = false;

            this.Cursor = Cursors.WaitCursor;
            try
            {
                ok = db.Upgrade(tbFileName.Text, openPassword, tbPassword.Text.Trim(), (Version)cbUpgradeTo.SelectedItem);
                if (ok)
                {
                    GlobalText.ShowInfo("UpgradeDone");
                }
                else
                {
                    GlobalText.ShowError("UpgradeError", db.LastError);
                }
            }
            catch (Exception ex)
            {
                GlobalText.ShowError("UpgradeError", ex.Message);
            }
            this.Cursor = Cursors.Default;

            if (ok)
            {
                LoadDatabase(tbFileName.Text, tbPassword.Text.Trim());
            }
            SetActiveButtons();
        }
コード例 #12
0
        private bool CreateBackup()
        {
            if (string.IsNullOrEmpty(db.FileName))
            {
                GlobalText.ShowError("NoDatabaseSelect");
                return(false);
            }

            if (!File.Exists(db.FileName))
            {
                GlobalText.ShowError("DatabaseMissing");
                return(false);
            }

            string backupFile = "";
            int    i          = 1;

            try
            {
                while (File.Exists(backupFile = Path.ChangeExtension(db.FileName, "." + i.ToString("0000") + Path.GetExtension(db.FileName))))
                {
                    i++;
                }
                File.Copy(db.FileName, backupFile);
                return(true);
            }
            catch (Exception ex)
            {
                GlobalText.ShowError("BackupError", ex.Message);
                return(false);
            }
        }
コード例 #13
0
 private void SetCultureTexts()
 {
     this.Text      = GlobalText.GetValue("Export");
     btnExport.Text = GlobalText.GetValue("Export");
     rbAll.Text     = GlobalText.GetValue("All");
     rbSchema.Text  = GlobalText.GetValue("OnlySchema");
     rbData.Text    = GlobalText.GetValue("OnlyData");
 }
コード例 #14
0
        private void btnExecute_Click(object sender, EventArgs e)
        {
            if (rtbQuery.Text.Trim().Length == 0)
            {
                return;
            }
            bool partial = rtbQuery.SelectedText.Trim().Length > 0;

            if (partial)
            {
                DialogResult result = MessageBox.Show(GlobalText.GetValue("SelectedTextQuery"), GlobalText.GetValue("Confirm"),
                                                      MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
                if (result == DialogResult.Cancel)
                {
                    return;
                }
                partial = result == DialogResult.Yes;
            }
            string sql = partial ? rtbQuery.SelectedText.Trim() : rtbQuery.Text.Trim();

            dataGrid.DataSource = null;

            // Initial time
            DateTime initTime = DateTime.Now;

            object resultSet = db.ExecuteSql(sql, false);

            long ms = (long)(DateTime.Now - initTime).TotalMilliseconds;

            dataGrid.DataSource = resultSet;

            if (resultSet != null || string.IsNullOrEmpty(db.LastError))
            {
                lbResult.ForeColor = Color.Black;
                lbResult.Text      = string.Format("{0} {1}, {2} {3}, {4} {5}", db.QueryCount, GlobalText.GetValue("Querys"), dataGrid.RowCount,
                                                   GlobalText.GetValue("Rows"), ms, GlobalText.GetValue("Milliseconds"));
                if (resultSet == null && regexCreateAlterDrop.IsMatch(regexDropQuotesAndBrackets.Replace(rtbQuery.Text, "")))
                {
                    db.ResetDdl();  // Update DDL
                    UpdateTreeDb();
                }
                else
                {
                    tabControl1.SelectedIndex = 0;
                    if (resultSet == null && regexInsertUpdateDelete.IsMatch(regexDropQuotesAndBrackets.Replace(rtbQuery.Text, "")))
                    {
                        TreeNode node = treeDb.SelectedNode;  // Update data view
                        treeDb.SelectedNode = null;
                        treeDb.SelectedNode = node;
                    }
                }
            }
            else
            {
                lbResult.ForeColor = Color.Red;
                lbResult.Text      = db.LastError;
            }
        }
コード例 #15
0
ファイル: MainForm.cs プロジェクト: olejorgensen/CompactView
        /// <summary>
        /// Load database with password
        /// </summary>
        /// <param name="fileName">Database file name</param>
        /// <param name="password">Database password</param>
        private void LoadDatabase(string fileName, string password)
        {
            Reset();

            try
            {
                if (!File.Exists(fileName))
                {
                    throw new Exception($"{GlobalText.GetValue("FileNotFound")}: '{fileName}'");
                }

                Cursor = Cursors.WaitCursor;

                if (db.Open(fileName, password))
                {
                    Text = string.Concat(formText, " - ", db.FileName);

                    // Fill tree with database name and table names
                    treeDb.BeginUpdate();
                    treeDb.Nodes.Clear();
                    TreeNode main = treeDb.Nodes.Add("Database", Path.GetFileNameWithoutExtension(fileName), 0, 0);
                    foreach (string tableName in db.TableNames)
                    {
                        main.Nodes.Add(tableName, tableName, 1, 1);
                    }
                    main.Expand();
                    treeDb.EndUpdate();
                    treeDb.SelectedNode = treeDb.Nodes[0];
                    settings.AddToRecentFiles(fileName);
                    UpdateRecentFilesMenu();
                }
                else
                {
                    bool badPassword = db.BadPassword;
                    Reset();
                    if (badPassword)
                    {
                        var form = new GetPassForm();
                        if (form.ShowDialog() == DialogResult.OK)
                        {
                            LoadDatabase(fileName, form.edPass.Text.Trim());
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                GlobalText.ShowError("UnableToOpen", ex.Message);
                btnQuery.Enabled = btnExecute.Enabled = btnClear.Enabled = false;
                settings.RemoveFromRecentFiles(fileName);
                UpdateRecentFilesMenu();
            }
            Cursor = Cursors.Default;

            UpdateStatus();
        }
コード例 #16
0
ファイル: MainForm.cs プロジェクト: olejorgensen/CompactView
 private void SetCultureTexts()
 {
     btnOpen.Text                       = GlobalText.GetValue("OpenDatabase");
     cbReadOnly.Items[0]                = GlobalText.GetValue("ReadOnly");
     cbReadOnly.Items[1]                = GlobalText.GetValue("AllowEditing");
     btnQuery.Text                      = GlobalText.GetValue("Query");
     btnExecute.Text                    = GlobalText.GetValue("Execute");
     btnClear.Text                      = GlobalText.GetValue("Clear");
     btnCut.Text                        = GlobalText.GetValue("Cut");
     btnCopy.Text                       = GlobalText.GetValue("Copy");
     btnPaste.Text                      = GlobalText.GetValue("Paste");
     tabControl1.TabPages[0].Text       = GlobalText.GetValue("Data");
     tabControl1.TabPages[1].Text       = GlobalText.GetValue("SqlSchema");
     lbResult.Text                      = GlobalText.GetValue("QueryNote");
     cutToolStripMenuItem.Text          = GlobalText.GetValue("Cut");
     copyToolStripMenuItem.Text         = GlobalText.GetValue("Copy");
     pasteToolStripMenuItem.Text        = GlobalText.GetValue("Paste");
     loadFromFileToolStripMenuItem.Text = $"{GlobalText.GetValue("LoadFromFile")}...";
     saveToFileToolStripMenuItem.Text   = $"{GlobalText.GetValue("SaveToFile")}...";
     printToolStripMenuItem.Text        = $"{GlobalText.GetValue("Print")}...";
     fileMenuItem.Text                  = GlobalText.GetValue("File");
     openDatabaseMenuItem.Text          = $"{GlobalText.GetValue("OpenDatabase")}...";
     recentFilesMenuItem.Text           = GlobalText.GetValue("RecentFiles");
     allowEditingMenuItem.Text          = GlobalText.GetValue("AllowEditing");
     importMenuItem.Text                = $"{GlobalText.GetValue("Import")}...";
     exportMenuItem.Text                = $"{GlobalText.GetValue("Export")}...";
     exitMenuItem.Text                  = GlobalText.GetValue("Exit");
     editMenuItem.Text                  = GlobalText.GetValue("Edit");
     cutMenuItem.Text                   = GlobalText.GetValue("Cut");
     copyMenuItem.Text                  = GlobalText.GetValue("Copy");
     pasteMenuItem.Text                 = GlobalText.GetValue("Paste");
     deleteMenuItem.Text                = GlobalText.GetValue("Delete");
     queryMenuItem.Text                 = GlobalText.GetValue("Query");
     showEditorMenuItem.Text            = GlobalText.GetValue("ShowEditor");
     executeMenuItem.Text               = GlobalText.GetValue("Execute");
     clearMenuItem.Text                 = GlobalText.GetValue("Clear");
     toolsMenuItem.Text                 = GlobalText.GetValue("Tools");
     databaseToolsMenuItem.Text         = $"{GlobalText.GetValue("DatabaseTools")}...";
     optionsMenuItem.Text               = $"{GlobalText.GetValue("Options")}...";
     helpMenuItem.Text                  = GlobalText.GetValue("Help");
     aboutCompactViewMenuItem.Text      = $"{GlobalText.GetValue("About")} CompactView";
     loadSqlMenuItem.Text               = $"{GlobalText.GetValue("LoadSqlQuery")}...";
     saveSqlMenuItem.Text               = $"{GlobalText.GetValue("SaveSqlQuery")}...";
     saveSchemaMenuItem.Text            = $"{GlobalText.GetValue("SaveSqlSchema")}...";
     closeDatabaseMenuItem.Text         = GlobalText.GetValue("CloseDatabase");
     printMenuItem.Text                 = $"{GlobalText.GetValue("Print")}...";
     previewMenuItem.Text               = GlobalText.GetValue("Preview");
 }
コード例 #17
0
 private void SetCultureTexts()
 {
     this.Text      = GlobalText.GetValue("Options");
     groupBox1.Text = GlobalText.GetValue("Colors");
     label6.Text    = GlobalText.GetValue("FontColor");
     label5.Text    = GlobalText.GetValue("BackgroundColor");
     label1.Text    = GlobalText.GetValue("Line") + " 1";
     label2.Text    = GlobalText.GetValue("Line") + " 2";
     label3.Text    = GlobalText.GetValue("Line") + " 3";
     label4.Text    = GlobalText.GetValue("Line") + " 4";
     label7.Text    = GlobalText.GetValue("ColorSet") + ":";
     cbColorSet.Items[cbColorSet.Items.Count - 1] = GlobalText.GetValue("UserDefined");
     groupBox2.Text = GlobalText.GetValue("UserDefined");
     btnOk.Text     = GlobalText.GetValue("Ok");
     btnCancel.Text = GlobalText.GetValue("Cancel");
 }
コード例 #18
0
        public object ExecuteSql(string sql, bool updatable)
        {
            if (Connection == null)
            {
                return(null);
            }

            if (Connection.State == ConnectionState.Closed)
            {
                Connection.Open();
            }

            LastError = string.Empty;

            object           command  = assembly.CreateInstance("System.Data.SqlServerCe.SqlCeCommand", false, BindingFlags.CreateInstance, null, new object[] { null, Connection }, null, null);
            var              enumType = assembly.GetType("System.Data.SqlServerCe.ResultSetOptions");
            ResultSetOptions options  = updatable ? ResultSetOptions.Scrollable | ResultSetOptions.Updatable : ResultSetOptions.Scrollable;

            object result = null;

            QueryCount = 0;

            for (Match m = regexSemicolon.Match(sql); m.Success; m = m.NextMatch())
            {
                if (!string.IsNullOrWhiteSpace(m.Value))
                {
                    QueryCount++;
                    try
                    {
                        command.GetType().InvokeMember("CommandText", BindingFlags.SetProperty, null, command, new object[] { m.Value.Trim() });
                        object resultset  = command.GetType().GetMethod("ExecuteResultSet", new Type[] { enumType }, null).Invoke(command, new object[] { options });
                        bool   scrollable = (bool)resultset.GetType().InvokeMember("Scrollable", BindingFlags.GetProperty, null, resultset, null);
                        if (scrollable)
                        {
                            result = resultset;
                        }
                    }
                    catch (Exception e)
                    {
                        LastError = $"{GlobalText.GetValue("Query")} {QueryCount}: {(e.InnerException == null ? e.Message : e.InnerException.Message)}";
                        return(null);
                    }
                }
            }

            return(result);
        }
コード例 #19
0
        public AboutBox1()
        {
            InitializeComponent();
            this.Text               = String.Format("{0} {1}", GlobalText.GetValue("About"), AssemblyTitle);
            labelProductName.Text   = AssemblyProduct;
            labelVersion.Text       = String.Format("{0} {1}", GlobalText.GetValue("Version"), AssemblyVersion);
            labelCopyright.Text     = AssemblyCopyright;
            textBoxDescription.Text = GlobalText.GetValue("AboutDescription");
            okButton.Text           = GlobalText.GetValue("Ok");
            labelLanguage.Text      = Thread.CurrentThread.CurrentUICulture.Name;
            string s = GlobalText.GetValue("TranslationInfo");

            labelTranslationInfo.Text = s + ".";
            if (s == "English translation by Iván Costales Suárez (CompactView)")
            {
                tableLayoutPanel.RowStyles[5].Height = 0;
            }
        }
コード例 #20
0
 public static void ShowWarning(string warningMsg)
 {
     MessageBox.Show(warningMsg, GlobalText.GetValue("Warning"), MessageBoxButtons.OK, MessageBoxIcon.Warning);
 }
コード例 #21
0
ファイル: MainForm.cs プロジェクト: olejorgensen/CompactView
 private void dataGrid_DataError(object sender, DataGridViewDataErrorEventArgs e)
 {
     // Error when show/edit field
     GlobalText.ShowError("ChangingDataError", e.Exception.Message);
     e.Cancel = true;
 }
コード例 #22
0
        private void btnImport_Click(object sender, EventArgs e)
        {
            bool anyTableExists  = false;
            bool allTablesExists = true;

            foreach (TreeNode node in treeDb.Nodes)
            {
                if (node.Checked)
                {
                    bool exists = db.TableNames.Contains(node.Text, StringComparer.InvariantCultureIgnoreCase);
                    if (exists)
                    {
                        anyTableExists = true;
                    }
                    else
                    {
                        allTablesExists = false;
                    }
                }
            }

            if (cbSchema.Checked && anyTableExists)
            {
                GlobalText.ShowError("ErrorImportingTablesSchema");
                DialogResult = DialogResult.Abort;
                return;
            }

            if (cbData.Checked && !cbSchema.Checked && !allTablesExists)
            {
                GlobalText.ShowError("ErrorImportingTablesData");
                DialogResult = DialogResult.Abort;
                return;
            }

            FilterDdl();

            toolStripProgressBar1.Value   = 0;
            toolStripProgressBar1.Maximum = ddl.Count;
            DbCommand cmd = db.Connection.CreateCommand();

            cmd.CommandType = CommandType.Text;

            try
            {
                foreach (string sql in ddl)
                {
                    toolStripProgressBar1.Increment(1);
                    cmd.CommandText = sql;
                    cmd.ExecuteNonQuery();
                }
                GlobalText.ShowInfo("ImportOk");
                DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                string sql = cmd.CommandText.Length <= 500 ? cmd.CommandText : $"{cmd.CommandText.Remove(500)}...";
                GlobalText.ShowError("ImportError", ex.Message + Environment.NewLine + Environment.NewLine + sql);
                DialogResult = DialogResult.Abort;
            }
        }
コード例 #23
0
        private void FillTreeDb(string fileName)
        {
            bool   schema   = false;
            bool   data     = false;
            bool   ok       = false;
            string cmdError = null;

            treeDb.Nodes.Clear();
            treeDb.BeginUpdate();
            var reader = new StreamReader(fileName);

            ddl = new List <string>();
            // Regular expression to search texts finished with semicolons that is not between single quotes
            for (Match m = Regex.Match(reader.ReadToEnd(), @"(?:[^;']|'[^']*')+;\s*", RegexOptions.Compiled); m.Success; m = m.NextMatch())
            {
                ddl.Add(m.Value.TrimEnd('\r', '\n'));
            }

            RegexOptions options          = RegexOptions.Compiled | RegexOptions.Singleline | RegexOptions.IgnoreCase;
            var          regexCreateTable = new Regex(@"(?<=^CREATE\s+TABLE\s+\[)[^\]]*(?=\]\s+\([^\)]*\))", options);
            var          regexInsert      = new Regex(@"(?<=^INSERT\s+INTO\s+\[)[^\]]*(?=\]\s+\([^\)]*\)\s+VALUES\s+\([^\)]*\))", options);
            var          regexAlterTable  = new Regex(@"^ALTER\s+TABLE\s+\[", options);
            var          regexCreateIndex = new Regex(@"^CREATE\s+.*INDEX\s+", options);
            var          regexSetIdentity = new Regex(@"^SET\s+IDENTITY_INSERT\s+\[", options);

            for (int i = 0; i < ddl.Count; i++)
            {
                ok = false;
                Match match1 = regexCreateTable.Match(ddl[i]);
                if (match1.Success)
                {
                    treeDb.Nodes.Add(match1.Value, match1.Value, 0, 0).Checked = true;
                    schema = true;
                    ok     = true;
                }
                Match match2 = regexInsert.Match(ddl[i]);
                if (match2.Success)
                {
                    if (!treeDb.Nodes.ContainsKey(match2.Value))
                    {
                        treeDb.Nodes.Add(match2.Value, match2.Value, 0, 0).Checked = true;
                    }
                    data = true;
                    ok   = true;
                }
                if (!ok)
                {
                    if (regexAlterTable.IsMatch(ddl[i]) | regexCreateIndex.IsMatch(ddl[i]) | regexSetIdentity.IsMatch(ddl[i]))
                    {
                        ok = true;
                    }
                    if (!ok)
                    {
                        cmdError = ddl[i].Length <= 500 ? ddl[i] : $"{ddl[i].Remove(500)}...";
                        break;
                    }
                }
            }

            treeDb.EndUpdate();
            treeDb.ExpandAll();
            cbSchema.Enabled = cbSchema.Checked = schema;
            cbData.Enabled   = cbData.Checked = data;

            if (!ok)
            {
                GlobalText.ShowError("ImportFormatError", cmdError);
                abort = true;
            }
        }
コード例 #24
0
        public static void ShowError(string key, string additionalMsg)
        {
            string errorText = string.IsNullOrEmpty(additionalMsg) ? GlobalText.GetValue(key) : GlobalText.GetValue(key) + ":\r\n\r\n" + additionalMsg;

            MessageBox.Show(errorText, GlobalText.GetValue("Error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
コード例 #25
0
 public static void ShowInfo(string key)
 {
     MessageBox.Show(GlobalText.GetValue(key), GlobalText.GetValue("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
 }