-
Notifications
You must be signed in to change notification settings - Fork 0
/
master_materials.aspx.cs
312 lines (286 loc) · 10.7 KB
/
master_materials.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Collections.Specialized;
using System.Drawing;
using System.Collections;
using System.Configuration;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
public partial class master_materials : System.Web.UI.Page
{
private const Int16 _DEFAULTPAGESIZE = 25;
protected void Page_Load(object sender, EventArgs e)
{
Whitfieldcore _wc = new Whitfieldcore();
if (!Page.IsPostBack)
{
//BindMaterials();
BindMaterialTypes();
try
{
grdpl1.PageSize = _DEFAULTPAGESIZE;
this.DisplayGrid();
}
catch (Exception exp)
{
Response.Write(exp.Message.ToString());
}
}
}
#region Show Closing Tag
public string ShowClosingTags()
{
return "</td></tr><tr><td colspan=\"8\">";
}
#endregion
protected void btnnew_Click(object sender, EventArgs e)
{
this.DisplayGrid();
}
//DataGrid Functions
private void DisplayGrid()
{
try
{
Whitfieldcore _dbClass = new Whitfieldcore();
DataSet _dsWorkOrders = new DataSet();
_dsWorkOrders = _dbClass.GetAllMaterials(Convert.ToInt32(ddlMatType.SelectedItem.Value));
PopulateDataGrid(_dsWorkOrders, grdpl1);
}
catch (Exception exp)
{
Response.Write(exp.Message.ToString());
}
}
public void PopulateDataGrid(DataSet dsGridResults, DataGrid grdpl1)
{
Int32 resultCount = 0;
if (dsGridResults.Tables.Count > 0)
resultCount = dsGridResults.Tables[0].Rows.Count;
Int32 maxResultItemInPage = 0;
Int32 minResultItemInPage = 0;
try
{
if (resultCount > 0)
{
DataTable tblInstallments = dsGridResults.Tables[0];
//Display results in Grid
if (resultCount > (grdpl1.CurrentPageIndex + 1) * grdpl1.PageSize)
maxResultItemInPage = (grdpl1.CurrentPageIndex + 1) * grdpl1.PageSize;
else
maxResultItemInPage = resultCount;
if (maxResultItemInPage - (grdpl1.PageSize - 1) > 1)
minResultItemInPage = maxResultItemInPage - (grdpl1.PageSize - 1);
else
minResultItemInPage = 1;
grdpl1.Visible = true;
grdpl1.DataSource = tblInstallments;
grdpl1.DataBind();
}
else
{
grdpl1.Visible = false;
}
}
catch (Exception exp)
{
Response.Write(exp.Message.ToString());
}
}
public void grdpl1_EditCommand(object sender, DataGridCommandEventArgs e)
{
grdpl1.ShowFooter = false;
grdpl1.EditItemIndex = Convert.ToInt32(e.Item.ItemIndex);
this.DisplayGrid();
}
public void grdpl1_CancelCommand(object sender, DataGridCommandEventArgs e)
{
grdpl1.ShowFooter = true;
grdpl1.EditItemIndex = -1;
this.DisplayGrid();
}
public void grdpl1_DeleteCommand(object sender, DataGridCommandEventArgs e)
{
String DetailId = "";
DetailId = grdpl1.DataKeys[Convert.ToInt32(e.Item.ItemIndex)].ToString();
Whitfieldcore _dbClass = new Whitfieldcore();
_dbClass.DeleteMaterials(Convert.ToInt32(DetailId));
this.DisplayGrid();
}
public void grdpl1_UpdateCommand(object sender, DataGridCommandEventArgs e)
{
String DetailId = grdpl1.DataKeys[Convert.ToInt32(e.Item.ItemIndex)].ToString();
Whitfieldcore _dbClass = new Whitfieldcore();
_dbClass.UPDATEMasterMaterials(Convert.ToInt32(DetailId), ((TextBox)(e.Item.FindControl("txtReference_Number"))).Text, ((TextBox)(e.Item.FindControl("txtDescription"))).Text, "", "N", ((TextBox)(e.Item.FindControl("txtComments"))).Text);
grdpl1.EditItemIndex = -1;
grdpl1.ShowFooter = true;
this.DisplayGrid();
}
public void PageResultGrid(object sender, DataGridPageChangedEventArgs e)
{
grdpl1.CurrentPageIndex = e.NewPageIndex;
this.DisplayGrid();
}
public void ResultGridItemCreated(object sender, DataGridItemEventArgs e)
{
ListItemType elemType = e.Item.ItemType;
TableCell pager = (TableCell)e.Item.Controls[0];
// Check to see if the item is the Pager Bar
if (elemType == ListItemType.Pager)
{
for (int i = 0; i < pager.Controls.Count; i += 2)
{
Object objControl = pager.Controls[i];
if (objControl is LinkButton)
{
LinkButton linkBtn = (LinkButton)objControl;
linkBtn.Text = " [" + linkBtn.Text + "] ";
}
else //Can only be a label
{
Label linkLabel = (Label)objControl;
linkLabel.Text = "Page " + linkLabel.Text;
linkLabel.CssClass = "Status";
}
}
}
}
public void grdpl1_Itemcommand(Object sender, DataGridCommandEventArgs e)
{
Int32 Material_ID = 0;
DataSet dsExpand = new DataSet();
Whitfieldcore _dbClass = new Whitfieldcore();
switch (e.CommandName)
{
case "Expand":
{
Material_ID = Convert.ToInt32(grdpl1.DataKeys[Convert.ToInt32(e.Item.ItemIndex)]);
Material_ID = Convert.ToInt32(grdpl1.DataKeys[e.Item.ItemIndex]);
dsExpand = _dbClass.GetAllSubMaterials(Material_ID);
PlaceHolder exp = new PlaceHolder();
exp = (System.Web.UI.WebControls.PlaceHolder)e.Item.Cells[6].FindControl("ExpandedContent");
ImageButton img = new ImageButton();
img = (System.Web.UI.WebControls.ImageButton)e.Item.Cells[0].FindControl("btnExpand");
if (dsExpand.Tables[0].Rows.Count > 0)
{
if (img.ImageUrl == "assets/img/Plus.gif")
{
img.ImageUrl = "assets/img/Minus.gif";
exp.Visible = true;
((submaterial)(e.Item.FindControl("DynamicTable1"))).Visible = true;
((submaterial)(e.Item.FindControl("DynamicTable1"))).Material_ID = Material_ID;
((submaterial)(e.Item.FindControl("DynamicTable1"))).FetchSubMaterials(dsExpand);
}
else
{
exp.Visible = false;
((submaterial)(e.Item.FindControl("DynamicTable1"))).Visible = false;
img.ImageUrl = "assets/img/Plus.gif";
}
}
else
{
if (img.ImageUrl == "assets/img/Plus.gif")
{
//((ViewDesignAdmin)(e.Item.FindControl("DynamicTable1"))).Visible = true;
img.ImageUrl = "assets/img/Minus.gif";
exp.Visible = true;
((submaterial)(e.Item.FindControl("DynamicTable1"))).Visible = true;
((submaterial)(e.Item.FindControl("DynamicTable1"))).Material_ID = Material_ID;
((submaterial)(e.Item.FindControl("DynamicTable1"))).FetchSubMaterials(dsExpand);
}
else
{
exp.Visible = false;
((submaterial)(e.Item.FindControl("DynamicTable1"))).Visible = false;
img.ImageUrl = "assets/img/Plus.gif";
}
}
break;
}
default:
{
break;
}
}
}
//DataGrid Funtion Ends
protected void ddlMatType_SelectedIndexChanged(object sender, EventArgs e)
{
DisplayGrid();
}
private void BindMaterialTypes()
{
try
{
Whitfieldcore _dbClass = new Whitfieldcore();
DataSet dsportfolio = new DataSet();
dsportfolio = _dbClass.GetAllMaterialTypes();
if (dsportfolio.Tables[0].Rows.Count > 0)
{
ddlMatType.DataSource = dsportfolio;
ddlMatType.DataTextField = "Mat_type_Desc";
ddlMatType.DataValueField = "Mat_type_id";
ddlMatType.DataBind();
ddlMatType.Items.Insert(0, common.AddItemToList("Fetch All Material Types", "0"));
}
}
catch (Exception ex)
{
HttpResponse objResponse = HttpContext.Current.Response;
objResponse.Write(ex.Message);
}
}
public static void ExportDataSetToExcel(DataSet ds, string filename)
{
try
{
HttpResponse response = HttpContext.Current.Response;
// first let's clean up the response.object
response.Clear();
response.Charset = "";
// set the response mime type for excel
response.ContentType = "application/vnd.ms-excel";
response.AddHeader("Content-Disposition", "attachment;filename=\"" + filename + "\"");
// create a string writer
using (StringWriter sw = new StringWriter())
{
using (HtmlTextWriter htw = new HtmlTextWriter(sw))
{
// instantiate a datagrid
DataGrid dg = new DataGrid();
dg.Font.Size = 9;
dg.DataSource = ds.Tables[0];
dg.DataBind();
dg.RenderControl(htw);
response.Write(sw.ToString());
response.End();
}
}
}
catch (Exception)
{
throw;
}
}
protected void btnexport_Click(object sender, EventArgs e)
{
try
{
Whitfieldcore _dbClass = new Whitfieldcore();
DataSet dsRpAdvances = _dbClass.GetAllMaterials(Convert.ToInt32(ddlMatType.SelectedItem.Value));
ExportDataSetToExcel(dsRpAdvances, "SystemListing.xls");
}
catch (Exception)
{
throw;
}
}
}