@ -1,5 +1,6 @@
using System ;
using System ;
using System.Collections.Generic ;
using System.Collections.Generic ;
using System.Data.SqlClient ;
using System.Linq ;
using System.Linq ;
using System.Text ;
using System.Text ;
using System.Threading.Tasks ;
using System.Threading.Tasks ;
@ -35,8 +36,15 @@ namespace SunlightCentralizedControlManagement_SCCM_.View
comboBoxCOM2 . Text = Configini . IniReadvalue ( "SYS" , "COM" ) ;
comboBoxCOM2 . Text = Configini . IniReadvalue ( "SYS" , "COM" ) ;
string [ ] Language = { "en-US" , "zh-CN" , "zh-TW" } ;
string [ ] Language = { "en-US" , "zh-CN" , "zh-TW" } ;
string [ ] SQMOD = { "Windows Authentication" , "SQL SERVER" } ;
comboBoxLanguage . ItemsSource = Language ;
comboBoxLanguage . ItemsSource = Language ;
TEXT_SQMOD . ItemsSource = SQMOD ;
comboBoxLanguage . Text = Configini . IniReadvalue ( "SYS" , "Language" ) ;
comboBoxLanguage . Text = Configini . IniReadvalue ( "SYS" , "Language" ) ;
TEXT_SQLIP . Text = Configini . IniReadvalue ( "SQL_SERVER" , "SQL1" ) ; //读配置文件
TEXT_SQLNAME . Text = Configini . IniReadvalue ( "SQL_SERVER" , "SQL2" ) ;
TEXT_SQMOD . Text = Configini . IniReadvalue ( "SQL_SERVER" , "SQL3" ) ;
TEXT_SQLUSER . Text = Configini . IniReadvalue ( "SQL_SERVER" , "SQL4" ) ;
TEXT_SQLPASWORD . Text = Configini . IniReadvalue ( "SQL_SERVER" , "SQL5" ) ;
}
}
//调用配置文件
//调用配置文件
private UserClass . IniFile . IniFiles Configini = new UserClass . IniFile . IniFiles ( Convert . ToString ( System . AppDomain . CurrentDomain . BaseDirectory ) + "SCCM.ini" ) ;
private UserClass . IniFile . IniFiles Configini = new UserClass . IniFile . IniFiles ( Convert . ToString ( System . AppDomain . CurrentDomain . BaseDirectory ) + "SCCM.ini" ) ;
@ -52,5 +60,44 @@ namespace SunlightCentralizedControlManagement_SCCM_.View
{
{
Configini . IniWritevalue ( "SYS" , "Language" , comboBoxLanguage . SelectedValue . ToString ( ) ) ;
Configini . IniWritevalue ( "SYS" , "Language" , comboBoxLanguage . SelectedValue . ToString ( ) ) ;
}
}
private async void Test_Click ( object sender , RoutedEventArgs e )
{
textlog . Text = "TEST" ;
textlog . Foreground = new SolidColorBrush ( Color . FromRgb ( 0 , 0 , 2 5 5 ) ) ;
string Connstr_SC ;
try
{
if ( TEXT_SQMOD . Text = = "Windows Authentication" ) //连接数据库测试
{
Connstr_SC = "server=" + TEXT_SQLIP . Text + ";database=" + TEXT_SQLNAME . Text + ";Trusted_Connection=SSPI" ;
}
else
{
Connstr_SC = "server=" + TEXT_SQLIP . Text + ";database=" + TEXT_SQLNAME . Text + ";User ID=" + TEXT_SQLUSER . Text + ";Password=" + TEXT_SQLPASWORD . Text ;
}
SqlConnection conn_SC = new SqlConnection ( Connstr_SC ) ;
await conn_SC . OpenAsync ( ) ; //连接数据库
conn_SC . Close ( ) ;
}
catch ( Exception )
{
textlog . Text = "Link timeout" ;
textlog . Foreground = new SolidColorBrush ( Color . FromRgb ( 2 5 5 , 0 , 0 ) ) ;
return ;
}
textlog . Text = "Link succeed" ;
textlog . Foreground = new SolidColorBrush ( Color . FromRgb ( 0 , 2 5 5 , 0 ) ) ;
MessageBoxResult SqlShow = System . Windows . MessageBox . Show ( "Whether the connection is successfully saved" , "SQL" , MessageBoxButton . YesNo , MessageBoxImage . Information ) ; //连接成功提示是否保存
if ( SqlShow = = MessageBoxResult . Yes )
{
Configini . IniWritevalue ( "SQL_SERVER" , "SQL1" , TEXT_SQLIP . Text ) ;
Configini . IniWritevalue ( "SQL_SERVER" , "SQL2" , TEXT_SQLNAME . Text ) ;
Configini . IniWritevalue ( "SQL_SERVER" , "SQL3" , TEXT_SQMOD . SelectedValue . ToString ( ) ) ;
Configini . IniWritevalue ( "SQL_SERVER" , "SQL4" , TEXT_SQLUSER . Text ) ;
Configini . IniWritevalue ( "SQL_SERVER" , "SQL5" , TEXT_SQLPASWORD . Text ) ;
}
}
}
}
}
}