12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Windows.Input;
- using Aitex.UI.Charting.Command;
- using System.Windows.Forms;
- using Aitex.UI.Charting.View;
- using System.Configuration;
- namespace Aitex.UI.Charting.ViewModel
- {
- public class DbConnConfigViewModel : ChartingBaseViewModel
- {
- public DbConnConfigViewModel(DbConnConfig view)
- {
- _view = view;
- TestDbConnectionCommand = new ChartingCommand((o) => true, (o) => OnTestDbConnection(o));
- CloseCommand = new ChartingCommand((o) => true, (o) => CloseWin(o));
- Ip = RegEdit.ReadRegedit("Aitex", "Database_IP");
- if (string.IsNullOrEmpty(Ip))
- {
- //创建默认注册表
- RegEdit.WriteRegedit("Aitex", "Database_Ip", "127.0.0.1");
- RegEdit.WriteRegedit("Aitex", "Database_Port", "5432");
- RegEdit.WriteRegedit("Aitex", "Database_User", "postgres");
- RegEdit.WriteRegedit("Aitex", "Database_Pwd", "123456");
- RegEdit.WriteRegedit("Aitex", "Database_Name", "postgres");
- }
- Ip = RegEdit.ReadRegedit("Aitex", "Database_IP");
- Port = RegEdit.ReadRegedit("Aitex", "Database_Port");
- User = RegEdit.ReadRegedit("Aitex", "Database_User");
- Pwd = RegEdit.ReadRegedit("Aitex", "Database_Pwd");
- DbName = RegEdit.ReadRegedit("Aitex", "Database_Name");
- view.pwdbox.Password = Pwd;
- }
- private void OnTestDbConnection(object param)
- {
- Pwd = _view.pwdbox.Password; //for PasswordBox's 'Password' property do not support binding function
- RegEdit.WriteRegedit("Aitex", "Database_Ip", Ip);
- RegEdit.WriteRegedit("Aitex", "Database_Port", Port);
- RegEdit.WriteRegedit("Aitex", "Database_User", User);
- RegEdit.WriteRegedit("Aitex", "Database_Pwd", Pwd);
- RegEdit.WriteRegedit("Aitex", "Database_Name", DbName);
- string reason;
- if (CreateConnection(out reason))
- {
- MessageBox.Show(DataAnalysisControl.Properties.Resource.DbConnConfigViewModel_OnTestDbConnection_DBConnect_succeed, "Database", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
- _view.Close();
- }
- else
- {
- MessageBox.Show(DataAnalysisControl.Properties.Resource.DbConnConfigViewModel_OnTestDbConnection_db_failed + reason, "Database", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
- }
- }
- private void CloseWin(object param)
- {
- _view.Close();
- }
- DbConnConfig _view;
- public ICommand TestDbConnectionCommand { get; set; }
- public ICommand CloseCommand { get; set; }
- public string Ip { get; set; }
- public string Port { get; set; }
- public string User { get; set; }
- public string Pwd { get; set; }
- public string DbName { get; set; }
- }
- }
|