/// <summary> /// Saves this instance. /// </summary> /// <param name="entity">The custom field selection to save.</param> /// <returns></returns> public static bool SaveOrUpdate(CustomFieldSelection entity) { if (entity.Id > Globals.NEW_ID) return (DataProviderManager.Provider.UpdateCustomFieldSelection(entity)); var tempId = DataProviderManager.Provider.CreateNewCustomFieldSelection(entity); if (tempId <= 0) return false; entity.Id = tempId; return true; }
/// <summary> /// Updates the custom field selection. /// </summary> /// <param name="customFieldSelectionToUpdate">The custom field selection to update.</param> /// <returns></returns> public override bool UpdateCustomFieldSelection(CustomFieldSelection customFieldSelectionToUpdate) { if (customFieldSelectionToUpdate == null) throw new ArgumentNullException("customFieldSelectionToUpdate"); using (var sqlCmd = new SqlCommand()) { AddParamToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null); AddParamToSqlCmd(sqlCmd, "@CustomFieldId", SqlDbType.Int, 0, ParameterDirection.Input, customFieldSelectionToUpdate.CustomFieldId); AddParamToSqlCmd(sqlCmd, "@CustomFieldSelectionId", SqlDbType.Int, 0, ParameterDirection.Input, customFieldSelectionToUpdate.Id); AddParamToSqlCmd(sqlCmd, "@CustomFieldSelectionName", SqlDbType.NVarChar, 255, ParameterDirection.Input, customFieldSelectionToUpdate.Name); AddParamToSqlCmd(sqlCmd, "@CustomFieldSelectionValue", SqlDbType.NVarChar, 255, ParameterDirection.Input, customFieldSelectionToUpdate.Value); AddParamToSqlCmd(sqlCmd, "@CustomFieldSelectionSortOrder", SqlDbType.Int, 0, ParameterDirection.Input, customFieldSelectionToUpdate.SortOrder); SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_CUSTOMFIELDSELECTION_UPDATE); ExecuteScalarCmd(sqlCmd); return ((int)sqlCmd.Parameters["@ReturnValue"].Value == 0); } }
/// <summary> /// Creates the new custom field selection. /// </summary> /// <param name="newCustomFieldSelection">The new custom field selection.</param> /// <returns></returns> public override int CreateNewCustomFieldSelection(CustomFieldSelection newCustomFieldSelection) { if (newCustomFieldSelection == null) throw new ArgumentNullException("newCustomFieldSelection"); using (var sqlCmd = new SqlCommand()) { AddParamToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null); AddParamToSqlCmd(sqlCmd, "@CustomFieldId", SqlDbType.Int, 0, ParameterDirection.Input, newCustomFieldSelection.CustomFieldId); AddParamToSqlCmd(sqlCmd, "@CustomFieldSelectionName", SqlDbType.NVarChar, 255, ParameterDirection.Input, newCustomFieldSelection.Name); AddParamToSqlCmd(sqlCmd, "@CUstomFieldSelectionValue", SqlDbType.NVarChar, 255, ParameterDirection.Input, newCustomFieldSelection.Value); SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_CUSTOMFIELDSELECTION_CREATE); ExecuteScalarCmd(sqlCmd); return ((int)sqlCmd.Parameters["@ReturnValue"].Value); } }
public abstract bool UpdateCustomFieldSelection(CustomFieldSelection customFieldSelectionToUpdate);
// Custom Field Selections public abstract int CreateNewCustomFieldSelection(CustomFieldSelection newCustomFieldSelection);
/// <summary> /// Handles the ItemCommand event of the grdSelectionValues control. /// </summary> /// <param name="source">The source of the event.</param> /// <param name="e">The <see cref="System.Web.UI.WebControls.DataGridCommandEventArgs"/> instance containing the event data.</param> protected void grdSelectionValues_ItemCommand(object source, DataGridCommandEventArgs e) { CustomFieldSelection cfs; var itemIndex = e.Item.ItemIndex; int itemId; var grid = source as DataGrid; switch (e.CommandName) { case "up": //move row up if (itemIndex == 0) return; itemId = Convert.ToInt32(grid.DataKeys[itemIndex]); cfs = CustomFieldSelectionManager.GetById(itemId); cfs.SortOrder -= 1; CustomFieldSelectionManager.SaveOrUpdate(cfs); break; case "down": //move row down if (itemIndex == grid.Items.Count - 1) return; itemId = Convert.ToInt32(grid.DataKeys[itemIndex]); cfs = CustomFieldSelectionManager.GetById(itemId); cfs.SortOrder += 1; CustomFieldSelectionManager.SaveOrUpdate(cfs); break; case "add": if (Page.IsValid) { var txtAddSelectionName = (TextBox) e.Item.FindControl("txtAddSelectionName"); var txtAddSelectionValue = (TextBox) e.Item.FindControl("txtAddSelectionValue"); cfs = new CustomFieldSelection { CustomFieldId = Convert.ToInt32(e.CommandArgument), Name = txtAddSelectionName.Text.Trim(), Value = txtAddSelectionValue.Text.Trim() }; CustomFieldSelectionManager.SaveOrUpdate(cfs); } break; } BindCustomFieldSelections(); }