public bool Match(string tableName, string dbName) { bool baseMatch = base.Match(tableName); bool DBMatch = (DBName != null && DBName.Equals(dbName)); return(baseMatch && DBMatch); }
/// <summary> /// 取得資料庫連線字串 /// </summary> /// <param name="s"></param> /// <param name="t"></param> /// <returns></returns> public static string DBConnStr(DBServer s, DBType t, DBName n) { string result = ""; result += Get_DBServer(s) + Get_DBType(t) + Get_DBName(n); return(result); }
protected virtual ResultStatus Save_Override(DataTable dt, string tableName, DBName dBName = DBName.CI) { DataGate DG = new DataGate(); MessageDisplay.Info("Save_Override has been remove"); return(ResultStatus.Fail); }
// public static void ExecuteCommandNonQuery(string connectionString, string commandText,DBName dbname) { #region MSSQL if (dbname == DBName.MSSQL) { using (SqlConnection conn = new SqlConnection(connectionString)) { conn.Open(); using (SqlCommand com = new SqlCommand(commandText, conn)) { com.ExecuteNonQuery(); } //dbconn.Close(); } } #endregion #region SQLite if(dbname == DBName.SQLite) { using (SQLiteConnection conn = new SQLiteConnection(connectionString)) { conn.Open(); using (SQLiteCommand com = new SQLiteCommand(commandText, conn)) { int tmp_int = com.ExecuteNonQuery(); } } } #endregion }
private static void Run(DBName dBName) { var connString = _configuration.GetConnectionString(dBName.ToString()); var scriptFolderPath = $"./Scripts/{dBName.ToString()}"; EnsureDatabase.For.PostgresqlDatabase(connString); var upgradeBuilder = DeployChanges.To .PostgresqlDatabase(connString) .WithScriptsFromFileSystem(Path.Combine(scriptFolderPath, "Scripts"), new SqlScriptOptions { RunGroupOrder = 1, ScriptType = ScriptType.RunOnce }) .WithScriptsFromFileSystem(Path.Combine(scriptFolderPath, "SeedData"), new SqlScriptOptions { RunGroupOrder = 2, ScriptType = ScriptType.RunOnce }); if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development") { upgradeBuilder.WithScriptsFromFileSystem(Path.Combine(scriptFolderPath, "SampleData"), new SqlScriptOptions { RunGroupOrder = 3, ScriptType = ScriptType.RunOnce }); } var upgrader = upgradeBuilder.LogToAutodetectedLog().Build(); upgrader.PerformUpgrade(); }
private void CopyDatabase() { string extension = Path.GetExtension(fullDBPath); var dbResourcePath = NSBundle.MainBundle.PathForResource(DBName.Replace(extension, null), extension.Remove(0, 1)); File.Copy(dbResourcePath, fullDBPath); }
public static string GetConnectionString(DBName dbName) { if (dbName == DBName.Default) { return(defaulConnectionString); } return(defaulConnectionString); }
public static int Execute(string sql, DynamicParameters param = null, DBName dbName = DBName.Default) { using (SqlConnection conn = new SqlConnection(GetConnectionString(dbName))) { conn.Open(); if (param == null) { param = new DynamicParameters(); } return(conn.Execute(sql, param, commandType: CommandType.StoredProcedure)); } }
public override bool Equals(object obj) { LoggingIdentity other = obj as LoggingIdentity; if (other != null) { if (DBName != null && DBName.Equals(other.DBName) && ColName != null && ColName.Equals(other.ColName) && BucketID == other.BucketID) { return(true); } } return(false); }
private static void Run(DBName dBName) { var connString = _configuration.GetConnectionString(dBName.ToString()); var scriptFolderPath = $"./Scripts/{dBName.ToString()}"; var upgrader = DeployChanges.To .PostgresqlDatabase(connString) .WithScriptsFromFileSystem(scriptFolderPath, new SqlScriptOptions { RunGroupOrder = DbUpDefaults.DefaultRunGroupOrder + 1 }) .LogToAutodetectedLog() .Build(); var result = upgrader.PerformUpgrade(); }
/// <summary> /// 資料庫名稱 /// </summary> /// <returns></returns> private static string Get_DBName(DBName n) { string result = ""; switch ((int)n) { case 0: result = "User Id=twuser;Password=twpassword;Database=tw_poi;"; break; case 1: result = "User Id=twuser;Password=twpassword;Database=tw_poi;"; break; } return(result); }
public CDataBase GetJsonDatabase(DBName db) { CDataBase database; if (databaseMap.TryGetValue(db, out database)) { } else { var binData = Resources.Load(dbName[(int)db]) as TextAsset; //Log.Important("binData "+binData); var arr = SimpleJSON.JSON.Parse(binData.text) as SimpleJSON.JSONArray; //Log.Important("Load database "+arr.ToString()); database = new CDataBase(arr); databaseMap[db] = database; } return(database); }
public static int ConvertDBTableToXML(DBName dbName, string connectionString, string tableName, string path) { XmlDocument doc = new XmlDocument(); DataSet dataSet = new DataSet(tableName); // DbConnection conn = null; // if (dbName == DBName.SQLite) conn = new SQLiteConnection(); else if (dbName == DBName.MSSQL) conn = new SqlConnection(); try { conn.ConnectionString = (connectionString); } catch { return 3;/*Возвращаем код ошибки 3 если не удалось соединиться*/ } ///////////////////////////////////////////////////////////////////////// DbCommand cmd = null; if (dbName == DBName.SQLite) cmd = new SQLiteCommand("select * from " + tableName, (SQLiteConnection)conn); if (dbName == DBName.MSSQL) cmd = new SqlCommand(@"select * from " + tableName, (SqlConnection)conn); ////////////////////////////////////////////////////////////////////////// DbDataAdapter adapter = null; if (dbName == DBName.SQLite) adapter = new SQLiteDataAdapter((SQLiteCommand)cmd); if (dbName == DBName.MSSQL) adapter = new SqlDataAdapter((SqlCommand)cmd); adapter.Fill(dataSet); ////////////////////////////////////////////////////////////////////////// StringBuilder sb = new StringBuilder(); StringWriter sw = new StringWriter(sb); //dataSet.WriteXml(sw); dataSet.WriteXml(path + tableName + ".xml"); //dataSet.ReadXml("fileName"); // //Console.WriteLine(fileName + " : " + sb.ToString()); //Console.Read(); return 0;//если нет ошибок }
public static DbContext Create(DBName dbName) { DbContext dbContext = CallContext.GetData(dbName.ToString()) as DbContext; if (dbContext == null) { lock (locker) { if (dbContext == null) { switch (dbName) { case DBName.ChannelDB: //dbContext = new ChannelEntities(); //CallContext.SetData(dbName.ToString(), dbContext); break; case DBName.MpConfigDB: //dbContext = new MPDBEntities(); //CallContext.SetData(dbName.ToString(), dbContext); break; case DBName.ReservationDB: //dbContext = new yudingEntities(); //CallContext.SetData(dbName.ToString(), dbContext); break; case DBName.ITicketDB: dbContext = new iticketDB(); CallContext.SetData(dbName.ToString(), dbContext); break; default: dbContext = null; break; } } } } return(dbContext); }
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { switch (comboBox1.SelectedItem.ToString()) { case "SQLite": SelectedDB = DBName.SQLite; SDB.Text = SelectedDB.ToString(); break; case "MySql": SelectedDB = DBName.MySql; SDB.Text = SelectedDB.ToString(); break; case "MSSQL": SelectedDB = DBName.MSSQL; SDB.Text = SelectedDB.ToString(); break; default: SelectedDB = DBName.SQLite; SDB.Text = SelectedDB.ToString(); break; } }
private void save_Click(object sender, EventArgs e) { if (hostName.Text == "") { MessageBox.Show("กรุณากรอก Host Name"); hostName.Select(); return; } else if (DBName.Text == "") { MessageBox.Show("กรุณากรอกชื่อ ฐานข้อมูล"); DBName.Select(); return; } else if (userName.Text == "") { MessageBox.Show("กรุณากรอก User Name"); userName.Select(); return; } saveFile(); testConDB(); }
//从配置代码中获取数据 public IConfig SearchIdByConf(DBName db, int id) { CDataBase database = null; if (databaseMap.TryGetValue(db, out database)) { database = databaseMap [db]; } else { var ch = new List <IConfig>(); if (db == DBName.PropsConfig) { foreach (PropsConfigData p in GameData.PropsConfig) { ch.Add(p); } } else if (db == DBName.EquipConfig) { foreach (EquipConfigData p in GameData.EquipConfig) { ch.Add(p); } } else if (db == DBName.ChapterConfig) { foreach (ChapterConfigData p in GameData.ChapterConfig) { ch.Add(p); } } database = new CDataBase(ch); } return(database.SearchIdByConf(id)); }
public static List<string> GetListOfDBTables(string connString, DBName dbname) { List<string> tmp = new List<string>(); // List<string[]> listOfTables = null; if (dbname == DBName.SQLite) { listOfTables = DBConverter.DBManager.ExecuteReadQuery(connString, @"SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;", dbname); } else if (dbname == DBName.MSSQL) { listOfTables = DBConverter.DBManager.ExecuteReadQuery(connString, @"select TABLE_NAME from INFORMATION_SCHEMA.TABLES where TABLE_TYPE = 'BASE TABLE' and TABLE_NAME != 'sysdiagrams';", dbname); } // foreach (string[] Mstr in listOfTables) { foreach (string str in Mstr) { tmp.Add(str); } } // return tmp; }
public override int GetHashCode() => ConnectionString?.GetHashCode() ?? 0 ^ Type?.GetHashCode() ?? 0 ^ DBName?.GetHashCode() ?? 0;
static void Main(string[] args) { // check if an instance is already running Process[] proc = Process.GetProcessesByName("FDACore"); if (proc.Length > 1) { Console.WriteLine("An existing FDA instance was detected, closing"); OperationalMessageServer.WriteLine("An existing FDA instance was detected, closing"); return; } // check arguments for console mode Globals.ConsoleMode = args.Contains("-console"); string message = "Starting the FDA in background mode"; if (Globals.ConsoleMode) { message = "Starting the FDA in console mode"; } Console.WriteLine(message); // generate a new execution ID ExecutionID = Guid.NewGuid(); // record the time of execution Globals.ExecutionTime = Globals.FDANow(); // get the FDA version string Globals.FDAVersion = Assembly.GetEntryAssembly().GetName().Version.ToString(); // load the configuration from appsettings.json file string FDAID; string DBInstance; string DBName; string userName; string userPass; IConfigurationSection appConfig = null; try { configuration = new ConfigurationBuilder().AddJsonFile("appsettings.json", false, true).Build(); appConfig = configuration.GetSection(nameof(AppSettings)); FDAID = appConfig["FDAID"]; DBInstance = appConfig["DatabaseInstance"]; DBType = appConfig["DatabaseType"]; DBName = appConfig["SystemDBName"]; userName = appConfig["SystemLogin"]; userPass = appConfig["SystemDBPass"]; if (DBInstance.Contains("(default")) { DBInstance = DBInstance.Replace("(default)", ""); LogEvent("DatabaseInstance setting not found, using the default value"); } if (DBName.Contains("(default")) { DBName = DBName.Replace("(default)", ""); LogEvent("SystemDBName setting not found, using the default value"); } if (userName.Contains("(default")) { userName = userName.Replace("(default)", ""); LogEvent("SystemLogin setting not found, using the default value"); } if (userPass.Contains("(default")) { userPass = userPass.Replace("(default)", ""); LogEvent("SystemLogin setting not found, using the default value "); } if (FDAID.Contains("(default")) { FDAID = FDAID.Replace("(default)", ""); LogEvent("FDAID setting not found, using the default"); } } catch (Exception ex) { OperationalMessageServer.WriteLine("Error while reading appsettings.json \"" + ex.Message + "\"\nFDA Exiting"); Console.WriteLine("Error while reading appsettings.json \"" + ex.Message + "\""); Console.WriteLine("FDA Exiting"); Console.Read(); return; } // start basic services server Console.WriteLine("Starting the basic services control port server"); _FDAControlServer = TCPServer.NewTCPServer(9572); if (_FDAControlServer != null) { _FDAControlServer.DataAvailable += TCPServer_DataAvailable; _FDAControlServer.ClientDisconnected += TCPServer_ClientDisconnected; _FDAControlServer.ClientConnected += TCPServer_ClientConnected; _FDAControlServer.Start(); } else { Globals.SystemManager.LogApplicationError(Globals.FDANow(), TCPServer.LastError, "Error occurred while initializing the Basic Services Control Port Server"); } // start operational messages server Console.WriteLine("Starting the operational messages streaming server"); OperationalMessageServer.Start(); // give clients a chance to connect to the server(s) before continuing Console.WriteLine("Waiting five seconds to allow clients to connect to the BSCP or OMSP ports"); Thread.Sleep(5000); // if running in background mode: hide the console, disable the x button, and disable quick edit mode (windows only) if (Environment.OSVersion.Platform == PlatformID.Win32NT) { // hide the console window if the -show command line option is not specified if (!args.Contains("-console")) { var handle = NativeMethods.GetConsoleWindow(); NativeMethods.ShowWindow(handle, NativeMethods.SW_HIDE); } else { // the console window is shown, we need to change some settings IntPtr conHandle = NativeMethods.GetConsoleWindow(); //disable the window close button(X) NativeMethods.DeleteMenu(NativeMethods.GetSystemMenu(conHandle, false), NativeMethods.SC_CLOSE, NativeMethods.MF_BYCOMMAND); // disable quick edit mode (this causes the app to pause when the user clicks in the console window) IntPtr stdHandle = NativeMethods.GetStdHandle(NativeMethods.STD_INPUT_HANDLE); if (!NativeMethods.GetConsoleMode(stdHandle, out int mode)) { // error getting the console mode Console.WriteLine("Error retrieving console mode"); OperationalMessageServer.WriteLine("Error retrieving the console mode"); } mode &= ~(NativeMethods.QuickEditMode | NativeMethods.ExtendedFlags); if (!NativeMethods.SetConsoleMode(stdHandle, mode)) { // error setting console mode. Console.WriteLine("Error setting console mode"); OperationalMessageServer.WriteLine("Error while settting the console mode"); } } } // initialize and start data acquisition try // general error catching { Globals.FDAIsElevated = false; Globals.FDAIsElevated = MQTTUtils.ThisProcessIsAdmin(); // start the FDASystemManager FDASystemManager systemManager; switch (DBType.ToUpper()) { case "POSTGRESQL": systemManager = new FDASystemManagerPG(DBInstance, DBName, userName, userPass, Globals.FDAVersion, ExecutionID); break; case "SQLSERVER": systemManager = new FDASystemManagerSQL(DBInstance, DBName, userName, userPass, Globals.FDAVersion, ExecutionID); break; default: LogEvent("Unrecognized database server type '" + DBType + "'. Should be 'POSTGRESQL' or 'SQLSERVER'"); return; } Dictionary <string, FDAConfig> options = systemManager.GetAppConfig(); systemManager.LogStartup(ExecutionID, Globals.FDANow(), Globals.FDAVersion); // set the "detailed messaging" flag if (options.ContainsKey("DetailedMessaging")) { Globals.DetailedMessaging = (systemManager.GetAppConfig()["DetailedMessaging"].OptionValue == "on"); } // connect to the MQTT broker Globals.MQTTEnabled = false; if (options.ContainsKey("MQTTEnabled")) { Globals.MQTTEnabled = (options["MQTTEnabled"].OptionValue == "1"); } if (Globals.MQTTEnabled) { MQTTConnect("localhost"); Globals.MQTT?.Publish("FDA/DBType", Encoding.UTF8.GetBytes(DBType.ToUpper()), 0, true); } else { Console.WriteLine("MQTT is disabled in AppConfig table, skipping MQTT connection"); } Globals.FDAStatus = Globals.AppState.Starting; // create a DBManager of the selected type string FDADBConnString = systemManager.GetAppDBConnectionString(); DBManager dbManager; Console.WriteLine("Connecting to the " + DBType + " database"); switch (DBType.ToUpper()) { case "SQLSERVER": dbManager = new DBManagerSQL(FDADBConnString); break; case "POSTGRESQL": dbManager = new DBManagerPG(FDADBConnString); break; default: Globals.SystemManager.LogApplicationEvent("FDA App", "", "unrecognized database server type '" + DBType + "', unable to continue"); return; } Console.WriteLine("Starting the Data Acquisition Manager"); // start the DataAcqManager _dataAquisitionManager = new DataAcqManager(FDAID, dbManager, ExecutionID); // watch for changes to the MQTTEnabled option _dataAquisitionManager.MQTTEnableStatusChanged += DataAquisitionManager_MQTTEnableStatusChanged; if (_dataAquisitionManager.TestDBConnection()) { _dataAquisitionManager.Start(); Globals.FDAStatus = Globals.AppState.Normal; } else { Console.WriteLine("Failed to connect to database, exiting"); return; } } catch (Exception ex) { if (Globals.SystemManager != null) { Globals.SystemManager.LogApplicationError(Globals.FDANow(), ex, "FDA: error in application initilization"); } else { Console.WriteLine("FDA: error in application initilization: " + ex.Message + " Stacktrace: " + ex.StackTrace); } return; } while (!ShutdownComplete) { Thread.Sleep(1000); } }
// public static List<string[]> ExecuteReadQuery(string connectionString, string _query, DBName dbname) { // List<string[]> tmp_str = new List<string[]>(); // try { #region SQLite if (dbname == DBName.SQLite) { using (SQLiteConnection connection = new SQLiteConnection()) { connection.ConnectionString = connectionString; connection.Open(); //---------------------- using (SQLiteCommand command = new SQLiteCommand(connection)) { command.CommandText = _query; command.CommandType = CommandType.Text; IDataReader sqliteReader = command.ExecuteReader(); // while (sqliteReader.Read()) { string[] str = new string[sqliteReader.FieldCount]; for (int j = 0; j < sqliteReader.FieldCount; j++) { str[j] = Convert.ToString(sqliteReader[j]); } tmp_str.Add(str); } } //---------------------- connection.Close(); } // return tmp_str; } #endregion //***********************************************************************// #region MSSQL if (dbname == DBName.MSSQL) { using (SqlConnection connection = new SqlConnection()) { connection.ConnectionString = connectionString; connection.Open(); //---------------------- using (SqlCommand command = new SqlCommand(_query,connection)) { command.CommandText = _query; command.CommandType = CommandType.Text; IDataReader sqlReader = command.ExecuteReader(); // while (sqlReader.Read()) { string[] str = new string[sqlReader.FieldCount]; for (int j = 0; j < sqlReader.FieldCount; j++) { str[j] = Convert.ToString(sqlReader[j]); } tmp_str.Add(str); } } //---------------------- connection.Close(); } // return tmp_str; } #endregion } catch { //return null; return tmp_str; } return tmp_str; }
// public static int ImportXMLToSQL(DBName dbName, string connectionString,string fileName) { List<string> tmp_list_params; tmp_list_params = GetTableParamsFromXML(fileName); ///////////////////////////////////////////////////////////// string commandText = "CREATE TABLE " + tmp_list_params[0]; // for (int i = 1; i < tmp_list_params.Count; i++) { if (i == 1) { commandText += " ("; } if (i == tmp_list_params.Count - 1) commandText += tmp_list_params[i] + " varchar(255));"; else commandText += tmp_list_params[i] + " varchar(255),"; } // DBManager.ExecuteCommandNonQuery(connectionString, commandText, dbName); commandText = ""; /////////////////////////////////////////////////////// List<string[]> tmp_list_tables_data = GetTablesDataFromXML(fileName); string comText = ""; for (int i = 0; i < tmp_list_tables_data.Count; i++) { comText = "INSERT INTO " + tmp_list_params[0] + " VALUES ("; for (int j = 0; j < tmp_list_tables_data[i].Length; j++) { if (j != tmp_list_tables_data[i].Length - 1) { comText += "'" + tmp_list_tables_data[i][j] + "',"; } else { comText += "'" + tmp_list_tables_data[i][j] + "');"; } } //Console.WriteLine(comText); DBManager.ExecuteCommandNonQuery(connectionString, comText, dbName); } /////////////////////////////////////////////////////// return 0; }
public static string GetConnectionString(string ServerName, DBName dbName, string UserName, string Password) { return(GetConnectionString(ServerName, Converter.GetString(dbName), UserName, Password)); }
//--------------------------------------ON SAVE CONNECTION DATA FUNCTION------------------------------------- private void Submit_Click(object sender, RoutedEventArgs e) //function to save the data used for the connection { Boolean ipchecked = true; string srvAdd, dbname, user, dbpasswd, admin, dbport; srvAdd = ServerAddress.Text; dbname = DBName.Text; user = UserID.Text; dbpasswd = UserPasswd.Password.ToString(); admin = AdminCredentials.Password.ToString(); dbport = Port.Text; //CHECKING IF THE FIELDS ARE ALL FILLED if (String.IsNullOrWhiteSpace(srvAdd) == true || String.IsNullOrWhiteSpace(dbname) == true || String.IsNullOrWhiteSpace(user) == true || String.IsNullOrWhiteSpace(dbport) == true) { MessageBox.Show("Please fill all the required fields", "Error", MessageBoxButton.OK, MessageBoxImage.Stop); } else if (!srvAdd.Equals("localhost"))//IF THE SERVER ADDRESS IS NOT THE LOCALHOST -> CHECK IF IT IS A VALID IP { ipchecked = CheckIPValid(srvAdd); if (ipchecked == false) { MessageBox.Show("Please enter a valid IP", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } else if (admin.Equals(Properties.Resources.adminpasswd.ToString()) && ipchecked == true) //CHECKING ADMINS PASSWORD { Properties.dbSettings.Default.datasource = srvAdd; //save the checkobox data into the programs settings Properties.dbSettings.Default.database = dbname; Properties.dbSettings.Default.username = user; Properties.dbSettings.Default.password = dbpasswd; Properties.dbSettings.Default.port = dbport; Properties.dbSettings.Default.Save(); MessageBox.Show("Changes saved successfully", "Success", MessageBoxButton.OK, MessageBoxImage.Information); ShowStoredValues(); ServerAddress.Clear(); DBName.Clear(); UserID.Clear(); UserPasswd.Clear(); AdminCredentials.Clear(); Port.Clear(); } else { MessageBox.Show("You must enter admins password", "Error", MessageBoxButton.OK, MessageBoxImage.Stop); } } else if (srvAdd.Equals("localhost"))//IF THE SERVER ADDRESS IS THE LOCALHOST THEN CHECK FOR ADMINS PASSWORD { if (admin.Equals(Properties.Resources.adminpasswd.ToString())) { Properties.dbSettings.Default.datasource = srvAdd; //save the checkobox data into the programs settings Properties.dbSettings.Default.database = dbname; Properties.dbSettings.Default.username = user; Properties.dbSettings.Default.password = dbpasswd; Properties.dbSettings.Default.port = dbport; Properties.dbSettings.Default.Save(); MessageBox.Show("Changes saved successfully", "Success", MessageBoxButton.OK, MessageBoxImage.Information); ShowStoredValues(); ServerAddress.Clear(); DBName.Clear(); UserID.Clear(); UserPasswd.Clear(); AdminCredentials.Clear(); Port.Clear(); } else { MessageBox.Show("You must enter a valid admins password", "Error", MessageBoxButton.OK, MessageBoxImage.Stop); } } }
public static string GetConnectionString(DBName dbName) { return(GetConnectionString(Converter.GetString(dbName))); }
private DapperInfrastructure.DB GetNewDB(DBName dbName) { return(DapperInfrastructure.DB.New(dbName.ToString())); }
public override int GetHashCode() { return(Name.GetHashCode() ^ DBName.GetHashCode() ^ (Relations != null?Relations.GetHashCode():0)); }
public override int GetHashCode() { return((DBName != null ? DBName.GetHashCode() : 0) + (ColName != null ? ColName.GetHashCode() : 0) + (this.NodeInfo != null ? NodeInfo.GetHashCode() : 0)); }
public override int GetHashCode() { return((DBName != null ? DBName.GetHashCode() : 0) + (ColName != null ? ColName.GetHashCode() : 0) + BucketID.GetHashCode()); }
/// <summary> /// Sử dụng lấy dữ liệu dạng danh sách /// </summary> /// <typeparam name="T"></typeparam> /// <param name="sql"></param> /// <param name="userInfo"></param> /// <param name="param"></param> /// <returns></returns> public static IEnumerable <T> QueryByStored <T>(string StoredName, DynamicParameters param = null, DBName dbName = DBName.Default) { using (SqlConnection conn = new SqlConnection(GetConnectionString(dbName))) { conn.Open(); if (param == null) { param = new DynamicParameters(); } List <string> para = new List <string>(); para.AddRange(param.ParameterNames); StoredName = StoredName.Trim() + " "; for (int i = 0; i < para.Count; i++) { if (i > 0) { StoredName += ","; } StoredName += "@" + para[i]; } return(conn.Query <T>(StoredName, param)); } }
private void RichText_SelectionChanged(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(DBName)) { return; } var seltext = this.RichText.SelectedText; if (string.IsNullOrWhiteSpace(seltext) || seltext.IndexOf('\n') > -1 || seltext.Length > 30) { return; } seltext = seltext.Trim().ToUpper(); var subtexts = seltext.Split('.').Select(p => p.Trim('[', ']').Trim()).ToArray(); List <string[]> keys = new List <string[]>(); if (subtexts.Length > 2) { keys.Add(new string[] { subtexts[subtexts.Length - 3], subtexts[subtexts.Length - 2], subtexts.Last() }); } else if (subtexts.Length > 1) { keys.Add(new string[] { DBName.ToUpper(), subtexts[subtexts.Length - 2], subtexts.Last() }); } else { //[\s\n]+from[\s\r\n]+(?:(?:[\w\.\[\]]{1,})[\s\r\n]+(?:as)?(?:\w+)?(?:\,(?:[\w\.\[\]]{1,})[\s\r\n]+(?:as)?(?:\s+\w+)?)*) //[\s\n]+from[\s\r\n]+((?:[\w\.\[\]]{1,}(?:\s?=\w+)?(?:\,?=[\w\.\[\]]{1,}(?:\s?=\w+)?))*)|[\s\n]+join[\s\n]+([\w\.\[\]]{1,})|(?:^?|\s+)update|insert\s+([\w\.\[\]]+) HashSet <Tuple <string, string> > tablenamehash = new HashSet <Tuple <string, string> >(); foreach (Match m in Regex.Matches(this.RichText.Text, @"[\s\r\n]+from[\s\r\n]+(?:([\w\.\[\]]{1,})[\s\r\n]+(?:as)?(?:\w+)?(?:\,[\r\n\s]*(?:[\w\.\[\]]{1,})[\s\r\n]+(?:as)?(?:[\s\r\n]+\w+)?)*)|[\s\n\r]+join[\s\n\r]+([\w\.\[\]]{1,})|(?:^?|\s+)update[\s\r\n]+([\w\.\[\]]{1,})|insert[\s\r\n]+into[\s\r\n]+([\w\.\[\]]+)|delete[\s\r\n]+from[\s\r\n]+([\w\.\[\]]+)", RegexOptions.IgnoreCase | RegexOptions.Multiline)) { if (!string.IsNullOrWhiteSpace(m.Groups[0].Value)) { foreach (Match n in Regex.Matches(m.Groups[0].Value, @",[\s\r\n]*([\w\.\[\]]{1,})[\s\r\n]+(?:as)?(?:[\s\r\n]+\w+)?", RegexOptions.IgnoreCase | RegexOptions.Multiline)) { var t = GetTableName(n.Groups[1].Value, DBName); if (!tablenamehash.Contains(t)) { tablenamehash.Add(t); } } } //select if (!string.IsNullOrEmpty(m.Groups[1].Value)) { var t1 = GetTableName(m.Groups[1].Value, DBName); if (!tablenamehash.Contains(t1)) { tablenamehash.Add(t1); } } //join if (!string.IsNullOrEmpty(m.Groups[2].Value)) { var t2 = GetTableName(m.Groups[2].Value, DBName); if (!tablenamehash.Contains(t2)) { tablenamehash.Add(t2); } } //update if (!string.IsNullOrEmpty(m.Groups[3].Value)) { var t = GetTableName(m.Groups[3].Value, DBName); if (!tablenamehash.Contains(t)) { tablenamehash.Add(t); } } //insert if (!string.IsNullOrEmpty(m.Groups[4].Value)) { var t = GetTableName(m.Groups[4].Value, DBName); if (!tablenamehash.Contains(t)) { tablenamehash.Add(t); } } //delete if (!string.IsNullOrEmpty(m.Groups[5].Value)) { var t = GetTableName(m.Groups[5].Value, DBName); if (!tablenamehash.Contains(t)) { tablenamehash.Add(t); } } } if (tablenamehash.Count > 0) { foreach (var it in tablenamehash) { keys.Add(new string[] { it.Item1, it.Item2, subtexts.Last() }); } } } if (keys.Count > 0) { var marklist = new List <MarkColumnInfo>(); foreach (var key in keys) { var findresult = LJC.FrameWorkV3.Data.EntityDataBase.BigEntityTableEngine.LocalEngine.Find <MarkColumnInfo>("MarkColumnInfo", "keys", key).FirstOrDefault(); if (findresult != null) { marklist.Add(findresult); } } if (marklist.Count > 0) { view.DataSource = marklist.Select(p => new { 提示 = p.DBName.ToLower() + "." + p.TBName.ToLower() + "." + p.ColumnName.ToLower() + ":" + p.MarkInfo }).ToList(); view.Visible = true; view.BringToFront(); view.Height = (view.Rows.GetRowsHeight(DataGridViewElementStates.Visible) / marklist.Count) * marklist.Count + view.ColumnHeadersHeight; view.Location = PointToClient(Control.MousePosition); } } }