-
Notifications
You must be signed in to change notification settings - Fork 0
/
ACKNOWLEDGEMENT.aspx.cs
364 lines (289 loc) · 11 KB
/
ACKNOWLEDGEMENT.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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
public partial class ACKNOWLEDGEMENT : System.Web.UI.Page
{
public string ccode;
public string pcode;
public string pname;
public string cname;
public string frmdate;
public string todate;
double fat, snf, clr;
double fatkg;
double snfkg;
double mokg;
DateTime dtm = new DateTime();
BLLuser Bllusers = new BLLuser();
public static int roleid;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if ((Session["Name"] != null) && (Session["pass"] != null))
{
roleid = Convert.ToInt32(Session["Role"].ToString());
ccode = Session["Company_code"].ToString();
pcode = Session["Plant_Code"].ToString();
cname = Session["cname"].ToString();
pname = Session["pname"].ToString();
dtm = System.DateTime.Now;
txt_FromDate.Text = dtm.ToShortDateString();
txt_ToDate.Text = dtm.ToShortDateString();
txt_FromDate.Text = dtm.ToString("dd/MM/yyyy");
txt_ToDate.Text = dtm.ToString("dd/MM/yyyy");
if (roleid < 3)
{
loadsingleplant();
}
else
{
LoadPlantcode();
}
pcode = ddl_Plantcode.SelectedItem.Value;
gridview();
}
else
{
//dtm = System.DateTime.Now;
//// dti = System.DateTime.Now;
//txt_FromDate.Text = dtm.ToString("dd/MM/yyy");
//txt_ToDate.Text = dtm.ToString("dd/MM/yyy");
// pcode = Session["Plant_Code"].ToString();
pcode = ddl_Plantcode.SelectedItem.Value;
// LoadPlantcode();
gridview();
// getrouteid();
}
}
else
{
pcode = ddl_Plantcode.SelectedItem.Value;
// LoadPlantcode();
// ddl_agentcode.Text = getrouteusingagent;
gridview();
}
}
protected void btn_Ok_Click(object sender, EventArgs e)
{
if (!IsPostBack)
{
ddl_Plantcode.SelectedIndex = ddl_Plantname.SelectedIndex;
pcode = ddl_Plantcode.SelectedItem.Value;
gridview();
// gridview();
}
}
public void gridview()
{
try
{
DateTime dt1 = new DateTime();
DateTime dt2 = new DateTime();
dt1 = DateTime.ParseExact(txt_FromDate.Text, "dd/MM/yyyy", null);
dt2 = DateTime.ParseExact(txt_ToDate.Text, "dd/MM/yyyy", null);
string d1 = dt1.ToString("MM/dd/yyyy");
string d2 = dt2.ToString("MM/dd/yyyy");
string connStr = ConfigurationManager.ConnectionStrings["AMPSConnectionString"].ConnectionString;
using (SqlConnection conn = new SqlConnection(connStr))
{
conn.Open();
// string sqlstr = "SELECT tid,agent_id,convert(varchar,prdate,103) as prdate,sessions,Milk_kg,fat,snf,remarkstatus,remark FROM procurementimport where plant_code='" + pcode + "' and prdate between '" + d1 + "' and '" + d2 + "' and agent_id='" + ddl_agentcode.Text + "' order by prdate,sessions ";
string sqlstr = "SELECT tid,tcnumber as TcNumber ,convert(varchar,Date,103) as Date,Milkkg,fat,snf,Rate,Amount,Ack_milkkg,Ack_fat,Ack_snf,Ack_clr,status FROM Despatchnew where plant_code='" + pcode + "' and Date between '" + d1 + "' and '" + d2 + "' order by Tid ";
// string sqlstr = "SELECT agent_id,convert(varchar,prdate,103) as prdate,sessions,fat FROM procurementimport where plant_code='" + pcode + "' and prdate between '" + d1 + "' and '" + d2 + "' order by Agent_id,prdate,sessions ";
SqlCommand COM = new SqlCommand(sqlstr, conn);
// SqlDataReader DR = COM.ExecuteReader();
DataTable dt = new DataTable();
SqlDataAdapter sqlDa = new SqlDataAdapter(COM);
sqlDa.Fill(dt);
if (dt.Rows.Count > 0)
{
GridView1.DataSource = dt;
GridView1.DataBind();
}
else
{
GridView1.DataSource = null;
GridView1.DataBind();
}
}
}
catch
{
}
}
private void loadsingleplant()
{
try
{
SqlDataReader dr = null;
ddl_Plantcode.Items.Clear();
ddl_Plantname.Items.Clear();
dr = Bllusers.LoadSinglePlantcode(ccode, pcode);
if (dr.HasRows)
{
while (dr.Read())
{
ddl_Plantcode.Items.Add(dr["Plant_Code"].ToString());
ddl_Plantname.Items.Add(dr["Plant_Code"].ToString() + "_" + dr["Plant_Name"].ToString());
}
}
}
catch (Exception ex)
{
WebMsgBox.Show(ex.ToString());
}
}
private void LoadPlantcode()
{
try
{
SqlDataReader dr = null;
ddl_Plantcode.Items.Clear();
ddl_Plantname.Items.Clear();
dr = Bllusers.LoadPlantcode(ccode);
if (dr.HasRows)
{
while (dr.Read())
{
ddl_Plantcode.Items.Add(dr["Plant_Code"].ToString());
ddl_Plantname.Items.Add(dr["Plant_Code"].ToString() + "_" + dr["Plant_Name"].ToString());
}
}
}
catch (Exception ex)
{
WebMsgBox.Show(ex.ToString());
}
}
protected void ddl_Plantname_SelectedIndexChanged(object sender, EventArgs e)
{
if (!IsPostBack)
{
// ddl_agentcode.Items.Clear();
ddl_Plantcode.SelectedIndex = ddl_Plantname.SelectedIndex;
pcode = ddl_Plantcode.SelectedItem.Value;
//gridview();
}
else
{
// ddl_agentcode.Items.Clear();
ddl_Plantcode.SelectedIndex = ddl_Plantname.SelectedIndex;
pcode = ddl_Plantcode.SelectedItem.Value;
//// getagentid();
// gridview();
}
}
protected void ddl_Plantcode_SelectedIndexChanged(object sender, EventArgs e)
{
gridview();
}
protected void GridView1_DataBound(object sender, EventArgs e)
{
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
gridview();
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
gridview();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.Cells[12].Text == "Pending")
{
e.Row.Cells[12].ForeColor = System.Drawing.Color.Red;
}
//else if (e.Row.Cells[0].Text == "Received")
//{
// e.Row.Cells[0].ForeColor = System.Drawing.Color.Green;
//}
}
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
gridview();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
try
{
string connStr = ConfigurationManager.ConnectionStrings["AMPSConnectionString"].ConnectionString;
SqlConnection conn = new SqlConnection(connStr);
int userid = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value.ToString());
GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex];
// Label lblID = (Label)row.FindControl("tid");
// TextBox bid = (TextBox)row.Cells[0].Controls[0];
TextBox ackmilkkg = (TextBox)row.Cells[8].Controls[0];
mokg = Convert.ToDouble(ackmilkkg.Text);
// TextBox routeid1 = (TextBox)row.Cells[1].Controls[0];
// TextBox milknature1 = (TextBox)row.Cells[2].Controls[0];
//foreach (GridViewRow gvr in GridView1.Rows)
//{
// ddate = GridView1.DataKeys[gvr.RowIndex].Values["prdate"].ToString();
//}
// TextBox prdate1 = (TextBox)row.Cells[2].Controls[0];
// TextBox prdate1 = ddate;
// TextBox shift1 = (TextBox)row.Cells[3].Controls[0];
TextBox ackfat = (TextBox)row.Cells[9].Controls[0];
TextBox acksnf = (TextBox)row.Cells[10].Controls[0];
// TextBox ackclr = (TextBox)row.Cells[11].Controls[0];
if (!(string.IsNullOrEmpty(acksnf.Text)))
snf = Convert.ToDouble(acksnf.Text);
if (!(string.IsNullOrEmpty(ackfat.Text)))
fat = Convert.ToDouble(ackfat.Text);
clr = (((snf - 0.36) - (fat * 0.21)) * 4);
//clr = Convert.ToDouble(ackclr.Text);
fatkg = (mokg * fat) / 100;
snfkg = (mokg * snf) / 100;
row.Cells[11].Text = clr.ToString();
string sta = "Received";
// TextBox status = "received".ToString();
// TextBox remark1 = (TextBox)row.Cells[8].Controls[0];
GridView1.EditIndex = -1;
conn.Open();
// getrouteusingagent = agentid1.Text;
// ddl_agentcode.Text = getrouteusingagent;
// ddl_agentcode.Text = getrouteusingagent;
// getrouteid();
SqlCommand cmd = new SqlCommand("update Despatchnew set fat_kg='" + fatkg + "',snf_kg='" + snfkg + "',Ack_milkkg='" + ackmilkkg.Text + "',Ack_fat='" + ackfat.Text + "',Ack_snf='" + acksnf.Text + "',Ack_clr='" + clr + "',status='" + sta + "' where tid='" + userid + "' and plant_code='" + pcode + "'", conn);
cmd.ExecuteNonQuery();
WebMsgBox.Show("Updated Successfully");
gridview();
}
catch
{
WebMsgBox.Show("Please Check updated Data");
}
gridview();
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void txt_ToDate_TextChanged(object sender, EventArgs e)
{
}
protected void txt_FromDate_TextChanged(object sender, EventArgs e)
{
}
}