using CnasSynchronusClient; using CnasSynchrousModel; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Windows.Forms; using System.Xml.Serialization; namespace CNAS_DBSync { public delegate void InstrumentItemDataHanlder(Dictionary dictInstrument); public partial class frmDatabaseParams : Form { public SyncInstrumentItemInfo syncInstrumentItem = new SyncInstrumentItemInfo(); //仪器信息项 public Dictionary dictInstrument = new Dictionary(); public InstumentCodeHanlder InstrumentDelegate; //传递仪器编码委托 public InstrumentItemDataHanlder InstrumentItemData; //传递仪器项委托 private string strReadExcelMode = ""; //读取Excel数据模式 private string strReadFoxproMode = ""; //读取Foxpro数据模式 private string strReadTxtMode = "";//读取Txt数据模式 private string strReadSqliteMode = ""; //读取sqlite数据模式 private string strReadAccessMode = ""; //读取Access数据模式 public DataBaseInfo targetDataBaseInfo = new DataBaseInfo(); //数据库 public SqlServerFormatConfig sqlServerFormat { get; set; } public frmDatabaseParams(SyncInstrumentItemInfo syncInstrumentItem) { InitializeComponent(); this.syncInstrumentItem = syncInstrumentItem; //读取Excel和FoxPro的模式 strReadExcelMode = FileOperation.GetFormatConfigData("ExcelFormatConfig.xml").ReadExcelFileMode; strReadFoxproMode = FileOperation.GetFormatConfigData("FoxProFormatConfig.xml").ReadFoxProFileMode; strReadTxtMode = FileOperation.GetFormatConfigData("NormalFileFormatConfig.xml").ReadNormalFileMode; strReadSqliteMode = FileOperation.GetFormatConfigData("SqliteFormatConfig.xml").ReadSqliteFileMode; strReadAccessMode = FileOperation.GetFormatConfigData("AccessFormatConfig.xml").ReadAccessFileMode; sqlServerFormat = FileOperation.GetFormatConfigData("SqlServerFormatConfig.xml"); if (GlobalCommonOperation.strStartWebApi == "1") { this.txtDBHost.Enabled = false; this.txtDBName.Enabled = false; this.txtDBUser.Enabled = false; this.txtDBPwd.Enabled = false; this.txtPort.Enabled = false; btnCNASTestLink.Enabled = false; } } private void frmDatabaseParams_Load(object sender, EventArgs e) { tabExcel.Text = strReadExcelMode == "0" ? "Excel(文件)" : "Excel(文件夹)"; tabFoxPro.Text = strReadFoxproMode == "0" ? "Foxpro(文件)" : "Foxpro(文件夹)"; tabTxt.Text = strReadTxtMode == "0" ? "TXT(文件)" : "TXT(文件夹)"; tabSQLite.Text = strReadSqliteMode == "0" ? "Sqlite(文件)" : "Sqlite(文件夹)"; tabAccess.Text = strReadAccessMode == "0" ? "Access(文件)" : "Access(文件夹)"; //if(sqlServerFormat) if (syncInstrumentItem.SyncInstrumentDSInfo == null) syncInstrumentItem.SyncInstrumentDSInfo = new InstrumentDataSourceInfo(); //如果有旧值,加载旧的值 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.txtRemoteExcelUser.Text = syncInstrumentItem.SyncInstrumentDSInfo.RemoteUser; this.txtRemoteExcelPwd.Text = syncInstrumentItem.SyncInstrumentDSInfo.RemotePwd; break; case DataSourceType.FoxPro: this.tabcDS.SelectedIndex = 1; this.txtFoxProFolder.Text = syncInstrumentItem.SyncInstrumentDSInfo.Path; this.txtFoxProUserId.Text = syncInstrumentItem.SyncInstrumentDSInfo.UserId; this.txtFoxProPwd.Text = syncInstrumentItem.SyncInstrumentDSInfo.UserPwd; this.cbxFoxProRemote.Checked = syncInstrumentItem.SyncInstrumentDSInfo.DsPathType == PathType.Local ? false : true; this.txtRemoteFoxProUserId.Text = syncInstrumentItem.SyncInstrumentDSInfo.RemoteUser; this.txtRemoteFoxProPwd.Text = syncInstrumentItem.SyncInstrumentDSInfo.RemotePwd; break; case DataSourceType.Access: this.tabcDS.SelectedIndex = 2; this.txtAccessPath.Text = syncInstrumentItem.SyncInstrumentDSInfo.Path; this.txtAccessUser.Text = syncInstrumentItem.SyncInstrumentDSInfo.UserId; this.txtAceessPwd.Text = syncInstrumentItem.SyncInstrumentDSInfo.UserPwd; this.cbxAccessRemote.Checked = syncInstrumentItem.SyncInstrumentDSInfo.DsPathType == PathType.Local ? false : true; this.txtAccessRemoteUser.Text = syncInstrumentItem.SyncInstrumentDSInfo.RemoteUser; this.txtAccessRemotePwd.Text = syncInstrumentItem.SyncInstrumentDSInfo.RemotePwd; break; case DataSourceType.SQLLite: this.tabcDS.SelectedIndex = 3; this.txtSqlitePath.Text= syncInstrumentItem.SyncInstrumentDSInfo.Path; this.txtSqliteUser.Text = syncInstrumentItem.SyncInstrumentDSInfo.UserId; this.txtSqlitePwd.Text = syncInstrumentItem.SyncInstrumentDSInfo.UserPwd; this.cbxSqliteRemote.Checked = syncInstrumentItem.SyncInstrumentDSInfo.DsPathType == PathType.Local ? false : true; this.txtSqliteRemoteUser.Text = syncInstrumentItem.SyncInstrumentDSInfo.RemoteUser; this.txtSqliteRemotePwd.Text = syncInstrumentItem.SyncInstrumentDSInfo.RemotePwd; break; case DataSourceType.SQL: this.tabcDS.SelectedIndex = 4; this.txtSqlServerHost.Text = syncInstrumentItem.SyncInstrumentDSInfo.Host; this.txtSqlServerName.Text = syncInstrumentItem.SyncInstrumentDSInfo.ServerName; this.txtSqlServerUser.Text = syncInstrumentItem.SyncInstrumentDSInfo.UserId; this.txtSqlServerPwd.Text = syncInstrumentItem.SyncInstrumentDSInfo.UserPwd; //this.txtSqlServerConnect.Text = sqlServerFormat.SqlServerConnection; break; case DataSourceType.MySQL: this.tabcDS.SelectedIndex = 5; 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 ; break; case DataSourceType.Oracle: this.tabcDS.SelectedIndex = 6; this.txtOracleHost.Text = syncInstrumentItem.SyncInstrumentDSInfo.Host ; this.txtOracleSource.Text = syncInstrumentItem.SyncInstrumentDSInfo.ServerName; this.txtOracleUserId.Text = syncInstrumentItem.SyncInstrumentDSInfo.UserId; this.txtOraclePwd.Text = syncInstrumentItem.SyncInstrumentDSInfo.UserPwd; this.txtOraclePort.Text = syncInstrumentItem.SyncInstrumentDSInfo.Port; break; case DataSourceType.TXT: this.tabcDS.SelectedIndex = 7; this.txtInportTxt.Text = syncInstrumentItem.SyncInstrumentDSInfo.Path; this.cbxRemoteTxt.Checked = syncInstrumentItem.SyncInstrumentDSInfo.DsPathType == PathType.Local ? false : true; this.txtRemoteTxtUserId.Text = syncInstrumentItem.SyncInstrumentDSInfo.RemoteUser; this.txtRemoteTxtPwd.Text = syncInstrumentItem.SyncInstrumentDSInfo.RemotePwd; break; default: break; } //加载旧的CNAS数据库信息 if (syncInstrumentItem.SyncTargetDBInfo != null) { targetDataBaseInfo = syncInstrumentItem.SyncTargetDBInfo; } else syncInstrumentItem.SyncTargetDBInfo = new DataBaseInfo(); this.txtDBHost.Text = targetDataBaseInfo.DBHost; this.txtDBName.Text = targetDataBaseInfo.DBName; this.txtDBUser.Text = targetDataBaseInfo.DBUser; this.txtDBPwd.Text = targetDataBaseInfo.DBPwd; this.txtPort.Text= targetDataBaseInfo.DBPort; } private void btnOK_Click(object sender, EventArgs e) { //点击确定按钮 //InstrumentData instrumentData = null; switch (syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType) { case DataSourceType.Access: syncInstrumentItem.SyncInstrumentDSInfo.Path = this.txtAccessPath.Text.Trim(); syncInstrumentItem.SyncInstrumentDSInfo.Host = ""; syncInstrumentItem.SyncInstrumentDSInfo.ServerName = ""; syncInstrumentItem.SyncInstrumentDSInfo.UserId = this.txtAccessUser.Text.Trim(); syncInstrumentItem.SyncInstrumentDSInfo.UserPwd = this.txtAceessPwd.Text.Trim(); syncInstrumentItem.SyncInstrumentDSInfo.DsPathType = this.cbxAccessRemote.Checked ? PathType.Remote : PathType.Local; syncInstrumentItem.SyncInstrumentDSInfo.RemoteUser = this.txtAccessRemoteUser.Text.Trim(); syncInstrumentItem.SyncInstrumentDSInfo.RemotePwd = this.txtAccessRemotePwd.Text.Trim(); break; case DataSourceType.SQLLite: syncInstrumentItem.SyncInstrumentDSInfo.Path = this.txtSqlitePath.Text.Trim(); syncInstrumentItem.SyncInstrumentDSInfo.Host = ""; syncInstrumentItem.SyncInstrumentDSInfo.ServerName = ""; syncInstrumentItem.SyncInstrumentDSInfo.UserId = this.txtSqliteUser.Text.Trim(); syncInstrumentItem.SyncInstrumentDSInfo.UserPwd = this.txtSqlitePwd.Text.Trim(); syncInstrumentItem.SyncInstrumentDSInfo.DsPathType = this.cbxSqliteRemote.Checked ? PathType.Remote : PathType.Local; syncInstrumentItem.SyncInstrumentDSInfo.RemoteUser = this.txtSqliteRemoteUser.Text.Trim(); syncInstrumentItem.SyncInstrumentDSInfo.RemotePwd = this.txtSqliteRemotePwd.Text.Trim(); break; case DataSourceType.SQL: 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(); break; case DataSourceType.MySQL: syncInstrumentItem.SyncInstrumentDSInfo.Host = this.txtMySqlHost.Text.Trim(); syncInstrumentItem.SyncInstrumentDSInfo.ServerName = this.txtMySqlServer.Text.Trim(); syncInstrumentItem.SyncInstrumentDSInfo.UserId = this.txtMySqlUser.Text.Trim(); syncInstrumentItem.SyncInstrumentDSInfo.UserPwd = this.txtMySqlPwd.Text.Trim(); syncInstrumentItem.SyncInstrumentDSInfo.Port = this.txtMySqlPort.Text.Trim(); break; case DataSourceType.Oracle: syncInstrumentItem.SyncInstrumentDSInfo.Host = this.txtOracleHost.Text.Trim(); syncInstrumentItem.SyncInstrumentDSInfo.ServerName = this.txtOracleSource.Text.Trim(); syncInstrumentItem.SyncInstrumentDSInfo.UserId = this.txtOracleUserId.Text.Trim(); syncInstrumentItem.SyncInstrumentDSInfo.UserPwd = this.txtOraclePwd.Text.Trim(); syncInstrumentItem.SyncInstrumentDSInfo.Port = this.txtOraclePort.Text.Trim(); break; case DataSourceType.FoxPro: syncInstrumentItem.SyncInstrumentDSInfo.Path = this.txtFoxProFolder.Text.Trim(); syncInstrumentItem.SyncInstrumentDSInfo.Host = ""; syncInstrumentItem.SyncInstrumentDSInfo.ServerName = ""; syncInstrumentItem.SyncInstrumentDSInfo.UserId = this.txtFoxProUserId.Text.Trim(); syncInstrumentItem.SyncInstrumentDSInfo.UserPwd = this.txtFoxProPwd.Text.Trim(); syncInstrumentItem.SyncInstrumentDSInfo.DsPathType = this.cbxFoxProRemote.Checked ? PathType.Remote : PathType.Local; syncInstrumentItem.SyncInstrumentDSInfo.RemoteUser = this.txtRemoteFoxProUserId.Text.Trim(); syncInstrumentItem.SyncInstrumentDSInfo.RemotePwd = this.txtRemoteFoxProPwd.Text.Trim(); break; case DataSourceType.TXT: syncInstrumentItem.SyncInstrumentDSInfo.Path = this.txtInportTxt.Text.Trim(); syncInstrumentItem.SyncInstrumentDSInfo.Host = ""; syncInstrumentItem.SyncInstrumentDSInfo.ServerName = ""; syncInstrumentItem.SyncInstrumentDSInfo.UserId = ""; syncInstrumentItem.SyncInstrumentDSInfo.UserPwd = ""; syncInstrumentItem.SyncInstrumentDSInfo.DsPathType = this.cbxRemoteTxt.Checked ? PathType.Remote : PathType.Local; syncInstrumentItem.SyncInstrumentDSInfo.RemoteUser = this.txtRemoteTxtUserId.Text.Trim(); syncInstrumentItem.SyncInstrumentDSInfo.RemotePwd = this.txtRemoteTxtPwd.Text.Trim(); break; case DataSourceType.Excel: default: syncInstrumentItem.SyncInstrumentDSInfo.Path = this.txtInportExcel.Text.Trim(); syncInstrumentItem.SyncInstrumentDSInfo.Host = ""; syncInstrumentItem.SyncInstrumentDSInfo.ServerName = ""; syncInstrumentItem.SyncInstrumentDSInfo.UserId = ""; syncInstrumentItem.SyncInstrumentDSInfo.UserPwd = ""; 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; } object[] obj = new object[] { "", "", "" }; //instrumentData = InstrumentDataFact.CreateInstrumentDataSource(syncInstrumentItem.SyncInstrumentDSInfo, obj); //dictInstrument = instrumentData.GetInstrumentData(); //目标库的信息 if (GlobalCommonOperation.strStartWebApi != "1") { syncInstrumentItem.SyncTargetDBInfo.DBHost = this.txtDBHost.Text.Trim(); syncInstrumentItem.SyncTargetDBInfo.DBName = this.txtDBName.Text.Trim(); syncInstrumentItem.SyncTargetDBInfo.DBUser = this.txtDBUser.Text.Trim(); syncInstrumentItem.SyncTargetDBInfo.DBPwd = this.txtDBPwd.Text.Trim(); syncInstrumentItem.SyncTargetDBInfo.DBPort = this.txtPort.Text.Trim(); } else syncInstrumentItem.SyncTargetDBInfo = targetDataBaseInfo; this.InstrumentDelegate(syncInstrumentItem); //this.InstrumentItemData(dictInstrument); this.Close(); } private void btnOpenFileExcel_Click(object sender, EventArgs e) { if (syncInstrumentItem.Code == null) return; if (syncInstrumentItem.SyncInstrumentDSInfo == null) syncInstrumentItem.SyncInstrumentDSInfo = new InstrumentDataSourceInfo(); syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType = DataSourceType.Excel; if (strReadExcelMode == "0") { OpenFileDialog openFile = new OpenFileDialog { Filter = "Excel(*.xlsx)|*.xlsx|Excel(*.xls)|*.xls", InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop), Multiselect = false }; if (openFile.ShowDialog() == DialogResult.Cancel) return; this.txtInportExcel.Text = syncInstrumentItem.SyncInstrumentDSInfo.Path = openFile.FileName; string fileType = System.IO.Path.GetExtension(openFile.FileName); if (string.IsNullOrEmpty(fileType)) return; } else { FolderBrowserDialog dialog = new FolderBrowserDialog(); dialog.Description = "请选择文件路径"; if (dialog.ShowDialog() == DialogResult.Cancel) return; this.txtInportExcel.Text = syncInstrumentItem.SyncInstrumentDSInfo.Path = dialog.SelectedPath; } } private void tabcDS_Selected(object sender, TabControlEventArgs e) { //切换的时候,检查其他类型数据源是否有值,如果有值,将提示删除旧值才能配置新值 if (e.TabPage == tabExcel) { //检查tabAccess页面是否为空 //检查tabSQLite页面是否为空 if (!CheckAccessControl() || !CheckSQLiteControl()|| !CheckSQLServerControl()||!CheckMySqlControl() || !CheckOracleControl()||!CheckFoxproControl()||!CheckTxtControl()) { if (MessageBox.Show("其他数据源存在已保存数据,继续将删除这些值,是否继续", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK) { ClearAccessControl(); ClearSqliteControl(); ClearSQLServerControl(); ClearMySQLControl(); ClearOracleControl(); ClearFoxproControl(); ClearTxtControl(); ClearObjectValue(); } else { ChangeSelectTabPageByType(); return; } } syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType = DataSourceType.Excel; } if (e.TabPage == tabAccess) { //检查tabAccess页面是否为空 //检查tabSQLite页面是否为空 if (!CheckExcelControl() || !CheckSQLiteControl() || !CheckSQLServerControl() || !CheckMySqlControl() || !CheckOracleControl() || !CheckFoxproControl() || !CheckTxtControl()) { if (MessageBox.Show("其他数据源存在已保存数据,继续将删除这些值,是否继续", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK) { ClearExcelControl(); ClearSqliteControl(); ClearSQLServerControl(); ClearMySQLControl(); ClearOracleControl(); ClearFoxproControl(); ClearTxtControl(); ClearObjectValue(); } else { ChangeSelectTabPageByType(); return; } } syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType = DataSourceType.Access; } if (e.TabPage == tabSQLite) { //检查tabAccess页面是否为空 //检查tabSQLite页面是否为空 if (!CheckExcelControl() || !CheckAccessControl() || !CheckSQLServerControl() || !CheckMySqlControl() || !CheckOracleControl() || !CheckFoxproControl() || !CheckTxtControl()) { if (MessageBox.Show("其他数据源存在已保存数据,继续将删除这些值,是否继续", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK) { ClearAccessControl(); ClearExcelControl(); ClearSQLServerControl(); ClearMySQLControl(); ClearOracleControl(); ClearFoxproControl(); ClearTxtControl(); ClearObjectValue(); } else { ChangeSelectTabPageByType(); return; } } syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType = DataSourceType.SQLLite; } if (e.TabPage == tabSQLServer) { //检查tabAccess页面是否为空 //检查tabSQLite页面是否为空 if (!CheckExcelControl() || !CheckAccessControl() || !CheckSQLiteControl() || !CheckMySqlControl() || !CheckOracleControl() || !CheckFoxproControl() || !CheckTxtControl()) { if (MessageBox.Show("其他数据源存在已保存数据,继续将删除这些值,是否继续", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK) { ClearAccessControl(); ClearExcelControl(); ClearSqliteControl(); ClearMySQLControl(); ClearOracleControl(); ClearFoxproControl(); ClearTxtControl(); ClearObjectValue(); } else { ChangeSelectTabPageByType(); return; } } syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType = DataSourceType.SQL; } if (e.TabPage == tabMySql) { //检查tabAccess页面是否为空 //检查tabSQLite页面是否为空 if (!CheckExcelControl() || !CheckAccessControl() || !CheckSQLiteControl() || !CheckSQLServerControl()||!CheckOracleControl() || !CheckFoxproControl() || !CheckTxtControl()) { if (MessageBox.Show("其他数据源存在已保存数据,继续将删除这些值,是否继续", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK) { ClearAccessControl(); ClearExcelControl(); ClearSqliteControl(); ClearSQLServerControl(); ClearOracleControl(); ClearFoxproControl(); ClearTxtControl(); ClearObjectValue(); } else { ChangeSelectTabPageByType(); return; } } syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType = DataSourceType.MySQL; } if (e.TabPage == tabOracle) { //检查tabAccess页面是否为空 //检查tabSQLite页面是否为空 if (!CheckExcelControl() || !CheckAccessControl() || !CheckSQLiteControl() || !CheckSQLServerControl()||!CheckMySqlControl() || !CheckFoxproControl() || !CheckTxtControl()) { if (MessageBox.Show("其他数据源存在已保存数据,继续将删除这些值,是否继续", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK) { ClearAccessControl(); ClearExcelControl(); ClearSqliteControl(); ClearSQLServerControl(); ClearMySQLControl(); ClearFoxproControl(); ClearTxtControl(); ClearObjectValue(); } else { ChangeSelectTabPageByType(); return; } } syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType = DataSourceType.Oracle; } if (e.TabPage == tabFoxPro) { if (!CheckExcelControl() || !CheckAccessControl() || !CheckSQLiteControl() || !CheckSQLServerControl() || !CheckMySqlControl() || !CheckOracleControl() || !CheckTxtControl()) { if (MessageBox.Show("其他数据源存在已保存数据,继续将删除这些值,是否继续", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK) { ClearAccessControl(); ClearExcelControl(); ClearSqliteControl(); ClearSQLServerControl(); ClearMySQLControl(); ClearOracleControl(); ClearTxtControl(); ClearObjectValue(); } else { ChangeSelectTabPageByType(); return; } } syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType = DataSourceType.FoxPro; } if (e.TabPage == tabTxt) { if (!CheckExcelControl() || !CheckAccessControl() || !CheckSQLiteControl() || !CheckSQLServerControl() || !CheckMySqlControl() || !CheckOracleControl() || !CheckFoxproControl()) { if (MessageBox.Show("其他数据源存在已保存数据,继续将删除这些值,是否继续", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK) { ClearAccessControl(); ClearExcelControl(); ClearSqliteControl(); ClearSQLServerControl(); ClearMySQLControl(); ClearOracleControl(); ClearFoxproControl(); ClearObjectValue(); } else { ChangeSelectTabPageByType(); return; } } syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType = DataSourceType.TXT; } } //根据数据源类型切换Tab页 private void ChangeSelectTabPageByType() { switch (syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType) { case DataSourceType.SQLLite: tabcDS.SelectedTab = tabSQLite; break; case DataSourceType.Access: tabcDS.SelectedTab = tabAccess; break; case DataSourceType.SQL: tabcDS.SelectedTab = tabSQLServer; break; case DataSourceType.Oracle: tabcDS.SelectedTab=tabOracle; break; case DataSourceType.FoxPro: tabcDS.SelectedTab = tabFoxPro; break; case DataSourceType.TXT: tabcDS.SelectedTab = tabTxt; break; case DataSourceType.Excel: default: tabcDS.SelectedTab = tabExcel; break; } } private bool CheckExcelControl() { if (this.txtInportExcel.Text != "") return false; else return true; } private bool CheckAccessControl() { if (this.txtAccessPath.Text != "" || this.txtAccessUser.Text != "" || this.txtAceessPwd.Text != "") return false; else return true; } private bool CheckSQLiteControl() { if (this.txtSqlitePath.Text != "" || this.txtSqliteUser.Text != "" || this.txtSqlitePwd.Text != "") return false; else return true; } private bool CheckSQLServerControl() { if (this.txtSqlServerHost.Text.Trim() != "" || this.txtSqlServerName.Text.Trim() != "" || this.txtSqlServerPwd.Text.Trim() != "" || this.txtSqlServerUser.Text.Trim() != "") return false; else return true; } private bool CheckMySqlControl() { 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; } private bool CheckOracleControl() { 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; } private bool CheckFoxproControl() { if (this.txtFoxProFolder.Text.Trim() != "" || this.txtFoxProUserId.Text.Trim() != "" || this.txtFoxProPwd.Text.Trim() != "" || this.txtRemoteFoxProUserId.Text.Trim() != "" || this.txtRemoteFoxProPwd.Text.Trim() != "") { return false; } else return true; } private bool CheckTxtControl() { if (this.txtInportTxt.Text.Trim() != "" || this.txtRemoteTxtUserId.Text.Trim() != "" || this.txtRemoteTxtPwd.Text.Trim() != "") return false; else return true; } private void btnCNASTestLink_Click(object sender, EventArgs e) { //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() })) MessageBox.Show("连接成功!"); else MessageBox.Show("连接失败!"); } private void ClearExcelControl() { this.txtInportExcel.Text = ""; this.txtRemoteExcelUser.Text = ""; this.txtRemoteExcelPwd.Text = ""; } private void ClearAccessControl() { this.txtAccessPath.Text = ""; this.txtAccessUser.Text = ""; this.txtAceessPwd.Text = ""; this.txtAccessRemoteUser.Text = ""; this.txtAccessRemotePwd.Text = ""; } private void ClearSqliteControl() { this.txtSqliteUser.Text = ""; this.txtSqlitePath.Text = ""; this.txtSqlitePwd.Text = ""; this.txtSqliteRemoteUser.Text = ""; this.txtSqliteRemotePwd.Text = ""; } private void ClearSQLServerControl() { this.txtSqlServerHost.Text = ""; this.txtSqlServerName.Text = ""; this.txtSqlServerUser.Text = ""; this.txtSqlServerPwd.Text = ""; } private void ClearMySQLControl() { this.txtMySqlHost.Text = ""; this.txtMySqlServer.Text = ""; this.txtMySqlUser.Text = ""; this.txtMySqlPwd.Text = ""; this.txtMySqlPort.Text = ""; } private void ClearOracleControl() { this.txtOracleHost.Text = ""; this.txtOracleSource.Text = ""; this.txtOracleUserId.Text = ""; this.txtOraclePwd.Text = ""; this.txtOraclePort.Text = ""; } private void ClearFoxproControl() { this.txtFoxProFolder.Text = ""; this.txtFoxProUserId.Text = ""; this.txtFoxProPwd.Text = ""; this.txtRemoteFoxProUserId.Text = ""; this.txtRemoteFoxProPwd.Text = ""; } private void ClearTxtControl() { this.txtInportTxt.Text = ""; this.txtRemoteTxtUserId.Text = ""; this.txtRemoteTxtPwd.Text = ""; } /// /// 清空对象中存储的值 /// private void ClearObjectValue() { syncInstrumentItem.SyncInstrumentDSInfo.Host = ""; syncInstrumentItem.SyncInstrumentDSInfo.ServerName = ""; syncInstrumentItem.SyncInstrumentDSInfo.Path = ""; syncInstrumentItem.SyncInstrumentDSInfo.UserId = ""; syncInstrumentItem.SyncInstrumentDSInfo.UserPwd = ""; syncInstrumentItem.SyncInstrumentDSInfo.Port = ""; syncInstrumentItem.SyncInstrumentDSInfo.DsPathType = PathType.Local; syncInstrumentItem.SyncInstrumentDSInfo.RemoteUser = ""; syncInstrumentItem.SyncInstrumentDSInfo.RemotePwd = ""; } private void btnOpenFileAccess_Click(object sender, EventArgs e) { if (syncInstrumentItem.Code == null) return; if (syncInstrumentItem.SyncInstrumentDSInfo == null) syncInstrumentItem.SyncInstrumentDSInfo = new InstrumentDataSourceInfo(); syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType = DataSourceType.Access; if (strReadAccessMode == "0") { OpenFileDialog openFile = new OpenFileDialog { Filter = "Microsoft Access(*.mdb)|*.mdb|Microsoft Access(*.accdb)|*.accdb", InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop), Multiselect = false }; if (openFile.ShowDialog() == DialogResult.Cancel) return; this.txtAccessPath.Text = syncInstrumentItem.SyncInstrumentDSInfo.Path = openFile.FileName; string fileType = System.IO.Path.GetExtension(openFile.FileName); if (string.IsNullOrEmpty(fileType)) return; } else { FolderBrowserDialog dialog = new FolderBrowserDialog(); dialog.Description = "请选择文件路径"; if (dialog.ShowDialog() == DialogResult.Cancel) return; this.txtAccessPath.Text = syncInstrumentItem.SyncInstrumentDSInfo.Path = dialog.SelectedPath; } } private void btnOpenFileSQLite_Click(object sender, EventArgs e) { if (syncInstrumentItem.Code == null) return; if (syncInstrumentItem.SyncInstrumentDSInfo == null) syncInstrumentItem.SyncInstrumentDSInfo = new InstrumentDataSourceInfo(); syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType = DataSourceType.SQLLite; if (strReadSqliteMode == "0") { OpenFileDialog openFile = new OpenFileDialog { Filter = "SQLite(*.db)|*.db", InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop), Multiselect = false }; if (openFile.ShowDialog() == DialogResult.Cancel) return; this.txtSqlitePath.Text = syncInstrumentItem.SyncInstrumentDSInfo.Path = openFile.FileName; string fileType = System.IO.Path.GetExtension(openFile.FileName); if (string.IsNullOrEmpty(fileType)) return; } else { FolderBrowserDialog dialog = new FolderBrowserDialog(); dialog.Description = "请选择文件路径"; if (dialog.ShowDialog() == DialogResult.Cancel) return; this.txtSqlitePath.Text = syncInstrumentItem.SyncInstrumentDSInfo.Path = dialog.SelectedPath; } } private void btnTestSQLLink_Click(object sender, EventArgs e) { if (this.txtSqlServerHost.Text.Trim() == "" || this.txtSqlServerName.Text.Trim() == "" || this.txtSqlServerUser.Text.Trim() == "") { MessageBox.Show("请填写相关连接信息。"); return; } InstrumentDataSourceInfo dbinfo = new InstrumentDataSourceInfo(); dbinfo.Host = this.txtSqlServerHost.Text.Trim(); dbinfo.ServerName = this.txtSqlServerName.Text.Trim(); dbinfo.UserId = this.txtSqlServerUser.Text.Trim(); dbinfo.UserPwd = this.txtSqlServerPwd.Text.Trim(); dbinfo.Port = this.txtSqlServerPort.Text.Trim(); if (new SQLServerInstrumentData(dbinfo, new object[] { "", "", "" }).TestSQLServerLink()) MessageBox.Show("连接成功!"); else MessageBox.Show("连接失败!"); } private void cbxExcelRemote_CheckedChanged(object sender, EventArgs e) { if (!cbxExcelRemote.Checked) { this.btnOpenFileExcel.Visible = true; lblExcelRemotePwd.Visible = false; lblExcelRemoteUser.Visible = false; txtRemoteExcelUser.Visible = false; txtRemoteExcelPwd.Visible = false; } else { this.btnOpenFileExcel.Visible = false; lblExcelRemotePwd.Visible = true; lblExcelRemoteUser.Visible = true; txtRemoteExcelUser.Visible = true; txtRemoteExcelPwd.Visible = true; } } private void cbxAccessRemote_CheckedChanged(object sender, EventArgs e) { if (cbxAccessRemote.Checked) { btnOpenFileAccess.Visible = false; lblAccessRemoteUser.Visible = true; lblAccessRemotePwd.Visible = true; txtAccessRemoteUser.Visible = true; txtAccessRemotePwd.Visible = true; } else { btnOpenFileAccess.Visible = true; lblAccessRemoteUser.Visible = false; lblAccessRemotePwd.Visible = false; txtAccessRemoteUser.Visible = false; txtAccessRemotePwd.Visible = false; } } private void cbxSqliteRemote_CheckedChanged(object sender, EventArgs e) { if (cbxSqliteRemote.Checked) { btnOpenFileSQLite.Visible = false; lblSqliteRemoteUser.Visible = true; lblSqliteRemotePwd.Visible = true; txtSqliteRemoteUser.Visible = true; txtSqliteRemotePwd.Visible = true; } else { btnOpenFileSQLite.Visible = true; lblSqliteRemoteUser.Visible = false; lblSqliteRemotePwd.Visible = false; txtSqliteRemoteUser.Visible = false; txtSqliteRemotePwd.Visible = false; } } private void btnMySqlTest_Click(object sender, EventArgs e) { if (CnasDataOperationFact.CnasDataOperation().TestConnect(new DataBaseInfo() { DBHost = this.txtMySqlHost.Text.Trim(), DBName = this.txtMySqlServer.Text.Trim(), DBUser = this.txtMySqlUser.Text.Trim(), DBPwd = this.txtMySqlPwd.Text.Trim(), DBPort = this.txtMySqlPort.Text.Trim() })) MessageBox.Show("连接成功!"); else MessageBox.Show("连接失败!"); } 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() == "") { MessageBox.Show("请填写相关连接信息。"); return; } InstrumentDataSourceInfo dbinfo = new InstrumentDataSourceInfo(); dbinfo.Host = this.txtOracleHost.Text.Trim(); dbinfo.ServerName = this.txtOracleSource.Text.Trim(); dbinfo.UserId = this.txtOracleUserId.Text.Trim(); dbinfo.UserPwd = this.txtOraclePwd.Text.Trim(); dbinfo.Port = this.txtOraclePort.Text.Trim(); if (new OracleInstrumentData(dbinfo, new object[] { "", "", "" }).TestSQLServerLink()) MessageBox.Show("连接成功!"); else MessageBox.Show("连接失败!"); } private void txtFileOpenFoxPro_Click(object sender, EventArgs e) { if (syncInstrumentItem.Code == null) return; if (syncInstrumentItem.SyncInstrumentDSInfo == null) syncInstrumentItem.SyncInstrumentDSInfo = new InstrumentDataSourceInfo(); syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType = DataSourceType.FoxPro; if (strReadFoxproMode == "0") { OpenFileDialog openFile = new OpenFileDialog { Filter = "Foxpro文件(*.dbf)|*.dbf", InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop), Multiselect = false }; if (openFile.ShowDialog() == DialogResult.Cancel) return; this.txtFoxProFolder.Text = syncInstrumentItem.SyncInstrumentDSInfo.Path = openFile.FileName; string fileType = System.IO.Path.GetExtension(openFile.FileName); if (string.IsNullOrEmpty(fileType)) return; } else { FolderBrowserDialog dialog = new FolderBrowserDialog(); dialog.Description = "请选择文件路径"; if (dialog.ShowDialog() == DialogResult.Cancel) return; this.txtFoxProFolder.Text = syncInstrumentItem.SyncInstrumentDSInfo.Path = dialog.SelectedPath; } } private void cbxFoxProRemote_CheckedChanged(object sender, EventArgs e) { if (!cbxFoxProRemote.Checked) { this.btnFileOpenFoxPro.Visible = true; lblFoxproRemoteUserId.Visible = false; lblFoxproRemotePwd.Visible = false; txtRemoteFoxProUserId.Visible = false; txtRemoteFoxProPwd.Visible = false; } else { this.btnFileOpenFoxPro.Visible = false; lblFoxproRemoteUserId.Visible = true; lblFoxproRemotePwd.Visible = true; txtRemoteFoxProUserId.Visible = true; txtRemoteFoxProPwd.Visible = true; } } private void btnOpenFileTxt_Click(object sender, EventArgs e) { if (syncInstrumentItem.Code == null) return; if (syncInstrumentItem.SyncInstrumentDSInfo == null) syncInstrumentItem.SyncInstrumentDSInfo = new InstrumentDataSourceInfo(); syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType = DataSourceType.TXT; if (strReadTxtMode == "0") { OpenFileDialog openFile = new OpenFileDialog { Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*", InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop), Multiselect = false }; if (openFile.ShowDialog() == DialogResult.Cancel) return; this.txtInportTxt.Text = syncInstrumentItem.SyncInstrumentDSInfo.Path = openFile.FileName; string fileType = System.IO.Path.GetExtension(openFile.FileName); if (string.IsNullOrEmpty(fileType)) return; } else { FolderBrowserDialog dialog = new FolderBrowserDialog(); dialog.Description = "请选择文件路径"; if (dialog.ShowDialog() == DialogResult.Cancel) return; this.txtInportTxt.Text = syncInstrumentItem.SyncInstrumentDSInfo.Path = dialog.SelectedPath; } } private void cbxRemoteTxt_CheckedChanged(object sender, EventArgs e) { if (!cbxRemoteTxt.Checked) { this.btnOpenFileTxt.Visible = true; lblTxtRemoteUserId.Visible = false; lblTxtRemoteUserPwd.Visible = false; txtRemoteTxtUserId.Visible = false; txtRemoteTxtPwd.Visible = false; } else { this.btnOpenFileTxt.Visible = false; lblTxtRemoteUserId.Visible = true; lblTxtRemoteUserPwd.Visible = true; txtRemoteTxtUserId.Visible = true; txtRemoteTxtPwd.Visible = true; } } private void cbxTargetDBSelect_SelectedIndexChanged(object sender, EventArgs e) { if (cbxTargetDBSelect.SelectedIndex == 0) { if (GlobalCommonOperation.strStartWebApi == "1") { targetDataBaseInfo = new DataBaseInfo() { DataBaseCode = "cnas" }; } else { DataBaseInfo CNASDataBase = FileOperation.GetLocalCnasDB(); if (CNASDataBase != null) { this.txtDBHost.Text = CNASDataBase.DBHost; this.txtDBName.Text = CNASDataBase.DBName; this.txtDBUser.Text = CNASDataBase.DBUser; this.txtDBPwd.Text = CNASDataBase.DBPwd; this.txtPort.Text = CNASDataBase.DBPort; } } } else if (cbxTargetDBSelect.SelectedIndex == 1) { if (GlobalCommonOperation.strStartWebApi == "1") { targetDataBaseInfo = new DataBaseInfo() { DataBaseCode = "platform" }; } else { DataBaseInfo PlatDataBase = FileOperation.GetLocalPlatFormDB(); if (PlatDataBase != null) { this.txtDBHost.Text = PlatDataBase.DBHost; this.txtDBName.Text = PlatDataBase.DBName; this.txtDBUser.Text = PlatDataBase.DBUser; this.txtDBPwd.Text = PlatDataBase.DBPwd; this.txtPort.Text = PlatDataBase.DBPort; } } } } } }