Pārlūkot izejas kodu

提交加载手动表格

develop
DESKTOP-58BB7H3\ZJH pirms 4 mēnešiem
vecāks
revīzija
a33d33bc05
8 mainītis faili ar 6858 papildinājumiem un 44 dzēšanām
  1. Binārs
      .vs/CNAS_DBSync/v15/.suo
  2. Binārs
      .vs/CNAS_DBSync/v15/Server/sqlite3/storage.ide
  3. Binārs
      .vs/CNAS_DBSync/v15/Server/sqlite3/storage.ide-wal
  4. +4
    -0
      CNAS_DBSync/CNAS_DBSync.csproj
  5. +118
    -44
      CNAS_DBSync/frmSyncParams.cs
  6. Binārs
      dll/CNAS_DBSync.exe
  7. +6736
    -0
      dll/ErrorLog/20250219.txt
  8. Binārs
      dll/Newtonsoft.Json.dll

Binārs
.vs/CNAS_DBSync/v15/.suo Parādīt failu


Binārs
.vs/CNAS_DBSync/v15/Server/sqlite3/storage.ide Parādīt failu


Binārs
.vs/CNAS_DBSync/v15/Server/sqlite3/storage.ide-wal Parādīt failu


+ 4
- 0
CNAS_DBSync/CNAS_DBSync.csproj Parādīt failu

@@ -46,6 +46,10 @@
<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>
</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.ComponentModel.DataAnnotations" />
<Reference Include="System.configuration" />


+ 118
- 44
CNAS_DBSync/frmSyncParams.cs Parādīt failu

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

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

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

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

}

private void frmSyncParams_Load(object sender, EventArgs e)
@@ -65,10 +66,10 @@ namespace CNAS_DBSync
{
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>
@@ -107,7 +108,7 @@ namespace CNAS_DBSync
lstDB.Add(currentSyncItem);
}
//重新保存信息
bIfSaveSuccess=FileOperation.SaveLocalSyncInStrumentData(lstDB);
bIfSaveSuccess = FileOperation.SaveLocalSyncInStrumentData(lstDB);
//委托发送参数
this.ParamsChangedDelegate(syncInstrumentItem);
}
@@ -123,16 +124,16 @@ namespace CNAS_DBSync
MessageBox.Show("关键字段不允许为空!");
return;
}
bIfSaveSuccess =FileOperation.SaveLocalSyncInStrumentData(lstSyncInstrument);
bIfSaveSuccess = FileOperation.SaveLocalSyncInStrumentData(lstSyncInstrument);
}
if(bIfSaveSuccess)
if (bIfSaveSuccess)
MessageBox.Show("保存成功!");
else
MessageBox.Show("保存失败!");
}
catch (Exception ex)
{
MessageBox.Show("保存失败!错误信息为:"+ex.Message.ToString());
MessageBox.Show("保存失败!错误信息为:" + ex.Message.ToString());
AppLog.Error(ex.Message);
}
}
@@ -142,7 +143,7 @@ namespace CNAS_DBSync
foreach (var item in lstSyncInstrument)
{
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)
{
bIfHave = false;
@@ -176,7 +177,7 @@ namespace CNAS_DBSync
frmSystemSetting frmSetting = new frmSystemSetting(lstSyncInstrument);

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

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

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


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

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();
return;
@@ -263,20 +264,20 @@ namespace CNAS_DBSync
else
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);
if(currentSyncItem.SyncInstrumentDSInfo.ServerName!="")
btnLoadDBData_Click(sender, e);
if (currentSyncItem.SyncInstrumentDSInfo.ServerName != "")
btnLoadDBData_Click(sender, e);
}
else
{
{
dgvMapping.DataSource = new BindingList<SyncParamasInfo>();
}
}
else
{
dgvMapping.DataSource =new BindingList<SyncParamasInfo>();
dgvMapping.DataSource = new BindingList<SyncParamasInfo>();
}
}
/// <summary>
@@ -295,7 +296,7 @@ namespace CNAS_DBSync
//dictInstruTables = instrumentData.GetInstrumentData();
//dictInstruTables =
DataTable dtTableType = null;
string strTableName_Instru = cbxInstrument.Text.ToString();
string strTableName_Instru = cbxInstrument.Text.ToString();

switch (currentSyncItem.SyncInstrumentDSInfo.InstrumentDataSourceType)
{
@@ -309,10 +310,10 @@ namespace CNAS_DBSync
dtTableType = SelectTableType.OrcSql(strTableName_Instru, currentSyncItem);
break;
case DataSourceType.PostgreSQL:
dtTableType = SelectTableType.PostgreSql(strTableName_Instru);
dtTableType = SelectTableType.PostgreSql(strTableName_Instru);
break;
case DataSourceType.SQL:
dtTableType = SelectTableType.Sqlserversec(strTableName_Instru, currentSyncItem);
dtTableType = SelectTableType.Sqlserversec(strTableName_Instru, currentSyncItem);
break;
default:
break;
@@ -327,7 +328,7 @@ namespace CNAS_DBSync
}

dgvInstruDS.DataSource = dtInstruShow;
}

/// <summary>
@@ -366,7 +367,7 @@ namespace CNAS_DBSync

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;
}
@@ -388,7 +389,7 @@ namespace CNAS_DBSync

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

//绑定数据
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>
@@ -466,7 +467,7 @@ namespace CNAS_DBSync
frmDatabaseParams frmDatabase = new frmDatabaseParams(currentSyncItem);
frmDatabase.InstrumentDelegate = delegate (SyncInstrumentItemInfo Instrumentitem)
{
this.currentSyncItem = Instrumentitem;
this.currentSyncItem = Instrumentitem;
};
frmDatabase.InstrumentItemData = delegate (Dictionary<string, DataTable> dict)
{
@@ -475,14 +476,12 @@ namespace CNAS_DBSync
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);
}

private void btnLoadDBData_Click(object sender, EventArgs e)

{

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

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

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)
{
dictInstruTables.Clear();
dictInstruTables.Add(cbxInstrument.Text, dataTableStruct);
cbxInstrument_SelectedIndexChanged(null, null);

//return 1;
}
else
@@ -664,6 +707,37 @@ namespace CNAS_DBSync
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)
{
if (dgvMapping.CurrentCell == null) return;
@@ -744,7 +818,7 @@ namespace CNAS_DBSync
MessageBox.Show("请先指定至少一个映射字段。");
return;
}
frmSourceFilter frm = new frmSourceFilter(currentSyncItem,strTableInfoMode);
frmSourceFilter frm = new frmSourceFilter(currentSyncItem, strTableInfoMode);
frm.sourceDataFilterHandler = delegate (SourceDataFilter dataFilter)
{
currentSyncItem.SourceFilter = dataFilter;
@@ -793,7 +867,7 @@ namespace CNAS_DBSync
cbxCNASColumn.Top = txtInstrumentColumn.Top;
cbxCNASColumn.Height = txtInstrumentColumn.Height;
cbxCNASColumn.Width = txtInstrumentColumn.Width;
cbxCNASColumn.Location= txtInstrumentColumn.Location;
cbxCNASColumn.Location = txtInstrumentColumn.Location;

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

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.ShowHelpIndex(this, strHelpFilePath);
System.Diagnostics.Process.Start(strHelpFilePath);


Binārs
dll/CNAS_DBSync.exe Parādīt failu


+ 6736
- 0
dll/ErrorLog/20250219.txt
Failā izmaiņas netiks attēlotas, jo tās ir par lielu
Parādīt failu


Binārs
dll/Newtonsoft.Json.dll Parādīt failu


Notiek ielāde…
Atcelt
Saglabāt