chore: initial commit
This commit is contained in:
107
Interface_WebAPI/WebApi/02_WebApi.csproj
Normal file
107
Interface_WebAPI/WebApi/02_WebApi.csproj
Normal file
@@ -0,0 +1,107 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{5C6E31A8-8B45-4459-BA62-07AF6135DF4A}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>WebApi</RootNamespace>
|
||||
<AssemblyName>WebApi</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<Deterministic>true</Deterministic>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<TargetZone>LocalIntranet</TargetZone>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<GenerateManifests>false</GenerateManifests>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<ApplicationManifest>Properties\app.manifest</ApplicationManifest>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="log4net, Version=2.0.14.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\log4net.2.0.14\lib\net45\log4net.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Net.Http.Formatting, Version=5.2.9.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.AspNet.WebApi.Client.5.2.9\lib\net45\System.Net.Http.Formatting.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web" />
|
||||
<Reference Include="System.Web.Cors, Version=5.2.9.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.AspNet.Cors.5.2.9\lib\net45\System.Web.Cors.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.Http, Version=5.2.9.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.AspNet.WebApi.Core.5.2.9\lib\net45\System.Web.Http.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.Http.Cors, Version=5.2.9.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.AspNet.WebApi.Cors.5.2.9\lib\net45\System.Web.Http.Cors.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.Http.SelfHost, Version=5.2.9.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.AspNet.WebApi.SelfHost.5.2.9\lib\net45\System.Web.Http.SelfHost.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ApiTools.cs" />
|
||||
<Compile Include="Controller\ZSavePositionController.cs" />
|
||||
<Compile Include="Controller\ZSaveTagController.cs" />
|
||||
<Compile Include="GlobalVar.cs" />
|
||||
<Compile Include="InitServer.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Z_Save_Position.cs" />
|
||||
<Compile Include="Z_Save_Tag.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
<None Include="log4net.config">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="packages.config" />
|
||||
<None Include="Properties\app.manifest" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="mysql.sql" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\DatabaseClient\01_DatabaseClient.csproj">
|
||||
<Project>{c7c5e929-be10-4ed6-94db-b8d65e05e52f}</Project>
|
||||
<Name>01_DatabaseClient</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
46
Interface_WebAPI/WebApi/ApiTools.cs
Normal file
46
Interface_WebAPI/WebApi/ApiTools.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.Http;
|
||||
using System.Net.Http;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace WebApi
|
||||
{
|
||||
public enum ResponseCode
|
||||
{
|
||||
Fail = 00000,
|
||||
Success = 00200,
|
||||
}
|
||||
|
||||
public class ApiTools
|
||||
{
|
||||
private string msgModel = "{{\"code\":{0},\"message\":\"{1}\",\"result\":{2}}}";
|
||||
public ApiTools()
|
||||
{
|
||||
}
|
||||
public HttpResponseMessage MsgFormat(ResponseCode code, string explanation, string result)
|
||||
{
|
||||
string r = @"^(\-|\+)?\d+(\.\d+)?$";
|
||||
string json = string.Empty;
|
||||
if (Regex.IsMatch(result, r) || result.ToLower() == "true" || result.ToLower() == "false" || result == "[]" || result.Contains('{'))
|
||||
{
|
||||
json = string.Format(msgModel, (int)code, explanation, result);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (result.Contains('"'))
|
||||
{
|
||||
json = string.Format(msgModel, (int)code, explanation, result);
|
||||
}
|
||||
else
|
||||
{
|
||||
json = string.Format(msgModel, (int)code, explanation, "\"" + result + "\"");
|
||||
}
|
||||
}
|
||||
return new HttpResponseMessage { Content = new StringContent(json, System.Text.Encoding.UTF8, "application/json") };
|
||||
}
|
||||
}
|
||||
}
|
||||
61
Interface_WebAPI/WebApi/App.config
Normal file
61
Interface_WebAPI/WebApi/App.config
Normal file
@@ -0,0 +1,61 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
|
||||
</startup>
|
||||
<appSettings>
|
||||
<add key="WebApiUrl" value="http://localhost:41190"/>
|
||||
<add key="DatabaseType" value="MySql"/>
|
||||
<add key="MysqlConnectString" value="server=localhost;database=mytest;username=root;password=123456;"/>
|
||||
<add key="SqliteConnectString" value="Data Source=mytest.sqlite;Version=3;"/>
|
||||
<add key="MssqlConnectString" value="server=.\WINCC;database=MW_DataFactory_App_Add;uid=sa;pwd=126.com;Connection Reset=FALSE;Max Pool Size = 1000;"/>
|
||||
</appSettings>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0"/>
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.1.4.0" newVersion="4.1.4.0"/>
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0"/>
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.1.1" newVersion="4.0.1.1"/>
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0"/>
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0"/>
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Text.Encodings.Web" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.4.0" newVersion="4.0.4.0"/>
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.ComponentModel.Annotations" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.2.1.0"/>
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0"/>
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-5.2.9.0" newVersion="5.2.9.0"/>
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-5.2.9.0" newVersion="5.2.9.0"/>
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
</configuration>
|
||||
119
Interface_WebAPI/WebApi/Controller/ZSavePositionController.cs
Normal file
119
Interface_WebAPI/WebApi/Controller/ZSavePositionController.cs
Normal file
@@ -0,0 +1,119 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using System.Web.Http;
|
||||
using System.Collections.Concurrent;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
|
||||
namespace WebApi
|
||||
{
|
||||
|
||||
[RoutePrefix("api/ZSavePosition")] //定义路由前缀
|
||||
public class ZSavePositionController : ApiController
|
||||
{
|
||||
/// <summary>
|
||||
/// 插入数据库
|
||||
/// </summary>
|
||||
/// <param name="jObject"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public void Insert(JObject jObject)
|
||||
{
|
||||
string pp = "";
|
||||
try
|
||||
{
|
||||
var z_Save_Position = JsonConvert.DeserializeObject<Z_Save_Position>(JsonConvert.SerializeObject(jObject));
|
||||
|
||||
//z_Save_Position.OpName = "a1";
|
||||
//z_Save_Position.Value = "asd";
|
||||
//z_Save_Position.OperationTime = "2022/06/29 16:40:43";
|
||||
//z_Save_Position.ProjectCode = "123";
|
||||
|
||||
string sql = "INSERT INTO z_save_position(OpName, Value, OperationTime, ProjectCode) VALUES('" + z_Save_Position.OpName + "', '" + z_Save_Position.Value + "', '" + z_Save_Position.OperationTime + "', '" + z_Save_Position.ProjectCode + "');\n";
|
||||
var res = GlobalVar.dbClient.ExecNonQuery(sql);
|
||||
|
||||
pp = res.ToString();
|
||||
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
GlobalVar.log.Error(err.Message);
|
||||
// Console.WriteLine(err.Message);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public HttpResponseMessage SelectPage([FromBody] JObject jobj)
|
||||
{
|
||||
string pp = "";
|
||||
try
|
||||
{
|
||||
var OpName = jobj["OpName"].ToString();
|
||||
var StartTime = jobj["StartTime"].ToString();
|
||||
var EndTime = jobj["EndTime"].ToString();
|
||||
var PageCurrent = jobj["PageCurrent"].ToString();
|
||||
var PageSize = jobj["PageSize"].ToString();
|
||||
|
||||
string sql = "SELECT * FROM z_save_position " +
|
||||
"WHERE(OperationTime BETWEEN '" + StartTime + "' AND '" + EndTime + "') AND OpName like '" + OpName + "%' " +
|
||||
"ORDER BY OperationTime;\n";
|
||||
var res = GlobalVar.dbClient.ExecQuery(sql);
|
||||
|
||||
var zSavePersonList = Z_Save_Position.DataTableToClass(res);
|
||||
|
||||
var newZSaveList = DatabaseClient.DBClient.SplitePage<Z_Save_Position>(zSavePersonList, Convert.ToInt32(PageSize), Convert.ToInt32(PageCurrent));
|
||||
var tableData = (JArray)JsonConvert.DeserializeObject(JsonConvert.SerializeObject(newZSaveList));
|
||||
JObject resjobj = new JObject() {
|
||||
new JProperty("ItemCount", zSavePersonList.Count.ToString()),
|
||||
new JProperty("TableData",tableData)
|
||||
};
|
||||
|
||||
pp = resjobj.ToString();
|
||||
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
GlobalVar.log.Error(err.Message);
|
||||
// Console.WriteLine(err.Message);
|
||||
}
|
||||
HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(pp, Encoding.GetEncoding("UTF-8"), "application/json") };
|
||||
return result;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public HttpResponseMessage Select([FromBody] JObject jobj)
|
||||
{
|
||||
string pp = "";
|
||||
try
|
||||
{
|
||||
var OpName = jobj["OpName"].ToString();
|
||||
var StartTime = jobj["StartTime"].ToString();
|
||||
var EndTime = jobj["EndTime"].ToString();
|
||||
|
||||
string sql = "SELECT * FROM z_save_position " +
|
||||
"WHERE(OperationTime BETWEEN '"+StartTime+"' AND '"+EndTime+"') AND OpName like '"+OpName+"%' " +
|
||||
"ORDER BY OperationTime;\n";
|
||||
var res = GlobalVar.dbClient.ExecQuery(sql);
|
||||
|
||||
var zSavePersonList = Z_Save_Position.DataTableToClass(res);
|
||||
|
||||
var zSavePersonListStr = JsonConvert.SerializeObject(zSavePersonList);
|
||||
|
||||
pp = zSavePersonListStr.ToString();
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
GlobalVar.log.Error(err.Message);
|
||||
// Console.WriteLine (err.Message);
|
||||
}
|
||||
HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(pp, Encoding.GetEncoding("UTF-8"), "application/json") };
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
122
Interface_WebAPI/WebApi/Controller/ZSaveTagController.cs
Normal file
122
Interface_WebAPI/WebApi/Controller/ZSaveTagController.cs
Normal file
@@ -0,0 +1,122 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using System.Web.Http;
|
||||
using System.Collections.Concurrent;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
|
||||
namespace WebApi
|
||||
{
|
||||
|
||||
[RoutePrefix("api/ZSaveTag")] //定义路由前缀
|
||||
public class ZSaveTagController : ApiController
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 插入数据库
|
||||
/// </summary>
|
||||
/// <param name="jObject"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public void Insert(JObject jObject)
|
||||
{
|
||||
string pp = "";
|
||||
try
|
||||
{
|
||||
var z_Save_Tag = JsonConvert.DeserializeObject<Z_Save_Tag>(JsonConvert.SerializeObject(jObject));
|
||||
|
||||
string sql = "" +
|
||||
"INSERT INTO z_save_tag (OpName, TagID, Value, KeepTime, OperationTime, ProjectCode) " +
|
||||
" VALUES('"+ z_Save_Tag.OpName+ "', '"+ z_Save_Tag.TagID+ "', '"+ z_Save_Tag.Value+ "', '"+ z_Save_Tag .KeepTime+ "', '"+ z_Save_Tag .OperationTime+ "', '"+ z_Save_Tag .ProjectCode+ "'); \n";
|
||||
var res = GlobalVar.dbClient.ExecNonQuery(sql);
|
||||
|
||||
pp = res.ToString();
|
||||
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
GlobalVar.log.Error(err.Message);
|
||||
}
|
||||
// HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(pp, Encoding.GetEncoding("UTF-8"), "application/json") };
|
||||
// return result;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public HttpResponseMessage SelectPage([FromBody]JObject jobj)
|
||||
{
|
||||
string pp = "";
|
||||
|
||||
try
|
||||
{
|
||||
var OpName = jobj["OpName"].ToString();
|
||||
var StartTime = jobj["StartTime"].ToString();
|
||||
var EndTime = jobj["EndTime"].ToString();
|
||||
var PageCurrent = jobj["PageCurrent"].ToString();
|
||||
var PageSize = jobj["PageSize"].ToString();
|
||||
|
||||
|
||||
string sql = "SELECT * FROM z_save_tag " +
|
||||
"WHERE(OperationTime BETWEEN '" + StartTime + "' AND '" + EndTime + "') AND OpName like '" + OpName + "%' " +
|
||||
"ORDER BY OperationTime;\n";
|
||||
var res = GlobalVar.dbClient.ExecQuery(sql);
|
||||
|
||||
var zSavePersonList = Z_Save_Position.DataTableToClass(res);
|
||||
|
||||
var newZSaveList = DatabaseClient.DBClient.SplitePage<Z_Save_Position>(zSavePersonList, Convert.ToInt32(PageSize), Convert.ToInt32(PageCurrent));
|
||||
var tableData = (JArray)JsonConvert.DeserializeObject(JsonConvert.SerializeObject(newZSaveList));
|
||||
JObject resjobj = new JObject() {
|
||||
new JProperty("ItemCount", zSavePersonList.Count.ToString()),
|
||||
new JProperty("TableData",tableData)
|
||||
};
|
||||
|
||||
pp = resjobj.ToString()
|
||||
//.Replace("\r\n","")
|
||||
;
|
||||
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
GlobalVar.log.Error(err.Message);
|
||||
// Console.WriteLine(err.Message);
|
||||
}
|
||||
HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(pp, Encoding.GetEncoding("UTF-8"), "application/json") };
|
||||
return result;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public HttpResponseMessage Select([FromBody] JObject jobj)
|
||||
{
|
||||
string pp = "";
|
||||
try
|
||||
{
|
||||
string OpName = jobj["OpName"].ToString();
|
||||
string StartTime = jobj["StartTime"].ToString();
|
||||
string EndTime = jobj["EndTime"].ToString();
|
||||
|
||||
string sql = "SELECT * FROM z_save_tag " +
|
||||
"WHERE(OperationTime BETWEEN '"+StartTime+"' AND '"+EndTime+"') AND OpName like '"+OpName+"%' " +
|
||||
"ORDER BY OperationTime;\n";
|
||||
var res = GlobalVar.dbClient.ExecQuery(sql);
|
||||
|
||||
var zSavePersonList = Z_Save_Position.DataTableToClass(res);
|
||||
|
||||
var zSavePersonListStr = JsonConvert.SerializeObject(zSavePersonList);
|
||||
|
||||
pp = zSavePersonListStr.ToString();
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
GlobalVar.log.Error(err.Message);
|
||||
// Console.WriteLine(err.Message);
|
||||
}
|
||||
HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(pp, Encoding.GetEncoding("UTF-8"), "application/json") };
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
16
Interface_WebAPI/WebApi/GlobalVar.cs
Normal file
16
Interface_WebAPI/WebApi/GlobalVar.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using DatabaseClient;
|
||||
using log4net;
|
||||
|
||||
namespace WebApi
|
||||
{
|
||||
class GlobalVar
|
||||
{
|
||||
public static DatabaseClient.DBClient dbClient;
|
||||
public static ILog log = LogManager.GetLogger("WebApi");
|
||||
}
|
||||
}
|
||||
68
Interface_WebAPI/WebApi/InitServer.cs
Normal file
68
Interface_WebAPI/WebApi/InitServer.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Formatting;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Web.Http;
|
||||
using System.Web.Http.Cors;
|
||||
using System.Web.Http.SelfHost;
|
||||
|
||||
namespace WebApi
|
||||
{
|
||||
|
||||
|
||||
public class InitServer
|
||||
{
|
||||
HttpSelfHostConfiguration config = null;
|
||||
HttpSelfHostServer server = null;
|
||||
public InitServer(string Url_WebApi)
|
||||
{
|
||||
// var Url_WebApi = System.Configuration.ConfigurationManager.AppSettings["Url_WebApi"];
|
||||
Init(Url_WebApi);
|
||||
}
|
||||
public void Init(string url)
|
||||
{
|
||||
config = new HttpSelfHostConfiguration(url);
|
||||
|
||||
// 启用跨域
|
||||
config.EnableCors(new EnableCorsAttribute("*", "*", "*"));
|
||||
// 启用特性路由
|
||||
config.MapHttpAttributeRoutes();
|
||||
|
||||
//config.Routes.MapHttpRoute(
|
||||
// name: "DefaultApi",
|
||||
// routeTemplate: "api/{controller}/{id}",
|
||||
// defaults: new { id = RouteParameter.Optional }
|
||||
//);
|
||||
|
||||
// 自定义路由匹配到action
|
||||
config.Routes.MapHttpRoute(
|
||||
name: "API Default",
|
||||
routeTemplate: "api/{controller}/{action}/{id}",
|
||||
defaults: new { id = RouteParameter.Optional }
|
||||
);
|
||||
|
||||
|
||||
|
||||
server = new HttpSelfHostServer(config);
|
||||
|
||||
server.OpenAsync().Wait();
|
||||
|
||||
|
||||
}
|
||||
public class JsonContentNegotiator : IContentNegotiator
|
||||
{
|
||||
private readonly JsonMediaTypeFormatter _jsonFormatter;
|
||||
|
||||
public JsonContentNegotiator(JsonMediaTypeFormatter formatter)
|
||||
{
|
||||
_jsonFormatter = formatter;
|
||||
}
|
||||
public ContentNegotiationResult Negotiate(Type type, HttpRequestMessage request, IEnumerable<MediaTypeFormatter> formatters)
|
||||
{
|
||||
var result = new ContentNegotiationResult(_jsonFormatter, new MediaTypeHeaderValue("application/json"));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
82
Interface_WebAPI/WebApi/Program.cs
Normal file
82
Interface_WebAPI/WebApi/Program.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using DatabaseClient;
|
||||
|
||||
|
||||
namespace WebApi
|
||||
{
|
||||
|
||||
internal class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
|
||||
// CallDbFactoryTest();
|
||||
|
||||
#region DBConfig
|
||||
var DatabaseType = System.Configuration.ConfigurationManager.AppSettings["DatabaseType"];
|
||||
var connString = "";
|
||||
switch (DatabaseType.ToLower())
|
||||
{
|
||||
case "mysql":
|
||||
{
|
||||
connString = System.Configuration.ConfigurationManager.AppSettings["MysqlConnectString"];
|
||||
break;
|
||||
}
|
||||
case "mssql":
|
||||
{
|
||||
connString = System.Configuration.ConfigurationManager.AppSettings["MssqlConnectString"];
|
||||
break;
|
||||
}
|
||||
case "sqlite":
|
||||
{
|
||||
connString = System.Configuration.ConfigurationManager.AppSettings["SqliteConnectString"];
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
connString = System.Configuration.ConfigurationManager.AppSettings["MysqlConnectString"];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
GlobalVar.dbClient = new DBClientFactory(DatabaseType).Create();
|
||||
GlobalVar.dbClient.Connect(connString);
|
||||
#endregion
|
||||
|
||||
var WebApiUrl = System.Configuration.ConfigurationManager.AppSettings["WebApiUrl"];
|
||||
new InitServer(WebApiUrl);
|
||||
|
||||
|
||||
//GlobalVar.log.Error("错误", new Exception("发生了一个异常"));//错误
|
||||
//GlobalVar.log.Fatal("严重错误", new Exception("发生了一个致命错误"));//严重错误
|
||||
//GlobalVar.log.Info("信息"); //记录一般信息
|
||||
//GlobalVar.log.Debug("调试信息");//记录调试信息
|
||||
//GlobalVar.log.Warn("警告");//记录警告信息
|
||||
|
||||
|
||||
GlobalVar.log.Info("Start WebApi server..."); //记录一般信息
|
||||
GlobalVar.log.Info("<URL> " + WebApiUrl); //记录一般信息
|
||||
// Console.WriteLine("Start WebApi server...");
|
||||
// Console.WriteLine("<URL> " + WebApiUrl);
|
||||
|
||||
Console.ReadKey();
|
||||
}
|
||||
|
||||
static void CallDbFactoryTest()
|
||||
{
|
||||
DBClientFactory factory = new DBClientFactory("Mysql");
|
||||
// 只需切换 MySqlDatabaseFactory 就可切换数据库
|
||||
var mySqlClient = factory.Create();
|
||||
|
||||
|
||||
// MySqlClient sqlClient = new MySqlClient();
|
||||
mySqlClient.Connect("server=localhost;database=mytest;username=root;password=123456;");
|
||||
var ds = mySqlClient.ExecQuery("select * from Z_Save_Position");
|
||||
var zSavePositionList = Z_Save_Position.DataTableToClass(ds);
|
||||
}
|
||||
}
|
||||
}
|
||||
39
Interface_WebAPI/WebApi/Properties/AssemblyInfo.cs
Normal file
39
Interface_WebAPI/WebApi/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("WebApi")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("WebApi")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2022")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("5c6e31a8-8b45-4459-ba62-07af6135df4a")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
|
||||
// 指定log4net 的配置文件
|
||||
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]
|
||||
75
Interface_WebAPI/WebApi/Properties/app.manifest
Normal file
75
Interface_WebAPI/WebApi/Properties/app.manifest
Normal file
@@ -0,0 +1,75 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<assemblyIdentity version="1.0.0.0" name="MyApplication.app" />
|
||||
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
|
||||
<security>
|
||||
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
|
||||
<!-- UAC Manifest Options
|
||||
If you want to change the Windows User Account Control level replace the
|
||||
requestedExecutionLevel node with one of the following.
|
||||
|
||||
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
|
||||
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
|
||||
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
|
||||
|
||||
Specifying requestedExecutionLevel element will disable file and registry virtualization.
|
||||
Remove this element if your application requires this virtualization for backwards
|
||||
compatibility.
|
||||
-->
|
||||
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
|
||||
|
||||
<!--<requestedExecutionLevel level="asInvoker" uiAccess="false" />-->
|
||||
</requestedPrivileges>
|
||||
<applicationRequestMinimum>
|
||||
<defaultAssemblyRequest permissionSetReference="Custom" />
|
||||
<PermissionSet class="System.Security.PermissionSet" version="1" Unrestricted="true" ID="Custom" SameSite="site" />
|
||||
</applicationRequestMinimum>
|
||||
</security>
|
||||
</trustInfo>
|
||||
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
|
||||
<application>
|
||||
<!-- A list of the Windows versions that this application has been tested on
|
||||
and is designed to work with. Uncomment the appropriate elements
|
||||
and Windows will automatically select the most compatible environment. -->
|
||||
<!-- Windows Vista -->
|
||||
<!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />-->
|
||||
<!-- Windows 7 -->
|
||||
<!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />-->
|
||||
<!-- Windows 8 -->
|
||||
<!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />-->
|
||||
<!-- Windows 8.1 -->
|
||||
<!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />-->
|
||||
<!-- Windows 10 -->
|
||||
<!--<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />-->
|
||||
</application>
|
||||
</compatibility>
|
||||
<!-- Indicates that the application is DPI-aware and will not be automatically scaled by Windows at higher
|
||||
DPIs. Windows Presentation Foundation (WPF) applications are automatically DPI-aware and do not need
|
||||
to opt in. Windows Forms applications targeting .NET Framework 4.6 that opt into this setting, should
|
||||
also set the 'EnableWindowsFormsHighDpiAutoResizing' setting to 'true' in their app.config.
|
||||
|
||||
Makes the application long-path aware. See https://docs.microsoft.com/windows/win32/fileio/maximum-file-path-limitation -->
|
||||
<!--
|
||||
<application xmlns="urn:schemas-microsoft-com:asm.v3">
|
||||
<windowsSettings>
|
||||
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
|
||||
<longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>
|
||||
</windowsSettings>
|
||||
</application>
|
||||
-->
|
||||
<!-- Enable themes for Windows common controls and dialogs (Windows XP and later) -->
|
||||
<!--
|
||||
<dependency>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity
|
||||
type="win32"
|
||||
name="Microsoft.Windows.Common-Controls"
|
||||
version="6.0.0.0"
|
||||
processorArchitecture="*"
|
||||
publicKeyToken="6595b64144ccf1df"
|
||||
language="*"
|
||||
/>
|
||||
</dependentAssembly>
|
||||
</dependency>
|
||||
-->
|
||||
</assembly>
|
||||
40
Interface_WebAPI/WebApi/Z_Save_Position.cs
Normal file
40
Interface_WebAPI/WebApi/Z_Save_Position.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using System.Data;
|
||||
|
||||
namespace WebApi
|
||||
{
|
||||
class Z_Save_Position
|
||||
{
|
||||
public int ID;
|
||||
public string OpName;
|
||||
public string Value;
|
||||
public string OperationTime;
|
||||
public string ProjectCode;
|
||||
|
||||
public Z_Save_Position() { }
|
||||
|
||||
public static List<Z_Save_Position> DataTableToClass(DataTable dt_Z_Save_Position)
|
||||
{
|
||||
List<Z_Save_Position> z_Save_PositionList = new List<Z_Save_Position>();
|
||||
Z_Save_Position z_Save_Position;
|
||||
for (int i = 0; i < dt_Z_Save_Position.Rows.Count; i++)
|
||||
{
|
||||
z_Save_Position = new Z_Save_Position();
|
||||
var row = dt_Z_Save_Position.Rows[i];
|
||||
z_Save_Position.ID = Convert.ToInt32(row["ID"]);
|
||||
z_Save_Position.OpName = row["OpName"].ToString();
|
||||
z_Save_Position.Value = row["Value"].ToString();
|
||||
z_Save_Position.OperationTime = row["OperationTime"].ToString();
|
||||
z_Save_Position.ProjectCode = row["ProjectCode"].ToString();
|
||||
z_Save_PositionList.Add(z_Save_Position);
|
||||
}
|
||||
|
||||
return z_Save_PositionList;
|
||||
}
|
||||
}
|
||||
}
|
||||
46
Interface_WebAPI/WebApi/Z_Save_Tag.cs
Normal file
46
Interface_WebAPI/WebApi/Z_Save_Tag.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WebApi
|
||||
{
|
||||
class Z_Save_Tag
|
||||
{
|
||||
public int ID;
|
||||
public string OpName;
|
||||
public string TagID;
|
||||
public string Value;
|
||||
public string KeepTime;
|
||||
public string OperationTime;
|
||||
public string ProjectCode;
|
||||
public Z_Save_Tag()
|
||||
{
|
||||
|
||||
}
|
||||
public static List<Z_Save_Tag> DataTableToClass(DataTable dt_Z_Save_Tag)
|
||||
{
|
||||
List<Z_Save_Tag> z_Save_TagList = new List<Z_Save_Tag>();
|
||||
Z_Save_Tag z_Save_Tag;
|
||||
for (int i = 0; i < dt_Z_Save_Tag.Rows.Count; i++)
|
||||
{
|
||||
z_Save_Tag = new Z_Save_Tag();
|
||||
|
||||
var row = dt_Z_Save_Tag.Rows[i];
|
||||
z_Save_Tag.ID = Convert.ToInt32(row["ID"]);
|
||||
z_Save_Tag.OpName = row["OpName"].ToString();
|
||||
z_Save_Tag.TagID = row["TagID"].ToString();
|
||||
z_Save_Tag.Value = row["Value"].ToString();
|
||||
z_Save_Tag.KeepTime = row["KeepTime"].ToString();
|
||||
z_Save_Tag.OperationTime = row["OperationTime"].ToString();
|
||||
z_Save_Tag.ProjectCode = row["ProjectCode"].ToString();
|
||||
|
||||
z_Save_TagList.Add(z_Save_Tag);
|
||||
}
|
||||
|
||||
return z_Save_TagList;
|
||||
}
|
||||
}
|
||||
}
|
||||
34
Interface_WebAPI/WebApi/log4net.config
Normal file
34
Interface_WebAPI/WebApi/log4net.config
Normal file
@@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<log4net>
|
||||
<!-- 控制台日志配置 -->
|
||||
<appender name="Console" type="log4net.Appender.ConsoleAppender">
|
||||
<!-- 日志输出格式 -->
|
||||
<layout type="log4net.Layout.PatternLayout">
|
||||
<!--<conversionPattern value="%5level [%thread] (%file:%line) - %message%newline" />-->
|
||||
<conversionPattern value="%date %-5level %thread %logger - %message%newline" />
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<!-- 文件存储日志配置 -->
|
||||
<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
|
||||
<!-- 保存文件的名称 -->
|
||||
<file value="./log/webapi.log" />
|
||||
<appendToFile value="true" />
|
||||
<!-- 文件的编码方式 -->
|
||||
<param name="Encoding" value="UTF-8"/>
|
||||
<!-- 每个文件的大小 -->
|
||||
<maximumFileSize value="100KB" />
|
||||
<!-- 保存文件数量 -->
|
||||
<maxSizeRollBackups value="2" />
|
||||
<!-- 日志输出格式 -->
|
||||
<layout type="log4net.Layout.PatternLayout">
|
||||
<conversionPattern value="%date %-5level %thread %logger - %message%newline" />
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<root>
|
||||
<level value="ALL" />
|
||||
<appender-ref ref="Console" />
|
||||
<appender-ref ref="RollingFile" />
|
||||
</root>
|
||||
</log4net>
|
||||
30
Interface_WebAPI/WebApi/mysql.sql
Normal file
30
Interface_WebAPI/WebApi/mysql.sql
Normal file
@@ -0,0 +1,30 @@
|
||||
CREATE DATABASE mytest;
|
||||
USE mytest;
|
||||
# show databases;
|
||||
# show engines;
|
||||
# show variables like '%character%';
|
||||
|
||||
-- auto-generated definition
|
||||
create table z_save_position
|
||||
(
|
||||
ID int auto_increment
|
||||
primary key,
|
||||
OpName varchar(50) null,
|
||||
Value varchar(200) null,
|
||||
OperationTime datetime null,
|
||||
ProjectCode varchar(50) null
|
||||
)engine = InnoDB;
|
||||
|
||||
|
||||
-- auto-generated definition
|
||||
create table z_save_tag
|
||||
(
|
||||
ID int auto_increment
|
||||
primary key,
|
||||
OpName varchar(50) null,
|
||||
TagID varchar(50) null,
|
||||
Value varchar(200) null,
|
||||
KeepTime varchar(50) null,
|
||||
OperationTime datetime null,
|
||||
ProjectCode varchar(50) null
|
||||
)engine = InnoDB;
|
||||
10
Interface_WebAPI/WebApi/packages.config
Normal file
10
Interface_WebAPI/WebApi/packages.config
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="log4net" version="2.0.14" targetFramework="net461" />
|
||||
<package id="Microsoft.AspNet.Cors" version="5.2.9" targetFramework="net461" />
|
||||
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.9" targetFramework="net461" />
|
||||
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.9" targetFramework="net461" />
|
||||
<package id="Microsoft.AspNet.WebApi.Cors" version="5.2.9" targetFramework="net461" />
|
||||
<package id="Microsoft.AspNet.WebApi.SelfHost" version="5.2.9" targetFramework="net461" />
|
||||
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net461" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user