Browse Source

add EDSDB

HaoShuang 4 years ago
parent
commit
650af9ca24

+ 0 - 12
DBManager/Class1.cs

@@ -1,12 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace DBManager
-{
-    public class Class1
-    {
-    }
-}

+ 46 - 2
DBManager/DBManager.csproj

@@ -1,5 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="..\packages\EntityFramework.6.3.0\build\EntityFramework.props" Condition="Exists('..\packages\EntityFramework.6.3.0\build\EntityFramework.props')" />
   <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
   <PropertyGroup>
     <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -9,10 +10,12 @@
     <AppDesignerFolder>Properties</AppDesignerFolder>
     <RootNamespace>DBManager</RootNamespace>
     <AssemblyName>DBManager</AssemblyName>
-    <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
+    <TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
     <FileAlignment>512</FileAlignment>
     <Deterministic>true</Deterministic>
     <TargetFrameworkProfile />
+    <NuGetPackageImportStamp>
+    </NuGetPackageImportStamp>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
     <DebugSymbols>true</DebugSymbols>
@@ -32,8 +35,27 @@
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
   <ItemGroup>
+    <Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
+      <HintPath>..\packages\EntityFramework.6.3.0\lib\net45\EntityFramework.dll</HintPath>
+    </Reference>
+    <Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
+      <HintPath>..\packages\EntityFramework.6.3.0\lib\net45\EntityFramework.SqlServer.dll</HintPath>
+    </Reference>
     <Reference Include="System" />
+    <Reference Include="System.ComponentModel.DataAnnotations" />
     <Reference Include="System.Core" />
+    <Reference Include="System.Data.SQLite, Version=1.0.113.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=AMD64">
+      <HintPath>..\packages\System.Data.SQLite.x64.1.0.113.0\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">
+      <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">
+      <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.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
+      <HintPath>..\packages\System.ValueTuple.4.5.0\lib\net461\System.ValueTuple.dll</HintPath>
+    </Reference>
     <Reference Include="System.Xml.Linq" />
     <Reference Include="System.Data.DataSetExtensions" />
     <Reference Include="Microsoft.CSharp" />
@@ -42,8 +64,30 @@
     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
-    <Compile Include="Class1.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="MeasureDB.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="App.config" />
+    <None Include="packages.config" />
+  </ItemGroup>
+  <ItemGroup>
+    <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" />
+  <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
+    <PropertyGroup>
+      <ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText>
+    </PropertyGroup>
+    <Error Condition="!Exists('..\packages\EntityFramework.6.3.0\build\EntityFramework.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\EntityFramework.6.3.0\build\EntityFramework.props'))" />
+    <Error Condition="!Exists('..\packages\EntityFramework.6.3.0\build\EntityFramework.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\EntityFramework.6.3.0\build\EntityFramework.targets'))" />
+  </Target>
+  <Import Project="..\packages\EntityFramework.6.3.0\build\EntityFramework.targets" Condition="Exists('..\packages\EntityFramework.6.3.0\build\EntityFramework.targets')" />
 </Project>

+ 357 - 0
DBManager/MeasureDB.cs

@@ -0,0 +1,357 @@
+//20201104 数据库基本操作 只包含创建和写入的动作,删除和读出查询的动作不包括在其中
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.IO;
+
+using System.Data.SQLite;
+
+using MeasureData;
+using Extender;
+
+namespace DBManager
+{
+    public class MeasureDB
+    {
+        public SQLiteConnection m_db;
+        private MeasureFile m_measureFile; //测量文件
+
+        public MeasureDB(MeasureFile mf)
+        {
+            Init(mf);
+            CreateDB();
+            CreateAnalysisPointsTable();
+            CreateXrayDataTable();
+            CreateAreaPositionTable();
+            CreateElementTable();
+        }
+
+        public void Init(MeasureFile mf)
+        {
+            m_measureFile = mf;
+        }
+
+        //创建一个空的数据库
+        public void CreateDB()
+        {
+            string path = Path.GetDirectoryName(m_measureFile.FileName);
+            path += "//MeasureDB.db";
+
+            if (Directory.Exists(path))
+            {
+                Directory.Delete(path);
+            }
+
+            m_db = new SQLiteConnection("data source =" + path);
+            m_db.Open();           
+        }
+
+        //创建分析点表
+        public void CreateAnalysisPointsTable()
+        {
+            string sql = "CREATE TABLE AnalysisPoints(";
+            string sPrimary = ", PRIMARY KEY( ";
+
+            //第1列, ID,是主键
+            sql = sql + "ID INTEGER";
+            sPrimary = sPrimary + "ID";
+
+            //第2列,Name
+            sql = sql + ",";
+            sql = sql + "Name TEXT";
+          
+            //第3列,EDSImagePath
+            sql = sql + ",";
+            sql = sql + "EDSImagePath TEXT";
+
+            //第4列,HavePoints
+            sql = sql + ",";
+            sql = sql + "HavePoints INTEGER";
+
+            //第5列,PointsNum
+            sql = sql + ",";
+            sql = sql + "PointsNum INTEGER";
+
+            //第6列,HaveAreas
+            sql = sql + ",";
+            sql = sql + "HaveAreas INTEGER";
+
+            //第7列,AreasNum
+            sql = sql + ",";
+            sql = sql + "AreasNum INTEGER";
+
+            sPrimary = sPrimary + ")";
+            sql = sql + sPrimary + ")";
+
+            SQLiteCommand command = new SQLiteCommand(sql, m_db);
+            command.ExecuteNonQuery();
+        }
+
+        //XrayData表
+        public void CreateXrayDataTable()
+        {
+            string sql = "CREATE TABLE XrayData(";
+            string sPrimary = ", PRIMARY KEY( ";
+
+            //第1列, ID,是主键
+            sql = sql + "ID INTEGER";
+            sPrimary = sPrimary + "ID";
+
+            //第2列,APID
+            sql = sql + ",";
+            sql = sql + "APID INTEGER";
+            sPrimary = sPrimary + ", APID";
+
+            //第3列,Type
+            sql = sql + ",";
+            sql = sql + "Type INTEGER";
+
+            //第4列,X
+            sql = sql + ",";
+            sql = sql + "X INTEGER";
+
+            //第5列,Y
+            sql = sql + ",";
+            sql = sql + "Y INTEGER";
+
+            //第6列,AreasID
+            sql = sql + ",";
+            sql = sql + "AreasID INTEGER";
+
+            //第7列,ElementNum
+            sql = sql + ",";
+            sql = sql + "ElementNum INTEGER";
+
+            //第8列,XrayData
+            sql = sql + ",";
+            sql = sql + "XrayData BLOB";
+
+            sPrimary = sPrimary + ")";
+            sql = sql + sPrimary + ")";
+
+            SQLiteCommand command = new SQLiteCommand(sql, m_db);
+            command.ExecuteNonQuery();
+        }
+
+        //创建元素表
+        public void CreateElementTable()
+        {
+            string sql = "CREATE TABLE Element(";
+            string sPrimary = ", PRIMARY KEY( ";
+
+            //第1列, ID,是主键
+            sql = sql + "XayID INTEGER";
+            sPrimary = sPrimary + "XayID";
+
+            //第3列,ElementNum,是主键
+            sql = sql + ",";
+            sql = sql + "ElementNum INTEGER";
+            sPrimary = sPrimary + ", ElementNum";
+
+            //第4列,ElementID,是主键
+            sql = sql + ",";
+            sql = sql + "ElementID INTEGER";
+            sPrimary = sPrimary + ", ElementID";
+
+            //第5列,Name
+            sql = sql + ",";
+            sql = sql + "Name TEXT";
+
+            //第6列,Percent
+            sql = sql + ",";
+            sql = sql + "Percent FLOAT";
+
+            sPrimary = sPrimary + ")";
+            sql = sql + sPrimary + ")";
+
+            SQLiteCommand command = new SQLiteCommand(sql, m_db);
+            command.ExecuteNonQuery();
+        }
+
+        //创建位置信息表
+        public void CreateAreaPositionTable()
+        {
+            string sql = "CREATE TABLE AreaPosition(";
+            string sPrimary = ", PRIMARY KEY( ";
+
+            //第1列, ID,是主键
+            sql = sql + "AID INTEGER";
+            sPrimary = sPrimary + "AID";
+
+            //第2列,SegNum
+            sql = sql + ",";
+            sql = sql + "SegNum INTEGER";
+            sPrimary = sPrimary + ", SegNum";
+
+            //第3列,SegID
+            sql = sql + ",";
+            sql = sql + "SegID INTEGER";
+            sPrimary = sPrimary + ", SegID";
+
+            //第4列,X
+            sql = sql + ",";
+            sql = sql + "X INTEGER";
+
+            //第5列,Y
+            sql = sql + ",";
+            sql = sql + "Y INTEGER";
+
+            //第6列,Length
+            sql = sql + ",";
+            sql = sql + "Length INTEGER";
+
+            sPrimary = sPrimary + ")";
+            sql = sql + sPrimary + ")";
+
+            SQLiteCommand command = new SQLiteCommand(sql, m_db);
+            command.ExecuteNonQuery();
+        }
+
+        public bool InsetAPoint(int PointsId, string PointName, string EDSImagePath,
+            bool HavePoints, int PointsNum, bool HaveArea, int AreasNum)
+        {
+            //开启一个事务
+            using (SQLiteTransaction tr = m_db.BeginTransaction())
+            {
+                //向分析点表插入数据
+                string sql = "INSERT INTO AnalysisPoints(ID, Name, EDSImagePath, HavePoints, PointsNum, HaveAreas, AreasNum) values ("
+                    + PointsId.ToString() + ","
+                    + "'" + PointName + "'" + ","
+                    + "'" + EDSImagePath + "'" + ","
+                    + Convert.ToInt32(HavePoints).ToString() + ","
+                    + PointsNum.ToString() + ","
+                    + Convert.ToInt32(HaveArea).ToString() + ","
+                    + AreasNum.ToString() + ")";
+
+                SQLiteCommand command = new SQLiteCommand(sql, m_db);
+                command.ExecuteNonQuery();
+                tr.Commit();
+            }
+            return true;
+        }
+
+        //插入一条点扫描Xray的信息
+        public bool InsertAPointXay(int PointsId, int XrayId, int X, int Y,long[] XrayData, List<Dictionary<string, double>> listElement)
+        {
+            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];
+            }
+
+            //开启一个事务
+            using (SQLiteTransaction tr = m_db.BeginTransaction())
+            {
+                //向能谱数据表插入数据
+                string sql = "INSERT INTO XrayData(ID, APID, Type, X, Y, AreasID, ElementNum, XrayData) values ("
+                    + XrayId.ToString() + ","
+                    + PointsId.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 = 0;
+                foreach (Dictionary<string, double> element in listElement)
+                {
+
+                    sql = "INSERT INTO Element(XayID, ElementNum, ElementID, Name, Percent) values ("
+                       + XrayId.ToString() + ","
+                       + listElement.Count.ToString() + ","
+                       + i.ToString() + ","
+                       + element.Keys + ","
+                       + element.Values.ToString() + ")";
+
+                    command = new SQLiteCommand(sql, m_db);
+                    command.ExecuteNonQuery();
+                    i++;
+                }
+                
+                tr.Commit();
+            }
+            return true;
+        }
+
+        //插入一条面扫描Xray的信息
+        public bool InsertAAreaXay(int PointsId, int PointName, int XrayId, int AreaId, List<Segment> listSeg,long[] XrayData, List<Dictionary<string, double>> listElement)
+        {
+            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];
+            }
+            //开启一个事务
+            using (SQLiteTransaction tr = m_db.BeginTransaction())
+            {
+                //向能谱数据表插入数据
+                string sql = "INSERT INTO XrayData(ID, APID, Type, X, Y, AreasID, ElementNum, XrayData) values ("
+                    + XrayId.ToString() + ","
+                    + PointsId.ToString() + ","
+                    + 1.ToString() + ","
+                    + (-1).ToString() + ","
+                    + (-1).ToString() + ","
+                    + AreaId.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 (Dictionary<string, double> element in listElement)
+                {
+
+                    sql = "INSERT INTO Element(XayID, ElementNum, ElementID, Name, Percent) values ("
+                       + XrayId.ToString() + ","
+                       + listElement.Count.ToString() + ","
+                       + i.ToString() + ","
+                       + element.Keys + ","
+                       + element.Values.ToString() + ")";
+
+                    command = new SQLiteCommand(sql, m_db);
+                    command.ExecuteNonQuery();
+                    i++;
+                }
+                //向位置表插入数据
+
+                i = 0;
+                foreach (Segment seg in listSeg)
+                {
+
+                    sql = "INSERT INTO AreaPosition(XayID, SegNum, SegID, X, Y, Length) values ("
+                       + XrayId.ToString() + ","
+                       + listSeg.Count.ToString() + ","
+                       + i.ToString() + ","
+                       + seg.X.ToString() + ","
+                       + seg.Y.ToString() + ","
+                       + seg.Length.ToString() + ")";
+
+                    command = new SQLiteCommand(sql, m_db);
+                    command.ExecuteNonQuery();
+                    i++;
+                }
+                tr.Commit();
+            }
+            return true;
+        }
+    }
+}

+ 21 - 5
ManulDo/App.config

@@ -1,6 +1,22 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
 <configuration>
-    <startup> 
-        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
-    </startup>
-</configuration>
+  <configSections>
+    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
+    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
+  </configSections>
+  <startup>
+    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" />
+  </startup>
+  <entityFramework>
+    <providers>
+      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
+      <provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
+    </providers>
+  </entityFramework>
+  <system.data>
+    <DbProviderFactories>
+      <remove invariant="System.Data.SQLite.EF6" />
+      <add name="SQLite Data Provider (Entity Framework 6)" invariant="System.Data.SQLite.EF6" description=".NET Framework Data Provider for SQLite (Entity Framework 6)" type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6" />
+    <remove invariant="System.Data.SQLite" /><add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".NET Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" /></DbProviderFactories>
+  </system.data>
+</configuration>

+ 16 - 2
ManulDo/MainForm.Designer.cs

@@ -30,6 +30,7 @@
         {
             System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
             this.groupBox1 = new System.Windows.Forms.GroupBox();
+            this.button8 = new System.Windows.Forms.Button();
             this.btnOpenFile = new System.Windows.Forms.Button();
             this.btnSaveFile = new System.Windows.Forms.Button();
             this.btnNewFile = new System.Windows.Forms.Button();
@@ -91,6 +92,7 @@
             // 
             // groupBox1
             // 
+            this.groupBox1.Controls.Add(this.button8);
             this.groupBox1.Controls.Add(this.btnOpenFile);
             this.groupBox1.Controls.Add(this.btnSaveFile);
             this.groupBox1.Controls.Add(this.btnNewFile);
@@ -98,11 +100,22 @@
             this.groupBox1.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
             this.groupBox1.Name = "groupBox1";
             this.groupBox1.Padding = new System.Windows.Forms.Padding(3, 2, 3, 2);
-            this.groupBox1.Size = new System.Drawing.Size(454, 80);
+            this.groupBox1.Size = new System.Drawing.Size(784, 80);
             this.groupBox1.TabIndex = 1;
             this.groupBox1.TabStop = false;
             this.groupBox1.Text = "测量文件操作";
             // 
+            // button8
+            // 
+            this.button8.Location = new System.Drawing.Point(346, 28);
+            this.button8.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+            this.button8.Name = "button8";
+            this.button8.Size = new System.Drawing.Size(114, 37);
+            this.button8.TabIndex = 3;
+            this.button8.Text = "创建数据库";
+            this.button8.UseVisualStyleBackColor = true;
+            this.button8.Click += new System.EventHandler(this.button8_Click);
+            // 
             // btnOpenFile
             // 
             this.btnOpenFile.Location = new System.Drawing.Point(235, 28);
@@ -149,7 +162,7 @@
             this.groupBox2.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
             this.groupBox2.Name = "groupBox2";
             this.groupBox2.Padding = new System.Windows.Forms.Padding(3, 2, 3, 2);
-            this.groupBox2.Size = new System.Drawing.Size(454, 130);
+            this.groupBox2.Size = new System.Drawing.Size(784, 130);
             this.groupBox2.TabIndex = 2;
             this.groupBox2.TabStop = false;
             this.groupBox2.Text = "测量流程";
@@ -702,6 +715,7 @@
         private System.Windows.Forms.Label label11;
         private System.Windows.Forms.Label label10;
         private System.Windows.Forms.Button button2;
+        private System.Windows.Forms.Button button8;
     }
 }
 

+ 9 - 0
ManulDo/MainForm.cs

@@ -11,6 +11,9 @@ using System.Windows.Forms;
 using MeasureData;
 using MeasureThread;
 using FileManager;
+using DBManager;
+
+using System.Data.SQLite;
 
 namespace WindowsFormsApp1
 {
@@ -438,5 +441,11 @@ namespace WindowsFormsApp1
                 m_BackgroundWorker.RunWorkerAsync(this);
             }
         }
+
+        private void button8_Click(object sender, EventArgs e)
+        {
+            MeasureDB db = new MeasureDB(m_MeasureFile);
+         
+        }
     }
 }

+ 27 - 1
ManulDo/ManulDo.csproj

@@ -1,5 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="..\packages\EntityFramework.6.3.0\build\EntityFramework.props" Condition="Exists('..\packages\EntityFramework.6.3.0\build\EntityFramework.props')" />
   <Import Project="..\packages\OpenCvSharp3-AnyCPU.4.0.0.20181129\build\OpenCvSharp3-AnyCPU.props" Condition="Exists('..\packages\OpenCvSharp3-AnyCPU.4.0.0.20181129\build\OpenCvSharp3-AnyCPU.props')" />
   <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
   <PropertyGroup>
@@ -9,7 +10,7 @@
     <OutputType>WinExe</OutputType>
     <RootNamespace>WindowsFormsApp1</RootNamespace>
     <AssemblyName>ManulDo</AssemblyName>
-    <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
+    <TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
     <FileAlignment>512</FileAlignment>
     <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
     <Deterministic>true</Deterministic>
@@ -37,6 +38,12 @@
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
   <ItemGroup>
+    <Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
+      <HintPath>..\packages\EntityFramework.6.3.0\lib\net45\EntityFramework.dll</HintPath>
+    </Reference>
+    <Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
+      <HintPath>..\packages\EntityFramework.6.3.0\lib\net45\EntityFramework.SqlServer.dll</HintPath>
+    </Reference>
     <Reference Include="OpenCvSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6adad1e807fea099, processorArchitecture=MSIL">
       <HintPath>..\packages\OpenCvSharp3-AnyCPU.4.0.0.20181129\lib\net461\OpenCvSharp.dll</HintPath>
     </Reference>
@@ -50,7 +57,17 @@
       <HintPath>..\packages\OpenCvSharp3-AnyCPU.4.0.0.20181129\lib\net461\OpenCvSharp.UserInterface.dll</HintPath>
     </Reference>
     <Reference Include="System" />
+    <Reference Include="System.ComponentModel.DataAnnotations" />
     <Reference Include="System.Core" />
+    <Reference Include="System.Data.SQLite, Version=1.0.113.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
+      <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">
+      <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">
+      <HintPath>..\packages\System.Data.SQLite.Linq.1.0.113.0\lib\net46\System.Data.SQLite.Linq.dll</HintPath>
+    </Reference>
     <Reference Include="System.Xml.Linq" />
     <Reference Include="System.Data.DataSetExtensions" />
     <Reference Include="Microsoft.CSharp" />
@@ -98,6 +115,10 @@
     <None Include="App.config" />
   </ItemGroup>
   <ItemGroup>
+    <ProjectReference Include="..\DBManager\DBManager.csproj">
+      <Project>{5674dd32-3a9f-4d74-b177-a693a75a0255}</Project>
+      <Name>DBManager</Name>
+    </ProjectReference>
     <ProjectReference Include="..\FileManager\FileManager.csproj">
       <Project>{14c99f54-b3c2-47cf-adb3-e79fdd2d382f}</Project>
       <Name>FileManager</Name>
@@ -121,5 +142,10 @@
       <ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText>
     </PropertyGroup>
     <Error Condition="!Exists('..\packages\OpenCvSharp3-AnyCPU.4.0.0.20181129\build\OpenCvSharp3-AnyCPU.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\OpenCvSharp3-AnyCPU.4.0.0.20181129\build\OpenCvSharp3-AnyCPU.props'))" />
+    <Error Condition="!Exists('..\packages\EntityFramework.6.3.0\build\EntityFramework.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\EntityFramework.6.3.0\build\EntityFramework.props'))" />
+    <Error Condition="!Exists('..\packages\EntityFramework.6.3.0\build\EntityFramework.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\EntityFramework.6.3.0\build\EntityFramework.targets'))" />
+    <Error Condition="!Exists('..\packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.113.3\build\net46\Stub.System.Data.SQLite.Core.NetFramework.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.113.3\build\net46\Stub.System.Data.SQLite.Core.NetFramework.targets'))" />
   </Target>
+  <Import Project="..\packages\EntityFramework.6.3.0\build\EntityFramework.targets" Condition="Exists('..\packages\EntityFramework.6.3.0\build\EntityFramework.targets')" />
+  <Import Project="..\packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.113.3\build\net46\Stub.System.Data.SQLite.Core.NetFramework.targets" Condition="Exists('..\packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.113.3\build\net46\Stub.System.Data.SQLite.Core.NetFramework.targets')" />
 </Project>

+ 6 - 0
ManulDo/packages.config

@@ -1,4 +1,10 @@
 <?xml version="1.0" encoding="utf-8"?>
 <packages>
+  <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.EF6" version="1.0.113.0" targetFramework="net462" />
+  <package id="System.Data.SQLite.Linq" version="1.0.113.0" targetFramework="net462" />
 </packages>

+ 25 - 6
MeasureThread/Measure.cs

@@ -18,6 +18,7 @@ using WebManager;
 
 using OpenCvSharp;
 using Extender;
+using DBManager;
 
 namespace MeasureThread
 {
@@ -446,6 +447,7 @@ namespace MeasureThread
         //全局只有一个Extender
         static ExtenderInterface factoryExtender = null;// ExtenderInterface.Instance;
         IExtenderControl iExtender = null;// factoryExtender.IExtender;
+        MeasureDB m_MeasDB = null;
 
         //@的作用是不用转义字符\\只打一个就行
         const String ImageName0 = @"Straighten.tif"; //传给客户,原始图像,为拉直操作
@@ -479,6 +481,7 @@ namespace MeasureThread
         String data_path = "";
 
         int m_nWorkHoleNo = -1;
+        int m_nXrayId = -1;
 
         //测量文件
         private MeasureFile m_measureFile;
@@ -556,6 +559,7 @@ namespace MeasureThread
             {
                 factoryExtender = ExtenderInterface.Instance;
                 iExtender = factoryExtender.IExtender;
+                m_MeasDB = new MeasureDB(m_measureFile);
             }
 
             return true;
@@ -576,8 +580,9 @@ namespace MeasureThread
             SendCutHolesStatus(this, arg);
         }
 
-        public bool DoEDS()
+        public bool DoEDS(int a_PointNum, string PointsName)
         {
+            //XrayID记录
             EDSParam param = m_measureFile.MParam.EDSP;
             double dDwellTime = param.DwellTime;
             int nImageType = param.ImageType;
@@ -586,13 +591,23 @@ namespace MeasureThread
 
             string path = EDS_path;
             iExtender.GrabImage(path + "\\EDSImage.tif", 0, 0, 0, 0, 0);
-
+            
             //送给客户,计算感兴趣的区域
+            List<Point> listPoints = new List<Point>();
+            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))
+            {
+                LogManager.AddHardwareLog("插入分析点失败", true);
+            }
+
+            int AreasNo = -1;
+
             if (param.PointMode == true)
             {
                 //点采集
-                List<Point> listPoints = new List<Point>();
-
                 foreach (Point pt in listPoints)
                 {
                     long[] XrayData = new long[2000];
@@ -600,6 +615,9 @@ namespace MeasureThread
                     iExtender.XrayPointCollectiong(param.PointTime, pt.X, pt.Y, out XrayData, out listElement);
 
                     //写入数据库
+                    m_nXrayId++;
+                    //InsertAPointXay(a_PointNum, m_nXrayId, pt.X, pt.Y, XrayData, listElement);
+                    
                 }
             }
             if (param.AreaMode == true)
@@ -608,13 +626,14 @@ namespace MeasureThread
                 long[] XrayData = new long[2000];
                 Dictionary<string, double> listElement = new Dictionary<string, double>();
 
-                List<List<Segment>> listFeature = new List<List<Segment>>();
-
                 foreach (List < Segment> listSeg in listFeature)
                 {
                     iExtender.XrayAreaCollectiong(param.AreaTime, listSeg, out XrayData, out listElement);
 
                     //写入数据库
+                    m_nXrayId++;
+                    
+                    AreasNo++;
                 }
             }
 

+ 4 - 0
MeasureThread/MeasureThread.csproj

@@ -63,6 +63,10 @@
     <Compile Include="ThreadStatus.cs" />
   </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>