/
SelectedItem.cs
203 lines (195 loc) · 9.15 KB
/
SelectedItem.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Newtonsoft.Json.Linq;
using RestSharp;
using AB.UI_Class;
namespace AB
{
public partial class SelectedItem : Form
{
string gAdjType = "";
public SelectedItem(string adjType)
{
gAdjType = adjType;
InitializeComponent();
}
utility_class utilityc = new utility_class();
public DataTable dtSelectedItems = new DataTable();
private void SelectedItem_Load(object sender, EventArgs e)
{
loadData();
}
public void loadData()
{
if (dtSelectedItems.Rows.Count > 0)
{
dgv.Rows.Clear();
foreach (DataRow row in dtSelectedItems.Rows)
{
dgv.Rows.Add(row["item_code"].ToString(), Convert.ToDouble(row["quantity"].ToString()), row["uom"].ToString());
}
}
}
private void dgv_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (dgv.Rows.Count > 0)
{
if (e.ColumnIndex == 3)
{
DialogResult dialogResult = MessageBox.Show("Are you sure you want to remove?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dialogResult == DialogResult.Yes)
{
dgv.Rows.RemoveAt(dgv.CurrentRow.Index);
}
}
}
}
private void btnBack_Click(object sender, EventArgs e)
{
DataTable dtDgv = new DataTable();
dtDgv.Columns.Add("item_code");
dtDgv.Columns.Add("quantity");
dtDgv.Columns.Add("uom");
dtDgv.Rows.Clear();
for(int i =0; i < dgv.Rows.Count; i++)
{
string itemName = dgv.Rows[i].Cells["item_code"].Value.ToString();
string quantity = dgv.Rows[i].Cells["quantity"].Value.ToString();
string uom = dgv.Rows[i].Cells["uom"].Value.ToString();
dtDgv.Rows.Add(itemName, quantity, uom);
}
AddAdjustmentIn addAdjustmentIn = new AddAdjustmentIn(gAdjType);
addAdjustmentIn.dtSelectedItems2 = dtDgv;
addAdjustmentIn.ShowDialog();
this.Hide();
}
private void btnProceed_Click(object sender, EventArgs e)
{
if (dgv.Rows.Count > 0)
{
SAP_Remarks sAP_Remarks = new SAP_Remarks();
sAP_Remarks.isOptional = true;
sAP_Remarks.ShowDialog();
if (SAP_Remarks.isSubmit)
{
int sap_number = SAP_Remarks.sap_number;
string remarks = SAP_Remarks.rem;
Cursor.Current = Cursors.WaitCursor;
if (Login.jsonResult != null)
{
string token = "";
foreach (var x in Login.jsonResult)
{
if (x.Key.Equals("token"))
{
token = x.Value.ToString();
}
}
if (!token.Equals(""))
{
var client = new RestClient(utilityc.URL);
client.Timeout = -1;
var request = new RestRequest("/api/inv_adj/" + gAdjType + "/new");
//MessageBox.Show("/api/inv_adj/" + gAdjType + "/new");
request.AddHeader("Authorization", "Bearer " + token);
request.Method = Method.POST;
JObject jObjectBody = new JObject();
JArray jArrayRows = new JArray();
JObject jObjectHeader = new JObject();
jObjectHeader.Add("transdate", DateTime.Now.ToString("yyyy-MM-dd hh:mm"));
if (sap_number <= 0)
{
jObjectHeader.Add("sap_number", null);
}
else
{
jObjectHeader.Add("sap_number", sap_number);
}
jObjectHeader.Add("remarks", remarks);
jObjectBody.Add("header", jObjectHeader);
if(dgv.Rows.Count > 0)
{
for (int i = 0; i < dgv.Rows.Count; i++)
{
JObject jObjectRows = new JObject();
string itemCode = dgv.Rows[i].Cells["item_code"].Value.ToString();
double quantity = Convert.ToDouble(dgv.Rows[i].Cells["quantity"].Value.ToString());
string uom = dgv.Rows[i].Cells["uom"].Value.ToString();
jObjectRows.Add("item_code", itemCode);
jObjectRows.Add("quantity", quantity);
jObjectRows.Add("uom", uom);
jArrayRows.Add(jObjectRows);
}
jObjectBody.Add("rows", jArrayRows);
request.AddParameter("application/json", jObjectBody, ParameterType.RequestBody);
var response = client.Execute(request);
if (response.Content.ToString().Substring(0, 1).Equals("{"))
{
JObject jObjectResponse = JObject.Parse(response.Content);
bool isSuccess = false;
foreach (var x in jObjectResponse)
{
if (x.Key.Equals("success"))
{
isSuccess = Convert.ToBoolean(x.Value.ToString());
}
}
if (isSuccess)
{
string msg = "Object message key not found";
foreach (var x in jObjectResponse)
{
if (x.Key.Equals("message"))
{
msg = x.Value.ToString();
}
}
Cursor.Current = Cursors.Default;
MessageBox.Show(msg, "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Hide();
}
else
{
string msg = "Object message key not found";
foreach (var x in jObjectResponse)
{
if (x.Key.Equals("message"))
{
msg = x.Value.ToString();
}
}
if (msg.Equals("Token is invalid"))
{
Cursor.Current = Cursors.Default;
MessageBox.Show("Your login session is expired. Please login again", "Validation", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
Cursor.Current = Cursors.Default;
MessageBox.Show(msg, "Validation", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
else
{
MessageBox.Show(response.Content.ToString(), "Validation", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
}
}
}
else
{
MessageBox.Show("No data selected", "Validation", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
}