You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

103 lines
4.6 KiB

using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace SunlightCentralizedControlManagement_SCCM_.View
{
/// <summary>
/// EngineerSetView.xaml 的交互逻辑
/// </summary>
public partial class EngineerSetView : UserControl
{
public EngineerSetView()
{
InitializeComponent();
// 获取所有可用串口端口,并添加到comboBoxCOM
string[] ports = System.IO.Ports.SerialPort.GetPortNames();
comboBoxCOM0.ItemsSource = ports;
comboBoxCOM0.Text = Configini.IniReadvalue("SYS", "COM");
comboBoxCOM1.ItemsSource = ports;
comboBoxCOM1.Text = Configini.IniReadvalue("SYS", "COM");
comboBoxCOM2.ItemsSource = ports;
comboBoxCOM2.Text = Configini.IniReadvalue("SYS", "COM");
string[] Language = {"en-US","zh-CN","zh-TW" };
string[] SQMOD = { "Windows Authentication", "SQL SERVER"};
comboBoxLanguage.ItemsSource = Language;
TEXT_SQMOD.ItemsSource = SQMOD;
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 void comboBoxCOM_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Configini.IniWritevalue("SYS", "COM0", comboBoxCOM0.SelectedValue.ToString());
Configini.IniWritevalue("SYS", "COM1", comboBoxCOM1.SelectedValue.ToString());
Configini.IniWritevalue("SYS", "COM2", comboBoxCOM2.SelectedValue.ToString());
}
private void comboBoxLanguage_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
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, 255));
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(255, 0, 0));
return;
}
textlog.Text = "Link succeed";
textlog.Foreground = new SolidColorBrush(Color.FromRgb(0, 255, 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);
}
}
}
}