using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using DatabaseDLL; using System.Configuration; using MySql.Data.MySqlClient; namespace Test { class DBTest { public string connectionString { get; set; } public int timeout { get; set; } public int garageID { get; set; } public DBOperation oper { get; set; } public void Init() { try { connectionString = ConfigurationManager.AppSettings["connectionString"]; timeout = Convert.ToInt32(ConfigurationManager.AppSettings["timeout"]); garageID = Convert.ToInt32(ConfigurationManager.AppSettings["garageID"]); } catch (Exception ex) { Console.WriteLine(ex.Message); } oper = new DBOperation(connectionString, timeout); bool flag = oper.InitConnPooling(10); if (!flag) { Console.WriteLine("数据库初始化失败"); } } public void Query() { string sql = "select * from garage where garageID = '" + garageID + "'"; MySqlDataReader reader = oper.Query(sql); int count; if (reader != null) { try { while (reader.Read()) { count = reader.GetInt32("garageFreeSpace"); } } catch (Exception ex) { Console.WriteLine(ex.Message); } reader.Dispose(); } } public void Insert() { List list = new List(); string sql = "insert into messagequeue(userID,context,messageType) values(1,'test',1)"; list.Add(sql); bool flag = oper.Insert(list); } public void Update() { List list = new List(); string sql = "update messagequeue set messageType = 2 where messageID = 1"; list.Add(sql); bool flag = oper.UpdateTransaction(list); } public bool IsAdmin(string nickname, string password) { bool flag = false; string sql = "select * from manager where managerTel = '" + nickname + "'"; MySqlDataReader reader = oper.Query(sql); if (reader != null) { try { while (reader.Read()) { string managerPassword = reader.GetString("managerPassword"); if (nickname.Equals(reader.GetString("managerTel")) && password.Equals(managerPassword)) { flag = true; } } reader.Dispose(); } catch (Exception ex) { Console.WriteLine(ex.Message); } reader.Dispose(); } return flag; } } }