private static void ExecuteFunction <T>(string keyString, string weightKey, ChangeWeightHandler <T> handler, Action <string> errorCallback) { T id; int weight; try { id = (T)Convert.ChangeType(keyString, typeof(T)); } catch (Exception e) { errorCallback(e.ToString()); return; } try { weight = Convert.ToInt32(weightKey); } catch (FormatException e) { errorCallback(Resources.SNotCorrectNumber); return; } handler(id, weight); }
public static bool ExecuteFunction <T>(string argument, string controlKey, ChangeWeightHandler <T> handlerDown, ChangeWeightHandler <T> handlerUp, Action <string> errorCallback) { var keyString = HttpContext.Current.Request.Form["keyMove" + controlKey]; var weightKey = HttpContext.Current.Request.Form["valueMove" + controlKey]; if (argument.StartsWith(MoveUpButton1)) { if (string.IsNullOrEmpty(keyString) || string.IsNullOrEmpty(weightKey)) { return(true); } ExecuteFunction(keyString, weightKey, handlerUp, errorCallback); return(true); } if (argument.StartsWith(MoveDownButton1)) { if (string.IsNullOrEmpty(keyString) || string.IsNullOrEmpty(weightKey)) { return(true); } ExecuteFunction(keyString, weightKey, handlerDown, errorCallback); return(true); } return(false); }
public static string MoveWeightButton(string argument, ChangeWeightHandler handlerDown, ChangeWeightHandler handlerUp) { var message = MoveWeightButton(argument, MoveDownButton1, "ChangeWeight1", handlerDown); if (message != null) { return(message); } message = MoveWeightButton(argument, MoveDownButton2, "ChangeWeight2", handlerDown); if (message != null) { return(message); } message = MoveWeightButton(argument, MoveUpButton1, "ChangeWeight1", handlerUp); if (message != null) { return(message); } message = MoveWeightButton(argument, MoveUpButton2, "ChangeWeight2", handlerUp); return(message); }
private static string MoveWeightButton(string argument, string argumentName, string fieldName, ChangeWeightHandler handler) { if (argument.StartsWith(argumentName) && !string.IsNullOrEmpty(HttpContext.Current.Request.Form[fieldName])) { int changeWeight; if (!int.TryParse(HttpContext.Current.Request.Params[fieldName], out changeWeight)) { return(Resources.SNotCorrectNumberForWeight); } long refSP = Convert.ToInt64(argument.Substring(argumentName.Length)); handler(refSP, changeWeight); } return(null); }