屠宰场客户端
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.

83 lines
2.6 KiB

using ButcherManage.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 ButcherManage.Tools
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
var list = XmlUtil.DeserializeFromFile<List<DbSelectEntity>>("Config\\DbSelectList.xml");
dbComboBox.SelectedValuePath = "Value";
dbComboBox.DisplayMemberPath = "Name";
dbComboBox.ItemsSource = list;
var idx = list.FindIndex(x => x.Value == AppContext.ConnectInfo.SqlConnection);
if (idx > -1)
dbComboBox.SelectedIndex = idx;
this.serverUrlBox.Text = AppContext.ConnectInfo.ServerUrl;
this.localOffline.IsChecked = AppContext.ConnectInfo.LocalOffline;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
if (!AppContext.ConnectInfo.LocalOffline)
throw new Exception("非离线模式无需升级数据库");
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("请先设置服务器地址");
if (AppContext.ConnectInfo.LocalOffline && string.IsNullOrEmpty(AppContext.ConnectInfo.SqlConnection))
throw new Exception("本机离线必须选择数据库");
AppContext.ConnectInfo.ServerUrl = uri;
AppContext.ConnectInfo.SqlConnection = (string)dbComboBox.SelectedValue;
AppContext.ConnectInfo.LocalOffline = this.localOffline.IsChecked.Value;
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; }
}
}