private void Page_Load(object sender, System.EventArgs e) { try { // 01/08/2006 Paul. The viewstate is no longer disabled, so we can go back to using ctlSearch.NAME. string sNAME = ctlSearch.NAME; //Sql.ToString(Request[ctlSearch.ListUniqueID]); ctlSearch.Visible = Sql.IsEmptyString(sNAME); ctlLayoutButtons.Visible = !ctlSearch.Visible; DataTable dtFields = null; if (!Sql.IsEmptyString(sNAME) && sNAME != Sql.ToString(ViewState["LAYOUT_VIEW_NAME"])) { // 01/08/2006 Paul. We are having a problem with the ViewState not loading properly. // This problem only seems to occur when the NewRecord is visible and we try and load a different view. // The solution seems to be to hide the Search dialog so that the user must Cancel out of editing the current view. // This works very well to clear the ViewState because we GET the next page instead of POST to it. Utils.SetPageTitle(Page, sNAME); Page.DataBind(); tblMain.EnableViewState = false; string sMODULE_NAME = String.Empty; string sVIEW_NAME = String.Empty; GetModuleName(sNAME, ref sMODULE_NAME, ref sVIEW_NAME); dtFields = GetLayoutFields(sNAME).Copy(); ViewState["MODULE_NAME"] = sMODULE_NAME; ViewState["VIEW_NAME"] = sVIEW_NAME; ViewState["LAYOUT_VIEW_NAME"] = sNAME; ViewState["dtFields"] = dtFields; if (dtFields.Rows.Count > 0) { ViewState["ROW_MINIMUM"] = dtFields.Rows[0][LayoutIndexName()]; } else { ViewState["ROW_MINIMUM"] = 0; } } else { dtFields = ViewState["dtFields"] as DataTable; } ctlNewRecord = ctlHeader.FindControl("ctlNewRecord") as NewRecord; if (ctlNewRecord != null) { if (Sql.IsEmptyString(sNAME)) { ctlNewRecord.Clear(); } else { ctlNewRecord.MODULE_NAME = Sql.ToString(ViewState["MODULE_NAME"]); ctlNewRecord.VIEW_NAME = Sql.ToString(ViewState["VIEW_NAME"]); } } // 01/07/2006 Paul. The problem with the ImageButton Delete event was that the dynamically rendered ID // was not being found on every other page request. The solution was to manually name and number the ImageButton IDs. // Make sure not to use ":" in the name, otherwise it will confuse the FindControl function. LayoutView_Bind(dtFields); } catch (Exception ex) { SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex.Message); ctlLayoutButtons.ErrorText = ex.Message; } }
protected virtual void Page_Command(Object sender, CommandEventArgs e) { try { DataTable dtFields = ViewState["dtFields"] as DataTable; //ctlLayoutButtons.ErrorText = e.CommandName + ": " + e.CommandArgument.ToString(); if (e.CommandName == "Layout.Delete") { int nFieldIndex = Sql.ToInteger(e.CommandArgument); DynamicTableDelete(dtFields, nFieldIndex); ViewState["dtFields"] = dtFields; LayoutView_Bind(dtFields); if (ctlNewRecord != null) { ctlNewRecord.Clear(); } } else if (e.CommandName == "Layout.MoveUp") { int nFieldIndex = Sql.ToInteger(e.CommandArgument); int nRowMinimum = Sql.ToInteger(ViewState["ROW_MINIMUM"]); DynamicTableMoveUp(dtFields, nFieldIndex, nRowMinimum); ViewState["dtFields"] = dtFields; LayoutView_Bind(dtFields); if (ctlNewRecord != null) { ctlNewRecord.Clear(); } } else if (e.CommandName == "Layout.MoveDown") { int nFieldIndex = Sql.ToInteger(e.CommandArgument); DynamicTableMoveDown(dtFields, nFieldIndex); ViewState["dtFields"] = dtFields; LayoutView_Bind(dtFields); if (ctlNewRecord != null) { ctlNewRecord.Clear(); } } else if (e.CommandName == "Layout.Edit") { } else if (e.CommandName == "NewRecord.Save") { } else if (e.CommandName == "NewRecord.Cancel") { if (ctlNewRecord != null) { ctlNewRecord.Clear(); } } else if (e.CommandName == "Layout.Insert") { if (ctlNewRecord != null) { ctlNewRecord.Clear(); int nFieldIndex = Sql.ToInteger(e.CommandArgument); ctlNewRecord.FIELD_ID = Guid.NewGuid(); ctlNewRecord.FIELD_INDEX = nFieldIndex; ctlNewRecord.Visible = true; } } else if (e.CommandName == "New") { if (ctlNewRecord != null) { ctlNewRecord.Clear(); int nFieldIndex = Sql.ToInteger(e.CommandArgument); ctlNewRecord.FIELD_ID = Guid.NewGuid(); ctlNewRecord.Visible = true; } } else if (e.CommandName == "Defaults") { } else if (e.CommandName == "Save") { DbProviderFactory dbf = DbProviderFactories.GetFactory(); using (IDbConnection con = dbf.CreateConnection()) { con.Open(); using (IDbTransaction trn = con.BeginTransaction()) { try { IDbCommand cmdUpdate = SqlProcs.Factory(con, LayoutUpdateProcedure()); cmdUpdate.Transaction = trn; foreach (IDataParameter par in cmdUpdate.Parameters) { par.Value = DBNull.Value; } IDbDataParameter parMODIFIED_USER_ID = Sql.FindParameter(cmdUpdate, "@MODIFIED_USER_ID"); if (parMODIFIED_USER_ID != null) { parMODIFIED_USER_ID.Value = Security.USER_ID; } DataView vwFields = new DataView(dtFields); vwFields.RowFilter = "DELETED = 0"; foreach (DataRowView row in vwFields) { if (row.Row.RowState == DataRowState.Modified || row.Row.RowState == DataRowState.Added) { foreach (IDataParameter par in cmdUpdate.Parameters) { string sFieldName = Sql.ExtractDbName(cmdUpdate, par.ParameterName); if (dtFields.Columns.Contains(sFieldName) && (sFieldName != "MODIFIED_USER_ID")) { // 01/09/2006 Paul. Make sure to use ToDBString to convert empty stings to NULL. switch (par.DbType) { case DbType.Guid: par.Value = Sql.ToGuid(row[sFieldName]); break; case DbType.Int16: par.Value = Sql.ToDBInteger(row[sFieldName]); break; case DbType.Int32: par.Value = Sql.ToDBInteger(row[sFieldName]); break; case DbType.Int64: par.Value = Sql.ToDBInteger(row[sFieldName]); break; case DbType.Double: par.Value = Sql.ToDBFloat(row[sFieldName]); break; case DbType.Decimal: par.Value = Sql.ToDBDecimal(row[sFieldName]); break; case DbType.Byte: par.Value = Sql.ToDBBoolean(row[sFieldName]); break; case DbType.DateTime: par.Value = Sql.ToDBDateTime(row[sFieldName]); break; default: par.Value = Sql.ToDBString(row[sFieldName]); break; } } } cmdUpdate.ExecuteNonQuery(); } } IDbCommand cmdDelete = SqlProcs.Factory(con, LayoutDeleteProcedure()); cmdDelete.Transaction = trn; IDbDataParameter parID = Sql.FindParameter(cmdDelete, "@ID"); parMODIFIED_USER_ID = Sql.FindParameter(cmdDelete, "@MODIFIED_USER_ID"); if (parMODIFIED_USER_ID != null) { parMODIFIED_USER_ID.Value = Security.USER_ID; } vwFields.RowFilter = "DELETED = 1"; foreach (DataRowView row in vwFields) { parID.Value = Sql.ToDBGuid(row["ID"]); cmdDelete.ExecuteNonQuery(); } trn.Commit(); // 01/09/2006 Paul. Make sure to clear the cache so that the changes will take effect immediately. ClearCache(Sql.ToString(ViewState["LAYOUT_VIEW_NAME"])); Response.Redirect("default.aspx"); } catch (Exception ex) { trn.Rollback(); throw(new Exception("Failed to update, transaction aborted; " + ex.Message, ex)); } } } } else if (e.CommandName == "Cancel") { Response.Redirect("default.aspx"); } } catch (Exception ex) { SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex.Message); ctlLayoutButtons.ErrorText = ex.Message; } }
private void Page_Load(object sender, System.EventArgs e) { try { // 01/08/2006 Paul. The viewstate is no longer disabled, so we can go back to using ctlSearch.NAME. string sNAME = ctlSearch.NAME; //Sql.ToString(Request[ctlSearch.ListUniqueID]); ctlSearch .Visible = Sql.IsEmptyString(sNAME); ctlLayoutButtons.Visible = !ctlSearch.Visible; // 09/08/2007 Paul. Add a list header so we will know what list we are working on. if ( ctlListHeader != null ) { ctlListHeader.Visible = !ctlSearch.Visible; ctlListHeader.Title = sNAME; } if ( !Sql.IsEmptyString(sNAME) && sNAME != Sql.ToString(ViewState["LAYOUT_VIEW_NAME"]) ) { // 01/08/2006 Paul. We are having a problem with the ViewState not loading properly. // This problem only seems to occur when the NewRecord is visible and we try and load a different view. // The solution seems to be to hide the Search dialog so that the user must Cancel out of editing the current view. // This works very well to clear the ViewState because we GET the next page instead of POST to it. SetPageTitle(sNAME); Page.DataBind(); tblMain.EnableViewState = false; string sMODULE_NAME = String.Empty; string sVIEW_NAME = String.Empty; GetModuleName(sNAME, ref sMODULE_NAME, ref sVIEW_NAME); GetLayoutFields(sNAME); LayoutView_Bind(); ViewState["MODULE_NAME" ] = sMODULE_NAME; ViewState["VIEW_NAME" ] = sVIEW_NAME ; ViewState["LAYOUT_VIEW_NAME"] = sNAME ; SaveFieldState(); if ( dtFields.Rows.Count > 0 ) { ViewState["ROW_MINIMUM"] = dtFields.Rows[0][LayoutIndexName()]; } else { ViewState["ROW_MINIMUM"] = 0; } } // 02/08/2007 Paul. The NewRecord control is now in the MasterPage. ContentPlaceHolder plcSidebar = Page.Master.FindControl("cntSidebar") as ContentPlaceHolder; if ( plcSidebar != null ) { ctlNewRecord = plcSidebar.FindControl("ctlNewRecord") as NewRecord; if ( ctlNewRecord != null ) { if ( Sql.IsEmptyString(sNAME) ) { ctlNewRecord.Clear(); } else { ctlNewRecord.MODULE_NAME = Sql.ToString(ViewState["MODULE_NAME"]); ctlNewRecord.VIEW_NAME = Sql.ToString(ViewState["VIEW_NAME" ]); } } } } catch(Exception ex) { SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex); ctlLayoutButtons.ErrorText = ex.Message; } }
private void Page_Load(object sender, System.EventArgs e) { try { // 01/08/2006 Paul. The viewstate is no longer disabled, so we can go back to using ctlSearch.NAME. string sNAME = ctlSearch.NAME; //Sql.ToString(Request[ctlSearch.ListUniqueID]); ctlSearch .Visible = Sql.IsEmptyString(sNAME); ctlLayoutButtons.Visible = !ctlSearch.Visible; DataTable dtFields = null; if ( !Sql.IsEmptyString(sNAME) && sNAME != Sql.ToString(ViewState["LAYOUT_VIEW_NAME"]) ) { // 01/08/2006 Paul. We are having a problem with the ViewState not loading properly. // This problem only seems to occur when the NewRecord is visible and we try and load a different view. // The solution seems to be to hide the Search dialog so that the user must Cancel out of editing the current view. // This works very well to clear the ViewState because we GET the next page instead of POST to it. Utils.SetPageTitle(Page, sNAME); Page.DataBind(); tblMain.EnableViewState = false; string sMODULE_NAME = String.Empty; string sVIEW_NAME = String.Empty; GetModuleName(sNAME, ref sMODULE_NAME, ref sVIEW_NAME); dtFields = GetLayoutFields(sNAME).Copy(); ViewState["MODULE_NAME" ] = sMODULE_NAME; ViewState["VIEW_NAME" ] = sVIEW_NAME ; ViewState["LAYOUT_VIEW_NAME"] = sNAME ; ViewState["dtFields" ] = dtFields ; if ( dtFields.Rows.Count > 0 ) { ViewState["ROW_MINIMUM"] = dtFields.Rows[0][LayoutIndexName()]; } else { ViewState["ROW_MINIMUM"] = 0; } } else { dtFields = ViewState["dtFields"] as DataTable; } ctlNewRecord = ctlHeader.FindControl("ctlNewRecord") as NewRecord; if ( ctlNewRecord != null ) { if ( Sql.IsEmptyString(sNAME) ) { ctlNewRecord.Clear(); } else { ctlNewRecord.MODULE_NAME = Sql.ToString(ViewState["MODULE_NAME"]); ctlNewRecord.VIEW_NAME = Sql.ToString(ViewState["VIEW_NAME" ]); } } // 01/07/2006 Paul. The problem with the ImageButton Delete event was that the dynamically rendered ID // was not being found on every other page request. The solution was to manually name and number the ImageButton IDs. // Make sure not to use ":" in the name, otherwise it will confuse the FindControl function. LayoutView_Bind(dtFields); } catch(Exception ex) { SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex.Message); ctlLayoutButtons.ErrorText = ex.Message; } }
private void Page_Load(object sender, System.EventArgs e) { try { // 01/08/2006 Paul. The viewstate is no longer disabled, so we can go back to using ctlSearch.NAME. string sNAME = ctlSearch.NAME; //Sql.ToString(Request[ctlSearch.ListUniqueID]); ctlSearch.Visible = Sql.IsEmptyString(sNAME); ctlLayoutButtons.Visible = !ctlSearch.Visible; // 09/08/2007 Paul. Add a list header so we will know what list we are working on. if (ctlListHeader != null) { ctlListHeader.Visible = !ctlSearch.Visible; ctlListHeader.Title = sNAME; } if (!Sql.IsEmptyString(sNAME) && sNAME != Sql.ToString(ViewState["LAYOUT_VIEW_NAME"])) { // 01/08/2006 Paul. We are having a problem with the ViewState not loading properly. // This problem only seems to occur when the NewRecord is visible and we try and load a different view. // The solution seems to be to hide the Search dialog so that the user must Cancel out of editing the current view. // This works very well to clear the ViewState because we GET the next page instead of POST to it. SetPageTitle(sNAME); Page.DataBind(); tblMain.EnableViewState = false; string sMODULE_NAME = String.Empty; string sVIEW_NAME = String.Empty; GetModuleName(sNAME, ref sMODULE_NAME, ref sVIEW_NAME); GetLayoutFields(sNAME); LayoutView_Bind(); ViewState["MODULE_NAME"] = sMODULE_NAME; ViewState["VIEW_NAME"] = sVIEW_NAME; ViewState["LAYOUT_VIEW_NAME"] = sNAME; SaveFieldState(); if (dtFields.Rows.Count > 0) { ViewState["ROW_MINIMUM"] = dtFields.Rows[0][LayoutIndexName()]; } else { ViewState["ROW_MINIMUM"] = 0; } } // 02/08/2007 Paul. The NewRecord control is now in the MasterPage. ContentPlaceHolder plcSidebar = Page.Master.FindControl("cntSidebar") as ContentPlaceHolder; if (plcSidebar != null) { ctlNewRecord = plcSidebar.FindControl("ctlNewRecord") as NewRecord; if (ctlNewRecord != null) { if (Sql.IsEmptyString(sNAME)) { ctlNewRecord.Clear(); } else { ctlNewRecord.MODULE_NAME = Sql.ToString(ViewState["MODULE_NAME"]); ctlNewRecord.VIEW_NAME = Sql.ToString(ViewState["VIEW_NAME"]); } } } } catch (Exception ex) { SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex); ctlLayoutButtons.ErrorText = ex.Message; } }