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
|
|
{
|
|
/// <summary>
|
|
/// MainWindow.xaml 的交互逻辑
|
|
/// </summary>
|
|
public partial class MainWindow : Window
|
|
{
|
|
public MainWindow()
|
|
{
|
|
InitializeComponent();
|
|
modeComboBox.Items.Add("MES");
|
|
modeComboBox.Items.Add("B3");
|
|
try
|
|
{
|
|
modeComboBox.SelectedIndex = AppContext.ConnectInfo.ServerMode;
|
|
var list = XmlUtil.DeserializeFromFile<List<DbSelectEntity>>("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.mesUrlBox.Text = AppContext.ConnectInfo.MESUrl;
|
|
this.b3UrlBox.Text = AppContext.ConnectInfo.B3Url;
|
|
this.clientCodeBox.Text = AppContext.ConnectInfo.ClientCode;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message);
|
|
}
|
|
}
|
|
|
|
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)
|
|
{
|
|
AppContext.ConnectInfo.MESUrl = this.mesUrlBox.Text.Trim();
|
|
AppContext.ConnectInfo.B3Url = this.b3UrlBox.Text.Trim();
|
|
AppContext.ConnectInfo.SqlConnection = (string)dbComboBox.SelectedValue;
|
|
AppContext.ConnectInfo.ServerMode = modeComboBox.SelectedIndex;
|
|
var code = this.clientCodeBox.Text.Trim();
|
|
if (!string.IsNullOrEmpty(code) && code.Length != 2)
|
|
{
|
|
MessageBox.Show("机器码长度必须为2位");
|
|
return;
|
|
}
|
|
AppContext.ConnectInfo.ClientCode = code;
|
|
AppContext.ConnectInfo.Save();
|
|
|
|
MessageBox.Show("设置保存成功!");
|
|
}
|
|
|
|
private void CloseBtnClick(object sender, RoutedEventArgs e)
|
|
{
|
|
Application.Current.Shutdown();
|
|
}
|
|
|
|
private void UrlTextBoxClick(object sender, MouseButtonEventArgs e)
|
|
{
|
|
var box = sender as TextBox;
|
|
box.Focus();
|
|
if (box.Name == "mesUrlBox")
|
|
{
|
|
var keyBoard = new VirtualKeyPad();
|
|
if (keyBoard.ShowDialog() == true)
|
|
box.Text = keyBoard.Result;
|
|
}
|
|
else
|
|
{
|
|
var keyBoard = new NumberPad();
|
|
if (keyBoard.ShowDialog() == true)
|
|
box.Text = keyBoard.Result;
|
|
}
|
|
}
|
|
}
|
|
|
|
public class DbSelectEntity
|
|
{
|
|
public string Name { get; set; }
|
|
|
|
public string Value { get; set; }
|
|
}
|
|
}
|