Beispiel #1
0
        // 삽입 시 중복 체크
        int checkDuplication(JsonTreeViewItem add_tvi)
        {
            if (add_tvi == null)
            {
                return(1);
            }

            JsonTextBox add_tb = add_tvi.Header.Children[0] as JsonTextBox;

            if (add_tb == null)
            {
                return(1);
            }

            // 중복 비교
            for (int i = 0; i < this.Items.Count; i++)
            {
                JsonTreeViewItem tvi = this.Items[i] as JsonTreeViewItem;
                if (tvi == null)
                {
                    continue;
                }

                JsonTextBox tb = tvi.Header.Children[0] as JsonTextBox;
                if (tb == null)
                {
                    continue;
                }
                // 키중복이면 삽입 x
                if (tb.Text == add_tb.Text)
                {
                    return(-1);
                }
            }
            return(0);
        }
Beispiel #2
0
        static void convertToJToken_recursive(JsonTreeViewItem tvi_cur, JObject jobj_cur)
        {
            if (tvi_cur == null || jobj_cur == null)
            {
                return;
            }

            JToken cur_jtok = jobj_cur;

            // 여기서부터는 property 로 시작
            foreach (var v in tvi_cur.Items)
            {
                JsonTreeViewItem tvi_child = v as JsonTreeViewItem;
                if (tvi_child == null)
                {
                    continue;
                }

                JsonTreeViewItemHeader pan = tvi_child.Header as JsonTreeViewItemHeader;
                if (pan == null)
                {
                    continue;
                }

                // pan(MyTreeViewItem.Header) = key, val or val.type, button
                JsonTextBox tb_key      = pan.Children[0] as JsonTextBox;
                ValuePanel  panel_value = pan.Children[1] as ValuePanel;

                switch (panel_value.type)
                {
                case JTokenType.Object:
                {
                    JObject   jobj  = new JObject();
                    JProperty jprop = new JProperty(tb_key.Text, jobj);
                    (cur_jtok as JObject).Add(jprop);
                    convertToJToken_recursive(tvi_child, jobj);
                }
                break;

                case JTokenType.Array:
                {
                    JArray    jarr  = new JArray();
                    JProperty jprop = new JProperty(tb_key.Text, jarr);
                    (cur_jtok as JObject).Add(jprop);
                    for (int i = 0; i < tvi_child.Items.Count; i++)
                    {
                        JObject jobj = new JObject();
                        jarr.Add(jobj);
                        convertToJToken_recursive(tvi_child.Items[i] as JsonTreeViewItem, jobj);
                    }
                }
                break;

                default:
                {
                    JProperty jprop = new JProperty(tb_key.Text, new JValue(panel_value.value));
                    (cur_jtok as JObject).Add(jprop);
                }
                break;
                }
            }
        }