/// <summary> /// 取得測試結果 /// ex.http://localhost:4803/data/getTestResult?LineID=testWeb /// </summary> /// <param name="LineID"></param> /// <returns></returns> public JsonResult getTestResult(string LineID = "") { RESPONSE_MSG rm = new RESPONSE_MSG(); string actionName = "getTestResult"; LogTool.Info(LineID, actionName, this.csName); //紀錄log EGG_TEST_INFO test_info = new EGG_TEST_INFO(); DBLink link = new DBLink(); try { #region 取得測試資料 string sql = test_info.getSelectList_KEY_USER_ID(); DynamicParameters dp = new DynamicParameters(); dp.Add("USER_ID", LineID); List <EGG_TEST_INFO> test_List = new List <EGG_TEST_INFO>(); #endregion test_List = link.DBA.getSqlDataTable <EGG_TEST_INFO>(sql, dp); if (test_List.Count > 0) { if (test_List.Exists(x => x.DATASTATUS == "0")) { test_info = test_List.Find(x => x.DATASTATUS == "0"); if (test_info.tempList.Count == 4) { #region 測試完畢,計算成績 rm.message = "您這一次測試結果如下所示"; test_info.DATASTATUS = "1"; this.getEggScore(ref test_info); test_info.MODIFY_DATE = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); test_info.MODIFY_ID = LineID; test_info.MODIFY_NAME = LineID; link.DBA.DBExecute <EGG_TEST_INFO>(test_info.getUpdateSQL_KEY_USER_ID_CREATE_DATE(), new List <EGG_TEST_INFO>() { test_info }); if (link.DBA.hasLastError) { rm.status = RESPONSE_STATUS.ERROR; rm.message = "SQL 發生錯誤,請洽資訊人員!"; LogTool.Error(link.DBA.lastError, actionName, this.csName); } else { rm.status = RESPONSE_STATUS.SUCCESS; rm.attachment = test_info; } #endregion } else { rm.status = RESPONSE_STATUS.ERROR; rm.message = "上有測驗尚未完成,請選擇功能清單點選測試區,繼續完成!"; } rm.attachment = test_info; } else { rm.message = "您最後一次測試結果如下所示"; test_info = test_List.FindAll(x => x.DATASTATUS == "1").OrderByDescending(x => DateTime.Parse(x.CREATE_DATE)).First(); rm.attachment = test_info; } } else { rm.message = "查無測試結果資料,請選擇功能清單點選測試區!"; } } catch (Exception ex) { LogTool.Fatal(ex, actionName, this.csName); rm.status = RESPONSE_STATUS.ERROR; rm.message = "程式發生錯誤,請洽資訊人員!"; } return(Json(rm, JsonRequestBehavior.AllowGet)); }
private void updateRowData(ref EGG_TEST_INFO test_info, ref bool hasUpdate, ref RESPONSE_MSG rm, ref DBLink link, string LineID, string msg) { #region 更新欄位 LogTool.Info(Newtonsoft.Json.JsonConvert.SerializeObject(this.AnserList), "updateRowData", "updateRowData"); //in Key List if (this.AnserList.Contains(msg)) { if (msg == this.AnserList[1]) { test_info.WASH_EGG = "我買的是洗選蛋"; //"我買的是洗選蛋" } if (msg == this.AnserList[2]) { test_info.WASH_EGG = "我買的不是洗選蛋"; //" "我買的不是洗選蛋" } if (msg == this.AnserList[3]) { test_info.STORE = "我把雞蛋放在室溫"; // "我把雞蛋放在室溫" } if (msg == this.AnserList[4]) { test_info.STORE = "我把雞蛋放在冰箱"; // "我把雞蛋放在冰箱" } if (msg == this.AnserList[5]) { test_info.BUY_PLACE = "我在北部"; // "我在北部" } if (msg == this.AnserList[6]) { test_info.BUY_PLACE = "我在中部"; // "我在中部" } if (msg == this.AnserList[7]) { test_info.BUY_PLACE = "我在南部"; // "我在南部" } if (this.AnserList.Skip(5).Take(3).Contains(msg)) { test_info.TEMP = this.getNowTemp(test_info.BUY_PLACE); } hasUpdate = true; } //是否是數值 if (NumberHelper.isInt(msg)) { hasUpdate = true; int _days = int.Parse(msg); if (Math.Abs(_days) >= 0) { test_info.DAYS = msg; rm.attachment = test_info.tempList; } else { rm.status = RESPONSE_STATUS.WARN; rm.message = "請輸入1-30任何一個數值!"; LogTool.Error(Newtonsoft.Json.JsonConvert.SerializeObject(test_info), "updateRowData", this.csName); } } #endregion if (rm.status == RESPONSE_STATUS.SUCCESS) { if (hasUpdate) { test_info.MODIFY_DATE = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); test_info.MODIFY_ID = LineID; test_info.MODIFY_NAME = LineID; link.DBA.DBExecute <EGG_TEST_INFO>(test_info.getUpdateSQL_KEY_USER_ID_CREATE_DATE(), new List <EGG_TEST_INFO>() { test_info }); } if (link.DBA.hasLastError) { rm.status = RESPONSE_STATUS.ERROR; rm.message = "SQL 發生錯誤,請洽資訊人員!"; LogTool.Error(link.DBA.lastError, "updateRowData", this.csName); } else { rm.status = RESPONSE_STATUS.SUCCESS; rm.attachment = test_info.tempList; } } }