256 lines
11 KiB
C#
256 lines
11 KiB
C#
|
using Newtonsoft.Json.Linq;
|
|||
|
using System;
|
|||
|
using System.Data;
|
|||
|
using System.Net.Http;
|
|||
|
using System.Net.Http.Headers;
|
|||
|
using System.Text.RegularExpressions;
|
|||
|
using System.Windows.Forms;
|
|||
|
|
|||
|
namespace HL_FristAidPlatform_DynamicElectrocardiogram
|
|||
|
{
|
|||
|
public partial class Form_ECGDW : Form
|
|||
|
{
|
|||
|
private Uri urlPath = new Uri("http://ecg.datawe.net/");
|
|||
|
private DataSet DataSet;
|
|||
|
public Form_ECGDW()
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
}
|
|||
|
|
|||
|
private void simpleButton1_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
string url = "ecgConsole/device-login.htm?userName=tangdx2&passWord=123456";
|
|||
|
DataSet = Get(url);
|
|||
|
}
|
|||
|
|
|||
|
public DataSet Get(string Url)
|
|||
|
{
|
|||
|
DataSet dataSet = new DataSet();
|
|||
|
try
|
|||
|
{
|
|||
|
|
|||
|
HttpClient client = new HttpClient
|
|||
|
{
|
|||
|
BaseAddress = urlPath
|
|||
|
};
|
|||
|
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded"));
|
|||
|
//client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
|||
|
HttpResponseMessage responseMessage = client.GetAsync(Url).Result;
|
|||
|
if (responseMessage.IsSuccessStatusCode)
|
|||
|
{
|
|||
|
var itemJson = responseMessage.Content.ReadAsStringAsync().Result;
|
|||
|
dataSet = JsonToDataTable(itemJson);
|
|||
|
return dataSet;
|
|||
|
}
|
|||
|
//else
|
|||
|
//{
|
|||
|
// if (responseMessage.StatusCode.ToString() == "Unauthorized")
|
|||
|
// {
|
|||
|
// if (ResetJWT(token))
|
|||
|
// {
|
|||
|
// return Get(Url);
|
|||
|
// }
|
|||
|
// }
|
|||
|
// else
|
|||
|
// {
|
|||
|
// PublicClass.WriteLog(DateTime.Now.ToString(PublicClass.TimeToString) + responseMessage.RequestMessage + responseMessage.Content.ReadAsStringAsync().Result);//写入一条新log
|
|||
|
// }
|
|||
|
//}
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
//PublicClass.WriteErrorLog("HttpClient", "Get:\r\n" + ex);
|
|||
|
}
|
|||
|
return dataSet;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Json转DataTable
|
|||
|
/// </summary>
|
|||
|
/// <param name="strJson">Json字符</param>
|
|||
|
/// <param name="totalNumber">分页时返回总条数</param>
|
|||
|
/// <returns></returns>
|
|||
|
private static DataSet JsonToDataTable(string strJson)
|
|||
|
{
|
|||
|
DataSet ds = new DataSet();
|
|||
|
try
|
|||
|
{
|
|||
|
DataTable tb = new DataTable();
|
|||
|
JObject jobject = JObject.Parse(strJson);
|
|||
|
tb.TableName = "User";
|
|||
|
DataRow dataRow = tb.NewRow();
|
|||
|
string dataJson = string.Empty;
|
|||
|
string dataInfoVo = string.Empty;
|
|||
|
foreach (var item in jobject)
|
|||
|
{
|
|||
|
if (item.Key == jobject.Property("wzId").Name)
|
|||
|
{
|
|||
|
DataColumn dc = new DataColumn(item.Key, Type.GetType("System.String"));
|
|||
|
tb.Columns.Add(dc);
|
|||
|
dataRow["wzId"] = Regex.Replace(jobject["wzId"].ToString(), @"\s", " ");//空白字符替换
|
|||
|
}
|
|||
|
if (item.Key == jobject.Property("hospitalName").Name)
|
|||
|
{
|
|||
|
DataColumn dc = new DataColumn(item.Key, Type.GetType("System.String"));
|
|||
|
tb.Columns.Add(dc);
|
|||
|
dataRow["hospitalName"] = Regex.Replace(jobject["hospitalName"].ToString(), @"\s", " ");//空白字符替换
|
|||
|
}
|
|||
|
if (item.Key == jobject.Property("dataAddress").Name)
|
|||
|
{
|
|||
|
DataColumn dc = new DataColumn(item.Key, Type.GetType("System.String"));
|
|||
|
tb.Columns.Add(dc);
|
|||
|
dataRow["dataAddress"] = Regex.Replace(jobject["dataAddress"].ToString(), @"\s", " ");//空白字符替换
|
|||
|
}
|
|||
|
if (item.Key == jobject.Property("earlyWarning").Name)
|
|||
|
{
|
|||
|
DataColumn dc = new DataColumn(item.Key, Type.GetType("System.String"));
|
|||
|
tb.Columns.Add(dc);
|
|||
|
dataRow["earlyWarning"] = Regex.Replace(jobject["earlyWarning"].ToString(), @"\s", " ");//空白字符替换
|
|||
|
}
|
|||
|
if (item.Key == jobject.Property("token").Name)
|
|||
|
{
|
|||
|
DataColumn dc = new DataColumn(item.Key, Type.GetType("System.String"));
|
|||
|
tb.Columns.Add(dc);
|
|||
|
dataRow["token"] = Regex.Replace(jobject["token"].ToString(), @"\s", " ");//空白字符替换
|
|||
|
}
|
|||
|
if (item.Key == jobject.Property("doctorVo").Name)
|
|||
|
{
|
|||
|
var dataObj = jobject["doctorVo"][0];
|
|||
|
dataJson = Regex.Replace(dataObj.ToString(), @"\s", " ");//空白字符替换
|
|||
|
}
|
|||
|
if (item.Key == jobject.Property("setInfoVo").Name)
|
|||
|
{
|
|||
|
var dataObj = jobject["setInfoVo"][0];
|
|||
|
dataInfoVo = Regex.Replace(dataObj.ToString(), @"\s", " ");//空白字符替换
|
|||
|
}
|
|||
|
}
|
|||
|
tb.Rows.Add(dataRow);
|
|||
|
|
|||
|
|
|||
|
DataTable doctorVo = new DataTable();
|
|||
|
doctorVo.TableName = "DoctorVo";
|
|||
|
JObject dataoVo = JObject.Parse(dataJson);
|
|||
|
foreach (var item in dataoVo)
|
|||
|
{
|
|||
|
DataColumn dc = new DataColumn(item.Key, Type.GetType("System.String"));
|
|||
|
doctorVo.Columns.Add(dc);
|
|||
|
}
|
|||
|
string data = string.Empty;
|
|||
|
for (int i = 0; i < ((JContainer)jobject["doctorVo"]).Count; i++)
|
|||
|
{
|
|||
|
var doctor = jobject["doctorVo"][i];
|
|||
|
data = Regex.Replace(doctor.ToString(), @"\s", " ");//空白字符替换
|
|||
|
JObject dataobj1 = JObject.Parse(data);
|
|||
|
DataRow doctorVoDataRow = doctorVo.NewRow();
|
|||
|
foreach (var item in dataobj1)
|
|||
|
{
|
|||
|
doctorVoDataRow[item.Key] = item.Value;
|
|||
|
}
|
|||
|
doctorVo.Rows.Add(doctorVoDataRow);
|
|||
|
}
|
|||
|
|
|||
|
DataTable setInfoVo = new DataTable();
|
|||
|
setInfoVo.TableName = "SetInfoVo";
|
|||
|
JObject infoVo = JObject.Parse(dataInfoVo);
|
|||
|
foreach (var item in infoVo)
|
|||
|
{
|
|||
|
if (item.Key != "bluetoothAddress")
|
|||
|
{
|
|||
|
DataColumn dc = new DataColumn(item.Key, Type.GetType("System.String"));
|
|||
|
setInfoVo.Columns.Add(dc);
|
|||
|
}
|
|||
|
}
|
|||
|
string info = string.Empty;
|
|||
|
for (int i = 0; i < ((JContainer)jobject["setInfoVo"]).Count; i++)
|
|||
|
{
|
|||
|
var doctor = jobject["setInfoVo"][i];
|
|||
|
info = Regex.Replace(doctor.ToString(), @"\s", " ");//空白字符替换
|
|||
|
JObject dataobj1 = JObject.Parse(info);
|
|||
|
DataRow doctorVoDataRow = setInfoVo.NewRow();
|
|||
|
foreach (var item in dataobj1)
|
|||
|
{
|
|||
|
if (item.Key != "bluetoothAddress")
|
|||
|
{
|
|||
|
doctorVoDataRow[item.Key] = item.Value;
|
|||
|
}
|
|||
|
}
|
|||
|
setInfoVo.Rows.Add(doctorVoDataRow);
|
|||
|
}
|
|||
|
ds.Tables.Add(tb);
|
|||
|
ds.Tables.Add(doctorVo);
|
|||
|
ds.Tables.Add(setInfoVo);
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
MessageBox.Show(ex.Message);
|
|||
|
}
|
|||
|
return ds;
|
|||
|
}
|
|||
|
|
|||
|
private void simpleButton2_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
string url = "/ecgConsole/sheet/create.htm";
|
|||
|
}
|
|||
|
|
|||
|
private void simpleButton3_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
string token=DataSet.Tables["User"].Rows[0]["token"].ToString();
|
|||
|
//string url = string.Format("/ecgConsole/sheet/ecgreports.htm?token={0}&orgCode={1}&hospitalCode={2}", token,);
|
|||
|
}
|
|||
|
|
|||
|
//public override ListEntity<T> Post(string url, List<T> list)
|
|||
|
//{
|
|||
|
// try
|
|||
|
// {
|
|||
|
// //创建一个处理序列化的DataContractJsonSerializer
|
|||
|
// DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(List<T>));
|
|||
|
// MemoryStream ms = new MemoryStream();
|
|||
|
// //将资料写入MemoryStream
|
|||
|
// serializer.WriteObject(ms, list[0]);
|
|||
|
// //一定要在这设定Position
|
|||
|
// ms.Position = 0;
|
|||
|
// string UrlPath = WebApiUrl + url;
|
|||
|
// //将MemoryStream转成HttpContent
|
|||
|
// HttpContent content = new StreamContent(ms);
|
|||
|
// content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
|
|||
|
|
|||
|
// ListEntity<T> returnT = new ListEntity<T>();
|
|||
|
// HttpClient client = new HttpClient();
|
|||
|
// string token = Information.User.Token;
|
|||
|
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
|||
|
|
|||
|
// //由HttpClient发出Post Method
|
|||
|
// HttpResponseMessage response = client.PostAsync(UrlPath, content).Result;
|
|||
|
// if (response.IsSuccessStatusCode)
|
|||
|
// {
|
|||
|
// var itemJson = response.Content.ReadAsStringAsync().Result;
|
|||
|
// returnT.Success = response.IsSuccessStatusCode;
|
|||
|
// returnT.Msg = response.RequestMessage.ToString();
|
|||
|
// returnT.DataString = itemJson;
|
|||
|
// return returnT;
|
|||
|
// }
|
|||
|
// //else
|
|||
|
// //{
|
|||
|
// // if (response.StatusCode.ToString() == "Unauthorized")
|
|||
|
// // {
|
|||
|
// // if (ResetJWT(token))
|
|||
|
// // {
|
|||
|
// // return Post(url, list);
|
|||
|
// // }
|
|||
|
// // }
|
|||
|
// // else
|
|||
|
// // {
|
|||
|
// // PublicClass.WriteErrorLog("HL_FristAidPlatform_Public", "HttpClientInstance Post:\r\n API地址:" + url + "\r\n错误消息:\r\n" + response.ToString() + "\r\n" + response.Content.ReadAsStringAsync().Result);
|
|||
|
// // }
|
|||
|
// //}
|
|||
|
// return returnT;
|
|||
|
// }
|
|||
|
// catch (Exception ex)
|
|||
|
// {
|
|||
|
// //PublicClass.WriteErrorLog("HttpClientInstance", "Post:\r\n" + ex);
|
|||
|
// return null;
|
|||
|
// }
|
|||
|
//}
|
|||
|
}
|
|||
|
}
|