private void SaveItem_Click(object sender, RoutedEventArgs e) { SaveFileDialog ofd = new SaveFileDialog() { Title = "Введите имя файла", Filter = "json files (*.json)|*.json" }; if (ofd.ShowDialog() == true) { SaverClass.SaveData(ofd.FileName); } }
/// <summary> /// Загрузка схемы /// </summary> void OpenSchema() { OpenFileDialog ofd = new OpenFileDialog() { Title = "Выберите файл", Filter = "json files (*.json)|*.json" }; if (ofd.ShowDialog() == true) { EditorCanvas.Children.Clear(); GraphClass.Connections.Clear(); SaverClass.LoadData(ofd.FileName); GraphClass.ElementZIndex = 10000; GraphClass.ConnectionZIndex = 0; foreach (ElementClass element in SaverClass.Elements) { switch (element.Type) { case 10: { InOutControl inControl = GraphClass.CreateInControl(element); inControl.MainGrid.ContextMenu = new ContextMenu(); inControl.MainGrid.ContextMenu.Items.Add(new MenuItem() { Header = "_Соединить вход" }); (inControl.MainGrid.ContextMenu.Items[0] as MenuItem).Click += ConntectionMenuItem_Click; EditorCanvas.Children.Add(inControl); continue; } case 11: { EditorCanvas.Children.Add(GraphClass.CreateOutControl(element)); foreach (Guid id in element.InElements) { Connection connection = new Connection() { Start = SaverClass.Elements.First(c => c.Id == id), Finish = element }; connection.CalculatePoints(); Panel.SetZIndex(connection.Line, GraphClass.ConnectionZIndex++); GraphClass.Connections.Add(connection); EditorCanvas.Children.Add(connection.Line); } continue; } } ElementControl el = GraphClass.CreateElementControl(element, ConntectionMenuItem_Click); el.PreviewMouseMove += El_PreviewMouseMove; EditorCanvas.Children.Add(el); foreach (Guid id in element.InElements) { Connection connection = new Connection() { Start = SaverClass.Elements.First(c => c.Id == id), Finish = element }; connection.CalculatePoints(); Panel.SetZIndex(connection.Line, GraphClass.ConnectionZIndex++); GraphClass.Connections.Add(connection); EditorCanvas.Children.Add(connection.Line); } } } }