diff --git a/Handler/Project/WebUI/MachineBridge.cs b/Handler/Project/WebUI/MachineBridge.cs index a481558..71590c1 100644 --- a/Handler/Project/WebUI/MachineBridge.cs +++ b/Handler/Project/WebUI/MachineBridge.cs @@ -71,29 +71,61 @@ namespace Project.WebUI _host.HandleCommand(command); } - public string SelectRecipe(string recipeId) + /// + /// 마이그레이션완료 + /// + /// + /// + public string SelectRecipe(string recipeTitle) { - Console.WriteLine($"[C#] Selecting Recipe: {recipeId}"); + Console.WriteLine($"[C#] Selecting Recipe: {recipeTitle}"); try { - string recipePath = Path.Combine(_recipeFolder, $"{recipeId}.json"); - - if (!File.Exists(recipePath)) + // Check if system is running + if (PUB.sm.Step == eSMStep.RUN || PUB.sm.Step == eSMStep.WAITSTART || PUB.sm.Step == eSMStep.PAUSE) { - var response = new { success = false, message = "Recipe not found" }; + var response = new { success = false, message = "Cannot change model while system is currently running (waiting)" }; return JsonConvert.SerializeObject(response); } - string json = File.ReadAllText(recipePath); - var recipeData = JsonConvert.DeserializeObject(json); + // Select model using PUB.SelectModelV + bool result = AR.PUB.SelectModelV(recipeTitle, true); - _host.SetCurrentRecipe(recipeId); + if (result) + { + Console.WriteLine($"[INFO] Recipe {recipeTitle} selected successfully"); - Console.WriteLine($"[INFO] Recipe {recipeId} selected successfully"); + // Get the selected model data + var dr = PUB.mdm.GetDataV(recipeTitle); + if (dr == null) + { + var response = new { success = false, message = "Recipe data not found" }; + return JsonConvert.SerializeObject(response); + } - var response2 = new { success = true, message = "Recipe selected successfully", recipeId = recipeId, recipe = recipeData }; - return JsonConvert.SerializeObject(response2); + // Convert DataRow to Dictionary + var recipeData = new Dictionary(); + foreach (System.Data.DataColumn col in dr.Table.Columns) + { + string colName = col.ColumnName; + object value = dr[colName]; + + // DBNull을 null로 변환 + if (value == DBNull.Value) + value = null; + + recipeData[colName] = value; + } + + var response2 = new { success = true, message = "Recipe selected successfully", recipeId = recipeTitle, recipe = recipeData }; + return JsonConvert.SerializeObject(response2); + } + else + { + var response = new { success = false, message = "Failed to select recipe" }; + return JsonConvert.SerializeObject(response); + } } catch (Exception ex) {