duheng
2024-03-26 a2d290779e72270ac5ee3ed86abe38aae3db064e
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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
 
namespace IStation.BLL
{
    public class PumpRunHelper
    {
        /// <summary>
        /// 查询实际数据
        /// 从众毅获取
        /// </summary>
        /// <param name="dateTime"></param>
        /// <param name="error"></param>
        /// <returns></returns>
        public Model.PumpRunParasDays GetPumpRunParasOneDay(DateTime dateTime,out string error)
        {
              string url = $"http://47.100.245.85:86/PumpRun/GetByOneDay?startday={dateTime}";
              string Accept = "application/json";
            //创建Web访问对象
             HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
            myRequest.Method = "GET";
            //myRequest.Accept = "application/json";
            //myRequest.ContentType = "application/json";  // //Content-Type: application/x-www-form-urlencoded 
            myRequest.AutomaticDecompression = DecompressionMethods.GZip;
            myRequest.Accept = Accept;
            //myRequest.ContentType = ContentType;
            myRequest.ContentType = "application/json; charset=UTF-8";
            //myRequest.ContentLength = buf.Length;
            myRequest.MaximumAutomaticRedirections = 1;
            myRequest.AllowAutoRedirect = true;
            HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
            //通过响应内容流创建StreamReader对象,因为StreamReader更高级更快
            StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
            //string returnXml = HttpUtility.UrlDecode(reader.ReadToEnd());//如果有编码问题就用这个方法
            string returnData = reader.ReadToEnd();//利用StreamReader就可以从响应内容从头读到尾
            if (string.IsNullOrEmpty(returnData))
            {
                myResponse.Close();
                error = "利用StreamReader就可以从响应内容从头读到尾";
                return null;
            }
            var ret = (new System.Web.Script.Serialization.JavaScriptSerializer()).Deserialize<IStation.Dto.ApiResult<Model.PumpRunParasDays>>(returnData);
            reader.Close();
            myResponse.Close();
            error = null;
            return ret.Data;
        }
 
 
        /// <summary>
        /// 查询去年运行数据
        /// </summary>
        /// <param name="dateTime"></param>
        /// <param name="error"></param>
        /// <returns></returns>
        public List<Model.RunParasData> GetByHistoryOneData(DateTime dateTime ,out string error)
        {
            string url = $"http://47.100.245.85:86/PumpRun/GetByHistoryOneDay?day={dateTime}";
            string Accept = "application/json";
            //创建Web访问对象
            HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
            myRequest.Method = "GET";
            //myRequest.Accept = "application/json";
            //myRequest.ContentType = "application/json";  // //Content-Type: application/x-www-form-urlencoded 
            myRequest.AutomaticDecompression = DecompressionMethods.GZip;
            myRequest.Accept = Accept;
            //myRequest.ContentType = ContentType;
            myRequest.ContentType = "application/json; charset=UTF-8";
            //myRequest.ContentLength = buf.Length;
            myRequest.MaximumAutomaticRedirections = 1;
            myRequest.AllowAutoRedirect = true;
            HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
            //通过响应内容流创建StreamReader对象,因为StreamReader更高级更快
            StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
            //string returnXml = HttpUtility.UrlDecode(reader.ReadToEnd());//如果有编码问题就用这个方法
            string returnData = reader.ReadToEnd();//利用StreamReader就可以从响应内容从头读到尾
            if (string.IsNullOrEmpty(returnData))
            {
                myResponse.Close();
                error = "利用StreamReader就可以从响应内容从头读到尾";
                return null;
            }
            var ret = (new System.Web.Script.Serialization.JavaScriptSerializer()).Deserialize<IStation.Dto.ApiResult<List< Model.RunParasData>>>(returnData);
            reader.Close();
            myResponse.Close();
            error = null;
            return ret.Data;
        }
    }
 }