|
@@ -18,6 +18,15 @@ namespace DBManager
|
|
|
public SQLiteConnection m_db;
|
|
|
private MeasureFile m_measureFile; //测量文件
|
|
|
|
|
|
+
|
|
|
+ private List<byte[]> LineXraybyte = new List<byte[]>();
|
|
|
+ private List<string> LineXraystring = new List<string>();
|
|
|
+ private List<string> LineXray = new List<string>();
|
|
|
+
|
|
|
+ private List<byte[]> PoinXraybyte = new List<byte[]>();
|
|
|
+ private List<string> PoinXraystring = new List<string>();
|
|
|
+ private List<string> PoinXray = new List<string>();
|
|
|
+
|
|
|
public MeasureDB(MeasureFile mf)
|
|
|
{
|
|
|
Init(mf);
|
|
@@ -48,8 +57,9 @@ namespace DBManager
|
|
|
//{
|
|
|
// File.Delete(path);
|
|
|
//}
|
|
|
-
|
|
|
+
|
|
|
m_db = new SQLiteConnection("data source =" + path);
|
|
|
+ //m_db = new SQLiteConnection("data source =" + @"D:\HOZ\数据库测试\MeasureDB.db");
|
|
|
m_db.Open();
|
|
|
}
|
|
|
|
|
@@ -262,73 +272,62 @@ namespace DBManager
|
|
|
public bool InsertAPointXray(int PointsId, int XrayId, int X, int Y, long[] XrayData, Dictionary<string, double> listElement, int ImageID)
|
|
|
{
|
|
|
byte[] bArray = new byte[8000];
|
|
|
-
|
|
|
- for (int i = 0; i < 2000; i++)
|
|
|
+ for (int a = 0; a < 2000; a++)
|
|
|
{
|
|
|
- byte[] temps = BitConverter.GetBytes(XrayData[i]);
|
|
|
- bArray[i * 4] = temps[0];
|
|
|
- bArray[i * 4 + 1] = temps[1];
|
|
|
- bArray[i * 4 + 2] = temps[2];
|
|
|
- bArray[i * 4 + 3] = temps[3];
|
|
|
+ byte[] temps = BitConverter.GetBytes(XrayData[a]);
|
|
|
+ bArray[a * 4] = temps[0];
|
|
|
+ bArray[a * 4 + 1] = temps[1];
|
|
|
+ bArray[a * 4 + 2] = temps[2];
|
|
|
+ bArray[a * 4 + 3] = temps[3];
|
|
|
}
|
|
|
-
|
|
|
//开启一个事务
|
|
|
- using (SQLiteTransaction tr = m_db.BeginTransaction())
|
|
|
+ //using (SQLiteTransaction tr = m_db.BeginTransaction())
|
|
|
+ //{
|
|
|
+ //向能谱数据表插入数据
|
|
|
+ string sql = "INSERT INTO XrayData(ID, APID, ImageID, Type, X, Y, AreasID, ElementNum, XrayData) values ("
|
|
|
+ + XrayId.ToString() + ","
|
|
|
+ + PointsId.ToString() + ","
|
|
|
+ + ImageID.ToString() + ","
|
|
|
+ + 0.ToString() + ","
|
|
|
+ + X.ToString() + ","
|
|
|
+ + Y.ToString() + ","
|
|
|
+ + (-1).ToString() + ","
|
|
|
+ + listElement.Count.ToString() + ",:XrayData)";
|
|
|
+ PoinXraybyte.Add(bArray);
|
|
|
+ PoinXraystring.Add(sql);
|
|
|
+ //SQLiteCommand command = new SQLiteCommand(sql, m_db);
|
|
|
+ //command.Parameters.Add("XrayData", System.Data.DbType.Binary).Value = bArray; // BLOB
|
|
|
+ //command.ExecuteNonQuery();
|
|
|
+ //向能谱元素表插入数据
|
|
|
+ int i = 1;
|
|
|
+ foreach (KeyValuePair<string, double> element in listElement)
|
|
|
{
|
|
|
- //向能谱数据表插入数据
|
|
|
- string sql = "INSERT INTO XrayData(ID, APID, ImageID, Type, X, Y, AreasID, ElementNum, XrayData) values ("
|
|
|
- + XrayId.ToString() + ","
|
|
|
- + PointsId.ToString() + ","
|
|
|
- + ImageID.ToString() + ","
|
|
|
- + 0.ToString() + ","
|
|
|
- + X.ToString() + ","
|
|
|
- + Y.ToString() + ","
|
|
|
- + (-1).ToString() + ","
|
|
|
- + listElement.Count.ToString() + ",:XrayData)";
|
|
|
-
|
|
|
- SQLiteCommand command = new SQLiteCommand(sql, m_db);
|
|
|
- command.Parameters.Add("XrayData", System.Data.DbType.Binary).Value = bArray; // BLOB
|
|
|
- command.ExecuteNonQuery();
|
|
|
-
|
|
|
- //向能谱元素表插入数据
|
|
|
- int i = 1;
|
|
|
- foreach (KeyValuePair<string, double> element in listElement)
|
|
|
- {
|
|
|
-
|
|
|
- sql = "INSERT INTO Element(XayID, ElementNum, ElementID, Name, Percent) values ("
|
|
|
- + XrayId.ToString() + ","
|
|
|
- + listElement.Count.ToString() + ","
|
|
|
- + i.ToString() + ",'"
|
|
|
- + element.Key + "',"
|
|
|
- + element.Value.ToString() + ")";
|
|
|
-
|
|
|
- command = new SQLiteCommand(sql, m_db);
|
|
|
- command.ExecuteNonQuery();
|
|
|
- i++;
|
|
|
- }
|
|
|
-
|
|
|
- //向位置表插入数据
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- sql = "INSERT INTO AreaPosition(XrayID, AID, SegNum, SegID, X, Y, Length) values ("
|
|
|
- + XrayId.ToString() + ","
|
|
|
- + PointsId.ToString() + ","
|
|
|
- + (-1).ToString() + ","
|
|
|
- + (-1).ToString() + ","
|
|
|
- + X.ToString() + ","
|
|
|
- + Y.ToString() + ","
|
|
|
- + (0).ToString() + ")";
|
|
|
-
|
|
|
- command = new SQLiteCommand(sql, m_db);
|
|
|
- command.ExecuteNonQuery();
|
|
|
-
|
|
|
-
|
|
|
- tr.Commit();
|
|
|
-
|
|
|
- Thread.Sleep(500);
|
|
|
+ sql = "INSERT INTO Element(XayID, ElementNum, ElementID, Name, Percent) values ("
|
|
|
+ + XrayId.ToString() + ","
|
|
|
+ + listElement.Count.ToString() + ","
|
|
|
+ + i.ToString() + ",'"
|
|
|
+ + element.Key + "',"
|
|
|
+ + element.Value.ToString() + ")";
|
|
|
+ PoinXray.Add(sql);
|
|
|
+ //command = new SQLiteCommand(sql, m_db);
|
|
|
+ //command.ExecuteNonQuery();
|
|
|
+ i++;
|
|
|
}
|
|
|
+ //向位置表插入数据
|
|
|
+ sql = "INSERT INTO AreaPosition(XrayID, AID, SegNum, SegID, X, Y, Length) values ("
|
|
|
+ + XrayId.ToString() + ","
|
|
|
+ + PointsId.ToString() + ","
|
|
|
+ + (-1).ToString() + ","
|
|
|
+ + (-1).ToString() + ","
|
|
|
+ + X.ToString() + ","
|
|
|
+ + Y.ToString() + ","
|
|
|
+ + (0).ToString() + ")";
|
|
|
+ PoinXray.Add(sql);
|
|
|
+ //command = new SQLiteCommand(sql, m_db);
|
|
|
+ //command.ExecuteNonQuery();
|
|
|
+ //tr.Commit();
|
|
|
+ Thread.Sleep(200);
|
|
|
+ //}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
@@ -402,5 +401,106 @@ namespace DBManager
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
+ public bool SaveToMemory(int PointsId, int XrayId, int AreaId, List<Segment> listSeg, long[] XrayData, Dictionary<string, double> listElement, int ImageID)
|
|
|
+ {
|
|
|
+ byte[] bArray = new byte[8000];
|
|
|
+ for (int a = 0; a < 2000; a++)
|
|
|
+ {
|
|
|
+ byte[] temps = BitConverter.GetBytes(XrayData[a]);
|
|
|
+ bArray[a * 4] = temps[0];
|
|
|
+ bArray[a * 4 + 1] = temps[1];
|
|
|
+ bArray[a * 4 + 2] = temps[2];
|
|
|
+ bArray[a * 4 + 3] = temps[3];
|
|
|
+ }
|
|
|
+ //向能谱数据表插入数据
|
|
|
+ string sql = "INSERT INTO XrayData(ID, APID, ImageID, Type, X, Y, AreasID, ElementNum, XrayData) values ("
|
|
|
+ + XrayId.ToString() + ","
|
|
|
+ + PointsId.ToString() + ","
|
|
|
+ + ImageID.ToString() + ","
|
|
|
+ + 1.ToString() + ","
|
|
|
+ + (-1).ToString() + ","
|
|
|
+ + (-1).ToString() + ","
|
|
|
+ + AreaId.ToString() + ","
|
|
|
+ + listElement.Count.ToString() + ",:XrayData)";
|
|
|
+ LineXraystring.Add(sql);
|
|
|
+ LineXraybyte.Add(bArray);
|
|
|
+ //向能谱元素表插入数据
|
|
|
+ int i = 1;
|
|
|
+ foreach (KeyValuePair<string, double> element in listElement)
|
|
|
+ {
|
|
|
+ sql = "INSERT INTO Element(XayID, ElementNum, ElementID, Name, Percent) values ("
|
|
|
+ + XrayId.ToString() + ","
|
|
|
+ + listElement.Count.ToString() + ","
|
|
|
+ + i.ToString() + ",'"
|
|
|
+ + element.Key + "',"
|
|
|
+ + element.Value.ToString() + ")";
|
|
|
+ LineXray.Add(sql);
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ //向位置表插入数据
|
|
|
+ i = 1;
|
|
|
+ foreach (Segment seg in listSeg)
|
|
|
+ {
|
|
|
+ sql = "INSERT INTO AreaPosition(XrayID, AID, SegNum, SegID, X, Y, Length) values ("
|
|
|
+ + XrayId.ToString() + ","
|
|
|
+ + PointsId.ToString() + ","
|
|
|
+ + listSeg.Count.ToString() + ","
|
|
|
+ + i.ToString() + ","
|
|
|
+ + seg.X.ToString() + ","
|
|
|
+ + seg.Y.ToString() + ","
|
|
|
+ + seg.Length.ToString() + ")";
|
|
|
+ LineXray.Add(sql);
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ public bool PointDataSubmitted()
|
|
|
+ {
|
|
|
+ using (SQLiteTransaction tr = m_db.BeginTransaction())
|
|
|
+ {
|
|
|
+ for (int i = 0; i < PoinXraystring.Count(); i++)
|
|
|
+ {
|
|
|
+ SQLiteCommand command = new SQLiteCommand(LineXraystring[i], m_db);
|
|
|
+ command.Parameters.Add("XrayData", System.Data.DbType.Binary).Value = PoinXraybyte[i]; // BLOB
|
|
|
+ command.ExecuteNonQuery();
|
|
|
+ }
|
|
|
+ for (int i = 0; i < PoinXray.Count(); i++)
|
|
|
+ {
|
|
|
+ SQLiteCommand command = new SQLiteCommand(PoinXray[i], m_db);
|
|
|
+ command.ExecuteNonQuery();
|
|
|
+ }
|
|
|
+ tr.Commit();
|
|
|
+ }
|
|
|
+ PoinXraystring.Clear();
|
|
|
+ PoinXraybyte.Clear();
|
|
|
+ PoinXray.Clear();
|
|
|
+ return true;
|
|
|
+
|
|
|
+ }
|
|
|
+ public bool LineDataSubmitted()
|
|
|
+ {
|
|
|
+ using (SQLiteTransaction tr = m_db.BeginTransaction())
|
|
|
+ {
|
|
|
+ for (int i = 0; i < LineXraystring.Count(); i++)
|
|
|
+ {
|
|
|
+ SQLiteCommand command = new SQLiteCommand(LineXraystring[i], m_db);
|
|
|
+ command.Parameters.Add("XrayData", System.Data.DbType.Binary).Value = LineXraybyte[i]; // BLOB
|
|
|
+ command.ExecuteNonQuery();
|
|
|
+ }
|
|
|
+ for (int i = 0; i < LineXray.Count(); i++)
|
|
|
+ {
|
|
|
+ SQLiteCommand command = new SQLiteCommand(LineXray[i], m_db);
|
|
|
+ command.ExecuteNonQuery();
|
|
|
+ }
|
|
|
+ tr.Commit();
|
|
|
+ }
|
|
|
+ LineXraystring.Clear();
|
|
|
+ LineXraybyte.Clear();
|
|
|
+ LineXray.Clear();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
}
|