-
Notifications
You must be signed in to change notification settings - Fork 0
/
addclient.aspx.cs
271 lines (251 loc) · 10.1 KB
/
addclient.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
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;
public partial class addclient : System.Web.UI.Page
{
private const Int16 _DEFAULTPAGESIZE = 10;
Int32 _clientNum;
protected void Page_Load(object sender, EventArgs e)
{
Whitfieldcore _wc = new Whitfieldcore();
if (!Page.IsPostBack)
{
BindState();
BindClientTypes();
BindCities("");
// 1
// Get collection
NameValueCollection n = Request.QueryString;
// 2
// See if any query string exists
if (n.HasKeys())
{
// 3
// Get first key and value
string k = n.GetKey(0);
string v = n.Get(0);
// 4
// Test different keys
if (k == "IsNew")
{
if (v == "Y")
{
_clientNum = _wc.GenerateClientID();
ViewState["ClientNum"] = _clientNum.ToString();
//ddlEstimator.SelectedIndex = ddlEstimator.Items.IndexOf(ddlEstimator.Items.FindByValue(Request.Cookies["UserId"].Value.Trim()));
}
else
{
v = n.Get(1);
ViewState["ClientNum"] = v.ToString();
FetchAndBind(Convert.ToInt32(v));
}
}
hidclient.Value = ViewState["ClientNum"].ToString();
// bind the datagrid for contacts for client
try
{
grdRpResults.PageSize = _DEFAULTPAGESIZE;
DataSet dsGridResults;
dsGridResults = this.Summary_Queue();
this.PopulateDataGrid(dsGridResults);
}
catch (Exception exp)
{
Response.Write(exp.Message.ToString());
}
}
}
}
#region UI Methods
public string ShowEditImage(object ClientID, object ContactID)
{
return "<a ID='ViewNotes' href=\"javascript:ShowEdit('" + ClientID.ToString().Trim() + "','" + ContactID.ToString().Trim() + "');\"" + ">" +
"<img src='" + Page.ResolveUrl("assets/img/edit.gif") + "' align='absmiddle' border='0' ID='ImageCheckBox'/></a>";
}
#endregion
#region Fetch and Bind
public void FetchAndBind(Int32 _clientNumber)
{
Whitfieldcore _wc = new Whitfieldcore();
IDataReader iReader = _wc.GetClientInfo(_clientNumber);
// ' Loop through the DataReader and write out each entry
while (iReader.Read())
{
txtclientname.Text = iReader["Name"] == DBNull.Value ? "" : iReader["Name"].ToString();
String cType = iReader["ClientType"] == DBNull.Value ? "" : iReader["ClientType"].ToString();
ddlClientType.SelectedIndex = ddlClientType.Items.IndexOf(ddlClientType.Items.FindByValue(cType.ToString()));
txtstreet.Text = iReader["Street"] == DBNull.Value ? "" : iReader["Street"].ToString();
String City = iReader["City"] == DBNull.Value ? "" : iReader["City"].ToString();
ddlCity.SelectedIndex = ddlCity.Items.IndexOf(ddlCity.Items.FindByValue(City.ToString()));
String Statecd = iReader["State"] == DBNull.Value ? "" : iReader["State"].ToString();
ddlState.SelectedIndex = ddlState.Items.IndexOf(ddlState.Items.FindByValue(Statecd.ToString()));
txtPhNumber.Text = iReader["Phone"] == DBNull.Value ? "" : iReader["Phone"].ToString();
txtFaxNumber.Text = iReader["Fax"] == DBNull.Value ? "" : iReader["Fax"].ToString();
txtFTP.Text = iReader["Web"] == DBNull.Value ? "" : iReader["Web"].ToString();
txtLogin.Text = iReader["login"] == DBNull.Value ? "" : iReader["login"].ToString();
txtPass.Text = iReader["pw"] == DBNull.Value ? "" : iReader["pw"].ToString();
txtWeb.Text = iReader["Web"] == DBNull.Value ? "" : iReader["Web"].ToString();
txtNotes.Text = iReader["Notes"] == DBNull.Value ? "" : iReader["Notes"].ToString();
}
}
#endregion
private void BindState()
{
DataSet dsGrp = new DataSet();
Whitfieldcore wUser = new Whitfieldcore();
dsGrp = wUser.GetStatelist();
if (dsGrp.Tables[0].Rows.Count > 0)
{
ddlState.DataSource = dsGrp;
ddlState.DataTextField = "StateCD";
ddlState.DataValueField = "StateID";
ddlState.DataBind();
ddlState.Items.Insert(0, common.AddItemToList("Select State", ""));
}
}
private void BindCities(String StateCD)
{
DataSet dsGrp = new DataSet();
Whitfieldcore wUser = new Whitfieldcore();
dsGrp = wUser.GetCityList(StateCD);
if (dsGrp.Tables[0].Rows.Count > 0)
{
ddlCity.DataSource = dsGrp;
ddlCity.DataTextField = "City";
ddlCity.DataValueField = "CityID";
ddlCity.DataBind();
ddlCity.Items.Insert(0, common.AddItemToList("Select City", ""));
}
}
private void BindClientTypes()
{
DataSet dsGrp = new DataSet();
Whitfieldcore wc = new Whitfieldcore();
dsGrp = wc.GetClientTypes();
if (dsGrp.Tables[0].Rows.Count > 0)
{
ddlClientType.DataSource = dsGrp;
ddlClientType.DataTextField = "ClientType";
ddlClientType.DataValueField = "ClientTypeID";
ddlClientType.DataBind();
ddlClientType.Items.Insert(0, common.AddItemToList("Client Types", "0"));
}
}
protected void btnnew_Click(object sender, EventArgs e)
{
Whitfieldcore wc = new Whitfieldcore();
if (Page.IsValid)
{
Boolean IsInsertSuccess = false;
IsInsertSuccess = wc.ManageClients(Convert.ToInt32(ViewState["ClientNum"].ToString()),
txtclientname.Text.Trim(),
Convert.ToInt32(ddlClientType.SelectedItem.Value),
txtstreet.Text.Trim(),
Convert.ToInt32(ddlCity.SelectedItem.Value),
Convert.ToInt32(ddlState.SelectedItem.Value),
txtPhNumber.Text.Trim(),
txtFaxNumber.Text.Trim(),
txtWeb.Text.Trim(),
txtFTP.Text.Trim(),
txtLogin.Text.Trim(),
txtPass.Text.Trim(),
txtNotes.Text.Trim());
if (IsInsertSuccess)
{
lblMsg.Text = "Client is Successfully saved";
}
}
}
#region Datagrid common Functions
public void PageResultGrid(object sender, DataGridPageChangedEventArgs e)
{
DataSet dsGridResults;
grdRpResults.CurrentPageIndex = e.NewPageIndex;
dsGridResults = dsGridResults = this.Summary_Queue();
PopulateDataGrid(dsGridResults);
}
private DataSet Summary_Queue()
{
DataSet dsRpAdvances = new DataSet();
try
{
Whitfieldcore _wc = new Whitfieldcore();
dsRpAdvances = _wc.GetContactsForClient(Convert.ToInt32(ViewState["ClientNum"].ToString()));
}
catch (Exception exp)
{
Response.Write(exp.Message.ToString());
}
return dsRpAdvances;
}
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";
}
}
}
}
private void PopulateDataGrid(DataSet dsGridResults)
{
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();
//Display the results message line
txtSelectionResultsMSG.Text = "Your selection found " + dsGridResults.Tables[0].Rows.Count + " contacts(s). Displaying users " + minResultItemInPage.ToString() + " - " + maxResultItemInPage.ToString() + ".";
}
else
{
txtSelectionResultsMSG.Text = "No Contacts Setup yet.";
grdRpResults.Visible = false;
}
}
catch (Exception exp)
{
Response.Write(exp.Message.ToString());
}
}
#endregion
}