Beispiel #1
0
        public static int LenB(string stTarget)
        {
            if (string.IsNullOrEmpty(stTarget))
            {
                return(0);
            }
            if (stTarget.Length == 0)
            {
                return(0);
            }


            int sumlength = 0;

            for (int i = 0; i <= stTarget.Length - 1; i++)
            {
                string str   = stTarget.Substring(i, 1);
                byte[] bytes = ExSjisEncoding.ucstojms(str);
                sumlength += bytes.Length;
            }

            return(sumlength);
        }
Beispiel #2
0
        public static bool IsFullString(string stTarget)
        {
            if (stTarget.Length == 0)
            {
                return(false);
            }
            if (stTarget.Length != 1)
            {
                return(false);
            }

            string str = stTarget.Substring(0, 1);

            byte[] bytes = ExSjisEncoding.ucstojms(str);
            if (bytes.Length == 2)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        private bool InputCheck2(string _text)
        {
            string _strText        = "";
            string _chktext        = "";
            int    _selectionStart = 0;

            switch (InputMode)
            {
            case geInputMode.Number:
                // 最大・最小入力値チェック
                _strText = this.Text;
                if (this.SelectedText != "")
                {
                    _strText = this.Text.Replace(this.SelectedText, "");
                }
                if (ExCast.zCDbl(_strText + _text) < this.MinNumber || ExCast.zCDbl(_strText + _text) > this.MaxNumber)
                {
                    return(false);
                }

                double _dbl = ExCast.zCDbl(_strText + _text);
                string strText;
                string str;
                if (this.DecimalNum > 0)
                {
                    if (this.DecimalNum == 1)
                    {
                        strText = _dbl.ToString("#,##0.00");
                        str     = strText.Substring(strText.Length - 1, 1);
                        if (str != "0")
                        {
                            return(false);
                        }
                    }
                    else if (this.DecimalNum == 2)
                    {
                        strText = _dbl.ToString("#,##0.000");
                        str     = strText.Substring(strText.Length - 1, 1);
                        if (str != "0")
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
                break;

            case geInputMode.ID:
            case geInputMode.Alphanumeric:
            case geInputMode.FullKana:
            case geInputMode.HalfKana:
            case geInputMode.FullShapeNative:
                if (ExCast.zCInt(this.MaxLengthB) != 0)
                {
                    if (ExString.IsFullString(_text) || ExString.LenB(_text) >= 2)
                    {
                        // 最大入力バイト数チェック
                        if (ExString.LenB(this.Text) - ExString.LenB(this.SelectedText) > ExCast.zCInt(this.MaxLengthB))
                        {
                            _chktext = this.Text + this.SelectedText;
                            for (int i = 1; i <= _chktext.Length; i++)
                            {
                                _chktext = _chktext.Substring(0, _chktext.Length - 1);
                                if (ExString.LenB(_chktext) <= ExCast.zCInt(this.MaxLengthB))
                                {
                                    _selectionStart     = this.SelectionStart + _text.Length;
                                    this.Text           = _chktext;
                                    this.SelectionStart = _selectionStart;
                                    break;
                                }
                            }
                            return(false);
                        }
                    }
                    else
                    {
                        // 最大入力バイト数チェック

                        if (ExString.LenB(this.Text + _text) - ExString.LenB(this.SelectedText) > ExCast.zCInt(this.MaxLengthB))
                        {
                            _chktext = this.Text + _text + this.SelectedText;
                            for (int i = 1; i <= _chktext.Length; i++)
                            {
                                _chktext = _chktext.Substring(0, _chktext.Length - 1);
                                if (ExString.LenB(_chktext) <= ExCast.zCInt(this.MaxLengthB))
                                {
                                    this.Text = _chktext;
                                    break;
                                }
                            }
                            return(false);
                        }
                    }
                }
                break;
            }

            // 全角チェック
            switch (InputMode)
            {
            case geInputMode.Number:
            case geInputMode.ID:
            case geInputMode.Alphanumeric:
                //case geInputMode.HalfKana:
                string strText = "";
                for (int i = 1; i <= this.Text.Length; i++)
                {
                    string str   = this.Text.Substring(i - 1, 1);
                    byte[] bytes = ExSjisEncoding.ucstojms(str);

                    // 全角は除く
                    if (bytes.Length == 1)
                    {
                        strText += str;
                    }
                }
                if (strText != this.Text)
                {
                    return(false);
                    //this.Text = strText;
                }
                break;
            }

            // 0入力チェック
            switch (InputMode)
            {
            case geInputMode.ID:
                if (this.Text + _text == "0")
                {
                    return(false);
                }
                break;
            }

            return(true);
        }