|
@@ -14,6 +14,7 @@ namespace parkMonitor.Database2
|
|
|
/// </summary>
|
|
|
public class DBOperation
|
|
|
{
|
|
|
+ public const int TIMEOUT = 120000;
|
|
|
/// <summary>
|
|
|
/// 查询车库表获得剩余车位数
|
|
|
/// </summary>
|
|
@@ -25,36 +26,52 @@ namespace parkMonitor.Database2
|
|
|
MySqlDataReader reader = null;
|
|
|
int garageFreeSpace = 0;
|
|
|
string sql = "select * from garage where garageID = '" + garageID + "'";
|
|
|
- Connection conn = ConnectionPoolManager.GetConnection(bq);
|
|
|
- DBAccess access = new DBAccess(sql, conn, CommandTypes.QUERYCOMMAND);
|
|
|
- object result = access.GetResult();
|
|
|
- try
|
|
|
+ Connection conn = ConnectionPoolManager.GetConnection(bq, TIMEOUT);
|
|
|
+ int i = 0;
|
|
|
+ while (conn == null && i < 2)
|
|
|
{
|
|
|
- reader = (MySqlDataReader)result;
|
|
|
- while (reader.Read())
|
|
|
+ ConnectionPoolManager.CheckConnPooling(2, 10, ConnectionPoolManager.remoteConf, bq);
|
|
|
+ conn = ConnectionPoolManager.GetConnection(bq, TIMEOUT);
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ if (conn == null)
|
|
|
+ {
|
|
|
+ Console.WriteLine("请检查网络!等待网络修复超时");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ DBAccess access = new DBAccess(sql, conn, CommandTypes.QUERYCOMMAND);
|
|
|
+ object result = access.GetResult();
|
|
|
+ try
|
|
|
{
|
|
|
- if (reader.HasRows)
|
|
|
+ reader = (MySqlDataReader)result;
|
|
|
+ while (reader.Read())
|
|
|
{
|
|
|
- garageFreeSpace = reader.GetInt32("garageFreeSpace");
|
|
|
- return garageFreeSpace;
|
|
|
+ if (reader.HasRows)
|
|
|
+ {
|
|
|
+ garageFreeSpace = reader.GetInt32("garageFreeSpace");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Console.WriteLine("车位剩余数查无结果");
|
|
|
+ }
|
|
|
}
|
|
|
- else
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ Console.WriteLine(ex.Message + "查询剩余车位异常");
|
|
|
+ }
|
|
|
+ finally
|
|
|
+ {
|
|
|
+ if (reader != null)
|
|
|
{
|
|
|
- Console.WriteLine("车位剩余数查无结果");
|
|
|
+ reader.Close();
|
|
|
+ reader.Dispose();
|
|
|
}
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- Console.WriteLine(ex.Message+"查询剩余车位异常");
|
|
|
- }
|
|
|
- finally
|
|
|
- {
|
|
|
- reader.Close();
|
|
|
- reader.Dispose();
|
|
|
- ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
+ ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
+ }
|
|
|
}
|
|
|
- return 0;
|
|
|
+ return garageFreeSpace; ;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 查询所有车位位置及状态
|
|
@@ -67,37 +84,54 @@ namespace parkMonitor.Database2
|
|
|
Dictionary<int, Parking_Space> lps = new Dictionary<int, Parking_Space>();
|
|
|
MySqlDataReader reader = null;
|
|
|
string sql = "select * from parkingspace where garageID = '" + garageID + "' ";
|
|
|
- Connection conn = ConnectionPoolManager.GetConnection(bq);
|
|
|
- DBAccess access = new DBAccess(sql, conn, CommandTypes.QUERYCOMMAND);
|
|
|
- object result = access.GetResult();
|
|
|
- try
|
|
|
+ Connection conn = ConnectionPoolManager.GetConnection(bq, TIMEOUT);
|
|
|
+ int i = 0;
|
|
|
+ while (conn == null && i < 2)
|
|
|
{
|
|
|
- reader = (MySqlDataReader)result;
|
|
|
- while (reader.Read())
|
|
|
- {
|
|
|
- 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;
|
|
|
+ ConnectionPoolManager.CheckConnPooling(2, 10, ConnectionPoolManager.remoteConf, bq);
|
|
|
+ conn = ConnectionPoolManager.GetConnection(bq, TIMEOUT);
|
|
|
+ i++;
|
|
|
}
|
|
|
- catch (Exception ex)
|
|
|
+ if (conn == null)
|
|
|
{
|
|
|
- Console.WriteLine(ex.Message + "查询车位表异常");
|
|
|
+ Console.WriteLine("请检查网络!等待网络修复超时");
|
|
|
}
|
|
|
- finally
|
|
|
+ else
|
|
|
{
|
|
|
- reader.Close();
|
|
|
- reader.Dispose();
|
|
|
- ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
+ DBAccess access = new DBAccess(sql, conn, CommandTypes.QUERYCOMMAND);
|
|
|
+ object result = access.GetResult();
|
|
|
+ try
|
|
|
+ {
|
|
|
+ reader = (MySqlDataReader)result;
|
|
|
+ while (reader.Read())
|
|
|
+ {
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ Console.WriteLine(ex.Message + "查询车位表异常");
|
|
|
+ }
|
|
|
+ finally
|
|
|
+ {
|
|
|
+ if (reader != null)
|
|
|
+ {
|
|
|
+ reader.Close();
|
|
|
+ reader.Dispose();
|
|
|
+ }
|
|
|
+ ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
+ }
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
@@ -112,38 +146,55 @@ namespace parkMonitor.Database2
|
|
|
Vehicle v = new Vehicle();
|
|
|
MySqlDataReader reader = null;
|
|
|
string sql = "select * from vehicle where numberPlate = '" + numberPlate + "'";
|
|
|
- Connection conn = ConnectionPoolManager.GetConnection(bq);
|
|
|
- DBAccess access = new DBAccess(sql, conn, CommandTypes.QUERYCOMMAND);
|
|
|
- object result = access.GetResult();
|
|
|
- try
|
|
|
+ Connection conn = ConnectionPoolManager.GetConnection(bq, TIMEOUT);
|
|
|
+ int i = 0;
|
|
|
+ while (conn == null && i < 2)
|
|
|
{
|
|
|
- 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;
|
|
|
- }
|
|
|
- }
|
|
|
+ ConnectionPoolManager.CheckConnPooling(2, 10, ConnectionPoolManager.remoteConf, bq);
|
|
|
+ conn = ConnectionPoolManager.GetConnection(bq, TIMEOUT);
|
|
|
+ i++;
|
|
|
}
|
|
|
- catch (Exception ex)
|
|
|
+ if (conn == null)
|
|
|
{
|
|
|
- Console.WriteLine(ex.Message + "查询车辆表异常");
|
|
|
+ Console.WriteLine("请检查网络!等待网络修复超时");
|
|
|
}
|
|
|
- finally
|
|
|
+ else
|
|
|
{
|
|
|
- reader.Close();
|
|
|
- reader.Dispose();
|
|
|
- ConnectionPoolManager.ReleaseConnection(conn, 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
|
|
|
+ {
|
|
|
+ if (reader != null)
|
|
|
+ {
|
|
|
+ reader.Close();
|
|
|
+ reader.Dispose();
|
|
|
+ }
|
|
|
+ ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
+ }
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
@@ -158,33 +209,50 @@ namespace parkMonitor.Database2
|
|
|
Parking_Space ps = new Parking_Space();
|
|
|
MySqlDataReader reader = null;
|
|
|
string sql = "select * from parkingspace where parkingSpaceID = '" + parkingSpaceID + " '";
|
|
|
- Connection conn = ConnectionPoolManager.GetConnection(bq);
|
|
|
- DBAccess access = new DBAccess(sql, conn, CommandTypes.QUERYCOMMAND);
|
|
|
- object result = access.GetResult();
|
|
|
- try
|
|
|
+ Connection conn = ConnectionPoolManager.GetConnection(bq, TIMEOUT);
|
|
|
+ int i = 0;
|
|
|
+ while (conn == null && i < 2)
|
|
|
{
|
|
|
- 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;
|
|
|
- }
|
|
|
- }
|
|
|
+ ConnectionPoolManager.CheckConnPooling(2, 10, ConnectionPoolManager.remoteConf, bq);
|
|
|
+ conn = ConnectionPoolManager.GetConnection(bq, TIMEOUT);
|
|
|
+ i++;
|
|
|
}
|
|
|
- catch (Exception ex)
|
|
|
+ if (conn == null)
|
|
|
{
|
|
|
- Console.WriteLine(ex.Message + "查询车位表获取x,y,z异常");
|
|
|
+ Console.WriteLine("请检查网络!等待网络修复超时");
|
|
|
}
|
|
|
- finally
|
|
|
+ else
|
|
|
{
|
|
|
- reader.Close();
|
|
|
- reader.Dispose();
|
|
|
- ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
+ DBAccess access = new DBAccess(sql, conn, CommandTypes.QUERYCOMMAND);
|
|
|
+ object result = access.GetResult();
|
|
|
+ try
|
|
|
+ {
|
|
|
+ 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异常");
|
|
|
+ }
|
|
|
+ finally
|
|
|
+ {
|
|
|
+ if (reader != null)
|
|
|
+ {
|
|
|
+ reader.Close();
|
|
|
+ reader.Dispose();
|
|
|
+ }
|
|
|
+ ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
+ }
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
@@ -198,28 +266,42 @@ namespace parkMonitor.Database2
|
|
|
{
|
|
|
bool isTelRegister = false;
|
|
|
string sql = "select * from user where userTelephone = '" + tel + "'";
|
|
|
- Connection conn = ConnectionPoolManager.GetConnection(bq);
|
|
|
- DBAccess access = new DBAccess(sql, conn, CommandTypes.SCALARCOMMAND);
|
|
|
- object result = access.GetResult();
|
|
|
- try
|
|
|
+ Connection conn = ConnectionPoolManager.GetConnection(bq, TIMEOUT);
|
|
|
+ int i = 0;
|
|
|
+ while (conn == null && i < 2)
|
|
|
{
|
|
|
- int count = (int)result;
|
|
|
- if (count > 0)
|
|
|
- {
|
|
|
- isTelRegister = true;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- isTelRegister = false;
|
|
|
- }
|
|
|
+ ConnectionPoolManager.CheckConnPooling(2, 10, ConnectionPoolManager.remoteConf, bq);
|
|
|
+ conn = ConnectionPoolManager.GetConnection(bq, TIMEOUT);
|
|
|
+ i++;
|
|
|
}
|
|
|
- catch (Exception ex)
|
|
|
+ if (conn == null)
|
|
|
{
|
|
|
- Console.WriteLine(ex.Message + "检测电话号码注册异常");
|
|
|
+ Console.WriteLine("请检查网络!等待网络修复超时");
|
|
|
}
|
|
|
- finally
|
|
|
+ else
|
|
|
{
|
|
|
- ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
+ DBAccess access = new DBAccess(sql, conn, CommandTypes.SCALARCOMMAND);
|
|
|
+ object result = access.GetResult();
|
|
|
+ try
|
|
|
+ {
|
|
|
+ int count = (int)result;
|
|
|
+ if (count > 0)
|
|
|
+ {
|
|
|
+ isTelRegister = true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ isTelRegister = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ Console.WriteLine(ex.Message + "检测电话号码注册异常");
|
|
|
+ }
|
|
|
+ finally
|
|
|
+ {
|
|
|
+ ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
+ }
|
|
|
}
|
|
|
return isTelRegister;
|
|
|
}
|
|
@@ -234,36 +316,52 @@ namespace parkMonitor.Database2
|
|
|
int parkingRecordsID = 0;
|
|
|
MySqlDataReader reader = null;
|
|
|
string sql = "select parkingRecordsID from parkingrecords where numberPlate = '" + numberPlate + "' and parkingRecordsState = 3";
|
|
|
- Connection conn = ConnectionPoolManager.GetConnection(bq);
|
|
|
- DBAccess access = new DBAccess(sql, conn, CommandTypes.QUERYCOMMAND);
|
|
|
- object result = access.GetResult();
|
|
|
- try
|
|
|
+ Connection conn = ConnectionPoolManager.GetConnection(bq, TIMEOUT);
|
|
|
+ int i = 0;
|
|
|
+ while (conn == null && i < 2)
|
|
|
+ {
|
|
|
+ ConnectionPoolManager.CheckConnPooling(2, 10, ConnectionPoolManager.remoteConf, bq);
|
|
|
+ conn = ConnectionPoolManager.GetConnection(bq, TIMEOUT);
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ if (conn == null)
|
|
|
+ {
|
|
|
+ Console.WriteLine("请检查网络!等待网络修复超时");
|
|
|
+ }
|
|
|
+ else
|
|
|
{
|
|
|
- reader = (MySqlDataReader)result;
|
|
|
- while (reader.Read())
|
|
|
+ DBAccess access = new DBAccess(sql, conn, CommandTypes.QUERYCOMMAND);
|
|
|
+ object result = access.GetResult();
|
|
|
+ try
|
|
|
{
|
|
|
- if (reader.HasRows)
|
|
|
+ reader = (MySqlDataReader)result;
|
|
|
+ while (reader.Read())
|
|
|
{
|
|
|
- parkingRecordsID = reader.GetInt32("parkingRecordsID");
|
|
|
- return parkingRecordsID;
|
|
|
+ if (reader.HasRows)
|
|
|
+ {
|
|
|
+ parkingRecordsID = reader.GetInt32("parkingRecordsID");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Console.WriteLine("停车记录id查无结果");
|
|
|
+ }
|
|
|
}
|
|
|
- else
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ Console.WriteLine(ex.Message + "查询停车记录id异常");
|
|
|
+ }
|
|
|
+ finally
|
|
|
+ {
|
|
|
+ if (reader != null)
|
|
|
{
|
|
|
- Console.WriteLine("停车记录id查无结果");
|
|
|
+ reader.Close();
|
|
|
+ reader.Dispose();
|
|
|
}
|
|
|
+ ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
}
|
|
|
}
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- Console.WriteLine(ex.Message + "查询停车记录id异常");
|
|
|
- }
|
|
|
- finally
|
|
|
- {
|
|
|
- reader.Close();
|
|
|
- reader.Dispose();
|
|
|
- ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
- }
|
|
|
- return 0;
|
|
|
+ return parkingRecordsID;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -277,28 +375,42 @@ namespace parkMonitor.Database2
|
|
|
{
|
|
|
bool isNumberPlate = true;
|
|
|
string sql = "select * from parkingrecords where numberPlate = '" + numberPlate + "' and parkingRecordsState = 3 and garageID = '" + garageID + "'";
|
|
|
- Connection conn = ConnectionPoolManager.GetConnection(bq);
|
|
|
- DBAccess access = new DBAccess(sql, conn, CommandTypes.SCALARCOMMAND);
|
|
|
- object result = access.GetResult();
|
|
|
- try
|
|
|
+ Connection conn = ConnectionPoolManager.GetConnection(bq, TIMEOUT);
|
|
|
+ int i = 0;
|
|
|
+ while (conn == null && i < 2)
|
|
|
{
|
|
|
- int count = (int)result;
|
|
|
- if (count > 0)
|
|
|
- {
|
|
|
- isNumberPlate = true;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- isNumberPlate = false;
|
|
|
- }
|
|
|
+ ConnectionPoolManager.CheckConnPooling(2, 10, ConnectionPoolManager.remoteConf, bq);
|
|
|
+ conn = ConnectionPoolManager.GetConnection(bq, TIMEOUT);
|
|
|
+ i++;
|
|
|
}
|
|
|
- catch (Exception ex)
|
|
|
+ if (conn == null)
|
|
|
{
|
|
|
- Console.WriteLine(ex.Message + "检测车库中车辆异常");
|
|
|
+ Console.WriteLine("请检查网络!等待网络修复超时");
|
|
|
}
|
|
|
- finally
|
|
|
+ else
|
|
|
{
|
|
|
- ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
+ DBAccess access = new DBAccess(sql, conn, CommandTypes.SCALARCOMMAND);
|
|
|
+ object result = access.GetResult();
|
|
|
+ try
|
|
|
+ {
|
|
|
+ int count = (int)result;
|
|
|
+ if (count > 0)
|
|
|
+ {
|
|
|
+ isNumberPlate = true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ isNumberPlate = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ Console.WriteLine(ex.Message + "检测车库中车辆异常");
|
|
|
+ }
|
|
|
+ finally
|
|
|
+ {
|
|
|
+ ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
+ }
|
|
|
}
|
|
|
return isNumberPlate;
|
|
|
}
|
|
@@ -312,28 +424,42 @@ namespace parkMonitor.Database2
|
|
|
{
|
|
|
bool isNumberPlateFromVehicle = true;
|
|
|
string sql = "select * from vehicle where numberPlate = '" + numberPlate + "' and vehiclepParkState = 1";
|
|
|
- Connection conn = ConnectionPoolManager.GetConnection(bq);
|
|
|
- DBAccess access = new DBAccess(sql, conn, CommandTypes.SCALARCOMMAND);
|
|
|
- object result = access.GetResult();
|
|
|
- try
|
|
|
+ Connection conn = ConnectionPoolManager.GetConnection(bq, TIMEOUT);
|
|
|
+ int i = 0;
|
|
|
+ while (conn == null && i < 2)
|
|
|
{
|
|
|
- int count = (int)result;
|
|
|
- if (count > 0)
|
|
|
- {
|
|
|
- isNumberPlateFromVehicle = true;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- isNumberPlateFromVehicle = false;
|
|
|
- }
|
|
|
+ ConnectionPoolManager.CheckConnPooling(2, 10, ConnectionPoolManager.remoteConf, bq);
|
|
|
+ conn = ConnectionPoolManager.GetConnection(bq, TIMEOUT);
|
|
|
+ i++;
|
|
|
}
|
|
|
- catch (Exception ex)
|
|
|
+ if (conn == null)
|
|
|
{
|
|
|
- Console.WriteLine(ex.Message + "检测车辆表车辆号牌异常");
|
|
|
+ Console.WriteLine("请检查网络!等待网络修复超时");
|
|
|
}
|
|
|
- finally
|
|
|
+ else
|
|
|
{
|
|
|
- ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
+ DBAccess access = new DBAccess(sql, conn, CommandTypes.SCALARCOMMAND);
|
|
|
+ object result = access.GetResult();
|
|
|
+ try
|
|
|
+ {
|
|
|
+ int count = (int)result;
|
|
|
+ if (count > 0)
|
|
|
+ {
|
|
|
+ isNumberPlateFromVehicle = true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ isNumberPlateFromVehicle = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ Console.WriteLine(ex.Message + "检测车辆表车辆号牌异常");
|
|
|
+ }
|
|
|
+ finally
|
|
|
+ {
|
|
|
+ ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
+ }
|
|
|
}
|
|
|
return isNumberPlateFromVehicle;
|
|
|
}
|
|
@@ -346,10 +472,24 @@ namespace parkMonitor.Database2
|
|
|
public void UpdateVehicleParkState(BlockingQueue bq, string numberPlate, int vehiclepParkState)
|
|
|
{
|
|
|
string sql = "update vehicle set vehiclepParkState = '" + vehiclepParkState + "'where numberPlate = '" + numberPlate + "'";
|
|
|
- Connection conn = ConnectionPoolManager.GetConnection(bq);
|
|
|
- DBAccess access = new DBAccess(sql, conn, CommandTypes.NOQUERYCOMMAND);
|
|
|
- object result = access.GetResult();
|
|
|
- ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
+ Connection conn = ConnectionPoolManager.GetConnection(bq, TIMEOUT);
|
|
|
+ int i = 0;
|
|
|
+ while (conn == null && i < 2)
|
|
|
+ {
|
|
|
+ ConnectionPoolManager.CheckConnPooling(2, 10, ConnectionPoolManager.remoteConf, bq);
|
|
|
+ conn = ConnectionPoolManager.GetConnection(bq, TIMEOUT);
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ if (conn == null)
|
|
|
+ {
|
|
|
+ Console.WriteLine("请检查网络!等待网络修复超时");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ DBAccess access = new DBAccess(sql, conn, CommandTypes.NOQUERYCOMMAND);
|
|
|
+ object result = access.GetResult();
|
|
|
+ ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
+ }
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 更新车位状态
|
|
@@ -360,11 +500,94 @@ namespace parkMonitor.Database2
|
|
|
public void UpdateParkingSpaceState(BlockingQueue bq, int parkingSpaceID, int parkingSpaceState)
|
|
|
{
|
|
|
string sql = "update parkingspace set parkingSpaceState = '" + parkingSpaceState + "'where parkingSpaceID = '" + parkingSpaceID + "'";
|
|
|
- Connection conn = ConnectionPoolManager.GetConnection(bq);
|
|
|
- DBAccess access = new DBAccess(sql, conn, CommandTypes.NOQUERYCOMMAND);
|
|
|
- object result = access.GetResult();
|
|
|
- ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
+ Connection conn = ConnectionPoolManager.GetConnection(bq, TIMEOUT);
|
|
|
+ int i = 0;
|
|
|
+ while (conn == null && i < 2)
|
|
|
+ {
|
|
|
+ ConnectionPoolManager.CheckConnPooling(2, 10, ConnectionPoolManager.remoteConf, bq);
|
|
|
+ conn = ConnectionPoolManager.GetConnection(bq, TIMEOUT);
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ if (conn == null)
|
|
|
+ {
|
|
|
+ Console.WriteLine("请检查网络!等待网络修复超时");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ 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)
|
|
|
+ {
|
|
|
+ int parkingRecordsID = 0;
|
|
|
+ Connection conn = ConnectionPoolManager.GetConnection(bq, TIMEOUT);
|
|
|
+ int i = 0;
|
|
|
+ while (conn == null && i < 2)
|
|
|
+ {
|
|
|
+ ConnectionPoolManager.CheckConnPooling(2, 10, ConnectionPoolManager.remoteConf, bq);
|
|
|
+ conn = ConnectionPoolManager.GetConnection(bq, TIMEOUT);
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ if (conn == null)
|
|
|
+ {
|
|
|
+ Console.WriteLine("请检查网络!等待网络修复超时");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ DBAccess access = new DBAccess(null, conn, CommandTypes.TRANSACTIONCOMMAND);
|
|
|
+ TransactionResult transactionResult = access.DealTransaction(strs);
|
|
|
+ try
|
|
|
+ {
|
|
|
+ parkingRecordsID = transactionResult.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 bool UpdateTransaction(BlockingQueue bq, List<string> strs)
|
|
|
+ {
|
|
|
+ bool flag = true;
|
|
|
+ Connection conn = ConnectionPoolManager.GetConnection(bq, TIMEOUT);
|
|
|
+ int i = 0;
|
|
|
+ while (conn == null && i < 2)
|
|
|
+ {
|
|
|
+ ConnectionPoolManager.CheckConnPooling(2, 10, ConnectionPoolManager.remoteConf, bq);
|
|
|
+ conn = ConnectionPoolManager.GetConnection(bq, TIMEOUT);
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ if (conn == null)
|
|
|
+ {
|
|
|
+ Console.WriteLine("请检查网络!等待网络修复超时");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ DBAccess access = new DBAccess(null, conn, CommandTypes.TRANSACTIONCOMMAND);
|
|
|
+ TransactionResult transactionResult = access.DealTransaction(strs);
|
|
|
+ flag = transactionResult.flag;
|
|
|
+ }
|
|
|
+ return flag;
|
|
|
+ }
|
|
|
+
|
|
|
///// <summary>
|
|
|
///// 插入停车记录表事务
|
|
|
///// </summary>
|
|
@@ -374,8 +597,43 @@ namespace parkMonitor.Database2
|
|
|
//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();
|
|
|
+ // 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
|
|
|
// {
|
|
@@ -383,7 +641,7 @@ namespace parkMonitor.Database2
|
|
|
// }
|
|
|
// catch (Exception ex)
|
|
|
// {
|
|
|
- // Console.WriteLine(ex.Message+"停车记录ID获取失败");
|
|
|
+ // Console.WriteLine(ex.Message + "停车记录ID获取失败");
|
|
|
// }
|
|
|
// finally
|
|
|
// {
|
|
@@ -396,120 +654,47 @@ namespace parkMonitor.Database2
|
|
|
///// </summary>
|
|
|
///// <param name="bq"></param>
|
|
|
///// <param name="strs"></param>
|
|
|
- //public static void UpdateTransaction(BlockingQueue bq, List<string> strs)
|
|
|
+ //public static object UpdateTransaction(BlockingQueue bq, List<string> strs)
|
|
|
//{
|
|
|
// Connection conn = ConnectionPoolManager.GetConnection(bq);
|
|
|
- // DBAccess access = new DBAccess(conn, CommandTypes.TRANSACTIONCOMMAND, strs);
|
|
|
- // object result = access.DealTransaction();
|
|
|
+ // 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;
|
|
|
//}
|
|
|
-
|
|
|
- /// <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;
|
|
|
- }
|
|
|
}
|
|
|
}
|