SServerManager.cs
6.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace OnlineStore.DeviceLibrary
{
public class SServerManager
{
//是否测值:
//http://10.85.17.233/ESMTCommonInterface/CommonService.asmx?op=VMICheckRLC
//结果上传:
//http://10.85.17.233/ReturnOne/WebServiceF.asmx?op=Return_Material
private static string Addr_VMICheckRLC = "/ESMTCommonInterface/CommonService.asmx?op=VMICheckRLC";
private static string Addr_Return_Material = "/ReturnOne/WebServiceF.asmx?op=Return_Material";
public static string Get_VMICheckRLC(string deviceName, string codeStr, out int targetP)
{
//reelID:
//partNum:
//{"data":{"IFneed":"不需要","iftest":"","component":"","msg":"不需要测量RLC","status":1}}
targetP=0;
string msg = "";
try
{
string[] codeArray = codeStr.Split(';');
if (codeArray.Length != 2)
{
return msg = deviceName + "【" + codeStr + "】未找到有效条码";
}
Dictionary<string, string> paramMap = new Dictionary<string, string>();
paramMap.Add("reelID", codeArray[1]);
paramMap.Add("partNum", codeArray[0]);
string server = GetAddr(Addr_VMICheckRLC, paramMap);
if (server.Equals(""))
{
return "获取是否测值失败";
}
DateTime startTime = DateTime.Now;
string resultStr = HttpHelper.Post(server, "");
LogUtil.info("Get_VMICheckRLC " + FormUtil.GetSpanStr(DateTime.Now - startTime) + " 【" + server + "】【" + resultStr + "】");
//{"data":{"IFneed":"不需要","iftest":"","component":"","msg":"不需要测量RLC","status":1}}
CheckData dataResult = JsonHelper.DeserializeJsonToObject<CheckData>(resultStr);
if (dataResult == null)
{
return "获取是否测值失败";
}
else if (dataResult.status.Equals(1) && dataResult.IFneed.Equals("不需要"))
{
targetP=1;
return "";
}
else if (dataResult.status.Equals(1) && dataResult.IFneed.Equals("需要"))
{
//需要时,component是电容 或者电阻
if (dataResult.component.Equals("电容"))
{
targetP = 2;
}
else
{
targetP = 3;
}
return "";
}
else
{
targetP = 0;
return msg;
}
}
catch (Exception ex)
{
LogUtil.error(deviceName + " ", ex);
return ex.ToString();
}
}
public static string Return_Material(string deviceName, string codeStr, int count)
{
// Parameter Value
//txtQty:
// txtReelId:
string msg = "";
try
{
string[] codeArray = codeStr.Split(';');
if (codeArray.Length != 2)
{
return msg = deviceName + "【" + codeStr + "】未找到有效条码";
}
Dictionary<string, string> paramMap = new Dictionary<string, string>();
paramMap.Add("txtQty", count.ToString());
paramMap.Add("txtReelId", codeArray[1]);
string server = GetAddr(Addr_Return_Material, paramMap);
if (server.Equals(""))
{
return "";
}
DateTime startTime = DateTime.Now;
string resultStr = HttpHelper.Post(server, "");
LogUtil.info("Return_Material " + FormUtil.GetSpanStr(DateTime.Now - startTime) + " 【" + server + "】【" + resultStr + "】");
// ServerData serverResult = JsonHelper.DeserializeJsonToObject<ServerData>(resultStr);
if (!msg.Equals(""))
{
LogUtil.error(msg);
}
}
catch (Exception ex)
{
LogUtil.error(deviceName + " ", ex);
}
return msg;
}
private static string GetAddr(string addr, Dictionary<string, string> paramsMap)
{
string server = ConfigAppSettings.GetValue(Setting_Init.ServerAddr).Trim();
if (server.Equals(""))
{
return "";
}
if (server.EndsWith("/"))
{
server = server.Substring(0, server.Length - 1);
}
string path = server + addr.Trim() + "?";
foreach (string paramName in paramsMap.Keys)
{
string par = System.Web.HttpUtility.UrlEncode(paramsMap[paramName], System.Text.Encoding.UTF8);
path += paramName + "=" + par + "&";
}
path = path.Substring(0, path.Length - 1);
return path;
}
private static string server = ConfigAppSettings.GetValue(Setting_Init.ServerAddr).Trim();
public static bool CanConnect()
{
return !String.IsNullOrEmpty(server);
}
}
public class CheckData
{
//{"data":{"IFneed":"不需要","iftest":"","component":"","msg":"不需要测量RLC","status":1}}
public int IFneed { get; set; }
public string iftest { get; set; }
public string component { get; set; }
public string msg { get; set; }
public int status { get; set; }
}
}