Skip to content

Commit 0c32c47

Browse files
committed
#86 WebUI - Sorting added to Objects and Object_Types grids. CLOSE #86
1 parent 36ee3b6 commit 0c32c47

4 files changed

Lines changed: 470 additions & 395 deletions

File tree

UI/Web/objects.aspx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,19 @@
6767
<div class="span8">
6868
<div ID="ObjPanel">
6969
<div class="row-fluid" ID="ObjGrid" style="overflow: auto; max-height:670px;" onscroll="SetDivPosition()">
70-
<asp:GridView runat="server" ID="gvObjects"
70+
<asp:GridView runat="server" ID="gvObjects" AllowSorting="True" OnSorting="gvObjects_OnSorting"
7171
AutoGenerateColumns="False"
7272
GridLines="None"
7373
CssClass="mGrid"
7474
AlternatingRowStyle-CssClass="alt" OnRowDataBound="gvObjects_RowDataBound" DataKeyNames="object_name" ShowHeaderWhenEmpty="true">
7575
<AlternatingRowStyle CssClass="alt"></AlternatingRowStyle>
7676
<Columns>
77-
<asp:BoundField DataField="container_name" HeaderText="Container" />
78-
<asp:BoundField DataField="object_name" HeaderText="Object" />
79-
<asp:BoundField DataField="object_type" HeaderText="Type" />
80-
<asp:BoundField DataField="state_label" HeaderText="State" />
81-
<asp:BoundField DataField="last_updated" HeaderText="Updated" ItemStyle-Width="10em" />
82-
<asp:BoundField DataField="address" HeaderText="Address" />
77+
<asp:BoundField DataField="container_name" HeaderText="Container" SortExpression="container_name"/>
78+
<asp:BoundField DataField="object_name" HeaderText="Object" SortExpression="object_name" />
79+
<asp:BoundField DataField="object_type" HeaderText="Type" SortExpression="object_type" />
80+
<asp:BoundField DataField="state_label" HeaderText="State" SortExpression="state_label" />
81+
<asp:BoundField DataField="last_updated" HeaderText="Updated" ItemStyle-Width="10em" SortExpression="last_updated" />
82+
<asp:BoundField DataField="address" HeaderText="Address" SortExpression="address" />
8383
</Columns>
8484
</asp:GridView>
8585
</div>
@@ -286,6 +286,7 @@
286286
</div>
287287

288288
<asp:Label runat="server" ID="hdnSelectedRow" Visible="false"></asp:Label>
289+
<asp:Label runat="server" ID="hdnLastRow" Visible="false"></asp:Label>
289290
<asp:Label runat="server" ID="hdnSelectedObjectName" Visible="false"></asp:Label>
290291
<asp:Label runat="server" ID="hdnSelectedPropRow" Visible="false"></asp:Label>
291292
<asp:Label runat="server" ID="hdnSelectedPropName" Visible="false"></asp:Label>

UI/Web/objects.aspx.cs

Lines changed: 56 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
public partial class home : System.Web.UI.Page
1111
{
12-
//OSAELog
1312
private OSAE.General.OSAELog Log = new OSAE.General.OSAELog();
1413

1514
public void RaisePostBackEvent(string eventArgument)
@@ -19,6 +18,7 @@ public void RaisePostBackEvent(string eventArgument)
1918
if (args[0] == "gvObjects")
2019
{
2120
alert.Visible = false;
21+
hdnLastRow.Text = hdnSelectedRow.Text;
2222
hdnSelectedRow.Text = args[1];
2323
panelEditForm.Visible = true;
2424
btnUpdate.Visible = true;
@@ -56,6 +56,7 @@ public void RaisePostBackEvent(string eventArgument)
5656
ddlPropValue.Items.Add(new ListItem("FALSE", "FALSE"));
5757
if (!String.IsNullOrEmpty(gvProperties.DataKeys[Int32.Parse(hdnSelectedPropRow.Text)]["property_value"].ToString()) && ddlPropValue.Items.FindByValue(gvProperties.DataKeys[Int32.Parse(hdnSelectedPropRow.Text)]["property_value"].ToString()) != null)
5858
ddlPropValue.SelectedValue = gvProperties.DataKeys[Int32.Parse(hdnSelectedPropRow.Text)]["property_value"].ToString();
59+
5960
txtPropValue.Visible = false;
6061
btnPropSave.Visible = true;
6162
lblPropName.Visible = true;
@@ -76,6 +77,7 @@ public void RaisePostBackEvent(string eventArgument)
7677
}
7778
if(!string.IsNullOrEmpty(gvProperties.DataKeys[Int32.Parse(hdnSelectedPropRow.Text)]["property_value"].ToString()) && ddlPropValue.Items.FindByValue(gvProperties.DataKeys[Int32.Parse(hdnSelectedPropRow.Text)]["property_value"].ToString()) != null)
7879
ddlPropValue.SelectedValue = gvProperties.DataKeys[Int32.Parse(hdnSelectedPropRow.Text)]["property_value"].ToString();
80+
7981
txtPropValue.Visible = false;
8082
ddlPropValue.Visible = true;
8183
}
@@ -90,41 +92,51 @@ public void RaisePostBackEvent(string eventArgument)
9092
lblPropName.Visible = true;
9193
btnEditPropList.Visible = false;
9294
}
93-
9495
}
9596
}
9697

9798
protected void Page_Load(object sender, EventArgs e)
9899
{
99-
gvObjects.DataSource = OSAESql.RunSQL("SELECT object_id, container_name, object_name, object_type, state_label, state_name, DATE_FORMAT(last_updated,'%m/%d %h:%i:%s %p') as last_updated, address FROM osae_v_object order by container_name, object_name");
100+
if (!IsPostBack)
101+
{
102+
ViewState["sortOrder"] = "";
103+
bindGridView("","");
104+
}
105+
}
106+
107+
public void bindGridView(string sortExp,string sortDir)
108+
{
109+
DataSet myDataSet = OSAESql.RunSQL("SELECT object_id, container_name, object_name, object_type, state_label, state_name, DATE_FORMAT(last_updated,'%m/%d %h:%i:%s %p') as last_updated, address FROM osae_v_object order by container_name, object_name");
110+
DataView myDataView = new DataView();
111+
myDataView = myDataSet.Tables[0].DefaultView;
112+
113+
if (sortExp != string.Empty)
114+
myDataView.Sort = string.Format("{0} {1}", sortExp, sortDir);
115+
116+
gvObjects.DataSource = myDataView;
100117
gvObjects.DataBind();
101-
if (!this.IsPostBack)
102-
{
103-
loadDDLs();
104-
}
118+
if (!this.IsPostBack) loadDDLs();
105119

106-
if (hdnSelectedPropRow.Text != "")
107-
{
108-
loadProperties();
109-
}
120+
if (hdnSelectedPropRow.Text != "") loadProperties();
110121
}
111122

112123
protected void Page_PreRender(object sender, EventArgs e)
113124
{
125+
if (hdnLastRow.Text != "")
126+
gvObjects.Rows[Int32.Parse(hdnLastRow.Text)].Attributes.Add("onmouseout", "this.style.background='none';");
127+
114128
if (hdnSelectedRow.Text != "")
115-
{
116129
gvObjects.Rows[Int32.Parse(hdnSelectedRow.Text)].Attributes.Remove("onmouseout");
117-
gvObjects.Rows[Int32.Parse(hdnSelectedRow.Text)].Style.Add("background", "lightblue");
118-
}
130+
119131
if (hdnSelectedPropRow.Text != "")
120132
{
121133
gvProperties.Rows[Int32.Parse(hdnSelectedPropRow.Text)].Attributes.Remove("onmouseout");
122134
gvProperties.Rows[Int32.Parse(hdnSelectedPropRow.Text)].Style.Add("background", "lightblue");
123135
}
136+
124137
if (hdnSelectedObjectName.Text != "")
125-
{
126138
txtExportScript.Text = OSAEObjectManager.ObjectExport(hdnSelectedObjectName.Text);
127-
}
139+
128140
hdnEditingPropList.Value = hdnEditingPropList.Value;
129141
}
130142

@@ -139,9 +151,30 @@ protected void gvObjects_RowDataBound(object sender, System.Web.UI.WebControls.G
139151
e.Row.Attributes.Add("onmouseout", "this.style.background='none';");
140152
e.Row.Attributes.Add("onclick", ClientScript.GetPostBackClientHyperlink(this, "gvObjects_" + e.Row.RowIndex.ToString()));
141153
}
154+
}
142155

156+
protected void gvObjects_OnSorting(object sender, GridViewSortEventArgs e)
157+
{
158+
bindGridView(e.SortExpression, sortOrder);
143159
}
144160

161+
public string sortOrder
162+
{
163+
get
164+
{
165+
if (ViewState["sortOrder"].ToString() == "desc")
166+
ViewState["sortOrder"] = "asc";
167+
else
168+
ViewState["sortOrder"] = "desc";
169+
170+
return ViewState["sortOrder"].ToString();
171+
}
172+
set
173+
{
174+
ViewState["sortOrder"] = value;
175+
}
176+
}
177+
145178
protected void gvProperties_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
146179
{
147180
if ((e.Row.RowType == DataControlRowType.DataRow))
@@ -150,19 +183,17 @@ protected void gvProperties_RowDataBound(object sender, System.Web.UI.WebControl
150183
if (drv["property_datatype"] != DBNull.Value)
151184
{
152185
if (((string)drv["property_datatype"]).ToUpper() == "PASSWORD")
153-
{
154186
e.Row.Cells[1].Text = "*****";
155-
}
156187
}
157188

158189
e.Row.Attributes.Add("onmouseover", "this.style.cursor='hand';this.style.background='lightblue';");
159190
if (e.Row.RowState == DataControlRowState.Alternate)
160191
e.Row.Attributes.Add("onmouseout", "this.style.background='#fcfcfc url(Images/grd_alt.png) repeat-x top';");
161192
else
162193
e.Row.Attributes.Add("onmouseout", "this.style.background='none';");
194+
163195
e.Row.Attributes.Add("onclick", ClientScript.GetPostBackClientHyperlink(this, "gvProperties_" + e.Row.RowIndex.ToString()));
164196
}
165-
166197
}
167198

168199
protected void gvPropList_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
@@ -174,9 +205,9 @@ protected void gvPropList_RowDataBound(object sender, System.Web.UI.WebControls.
174205
e.Row.Attributes.Add("onmouseout", "this.style.background='#fcfcfc url(Images/grd_alt.png) repeat-x top';");
175206
else
176207
e.Row.Attributes.Add("onmouseout", "this.style.background='none';");
208+
177209
e.Row.Attributes.Add("onclick", "selectPropListItem('" + gvPropList.DataKeys[e.Row.RowIndex]["item_name"].ToString() + "', this);");
178210
}
179-
180211
}
181212

182213
protected void ddlState_SelectedIndexChanged(object sender, EventArgs e)
@@ -185,6 +216,7 @@ protected void ddlState_SelectedIndexChanged(object sender, EventArgs e)
185216
lblAlert.Text = "State set successfully to " + ddlState.SelectedItem.Text;
186217
alert.Visible = true;
187218
}
219+
188220
protected void ddlMethod_SelectedIndexChanged(object sender, EventArgs e)
189221
{
190222
DataSet ds = OSAESql.RunSQL("SELECT param_1_label, param_2_label, param_1_default, param_2_default FROM osae_v_object_type_method otm INNER JOIN osae_object oo ON oo.object_type_id = otm.object_type_id WHERE object_name = '" + hdnSelectedObjectName.Text.Replace("'","''") + "' AND method_name = '" + ddlMethod.SelectedItem.Value + "'");
@@ -240,7 +272,6 @@ private void loadDDLs()
240272
else
241273
divState.Visible = true;
242274

243-
244275
ddlMethod.DataSource = OSAESql.RunSQL("SELECT method_label as Text, method_name as Value FROM osae_object_type_method ts INNER JOIN osae_object o ON o.object_type_id = ts.object_type_id where object_name = '" + hdnSelectedObjectName.Text.Replace("'", "''") + "' ORDER BY method_label");
245276
ddlMethod.DataBind();
246277
if (ddlMethod.Items.Count == 0)
@@ -285,7 +316,6 @@ private void loadPropertyList()
285316
gvPropList.DataSource = OSAESql.RunSQL("SELECT item_name, item_label FROM osae_object_property_array WHERE object_property_id = " + gvProperties.DataKeys[Int32.Parse(hdnSelectedPropRow.Text)]["object_property_id"].ToString());
286317
gvPropList.DataBind();
287318
btnListItemUpdate.Enabled = false;
288-
289319
}
290320

291321
private void loadDetails()
@@ -314,7 +344,7 @@ protected void btnPropSave_Click(object sender, EventArgs e)
314344
value = ddlPropValue.SelectedValue;
315345
else
316346
{
317-
if(ddlPropValue.Visible)
347+
if (ddlPropValue.Visible)
318348
value = ddlPropValue.SelectedValue;
319349
else
320350
value = txtPropValue.Text;
@@ -323,6 +353,7 @@ protected void btnPropSave_Click(object sender, EventArgs e)
323353
OSAEObjectPropertyManager.ObjectPropertySet(hdnSelectedObjectName.Text, hdnSelectedPropName.Text, value, "Web UI");
324354
loadProperties();
325355
}
356+
326357
protected void btnAdd_Click(object sender, EventArgs e)
327358
{
328359
OSAEObjectManager.ObjectAdd(txtName.Text, txtDescr.Text, ddlType.SelectedItem.Value, txtAddress.Text, ddlContainer.SelectedValue, chkEnabled.Checked);
@@ -335,6 +366,7 @@ protected void btnAdd_Click(object sender, EventArgs e)
335366
panelEditForm.Visible = false;
336367
loadDDLs();
337368
}
369+
338370
protected void btnDelete_Click(object sender, EventArgs e)
339371
{
340372
OSAEObjectManager.ObjectDelete(gvObjects.DataKeys[Int32.Parse(hdnSelectedRow.Text)]["object_name"].ToString());
@@ -353,6 +385,7 @@ protected void btnDelete_Click(object sender, EventArgs e)
353385
else
354386
hdnSelectedRow.Text = selectedRow.ToString();
355387
}
388+
356389
protected void btnUpdate_Click(object sender, EventArgs e)
357390
{
358391
int enabled = 0;

0 commit comments

Comments
 (0)