BTool.DeviceTabsForm.GATTWriteValueValidation C# (CSharp) Method

GATTWriteValueValidation() private method

private GATTWriteValueValidation ( string valStr ) : bool
valStr string
return bool
        private bool GATTWriteValueValidation(string valStr)
        {
            string str = string.Empty;
            if (rbHexWrite.Checked)
            {
                if (devUtils.String2Bytes_LSBMSB(valStr, (byte)16) != null)
                {
                    tbWriteValue.Tag = valStr;
                    return true;
                }
                else
                {
                    string msg = string.Format("Invalid Hex Value '{0}'\nFormat#1: 11:22:33:44:55:66\nFormat#2: 11 22 33 44 55 66\n", valStr);
                    msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error, msg);
                    return false;
                }
            }
            else if (rbDecimalWrite.Checked)
            {
                try
                {
                    byte[] bytes = BitConverter.GetBytes(Convert.ToUInt32(valStr, 10));
                    int index1 = bytes.Length - 1;
                    for (int index2 = 0; index2 < bytes.Length / 2; ++index2)
                    {
                        byte num = bytes[index2];
                        bytes[index2] = bytes[index1];
                        bytes[index1] = num;
                        --index1;
                    }
                    if (bytes != null)
                    {
                        bool flag = false;
                        for (byte index2 = (byte)0; (int)index2 < bytes.Length; ++index2)
                        {
                            if (!flag)
                            {
                                if ((int)index2 >= 3 || (int)bytes[(int)index2] != 0)
                                    flag = true;
                                else
                                    continue;
                            }
                            str = str + string.Format("{0:X2} ", bytes[(int)index2]);
                        }
                        tbWriteValue.Tag = str.Trim();
                        return true;
                    }
                    else
                    {
                        string msg = string.Format("Invalid Dec Value '{0}'\nValid Range 0 to 4294967295\n", valStr);
                        msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error, msg);
                        return false;
                    }
                }
                catch (Exception ex)
                {
                    string msg = string.Format("Invalid Dec Value '{0}'\nValid Range 0 to 4294967295\n\n{1}", valStr, ex.Message);
                    msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error, msg);
                    return false;
                }
            }
            else
            {
                if (!rbASCIIWrite.Checked)
                    return false;
                byte[] numArray = devUtils.String2Bytes_LSBMSB(valStr, byte.MaxValue);
                if (numArray != null)
                {
                    for (byte index = (byte)0; (int)index < numArray.Length; ++index)
                        str = str + string.Format("{0:X2} ", numArray[(int)index]);
                    tbWriteValue.Tag = str.Trim();
                    return true;
                }
                else
                {
                    string msg = string.Format("Invalid ASCII Value '{0}'\nFormat: Sample\n", valStr);
                    msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error, msg);
                    return false;
                }
            }
        }
DeviceTabsForm