-
Notifications
You must be signed in to change notification settings - Fork 0
/
md_general.cs
237 lines (218 loc) · 7.41 KB
/
md_general.cs
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
using System;
using System.Data;
using System.IO;
using System.Text;
public class md_general
{
public class PKK_Property_Info
{
public pkk_feature feature;
public string note;
public int status;
}
public class pkk_feature
{
public pkk_attrs attrs;
public pkk_center center;
public pkk_extent extent;
public bool stat;
public int type;
}
public class pkk_attrs {
public DateTime adate;
public string address;
public string anno_text;
public string area_type;
public string area_unit;
public decimal area_value;
public decimal cad_cost;
public pkk_cad_eng_data cad_eng_data;
public DateTime cad_record_date;
public string cad_unit;
public string category_type;
public string cn;
public DateTime date_cost;
public DateTime date_create;
public string fp;
public string id;
public string kvartal;
public string kvartal_cn;
public string okrug;
public string okrug_cn;
public DateTime pubdate;
public string rayon;
public string rayon_cn;
public int reg;
public string rifr;
public int rights_reg;
public int sale;
public string statecd;
public string util_by_doc;
public string util_code;
}
public class pkk_cad_eng_data
{
public string actual_date;
public string ci_first;
public string ci_n_certificate;
public string ci_patronymic;
public string ci_surname;
public string lastmodified;
public int rc_type;
}
public class pkk_center
{
public decimal x;
public decimal y;
}
public class pkk_extent
{
public decimal xmax;
public decimal xmin;
public decimal ymax;
public decimal ymin;
}
public static DataTable GetCadastralInfoFromPKK_REST(string cadastral)
{
//System.Net.WebClient obj = new System.Net.WebClient();
string rosreestr_id = "";
string str_text = "";
//UTF8Encoding utf8 = new UTF8Encoding();
//byte[] qqq;
DataSet dsCadastral;
DataTable dtCadastral;
DataRow d_row;
PKK_Property_Info pty = new PKK_Property_Info();
Newtonsoft.Json.JsonSerializerSettings settings = new Newtonsoft.Json.JsonSerializerSettings();
settings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
settings.StringEscapeHandling = Newtonsoft.Json.StringEscapeHandling.Default;
rosreestr_id = Transform_Cadastral(cadastral);
Uri strUrl = new Uri(System.String.Format("http://pkk5.rosreestr.ru/api/features/1/{0}?date_format=%Y-%m-%d", rosreestr_id));
//--------------------------------------------------------
System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(strUrl);
request.Method = System.Net.WebRequestMethods.Http.Get;
request.Accept = "application/json";
request.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
request.Credentials = System.Net.CredentialCache.DefaultCredentials;
request.ReadWriteTimeout = 60000;
try
{
System.Net.WebResponse response = request.GetResponse();
using (Stream responseStream = response.GetResponseStream()) {
StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
str_text = reader.ReadToEnd();
}
}
catch (System.Net.WebException ex)
{
dsCadastral = new DataSet();
dtCadastral = dsCadastral.Tables.Add();
dtCadastral.Columns.Add("error", typeof(String));
d_row = dtCadastral.NewRow();
d_row["error"] = ex.Message;
dtCadastral.Rows.Add(d_row);
return dtCadastral;
throw;
}
//--------------------------------------------------------
// str_text = utf8.GetString(qqq)
pty = Newtonsoft.Json.JsonConvert.DeserializeObject<PKK_Property_Info>(str_text, settings);
dsCadastral = new DataSet();
string xml_file_path = AppDomain.CurrentDomain.BaseDirectory + "XML\\online_data.xsd";
//''dsCadastral.ReadXmlSchema(xml_file_path)
//' dtCadastral = dsCadastral.Tables("Property")
//''dtCadastral = dsCadastral.Tables("rosreestr_info")
dtCadastral = new Rosreestr_Info.XML.online_data.rosreestr_infoDataTable();
d_row = dtCadastral.NewRow();
d_row["cadastral"] = cadastral;
if (pty.feature == null)
{
dsCadastral = new DataSet();
dtCadastral = dsCadastral.Tables.Add();
dtCadastral.Columns.Add("error", typeof(String));
d_row = dtCadastral.NewRow();
d_row["error"] = "Не найдено";
dtCadastral.Rows.Add(d_row);
return dtCadastral;
}
d_row["p_cadastral"] = pty.feature.attrs.cn;
d_row["p_stoim"] = pty.feature.attrs.cad_cost;
d_row["p_date_stoim"] = pty.feature.attrs.date_cost;
d_row["p_area"] = pty.feature.attrs.area_value;
if (pty.feature.attrs.util_by_doc != null)
{
d_row["p_utilByDoc"] = pty.feature.attrs.util_by_doc.Replace(""", "\"\"");
}
else
{
d_row["p_utilByDoc"] = "";
}
if (pty.feature.attrs.util_code != null)
{
d_row["p_utilCode"] = pty.feature.attrs.util_code;
}
else
{
d_row["p_utilCode"] = "";
}
//'If Not (pty.parcelData.utilCodedesc Is Nothing) Then
//' d_row("p_utilDesc") = pty.parcelData.utilCodedesc.Replace(""", """")
//'Else
//' d_row("p_utilDesc") = ""
//'End If
d_row["p_status"] = "";
d_row["p_status_str"] = "-";
string status_text ="";
if (pty.feature.attrs.statecd != null) {
d_row["p_status"] = pty.feature.attrs.statecd;
switch (pty.feature.attrs.statecd)
{
case "01":
status_text = "Ранее учтенный";
break;
case "06":
status_text = "Учтенный";
break;
case "07":
status_text = "Снят с учета";
break;
default:
break;
}
d_row["p_status_str"] = status_text;
}
dtCadastral.Rows.Add(d_row);
return dtCadastral;
}
public static string Transform_Cadastral(string cadastral)
{
string res = "";
string[] ar_cad;
string part = "";
string sep = "";
ar_cad = cadastral.Split(':');
int n;
for (int i = 0; i < ar_cad.Length ; i++)
{
if (int.TryParse(ar_cad[i], out n))
{
// part = ar_cad[i].TrimStart('0');
part = n.ToString() ;
}
else
{
part = ar_cad[i];
}
if (i==0)
{
sep = "";
}
else
{
sep = ":";
}
res = res + sep + part.Trim(' ');
}
return res;
}
}