123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- using MesAdaptor;
- using ST_CUBE_MES.Service;
- using System;
- using System.Collections.Generic;
- 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.Shapes;
- namespace ST_CUBE_MES
- {
- /// <summary>
- /// LoginWindow.xaml 的互動邏輯
- /// </summary>
- public partial class LoginWindow : Window
- {
- public LoginWindow()
- {
- InitializeComponent();
- uxErrmsg.Content = "";
- SajetConnect.SetMes(AppSettingService.Instance.MES, AppSettingService.Instance.MechineCode);
- SajetConnect.SajetTransStart();
- }
- public string UserId
- {
- get => uxIdBox.Text;
- set => uxIdBox.Text = value;
- }
- public string WorkOrder
- {
- get => uxWorkOrderBox.Text;
- set => uxWorkOrderBox.Text = value;
- }
- //protected override void OnClosing(CancelEventArgs e)
- //{
- // if (DialogResult == null)
- // {
- // SajetConnect.SetMes(null);
- // Application.Current.Shutdown();
- // }
- // base.OnClosing(e);
- //}
- private void Exit_Click(object sender, RoutedEventArgs e)
- {
- this.Close();
- }
- private void Connect_Click(object sender, RoutedEventArgs e)
- {
- if (!CheckConnect())
- {
- return;
- }
- this.Hide();
- var mainWindow = new MainWindow()
- {
- UserId = UserId,
- WorkOrder = WorkOrder
- };
- mainWindow.Closed += MainWindow_Closed;
- mainWindow.Owner = this;
- mainWindow.ShowDialog();
- }
- private void MainWindow_Closed(object sender, EventArgs e)
- {
- this.Show();
- WorkOrder = "";
- }
- private bool CheckConnect()
- {
- uxErrmsg.Content = "";
- if (string.IsNullOrEmpty(uxIdBox.Text))
- {
- uxErrmsg.Content = "員工代號不可為空";
- return false;
- }
- string id = uxIdBox.Text;
- string idBackup = id;
- if (CheckIsMesDisableAccount())
- {
- //SajetConnect.IsEmsEnabled = false;
- SajetConnect.SetMes("test");
- return true;
- }
- if (!SajetConnect.SajetTransSignIn(ref id))
- {
- if (id.StartsWith(idBackup))
- {
- //data not changed
- uxErrmsg.Content = "MES 連線失敗";// "ID Error";
- }
- else
- {
- uxErrmsg.Content = "員工代號不存在";// "ID Error";
- }
- return false;
- }
- if (string.IsNullOrEmpty(id) || id.StartsWith("NG"))
- {
- uxErrmsg.Content = "員工代號不存在";
- return false;
- }
- if (!string.IsNullOrEmpty(uxWorkOrderBox.Text))
- {
- string workOrder = uxWorkOrderBox.Text;
- if (!SajetConnect.SajetTransWoCheck(ref workOrder))
- {
- uxErrmsg.Content = "工單號錯誤";
- return false;
- }
- if (string.IsNullOrEmpty(workOrder) || workOrder.StartsWith("NG"))
- {
- uxErrmsg.Content = "工單號錯誤";
- return false;
- }
- }
- return true;
- }
- private bool CheckIsMesDisableAccount()
- {
- return uxIdBox.Text == "Admin" && uxWorkOrderBox.Text == "Admin21896826";
- }
- }
- }
|