LoginWindow.xaml.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. using MesAdaptor;
  2. using ST_CUBE_MES.Service;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. using System.Windows.Documents;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Shapes;
  16. namespace ST_CUBE_MES
  17. {
  18. /// <summary>
  19. /// LoginWindow.xaml 的互動邏輯
  20. /// </summary>
  21. public partial class LoginWindow : Window
  22. {
  23. public LoginWindow()
  24. {
  25. InitializeComponent();
  26. uxErrmsg.Content = "";
  27. SajetConnect.SetMes(AppSettingService.Instance.MES, AppSettingService.Instance.MechineCode);
  28. SajetConnect.SajetTransStart();
  29. }
  30. public string UserId
  31. {
  32. get => uxIdBox.Text;
  33. set => uxIdBox.Text = value;
  34. }
  35. public string WorkOrder
  36. {
  37. get => uxWorkOrderBox.Text;
  38. set => uxWorkOrderBox.Text = value;
  39. }
  40. //protected override void OnClosing(CancelEventArgs e)
  41. //{
  42. // if (DialogResult == null)
  43. // {
  44. // SajetConnect.SetMes(null);
  45. // Application.Current.Shutdown();
  46. // }
  47. // base.OnClosing(e);
  48. //}
  49. private void Exit_Click(object sender, RoutedEventArgs e)
  50. {
  51. this.Close();
  52. }
  53. private void Connect_Click(object sender, RoutedEventArgs e)
  54. {
  55. if (!CheckConnect())
  56. {
  57. return;
  58. }
  59. this.Hide();
  60. var mainWindow = new MainWindow()
  61. {
  62. UserId = UserId,
  63. WorkOrder = WorkOrder
  64. };
  65. mainWindow.Closed += MainWindow_Closed;
  66. mainWindow.Owner = this;
  67. mainWindow.ShowDialog();
  68. }
  69. private void MainWindow_Closed(object sender, EventArgs e)
  70. {
  71. this.Show();
  72. WorkOrder = "";
  73. }
  74. private bool CheckConnect()
  75. {
  76. uxErrmsg.Content = "";
  77. if (string.IsNullOrEmpty(uxIdBox.Text))
  78. {
  79. uxErrmsg.Content = "員工代號不可為空";
  80. return false;
  81. }
  82. string id = uxIdBox.Text;
  83. string idBackup = id;
  84. if (CheckIsMesDisableAccount())
  85. {
  86. //SajetConnect.IsEmsEnabled = false;
  87. SajetConnect.SetMes("test");
  88. return true;
  89. }
  90. if (!SajetConnect.SajetTransSignIn(ref id))
  91. {
  92. if (id.StartsWith(idBackup))
  93. {
  94. //data not changed
  95. uxErrmsg.Content = "MES 連線失敗";// "ID Error";
  96. }
  97. else
  98. {
  99. uxErrmsg.Content = "員工代號不存在";// "ID Error";
  100. }
  101. return false;
  102. }
  103. if (string.IsNullOrEmpty(id) || id.StartsWith("NG"))
  104. {
  105. uxErrmsg.Content = "員工代號不存在";
  106. return false;
  107. }
  108. if (!string.IsNullOrEmpty(uxWorkOrderBox.Text))
  109. {
  110. string workOrder = uxWorkOrderBox.Text;
  111. if (!SajetConnect.SajetTransWoCheck(ref workOrder))
  112. {
  113. uxErrmsg.Content = "工單號錯誤";
  114. return false;
  115. }
  116. if (string.IsNullOrEmpty(workOrder) || workOrder.StartsWith("NG"))
  117. {
  118. uxErrmsg.Content = "工單號錯誤";
  119. return false;
  120. }
  121. }
  122. return true;
  123. }
  124. private bool CheckIsMesDisableAccount()
  125. {
  126. return uxIdBox.Text == "Admin" && uxWorkOrderBox.Text == "Admin21896826";
  127. }
  128. }
  129. }