private bool ParseDouble(string s, out double value) { bool ok = double.TryParse(s, NumberStyles.Float, CultureInfo.InvariantCulture, out value); if (!ok) { s = s.Contains('.') ? s.Replace(".", ",") : s.Replace(",", "."); ok = double.TryParse(s, NumberStyles.Float, CultureInfo.InvariantCulture, out value); } if (!ok) { Error.AddError(string.Format("Error while parsing string '{0}'", s), this.ClassName); } return(ok); }
public void FindMatchingFood(string selectedFood) { /* Find matching food from user selected food. If match is found, * display a tick and set the correct food image alpha to half */ if (customerList.transform.childCount <= 0) { return; } bool foodFound = false; GameObject[] currentOrder = foodList.GetCurrentOrder(); if (currentOrder.Length <= 0) { return; } foreach (GameObject order in currentOrder) { SpriteRenderer foodSprite = order.GetComponent <SpriteRenderer>(); if (foodSprite.sprite.name == selectedFood) { foodFound = true; foodSprite.color = new Color(1f, 1f, 1f, 0.5f); GameObject newTick = Instantiate(tick, order.transform.position, Quaternion.identity) as GameObject; newTick.transform.parent = tickGroup.transform; earningText.AddEarning(); } } checkAllMatching(); if (!foodFound) { Debug.Log(string.Format("Selected food {0} not found", selectedFood)); error.AddError(); } }
private void AddME(string me) { string x = Regex.Replace(me, @" ", ""); if (x.Length < 5) { return; } string meType = x.Substring(0, 2).ToLower(); if (meType != "sd" && meType != "cv") { return; } if (x[2] != '(') { return; } if (x.Last() != ')') { return; } string str = x.Substring(3, x.Length - 4); if (str == string.Empty) { return; } string[] numbers = str.Split(new char[] { '~' }, StringSplitOptions.RemoveEmptyEntries); if ((numbers.Length == 0) || (numbers.Length > 2)) { return; } double a, b; bool test; test = ParseDouble(numbers[0], out a); if (!test) { return; } b = a; if (numbers.Length == 2) { test = ParseDouble(numbers[1], out b); if (!test) { return; } } if (a > b) { Error.AddError(string.Format("({0}, {1}) do not represent a valid range for the measurement error.", a, b), this.ClassName); return; } this.ME = (meType == "sd") ? MeasurementError.NewSDError(a, b) : MeasurementError.NewCVError(a, b); return; }