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.
 
 
 

151 lines
7.1 KiB

using ScottPlot.TickGenerators.TimeUnits;
using SunlightCentralizedControlManagement_SCCM_.UserClass;
using SunlightCentralizedControlManagement_SCCM_.ViewModel;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Speech.Synthesis;
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();
ports.Append("COM");
comboBoxCOM0.ItemsSource = ports;
comboBoxCOM0.Text = Configini.IniReadvalue("SYS", "COMP1");
comboBoxCOM1.ItemsSource = ports;
comboBoxCOM1.Text = Configini.IniReadvalue("SYS", "COMP2");
comboBoxCOM2.ItemsSource = ports;
comboBoxCOM2.Text = Configini.IniReadvalue("SYS", "COMP3");
string[] Language = {"en-US","zh-CN","zh-TW" };
string[] SQMOD = { "Windows Authentication", "SQL SERVER"};
comboBoxLanguage.ItemsSource = Language;
TEXT_SQMOD.ItemsSource = SQMOD;
try
{
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");
dDispenser.IsChecked = Convert.ToBoolean(Configini.IniReadvalue("SYS", "DyelotsDispenser"));
VOICE_V1.Text = Configini.IniReadvalue("VOICE", "V1");
VOICE_V2.Text = Configini.IniReadvalue("VOICE", "V2");
}
catch (Exception ex) { LogGing.ERRDATA(ex); }
}
//调用配置文件
private UserClass.IniFile.IniFiles Configini = new UserClass.IniFile.IniFiles(Convert.ToString(System.AppDomain.CurrentDomain.BaseDirectory) + "SCCM.ini");
private SpeechSynthesizer synth = new SpeechSynthesizer();//语音
private void comboBoxCOM_SelectionChanged0(object sender, SelectionChangedEventArgs e)
{
Configini.IniWritevalue("SYS", "COMP1", comboBoxCOM0.SelectedValue.ToString());
// Configini.IniWritevalue("SYS", "COMP1", comboBoxCOM1.SelectedValue.ToString());
// Configini.IniWritevalue("SYS", "COMP2", comboBoxCOM2.SelectedValue.ToString());
}
private void comboBoxCOM_SelectionChanged1(object sender, SelectionChangedEventArgs e)
{
//Configini.IniWritevalue("SYS", "COMP0", comboBoxCOM0.SelectedValue.ToString());
Configini.IniWritevalue("SYS", "COMP2", comboBoxCOM1.SelectedValue.ToString());
// Configini.IniWritevalue("SYS", "COMP2", comboBoxCOM2.SelectedValue.ToString());
}
private void comboBoxCOM_SelectionChanged2(object sender, SelectionChangedEventArgs e)
{
//Configini.IniWritevalue("SYS", "COMP0", comboBoxCOM0.SelectedValue.ToString());
// Configini.IniWritevalue("SYS", "COMP1", comboBoxCOM1.SelectedValue.ToString());
Configini.IniWritevalue("SYS", "COMP3", 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);
MainWindowViewModel.SQLIP = TEXT_SQLIP.Text;
MainWindowViewModel.SQLNAME = TEXT_SQLNAME.Text;
MainWindowViewModel.SQMOD = TEXT_SQMOD.Text;
MainWindowViewModel.SQLUSER = TEXT_SQLUSER.Text;
MainWindowViewModel.SQLPASWORD = TEXT_SQLPASWORD.Text;
}
}
private void dDispenser_Checked(object sender, RoutedEventArgs e)
{
Configini.IniWritevalue("SYS", "DyelotsDispenser", dDispenser.IsChecked.ToString());
MainWindowViewModel.DyelotsDispenser = (bool)dDispenser.IsChecked;
}
private void VOICE_Click(object sender, RoutedEventArgs e)//语言测试按钮
{
try
{
synth.Rate = int.Parse(VOICE_V1.Text);
synth.Volume = int.Parse(VOICE_V2.Text);
synth.SpeakAsync(Properties.Resources.TESTVOICE);
Configini.IniWritevalue("VOICE", "V1", VOICE_V1.Text);
Configini.IniWritevalue("VOICE", "V2", VOICE_V2.Text);
}
catch (Exception) { }
}
}
}