using ButcherFactory.BO.Utils; using System; using System.Collections.Generic; using System.Linq; using System.Text; 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; using WinFormControl; namespace ButcherFactory.Tools { /// /// MainWindow.xaml 的交互逻辑 /// public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); modeComboBox.Items.Add("MES"); modeComboBox.Items.Add("B3"); modeComboBox.SelectedIndex = AppContext.ConnectInfo.ServerMode; var list = XmlUtil.DeserializeFromFile>("Config\\DbSelectList.xml"); dbComboBox.SelectedValuePath = "Value"; dbComboBox.DisplayMemberPath = "Name"; dbComboBox.ItemsSource = list; if (!string.IsNullOrEmpty(AppContext.ConnectInfo.SqlConnection)) { var idx = list.FindIndex(x => x.Value == AppContext.ConnectInfo.SqlConnection); if (idx > -1) dbComboBox.SelectedIndex = idx; } this.serverUrlBox.Text = AppContext.ConnectInfo.ServerUrl; } private void Button_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(AppContext.ConnectInfo.SqlConnection)) { MessageBox.Show("请先设置数据库地址", "错误", MessageBoxButton.OK, MessageBoxImage.Error); } DbUtil.UpdateDatabase(AppContext.ConnectInfo.SqlConnection); MessageBox.Show("数据库升级成功"); } private void SaveBtnClick(object sender, RoutedEventArgs e) { string uri = this.serverUrlBox.Text.Trim(); if (string.IsNullOrEmpty(uri)) throw new Exception("请先设置服务器地址"); AppContext.ConnectInfo.ServerUrl = uri; AppContext.ConnectInfo.SqlConnection = (string)dbComboBox.SelectedValue; AppContext.ConnectInfo.ServerMode = modeComboBox.SelectedIndex; AppContext.ConnectInfo.Save(); MessageBox.Show("设置保存成功!"); } private void CloseBtnClick(object sender, RoutedEventArgs e) { Application.Current.Shutdown(); } private void ServerUrlTextBoxClick(object sender, MouseButtonEventArgs e) { serverUrlBox.Focus(); var keyBoard = new VirtualKeyPad(); if (keyBoard.ShowDialog() == true) serverUrlBox.Text = keyBoard.Result; } } public class DbSelectEntity { public string Name { get; set; } public string Value { get; set; } } }