Merge branch 'master' of http://www.scserverddns.top:13000/sc/SunlightCentralizedControlManagement
This commit is contained in:
commit
7c5541de04
11 files changed
+98
-1325
No files matched your search
+5
-1
@@ -3,9 +3,13 @@
|
|||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:lang="clr-namespace:SunlightCentralizedControlManagement_SCCM_.Properties"
|
||||||
|
xmlns:viewmodel="clr-namespace:SunlightCentralizedControlManagement_SCCM_.ViewModel"
|
||||||
xmlns:local="clr-namespace:SunlightCentralizedControlManagement_SCCM_"
|
xmlns:local="clr-namespace:SunlightCentralizedControlManagement_SCCM_"
|
||||||
|
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
Title="MainWindow" Height="1080" Width="1920">
|
Title="SUNLIGHT SCCM b0.0.1 (2024/08/10)"
|
||||||
|
Height="1080" Width="1920">
|
||||||
<Grid>
|
<Grid>
|
||||||
|
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|||||||
@@ -34,9 +34,16 @@
|
|||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
<PropertyGroup>
|
||||||
|
<StartupObject>SunlightCentralizedControlManagement_SCCM_.App</StartupObject>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup>
|
||||||
|
<ApplicationIcon>sunlight_logo.ico</ApplicationIcon>
|
||||||
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Data" />
|
<Reference Include="System.Data" />
|
||||||
|
<Reference Include="System.Windows.Forms" />
|
||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
<Reference Include="Microsoft.CSharp" />
|
<Reference Include="Microsoft.CSharp" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
@@ -55,7 +62,6 @@
|
|||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
</ApplicationDefinition>
|
</ApplicationDefinition>
|
||||||
<Compile Include="UserClass\AsyncTcpServer.cs" />
|
|
||||||
<Compile Include="UserClass\ClsLock.cs" />
|
<Compile Include="UserClass\ClsLock.cs" />
|
||||||
<Compile Include="UserClass\CRCcheck16.cs" />
|
<Compile Include="UserClass\CRCcheck16.cs" />
|
||||||
<Compile Include="UserClass\CSV.cs" />
|
<Compile Include="UserClass\CSV.cs" />
|
||||||
@@ -64,17 +70,15 @@
|
|||||||
<Compile Include="UserClass\get_local_ip_address.cs" />
|
<Compile Include="UserClass\get_local_ip_address.cs" />
|
||||||
<Compile Include="UserClass\HardwareSN.cs" />
|
<Compile Include="UserClass\HardwareSN.cs" />
|
||||||
<Compile Include="UserClass\IniFile.cs" />
|
<Compile Include="UserClass\IniFile.cs" />
|
||||||
<Compile Include="UserClass\Json.cs" />
|
|
||||||
<Compile Include="UserClass\LogDataRead.cs" />
|
|
||||||
<Compile Include="UserClass\LogGing.cs" />
|
<Compile Include="UserClass\LogGing.cs" />
|
||||||
<Compile Include="UserClass\MD5check.cs" />
|
<Compile Include="UserClass\MD5check.cs" />
|
||||||
<Compile Include="UserClass\NetFwManger.cs" />
|
<Compile Include="UserClass\NetFwManger.cs" />
|
||||||
<Compile Include="UserClass\NumericTextColumn .cs" />
|
<Compile Include="UserClass\NumericTextColumn .cs" />
|
||||||
<Compile Include="UserClass\PID.cs" />
|
<Compile Include="UserClass\PID.cs" />
|
||||||
<Compile Include="UserClass\PressKey.cs" />
|
<Compile Include="UserClass\PressKey.cs" />
|
||||||
<Compile Include="UserClass\SQLDATA.cs" />
|
|
||||||
<Compile Include="UserClass\SqliteHelper.cs" />
|
|
||||||
<Compile Include="UserClass\StrToInt.cs" />
|
<Compile Include="UserClass\StrToInt.cs" />
|
||||||
|
<Compile Include="ViewModel\MainWindowViewModel.cs" />
|
||||||
|
<Compile Include="ViewModel\ViewModelLocator.cs" />
|
||||||
<Page Include="MainWindow.xaml">
|
<Page Include="MainWindow.xaml">
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
@@ -156,6 +160,9 @@
|
|||||||
<None Include="App.config" />
|
<None Include="App.config" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="CommonServiceLocator">
|
||||||
|
<Version>2.0.7</Version>
|
||||||
|
</PackageReference>
|
||||||
<PackageReference Include="CommunityToolkit.Mvvm">
|
<PackageReference Include="CommunityToolkit.Mvvm">
|
||||||
<Version>8.3.2</Version>
|
<Version>8.3.2</Version>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
@@ -168,15 +175,21 @@
|
|||||||
<PackageReference Include="NModbus">
|
<PackageReference Include="NModbus">
|
||||||
<Version>3.0.81</Version>
|
<Version>3.0.81</Version>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
|
<PackageReference Include="ScottPlot">
|
||||||
|
<Version>5.0.41</Version>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="TouchSocket">
|
||||||
|
<Version>2.1.10</Version>
|
||||||
|
</PackageReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="ViewModel\" />
|
|
||||||
<Folder Include="View\" />
|
<Folder Include="View\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="Fonts\font-awesome-4.7.0\css\font-awesome.css" />
|
<Content Include="Fonts\font-awesome-4.7.0\css\font-awesome.css" />
|
||||||
<Content Include="Fonts\font-awesome-4.7.0\css\font-awesome.min.css" />
|
<Content Include="Fonts\font-awesome-4.7.0\css\font-awesome.min.css" />
|
||||||
<Content Include="Fonts\font-awesome-4.7.0\fonts\fontawesome-webfont.svg" />
|
<Content Include="Fonts\font-awesome-4.7.0\fonts\fontawesome-webfont.svg" />
|
||||||
|
<Resource Include="sunlight_logo.ico" />
|
||||||
<Resource Include="LOGO\SUNLIGHT.ico" />
|
<Resource Include="LOGO\SUNLIGHT.ico" />
|
||||||
<Resource Include="LOGO\sunlight_logo.ico" />
|
<Resource Include="LOGO\sunlight_logo.ico" />
|
||||||
<Resource Include="LOGO\sunlight_logo.jpg" />
|
<Resource Include="LOGO\sunlight_logo.jpg" />
|
||||||
@@ -184,6 +197,17 @@
|
|||||||
<Resource Include="LOGO\sunlight_sc.png" />
|
<Resource Include="LOGO\sunlight_sc.png" />
|
||||||
<Resource Include="Fonts\font-awesome-4.7.0\HELP-US-OUT.txt" />
|
<Resource Include="Fonts\font-awesome-4.7.0\HELP-US-OUT.txt" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<COMReference Include="NetFwTypeLib">
|
||||||
|
<Guid>{58FBCF7C-E7A9-467C-80B3-FC65E8FCCA08}</Guid>
|
||||||
|
<VersionMajor>1</VersionMajor>
|
||||||
|
<VersionMinor>0</VersionMinor>
|
||||||
|
<Lcid>0</Lcid>
|
||||||
|
<WrapperTool>tlbimp</WrapperTool>
|
||||||
|
<Isolated>False</Isolated>
|
||||||
|
<EmbedInteropTypes>True</EmbedInteropTypes>
|
||||||
|
</COMReference>
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<Target Name="AfterResolveReferences">
|
<Target Name="AfterResolveReferences">
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -1,344 +0,0 @@
|
|||||||
using DyeingComputer.UserClass;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Data;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Net;
|
|
||||||
using System.Net.Http;
|
|
||||||
using System.Net.Sockets;
|
|
||||||
using System.Reflection.Emit;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using TouchSocket.Core;
|
|
||||||
using TouchSocket.Sockets;
|
|
||||||
using DyeingComputer.ViewModel;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using ScottPlot.Colormaps;
|
|
||||||
using static System.Windows.Forms.AxHost;
|
|
||||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TaskbarClock;
|
|
||||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using static DyeingComputer.UserClass.SqliteHelper;
|
|
||||||
using DyeingComputer.View;
|
|
||||||
|
|
||||||
namespace DyeingComputer.UserClass
|
|
||||||
{/// <summary>
|
|
||||||
/// 异步TCP服务器
|
|
||||||
/// </summary>
|
|
||||||
public class AsyncTcpServer
|
|
||||||
{
|
|
||||||
//设置系统时间的API函数
|
|
||||||
[DllImport("kernel32.dll")]
|
|
||||||
private static extern bool SetLocalTime(ref SYSTEMTIME time);
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
private struct SYSTEMTIME
|
|
||||||
{
|
|
||||||
public short year;
|
|
||||||
public short month;
|
|
||||||
public short dayOfWeek;
|
|
||||||
public short day;
|
|
||||||
public short hour;
|
|
||||||
public short minute;
|
|
||||||
public short second;
|
|
||||||
public short milliseconds;
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// 设置系统时间
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="dt">需要设置的时间</param>
|
|
||||||
/// <returns>返回系统时间设置状态,true为成功,false为失败</returns>
|
|
||||||
private static bool SetLocalDateTime(DateTime dt)
|
|
||||||
{
|
|
||||||
SYSTEMTIME st;
|
|
||||||
st.year = (short)dt.Year;
|
|
||||||
st.month = (short)dt.Month;
|
|
||||||
st.dayOfWeek = (short)dt.DayOfWeek;
|
|
||||||
st.day = (short)dt.Day;
|
|
||||||
st.hour = (short)dt.Hour;
|
|
||||||
st.minute = (short)dt.Minute;
|
|
||||||
st.second = (short)dt.Second;
|
|
||||||
st.milliseconds = (short)dt.Millisecond;
|
|
||||||
bool rt = SetLocalTime(ref st);
|
|
||||||
return rt;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static async Task Main()
|
|
||||||
{
|
|
||||||
NetFwManger.AllowPort(7790,"TCP");//开放7790端口
|
|
||||||
TcpService service = new TcpService();
|
|
||||||
service.Connecting = (client, e) => { return EasyTask.CompletedTask; };//有客户端正在连接
|
|
||||||
service.Connected = (client, e) => { return EasyTask.CompletedTask; };//有客户端成功连接
|
|
||||||
service.Closing = (client, e) => { return EasyTask.CompletedTask; };//有客户端正在断开连接,只有当主动断开时才有效。
|
|
||||||
service.Closed = (client, e) => { return EasyTask.CompletedTask; };//有客户端断开连接
|
|
||||||
service.Received = (client, e) =>
|
|
||||||
{
|
|
||||||
string SYSAPI = e.ByteBlock.Span.ToString(Encoding.ASCII).Substring(0,5);
|
|
||||||
string DAT = e.ByteBlock.Span.ToString(Encoding.ASCII).Substring(5);
|
|
||||||
string SYSDAT ="";// = e.ByteBlock.Span.ToString(Encoding.ASCII).Substring(5);
|
|
||||||
string SYSKEY ="";
|
|
||||||
if(DAT.Length>=16) SYSKEY = DAT.Substring(0,16);
|
|
||||||
if (DAT.Length > 16) SYSDAT = DAT.Substring(16);
|
|
||||||
//LogGing.LogSQLDATA("800", "TcpServer", "API:"+ SYSAPI);
|
|
||||||
if (SYSAPI == "SC800")
|
|
||||||
{
|
|
||||||
Dictionary<string, object> Chart_new = new Dictionary<string, object>();//缓存函数
|
|
||||||
Chart_new.Add("MACHINE", MainWindowViewModel.S01);
|
|
||||||
Chart_new.Add("GROUP", MainWindowViewModel.S05);
|
|
||||||
Chart_new.Add("SYSKEY", MainWindowViewModel.SYSKEY);
|
|
||||||
Chart_new.Add("TIME", MainWindowViewModel.SYSTime);
|
|
||||||
client.SendAsync("[" + MainWindowViewModel.S01 + "]" + Chart_new.ToJsonString());
|
|
||||||
}
|
|
||||||
else if (SYSAPI == "SC810")
|
|
||||||
{
|
|
||||||
if (SYSKEY == MainWindowViewModel.SYSKEY)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Dictionary<string, object> WorkOrder_dat;
|
|
||||||
WorkOrder_dat = SerializeConvert.JsonDeserializeFromString<Dictionary<string, object>>(SYSDAT);
|
|
||||||
//WorkOrder_dat.GetValue("WorkOrder");
|
|
||||||
bool dat_w= SQLDATA.WorkOrder(
|
|
||||||
WorkOrder_dat.GetValue("WorkOrder").ToString(),
|
|
||||||
WorkOrder_dat.GetValue("ProcessName").ToString(),
|
|
||||||
WorkOrder_dat.GetValue("StartTime").ToString(),
|
|
||||||
WorkOrder_dat.GetValue("EndTime").ToString(),
|
|
||||||
WorkOrder_dat.GetValue("Time").ToString(),
|
|
||||||
WorkOrder_dat.GetValue("Remark").ToString(),
|
|
||||||
WorkOrder_dat.GetValue("lock").ToString(),
|
|
||||||
WorkOrder_dat.GetValue("State").ToString(),
|
|
||||||
WorkOrder_dat.GetValue("ProcessID").ToString());
|
|
||||||
if (!dat_w) { client.SendAsync("SC910"); }
|
|
||||||
else { client.SendAsync("SC810"+SYSKEY+SYSDAT); }
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
client.SendAsync("SC990");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else { client.SendAsync("SC999"); }
|
|
||||||
}//WorkOrder表信息检查写入
|
|
||||||
else if (SYSAPI == "SC811")
|
|
||||||
{
|
|
||||||
if (SYSKEY == MainWindowViewModel.SYSKEY)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
DataTable WorkOrder_dat;
|
|
||||||
WorkOrder_dat = SerializeConvert.JsonDeserializeFromString<DataTable>(SYSDAT);
|
|
||||||
bool dat_w = SQLDATA.WorkOderStep(WorkOrder_dat);
|
|
||||||
if (!dat_w) { client.SendAsync("SC911"); }
|
|
||||||
else { client.SendAsync("SC811" + SYSKEY + SYSDAT); }
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
client.SendAsync("SC991");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else { client.SendAsync("SC999"); }
|
|
||||||
}//WorkOrderstep表信息检查写入
|
|
||||||
else if (SYSAPI == "SC820")
|
|
||||||
{
|
|
||||||
if (SYSKEY == MainWindowViewModel.SYSKEY)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (SYSDAT.Length == 21)
|
|
||||||
{
|
|
||||||
SYSDAT = SYSDAT.Substring(1, 19);
|
|
||||||
DateTime dt;
|
|
||||||
if (DateTime.TryParse(SYSDAT, out dt))
|
|
||||||
SetLocalDateTime(dt);
|
|
||||||
}
|
|
||||||
client.SendAsync("[" + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "]");
|
|
||||||
}
|
|
||||||
catch { client.SendAsync("SC920"); }
|
|
||||||
}
|
|
||||||
else { client.SendAsync("SC999"); }
|
|
||||||
}//设置系统时间
|
|
||||||
else if (SYSAPI == "SC821")
|
|
||||||
{
|
|
||||||
if (SYSKEY == MainWindowViewModel.SYSKEY)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Dictionary<string, object> dat_821;
|
|
||||||
dat_821 = SerializeConvert.JsonDeserializeFromString<Dictionary<string, object>>(SYSDAT);
|
|
||||||
if (dat_821.GetValue("INSTRUCTION").ToString() == "START")
|
|
||||||
{
|
|
||||||
SQLDATA.TechnologicalProcess_START(dat_821.GetValue("ProgramID").ToString());
|
|
||||||
}
|
|
||||||
else if (dat_821.GetValue("INSTRUCTION").ToString() == "STOP")
|
|
||||||
{
|
|
||||||
MainWindowViewModel.WORK_RUN = 0;//停止
|
|
||||||
MainWindowViewModel.DIDETime = 0;
|
|
||||||
}
|
|
||||||
else if (dat_821.GetValue("INSTRUCTION").ToString() == "PAUSE")
|
|
||||||
{
|
|
||||||
MainWindowViewModel.WORK_RUN = 1;//暂停
|
|
||||||
}
|
|
||||||
else if (dat_821.GetValue("INSTRUCTION").ToString() == "CONTINUE")
|
|
||||||
{
|
|
||||||
MainWindowViewModel.WORK_RUN = 2;//暂停
|
|
||||||
}
|
|
||||||
else if (dat_821.GetValue("INSTRUCTION").ToString() == "JUMP")
|
|
||||||
{
|
|
||||||
MainWindowViewModel.RUN_DATATABLE = TechnologicalProcessView.sql.Tables[0];//缓存表
|
|
||||||
MainWindowViewModel.RUN_STEPID = Convert.ToInt16(dat_821.GetValue("ID").ToString());//插入步骤号
|
|
||||||
MainWindowViewModel.STEP_START(dat_821.GetValue("Numder").ToString(), Convert.ToDouble(dat_821.GetValue("P1")),
|
|
||||||
Convert.ToDouble(dat_821.GetValue("P2")), Convert.ToDouble(dat_821.GetValue("P3")),
|
|
||||||
Convert.ToDouble(dat_821.GetValue("P4")), Convert.ToDouble(dat_821.GetValue("P5")));
|
|
||||||
}
|
|
||||||
client.SendAsync("SC821" + SYSKEY + SYSDAT);
|
|
||||||
}
|
|
||||||
catch { client.SendAsync("SC921"); }
|
|
||||||
}
|
|
||||||
else { client.SendAsync("SC999"); }
|
|
||||||
}//启停跳步指令
|
|
||||||
else if (SYSAPI == "SC830")
|
|
||||||
{
|
|
||||||
if (SYSKEY == MainWindowViewModel.SYSKEY)
|
|
||||||
{
|
|
||||||
Dictionary<string, object> Chart_new = new Dictionary<string, object>();//缓存函数
|
|
||||||
Chart_new.Add("DYELOT", MainWindowViewModel.WorkNumder);
|
|
||||||
Chart_new.Add("Time", MainWindowViewModel.SYSTime);
|
|
||||||
Chart_new.Add("MST", MainWindowViewModel.TEMP_co);
|
|
||||||
Chart_new.Add("MTT", MainWindowViewModel.Selet_dtm("1010"));
|
|
||||||
Chart_new.Add("MTL", MainWindowViewModel.Selet_dtm("1015"));
|
|
||||||
Chart_new.Add("MTH", MainWindowViewModel.Selet_dtm("1009"));
|
|
||||||
Chart_new.Add("MUT", MainWindowViewModel.Selet_dtm("1011"));
|
|
||||||
Chart_new.Add("STTA", MainWindowViewModel.Selet_dtm("1012"));
|
|
||||||
Chart_new.Add("STLA", MainWindowViewModel.Selet_dtm("1017"));
|
|
||||||
Chart_new.Add("STTB", MainWindowViewModel.Selet_dtm("1013"));
|
|
||||||
Chart_new.Add("STLB", MainWindowViewModel.Selet_dtm("1018"));
|
|
||||||
Chart_new.Add("STTC", MainWindowViewModel.Selet_dtm("1014"));
|
|
||||||
Chart_new.Add("STLC", MainWindowViewModel.Selet_dtm("1019"));
|
|
||||||
client.SendAsync("[" + MainWindowViewModel.S01 + "]" + Chart_new.ToJsonString());
|
|
||||||
}
|
|
||||||
else { client.SendAsync("SC999"); }
|
|
||||||
}//当前信息
|
|
||||||
else if (SYSAPI == "SC831")
|
|
||||||
{
|
|
||||||
if (SYSKEY == MainWindowViewModel.SYSKEY)
|
|
||||||
{
|
|
||||||
|
|
||||||
client.SendAsync("[" + MainWindowViewModel.S01 + "]" +TechnologicalProcessView.sql.Tables[0].ToJsonString());
|
|
||||||
}
|
|
||||||
else { client.SendAsync("SC999"); }
|
|
||||||
}//当前工作表
|
|
||||||
else if (SYSAPI == "SC832")
|
|
||||||
{
|
|
||||||
if (SYSKEY == MainWindowViewModel.SYSKEY)
|
|
||||||
{
|
|
||||||
|
|
||||||
client.SendAsync("[" + MainWindowViewModel.S01 + "]" + MainWindowViewModel.SYSlog);
|
|
||||||
}
|
|
||||||
else { client.SendAsync("SC999"); }
|
|
||||||
}//当前细节信息
|
|
||||||
else if (SYSAPI == "SC851")
|
|
||||||
{
|
|
||||||
if (SYSKEY == MainWindowViewModel.SYSKEY)
|
|
||||||
{
|
|
||||||
client.SendAsync("[" + MainWindowViewModel.S01 + "]" + MainWindowViewModel.dt_d.ToJsonString());//数字开关信息
|
|
||||||
}
|
|
||||||
else { client.SendAsync("SC999"); }
|
|
||||||
}//数字开关表
|
|
||||||
else if (SYSAPI == "SC852")
|
|
||||||
{
|
|
||||||
if (SYSKEY == MainWindowViewModel.SYSKEY)
|
|
||||||
{
|
|
||||||
client.SendAsync("[" + MainWindowViewModel.S01 + "]" + MainWindowViewModel.dt_a.ToJsonString());//寄存器信息
|
|
||||||
}
|
|
||||||
else { client.SendAsync("SC999"); }
|
|
||||||
}//寄存器表
|
|
||||||
else if (SYSAPI == "SC853")
|
|
||||||
{
|
|
||||||
if (SYSKEY == MainWindowViewModel.SYSKEY)
|
|
||||||
{
|
|
||||||
client.SendAsync("[" + MainWindowViewModel.S01 + "]" + MainWindowViewModel.dt_m.ToJsonString());//缓存信息
|
|
||||||
}
|
|
||||||
else { client.SendAsync("SC999"); }
|
|
||||||
}//缓存表
|
|
||||||
|
|
||||||
return EasyTask.CompletedTask;
|
|
||||||
};
|
|
||||||
|
|
||||||
await service.SetupAsync(new TouchSocketConfig()//载入配置
|
|
||||||
.SetListenIPHosts(new IPHost[] { new IPHost("tcp://127.0.0.1:7789"), new IPHost(7790) })//同时监听两个地址
|
|
||||||
.ConfigureContainer(a =>//容器的配置顺序应该在最前面
|
|
||||||
{
|
|
||||||
//a.AddConsoleLogger();//添加一个控制台日志注入(注意:在maui中控制台日志不可用)
|
|
||||||
})
|
|
||||||
.ConfigurePlugins(a =>
|
|
||||||
{
|
|
||||||
//a.Add<DifferentProtocolPlugin>();
|
|
||||||
})
|
|
||||||
);
|
|
||||||
await service.StartAsync();//启动
|
|
||||||
|
|
||||||
LogGing.LogGingDATA("800SREVER:START");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class MyTcpService : TcpService<MyTcpSessionClient>
|
|
||||||
{
|
|
||||||
protected override MyTcpSessionClient NewClient()
|
|
||||||
{
|
|
||||||
return new MyTcpSessionClient();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class MyTcpSessionClient : TcpSessionClient
|
|
||||||
{
|
|
||||||
internal void SetDataHandlingAdapter(SingleStreamDataHandlingAdapter adapter)
|
|
||||||
{
|
|
||||||
base.SetAdapter(adapter);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 此插件实现,按照不同端口,使用不同适配器。
|
|
||||||
/// <list type="bullet">
|
|
||||||
/// <item>7789端口:使用"**"结尾的数据</item>
|
|
||||||
/// <item>7790端口:使用"##"结尾的数据</item>
|
|
||||||
/// </list>
|
|
||||||
/// </summary>
|
|
||||||
internal class DifferentProtocolPlugin : PluginBase, ITcpConnectingPlugin, ITcpReceivedPlugin
|
|
||||||
{
|
|
||||||
public async Task OnTcpConnecting(ITcpSession client, ConnectingEventArgs e)
|
|
||||||
{
|
|
||||||
if (client is MyTcpSessionClient sessionClient)
|
|
||||||
{
|
|
||||||
if (sessionClient.ServicePort == 7789)
|
|
||||||
{
|
|
||||||
sessionClient.SetDataHandlingAdapter(new TerminatorPackageAdapter("**"));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sessionClient.SetDataHandlingAdapter(new TerminatorPackageAdapter("##"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
await e.InvokeNext();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task OnTcpReceived(ITcpSession client, ReceivedDataEventArgs e)
|
|
||||||
{
|
|
||||||
//如果是自定义适配器,此处解析时,可以判断e.RequestInfo的类型
|
|
||||||
|
|
||||||
if (client is ITcpSessionClient sessionClient)
|
|
||||||
{
|
|
||||||
sessionClient.Logger.Info($"{sessionClient.GetIPPort()}收到数据,服务器端口:{sessionClient.ServicePort},数据:{e.ByteBlock}");
|
|
||||||
}
|
|
||||||
|
|
||||||
await e.InvokeNext();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,97 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Runtime.Remoting.Metadata.W3cXsd2001;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
|
||||||
|
|
||||||
|
|
||||||
namespace DyeingComputer.UserClass
|
|
||||||
{
|
|
||||||
public class Json
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ProgramSteps_
|
|
||||||
{
|
|
||||||
public string Program { get; set; }
|
|
||||||
public int Step { get; set; }
|
|
||||||
public string StepID { get; set; }
|
|
||||||
public string StepName { get; set; }
|
|
||||||
public string ParameterName { get; set; }
|
|
||||||
public double Parameter1 { get; set; }
|
|
||||||
public double Parameter2 { get; set; }
|
|
||||||
public double Parameter3 { get; set; }
|
|
||||||
public double Parameter4 { get; set; }
|
|
||||||
public double Parameter5 { get; set; }
|
|
||||||
public double Parameter6 { get; set; }
|
|
||||||
public double Parameter7 { get; set; }
|
|
||||||
public double Parameter8 { get; set; }
|
|
||||||
public double Parameter9 { get; set; }
|
|
||||||
public double Parameter10 { get; set; }
|
|
||||||
public string Remark { get; set; }
|
|
||||||
}
|
|
||||||
public class WorkorderSteps_
|
|
||||||
{
|
|
||||||
public string Program { get; set; }
|
|
||||||
public int Step { get; set; }
|
|
||||||
public string StepID { get; set; }
|
|
||||||
public string StepName { get; set; }
|
|
||||||
public string ParameterName { get; set; }
|
|
||||||
public double Parameter1 { get; set; }
|
|
||||||
public double Parameter2 { get; set; }
|
|
||||||
public double Parameter3 { get; set; }
|
|
||||||
public double Parameter4 { get; set; }
|
|
||||||
public double Parameter5 { get; set; }
|
|
||||||
public string Remark { get; set; }
|
|
||||||
}
|
|
||||||
public class WorkOrder_
|
|
||||||
{
|
|
||||||
public string WorkOrder { get; set; }
|
|
||||||
public string ProcessName { get; set; }
|
|
||||||
public DateTime StartTime { get; set; }
|
|
||||||
public DateTime EndTime { get; set; }
|
|
||||||
public DateTime Time { get; set; }
|
|
||||||
public string Remark { get; set; }
|
|
||||||
public string ProcessID { get; set; }
|
|
||||||
public int State { get; set; }
|
|
||||||
public int lock_ { get; set; }
|
|
||||||
}
|
|
||||||
public class RUN_
|
|
||||||
{
|
|
||||||
public string Program { get; set; }
|
|
||||||
public int Step { get; set; }
|
|
||||||
public string StepID { get; set; }
|
|
||||||
public string StepName { get; set; }
|
|
||||||
public string ParameterName { get; set; }
|
|
||||||
public double Parameter1 { get; set; }
|
|
||||||
public double Parameter2 { get; set; }
|
|
||||||
public double Parameter3 { get; set; }
|
|
||||||
public double Parameter4 { get; set; }
|
|
||||||
public double Parameter5 { get; set; }
|
|
||||||
public double Parameter6 { get; set; }
|
|
||||||
public double Parameter7 { get; set; }
|
|
||||||
public double Parameter8 { get; set; }
|
|
||||||
public double Parameter9 { get; set; }
|
|
||||||
public double Parameter10 { get; set; }
|
|
||||||
public string Remark { get; set; }
|
|
||||||
public int Run { get; set; }
|
|
||||||
public string Ryelot { get; set; }
|
|
||||||
}
|
|
||||||
public class DyelotHistory_
|
|
||||||
{
|
|
||||||
public DateTime TIME { get; set;}
|
|
||||||
public string WorkOrder { get; set; }
|
|
||||||
public string Dyelot { get; set; }
|
|
||||||
public int Tank { get; set; }
|
|
||||||
public int Step { get; set; }
|
|
||||||
public int State { get; set; }
|
|
||||||
public int Redye { get; set; }
|
|
||||||
public int Type { get; set; }
|
|
||||||
public string Machine { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,76 +0,0 @@
|
|||||||
using System.Text;
|
|
||||||
using System.Windows.Controls;
|
|
||||||
using System.Windows.Documents;
|
|
||||||
using System.Windows.Media;
|
|
||||||
|
|
||||||
namespace DyeingComputer.UserClass
|
|
||||||
{
|
|
||||||
public static class LogDataRead
|
|
||||||
{
|
|
||||||
private const int MaxCount = 1000;
|
|
||||||
private static int Count = 0;
|
|
||||||
private static RichTextBox textControl;
|
|
||||||
private static InlineCollection inlines;
|
|
||||||
|
|
||||||
//设置主控件
|
|
||||||
public static void SetTextControl(RichTextBox _textBox)
|
|
||||||
{
|
|
||||||
textControl = _textBox;
|
|
||||||
Paragraph graph = new Paragraph();
|
|
||||||
inlines = graph.Inlines;
|
|
||||||
textControl.Document.Blocks.Add(graph);
|
|
||||||
}
|
|
||||||
|
|
||||||
//输出黑色消息
|
|
||||||
public static void Info(string format, params object[] args)
|
|
||||||
{
|
|
||||||
AppendText(Brushes.Black, format, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
//输出绿色消息
|
|
||||||
public static void Suc(string format, params object[] args)
|
|
||||||
{
|
|
||||||
AppendText(Brushes.DarkGreen, format, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
//输出黄色消息
|
|
||||||
public static void Warning(string format, params object[] args)
|
|
||||||
{
|
|
||||||
AppendText(Brushes.DarkOrange, format, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
//输出红色消息
|
|
||||||
public static void Error(string format, params object[] args)
|
|
||||||
{
|
|
||||||
AppendText(Brushes.Red, format, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
//清除日志
|
|
||||||
public static void Clear()
|
|
||||||
{
|
|
||||||
Count = 0;
|
|
||||||
inlines.Clear();
|
|
||||||
textControl.ScrollToEnd();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void AppendText(Brush color, string format, params object[] args)
|
|
||||||
{
|
|
||||||
textControl.BeginChange();
|
|
||||||
StringBuilder builder = new StringBuilder();
|
|
||||||
builder.Append("[");
|
|
||||||
builder.Append(Count++);
|
|
||||||
builder.Append("] : ");
|
|
||||||
builder.Append(string.Format(format, (object[])args));
|
|
||||||
builder.Append("\n");
|
|
||||||
string str = builder.ToString();
|
|
||||||
inlines.Add(new Run(str) { Foreground = color });
|
|
||||||
if (inlines.Count > MaxCount)
|
|
||||||
{
|
|
||||||
inlines.Remove(inlines.FirstInline);
|
|
||||||
}
|
|
||||||
textControl.ScrollToEnd();
|
|
||||||
textControl.EndChange();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace DyeingComputer.UserClass
|
namespace SunlightCentralizedControlManagement_SCCM_.UserClass
|
||||||
{
|
{
|
||||||
internal class PressKey
|
internal class PressKey
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,114 +0,0 @@
|
|||||||
using DyeingComputer.View;
|
|
||||||
using DyeingComputer.ViewModel;
|
|
||||||
using ScottPlot.Colormaps;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Data;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Windows.Documents;
|
|
||||||
using System.Xml.Linq;
|
|
||||||
using static DyeingComputer.UserClass.SqliteHelper;
|
|
||||||
|
|
||||||
namespace DyeingComputer.UserClass
|
|
||||||
{
|
|
||||||
public class SQLDATA
|
|
||||||
{
|
|
||||||
private static SQLiteHelper SQLiteHelpers = null; //定义数据库
|
|
||||||
private readonly static string DBAddress = Environment.CurrentDirectory + "\\DataBase\\800COMPUTER.db"; //数据库路径
|
|
||||||
//WorkOrder表检查写入
|
|
||||||
public static bool WorkOrder(string WorkOrder, string ProcessName,string StartTime, string EndTime, string Time, string Remark,string lock_,string state,string ProcessID)
|
|
||||||
{
|
|
||||||
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
|
|
||||||
SQLiteHelpers.Open(); //打开数据库
|
|
||||||
object i = SQLiteHelpers.ExecuteScalar("select * from WorkOrder where WorkOrder = "+ WorkOrder,null);
|
|
||||||
if (i!=null)
|
|
||||||
{
|
|
||||||
SQLiteHelpers.Close();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
Dictionary<string, object> WorkOrder_new = new Dictionary<string, object>();//缓存函数
|
|
||||||
WorkOrder_new.Add("WorkOrder", WorkOrder);
|
|
||||||
WorkOrder_new.Add("ProcessName", ProcessName);
|
|
||||||
WorkOrder_new.Add("StartTime", StartTime);
|
|
||||||
WorkOrder_new.Add("EndTime", EndTime);
|
|
||||||
WorkOrder_new.Add("Time", Time);
|
|
||||||
WorkOrder_new.Add("Remark", Remark);
|
|
||||||
WorkOrder_new.Add("lock", Convert.ToInt16(lock_));
|
|
||||||
WorkOrder_new.Add("state", Convert.ToInt16(state));
|
|
||||||
WorkOrder_new.Add("ProcessID", ProcessID);
|
|
||||||
SQLiteHelpers.InsertData("WorkOrder", WorkOrder_new);
|
|
||||||
SQLiteHelpers.Close();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool WorkOderStep(DataTable WorkOrderStep_)
|
|
||||||
{
|
|
||||||
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
|
|
||||||
SQLiteHelpers.Open(); //打开数据库
|
|
||||||
DataTable data_t = WorkOrderStep_.Clone();
|
|
||||||
int a = WorkOrderStep_.Rows.Count;
|
|
||||||
if (a < 1)
|
|
||||||
{
|
|
||||||
SQLiteHelpers.Close();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
string Program = WorkOrderStep_.Rows[0][0].ToString();
|
|
||||||
object n = SQLiteHelpers.ExecuteScalar("select * from WorkorderSteps where Program = " + Program, null);
|
|
||||||
if (n != null)//如id存在着返回错误状态
|
|
||||||
{
|
|
||||||
SQLiteHelpers.Close();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
for (int i = 0; i < a; i++)
|
|
||||||
{
|
|
||||||
data_t.Clear();//清空
|
|
||||||
DataRow dr = data_t.NewRow();
|
|
||||||
dr.ItemArray = WorkOrderStep_.Rows[i].ItemArray;
|
|
||||||
data_t.Rows.InsertAt(dr, 0);
|
|
||||||
SQLiteHelpers.InsertData("WorkorderSteps", SQLiteHelpers.DataTableToDictionary(data_t));//行插入
|
|
||||||
}
|
|
||||||
SQLiteHelpers.Close(); //关闭连接
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void TechnologicalProcess_START(string workName)
|
|
||||||
{
|
|
||||||
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
|
|
||||||
SQLiteHelpers.Open(); //打开数据库
|
|
||||||
int r = 0;
|
|
||||||
string sql_script = "select * from WorkorderSteps where ProgramID = '" + workName + "'";
|
|
||||||
if (TechnologicalProcessView.sql != null) TechnologicalProcessView.sql.Clear(); //清空缓存
|
|
||||||
TechnologicalProcessView.sql = SQLiteHelpers.ExecuteDataSet(sql_script, null); //读取表写入缓存
|
|
||||||
TechnologicalProcessView.Program_Name = SQLiteHelpers.ExecuteScalar("select ProgramName from Workorder where ProgramID = '" + workName + "'", null).ToString();
|
|
||||||
|
|
||||||
SQLiteHelpers.Delete("RUN", null, null); //删除run信息
|
|
||||||
DataTable data_t = new DataTable();
|
|
||||||
data_t = TechnologicalProcessView.sql.Tables[0].Clone();
|
|
||||||
data_t.Columns.Add("DYELOT", typeof(string)); //添加列
|
|
||||||
int a = TechnologicalProcessView.sql.Tables[0].Rows.Count;
|
|
||||||
for (int i = 0; i < a; i++)
|
|
||||||
{
|
|
||||||
data_t.Clear();//清空
|
|
||||||
DataRow dt = TechnologicalProcessView.sql.Tables[0].Rows[i];//行转
|
|
||||||
DataRow dr = data_t.NewRow();
|
|
||||||
dr.ItemArray = dt.ItemArray;
|
|
||||||
dr.BeginEdit(); //添加订单号
|
|
||||||
dr["DYELOT"] = MainWindowViewModel.WorkNumder;
|
|
||||||
dr.EndEdit();
|
|
||||||
data_t.Rows.InsertAt(dr, 0); //行转换
|
|
||||||
|
|
||||||
r = SQLiteHelpers.InsertData("RUN", SQLiteHelpers.DataTableToDictionary(data_t));//行插入
|
|
||||||
}
|
|
||||||
//数据插入
|
|
||||||
MainWindowViewModel.WorkNumder = SQLiteHelpers.ExecuteDataSet("select WorkOrder from Workorder where ProgramID = '" + workName + "'", null);;
|
|
||||||
TechnologicalProcessView.workName = workName;
|
|
||||||
MainWindowViewModel.SYS_REDYE = 0;
|
|
||||||
MainWindowViewModel.ViewID = 1;
|
|
||||||
|
|
||||||
SQLiteHelpers.Close(); //关闭连接
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,686 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Data;
|
|
||||||
using System.IO;
|
|
||||||
using System.Data.Common;
|
|
||||||
using System.Windows.Media.Animation;
|
|
||||||
using System.Data.SQLite;
|
|
||||||
using System.Windows.Shapes;
|
|
||||||
using System.Drawing;
|
|
||||||
|
|
||||||
|
|
||||||
namespace DyeingComputer.UserClass
|
|
||||||
{
|
|
||||||
public class SqliteHelper
|
|
||||||
{
|
|
||||||
|
|
||||||
public class SQLiteHelper
|
|
||||||
{
|
|
||||||
#region 字段
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 事务的基类
|
|
||||||
/// </summary>
|
|
||||||
private DbTransaction DBtrans;
|
|
||||||
/// <summary>
|
|
||||||
/// 使用静态变量字典解决多线程实例本类,实现一个数据库对应一个clslock
|
|
||||||
/// </summary>
|
|
||||||
private static readonly Dictionary<string, ClsLock> RWL = new Dictionary<string, ClsLock>();
|
|
||||||
/// <summary>
|
|
||||||
/// 数据库地址
|
|
||||||
/// </summary>
|
|
||||||
private readonly string mdataFile;
|
|
||||||
/// <summary>
|
|
||||||
/// 数据库密码
|
|
||||||
/// </summary>
|
|
||||||
private readonly string mPassWord;
|
|
||||||
private readonly string LockName = null;
|
|
||||||
/// <summary>
|
|
||||||
/// 数据库连接定义
|
|
||||||
/// </summary>
|
|
||||||
private SQLiteConnection mConn;
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region 构造函数
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 根据数据库地址初始化
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="dataFile">数据库地址</param>
|
|
||||||
public SQLiteHelper(string dataFile)
|
|
||||||
{
|
|
||||||
this.mdataFile = dataFile ?? throw new ArgumentNullException("dataFile=null");
|
|
||||||
//this.mdataFile = AppDomain.CurrentDomain.BaseDirectory + dataFile;
|
|
||||||
this.mdataFile = dataFile;
|
|
||||||
if (!RWL.ContainsKey(dataFile))
|
|
||||||
{
|
|
||||||
LockName = dataFile;
|
|
||||||
RWL.Add(dataFile, new ClsLock());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 使用密码打开数据库
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="dataFile">数据库地址</param>
|
|
||||||
/// <param name="PassWord">数据库密码</param>
|
|
||||||
public SQLiteHelper(string dataFile, string PassWord)
|
|
||||||
{
|
|
||||||
this.mdataFile = dataFile ?? throw new ArgumentNullException("dataFile is null");
|
|
||||||
this.mPassWord = PassWord ?? throw new ArgumentNullException("PassWord is null");
|
|
||||||
//this.mdataFile = AppDomain.CurrentDomain.BaseDirectory + dataFile;
|
|
||||||
this.mdataFile = dataFile;
|
|
||||||
if (!RWL.ContainsKey(dataFile))
|
|
||||||
{
|
|
||||||
LockName = dataFile;
|
|
||||||
RWL.Add(dataFile, new ClsLock());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region 打开/关闭 数据库
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 打开 SQLiteManager 使用的数据库连接
|
|
||||||
/// </summary>
|
|
||||||
public void Open()
|
|
||||||
{
|
|
||||||
if (string.IsNullOrWhiteSpace(mPassWord))
|
|
||||||
{
|
|
||||||
mConn = OpenConnection(this.mdataFile);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mConn = OpenConnection(this.mdataFile, mPassWord);
|
|
||||||
}
|
|
||||||
Console.WriteLine("The database was opened successfully");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 关闭连接
|
|
||||||
/// </summary>
|
|
||||||
public void Close()
|
|
||||||
{
|
|
||||||
if (this.mConn != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
this.mConn.Close();
|
|
||||||
if (RWL.ContainsKey(LockName))
|
|
||||||
{
|
|
||||||
RWL.Remove(LockName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
Console.WriteLine("Shutdown failed");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Console.WriteLine("The database was shut down successfully");
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region 事务
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 开始事务
|
|
||||||
/// </summary>
|
|
||||||
public void BeginTrain()
|
|
||||||
{
|
|
||||||
EnsureConnection();
|
|
||||||
DBtrans = mConn.BeginTransaction();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 提交事务
|
|
||||||
/// </summary>
|
|
||||||
public void DBCommit()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
DBtrans.Commit();
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
DBtrans.Rollback();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region 工具
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 打开一个SQLite数据库文件,如果文件不存在,则创建(无密码)
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="dataFile"></param>
|
|
||||||
/// <returns>SQLiteConnection 类</returns>
|
|
||||||
private SQLiteConnection OpenConnection(string dataFile)
|
|
||||||
{
|
|
||||||
if (dataFile == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException("dataFiledataFile=null");
|
|
||||||
}
|
|
||||||
if (!File.Exists(dataFile))
|
|
||||||
{
|
|
||||||
SQLiteConnection.CreateFile(dataFile);
|
|
||||||
}
|
|
||||||
SQLiteConnection conn = new SQLiteConnection();
|
|
||||||
SQLiteConnectionStringBuilder conStr = new SQLiteConnectionStringBuilder
|
|
||||||
{
|
|
||||||
DataSource = dataFile
|
|
||||||
};
|
|
||||||
conn.ConnectionString = conStr.ToString();
|
|
||||||
conn.Open();
|
|
||||||
return conn;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 打开一个SQLite数据库文件,如果文件不存在,则创建(有密码)
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="dataFile"></param>
|
|
||||||
/// <param name="Password"></param>
|
|
||||||
/// <returns>SQLiteConnection 类</returns>
|
|
||||||
private SQLiteConnection OpenConnection(string dataFile, string Password)
|
|
||||||
{
|
|
||||||
if (dataFile == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException("dataFile=null");
|
|
||||||
}
|
|
||||||
if (!File.Exists(Convert.ToString(dataFile)))
|
|
||||||
{
|
|
||||||
SQLiteConnection.CreateFile(dataFile);
|
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
SQLiteConnection conn = new SQLiteConnection();
|
|
||||||
SQLiteConnectionStringBuilder conStr = new SQLiteConnectionStringBuilder
|
|
||||||
{
|
|
||||||
DataSource = dataFile,
|
|
||||||
Password = Password
|
|
||||||
};
|
|
||||||
conn.ConnectionString = conStr.ToString();
|
|
||||||
conn.Open();
|
|
||||||
return conn;
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 读取 或 设置 SQLiteManager 使用的数据库连接
|
|
||||||
/// </summary>
|
|
||||||
public SQLiteConnection Connection
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return mConn;
|
|
||||||
}
|
|
||||||
private set
|
|
||||||
{
|
|
||||||
mConn = value ?? throw new ArgumentNullException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 确保数据库是连接状态
|
|
||||||
/// </summary>
|
|
||||||
/// <exception cref="Exception"></exception>
|
|
||||||
protected void EnsureConnection()
|
|
||||||
{
|
|
||||||
if (this.mConn == null)
|
|
||||||
{
|
|
||||||
throw new Exception("SQLiteManager.Connection=null");
|
|
||||||
}
|
|
||||||
if (mConn.State != ConnectionState.Open)
|
|
||||||
{
|
|
||||||
mConn.Open();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取数据库文件的路径
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public string GetDataFile()
|
|
||||||
{
|
|
||||||
return this.mdataFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 判断表 table 是否存在
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="table"></param>
|
|
||||||
/// <returns>存在返回true,否则返回false</returns>
|
|
||||||
public bool TableExists(string table)
|
|
||||||
{
|
|
||||||
if (table == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException("table=null");
|
|
||||||
}
|
|
||||||
EnsureConnection();
|
|
||||||
SQLiteDataReader reader = ExecuteReader("SELECT count(*) as c FROM sqlite_master WHERE type='table' AND name=@tableName ", new SQLiteParameter[] { new SQLiteParameter("tableName", table) });
|
|
||||||
if (reader == null)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
reader.Read();
|
|
||||||
int c = reader.GetInt32(0);
|
|
||||||
reader.Close();
|
|
||||||
reader.Dispose();
|
|
||||||
//return false;
|
|
||||||
return c == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// VACUUM 命令(通过复制主数据库中的内容到一个临时数据库文件,然后清空主数据库,并从副本中重新载入原始的数据库文件)
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public bool Vacuum()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
using (SQLiteCommand Command = new SQLiteCommand("VACUUM", Connection))
|
|
||||||
{
|
|
||||||
Command.ExecuteNonQuery();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch (System.Data.SQLite.SQLiteException)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region 执行SQL
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 执行SQL, 并返回 SQLiteDataReader 对象结果
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sql"></param>
|
|
||||||
/// <param name="paramArr">null 表示无参数</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public SQLiteDataReader ExecuteReader(string sql, SQLiteParameter[] paramArr)
|
|
||||||
{
|
|
||||||
if (sql == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException("sql=null");
|
|
||||||
}
|
|
||||||
EnsureConnection();
|
|
||||||
using (RWL[LockName].Read())
|
|
||||||
{
|
|
||||||
using (SQLiteCommand cmd = new SQLiteCommand(sql, Connection))
|
|
||||||
{
|
|
||||||
if (paramArr != null)
|
|
||||||
{
|
|
||||||
cmd.Parameters.AddRange(paramArr);
|
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
SQLiteDataReader reader = cmd.ExecuteReader();
|
|
||||||
cmd.Parameters.Clear();
|
|
||||||
return reader;
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 执行查询,并返回dataset对象
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sql">SQL查询语句</param>
|
|
||||||
/// <param name="paramArr">参数数组</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public DataSet ExecuteDataSet(string sql, SQLiteParameter[] paramArr)
|
|
||||||
{
|
|
||||||
if (sql == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException("sql=null");
|
|
||||||
}
|
|
||||||
this.EnsureConnection();
|
|
||||||
using (RWL[LockName].Read())
|
|
||||||
{
|
|
||||||
using (SQLiteCommand cmd = new SQLiteCommand(sql, this.Connection))
|
|
||||||
{
|
|
||||||
if (paramArr != null)
|
|
||||||
{
|
|
||||||
cmd.Parameters.AddRange(paramArr);
|
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
SQLiteDataAdapter da = new SQLiteDataAdapter();
|
|
||||||
DataSet ds = new DataSet();
|
|
||||||
da.SelectCommand = cmd;
|
|
||||||
da.Fill(ds);
|
|
||||||
cmd.Parameters.Clear();
|
|
||||||
da.Dispose();
|
|
||||||
return ds;
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 执行SQL查询,并返回dataset对象。
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="strTable">映射源表的名称</param>
|
|
||||||
/// <param name="sql">SQL语句</param>
|
|
||||||
/// <param name="paramArr">SQL参数数组</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public DataSet ExecuteDataSet(string strTable, string sql, SQLiteParameter[] paramArr)
|
|
||||||
{
|
|
||||||
if (sql == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException("sql=null");
|
|
||||||
}
|
|
||||||
this.EnsureConnection();
|
|
||||||
using (RWL[LockName].Read())
|
|
||||||
{
|
|
||||||
using (SQLiteCommand cmd = new SQLiteCommand(sql, this.Connection))
|
|
||||||
{
|
|
||||||
if (paramArr != null)
|
|
||||||
{
|
|
||||||
cmd.Parameters.AddRange(paramArr);
|
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
SQLiteDataAdapter da = new SQLiteDataAdapter();
|
|
||||||
DataSet ds = new DataSet();
|
|
||||||
da.SelectCommand = cmd;
|
|
||||||
da.Fill(ds, strTable);
|
|
||||||
cmd.Parameters.Clear();
|
|
||||||
da.Dispose();
|
|
||||||
return ds;
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 执行SQL,返回受影响的行数,可用于执行表创建语句,paramArr == null 表示无参数
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sql"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public int ExecuteNonQuery(string sql, SQLiteParameter[] paramArr)
|
|
||||||
{
|
|
||||||
if (sql == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException("sql=null");
|
|
||||||
}
|
|
||||||
this.EnsureConnection();
|
|
||||||
using (RWL[LockName].Read())
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
using (SQLiteCommand cmd = new SQLiteCommand(sql, Connection))
|
|
||||||
{
|
|
||||||
if (paramArr != null)
|
|
||||||
{
|
|
||||||
foreach (SQLiteParameter p in paramArr)
|
|
||||||
{
|
|
||||||
cmd.Parameters.Add(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
int c = cmd.ExecuteNonQuery();
|
|
||||||
cmd.Parameters.Clear();
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (SQLiteException)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 执行SQL,返回结果集第一行,如果结果集为空,那么返回空 List(List.Count=0),
|
|
||||||
/// rowWrapper = null 时,使用 WrapRowToDictionary
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sql"></param>
|
|
||||||
/// <param name="paramArr"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public object ExecuteScalar(string sql, SQLiteParameter[] paramArr)
|
|
||||||
{
|
|
||||||
if (sql == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException("sql=null");
|
|
||||||
}
|
|
||||||
this.EnsureConnection();
|
|
||||||
using (RWL[LockName].Read())
|
|
||||||
{
|
|
||||||
using (SQLiteCommand cmd = new SQLiteCommand(sql, Connection))
|
|
||||||
{
|
|
||||||
if (paramArr != null)
|
|
||||||
{
|
|
||||||
cmd.Parameters.AddRange(paramArr);
|
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
object reader = cmd.ExecuteScalar();
|
|
||||||
cmd.Parameters.Clear();
|
|
||||||
cmd.Dispose();
|
|
||||||
return reader;
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 查询一行记录,无结果时返回 null,conditionCol = null 时将忽略条件,直接执行 select * from table
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="table">表名</param>
|
|
||||||
/// <param name="conditionCol"></param>
|
|
||||||
/// <param name="conditionVal"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public object QueryOne(string table, string conditionCol, object conditionVal)
|
|
||||||
{
|
|
||||||
if (table == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException("table=null");
|
|
||||||
}
|
|
||||||
this.EnsureConnection();
|
|
||||||
string sql = "select * from " + table;
|
|
||||||
if (conditionCol != null)
|
|
||||||
{
|
|
||||||
sql += " where " + conditionCol + "=@" + conditionCol;
|
|
||||||
}
|
|
||||||
object result = ExecuteScalar(sql, new SQLiteParameter[] { new SQLiteParameter(conditionCol, conditionVal) });
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region 增 删 改
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 执行 insert into 语句
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="table"></param>
|
|
||||||
/// <param name="entity"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public int InsertData(string table, Dictionary<string, object> entity)
|
|
||||||
{
|
|
||||||
if (table == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException("table=null");
|
|
||||||
}
|
|
||||||
this.EnsureConnection();
|
|
||||||
string sql = BuildInsert(table, entity);
|
|
||||||
return this.ExecuteNonQuery(sql, BuildParamArray(entity));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 执行 update 语句,注意:如果 where = null,那么 whereParams 也为 null,
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="table">表名</param>
|
|
||||||
/// <param name="entity">要修改的列名和列名的值</param>
|
|
||||||
/// <param name="where">查找符合条件的列</param>
|
|
||||||
/// <param name="whereParams">where条件中参数的值</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public int Update(string table, Dictionary<string, object> entity, string where, SQLiteParameter[] whereParams)
|
|
||||||
{
|
|
||||||
if (table == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException("table=null");
|
|
||||||
}
|
|
||||||
this.EnsureConnection();
|
|
||||||
string sql = BuildUpdate(table, entity);
|
|
||||||
SQLiteParameter[] parameter = BuildParamArray(entity);
|
|
||||||
if (where != null)
|
|
||||||
{
|
|
||||||
sql += " where " + where;
|
|
||||||
if (whereParams != null)
|
|
||||||
{
|
|
||||||
SQLiteParameter[] newArr = new SQLiteParameter[(parameter.Length + whereParams.Length)];
|
|
||||||
Array.Copy(parameter, newArr, parameter.Length);
|
|
||||||
Array.Copy(whereParams, 0, newArr, parameter.Length, whereParams.Length);
|
|
||||||
parameter = newArr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return this.ExecuteNonQuery(sql, parameter);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 执行 delete from table 语句,where不必包含'where'关键字,where = null 时将忽略 whereParams
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="table"></param>
|
|
||||||
/// <param name="where"></param>
|
|
||||||
/// <param name="whereParams"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public int Delete(string table, string where, SQLiteParameter[] whereParams)
|
|
||||||
{
|
|
||||||
if (table == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException("table=null");
|
|
||||||
}
|
|
||||||
this.EnsureConnection();
|
|
||||||
string sql = "delete from " + table + " ";
|
|
||||||
if (where != null)
|
|
||||||
{
|
|
||||||
sql += "where " + where;
|
|
||||||
}
|
|
||||||
return ExecuteNonQuery(sql, whereParams);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 将 Dictionary 类型数据 转换为 SQLiteParameter[] 类型
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="entity"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
private SQLiteParameter[] BuildParamArray(Dictionary<string, object> entity)
|
|
||||||
{
|
|
||||||
List<SQLiteParameter> list = new List<SQLiteParameter>();
|
|
||||||
foreach (string key in entity.Keys)
|
|
||||||
{
|
|
||||||
list.Add(new SQLiteParameter(key, entity[key]));
|
|
||||||
}
|
|
||||||
if (list.Count == 0)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return list.ToArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 将 Dictionary 类型数据 转换为 插入数据 的 SQL语句
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="table">表名</param>
|
|
||||||
/// <param name="entity">字典</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
private string BuildInsert(string table, Dictionary<string, object> entity)
|
|
||||||
{
|
|
||||||
StringBuilder buf = new StringBuilder();
|
|
||||||
buf.Append("insert into ").Append(table);
|
|
||||||
buf.Append(" (");
|
|
||||||
foreach (string key in entity.Keys)
|
|
||||||
{
|
|
||||||
buf.Append(key).Append(",");
|
|
||||||
}
|
|
||||||
buf.Remove(buf.Length - 1, 1); // 移除最后一个,
|
|
||||||
buf.Append(") ");
|
|
||||||
buf.Append("values(");
|
|
||||||
foreach (string key in entity.Keys)
|
|
||||||
{
|
|
||||||
buf.Append("@").Append(key).Append(","); // 创建一个参数
|
|
||||||
}
|
|
||||||
buf.Remove(buf.Length - 1, 1);
|
|
||||||
buf.Append(") ");
|
|
||||||
|
|
||||||
return buf.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 将 Dictionary 类型数据 转换为 修改数据 的 SQL语句
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="table">表名</param>
|
|
||||||
/// <param name="entity">字典</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
private string BuildUpdate(string table, Dictionary<string, object> entity)
|
|
||||||
{
|
|
||||||
StringBuilder buf = new StringBuilder();
|
|
||||||
buf.Append("update ").Append(table).Append(" set ");
|
|
||||||
foreach (string key in entity.Keys)
|
|
||||||
{
|
|
||||||
buf.Append(key).Append("=").Append("@").Append(key).Append(",");
|
|
||||||
}
|
|
||||||
buf.Remove(buf.Length - 1, 1);
|
|
||||||
buf.Append(" ");
|
|
||||||
return buf.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 将 DataTable 转换为 Dictionary 类型数据
|
|
||||||
/// </summary>
|
|
||||||
public Dictionary<string, object> DataTableToDictionary(DataTable dataTable)
|
|
||||||
{
|
|
||||||
Dictionary<string, object> result = new Dictionary<string, object>();
|
|
||||||
if (dataTable != null)
|
|
||||||
{
|
|
||||||
foreach (DataRow dataRow in dataTable.Rows)
|
|
||||||
{
|
|
||||||
foreach (DataColumn dataColumn in dataTable.Columns)
|
|
||||||
{
|
|
||||||
result.Add(dataColumn.ColumnName, dataRow[dataColumn].ToString());
|
|
||||||
//result = Console.WriteLine(dataRow[dataColumn].ToString());
|
|
||||||
//result.Add(dataColumn.ColumnName, dataRow[dataColumn].ToString())(new RepeatDictionaryComparer());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
result = null;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 变量传递至ui
|
||||||
|
/// </summary>
|
||||||
|
public class ViewModelBase : INotifyPropertyChanged
|
||||||
|
{
|
||||||
|
public event PropertyChangedEventHandler PropertyChanged;
|
||||||
|
protected virtual void OnPropertyChanged(string propertyName)
|
||||||
|
{
|
||||||
|
if (PropertyChanged != null)
|
||||||
|
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
|
||||||
|
}
|
||||||
|
public void RaisePropertyChanged(string propertyName)
|
||||||
|
{
|
||||||
|
if (PropertyChanged != null)
|
||||||
|
{
|
||||||
|
if (propertyName != null)
|
||||||
|
{
|
||||||
|
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public class MainWindowViewModel : ViewModelBase
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
using CommonServiceLocator;
|
||||||
|
|
||||||
|
namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
|
||||||
|
{
|
||||||
|
public class ViewModelLocator
|
||||||
|
{
|
||||||
|
public ViewModelLocator()
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public MainWindowViewModel Main
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return ServiceLocator.Current.GetInstance<MainWindowViewModel>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 17 KiB |
Reference in new issue
Block a user