using framework_business;
using framework_library;
using System;
using System.Collections;
using System.Data;
using System.Reflection;
using System.Web.UI;
public partial class controls_admin_surfaceGrids : System.Web.UI.UserControl, IControlBase
{
#region methods
///
/// Event fires from control base
///
public void ReloadControl()
{
try
{
if (utils.verifySession("surface"))
{
oSurface surface = (oSurface)Session["surface"];
SetCheckBoxValues(surface);
BindSortingColumns(surface);
BindAggregateColumns(surface);
BindAggregateTypes();
aggDiv.Visible = ddlEditTypes.SelectedValue == pNums.SurfaceGridEditType.Batch.GetHashCode().ToString();
}
}
catch (Exception ex)
{
exception.HandleException("SurfaceGrids:", MethodBase.GetCurrentMethod().Name, ex, 0);
Response.Redirect("/error", false);
}
}
public void SaveControlData() { }
///
/// Bind Repeater
///
///
private void BindRepeater(oSurface surface)
{
ArrayList list = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isGrid", surface.recId.ToString() + ",1", "colSequence");
if (list == null || list.Count == 0)
{
DataTable dt = new DataTable();
dt.Columns.Add("surfaceFieldDisplay");
DataRow row = dt.NewRow();
row["surfaceFieldDisplay"] = "None";
dt.Rows.Add(row);
rptSurfaceFieldsHeaders.DataSource = rptSurfaceFields.DataSource = dt;
}
else
{
rptSurfaceFieldsHeaders.DataSource = rptSurfaceFields.DataSource = list;
}
rptSurfaceFieldsHeaders.DataBind();
rptSurfaceFields.DataBind();
}
///
/// Set Checkbox values
///
///
private void SetCheckBoxValues(oSurface surface)
{
Session["SurfaceGridOptions"] = new oSurfaceGridOptions();
((oSurfaceGridOptions)Session["SurfaceGridOptions"]).surfaceGridEditTypeId = 1;
((oSurfaceGridOptions)Session["SurfaceGridOptions"]).pagingCount = 10;
foreach (oSurfaceGridOptions gridItem in xData.GetTypedByCriteriaSpecific("recID", typeof(oSurfaceGridOptions), "surfaceId", surface.recId.ToString()))
{
Session["SurfaceGridOptions"] = gridItem;
}
chkAllowAdd.Checked = ((oSurfaceGridOptions)Session["SurfaceGridOptions"]).allowAdd;
btnNewField.Visible = chkAllowAdd.Checked;
chkAllowBulkUpdate.Checked = ((oSurfaceGridOptions)Session["SurfaceGridOptions"]).allowBulkUpdate;
btnBulkUpdateField.Visible = chkAllowBulkUpdate.Checked;
chkAllowScroll.Checked = ((oSurfaceGridOptions)Session["SurfaceGridOptions"]).allowScroll;
txtFixedColumns.Text = ((oSurfaceGridOptions)Session["SurfaceGridOptions"]).fixedColumns.ToString();
chkAllowEdit.Checked = ((oSurfaceGridOptions)Session["SurfaceGridOptions"]).allowEdit;
thEdit.Visible = tdEdit.Visible = ddlEditTypes.Visible = lblddlEditTypes.Visible = chkAllowEdit.Checked;
chkAllowClone.Checked = ((oSurfaceGridOptions)Session["SurfaceGridOptions"]).allowClone;
thClone.Visible = tdClone.Visible = chkAllowClone.Checked;
chkAllowRemove.Checked = ((oSurfaceGridOptions)Session["SurfaceGridOptions"]).allowRemove;
thRemove.Visible = tdRemove.Visible = chkAllowRemove.Checked;
chkAllowView.Checked = ((oSurfaceGridOptions)Session["SurfaceGridOptions"]).allowView;
thView.Visible = tdView.Visible = chkAllowView.Checked;
chkAllowSort.Checked = ((oSurfaceGridOptions)Session["SurfaceGridOptions"]).allowSort;
chkAllowFilter.Checked = ((oSurfaceGridOptions)Session["SurfaceGridOptions"]).allowFilter;
chkAllowExport.Checked = ((oSurfaceGridOptions)Session["SurfaceGridOptions"]).allowExport;
chkAllowColVis.Checked = ((oSurfaceGridOptions)Session["SurfaceGridOptions"]).allowColVis;
chkIsTabbed.Checked = ((oSurfaceGridOptions)Session["SurfaceGridOptions"]).isTabbed;
chkShowWizardStatus.Checked = ((oSurfaceGridOptions)Session["SurfaceGridOptions"]).showWizardStatus;
chkShowAggregate.Checked = ((oSurfaceGridOptions)Session["SurfaceGridOptions"]).showAggregate;
txtAggregateTitle.Text = ((oSurfaceGridOptions)Session["SurfaceGridOptions"]).aggregateTitle;
chkUseFooTable.Checked = ((oSurfaceGridOptions)Session["SurfaceGridOptions"]).useFooTable;
ddlViewIcon.SelectedValue = ((oSurfaceGridOptions)Session["SurfaceGridOptions"]).viewIcon;
ddlEditIcon.SelectedValue = ((oSurfaceGridOptions)Session["SurfaceGridOptions"]).editIcon;
ddlPaging.SelectedIndex = ddlPaging.Items.IndexOf(ddlPaging.Items.FindByValue(((oSurfaceGridOptions)Session["SurfaceGridOptions"]).pagingCount.ToString()));
SetGridAsDataTable((oSurfaceGridOptions)Session["SurfaceGridOptions"]);
BindEditTypes();
ddlEditTypes.SelectedIndex = ddlEditTypes.Items.IndexOf(ddlEditTypes.Items.FindByValue(((oSurfaceGridOptions)Session["SurfaceGridOptions"]).surfaceGridEditTypeId.ToString()));
BindAccessRoles();
if (ddlAddAccess.Items.FindByValue(((oSurfaceGridOptions)Session["SurfaceGridOptions"]).addAccessType.ToString()) != null)
ddlAddAccess.SelectedValue = ((oSurfaceGridOptions)Session["SurfaceGridOptions"]).addAccessType.ToString();
if (ddlEditAccess.Items.FindByValue(((oSurfaceGridOptions)Session["SurfaceGridOptions"]).editAccessType.ToString()) != null)
ddlEditAccess.SelectedValue = ((oSurfaceGridOptions)Session["SurfaceGridOptions"]).editAccessType.ToString();
if (ddlViewAccess.Items.FindByValue(((oSurfaceGridOptions)Session["SurfaceGridOptions"]).viewAccessType.ToString()) != null)
ddlViewAccess.SelectedValue = ((oSurfaceGridOptions)Session["SurfaceGridOptions"]).viewAccessType.ToString();
if (ddlRemoveAccess.Items.FindByValue(((oSurfaceGridOptions)Session["SurfaceGridOptions"]).removeAccessType.ToString()) != null)
ddlRemoveAccess.SelectedValue = ((oSurfaceGridOptions)Session["SurfaceGridOptions"]).removeAccessType.ToString();
if (ddlCloneAccess.Items.FindByValue(((oSurfaceGridOptions)Session["SurfaceGridOptions"]).cloneAccessType.ToString()) != null)
ddlCloneAccess.SelectedValue = ((oSurfaceGridOptions)Session["SurfaceGridOptions"]).cloneAccessType.ToString();
BindRepeater(surface);
BindSortingColumns(surface);
hidDefaultSorting.Value = ((oSurfaceGridOptions)Session["SurfaceGridOptions"]).defaultSort;
string sortText = "";
foreach (string sortCol in ((oSurfaceGridOptions)Session["SurfaceGridOptions"]).defaultSort.Split(','))
{
string value = sortCol.Replace(" ASC", "").Replace(" DESC", "").Trim();
string direction = "ASC";
if (sortCol.IndexOf("DESC") > 0)
direction = "DESC";
if (ddSortingColumn.Items.FindByValue(value) != null)
{
if (sortText == String.Empty)
sortText = ddSortingColumn.Items.FindByValue(value).Text + " " + direction;
else
sortText += ", " + ddSortingColumn.Items.FindByValue(value).Text + " " + direction;
}
}
if (sortText == String.Empty)
sortText = "None";
lblDefaultSorting.InnerText = sortText;
SetAggregateLabel(surface);
BindAggregateColumns(surface);
}
private void SetAggregateLabel(oSurface surface)
{
string aggLabel = "", aggHf = "";
int count = 1;
foreach (oSurfaceGridAggregate gridAgg in xData.GetTypedByCriteriaSpecific("recId",typeof(oSurfaceGridAggregate),"surfaceId",surface.recId.ToString()))
{
string fieldName = "";
string aggName = "";
foreach (oSurfaceField field in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "recId", gridAgg.surfaceFieldId.ToString()))
{
fieldName = field.surfaceFieldDisplay;
}
foreach (oSurfaceGridAggregateType aggType in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceGridAggregateType), "recId", gridAgg.aggregateTypeId.ToString()))
{
aggName = aggType.aggregateType;
}
if (count == 1)
{
aggHf = gridAgg.surfaceFieldId.ToString()+"|"+gridAgg.aggregateTypeId.ToString();
aggLabel = fieldName + " (" + aggName + ")";
}
else
{
aggHf += ","+ gridAgg.surfaceFieldId.ToString() + "|" + gridAgg.aggregateTypeId.ToString();
aggLabel += ", " + fieldName + " (" + aggName + ")";
}
count++;
}
hfAggregates.Value = aggHf;
lblAggregates.InnerText = aggLabel;
}
private void BindEditTypes()
{
try
{
ArrayList editTypes = new ArrayList();
editTypes = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceGridEditType), "isActive", "1");
ddlEditTypes.DataSource = editTypes;
ddlEditTypes.DataTextField = "gridEditType";
ddlEditTypes.DataValueField = "recId";
ddlEditTypes.DataBind();
}
catch (Exception ex)
{
exception.HandleException("SurfaceGrids:", MethodBase.GetCurrentMethod().Name, ex, 0);
Response.Redirect("Error.aspx", false);
}
}
private void BindAccessRoles()
{
try
{
DataTable dtUserType = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oUserType), "isActive", "1", "sequence");
ddlViewAccess.DataSource = dtUserType;
ddlViewAccess.DataTextField = "userType";
ddlViewAccess.DataValueField = "recId";
ddlViewAccess.DataBind();
ddlAddAccess.DataSource = dtUserType;
ddlAddAccess.DataTextField = "userType";
ddlAddAccess.DataValueField = "recId";
ddlAddAccess.DataBind();
ddlRemoveAccess.DataSource = dtUserType;
ddlRemoveAccess.DataTextField = "userType";
ddlRemoveAccess.DataValueField = "recId";
ddlRemoveAccess.DataBind();
ddlEditAccess.DataSource = dtUserType;
ddlEditAccess.DataTextField = "userType";
ddlEditAccess.DataValueField = "recId";
ddlEditAccess.DataBind();
ddlCloneAccess.DataSource = dtUserType;
ddlCloneAccess.DataTextField = "userType";
ddlCloneAccess.DataValueField = "recId";
ddlCloneAccess.DataBind();
}
catch (Exception ex)
{
exception.HandleException("SurfaceGrids:", MethodBase.GetCurrentMethod().Name, ex, 0);
Response.Redirect("Error.aspx", false);
}
}
///
/// Bind Aggregate Columns
///
///
private void BindAggregateColumns(oSurface surface)
{
try
{
ArrayList list = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,isGrid,surfaceFieldTypeId", surface.recId + ",1,1,~()" + pNums.FieldType.Number.GetHashCode().ToString() + "|" + pNums.FieldType.Decimal.GetHashCode().ToString());
ddAggregateField.DataSource = list;
ddAggregateField.DataTextField = "surfaceFieldDisplay";
ddAggregateField.DataValueField = "recId";
ddAggregateField.DataBind();
}
catch (Exception ex)
{
exception.HandleException("SurfaceGrids:", MethodBase.GetCurrentMethod().Name, ex, 0);
Response.Redirect("Error.aspx", false);
}
}
///
/// Bind Aggregate Types
///
private void BindAggregateTypes()
{
try
{
ArrayList list = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceGridAggregateType), "isActive", "1");
ddAggregateType.DataSource = list;
ddAggregateType.DataTextField = "aggregateType";
ddAggregateType.DataValueField = "recId";
ddAggregateType.DataBind();
}
catch (Exception ex)
{
exception.HandleException("SurfaceGrids:", MethodBase.GetCurrentMethod().Name, ex, 0);
Response.Redirect("Error.aspx", false);
}
}
///
/// bind sorting columns
///
///
private void BindSortingColumns(oSurface surface)
{
try
{
ArrayList list = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,isGrid", surface.recId + ",1,1");
ddSortingColumn.DataSource = list;
ddSortingColumn.DataTextField = "surfaceFieldDisplay";
ddSortingColumn.DataValueField = "surfaceFieldName";
ddSortingColumn.DataBind();
}
catch (Exception ex)
{
exception.HandleException("SurfaceGrids:", MethodBase.GetCurrentMethod().Name, ex, 0);
Response.Redirect("Error.aspx", false);
}
}
///
/// Set Grid as Data Table
///
private void SetGridAsDataTable(oSurfaceGridOptions opts)
{
string js = "var btns = [];";
string tblinfo = "false";
if (opts.pagingCount > -1 || opts.allowFilter)
tblinfo = "true";
if (opts.allowExport)
{
js += "btns.push('copy');";
js += "btns.push('excel');";
js += "btns.push('pdf');";
}
if (opts.allowColVis)
js += "btns.push('colvis');";
//search, page, tblInfo, btns
js += "setDT(" + (opts.allowSort ? "true" : "false") + "," + (opts.allowFilter ? "true" : "false") + "," + (opts.pagingCount == -1 ? "false" : "true") + "," + tblinfo + "," + opts.pagingCount + ",btns);";
ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "setDT", js, true);
}
#endregion
#region events
///
/// Page Load Event
///
///
///
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//CVH 2016-10-06 Not required, ReloadControl is called before opening, and causing problems, setDT not defined
//if (utils.verifySession("surface"))
//{
// oSurface surface = (oSurface)Session["surface"];
// SetCheckBoxValues(surface);
//}
}
}
///
/// Change Allow Add Check
///
///
///
protected void chkAllowAdd_CheckedChanged(object sender, EventArgs e)
{
pnlResult.Visible = false;
oSurfaceGridOptions opts = new oSurfaceGridOptions();
if (utils.verifySession("SurfaceGridOptions"))
{
((oSurfaceGridOptions)Session["SurfaceGridOptions"]).allowAdd = chkAllowAdd.Checked;
opts = (oSurfaceGridOptions)Session["SurfaceGridOptions"];
}
btnNewField.Visible = chkAllowAdd.Checked;
SetGridAsDataTable(opts);
}
///
/// Change Allow Edit Check
///
///
///
protected void chkAllowEdit_CheckedChanged(object sender, EventArgs e)
{
pnlResult.Visible = false;
oSurfaceGridOptions opts = new oSurfaceGridOptions();
if (utils.verifySession("SurfaceGridOptions"))
{
((oSurfaceGridOptions)Session["SurfaceGridOptions"]).allowEdit = chkAllowEdit.Checked;
opts = (oSurfaceGridOptions)Session["SurfaceGridOptions"];
}
thEdit.Visible = tdEdit.Visible = ddlEditTypes.Visible = lblddlEditTypes.Visible = chkAllowEdit.Checked;
SetGridAsDataTable(opts);
}
protected void chkAllowClone_CheckedChanged(object sender, EventArgs e)
{
pnlResult.Visible = false;
oSurfaceGridOptions opts = new oSurfaceGridOptions();
if (utils.verifySession("SurfaceGridOptions"))
{
((oSurfaceGridOptions)Session["SurfaceGridOptions"]).allowClone = chkAllowClone.Checked;
opts = (oSurfaceGridOptions)Session["SurfaceGridOptions"];
}
thClone.Visible = tdClone.Visible = chkAllowClone.Checked;
SetGridAsDataTable(opts);
}
///
/// Change Allow Remove Check
///
///
///
protected void chkAllowRemove_CheckedChanged(object sender, EventArgs e)
{
pnlResult.Visible = false;
oSurfaceGridOptions opts = new oSurfaceGridOptions();
if (utils.verifySession("SurfaceGridOptions"))
{
((oSurfaceGridOptions)Session["SurfaceGridOptions"]).allowRemove = chkAllowRemove.Checked;
opts = (oSurfaceGridOptions)Session["SurfaceGridOptions"];
}
thRemove.Visible = tdRemove.Visible = chkAllowRemove.Checked;
SetGridAsDataTable(opts);
}
///
/// Change Allow View Check
///
///
///
protected void chkAllowView_CheckedChanged(object sender, EventArgs e)
{
pnlResult.Visible = false;
oSurfaceGridOptions opts = new oSurfaceGridOptions();
if (utils.verifySession("SurfaceGridOptions"))
{
((oSurfaceGridOptions)Session["SurfaceGridOptions"]).allowView = chkAllowView.Checked;
opts = (oSurfaceGridOptions)Session["SurfaceGridOptions"];
}
thView.Visible = tdView.Visible = chkAllowView.Checked;
SetGridAsDataTable(opts);
}
///
/// Change Allow Sort Check
///
///
///
protected void chkAllowSort_CheckedChanged(object sender, EventArgs e)
{
pnlResult.Visible = false;
oSurfaceGridOptions opts = new oSurfaceGridOptions();
if (utils.verifySession("SurfaceGridOptions"))
{
((oSurfaceGridOptions)Session["SurfaceGridOptions"]).allowSort = chkAllowSort.Checked;
opts = (oSurfaceGridOptions)Session["SurfaceGridOptions"];
}
SetGridAsDataTable(opts);
}
///
/// Change Allow Filter Check
///
///
///
protected void chkAllowFilter_CheckedChanged(object sender, EventArgs e)
{
pnlResult.Visible = false;
oSurfaceGridOptions opts = new oSurfaceGridOptions();
if (utils.verifySession("SurfaceGridOptions"))
{
((oSurfaceGridOptions)Session["SurfaceGridOptions"]).allowFilter = chkAllowFilter.Checked;
opts = (oSurfaceGridOptions)Session["SurfaceGridOptions"];
}
SetGridAsDataTable(opts);
}
protected void chkAllowExport_CheckedChanged(object sender, EventArgs e)
{
pnlResult.Visible = false;
oSurfaceGridOptions opts = new oSurfaceGridOptions();
if (utils.verifySession("SurfaceGridOptions"))
{
((oSurfaceGridOptions)Session["SurfaceGridOptions"]).allowExport = chkAllowExport.Checked;
opts = (oSurfaceGridOptions)Session["SurfaceGridOptions"];
}
SetGridAsDataTable(opts);
}
protected void chkAllowColVis_CheckedChanged(object sender, EventArgs e)
{
pnlResult.Visible = false;
oSurfaceGridOptions opts = new oSurfaceGridOptions();
if (utils.verifySession("SurfaceGridOptions"))
{
((oSurfaceGridOptions)Session["SurfaceGridOptions"]).allowColVis = chkAllowColVis.Checked;
opts = (oSurfaceGridOptions)Session["SurfaceGridOptions"];
}
SetGridAsDataTable(opts);
}
protected void chkIsTabbed_CheckedChanged(object sender, EventArgs e)
{
pnlResult.Visible = false;
oSurfaceGridOptions opts = new oSurfaceGridOptions();
if (utils.verifySession("SurfaceGridOptions"))
{
((oSurfaceGridOptions)Session["SurfaceGridOptions"]).isTabbed = chkIsTabbed.Checked;
opts = (oSurfaceGridOptions)Session["SurfaceGridOptions"];
}
SetGridAsDataTable(opts);
}
protected void chkShowWizardStatus_CheckedChanged(object sender, EventArgs e)
{
pnlResult.Visible = false;
oSurfaceGridOptions opts = new oSurfaceGridOptions();
if (utils.verifySession("SurfaceGridOptions"))
{
((oSurfaceGridOptions)Session["SurfaceGridOptions"]).showWizardStatus = chkShowWizardStatus.Checked;
opts = (oSurfaceGridOptions)Session["SurfaceGridOptions"];
}
SetGridAsDataTable(opts);
}
protected void chkAllowBulkUpdate_CheckedChanged(object sender, EventArgs e)
{
pnlResult.Visible = false;
oSurfaceGridOptions opts = new oSurfaceGridOptions();
if (utils.verifySession("SurfaceGridOptions"))
{
((oSurfaceGridOptions)Session["SurfaceGridOptions"]).allowBulkUpdate = chkAllowBulkUpdate.Checked;
opts = (oSurfaceGridOptions)Session["SurfaceGridOptions"];
}
btnBulkUpdateField.Visible = chkAllowBulkUpdate.Checked;
SetGridAsDataTable(opts);
}
///
/// Change Paging Count
///
///
///
protected void ddlPaging_SelectedIndexChanged(object sender, EventArgs e)
{
pnlResult.Visible = false;
oSurfaceGridOptions opts = new oSurfaceGridOptions();
if (utils.verifySession("SurfaceGridOptions"))
{
((oSurfaceGridOptions)Session["SurfaceGridOptions"]).pagingCount = Convert.ToInt32(ddlPaging.SelectedValue);
opts = (oSurfaceGridOptions)Session["SurfaceGridOptions"];
}
SetGridAsDataTable(opts);
}
///
/// Save Form Values
///
///
///
protected void btnSave_Click(object sender, EventArgs e)
{
if (utils.verifySession("surface") && utils.verifySession("SurfaceGridOptions"))
{
oSurface surface = (oSurface)Session["surface"];
foreach (oSurfaceGridOptions gridItem in xData.GetTypedByCriteriaSpecific("recID", typeof(oSurfaceGridOptions), "surfaceId", surface.recId.ToString()))
{
((oSurfaceGridOptions)Session["SurfaceGridOptions"]).recId = gridItem.recId;
}
((oSurfaceGridOptions)Session["SurfaceGridOptions"]).surfaceId = surface.recId;
((oSurfaceGridOptions)Session["SurfaceGridOptions"]).viewIcon = ddlViewIcon.Text;
((oSurfaceGridOptions)Session["SurfaceGridOptions"]).editIcon = ddlEditIcon.Text;
((oSurfaceGridOptions)Session["SurfaceGridOptions"]).defaultSort = hidDefaultSorting.Value;
if (((oSurfaceGridOptions)Session["SurfaceGridOptions"]).allowAdd)
((oSurfaceGridOptions)Session["SurfaceGridOptions"]).addAccessType = Convert.ToInt32(ddlAddAccess.SelectedValue);
if (((oSurfaceGridOptions)Session["SurfaceGridOptions"]).allowEdit)
((oSurfaceGridOptions)Session["SurfaceGridOptions"]).editAccessType = Convert.ToInt32(ddlEditAccess.SelectedValue);
if (((oSurfaceGridOptions)Session["SurfaceGridOptions"]).allowView)
((oSurfaceGridOptions)Session["SurfaceGridOptions"]).viewAccessType = Convert.ToInt32(ddlViewAccess.SelectedValue);
if (((oSurfaceGridOptions)Session["SurfaceGridOptions"]).allowRemove)
((oSurfaceGridOptions)Session["SurfaceGridOptions"]).removeAccessType = Convert.ToInt32(ddlRemoveAccess.SelectedValue);
((oSurfaceGridOptions)Session["SurfaceGridOptions"]).showAggregate = chkShowAggregate.Checked;
((oSurfaceGridOptions)Session["SurfaceGridOptions"]).aggregateTitle = txtAggregateTitle.Text;
((oSurfaceGridOptions)Session["SurfaceGridOptions"]).allowScroll = chkAllowScroll.Checked;
((oSurfaceGridOptions)Session["SurfaceGridOptions"]).fixedColumns = Convert.ToInt32(txtFixedColumns.Text);
((oSurfaceGridOptions)Session["SurfaceGridOptions"]).useFooTable = chkUseFooTable.Checked;
SaveAggregates(surface);
if (((oSurfaceGridOptions)Session["SurfaceGridOptions"]).recId > 0)
xData.UpdateTyped("recId", ((oSurfaceGridOptions)Session["SurfaceGridOptions"]).recId.ToString(), typeof(oSurfaceGridOptions), ((oSurfaceGridOptions)Session["SurfaceGridOptions"]));
else
xData.SaveTyped("recId", typeof(oSurfaceGridOptions), ((oSurfaceGridOptions)Session["SurfaceGridOptions"]));
pnlResult.Visible = true;
lblResult.Text = "your changes were updated successfully.";
}
else
{
Response.Redirect("/admin", false);
}
}
private void SaveAggregates(oSurface surface)
{
try
{
if (hfAggregates.Value.Length > 0)
{
string aggregateValue = hfAggregates.Value;
foreach (string aggregate in aggregateValue.Split(','))
{
string fieldId = aggregate.Split('|')[0];
string aggType = aggregate.Split('|')[1];
oSurfaceGridAggregate gridAgg = new oSurfaceGridAggregate();
foreach (oSurfaceGridAggregate gridAggregate in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceGridAggregate), "surfaceId,surfaceFieldId", surface.recId.ToString() + "," + fieldId))
{
gridAgg = gridAggregate;
}
gridAgg.surfaceFieldId = Convert.ToInt32(fieldId);
gridAgg.aggregateTypeId = Convert.ToInt32(aggType);
gridAgg.surfaceId = surface.recId;
if (gridAgg.recId > 0)
xData.UpdateTyped("recId", gridAgg.recId.ToString(), typeof(oSurfaceGridAggregate), gridAgg);
else
xData.SaveTyped("recId", typeof(oSurfaceGridAggregate), gridAgg);
}
}
}
catch (Exception ex)
{
exception.HandleException("SurfaceGrids:", MethodBase.GetCurrentMethod().Name, ex, 0);
Response.Redirect("Error.aspx", false);
}
}
///
/// Change Edit Type
///
///
///
protected void ddlEditTypes_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
pnlResult.Visible = false;
if (utils.verifySession("SurfaceGridOptions"))
{
((oSurfaceGridOptions)Session["SurfaceGridOptions"]).surfaceGridEditTypeId = Convert.ToInt32(ddlEditTypes.SelectedValue);
}
aggDiv.Visible = ddlEditTypes.SelectedValue == pNums.SurfaceGridEditType.Batch.GetHashCode().ToString();
}
catch (Exception ex)
{
exception.HandleException("SurfaceGrids:", MethodBase.GetCurrentMethod().Name, ex, 0);
Response.Redirect("Error.aspx", false);
}
}
protected void btnAddSort_Click(object sender, EventArgs e)
{
try
{
string sortValue = hidDefaultSorting.Value;
string sortText = lblDefaultSorting.InnerText;
if (ddSortingColumn.SelectedItem != null)
{
string direction = "ASC";
if (ddSortingDirection.SelectedItem != null)
direction = ddSortingDirection.SelectedItem.Value;
string value = ddSortingColumn.SelectedItem.Value;
if (!sortValue.Contains(value))
{
if (sortValue == String.Empty)
{
sortValue = value + " " + direction;
sortText = ddSortingColumn.SelectedItem.Text + " " + direction;
}
else
{
sortValue += ", " + value + " " + direction;
sortText += ", " + ddSortingColumn.SelectedItem.Text + " " + direction;
}
}
}
hidDefaultSorting.Value = sortValue;
lblDefaultSorting.InnerText = sortText;
}
catch (Exception ex)
{
exception.HandleException("SurfaceGrids:", MethodBase.GetCurrentMethod().Name, ex, 0);
Response.Redirect("Error.aspx", false);
}
}
protected void btnClearSort_Click(object sender, EventArgs e)
{
try
{
hidDefaultSorting.Value = "";
lblDefaultSorting.InnerText = "None";
}
catch (Exception ex)
{
exception.HandleException("SurfaceGrids:", MethodBase.GetCurrentMethod().Name, ex, 0);
Response.Redirect("Error.aspx", false);
}
}
#endregion
protected void lnkClearAggregates_Click(object sender, EventArgs e)
{
try
{
hfAggregates.Value = "";
lblAggregates.InnerText = "None";
}
catch (Exception ex)
{
exception.HandleException("SurfaceGrids:", MethodBase.GetCurrentMethod().Name, ex, 0);
Response.Redirect("Error.aspx", false);
}
}
protected void btnAddAggregate_Click(object sender, EventArgs e)
{
try
{
string aggregateValue = hfAggregates.Value;
string aggregateText = lblAggregates.InnerText;
if (ddAggregateField.SelectedItem != null && ddAggregateType.SelectedItem != null)
{
string aggregateType = ddAggregateType.SelectedItem.Text;
string aggregateField = ddAggregateField.SelectedValue;
if (!aggregateValue.Contains(aggregateField))
{
if (aggregateValue == string.Empty)
{
aggregateValue = aggregateField + "|" + ddAggregateType.SelectedValue;
aggregateText = ddAggregateField.SelectedItem.Text + " (" + aggregateType + ")";
}
else
{
aggregateValue += "," + aggregateField + "|" + ddAggregateType.SelectedValue;
aggregateText += ", " + ddAggregateField.SelectedItem.Text + " (" + aggregateType + ")";
}
}
}
hfAggregates.Value = aggregateValue;
lblAggregates.InnerText = aggregateText;
}
catch (Exception ex)
{
exception.HandleException("SurfaceGrids:", MethodBase.GetCurrentMethod().Name, ex, 0);
Response.Redirect("Error.aspx", false);
}
}
}