OCEAN 4 місяці тому
джерело
коміт
8b258944c8
17 змінених файлів з 10168 додано та 81 видалено
  1. BIN
      .vs/CNAS_DBSync/v15/.suo
  2. BIN
      .vs/CNAS_DBSync/v15/Server/sqlite3/storage.ide
  3. BIN
      .vs/CNAS_DBSync/v15/Server/sqlite3/storage.ide-shm
  4. BIN
      .vs/CNAS_DBSync/v15/Server/sqlite3/storage.ide-wal
  5. +9
    -0
      CNAS_DBSync/CNAS_DBSync.csproj
  6. +191
    -0
      CNAS_DBSync/SelectTableType.cs
  7. +136
    -74
      CNAS_DBSync/frmSyncParams.cs
  8. +1
    -1
      CnasSynchronusDAL/DAL/PostgreSqlDAL.cs
  9. +3
    -3
      CnasSynchronusDAL/DAL/SQLDAL.cs
  10. BIN
      dll/CNAS_DBSync.exe
  11. BIN
      dll/CNAS_RunSync.exe
  12. +11
    -3
      dll/CNAS_RunSync.exe.config
  13. BIN
      dll/CnasSynchronusClient.dll
  14. BIN
      dll/CnasSynchronusDAL.dll
  15. +17
    -0
      dll/ErrorLog/20250218.txt
  16. +9800
    -0
      dll/ErrorLog/20250219.txt
  17. BIN
      dll/Newtonsoft.Json.dll

BIN
.vs/CNAS_DBSync/v15/.suo Переглянути файл


BIN
.vs/CNAS_DBSync/v15/Server/sqlite3/storage.ide Переглянути файл


BIN
.vs/CNAS_DBSync/v15/Server/sqlite3/storage.ide-shm Переглянути файл


BIN
.vs/CNAS_DBSync/v15/Server/sqlite3/storage.ide-wal Переглянути файл


+ 9
- 0
CNAS_DBSync/CNAS_DBSync.csproj Переглянути файл

@@ -46,6 +46,10 @@
<Reference Include="log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL"> <Reference Include="log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.8\lib\net40-full\log4net.dll</HintPath> <HintPath>..\packages\log4net.2.0.8\lib\net40-full\log4net.dll</HintPath>
</Reference> </Reference>
<Reference Include="Oracle.ManagedDataAccess, Version=4.122.19.1, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\dll\Oracle.ManagedDataAccess.dll</HintPath>
</Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" /> <Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.configuration" /> <Reference Include="System.configuration" />
@@ -70,6 +74,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 +247,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>


+ 191
- 0
CNAS_DBSync/SelectTableType.cs Переглянути файл

@@ -0,0 +1,191 @@
using CnasSynchronousCommon;
using CnasSynchronusDAL;
using CnasSynchrousModel;
using Oracle.ManagedDataAccess.Client;
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
c.COLUMN_NAME AS ColumnName,
c.DATA_TYPE AS DataType,
c.DATA_LENGTH AS 字段长度,
c.NULLABLE AS 是否允许为空,
com.COMMENTS AS remark
FROM
USER_TAB_COLUMNS c
LEFT JOIN
USER_COL_COMMENTS com
ON
c.TABLE_NAME = com.TABLE_NAME
AND c.COLUMN_NAME = com.COLUMN_NAME
WHERE
c.TABLE_NAME = '{0}';", strTableName);
try
{
dt = DamengHelper.ExecuteDataSet(strSql).Tables[0];
}
catch (Exception ex)
{
AppLog.Error(ex.Message);
}
return dt;


}

public static DataTable OrcSql(string strTableName, SyncInstrumentItemInfo t) {
connectionStr = $"Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST={t.SyncInstrumentDSInfo.Host})(PORT={t.SyncInstrumentDSInfo.Port}))" + $"(CONNECT_DATA=(SID={t.SyncInstrumentDSInfo.ServerName})));User Id={t.SyncInstrumentDSInfo.UserId};Password={t.SyncInstrumentDSInfo.UserPwd};";
DataTable dt = new DataTable();
string strSql = string.Format("select COLUMN_NAME AS ColumnName,NULLABLE AS IsNullable,DATA_TYPE AS DataType,DATA_LENGTH AS CharMaxLenth,DATA_LENGTH AS CharOcterLenth,DATA_PRECISION AS NumericPrecision,DATA_SCALE AS NumericScale from user_tab_columns where table_name='{0}'", strTableName.ToUpper());
try
{
dt = GetDataTable(strSql, new OracleParameter[] { });
}
catch (Exception ex)
{
AppLog.Error(ex.Message);
}
return dt;
}

/// <summary>
/// 查询操作
/// </summary>
/// <param name="sql"></param>
/// <returns></returns>
public static DataTable GetDataTable(string sql, params OracleParameter[] sp)
{
DataTable dt = new DataTable();
try
{
using (OracleConnection conn = new OracleConnection(connectionStr))
{
conn.Open();
//using (OracleDataAdapter sda = new OracleDataAdapter("select * from t_weight_info where WEIGH_DATE > '2019-10-02 14:20:12'", conn))
using (OracleDataAdapter sda = new OracleDataAdapter(sql, conn))
{
sda.SelectCommand.Parameters.AddRange(sp);
sda.Fill(dt);
}
}
}
catch (Exception ex)
{
AppLog.Error(ex.Message);
}
return dt;
}
}
}

+ 136
- 74
CNAS_DBSync/frmSyncParams.cs Переглянути файл

@@ -9,6 +9,7 @@ using System.Drawing;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms; using System.Windows.Forms;
using System.Xml.Linq; using System.Xml.Linq;
using System.Xml.Serialization; using System.Xml.Serialization;
@@ -27,7 +28,7 @@ namespace CNAS_DBSync
private string strMode = ""; private string strMode = "";
private string strTableInfoMode = ""; //获取所有表信息的方式;0为自动获取,1为手动输入 private string strTableInfoMode = ""; //获取所有表信息的方式;0为自动获取,1为手动输入


public frmSyncParams(SyncInstrumentItemInfo syncInstrumentItem=null)
public frmSyncParams(SyncInstrumentItemInfo syncInstrumentItem = null)
{ {
InitializeComponent(); InitializeComponent();


@@ -42,7 +43,7 @@ namespace CNAS_DBSync


dgvMapping.AutoGenerateColumns = false; dgvMapping.AutoGenerateColumns = false;
dgvMapping.RowHeadersVisible = false; dgvMapping.RowHeadersVisible = false;
if (syncInstrumentItem != null) if (syncInstrumentItem != null)
{ {
strMode = "Reference"; strMode = "Reference";
@@ -52,7 +53,7 @@ namespace CNAS_DBSync
this.btnDel.Visible = false; this.btnDel.Visible = false;
} }


} }


private void frmSyncParams_Load(object sender, EventArgs e) private void frmSyncParams_Load(object sender, EventArgs e)
@@ -65,10 +66,10 @@ namespace CNAS_DBSync
{ {
lstSyncInstrument = new List<SyncInstrumentItemInfo>() { syncInstrumentItem }; lstSyncInstrument = new List<SyncInstrumentItemInfo>() { syncInstrumentItem };
} }
//绑定数据源,填写相关内容 //绑定数据源,填写相关内容
if(lstSyncInstrument.Count!=0)
dgvInstrument.DataSource = new BindingList<SyncInstrumentItemInfo>(lstSyncInstrument);
if (lstSyncInstrument.Count != 0)
dgvInstrument.DataSource = new BindingList<SyncInstrumentItemInfo>(lstSyncInstrument);
} }


/// <summary> /// <summary>
@@ -107,7 +108,7 @@ namespace CNAS_DBSync
lstDB.Add(currentSyncItem); lstDB.Add(currentSyncItem);
} }
//重新保存信息 //重新保存信息
bIfSaveSuccess=FileOperation.SaveLocalSyncInStrumentData(lstDB);
bIfSaveSuccess = FileOperation.SaveLocalSyncInStrumentData(lstDB);
//委托发送参数 //委托发送参数
this.ParamsChangedDelegate(syncInstrumentItem); this.ParamsChangedDelegate(syncInstrumentItem);
} }
@@ -123,16 +124,16 @@ namespace CNAS_DBSync
MessageBox.Show("关键字段不允许为空!"); MessageBox.Show("关键字段不允许为空!");
return; return;
} }
bIfSaveSuccess =FileOperation.SaveLocalSyncInStrumentData(lstSyncInstrument);
bIfSaveSuccess = FileOperation.SaveLocalSyncInStrumentData(lstSyncInstrument);
} }
if(bIfSaveSuccess)
if (bIfSaveSuccess)
MessageBox.Show("保存成功!"); MessageBox.Show("保存成功!");
else else
MessageBox.Show("保存失败!"); MessageBox.Show("保存失败!");
} }
catch (Exception ex) catch (Exception ex)
{ {
MessageBox.Show("保存失败!错误信息为:"+ex.Message.ToString());
MessageBox.Show("保存失败!错误信息为:" + ex.Message.ToString());
AppLog.Error(ex.Message); AppLog.Error(ex.Message);
} }
} }
@@ -142,7 +143,7 @@ namespace CNAS_DBSync
foreach (var item in lstSyncInstrument) foreach (var item in lstSyncInstrument)
{ {
if (item.LstSyncPramas == null) continue; if (item.LstSyncPramas == null) continue;
if (item.LstSyncPramas.Count <=0) continue;
if (item.LstSyncPramas.Count <= 0) continue;
if (item.LstSyncPramas.Where(s => s.IfDateField == true).Count() != 1) if (item.LstSyncPramas.Where(s => s.IfDateField == true).Count() != 1)
{ {
bIfHave = false; bIfHave = false;
@@ -176,7 +177,7 @@ namespace CNAS_DBSync
frmSystemSetting frmSetting = new frmSystemSetting(lstSyncInstrument); frmSystemSetting frmSetting = new frmSystemSetting(lstSyncInstrument);


frmInstrumentCode frmCode = new frmInstrumentCode(lstSyncInstrument); frmInstrumentCode frmCode = new frmInstrumentCode(lstSyncInstrument);
frmSetting.InstrumentDelegate = delegate(SyncInstrumentItemInfo Instrumentitem)
frmSetting.InstrumentDelegate = delegate (SyncInstrumentItemInfo Instrumentitem)
{ {
lstSyncInstrument.Add(Instrumentitem); lstSyncInstrument.Add(Instrumentitem);


@@ -186,7 +187,7 @@ namespace CNAS_DBSync


dgvInstrument_SelectionChanged(null, null); dgvInstrument_SelectionChanged(null, null);
}; };
frmSetting.ShowDialog();
frmSetting.ShowDialog();
} }




@@ -239,7 +240,7 @@ namespace CNAS_DBSync


private void dgvInstrument_SelectionChanged(object sender, EventArgs e) private void dgvInstrument_SelectionChanged(object sender, EventArgs e)
{ {
if (dgvInstrument.Rows.Count <= 0|| dgvInstrument.Rows[dgvInstrument.CurrentRow.Index].Cells[0].Value == null)
if (dgvInstrument.Rows.Count <= 0 || dgvInstrument.Rows[dgvInstrument.CurrentRow.Index].Cells[0].Value == null)
{ {
currentSyncItem = new SyncInstrumentItemInfo(); currentSyncItem = new SyncInstrumentItemInfo();
return; return;
@@ -263,20 +264,20 @@ namespace CNAS_DBSync
else else
txtInstrumentColumn.Text = ""; txtInstrumentColumn.Text = "";


if (currentSyncItem.SyncInstrumentDSInfo != null&& currentSyncItem.SyncInstrumentDSInfo.InstrumentDataSourceType!=DataSourceType.None)
{
if (currentSyncItem.SyncInstrumentDSInfo != null && currentSyncItem.SyncInstrumentDSInfo.InstrumentDataSourceType != DataSourceType.None)
{
dgvMapping.DataSource = new BindingList<SyncParamasInfo>(currentSyncItem.LstSyncPramas); dgvMapping.DataSource = new BindingList<SyncParamasInfo>(currentSyncItem.LstSyncPramas);
if(currentSyncItem.SyncInstrumentDSInfo.ServerName!="")
btnLoadDBData_Click(sender, e);
if (currentSyncItem.SyncInstrumentDSInfo.ServerName != "")
btnLoadDBData_Click(sender, e);
} }
else else
{
{
dgvMapping.DataSource = new BindingList<SyncParamasInfo>(); dgvMapping.DataSource = new BindingList<SyncParamasInfo>();
} }
} }
else else
{ {
dgvMapping.DataSource =new BindingList<SyncParamasInfo>();
dgvMapping.DataSource = new BindingList<SyncParamasInfo>();
} }
} }
/// <summary> /// <summary>
@@ -294,11 +295,29 @@ 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 =
DataTable dtTableType = null;
string strTableName_Instru = cbxInstrument.Text.ToString(); string strTableName_Instru = cbxInstrument.Text.ToString();
DataTable dtTableType = CnasDataOperationFact.CnasDataOperation().GetCNASTableTypeLenth(strTableName_Instru, currentSyncItem.SyncTargetDBInfo);

//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:
dtTableType = SelectTableType.OrcSql(strTableName_Instru, currentSyncItem);
break;
case DataSourceType.PostgreSQL:
dtTableType = SelectTableType.PostgreSql(strTableName_Instru);
break;
case DataSourceType.SQL:
dtTableType = SelectTableType.Sqlserversec(strTableName_Instru, currentSyncItem);
break;
default:
break;
}
DataTable dtInstruShow = new DataTable(); DataTable dtInstruShow = new DataTable();
dtInstruShow.Columns.Add("InstruFieldName"); dtInstruShow.Columns.Add("InstruFieldName");
dtInstruShow.Columns.Add("InstruDataType"); dtInstruShow.Columns.Add("InstruDataType");
@@ -309,23 +328,7 @@ namespace CNAS_DBSync
} }


dgvInstruDS.DataSource = dtInstruShow; dgvInstruDS.DataSource = dtInstruShow;
//if (dictInstruTables.ContainsKey(strTableName_Instru))
//{
// DataTable dt = dictInstruTables[strTableName_Instru];
// if (dt != null)
// {
// DataTable dtInstruShow = new DataTable();
// dtInstruShow.Columns.Add("InstruFieldName");
// dtInstruShow.Columns.Add("InstruDataType");

// foreach (DataColumn dc in dt.Columns)
// {
// dtInstruShow.Rows.Add(new object[] { dc.ColumnName,dc.DataType});
// }

// }
//}

} }


/// <summary> /// <summary>
@@ -339,26 +342,12 @@ namespace CNAS_DBSync


string strTableName_Cnas = cbxCnas.Text.ToString(); string strTableName_Cnas = cbxCnas.Text.ToString();


//if (currentSyncItem.CnasInstrumentColumn != null && currentSyncItem.CnasInstrumentColumn != "")
//{
// DialogResult dr = MessageBox.Show("已存在配置完成的CNAS仪器对应列,切换表将导致该配置失效,是否继续?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
// if (dr == DialogResult.No)
// {
// return;
// }
//}

DataTable dtTableStruct = CnasDataOperationFact.CnasDataOperation().GetCNASTableTypeLenth(strTableName_Cnas, currentSyncItem.SyncTargetDBInfo); DataTable dtTableStruct = CnasDataOperationFact.CnasDataOperation().GetCNASTableTypeLenth(strTableName_Cnas, currentSyncItem.SyncTargetDBInfo);


//从数据库中加载数据表结构 //从数据库中加载数据表结构
//DataTable dtTableStruct = CnasDataOperationFact.CnasDataOperation().GetCNASTablesStruct(strTableName_Cnas,currentSyncItem.SyncTargetDBInfo); //DataTable dtTableStruct = CnasDataOperationFact.CnasDataOperation().GetCNASTablesStruct(strTableName_Cnas,currentSyncItem.SyncTargetDBInfo);
if (dtTableStruct != null) if (dtTableStruct != null)
{ {

//DataTable dtTableType = CnasDataOperationFact.CnasDataOperation().GetCNASTableTypeLenth(strTableName_Instru, currentSyncItem.SyncTargetDBInfo);

//string strTableName_Instru = cbxInstrument.Text.ToString();

DataTable dtCnasShow = new DataTable(); DataTable dtCnasShow = new DataTable();
dtCnasShow.Columns.Add("CnasFieldName"); dtCnasShow.Columns.Add("CnasFieldName");
dtCnasShow.Columns.Add("CnasDataType"); dtCnasShow.Columns.Add("CnasDataType");
@@ -378,7 +367,7 @@ namespace CNAS_DBSync


if (dtTableStruct.Columns.Count > 0) if (dtTableStruct.Columns.Count > 0)
{ {
if (!string.IsNullOrWhiteSpace(currentSyncItem.CnasInstrumentColumn)&&dtTableStruct.Columns.Contains(currentSyncItem.CnasInstrumentColumn))
if (!string.IsNullOrWhiteSpace(currentSyncItem.CnasInstrumentColumn) && dtTableStruct.Columns.Contains(currentSyncItem.CnasInstrumentColumn))
{ {
cbxCNASColumn.Text = this.txtInstrumentColumn.Text = currentSyncItem.CnasInstrumentColumn; cbxCNASColumn.Text = this.txtInstrumentColumn.Text = currentSyncItem.CnasInstrumentColumn;
} }
@@ -400,7 +389,7 @@ namespace CNAS_DBSync


SyncParamasInfo syncParamas = new SyncParamasInfo(); SyncParamasInfo syncParamas = new SyncParamasInfo();
if (currentSyncItem.LstSyncPramas == null) currentSyncItem.LstSyncPramas = new List<SyncParamasInfo>(); if (currentSyncItem.LstSyncPramas == null) currentSyncItem.LstSyncPramas = new List<SyncParamasInfo>();
if (dgvCnas.Rows[dgvCnas.CurrentCell.RowIndex].Cells[0].Value.ToString().ToUpper() == "ID") if (dgvCnas.Rows[dgvCnas.CurrentCell.RowIndex].Cells[0].Value.ToString().ToUpper() == "ID")
{ {
MessageBox.Show("该字段为CNAS数据库保留字段,不允许插入数据,请重新选择!"); MessageBox.Show("该字段为CNAS数据库保留字段,不允许插入数据,请重新选择!");
@@ -440,9 +429,9 @@ namespace CNAS_DBSync


//绑定数据 //绑定数据
currentSyncItem.LstSyncPramas.Add(syncParamas); currentSyncItem.LstSyncPramas.Add(syncParamas);
dgvMapping.DataSource= new BindingList<SyncParamasInfo>(currentSyncItem.LstSyncPramas);
dgvMapping.DataSource = new BindingList<SyncParamasInfo>(currentSyncItem.LstSyncPramas);
//选中最后一行 //选中最后一行
dgvMapping.CurrentCell = dgvMapping.Rows[dgvMapping.Rows.Count-1].Cells[0];
dgvMapping.CurrentCell = dgvMapping.Rows[dgvMapping.Rows.Count - 1].Cells[0];
} }


/// <summary> /// <summary>
@@ -478,7 +467,7 @@ namespace CNAS_DBSync
frmDatabaseParams frmDatabase = new frmDatabaseParams(currentSyncItem); frmDatabaseParams frmDatabase = new frmDatabaseParams(currentSyncItem);
frmDatabase.InstrumentDelegate = delegate (SyncInstrumentItemInfo Instrumentitem) frmDatabase.InstrumentDelegate = delegate (SyncInstrumentItemInfo Instrumentitem)
{ {
this.currentSyncItem = Instrumentitem;
this.currentSyncItem = Instrumentitem;
}; };
frmDatabase.InstrumentItemData = delegate (Dictionary<string, DataTable> dict) frmDatabase.InstrumentItemData = delegate (Dictionary<string, DataTable> dict)
{ {
@@ -487,14 +476,12 @@ namespace CNAS_DBSync
frmDatabase.ShowDialog(); frmDatabase.ShowDialog();


//加载数据 //加载数据
if ((currentSyncItem.SyncInstrumentDSInfo.Host!=null&& currentSyncItem.SyncInstrumentDSInfo.Host.Length>0) || (currentSyncItem.SyncInstrumentDSInfo.Path!=null&& currentSyncItem.SyncInstrumentDSInfo.Path.Length>0))
if ((currentSyncItem.SyncInstrumentDSInfo.Host != null && currentSyncItem.SyncInstrumentDSInfo.Host.Length > 0) || (currentSyncItem.SyncInstrumentDSInfo.Path != null && currentSyncItem.SyncInstrumentDSInfo.Path.Length > 0))
btnLoadDBData_Click(null, null); btnLoadDBData_Click(null, null);
} }


private void btnLoadDBData_Click(object sender, EventArgs e) private void btnLoadDBData_Click(object sender, EventArgs e)

{ {

string strInstrumentCode = this.dgvInstrument.Rows[this.dgvInstrument.CurrentRow.Index].Cells[0].Value.ToString(); string strInstrumentCode = this.dgvInstrument.Rows[this.dgvInstrument.CurrentRow.Index].Cells[0].Value.ToString();


strTableInfoMode = FileOperation.GetSystemFormatConfigData(strInstrumentCode).TableInfoMode; strTableInfoMode = FileOperation.GetSystemFormatConfigData(strInstrumentCode).TableInfoMode;
@@ -504,10 +491,10 @@ namespace CNAS_DBSync
//cbxCnas.DropDownStyle = ComboBoxStyle.DropDown; //cbxCnas.DropDownStyle = ComboBoxStyle.DropDown;
} }
int iReturn = 0; int iReturn = 0;
if (strTableInfoMode=="0")
iReturn=LoadSourceAndTargetData(true);
if (strTableInfoMode == "0")
iReturn = LoadSourceAndTargetData(true);
else else
iReturn= LoadSourceAndTargetData();
iReturn = LoadSourceAndTargetData();
switch (iReturn) switch (iReturn)
{ {
case -1: case -1:
@@ -546,7 +533,7 @@ namespace CNAS_DBSync
/// </summary> /// </summary>
/// <param name="bIfLoading"></param> /// <param name="bIfLoading"></param>
/// <returns></returns> /// <returns></returns>
public int LoadSourceAndTargetData(bool bIfLoading=false)
public int LoadSourceAndTargetData(bool bIfLoading = false)
{ {
//检查配置信息 //检查配置信息
if (currentSyncItem.SyncInstrumentDSInfo == null) return -1; if (currentSyncItem.SyncInstrumentDSInfo == null) return -1;
@@ -585,7 +572,7 @@ namespace CNAS_DBSync
{ {
List<string> lstCnasTables = new List<string>(); List<string> lstCnasTables = new List<string>();
foreach (DataRow dr in dtCNAS.Rows) foreach (DataRow dr in dtCNAS.Rows)
{
{
if (dtCNAS.Columns.Contains("TABNAME")) if (dtCNAS.Columns.Contains("TABNAME"))
lstCnasTables.Add(dr["TABNAME"].ToString()); lstCnasTables.Add(dr["TABNAME"].ToString());
else if (dtCNAS.Columns.Contains("table_name")) else if (dtCNAS.Columns.Contains("table_name"))
@@ -625,19 +612,63 @@ namespace CNAS_DBSync
{ {
if (currentSyncItem.SyncInstrumentDSInfo == null) return -1; if (currentSyncItem.SyncInstrumentDSInfo == null) return -1;
if (currentSyncItem.SyncTargetDBInfo == null) return -2; if (currentSyncItem.SyncTargetDBInfo == null) return -2;
SqlServerFormatConfig SqlServerFormat = FileOperation.GetFormatConfigData<SqlServerFormatConfig>("SqlServerFormatConfig.xml");

string sql = SqlServerFormat.AutoSql.SqlServerViewSql;

cbxInstrument.Text = ExtractTableNames(sql);
if (cbxInstrument.Text == "") return -6; if (cbxInstrument.Text == "") return -6;


int returnValue = 1; int returnValue = 1;


//根据手动输入来源库的表名加载字段 //根据手动输入来源库的表名加载字段
InstrumentData instrumentData = InstrumentDataFact.CreateInstrumentDataSource(currentSyncItem.SyncInstrumentDSInfo, new object[] { cbxInstrument.Text, "", "" });
DataTable dataTableStruct = instrumentData.GetInstrumentDataStruct();



InstrumentData instrumentData = InstrumentDataFact.CreateInstrumentDataSource(currentSyncItem.SyncInstrumentDSInfo, new object[] { "", "", "" });
//dictInstruTables = instrumentData.GetInstrumentData();
//dictInstruTables =
DataTable dataTableStruct = null;
string strTableName_Instru = cbxInstrument.Text.ToString();

switch (currentSyncItem.SyncInstrumentDSInfo.InstrumentDataSourceType)
{
case DataSourceType.MySQL:
dataTableStruct = SelectTableType.MySqlsec(cbxInstrument.Text);
break;
case DataSourceType.Dm:
dataTableStruct = SelectTableType.DmSql(cbxInstrument.Text);
break;
case DataSourceType.Oracle:
dataTableStruct = SelectTableType.OrcSql(cbxInstrument.Text, currentSyncItem);
break;
case DataSourceType.PostgreSQL:
dataTableStruct = SelectTableType.PostgreSql(cbxInstrument.Text);
break;
case DataSourceType.SQL:
dataTableStruct = SelectTableType.Sqlserversec(cbxInstrument.Text, currentSyncItem);
break;
default:
break;
}
DataTable dtInstruShow = new DataTable();
dtInstruShow.Columns.Add("InstruFieldName");
dtInstruShow.Columns.Add("InstruDataType");
dtInstruShow.Columns.Add("remark");
if (dataTableStruct != null)
{
for (int i = 0; i < dataTableStruct.Rows.Count; i++)
{
dtInstruShow.Rows.Add(new object[] { dataTableStruct.Rows[i]["ColumnName"], dataTableStruct.Rows[i]["DataType"], dataTableStruct.Rows[i]["remark"] });
}
}
dgvInstruDS.DataSource = dtInstruShow;


if (dataTableStruct != null && dataTableStruct.Columns.Count > 0) if (dataTableStruct != null && dataTableStruct.Columns.Count > 0)
{ {
dictInstruTables.Clear(); dictInstruTables.Clear();
dictInstruTables.Add(cbxInstrument.Text, dataTableStruct); dictInstruTables.Add(cbxInstrument.Text, dataTableStruct);
cbxInstrument_SelectedIndexChanged(null, null);

//return 1; //return 1;
} }
else else
@@ -676,6 +707,37 @@ namespace CNAS_DBSync
return returnValue; return returnValue;
} }



public string ExtractTableNames(string sql)
{
// 预处理:去除注释、统一空格
sql = Regex.Replace(sql, @"(--.*)|(\/\*[\s\S]*?\*\/)", "", RegexOptions.Multiline);
sql = Regex.Replace(sql, @"\s+", " ");

// 定义匹配模式
var patterns = new Dictionary<string, string>
{
{ "SELECT", @"(?:FROM|JOIN)\s+([\w\.]+)(?:\s+AS\s+\w+)?" },
{ "INSERT", @"INSERT\s+INTO\s+([\w\.]+)" },
{ "UPDATE", @"UPDATE\s+([\w\.]+)" },
{ "DELETE", @"DELETE\s+FROM\s+([\w\.]+)" }
};

var tables = new HashSet<string>();
foreach (var pattern in patterns.Values)
{
var matches = Regex.Matches(sql, pattern, RegexOptions.IgnoreCase);
foreach (Match match in matches)
{
if (match.Groups[1].Success)
tables.Add(match.Groups[1].Value.Trim());
}
}
if (tables.Count == 0)
return "";
else
return tables.ToList()[0];
}
private void dgvMapping_CellValueChanged(object sender, DataGridViewCellEventArgs e) private void dgvMapping_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{ {
if (dgvMapping.CurrentCell == null) return; if (dgvMapping.CurrentCell == null) return;
@@ -756,7 +818,7 @@ namespace CNAS_DBSync
MessageBox.Show("请先指定至少一个映射字段。"); MessageBox.Show("请先指定至少一个映射字段。");
return; return;
} }
frmSourceFilter frm = new frmSourceFilter(currentSyncItem,strTableInfoMode);
frmSourceFilter frm = new frmSourceFilter(currentSyncItem, strTableInfoMode);
frm.sourceDataFilterHandler = delegate (SourceDataFilter dataFilter) frm.sourceDataFilterHandler = delegate (SourceDataFilter dataFilter)
{ {
currentSyncItem.SourceFilter = dataFilter; currentSyncItem.SourceFilter = dataFilter;
@@ -805,7 +867,7 @@ namespace CNAS_DBSync
cbxCNASColumn.Top = txtInstrumentColumn.Top; cbxCNASColumn.Top = txtInstrumentColumn.Top;
cbxCNASColumn.Height = txtInstrumentColumn.Height; cbxCNASColumn.Height = txtInstrumentColumn.Height;
cbxCNASColumn.Width = txtInstrumentColumn.Width; cbxCNASColumn.Width = txtInstrumentColumn.Width;
cbxCNASColumn.Location= txtInstrumentColumn.Location;
cbxCNASColumn.Location = txtInstrumentColumn.Location;


cbxCNASColumn.Visible = true; cbxCNASColumn.Visible = true;
} }
@@ -850,7 +912,7 @@ namespace CNAS_DBSync


private void tsmHelper_Click(object sender, EventArgs e) private void tsmHelper_Click(object sender, EventArgs e)
{ {
string strHelpFilePath = FileHelper.getBasePath()+ @"\Helper.CHM";
string strHelpFilePath = FileHelper.getBasePath() + @"\Helper.CHM";
//Help.ShowHelp(null, strHelpFilePath, HelpNavigator.TopicId, "1"); //Help.ShowHelp(null, strHelpFilePath, HelpNavigator.TopicId, "1");
//Help.ShowHelpIndex(this, strHelpFilePath); //Help.ShowHelpIndex(this, strHelpFilePath);
System.Diagnostics.Process.Start(strHelpFilePath); System.Diagnostics.Process.Start(strHelpFilePath);


+ 1
- 1
CnasSynchronusDAL/DAL/PostgreSqlDAL.cs Переглянути файл

@@ -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, "", ""));
} }


} }


+ 3
- 3
CnasSynchronusDAL/DAL/SQLDAL.cs Переглянути файл

@@ -17,8 +17,8 @@ namespace CnasSynchronusDAL
private static string connectionStr =""; private static string connectionStr ="";
public static void CreateConnection(SqlServerOpenParams t) public static void CreateConnection(SqlServerOpenParams t)
{ {
if (!string.IsNullOrWhiteSpace(t.StrConnecttion))
SqlServerDAL.connectionStr = $"Data Source = {t.StrHost}; Initial Catalog = {t.StrServer}; User Id = {t.StrUser}; Password = {t.StrPwd};Port={t.StrPort}";
if (!string.IsNullOrWhiteSpace(t.StrConnecttion)|| t.StrConnecttion=="")
SqlServerDAL.connectionStr = $"Data Source = {t.StrHost}; Initial Catalog = {t.StrServer}; User Id = {t.StrUser}; Password = {t.StrPwd};";
else else
SqlServerDAL.connectionStr = t.StrConnecttion; SqlServerDAL.connectionStr = t.StrConnecttion;
} }
@@ -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();


BIN
dll/CNAS_DBSync.exe Переглянути файл


BIN
dll/CNAS_RunSync.exe Переглянути файл


+ 11
- 3
dll/CNAS_RunSync.exe.config Переглянути файл

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<configuration> <configuration>
<configSections> <configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" /> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
@@ -50,7 +50,9 @@
</filter> </filter>
</appender> </appender>
</log4net> </log4net>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" /></startup>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
</startup>
<runtime> <runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly> <dependentAssembly>
@@ -74,5 +76,11 @@
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" /> <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly> </dependentAssembly>
</assemblyBinding> </assemblyBinding>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime> </runtime>
</configuration>
</configuration>

BIN
dll/CnasSynchronusClient.dll Переглянути файл


BIN
dll/CnasSynchronusDAL.dll Переглянути файл


+ 17
- 0
dll/ErrorLog/20250218.txt Переглянути файл

@@ -17897,3 +17897,20 @@
记录时间:2025-02-18 11:55:16,431 线程ID:[1]- 错误描述:类名:MySQLHelper 方法名:ExecuteDataSet 信息:===-3223-===select COLUMN_NAME AS 'ColumnName',IS_NULLABLE AS 'IsNullable',DATA_TYPE AS 'DataType',CHARACTER_MAXIMUM_LENGTH AS 'CharMaxLenth',CHARACTER_OCTET_LENGTH AS 'CharOcterLenth',NUMERIC_PRECISION AS 'NumericPrecision',NUMERIC_SCALE AS 'NumericScale',COLUMN_COMMENT as 'remark' FROM information_schema.COLUMNS WHERE TABLE_NAME LIKE 'boiler_quality_copy1'System.Data.DataSet 记录时间:2025-02-18 11:55:16,431 线程ID:[1]- 错误描述:类名:MySQLHelper 方法名:ExecuteDataSet 信息:===-3223-===select COLUMN_NAME AS 'ColumnName',IS_NULLABLE AS 'IsNullable',DATA_TYPE AS 'DataType',CHARACTER_MAXIMUM_LENGTH AS 'CharMaxLenth',CHARACTER_OCTET_LENGTH AS 'CharOcterLenth',NUMERIC_PRECISION AS 'NumericPrecision',NUMERIC_SCALE AS 'NumericScale',COLUMN_COMMENT as 'remark' FROM information_schema.COLUMNS WHERE TABLE_NAME LIKE 'boiler_quality_copy1'System.Data.DataSet
记录时间:2025-02-18 11:55:16,436 线程ID:[1]- 错误描述:类名:MySQLHelper 方法名:ExecuteDataSet 信息:===-3333-===select COLUMN_NAME AS 'ColumnName',IS_NULLABLE AS 'IsNullable',DATA_TYPE AS 'DataType',CHARACTER_MAXIMUM_LENGTH AS 'CharMaxLenth',CHARACTER_OCTET_LENGTH AS 'CharOcterLenth',NUMERIC_PRECISION AS 'NumericPrecision',NUMERIC_SCALE AS 'NumericScale',COLUMN_COMMENT as 'remark' FROM information_schema.COLUMNS WHERE TABLE_NAME LIKE 'boiler_quality_copy1'System.Data.DataSet 记录时间:2025-02-18 11:55:16,436 线程ID:[1]- 错误描述:类名:MySQLHelper 方法名:ExecuteDataSet 信息:===-3333-===select COLUMN_NAME AS 'ColumnName',IS_NULLABLE AS 'IsNullable',DATA_TYPE AS 'DataType',CHARACTER_MAXIMUM_LENGTH AS 'CharMaxLenth',CHARACTER_OCTET_LENGTH AS 'CharOcterLenth',NUMERIC_PRECISION AS 'NumericPrecision',NUMERIC_SCALE AS 'NumericScale',COLUMN_COMMENT as 'remark' FROM information_schema.COLUMNS WHERE TABLE_NAME LIKE 'boiler_quality_copy1'System.Data.DataSet
记录时间:2025-02-18 11:55:16,437 线程ID:[1]- 错误描述:类名:MySQLHelper 方法名:ExecuteDataSet 信息:===-3443-===select COLUMN_NAME AS 'ColumnName',IS_NULLABLE AS 'IsNullable',DATA_TYPE AS 'DataType',CHARACTER_MAXIMUM_LENGTH AS 'CharMaxLenth',CHARACTER_OCTET_LENGTH AS 'CharOcterLenth',NUMERIC_PRECISION AS 'NumericPrecision',NUMERIC_SCALE AS 'NumericScale',COLUMN_COMMENT as 'remark' FROM information_schema.COLUMNS WHERE TABLE_NAME LIKE 'boiler_quality_copy1'System.Data.DataSet 记录时间:2025-02-18 11:55:16,437 线程ID:[1]- 错误描述:类名:MySQLHelper 方法名:ExecuteDataSet 信息:===-3443-===select COLUMN_NAME AS 'ColumnName',IS_NULLABLE AS 'IsNullable',DATA_TYPE AS 'DataType',CHARACTER_MAXIMUM_LENGTH AS 'CharMaxLenth',CHARACTER_OCTET_LENGTH AS 'CharOcterLenth',NUMERIC_PRECISION AS 'NumericPrecision',NUMERIC_SCALE AS 'NumericScale',COLUMN_COMMENT as 'remark' FROM information_schema.COLUMNS WHERE TABLE_NAME LIKE 'boiler_quality_copy1'System.Data.DataSet
记录时间:2025-02-18 17:12:24,543 线程ID:[1]- 错误描述:类名:DamengHelper 方法名:ExecuteDataSet 信息:6001,[LOCALHOST:5236 (UNKNOW, UNKNOW)]由于目标计算机积极拒绝,无法连接。 [::1]:5236

记录时间:2025-02-18 17:12:24,578 线程ID:[1]- 错误描述:类名:DmDAL 方法名:GetTableNames 信息:6001,[LOCALHOST:5236 (UNKNOW, UNKNOW)]由于目标计算机积极拒绝,无法连接。 [::1]:5236

记录时间:2025-02-18 17:12:27,035 线程ID:[1]- 错误描述:类名:DamengHelper 方法名:ExecuteDataSet 信息:6001,[LOCALHOST:5236 (UNKNOW, UNKNOW)]由于目标计算机积极拒绝,无法连接。 [::1]:5236

记录时间:2025-02-18 17:12:27,042 线程ID:[1]- 错误描述:类名:DmDAL 方法名:GetTableNames 信息:6001,[LOCALHOST:5236 (UNKNOW, UNKNOW)]由于目标计算机积极拒绝,无法连接。 [::1]:5236

记录时间:2025-02-18 17:12:28,490 线程ID:[1]- 错误描述:类名:DamengHelper 方法名:ExecuteDataSet 信息:6001,[LOCALHOST:5236 (UNKNOW, UNKNOW)]由于目标计算机积极拒绝,无法连接。 [::1]:5236

记录时间:2025-02-18 17:12:28,498 线程ID:[1]- 错误描述:类名:DmDAL 方法名:GetTableNames 信息:6001,[LOCALHOST:5236 (UNKNOW, UNKNOW)]由于目标计算机积极拒绝,无法连接。 [::1]:5236

记录时间:2025-02-18 17:12:51,693 线程ID:[1]- 错误描述:类名:SqlServerDAL 方法名:TestSQLServerLink 信息:ConnectionString 属性尚未初始化。
记录时间:2025-02-18 17:13:54,203 线程ID:[1]- 错误描述:类名:MySQLHelper 方法名:ExecuteDataSet 信息:Access denied for user 'root'@'localhost' (using password: YES)
记录时间:2025-02-18 17:13:54,211 线程ID:[1]- 错误描述:类名:MySQLDAL 方法名:GetTableTypeAndLenth 信息:Access denied for user 'root'@'localhost' (using password: YES)
记录时间:2025-02-18 17:14:45,061 线程ID:[1]- 错误描述:类名:MySQLHelper 方法名:ExecuteDataSet 信息:Access denied for user 'root'@'localhost' (using password: YES)
记录时间:2025-02-18 17:14:45,067 线程ID:[1]- 错误描述:类名:MySQLDAL 方法名:GetTableNames 信息:Access denied for user 'root'@'localhost' (using password: YES)

+ 9800
- 0
dll/ErrorLog/20250219.txt
Різницю між файлами не показано, бо вона завелика
Переглянути файл


BIN
dll/Newtonsoft.Json.dll Переглянути файл


Завантаження…
Відмінити
Зберегти