/
Clients.aspx.cs
205 lines (184 loc) · 8.88 KB
/
Clients.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
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using PolytexData;
using UniStr;
using PolytexControls;
using PolytexObjects;
public partial class Clients : PolyPage
{
#region Variables
//For Items GridView controls reference
PolytexControls.TextBox TextBoxName;
PolytexControls.DropDownList DropDownListTerritoryId;
PolytexControls.TextBox TextBoxManagerVersion;
int systemUserId;
#endregion
#region Methods
protected void Page_Load(object sender, EventArgs e)
{
ObjectDataSourceTerritory.SelectParameters["territoryId"].DefaultValue = CurrentUser.TerritoryId.ToString();
if (!IsPostBack)
{
ObjectDataSource1.SelectParameters["territoryId"].DefaultValue = CurrentUser.TerritoryId.ToString();
HiddenFieldTerritoryId.Value = CurrentUser.TerritoryId.ToString();
}
}
protected void GridViewOnRowCommand(object sender, GridViewCommandEventArgs e)
{
string commandName = e.CommandName;
GridViewRow gridViewRowData;
switch (commandName)
{
case "Insert":
PolyGridViewUtils.ClearSetRows(GridView1, true, true);
gridViewRowData = GridView1.FooterRow;
Page.Validate("GridEditItem");
if (Page.IsValid)
{
SetInputControls(gridViewRowData);
systemUserId = Manage_Clients.Insert(TextBoxName.Text.Trim(), DropDownListTerritoryId.AspDropDownList.SelectedValue, TextBoxManagerVersion.Text.Trim());
PolyGridViewUtils.ClearSetRows(GridView1, true, true);
PolyGridViewUtils.SetSelectedRow(GridView1, systemUserId);
SetActionMessage(ActionMessage.InsertedSuccessfuly);
}
else
{
SetActionMessage(ActionMessage.InsertFailure);
}
break;
case "UpdateClient":
gridViewRowData = GridView1.Rows[GridView1.EditIndex];
systemUserId = Convert.ToInt32(e.CommandArgument);
Page.Validate("GridEditItem");
if (Page.IsValid)
{
SetInputControls(gridViewRowData);
if (Manage_Clients.Update(systemUserId, TextBoxName.Text, DropDownListTerritoryId.AspDropDownList.SelectedValue,TextBoxManagerVersion.Text))
{
PolyGridViewUtils.SetSelectedRow(GridView1, systemUserId);
SetActionMessage(ActionMessage.UpdatedSuccessfuly);
}
else
{
SetActionMessage(ActionMessage.UpdateFailure);
}
}
else
{
SetActionMessage(ActionMessage.UpdateFailure);
}
break;
case "Enable":
Manage_Clients.Enable(Convert.ToInt32(e.CommandArgument), true);
PolyGridViewUtils.SetSelectedRow(GridView1, e.CommandArgument);
SetActionMessage(ActionMessage.EnabledSuccessfuly);
break;
case "Disable":
Manage_Clients.Disable(Convert.ToInt32(e.CommandArgument), false);
if (CheckBoxIncludeDisabled.Checked)
{
PolyGridViewUtils.SetSelectedRow(GridView1, e.CommandArgument);
}
else
{
PolyGridViewUtils.SetSelectedRow(GridView1, 0);
}
SetActionMessage(ActionMessage.DisabledSuccessfuly);
break;
case "Filter":
gridViewRowData = GridView1.FooterRow;
TextBoxName = (PolytexControls.TextBox)(gridViewRowData.FindControl("TextBoxName"));
DropDownListTerritoryId = (PolytexControls.DropDownList)(gridViewRowData.FindControl("DropDownListTerritory"));
TextBoxManagerVersion = (PolytexControls.TextBox)(gridViewRowData.FindControl("TextBoxManagerVersion"));
ObjectDataSource1.SelectParameters["territoryId"].DefaultValue = Util.ValidateInt(DropDownListTerritoryId.AspDropDownList.SelectedValue, CurrentUser.TerritoryId).ToString();
ObjectDataSource1.SelectParameters["clientName"].DefaultValue = TextBoxName.Text;
ObjectDataSource1.SelectParameters["version"].DefaultValue = TextBoxManagerVersion.Text;
ObjectDataSource1.DataBind();
HiddenFieldTerritoryId.Value = Util.ValidateInt(DropDownListTerritoryId.AspDropDownList.SelectedValue, CurrentUser.TerritoryId).ToString();
HiddenFieldClient.Value = TextBoxName.Text;
HiddenFieldVersion.Value = TextBoxManagerVersion.Text;
break;
case "Clear":
HiddenFieldTerritoryId.Value = CurrentUser.TerritoryId.ToString();
HiddenFieldClient.Value = "";
HiddenFieldVersion.Value = "";
ObjectDataSource1.SelectParameters["territoryId"].DefaultValue = CurrentUser.TerritoryId.ToString();
ObjectDataSource1.SelectParameters["clientName"].DefaultValue = "";
ObjectDataSource1.SelectParameters["version"].DefaultValue = "";
break;
}
}
protected void GridViewOnPreRender(object sender, EventArgs e)
{
int territoryId = Util.ValidateInt(HiddenFieldTerritoryId.Value, CurrentUser.TerritoryId);
GridViewRow gridViewRowData = GridView1.FooterRow;
TextBoxName = (PolytexControls.TextBox)(gridViewRowData.FindControl("TextBoxName"));
DropDownListTerritoryId = (PolytexControls.DropDownList)(gridViewRowData.FindControl("DropDownListTerritory"));
TextBoxManagerVersion = (PolytexControls.TextBox)(gridViewRowData.FindControl("TextBoxManagerVersion"));
TextBoxManagerVersion.Text = HiddenFieldVersion.Value;
TextBoxName.Text = HiddenFieldClient.Value;
if (territoryId > 0)
{
DropDownListTerritoryId.AspDropDownList.SelectedValue = territoryId.ToString();
}
else
{
DropDownListTerritoryId.AspDropDownList.SelectedValue = null;
}
}
//Assigns the right controls to global controls variables
public void SetInputControls(GridViewRow gridViewRowData)
{
TextBoxName = (PolytexControls.TextBox)(gridViewRowData.FindControl("TextBoxName"));
DropDownListTerritoryId = (PolytexControls.DropDownList)(gridViewRowData.FindControl("DropDownListTerritory"));
TextBoxManagerVersion = (PolytexControls.TextBox)(gridViewRowData.FindControl("TextBoxManagerVersion"));
}
protected void CheckBoxIncludeDisabled_CheckedChanged(object sender, EventArgs e)
{
if (CheckBoxIncludeDisabled.Checked)
{
ObjectDataSource1.SelectParameters["includeDisabled"].DefaultValue = "true";
}
else
{
ObjectDataSource1.SelectParameters["includeDisabled"].DefaultValue = "false";
}
PolyGridViewUtils.ClearSetRows(GridView1, true, true);
GridView1.PageIndex = 0;
}
protected void CustomValidatorClientNameUnique(object source, ServerValidateEventArgs args)
{
GridViewRow gridViewRowData = GridView1.Rows[GridView1.EditIndex];
SetInputControls(gridViewRowData);
string TerritoryId = DropDownListTerritoryId.AspDropDownList.SelectedValue.ToString();
if (systemUserId > 0)
{
string clientName = ((PolytexControls.TextBox)(GridView1.Rows[GridView1.EditIndex].FindControl("TextBoxName"))).Text;
args.IsValid = PolyUtils.DbObjectNameIsUniqueByTable(@"""NAME""", "CLIENTS", clientName, "TERRITORY_ID", TerritoryId, systemUserId);
}
else
{
args.IsValid = false;
}
}
protected void CustomValidatorClientNameExists(object source, ServerValidateEventArgs args)
{
string clientName = ((PolytexControls.TextBox)GridView1.FooterRow.Cells[1].FindControl("TextBoxName")).Text;
string TerritoryId = ((PolytexControls.DropDownList)GridView1.FooterRow.Cells[1].FindControl("DropDownListTerritory")).AspDropDownList.SelectedValue;
args.IsValid = PolyUtils.DbObjectNameIsNewByTable(@"""NAME""", "CLIENTS", clientName, "TERRITORY_ID", TerritoryId);
}
protected void CustomImageButtonProperties_OnPreRender(object sender, EventArgs e)
{
PolytexControls.CustomImageButton ImageButtonProperties = (PolytexControls.CustomImageButton)sender;
ImageButtonProperties.OnClientClick = "return EditSiteMenu(" + ImageButtonProperties.CommandArgument + ")";
}
#endregion
}