/
_List.ascx.cs
465 lines (402 loc) · 19.1 KB
/
_List.ascx.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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
using AceSoft.RetailPlus.Data;
using AceSoft.RetailPlus.Security;
namespace AceSoft.RetailPlus.Inventory
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
public partial class __List : System.Web.UI.UserControl
{
protected PagedDataSource PageData = new PagedDataSource();
#region Web Form Methods
protected void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
if (Visible)
{
ManageSecurity();
LoadOptions();
LoadList();
cmdDelete.Attributes.Add("onClick", "return confirm_delete();");
imgDelete.Attributes.Add("onClick", "return confirm_delete();");
}
}
#endregion
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.imgAdd.Click += new System.Web.UI.ImageClickEventHandler(this.imgAdd_Click);
this.imgDelete.Click += new System.Web.UI.ImageClickEventHandler(this.imgDelete_Click);
this.idEdit.Click += new System.Web.UI.ImageClickEventHandler(this.idEdit_Click);
}
#endregion
#region Web Control Methods
protected void imgAdd_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
string stParam = "?task=" + Common.Encrypt("add",Session.SessionID);
Response.Redirect("/RetailPlus/MasterFiles/_Product/Default.aspx" + stParam);
}
protected void cmdAdd_Click(object sender, System.EventArgs e)
{
string stParam = "?task=" + Common.Encrypt("add",Session.SessionID);
Response.Redirect("/RetailPlus/MasterFiles/_Product/Default.aspx" + stParam);
}
protected void lstItem_ItemDataBound(object sender, DataListItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DataRowView dr = (DataRowView) e.Item.DataItem;
HtmlInputCheckBox chkList = (HtmlInputCheckBox) e.Item.FindControl("chkList");
chkList.Value = dr[ProductColumnNames.ProductID].ToString();
HyperLink lnkBarcode = (HyperLink)e.Item.FindControl("lnkBarcode");
lnkBarcode.Text = dr[ProductColumnNames.BarCode].ToString();
lnkBarcode.NavigateUrl = Constants.ROOT_DIRECTORY + "/MasterFiles/_Product/Default.aspx?task=" + Common.Encrypt("det", Session.SessionID) + "&id=" + Common.Encrypt(dr[ProductColumnNames.ProductID].ToString(), Session.SessionID);
HyperLink lnkProductCode = (HyperLink)e.Item.FindControl("lnkProductCode");
lnkProductCode.Text = dr[ProductColumnNames.ProductCode].ToString();
if (!string.IsNullOrEmpty(dr["MatrixDescription"].ToString())) {
lnkProductCode.Text += " - " + dr["MatrixDescription"].ToString();
}
lnkProductCode.NavigateUrl = Constants.ROOT_DIRECTORY + "/MasterFiles/_Product/Default.aspx?task=" + Common.Encrypt("det", Session.SessionID) + "&id=" + Common.Encrypt(dr[ProductColumnNames.ProductID].ToString(), Session.SessionID);
Label lblGroup = (Label)e.Item.FindControl("lblGroup");
lblGroup.Text = dr[ProductColumnNames.ProductGroupCode].ToString() + " / " + dr[ProductColumnNames.ProductSubGroupCode].ToString();
Label lblQuantity = (Label)e.Item.FindControl("lblQuantity");
// lblQuantity.Text = Convert.ToDecimal(dr[ProductColumnNames.MainQuantity].ToString()).ToString("#,##0.#0") + " " + dr[ProductColumnNames.BaseUnitCode];
lblQuantity.Text = dr[ProductColumnNames.ConvertedQuantity].ToString();
Label lblMinThreshold = (Label) e.Item.FindControl("lblMinThreshold");
lblMinThreshold.Text = Convert.ToDecimal(dr[ProductColumnNames.MinThreshold].ToString()).ToString("#,##0.#0");
Label lblMaxThreshold = (Label) e.Item.FindControl("lblMaxThreshold");
lblMaxThreshold.Text = Convert.ToDecimal(dr[ProductColumnNames.MaxThreshold].ToString()).ToString("#,##0.#0");
if (cboBranch.SelectedItem.Value == Constants.ZERO_STRING &&
(cboContact.SelectedItem.Value != Constants.ZERO_STRING || cboProductGroup.SelectedItem.Value != Constants.ZERO_STRING || cboSubGroup.SelectedItem.Value != Constants.ZERO_STRING))
{
ProductInventories clsProduct = new ProductInventories();
System.Data.DataTable dt = clsProduct.ListAsDataTable(ProductID: long.Parse(dr[ProductColumnNames.ProductID].ToString()), MatrixID: long.Parse(dr["MatrixID"].ToString()), isSummary: 0);
clsProduct.CommitAndDispose();
DataList lstBranchInventory = (DataList)e.Item.FindControl("lstBranchInventory");
lstBranchInventory.Visible = true;
lstBranchInventory.DataSource = dt.DefaultView;
lstBranchInventory.DataBind();
}
}
}
protected void lstItem_ItemCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)
{
HtmlInputCheckBox chkList = null;
string stParam = null;
chkList = (HtmlInputCheckBox) e.Item.FindControl("chkList");
stParam = "?task=" + Common.Encrypt("list",Session.SessionID) +
"&prodid=" + Common.Encrypt(chkList.Value,Session.SessionID);
switch(e.CommandName)
{
case "imgVariationsMatrixClick":
Response.Redirect("/RetailPlus/Inventory/_VariationsMatrix/Default.aspx" + stParam);
break;
}
}
protected void lstBranchInventory_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DataRowView dr = (DataRowView)e.Item.DataItem;
HyperLink lnkBranchCode = (HyperLink)e.Item.FindControl("lnkBranchCode");
lnkBranchCode.Text = dr[BranchInventoryColumnNames.BranchCode].ToString();
lnkBranchCode.NavigateUrl = Constants.ROOT_DIRECTORY + "/Inventory/_Branch/Default.aspx?task=" + Common.Encrypt("det", Session.SessionID) + "&id=" + Common.Encrypt(dr[BranchInventoryColumnNames.BranchID].ToString(), Session.SessionID);
Label lblQuantity = (Label)e.Item.FindControl("lblQuantity");
lblQuantity.Text = dr[BranchInventoryColumnNames.ConvertedQuantity].ToString();
}
}
protected void imgDelete_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
if (Delete())
LoadList();
}
protected void cmdDelete_Click(object sender, System.EventArgs e)
{
if (Delete())
LoadList();
}
protected void cboProductGroup_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
ProductSubGroupColumns clsProductSubGroupColumns = new ProductSubGroupColumns();
clsProductSubGroupColumns.ProductSubGroupCode = true;
clsProductSubGroupColumns.ProductSubGroupName = true;
ProductSubGroupDetails clsSearchKeys = new ProductSubGroupDetails();
clsSearchKeys.ProductGroupID = long.Parse(cboProductGroup.SelectedItem.Value);
clsSearchKeys.ProductSubGroupCode = txtSubGroupCode.Text;
ProductSubGroup clsSubGroup = new ProductSubGroup();
cboSubGroup.DataTextField = "ProductSubGroupName";
cboSubGroup.DataValueField = "ProductSubGroupID";
cboSubGroup.DataSource = clsSubGroup.ListAsDataTable(clsProductSubGroupColumns, clsSearchKeys, 0);
cboSubGroup.DataBind();
cboSubGroup.Items.Insert(0, new ListItem(Constants.ALL, Constants.ZERO_STRING));
if (cboSubGroup.Items.Count > 1 && txtSubGroupCode.Text.Trim() != string.Empty) cboSubGroup.SelectedIndex = 1; else cboSubGroup.SelectedIndex = 0;
clsSubGroup.CommitAndDispose();
}
catch { }
}
protected void imgSubGroupCodeSearch_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
cboProductGroup_SelectedIndexChanged(null, null);
}
protected void imgProductGroupCodeSearch_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
ProductGroup clsProductGroup = new ProductGroup();
cboProductGroup.DataTextField = "ProductGroupName";
cboProductGroup.DataValueField = "ProductGroupID";
cboProductGroup.DataSource = clsProductGroup.ListAsDataTable(txtProductGroupCode.Text).DefaultView;
cboProductGroup.DataBind();
cboProductGroup.Items.Insert(0, new ListItem(Constants.ALL, Constants.ZERO_STRING));
if (cboProductGroup.Items.Count > 1 && txtProductGroupCode.Text.Trim() != string.Empty) cboProductGroup.SelectedIndex = 1; else cboProductGroup.SelectedIndex = 0;
clsProductGroup.CommitAndDispose();
cboProductGroup_SelectedIndexChanged(null, System.EventArgs.Empty);
}
protected void imgContactCodeSearch_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
Contacts clsContact = new Contacts();
cboContact.DataTextField = "ContactName";
cboContact.DataValueField = "ContactID";
cboContact.DataSource = clsContact.SuppliersAsDataTable(txtContactCode.Text, 100).DefaultView;
cboContact.DataBind();
cboContact.Items.Insert(0, new ListItem(Constants.ALL, Constants.ZERO_STRING));
if (cboContact.Items.Count > 1 && txtContactCode.Text.Trim() != string.Empty) cboContact.SelectedIndex = 1; else cboContact.SelectedIndex = 0;
clsContact.CommitAndDispose();
}
private void idEdit_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
Update();
}
protected void cmdEdit_Click(object sender, System.EventArgs e)
{
Update();
}
protected void cboCurrentPage_SelectedIndexChanged(object sender, System.EventArgs e)
{
LoadList();
}
private void imgPrice_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
UpdateProductPrice();
}
protected void cmdProductPriceUpdate_Click(object sender, System.EventArgs e)
{
UpdateProductPrice();
}
protected void cmdSearch_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
LoadList();
}
#endregion
#region Private methods
private bool Delete()
{
bool boRetValue = false;
string stIDs = "";
foreach(DataListItem item in lstItem.Items)
{
HtmlInputCheckBox chkList = (HtmlInputCheckBox) item.FindControl("chkList");
if (chkList!=null)
{
if (chkList.Checked == true)
{
stIDs += chkList.Value + ",";
boRetValue = true;
}
}
}
if (boRetValue)
{
Products clsProduct = new Products();
clsProduct.Delete(stIDs.Substring(0, stIDs.Length - 1), Convert.ToString(Session["Name"]));
clsProduct.CommitAndDispose();
}
return boRetValue;
}
private void Update()
{
if (isChkListSingle() == true)
{
string stID = GetFirstID();
if (stID!=null)
{
string stParam = "?task=" + Common.Encrypt("edit",Session.SessionID) + "&id=" + Common.Encrypt(stID,Session.SessionID);
Response.Redirect("/RetailPlus/MasterFiles/_Product/Default.aspx" + stParam);
}
}
else
{
string stScript = "<Script>";
stScript += "window.alert('Cannot update more than one record. Please select at least one record to update.')";
stScript += "</Script>";
Response.Write(stScript);
}
}
private string GetFirstID()
{
foreach(DataListItem item in lstItem.Items)
{
HtmlInputCheckBox chkList = (HtmlInputCheckBox) item.FindControl("chkList");
if (chkList!=null)
{
if (chkList.Checked == true)
{
return chkList.Value;
}
}
}
return null;
}
private bool isChkListSingle()
{
bool boChkListSingle = true;
int iCount = 0;
foreach(DataListItem item in lstItem.Items)
{
HtmlInputCheckBox chkList = (HtmlInputCheckBox) item.FindControl("chkList");
if (chkList!=null)
{
if (chkList.Checked == true)
{
iCount += 1;
if (iCount >= 2)
{ return false; }
}
}
}
return boChkListSingle;
}
private void UpdateProductPrice()
{
if (isChkListSingle() == true)
{
string stID = GetFirstID();
if (stID!=null)
{
string stParam = "?task=" + Common.Encrypt("ProductPrice",Session.SessionID) + "&id=" + Common.Encrypt(stID,Session.SessionID);
Response.Redirect("/RetailPlus/MasterFiles/_Product/Default.aspx" + stParam);
}
}
else
{
string stScript = "<Script>";
stScript += "window.alert('Cannot update more than one record. Please select at least one record to update.')";
stScript += "</Script>";
Response.Write(stScript);
}
}
private void ManageSecurity()
{
Int64 UID = Convert.ToInt64(Session["UID"]);
AccessRights clsAccessRights = new AccessRights();
AccessRightsDetails clsDetails = new AccessRightsDetails();
clsDetails = clsAccessRights.Details(UID, (int)AccessTypes.AccessGroups);
imgAdd.Visible = clsDetails.Write;
cmdAdd.Visible = clsDetails.Write;
imgDelete.Visible = clsDetails.Write;
cmdDelete.Visible = clsDetails.Write;
cmdEdit.Visible = clsDetails.Write;
idEdit.Visible = clsDetails.Write;
lblSeparator1.Visible = clsDetails.Write;
lblSeparator2.Visible = clsDetails.Write;
clsAccessRights.CommitAndDispose();
}
private void LoadOptions()
{
txtExpiryDate.Text = DateTime.Now.ToString("yyyy-MM-dd");
Branch clsBranch = new Branch();
clsBranch.GetConnection();
Int64 UID = Convert.ToInt64(Session["UID"]);
cboBranch.DataTextField = "BranchCode";
cboBranch.DataValueField = "BranchID";
cboBranch.DataSource = clsBranch.ListAsDataTable().DefaultView;
cboBranch.DataBind();
cboBranch.Items.Insert(0, new ListItem(Constants.ALL, Constants.ZERO_STRING));
cboBranch.SelectedIndex = 0;
Contacts clsContact = new Contacts(clsBranch.Connection, clsBranch.Transaction);
cboContact.DataTextField = "ContactName";
cboContact.DataValueField = "ContactID";
cboContact.DataSource = clsContact.SuppliersAsDataTable(txtContactCode.Text, 100).DefaultView;
cboContact.DataBind();
cboContact.Items.Insert(0, new ListItem(Constants.ALL, Constants.ZERO_STRING));
cboContact.SelectedIndex = 0;
ProductGroup clsProductGroup = new ProductGroup(clsBranch.Connection, clsBranch.Transaction);
cboProductGroup.DataTextField = "ProductGroupName";
cboProductGroup.DataValueField = "ProductGroupID";
cboProductGroup.DataSource = clsProductGroup.ListAsDataTable(txtProductGroupCode.Text).DefaultView;
cboProductGroup.DataBind();
cboProductGroup.Items.Insert(0, new ListItem(Constants.ALL, Constants.ZERO_STRING));
cboProductGroup.SelectedIndex = 0;
clsBranch.CommitAndDispose();
cboProductGroup_SelectedIndexChanged(null, System.EventArgs.Empty);
}
private void LoadList()
{
string SortField = "ProductDesc";
if (Request.QueryString["sortfield"] != null)
{ SortField = Common.Decrypt(Request.QueryString["sortfield"].ToString(), Session.SessionID); }
SortOption sortoption = SortOption.Ascending;
if (Request.QueryString["sortoption"] != null)
{ sortoption = (SortOption)Enum.Parse(typeof(SortOption), Common.Decrypt(Request.QueryString["sortoption"], Session.SessionID), true); }
string stSearchKey = string.Empty;
if (Request.QueryString["Search"] != null)
{ stSearchKey = Server.UrlDecode(Common.Decrypt((string)Request.QueryString["search"], Session.SessionID)); }
else if (Session["Search"] != null)
{ stSearchKey = Server.UrlDecode(Common.Decrypt(Session["Search"].ToString(), Session.SessionID)); }
try { Session.Remove("Search"); }
catch { }
if (stSearchKey == null) { stSearchKey = string.Empty; }
else if (stSearchKey != string.Empty) { Session.Add("Search", Common.Encrypt(stSearchKey, Session.SessionID)); }
string strProductCode = txtProductCode.Text;
int intBranchID = int.Parse(cboBranch.SelectedItem.Value);
long lngSupplierID = long.Parse(cboContact.SelectedItem.Value);
long lngProductGroupID = long.Parse(cboProductGroup.SelectedItem.Value);
long lngProductSubGroupID = long.Parse(cboSubGroup.SelectedItem.Value);
ProductInventories clsProduct = new ProductInventories();
System.Data.DataTable dt = clsProduct.ListAsDataTable(BranchID: intBranchID, BarCode: stSearchKey, ProductCode: strProductCode, ProductGroupID: lngProductGroupID, ProductSubGroupID: lngProductSubGroupID, SupplierID: lngSupplierID, Limit: 100, SortField: SortField, SortOrder: SortOption.Ascending);
clsProduct.CommitAndDispose();
PageData.DataSource = dt.DefaultView;
int iPageSize = Convert.ToInt16(Session["PageSize"]);
PageData.AllowPaging = true;
PageData.PageSize = iPageSize;
try
{
PageData.CurrentPageIndex = Convert.ToInt16(cboCurrentPage.SelectedItem.Value) - 1;
lstItem.DataSource = PageData;
lstItem.DataBind();
}
catch
{
PageData.CurrentPageIndex = 1;
lstItem.DataSource = PageData;
lstItem.DataBind();
}
cboCurrentPage.Items.Clear();
for (int i = 0; i < PageData.PageCount; i++)
{
int iValue = i + 1;
cboCurrentPage.Items.Add(new ListItem(iValue.ToString(), iValue.ToString()));
if (PageData.CurrentPageIndex == i)
{ cboCurrentPage.Items[i].Selected = true; }
else
{ cboCurrentPage.Items[i].Selected = false; }
}
lblDataCount.Text = " of " + " " + PageData.PageCount;
}
#endregion
}
}