|
@@ -25,19 +25,35 @@ namespace parkMonitor.Database2
|
|
|
MySqlDataReader reader = null;
|
|
|
int garageFreeSpace = 0;
|
|
|
string sql = "select * from garage where garageID = '" + garageID + "'";
|
|
|
- Operation oper = new Operation(bq, sql);
|
|
|
- int count = 0;
|
|
|
- reader = oper.getResultSet(ref count);
|
|
|
- if (count > 0 && reader.Read())
|
|
|
+ Connection conn = ConnectionPoolManager.GetConnection(bq);
|
|
|
+ DBAccess access = new DBAccess(sql, conn, CommandTypes.QUERYCOMMAND);
|
|
|
+ object result = access.GetResult();
|
|
|
+ try
|
|
|
{
|
|
|
- garageFreeSpace = reader.GetInt32("garageFreeSpace");
|
|
|
- return garageFreeSpace;
|
|
|
+ reader = (MySqlDataReader)result;
|
|
|
+ while (reader.Read())
|
|
|
+ {
|
|
|
+ if (reader.HasRows)
|
|
|
+ {
|
|
|
+ garageFreeSpace = reader.GetInt32("garageFreeSpace");
|
|
|
+ return garageFreeSpace;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Console.WriteLine("车位剩余数查无结果");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ Console.WriteLine(ex.Message+"查询剩余车位异常");
|
|
|
}
|
|
|
- else
|
|
|
+ finally
|
|
|
{
|
|
|
- Console.WriteLine("车位剩余数查无结果");
|
|
|
+ reader.Close();
|
|
|
+ reader.Dispose();
|
|
|
+ ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
}
|
|
|
- oper.DBClose(null,null,reader);
|
|
|
return 0;
|
|
|
}
|
|
|
/// <summary>
|
|
@@ -51,29 +67,38 @@ namespace parkMonitor.Database2
|
|
|
Dictionary<int, Parking_Space> lps = new Dictionary<int, Parking_Space>();
|
|
|
MySqlDataReader reader = null;
|
|
|
string sql = "select * from parkingspace where garageID = '" + garageID + "' ";
|
|
|
- Operation oper = new Operation(bq, sql);
|
|
|
- int count = 0;
|
|
|
- reader = oper.getResultSet(ref count);
|
|
|
- if (count > 0)
|
|
|
+ Connection conn = ConnectionPoolManager.GetConnection(bq);
|
|
|
+ DBAccess access = new DBAccess(sql, conn, CommandTypes.QUERYCOMMAND);
|
|
|
+ object result = access.GetResult();
|
|
|
+ try
|
|
|
{
|
|
|
- for (int i = 1; i <= count && reader.Read(); i++)
|
|
|
+ reader = (MySqlDataReader)result;
|
|
|
+ while (reader.Read())
|
|
|
{
|
|
|
- Parking_Space ps = new Parking_Space();
|
|
|
- ps.parkingSpaceID = reader.GetInt32("parkingSpaceID");
|
|
|
- ps.parkingSpaceX = reader.GetInt32("parkingSpaceX");
|
|
|
- ps.parkingSpaceY = reader.GetInt32("parkingSpaceY");
|
|
|
- ps.parkingSpaceZ = reader.GetInt32("parkingSpaceZ");
|
|
|
- ps.parkingSpaceState = reader.GetInt32("parkingSpaceState");
|
|
|
- ps.garageID = garageID;
|
|
|
- lps.Add(ps.parkingSpaceID, (Parking_Space)ps.Clone());
|
|
|
+ if (reader.HasRows)
|
|
|
+ {
|
|
|
+ Parking_Space ps = new Parking_Space();
|
|
|
+ ps.parkingSpaceID = reader.GetInt32("parkingSpaceID");
|
|
|
+ ps.parkingSpaceX = reader.GetInt32("parkingSpaceX");
|
|
|
+ ps.parkingSpaceY = reader.GetInt32("parkingSpaceY");
|
|
|
+ ps.parkingSpaceZ = reader.GetInt32("parkingSpaceZ");
|
|
|
+ ps.parkingSpaceState = reader.GetInt32("parkingSpaceState");
|
|
|
+ ps.garageID = garageID;
|
|
|
+ lps.Add(ps.parkingSpaceID, (Parking_Space)ps.Clone());
|
|
|
+ }
|
|
|
}
|
|
|
return lps;
|
|
|
}
|
|
|
- else
|
|
|
+ catch (Exception ex)
|
|
|
{
|
|
|
- Console.WriteLine("所有车位查无结果");
|
|
|
+ Console.WriteLine(ex.Message + "查询车位表异常");
|
|
|
+ }
|
|
|
+ finally
|
|
|
+ {
|
|
|
+ reader.Close();
|
|
|
+ reader.Dispose();
|
|
|
+ ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
}
|
|
|
- oper.DBClose(null,null,reader);
|
|
|
return null;
|
|
|
}
|
|
|
/// <summary>
|
|
@@ -87,27 +112,39 @@ namespace parkMonitor.Database2
|
|
|
Vehicle v = new Vehicle();
|
|
|
MySqlDataReader reader = null;
|
|
|
string sql = "select * from vehicle where numberPlate = '" + numberPlate + "'";
|
|
|
- Operation oper = new Operation(bq, sql);
|
|
|
- int count = 0;
|
|
|
- reader = oper.getResultSet(ref count);
|
|
|
- if (count > 0 && reader.Read())
|
|
|
- {
|
|
|
- int parkingSpaceID = reader.GetInt32("parkingSpaceID");
|
|
|
- int garageID = reader.GetInt32("garageID");
|
|
|
- int frontwheelbase = reader.GetInt32("frontwheelbase");
|
|
|
- int rearwheelbase = reader.GetInt32("rearwheelbase");
|
|
|
- v.parkingRecordsID = reader.GetInt32("parkingRecordsID");
|
|
|
- v.parkingSpaceID = parkingSpaceID;
|
|
|
- v.garageID = garageID;
|
|
|
- v.frontwheelbase = frontwheelbase;
|
|
|
- v.rearwheelbase = rearwheelbase;
|
|
|
- return v;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- Console.WriteLine("云端车辆查无结果");
|
|
|
- }
|
|
|
- oper.DBClose(null,null,reader);
|
|
|
+ Connection conn = ConnectionPoolManager.GetConnection(bq);
|
|
|
+ DBAccess access = new DBAccess(sql, conn, CommandTypes.QUERYCOMMAND);
|
|
|
+ object result = access.GetResult();
|
|
|
+ try
|
|
|
+ {
|
|
|
+ reader = (MySqlDataReader)result;
|
|
|
+ while (reader.Read())
|
|
|
+ {
|
|
|
+ if (reader.HasRows)
|
|
|
+ {
|
|
|
+ int parkingSpaceID = reader.GetInt32("parkingSpaceID");
|
|
|
+ int garageID = reader.GetInt32("garageID");
|
|
|
+ int frontwheelbase = reader.GetInt32("frontwheelbase");
|
|
|
+ int rearwheelbase = reader.GetInt32("rearwheelbase");
|
|
|
+ v.parkingRecordsID = reader.GetInt32("parkingRecordsID");
|
|
|
+ v.parkingSpaceID = parkingSpaceID;
|
|
|
+ v.garageID = garageID;
|
|
|
+ v.frontwheelbase = frontwheelbase;
|
|
|
+ v.rearwheelbase = rearwheelbase;
|
|
|
+ return v;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ Console.WriteLine(ex.Message + "查询车辆表异常");
|
|
|
+ }
|
|
|
+ finally
|
|
|
+ {
|
|
|
+ reader.Close();
|
|
|
+ reader.Dispose();
|
|
|
+ ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
+ }
|
|
|
return null;
|
|
|
}
|
|
|
/// <summary>
|
|
@@ -121,22 +158,34 @@ namespace parkMonitor.Database2
|
|
|
Parking_Space ps = new Parking_Space();
|
|
|
MySqlDataReader reader = null;
|
|
|
string sql = "select * from parkingspace where parkingSpaceID = '" + parkingSpaceID + " '";
|
|
|
- Operation oper = new Operation(bq, sql);
|
|
|
- int count = 0;
|
|
|
- reader = oper.getResultSet(ref count);
|
|
|
- if (count > 0 && reader.Read())
|
|
|
+ Connection conn = ConnectionPoolManager.GetConnection(bq);
|
|
|
+ DBAccess access = new DBAccess(sql, conn, CommandTypes.QUERYCOMMAND);
|
|
|
+ object result = access.GetResult();
|
|
|
+ try
|
|
|
{
|
|
|
- ps.parkingSpaceID = parkingSpaceID;
|
|
|
- ps.parkingSpaceX = reader.GetInt32("parkingSpaceX");
|
|
|
- ps.parkingSpaceY = reader.GetInt32("parkingSpaceY");
|
|
|
- ps.parkingSpaceZ = reader.GetInt32("parkingSpaceZ");
|
|
|
- return ps;
|
|
|
+ reader = (MySqlDataReader)result;
|
|
|
+ while (reader.Read())
|
|
|
+ {
|
|
|
+ if (reader.HasRows)
|
|
|
+ {
|
|
|
+ ps.parkingSpaceID = parkingSpaceID;
|
|
|
+ ps.parkingSpaceX = reader.GetInt32("parkingSpaceX");
|
|
|
+ ps.parkingSpaceY = reader.GetInt32("parkingSpaceY");
|
|
|
+ ps.parkingSpaceZ = reader.GetInt32("parkingSpaceZ");
|
|
|
+ return ps;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ Console.WriteLine(ex.Message + "查询车位表获取x,y,z异常");
|
|
|
}
|
|
|
- else
|
|
|
+ finally
|
|
|
{
|
|
|
- Console.WriteLine("车位xyz查无结果");
|
|
|
+ reader.Close();
|
|
|
+ reader.Dispose();
|
|
|
+ ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
}
|
|
|
- oper.DBClose(null,null,reader);
|
|
|
return null;
|
|
|
}
|
|
|
/// <summary>
|
|
@@ -148,63 +197,31 @@ namespace parkMonitor.Database2
|
|
|
public bool IsTelRegister(BlockingQueue bq, string tel)
|
|
|
{
|
|
|
bool isTelRegister = false;
|
|
|
- MySqlDataReader reader = null;
|
|
|
string sql = "select * from user where userTelephone = '" + tel + "'";
|
|
|
- Operation oper = new Operation(bq, sql);
|
|
|
- int count = 0;
|
|
|
- reader = oper.getResultSet(ref count);
|
|
|
- if (count > 0)
|
|
|
- {
|
|
|
- isTelRegister = true;
|
|
|
- }
|
|
|
- else
|
|
|
+ Connection conn = ConnectionPoolManager.GetConnection(bq);
|
|
|
+ DBAccess access = new DBAccess(sql, conn, CommandTypes.SCALARCOMMAND);
|
|
|
+ object result = access.GetResult();
|
|
|
+ try
|
|
|
{
|
|
|
- isTelRegister = false;
|
|
|
+ int count = (int)result;
|
|
|
+ if (count > 0)
|
|
|
+ {
|
|
|
+ isTelRegister = true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ isTelRegister = false;
|
|
|
+ }
|
|
|
}
|
|
|
- oper.DBClose(null,null,reader);
|
|
|
- return isTelRegister;
|
|
|
- }
|
|
|
- /// <summary>
|
|
|
- /// 注册信息写入数据库,返回注册成功信息
|
|
|
- /// </summary>
|
|
|
- /// <param name="bq"></param>
|
|
|
- /// <param name="tel"></param>
|
|
|
- /// <param name="password"></param>
|
|
|
- /// <returns></returns>
|
|
|
- public int InsertUser(BlockingQueue bq, string tel, string password)
|
|
|
- {
|
|
|
- string sql = "insert into user(userTelephone,userPassword,userLevel) values('" + tel + "','" + password + "',1)";
|
|
|
- int userID = 0;
|
|
|
- Operation oper = new Operation(bq, sql);
|
|
|
- oper.getInsert();
|
|
|
- userID = oper.getInsertId();
|
|
|
- return userID;
|
|
|
- }
|
|
|
- /// <summary>
|
|
|
- /// 根据电话号码查询userID
|
|
|
- /// </summary>
|
|
|
- /// <param name="bq"></param>
|
|
|
- /// <param name="tel"></param>
|
|
|
- /// <returns></returns>
|
|
|
- public int GetUserID(BlockingQueue bq, string tel)
|
|
|
- {
|
|
|
- int userID = 0;
|
|
|
- MySqlDataReader reader = null;
|
|
|
- string sql = "select userID from user where userTelephone = '" + tel + "'";
|
|
|
- int count = 0;
|
|
|
- Operation oper = new Operation(bq, sql);
|
|
|
- reader = oper.getResultSet(ref count);
|
|
|
- if (count > 0 && reader.Read())
|
|
|
+ catch (Exception ex)
|
|
|
{
|
|
|
- userID = reader.GetInt32("userID");
|
|
|
- return userID;
|
|
|
+ Console.WriteLine(ex.Message + "检测电话号码注册异常");
|
|
|
}
|
|
|
- else
|
|
|
+ finally
|
|
|
{
|
|
|
- Console.WriteLine("userID查无结果");
|
|
|
+ ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
}
|
|
|
- oper.DBClose(null,null,reader);
|
|
|
- return 0;
|
|
|
+ return isTelRegister;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 查询停车记录id
|
|
@@ -217,19 +234,35 @@ namespace parkMonitor.Database2
|
|
|
int parkingRecordsID = 0;
|
|
|
MySqlDataReader reader = null;
|
|
|
string sql = "select parkingRecordsID from parkingrecords where numberPlate = '" + numberPlate + "' and parkingRecordsState = 3";
|
|
|
- int count = 0;
|
|
|
- Operation oper = new Operation(bq, sql);
|
|
|
- reader = oper.getResultSet(ref count);
|
|
|
- if (count > 0 && reader.Read())
|
|
|
+ Connection conn = ConnectionPoolManager.GetConnection(bq);
|
|
|
+ DBAccess access = new DBAccess(sql, conn, CommandTypes.QUERYCOMMAND);
|
|
|
+ object result = access.GetResult();
|
|
|
+ try
|
|
|
+ {
|
|
|
+ reader = (MySqlDataReader)result;
|
|
|
+ while (reader.Read())
|
|
|
+ {
|
|
|
+ if (reader.HasRows)
|
|
|
+ {
|
|
|
+ parkingRecordsID = reader.GetInt32("parkingRecordsID");
|
|
|
+ return parkingRecordsID;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Console.WriteLine("停车记录id查无结果");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
{
|
|
|
- parkingRecordsID = reader.GetInt32("parkingRecordsID");
|
|
|
- return parkingRecordsID;
|
|
|
+ Console.WriteLine(ex.Message + "查询停车记录id异常");
|
|
|
}
|
|
|
- else
|
|
|
+ finally
|
|
|
{
|
|
|
- Console.WriteLine("停车记录id查无结果");
|
|
|
+ reader.Close();
|
|
|
+ reader.Dispose();
|
|
|
+ ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
}
|
|
|
- oper.DBClose(null,null,reader);
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
@@ -243,20 +276,30 @@ namespace parkMonitor.Database2
|
|
|
public bool IsNumberPlate(BlockingQueue bq, string numberPlate, int garageID)
|
|
|
{
|
|
|
bool isNumberPlate = true;
|
|
|
- MySqlDataReader reader = null;
|
|
|
string sql = "select * from parkingrecords where numberPlate = '" + numberPlate + "' and parkingRecordsState = 3 and garageID = '" + garageID + "'";
|
|
|
- Operation oper = new Operation(bq, sql);
|
|
|
- int count = 0;
|
|
|
- reader = oper.getResultSet(ref count);
|
|
|
- if (count > 0 && reader.Read())
|
|
|
+ Connection conn = ConnectionPoolManager.GetConnection(bq);
|
|
|
+ DBAccess access = new DBAccess(sql, conn, CommandTypes.SCALARCOMMAND);
|
|
|
+ object result = access.GetResult();
|
|
|
+ try
|
|
|
{
|
|
|
- isNumberPlate = true;
|
|
|
+ int count = (int)result;
|
|
|
+ if (count > 0)
|
|
|
+ {
|
|
|
+ isNumberPlate = true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ isNumberPlate = false;
|
|
|
+ }
|
|
|
}
|
|
|
- else
|
|
|
+ catch (Exception ex)
|
|
|
{
|
|
|
- isNumberPlate = false;
|
|
|
+ Console.WriteLine(ex.Message + "检测车库中车辆异常");
|
|
|
+ }
|
|
|
+ finally
|
|
|
+ {
|
|
|
+ ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
}
|
|
|
- oper.DBClose(null,null,reader);
|
|
|
return isNumberPlate;
|
|
|
}
|
|
|
/// <summary>
|
|
@@ -269,19 +312,29 @@ namespace parkMonitor.Database2
|
|
|
{
|
|
|
bool isNumberPlateFromVehicle = true;
|
|
|
string sql = "select * from vehicle where numberPlate = '" + numberPlate + "' and vehiclepParkState = 1";
|
|
|
- MySqlDataReader reader = null;
|
|
|
- Operation oper = new Operation(bq, sql);
|
|
|
- int count = 0;
|
|
|
- reader = oper.getResultSet(ref count);
|
|
|
- if (count > 0 && reader.Read())
|
|
|
+ Connection conn = ConnectionPoolManager.GetConnection(bq);
|
|
|
+ DBAccess access = new DBAccess(sql, conn, CommandTypes.SCALARCOMMAND);
|
|
|
+ object result = access.GetResult();
|
|
|
+ try
|
|
|
{
|
|
|
- isNumberPlateFromVehicle = true;
|
|
|
+ int count = (int)result;
|
|
|
+ if (count > 0)
|
|
|
+ {
|
|
|
+ isNumberPlateFromVehicle = true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ isNumberPlateFromVehicle = false;
|
|
|
+ }
|
|
|
}
|
|
|
- else
|
|
|
+ catch (Exception ex)
|
|
|
{
|
|
|
- isNumberPlateFromVehicle = false;
|
|
|
+ Console.WriteLine(ex.Message + "检测车辆表车辆号牌异常");
|
|
|
+ }
|
|
|
+ finally
|
|
|
+ {
|
|
|
+ ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
}
|
|
|
- oper.DBClose(null,null,reader);
|
|
|
return isNumberPlateFromVehicle;
|
|
|
}
|
|
|
/// <summary>
|
|
@@ -293,8 +346,10 @@ namespace parkMonitor.Database2
|
|
|
public void UpdateVehicleParkState(BlockingQueue bq, string numberPlate, int vehiclepParkState)
|
|
|
{
|
|
|
string sql = "update vehicle set vehiclepParkState = '" + vehiclepParkState + "'where numberPlate = '" + numberPlate + "'";
|
|
|
- Operation oper = new Operation(bq, sql);
|
|
|
- oper.getUpdate();
|
|
|
+ Connection conn = ConnectionPoolManager.GetConnection(bq);
|
|
|
+ DBAccess access = new DBAccess(sql, conn, CommandTypes.NOQUERYCOMMAND);
|
|
|
+ object result = access.GetResult();
|
|
|
+ ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 更新车位状态
|
|
@@ -305,8 +360,156 @@ namespace parkMonitor.Database2
|
|
|
public void UpdateParkingSpaceState(BlockingQueue bq, int parkingSpaceID, int parkingSpaceState)
|
|
|
{
|
|
|
string sql = "update parkingspace set parkingSpaceState = '" + parkingSpaceState + "'where parkingSpaceID = '" + parkingSpaceID + "'";
|
|
|
- Operation oper = new Operation(bq, sql);
|
|
|
- oper.getUpdate();
|
|
|
+ Connection conn = ConnectionPoolManager.GetConnection(bq);
|
|
|
+ DBAccess access = new DBAccess(sql, conn, CommandTypes.NOQUERYCOMMAND);
|
|
|
+ object result = access.GetResult();
|
|
|
+ ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
+ }
|
|
|
+ ///// <summary>
|
|
|
+ ///// 插入停车记录表事务
|
|
|
+ ///// </summary>
|
|
|
+ ///// <param name="bq"></param>
|
|
|
+ ///// <param name="strs"></param>
|
|
|
+ ///// <returns></returns>
|
|
|
+ //public static int InsertParkingRecords(BlockingQueue bq, List<string> strs)
|
|
|
+ //{
|
|
|
+ // Connection conn = ConnectionPoolManager.GetConnection(bq);
|
|
|
+ // DBAccess access = new DBAccess(conn, CommandTypes.TRANSACTIONCOMMAND, strs);
|
|
|
+ // object result = access.DealTransaction();
|
|
|
+ // int parkingRecordsID = 0;
|
|
|
+ // try
|
|
|
+ // {
|
|
|
+ // parkingRecordsID = (int)result;
|
|
|
+ // }
|
|
|
+ // catch (Exception ex)
|
|
|
+ // {
|
|
|
+ // Console.WriteLine(ex.Message+"停车记录ID获取失败");
|
|
|
+ // }
|
|
|
+ // finally
|
|
|
+ // {
|
|
|
+ // ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
+ // }
|
|
|
+ // return parkingRecordsID;
|
|
|
+ //}
|
|
|
+ ///// <summary>
|
|
|
+ ///// 更新数据库事务
|
|
|
+ ///// </summary>
|
|
|
+ ///// <param name="bq"></param>
|
|
|
+ ///// <param name="strs"></param>
|
|
|
+ //public static void UpdateTransaction(BlockingQueue bq, List<string> strs)
|
|
|
+ //{
|
|
|
+ // Connection conn = ConnectionPoolManager.GetConnection(bq);
|
|
|
+ // DBAccess access = new DBAccess(conn, CommandTypes.TRANSACTIONCOMMAND, strs);
|
|
|
+ // object result = access.DealTransaction();
|
|
|
+ //}
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 插入停车记录表事务
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="bq"></param>
|
|
|
+ /// <param name="strs"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public static int InsertParkingRecords(BlockingQueue bq, List<string> strs)
|
|
|
+ {
|
|
|
+ Connection conn = ConnectionPoolManager.GetConnection(bq);
|
|
|
+ object result = null;
|
|
|
+ MySqlCommand myCommand = conn.mySqlConnection.CreateCommand();
|
|
|
+ MySqlTransaction myTrans;
|
|
|
+ myTrans = conn.mySqlConnection.BeginTransaction();
|
|
|
+ myCommand.Connection = conn.mySqlConnection;
|
|
|
+ myCommand.Transaction = myTrans;
|
|
|
+ try
|
|
|
+ {
|
|
|
+ for (int i = 0; i < strs.Count(); i++)
|
|
|
+ {
|
|
|
+ myCommand.CommandText = strs[i];
|
|
|
+ myCommand.ExecuteNonQuery();
|
|
|
+ result = Convert.ToInt32(myCommand.LastInsertedId);
|
|
|
+ }
|
|
|
+ myTrans.Commit();
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ myTrans.Rollback();
|
|
|
+ }
|
|
|
+ catch (MySqlException ex)
|
|
|
+ {
|
|
|
+ if (myTrans.Connection != null)
|
|
|
+ {
|
|
|
+ Console.WriteLine(ex.Message + "事务回滚失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Console.WriteLine(e.Message + "事务操作失败");
|
|
|
+ }
|
|
|
+ finally
|
|
|
+ {
|
|
|
+ myCommand.Dispose();
|
|
|
+ myTrans.Dispose();
|
|
|
+ //ConnectionPoolManager.ReleaseConnection(conn);
|
|
|
+ }
|
|
|
+ int parkingRecordsID = 0;
|
|
|
+ try
|
|
|
+ {
|
|
|
+ parkingRecordsID = (int)result;
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ Console.WriteLine(ex.Message + "停车记录ID获取失败");
|
|
|
+ }
|
|
|
+ finally
|
|
|
+ {
|
|
|
+ ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
+ }
|
|
|
+ return parkingRecordsID;
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 更新数据库事务
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="bq"></param>
|
|
|
+ /// <param name="strs"></param>
|
|
|
+ public static object UpdateTransaction(BlockingQueue bq, List<string> strs)
|
|
|
+ {
|
|
|
+ Connection conn = ConnectionPoolManager.GetConnection(bq);
|
|
|
+ object result = false;
|
|
|
+ MySqlCommand myCommand = conn.mySqlConnection.CreateCommand();
|
|
|
+ MySqlTransaction myTrans;
|
|
|
+ myTrans = conn.mySqlConnection.BeginTransaction();
|
|
|
+ myCommand.Connection = conn.mySqlConnection;
|
|
|
+ myCommand.Transaction = myTrans;
|
|
|
+ try
|
|
|
+ {
|
|
|
+ for (int i = 0; i < strs.Count(); i++)
|
|
|
+ {
|
|
|
+ myCommand.CommandText = strs[i];
|
|
|
+ myCommand.ExecuteNonQuery();
|
|
|
+ result = true;
|
|
|
+ }
|
|
|
+ myTrans.Commit();
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ myTrans.Rollback();
|
|
|
+ }
|
|
|
+ catch (MySqlException ex)
|
|
|
+ {
|
|
|
+ if (myTrans.Connection != null)
|
|
|
+ {
|
|
|
+ Console.WriteLine(ex.Message + "事务回滚失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Console.WriteLine(e.Message + "事务操作失败");
|
|
|
+ }
|
|
|
+ finally
|
|
|
+ {
|
|
|
+ myCommand.Dispose();
|
|
|
+ myTrans.Dispose();
|
|
|
+ ConnectionPoolManager.ReleaseConnection(conn,bq);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
}
|
|
|
}
|
|
|
}
|