Exemplo n.º 1
0
        public ScriptingForm(DBRegistrationClass drc, List <string> script)
        {
            InitializeComponent();
            MdiParent          = FbXpertMainForm.Instance();
            _actScriptingDbReg = drc;
            _lastDirectory     = AppSettingsClass.Instance.PathSettings.ScriptingPath;
            _notifies.Register4Info(FormMeldungRaised);
            _notifies.Register4Error(FormErrorRaised);

            fcbSQL.Clear();
            fcbSQL.SelectionStart = 0;
            string _connstr = ConnectionStrings.Instance.MakeConnectionString(_actScriptingDbReg);

            _sql = new DBBasicClassLibrary.SQLScriptingClass(_connstr, AppSettingsClass.Instance.SQLVariables.GetNewLine(), AppSettingsClass.Instance.SQLVariables.CommentStart, AppSettingsClass.Instance.SQLVariables.CommentEnd, AppSettingsClass.Instance.SQLVariables.SingleLineComment, "SCRIPT");
            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);
                }
            }
        }
Exemplo n.º 2
0
        private void Create()
        {
            //var _sql = new SQLScriptingClass(_dbReg,"SCRIPT",_localNotify);
            string _connstr  = ConnectionStrings.Instance.MakeConnectionString(_dbReg);
            var    _sql      = new DBBasicClassLibrary.SQLScriptingClass(_connstr, AppSettingsClass.Instance.SQLVariables.GetNewLine(), AppSettingsClass.Instance.SQLVariables.CommentStart, AppSettingsClass.Instance.SQLVariables.CommentEnd, AppSettingsClass.Instance.SQLVariables.SingleLineComment, "SCRIPT");
            var    riList    = _sql.ExecuteCommands(fctSQL.Lines);
            var    riFailure = riList.Find(x => x.commandDone == false);

            oldIndexColumnName = _indexObject.Name;

            if (_dataFilled)
            {
                MakeSQL();
            }

            AppStaticFunctionsClass.SendResultNotify(riList, _localNotify);


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

            DbExplorerForm.Instance().DbExlorerNotify.Notify.RaiseInfo(info, StaticVariablesClass.ReloadIndex, $@"->Proc:{Name}->Create");
            _localNotify.Notify.RaiseInfo(info, StaticVariablesClass.ReloadIndex, $@"->Proc:{Name}->Create");
        }
Exemplo n.º 3
0
        private void hsRunStatement_Click(object sender, EventArgs e)
        {
            //var _sql = new SQLScriptingClass(_dbReg,"SCRIPT",_localNotify);
            string _connstr  = ConnectionStrings.Instance.MakeConnectionString(_dbReg);
            var    _sql      = new DBBasicClassLibrary.SQLScriptingClass(_connstr, AppSettingsClass.Instance.SQLVariables.GetNewLine(), AppSettingsClass.Instance.SQLVariables.CommentStart, AppSettingsClass.Instance.SQLVariables.CommentEnd, AppSettingsClass.Instance.SQLVariables.SingleLineComment, "SCRIPT");
            var    riList    = _sql.ExecuteCommands(fctSQL.Lines);
            var    riFailure = riList.Find(x => x.commandDone == false);
            var    riOk      = riList.Find(x => x.commandDone == true);
            long   costs     = AppStaticFunctionsClass.SendResultNotify(riList, _localNotify);

            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})");
                }
            }

            tabPageMessages.Text = sb.ToString();
            fctMessages.ScrollLeft();
            lblUsedMs.Text = costs.ToString();
        }
Exemplo n.º 4
0
        private void Create()
        {
            //var _sql = new SQLScriptingClass(_dbReg,"SCRIPT",_localNotify);
            string _connstr  = ConnectionStrings.Instance.MakeConnectionString(_dbReg);
            var    _sql      = new DBBasicClassLibrary.SQLScriptingClass(_connstr, AppSettingsClass.Instance.SQLVariables.GetNewLine(), AppSettingsClass.Instance.SQLVariables.CommentStart, AppSettingsClass.Instance.SQLVariables.CommentEnd, AppSettingsClass.Instance.SQLVariables.SingleLineComment, "SCRIPT");
            var    riList    = _sql.ExecuteCommands(fctSQL.Lines);
            var    riFailure = riList.Find(x => x.commandDone == false);

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

            AppStaticFunctionsClass.SendResultNotify(riList, _localNotify);

            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.ReloadAllForeignKeys, $@"->Proc:{Name}->Create");
            _localNotify.Notify.RaiseInfo(info);


            BearbeitenMode = StateClasses.EditStateClass.eBearbeiten.eEdit;
        }
Exemplo n.º 5
0
        private void ExecueteSQL()
        {
            string _connstr = ConnectionStrings.Instance.MakeConnectionString(_dbReg);
            var    _sql     = new DBBasicClassLibrary.SQLScriptingClass(_connstr, AppSettingsClass.Instance.SQLVariables.GetNewLine(), AppSettingsClass.Instance.SQLVariables.CommentStart, AppSettingsClass.Instance.SQLVariables.CommentEnd, AppSettingsClass.Instance.SQLVariables.SingleLineComment, "SCRIPT");

            //_sql.ScriptNotify.Register4Info(InfoRaised);
            _sql.ScriptNotify.Register4Error(ErrorRaised);

            var riList    = _sql.ExecuteCommands(fctSQL.Lines);
            var riFailure = riList.Find(x => x.commandDone == false);

            EditToData();
            if (riFailure == null)
            {
                OrgFieldObject = FieldObject.DeepClone();
                BearbeitenMode = StateClasses.EditStateClass.eBearbeiten.eEdit;
                ObjectToEdit(FieldObject);
                MakeSQL();
            }
            AppStaticFunctionsClass.SendResultNotify(riList, localNotify);

            string info = (riFailure == null)
                ? $@"Fields for {_dbReg.Alias}->{FieldObject.TableName} updated."
                : $@"Fields for {_dbReg.Alias}->{FieldObject.TableName} not updated !!!{Environment.NewLine}{riFailure.nErrors} errors";

            DbExplorerForm.Instance().DbExlorerNotify.Notify.RaiseInfo(info, StaticVariablesClass.ReloadFields, $@"->Proc:{Name}->ExecueteSQL()");
            _localTableNotify.Notify.RaiseInfo(info, StaticVariablesClass.ReloadFields);
        }
Exemplo n.º 6
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();
            string _connstr = ConnectionStrings.Instance.MakeConnectionString(_actScriptingDbReg);

            _sql = new DBBasicClassLibrary.SQLScriptingClass(_connstr, AppSettingsClass.Instance.SQLVariables.GetNewLine(), AppSettingsClass.Instance.SQLVariables.CommentStart, AppSettingsClass.Instance.SQLVariables.CommentEnd, AppSettingsClass.Instance.SQLVariables.SingleLineComment, "SCRIPT");
            _sql.ScriptNotify.Register4Info(EventMeldungRaised);
            _sql.Commands.Clear();

            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.Commands.Clear();
                }
                fcbCommands.EndUpdate();
                Cursor = Cursors.Default;
                _notifies?.AddToINFO($@"{StaticFunctionsClass.DateTimeNowStr()} Preparing done {lineCount.ToString()} commands");
                Application.DoEvents();
            }
        }
Exemplo n.º 7
0
        private void PrepareCommandsFromFile(string fn)
        {
            string        sql    = File.ReadAllText(fn);
            List <string> sqlarr = new List <string>();

            sqlarr.Add(sql);
            string _connstr = ConnectionStrings.Instance.MakeConnectionString(_actScriptingDbReg);

            _sql = new DBBasicClassLibrary.SQLScriptingClass(_connstr, AppSettingsClass.Instance.SQLVariables.GetNewLine(), AppSettingsClass.Instance.SQLVariables.CommentStart, AppSettingsClass.Instance.SQLVariables.CommentEnd, AppSettingsClass.Instance.SQLVariables.SingleLineComment, "SCRIPT");
            _sql.ScriptNotify.Register4Info(EventMeldungRaised);
            //_sql.PrepareCommands(sqlarr, cbClearBeforePreparing.Checked);
            _sql.ExecuteCommands(sqlarr);
            //int clearAfter = StaticFunctionsClass.ToIntDef(txtClear.Text, 1000);
        }
Exemplo n.º 8
0
        private void ExecueteSQL()
        {
            string _connstr = ConnectionStrings.Instance.MakeConnectionString(DBReg);
            var    _sql     = new DBBasicClassLibrary.SQLScriptingClass(_connstr, AppSettingsClass.Instance.SQLVariables.GetNewLine(), AppSettingsClass.Instance.SQLVariables.CommentStart, AppSettingsClass.Instance.SQLVariables.CommentEnd, AppSettingsClass.Instance.SQLVariables.SingleLineComment, "SCRIPT");

            //_sql.ScriptNotify.Register4Info(InfoRaised);
            _sql.ScriptNotify.Register4Error(ErrorRaised);

            var riList    = _sql.ExecuteCommands(fctSQL.Lines);
            var riFailure = riList.Find(x => x.commandDone == false);

            AppStaticFunctionsClass.SendResultNotify(riList, _localNotify);

            _localNotify.Notify.RaiseInfo("info", StaticVariablesClass.ReloadFields);
            RefreshUsers();
        }
Exemplo n.º 9
0
        private void PrepareCommandsFromSQL()
        {
            string _connstr = ConnectionStrings.Instance.MakeConnectionString(_actScriptingDbReg);

            _sql = new DBBasicClassLibrary.SQLScriptingClass(_connstr, AppSettingsClass.Instance.SQLVariables.GetNewLine(), AppSettingsClass.Instance.SQLVariables.CommentStart, AppSettingsClass.Instance.SQLVariables.CommentEnd, AppSettingsClass.Instance.SQLVariables.SingleLineComment, "SCRIPT");
            _sql.ScriptNotify.Register4Info(EventMeldungRaised);
            if (cbClearBeforePreparing.Checked)
            {
                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);
        }
Exemplo n.º 10
0
        public ScriptingForm(DBRegistrationClass drc)
        {
            InitializeComponent();
            MdiParent          = FbXpertMainForm.Instance();
            _actScriptingDbReg = drc;
            _lastDirectory     = AppSettingsClass.Instance.PathSettings.ScriptingPath;
            _notifies.Register4Info(FormMeldungRaised);
            _notifies.Register4Error(FormErrorRaised);

            fcbSQL.Clear();
            fcbSQL.SelectionStart = 0;
            string _connstr = ConnectionStrings.Instance.MakeConnectionString(_actScriptingDbReg);

            _sql = new DBBasicClassLibrary.SQLScriptingClass(_connstr, AppSettingsClass.Instance.SQLVariables.GetNewLine(), AppSettingsClass.Instance.SQLVariables.CommentStart, AppSettingsClass.Instance.SQLVariables.CommentEnd, AppSettingsClass.Instance.SQLVariables.SingleLineComment, "SCRIPT");
            _sql.ScriptNotify.Register4Info(EventMeldungRaised);
        }
Exemplo n.º 11
0
        private void Create()
        {
            string _connstr = ConnectionStrings.Instance.MakeConnectionString(_dbReg);
            var    _sql     = new DBBasicClassLibrary.SQLScriptingClass(_connstr, AppSettingsClass.Instance.SQLVariables.GetNewLine(), AppSettingsClass.Instance.SQLVariables.CommentStart, AppSettingsClass.Instance.SQLVariables.CommentEnd, AppSettingsClass.Instance.SQLVariables.SingleLineComment, "SCRIPT");

            var riList    = _sql.ExecuteCommands(fctSQL.Lines);
            var riFailure = riList.Find(x => x.commandDone == false);

            AppStaticFunctionsClass.SendResultNotify(riList, _localNotify);

            string info = (riFailure == null)
                ? $@"Domain {_dbReg.Alias}->{DomainObject.Name} updated."
                : $@"Domain {_dbReg.Alias}->{DomainObject.Name} not updated !!!{Environment.NewLine}{riFailure.nErrors} errors";

            //DbExplorerForm.Instance().DbExlorerNotify.Notify.RaiseInfo(info,StaticVariablesClass.ReloadDomains,$@"->Proc:{Name}->Create");
            _localNotify.Notify.RaiseInfo(info);
            EditToData();
        }
Exemplo n.º 12
0
        private void Create()
        {
            //var _sql = new SQLScriptingClass(_dbReg,"SCRIPT",_localNotify);

            string _connstr = ConnectionStrings.Instance.MakeConnectionString(_dbReg);
            var    _sql     = new DBBasicClassLibrary.SQLScriptingClass(_connstr, AppSettingsClass.Instance.SQLVariables.GetNewLine(), AppSettingsClass.Instance.SQLVariables.CommentStart, AppSettingsClass.Instance.SQLVariables.CommentEnd, AppSettingsClass.Instance.SQLVariables.SingleLineComment, "SCRIPT");
            var    riList   = _sql.ExecuteCommands(fctSQL.Lines);

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

            AppStaticFunctionsClass.SendResultNotify(riList, _localNotify);

            string info = (riFailure == null)
                ? $@"NotNull {_dbReg.Alias}->Field:{cbFields.Text}->NOT NULL Constraint:{txtConstraintName.Text} updated."
                : $@"NotNull {_dbReg.Alias}->Field:{cbFields.Text}->NOT NULL Constraint {txtConstraintName.Text} not updated !!!{Environment.NewLine}{riFailure.nErrors} errors, last error:{riFailure.lastError}";

            DbExplorerForm.Instance().DbExlorerNotify.Notify.RaiseInfo(info, StaticVariablesClass.ReloadConstraits, $@"->Proc:{Name}->Create");
            _localNotify.Notify.RaiseInfo(info);
        }
Exemplo n.º 13
0
        private void RunSingleCommand(DBBasicClassLibrary.SCRIPTCommandClass command)
        {
            _notifies?.AddToINFO($@"{StaticFunctionsClass.DateTimeNowStr()}->{command.CommandType}->Executing");
            Application.DoEvents();

            string _connstr = ConnectionStrings.Instance.MakeConnectionString(_actScriptingDbReg);

            _sql = new DBBasicClassLibrary.SQLScriptingClass(_connstr, AppSettingsClass.Instance.SQLVariables.GetNewLine(), AppSettingsClass.Instance.SQLVariables.CommentStart, AppSettingsClass.Instance.SQLVariables.CommentEnd, AppSettingsClass.Instance.SQLVariables.SingleLineComment, "SCRIPT");
            _sql.ScriptNotify.Register4Info(ScriptInfoRaised);
            _sql.ScriptNotify.Register4Error(ScriptErrorRaised);
            _sql.Commands.Clear();
            FbConnection fbConn   = null;
            FbCommand    fbCmd    = null;
            bool         connOpen = false;

            if (_actScriptingDbReg.DatabasePath.Length > 0)
            {
                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()}->{command.CommandType}->done in {sw.ElapsedMilliseconds} ms");
                Application.DoEvents();
            }
            else
            {
                _notifies?.AddToINFO($@"{StaticFunctionsClass.DateTimeNowStr()} Database {_actScriptingDbReg.Alias} not open ");
                Application.DoEvents();
            }
        }