Esempio n. 1
0
        public ScriptingForm(DBRegistrationClass drc, List <string> script)
        {
            InitializeComponent();
            MdiParent          = FbXpertMainForm.Instance();
            _actScriptingDbReg = drc;
            _lastDirectory     = _actScriptingDbReg.InitialScriptingPath;
            _notifies.Notify.OnRaiseInfoHandler      += MeldungRaised;
            _notifies.Notify.OnRaiseErrorHandler     += ErrorRaised;
            _eventnotifies.Notify.OnRaiseInfoHandler += EventMeldungRaised;
            fcbSQL.Clear();

            fcbSQL.SelectionStart = 0;
            _sql = new SQLScriptingClass(_actScriptingDbReg, "SCRIPT", _notifies, _eventnotifies);
            foreach (string str in script)
            {
                if (!string.IsNullOrEmpty(str))
                {
                    if (str.EndsWith(Environment.NewLine))
                    {
                        this.AppendSql(str);
                    }
                    else
                    {
                        this.AppendSql(str + Environment.NewLine);
                    }
                }
                else
                {
                    this.AppendSql(Environment.NewLine);
                }
            }
        }
Esempio n. 2
0
        private void ExecuteCommandsFromFile(string filename)
        {
            var fi = new FileInfo(filename);

            if (!fi.Exists)
            {
                return;
            }

            var content = new StringBuilder();

            _notifies?.AddToINFO($@"{StaticFunctionsClass.DateTimeNowStr()} Prepare executing script in file {filename}");
            Application.DoEvents();
            var _sql = new SQLScriptingClass(_actScriptingDbReg, "SCRIPT", _notifies, _eventnotifies);

            _sql.ClearCommands();

            int lineCount  = 0;
            int clearAfter = StaticFunctionsClass.ToIntDef(txtClear.Text, 1000);

            fcbCommands.Clear();
            fcbCommands.BeginUpdate();
            content.Clear();
            long mx = fi.Length / 20;

            pbProgress.Maximum = (int)mx;
            pbProgress.Minimum = 0;
            pbProgress.Value   = 0;

            using (var sr = new StreamReader(fi.FullName, Encoding.Default))
            {
                if (pbProgress.Maximum >= pbProgress.Minimum)
                {
                    pbProgress.Value = 0;
                }
                var startDt = DateTime.Now;
                while (!sr.EndOfStream)
                {
                    string str     = sr.ReadLine();
                    bool   cmdeady = _sql.AddCommandLine($@"{str}{Environment.NewLine}");
                    if (!cmdeady)
                    {
                        continue;
                    }
                    lineCount++;
                    var returnList = _sql.RunPreparedCommands();
                    _sql.ClearCommands();
                }
                fcbCommands.EndUpdate();
                Cursor = Cursors.Default;
                _notifies?.AddToINFO($@"{StaticFunctionsClass.DateTimeNowStr()} Preparing done {lineCount.ToString()} commands");
                Application.DoEvents();
            }
        }
Esempio n. 3
0
 public ScriptingForm(DBRegistrationClass drc)
 {
     InitializeComponent();
     MdiParent          = FbXpertMainForm.Instance();
     _actScriptingDbReg = drc;
     _lastDirectory     = _actScriptingDbReg.InitialScriptingPath;
     _notifies.Notify.OnRaiseInfoHandler      += MeldungRaised;
     _notifies.Notify.OnRaiseErrorHandler     += ErrorRaised;
     _eventnotifies.Notify.OnRaiseInfoHandler += EventMeldungRaised;
     fcbSQL.Clear();
     _sql = new SQLScriptingClass(_actScriptingDbReg, "SCRIPT", _notifies, _eventnotifies);
 }
Esempio n. 4
0
        private void Create()
        {
            var _sql      = new SQLScriptingClass(_dbReg, "SCRIPT", _localNotify);
            var riList    = _sql.ExecuteCommands(fctSQL.Lines);
            var riFailure = riList.Find(x => x.commandDone = false);

            string info = (riFailure == null)
                ? $@"Table {_dbReg.Alias}->{_tableObject.Name} updated."
                : $@"Table {_dbReg.Alias}->{_tableObject.Name} not updated !!!{Environment.NewLine}{riFailure.nErrors} errors, last error:{riFailure.lastError}";

            DbExplorerForm.Instance().DbExlorerNotify.Notify.RaiseInfo(info, StaticVariablesClass.ReloadTable, $@"->Proc:{Name}->Create");
            _localNotify.Notify.RaiseInfo(info);
        }
Esempio n. 5
0
 private void PrepareCommandsFromSQL()
 {
     if (cbClearBeforePreparing.Checked)
     {
         _sql = new SQLScriptingClass(_actScriptingDbReg, "SCRIPT", _notifies, _eventnotifies);
         lvCommands.Items.Clear();
     }
     pbProgress.Maximum = fcbSQL.Lines.Count;;
     pbProgress.Minimum = 0;
     pbProgress.Value   = 0;
     _sql.PrepareCommands(fcbSQL.Lines, cbClearBeforePreparing.Checked);
     int clearAfter = StaticFunctionsClass.ToIntDef(txtClear.Text, 1000);
 }
Esempio n. 6
0
        private void hsRunStatement_Click(object sender, EventArgs e)
        {
            var _sql      = new SQLScriptingClass(_dbReg, "SCRIPT", _localNotify);
            var riList    = _sql.ExecuteCommands(fctSQL.Lines);
            var riFailure = riList.Find(x => x.commandDone = false);
            var riOk      = riList.Find(x => x.commandDone = true);
            var sb        = new StringBuilder();

            if (riFailure != null)
            {
                messages_count++;
                if (messages_count > 0)
                {
                    sb.Append($@"Messages ({messages_count}) ");
                }
                if (error_count > 0)
                {
                    sb.Append($@"Errors ({error_count})");
                }
            }

            long costs = 0;

            foreach (var ri in riList)
            {
                if (ri.commandDone)
                {
                    fctMessages.CurrentLineColor = System.Drawing.Color.Blue;
                    fctMessages.AppendText($@"done {ri.lastSQL}");
                }
                else
                {
                    fctMessages.CurrentLineColor = System.Drawing.Color.Red;
                    fctMessages.AppendText($@"not done {ri.lastSQL}");
                }
                costs += ri.costs;
            }

            tabPageMessages.Text = sb.ToString();
            fctMessages.ScrollLeft();
            lblUsedMs.Text = costs.ToString();
        }
Esempio n. 7
0
        private void Create()
        {
            var _sql   = new SQLScriptingClass(_dbReg, "SCRIPT", _localNotify);
            var riList = _sql.ExecuteCommands(fctSQL.Lines);

            var riFailure = riList.Find(x => x.commandDone = false);

            oldIndexName = NewIndexName;
            if (DataFilled)
            {
                MakeSQL();
            }

            string info = (riFailure == null)
                ? $@"Index {_dbReg.Alias}->{NewIndexName} updated."
                : $@"Index {_dbReg.Alias}->{NewIndexName} not updated !!!{Environment.NewLine}{riFailure.nErrors} errors, last error:{riFailure.lastError}";

            DbExplorerForm.Instance().DbExlorerNotify.Notify.RaiseInfo(info, Constants.ReloadIndex, $@"->Proc:{Name}->Create");
            _localNotify.Notify.RaiseInfo(info, Constants.ReloadIndex, $@"->Proc:{Name}->Create");
        }
Esempio n. 8
0
        private void ExecueteSQL()
        {
            var _sql      = new SQLScriptingClass(_dbReg, "SCRIPT", localNotify);
            var riList    = _sql.ExecuteCommands(fctSQL.Lines);
            var riFailure = riList.Find(x => x.commandDone == false);

            EditToObject();
            if (riFailure == null)
            {
                OrgFieldObject = FieldObject.DeepClone();
                BearbeitenMode = StateClasses.EditStateClass.eBearbeiten.eEdit;
                ObjectToEdit(FieldObject);
                MakeSQL();
            }
            string info = (riFailure == null)
                ? $@"Fields for {_dbReg.Alias}->{FieldObject.TableName} updated."
                : $@"Fields for {_dbReg.Alias}->{FieldObject.TableName} not updated !!!{Environment.NewLine}{riFailure.nErrors} errors, last error:{riFailure.lastError}";

            DbExplorerForm.Instance().DbExlorerNotify.Notify.RaiseInfo(info, StaticVariablesClass.ReloadFields, $@"->Proc:{Name}->Create");
            _localTableNotify.Notify.RaiseInfo(info);
        }
Esempio n. 9
0
        private void Create()
        {
            var _sql      = new SQLScriptingClass(_dbReg, "SCRIPT", _localNotify);
            var riList    = _sql.ExecuteCommands(fctSQL.Lines);
            var riFailure = riList.Find(x => x.commandDone = false);

            if (riFailure == null)
            {
                old_constraint_name = txtConstraintName.Name;
            }


            string info = (riFailure == null)
                ? $@"Foreign key for {_dbReg.Alias}->{ForeignKeyObject.SourceTableName} updated."
                : $@"Foreign key for {_dbReg.Alias}->{ForeignKeyObject.SourceTableName} not updated !!!{Environment.NewLine}{riFailure.nErrors} errors, last error:{riFailure.lastError}";

            DbExplorerForm.Instance().DbExlorerNotify.Notify.RaiseInfo(info, StaticVariablesClass.ReloadForeignKeys, $@"->Proc:{Name}->Create");
            _localNotify.Notify.RaiseInfo(info);


            BearbeitenMode = StateClasses.EditStateClass.eBearbeiten.eEdit;
        }
Esempio n. 10
0
        private void RunSingleCommand(SCRIPTCommandClass command)
        {
            _notifies?.AddToINFO($@"{StaticFunctionsClass.DateTimeNowStr()} Executing script command");
            Application.DoEvents();
            var _sql = new SQLScriptingClass(_actScriptingDbReg, "SCRIPT", _notifies);

            _sql.ClearCommands();
            FbConnection fbConn   = null;
            FbCommand    fbCmd    = null;
            bool         connOpen = false;

            if (_actScriptingDbReg.DatabasePath.Length > 0)
            {
                var connstr = ConnectionStrings.Instance().MakeConnectionString(_actScriptingDbReg);
                try
                {
                    fbConn = new FbConnection(connstr);
                    fbConn.Open();
                    connOpen = fbConn.State == System.Data.ConnectionState.Open;
                }
                catch (Exception ex)
                {
                    Enabled = false;
                    object[] param = { ex.Message };
                    SEMessageBox.ShowMDIDialog(FbXpertMainForm.Instance(), "DatabaseExceptionCaption", "ErrorWhileOpeningDatabase", SEMessageBoxButtons.OK, SEMessageBoxIcon.Exclamation, null, param);
                    Enabled = true;
                    BringToFront();
                }
            }

            if (connOpen)
            {
                var sw = new Stopwatch();
                sw.Start();
                FbConnection usedCon = IsCreateDatabaseOrConnect(command.CommandText, fbConn);
                if (usedCon != null)
                {
                    //Create database oder connect database
                    fbConn = usedCon;
                }
                else // kein create oder connect, voreingestellte connetion wird verwended
                {
                    fbCmd             = new FbCommand(command.CommandText, fbConn);
                    fbCmd.Transaction = fbConn.BeginTransaction();
                    try
                    {
                        if (command.CommandType == SQLCommandType.commit)
                        {
                            fbCmd.Transaction.Commit();
                        }
                        else
                        {
                            fbCmd.ExecuteNonQuery();
                            if (fbCmd.Transaction != null)
                            {
                                fbCmd.Transaction.Commit();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        if (fbCmd.Transaction != null)
                        {
                            fbCmd.Transaction.Rollback();
                        }
                        fbCmd.Transaction = null;
                        _notifies?.AddToERROR(AppStaticFunctionsClass.GetFormattedError($@"Command error {fbCmd.CommandText}", ex));
                    }
                }
                if (connOpen)
                {
                    fbConn.Close();
                }
                sw.Stop();
                Cursor = Cursors.Default;
                _notifies?.AddToINFO($@"{StaticFunctionsClass.DateTimeNowStr()} Executing done in {sw} ms");
                Application.DoEvents();
            }
            else
            {
                _notifies?.AddToINFO($@"{StaticFunctionsClass.DateTimeNowStr()} Database {_actScriptingDbReg.Alias} not open ");
                Application.DoEvents();
            }
        }