public void CalculatorButtonClicked(object keyData)
        {
            CalculatorKeyData calculatorKeyData = (CalculatorKeyData)keyData;
            var value = calculatorKeyData.KeyName;

            if (operationStringArr.Any(x => ResultString.EndsWith(x) && ResultString.EndsWith(value)))
            {
                return;
            }
            if (value == "C")
            {
                ResultString = "0";
                return;
            }
            if (ResultString == "0" || ResultString == "E")
            {
                ResultString = "";
            }
            //restricts the calculator input to max of 15 character length
            if (ResultString.Length >= 15 && !operationStringArr.Any(x => ResultString.Contains(x)))
            {
                return;
            }
            else if (ResultString.Length >= 15 && value != "=")
            {
                return;
            }
            ResultString += Convert.ToString(value);
            if (value == "=")
            {
                try{
                    ResultString = new DataTable().Compute(ResultString.TrimEnd('='), null).ToString();
                }
                catch (Exception ex) {
                    //returns error to user if any operation in the screen results in and error during parsing and computation
                    ResultString = "E";
                }
            }
        }
Esempio n. 2
0
 public void SaveResult(byte ReadByte)
 {
     ResultByte.Add(ReadByte);
     if (RawCmdKey.Contains(CmdKey))
     {
         if (ReadByte <= 0x7f)
         {
             AsciiCount++;
         }
         else
         {
             AsciiCount = 0;
         }
         if (ReadByte == '\n' && AsciiCount >= 3 && AsciiCount == ResultByte.Count)
         {
             ResultStringList.Add(ResultString.Replace("\r", ""));
             Log.shell(ResultString.Replace("\r", ""));
             ResultByte.Clear();
             AsciiCount = 0;
         }
         else if (ResultString.EndsWith("TS->") && ResultByte.Count > 4)
         {
             ResultByteList.Add(ResultByte.Take(ResultByte.Count - 4).ToArray());
             ResultStringList.Add("RawData Saved\n");
             ResultByte.RemoveRange(0, ResultByte.Count - 4);
             Log.shell(ResultStringList.Last());
             AsciiCount = 0;
         }
     }
     else if (ReadByte == '\n')
     {
         ResultStringList.Add(ResultString);
         Log.shell(ResultString.Replace("\r", ""));
         ResultByte.Clear();
     }
     ReadTime = DateTime.Now;
 }