Beispiel #1
0
 public void FromRegに無効な文字列を与えるとfalseが返る(int colMax, String str)
 {
     //setUp
     var sut = new Dat(new CtrlType[colMax]);
     const bool expected = false;
     //exercise
     var actual = sut.FromReg(str);
     //verify
     Assert.That(actual, Is.EqualTo(expected));
 }
Beispiel #2
0
        public void FromRegに無効な文字列を与えるとfalseが返る(int colMax, String str)
        {
            //setUp
            var        sut      = new Dat(new CtrlType[colMax]);
            const bool expected = false;
            //exercise
            var actual = sut.FromReg(str);

            //verify
            Assert.That(actual, Is.EqualTo(expected));
        }
Beispiel #3
0
 public void FromRegで初期化してtoRegで取り出す(int colMax, String str)
 {
     //setUp
     var ctrlTypeList = new CtrlType[colMax];
     for (var i = 0; i < colMax; i++) {
         ctrlTypeList[i] = CtrlType.Int;
     }
     var sut = new Dat(new CtrlType[colMax]);
     var expected = str;
     sut.FromReg(str);
     //exercise
     var actual = sut.ToReg(false);
     //verify
     Assert.That(actual, Is.EqualTo(expected));
 }
Beispiel #4
0
        public void FromRegで初期化してtoRegで取り出す(int colMax, String str)
        {
            //setUp
            var ctrlTypeList = new CtrlType[colMax];

            for (var i = 0; i < colMax; i++)
            {
                ctrlTypeList[i] = CtrlType.Int;
            }
            var sut      = new Dat(new CtrlType[colMax]);
            var expected = str;

            sut.FromReg(str);
            //exercise
            var actual = sut.ToReg(false);

            //verify
            Assert.That(actual, Is.EqualTo(expected));
        }
Beispiel #5
0
        //出力ファイル(Option.ini)からの入力用<br>
        //不正な文字列があった場合は、無効行として無視される<br>
        public bool FromReg(String str)
        {
            if (str == null){
                Value = null;
                return false;
            }
            switch (OneCtrl.GetCtrlType()){
                case CtrlType.Dat:
                    CtrlDat ctrlDat = (CtrlDat) OneCtrl;
                    Dat dat = new Dat(ctrlDat.CtrlTypeList);
                    if (!dat.FromReg(str)){
                        Value = null;
                        return false;
                    }
                    //Ver5.8.7 Java fix Datの中にComboBoxが存在する場合の旧バージョンの変換
                    foreach (var d in dat){
                        for (int i = 0; i < ctrlDat.ListVal.Count; i++){
                            if (ctrlDat.ListVal[i].OneCtrl.GetCtrlType() == CtrlType.ComboBox){
                                int val;
                                if(!int.TryParse(d.StrList[i],out val)){
                                    //Ver5.7.x以前のデータ
                                    OneVal dmy = new OneVal("dmy",null,Crlf.Nextline, ctrlDat.ListVal[i].OneCtrl);
                                    if (dmy.FromRegConv(d.StrList[i])){
                                        d.StrList[i] = dmy.ToReg(false);
                                    }
                                }

                            }
                        }
                    }
                    Value = dat;
                    break;
                case CtrlType.CheckBox:
                     try {
                        Value = Boolean.Parse(str);
                    } catch {
                        Value = false;
                        return false;
                    }
                    break;
                case CtrlType.Font:
                    Value = null;
                    var tmp = str.Split(',');
                    if (tmp.Length == 3){
                        try{

                            var family = new FontFamily(tmp[0]);
                            var size = (float) Convert.ToDouble(tmp[1]);
                            var style = (FontStyle) Enum.Parse(typeof (FontStyle), tmp[2]);
                            Value = new Font(family, size, style);
                        }catch(Exception){
                            Value = null;
                        }
                    }
                    if(Value==null){
                        return false;
                    }
                    break;
                case CtrlType.Memo:
                    Value = Util.SwapStr("\t", "\r\n", str);
                    break;
                case CtrlType.File:
                case CtrlType.Folder:
                case CtrlType.TextBox:
                    Value = str;
                    break;
                case CtrlType.Hidden:
                    try{
                        Value = Crypt.Decrypt(str);
                    }
                    catch (Exception){
                        Value = "";
                        return false;
                    }
                    break;
                case CtrlType.Radio:
                    try{
                        Value = Int32.Parse(str);
                    }catch (Exception){
                        Value = 0;
                        return false;
                    }
                    if ((int) Value < 0){
                        Value = 0;
                        return false;
                    }
                    break;
                case CtrlType.ComboBox:
                    int max = ((CtrlComboBox) OneCtrl).Max;
                    try {
                        var n = Int32.Parse(str);
                        if (n < 0 || max <= n) {
                            Value = 0;
                            return false;
                        }
                        Value = n;
                    } catch {
                        Value = 0;
                        //Ver5.9.2 Ver5.7.x以前のデータのコンバート
                        OneVal dmy = new OneVal("dmy", null, Crlf.Nextline, OneCtrl);
                        if (dmy.FromRegConv(str)) {
                            int n;
                            Int32.TryParse(dmy.ToReg(false), out n);
                            if (n < 0 || max <= n) {
                                Value = 0;
                                return false;
                            }
                            Value = n;
                        }
                        return false;
                    }
                    break;
                case CtrlType.Int:
                    try {
                        Value = Int32.Parse(str);
                    } catch {
                        Value = 0;
                        return false;
                    }
                    break;
                case CtrlType.BindAddr:
                    try{
                        Value = new BindAddr(str);
                    }
                    catch (ValidObjException){
                        Value = 0;
                        return false;
                    }
                    break;
                case CtrlType.AddressV4:
                    try{
                        Value = new Ip(str);
                    }
                    catch (ValidObjException){
                        Value = null;
                        return false;
                    }
                    break;
                case CtrlType.TabPage:
                case CtrlType.Group:
                    break;
                default:
                    Value = 0;
                    return false;
                    // "実装されていないCtrlTypeが指定されました OneVal.fromReg()"
            }
            return true;
        }