private void OnClickButtonSaveJsonFile(object sender, RoutedEventArgs e) { if (JsonInfo.current == null) { return; } if (JsonInfo.current.Path == null) { OnClickButtonOtherSaveJsonFile(sender, e); return; } FileInfo f = new FileInfo(JsonInfo.current.Path); if (!f.Exists) { OnClickButtonOtherSaveJsonFile(sender, e); return; } // root JsonTreeViewItem = TreeView.Items[0] JsonTreeViewItem root = json_tree_view.Items[0] as JsonTreeViewItem; if (root == null) { return; } JToken Jtok_root = JsonTreeViewItem.convertToJToken(root); FileContoller.write(JsonInfo.current.Path, Jtok_root.ToString()); }
private void OnTextChanged_value(object sender, TextChangedEventArgs e) { TextBox tb = sender as TextBox; Console.WriteLine(cur_jsonfile.jroot.ToString()); Console.WriteLine(cur_jsonfile.GetHashCode()); FileContoller.write(cur_jsonfile.filename, cur_jsonfile.jroot.ToString()); }
public static void save() { if (!FileContoller.write(ServerInfo.PATH, ServerInfo.jobj_root.ToString())) { string caption = "save error"; string message = "serverinfo.json 파일을 저장하는데 문제가 생겼습니다."; MessageBox.Show(message, caption); Console.WriteLine("[" + caption + "] " + message); } }
private void SaveFile(string path) { if (!CheckJson()) { return; } JToken Jtok_root = JsonTreeViewItem.convertToJToken(json_tree_view.Items[0] as JsonTreeViewItem); if (FileContoller.write(path, Jtok_root.ToString())) { MessageBox.Show(path + " 파일이 저장되었습니다.", "save"); } else { string caption = "save error"; string message = path + " 파일을 저장하는데 문제가 생겼습니다."; MessageBox.Show(message, caption); Console.WriteLine("[" + caption + "] " + message); } }
void addKeyTextBox(Panel pan, string key, List <string> key_stack) { string[] arr = new string[key_stack.Count]; key_stack.CopyTo(arr); TextBox tb_key = new TextBox(); tb_key.Text = key; tb_key.Margin = new Thickness(5); tb_key.Width = 150; //tb_key.IsEnabled = false; tb_key.TextChanged += delegate(object sender, TextChangedEventArgs e) { JToken tmp = cur_jsonfile.jtoken; for (int i = 0; i < arr.Length; i++) { if (tmp is JObject) { tmp = ((JObject)tmp).GetValue(arr[i]); } else if (tmp is JArray) { tmp = ((JArray)tmp)[Convert.ToInt16(arr[i])]; } else { break; } } tmp[tb_key.Text] = tmp[key]; tmp[key].Parent.Remove(); //(tmp[key] as JProperty).Remove(); FileContoller.write(cur_jsonfile.filename, cur_jsonfile.jtoken.ToString()); }; pan.Children.Add(tb_key); //tb_key.SetValue(Grid.ColumnProperty, 0); }
void addValueTextBox(Panel pan, string key, string data, List <string> key_stack) { string[] arr = new string[key_stack.Count]; key_stack.CopyTo(arr); TextBox tb_value = new TextBox(); tb_value.Text = data; tb_value.Margin = new Thickness(5); tb_value.Width = 150; tb_value.TextChanged += delegate(object sender, TextChangedEventArgs e) { JToken tmp = cur_jsonfile.jtoken; for (int i = 0; i < arr.Length; i++) { if (tmp is JObject) { tmp = ((JObject)tmp).GetValue(arr[i]); } else if (tmp is JArray) { tmp = ((JArray)tmp)[Convert.ToInt16(arr[i])]; } else { break; } } tmp[key] = tb_value.Text; FileContoller.write(cur_jsonfile.filename, cur_jsonfile.jtoken.ToString()); }; //tb_value.TextChanged += Tb_value_TextChanged; pan.Children.Add(tb_value); //tb_value.SetValue(Grid.ColumnProperty, 1); }
private void OnClickButtonOtherSaveJsonFile(object sender, RoutedEventArgs e) { if (JsonInfo.current == null) { return; } SaveFileDialog sfd = new SaveFileDialog(); sfd.InitialDirectory = root_path; if (JsonInfo.current.Path != null) { string dir_path = JsonInfo.current.Path.Substring(0, JsonInfo.current.Path.LastIndexOf('\\') + 1); DirectoryInfo d = new DirectoryInfo(dir_path); if (d.Exists) { sfd.InitialDirectory = dir_path; } } sfd.Filter = "JSon Files (.json)|*.json"; if (sfd.ShowDialog(this) == true) { // root JsonTreeViewItem = TreeView.Items[0] JsonTreeViewItem root = json_tree_view.Items[0] as JsonTreeViewItem; if (root == null) { return; } JToken Jtok_root = JsonTreeViewItem.convertToJToken(root); FileContoller.write(sfd.FileName, Jtok_root.ToString()); JsonInfo.current.Path = sfd.FileName; } }
void addButtonDeletejson(Panel pan, List <string> key_stack) { System.Windows.Controls.Button btn = new System.Windows.Controls.Button(); btn.Content = '-'; btn.Background = Brushes.White; btn.BorderBrush = Brushes.Black; btn.Width = 20; btn.Height = 20; btn.VerticalContentAlignment = VerticalAlignment.Center; btn.HorizontalContentAlignment = HorizontalAlignment.Center; string[] arr_key_stack = new string[key_stack.Count]; key_stack.CopyTo(arr_key_stack); btn.Click += delegate(object sender, RoutedEventArgs e) { TreeViewItem parent = pan.Parent as TreeViewItem; if (parent != null) { if (parent.Header == pan) { TreeViewItem grandparent = parent.Parent as TreeViewItem; if (grandparent != null) { grandparent.Items.Remove(parent); } } else { parent.Items.Remove(pan); } } JToken tmp = cur_jsonfile.jtoken; for (int i = 0; i < arr_key_stack.Length; i++) { if (tmp is JObject) { tmp = ((JObject)tmp).GetValue(arr_key_stack[i]); } else if (tmp is JArray) { tmp = ((JArray)tmp)[Convert.ToInt16(arr_key_stack[i])]; } else { break; } } string key; TextBox tb = pan.Children[0] as TextBox; if (tb != null) { key = tb.Text; JToken jt = tmp[key]; if (jt != null) { tmp[key].Parent.Remove(); } } FileContoller.write(cur_jsonfile.filename, cur_jsonfile.jtoken.ToString()); }; pan.Children.Add(btn); //btn.SetValue(Grid.ColumnProperty, 2); }
public static void save() { FileContoller.write(ServerInfo.PATH, ServerInfo.jobj_root.ToString()); }
private void Button_Click(object sender, EventArgs e) { Console.WriteLine(cur_jsonfile.jroot.ToString()); Console.WriteLine(cur_jsonfile.GetHashCode()); FileContoller.write(cur_jsonfile.filename, cur_jsonfile.jroot.ToString()); }