基线 SVN r240
SVN-Revision: r240
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.34114.132
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AfkDataService", "AfkDataService\AfkDataService.csproj", "{36F96F46-E6C8-4315-A961-E79A4155CFAF}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{36F96F46-E6C8-4315-A961-E79A4155CFAF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{36F96F46-E6C8-4315-A961-E79A4155CFAF}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{36F96F46-E6C8-4315-A961-E79A4155CFAF}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{36F96F46-E6C8-4315-A961-E79A4155CFAF}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {A05F5A23-831E-44AD-8DC3-5B3BB22FF9EA}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,259 @@
|
||||
using MySql.Data.MySqlClient;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AfkDataService
|
||||
{
|
||||
/// <summary>
|
||||
/// 数据传递方向
|
||||
/// </summary>
|
||||
public enum DataDirection : int
|
||||
{
|
||||
LsToAfk = 1,
|
||||
AfkToLs = 0
|
||||
}
|
||||
public class AbutmentModel
|
||||
{
|
||||
/// <summary>
|
||||
/// 同步表当前id
|
||||
/// </summary>
|
||||
public int id;
|
||||
/// <summary>
|
||||
/// 当前数据唯一标识
|
||||
/// </summary>
|
||||
public string uuid;
|
||||
/// <summary>
|
||||
/// 数据传输方向
|
||||
/// </summary>
|
||||
public DataDirection dataDirection;
|
||||
/// <summary>
|
||||
/// 数据源字段解析
|
||||
/// </summary>
|
||||
public string[] targetStrs;
|
||||
/// <summary>
|
||||
/// 同步字段解析
|
||||
/// </summary>
|
||||
public string[] synchroStrs;
|
||||
/// <summary>
|
||||
/// 同步日志表字段解析
|
||||
/// </summary>
|
||||
public string[] synLogStrs;
|
||||
/// <summary>
|
||||
/// 主表和明细表的关联更新字段
|
||||
/// </summary>
|
||||
public string mainDetailCond;
|
||||
/// <summary>
|
||||
/// 双方主键
|
||||
/// </summary>
|
||||
public string[] primaryKeys;
|
||||
#region 中航方相关信息
|
||||
/// <summary>
|
||||
/// 中航方表名
|
||||
/// </summary>
|
||||
public string afkTabName;
|
||||
/// <summary>
|
||||
/// 中航方列名
|
||||
/// </summary>
|
||||
public string afkTargeFields;
|
||||
/// <summary>
|
||||
/// 中航方主键
|
||||
/// </summary>
|
||||
public string afkPrimaryKey;
|
||||
#endregion
|
||||
#region 朗速方相关信息
|
||||
/// <summary>
|
||||
/// 朗速表名
|
||||
/// </summary>
|
||||
public string lsTabName;
|
||||
/// <summary>
|
||||
/// 朗速字段名
|
||||
/// </summary>
|
||||
public string lsTargeFields;
|
||||
/// <summary>
|
||||
/// 朗速主键
|
||||
/// </summary>
|
||||
public string lsPrimaryKey;
|
||||
#endregion
|
||||
#region 日志表相关信息
|
||||
/// <summary>
|
||||
/// 日志表名
|
||||
/// </summary>
|
||||
public string logTabName;
|
||||
/// <summary>
|
||||
/// 日志不同列名
|
||||
/// </summary>
|
||||
public string[] logFields;
|
||||
/// <summary>
|
||||
/// 日志不同列别名
|
||||
/// </summary>
|
||||
public string[] logAsFields;
|
||||
#endregion
|
||||
#region 其他信息
|
||||
/// <summary>
|
||||
/// 是否为批量传递类型
|
||||
/// </summary>
|
||||
public bool isBatch;
|
||||
/// <summary>
|
||||
/// 是否为批量传递基础档案提前类型
|
||||
/// </summary>
|
||||
public bool isBefore;
|
||||
/// <summary>
|
||||
/// 批量传递类型验证sql
|
||||
/// </summary>
|
||||
public string batchAfterSql;
|
||||
/// <summary>
|
||||
/// 执行后aftersql
|
||||
/// </summary>
|
||||
public string afterSql;
|
||||
/// <summary>
|
||||
/// tagid是3或者4,指定字段改变
|
||||
/// </summary>
|
||||
public string disableFieids;
|
||||
/// <summary>
|
||||
/// 朗速字段属性表
|
||||
/// </summary>
|
||||
public DataTable SQLQueryPropertySheet;
|
||||
/// <summary>
|
||||
/// 中航字段属性表
|
||||
/// </summary>
|
||||
public DataTable MYSQLPropertySheet;
|
||||
#endregion
|
||||
/// <summary>
|
||||
/// 数据源where条件
|
||||
/// </summary>
|
||||
public string sourceWhereCond;
|
||||
/// <summary>
|
||||
/// 数据源表名
|
||||
/// </summary>
|
||||
public string sourceTabNale;
|
||||
/// <summary>
|
||||
/// 接受数据表表名
|
||||
/// </summary>
|
||||
public string getSourceTabName;
|
||||
/// <summary>
|
||||
/// 数据源字段
|
||||
/// </summary>
|
||||
public string sourceSelectFields;
|
||||
/// <summary>
|
||||
/// 批量同步到朗速临时表名
|
||||
/// </summary>
|
||||
public string lsTempTabName;
|
||||
/// <summary>
|
||||
/// 数据源字段
|
||||
/// </summary>
|
||||
public DataTable sourceTab;
|
||||
/// <summary>
|
||||
/// 接收到的数据量
|
||||
/// </summary>
|
||||
public int allCount = 0;
|
||||
public AbutmentModel(DataRow _item, DataDirection _dataDirection, string afkDataBase, string sqlHelperConStr, string mySqlHelperConStr)
|
||||
{
|
||||
AfkDataService.MySqlHelper MySqlHelper = new AfkDataService.MySqlHelper(new MySqlConnection(mySqlHelperConStr));
|
||||
AfkDataService.SqlHelper SqlHelper = new AfkDataService.SqlHelper(new SqlConnection(sqlHelperConStr));
|
||||
this.dataDirection = _dataDirection;
|
||||
this.id = Convert.ToInt32(_item["id"] + "");
|
||||
this.targetStrs = (_item["targetTabSql"] + "").ToLower().Split('^');//数据源字段解析
|
||||
this.synchroStrs = (_item["synchroSql"] + "").ToLower().Split('^');//同步字段解析
|
||||
this.synLogStrs = (_item["synLogSql"] + "").ToLower().Split('^');//同步日志表字段解析
|
||||
this.mainDetailCond = (_item["mainDetailCond"] + "").ToLower();//主、明细关联更新
|
||||
|
||||
this.primaryKeys = null;
|
||||
if (this.synchroStrs.Length == 4)
|
||||
{
|
||||
this.primaryKeys = this.synchroStrs[3].Replace(" ", "").Split('=');
|
||||
}
|
||||
#region 中航方相关信息
|
||||
this.afkTabName = this.dataDirection == 0 ? this.targetStrs[0].Replace(" ", "") : this.synchroStrs[0].Replace(" ", "");//表名
|
||||
this.afkTargeFields = this.dataDirection == 0 ? this.synchroStrs[2].Replace(" ", "") : this.synchroStrs[1].Replace(" ", "");//字段名
|
||||
this.afkPrimaryKey = this.dataDirection == 0 ? (this.primaryKeys != null && this.primaryKeys.Length == 2 ? this.primaryKeys[1] : "") : (this.primaryKeys != null && this.primaryKeys.Length == 2 ? this.primaryKeys[0] : "");
|
||||
#endregion
|
||||
#region 朗速方相关信息
|
||||
this.lsTabName = this.dataDirection == 0 ? this.synchroStrs[0].Replace(" ", "") : this.targetStrs[0].Replace(" ", "");
|
||||
this.lsTargeFields = this.dataDirection == 0 ? this.synchroStrs[1].Replace(" ", "") : this.synchroStrs[2].Replace(" ", "");
|
||||
this.lsPrimaryKey = this.dataDirection == 0 ? (this.primaryKeys != null && this.primaryKeys.Length == 2 ? this.primaryKeys[0] : "") : (this.primaryKeys != null && this.primaryKeys.Length == 2 ? this.primaryKeys[1] : "");
|
||||
#endregion
|
||||
#region 日志表相关信息
|
||||
this.logTabName = this.synLogStrs.Length == 3 ? this.synLogStrs[0].Replace(" ", "") : "";
|
||||
this.logFields = this.synLogStrs.Length == 3 ? this.synLogStrs[1].Replace(" ", "").Split(',') : null;
|
||||
this.logAsFields = this.synLogStrs.Length == 3 ? this.synLogStrs[2].Replace(" ", "").Split(',') : null;
|
||||
#endregion
|
||||
#region 其他信息
|
||||
this.lsTempTabName = string.Format("{0}_copy", this.lsTabName);
|
||||
this.isBatch = _item.Table.Columns.Contains("isBatch") ? (_item["isBatch"] + "").Equals("true") : false;
|
||||
this.isBefore = _item.Table.Columns.Contains("isBefore") ? (_item["isBefore"] + "").Equals("true") : false;
|
||||
this.batchAfterSql = _item.Table.Columns.Contains("batchAfterSql") ? _item["batchAfterSql"] + "" : "";
|
||||
this.afterSql = (_item["afterSql"] + "").ToLower();//同步完成后执行的sql
|
||||
this.disableFieids = (_item["disableField"] + "").ToLower();//tagid是3或者4,指定字段改变
|
||||
//数据库属性表
|
||||
//this.SQLQueryPropertySheet = SqlHelper.ExecuteDataTable(string.Format("select COLUMN_NAME,DATA_TYPE,CHARACTER_MAXIMUM_LENGTH,IS_NULLABLE from information_schema.columns where table_name = '{0}'", this.lsTabName));
|
||||
//this.MYSQLPropertySheet = MySqlHelper.ExecuteDataTable(string.Format("show full columns from {0}", this.afkTabName));
|
||||
#endregion
|
||||
string lsExistTagStr = string.Format(@"if not exists(select * from syscolumns
|
||||
where id=object_id('{0}') and name='directTag')
|
||||
begin
|
||||
alter table {0} add directTag int
|
||||
end", this.lsTabName);
|
||||
SqlHelper.ExecuteNonQuery(lsExistTagStr);//判断朗速方是否存在同步完成字段
|
||||
string afkExistTagStr = string.Format(@"select CASE when (select count(1)
|
||||
FROM information_schema.COLUMNS
|
||||
WHERE table_schema = '{0}'
|
||||
and table_name = '{1}'
|
||||
AND column_name = 'isSynchro') > 0
|
||||
then '1'
|
||||
else '2'
|
||||
end
|
||||
", afkDataBase, this.afkTabName);
|
||||
string afkExistResult = MySqlHelper.ExecuteScalar(afkExistTagStr) + "";//判断中航方有无标识列
|
||||
if (afkExistResult.Equals("2"))
|
||||
{
|
||||
string afkAddTagStr = string.Format("alter table {0} add column isSynchro varchar(30);", this.afkTabName); //如果不存在则添加标识列
|
||||
MySqlHelper.ExecuteNonQuery(afkAddTagStr);
|
||||
}
|
||||
if (this.targetStrs.Length == 1)
|
||||
this.sourceWhereCond = this.dataDirection == 0 ? "where isSynchro = '1'" : " where directTag <> 2";//数据源是afk则默认条件字段没有意义,数据源是ls则需获取默认条件字段不为2的数据
|
||||
else
|
||||
this.sourceWhereCond = string.Format(" where {0}", this.dataDirection == 0 ? this.targetStrs[1] + " and isSynchro = '1' " : this.targetStrs[1]);
|
||||
if (dataDirection == 0)//如果是ls获取数据,要先把数据源中当前的符合条件的数据的isSynchro变为1
|
||||
{
|
||||
string conditions = string.Empty;
|
||||
conditions = this.targetStrs.Length == 2 ? " where (isSynchro is null or isSynchro <> '1') and " + this.targetStrs[1] : "";
|
||||
if (!string.IsNullOrEmpty(mainDetailCond))
|
||||
{
|
||||
string sql = string.Format("update {0} set isSynchro = '';", this.afkTabName, mainDetailCond);
|
||||
MySqlHelper.ExecuteNonQuery(sql);
|
||||
sql = string.Format("{0};", mainDetailCond);
|
||||
MySqlHelper.ExecuteNonQuery(sql);
|
||||
}
|
||||
else
|
||||
{
|
||||
string sql = string.Format("update {0} set isSynchro = '1' {1};", this.afkTabName, conditions);
|
||||
MySqlHelper.ExecuteNonQuery(sql);
|
||||
}
|
||||
}
|
||||
#region 获取数据源
|
||||
this.sourceTabNale = this.dataDirection == 0 ? this.afkTabName : this.lsTabName;//数据源表名
|
||||
this.getSourceTabName = this.dataDirection == 0 ? this.lsTabName : this.afkTabName;//接受数据表表名
|
||||
this.sourceSelectFields = this.dataDirection == 0 ? this.afkTargeFields : this.lsTargeFields;//数据源字段
|
||||
//if (this.sourceSelectFields.Contains("getdate()"))//处理各种特殊字段
|
||||
// this.sourceSelectFields = this.sourceSelectFields.Replace("getdate()", this.dataDirection == 0 ? "now() as as_senddate" : "getdate() as as_senddate");
|
||||
if (this.sourceSelectFields.Contains("#add$_"))
|
||||
this.sourceSelectFields = this.sourceSelectFields.Replace("#add$_", "");
|
||||
if (dataDirection == 0)//同步到ls添加uuid唯一标识字段
|
||||
{
|
||||
sourceSelectFields += $",'{uuid}' as uuid";
|
||||
}
|
||||
string selectSourceSql = string.Format("select {0} from {1}{2}", sourceSelectFields, sourceTabNale, sourceWhereCond);//查询数据源sql
|
||||
//this.sourceTab = this.dataDirection == 0 ? MySqlHelper.ExecuteDataTable(selectSourceSql) : SqlHelper.ExecuteDataTable(selectSourceSql);//获取数据源
|
||||
//if (!this.sourceTab.Columns.Contains("suuid"))
|
||||
//{
|
||||
// this.sourceTab.Columns.Add("suuid");
|
||||
//}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
<?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>{36F96F46-E6C8-4315-A961-E79A4155CFAF}</ProjectGuid>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<RootNamespace>AfkDataService</RootNamespace>
|
||||
<AssemblyName>AfkDataService</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<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>
|
||||
<ApplicationIcon>erp.ico</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="DevExpress.Data.v15.2, Version=15.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
|
||||
<Reference Include="DevExpress.Printing.v15.2.Core, Version=15.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
|
||||
<Reference Include="DevExpress.Sparkline.v15.2.Core, Version=15.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
|
||||
<Reference Include="DevExpress.Utils.v15.2, Version=15.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
|
||||
<Reference Include="DevExpress.XtraEditors.v15.2, Version=15.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL" />
|
||||
<Reference Include="Lskj.Control">
|
||||
<HintPath>dll\Lskj.Control.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Lskj.Core">
|
||||
<HintPath>dll\Lskj.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Lskj.Data">
|
||||
<HintPath>dll\Lskj.Data.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Lskj.Util">
|
||||
<HintPath>dll\Lskj.Util.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MySql.Data, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>dll\MySql.Data.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MySqlConnector, Version=2.0.0.0, Culture=neutral, PublicKeyToken=d33d3e53aa5f8c92, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\MySqlConnector.2.2.7\lib\net461\MySqlConnector.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Data.Linq" />
|
||||
<Reference Include="System.Diagnostics.DiagnosticSource, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Diagnostics.DiagnosticSource.6.0.0\lib\net461\System.Diagnostics.DiagnosticSource.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Memory, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Numerics" />
|
||||
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Transactions" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Deployment" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AbutmentModel.cs" />
|
||||
<Compile Include="FrmMain.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="FrmMain.Designer.cs">
|
||||
<DependentUpon>FrmMain.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="IniHelper.cs" />
|
||||
<Compile Include="MySqlHelper.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="SqlHelper.cs" />
|
||||
<Compile Include="SynchData.cs" />
|
||||
<EmbeddedResource Include="FrmMain.resx">
|
||||
<DependentUpon>FrmMain.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
<SubType>Designer</SubType>
|
||||
</EmbeddedResource>
|
||||
<Compile Include="Properties\Resources.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
<DesignTime>True</DesignTime>
|
||||
</Compile>
|
||||
<None Include="packages.config" />
|
||||
<None Include="Properties\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||
</None>
|
||||
<Compile Include="Properties\Settings.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="erp.ico" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
|
||||
</startup>
|
||||
<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-6.0.0.0" newVersion="6.0.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.1.2" newVersion="4.0.1.2" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
</configuration>
|
||||
+495
@@ -0,0 +1,495 @@
|
||||
|
||||
namespace AfkDataService
|
||||
{
|
||||
partial class FrmMain
|
||||
{
|
||||
/// <summary>
|
||||
/// 必需的设计器变量。
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// 清理所有正在使用的资源。
|
||||
/// </summary>
|
||||
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows 窗体设计器生成的代码
|
||||
|
||||
/// <summary>
|
||||
/// 设计器支持所需的方法 - 不要修改
|
||||
/// 使用代码编辑器修改此方法的内容。
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.tabMain = new DevExpress.XtraTab.XtraTabControl();
|
||||
this.dataMainPage = new DevExpress.XtraTab.XtraTabPage();
|
||||
this.MsgPanel = new System.Windows.Forms.Panel();
|
||||
this.connectInfoPanel = new System.Windows.Forms.Panel();
|
||||
this.panel1 = new System.Windows.Forms.Panel();
|
||||
this.startPanel = new System.Windows.Forms.Panel();
|
||||
this.startBtn = new DevExpress.XtraEditors.SimpleButton();
|
||||
this.label10 = new System.Windows.Forms.Label();
|
||||
this.intervalTime = new System.Windows.Forms.TextBox();
|
||||
this.label11 = new System.Windows.Forms.Label();
|
||||
this.groupBox1 = new System.Windows.Forms.GroupBox();
|
||||
this.afkPortNumber = new System.Windows.Forms.TextBox();
|
||||
this.label9 = new System.Windows.Forms.Label();
|
||||
this.afkName = new System.Windows.Forms.TextBox();
|
||||
this.label3 = new System.Windows.Forms.Label();
|
||||
this.afkDataBase = new System.Windows.Forms.TextBox();
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.afkPassword = new System.Windows.Forms.TextBox();
|
||||
this.afkSeverId = new System.Windows.Forms.TextBox();
|
||||
this.label4 = new System.Windows.Forms.Label();
|
||||
this.label2 = new System.Windows.Forms.Label();
|
||||
this.groupBox2 = new System.Windows.Forms.GroupBox();
|
||||
this.lsName = new System.Windows.Forms.TextBox();
|
||||
this.lsSeverId = new System.Windows.Forms.TextBox();
|
||||
this.label5 = new System.Windows.Forms.Label();
|
||||
this.label8 = new System.Windows.Forms.Label();
|
||||
this.lsDataBase = new System.Windows.Forms.TextBox();
|
||||
this.label7 = new System.Windows.Forms.Label();
|
||||
this.label6 = new System.Windows.Forms.Label();
|
||||
this.lsPassword = new System.Windows.Forms.TextBox();
|
||||
this.splitContainer = new System.Windows.Forms.SplitContainer();
|
||||
this.toLsTextBox = new System.Windows.Forms.TextBox();
|
||||
this.toAfkTextBox = new System.Windows.Forms.TextBox();
|
||||
((System.ComponentModel.ISupportInitialize)(this.tabMain)).BeginInit();
|
||||
this.tabMain.SuspendLayout();
|
||||
this.dataMainPage.SuspendLayout();
|
||||
this.MsgPanel.SuspendLayout();
|
||||
this.connectInfoPanel.SuspendLayout();
|
||||
this.panel1.SuspendLayout();
|
||||
this.startPanel.SuspendLayout();
|
||||
this.groupBox1.SuspendLayout();
|
||||
this.groupBox2.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit();
|
||||
this.splitContainer.Panel1.SuspendLayout();
|
||||
this.splitContainer.Panel2.SuspendLayout();
|
||||
this.splitContainer.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// tabMain
|
||||
//
|
||||
this.tabMain.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.tabMain.Location = new System.Drawing.Point(0, 0);
|
||||
this.tabMain.Name = "tabMain";
|
||||
this.tabMain.SelectedTabPage = this.dataMainPage;
|
||||
this.tabMain.Size = new System.Drawing.Size(861, 711);
|
||||
this.tabMain.TabIndex = 0;
|
||||
this.tabMain.TabPages.AddRange(new DevExpress.XtraTab.XtraTabPage[] {
|
||||
this.dataMainPage});
|
||||
//
|
||||
// dataMainPage
|
||||
//
|
||||
this.dataMainPage.Controls.Add(this.MsgPanel);
|
||||
this.dataMainPage.Controls.Add(this.connectInfoPanel);
|
||||
this.dataMainPage.Name = "dataMainPage";
|
||||
this.dataMainPage.Size = new System.Drawing.Size(854, 675);
|
||||
this.dataMainPage.Text = "数据对接";
|
||||
//
|
||||
// MsgPanel
|
||||
//
|
||||
this.MsgPanel.Controls.Add(this.splitContainer);
|
||||
this.MsgPanel.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.MsgPanel.Location = new System.Drawing.Point(0, 229);
|
||||
this.MsgPanel.Name = "MsgPanel";
|
||||
this.MsgPanel.Size = new System.Drawing.Size(854, 446);
|
||||
this.MsgPanel.TabIndex = 1;
|
||||
//
|
||||
// connectInfoPanel
|
||||
//
|
||||
this.connectInfoPanel.Controls.Add(this.groupBox2);
|
||||
this.connectInfoPanel.Controls.Add(this.panel1);
|
||||
this.connectInfoPanel.Controls.Add(this.groupBox1);
|
||||
this.connectInfoPanel.Dock = System.Windows.Forms.DockStyle.Top;
|
||||
this.connectInfoPanel.Location = new System.Drawing.Point(0, 0);
|
||||
this.connectInfoPanel.Name = "connectInfoPanel";
|
||||
this.connectInfoPanel.Size = new System.Drawing.Size(854, 229);
|
||||
this.connectInfoPanel.TabIndex = 0;
|
||||
//
|
||||
// panel1
|
||||
//
|
||||
this.panel1.Controls.Add(this.startPanel);
|
||||
this.panel1.Controls.Add(this.label10);
|
||||
this.panel1.Controls.Add(this.intervalTime);
|
||||
this.panel1.Controls.Add(this.label11);
|
||||
this.panel1.Dock = System.Windows.Forms.DockStyle.Right;
|
||||
this.panel1.Location = new System.Drawing.Point(632, 0);
|
||||
this.panel1.Name = "panel1";
|
||||
this.panel1.Size = new System.Drawing.Size(222, 229);
|
||||
this.panel1.TabIndex = 25;
|
||||
//
|
||||
// startPanel
|
||||
//
|
||||
this.startPanel.Controls.Add(this.startBtn);
|
||||
this.startPanel.Dock = System.Windows.Forms.DockStyle.Bottom;
|
||||
this.startPanel.Location = new System.Drawing.Point(0, 174);
|
||||
this.startPanel.Margin = new System.Windows.Forms.Padding(4);
|
||||
this.startPanel.Name = "startPanel";
|
||||
this.startPanel.Size = new System.Drawing.Size(222, 55);
|
||||
this.startPanel.TabIndex = 19;
|
||||
//
|
||||
// startBtn
|
||||
//
|
||||
this.startBtn.Appearance.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(52)))), ((int)(((byte)(142)))), ((int)(((byte)(216)))));
|
||||
this.startBtn.Appearance.ForeColor = System.Drawing.Color.White;
|
||||
this.startBtn.Appearance.Options.UseBackColor = true;
|
||||
this.startBtn.Appearance.Options.UseForeColor = true;
|
||||
this.startBtn.ButtonStyle = DevExpress.XtraEditors.Controls.BorderStyles.Simple;
|
||||
this.startBtn.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.startBtn.Location = new System.Drawing.Point(0, 0);
|
||||
this.startBtn.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.startBtn.Name = "startBtn";
|
||||
this.startBtn.Size = new System.Drawing.Size(222, 55);
|
||||
this.startBtn.TabIndex = 5;
|
||||
this.startBtn.Text = "开始同步";
|
||||
//
|
||||
// label10
|
||||
//
|
||||
this.label10.Location = new System.Drawing.Point(125, 25);
|
||||
this.label10.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||
this.label10.Name = "label10";
|
||||
this.label10.Size = new System.Drawing.Size(100, 26);
|
||||
this.label10.TabIndex = 18;
|
||||
this.label10.Text = "秒(最短30秒)";
|
||||
this.label10.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
//
|
||||
// intervalTime
|
||||
//
|
||||
this.intervalTime.Location = new System.Drawing.Point(70, 27);
|
||||
this.intervalTime.Margin = new System.Windows.Forms.Padding(4);
|
||||
this.intervalTime.Name = "intervalTime";
|
||||
this.intervalTime.Size = new System.Drawing.Size(51, 26);
|
||||
this.intervalTime.TabIndex = 17;
|
||||
//
|
||||
// label11
|
||||
//
|
||||
this.label11.AutoSize = true;
|
||||
this.label11.Location = new System.Drawing.Point(7, 30);
|
||||
this.label11.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||
this.label11.Name = "label11";
|
||||
this.label11.Size = new System.Drawing.Size(68, 18);
|
||||
this.label11.TabIndex = 16;
|
||||
this.label11.Text = "间隔时间";
|
||||
this.label11.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
//
|
||||
// groupBox1
|
||||
//
|
||||
this.groupBox1.Controls.Add(this.afkPortNumber);
|
||||
this.groupBox1.Controls.Add(this.label9);
|
||||
this.groupBox1.Controls.Add(this.afkName);
|
||||
this.groupBox1.Controls.Add(this.label3);
|
||||
this.groupBox1.Controls.Add(this.afkDataBase);
|
||||
this.groupBox1.Controls.Add(this.label1);
|
||||
this.groupBox1.Controls.Add(this.afkPassword);
|
||||
this.groupBox1.Controls.Add(this.afkSeverId);
|
||||
this.groupBox1.Controls.Add(this.label4);
|
||||
this.groupBox1.Controls.Add(this.label2);
|
||||
this.groupBox1.Dock = System.Windows.Forms.DockStyle.Left;
|
||||
this.groupBox1.Location = new System.Drawing.Point(0, 0);
|
||||
this.groupBox1.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.groupBox1.Name = "groupBox1";
|
||||
this.groupBox1.Padding = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.groupBox1.Size = new System.Drawing.Size(317, 229);
|
||||
this.groupBox1.TabIndex = 1;
|
||||
this.groupBox1.TabStop = false;
|
||||
this.groupBox1.Text = "AFk地址";
|
||||
//
|
||||
// afkPortNumber
|
||||
//
|
||||
this.afkPortNumber.Location = new System.Drawing.Point(115, 65);
|
||||
this.afkPortNumber.Margin = new System.Windows.Forms.Padding(4);
|
||||
this.afkPortNumber.Name = "afkPortNumber";
|
||||
this.afkPortNumber.Size = new System.Drawing.Size(180, 26);
|
||||
this.afkPortNumber.TabIndex = 18;
|
||||
//
|
||||
// label9
|
||||
//
|
||||
this.label9.Location = new System.Drawing.Point(7, 64);
|
||||
this.label9.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||
this.label9.Name = "label9";
|
||||
this.label9.Size = new System.Drawing.Size(100, 26);
|
||||
this.label9.TabIndex = 17;
|
||||
this.label9.Text = "端 口 号";
|
||||
this.label9.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
//
|
||||
// afkName
|
||||
//
|
||||
this.afkName.Location = new System.Drawing.Point(115, 145);
|
||||
this.afkName.Margin = new System.Windows.Forms.Padding(4);
|
||||
this.afkName.Name = "afkName";
|
||||
this.afkName.Size = new System.Drawing.Size(180, 26);
|
||||
this.afkName.TabIndex = 16;
|
||||
//
|
||||
// label3
|
||||
//
|
||||
this.label3.Location = new System.Drawing.Point(7, 145);
|
||||
this.label3.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||
this.label3.Name = "label3";
|
||||
this.label3.Size = new System.Drawing.Size(100, 26);
|
||||
this.label3.TabIndex = 11;
|
||||
this.label3.Text = "登 录 名 称";
|
||||
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
//
|
||||
// afkDataBase
|
||||
//
|
||||
this.afkDataBase.Location = new System.Drawing.Point(115, 105);
|
||||
this.afkDataBase.Margin = new System.Windows.Forms.Padding(4);
|
||||
this.afkDataBase.Name = "afkDataBase";
|
||||
this.afkDataBase.Size = new System.Drawing.Size(180, 26);
|
||||
this.afkDataBase.TabIndex = 15;
|
||||
//
|
||||
// label1
|
||||
//
|
||||
this.label1.Location = new System.Drawing.Point(7, 24);
|
||||
this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(100, 26);
|
||||
this.label1.TabIndex = 9;
|
||||
this.label1.Text = "服务器地址";
|
||||
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
//
|
||||
// afkPassword
|
||||
//
|
||||
this.afkPassword.Location = new System.Drawing.Point(115, 185);
|
||||
this.afkPassword.Margin = new System.Windows.Forms.Padding(4);
|
||||
this.afkPassword.Name = "afkPassword";
|
||||
this.afkPassword.PasswordChar = '*';
|
||||
this.afkPassword.Size = new System.Drawing.Size(180, 26);
|
||||
this.afkPassword.TabIndex = 14;
|
||||
//
|
||||
// afkSeverId
|
||||
//
|
||||
this.afkSeverId.Location = new System.Drawing.Point(115, 25);
|
||||
this.afkSeverId.Margin = new System.Windows.Forms.Padding(4);
|
||||
this.afkSeverId.Name = "afkSeverId";
|
||||
this.afkSeverId.Size = new System.Drawing.Size(180, 26);
|
||||
this.afkSeverId.TabIndex = 13;
|
||||
//
|
||||
// label4
|
||||
//
|
||||
this.label4.Location = new System.Drawing.Point(7, 104);
|
||||
this.label4.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||
this.label4.Name = "label4";
|
||||
this.label4.Size = new System.Drawing.Size(100, 26);
|
||||
this.label4.TabIndex = 12;
|
||||
this.label4.Text = " 数 据 库 ";
|
||||
this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
//
|
||||
// label2
|
||||
//
|
||||
this.label2.Location = new System.Drawing.Point(7, 184);
|
||||
this.label2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||
this.label2.Name = "label2";
|
||||
this.label2.Size = new System.Drawing.Size(100, 26);
|
||||
this.label2.TabIndex = 10;
|
||||
this.label2.Text = "登 录 密 码";
|
||||
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
//
|
||||
// groupBox2
|
||||
//
|
||||
this.groupBox2.Controls.Add(this.lsName);
|
||||
this.groupBox2.Controls.Add(this.lsSeverId);
|
||||
this.groupBox2.Controls.Add(this.label5);
|
||||
this.groupBox2.Controls.Add(this.label8);
|
||||
this.groupBox2.Controls.Add(this.lsDataBase);
|
||||
this.groupBox2.Controls.Add(this.label7);
|
||||
this.groupBox2.Controls.Add(this.label6);
|
||||
this.groupBox2.Controls.Add(this.lsPassword);
|
||||
this.groupBox2.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.groupBox2.Location = new System.Drawing.Point(317, 0);
|
||||
this.groupBox2.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.groupBox2.Name = "groupBox2";
|
||||
this.groupBox2.Padding = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.groupBox2.Size = new System.Drawing.Size(315, 229);
|
||||
this.groupBox2.TabIndex = 26;
|
||||
this.groupBox2.TabStop = false;
|
||||
this.groupBox2.Text = "朗速地址";
|
||||
//
|
||||
// lsName
|
||||
//
|
||||
this.lsName.Location = new System.Drawing.Point(115, 104);
|
||||
this.lsName.Margin = new System.Windows.Forms.Padding(4);
|
||||
this.lsName.Name = "lsName";
|
||||
this.lsName.Size = new System.Drawing.Size(180, 26);
|
||||
this.lsName.TabIndex = 24;
|
||||
//
|
||||
// lsSeverId
|
||||
//
|
||||
this.lsSeverId.Location = new System.Drawing.Point(115, 24);
|
||||
this.lsSeverId.Margin = new System.Windows.Forms.Padding(4);
|
||||
this.lsSeverId.Name = "lsSeverId";
|
||||
this.lsSeverId.Size = new System.Drawing.Size(180, 26);
|
||||
this.lsSeverId.TabIndex = 21;
|
||||
//
|
||||
// label5
|
||||
//
|
||||
this.label5.Location = new System.Drawing.Point(7, 104);
|
||||
this.label5.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||
this.label5.Name = "label5";
|
||||
this.label5.Size = new System.Drawing.Size(100, 26);
|
||||
this.label5.TabIndex = 19;
|
||||
this.label5.Text = "登 录 名 称";
|
||||
this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
//
|
||||
// label8
|
||||
//
|
||||
this.label8.Location = new System.Drawing.Point(7, 145);
|
||||
this.label8.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||
this.label8.Name = "label8";
|
||||
this.label8.Size = new System.Drawing.Size(100, 26);
|
||||
this.label8.TabIndex = 18;
|
||||
this.label8.Text = "登 录 密 码";
|
||||
this.label8.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
//
|
||||
// lsDataBase
|
||||
//
|
||||
this.lsDataBase.Location = new System.Drawing.Point(115, 64);
|
||||
this.lsDataBase.Margin = new System.Windows.Forms.Padding(4);
|
||||
this.lsDataBase.Name = "lsDataBase";
|
||||
this.lsDataBase.Size = new System.Drawing.Size(180, 26);
|
||||
this.lsDataBase.TabIndex = 23;
|
||||
//
|
||||
// label7
|
||||
//
|
||||
this.label7.Location = new System.Drawing.Point(7, 65);
|
||||
this.label7.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||
this.label7.Name = "label7";
|
||||
this.label7.Size = new System.Drawing.Size(100, 26);
|
||||
this.label7.TabIndex = 20;
|
||||
this.label7.Text = " 数 据 库 ";
|
||||
this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
//
|
||||
// label6
|
||||
//
|
||||
this.label6.Location = new System.Drawing.Point(7, 25);
|
||||
this.label6.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||
this.label6.Name = "label6";
|
||||
this.label6.Size = new System.Drawing.Size(100, 26);
|
||||
this.label6.TabIndex = 17;
|
||||
this.label6.Text = "服务器地址";
|
||||
this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
//
|
||||
// lsPassword
|
||||
//
|
||||
this.lsPassword.Location = new System.Drawing.Point(115, 145);
|
||||
this.lsPassword.Margin = new System.Windows.Forms.Padding(4);
|
||||
this.lsPassword.Name = "lsPassword";
|
||||
this.lsPassword.PasswordChar = '*';
|
||||
this.lsPassword.Size = new System.Drawing.Size(180, 26);
|
||||
this.lsPassword.TabIndex = 22;
|
||||
//
|
||||
// splitContainer
|
||||
//
|
||||
this.splitContainer.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.splitContainer.Location = new System.Drawing.Point(0, 0);
|
||||
this.splitContainer.Name = "splitContainer";
|
||||
//
|
||||
// splitContainer.Panel1
|
||||
//
|
||||
this.splitContainer.Panel1.Controls.Add(this.toLsTextBox);
|
||||
//
|
||||
// splitContainer.Panel2
|
||||
//
|
||||
this.splitContainer.Panel2.Controls.Add(this.toAfkTextBox);
|
||||
this.splitContainer.Size = new System.Drawing.Size(854, 446);
|
||||
this.splitContainer.SplitterDistance = 464;
|
||||
this.splitContainer.TabIndex = 0;
|
||||
//
|
||||
// toLsTextBox
|
||||
//
|
||||
this.toLsTextBox.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.toLsTextBox.Location = new System.Drawing.Point(0, 0);
|
||||
this.toLsTextBox.Multiline = true;
|
||||
this.toLsTextBox.Name = "toLsTextBox";
|
||||
this.toLsTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
|
||||
this.toLsTextBox.Size = new System.Drawing.Size(464, 446);
|
||||
this.toLsTextBox.TabIndex = 2;
|
||||
//
|
||||
// toAfkTextBox
|
||||
//
|
||||
this.toAfkTextBox.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.toAfkTextBox.Location = new System.Drawing.Point(0, 0);
|
||||
this.toAfkTextBox.Multiline = true;
|
||||
this.toAfkTextBox.Name = "toAfkTextBox";
|
||||
this.toAfkTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
|
||||
this.toAfkTextBox.Size = new System.Drawing.Size(386, 446);
|
||||
this.toAfkTextBox.TabIndex = 3;
|
||||
//
|
||||
// FrmMain
|
||||
//
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
|
||||
this.ClientSize = new System.Drawing.Size(861, 711);
|
||||
this.Controls.Add(this.tabMain);
|
||||
this.Name = "FrmMain";
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||
this.Text = "中航数据对接";
|
||||
((System.ComponentModel.ISupportInitialize)(this.tabMain)).EndInit();
|
||||
this.tabMain.ResumeLayout(false);
|
||||
this.dataMainPage.ResumeLayout(false);
|
||||
this.MsgPanel.ResumeLayout(false);
|
||||
this.connectInfoPanel.ResumeLayout(false);
|
||||
this.panel1.ResumeLayout(false);
|
||||
this.panel1.PerformLayout();
|
||||
this.startPanel.ResumeLayout(false);
|
||||
this.groupBox1.ResumeLayout(false);
|
||||
this.groupBox1.PerformLayout();
|
||||
this.groupBox2.ResumeLayout(false);
|
||||
this.groupBox2.PerformLayout();
|
||||
this.splitContainer.Panel1.ResumeLayout(false);
|
||||
this.splitContainer.Panel1.PerformLayout();
|
||||
this.splitContainer.Panel2.ResumeLayout(false);
|
||||
this.splitContainer.Panel2.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.splitContainer)).EndInit();
|
||||
this.splitContainer.ResumeLayout(false);
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private DevExpress.XtraTab.XtraTabControl tabMain;
|
||||
private DevExpress.XtraTab.XtraTabPage dataMainPage;
|
||||
private System.Windows.Forms.Panel connectInfoPanel;
|
||||
private System.Windows.Forms.Panel MsgPanel;
|
||||
private System.Windows.Forms.Panel panel1;
|
||||
private System.Windows.Forms.Panel startPanel;
|
||||
private DevExpress.XtraEditors.SimpleButton startBtn;
|
||||
private System.Windows.Forms.Label label10;
|
||||
private System.Windows.Forms.TextBox intervalTime;
|
||||
private System.Windows.Forms.Label label11;
|
||||
private System.Windows.Forms.GroupBox groupBox1;
|
||||
private System.Windows.Forms.TextBox afkPortNumber;
|
||||
private System.Windows.Forms.Label label9;
|
||||
private System.Windows.Forms.TextBox afkName;
|
||||
private System.Windows.Forms.Label label3;
|
||||
private System.Windows.Forms.TextBox afkDataBase;
|
||||
private System.Windows.Forms.Label label1;
|
||||
private System.Windows.Forms.TextBox afkPassword;
|
||||
private System.Windows.Forms.TextBox afkSeverId;
|
||||
private System.Windows.Forms.Label label4;
|
||||
private System.Windows.Forms.Label label2;
|
||||
private System.Windows.Forms.GroupBox groupBox2;
|
||||
private System.Windows.Forms.TextBox lsName;
|
||||
private System.Windows.Forms.TextBox lsSeverId;
|
||||
private System.Windows.Forms.Label label5;
|
||||
private System.Windows.Forms.Label label8;
|
||||
private System.Windows.Forms.TextBox lsDataBase;
|
||||
private System.Windows.Forms.Label label7;
|
||||
private System.Windows.Forms.Label label6;
|
||||
private System.Windows.Forms.TextBox lsPassword;
|
||||
private System.Windows.Forms.SplitContainer splitContainer;
|
||||
public System.Windows.Forms.TextBox toLsTextBox;
|
||||
public System.Windows.Forms.TextBox toAfkTextBox;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,516 @@
|
||||
using Lskj.Control;
|
||||
using MySql.Data.MySqlClient;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace AfkDataService
|
||||
{
|
||||
public partial class FrmMain : Form
|
||||
{
|
||||
#region 变量
|
||||
/// <summary>
|
||||
/// 同步到ls循环timer事件
|
||||
/// </summary>
|
||||
public System.Timers.Timer toLsTimer = new System.Timers.Timer();
|
||||
/// <summary>
|
||||
/// 同步到afk循环timer事件
|
||||
/// </summary>
|
||||
public System.Timers.Timer toAfkTimer = new System.Timers.Timer();
|
||||
/// <summary>
|
||||
/// sqlserver连接字符串
|
||||
/// </summary>
|
||||
public string sqlServerConStr { get; set; }
|
||||
/// <summary>
|
||||
/// mySql连接字符串
|
||||
/// </summary>
|
||||
public string mySqlConStr { get; set; }
|
||||
#endregion
|
||||
public FrmMain()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.Load += OnFrmMainLoad;
|
||||
this.startBtn.Appearance.BackColor = Color.FromArgb(140, 208, 1);
|
||||
this.startBtn.MouseHover += new EventHandler(OnStartBtn_MouseHover);
|
||||
this.startBtn.MouseLeave += new EventHandler(OnStartBtn_MouseLeave);
|
||||
this.startBtn.Click += new EventHandler(OnStartBtn_Click);
|
||||
this.intervalTime.LostFocus += new EventHandler(OnIntervalTime_LostFocus);
|
||||
}
|
||||
#region 事件
|
||||
/// <summary>
|
||||
/// 窗体初始化
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void OnFrmMainLoad(object sender, EventArgs e)
|
||||
{
|
||||
InitConnectInfo();
|
||||
}
|
||||
/// <summary>
|
||||
/// 开始按钮点击
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void OnStartBtn_Click(object sender, EventArgs e)
|
||||
{
|
||||
this.startBtn.Enabled = false;
|
||||
try
|
||||
{
|
||||
this.sqlServerConStr = GetSqlConnection();
|
||||
this.mySqlConStr = GetMySqlConnection();
|
||||
//初始化同步到朗速的timer
|
||||
this.toLsTimer.Elapsed += ToLsTimer_Elapsed;
|
||||
this.toLsTimer.Interval = 100;//初始化为100,以确保立刻执行,过程中进行修改
|
||||
this.toLsTimer.AutoReset = true;
|
||||
this.toLsTimer.Start();
|
||||
//初始化同步到中航的timer
|
||||
this.toAfkTimer.Elapsed += ToAfkTimer_Elapsed;
|
||||
this.toAfkTimer.Interval = 100;
|
||||
this.toAfkTimer.AutoReset = true;
|
||||
this.toAfkTimer.Start();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageUtil.Show($"初始化平台失败,原因:{ex.Message}");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 朗速同步到中航的逻辑
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ToAfkTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
|
||||
{
|
||||
this.toAfkTimer.Enabled = false;
|
||||
try
|
||||
{
|
||||
if (this.toAfkTimer.Interval == 100)
|
||||
{
|
||||
this.toAfkTimer.Interval = Convert.ToInt32(intervalTime.Text) * 1000;
|
||||
}
|
||||
this.toAfkTextBox.Invoke(new Action(() =>
|
||||
{
|
||||
this.toAfkTextBox.Clear();
|
||||
}));
|
||||
AfkDataService.SqlHelper SqlHelper = new AfkDataService.SqlHelper(new SqlConnection(this.sqlServerConStr));
|
||||
AfkDataService.MySqlHelper MySqlHelper = new AfkDataService.MySqlHelper(new MySqlConnection(this.mySqlConStr));
|
||||
DataTable dataDirectTable = SqlHelper.ExecuteDataTable("select * from p_synchrTab where disableTag = 'true' and directionTag = '1' ORDER BY id");
|
||||
string selectCond = string.Format("directionTag='{0}'", ((int)DataDirection.LsToAfk));
|
||||
IEnumerable<IGrouping<string, DataRow>> performDrGroup = dataDirectTable.Select(selectCond).GroupBy(n => n["id"] + "");//需要执行的数据条数
|
||||
string uuid = Guid.NewGuid().ToString().Replace("-", "").ToLower();//每一次循环的uuid相同
|
||||
foreach (IGrouping<string, DataRow> groupItem in performDrGroup)
|
||||
{
|
||||
SendMessage(toAfkTextBox, $"准备同步ID:{groupItem.Key},同步表数量{groupItem.Count()}\r\n");
|
||||
List<AbutmentModel> abutmentModels = new List<AbutmentModel>();//同步分组对象集合
|
||||
SynchData synchData = new SynchData(SqlHelper, MySqlHelper);
|
||||
synchData.frmMain = this;
|
||||
synchData.SqlConnectStr = this.sqlServerConStr;
|
||||
synchData.MySqlConnectStr = this.mySqlConStr;
|
||||
foreach (DataRow item in groupItem)
|
||||
{
|
||||
AbutmentModel abutmentModel;
|
||||
try
|
||||
{
|
||||
abutmentModel = new AbutmentModel(item, DataDirection.LsToAfk, this.afkDataBase.Text + "", this.sqlServerConStr, this.mySqlConStr);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
SendMessage(toAfkTextBox, $"同步配置{item["explain"]}信息获取失败,原因:{ex.Message}\r\n");
|
||||
continue;
|
||||
}
|
||||
abutmentModel.uuid = uuid;
|
||||
abutmentModels.Add(abutmentModel);
|
||||
}
|
||||
bool isSucess = false;
|
||||
foreach (AbutmentModel item in abutmentModels)//同步数据
|
||||
{
|
||||
SendMessage(toAfkTextBox, $"正在同步表{item.lsTabName}==>{item.afkTabName}\r\n");
|
||||
isSucess = synchData.SyncDataTable(item);
|
||||
if (!isSucess) break;
|
||||
}
|
||||
if (!isSucess) continue;
|
||||
foreach (AbutmentModel item in abutmentModels)//同步日志
|
||||
{
|
||||
SendMessage(toAfkTextBox, $"正在反写日志==>{item.logTabName}\r\n");
|
||||
isSucess = synchData.SendLog(item);
|
||||
if (!isSucess) break;
|
||||
}
|
||||
if (!isSucess) continue;
|
||||
foreach (AbutmentModel item in abutmentModels)//完成后改变标记
|
||||
{
|
||||
isSucess = synchData.AfterSync(item);
|
||||
if (!isSucess) break;
|
||||
}
|
||||
if (!isSucess) continue;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
this.toAfkTimer.Enabled = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// afk同步到朗速的数据逻辑
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ToLsTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
|
||||
{
|
||||
this.toLsTimer.Enabled = false;
|
||||
try
|
||||
{
|
||||
if (this.toLsTimer.Interval == 100)
|
||||
{
|
||||
this.toLsTimer.Interval = Convert.ToInt32(intervalTime.Text) * 1000;
|
||||
}
|
||||
this.toLsTextBox.Invoke(new Action(() =>
|
||||
{
|
||||
this.toLsTextBox.Clear();
|
||||
}));
|
||||
AfkDataService.SqlHelper SqlHelper = new AfkDataService.SqlHelper(new SqlConnection(this.sqlServerConStr));
|
||||
AfkDataService.MySqlHelper MySqlHelper = new AfkDataService.MySqlHelper(new MySqlConnection(this.mySqlConStr));
|
||||
DataTable dataDirectTable = SqlHelper.ExecuteDataTable("select * from p_synchrTab where disableTag = 'true' and directionTag = '0' ORDER BY id");
|
||||
string selectCond = string.Format("directionTag='{0}'", ((int)DataDirection.AfkToLs));
|
||||
IEnumerable<IGrouping<string, DataRow>> performDrGroup = dataDirectTable.Select(selectCond).GroupBy(n => n["id"] + "");//需要执行的数据条数
|
||||
string uuid = Guid.NewGuid().ToString().Replace("-", "").ToLower();//每一次循环的uuid相同
|
||||
foreach (IGrouping<string, DataRow> groupItem in performDrGroup)
|
||||
{
|
||||
SendMessage(toLsTextBox, $"准备同步ID:{groupItem.Key},同步表数量{groupItem.Count()}\r\n");
|
||||
List<AbutmentModel> abutmentModels = new List<AbutmentModel>();//同步分组对象集合
|
||||
SynchData synchData = new SynchData(SqlHelper, MySqlHelper);
|
||||
synchData.frmMain = this;
|
||||
synchData.SqlConnectStr = this.sqlServerConStr;
|
||||
synchData.MySqlConnectStr = this.mySqlConStr;
|
||||
foreach (DataRow item in groupItem)
|
||||
{
|
||||
AbutmentModel abutmentModel;
|
||||
try
|
||||
{
|
||||
abutmentModel = new AbutmentModel(item, DataDirection.AfkToLs, this.afkDataBase.Text + "", this.sqlServerConStr, this.mySqlConStr);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
SendMessage(toLsTextBox, $"同步配置{item["explain"]}信息获取失败,原因:{ex.Message}\r\n");
|
||||
continue;
|
||||
}
|
||||
abutmentModel.uuid = uuid;
|
||||
abutmentModels.Add(abutmentModel);
|
||||
}
|
||||
bool isSucess = false;
|
||||
foreach (AbutmentModel item in abutmentModels)//同步数据
|
||||
{
|
||||
SendMessage(toLsTextBox, $"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}:正在同步表{item.afkTabName}==>{item.lsTempTabName}\r\n");
|
||||
isSucess = synchData.SyncDataTable(item);
|
||||
if (!isSucess) break;
|
||||
}
|
||||
if (!isSucess) continue;
|
||||
foreach (AbutmentModel item in abutmentModels)//存储过程
|
||||
{
|
||||
SendMessage(toLsTextBox, $"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}:正在执行业务逻辑判断\r\n");
|
||||
isSucess = synchData.ExecBatchAfter(item);
|
||||
if (!isSucess) break;
|
||||
}
|
||||
if (!isSucess) continue;
|
||||
foreach (AbutmentModel item in abutmentModels)//同步日志
|
||||
{
|
||||
SendMessage(toLsTextBox, $"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}:正在反写日志==>{item.logTabName}\r\n");
|
||||
isSucess = synchData.SendLog(item);
|
||||
if (!isSucess) break;
|
||||
}
|
||||
if (!isSucess) continue;
|
||||
foreach (AbutmentModel item in abutmentModels)//完成后改变标记
|
||||
{
|
||||
isSucess = synchData.AfterSync(item);
|
||||
if (!isSucess) break;
|
||||
}
|
||||
if (!isSucess) continue;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
this.toLsTimer.Enabled = true;
|
||||
}
|
||||
/// <summary>
|
||||
/// 开始按钮颜色变化
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void OnStartBtn_MouseLeave(object sender, EventArgs e)
|
||||
{
|
||||
DevExpress.XtraEditors.SimpleButton btn = (DevExpress.XtraEditors.SimpleButton)sender;
|
||||
btn.Appearance.BackColor = Color.FromArgb(52, 142, 216);
|
||||
}
|
||||
/// <summary>
|
||||
/// 开始按钮颜色变化
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void OnStartBtn_MouseHover(object sender, EventArgs e)
|
||||
{
|
||||
DevExpress.XtraEditors.SimpleButton btn = (DevExpress.XtraEditors.SimpleButton)sender;
|
||||
btn.Appearance.BackColor = Color.FromArgb(140, 208, 1);
|
||||
}
|
||||
// <summary>
|
||||
/// 时间间隔TextBox失去焦点事件
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void OnIntervalTime_LostFocus(object sender, EventArgs e)
|
||||
{
|
||||
string checkStr = intervalTime.Text.ToString();
|
||||
if (string.IsNullOrEmpty(checkStr)) intervalTime.Text = "30";
|
||||
int check = Convert.ToInt32(intervalTime.Text.ToString());
|
||||
if (check < 30)
|
||||
{
|
||||
intervalTime.Text = "30";
|
||||
}
|
||||
IniHelper.Write("parameter", "time", intervalTime.Text.ToString());
|
||||
}
|
||||
#endregion
|
||||
#region 方法
|
||||
/// <summary>
|
||||
/// 初始化连接信息
|
||||
/// </summary>
|
||||
public void InitConnectInfo()
|
||||
{
|
||||
//afk
|
||||
afkSeverId.Text = IniHelper.Read("Setting.ini", "AFK", "serverName");//地址
|
||||
afkPortNumber.Text = IniHelper.Read("Setting.ini", "AFK", "port"); //端口
|
||||
afkDataBase.Text = IniHelper.Read("Setting.ini", "AFK", "dbName");//数据库名
|
||||
afkName.Text = IniHelper.Read("Setting.ini", "AFK", "user");//用户名
|
||||
afkPassword.Text = IniHelper.Read("Setting.ini", "AFK", "password");//密码
|
||||
//ls
|
||||
lsSeverId.Text = IniHelper.Read("Setting.ini", "LS", "serverName");//地址
|
||||
lsDataBase.Text = IniHelper.Read("Setting.ini", "LS", "dbName");//数据库名
|
||||
lsName.Text = IniHelper.Read("Setting.ini", "LS", "user");//用户名
|
||||
lsPassword.Text = IniHelper.Read("Setting.ini", "LS", "password");//密码
|
||||
//parameter
|
||||
string time = IniHelper.Read("Setting.ini", "parameter", "time");//间隔时间
|
||||
if (string.IsNullOrEmpty(time)) time = "30";
|
||||
if (Convert.ToInt32(time) < 30) time = "30";
|
||||
intervalTime.Text = time;
|
||||
}
|
||||
#region 数据库连接方法
|
||||
/// <summary>
|
||||
/// 获取sqlserver服务器的连接字符串
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string GetSqlConnection()
|
||||
{
|
||||
string serverName = this.lsSeverId.Text.Trim();//地址
|
||||
string dbName = this.lsDataBase.Text.Trim();//数据库名
|
||||
string user = this.lsName.Text.Trim();//用户名
|
||||
string password = this.lsPassword.Text.Trim();//密码
|
||||
return string.Format("Server={0};Database={1};Persist Security Info=True;User ID={2};Password={3};Connection Timeout=5;MultipleActiveResultSets=true", serverName, dbName, user, password);
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取mysql服务器的连接字符串
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string GetMySqlConnection()
|
||||
{
|
||||
string serverName = this.afkSeverId.Text.Trim();//地址
|
||||
string port = this.afkPortNumber.Text.Trim();//端口
|
||||
string dbName = this.afkDataBase.Text.Trim();//数据库名
|
||||
string user = this.afkName.Text.Trim();//用户名
|
||||
string password = this.afkPassword.Text.Trim();//密码
|
||||
IniHelper.Write("AFK", "serverName", serverName);
|
||||
IniHelper.Write("AFK", "port", port);
|
||||
IniHelper.Write("AFK", "dbName", dbName);
|
||||
IniHelper.Write("AFK", "user", user);
|
||||
IniHelper.Write("AFK", "password", password);
|
||||
return string.Format("Data Source={0};Port={1};Database={2};User ID={3};Password={4};Charset=utf8;Convert Zero Datetime=True;", serverName, port, dbName, user, password);
|
||||
}
|
||||
///// <summary>
|
||||
///// 创建sqlserver数据库连接
|
||||
///// </summary>
|
||||
///// <param name="isSave"></param>
|
||||
///// <returns></returns>
|
||||
//public bool ConnectSqlServer()
|
||||
//{
|
||||
// string serverName = this.lsSeverId.Text.Trim();//地址
|
||||
// string dbName = this.lsDataBase.Text.Trim();//数据库名
|
||||
// string user = this.lsName.Text.Trim();//用户名
|
||||
// string password = this.lsPassword.Text.Trim();//密码
|
||||
// if (string.IsNullOrWhiteSpace(serverName))
|
||||
// {
|
||||
// MessageUtil.Show("请重新输入朗速数据库地址");
|
||||
// return false;
|
||||
// }
|
||||
// if (string.IsNullOrWhiteSpace(dbName))
|
||||
// {
|
||||
// MessageUtil.Show("请重新输入朗速数据库库名");
|
||||
// return false;
|
||||
// }
|
||||
// if (string.IsNullOrWhiteSpace(user))
|
||||
// {
|
||||
// MessageUtil.Show("请重新输入朗速数据库用户名");
|
||||
// return false;
|
||||
// }
|
||||
// // 测试数据库连接
|
||||
// try
|
||||
// {
|
||||
// if (ConnectingToSqlServer())
|
||||
// {
|
||||
// IniHelper.Write("LS", "serverName", serverName);
|
||||
// IniHelper.Write("LS", "dbName", dbName);
|
||||
// IniHelper.Write("LS", "user", user);
|
||||
// IniHelper.Write("LS", "password", password);
|
||||
// return true;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// MessageUtil.Show("连接失败,请检查朗速方配置");
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// MessageUtil.Show($"连接失败,原因:{ex.Message},请检查朗速方配置");
|
||||
// }
|
||||
// return true;
|
||||
//}
|
||||
//public bool ConnectingToSqlServer()
|
||||
//{
|
||||
// string connStr = GetSqlConnection();
|
||||
// sqlServerConStr = connStr;
|
||||
// if (SqlHelper._connection != null)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// SqlHelper._connection.Close();
|
||||
// SqlHelper._connection.Dispose();
|
||||
// }
|
||||
// catch (Exception)
|
||||
// {
|
||||
// }
|
||||
// SqlHelper._connection = null;
|
||||
// }
|
||||
// try
|
||||
// {
|
||||
// SqlHelper._connection = new SqlConnection(connStr);
|
||||
// SqlHelper._connection.Open();
|
||||
// return true;
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// Console.WriteLine(ex.Message);
|
||||
// }
|
||||
// return false;
|
||||
//}
|
||||
///// <summary>
|
||||
///// 创建Mysql数据库连接
|
||||
///// </summary>
|
||||
///// <param name="isSave"></param>
|
||||
///// <returns></returns>
|
||||
//public bool ConnectMySql()
|
||||
//{
|
||||
// string serverName = this.afkSeverId.Text.Trim();//地址
|
||||
// string port = this.afkPortNumber.Text.Trim();//端口
|
||||
// string dbName = this.afkDataBase.Text.Trim();//数据库名
|
||||
// string user = this.afkName.Text.Trim();//用户名
|
||||
// string password = this.afkPassword.Text.Trim();//密码
|
||||
// if (string.IsNullOrWhiteSpace(serverName))
|
||||
// {
|
||||
// MessageUtil.Show("请重新输入Afk数据库地址");
|
||||
// return false;
|
||||
// }
|
||||
// if (string.IsNullOrWhiteSpace(port))
|
||||
// {
|
||||
// MessageUtil.Show("请重新输入Afk数据库端口");
|
||||
// return false;
|
||||
// }
|
||||
// if (string.IsNullOrWhiteSpace(dbName))
|
||||
// {
|
||||
// MessageUtil.Show("请重新输入Afk数据库库名");
|
||||
// return false;
|
||||
// }
|
||||
// if (string.IsNullOrWhiteSpace(user))
|
||||
// {
|
||||
// MessageUtil.Show("请重新输入Afk数据库用户名");
|
||||
// return false;
|
||||
// }
|
||||
// // 测试数据库连接
|
||||
// try
|
||||
// {
|
||||
// if (ConnectingToMySql())
|
||||
// {
|
||||
|
||||
// IniHelper.Write("AFK", "serverName", serverName);
|
||||
// IniHelper.Write("AFK", "port", port);
|
||||
// IniHelper.Write("AFK", "dbName", dbName);
|
||||
// IniHelper.Write("AFK", "user", user);
|
||||
// IniHelper.Write("AFK", "password", password);
|
||||
// return true;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// MessageUtil.Show("连接失败,请检查AFK方配置");
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// MessageUtil.Show($"连接失败,原因:{ex.Message},请检查AFK方配置");
|
||||
// }
|
||||
// return true;
|
||||
//}
|
||||
//public bool ConnectingToMySql()
|
||||
//{
|
||||
// string connStr = GetMySqlConnection();
|
||||
// mySqlConStr = connStr;
|
||||
// if (MySqlHelper._connection != null)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// MySqlHelper._connection.Close();
|
||||
// MySqlHelper._connection.Dispose();
|
||||
// }
|
||||
// catch (Exception)
|
||||
// {
|
||||
// }
|
||||
// MySqlHelper._connection = null;
|
||||
// }
|
||||
// try
|
||||
// {
|
||||
// MySqlHelper._connection = new MySqlConnection(connStr);
|
||||
// MySqlHelper._connection.Open();
|
||||
// return true;
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// Console.WriteLine(ex.Message);
|
||||
// }
|
||||
// return false;
|
||||
//}
|
||||
#endregion
|
||||
public void SendMessage(TextBox textBox, string message)
|
||||
{
|
||||
if (textBox.InvokeRequired)
|
||||
{
|
||||
textBox.Invoke(new Action(() =>
|
||||
{
|
||||
textBox.AppendText(message);
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
textBox.AppendText(message);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
@@ -0,0 +1,133 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace AfkDataService
|
||||
{
|
||||
/// <summary>
|
||||
/// Ini 文件操作类
|
||||
/// </summary>
|
||||
public static class IniHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 写入INI文件
|
||||
/// </summary>
|
||||
/// <param name="section">节点名称[如[TypeName]]</param>
|
||||
/// <param name="key">键</param>
|
||||
/// <param name="val">值</param>
|
||||
/// <param name="filepath">文件路径</param>
|
||||
/// <returns></returns>
|
||||
[DllImport("kernel32")]
|
||||
private static extern long WritePrivateProfileString(string section, string key, string val, string filepath);
|
||||
/// <summary>
|
||||
/// 读取INI文件
|
||||
/// </summary>
|
||||
/// <param name="section">节点名称</param>
|
||||
/// <param name="key">键</param>
|
||||
/// <param name="def">值</param>
|
||||
/// <param name="retval">stringbulider对象</param>
|
||||
/// <param name="size">字节大小</param>
|
||||
/// <param name="filePath">文件路径</param>
|
||||
/// <returns></returns>
|
||||
[DllImport("kernel32")]
|
||||
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retval, int size, string filePath);
|
||||
/// <summary>
|
||||
/// <para>说明:通过Key获取Value值</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-07-22</para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="key">键</param>
|
||||
/// <returns>值</returns>
|
||||
public static string Read(string iniName, string key)
|
||||
{
|
||||
string value = string.Empty;
|
||||
try
|
||||
{
|
||||
//判读INI文件是否存在
|
||||
string filePath = Path.Combine(new string[] { Application.StartupPath + "\\" + iniName });
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
StringBuilder temp = new StringBuilder(1024);
|
||||
string fileName = Path.GetFileNameWithoutExtension(filePath);
|
||||
GetPrivateProfileString(fileName, key, "", temp, 1024, filePath);
|
||||
return temp + "";
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:通过Key获取Value值</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-07-22</para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="key">键</param>
|
||||
/// <returns>值</returns>
|
||||
public static string Read(string iniName, string mainKey, string listKey)
|
||||
{
|
||||
string value = string.Empty;
|
||||
try
|
||||
{
|
||||
//判读INI文件是否存在
|
||||
string filePath = Path.Combine(new string[] { Application.StartupPath + "\\" + iniName });
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
StringBuilder temp = new StringBuilder(1024);
|
||||
string fileName = Path.GetFileNameWithoutExtension(filePath);
|
||||
GetPrivateProfileString(mainKey, listKey, "", temp, 1024, filePath);
|
||||
return temp + "";
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:写入Ini文件(以键值对的形式存放)</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-07-22</para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="key">键</param>
|
||||
/// <param name="value">值</param>
|
||||
/// <returns></returns>
|
||||
public static void Write(string iniName, string key, string value)
|
||||
{
|
||||
try
|
||||
{
|
||||
//根据INI文件名设置要写入INI文件的节点名称
|
||||
//此处的节点名称完全可以根据实际需要进行配置
|
||||
string filePath = Path.Combine(new string[] { Application.StartupPath + "\\Setting.ini" });
|
||||
if (!File.Exists(filePath))
|
||||
{
|
||||
File.Create(filePath);
|
||||
}
|
||||
WritePrivateProfileString(iniName, key, value, filePath);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,599 @@
|
||||
using MySql.Data.MySqlClient;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AfkDataService
|
||||
{
|
||||
public class MySqlHelper
|
||||
{ /// <summary>
|
||||
/// 数据连接
|
||||
/// </summary>
|
||||
public MySqlConnection _connection;
|
||||
/// <summary>
|
||||
/// 请求超时时间
|
||||
/// </summary>
|
||||
public int CommandTimeout;
|
||||
#region ExecuteAdapter
|
||||
public MySqlHelper(MySqlConnection connection)
|
||||
{
|
||||
this._connection = connection;
|
||||
this._connection.Open();
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:获取适配器</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-07-24 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="cmdType">Type of the command.</param>
|
||||
/// <param name="cmdText">The command text.</param>
|
||||
/// <param name="commandParameters">The command parameters.</param>
|
||||
/// <returns>MySqlDataAdapter.</returns>
|
||||
public MySqlDataAdapter ExecuteAdapter(CommandType cmdType, string cmdText, params MySqlParameter[] commandParameters)
|
||||
{
|
||||
MySqlDataAdapter adapter;
|
||||
MySqlCommand cmd = new MySqlCommand();
|
||||
try
|
||||
{
|
||||
PrepareCommand(cmd, _connection, null, cmdType, cmdText, commandParameters);
|
||||
adapter = new MySqlDataAdapter(cmd);
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
return adapter;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// <para>说明:获取适配器</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-07-24 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="cmdType">Type of the command.</param>
|
||||
/// <param name="cmdText">The command text.</param>
|
||||
/// <returns>MySqlDataAdapter.</returns>
|
||||
public MySqlDataAdapter ExecuteAdapter(CommandType cmdType, string cmdText)
|
||||
{
|
||||
MySqlDataAdapter adapter;
|
||||
MySqlCommand cmd = new MySqlCommand();
|
||||
try
|
||||
{
|
||||
PrepareCommand(cmd, _connection, null, cmdType, cmdText, null);
|
||||
adapter = new MySqlDataAdapter(cmd);
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
return adapter;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ExecuteDataTable
|
||||
/// <summary>
|
||||
/// <para>说明:执行sql返回DataTable</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-07-24 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="cmdText">The command text.</param>
|
||||
/// <returns>DataTable.</returns>
|
||||
public DataTable ExecuteDataTable(string cmdText)
|
||||
{
|
||||
return ExecuteDataSet(cmdText).Tables[0];
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:执行sql返回DataTable</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-07-24 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="cmdText">The command text.</param>
|
||||
/// <returns>DataTable.</returns>
|
||||
public DataTable ExecuteDataTable(string cmdText, params MySqlParameter[] commandParameters)
|
||||
{
|
||||
return ExecuteDataSet(CommandType.Text, cmdText, "temp", commandParameters).Tables[0];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>说明:执行sql返回指定字段值</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-08-15 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="fieldName">Name of the field.</param>
|
||||
/// <param name="cmdText">The command text.</param>
|
||||
/// <returns>System.Object.</returns>
|
||||
public object ExecuteObject(string fieldName, string cmdText)
|
||||
{
|
||||
object result = null;
|
||||
try
|
||||
{
|
||||
result = ExecuteDataSet(cmdText).Tables[0].Rows[0][fieldName];
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:执行sql返回指定字段值</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-11-27 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="fieldName">Name of the field.</param>
|
||||
/// <param name="cmdText">The command text.</param>
|
||||
/// <param name="commandParameters">The command parameters.</param>
|
||||
/// <returns>System.Object.</returns>
|
||||
public object ExecuteObject(string fieldName, string cmdText, params MySqlParameter[] commandParameters)
|
||||
{
|
||||
object result = null;
|
||||
try
|
||||
{
|
||||
result = ExecuteDataSet(CommandType.Text, cmdText, "temp", commandParameters).Tables[0].Rows[0][fieldName];
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:执行sql返回指定字段值</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-08-15 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="fieldName">Name of the field.</param>
|
||||
/// <param name="cmdText">The command text.</param>
|
||||
/// <returns>System.Object.</returns>
|
||||
public string ExecuteString(string fieldName, string cmdText)
|
||||
{
|
||||
object obj = ExecuteObject(fieldName, cmdText);
|
||||
return obj == null ? "" : obj.ToString();
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:执行sql返回指定字段值</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-11-27 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="fieldName">Name of the field.</param>
|
||||
/// <param name="cmdText">The command text.</param>
|
||||
/// <param name="commandParameters">The command parameters.</param>
|
||||
/// <returns>System.String.</returns>
|
||||
public string ExecuteString(string fieldName, string cmdText, params MySqlParameter[] commandParameters)
|
||||
{
|
||||
object obj = ExecuteObject(fieldName, cmdText, commandParameters);
|
||||
return obj == null ? "" : obj.ToString();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ExecuteDataSet
|
||||
|
||||
/// <summary>
|
||||
/// <para>说明:查询结果集</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-07-24 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="cmdType">Type of the command.</param>
|
||||
/// <param name="cmdText">The command text.</param>
|
||||
/// <param name="tabName">Name of the tab.</param>
|
||||
/// <param name="commandParameters">The command parameters.</param>
|
||||
/// <returns>DataSet.</returns>
|
||||
public DataSet ExecuteDataSet(int cmdType, string cmdText, string tabName, params MySqlParameter[] commandParameters)
|
||||
{
|
||||
CommandType _cmdType = CommandType.Text;
|
||||
switch (cmdType)
|
||||
{
|
||||
case 4:
|
||||
_cmdType = CommandType.StoredProcedure;
|
||||
break;
|
||||
case 512:
|
||||
_cmdType = CommandType.TableDirect;
|
||||
break;
|
||||
}
|
||||
return ExecuteDataSet(_cmdType, cmdText, tabName, commandParameters);
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:查询结果集</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-07-24 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="cmdType">语句类型存储过程或者sql语句</param>
|
||||
/// <param name="cmdText">执行内容</param>
|
||||
/// <param name="tabName">表名</param>
|
||||
/// <param name="commandParameters">参数</param>
|
||||
/// <returns>DataSet.</returns>
|
||||
public DataSet ExecuteDataSet(CommandType cmdType, string cmdText, string tabName, params MySqlParameter[] commandParameters)
|
||||
{
|
||||
DataSet set2;
|
||||
MySqlCommand cmd = new MySqlCommand();
|
||||
try
|
||||
{
|
||||
PrepareCommand(cmd, _connection, null, cmdType, cmdText, commandParameters);//sql参数处理
|
||||
MySqlDataAdapter adapter = new MySqlDataAdapter(cmd);//创建对象,与sql命令对象绑定
|
||||
DataSet dataSet = new DataSet();
|
||||
adapter.Fill(dataSet, tabName);//填充数据。第二个参数是数据集中内存表的名字,可以与数据库中的不同
|
||||
//adapter.FillSchema(dataSet, SchemaType.Mapped, tabName);
|
||||
set2 = dataSet;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (e.Message.StartsWith("在从服务器接收结果时发生传输级错误") ||
|
||||
e.Message.StartsWith("在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误") ||
|
||||
e.Message.StartsWith("在向服务器发送请求时发生传输级错误"))
|
||||
{
|
||||
throw new Exception("无法连接服务器,请检查网络连接.");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception(e.Message + " SQL=[ " + cmdText + " ]", e);
|
||||
//throw;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Dispose();
|
||||
}
|
||||
|
||||
return set2;
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:查询结果集</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-07-24 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="cmdType">语句类型存储过程或者sql语句</param>
|
||||
/// <param name="cmdText">执行内容</param>
|
||||
/// <param name="tabName">表名</param>
|
||||
/// <returns>DataSet.</returns>
|
||||
public DataSet ExecuteDataSet(CommandType cmdType, string cmdText, string tabName)
|
||||
{
|
||||
return ExecuteDataSet(cmdType, cmdText, tabName, null);
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:查询结果集</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-07-24 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="cmdText">执行内容</param>
|
||||
/// <returns>DataSet.</returns>
|
||||
public DataSet ExecuteDataSet(string cmdText)
|
||||
{
|
||||
return ExecuteDataSet(CommandType.Text, cmdText, "temp");
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:查询结果集</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-07-24 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="procedureName">Name of the procedure.</param>
|
||||
/// <param name="tabName">表名</param>
|
||||
/// <param name="parameterNames">The parameter names.</param>
|
||||
/// <param name="parameterValues">The parameter values.</param>
|
||||
/// <returns>DataSet.</returns>
|
||||
public DataSet ExecuteDataSet(string procedureName, string tabName, string[] parameterNames, object[] parameterValues)
|
||||
{
|
||||
DataSet set2;
|
||||
try
|
||||
{
|
||||
MySqlCommand cmd = new MySqlCommand(procedureName, _connection);
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
|
||||
if (parameterNames != null && parameterValues != null)
|
||||
{
|
||||
for (int i = 0; i < parameterNames.Length && i < parameterValues.Length; i++)
|
||||
{
|
||||
cmd.Parameters.AddWithValue(parameterNames[i], parameterValues[i]);
|
||||
}
|
||||
}
|
||||
MySqlDataAdapter adapter = new MySqlDataAdapter(cmd);
|
||||
DataSet dataSet = new DataSet();
|
||||
adapter.Fill(dataSet, tabName);
|
||||
set2 = dataSet;
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
return set2;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ExecuteNonQuery
|
||||
/// <summary>
|
||||
/// <para>说明:执行sql语句或者存储过程</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-07-24 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="cmdType">Type of the command.</param>
|
||||
/// <param name="cmdText">The command text.</param>
|
||||
/// <param name="commandParameters">The command parameters.</param>
|
||||
/// <returns>System.Int32.</returns>
|
||||
public int ExecuteNonQuery(CommandType cmdType, string cmdText, params MySqlParameter[] commandParameters)
|
||||
{
|
||||
MySqlCommand cmd = new MySqlCommand();
|
||||
int num = 0;
|
||||
try
|
||||
{
|
||||
|
||||
PrepareCommand(cmd, _connection, null, cmdType, cmdText, commandParameters);
|
||||
num = cmd.ExecuteNonQuery();
|
||||
cmd.Parameters.Clear();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (e.Message.StartsWith("在从服务器接收结果时发生传输级错误") ||
|
||||
e.Message.StartsWith("在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误") ||
|
||||
e.Message.StartsWith("在向服务器发送请求时发生传输级错误"))
|
||||
{
|
||||
throw new Exception("无法连接服务器,请检查网络连接.");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception(e.Message + " SQL=[ " + cmdText + " ]", e);
|
||||
//throw;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Dispose();
|
||||
}
|
||||
return num;
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:执行sql语句或者存储过程</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-07-24 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="cmdType">Type of the command.</param>
|
||||
/// <param name="cmdText">The command text.</param>
|
||||
/// <returns>System.Int32.</returns>
|
||||
public int ExecuteNonQuery(CommandType cmdType, string cmdText)
|
||||
{
|
||||
return ExecuteNonQuery(CommandType.Text, cmdText, null);
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:执行sql语句或者存储过程</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-07-24 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="cmdText">The command text.</param>
|
||||
/// <returns>System.Int32.</returns>
|
||||
public int ExecuteNonQuery(string cmdText)
|
||||
{
|
||||
return ExecuteNonQuery(CommandType.Text, cmdText);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ExecuteReader
|
||||
/// <summary>
|
||||
/// <para>说明:执行sql语句或者存储过程并返回结果集(只读、只进)</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-07-24 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="cmdType">Type of the command.</param>
|
||||
/// <param name="cmdText">The command text.</param>
|
||||
/// <param name="commandParameters">The command parameters.</param>
|
||||
/// <returns>OleDbDataReader.</returns>
|
||||
public MySqlDataReader ExecuteReader(CommandType cmdType, string cmdText, params MySqlParameter[] commandParameters)
|
||||
{
|
||||
MySqlDataReader reader2;
|
||||
MySqlCommand cmd = new MySqlCommand();
|
||||
try
|
||||
{
|
||||
PrepareCommand(cmd, _connection, null, cmdType, cmdText, commandParameters);
|
||||
MySqlDataReader reader = cmd.ExecuteReader();
|
||||
cmd.Parameters.Clear();
|
||||
reader2 = reader;
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
return reader2;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ExecuteScalar
|
||||
/// <summary>
|
||||
/// <para>说明:执行sql语句或者存储过程并返回结果集第一行第一列</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-07-24 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="Connectionection">The connectionection.</param>
|
||||
/// <param name="cmdType">Type of the command.</param>
|
||||
/// <param name="cmdText">The command text.</param>
|
||||
/// <param name="commandParameters">The command parameters.</param>
|
||||
/// <returns>System.Object.</returns>
|
||||
public object ExecuteScalar(MySqlConnection Connectionection, CommandType cmdType, string cmdText, params MySqlParameter[] commandParameters)
|
||||
{
|
||||
MySqlCommand cmd = new MySqlCommand();
|
||||
PrepareCommand(cmd, Connectionection, null, cmdType, cmdText, commandParameters);
|
||||
object obj2 = cmd.ExecuteScalar();
|
||||
cmd.Parameters.Clear();
|
||||
return obj2;
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:执行sql语句或者存储过程并返回结果集第一行第一列</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-07-24 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="cmdType">Type of the command.</param>
|
||||
/// <param name="cmdText">The command text.</param>
|
||||
/// <param name="commandParameters">The command parameters.</param>
|
||||
/// <returns>System.Object.</returns>
|
||||
public object ExecuteScalar(CommandType cmdType, string cmdText, params MySqlParameter[] commandParameters)
|
||||
{
|
||||
MySqlCommand cmd = new MySqlCommand();
|
||||
{
|
||||
PrepareCommand(cmd, _connection, null, cmdType, cmdText, commandParameters);
|
||||
object obj2 = cmd.ExecuteScalar();
|
||||
cmd.Parameters.Clear();
|
||||
return obj2;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:执行sql语句或者存储过程并返回结果集第一行第一列</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-07-24 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="cmdType">Type of the command.</param>
|
||||
/// <param name="cmdText">The command text.</param>
|
||||
/// <returns>System.Object.</returns>
|
||||
public object ExecuteScalar(CommandType cmdType, string cmdText)
|
||||
{
|
||||
MySqlCommand cmd = new MySqlCommand();
|
||||
{
|
||||
PrepareCommand(cmd, _connection, null, cmdType, cmdText, null);
|
||||
object obj2 = cmd.ExecuteScalar();
|
||||
cmd.Parameters.Clear();
|
||||
return obj2;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:执行sql语句或者存储过程并返回结果集第一行第一列</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-08-21 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="cmdText">The command text.</param>
|
||||
/// <returns>System.Object.</returns>
|
||||
public object ExecuteScalar(string cmdText)
|
||||
{
|
||||
MySqlCommand cmd = new MySqlCommand();
|
||||
{
|
||||
PrepareCommand(cmd, _connection, null, CommandType.Text, cmdText, null);
|
||||
object obj2 = cmd.ExecuteScalar();
|
||||
cmd.Parameters.Clear();
|
||||
return obj2;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region PrepareCommand
|
||||
/// <summary>
|
||||
/// <para>说明: sql参数处理</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-07-24 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="cmd">The command.</param>
|
||||
/// <param name="Connection">The connection.</param>
|
||||
/// <param name="trans">The trans.</param>
|
||||
/// <param name="cmdType">Type of the command.</param>
|
||||
/// <param name="cmdText">The command text.</param>
|
||||
/// <param name="cmdParms">The command parms.</param>
|
||||
private void PrepareCommand(MySqlCommand cmd, MySqlConnection Connection, MySqlTransaction trans, CommandType cmdType, string cmdText, MySqlParameter[] cmdParms)
|
||||
{
|
||||
if (Connection.State != ConnectionState.Open)
|
||||
{
|
||||
Connection.Open();
|
||||
}
|
||||
cmd.Connection = Connection;
|
||||
cmd.CommandTimeout = CommandTimeout;
|
||||
cmd.CommandText = cmdText;
|
||||
if (trans != null)
|
||||
{
|
||||
cmd.Transaction = trans;
|
||||
}
|
||||
cmd.CommandType = cmdType;
|
||||
if (cmdParms != null)
|
||||
{
|
||||
foreach (MySqlParameter parameter in cmdParms)
|
||||
{
|
||||
cmd.Parameters.Add(parameter);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace AfkDataService
|
||||
{
|
||||
static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// 应用程序的主入口点。
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Application.Run(new FrmMain());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// 有关程序集的一般信息由以下
|
||||
// 控制。更改这些特性值可修改
|
||||
// 与程序集关联的信息。
|
||||
[assembly: AssemblyTitle("AfkDataService")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("AfkDataService")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2023")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// 将 ComVisible 设置为 false 会使此程序集中的类型
|
||||
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
|
||||
//请将此类型的 ComVisible 特性设置为 true。
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
|
||||
[assembly: Guid("36f96f46-e6c8-4315-a961-e79a4155cfaf")]
|
||||
|
||||
// 程序集的版本信息由下列四个值组成:
|
||||
//
|
||||
// 主版本
|
||||
// 次版本
|
||||
// 生成号
|
||||
// 修订号
|
||||
//
|
||||
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
|
||||
//通过使用 "*",如下所示:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
@@ -0,0 +1,63 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// 此代码由工具生成。
|
||||
// 运行时版本:4.0.30319.42000
|
||||
//
|
||||
// 对此文件的更改可能会导致不正确的行为,并且如果
|
||||
// 重新生成代码,这些更改将会丢失。
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace AfkDataService.Properties {
|
||||
using System;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 一个强类型的资源类,用于查找本地化的字符串等。
|
||||
/// </summary>
|
||||
// 此类是由 StronglyTypedResourceBuilder
|
||||
// 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
|
||||
// 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
|
||||
// (以 /str 作为命令选项),或重新生成 VS 项目。
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Resources {
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Resources() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 返回此类使用的缓存的 ResourceManager 实例。
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("AfkDataService.Properties.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重写当前线程的 CurrentUICulture 属性,对
|
||||
/// 使用此强类型资源类的所有资源查找执行重写。
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture {
|
||||
get {
|
||||
return resourceCulture;
|
||||
}
|
||||
set {
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
@@ -0,0 +1,26 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// 此代码由工具生成。
|
||||
// 运行时版本:4.0.30319.42000
|
||||
//
|
||||
// 对此文件的更改可能会导致不正确的行为,并且如果
|
||||
// 重新生成代码,这些更改将会丢失。
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace AfkDataService.Properties {
|
||||
|
||||
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.10.0.0")]
|
||||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
|
||||
|
||||
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||
|
||||
public static Settings Default {
|
||||
get {
|
||||
return defaultInstance;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
|
||||
<Profiles>
|
||||
<Profile Name="(Default)" />
|
||||
</Profiles>
|
||||
<Settings />
|
||||
</SettingsFile>
|
||||
@@ -0,0 +1,595 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace AfkDataService
|
||||
{
|
||||
public class SqlHelper
|
||||
{ /// <summary>
|
||||
/// 数据连接
|
||||
/// </summary>
|
||||
public SqlConnection _connection;
|
||||
/// <summary>
|
||||
/// 请求超时时间
|
||||
/// </summary>
|
||||
public int CommandTimeout;
|
||||
public SqlHelper(SqlConnection connection)
|
||||
{
|
||||
this._connection = connection;
|
||||
this._connection.Open();
|
||||
}
|
||||
#region ExecuteAdapter
|
||||
/// <summary>
|
||||
/// <para>说明:获取适配器</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-07-24 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="cmdType">Type of the command.</param>
|
||||
/// <param name="cmdText">The command text.</param>
|
||||
/// <param name="commandParameters">The command parameters.</param>
|
||||
/// <returns>SqlDataAdapter.</returns>
|
||||
public SqlDataAdapter ExecuteAdapter(CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
|
||||
{
|
||||
SqlDataAdapter adapter;
|
||||
SqlCommand cmd = new SqlCommand();
|
||||
try
|
||||
{
|
||||
PrepareCommand(cmd, _connection, null, cmdType, cmdText, commandParameters);
|
||||
adapter = new SqlDataAdapter(cmd);
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
return adapter;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// <para>说明:获取适配器</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-07-24 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="cmdType">Type of the command.</param>
|
||||
/// <param name="cmdText">The command text.</param>
|
||||
/// <returns>SqlDataAdapter.</returns>
|
||||
public SqlDataAdapter ExecuteAdapter(CommandType cmdType, string cmdText)
|
||||
{
|
||||
SqlDataAdapter adapter;
|
||||
SqlCommand cmd = new SqlCommand();
|
||||
try
|
||||
{
|
||||
PrepareCommand(cmd, _connection, null, cmdType, cmdText, null);
|
||||
adapter = new SqlDataAdapter(cmd);
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
return adapter;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ExecuteDataTable
|
||||
/// <summary>
|
||||
/// <para>说明:执行sql返回DataTable</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-07-24 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="cmdText">The command text.</param>
|
||||
/// <returns>DataTable.</returns>
|
||||
public DataTable ExecuteDataTable(string cmdText)
|
||||
{
|
||||
return ExecuteDataSet(cmdText).Tables[0];
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:执行sql返回DataTable</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-07-24 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="cmdText">The command text.</param>
|
||||
/// <returns>DataTable.</returns>
|
||||
public DataTable ExecuteDataTable(string cmdText, params SqlParameter[] commandParameters)
|
||||
{
|
||||
return ExecuteDataSet(CommandType.Text, cmdText, "temp", commandParameters).Tables[0];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>说明:执行sql返回指定字段值</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-08-15 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="fieldName">Name of the field.</param>
|
||||
/// <param name="cmdText">The command text.</param>
|
||||
/// <returns>System.Object.</returns>
|
||||
public object ExecuteObject(string fieldName, string cmdText)
|
||||
{
|
||||
object result = null;
|
||||
try
|
||||
{
|
||||
result = ExecuteDataSet(cmdText).Tables[0].Rows[0][fieldName];
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:执行sql返回指定字段值</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-11-27 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="fieldName">Name of the field.</param>
|
||||
/// <param name="cmdText">The command text.</param>
|
||||
/// <param name="commandParameters">The command parameters.</param>
|
||||
/// <returns>System.Object.</returns>
|
||||
public object ExecuteObject(string fieldName, string cmdText, params SqlParameter[] commandParameters)
|
||||
{
|
||||
object result = null;
|
||||
try
|
||||
{
|
||||
result = ExecuteDataSet(CommandType.Text, cmdText, "temp", commandParameters).Tables[0].Rows[0][fieldName];
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:执行sql返回指定字段值</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-08-15 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="fieldName">Name of the field.</param>
|
||||
/// <param name="cmdText">The command text.</param>
|
||||
/// <returns>System.Object.</returns>
|
||||
public string ExecuteString(string fieldName, string cmdText)
|
||||
{
|
||||
object obj = ExecuteObject(fieldName, cmdText);
|
||||
return obj == null ? "" : obj.ToString();
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:执行sql返回指定字段值</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-11-27 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="fieldName">Name of the field.</param>
|
||||
/// <param name="cmdText">The command text.</param>
|
||||
/// <param name="commandParameters">The command parameters.</param>
|
||||
/// <returns>System.String.</returns>
|
||||
public string ExecuteString(string fieldName, string cmdText, params SqlParameter[] commandParameters)
|
||||
{
|
||||
object obj = ExecuteObject(fieldName, cmdText, commandParameters);
|
||||
return obj == null ? "" : obj.ToString();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ExecuteDataSet
|
||||
|
||||
/// <summary>
|
||||
/// <para>说明:查询结果集</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-07-24 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="cmdType">Type of the command.</param>
|
||||
/// <param name="cmdText">The command text.</param>
|
||||
/// <param name="tabName">Name of the tab.</param>
|
||||
/// <param name="commandParameters">The command parameters.</param>
|
||||
/// <returns>DataSet.</returns>
|
||||
public DataSet ExecuteDataSet(int cmdType, string cmdText, string tabName, params SqlParameter[] commandParameters)
|
||||
{
|
||||
CommandType _cmdType = CommandType.Text;
|
||||
switch (cmdType)
|
||||
{
|
||||
case 4:
|
||||
_cmdType = CommandType.StoredProcedure;
|
||||
break;
|
||||
case 512:
|
||||
_cmdType = CommandType.TableDirect;
|
||||
break;
|
||||
}
|
||||
return ExecuteDataSet(_cmdType, cmdText, tabName, commandParameters);
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:查询结果集</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-07-24 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="cmdType">语句类型存储过程或者sql语句</param>
|
||||
/// <param name="cmdText">执行内容</param>
|
||||
/// <param name="tabName">表名</param>
|
||||
/// <param name="commandParameters">参数</param>
|
||||
/// <returns>DataSet.</returns>
|
||||
public DataSet ExecuteDataSet(CommandType cmdType, string cmdText, string tabName, params SqlParameter[] commandParameters)
|
||||
{
|
||||
DataSet set2;
|
||||
SqlCommand cmd = new SqlCommand();
|
||||
try
|
||||
{
|
||||
PrepareCommand(cmd, _connection, null, cmdType, cmdText, commandParameters);
|
||||
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
|
||||
DataSet dataSet = new DataSet();
|
||||
adapter.Fill(dataSet, tabName);
|
||||
//adapter.FillSchema(dataSet, SchemaType.Mapped, tabName);
|
||||
set2 = dataSet;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (e.Message.StartsWith("在从服务器接收结果时发生传输级错误") ||
|
||||
e.Message.StartsWith("在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误") ||
|
||||
e.Message.StartsWith("在向服务器发送请求时发生传输级错误"))
|
||||
{
|
||||
throw new Exception("无法连接服务器,请检查网络连接.");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Dispose();
|
||||
}
|
||||
|
||||
return set2;
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:查询结果集</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-07-24 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="cmdType">语句类型存储过程或者sql语句</param>
|
||||
/// <param name="cmdText">执行内容</param>
|
||||
/// <param name="tabName">表名</param>
|
||||
/// <returns>DataSet.</returns>
|
||||
public DataSet ExecuteDataSet(CommandType cmdType, string cmdText, string tabName)
|
||||
{
|
||||
return ExecuteDataSet(cmdType, cmdText, tabName, null);
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:查询结果集</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-07-24 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="cmdText">执行内容</param>
|
||||
/// <returns>DataSet.</returns>
|
||||
public DataSet ExecuteDataSet(string cmdText)
|
||||
{
|
||||
return ExecuteDataSet(CommandType.Text, cmdText, "temp");
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:查询结果集</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-07-24 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="procedureName">Name of the procedure.</param>
|
||||
/// <param name="tabName">表名</param>
|
||||
/// <param name="parameterNames">The parameter names.</param>
|
||||
/// <param name="parameterValues">The parameter values.</param>
|
||||
/// <returns>DataSet.</returns>
|
||||
public DataSet ExecuteDataSet(string procedureName, string tabName, string[] parameterNames, object[] parameterValues)
|
||||
{
|
||||
DataSet set2;
|
||||
try
|
||||
{
|
||||
SqlCommand cmd = new SqlCommand(procedureName, _connection);
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
|
||||
if (parameterNames != null && parameterValues != null)
|
||||
{
|
||||
for (int i = 0; i < parameterNames.Length && i < parameterValues.Length; i++)
|
||||
{
|
||||
cmd.Parameters.AddWithValue(parameterNames[i], parameterValues[i]);
|
||||
}
|
||||
}
|
||||
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
|
||||
DataSet dataSet = new DataSet();
|
||||
adapter.Fill(dataSet, tabName);
|
||||
set2 = dataSet;
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
return set2;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ExecuteNonQuery
|
||||
/// <summary>
|
||||
/// <para>说明:执行sql语句或者存储过程</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-07-24 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="cmdType">Type of the command.</param>
|
||||
/// <param name="cmdText">The command text.</param>
|
||||
/// <param name="commandParameters">The command parameters.</param>
|
||||
/// <returns>System.Int32.</returns>
|
||||
public int ExecuteNonQuery(CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
|
||||
{
|
||||
SqlCommand cmd = new SqlCommand();
|
||||
int num = 0;
|
||||
try
|
||||
{
|
||||
PrepareCommand(cmd, _connection, null, cmdType, cmdText, commandParameters);
|
||||
num = cmd.ExecuteNonQuery();
|
||||
cmd.Parameters.Clear();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (e.Message.StartsWith("在从服务器接收结果时发生传输级错误") ||
|
||||
e.Message.StartsWith("在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误") ||
|
||||
e.Message.StartsWith("在向服务器发送请求时发生传输级错误"))
|
||||
{
|
||||
throw new Exception("无法连接服务器,请检查网络连接.");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Dispose();
|
||||
}
|
||||
return num;
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:执行sql语句或者存储过程</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-07-24 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="cmdType">Type of the command.</param>
|
||||
/// <param name="cmdText">The command text.</param>
|
||||
/// <returns>System.Int32.</returns>
|
||||
public int ExecuteNonQuery(CommandType cmdType, string cmdText)
|
||||
{
|
||||
return ExecuteNonQuery(CommandType.Text, cmdText, null);
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:执行sql语句或者存储过程</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-07-24 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="cmdText">The command text.</param>
|
||||
/// <returns>System.Int32.</returns>
|
||||
public int ExecuteNonQuery(string cmdText)
|
||||
{
|
||||
return ExecuteNonQuery(CommandType.Text, cmdText);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ExecuteReader
|
||||
/// <summary>
|
||||
/// <para>说明:执行sql语句或者存储过程并返回结果集(只读、只进)</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-07-24 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="cmdType">Type of the command.</param>
|
||||
/// <param name="cmdText">The command text.</param>
|
||||
/// <param name="commandParameters">The command parameters.</param>
|
||||
/// <returns>SqlDataReader.</returns>
|
||||
public SqlDataReader ExecuteReader(CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
|
||||
{
|
||||
SqlDataReader reader2;
|
||||
SqlCommand cmd = new SqlCommand();
|
||||
try
|
||||
{
|
||||
PrepareCommand(cmd, _connection, null, cmdType, cmdText, commandParameters);
|
||||
SqlDataReader reader = cmd.ExecuteReader();
|
||||
cmd.Parameters.Clear();
|
||||
reader2 = reader;
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
return reader2;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ExecuteScalar
|
||||
/// <summary>
|
||||
/// <para>说明:执行sql语句或者存储过程并返回结果集第一行第一列</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-07-24 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="Connectionection">The connectionection.</param>
|
||||
/// <param name="cmdType">Type of the command.</param>
|
||||
/// <param name="cmdText">The command text.</param>
|
||||
/// <param name="commandParameters">The command parameters.</param>
|
||||
/// <returns>System.Object.</returns>
|
||||
public object ExecuteScalar(SqlConnection Connectionection, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
|
||||
{
|
||||
SqlCommand cmd = new SqlCommand();
|
||||
PrepareCommand(cmd, Connectionection, null, cmdType, cmdText, commandParameters);
|
||||
object obj2 = cmd.ExecuteScalar();
|
||||
cmd.Parameters.Clear();
|
||||
return obj2;
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:执行sql语句或者存储过程并返回结果集第一行第一列</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-07-24 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="cmdType">Type of the command.</param>
|
||||
/// <param name="cmdText">The command text.</param>
|
||||
/// <param name="commandParameters">The command parameters.</param>
|
||||
/// <returns>System.Object.</returns>
|
||||
public object ExecuteScalar(CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
|
||||
{
|
||||
SqlCommand cmd = new SqlCommand();
|
||||
{
|
||||
PrepareCommand(cmd, _connection, null, cmdType, cmdText, commandParameters);
|
||||
object obj2 = cmd.ExecuteScalar();
|
||||
cmd.Parameters.Clear();
|
||||
return obj2;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:执行sql语句或者存储过程并返回结果集第一行第一列</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-07-24 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="cmdType">Type of the command.</param>
|
||||
/// <param name="cmdText">The command text.</param>
|
||||
/// <returns>System.Object.</returns>
|
||||
public object ExecuteScalar(CommandType cmdType, string cmdText)
|
||||
{
|
||||
SqlCommand cmd = new SqlCommand();
|
||||
{
|
||||
PrepareCommand(cmd, _connection, null, cmdType, cmdText, null);
|
||||
object obj2 = cmd.ExecuteScalar();
|
||||
cmd.Parameters.Clear();
|
||||
return obj2;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:执行sql语句或者存储过程并返回结果集第一行第一列</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-08-21 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="cmdText">The command text.</param>
|
||||
/// <returns>System.Object.</returns>
|
||||
public object ExecuteScalar(string cmdText)
|
||||
{
|
||||
SqlCommand cmd = new SqlCommand();
|
||||
{
|
||||
PrepareCommand(cmd, _connection, null, CommandType.Text, cmdText, null);
|
||||
object obj2 = cmd.ExecuteScalar();
|
||||
cmd.Parameters.Clear();
|
||||
return obj2;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region PrepareCommand
|
||||
/// <summary>
|
||||
/// <para>说明: sql参数处理</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-07-24 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="cmd">The command.</param>
|
||||
/// <param name="Connection">The connection.</param>
|
||||
/// <param name="trans">The trans.</param>
|
||||
/// <param name="cmdType">Type of the command.</param>
|
||||
/// <param name="cmdText">The command text.</param>
|
||||
/// <param name="cmdParms">The command parms.</param>
|
||||
private void PrepareCommand(SqlCommand cmd, SqlConnection Connection, SqlTransaction trans, CommandType cmdType, string cmdText, SqlParameter[] cmdParms)
|
||||
{
|
||||
if (Connection.State != ConnectionState.Open)
|
||||
{
|
||||
Connection.Open();
|
||||
}
|
||||
cmd.Connection = Connection;
|
||||
cmd.CommandTimeout = CommandTimeout;
|
||||
cmd.CommandText = cmdText;
|
||||
if (trans != null)
|
||||
{
|
||||
cmd.Transaction = trans;
|
||||
}
|
||||
cmd.CommandType = cmdType;
|
||||
if (cmdParms != null)
|
||||
{
|
||||
foreach (SqlParameter parameter in cmdParms)
|
||||
{
|
||||
cmd.Parameters.Add(parameter);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,884 @@
|
||||
using MySql.Data.MySqlClient;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace AfkDataService
|
||||
{
|
||||
public class SynchData
|
||||
{
|
||||
public FrmMain frmMain;
|
||||
/// <summary>
|
||||
/// sqlserver连接对象
|
||||
/// </summary>
|
||||
public AfkDataService.SqlHelper SqlHelper;
|
||||
/// <summary>
|
||||
/// sql连接字符串
|
||||
/// </summary>
|
||||
public string SqlConnectStr;
|
||||
/// <summary>
|
||||
/// mysql连接对象
|
||||
/// </summary>
|
||||
public AfkDataService.MySqlHelper MySqlHelper;
|
||||
/// <summary>
|
||||
/// mysql连接字符串
|
||||
/// </summary>
|
||||
public string MySqlConnectStr;
|
||||
public SynchData(AfkDataService.SqlHelper sqlHelper, AfkDataService.MySqlHelper mySqlHelper)
|
||||
{
|
||||
this.SqlHelper = sqlHelper;
|
||||
this.MySqlHelper = mySqlHelper;
|
||||
}
|
||||
/// <summary>
|
||||
/// 判断表是否存在
|
||||
/// </summary>
|
||||
/// <param name="abutmentModel"></param>
|
||||
private void CreateTable(AbutmentModel abutmentModel)
|
||||
{
|
||||
if (abutmentModel.dataDirection == DataDirection.AfkToLs)//afk到ls
|
||||
{
|
||||
// 获取lsSQL表结构
|
||||
DataTable schemaTable = SqlHelper.ExecuteDataTable($"select * from information_schema.columns where table_name = '{abutmentModel.lsTabName}'");
|
||||
if (!CheckIfTableExists(abutmentModel.lsTempTabName, SqlHelper))
|
||||
{
|
||||
CreateSqlServerTableWithSpecialFields(abutmentModel.lsTempTabName, schemaTable, SqlHelper);
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 同步数据表
|
||||
/// </summary>
|
||||
/// <param name="abutmentModel"></param>
|
||||
public bool SyncDataTable(AbutmentModel abutmentModel)
|
||||
{
|
||||
bool isSuccess = false;
|
||||
abutmentModel.allCount = 0;
|
||||
if (abutmentModel.dataDirection == DataDirection.AfkToLs)//afk到ls
|
||||
{
|
||||
try
|
||||
{
|
||||
CreateTable(abutmentModel);
|
||||
// 同步数据
|
||||
using (var bulkCopy = new SqlBulkCopy(SqlHelper._connection))
|
||||
{
|
||||
bulkCopy.DestinationTableName = abutmentModel.lsTempTabName;
|
||||
bulkCopy.BulkCopyTimeout = 0;
|
||||
string sourceSelectFields = GetSelectFieldsStr(abutmentModel).ToString();
|
||||
abutmentModel.allCount = Convert.ToInt32(MySqlHelper.ExecuteScalar($"select count(*) from {abutmentModel.afkTabName} {abutmentModel.sourceWhereCond}") + "");
|
||||
for (int i = 0; i <= abutmentModel.allCount; i += 10000)
|
||||
{
|
||||
try
|
||||
{
|
||||
string selectSourceSql = string.Format("select {0} from {1} {2}", sourceSelectFields.TrimEnd(','), abutmentModel.afkTabName, abutmentModel.sourceWhereCond + $" limit {i},10000");
|
||||
DataTable dataTable = MySqlHelper.ExecuteDataTable(selectSourceSql);
|
||||
bulkCopy.ColumnMappings.Clear();
|
||||
foreach (DataColumn item in dataTable.Columns)
|
||||
{
|
||||
bulkCopy.ColumnMappings.Add(item.ColumnName, item.ColumnName);
|
||||
}
|
||||
bulkCopy.WriteToServer(dataTable);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
frmMain.SendMessage(frmMain.toLsTextBox, $"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}:同步表{abutmentModel.afkTabName}==>{abutmentModel.lsTempTabName}成功\r\n");
|
||||
isSuccess = true;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
frmMain.SendMessage(frmMain.toLsTextBox, $"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}:同步表{abutmentModel.afkTabName}==>{abutmentModel.lsTempTabName}失败,原因:{ex.Message}\r\n后续步骤已终止\r\n");
|
||||
string remarkSql = $"insert into p_remarktable (lstablename,primkey,primkeyvalue,messages,recordingtime) values " +
|
||||
$"('{abutmentModel.lsTempTabName}','uuid','{abutmentModel.uuid}','批量同步到朗速失败,原因:{ex.Message.Replace("'", "''")}','{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}')";
|
||||
try
|
||||
{
|
||||
SqlHelper.ExecuteNonQuery(remarkSql);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (abutmentModel.dataDirection == DataDirection.LsToAfk)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 同步数据
|
||||
using (MySqlConnector.MySqlConnection MySqlConnection = new MySqlConnector.MySqlConnection(MySqlConnectStr + "AllowLoadLocalInfile=true;"))
|
||||
{
|
||||
var mySqlBulkCopy = new MySqlConnector.MySqlBulkCopy(MySqlConnection);
|
||||
mySqlBulkCopy.DestinationTableName = abutmentModel.afkTabName;
|
||||
string sourceSelectFields = GetSelectFieldsStr(abutmentModel).ToString();
|
||||
string dourceSql = string.Format("select {0} from {1}{2}", sourceSelectFields.TrimEnd(','), abutmentModel.lsTabName, abutmentModel.sourceWhereCond);
|
||||
DataTable dataTable = SqlHelper.ExecuteDataTable(dourceSql);
|
||||
abutmentModel.allCount = dataTable.Rows.Count;
|
||||
for (int i = 0; i < dataTable.Columns.Count; i++)
|
||||
{
|
||||
DataColumn item = dataTable.Columns[i];
|
||||
MySqlConnector.MySqlBulkCopyColumnMapping mySqlBulkCopyColumnMapping = new MySqlConnector.MySqlBulkCopyColumnMapping();
|
||||
mySqlBulkCopyColumnMapping.SourceOrdinal = i;
|
||||
mySqlBulkCopyColumnMapping.DestinationColumn = item.ColumnName;
|
||||
mySqlBulkCopy.ColumnMappings.Add(mySqlBulkCopyColumnMapping);
|
||||
}
|
||||
mySqlBulkCopy.WriteToServer(dataTable);
|
||||
frmMain.SendMessage(frmMain.toAfkTextBox, $"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}:同步表{abutmentModel.lsTabName}==>{abutmentModel.afkTabName}成功\r\n");
|
||||
isSuccess = true;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
frmMain.SendMessage(frmMain.toAfkTextBox, $"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}:同步表{abutmentModel.lsTabName}==>{abutmentModel.afkTabName}失败,原因:{ex.Message}\r\n后续步骤已终止\r\n");
|
||||
string remarkSql = $"insert into p_remarktable (lstablename,primkey,primkeyvalue,messages,recordingtime) values " +
|
||||
$"('{ abutmentModel.afkTabName}','uuid','{abutmentModel.uuid}','批量同步到中航失败,原因:{ex.Message.Replace("'", "''")}','{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}')";
|
||||
try
|
||||
{
|
||||
SqlHelper.ExecuteNonQuery(remarkSql);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
return isSuccess;
|
||||
}
|
||||
/// <summary>
|
||||
/// 执行同步后的业务存储过程
|
||||
/// </summary>
|
||||
/// <param name="abutmentModel"></param>
|
||||
/// <returns></returns>
|
||||
public bool ExecBatchAfter(AbutmentModel abutmentModel)
|
||||
{
|
||||
bool isSucess = false;
|
||||
if (abutmentModel.dataDirection == DataDirection.AfkToLs)//afk到ls
|
||||
{
|
||||
if (!string.IsNullOrEmpty(abutmentModel.batchAfterSql))
|
||||
{
|
||||
try
|
||||
{
|
||||
int result = SqlHelper.ExecuteNonQuery(abutmentModel.batchAfterSql.Replace("{uuid}", abutmentModel.uuid));
|
||||
frmMain.SendMessage(frmMain.toLsTextBox, $"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}:业务逻辑判断完成\r\n");
|
||||
isSucess = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
frmMain.SendMessage(frmMain.toLsTextBox, $"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}:业务逻辑判断失败,原因:{ex.Message}\r\n后续步骤已终止\r\n");
|
||||
string remarkSql = $"insert into p_remarktable (lstablename,primkey,primkeyvalue,messages,recordingtime) values " +
|
||||
$"('{abutmentModel.batchAfterSql.Replace("'", "''")}','uuid','{abutmentModel.uuid}','执行业务存储过程失败,原因:{ex.Message.Replace("'", "''")}','{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}')";
|
||||
try
|
||||
{
|
||||
SqlHelper.ExecuteNonQuery(remarkSql);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
frmMain.SendMessage(frmMain.toLsTextBox, $"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}:业务逻辑判断完成\r\n");
|
||||
isSucess = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
isSucess = true;
|
||||
}
|
||||
return isSucess;
|
||||
}
|
||||
/// <summary>
|
||||
/// 发送日志
|
||||
/// </summary>
|
||||
/// <param name="abutmentModel"></param>
|
||||
/// <returns></returns>
|
||||
public bool SendLog(AbutmentModel abutmentModel)
|
||||
{
|
||||
bool isSuccess = false;
|
||||
if (abutmentModel.dataDirection == DataDirection.AfkToLs)//afk到ls
|
||||
{
|
||||
try
|
||||
{
|
||||
string sourceSelectFields = GetSelectFieldsStr(abutmentModel, true).ToString();
|
||||
if (!string.IsNullOrWhiteSpace(sourceSelectFields))
|
||||
{
|
||||
using (MySqlConnector.MySqlConnection MySqlConnection = new MySqlConnector.MySqlConnection(MySqlConnectStr + "AllowLoadLocalInfile=true;"))
|
||||
{
|
||||
var mySqlBulkCopy = new MySqlConnector.MySqlBulkCopy(MySqlConnection);
|
||||
mySqlBulkCopy.DestinationTableName = abutmentModel.logTabName;
|
||||
mySqlBulkCopy.BulkCopyTimeout = 0;
|
||||
string logSourceSql = string.Format("select {0} from {1} where uuid = '{2}'", sourceSelectFields.TrimEnd(','), abutmentModel.lsTempTabName, abutmentModel.uuid);
|
||||
DataTable logDataTable = SqlHelper.ExecuteDataTable(logSourceSql);
|
||||
int count = logDataTable.Rows.Count;
|
||||
if (count != abutmentModel.allCount)
|
||||
{
|
||||
throw new Exception($"同步数据与日志数据条数不一致,同步数据{abutmentModel.allCount}条,日志数据{count}条,uuid:{abutmentModel.uuid}");
|
||||
}
|
||||
for (int i = 0; i < logDataTable.Columns.Count; i++)
|
||||
{
|
||||
DataColumn item = logDataTable.Columns[i];
|
||||
MySqlConnector.MySqlBulkCopyColumnMapping mySqlBulkCopyColumnMapping = new MySqlConnector.MySqlBulkCopyColumnMapping();
|
||||
mySqlBulkCopyColumnMapping.SourceOrdinal = i;
|
||||
mySqlBulkCopyColumnMapping.DestinationColumn = item.ColumnName;
|
||||
mySqlBulkCopy.ColumnMappings.Add(mySqlBulkCopyColumnMapping);
|
||||
}
|
||||
mySqlBulkCopy.WriteToServer(logDataTable);
|
||||
frmMain.SendMessage(frmMain.toLsTextBox, $"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}:反写日志==>{abutmentModel.logTabName}成功\r\n");
|
||||
isSuccess = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//未配置日志表
|
||||
frmMain.SendMessage(frmMain.toLsTextBox, $"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}:反写日志==>{abutmentModel.logTabName}成功,但未查询到对应日志表\r\n");
|
||||
isSuccess = true;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
frmMain.SendMessage(frmMain.toLsTextBox, $"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}:反写日志==>{abutmentModel.logTabName}失败,原因{ex.Message}\r\n后续步骤已终止\r\n");
|
||||
string remarkSql = $"insert into p_remarktable (lstablename,primkey,primkeyvalue,messages,recordingtime) values " +
|
||||
$"('{abutmentModel.logTabName}','uuid','{abutmentModel.uuid}','批量同步到朗速的数据记录到中航日志表失败,原因:{ex.Message.Replace("'", "''")}','{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}')";
|
||||
try
|
||||
{
|
||||
SqlHelper.ExecuteNonQuery(remarkSql);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (abutmentModel.dataDirection == DataDirection.LsToAfk)
|
||||
{
|
||||
try
|
||||
{
|
||||
string sourceSelectFields = GetSelectFieldsStr(abutmentModel, true).ToString();
|
||||
if (!string.IsNullOrWhiteSpace(sourceSelectFields))
|
||||
{
|
||||
using (MySqlConnector.MySqlConnection MySqlConnection = new MySqlConnector.MySqlConnection(MySqlConnectStr + "AllowLoadLocalInfile=true;"))
|
||||
{
|
||||
var mySqlBulkCopy = new MySqlConnector.MySqlBulkCopy(MySqlConnection);
|
||||
mySqlBulkCopy.DestinationTableName = abutmentModel.logTabName;
|
||||
string logSourceSql = string.Format("select {0} from {1}{2}", sourceSelectFields.TrimEnd(','), abutmentModel.lsTabName, abutmentModel.sourceWhereCond);
|
||||
DataTable logDataTable = SqlHelper.ExecuteDataTable(logSourceSql);
|
||||
int count = logDataTable.Rows.Count;
|
||||
if (count != abutmentModel.allCount)
|
||||
{
|
||||
throw new Exception($"同步数据与日志数据条数不一致,同步数据{abutmentModel.allCount}条,日志数据{count}条,uuid:{abutmentModel.uuid}");
|
||||
}
|
||||
for (int i = 0; i < logDataTable.Columns.Count; i++)
|
||||
{
|
||||
DataColumn item = logDataTable.Columns[i];
|
||||
MySqlConnector.MySqlBulkCopyColumnMapping mySqlBulkCopyColumnMapping = new MySqlConnector.MySqlBulkCopyColumnMapping();
|
||||
mySqlBulkCopyColumnMapping.SourceOrdinal = i;
|
||||
mySqlBulkCopyColumnMapping.DestinationColumn = item.ColumnName;
|
||||
mySqlBulkCopy.ColumnMappings.Add(mySqlBulkCopyColumnMapping);
|
||||
}
|
||||
mySqlBulkCopy.WriteToServer(logDataTable);
|
||||
frmMain.SendMessage(frmMain.toAfkTextBox, $"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}:反写日志==>{abutmentModel.logTabName}成功\r\n");
|
||||
isSuccess = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//未配置日志表
|
||||
frmMain.SendMessage(frmMain.toAfkTextBox, $"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}:反写日志==>{abutmentModel.logTabName}成功,但未查询到对应日志表\r\n");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
frmMain.SendMessage(frmMain.toAfkTextBox, $"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}:反写日志==>{abutmentModel.logTabName}失败,原因{ex.Message}\r\n后续步骤已终止\r\n");
|
||||
string remarkSql = $"insert into p_remarktable (lstablename,primkey,primkeyvalue,messages,recordingtime) values " +
|
||||
$"('{ abutmentModel.logTabName}','uuid','{abutmentModel.uuid}','批量同步到中航的数据记录到中航日志表失败,原因:{ex.Message.Replace("'", "''")}','{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}')";
|
||||
try
|
||||
{
|
||||
SqlHelper.ExecuteNonQuery(remarkSql);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
return isSuccess;
|
||||
}
|
||||
/// <summary>
|
||||
/// 同步完成后更改状态
|
||||
/// </summary>
|
||||
/// <param name="abutmentModel"></param>
|
||||
/// <returns></returns>
|
||||
public bool AfterSync(AbutmentModel abutmentModel)
|
||||
{
|
||||
bool isSuccess = false;
|
||||
if (abutmentModel.dataDirection == DataDirection.AfkToLs)//afk到ls
|
||||
{
|
||||
//所有操作完成后删除中航中间表已同步完成数据
|
||||
string deleteSql = string.Format("delete from {0} {1}", abutmentModel.afkTabName, abutmentModel.sourceWhereCond);
|
||||
try
|
||||
{
|
||||
MySqlHelper.ExecuteNonQuery(deleteSql);
|
||||
isSuccess = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
string remarkSql = $"insert into p_remarktable (lstablename,primkey,primkeyvalue,messages,recordingtime) values " +
|
||||
$"('{abutmentModel.afkTabName}','uuid','{abutmentModel.uuid}','删除已同步中间表数据失败,原因:{ex.Message.Replace("'", "''")}','{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}')";
|
||||
try
|
||||
{
|
||||
SqlHelper.ExecuteNonQuery(remarkSql);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (abutmentModel.dataDirection == DataDirection.LsToAfk)
|
||||
{
|
||||
//所有操作完成后更改朗速中间表已同步完成数据同步标记
|
||||
string updateSql = string.Format("update {0} set directTag = '2' {1}", abutmentModel.lsTabName, abutmentModel.sourceWhereCond);
|
||||
try
|
||||
{
|
||||
SqlHelper.ExecuteNonQuery(updateSql);
|
||||
isSuccess = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
string remarkSql = $"insert into p_remarktable (lstablename,primkey,primkeyvalue,messages,recordingtime) values " +
|
||||
$"('{abutmentModel.afkTabName}','uuid','{abutmentModel.uuid}','删除已同步中间表数据失败,原因:{ex.Message.Replace("'", "''")}','{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}')";
|
||||
try
|
||||
{
|
||||
SqlHelper.ExecuteNonQuery(remarkSql);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
return isSuccess;
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:创建Afk向朗速传递数据的同步方法</para>
|
||||
/// <para>创建人:王一帆</para>
|
||||
/// <para>创建日期:2023-11-10 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="sqlServerTableName">Ls方需要构建的表</param>
|
||||
/// <param name="mysqlTableName">Afk方需要构建的表</param>
|
||||
/// <param name="specialFieldNames">特殊不同字段集合</param>
|
||||
public void CreateAndSyncTable(AbutmentModel abutmentModel, bool isSync = true, bool isExecAfter = true, bool isSendLog = true, bool isDeleteSync = true)
|
||||
{
|
||||
if (abutmentModel.dataDirection == DataDirection.AfkToLs)//afk到ls
|
||||
{
|
||||
// 获取MySQL表结构
|
||||
DataTable schemaTable = GetSchemaTable(abutmentModel.afkTabName, MySqlHelper);
|
||||
if (!CheckIfTableExists(abutmentModel.lsTempTabName, SqlHelper))
|
||||
{
|
||||
CreateSqlServerTableWithSpecialFields(abutmentModel.lsTempTabName, schemaTable, SqlHelper);
|
||||
}
|
||||
if (isSync)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 同步数据
|
||||
using (var bulkCopy = new SqlBulkCopy(SqlHelper._connection))
|
||||
{
|
||||
bulkCopy.DestinationTableName = abutmentModel.lsTempTabName;
|
||||
bulkCopy.BulkCopyTimeout = 0;
|
||||
string sourceSelectFields = GetSelectFieldsStr(abutmentModel).ToString();
|
||||
string selectSourceSql = string.Format("select {0} from {1}{2}", sourceSelectFields.TrimEnd(','), abutmentModel.afkTabName, abutmentModel.sourceWhereCond);
|
||||
DataTable dataTable = MySqlHelper.ExecuteDataTable(selectSourceSql);
|
||||
foreach (DataColumn item in dataTable.Columns)
|
||||
{
|
||||
bulkCopy.ColumnMappings.Add(item.ColumnName, item.ColumnName);
|
||||
}
|
||||
bulkCopy.WriteToServer(dataTable);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
string remarkSql = $"insert into p_remarktable (lstablename,primkey,primkeyvalue,messages,recordingtime) values " +
|
||||
$"('{abutmentModel.lsTempTabName}','uuid','{abutmentModel.uuid}','批量同步到朗速失败,原因:{ex.Message.Replace("'", "''")}','{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}')";
|
||||
try
|
||||
{
|
||||
SqlHelper.ExecuteNonQuery(remarkSql);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
//同步后执行存储过程
|
||||
if (isExecAfter)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(abutmentModel.batchAfterSql))
|
||||
{
|
||||
try
|
||||
{
|
||||
int result = SqlHelper.ExecuteNonQuery(abutmentModel.batchAfterSql.Replace("{uuid}", abutmentModel.uuid));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
string remarkSql = $"insert into p_remarktable (lstablename,primkey,primkeyvalue,messages,recordingtime) values " +
|
||||
$"('{abutmentModel.batchAfterSql.Replace("'", "''")}','uuid','{abutmentModel.uuid}','执行业务存储过程失败,原因:{ex.Message.Replace("'", "''")}','{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}')";
|
||||
try
|
||||
{
|
||||
SqlHelper.ExecuteNonQuery(remarkSql);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
//同步到ls后向中航方写入日志数据
|
||||
if (isSendLog)
|
||||
{
|
||||
try
|
||||
{
|
||||
string sourceSelectFields = GetSelectFieldsStr(abutmentModel, true).ToString();
|
||||
if (!string.IsNullOrWhiteSpace(sourceSelectFields))
|
||||
{
|
||||
using (MySqlConnector.MySqlConnection MySqlConnection = new MySqlConnector.MySqlConnection(MySqlConnectStr + "AllowLoadLocalInfile=true;"))
|
||||
{
|
||||
var mySqlBulkCopy = new MySqlConnector.MySqlBulkCopy(MySqlConnection);
|
||||
mySqlBulkCopy.DestinationTableName = abutmentModel.logTabName;
|
||||
mySqlBulkCopy.BulkCopyTimeout = 0;
|
||||
string logSourceSql = string.Format("select {0} from {1} where uuid = '{2}'", sourceSelectFields.TrimEnd(','), abutmentModel.lsTempTabName, abutmentModel.uuid);
|
||||
DataTable logDataTable = SqlHelper.ExecuteDataTable(logSourceSql);
|
||||
mySqlBulkCopy.WriteToServer(logDataTable);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//未配置日志表
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
string remarkSql = $"insert into p_remarktable (lstablename,primkey,primkeyvalue,messages,recordingtime) values " +
|
||||
$"('{abutmentModel.logTabName}','uuid','{abutmentModel.uuid}','批量同步到朗速的数据记录到中航日志表失败,原因:{ex.Message.Replace("'", "''")}','{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}')";
|
||||
try
|
||||
{
|
||||
SqlHelper.ExecuteNonQuery(remarkSql);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
//所有操作完成后删除中航中间表已同步完成数据
|
||||
if (isDeleteSync)
|
||||
{
|
||||
//string deleteSql = string.Format("delete from {0} {1}", abutmentModel.afkTabName, abutmentModel.sourceWhereCond);
|
||||
//try
|
||||
//{
|
||||
// MySqlHelper.ExecuteNonQuery(deleteSql);
|
||||
//}
|
||||
//catch (Exception ex)
|
||||
//{
|
||||
// string remarkSql = $"insert into p_remarktable (lstablename,primkey,primkeyvalue,messages,recordingtime) values " +
|
||||
// $"('{abutmentModel.afkTabName}','uuid','{abutmentModel.uuid}','删除已同步中间表数据失败,原因:{ex.Message.Replace("'", "''")}','{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}')";
|
||||
// try
|
||||
// {
|
||||
// SqlHelper.ExecuteNonQuery(remarkSql);
|
||||
// }
|
||||
// catch (Exception e)
|
||||
// {
|
||||
// Console.WriteLine(e.Message);
|
||||
// }
|
||||
// return;
|
||||
//}
|
||||
}
|
||||
}
|
||||
else if (abutmentModel.dataDirection == DataDirection.LsToAfk)//ls到afk
|
||||
{
|
||||
try
|
||||
{
|
||||
// 同步数据
|
||||
using (MySqlConnector.MySqlConnection MySqlConnection = new MySqlConnector.MySqlConnection(MySqlConnectStr))
|
||||
{
|
||||
var mySqlBulkCopy = new MySqlConnector.MySqlBulkCopy(MySqlConnection);
|
||||
mySqlBulkCopy.DestinationTableName = abutmentModel.afkTabName;
|
||||
string sourceSelectFields = GetSelectFieldsStr(abutmentModel).ToString();
|
||||
string dourceSql = string.Format("select {0} from {1}{2}", sourceSelectFields.TrimEnd(','), abutmentModel.lsTabName, abutmentModel.sourceWhereCond);
|
||||
DataTable dataTable = SqlHelper.ExecuteDataTable(dourceSql);
|
||||
mySqlBulkCopy.WriteToServer(dataTable);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
string remarkSql = $"insert into p_remarktable (lstablename,primkey,primkeyvalue,messages,recordingtime) values " +
|
||||
$"('{ abutmentModel.afkTabName}','uuid','{abutmentModel.uuid}','批量同步到中航失败,原因:{ex.Message.Replace("'", "''")}','{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}')";
|
||||
try
|
||||
{
|
||||
SqlHelper.ExecuteNonQuery(remarkSql);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
}
|
||||
return;
|
||||
}
|
||||
//同步到afk后向中航方写入日志数据
|
||||
try
|
||||
{
|
||||
string sourceSelectFields = GetSelectFieldsStr(abutmentModel, true).ToString();
|
||||
if (!string.IsNullOrWhiteSpace(sourceSelectFields))
|
||||
{
|
||||
using (MySqlConnector.MySqlConnection MySqlConnection = new MySqlConnector.MySqlConnection(MySqlConnectStr))
|
||||
{
|
||||
var mySqlBulkCopy = new MySqlConnector.MySqlBulkCopy(MySqlConnection);
|
||||
mySqlBulkCopy.DestinationTableName = abutmentModel.logTabName;
|
||||
string logSourceSql = string.Format("select {0} from {1}{2}", sourceSelectFields.TrimEnd(','), abutmentModel.lsTabName, abutmentModel.sourceWhereCond);
|
||||
DataTable logDataTable = MySqlHelper.ExecuteDataTable(logSourceSql);
|
||||
mySqlBulkCopy.WriteToServer(logDataTable);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//未配置日志表
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
string remarkSql = $"insert into p_remarktable (lstablename,primkey,primkeyvalue,messages,recordingtime) values " +
|
||||
$"('{ abutmentModel.logTabName}','uuid','{abutmentModel.uuid}','批量同步到中航的数据记录到中航日志表失败,原因:{ex.Message.Replace("'", "''")}','{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}')";
|
||||
try
|
||||
{
|
||||
SqlHelper.ExecuteNonQuery(remarkSql);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
}
|
||||
return;
|
||||
}
|
||||
//所有操作完成后更改朗速中间表已同步完成数据同步标记
|
||||
//string updateSql = string.Format("update {0} set directTag = '2' where {1}", abutmentModel.lsTabName, abutmentModel.sourceWhereCond);
|
||||
//try
|
||||
//{
|
||||
// SqlHelper.ExecuteNonQuery(updateSql);
|
||||
//}
|
||||
//catch (Exception ex)
|
||||
//{
|
||||
// string remarkSql = $"insert into p_remarktable (lstablename,primkey,primkeyvalue,messages,recordingtime) values " +
|
||||
// $"('{abutmentModel.afkTabName}','uuid','{abutmentModel.uuid}','删除已同步中间表数据失败,原因:{ex.Message.Replace("'", "''")}','{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}')";
|
||||
// try
|
||||
// {
|
||||
// SqlHelper.ExecuteNonQuery(remarkSql);
|
||||
// }
|
||||
// catch (Exception e)
|
||||
// {
|
||||
// Console.WriteLine(e.Message);
|
||||
// }
|
||||
// return;
|
||||
//}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:获取mysql表中的列信息方便调用时候直接取用</para>
|
||||
/// <para>创建人:王一帆</para>
|
||||
/// <para>创建日期:2023-11-10 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="tableName">mysql表名</param>
|
||||
/// <param name="connection">MySqlConnection的连接</param>
|
||||
/// <returns></returns>
|
||||
private DataTable GetSchemaTable(string tableName, AfkDataService.MySqlHelper mySqlHelper)
|
||||
{
|
||||
DataTable schemaTable = new DataTable();
|
||||
try
|
||||
{
|
||||
schemaTable = mySqlHelper.ExecuteDataTable($"DESCRIBE {tableName}");
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
}
|
||||
return schemaTable;
|
||||
}
|
||||
private DataTable GetSchemaTable(string tableName, AfkDataService.SqlHelper sqlHelper)
|
||||
{
|
||||
DataTable schemaTable = new DataTable();
|
||||
try
|
||||
{
|
||||
schemaTable = sqlHelper.ExecuteDataTable($"Select * FROM SysColumns Where id = Object_Id ('{tableName}')");
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
}
|
||||
return schemaTable;
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:判断Ls数据库中是否存在需要同步的表名</para>
|
||||
/// <para>创建人:王一帆</para>
|
||||
/// <para>创建日期:2023-11-10 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="tableName">表名</param>
|
||||
/// <param name="connection">SqlConnection的连接</param>
|
||||
/// <returns></returns>
|
||||
private bool CheckIfTableExists(string tableName, AfkDataService.SqlHelper sqlHelper)
|
||||
{
|
||||
bool result = false;
|
||||
try
|
||||
{
|
||||
result = 1 == (int)sqlHelper.ExecuteScalar($"SELECT CASE WHEN EXISTS((SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = '{tableName}')) THEN 1 ELSE 0 END");
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:通过对应的数据结构进行同步</para>
|
||||
/// <para>创建人:王一帆</para>
|
||||
/// <para>创建日期:2023-11-10 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="tableName">Ls方需要构建的表名</param>
|
||||
/// <param name="schemaTable"></param>
|
||||
/// <param name="specialFieldNames"></param>
|
||||
/// <param name="connection"></param>
|
||||
private void CreateSqlServerTableWithSpecialFields(string tableName, DataTable schemaTable, SqlHelper sqlHelper)
|
||||
{
|
||||
StringBuilder sqlBuilder = new StringBuilder();
|
||||
// 创建表的SQL语句
|
||||
sqlBuilder.Append($"CREATE TABLE {tableName} (");
|
||||
|
||||
foreach (DataRow row in schemaTable.Rows)
|
||||
{
|
||||
var columnName = row["column_name"] + "";
|
||||
var columnType = row["data_type"] + "";
|
||||
var length = row["character_maximum_length"] + "";
|
||||
var number = row["NUMERIC_SCALE"] + "";
|
||||
//跳过自增长列
|
||||
//if (extra.Equals("auto_increment", StringComparison.OrdinalIgnoreCase))
|
||||
//{
|
||||
// continue;
|
||||
//}
|
||||
// 转换MySQL数据类型到SQL Server数据类型
|
||||
if (columnType.StartsWith("varchar"))
|
||||
{
|
||||
sqlBuilder.Append($"[{columnName}] varchar({length}), ");
|
||||
}
|
||||
else if (columnType.StartsWith("int"))
|
||||
{
|
||||
sqlBuilder.Append($"[{columnName}] int, ");
|
||||
}
|
||||
else if (columnType.StartsWith("decimal"))
|
||||
{
|
||||
sqlBuilder.Append($"[{columnName}] decimal(18,{number}), ");
|
||||
}
|
||||
else if (columnType.StartsWith("datetime"))
|
||||
{
|
||||
sqlBuilder.Append($"[{columnName}] datetime, ");
|
||||
}
|
||||
else
|
||||
{
|
||||
sqlBuilder.Append($"[{columnName}] varchar(max), ");
|
||||
}
|
||||
}
|
||||
sqlBuilder.Append($"[synchroSuccess] varchar(1000), ");
|
||||
sqlBuilder.Append($"[synchroMessage] varchar(1000), ");
|
||||
sqlBuilder.Append($"[uuid] varchar(1000), ");
|
||||
sqlHelper.ExecuteNonQuery(sqlBuilder.ToString().TrimEnd(',', ' ') + ")");
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取查询列字段集合
|
||||
/// </summary>
|
||||
/// <param name="abutmentModel"></param>
|
||||
/// <returns></returns>
|
||||
private StringBuilder GetSelectFieldsStr(AbutmentModel abutmentModel, bool isLog = false)
|
||||
{
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
try
|
||||
{
|
||||
string[] lsTargeFieldsArray = abutmentModel.lsTargeFields.Split(',');
|
||||
string[] afkTargeFieldsArray = abutmentModel.afkTargeFields.Split(',');
|
||||
DataTable mySqlSchemaTable = new DataTable();
|
||||
DataTable sqlServerSchemaTable = new DataTable();
|
||||
if (abutmentModel.dataDirection == DataDirection.AfkToLs)
|
||||
{
|
||||
sqlServerSchemaTable = SqlHelper.ExecuteDataTable($"Select name FROM SysColumns Where id = Object_Id ('{abutmentModel.lsTempTabName}')");
|
||||
if (!isLog)
|
||||
{
|
||||
mySqlSchemaTable = MySqlHelper.ExecuteDataTable($"DESCRIBE {abutmentModel.afkTabName}");
|
||||
for (int i = 0; i < afkTargeFieldsArray.Length; i++)
|
||||
{
|
||||
string columnName = afkTargeFieldsArray[i].Trim();
|
||||
DataRow colDataRow = mySqlSchemaTable.Rows.Cast<DataRow>().Where(n => (n["Field"] + "").Equals(columnName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
|
||||
string lsColName = lsTargeFieldsArray[i].Trim();
|
||||
DataRow selectRow = sqlServerSchemaTable.Rows.Cast<DataRow>().Where(n => (n["name"] + "").Equals(lsColName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
|
||||
if (colDataRow != null && selectRow != null)
|
||||
{
|
||||
stringBuilder.Append($"{columnName} as {selectRow["name"]},");
|
||||
}
|
||||
}
|
||||
stringBuilder.Append($"'{abutmentModel.uuid}' as uuid,");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(abutmentModel.logTabName))
|
||||
{
|
||||
return stringBuilder;
|
||||
}
|
||||
mySqlSchemaTable = MySqlHelper.ExecuteDataTable($"DESCRIBE {abutmentModel.logTabName}");
|
||||
for (int i = 0; i < lsTargeFieldsArray.Length; i++)
|
||||
{
|
||||
string columnName = lsTargeFieldsArray[i].Trim();
|
||||
DataRow colDataRow = sqlServerSchemaTable.Rows.Cast<DataRow>().Where(n => (n["name"] + "").Equals(columnName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
|
||||
string afkColName = afkTargeFieldsArray[i].Trim();
|
||||
DataRow selectRow = mySqlSchemaTable.Rows.Cast<DataRow>().Where(n => !(n["Extra"] + "").Equals("auto_increment", StringComparison.OrdinalIgnoreCase) && (n["Field"] + "").Equals(afkColName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
|
||||
if (colDataRow != null && selectRow != null)
|
||||
{
|
||||
stringBuilder.Append($"{columnName} as {selectRow["Field"]},");
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < abutmentModel.logAsFields.Length; i++)
|
||||
{
|
||||
string logAsField = abutmentModel.logAsFields[i];
|
||||
DataRow selectRow = mySqlSchemaTable.Rows.Cast<DataRow>().Where(n => !(n["Extra"] + "").Equals("auto_increment", StringComparison.OrdinalIgnoreCase) && (n["Field"] + "").Equals(abutmentModel.logFields[i], StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
|
||||
if (logAsField.Equals("@ErrorType", StringComparison.OrdinalIgnoreCase) && sqlServerSchemaTable.Rows.Cast<DataRow>().Where(n => (n["name"] + "").Equals("synchroSuccess", StringComparison.OrdinalIgnoreCase)).Count() > 0)
|
||||
{
|
||||
stringBuilder.Append($"(case when synchroSuccess = '成功' then '0' else '1' end) as {selectRow["Field"]},");
|
||||
}
|
||||
else if (logAsField.Equals("@ErrorMessage", StringComparison.OrdinalIgnoreCase) && sqlServerSchemaTable.Rows.Cast<DataRow>().Where(n => (n["name"] + "").Equals("synchroMessage", StringComparison.OrdinalIgnoreCase)).Count() > 0)
|
||||
{
|
||||
stringBuilder.Append($"(synchroSuccess + synchroMessage) as {selectRow["Field"]},");
|
||||
}
|
||||
else if (logAsField.Equals("@TransferLogo", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
stringBuilder.Append($"(case when synchroSuccess = '成功' then '1' else '2' end) as {selectRow["Field"]},");
|
||||
}
|
||||
else if (logAsField.Equals("getdate()", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
stringBuilder.Append($"getdate() as {selectRow["Field"]},");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (abutmentModel.dataDirection == DataDirection.LsToAfk)
|
||||
{
|
||||
sqlServerSchemaTable = SqlHelper.ExecuteDataTable($"Select name FROM SysColumns Where id = Object_Id ('{abutmentModel.lsTabName}')");
|
||||
if (!isLog)
|
||||
{
|
||||
mySqlSchemaTable = MySqlHelper.ExecuteDataTable($"DESCRIBE {abutmentModel.afkTabName}");
|
||||
for (int i = 0; i < lsTargeFieldsArray.Length; i++)
|
||||
{
|
||||
string columnName = lsTargeFieldsArray[i].Trim();
|
||||
DataRow colDataRow = sqlServerSchemaTable.Rows.Cast<DataRow>().Where(n => (n["name"] + "").Equals(columnName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
|
||||
string afkColName = afkTargeFieldsArray[i].Trim();
|
||||
DataRow selectRow = mySqlSchemaTable.Rows.Cast<DataRow>().Where(n => !(n["Extra"] + "").Equals("auto_increment", StringComparison.OrdinalIgnoreCase) && (n["Field"] + "").Equals(afkColName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
|
||||
if (colDataRow != null && selectRow != null)
|
||||
{
|
||||
stringBuilder.Append($"{columnName} as {selectRow["Field"]},");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(abutmentModel.logTabName))
|
||||
{
|
||||
return stringBuilder;
|
||||
}
|
||||
mySqlSchemaTable = MySqlHelper.ExecuteDataTable($"DESCRIBE {abutmentModel.logTabName}");
|
||||
for (int i = 0; i < lsTargeFieldsArray.Length; i++)
|
||||
{
|
||||
string columnName = lsTargeFieldsArray[i].Trim();
|
||||
DataRow colDataRow = sqlServerSchemaTable.Rows.Cast<DataRow>().Where(n => (n["name"] + "").Equals(columnName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
|
||||
string afkColName = afkTargeFieldsArray[i].Trim();
|
||||
DataRow selectRow = mySqlSchemaTable.Rows.Cast<DataRow>().Where(n => !(n["Extra"] + "").Equals("auto_increment", StringComparison.OrdinalIgnoreCase) && (n["Field"] + "").Equals(afkColName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
|
||||
if (selectRow != null)
|
||||
{
|
||||
stringBuilder.Append($"{columnName} as {selectRow["Field"]},");
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < abutmentModel.logAsFields.Length; i++)
|
||||
{
|
||||
string logAsField = abutmentModel.logAsFields[i];
|
||||
DataRow selectRow = mySqlSchemaTable.Rows.Cast<DataRow>().Where(n => !(n["Extra"] + "").Equals("auto_increment", StringComparison.OrdinalIgnoreCase) && (n["Field"] + "").Equals(abutmentModel.logFields[i], StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
|
||||
if (logAsField.Equals("@ErrorType", StringComparison.OrdinalIgnoreCase) && sqlServerSchemaTable.Rows.Cast<DataRow>().Where(n => (n["name"] + "").Equals("synchroSuccess", StringComparison.OrdinalIgnoreCase)).Count() > 0)
|
||||
{
|
||||
stringBuilder.Append($"0 as {selectRow["Field"]},");
|
||||
}
|
||||
else if (logAsField.Equals("@ErrorMessage", StringComparison.OrdinalIgnoreCase) && sqlServerSchemaTable.Rows.Cast<DataRow>().Where(n => (n["name"] + "").Equals("synchroMessage", StringComparison.OrdinalIgnoreCase)).Count() > 0)
|
||||
{
|
||||
stringBuilder.Append($"'' as {selectRow["Field"]},");
|
||||
}
|
||||
else if (logAsField.Equals("@TransferLogo", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
stringBuilder.Append($"1 as {selectRow["Field"]},");
|
||||
}
|
||||
else if (logAsField.Equals("getdate()", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
stringBuilder.Append($"getdate() as {selectRow["Field"]},");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
return stringBuilder;
|
||||
}
|
||||
/// <summary>
|
||||
/// 改变afk的同步标识
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="dataDirection"></param>
|
||||
/// <returns></returns>
|
||||
private string GetChangeSynchroTagSql(AbutmentModel abutmentModel)
|
||||
{
|
||||
string sql = "";
|
||||
try
|
||||
{
|
||||
string conditions = string.Empty;
|
||||
conditions = abutmentModel.targetStrs.Length == 2 ? " where isSynchro is null and " + abutmentModel.targetStrs[1] : "";
|
||||
sql = string.Format("update {0} set isSynchro='1' {1} ", abutmentModel.afkTabName, conditions);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
return sql;
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 66 KiB |
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="MySqlConnector" version="2.2.7" targetFramework="net461" />
|
||||
<package id="System.Buffers" version="4.5.1" targetFramework="net461" />
|
||||
<package id="System.Diagnostics.DiagnosticSource" version="6.0.0" targetFramework="net461" />
|
||||
<package id="System.Memory" version="4.5.5" targetFramework="net461" />
|
||||
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net461" />
|
||||
<package id="System.Runtime.CompilerServices.Unsafe" version="6.0.0" targetFramework="net461" />
|
||||
<package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net461" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user