@@ -70,6 +70,7 @@ | |||||
<DependentUpon>ActivationForm.cs</DependentUpon> | <DependentUpon>ActivationForm.cs</DependentUpon> | ||||
</Compile> | </Compile> | ||||
<Compile Include="FormSizeHelper.cs" /> | <Compile Include="FormSizeHelper.cs" /> | ||||
<Compile Include="SelectTableType.cs" /> | |||||
<Compile Include="SourceSettingTextBoxDecrible.cs" /> | <Compile Include="SourceSettingTextBoxDecrible.cs" /> | ||||
<Compile Include="frmAddSubtract.cs"> | <Compile Include="frmAddSubtract.cs"> | ||||
<SubType>Form</SubType> | <SubType>Form</SubType> | ||||
@@ -242,6 +243,10 @@ | |||||
<Project>{cb9b6d92-3cc4-46c6-92e8-a6fd0ad48041}</Project> | <Project>{cb9b6d92-3cc4-46c6-92e8-a6fd0ad48041}</Project> | ||||
<Name>CnasSynchronusClient</Name> | <Name>CnasSynchronusClient</Name> | ||||
</ProjectReference> | </ProjectReference> | ||||
<ProjectReference Include="..\CnasSynchronusDAL\CnasSynchronusDAL.csproj"> | |||||
<Project>{F4EC1B78-EFF4-4D04-AE79-631D220187AF}</Project> | |||||
<Name>CnasSynchronusDAL</Name> | |||||
</ProjectReference> | |||||
<ProjectReference Include="..\CnasSynchrousModel\CnasSynchrousModel.csproj"> | <ProjectReference Include="..\CnasSynchrousModel\CnasSynchrousModel.csproj"> | ||||
<Project>{0c3243f5-729e-409c-b406-c6de56e632e0}</Project> | <Project>{0c3243f5-729e-409c-b406-c6de56e632e0}</Project> | ||||
<Name>CnasSynchrousModel</Name> | <Name>CnasSynchrousModel</Name> | ||||
@@ -0,0 +1,152 @@ | |||||
using CnasSynchronousCommon; | |||||
using CnasSynchronusDAL; | |||||
using CnasSynchrousModel; | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Data; | |||||
using System.Data.SqlClient; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace CNAS_DBSync | |||||
{ | |||||
public class SelectTableType | |||||
{ | |||||
private static string connectionStr = ""; | |||||
public static DataTable MySqlsec(string strTableName) | |||||
{ | |||||
MySQLDAL mysql = new MySQLDAL(); | |||||
DataTable tb = mysql.GetTableTypeAndLenth(strTableName); | |||||
return tb; | |||||
} | |||||
public static DataTable Sqlserversec(string strTableName, SyncInstrumentItemInfo t) | |||||
{ | |||||
DataTable dt = new DataTable(); | |||||
try | |||||
{ | |||||
if (t.SyncInstrumentDSInfo.Host != "") | |||||
connectionStr = $"Data Source = {t.SyncInstrumentDSInfo.Host}; Initial Catalog = {t.SyncInstrumentDSInfo.ServerName}; User Id = {t.SyncInstrumentDSInfo.UserId}; Password = {t.SyncInstrumentDSInfo.UserPwd};"; | |||||
string sql = string.Format(@"SELECT | |||||
c.name AS ColumnName, | |||||
t.name AS DataType, | |||||
c.max_length AS MaxLength, | |||||
c.is_nullable AS IsNullable, | |||||
c.default_object_id AS DefaultObjectId, | |||||
ep.value AS remark | |||||
FROM | |||||
sys.columns c | |||||
JOIN | |||||
sys.types t ON c.user_type_id = t.user_type_id | |||||
LEFT JOIN | |||||
sys.extended_properties ep | |||||
ON | |||||
c.object_id = ep.major_id | |||||
AND c.column_id = ep.minor_id | |||||
AND ep.name = 'MS_Description' -- 备注的属性名称 | |||||
WHERE | |||||
c.object_id = OBJECT_ID('{0}'); ", strTableName); //查询字符串 | |||||
dt = GetDataTable(sql, new SqlParameter[] { }); | |||||
} | |||||
catch (Exception ex) | |||||
{ | |||||
//发生异常,写入日志 | |||||
AppLog.Error(ex.Message); | |||||
} | |||||
return dt; | |||||
} | |||||
/// <summary> | |||||
/// 查询操作 | |||||
/// </summary> | |||||
/// <param name="sql"></param> | |||||
/// <returns></returns> | |||||
public static DataTable GetDataTable(string sql, params SqlParameter[] sp) | |||||
{ | |||||
using (SqlConnection conn = new SqlConnection(connectionStr)) | |||||
{ | |||||
conn.Open(); | |||||
using (SqlDataAdapter sda = new SqlDataAdapter(sql, conn)) | |||||
{ | |||||
sda.SelectCommand.Parameters.AddRange(sp); | |||||
DataTable dt = new DataTable(); | |||||
sda.Fill(dt); | |||||
return dt; | |||||
} | |||||
} | |||||
} | |||||
public static DataTable PostgreSql(string strTableName) | |||||
{ | |||||
DataTable dt = new DataTable(); | |||||
string strSql = string.Format(@"SELECT | |||||
a.attname as ColumnName, | |||||
format_type(a.atttypid, a.atttypmod) as DataType, | |||||
a.attnotnull as 非空, | |||||
col_description(a.attrelid, a.attnum) as remark | |||||
FROM | |||||
pg_class as c, pg_attribute as a | |||||
where | |||||
a.attrelid = c.oid | |||||
and | |||||
a.attnum > 0 | |||||
and | |||||
c.relname = '{0}'; ", strTableName); | |||||
try | |||||
{ | |||||
dt = PostgreSQLHelper.ExecuteDataSet(strSql).Tables[0]; | |||||
} | |||||
catch (Exception ex) | |||||
{ | |||||
AppLog.Error(ex.Message); | |||||
} | |||||
return dt; | |||||
} | |||||
public static DataTable DmSql(string strTableName) | |||||
{ | |||||
DataTable dt = new DataTable(); | |||||
string strSql = string.Format(@"SELECT | |||||
a.COLUMN_NAME AS ColumnName, | |||||
b.COMMENTS AS remark, | |||||
a.DATA_TYPE || CASE | |||||
WHEN a.DATA_TYPE IN('VARCHAR', 'CHAR') THEN '(' || a.DATA_LENGTH || ')' | |||||
WHEN a.DATA_TYPE IN('DECIMAL', 'NUMERIC') THEN '(' || a.DATA_PRECISION || ',' || a.DATA_SCALE || ')' | |||||
ELSE '' | |||||
END AS DataType | |||||
FROM | |||||
ALL_TAB_COLUMNS a | |||||
LEFT JOIN | |||||
ALL_COL_COMMENTS b | |||||
ON a.OWNER = b.OWNER | |||||
AND a.TABLE_NAME = b.TABLE_NAME | |||||
AND a.COLUMN_NAME = b.COLUMN_NAME | |||||
WHERE | |||||
a.TABLE_NAME = '{0}' | |||||
ORDER BY | |||||
a.COLUMN_ID;", strTableName); | |||||
try | |||||
{ | |||||
dt = DamengHelper.ExecuteDataSet(strSql).Tables[0]; | |||||
} | |||||
catch (Exception ex) | |||||
{ | |||||
AppLog.Error(ex.Message); | |||||
} | |||||
return dt; | |||||
} | |||||
} | |||||
} |
@@ -294,8 +294,35 @@ namespace CNAS_DBSync | |||||
InstrumentData instrumentData = InstrumentDataFact.CreateInstrumentDataSource(currentSyncItem.SyncInstrumentDSInfo, new object[] { "", "", "" }); | InstrumentData instrumentData = InstrumentDataFact.CreateInstrumentDataSource(currentSyncItem.SyncInstrumentDSInfo, new object[] { "", "", "" }); | ||||
//dictInstruTables = instrumentData.GetInstrumentData(); | //dictInstruTables = instrumentData.GetInstrumentData(); | ||||
//dictInstruTables = | //dictInstruTables = | ||||
string strTableName_Instru = cbxInstrument.Text.ToString(); | |||||
DataTable dtTableType = CnasDataOperationFact.CnasDataOperation().GetCNASTableTypeLenth(strTableName_Instru, currentSyncItem.SyncTargetDBInfo); | |||||
DataTable dtTableType = null; | |||||
string strTableName_Instru = cbxInstrument.Text.ToString(); | |||||
switch (currentSyncItem.SyncInstrumentDSInfo.InstrumentDataSourceType) | |||||
{ | |||||
case DataSourceType.MySQL: | |||||
dtTableType = SelectTableType.MySqlsec(strTableName_Instru); | |||||
break; | |||||
case DataSourceType.Dm: | |||||
dtTableType = SelectTableType.DmSql(strTableName_Instru); | |||||
break; | |||||
case DataSourceType.Oracle: | |||||
break; | |||||
case DataSourceType.PostgreSQL: | |||||
dtTableType = SelectTableType.PostgreSql(strTableName_Instru); | |||||
break; | |||||
case DataSourceType.SQL: | |||||
dtTableType = SelectTableType.Sqlserversec(strTableName_Instru, currentSyncItem); | |||||
break; | |||||
case DataSourceType.SQLLite: | |||||
default: | |||||
break; | |||||
} | |||||
//dtTableType = CnasDataOperationFact.CnasDataOperation().GetCNASTableTypeLenth(strTableName_Instru, currentSyncItem.SyncTargetDBInfo); | |||||
//string strTableName_Instru = cbxInstrument.Text.ToString(); | //string strTableName_Instru = cbxInstrument.Text.ToString(); | ||||
@@ -428,7 +428,7 @@ namespace CnasSynchronusDAL | |||||
{ | { | ||||
string strTableName = dr[0].ToString(); | string strTableName = dr[0].ToString(); | ||||
AppLog.Error("===---===" + strTableName + "GetTableStruct(strTableName, )"); | AppLog.Error("===---===" + strTableName + "GetTableStruct(strTableName, )"); | ||||
dictTables.Add(strTableName.ToUpper(), GetTableStruct(strTableName, "", "")); | |||||
dictTables.Add(strTableName, GetTableStruct(strTableName, "", "")); | |||||
} | } | ||||
} | } | ||||
@@ -181,7 +181,7 @@ namespace CnasSynchronusDAL | |||||
/// 获取所有数据字段,然后记录其中是否存在需要特殊处理的字段 | /// 获取所有数据字段,然后记录其中是否存在需要特殊处理的字段 | ||||
/// </summary> | /// </summary> | ||||
/// <returns></returns> | /// <returns></returns> | ||||
private static Dictionary<string, string> GetSpecialOperaField(string strTableName) | |||||
public static Dictionary<string, string> GetSpecialOperaField(string strTableName) | |||||
{ | { | ||||
Dictionary<string, string> DictFiled = new Dictionary<string, string>(); | Dictionary<string, string> DictFiled = new Dictionary<string, string>(); | ||||
DataTable dt = new DataTable(); | DataTable dt = new DataTable(); | ||||