@@ -131,12 +131,12 @@ | |||
this.txtPostgreSqlPort = new System.Windows.Forms.TextBox(); | |||
this.label35 = new System.Windows.Forms.Label(); | |||
this.btnPostgreSqlConn = new System.Windows.Forms.Button(); | |||
this.txtPostgreSqlName = new System.Windows.Forms.TextBox(); | |||
this.txtPostgreSqlServer = new System.Windows.Forms.TextBox(); | |||
this.txtPostgreSqlHost = new System.Windows.Forms.TextBox(); | |||
this.label38 = new System.Windows.Forms.Label(); | |||
this.label39 = new System.Windows.Forms.Label(); | |||
this.txtPostgreSqlPwd = new System.Windows.Forms.TextBox(); | |||
this.txtPostgreSqlUserId = new System.Windows.Forms.TextBox(); | |||
this.txtPostgreSqlUser = new System.Windows.Forms.TextBox(); | |||
this.label40 = new System.Windows.Forms.Label(); | |||
this.label41 = new System.Windows.Forms.Label(); | |||
this.tabCnas = new System.Windows.Forms.TabPage(); | |||
@@ -1271,12 +1271,12 @@ | |||
this.tabPostgreSql.Controls.Add(this.txtPostgreSqlPort); | |||
this.tabPostgreSql.Controls.Add(this.label35); | |||
this.tabPostgreSql.Controls.Add(this.btnPostgreSqlConn); | |||
this.tabPostgreSql.Controls.Add(this.txtPostgreSqlName); | |||
this.tabPostgreSql.Controls.Add(this.txtPostgreSqlServer); | |||
this.tabPostgreSql.Controls.Add(this.txtPostgreSqlHost); | |||
this.tabPostgreSql.Controls.Add(this.label38); | |||
this.tabPostgreSql.Controls.Add(this.label39); | |||
this.tabPostgreSql.Controls.Add(this.txtPostgreSqlPwd); | |||
this.tabPostgreSql.Controls.Add(this.txtPostgreSqlUserId); | |||
this.tabPostgreSql.Controls.Add(this.txtPostgreSqlUser); | |||
this.tabPostgreSql.Controls.Add(this.label40); | |||
this.tabPostgreSql.Controls.Add(this.label41); | |||
this.tabPostgreSql.Location = new System.Drawing.Point(4, 28); | |||
@@ -1313,15 +1313,15 @@ | |||
this.btnPostgreSqlConn.TabIndex = 47; | |||
this.btnPostgreSqlConn.Text = "测试连接"; | |||
this.btnPostgreSqlConn.UseVisualStyleBackColor = true; | |||
this.btnPostgreSqlConn.Click += new System.EventHandler(this.button1_Click); | |||
this.btnPostgreSqlConn.Click += new System.EventHandler(this.btnPostgreSqlConn_Click); | |||
// | |||
// txtPostgreSqlName | |||
// txtPostgreSqlServer | |||
// | |||
this.txtPostgreSqlName.Location = new System.Drawing.Point(145, 90); | |||
this.txtPostgreSqlName.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); | |||
this.txtPostgreSqlName.Name = "txtPostgreSqlName"; | |||
this.txtPostgreSqlName.Size = new System.Drawing.Size(472, 28); | |||
this.txtPostgreSqlName.TabIndex = 42; | |||
this.txtPostgreSqlServer.Location = new System.Drawing.Point(145, 90); | |||
this.txtPostgreSqlServer.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); | |||
this.txtPostgreSqlServer.Name = "txtPostgreSqlServer"; | |||
this.txtPostgreSqlServer.Size = new System.Drawing.Size(472, 28); | |||
this.txtPostgreSqlServer.TabIndex = 42; | |||
// | |||
// txtPostgreSqlHost | |||
// | |||
@@ -1359,13 +1359,13 @@ | |||
this.txtPostgreSqlPwd.Size = new System.Drawing.Size(472, 28); | |||
this.txtPostgreSqlPwd.TabIndex = 45; | |||
// | |||
// txtPostgreSqlUserId | |||
// txtPostgreSqlUser | |||
// | |||
this.txtPostgreSqlUserId.Location = new System.Drawing.Point(145, 133); | |||
this.txtPostgreSqlUserId.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); | |||
this.txtPostgreSqlUserId.Name = "txtPostgreSqlUserId"; | |||
this.txtPostgreSqlUserId.Size = new System.Drawing.Size(472, 28); | |||
this.txtPostgreSqlUserId.TabIndex = 43; | |||
this.txtPostgreSqlUser.Location = new System.Drawing.Point(145, 133); | |||
this.txtPostgreSqlUser.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); | |||
this.txtPostgreSqlUser.Name = "txtPostgreSqlUser"; | |||
this.txtPostgreSqlUser.Size = new System.Drawing.Size(472, 28); | |||
this.txtPostgreSqlUser.TabIndex = 43; | |||
// | |||
// label40 | |||
// | |||
@@ -1801,12 +1801,12 @@ | |||
private System.Windows.Forms.TextBox txtPostgreSqlPort; | |||
private System.Windows.Forms.Label label35; | |||
private System.Windows.Forms.Button btnPostgreSqlConn; | |||
private System.Windows.Forms.TextBox txtPostgreSqlName; | |||
private System.Windows.Forms.TextBox txtPostgreSqlServer; | |||
private System.Windows.Forms.TextBox txtPostgreSqlHost; | |||
private System.Windows.Forms.Label label38; | |||
private System.Windows.Forms.Label label39; | |||
private System.Windows.Forms.TextBox txtPostgreSqlPwd; | |||
private System.Windows.Forms.TextBox txtPostgreSqlUserId; | |||
private System.Windows.Forms.TextBox txtPostgreSqlUser; | |||
private System.Windows.Forms.Label label40; | |||
private System.Windows.Forms.Label label41; | |||
private System.Windows.Forms.TextBox txtMySqlPort; | |||
@@ -13,12 +13,12 @@ using System.Xml.Serialization; | |||
namespace CNAS_DBSync | |||
{ | |||
public delegate void InstrumentItemDataHanlder(Dictionary<string,DataTable> dictInstrument); | |||
public delegate void InstrumentItemDataHanlder(Dictionary<string, DataTable> dictInstrument); | |||
public partial class frmDatabaseParams : Form | |||
{ | |||
public SyncInstrumentItemInfo syncInstrumentItem = new SyncInstrumentItemInfo(); //仪器信息项 | |||
public Dictionary<string, DataTable> dictInstrument = new Dictionary<string, DataTable>(); | |||
public Dictionary<string, DataTable> dictInstrument = new Dictionary<string, DataTable>(); | |||
public InstumentCodeHanlder InstrumentDelegate; //传递仪器编码委托 | |||
public InstrumentItemDataHanlder InstrumentItemData; //传递仪器项委托 | |||
private string strReadExcelMode = ""; //读取Excel数据模式 | |||
@@ -70,12 +70,12 @@ namespace CNAS_DBSync | |||
//如果有旧值,加载旧的值 | |||
switch (syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType) | |||
{ | |||
{ | |||
case DataSourceType.Excel: | |||
this.tabcDS.SelectedIndex = 0; | |||
this.txtInportExcel.Text = syncInstrumentItem.SyncInstrumentDSInfo.Path; | |||
this.cbxExcelRemote.Checked= syncInstrumentItem.SyncInstrumentDSInfo.DsPathType == PathType.Local ? false : true; | |||
this.cbxExcelRemote.Checked = syncInstrumentItem.SyncInstrumentDSInfo.DsPathType == PathType.Local ? false : true; | |||
this.txtRemoteExcelUser.Text = syncInstrumentItem.SyncInstrumentDSInfo.RemoteUser; | |||
this.txtRemoteExcelPwd.Text = syncInstrumentItem.SyncInstrumentDSInfo.RemotePwd; | |||
break; | |||
@@ -101,7 +101,7 @@ namespace CNAS_DBSync | |||
break; | |||
case DataSourceType.SQLLite: | |||
this.tabcDS.SelectedIndex = 3; | |||
this.txtSqlitePath.Text= syncInstrumentItem.SyncInstrumentDSInfo.Path; | |||
this.txtSqlitePath.Text = syncInstrumentItem.SyncInstrumentDSInfo.Path; | |||
this.txtSqliteUser.Text = syncInstrumentItem.SyncInstrumentDSInfo.UserId; | |||
this.txtSqlitePwd.Text = syncInstrumentItem.SyncInstrumentDSInfo.UserPwd; | |||
@@ -120,16 +120,16 @@ namespace CNAS_DBSync | |||
break; | |||
case DataSourceType.MySQL: | |||
this.tabcDS.SelectedIndex = 5; | |||
this.txtMySqlHost.Text= syncInstrumentItem.SyncInstrumentDSInfo.Host; | |||
this.txtMySqlHost.Text = syncInstrumentItem.SyncInstrumentDSInfo.Host; | |||
this.txtMySqlServer.Text = syncInstrumentItem.SyncInstrumentDSInfo.ServerName; | |||
this.txtMySqlUser.Text = syncInstrumentItem.SyncInstrumentDSInfo.UserId; | |||
this.txtMySqlPwd.Text = syncInstrumentItem.SyncInstrumentDSInfo.UserPwd; | |||
this.txtMySqlPort.Text = syncInstrumentItem.SyncInstrumentDSInfo.Port ; | |||
this.txtMySqlPort.Text = syncInstrumentItem.SyncInstrumentDSInfo.Port; | |||
break; | |||
case DataSourceType.Oracle: | |||
this.tabcDS.SelectedIndex = 6; | |||
this.txtOracleHost.Text = syncInstrumentItem.SyncInstrumentDSInfo.Host ; | |||
this.txtOracleHost.Text = syncInstrumentItem.SyncInstrumentDSInfo.Host; | |||
this.txtOracleSource.Text = syncInstrumentItem.SyncInstrumentDSInfo.ServerName; | |||
this.txtOracleUserId.Text = syncInstrumentItem.SyncInstrumentDSInfo.UserId; | |||
this.txtOraclePwd.Text = syncInstrumentItem.SyncInstrumentDSInfo.UserPwd; | |||
@@ -143,8 +143,16 @@ namespace CNAS_DBSync | |||
this.txtRemoteTxtUserId.Text = syncInstrumentItem.SyncInstrumentDSInfo.RemoteUser; | |||
this.txtRemoteTxtPwd.Text = syncInstrumentItem.SyncInstrumentDSInfo.RemotePwd; | |||
break; | |||
case DataSourceType.PostgreSQL: | |||
this.tabcDS.SelectedIndex = 8; | |||
this.txtPostgreSqlHost.Text = syncInstrumentItem.SyncInstrumentDSInfo.Host; | |||
this.txtPostgreSqlServer.Text = syncInstrumentItem.SyncInstrumentDSInfo.ServerName; | |||
this.txtPostgreSqlUser.Text = syncInstrumentItem.SyncInstrumentDSInfo.UserId; | |||
this.txtPostgreSqlPwd.Text = syncInstrumentItem.SyncInstrumentDSInfo.UserPwd; | |||
this.txtPostgreSqlPort.Text = syncInstrumentItem.SyncInstrumentDSInfo.Port; | |||
break; | |||
default: | |||
break; | |||
break; | |||
} | |||
//加载旧的CNAS数据库信息 | |||
@@ -159,7 +167,7 @@ namespace CNAS_DBSync | |||
this.txtDBName.Text = targetDataBaseInfo.DBName; | |||
this.txtDBUser.Text = targetDataBaseInfo.DBUser; | |||
this.txtDBPwd.Text = targetDataBaseInfo.DBPwd; | |||
this.txtPort.Text= targetDataBaseInfo.DBPort; | |||
this.txtPort.Text = targetDataBaseInfo.DBPort; | |||
} | |||
@@ -168,7 +176,7 @@ namespace CNAS_DBSync | |||
{ | |||
//点击确定按钮 | |||
//InstrumentData instrumentData = null; | |||
switch (syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType) | |||
{ | |||
case DataSourceType.Access: | |||
@@ -197,7 +205,7 @@ namespace CNAS_DBSync | |||
syncInstrumentItem.SyncInstrumentDSInfo.Host = this.txtSqlServerHost.Text.Trim(); | |||
syncInstrumentItem.SyncInstrumentDSInfo.ServerName = this.txtSqlServerName.Text.Trim(); | |||
syncInstrumentItem.SyncInstrumentDSInfo.UserId = this.txtSqlServerUser.Text.Trim(); | |||
syncInstrumentItem.SyncInstrumentDSInfo.UserPwd = this.txtSqlServerPwd.Text.Trim(); | |||
syncInstrumentItem.SyncInstrumentDSInfo.UserPwd = this.txtSqlServerPwd.Text.Trim(); | |||
break; | |||
case DataSourceType.MySQL: | |||
syncInstrumentItem.SyncInstrumentDSInfo.Host = this.txtMySqlHost.Text.Trim(); | |||
@@ -236,6 +244,7 @@ namespace CNAS_DBSync | |||
syncInstrumentItem.SyncInstrumentDSInfo.RemotePwd = this.txtRemoteTxtPwd.Text.Trim(); | |||
break; | |||
case DataSourceType.Excel: | |||
case DataSourceType.PostgreSQL: | |||
default: | |||
syncInstrumentItem.SyncInstrumentDSInfo.Path = this.txtInportExcel.Text.Trim(); | |||
syncInstrumentItem.SyncInstrumentDSInfo.Host = ""; | |||
@@ -246,7 +255,7 @@ namespace CNAS_DBSync | |||
syncInstrumentItem.SyncInstrumentDSInfo.DsPathType = this.cbxExcelRemote.Checked ? PathType.Remote : PathType.Local; | |||
syncInstrumentItem.SyncInstrumentDSInfo.RemoteUser = this.txtRemoteExcelUser.Text.Trim(); | |||
syncInstrumentItem.SyncInstrumentDSInfo.RemotePwd = this.txtRemoteExcelPwd.Text.Trim(); | |||
break; | |||
break; | |||
} | |||
object[] obj = new object[] { "", "", "" }; | |||
//instrumentData = InstrumentDataFact.CreateInstrumentDataSource(syncInstrumentItem.SyncInstrumentDSInfo, obj); | |||
@@ -300,7 +309,7 @@ namespace CNAS_DBSync | |||
if (dialog.ShowDialog() == DialogResult.Cancel) return; | |||
this.txtInportExcel.Text = syncInstrumentItem.SyncInstrumentDSInfo.Path = dialog.SelectedPath; | |||
} | |||
} | |||
} | |||
private void tabcDS_Selected(object sender, TabControlEventArgs e) | |||
@@ -309,7 +318,7 @@ namespace CNAS_DBSync | |||
if (e.TabPage == tabExcel) | |||
{ | |||
//检查tabAccess页面是否为空 //检查tabSQLite页面是否为空 | |||
if (!CheckAccessControl() || !CheckSQLiteControl()|| !CheckSQLServerControl()||!CheckMySqlControl() || !CheckOracleControl()||!CheckFoxproControl()||!CheckTxtControl()) | |||
if (!CheckAccessControl() || !CheckSQLiteControl() || !CheckSQLServerControl() || !CheckMySqlControl() || !CheckOracleControl() || !CheckFoxproControl() || !CheckTxtControl()) | |||
{ | |||
if (MessageBox.Show("其他数据源存在已保存数据,继续将删除这些值,是否继续", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK) | |||
{ | |||
@@ -409,7 +418,7 @@ namespace CNAS_DBSync | |||
if (e.TabPage == tabMySql) | |||
{ | |||
//检查tabAccess页面是否为空 //检查tabSQLite页面是否为空 | |||
if (!CheckExcelControl() || !CheckAccessControl() || !CheckSQLiteControl() || !CheckSQLServerControl()||!CheckOracleControl() || !CheckFoxproControl() || !CheckTxtControl()) | |||
if (!CheckExcelControl() || !CheckAccessControl() || !CheckSQLiteControl() || !CheckSQLServerControl() || !CheckOracleControl() || !CheckFoxproControl() || !CheckTxtControl()) | |||
{ | |||
if (MessageBox.Show("其他数据源存在已保存数据,继续将删除这些值,是否继续", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK) | |||
{ | |||
@@ -434,7 +443,7 @@ namespace CNAS_DBSync | |||
if (e.TabPage == tabOracle) | |||
{ | |||
//检查tabAccess页面是否为空 //检查tabSQLite页面是否为空 | |||
if (!CheckExcelControl() || !CheckAccessControl() || !CheckSQLiteControl() || !CheckSQLServerControl()||!CheckMySqlControl() || !CheckFoxproControl() || !CheckTxtControl()) | |||
if (!CheckExcelControl() || !CheckAccessControl() || !CheckSQLiteControl() || !CheckSQLServerControl() || !CheckMySqlControl() || !CheckFoxproControl() || !CheckTxtControl()) | |||
{ | |||
if (MessageBox.Show("其他数据源存在已保存数据,继续将删除这些值,是否继续", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK) | |||
{ | |||
@@ -504,6 +513,34 @@ namespace CNAS_DBSync | |||
} | |||
syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType = DataSourceType.TXT; | |||
} | |||
if (e.TabPage == tabPostgreSql) | |||
{ | |||
if (!CheckExcelControl() || !CheckAccessControl() || !CheckSQLiteControl() || | |||
!CheckSQLServerControl() || !CheckMySqlControl() || !CheckOracleControl() || | |||
!CheckFoxproControl() || !CheckTxtControl()) | |||
{ | |||
if (MessageBox.Show("其他数据源存在已保存数据,继续将删除这些值,是否继续", "提示", | |||
MessageBoxButtons.OKCancel) == DialogResult.OK) | |||
{ | |||
ClearAccessControl(); | |||
ClearExcelControl(); | |||
ClearSqliteControl(); | |||
ClearSQLServerControl(); | |||
ClearMySQLControl(); | |||
ClearOracleControl(); | |||
ClearFoxproControl(); | |||
ClearTxtControl(); | |||
ClearObjectValue(); | |||
} | |||
else | |||
{ | |||
ChangeSelectTabPageByType(); | |||
return; | |||
} | |||
} | |||
syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType = DataSourceType.PostgreSQL; | |||
} | |||
} | |||
//根据数据源类型切换Tab页 | |||
@@ -520,9 +557,9 @@ namespace CNAS_DBSync | |||
case DataSourceType.SQL: | |||
tabcDS.SelectedTab = tabSQLServer; | |||
break; | |||
case DataSourceType.Oracle: | |||
tabcDS.SelectedTab=tabOracle; | |||
break; | |||
case DataSourceType.Oracle: | |||
tabcDS.SelectedTab = tabOracle; | |||
break; | |||
case DataSourceType.FoxPro: | |||
tabcDS.SelectedTab = tabFoxPro; | |||
break; | |||
@@ -530,6 +567,7 @@ namespace CNAS_DBSync | |||
tabcDS.SelectedTab = tabTxt; | |||
break; | |||
case DataSourceType.Excel: | |||
case DataSourceType.PostgreSQL: | |||
default: | |||
tabcDS.SelectedTab = tabExcel; | |||
break; | |||
@@ -570,7 +608,7 @@ namespace CNAS_DBSync | |||
private bool CheckMySqlControl() | |||
{ | |||
if (this.txtMySqlHost.Text.Trim() != "" || this.txtMySqlServer.Text.Trim() != "" || this.txtMySqlUser.Text.Trim() != "" || this.txtMySqlPwd.Text.Trim() != ""|| this.txtMySqlPort.Text.Trim()!="") | |||
if (this.txtMySqlHost.Text.Trim() != "" || this.txtMySqlServer.Text.Trim() != "" || this.txtMySqlUser.Text.Trim() != "" || this.txtMySqlPwd.Text.Trim() != "" || this.txtMySqlPort.Text.Trim() != "") | |||
return false; | |||
else | |||
return true; | |||
@@ -578,7 +616,7 @@ namespace CNAS_DBSync | |||
private bool CheckOracleControl() | |||
{ | |||
if (this.txtOraclePort.Text.Trim() != "" || this.txtOraclePwd.Text.Trim() != ""||this.txtOracleHost.Text.Trim()!="" || this.txtOracleSource.Text.Trim() != "" || this.txtOracleUserId.Text.Trim() != "") | |||
if (this.txtOraclePort.Text.Trim() != "" || this.txtOraclePwd.Text.Trim() != "" || this.txtOracleHost.Text.Trim() != "" || this.txtOracleSource.Text.Trim() != "" || this.txtOracleUserId.Text.Trim() != "") | |||
return false; | |||
else | |||
return true; | |||
@@ -607,11 +645,11 @@ namespace CNAS_DBSync | |||
//this.txtDBHost.Text.Trim(), this.txtDBName.Text.Trim(), this.txtDBUser.Text.Trim(), this.txtDBPwd.Text.Trim(),this.txtPort.Text.Trim() | |||
if (CnasDataOperationFact.CnasDataOperation().TestConnect(new DataBaseInfo() | |||
{ | |||
DBHost= this.txtDBHost.Text.Trim(), | |||
DBName= this.txtDBName.Text.Trim(), | |||
DBUser= this.txtDBUser.Text.Trim(), | |||
DBPwd= this.txtDBPwd.Text.Trim(), | |||
DBPort= this.txtPort.Text.Trim() | |||
DBHost = this.txtDBHost.Text.Trim(), | |||
DBName = this.txtDBName.Text.Trim(), | |||
DBUser = this.txtDBUser.Text.Trim(), | |||
DBPwd = this.txtDBPwd.Text.Trim(), | |||
DBPort = this.txtPort.Text.Trim() | |||
})) | |||
MessageBox.Show("连接成功!"); | |||
else | |||
@@ -774,7 +812,7 @@ namespace CNAS_DBSync | |||
MessageBox.Show("请填写相关连接信息。"); | |||
return; | |||
} | |||
InstrumentDataSourceInfo dbinfo = new InstrumentDataSourceInfo(); | |||
dbinfo.Host = this.txtSqlServerHost.Text.Trim(); | |||
dbinfo.ServerName = this.txtSqlServerName.Text.Trim(); | |||
@@ -859,7 +897,7 @@ namespace CNAS_DBSync | |||
private void btnMySqlTest_Click(object sender, EventArgs e) | |||
{ | |||
if (CnasDataOperationFact.CnasDataOperation().TestConnect(new DataBaseInfo() | |||
{ | |||
DBHost = this.txtMySqlHost.Text.Trim(), | |||
@@ -875,7 +913,7 @@ namespace CNAS_DBSync | |||
private void btnOracleTestLink_Click(object sender, EventArgs e) | |||
{ | |||
if (this.txtOracleHost.Text.Trim()==""||this.txtOracleSource.Text.Trim() == "" || this.txtOracleUserId.Text.Trim() == ""|| this.txtOraclePort.Text.Trim() == "") | |||
if (this.txtOracleHost.Text.Trim() == "" || this.txtOracleSource.Text.Trim() == "" || this.txtOracleUserId.Text.Trim() == "" || this.txtOraclePort.Text.Trim() == "") | |||
{ | |||
MessageBox.Show("请填写相关连接信息。"); | |||
return; | |||
@@ -982,7 +1020,7 @@ namespace CNAS_DBSync | |||
if (dialog.ShowDialog() == DialogResult.Cancel) return; | |||
this.txtInportTxt.Text = syncInstrumentItem.SyncInstrumentDSInfo.Path = dialog.SelectedPath; | |||
} | |||
} | |||
} | |||
private void cbxRemoteTxt_CheckedChanged(object sender, EventArgs e) | |||
@@ -1013,7 +1051,8 @@ namespace CNAS_DBSync | |||
{ | |||
if (GlobalCommonOperation.strStartWebApi == "1") | |||
{ | |||
targetDataBaseInfo = new DataBaseInfo() { | |||
targetDataBaseInfo = new DataBaseInfo() | |||
{ | |||
DataBaseCode = "cnas" | |||
}; | |||
} | |||
@@ -1028,7 +1067,7 @@ namespace CNAS_DBSync | |||
this.txtDBPwd.Text = CNASDataBase.DBPwd; | |||
this.txtPort.Text = CNASDataBase.DBPort; | |||
} | |||
} | |||
} | |||
} | |||
else if (cbxTargetDBSelect.SelectedIndex == 1) | |||
{ | |||
@@ -1050,13 +1089,61 @@ namespace CNAS_DBSync | |||
this.txtDBPwd.Text = PlatDataBase.DBPwd; | |||
this.txtPort.Text = PlatDataBase.DBPort; | |||
} | |||
} | |||
} | |||
} | |||
} | |||
private void button1_Click(object sender, EventArgs e) | |||
private void btnPostgreSqlConn_Click(object sender, EventArgs e) | |||
{ | |||
if (CnasDataOperationFact.CnasDataOperation().TestConnect(new DataBaseInfo() | |||
{ | |||
DBHost = this.txtPostgreSqlHost.Text.Trim(), | |||
DBName = this.txtPostgreSqlServer.Text.Trim(), | |||
DBUser = this.txtPostgreSqlUser.Text.Trim(), | |||
DBPwd = this.txtPostgreSqlPwd.Text.Trim(), | |||
DBPort = this.txtPostgreSqlPort.Text.Trim() | |||
})) | |||
MessageBox.Show("连接成功!"); | |||
else | |||
MessageBox.Show("连接失败!"); | |||
//if (this.txtPostgreSqlHost.Text.Trim() == "" || this.txtPostgreSqlServer.Text.Trim() == "" || | |||
// this.txtPostgreSqlUser.Text.Trim() == "" || this.txtPostgreSqlPort.Text.Trim() == "") | |||
//{ | |||
// MessageBox.Show("请填写相关连接信息。"); | |||
// return; | |||
//} | |||
//InstrumentDataSourceInfo dbinfo = new InstrumentDataSourceInfo(); | |||
//dbinfo.Host = this.txtPostgreSqlHost.Text.Trim(); | |||
//dbinfo.ServerName = this.txtPostgreSqlServer.Text.Trim(); | |||
//dbinfo.UserId = this.txtPostgreSqlUser.Text.Trim(); | |||
//dbinfo.UserPwd = this.txtPostgreSqlPwd.Text.Trim(); | |||
//dbinfo.Port = this.txtPostgreSqlPort.Text.Trim(); | |||
//if (new PostgreSqlInstrumentData(dbinfo, new object[] { "", "", "" }).TestConnection()) | |||
// MessageBox.Show("连接成功!"); | |||
//else | |||
// MessageBox.Show("连接失败!"); | |||
} | |||
private bool CheckPostgreSqlControl() | |||
{ | |||
if (this.txtPostgreSqlHost.Text.Trim() != "" || this.txtPostgreSqlServer.Text.Trim() != "" || | |||
this.txtPostgreSqlUser.Text.Trim() != "" || this.txtPostgreSqlPwd.Text.Trim() != "" || | |||
this.txtPostgreSqlPort.Text.Trim() != "") | |||
return false; | |||
else | |||
return true; | |||
} | |||
private void ClearPostgreSqlControl() | |||
{ | |||
this.txtPostgreSqlHost.Text = ""; | |||
this.txtPostgreSqlServer.Text = ""; | |||
this.txtPostgreSqlUser.Text = ""; | |||
this.txtPostgreSqlPwd.Text = ""; | |||
this.txtPostgreSqlPort.Text = ""; | |||
} | |||
} | |||
} |
@@ -36,7 +36,11 @@ namespace CnasSynchronusClient | |||
case "ORACLE": | |||
operation = new OracleCnasDataOperation(); | |||
break; | |||
case "POSTGRESQL": | |||
operation = new PostgreSQLSQLCNASDataOperation(); | |||
break; | |||
case "DB2": | |||
default: | |||
operation = new DB2CNASDataOperation(); | |||
break; | |||
@@ -0,0 +1,118 @@ | |||
using CnasSynchronousCommon; | |||
using CnasSynchronusDAL; | |||
using CnasSynchronusIDAL; | |||
using CnasSynchrousModel; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Data; | |||
using System.Linq; | |||
using System.Text; | |||
namespace CnasSynchronusClient | |||
{ | |||
/// <summary> | |||
/// MySQL数据库数据操作类 | |||
/// </summary> | |||
public class PostgreSQLSQLCNASDataOperation : ICnasDataOperation | |||
{ | |||
public IPostgreSqlDBService mysqlDataBaseService | |||
{ | |||
get | |||
{ | |||
return new PostgreSqlDBService(); | |||
} | |||
} | |||
/// <summary> | |||
/// 验证MAC | |||
/// </summary> | |||
/// <param name="dataBase"></param> | |||
/// <param name="strMac"></param> | |||
/// <returns></returns> | |||
public bool CheckMacMessage(DataBaseInfo dataBase, string strMac) | |||
{ | |||
return mysqlDataBaseService.CheckMacMessage(dataBase, strMac); | |||
} | |||
public DataTable GetAllCNASTablesName(DataBaseInfo dataBase) | |||
{ | |||
return mysqlDataBaseService.GetAllCNASTablesName(dataBase); | |||
} | |||
public DataTable GetCNASTablesStruct(string strTableName, DataBaseInfo dataBase) | |||
{ | |||
return mysqlDataBaseService.GetCNASTablesStruct(strTableName, dataBase); | |||
} | |||
public DataTable GetCNASTableTypeLenth(string strTableName, DataBaseInfo dataBase) | |||
{ | |||
return mysqlDataBaseService.GetCNASTableTypeLenth(strTableName, dataBase); | |||
} | |||
public DataTable GetLoginNameByPwd(DataBaseInfo dataBase, string strUserName, string strPwd) | |||
{ | |||
return mysqlDataBaseService.GetLoginNameByPwd(dataBase, strUserName, strPwd); | |||
} | |||
public string GetMaxTimeByTableName(DataBaseInfo dataBase, string strTableName, string strDateColumn, string strInstrumentColumn, string strInstrumentValue) | |||
{ | |||
return mysqlDataBaseService.GetMaxTimeByTableName(dataBase, strTableName, strDateColumn, strInstrumentColumn, strInstrumentValue); | |||
} | |||
public int InsertDataToCNASTable(DataTable dt, DataBaseInfo dataBase, List<SyncParamasInfo> syncParamasInfos, string strInstrumentColumn, List<CnasConditionMapValue> lstFixedValue) | |||
{ | |||
return mysqlDataBaseService.InsertDataToCNASTable(dt, dataBase, syncParamasInfos, strInstrumentColumn, lstFixedValue); | |||
} | |||
public bool TestConnect(string strHost, string strName, string strUser, string strPwd, string strPort) | |||
{ | |||
return mysqlDataBaseService.TestConnect(strHost, strName, strUser, strPwd, strPort); | |||
} | |||
public bool TestConnect(DataBaseInfo dataBase) | |||
{ | |||
return mysqlDataBaseService.TestConnect(dataBase.DBHost, dataBase.DBName, dataBase.DBUser, dataBase.DBPwd, dataBase.DBPort); | |||
} | |||
/// <summary> | |||
/// 获取某个表的数据 | |||
/// </summary> | |||
/// <param name="dataBase"></param> | |||
/// <param name="strSql"></param> | |||
/// <returns></returns> | |||
public DataTable GetTableData(DataBaseInfo dataBase, string strSql) | |||
{ | |||
DataTable dt = new DataTable(); | |||
try | |||
{ | |||
dt = mysqlDataBaseService.GetTableData(dataBase, strSql); | |||
} | |||
catch (Exception ex) | |||
{ | |||
AppLog.Error(ex.Message); | |||
} | |||
return dt; | |||
} | |||
/// <summary> | |||
/// 插入某个表的数据 | |||
/// </summary> | |||
/// <param name="dataBase"></param> | |||
/// <param name="strSql"></param> | |||
/// <returns></returns> | |||
public bool InsertTableData(DataBaseInfo dataBase, string strSql) | |||
{ | |||
try | |||
{ | |||
return mysqlDataBaseService.InsertTableData(dataBase, strSql); | |||
} | |||
catch (Exception ex) | |||
{ | |||
AppLog.Error(ex.Message); | |||
} | |||
return false; | |||
} | |||
} | |||
} |
@@ -0,0 +1,517 @@ | |||
| |||
using System; | |||
using System.Collections.Generic; | |||
using System.Data; | |||
using System.Linq; | |||
using System.Text; | |||
using CnasSynchronousCommon; | |||
namespace CnasSynchronusDAL | |||
{ | |||
public static class PostgreSQLHelper | |||
{ | |||
private static String mConnStr = null; | |||
public static void InitConnectionString(string strServerIP,string strServerPort,string strServerHost,string strServerUser,string strServerPwd) | |||
{ | |||
mConnStr = "server=" + strServerIP + ";port=" + strServerPort + ";user=" + strServerUser + ";password=" + strServerPwd + ";database=" + strServerHost + ";CharSet=utf8;Allow User Variables=True"; | |||
} | |||
public static void InitConnectionString(string strConnectiong) | |||
{ | |||
mConnStr = strConnectiong; | |||
} | |||
/// <summary> | |||
/// 对SQLite数据库执行增删改操作,返回受影响的行数。 | |||
/// </summary> | |||
/// <param name="sql">要执行的增删改的SQL语句</param> | |||
/// <returns></returns> | |||
public static int ExecuteNonQuery(String sql) | |||
{ | |||
MySqlConnection connection = new MySqlConnection(mConnStr); | |||
try | |||
{ | |||
using (connection) | |||
{ | |||
connection.Open(); | |||
MySqlTransaction transaction = connection.BeginTransaction(); | |||
using (MySqlCommand cmd = new MySqlCommand()) | |||
{ | |||
try | |||
{ | |||
PrepareCommand(cmd, connection, transaction, CommandType.Text, sql, null); | |||
int rows = cmd.ExecuteNonQuery(); | |||
transaction.Commit(); | |||
cmd.Parameters.Clear(); | |||
return rows; | |||
} | |||
catch (MySqlException e1) | |||
{ | |||
try | |||
{ | |||
transaction.Rollback(); | |||
} | |||
catch (Exception e2) | |||
{ | |||
AppLog.Error(e2.Message); | |||
throw e2; | |||
} | |||
AppLog.Error(e1.Message); | |||
throw e1; | |||
} | |||
} | |||
} | |||
} | |||
catch (Exception e) | |||
{ | |||
AppLog.Error(e.Message); | |||
throw e; | |||
} | |||
finally | |||
{ | |||
if (connection != null) | |||
{ | |||
//关闭数据库连接 | |||
connection.Close(); | |||
} | |||
} | |||
} | |||
/// <summary> | |||
/// 对数据库执行增删改操作,返回受影响的行数。 | |||
/// </summary> | |||
/// <param name="sql">要执行的增删改的SQL语句</param> | |||
/// <returns></returns> | |||
public static int ExecuteNonQuery(String sql, MySqlParameter[] cmdParams) | |||
{ | |||
try | |||
{ | |||
using (MySqlConnection connection = new MySqlConnection(mConnStr)) | |||
{ | |||
connection.Open(); | |||
MySqlTransaction transaction = connection.BeginTransaction(); | |||
using (MySqlCommand cmd = new MySqlCommand()) | |||
{ | |||
try | |||
{ | |||
PrepareCommand(cmd, connection, transaction, CommandType.Text, sql, cmdParams); | |||
int rows = cmd.ExecuteNonQuery(); | |||
transaction.Commit(); | |||
cmd.Parameters.Clear(); | |||
return rows; | |||
} | |||
catch (MySqlException e1) | |||
{ | |||
try | |||
{ | |||
transaction.Rollback(); | |||
} | |||
catch (Exception e2) | |||
{ | |||
AppLog.Error(e2.Message); | |||
throw e2; | |||
} | |||
AppLog.Error(e1.Message); | |||
throw e1; | |||
} | |||
} | |||
} | |||
} | |||
catch (Exception e) | |||
{ | |||
AppLog.Error(e.Message); | |||
throw e; | |||
} | |||
} | |||
/// <summary> | |||
/// 对SQLite数据库执行操作,返回 返回第一行第一列数据 | |||
/// </summary> | |||
/// <param name="sql"></param> | |||
/// <returns></returns> | |||
public static int ExecuteScalar(String sql) | |||
{ | |||
try | |||
{ | |||
using (MySqlConnection connection = new MySqlConnection(mConnStr)) | |||
{ | |||
connection.Open(); | |||
MySqlTransaction transaction = connection.BeginTransaction(); | |||
using (MySqlCommand cmd = new MySqlCommand()) | |||
{ | |||
try | |||
{ | |||
int line = 0; | |||
PrepareCommand(cmd, connection, transaction, CommandType.Text, sql, null); | |||
String str = cmd.ExecuteScalar().ToString(); | |||
transaction.Commit(); | |||
line = Convert.ToInt32(str); | |||
cmd.Parameters.Clear(); | |||
return line; | |||
} | |||
catch (MySqlException e1) | |||
{ | |||
try | |||
{ | |||
transaction.Rollback(); | |||
} | |||
catch (Exception e2) | |||
{ | |||
AppLog.Error(e2.Message); | |||
throw e2; | |||
} | |||
AppLog.Error(e1.Message); | |||
throw e1; | |||
} | |||
} | |||
} | |||
} | |||
catch (Exception e) | |||
{ | |||
AppLog.Error(e.Message); | |||
throw e; | |||
} | |||
} | |||
/// <summary> | |||
/// 对SQLite数据库执行操作,返回 返回第一行第一列数据 | |||
/// </summary> | |||
/// <param name="sql"></param> | |||
/// <returns></returns> | |||
public static int ExecuteScalar(String sql, MySqlParameter[] cmdParams) | |||
{ | |||
try | |||
{ | |||
using (MySqlConnection connection = new MySqlConnection(mConnStr)) | |||
{ | |||
connection.Open(); | |||
MySqlTransaction transaction = connection.BeginTransaction(); | |||
using (MySqlCommand cmd = new MySqlCommand()) | |||
{ | |||
try | |||
{ | |||
int line = 0; | |||
PrepareCommand(cmd, connection, transaction, CommandType.Text, sql, cmdParams); | |||
String str = cmd.ExecuteScalar().ToString(); | |||
transaction.Commit(); | |||
line = Convert.ToInt32(str); | |||
cmd.Parameters.Clear(); | |||
return line; | |||
} | |||
catch (MySqlException e1) | |||
{ | |||
try | |||
{ | |||
transaction.Rollback(); | |||
} | |||
catch (Exception e2) | |||
{ | |||
AppLog.Error(e2.Message); | |||
throw e2; | |||
} | |||
AppLog.Error(e1.Message); | |||
throw e1; | |||
} | |||
} | |||
} | |||
} | |||
catch (Exception e) | |||
{ | |||
AppLog.Error(e.Message); | |||
throw e; | |||
} | |||
} | |||
/// <summary> | |||
/// 用执行的数据库连接执行一个返回数据集的sql命令 | |||
/// </summary> | |||
/// <param name="sql"></param> | |||
/// <returns></returns> | |||
public static MySqlDataReader ExecuteReader(String sql) | |||
{ | |||
try | |||
{ | |||
//创建一个MySqlConnection对象 | |||
using (MySqlConnection connection = new MySqlConnection(mConnStr)) | |||
{ | |||
connection.Open(); | |||
MySqlTransaction transaction = connection.BeginTransaction(); | |||
//创建一个MySqlCommand对象 | |||
using (MySqlCommand cmd = new MySqlCommand()) | |||
{ | |||
try | |||
{ | |||
PrepareCommand(cmd, connection, transaction, CommandType.Text, sql, null); | |||
MySqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection); | |||
transaction.Commit(); | |||
cmd.Parameters.Clear(); | |||
return reader; | |||
} | |||
catch (MySqlException e1) | |||
{ | |||
try | |||
{ | |||
transaction.Rollback(); | |||
} | |||
catch (Exception e2) | |||
{ | |||
AppLog.Error(e2.Message); | |||
throw e2; | |||
} | |||
AppLog.Error(e1.Message); | |||
throw e1; | |||
} | |||
} | |||
} | |||
} | |||
catch (Exception e) | |||
{ | |||
AppLog.Error(e.Message); | |||
throw e; | |||
} | |||
} | |||
/// <summary> | |||
/// 查询返回Dtaset | |||
/// </summary> | |||
/// <param name="sql"></param> | |||
/// <returns></returns> | |||
public static DataSet ExecuteDataSet(String sql) | |||
{ | |||
MySqlConnection connection = new MySqlConnection(mConnStr); | |||
try | |||
{ | |||
//创建一个MySqlConnection对象 | |||
using (connection) | |||
{ | |||
connection.Open(); | |||
MySqlTransaction transaction = connection.BeginTransaction(); | |||
//创建一个MySqlCommand对象 | |||
using (MySqlCommand cmd = new MySqlCommand()) | |||
{ | |||
try | |||
{ | |||
AppLog.Error("===-3113-==="+ sql + mConnStr); | |||
PrepareCommand(cmd, connection, transaction, CommandType.Text, sql, null); | |||
AppLog.Error("===-3223-==="+ sql + mConnStr); | |||
MySqlDataAdapter adapter = new MySqlDataAdapter(); | |||
adapter.SelectCommand = cmd; | |||
DataSet ds = new DataSet(); | |||
AppLog.Error("===-3223-==="+ sql + ds); | |||
adapter.Fill(ds); | |||
AppLog.Error("===-3333-==="+ sql + ds); | |||
transaction.Commit(); | |||
AppLog.Error("===-3443-==="+ sql + ds); | |||
//清除参数 | |||
cmd.Parameters.Clear(); | |||
return ds; | |||
AppLog.Error("===-3553-==="+ sql + ds); | |||
} | |||
catch (MySqlException e1) | |||
{ | |||
try | |||
{ | |||
transaction.Rollback(); | |||
} | |||
catch (Exception e2) | |||
{ | |||
AppLog.Error(e2.Message); | |||
throw e2; | |||
} | |||
AppLog.Error(e1.Message); | |||
throw e1; | |||
} | |||
} | |||
} | |||
} | |||
catch (Exception e) | |||
{ | |||
AppLog.Error(e.Message); | |||
throw e; | |||
}finally | |||
{ | |||
if (connection != null) | |||
{ | |||
//关闭数据库连接 | |||
connection.Close(); | |||
} | |||
} | |||
} | |||
/// <summary> | |||
/// 执行sql 返回一个DataTable | |||
/// </summary> | |||
/// <param name="sqlText"></param> | |||
/// <param name="parameters"></param> | |||
/// <returns></returns> | |||
public static DataTable ExecuteDataTable(string sqlText, params MySqlParameter[] parameters) | |||
{ | |||
DataTable dt = null; | |||
try | |||
{ | |||
using (MySqlDataAdapter adapter = new MySqlDataAdapter(sqlText, mConnStr)) | |||
{ | |||
dt = new DataTable(); | |||
adapter.SelectCommand.Parameters.AddRange(parameters); | |||
adapter.Fill(dt); | |||
return dt; | |||
} | |||
} | |||
catch (Exception ex) | |||
{ | |||
AppLog.Error(ex.Message); | |||
} | |||
return null; | |||
} | |||
/// <summary> | |||
/// 查询返回Dtaset | |||
/// </summary> | |||
/// <param name="sql"></param> | |||
/// <returns></returns> | |||
public static DataSet ExecuteDataSet(String sql, MySqlParameter[] cmdParams) | |||
{ | |||
MySqlConnection connection = new MySqlConnection(mConnStr); | |||
try | |||
{ | |||
//创建一个MySqlConnection对象 | |||
using (connection) | |||
{ | |||
connection.Open(); | |||
MySqlTransaction transaction = connection.BeginTransaction(); | |||
//创建一个MySqlCommand对象 | |||
using (MySqlCommand cmd = new MySqlCommand()) | |||
{ | |||
try | |||
{ | |||
PrepareCommand(cmd, connection, transaction, CommandType.Text, sql, cmdParams); | |||
MySqlDataAdapter adapter = new MySqlDataAdapter(); | |||
adapter.SelectCommand = cmd; | |||
DataSet ds = new DataSet(); | |||
adapter.Fill(ds); | |||
transaction.Commit(); | |||
//清除参数 | |||
cmd.Parameters.Clear(); | |||
return ds; | |||
} | |||
catch (MySqlException e1) | |||
{ | |||
try | |||
{ | |||
transaction.Rollback(); | |||
} | |||
catch (Exception e2) | |||
{ | |||
AppLog.Error(e2.Message); | |||
throw e2; | |||
} | |||
AppLog.Error(e1.Message); | |||
throw e1; | |||
} | |||
} | |||
} | |||
} | |||
catch (Exception e) | |||
{ | |||
AppLog.Error(e.Message); | |||
throw e; | |||
}finally | |||
{ | |||
if (connection != null) | |||
{ | |||
//关闭数据库连接 | |||
connection.Close(); | |||
} | |||
} | |||
} | |||
/// <summary> | |||
/// 准备执行一个命令 | |||
/// </summary> | |||
/// <param name="cmd">sql命令</param> | |||
/// <param name="conn">OleDb连接</param> | |||
/// <param name="trans">OleDb事务</param> | |||
/// <param name="cmdType">命令类型例如 存储过程或者文本</param> | |||
/// <param name="cmdText">命令文本,例如:Select * from Products</param> | |||
/// <param name="cmdParms">执行命令的参数</param> | |||
private static void PrepareCommand(MySqlCommand cmd, MySqlConnection conn, MySqlTransaction trans, CommandType cmdType, string cmdText, MySqlParameter[] cmdParms) | |||
{ | |||
if (conn.State != ConnectionState.Open) | |||
conn.Open(); | |||
cmd.Connection = conn; | |||
cmd.CommandText = cmdText; | |||
if (trans != null) | |||
cmd.Transaction = trans; | |||
cmd.CommandType = cmdType; | |||
if (cmdParms != null) | |||
{ | |||
foreach (MySqlParameter parm in cmdParms) | |||
cmd.Parameters.Add(parm); | |||
} | |||
} | |||
public static bool TestConnectMySql() | |||
{ | |||
bool bIfSuccess = false; | |||
try | |||
{ | |||
//创建一个MySqlConnection对象 | |||
using (MySqlConnection connection = new MySqlConnection(mConnStr)) | |||
{ | |||
connection.Open(); | |||
if (connection.State == System.Data.ConnectionState.Open) | |||
bIfSuccess = true; | |||
} | |||
} | |||
catch (Exception ex) | |||
{ | |||
AppLog.Error(ex.Message); | |||
bIfSuccess = false; | |||
} | |||
return bIfSuccess; | |||
} | |||
} | |||
} |
@@ -3,7 +3,7 @@ using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Data; | |||
using MySql.Data.MySqlClient; | |||
using CnasSynchronousCommon; | |||
using CnasSynchrousModel; | |||
using System.Reflection; | |||
@@ -13,9 +13,9 @@ namespace CnasSynchronusDAL | |||
{ | |||
public class PostgreSqlDAL | |||
{ | |||
public void CreateConnectString(string strIP,string strPort,string strName, string strUser, string strPwd) | |||
{ | |||
MySQLHelper.InitConnectionString(strIP,strPort,strName,strUser,strPwd); | |||
public void CreateConnectString(string strIP, string strPort, string strName, string strUser, string strPwd) | |||
{ | |||
MySQLHelper.InitConnectionString(strIP, strPort, strName, strUser, strPwd); | |||
} | |||
public void CreateConnectString(string strConnectString) | |||
@@ -44,7 +44,7 @@ namespace CnasSynchronusDAL | |||
/// </summary> | |||
/// <param name="strTableName"></param> | |||
/// <returns></returns> | |||
public DataTable GetTableStruct(string strTableName,string strViewName,string strViewSql) | |||
public DataTable GetTableStruct(string strTableName, string strViewName, string strViewSql) | |||
{ | |||
DataTable dt = new DataTable(); | |||
if (strTableName.Length <= 0) return dt; | |||
@@ -55,9 +55,9 @@ namespace CnasSynchronusDAL | |||
strSql = string.Format("SELECT * FROM {0} Where 0=1", strTableName); | |||
try | |||
{ | |||
AppLog.Error("===-222-==="+ strTableName + strSql); | |||
AppLog.Error("===-222-===" + strTableName + strSql); | |||
dt = MySQLHelper.ExecuteDataSet(strSql).Tables[0]; | |||
AppLog.Error("===-333-==="+ strTableName + "MySQLHelper.ExecuteDataSet(strSql)" + dt); | |||
AppLog.Error("===-333-===" + strTableName + "MySQLHelper.ExecuteDataSet(strSql)" + dt); | |||
} | |||
catch (Exception ex) | |||
{ | |||
@@ -92,7 +92,7 @@ namespace CnasSynchronusDAL | |||
/// </summary> | |||
/// <param name="dt"></param> | |||
/// <returns></returns> | |||
public int InsertCnasData(DataTable dt, List<SyncParamasInfo> syncParamasInfos, List<CnasConditionMapValue> lstFixedValue,string strInsumentColumn) | |||
public int InsertCnasData(DataTable dt, List<SyncParamasInfo> syncParamasInfos, List<CnasConditionMapValue> lstFixedValue, string strInsumentColumn) | |||
{ | |||
int iReturn = 0; | |||
if (dt.Rows.Count <= 0) return 0; | |||
@@ -127,7 +127,7 @@ namespace CnasSynchronusDAL | |||
//如果映射列中不包含固定列,则需要将这些列添加到SQL语句中 | |||
if (lstFixedValue != null) | |||
{ | |||
{ | |||
foreach (var cnasfield in lstFixedValue) | |||
{ | |||
if (cnasfield.TableName != syncParamasInfos[0].TargetTable) continue; | |||
@@ -163,7 +163,7 @@ namespace CnasSynchronusDAL | |||
} | |||
//插入时发现已经在数据库中存在该值,则进行更新操作 | |||
int ifHavaValue = ExistSingleCnasData(lstKeyColumns, syncParamasInfos[0].TargetTable, dr, ref dtSelect); | |||
if (ifHavaValue==1) | |||
if (ifHavaValue == 1) | |||
{ | |||
if (dtSelect.Rows.Count == 1) | |||
{ | |||
@@ -186,7 +186,7 @@ namespace CnasSynchronusDAL | |||
AppLog.Error("更新时发现在数据库中多条相同关键字段数据,请重新配置关键字段。"); | |||
} | |||
} | |||
else if(ifHavaValue==0) | |||
else if (ifHavaValue == 0) | |||
{ | |||
//执行InsertSQL语句 | |||
iReturn += MySQLHelper.ExecuteNonQuery(strInsertSql, parameters); | |||
@@ -211,7 +211,7 @@ namespace CnasSynchronusDAL | |||
/// <param name="lstColumnName"></param> | |||
/// <param name="lstPrimaryColumn"></param> | |||
/// <param name="dr"></param> | |||
private string GetUpdateSql(List<string> lstColumnName,List<string> lstPrimaryColumn, string strTableName,DataRow dr) | |||
private string GetUpdateSql(List<string> lstColumnName, List<string> lstPrimaryColumn, string strTableName, DataRow dr) | |||
{ | |||
//构造关键字段条件 | |||
string strsql_partial = ""; | |||
@@ -232,8 +232,8 @@ namespace CnasSynchronusDAL | |||
strsql_partial2 += $"{item}=@{item},"; | |||
} | |||
if(strsql_partial.Length > 3&&strsql_partial2.Length>0) | |||
strUpdateSql = $"update {strTableName} set {strsql_partial2.Substring(0,strsql_partial2.Length-1)} where {strsql_partial.Substring(0, strsql_partial.Length - 4)}"; | |||
if (strsql_partial.Length > 3 && strsql_partial2.Length > 0) | |||
strUpdateSql = $"update {strTableName} set {strsql_partial2.Substring(0, strsql_partial2.Length - 1)} where {strsql_partial.Substring(0, strsql_partial.Length - 4)}"; | |||
return strUpdateSql; | |||
} | |||
@@ -265,7 +265,7 @@ namespace CnasSynchronusDAL | |||
/// <param name="dr"></param> | |||
/// <param name="dtSelect"></param> | |||
/// <returns></returns> | |||
private int ExistSingleCnasData(List<string> lstPrimaryColumn, string strTableName, DataRow dr,ref DataTable dtSelect) | |||
private int ExistSingleCnasData(List<string> lstPrimaryColumn, string strTableName, DataRow dr, ref DataTable dtSelect) | |||
{ | |||
int bIfHaveValue = 0; //如果存在,返回1;如果不存在,返回0;如果发生了异常,返回-1 | |||
string strsql_partial = ""; | |||
@@ -286,7 +286,7 @@ namespace CnasSynchronusDAL | |||
if (strSql != "") | |||
{ | |||
DataTable dt = MySQLHelper.ExecuteDataTable(strSql,new MySqlParameter[] { }); | |||
DataTable dt = MySQLHelper.ExecuteDataTable(strSql, new MySqlParameter[] { }); | |||
if (dt != null && dt.Rows.Count > 0) | |||
{ | |||
bIfHaveValue = 1; | |||
@@ -304,7 +304,7 @@ namespace CnasSynchronusDAL | |||
internal DataTable GetLoginNameByPwd(string strUserName, string strPwd) | |||
{ | |||
DataTable dt = new DataTable(); | |||
string strSql = string.Format("select * FROM user WHERE userid='{0}' and password='{1}'", strUserName,strPwd); | |||
string strSql = string.Format("select * FROM user WHERE userid='{0}' and password='{1}'", strUserName, strPwd); | |||
try | |||
{ | |||
dt = MySQLHelper.ExecuteDataSet(strSql).Tables[0]; | |||
@@ -326,7 +326,7 @@ namespace CnasSynchronusDAL | |||
/// </summary> | |||
/// <param name="dt"></param> | |||
/// <returns></returns> | |||
public string GetMaxTimeByTableName(string strTableName,string strDateColumn, string strInstrumentColumn, string strInstrumentValue) | |||
public string GetMaxTimeByTableName(string strTableName, string strDateColumn, string strInstrumentColumn, string strInstrumentValue) | |||
{ | |||
string strReturnTime = ""; | |||
//因为数据库用varchar存储日期字段,从而格式不固定,需要使用多种格式读取 | |||
@@ -365,8 +365,8 @@ namespace CnasSynchronusDAL | |||
# endregion | |||
string strSql = string.Format("SELECT Convert(max(Convert({0},datetime)) using utf8) FROM {1}", strDateColumn, strTableName, strInstrumentColumn, strInstrumentValue); | |||
if(!string.IsNullOrWhiteSpace(strInstrumentColumn)&& !string.IsNullOrWhiteSpace(strInstrumentValue)) | |||
strSql+= string.Format(" where {0}='{1}'", strInstrumentColumn,strInstrumentValue); | |||
if (!string.IsNullOrWhiteSpace(strInstrumentColumn) && !string.IsNullOrWhiteSpace(strInstrumentValue)) | |||
strSql += string.Format(" where {0}='{1}'", strInstrumentColumn, strInstrumentValue); | |||
string strDateTime = GetMaxTimeByTableName(strSql); | |||
DateTime dateTime = DateTime.Now; | |||
if (DateTime.TryParse(strDateTime, out dateTime)) | |||
@@ -387,7 +387,7 @@ namespace CnasSynchronusDAL | |||
return strReturnTime; | |||
} | |||
internal DataTable GetDataByDateColumn(string strDBName,string strViewName,string strViewSql,string strTableName, string strDateColumn, string strDate) | |||
internal DataTable GetDataByDateColumn(string strDBName, string strViewName, string strViewSql, string strTableName, string strDateColumn, string strDate) | |||
{ | |||
DataTable dtReturn = new DataTable(); | |||
try | |||
@@ -399,7 +399,7 @@ namespace CnasSynchronusDAL | |||
strSql = $"select * from {strDBName}.{strTableName} where {strDateColumn} >convert( '{strDate}',datetime)"; | |||
DataTable dt = MySQLHelper.ExecuteDataSet(strSql).Tables[0]; | |||
Dictionary<string, string> dictFiled = GetSpecialOperaField(strDBName,strTableName); | |||
Dictionary<string, string> dictFiled = GetSpecialOperaField(strDBName, strTableName); | |||
if (dictFiled.Count > 0) | |||
dtReturn = DateAndTimeTypeOpera(dt, dictFiled); | |||
else | |||
@@ -423,10 +423,10 @@ namespace CnasSynchronusDAL | |||
foreach (DataRow dr in TablesName.Rows) | |||
{ | |||
string strTableName = dr[0].ToString(); | |||
AppLog.Error("===---==="+ strTableName + "GetTableStruct(strTableName, )"); | |||
dictTables.Add(strTableName.ToUpper(), GetTableStruct(strTableName,"","")); | |||
AppLog.Error("===---===" + strTableName + "GetTableStruct(strTableName, )"); | |||
dictTables.Add(strTableName.ToUpper(), GetTableStruct(strTableName, "", "")); | |||
} | |||
} | |||
catch (Exception ex) | |||
{ | |||
@@ -442,7 +442,7 @@ namespace CnasSynchronusDAL | |||
string strDateTime = ""; | |||
try | |||
{ | |||
DataTable dt = MySQLHelper.ExecuteDataSet(strSql).Tables[0]; | |||
AppLog.Info($"执行语句获得最晚时间:{strSql}"); | |||
if (dt != null && dt.Rows.Count == 1) | |||
@@ -467,7 +467,7 @@ namespace CnasSynchronusDAL | |||
/// 获取所有数据字段,然后记录其中是否存在需要特殊处理的字段 | |||
/// </summary> | |||
/// <returns></returns> | |||
private static Dictionary<string, string> GetSpecialOperaField(string strDBName,string strTableName) | |||
private static Dictionary<string, string> GetSpecialOperaField(string strDBName, string strTableName) | |||
{ | |||
Dictionary<string, string> DictFiled = new Dictionary<string, string>(); | |||
DataTable dt = new DataTable(); | |||
@@ -563,7 +563,7 @@ namespace CnasSynchronusDAL | |||
public DataTable GetTableData(string strSql) | |||
{ | |||
DataTable dt = new DataTable(); | |||
try | |||
try | |||
{ | |||
dt = MySQLHelper.ExecuteDataSet(strSql).Tables[0]; | |||
} | |||
@@ -581,10 +581,10 @@ namespace CnasSynchronusDAL | |||
/// <returns></returns> | |||
public bool InsertTableData(string strSql) | |||
{ | |||
try | |||
{ | |||
return MySQLHelper.ExecuteNonQuery(strSql)>0; | |||
return MySQLHelper.ExecuteNonQuery(strSql) > 0; | |||
} | |||
catch (Exception ex) | |||
{ | |||