-
Notifications
You must be signed in to change notification settings - Fork 2
/
Corporates.aspx.cs
298 lines (235 loc) · 10.5 KB
/
Corporates.aspx.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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Text.RegularExpressions;
using System.Data.SqlTypes;
using System.Text;
using Newtonsoft.Json;
using System.IO;
public partial class Corporates : System.Web.UI.Page
{
public class Token
{
public string access_token { get; set; }
public string token_type { get; set; }
public string expires_in { get; set; }
// public string Content-type { get; set; }
}
public class Receiver
{
public string Success { get; set; }
//public string Message { get; set; }
//public string Result { get; set; }
}
SqlConnection con = new SqlConnection(PAYEClass.connection);
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
/***************************************************************/
// string URI = "https://stage-api.eirsautomation.xyz/Account/Login";
// URI = PAYEClass.URL_API + "Account/Login";
// // string myParameters = "UserName=Contec&Password=3Uhf7j~4&grant_type=password";
// string user = "Contec";
// string myParameters = "UserName=" + user + "&Password=Znal821*&grant_type=password";
// string BearerToken = "";
// using (WebClient wc = new WebClient())
// {
// wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
// BearerToken = wc.UploadString(URI, myParameters);
// }
// // Token[] jsonObject = JsonReader.Deserialize<Token[]>(BearerToken);
// Token TokenObj = JsonConvert.DeserializeObject<Token>(BearerToken);
// /**************************************************************/
//// string a = get_json();
// DataTable dt_updated = new DataTable();
// SqlDataAdapter Adp_updated = new SqlDataAdapter("SELECT DATEDIFF(minute, CAST(lastUpdatedOn as DATETIME), GETDATE()) as diff, frequency FROM tables_API_Updated where TableName='CompanyList_API'", con);
// // DataTable Dt_database = new DataTable();
// Adp_updated.Fill(dt_updated);
// string a = "";
////if (Convert.ToInt32(dt_updated.Rows[0]["diff"].ToString()) >= 0)
// if (Convert.ToInt32(dt_updated.Rows[0]["diff"].ToString()) > Convert.ToInt32(dt_updated.Rows[0]["frequency"].ToString()))
// {
// a = upload_json("");
// }
// var des = (Receiver)JsonConvert.DeserializeObject(a, typeof(Receiver));
// string InsCompRes = "";
// InsCompRes = a;
DataTable dt_list = new DataTable();
// if (des!=null && (des.Success).ToLower().ToString() == "true")
// {
// if (a != "" && InsCompRes.Split('[')[1].ToString() != "]}")
// {
// dt_list = (DataTable)JsonConvert.DeserializeObject("[" + InsCompRes.Split('[')[1].Replace("}]", "") + InsCompRes.Split('[')[2].Replace("}]", "") + "]", (typeof(DataTable)));
// // DataTable dt_list = (DataTable)JsonConvert.DeserializeObject("[" + InsCompRes.Split('[')[1].Replace("}]", "") + "]", (typeof(DataTable)));
// insert(dt_list);
// }
// else
// {
// SqlDataAdapter Adp = new SqlDataAdapter("select * from CompanyList_API", con);
// // DataTable Dt_database = new DataTable();
// Adp.Fill(dt_list);
// }
// }
// else
// {
SqlDataAdapter Adp = new SqlDataAdapter("select * from CompanyList_API", con);
// DataTable Dt_database = new DataTable();
Adp.Fill(dt_list);
//}
Session["dt_l"] = dt_list;
grd_Corporate.DataSource = dt_list;
grd_Corporate.DataBind();
int pagesize = grd_Corporate.Rows.Count;
int from_pg = 1;
int to = grd_Corporate.Rows.Count;
int totalcount = dt_list.Rows.Count;
lblpagefrom.Text = from_pg.ToString();
lblpageto.Text = (from_pg + pagesize - 1).ToString();
lbltoal.Text = totalcount.ToString();
if (totalcount < grd_Corporate.PageSize)
div_paging.Style.Add("margin-top", "0px");
else
div_paging.Style.Add("margin-top", "-60px");
}
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
grd_Corporate.PageIndex = e.NewPageIndex;
grd_Corporate.DataSource = Session["dt_l"];
grd_Corporate.DataBind();
if (e.NewPageIndex + 1 == 1)
{
lblpagefrom.Text = "1";
}
else
{
lblpagefrom.Text = ((grd_Corporate.Rows.Count * e.NewPageIndex) + 1).ToString();
}
lblpageto.Text = ((e.NewPageIndex + 1) * grd_Corporate.Rows.Count).ToString();
}
protected void btn_search_Click(object sender, EventArgs e)
{
DataTable dt_list_s = new DataTable();
dt_list_s = (DataTable)Session["dt_l"];
// DataRow[] filteredRows = dt_list_s.Select("TaxPayerRIN LIKE '" + txt_RIN.Text + "'");
DataTable dt_filtered = new DataTable();
DataView dt_v = dt_list_s.DefaultView;
if (txt_RIN.Text != "")
dt_v.RowFilter = "TaxPayerRIN like '%" + txt_RIN.Text + "%'";
if (txt_name.Text != "")
dt_v.RowFilter = "TaxPayerName like '%" + txt_name.Text + "%'";
if (txt_tin.Text != "")
dt_v.RowFilter = "TIN like '%" + txt_tin.Text + "%'";
grd_Corporate.DataSource = dt_v;
grd_Corporate.DataBind();
int pagesize = grd_Corporate.Rows.Count;
int from_pg = 1;
int to = grd_Corporate.Rows.Count;
int totalcount = dt_v.Count;
lblpagefrom.Text = from_pg.ToString();
lblpageto.Text = (from_pg + pagesize - 1).ToString();
lbltoal.Text = totalcount.ToString();
if (totalcount < grd_Corporate.PageSize)
div_paging.Style.Add("margin-top", "0px");
else
div_paging.Style.Add("margin-top", "-60px");
}
public string get_json()
{
WebClient request = new WebClient();
string url = PAYEClass.uploadurltxtfile + "Company.txt";
string version = "";
string fileString = "";
request.Credentials = new NetworkCredential(PAYEClass.ftpusername, PAYEClass.ftppassword);
// FtpWebResponse response = (FtpWebResponse)request.GetResponse();
try
{
// byte[] data = Encoding.ASCII.GetBytes("dd");
// request.UploadData(new Uri("ftp://pinscher.eirsautomation.xyz/App_Code/") + "Individuals.txt",data);
byte[] newFileData = request.DownloadData(new Uri(url));
fileString = System.Text.Encoding.UTF8.GetString(newFileData);
}
catch (WebException e)
{
}
return fileString;
}
public string upload_json(string json)
{
/***************************************************************/
string token = PAYEClass.getToken();
/**************************************************************/
string URI1 = "https://stage-api.eirsautomation.xyz/SupplierData/PAYE_Collection_Multiple_Employees_BS_A_F_TaxPayer";
URI1 = PAYEClass.URL_API + "SupplierData/PAYE_Collection_Multiple_Employees_BS_A_F_TaxPayer";
string myParameters1 = "";
string InsCompRes = "";
using (var wc = new WebClient())
{
wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
wc.Headers[HttpRequestHeader.Authorization] = "Bearer " + token;
InsCompRes = wc.DownloadString(URI1);
}
json = InsCompRes;
WebClient request = new WebClient();
string url = PAYEClass.uploadurltxtfile + "Company.txt";
string version = "";
string fileString = "";
request.Credentials = new NetworkCredential(PAYEClass.ftpusername, PAYEClass.ftppassword);
try
{
// byte[] data = Encoding.ASCII.GetBytes(json);
// request.UploadData(new Uri(url), data);
}
catch (WebException e)
{
}
return json;
}
protected void lnkCustDetails_Click(object sender, EventArgs e)
{
// divTaxPayerModal.Style.Add("display", "");
}
public void insert(DataTable table)
{
try
{
SqlConnection con1 = new SqlConnection(PAYEClass.connection);
SqlCommand truncate = new SqlCommand("TRUNCATE TABLE CompanyList_API", con);
con.Open();
truncate.ExecuteNonQuery();
con.Close();
SqlCommand update_tables_API_Updated = new SqlCommand("update tables_API_Updated set LastUpdatedOn=getdate() where TableName='CompanyList_API'", con);
con.Open();
update_tables_API_Updated.ExecuteNonQuery();
con.Close();
// Array.ForEach<DataRow>(table.Select("TaxPayerRIN IS NULL"), row => row.Delete());
Array.ForEach<DataRow>(table.Select("TaxPayerTypeID IS NULL"), row => row.Delete());
Array.ForEach<DataRow>(table.Select("TaxPayerID IS NULL"), row => row.Delete());
using (var bulkCopy = new SqlBulkCopy(con1.ConnectionString, SqlBulkCopyOptions.KeepIdentity))
{
//con.Open();
// my DataTable column names match my SQL Column names, so I simply made this loop. However if your column names don't match, just pass in which datatable name matches the SQL column name in Column Mappings
foreach (DataColumn col in table.Columns)
{
bulkCopy.ColumnMappings.Add(col.ColumnName, col.ColumnName);
}
bulkCopy.BulkCopyTimeout = 600;
bulkCopy.DestinationTableName = "CompanyList_API";
bulkCopy.WriteToServer(table);
}
}
catch (Exception e)
{
}
}
protected void grd_Corporate_RowDataBound(object sender, GridViewRowEventArgs e)
{
}
}