|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- using CnasSynchronusClient;
- using CnasSynchrousModel;
- using System;
- using System.IO;
- using System.Windows.Forms;
- using System.Xml.Serialization;
-
- namespace CNASBalanceDBManage
- {
- public partial class frmBalanceDB : Form
- {
- public DataBaseInfo CNASDataBase { get; set; }
-
- public DataBaseInfo PlatDataBase { get; set; }
-
- public string strOldPwd { get; set; }
-
- public frmBalanceDB()
- {
- InitializeComponent();
- }
-
- private void btnCNASTestLink_Click(object sender, EventArgs e)
- {
- if (this.txtDBHost.Text.Trim() == "" || this.txtDBName.Text.Trim() == "" || this.txtDBUser.Text.Trim() == "" || this.txtDBPwd.Text.Trim() == "" || this.txtPort.Text.Trim()=="")
- {
- MessageBox.Show("不允许为空!");
- return;
- }
-
- if (CnasDataOperationFact.CnasDataOperation().TestConnect(new DataBaseInfo()
- {
- DataBaseCode="cnas",
- 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 frmBalanceDB_Load(object sender, EventArgs e)
- {
- CNASDataBase = FileOperation.GetLocalCnasDB();
- if (this.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;
- }
- PlatDataBase = FileOperation.GetLocalPlatFormDB();
- if(PlatDataBase!=null)
- {
- this.txtPlatHost.Text = PlatDataBase.DBHost;
- this.txtPlatServer.Text = PlatDataBase.DBName;
- this.txtPlatUser.Text = PlatDataBase.DBUser;
- this.txtPlatPwd.Text = PlatDataBase.DBPwd;
- this.txtPlatPort.Text = PlatDataBase.DBPort;
- }
-
- strOldPwd = FileOperation.GetLocalOperationPwd();
- }
-
- private void btnOK_Click(object sender, EventArgs e)
- {
- bool bIfSavePwd = false;
- if (this.txtDBHost.Text.Trim() == "" || this.txtDBName.Text.Trim() == "" || this.txtDBUser.Text.Trim() == "" || this.txtDBPwd.Text.Trim() == "" || this.txtPort.Text.Trim() == "")
- {
- MessageBox.Show("CNAS数据库配置不允许为空!");
- return;
- }
- if (this.txtPlatHost.Text.Trim() == "" || this.txtPlatServer.Text.Trim() == "" || this.txtPlatUser.Text.Trim() == "" || this.txtPlatPwd.Text.Trim() == "" || this.txtPlatPort.Text.Trim() == "")
- {
- MessageBox.Show("平台数据库配置不允许为空!");
- return;
- }
- if (this.txtOldPwd.Text == "" && this.txtNewPwd.Text == "" && this.txtRepeatPwd.Text == "") //此时认为用户无意修改密码
- {
- bIfSavePwd = false;
- }
- else
- {
- //旧密码不正确
- if (this.txtOldPwd.Text == ""||(this.txtOldPwd.Text != "" && this.txtOldPwd.Text != strOldPwd))
- {
- MessageBox.Show("旧操作密码错误!");
- return;
- }
- if (this.txtNewPwd.Text.Trim() == "")
- {
- MessageBox.Show("新操作密码不能为空!");
- return;
- }
- if (this.txtOldPwd.Text == this.txtNewPwd.Text)
- {
- MessageBox.Show("新旧操作密码不能一样!");
- return;
- }
- if (this.txtNewPwd.Text.Trim() != this.txtRepeatPwd.Text.Trim())
- {
- MessageBox.Show("重复输入操作密码不一样!");
- return;
- }
- bIfSavePwd = true;
- }
-
- //目标库的信息
- CNASDataBase.DBHost = this.txtDBHost.Text.Trim();
- CNASDataBase.DBName = this.txtDBName.Text.Trim();
- CNASDataBase.DBUser = this.txtDBUser.Text.Trim();
- CNASDataBase.DBPwd = this.txtDBPwd.Text.Trim();
- CNASDataBase.DBPort = this.txtPort.Text.Trim();
-
-
- PlatDataBase.DBHost = this.txtPlatHost.Text.Trim();
- PlatDataBase.DBName = this.txtPlatServer.Text.Trim();
- PlatDataBase.DBUser = this.txtPlatUser.Text.Trim();
- PlatDataBase.DBPwd = this.txtPlatPwd.Text.Trim();
- PlatDataBase.DBPort = this.txtPlatPort.Text.Trim();
-
- /*一套有点恶心的逻辑,但没想到其他的方案*/
- //保存数据到本地
- if (!bIfSavePwd) //此时没有修改密码,此时只判断两个数据库配置的存储
- {
- bool bSaveCNAS = FileOperation.SaveLocalCnasDB(CNASDataBase);
- bool bSavePlat= FileOperation.SaveLocalPlatDB(PlatDataBase);
- if (bSaveCNAS && bSavePlat)
- {
- MessageBox.Show("数据库配置保存成功!");
- }
- else if (bSaveCNAS && !bSavePlat)
- {
- MessageBox.Show("平台数据库配置保存失败。");
- }
- else if (!bSaveCNAS && bSavePlat)
- {
- MessageBox.Show("CNAS数据库配置保存失败。");
- }
- else
- {
- MessageBox.Show("数据库配置保存失败。");
- }
- }
- else
- {
- string strMsg = "";
- bool bSaveDB = bSaveDataBase(ref strMsg);
- bool bSavePwd = FileOperation.SaveLocalOperationPwd(this.txtNewPwd.Text.Trim());
- if (bSaveDB == true && bSavePwd == true)
- {
- MessageBox.Show("保存成功!");
- }
- else if (bSaveDB == true && bSavePwd == false)
- {
- MessageBox.Show("数据库配置保存成功,操作密码保存失败!");
- }
- else if (bSaveDB == false && bSavePwd == true)
- {
- MessageBox.Show(strMsg+"操作密码设置保存成功!");
- }
- else
- {
- MessageBox.Show("保存失败!");
- }
- }
- }
-
- private bool bSaveDataBase(ref string strMsg)
- {
- bool bSaveCNAS = FileOperation.SaveLocalCnasDB(CNASDataBase);
- bool bSavePlat = FileOperation.SaveLocalPlatDB(PlatDataBase);
- if (bSaveCNAS && bSavePlat)
- {
- strMsg="数据库配置保存成功!";
- return true;
- }
- else if (bSaveCNAS && !bSavePlat)
- {
- strMsg = "平台数据库配置保存失败。";
- return false;
- }
- else if (!bSaveCNAS && bSavePlat)
- {
- strMsg = "CNAS数据库配置保存失败。";
- return false;
- }
- else
- {
- strMsg = "数据库配置保存失败。";
- return false;
- }
- }
-
- private void btnPlatTest_Click(object sender, EventArgs e)
- {
- if (this.txtPlatHost.Text.Trim() == "" || this.txtPlatServer.Text.Trim() == "" || this.txtPlatUser.Text.Trim() == "" || this.txtPlatPwd.Text.Trim() == "" || this.txtPlatPort.Text.Trim() == "")
- {
- MessageBox.Show("平台数据库配置不允许为空!");
- return;
- }
-
- //if (CnasDataOperationFact.CnasDataOperation().TestConnect(this.txtPlatHost.Text.Trim(), this.txtPlatServer.Text.Trim(), this.txtPlatUser.Text.Trim(), this.txtPlatPwd.Text.Trim(), this.txtPlatPort.Text.Trim()))
- if (CnasDataOperationFact.CnasDataOperation().TestConnect(new DataBaseInfo()
- {
- DBHost = this.txtPlatHost.Text.Trim(),
- DBName = this.txtPlatServer.Text.Trim(),
- DBUser = this.txtPlatUser.Text.Trim(),
- DBPwd = this.txtPlatPwd.Text.Trim(),
- DBPort = this.txtPlatPort.Text.Trim()
- }))
- MessageBox.Show("连接成功!");
- else
- MessageBox.Show("连接失败!");
- }
-
- }
- }
|