yhluo 4 дней назад
Родитель
Сommit
7fe57e5d6b

+ 86 - 74
UAS_MES_YTDZ/FunctionCode/Make/Make_Humiture.cs

@@ -1,12 +1,10 @@
-using System;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
+using System;
 using System.Collections.Generic;
 using System.Drawing;
-using System.IO;
-using System.Linq;
 using System.Net.Http;
-using System.Runtime.InteropServices.ComTypes;
 using System.Text;
-using System.Text.Json;
 using System.Threading.Tasks;
 using System.Windows.Forms;
 using UAS_MES_NEW.CustomControl.RichText;
@@ -87,103 +85,117 @@ namespace UAS_MES_NEW.Make
                         secret = secret
                     };
                     string result = await HttpHelper.PostAsync(apiUrl, dataObject);
-                    JsonDocument doc = JsonDocument.Parse(result);
-                    JsonElement root = doc.RootElement;
+                    JObject root = JObject.Parse(result);
+                    JArray dataArr = (JArray)root["data"];
 
-                    JsonElement dataArr = root.GetProperty("data");
-                    if (dataArr.ValueKind == JsonValueKind.Array)
+                    foreach (JToken item in dataArr)
                     {
-                        foreach (JsonElement item in dataArr.EnumerateArray())
-                        {
-                            clientId.Add(item.GetProperty("clientid").ToString());
-                            clientName.Add(item.GetProperty("clientname").ToString());
-                        }
+                        clientId.Add(item["clientid"].ToString());
+                        clientName.Add(item["clientname"].ToString());
                     }
 
-                    JsonElement nameElement = root.GetProperty("status");
-                    if (nameElement.ToString() == "200")
+                    if (root["status"].ToString() == "200")
                     {
-                        ShowMsg(Msg1, 1, $"获取温湿度设备成功,已获取到{dataArr.GetArrayLength()}个");
+                        ShowMsg(Msg1, 1, $"获取温湿度设备成功,已获取到{dataArr.Count}个");
                     }
                 }
 
                 string basrUrl = IpPortUrlVal.Text.Trim() + "getEquipDetails";
-                for(int i = 0;i < clientId.Count;i++)
+                for (int i = 0; i < clientId.Count; i++)
                 {
-                    var paramsObj = new
-                    {
-                        secret = secret,
-                        clientId = clientId[i]
-                    };
-                    string result = await HttpHelper.PostAsync(basrUrl, paramsObj);
-                    JsonDocument doc = JsonDocument.Parse(result);
-                    JsonElement root = doc.RootElement;
-
-                    JsonElement nameElement = root.GetProperty("status");
-                    if (nameElement.ToString() == "200")
+                    try
                     {
-                        switch (i)
+                        var paramsObj = new
                         {
-                            case 1:
-                                ShowMsg(Msg2, 1, $"温湿度设备:{clientName[i]},已获取并记录运行信息");
-                                break;
-                            case 2:
-                                ShowMsg(Msg3, 1, $"温湿度设备:{clientName[i]},已获取并记录运行信息");
-                                break;
-                            case 3:
-                                ShowMsg(Msg4, 1, $"温湿度设备:{clientName[i]},已获取并记录运行信息");
-                                break;
-                            default:
-                                ShowMsg(Msg1, 1, $"温湿度设备:{clientName[i]},已获取并记录运行信息");
-                                break;
+                            secret = secret,
+                            clientId = clientId[i]
+                        };
+                        string result = await HttpHelper.PostAsync(basrUrl, paramsObj);
+                        JObject root = JObject.Parse(result);
+                        string status = root["status"].ToString();
+
+                        if (status == "200")
+                        {
+                            switch (i)
+                            {
+                                case 1:
+                                    ShowMsg(Msg2, 1, $"温湿度设备:{clientName[i]},已获取并记录运行信息");
+                                    break;
+                                case 2:
+                                    ShowMsg(Msg3, 1, $"温湿度设备:{clientName[i]},已获取并记录运行信息");
+                                    break;
+                                case 3:
+                                    ShowMsg(Msg4, 1, $"温湿度设备:{clientName[i]},已获取并记录运行信息");
+                                    break;
+                                default:
+                                    ShowMsg(Msg1, 1, $"温湿度设备:{clientName[i]},已获取并记录运行信息");
+                                    break;
+                            }
+                        }
+                        else
+                        {
+                            switch (i)
+                            {
+                                case 1:
+                                    ShowMsg(Msg2, 0, $"温湿度设备:{clientName[i]},获取运行数据异常,请检查设备");
+                                    break;
+                                case 2:
+                                    ShowMsg(Msg3, 0, $"温湿度设备:{clientName[i]},获取运行数据异常,请检查设备");
+                                    break;
+                                case 3:
+                                    ShowMsg(Msg4, 0, $"温湿度设备:{clientName[i]},获取运行数据异常,请检查设备");
+                                    break;
+                                default:
+                                    ShowMsg(Msg1, 0, $"温湿度设备:{clientName[i]},获取运行数据异常,请检查设备");
+                                    break;
+                            }
                         }
+                        JToken chart = root["data"]["equip"]["chart"];
+
+                        string checkPoint1_T = chart["检测点01"]["当前温度"].ToString();
+                        string checkPoint1_H = chart["检测点01"]["当前湿度"].ToString();
+
+                        string checkPoint2_T = chart["检测点02"]["当前温度"].ToString();
+                        string checkPoint2_H = chart["检测点02"]["当前湿度"].ToString();
+
+                        string checkPoint3_T = chart["检测点03"]["当前温度"].ToString();
+                        string checkPoint3_H = chart["检测点03"]["当前湿度"].ToString();
+
+                        string checkPoint4_T = chart["检测点04"]["当前温度"].ToString();
+                        string checkPoint4_H = chart["检测点04"]["当前湿度"].ToString();
+
+                        string checkPoint5_T = chart["检测点05"]["当前温度"].ToString();
+                        string checkPoint5_H = chart["检测点05"]["当前湿度"].ToString();
+
+                        string average = chart["环境平均湿度"].ToString();
+
+                        dh.ExecuteSql($@"INSERT INTO HUMITURE (HU_ID,HU_INDATE,CHECKPOINT1_T,CHECKPOINT1_H,CHECKPOINT2_T,CHECKPOINT2_H,CHECKPOINT3_T,CHECKPOINT3_H,
+                        CHECKPOINT4_T,CHECKPOINT4_H,CHECKPOINT5_T,CHECKPOINT5_H,AVERAGE,EQUITYPE,EQUIID) VALUES 
+                        (HUMITURE_SEQ.NEXTVAL,sysdate,'{checkPoint1_T}','{checkPoint1_H}','{checkPoint2_T}','{checkPoint2_H}','{checkPoint3_T}','{checkPoint3_H}',
+                         '{checkPoint4_T}','{checkPoint4_H}','{checkPoint5_T}','{checkPoint5_H}','{average}','{clientName[i]}','{clientId[i]}')", "insert");
                     }
-                    else
+                    catch(Exception ex)
                     {
                         switch (i)
                         {
                             case 1:
-                                ShowMsg(Msg2, 0, $"温湿度设备:{clientName[i]},获取运行数据异常,请检查设备");
+                                ShowMsg(Msg2, 0, $"获取设备:{clientName[i]}数据时发生错误: {ex.Message}");
                                 break;
                             case 2:
-                                ShowMsg(Msg3, 0, $"温湿度设备:{clientName[i]},获取运行数据异常,请检查设备");
+                                ShowMsg(Msg3, 0, $"获取设备:{clientName[i]}数据时发生错误: {ex.Message}");
                                 break;
                             case 3:
-                                ShowMsg(Msg4, 0, $"温湿度设备:{clientName[i]},获取运行数据异常,请检查设备");
+                                ShowMsg(Msg4, 0, $"获取设备:{clientName[i]}数据时发生错误: {ex.Message}");
                                 break;
                             default:
-                                ShowMsg(Msg1, 0, $"温湿度设备:{clientName[i]},获取运行数据异常,请检查设备");
+                                ShowMsg(Msg1, 0, $"获取设备:{clientName[i]}数据时发生错误: {ex.Message}");
                                 break;
                         }
                     }
-
-                    JsonElement chart = root.GetProperty("data").GetProperty("equip").GetProperty("chart");
-
-                    JsonElement checkPoint1_T = chart.GetProperty("检测点01").GetProperty("当前温度");
-                    JsonElement checkPoint1_H = chart.GetProperty("检测点01").GetProperty("当前湿度");
-
-                    JsonElement checkPoint2_T = chart.GetProperty("检测点02").GetProperty("当前温度");
-                    JsonElement checkPoint2_H = chart.GetProperty("检测点02").GetProperty("当前湿度");
-
-                    JsonElement checkPoint3_T = chart.GetProperty("检测点03").GetProperty("当前温度");
-                    JsonElement checkPoint3_H = chart.GetProperty("检测点03").GetProperty("当前湿度");
-
-                    JsonElement checkPoint4_T = chart.GetProperty("检测点04").GetProperty("当前温度");
-                    JsonElement checkPoint4_H = chart.GetProperty("检测点04").GetProperty("当前湿度");
-
-                    JsonElement checkPoint5_T = chart.GetProperty("检测点05").GetProperty("当前温度");
-                    JsonElement checkPoint5_H = chart.GetProperty("检测点05").GetProperty("当前湿度");
-
-                    JsonElement average = chart.GetProperty("环境平均湿度");
-
-                    dh.ExecuteSql($@"INSERT INTO HUMITURE (HU_ID,HU_INDATE,CHECKPOINT1_T,CHECKPOINT1_H,CHECKPOINT2_T,CHECKPOINT2_H,CHECKPOINT3_T,CHECKPOINT3_H,
-                                CHECKPOINT4_T,CHECKPOINT4_H,CHECKPOINT5_T,CHECKPOINT5_H,AVERAGE,EQUITYPE,EQUIID) VALUES 
-                                (HUMITURE_SEQ.NEXTVAL,sysdate,'{checkPoint1_T.ToString()}','{checkPoint1_H.ToString()}','{checkPoint2_T.ToString()}','{checkPoint2_H.ToString()}','{checkPoint3_T.ToString()}','{checkPoint3_H.ToString()}',
-                                 '{checkPoint4_T.ToString()}','{checkPoint4_H.ToString()}','{checkPoint5_T.ToString()}','{checkPoint5_H.ToString()}','{average.ToString()}','{clientName[i]}','{clientId[i]}')", "insert");
-
+                    
                 }
             }
-            catch(Exception ex)
+            catch (Exception ex)
             {
                 ShowMsg(Msg1, 0, $"获取数据时发生错误: {ex.Message}");
             }
@@ -228,7 +240,7 @@ namespace UAS_MES_NEW.Make
             public static async Task<string> PostAsync<T>(string url, T data)
             {
                 var client = new HttpClient();
-                string json = JsonSerializer.Serialize(data);
+                string json = JsonConvert.SerializeObject(data);
                 var content = new StringContent(json, Encoding.UTF8, "application/json");
                 var response = await client.PostAsync(url, content);
                 response.EnsureSuccessStatusCode();

+ 3 - 29
UAS_MES_YTDZ/UAS_MES_YTDZ.csproj

@@ -32,8 +32,6 @@
     <CreateDesktopShortcut>true</CreateDesktopShortcut>
     <PublishWizardCompleted>true</PublishWizardCompleted>
     <BootstrapperEnabled>true</BootstrapperEnabled>
-    <NuGetPackageImportStamp>
-    </NuGetPackageImportStamp>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
     <PlatformTarget>x86</PlatformTarget>
@@ -144,8 +142,9 @@
       <EmbedInteropTypes>False</EmbedInteropTypes>
       <HintPath>Tool\Interop.SpeechLib.dll</HintPath>
     </Reference>
-    <Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=10.0.0.8, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
-      <HintPath>packages\Microsoft.Bcl.AsyncInterfaces.10.0.8\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
+    <Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
     </Reference>
     <Reference Include="NPOI, Version=1.2.5.0, Culture=neutral, PublicKeyToken=0df73ec7942b34e1, processorArchitecture=MSIL">
       <SpecificVersion>False</SpecificVersion>
@@ -158,28 +157,11 @@
     <Reference Include="System" />
     <Reference Include="System.Configuration" />
     <Reference Include="System.Core" />
-    <Reference Include="System.IO.Pipelines, Version=10.0.0.8, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
-      <HintPath>packages\System.IO.Pipelines.10.0.8\lib\net462\System.IO.Pipelines.dll</HintPath>
-    </Reference>
     <Reference Include="System.Management" />
-    <Reference Include="System.Memory, Version=4.0.5.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
-      <HintPath>packages\System.Memory.4.6.3\lib\net462\System.Memory.dll</HintPath>
-    </Reference>
     <Reference Include="System.Net.Http" />
     <Reference Include="System.Runtime.Serialization" />
     <Reference Include="System.ServiceModel" />
-    <Reference Include="System.Text.Encodings.Web, Version=10.0.0.8, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
-      <HintPath>packages\System.Text.Encodings.Web.10.0.8\lib\net462\System.Text.Encodings.Web.dll</HintPath>
-    </Reference>
-    <Reference Include="System.Text.Json, Version=10.0.0.8, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
-      <HintPath>packages\System.Text.Json.10.0.8\lib\net462\System.Text.Json.dll</HintPath>
-    </Reference>
-    <Reference Include="System.Threading.Tasks.Extensions, Version=4.2.4.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
-      <HintPath>packages\System.Threading.Tasks.Extensions.4.6.3\lib\net462\System.Threading.Tasks.Extensions.dll</HintPath>
-    </Reference>
-    <Reference Include="System.ValueTuple" />
     <Reference Include="System.Web" />
-    <Reference Include="System.Web.Extensions" />
     <Reference Include="System.Web.Services" />
     <Reference Include="System.Windows.Forms.DataVisualization" />
     <Reference Include="System.Xml.Linq" />
@@ -1653,7 +1635,6 @@
     <None Include="App.config">
       <SubType>Designer</SubType>
     </None>
-    <None Include="packages.config" />
     <None Include="Properties\Settings.settings">
       <Generator>SettingsSingleFileGenerator</Generator>
       <LastGenOutput>Settings1.Designer.cs</LastGenOutput>
@@ -1856,11 +1837,4 @@
   <Target Name="AfterBuild">
   </Target>
   -->
-  <Import Project="packages\System.ValueTuple.4.6.2\build\net471\System.ValueTuple.targets" Condition="Exists('packages\System.ValueTuple.4.6.2\build\net471\System.ValueTuple.targets')" />
-  <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
-    <PropertyGroup>
-      <ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText>
-    </PropertyGroup>
-    <Error Condition="!Exists('packages\System.ValueTuple.4.6.2\build\net471\System.ValueTuple.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\System.ValueTuple.4.6.2\build\net471\System.ValueTuple.targets'))" />
-  </Target>
 </Project>

+ 0 - 14
UAS_MES_YTDZ/packages.config

@@ -1,14 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<packages>
-  <package id="Microsoft.Bcl.AsyncInterfaces" version="10.0.8" targetFramework="net48" />
-  <package id="Newtonsoft.Json" version="13.0.4" targetFramework="net48" />
-  <package id="System.Buffers" version="4.6.1" targetFramework="net48" />
-  <package id="System.IO.Pipelines" version="10.0.8" targetFramework="net48" />
-  <package id="System.Memory" version="4.6.3" targetFramework="net48" />
-  <package id="System.Numerics.Vectors" version="4.6.1" targetFramework="net48" />
-  <package id="System.Runtime.CompilerServices.Unsafe" version="6.1.2" targetFramework="net48" />
-  <package id="System.Text.Encodings.Web" version="10.0.8" targetFramework="net48" />
-  <package id="System.Text.Json" version="10.0.8" targetFramework="net48" />
-  <package id="System.Threading.Tasks.Extensions" version="4.6.3" targetFramework="net48" />
-  <package id="System.ValueTuple" version="4.6.2" targetFramework="net48" />
-</packages>