-
Notifications
You must be signed in to change notification settings - Fork 0
/
Orders.aspx.cs
258 lines (218 loc) · 9.67 KB
/
Orders.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySql.Data.MySqlClient;
namespace RMS3
{
public partial class Orders : System.Web.UI.Page
{
MySqlConnection conn;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
conn = new MySqlConnection(GetConnectionString());
try
{
conn.Open();
String sql="Select DATE_FORMAT(Date_Time,'%d-%M-%Y') from Order_Detail_Store group by Date_Time";
MySqlCommand comm=new MySqlCommand(sql,conn);
MySqlDataReader dr=comm.ExecuteReader();
DropDownList3.DataSource=dr;
DropDownList3.DataTextField="DATE_FORMAT(Date_Time,'%d-%M-%Y')";
DropDownList3.DataBind();
dr.Close();
sql="Select WEEK(Date_Time) from Order_Detail_Store group by Date_Time";
comm.CommandText=sql;
dr=comm.ExecuteReader();
DropDownList1.DataSource=dr;
DropDownList1.DataTextField="WEEK(Date_Time)";
DropDownList1.DataBind();
dr.Close();
sql="Select MONTHNAME(Date_Time) from Order_Detail_Store group by Date_Time";
comm.CommandText=sql;
dr=comm.ExecuteReader();
DropDownList2.DataSource=dr;
DropDownList2.DataTextField="MONTHNAME(Date_Time)";
DropDownList2.DataBind();
dr.Close();
sql="Select QUARTER(Date_Time) from Order_Detail_Store group by Date_Time";
comm.CommandText=sql;
dr=comm.ExecuteReader();
DropDownList4.DataSource=dr;
DropDownList4.DataTextField="QUARTER(Date_Time)";
DropDownList4.DataBind();
dr.Close();
sql="Select DATE_FORMAT(NOW(),'%d-%M-%Y'),WEEK(NOW()),MONTHNAME(NOW()),QUARTER(NOW())";
comm.CommandText=sql;
dr=comm.ExecuteReader();
dr.Read();
DropDownList3.SelectedValue=dr.GetValue(0).ToString();
DropDownList1.SelectedValue=dr.GetValue(1).ToString();
DropDownList2.SelectedValue=dr.GetValue(2).ToString();
DropDownList4.SelectedValue=dr.GetValue(3).ToString();
dr.Close();
comm.CommandText = "Select Order_ID from Order_Detail_Store where DATE(DateTime) > DATE_ADD(NOW(),INTERVAL 3 DAY) and Order_Received='Pending'";
dr = comm.ExecuteReader();
dr.Read();
String oid1 = dr.GetValue(0).ToString();
dr.Close();
comm.CommandText = "Select count(*) from Alert_Details";
dr = comm.ExecuteReader();
dr.Read();
String aid = "AR" + (dr.GetInt32(0) + 1);
dr.Close();
comm.CommandText = "Insert into Alert_Details values('"+aid+"',NOW(),'Order Not Recieved','Delay in Recieving Order ID:"+oid1+" ','Check Status of Order','','unread')";
comm.ExecuteNonQuery();
}
catch (Exception ex)
{ Response.Write(ex.Message); }
finally { conn.Close(); }
}
}
protected void View_Click(object sender, EventArgs e)
{
conn=new MySqlConnection(GetConnectionString());
String orderid=TextBox8.Text;
try
{
conn.Open();
MySqlCommand comm = new MySqlCommand("Select Order_ID,Amount,Quantity,Date_Time from Order_Detail_Store where Order_ID='" + orderid + "'", conn);
MySqlDataReader dr1 = comm.ExecuteReader();
OrderStatus1.DataSource = dr1;
OrderStatus1.DataBind();
dr1.Close();
comm.CommandText = "Select Order_Made,Order_Ready,Order_Dispatch,Order_Received from Order_Detail_Store where Order_ID='" + orderid + "'";
dr1 = comm.ExecuteReader();
OrderStatus2.DataSource = dr1;
OrderStatus2.DataBind();
dr1.Close();
comm.CommandText = "Select p.Product_ID,p.Company_Name,p.Product_Name,o.Quantity,o.Amount from Master_Products p, Order_Product_Store o where o.Product_ID = p.Product_ID";
dr1 = comm.ExecuteReader();
OrderProductsGrid.DataSource = dr1;
OrderProductsGrid.DataBind();
dr1.Close();
}
catch (Exception ex)
{ Response.Write(ex.Message); }
finally { conn.Close(); }
TextBox8.Text = "";
}
public static string GetConnectionString()
{
string connStr = String.Format("server={0};user id={1}; password={2};" +
"database=footpri8_RMS2; pooling=true", "66.147.244.153",
"footpri8", "Yhu#56gj6!");
return connStr;
}
protected void Confirm_Click(object sender, EventArgs e)
{
conn = new MySqlConnection(GetConnectionString());
String orderid = TextBox7.Text;
List<String> ProductID = new List<String>();
List<int> Quantity = new List<int>();
try
{
conn.Open();
// MySqlCommand comm=new MySqlCommand("Update Order_Detail_Store set Order_Received='Completed' where Order_ID='"+orderid+"'",conn);
MySqlCommand comm=new MySqlCommand("Select Order_Received from Order_Detail_Store where Order_ID='"+orderid+"'",conn);
MySqlDataReader dr=comm.ExecuteReader();
dr.Read();
String flag=dr.GetValue(0).ToString();
dr.Close();
if(flag.Equals("Pending"))
{
comm.CommandText="Update Order_Detail_Store set Order_Received='Completed' where Order_ID='"+orderid+"'";
comm.ExecuteNonQuery();
comm.CommandText = "Update Order_Detail_Store_Central set Order_Received='Completed' where Order_ID='" + orderid + "'";
comm.ExecuteNonQuery();
comm.CommandText = "Select Product_ID,Quantity from Order_Product_Store where Order_ID='"+orderid+"'";
MySqlDataReader dr1 = comm.ExecuteReader();
while (dr1.Read())
{
ProductID.Add(dr1.GetValue(0).ToString());
Quantity.Add(int.Parse(dr1.GetValue(1).ToString()));
}
dr1.Close();
int i=0;
foreach (String pid in ProductID)
{
int quant = Quantity.ElementAt(i);
i++;
comm.CommandText = "Update Current_Store_Products set Stock=Stock+" + quant + " where Product_ID='" + pid + "'";
comm.ExecuteNonQuery();
}
}
}
catch (Exception ex)
{ Response.Write(ex.Message); }
finally { conn.Close(); }
TextBox7.Text="";
}
protected void SearchOrders_Click(object sender, EventArgs e)
{
String timeperiod = RadioButtonList1.SelectedValue.ToString();
String status = RadioButtonList3.SelectedValue.ToString();
String sql="";
String sql2 = "";
conn = new MySqlConnection(GetConnectionString());
if (timeperiod.Equals("By Day"))
{
String temp = DropDownList3.SelectedValue.ToString();
sql = "Select Order_ID,Amount,Quantity,Date_Time,Order_Received from Order_Detail_Store where DATE_FORMAT(Date_Time,'%d-%M-%Y') like '" + temp + "'";
}
if (timeperiod.Equals("By Week"))
{
String temp = DropDownList1.SelectedValue.ToString();
sql = "Select Order_ID,Amount,Quantity,Date_Time,Order_Received from Order_Detail_Store where WEEK(Date_Time) = " + temp + "";
}
if (timeperiod.Equals("By Month"))
{
String temp = DropDownList2.SelectedValue.ToString();
sql = "Select Order_ID,Amount,Quantity,Date_Time,Order_Received from Order_Detail_Store where MONTHNAME(Date_Time) = '" + temp + "'";
}
if (timeperiod.Equals("By Quarter"))
{
String temp = DropDownList4.SelectedValue.ToString();
sql = "Select Order_ID,Amount,Quantity,Date_Time,Order_Received from Order_Detail_Store where QUARTER(Date_Time) = " + temp + "";
}
if (timeperiod.Equals("Custom Date"))
{
String date1 = TextBox5.Text;
String date2 = TextBox6.Text;
sql = "Select Order_ID,Amount,Quantity,Date_Time,Order_Received from Order_Detail_Store where DATE(Date_Time) BETWEEN '"+date1+"' AND '"+date2+"'";
}
if(status.Equals("") || status.Equals("All"))
{
sql2="";
}
if (status.Equals("Received"))
{
sql2 = " and Order_Received='Completed'";
}
if (status.Equals("Pending"))
{
sql2 = " and Order_Received='Pending'";
}
Response.Write(sql + sql2);
try
{
conn.Open();
MySqlCommand comm = new MySqlCommand(sql + sql2, conn);
MySqlDataReader dr1 = comm.ExecuteReader();
OrdersGrid.DataSource = dr1;
OrdersGrid.DataBind();
dr1.Close();
}
catch (Exception ex)
{ Response.Write(ex.Message); }
finally { conn.Close(); }
}
protected void TextBox5_TextChanged(object sender, EventArgs e)
{
}
}
}