private void Connect() { string _funcStr = "Connect()"; pnlConnectState.BackColor = System.Drawing.Color.Yellow; Application.DoEvents(); //EditToData(); string lfText = string.Empty; try { lfText = (rb25_32.Checked || rb25_64.Checked) ? AppStaticFunctionsClass.GetLifetime(txtConnectionString.Text, false) : AppStaticFunctionsClass.GetLifetime(txtConnectionString.Text, true); pnlConnectState.BackColor = System.Drawing.Color.Green; } catch (Exception ex) { NotifiesClass.Instance.AddToERROR(AppStaticFunctionsClass.GetFormattedError($@"{ex.Message}->{_funcStr}", ex), _funcStr); lfText = "-1"; } if (lfText == "-1") { pnlConnectState.BackColor = System.Drawing.Color.Red; } txtLifetime.Text = lfText; }
private void hsSaveSourceCodes_Click(object sender, EventArgs e) { var items = selDBObjects.CheckedItemDatas; pbExport.Minimum = 0; pbExport.Value = 0; pbExport.Maximum = items.Count; if (ckDeleteOldSourceFiles.Checked) { string[] files = Directory.GetFiles(txtSourceCodePath.Text); foreach (string file in files) { try { File.Delete($@"{file}"); } catch (Exception ex) { } } } var gsource = MakeGlobalCode(); try { var fi = new FileInfo(txtSourceCodePath.Text + "\\DBGlobalFunctionsClass.cs"); if (fi.Directory != null && fi.Directory.Exists) { File.WriteAllText(txtSourceCodePath.Text + "\\DBGlobalFunctionsClass.cs", gsource); } } catch (Exception ex) { _localNotify?.AddToERROR(AppStaticFunctionsClass.GetFormattedError($@"hsSaveSourceCodes_Click", ex)); } foreach (var itm in items) { var source = itm.Text.StartsWith("Cb") ? MakeCbSourceCode(itm.Object) : MakeSourceCode(itm.Object); try { var fi = new FileInfo(txtSourceCodePath.Text + "\\" + itm.Text + "Class.cs"); if (fi.Directory != null && fi.Directory.Exists) { File.WriteAllText(txtSourceCodePath.Text + "\\" + itm.Text + "Class.cs", source); } } catch (Exception ex) { _localNotify?.AddToERROR(AppStaticFunctionsClass.GetFormattedError($@"hsSaveSourceCodes_Click", ex)); } pbExport.Value++; gbExportProgress.Text = LanguageClass.Instance().GetString("PROGRESS") + $@" ({pbExport.Value}/{pbExport.Maximum})"; Application.DoEvents(); } }
private void LoadUserDesign() { _ss.SharedFolder = ApplicationPathClass.Instance.GetFullPath(Application.UserAppDataPath); _ss.StorageName = Name; _ss.DestroyWhenDisposed = false; try { var mw2 = (MerkeWerte)_ss[Name]; if (mw2 == null) { return; } _mw = mw2; AddCbXMLFileText(_mw.XmlDataFileName); if (!string.IsNullOrEmpty(_mw.XmlDataFileName)) { fctXML.OpenFile(_mw.XmlDataFileName); } AddCbXSDFileText(_mw.XsdSchemaFileName); if (!string.IsNullOrEmpty(_mw.XsdSchemaFileName)) { fctXSD.OpenFile(_mw.XsdSchemaFileName); } AddCbReportFileText(_mw.ReportFileName); if (!string.IsNullOrEmpty(_mw.ReportFileName)) { fctFRX.OpenFile(_mw.ReportFileName); } foreach (ReportSqlCommands scmd in _mw.SqlCommands) { AddItem(scmd.cmd, scmd.caption); } if (lvCreateStatements.Items.Count > 0) { lvCreateStatements.Items[0].Selected = true; } } catch (Exception ex) { _notifies?.AddToERROR(AppStaticFunctionsClass.GetFormattedError($@"{Name}-> LoadUserDesign()", ex)); } }
public SQLCommandsReturnInfoClass ExecSql(string cmd, DBRegistrationClass DBReg, NotifiesClass localNotify) { var SQLcommand = new SQLCommandsClass(DBReg); SQLcommand.SetEncoding("NONE"); var ri = SQLcommand.ExecuteCommand(cmd, true); if (!ri.commandDone) { string errorStr = AppStaticFunctionsClass.GetErrorCodeString(ri.lastError, DBReg); localNotify?.AddToERROR(AppStaticFunctionsClass.GetFormattedError($@"FieldForm->ExecuteCommand", $@"{cmd}->{errorStr}")); } else { localNotify?.AddToINFO(AppStaticFunctionsClass.GetFormattedInfo($@"Command done", cmd)); } return(ri); }
public int RefreshMonitorConnections() { GetConnections(); try { string cmd_index = SQLStatementsClass.Instance.GetMonitorConnections(DBReg.Version, cbAllConnections.Checked); dsMonConnections.Clear(); dgvMonConnections.AutoGenerateColumns = true; var con = new FbConnection(ConnectionStrings.Instance.MakeConnectionString(DBReg)); var ds = new FbDataAdapter(cmd_index, con); ds.Fill(dsMonConnections); con.Close(); bsMonConnections.DataMember = "Table"; return(dsMonConnections.Tables[0].Rows.Count); } catch (Exception ex) { NotifiesClass.Instance.AddToERROR(AppStaticFunctionsClass.GetFormattedError($@"{Name}-> RefreshMonitorConnections()", ex)); } bsMonConnections.DataMember = "Table"; return(dsMonConnections.Tables[0].Rows.Count); }
public List <SQLCommandsReturnInfoClass> RunPreparedCommands() { //var sb = new StringBuilder(); var riList = new List <SQLCommandsReturnInfoClass>(); _parentNotifies?.AddToINFO($@"{StaticFunctionsClass.DateTimeNowStr()} Executing script"); Application.DoEvents(); // int i = 0; int nr = 0; FbConnection fbConn = null; FbCommand fbCmd = null; if (_drc.DatabasePath.Length > 0) { var connstr = ConnectionStrings.Instance().MakeConnectionString(_drc); try { fbConn = new FbConnection(connstr); fbConn.Open(); } catch (Exception ex) { object[] param = { ex.Message }; SEMessageBox.ShowMDIDialog(FbXpertMainForm.Instance(), "DatabaseExceptionCaption", "ErrorWhileOpeningDatabase", SEMessageBoxButtons.OK, SEMessageBoxIcon.Exclamation, null, param); } } if (fbConn.State == System.Data.ConnectionState.Open) { var startDt = DateTime.Now; bool DBRepoend = false; bool ReopenConnectionEachCommand = true; foreach (SCRIPTCommandClass command in this.Commands.Values) { var ri = new SQLCommandsReturnInfoClass(); if (ReopenConnectionEachCommand) { if (fbCmd != null && fbCmd.Transaction != null) { ri.lastSQL = "ReopenDatabase"; try { fbCmd.Transaction.Commit(); fbCmd.Transaction = null; ri.commandDone = true; } catch (Exception ex) { ri.commandDone = false; _parentNotifies?.AddToERROR(AppStaticFunctionsClass.GetFormattedError($@"Command error {fbCmd.CommandText}", ex)); if (fbCmd.Transaction != null) { fbCmd.Transaction.Rollback(); fbCmd.Transaction = null; } } } fbConn.Close(); fbConn.Open(); DBRepoend = fbConn.State == System.Data.ConnectionState.Open; } var actDt = DateTime.Now; if ((actDt.Ticks - startDt.Ticks) > 30000000000) { _parentNotifies?.AddToINFO($@"{StaticFunctionsClass.DateTimeNowStr()} ...Executing script{nr.ToString()} commands done of {Commands.Count}."); } FbConnection usedCon = IsCreateDatabaseOrConnect(command.CommandText, fbConn); if (usedCon != null) { //Create Databes oder connect if (fbConn != null) { if (fbConn.State != System.Data.ConnectionState.Closed) { fbConn.Close(); } } fbConn = usedCon; if (fbConn.State != System.Data.ConnectionState.Open) { fbConn.Open(); } continue; } if (fbCmd == null || fbCmd.Transaction == null || DBRepoend) { fbCmd = new FbCommand(command.CommandText, fbConn); fbCmd.Transaction = fbConn.BeginTransaction(); DBRepoend = false; } else { fbCmd.CommandText = command.CommandText; } var sw = new Stopwatch(); sw.Start(); ri.lastCommandType = command.CommandType; ri.lastSQL = command.CommandText; try { if (command.CommandType == SQLCommandType.commit) { fbCmd.Transaction.Commit(); fbCmd.Transaction = null; } else { fbCmd.ExecuteNonQuery(); } ri.commandDone = true; } catch (Exception ex) { ri.nErrors++; ri.lastError = ex.Message; ri.commandDone = false; _parentNotifies?.AddToERROR(AppStaticFunctionsClass.GetFormattedError($@"Command error {fbCmd.CommandText}", ex)); if (fbCmd.Transaction != null) { fbCmd.Transaction.Rollback(); fbCmd.Transaction = null; } } sw.Stop(); command.Costs = sw.ElapsedMilliseconds; _eventNotifies?.Notify.RaiseInfo($@"SQLScriptingClass.RunPreparedCommands()", Constants.CommandDone, command); ri.costs = sw.ElapsedMilliseconds; riList.Add(ri); nr++; } if (fbCmd != null && fbCmd.Transaction != null) { fbCmd.Transaction.Commit(); fbCmd.Transaction = null; } if (fbConn.State == System.Data.ConnectionState.Open) { fbConn.Close(); } } _parentNotifies?.AddToINFO($@"{StaticFunctionsClass.DateTimeNowStr()} Executing done {nr.ToString()} Commands"); Application.DoEvents(); return(riList); }
private bool CreateDatabase(string sqlCmd) { /* * CREATE DATABASE 'localhost:D:\Data\kj\KJFERT59.FDB' * USER 'SYSDBA' PASSWORD 'masterkey' * PAGE_SIZE 8192 * DEFAULT CHARACTER SET NONE; */ string sql = sqlCmd.ToUpper(); string location = "D:\\Data\\test111.FDB"; string server = "localhost"; string user = "******"; string password = "******"; string packetsize = "8192"; int inx = sql.IndexOf("CREATE DATABASE ", StringComparison.Ordinal); if (inx >= 0) { string cmd3 = sqlCmd.Substring(inx + 16); int inx2 = cmd3.IndexOf(" ", StringComparison.Ordinal); string arg = cmd3.Substring(0, inx2); int inx3 = arg.IndexOf(":\\", StringComparison.Ordinal); int inx4 = arg.IndexOf(":", StringComparison.Ordinal); if (inx4 < inx3) { //server server = arg.Substring(0, inx4).Replace("'", ""); location = arg.Substring(inx4 + 1); location = location.Replace("'", ""); } else { //nur dateipfad server = "localhost"; location = arg.Replace("'", ""); } } inx = sql.IndexOf("USER ", StringComparison.Ordinal); if (inx >= 0) { string cmd3 = sqlCmd.Substring(inx + 5); int inx2 = cmd3.IndexOf(" ", StringComparison.Ordinal); string arg = cmd3.Substring(0, inx2); user = arg.Replace("'", ""); } inx = sql.IndexOf("PASSWORD ", StringComparison.Ordinal); if (inx >= 0) { string cmd3 = sqlCmd.Substring(inx + 9); int inx2 = cmd3.IndexOf(" ", StringComparison.Ordinal); string arg = cmd3.Substring(0, inx2); password = arg.Replace("'", ""); } inx = sql.IndexOf("PAGE_SIZE ", StringComparison.Ordinal); if (inx >= 0) { string cmd3 = sqlCmd.Substring(inx + 10); int inx2 = cmd3.IndexOf(" ", StringComparison.Ordinal); string arg = cmd3.Substring(0, inx2); packetsize = arg; } try { _parentNotifies?.AddToINFO(StaticFunctionsClass.DateTimeNowStr() + " ...Creating new database via script " + server + ":" + location); DBProviderSet.CreateDatabase(location, server, user, password, StaticFunctionsClass.ToIntDef(packetsize, AppSettingsClass.Instance().DatabaseSettings.DefaultPacketSize)); } catch (Exception ex) { NotifiesClass.Instance().AddToERROR(AppStaticFunctionsClass.GetFormattedError($@"{sqlCmd}-> CreateDatabase()", ex)); } return(true); }
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(); } }
private void hsSaveSourceCodes_Click(object sender, EventArgs e) { if (!Directory.Exists(txtSourceCodePath.Text)) { object[] p = { txtSourceCodePath.Text, Environment.NewLine }; SEMessageBox.ShowMDIDialog(FbXpertMainForm.Instance(), "DirectoryNotExists", "DirectoryNotExistsParam", FormStartPosition.CenterScreen, SEMessageBoxButtons.OK, SEMessageBoxIcon.Exclamation, null, p); return; } var items = selDBObjects.CheckedItemDatas; pbExport.Minimum = 0; pbExport.Value = 0; pbExport.Maximum = items.Count; if (ckDeleteOldSourceFiles.Checked) { string[] files = Directory.GetFiles(txtSourceCodePath.Text); foreach (string file in files) { try { File.Delete($@"{file}"); } catch //(Exception ex) { } } } var gsource = MakeGlobalCode(); try { var fi = new FileInfo(txtSourceCodePath.Text + "\\DBGlobalFunctionsClass.cs"); if (fi.Directory != null && fi.Directory.Exists) { File.WriteAllText(txtSourceCodePath.Text + "\\DBGlobalFunctionsClass.cs", gsource); } } catch (Exception ex) { _localNotify?.AddToERROR(AppStaticFunctionsClass.GetFormattedError($@"hsSaveSourceCodes_Click", ex)); } foreach (var itm in items) { var source = itm.Text.StartsWith("Cb") ? MakeCbSourceCode(itm.Object) : MakeSourceCode(itm.Object); try { var fi = new FileInfo(txtSourceCodePath.Text + "\\" + itm.Text + "Class.cs"); if (fi.Directory != null && fi.Directory.Exists) { File.WriteAllText(txtSourceCodePath.Text + "\\" + itm.Text + "Class.cs", source); } } catch (Exception ex) { _localNotify?.AddToERROR(AppStaticFunctionsClass.GetFormattedError($@"hsSaveSourceCodes_Click", ex)); } pbExport.Value++; gbExportProgress.Text = LanguageClass.Instance.GetString("PROGRESS") + $@" ({pbExport.Value}/{pbExport.Maximum})"; Application.DoEvents(); } }