Robert 1 жил өмнө
parent
commit
7d884341b2

+ 37 - 4
ST-CUBE_MES/MainWindow.xaml.cs

@@ -42,6 +42,7 @@ namespace ST_CUBE_MES
             this.resultDialog = new ResultDialog();
 
             Loaded += MainWindow_Loaded;
+            KeyDown += MainWindow_KeyDown;
         }
 
         private delegate void GenericDelegate();
@@ -91,6 +92,18 @@ namespace ST_CUBE_MES
                 uxBinFilePath.IsEnabled = false;
                 uxBinFileBtn.IsEnabled = false;
             }
+
+            uxSN.Focus();
+        }
+
+        private async void MainWindow_KeyDown(object sender, KeyEventArgs e)
+        {
+            if (e.Key != Key.Enter)
+            {
+                return;
+            }
+
+            await StartRun();
         }
 
         private void uxBinFileBtn_Click(object sender, RoutedEventArgs e)
@@ -108,6 +121,16 @@ namespace ST_CUBE_MES
 
         private async void uxRunBtn_Click(object sender, RoutedEventArgs e)
         {
+            await StartRun();
+        }
+
+        private async Task StartRun()
+        {
+            if (uxRunBtn.IsEnabled == false)
+            {
+                return;
+            }
+
             uxRunBtn.IsEnabled = false;
             try
             {
@@ -207,7 +230,7 @@ namespace ST_CUBE_MES
                     resultDialog = new ResultDialog();
                     resultDialog.Owner = this;
 
-                    resultDialog.MouseDown += ResultDialog_MouseDown;
+                    resultDialog.OnAnyInput += ResultDialog_OnAnyInput;
                     resultDialog.ShowResult(false);
                 });
             }
@@ -222,7 +245,7 @@ namespace ST_CUBE_MES
                     resultDialog = new ResultDialog();
                     resultDialog.Owner = this;
 
-                    resultDialog.MouseDown += ResultDialog_MouseDown;
+                    resultDialog.OnAnyInput += ResultDialog_OnAnyInput;
                     resultDialog.ShowResult(true);
                 });
             }
@@ -249,11 +272,21 @@ namespace ST_CUBE_MES
             }
         }
 
-        private void ResultDialog_MouseDown(object sender, MouseButtonEventArgs e)
+        private void ResultDialog_OnAnyInput(object sender, EventArgs e)
+        {
+            CloseResultDialog();
+        }
+
+        private void CloseResultDialog()
         {
-            resultDialog.MouseDown -= ResultDialog_MouseDown;
+            resultDialog.OnAnyInput -= ResultDialog_OnAnyInput;
             resultDialog.Close();
             //this.Close();
+
+            if (resultDialog.IsSuccess)
+            {
+                uxSN.Text = string.Empty;
+            }
         }
 
         private void ResultDialog_Closing(object sender, CancelEventArgs e)

+ 17 - 0
ST-CUBE_MES/ResultDialog.xaml.cs

@@ -22,10 +22,26 @@ namespace ST_CUBE_MES
         public ResultDialog()
         {
             InitializeComponent();
+
+            KeyDown += ResultDialog_KeyDown;
+            MouseDown += ResultDialog_MouseDown;
         }
 
+        public event EventHandler OnAnyInput;
+        public bool IsSuccess { get; private set; }
+
         private delegate void GenericDelegate();
 
+        private void ResultDialog_KeyDown(object sender, KeyEventArgs e)
+        {
+            OnAnyInput?.Invoke(this, e);
+        }
+
+        private void ResultDialog_MouseDown(object sender, MouseButtonEventArgs e)
+        {
+            OnAnyInput?.Invoke(this, e);
+        }
+
         public void ShowResult(bool isSuccess)
         {
             GenericDelegate ShowResultAct = () => {
@@ -40,6 +56,7 @@ namespace ST_CUBE_MES
                     uxBg.Background = Brushes.Red;
                     uxResultText.Content = "FAIL";
                 }
+                IsSuccess = isSuccess;
                 this.ShowDialog();
             };
             this.Dispatcher.BeginInvoke(ShowResultAct);

+ 1 - 0
ST-CUBE_MES/Service/STLinkCliPrograrmService.cs

@@ -28,6 +28,7 @@ namespace ST_CUBE_MES.Service
         public Result StartProgramProcess(string filePath)
         {
             Result result = new Result() { IsSuccess = false };
+            return result;
 
             result.Step = 1;
             var setOptionByteResult = SetOptionByte();