private void LoadData() { using (var transaction = new DBTransaction()) { var command = transaction.AddCommand(""); foreach (TableItemNode node in listObjects.Nodes) { if (node.Item is DBTable table && table.IsLoging && table.StatusKey != null) { var filter = table.GetStatusParam(DBStatus.New | DBStatus.Edit | DBStatus.Delete); command.CommandText = table.BuildQuery("where " + filter.Format(), "a", null, "count(*)"); object count = transaction.ExecuteQuery(command, DBExecuteType.Scalar); node.Count = int.Parse(count.ToString()); node.Visible = count.ToString() != "0"; } } } }
public object Execute(ExecuteEventArgs arg) { object flag = null; var regex = new Regex(@"\s*go\s*(\n|$)", RegexOptions.IgnoreCase); string[] split = regex.Split(arg.Query); foreach (string s in split) { string query = s.Trim(); if (query.Length == 0) { continue; } if (arg.Cancel) { break; } using (var transaction = new DBTransaction(arg.Schema.Connection)) { var command = transaction.AddCommand(query); command.CommandTimeout = 30000; try { arg.Table.Access = null; using (transaction.Reader = transaction.ExecuteQuery(command, DBExecuteType.Reader) as IDataReader) { arg.Table.CheckColumns(transaction); Application.Invoke(() => list.ResetColumns()); while (transaction.Reader.Read()) { if (arg.Cancel) { command.Cancel(); break; } if (arg.Table != null) { arg.Table.Add(arg.Table.LoadItemFromReader(transaction)); flag = arg.Table.Count; } else { flag = transaction.Reader.GetValue(0); break; } } transaction.Reader.Close(); } if (GuiService.Main != null) { GuiService.Main.SetStatus(new StateInfo("Data Query", "Execution complete!", s)); } } catch (Exception ex) { if (GuiService.Main != null) { GuiService.Main.SetStatus(new StateInfo("Data Query", ex.Message, s, StatusType.Error)); } flag = ex; break; } if (!(flag is Exception)) { transaction.Commit(); } } } return(flag); }