Explorar o código

更改EDS程序和数据库处理操作。

@wang_qi0307 %!s(int64=4) %!d(string=hai) anos
pai
achega
dc232c4b0d

+ 26 - 21
DBManager/MeasureDB.cs

@@ -37,11 +37,11 @@ namespace DBManager
         public void CreateDB()
         {
             string path = Path.GetDirectoryName(m_measureFile.FileName);
-            path += "//MeasureDB.db";
+            path += "\\MeasureDB.db";
 
-            if (Directory.Exists(path))
+            if (File.Exists(path))
             {
-                Directory.Delete(path);
+                File.Delete(path);
             }
 
             m_db = new SQLiteConnection("data source =" + path);
@@ -194,11 +194,13 @@ namespace DBManager
             //第3列,SegNum
             sql = sql + ",";
             sql = sql + "SegNum INTEGER";
-           
+            sPrimary = sPrimary + ", SegNum";
+
             //第4列,SegID
             sql = sql + ",";
             sql = sql + "SegID INTEGER";
-            
+            sPrimary = sPrimary + ", SegID";
+
             //第5列,X
             sql = sql + ",";
             sql = sql + "X INTEGER";
@@ -218,8 +220,7 @@ namespace DBManager
             command.ExecuteNonQuery();
         }
 
-        public bool InsetAPoint(int PointsId, string PointName, string EDSImagePath,
-            bool HavePoints, int PointsNum, bool HaveArea, int AreasNum)
+        public bool InsetAPoint(int PointsId, string PointName, string EDSImagePath, int PointsNum, int AreasNum)
         {
             //开启一个事务
             using (SQLiteTransaction tr = m_db.BeginTransaction())
@@ -229,9 +230,9 @@ namespace DBManager
                     + PointsId.ToString() + ","
                     + "'" + PointName + "'" + ","
                     + "'" + EDSImagePath + "'" + ","
-                    + Convert.ToInt32(HavePoints).ToString() + ","
+                    + Convert.ToInt32(Convert.ToBoolean(PointsNum)).ToString() + ","
                     + PointsNum.ToString() + ","
-                    + Convert.ToInt32(HaveArea).ToString() + ","
+                    + Convert.ToInt32(Convert.ToBoolean(AreasNum)).ToString() + ","
                     + AreasNum.ToString() + ")";
 
                 SQLiteCommand command = new SQLiteCommand(sql, m_db);
@@ -244,15 +245,17 @@ namespace DBManager
         //插入一条点扫描Xray的信息
         public bool InsertAPointXay(int PointsId, int XrayId, int X, int Y,long[] XrayData, Dictionary<string, double> listElement)
         {
+            Console.WriteLine(XrayId.ToString() + "," + PointsId.ToString());
+
             byte[] bArray = new byte[8000];
 
             for (int i = 0; i < 2000; i++)
             {
                 byte[] temps = BitConverter.GetBytes(XrayData[i]);
-                bArray[i] = temps[0];
-                bArray[i+1] = temps[1];
-                bArray[i+2] = temps[2];
-                bArray[i+3] = temps[3];
+                bArray[i * 4] = temps[0];
+                bArray[i * 4 + 1] = temps[1];
+                bArray[i * 4 + 2] = temps[2];
+                bArray[i * 4 + 3] = temps[3];
             }
 
             //开启一个事务
@@ -273,15 +276,15 @@ namespace DBManager
                 command.ExecuteNonQuery();
 
                 //向能谱元素表插入数据
-                int i = 0;
+                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 + ","
+                       + i.ToString() + ",'"
+                       + element.Key + "',"
                        + element.Value.ToString() + ")";
 
                     command = new SQLiteCommand(sql, m_db);
@@ -290,6 +293,8 @@ namespace DBManager
                 }
                 
                 tr.Commit();
+
+                Console.WriteLine(XrayId.ToString() + "," + PointsId.ToString());
             }
             return true;
         }
@@ -325,15 +330,15 @@ namespace DBManager
                 command.ExecuteNonQuery();
                 
                 //向能谱元素表插入数据
-                int i = 0;
+                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 + ","
+                       + i.ToString() + ",'"
+                       + element.Key + "',"
                        + element.Value.ToString() + ")";
 
                     command = new SQLiteCommand(sql, m_db);
@@ -342,11 +347,11 @@ namespace DBManager
                 }
                 //向位置表插入数据
 
-                i = 0;
+                i = 1;
                 foreach (Segment seg in listSeg)
                 {
 
-                    sql = "INSERT INTO AreaPosition(XayID, AID, SegNum, SegID, X, Y, Length) values ("
+                    sql = "INSERT INTO AreaPosition(XrayID, AID, SegNum, SegID, X, Y, Length) values ("
                        + XrayId.ToString() + ","
                        + AreaId.ToString() + ","
                        + listSeg.Count.ToString() + ","

+ 15 - 3
ExtenderControl/Extender.cs

@@ -1107,6 +1107,11 @@ namespace Extender
         {            
         }
 
+        public bool IsAcquiringSpectrum()
+        {
+             return EdSpectrumAcquisitionController.IsAcquiring; 
+        }
+
         //点扫描
         //X-ray
         public Boolean XrayPointCollectiong(double dMilliSecondsTime, int x, int y, out long[] XrayData, out Dictionary<string, double> a_listElement)
@@ -1118,14 +1123,20 @@ namespace Extender
 
             SetXrayAcquisitionParam(dMilliSecondsTime);
             SetPointAcquistionRegion(x, y);
-           
+
+            
+
             // IEdSpectrumSettings.EdCapabilities will validate settings and hardware availability.
             if (EdSpectrumAcquisitionController.IsEdHardwareReady(EdSpectrumSettings))
             {
+
+
+
                 // This only used for multiple acquisition:
                 //      if this is the first acquisition, call BeginMultipleAcquisition 
                 //      on the IEdSpectrumAcquisitionController to suppress external scan switching
-                EdSpectrumAcquisitionController.BeginMultipleAcquisition();
+                if (m_bXrayDone)
+                    EdSpectrumAcquisitionController.BeginMultipleAcquisition();
 
                 // Start spectrum acquisition
                 try
@@ -1186,7 +1197,8 @@ namespace Extender
                 // This only used for multiple acquisition:
                 //      if this is the first acquisition, call BeginMultipleAcquisition 
                 //      on the IEdSpectrumAcquisitionController to suppress external scan switching
-                EdSpectrumAcquisitionController.BeginMultipleAcquisition();
+                if (m_bXrayDone)
+                    EdSpectrumAcquisitionController.BeginMultipleAcquisition();
 
                 // Start spectrum acquisition
                 try

+ 5 - 3
ExtenderControl/ExtenderInterface.cs

@@ -51,7 +51,7 @@ namespace Extender
         {
             get { return m_nX; }
             set {
-                if (m_nX > 0)
+                if (value > 0)
                 {
                     m_nX = value;
                 }
@@ -63,7 +63,7 @@ namespace Extender
             get { return m_nY; }
             set
             {
-                if (m_nY > 0)
+                if (value > 0)
                 {
                     m_nY = value;
                 }
@@ -75,7 +75,7 @@ namespace Extender
             get { return m_nLength; }
             set
             {
-                if (m_nLength > 0)
+                if (value > 0)
                 {
                     m_nLength = value;
                 }
@@ -135,6 +135,8 @@ namespace Extender
         //获取bitmap
         Bitmap GetBitmap();
 
+        bool IsAcquiringSpectrum();
+
         //X-ray
         //点采集
         Boolean XrayPointCollectiong(double dMilliSecondsTime, int x, int y, out long[] XrayData, out Dictionary<string, double> a_listElement);

+ 2 - 2
ManulDo/packages.config

@@ -3,8 +3,8 @@
   <package id="EntityFramework" version="6.3.0" targetFramework="net462" />
   <package id="OpenCvSharp3-AnyCPU" version="4.0.0.20181129" targetFramework="net461" />
   <package id="Stub.System.Data.SQLite.Core.NetFramework" version="1.0.113.3" targetFramework="net462" />
-  <package id="System.Data.SQLite" version="1.0.113.5" targetFramework="net462" />
-  <package id="System.Data.SQLite.Core" version="1.0.113.5" targetFramework="net462" />
+  <package id="System.Data.SQLite" version="1.0.113.6" targetFramework="net462" />
+  <package id="System.Data.SQLite.Core" version="1.0.113.6" targetFramework="net462" />
   <package id="System.Data.SQLite.EF6" version="1.0.113.0" targetFramework="net462" />
   <package id="System.Data.SQLite.Linq" version="1.0.113.0" targetFramework="net462" />
 </packages>

+ 1 - 2
MeasureThread/Measure.cs

@@ -597,8 +597,7 @@ namespace MeasureThread
             List<List<Segment>> listFeature = new List<List<Segment>>();
 
             //向分析点数据库更新
-            if (!m_MeasDB.InsetAPoint(a_PointNum, PointsName, EDS_path,
-           param.PointMode, listPoints.Count, param.AreaMode, listFeature.Count))
+            if (!m_MeasDB.InsetAPoint(a_PointNum, PointsName, EDS_path,listPoints.Count,listFeature.Count))
             {
                 LogManager.AddHardwareLog("插入分析点失败", true);
             }

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 260 - 159
OxfordTest/Form1.Designer.cs


+ 213 - 2
OxfordTest/Form1.cs

@@ -9,6 +9,9 @@ using System.Threading.Tasks;
 using System.Windows.Forms;
 using System.Windows.Forms.DataVisualization.Charting;
 using Extender;
+using DBManager;
+using MeasureData;
+using System.Data.SQLite;
 
 namespace OxfordTest
 {
@@ -272,14 +275,71 @@ namespace OxfordTest
             }
         }
 
+        int li = 0;
         //点采集
         private void button25_Click(object sender, EventArgs e)
         {
+            
             long[] XrayData = new long[2000];
             Dictionary<string, double> listElement = new Dictionary<string, double>();
-            iExtender.XrayPointCollectiong(200,1, 1, out XrayData, out listElement);
+            iExtender.XrayPointCollectiong(200,44, 55, out XrayData, out listElement);
 
             ShowData(XrayData, listElement);
+            li++;
+            Console.WriteLine(li.ToString());
+            //byte[] bArray = new byte[8000];
+
+            //for (int i = 0; i < 2000; i++)
+            //{
+            //    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];
+            //}
+
+            //SQLiteConnection m_db = new SQLiteConnection("data source =" + @"E:\HOZ\Test\MeasureDB.db");
+            //m_db.Open();
+
+            ////开启一个事务
+            //using (SQLiteTransaction tr = m_db.BeginTransaction())
+            //{
+            //    //向能谱数据表插入数据
+            //    string sql = "INSERT INTO XrayData(ID, APID, Type, X, Y, AreasID, ElementNum, XrayData) values ("
+            //        + 2.ToString() + ","
+            //        + 3.ToString() + ","
+            //        + 0.ToString() + ","
+            //        + 111.ToString() + ","
+            //        + 222.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 = 0;
+            //    foreach (KeyValuePair<string, double> element in listElement)
+            //    {
+
+            //        sql = "INSERT INTO Element(XayID, ElementNum, ElementID, Name, Percent) values ("
+            //           + 2.ToString() + ","
+            //           + listElement.Count.ToString() + ","
+            //           + i.ToString() + ",'"
+            //           + element.Key + "',"
+            //           + element.Value.ToString() + ")";
+
+            //        command = new SQLiteCommand(sql, m_db);
+            //        command.ExecuteNonQuery();
+            //        i++;
+            //    }
+
+            //    tr.Commit();
+            //}
+
+            //m_db.Close();
+            //m_db.Dispose();
         }
 
         void ShowData(long[] XrayData, Dictionary<string, double> listElement)
@@ -293,13 +353,27 @@ namespace OxfordTest
             }
 
             this.dataGridView1.Rows.Clear();
-            int index = this.dataGridView1.Rows.Add();
+            int index = 0; 
 
             var ie = listElement.GetEnumerator();
             while (ie.MoveNext())
             {
+                this.dataGridView1.Rows.Add();
                 this.dataGridView1.Rows[index].Cells[0].Value = ie.Current.Key;
                 this.dataGridView1.Rows[index].Cells[1].Value = ie.Current.Value;
+                index++;
+            }
+
+        }
+
+        void ShowReadData(long[] XrayData)
+        {
+            Series series = chart1.Series[1];
+            series.Points.Clear();
+
+            for (int i = 0; i < 2000; i++)
+            {
+                series.Points.AddXY(i, XrayData[i]);
             }
 
         }
@@ -329,5 +403,142 @@ namespace OxfordTest
             iExtender.XrayAreaCollectiong(200, listSeg, out XrayData, out listElement);
             ShowData(XrayData, listElement);
         }
+
+        private void btnCreateDB_Click(object sender, EventArgs e)
+        {
+            MeasureFile msf = new MeasureFile();
+            msf.FileName = @"E:\HOZ\Test\asd.msf";
+            MeasureDB db = new MeasureDB(msf);
+        }
+
+        private void btnReadP_Click(object sender, EventArgs e)
+        {
+            SQLiteConnection m_db = new SQLiteConnection("data source =" + @"E:\HOZ\Test\MeasureDB.db");
+            m_db.Open();
+
+            String sql = "Select XrayData from XrayData where ID =" + NUDNum.Value.ToString();
+            //SQLiteDataAdapter adapter = new SQLiteDataAdapter(sql, m_db);
+            //DataSet ds = new DataSet();
+            //adapter.Fill(ds);
+            //DataTable dt = ds.Tables[0];
+
+            SQLiteCommand cmd = new SQLiteCommand(sql, m_db);
+            SQLiteDataReader sdr = cmd.ExecuteReader();
+            sdr.Read();
+            byte[] blob = null;
+            blob = new byte[sdr.GetBytes(0, 0, null, 0, int.MaxValue)];
+            sdr.GetBytes(0, 0, blob, 0, blob.Length);
+
+            sdr.Close();
+            m_db.Close();
+            m_db.Dispose();
+
+            long[] rd = new long[blob.Length / 4];
+            for(int i=0;i<rd.Length;i++)
+            {
+                long temp = BitConverter.ToInt32(blob, i * 4);
+                rd[i] = temp + 10;
+            }
+
+            ShowReadData(rd);
+        }
+
+        private void btnTest_Click(object sender, EventArgs e)
+        {
+            List<Point> listPoints = new List<Point>();
+            List<List<Segment>> listFeature = new List<List<Segment>>();
+            List<Segment> ls = new List<Segment>();
+
+            listPoints.Add(new Point(Convert.ToInt32(txtpx1.Text), Convert.ToInt32(txtpy1.Text)));
+            listPoints.Add(new Point(Convert.ToInt32(txtpx2.Text), Convert.ToInt32(txtpy2.Text)));
+            listPoints.Add(new Point(Convert.ToInt32(txtpx3.Text), Convert.ToInt32(txtpy3.Text)));
+            listPoints.Add(new Point(Convert.ToInt32(txtpx4.Text), Convert.ToInt32(txtpy4.Text)));
+            listPoints.Add(new Point(Convert.ToInt32(txtpx5.Text), Convert.ToInt32(txtpy5.Text)));
+
+            Segment sgt = new Segment();
+            sgt.X = Convert.ToInt32(txtarea1x1.Text);
+            sgt.Y = Convert.ToInt32(txtarea1y1.Text);
+            sgt.Length = Convert.ToInt32(txtarea1l1.Text);
+            ls.Add(sgt);
+            sgt = new Segment();
+            sgt.X = Convert.ToInt32(txtarea1x2.Text);
+            sgt.Y = Convert.ToInt32(txtarea1y2.Text);
+            sgt.Length = Convert.ToInt32(txtarea1l2.Text);
+            ls.Add(sgt);
+            sgt = new Segment();
+            sgt.X = Convert.ToInt32(txtarea1x3.Text);
+            sgt.Y = Convert.ToInt32(txtarea1y3.Text);
+            sgt.Length = Convert.ToInt32(txtarea1l3.Text);
+            ls.Add(sgt);
+
+            listFeature.Add(ls);
+
+            ls = new List<Segment>();
+            sgt = new Segment();
+            sgt.X = Convert.ToInt32(txtarea2x1.Text);
+            sgt.Y = Convert.ToInt32(txtarea2y1.Text);
+            sgt.Length = Convert.ToInt32(txtarea2l1.Text);
+            ls.Add(sgt);
+            sgt = new Segment();
+            sgt.X = Convert.ToInt32(txtarea2x2.Text);
+            sgt.Y = Convert.ToInt32(txtarea2y2.Text);
+            sgt.Length = Convert.ToInt32(txtarea2l2.Text);
+            ls.Add(sgt);
+            sgt = new Segment();
+            sgt.X = Convert.ToInt32(txtarea2x3.Text);
+            sgt.Y = Convert.ToInt32(txtarea2y3.Text);
+            sgt.Length = Convert.ToInt32(txtarea2l3.Text);
+            ls.Add(sgt);
+
+            listFeature.Add(ls);
+
+            //向数据库插入分析点数据
+            MeasureFile msf = new MeasureFile();
+            msf.FileName = @"E:\HOZ\Test\asd.msf";
+            msf.MParam.EDSP.DwellTime = 200;
+            msf.MParam.EDSP.AreaTime = 200;
+            MeasureDB m_MeasDB = new MeasureDB(msf);
+
+            int analysispoints_id = 1;
+
+            m_MeasDB.InsetAPoint(analysispoints_id, "aa", @"D:\\", listPoints.Count, listFeature.Count);
+
+            long[] XrayData = null;
+            Dictionary<string, double> listElement = null;
+            int xraydata_id = 1;
+
+            //点扫描数据存储
+            for(int i=0;i<listPoints.Count;i++)
+            {
+                Console.WriteLine("Points:" + i.ToString());
+                XrayData = new long[2000];
+                listElement = new Dictionary<string, double>();
+                Console.WriteLine("Points:" + i.ToString());
+                iExtender.XrayPointCollectiong(msf.MParam.EDSP.DwellTime, listPoints[i].X, listPoints[i].Y, out XrayData, out listElement);
+                Console.WriteLine("Points:" + i.ToString());
+                m_MeasDB.InsertAPointXay(analysispoints_id, xraydata_id, listPoints[i].X, listPoints[i].Y, XrayData, listElement);
+                xraydata_id++;
+            }
+
+            //面扫描数据存储
+            int AreasNo = 0;
+            foreach (List<Segment> listSeg in listFeature)
+            {
+                XrayData = new long[2000];
+                listElement = new Dictionary<string, double>();
+
+                iExtender.XrayAreaCollectiong(msf.MParam.EDSP.AreaTime, listSeg, out XrayData, out listElement);
+
+                //写入数据库
+
+                AreasNo++;
+                m_MeasDB.InsertAAreaXay(analysispoints_id, xraydata_id, AreasNo, listSeg, XrayData, listElement);
+                xraydata_id++;
+            }
+        
+            m_MeasDB.CloseDB();
+
+            MessageBox.Show("测试完成!");
+        }
     }
 }

+ 6 - 0
OxfordTest/Form1.resx

@@ -123,4 +123,10 @@
   <metadata name="含量.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
     <value>True</value>
   </metadata>
+  <metadata name="元素.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>True</value>
+  </metadata>
+  <metadata name="含量.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>True</value>
+  </metadata>
 </root>

+ 25 - 1
OxfordTest/OxfordTest.csproj

@@ -14,7 +14,7 @@
     <Deterministic>true</Deterministic>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
-    <PlatformTarget>AnyCPU</PlatformTarget>
+    <PlatformTarget>x64</PlatformTarget>
     <DebugSymbols>true</DebugSymbols>
     <DebugType>full</DebugType>
     <Optimize>false</Optimize>
@@ -35,6 +35,22 @@
   <ItemGroup>
     <Reference Include="System" />
     <Reference Include="System.Core" />
+    <Reference Include="System.Data.SQLite, Version=1.0.113.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=AMD64">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.113.3\lib\net46\System.Data.SQLite.dll</HintPath>
+    </Reference>
+    <Reference Include="System.Data.SQLite.EF6, Version=1.0.113.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\packages\System.Data.SQLite.EF6.1.0.113.0\lib\net46\System.Data.SQLite.EF6.dll</HintPath>
+    </Reference>
+    <Reference Include="System.Data.SQLite.Linq, Version=1.0.113.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\packages\System.Data.SQLite.Linq.1.0.113.0\lib\net46\System.Data.SQLite.Linq.dll</HintPath>
+    </Reference>
+    <Reference Include="System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\packages\System.ValueTuple.4.5.0\lib\net461\System.ValueTuple.dll</HintPath>
+    </Reference>
     <Reference Include="System.Windows.Forms.DataVisualization" />
     <Reference Include="System.Xml.Linq" />
     <Reference Include="System.Data.DataSetExtensions" />
@@ -81,10 +97,18 @@
     <None Include="App.config" />
   </ItemGroup>
   <ItemGroup>
+    <ProjectReference Include="..\DBManager\DBManager.csproj">
+      <Project>{5674dd32-3a9f-4d74-b177-a693a75a0255}</Project>
+      <Name>DBManager</Name>
+    </ProjectReference>
     <ProjectReference Include="..\ExtenderControl\Extender.csproj">
       <Project>{f5092f52-1fbd-4882-bb9c-399809d87779}</Project>
       <Name>Extender</Name>
     </ProjectReference>
+    <ProjectReference Include="..\MeasureData\MeasureData.csproj">
+      <Project>{12617585-8d9a-4ad4-b6c4-6894a48cee9e}</Project>
+      <Name>MeasureData</Name>
+    </ProjectReference>
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
 </Project>

Algúns arquivos non se mostraron porque demasiados arquivos cambiaron neste cambio