-
Notifications
You must be signed in to change notification settings - Fork 0
/
master_contingency.ascx.cs
199 lines (186 loc) · 6.95 KB
/
master_contingency.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
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 System.Net;
using System.Net.Mail;
using System.Collections.Specialized;
using System.IO;
public partial class master_contingency1 : System.Web.UI.UserControl
{
public Int32 cont_id;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindddlUOM();
BindDDLDefaults();
}
}
public void BindddlUOM()
{
Hashtable hTable = new Hashtable();
hTable.Add("Each", "Each");
hTable.Add("Lump Sum", "Lump Sum");
hTable.Add("Month", "MOnth");
hTable.Add("Week", "Week");
hTable.Add("Day", "Day");
hTable.Add("Hour", "Hour");
ddlUOM.DataSource = hTable;
ddlUOM.DataTextField = "value";
ddlUOM.DataValueField = "key";
ddlUOM.DataBind();
ddlUOM.Items.Insert(0, common.AddItemToList("Select", ""));
}
public void BindDDLDefaults()
{
Hashtable hTable = new Hashtable();
hTable.Add("Yes", "Y");
hTable.Add("No", "N");
ddldefault.DataSource = hTable;
ddldefault.DataTextField = "value";
ddldefault.DataValueField = "key";
ddldefault.DataBind();
}
protected void btnSave_Click(object sender, EventArgs e)
{
try
{
contingency mm = new contingency();
Int32 IsValidInsert = mm.PopulateSubContingency(Convert.ToInt32(ViewState["cont_id"].ToString()), txtdesc.Text.Trim(), ddlUOM.SelectedItem.Value,txtCost.Text.Trim(),ddldefault.SelectedItem.Value);
DataSet dsGridResults = mm.FetchSubContingencyData(Convert.ToInt32(ViewState["cont_id"].ToString()));
PopulateDataGrid(dsGridResults, grd1);
}
catch (Exception)
{
throw;
}
}
public void grd1_EditCommand(object sender, DataGridCommandEventArgs e)
{
contingency _wc = new contingency();
grd1.ShowFooter = false;
grd1.EditItemIndex = Convert.ToInt32(e.Item.ItemIndex);
DataSet dsGridResults = _wc.FetchSubContingencyData(Convert.ToInt32(ViewState["cont_id"].ToString()));
PopulateDataGrid(dsGridResults, grd1);
}
public void grd1_CancelCommand(object sender, DataGridCommandEventArgs e)
{
contingency _wc = new contingency();
grd1.ShowFooter = true;
grd1.EditItemIndex = -1;
DataSet dsGridResults = _wc.FetchSubContingencyData(Convert.ToInt32(ViewState["cont_id"].ToString()));
PopulateDataGrid(dsGridResults, grd1);
}
public void grd1_DeleteCommand(object sender, DataGridCommandEventArgs e)
{
contingency _wc = new contingency();
String DetailId = "";
DetailId = grd1.DataKeys[Convert.ToInt32(e.Item.ItemIndex)].ToString();
Whitfieldcore _dbClass = new Whitfieldcore();
_wc.DeleteSubContingency(Convert.ToInt32(DetailId));
DataSet dsGridResults = _wc.FetchSubContingencyData(Convert.ToInt32(ViewState["cont_id"].ToString()));
PopulateDataGrid(dsGridResults, grd1);
}
public void grd1_UpdateCommand(object sender, DataGridCommandEventArgs e)
{
String DetailId = grd1.DataKeys[Convert.ToInt32(e.Item.ItemIndex)].ToString();
contingency _wc = new contingency();
_wc.UpdatesubContingency(Convert.ToInt32(DetailId), ((TextBox)(e.Item.FindControl("txtdesc"))).Text, ((RadioButtonList)(e.Item.FindControl("chkUOM"))).SelectedItem.Value, ((TextBox)(e.Item.FindControl("txtcost"))).Text, ((RadioButtonList)(e.Item.FindControl("chkis_default"))).SelectedItem.Value);
grd1.EditItemIndex = -1;
grd1.ShowFooter = true;
DataSet dsGridResults = _wc.FetchSubContingencyData(Convert.ToInt32(ViewState["cont_id"].ToString()));
PopulateDataGrid(dsGridResults, grd1);
}
public void LoadDetails(DataSet dsrec)
{
try
{
BindddlUOM();
BindDDLDefaults();
ViewState["cont_id"] = cont_id.ToString();
PopulateDataGrid(dsrec, grd1);
}
catch (Exception Ex)
{
Response.Write("Exception:" + Ex.Message);
}
}
#region DataGrid Functions
private void PopulateDataGrid(DataSet dsGridResults, DataGrid grdRpResults)
{
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 > (grdRpResults.CurrentPageIndex + 1) * grdRpResults.PageSize)
maxResultItemInPage = (grdRpResults.CurrentPageIndex + 1) * grdRpResults.PageSize;
else
maxResultItemInPage = resultCount;
if (maxResultItemInPage - (grdRpResults.PageSize - 1) > 1)
minResultItemInPage = maxResultItemInPage - (grdRpResults.PageSize - 1);
else
minResultItemInPage = 1;
grdRpResults.Visible = true;
grdRpResults.DataSource = tblInstallments;
grdRpResults.DataBind();
}
else
{
grdRpResults.Visible = false;
}
}
catch (Exception exp)
{
Response.Write(exp.Message.ToString());
}
}
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 PageResultGrid1(object sender, DataGridPageChangedEventArgs e)
{
contingency mm = new contingency();
DataSet dsGridResults;
grd1.CurrentPageIndex = e.NewPageIndex;
dsGridResults = mm.FetchContingencyData();
PopulateDataGrid(dsGridResults, grd1);
}
#endregion
}