public bool CheckDetailRequireByAppendCount(RequireData data, int index, int count, out string reason) { reason = null; if (data == null || data.Key == null || data.Maxval == null || data.Minval == null) { return(true); } if (data.Key.Length <= index) { return(false); } string[] key = data.Key; int[] min = data.Minval; int[] max = data.Maxval; string[] text = data.Text; CheckHandler handler; string k = key[index]; if (string.IsNullOrEmpty(k) || k == "0") { return(true); } string prefix = k.Substring(0, 1); handler = map.Get(prefix); if (handler == null) { return(false); } var tuple = handler.Invoke(k, min[index], max[index]); if (tuple.Item1 == false) { if (text != null && index < text.Length) { reason = text[index]; } return(false); } else { var checkVal = tuple.Item2 + count; if (max[index] == -1) { return(checkVal >= min[index]); } else { return(checkVal >= min[index] && checkVal < max[index]); } } }
public bool CheckRequire(RequireData data, out string reason) { reason = null; if (data == null || data.Key == null || data.Maxval == null || data.Minval == null) { return(true); } string[] key = data.Key; int[] min = data.Minval; int[] max = data.Maxval; string[] text = data.Text; CheckHandler handler; string prefix = null; string k = null; for (int i = 0; i < key.Length; i++) { try { k = key[i]; if (string.IsNullOrEmpty(k) || k == "0") { continue; } prefix = k.Substring(0, 1); k = k.Substring(1); handler = map.Get(prefix); if (handler == null) { return(false); } var tuple = handler.Invoke(k, min[i], max[i]); if (tuple.Item1 == false) { if (text != null && i < text.Length) { reason = text[i]; } return(false); } } catch (Exception) { string info = string.Format("checkRequire Error key={0},min={1},max={2},reason{3}", key[i], min[i], max[i]); throw new Exception(info); } } return(true); }
public async Task <List <RequireResult> > CheckRequireListAsync(RequireData data) { List <RequireResult> resultlist = new List <RequireResult>(); RequireResult rr = null; if (data == null || data.Key == null || data.Maxval == null || data.Minval == null) { rr = new RequireResult(); rr.Result = true; rr.Result = true; resultlist.Add(rr); return(resultlist); } string[] key = data.Key; int[] min = data.Minval; int[] max = data.Maxval; string[] text = data.Text; CheckHandlerAsync handler; string prefix = null; string k = null; for (int i = 0; i < key.Length; i++) { try { k = key[i]; if (string.IsNullOrEmpty(k) || k == "0") { continue; } rr = new RequireResult(); prefix = k.Substring(0, 1); k = k.Substring(1); handler = mapAsync.Get(prefix); if (handler == null) { rr.Result = false; rr.Reason = "can not find require handler"; } else { var ret = await handler.Invoke(k, min[i], max[i]); rr.Result = ret.Item1; rr.CurVal = ret.Item2; rr.MaxVal = max[i]; rr.MinVal = min[i]; if (text != null) { rr.Reason = text[i]; } } } catch (Exception) { string info = string.Format("checkRequire Error key={0},min={1},max={2},reason{3}", key[i], min[i], max[i], text[i]); throw new Exception(info); } resultlist.Add(rr); } return(resultlist); }
public async Task <RequireResult> CheckDetailRequireByAppendCountAsync(RequireData data, int index, int count) { RequireResult result = new RequireResult(); result.Result = true; if (data == null || data.Key == null || data.Maxval == null || data.Minval == null) { return(result); } if (data.Key.Length <= index) { result.Result = false; return(result); } string[] key = data.Key; int[] min = data.Minval; int[] max = data.Maxval; string[] text = data.Text; CheckHandlerAsync handler; string k = key[index]; if (string.IsNullOrEmpty(k) || k == "0") { return(result); } string prefix = k.Substring(0, 1); handler = mapAsync.Get(prefix); if (handler == null) { result.Result = false; return(result); } var tuple = await handler.Invoke(k, min[index], max[index]); if (tuple.Item1 == false) { result.Result = false; if (text != null && index < text.Length) { result.Reason = text[index]; } return(result); } else { var checkVal = tuple.Item2 + count; if (max[index] == -1) { if (checkVal < min[index]) { result.Result = false; if (text != null && index < text.Length) { result.Reason = text[index]; } } } else { if (!(checkVal >= min[index] && checkVal < max[index])) { result.Result = false; if (text != null && index < text.Length) { result.Reason = text[index]; } } } return(result); } }
public async Task <RequireResult> CheckRequireAsync(RequireData data) { RequireResult result = new RequireResult(); result.Result = true; result.Reason = string.Empty; if (data == null || data.Key == null || data.Maxval == null || data.Minval == null) { return(result); } string[] key = data.Key; int[] min = data.Minval; int[] max = data.Maxval; string[] text = data.Text; CheckHandlerAsync handler; string prefix = null; string k = null; for (int i = 0; i < key.Length; i++) { try { k = key[i]; if (string.IsNullOrEmpty(k) || k == "0") { return(result); } prefix = k.Substring(0, 1); k = k.Substring(1); handler = mapAsync.Get(prefix); if (handler == null) { result.Result = false; return(result); } var tuple = await handler.Invoke(k, min[i], max[i]); if (tuple.Item1 == false) { if (text != null && i < text.Length) { result.Reason = text[i]; } result.Result = false; return(result); } } catch (Exception) { string info = string.Format("checkRequire Error key={0},min={1},max={2},reason{3}", key[i], min[i], max[i]); throw new Exception(info); } } return(result); }