void SaveFile(XElement xElement, FlowChar flowChar) { string FileName = "Flow"; if (flowChar.Flowtype == 1) { FileName = "FlowChar"; } SaveFileDialog saveFile = new SaveFileDialog(); if (!string.IsNullOrEmpty(flowChar.FlowcharPath) && flowChar != null) { xElement.Save(flowChar.FlowcharPath); } else { string str1 = Directory.GetCurrentDirectory(); string Enclosure_Path = str1 + $"\\{FileName}"; if (!Directory.Exists(Enclosure_Path)) // 返回bool类型,存在返回true,不存在返回false { Directory.CreateDirectory(Enclosure_Path); //不存在则创建路径 } var filepath = Enclosure_Path + $"\\{DateTime.Now.ToString("yyyyMMddHHmmss")}" + ".xml"; flowChar.FlowcharPath = filepath; // saveFile.InitialDirectory = Enclosure_Path; //saveFile.Filter = "Files (*.xml)|*.xml|All Files (*.*)|*.*"; //if (saveFile.ShowDialog() == true) //{ //} try { xElement.Save(filepath); } catch (Exception ex) { MessageBox.Show(ex.StackTrace, ex.Message, MessageBoxButton.OK, MessageBoxImage.Error); } } if (FileName == "FlowChar") { //FlowChar flowcharcontrol = new FlowChar(); ////todo 文件名称通过截取,但是会有一点问题如果输入的名称是带点的话会有问题 //string[] strArray = saveFile.SafeFileName.Split('.'); //flowcharcontrol.Flowname = flowChar.Flowname; //flowcharcontrol.FlowcharPath = flowChar.FlowcharPath; //flowcharcontrol.IcoImage = flowChar.IcoImage; rememberClass.AddRemember(flowChar); } }
private void Save_Executed(object sender, ExecutedRoutedEventArgs e) { FlowChar flow = e.Parameter as FlowChar; if (string.IsNullOrEmpty(flow.Flowname) || flow.Flowname == "") { MessageBox.Show("流程名称不能为空", "提示信息"); return; } if (flow.Flowtype == 1 && string.IsNullOrEmpty(flow.IcoImage)) { MessageBox.Show("子流程图片不能为空", "提示信息"); return; } IEnumerable <DesignerItem> designerItems = this.Children.OfType <DesignerItem>(); IEnumerable <Connection> connections = this.Children.OfType <Connection>(); XElement designerItemsXML = SerializeDesignerItems(designerItems); XElement connectionsXML = SerializeConnections(connections); XElement root = new XElement("Root"); root.Add(designerItemsXML); root.Add(connectionsXML); SaveFile(root, flow); }
protected override void OnDrop(DragEventArgs e) { base.OnDrop(e); DragObject dragObject = e.Data.GetData(typeof(DragObject)) as DragObject; if (dragObject != null && !String.IsNullOrEmpty(dragObject.Xaml)) { //子流程的新建 if (dragObject.Xaml.Contains("子流程")) { FlowChar flowChar = new FlowChar(); string str1 = Directory.GetCurrentDirectory(); string Enclosure_Path = str1 + "\\FlowChar"; if (!Directory.Exists(Enclosure_Path)) // 返回bool类型,存在返回true,不存在返回false { Directory.CreateDirectory(Enclosure_Path); //不存在则创建路径 } var filepath = Enclosure_Path + $"\\{DateTime.Now.ToString("yyyyMMddhhmmssMM")}" + ".xml"; flowChar.FlowcharPath = filepath; flowChar.Flowname = "子流程1"; flowChar.IcoImage = "/WpfApp3;component/Image/flowchild.png"; flowChar.Flowtype = 1; XElement root = new XElement("Root"); try { root.Save(filepath); RememberClass rememberClass = this.Tag as RememberClass; rememberClass.AddRemember(flowChar, false); if (flowChar != null) { Grid grid = new Grid(); grid.Width = 80; grid.Height = 70; RowDefinition row1 = new RowDefinition(); RowDefinition row2 = new RowDefinition(); row2.Height = GridLength.Auto; grid.RowDefinitions.Add(row1); grid.RowDefinitions.Add(row2); Image image = new Image(); image.Source = new BitmapImage(new Uri(flowChar.IcoImage, UriKind.RelativeOrAbsolute)); Button button = new Button(); button.Content = "编辑"; button.Margin = new Thickness(5, 2, 5, 2); button.Tag = flowChar; button.Click += OpenFlowChar; grid.Children.Add(image); grid.Children.Add(button); Grid.SetRow(image, 0); Grid.SetRow(button, 1); DesignerItem newItem = null; // Object content = XamlReader.Load(XmlReader.Create(new StringReader(dragObject.Xaml))); newItem = new DesignerItem(); newItem.Content = grid; Point position = e.GetPosition(this); // Size desiredSize = dragObject.DesiredSize.Value; newItem.Width = grid.Width; newItem.Height = grid.Height; DesignerCanvas.SetLeft(newItem, Math.Max(0, position.X - newItem.Width / 2)); DesignerCanvas.SetTop(newItem, Math.Max(0, position.Y - newItem.Height / 2)); //else //{ // DesignerCanvas.SetLeft(newItem, Math.Max(0, position.X)); // DesignerCanvas.SetTop(newItem, Math.Max(0, position.Y)); //} Canvas.SetZIndex(newItem, this.Children.Count); this.Children.Add(newItem); SetConnectorDecoratorTemplate(newItem); //update selection this.SelectionService.SelectItem(newItem); newItem.Focus(); rememberClass.LoadFlowMD(); e.Handled = true; } } catch (Exception ex) { MessageBox.Show(ex.StackTrace, ex.Message, MessageBoxButton.OK, MessageBoxImage.Error); } } //基本流程 else { DesignerItem newItem = null; Object content = XamlReader.Load(XmlReader.Create(new StringReader(dragObject.Xaml))); if (content != null) { newItem = new DesignerItem(); newItem.Content = content; Point position = e.GetPosition(this); if (dragObject.DesiredSize.HasValue) { Size desiredSize = dragObject.DesiredSize.Value; newItem.Width = desiredSize.Width; newItem.Height = desiredSize.Height; DesignerCanvas.SetLeft(newItem, Math.Max(0, position.X - newItem.Width / 2)); DesignerCanvas.SetTop(newItem, Math.Max(0, position.Y - newItem.Height / 2)); } else { DesignerCanvas.SetLeft(newItem, Math.Max(0, position.X)); DesignerCanvas.SetTop(newItem, Math.Max(0, position.Y)); } Canvas.SetZIndex(newItem, this.Children.Count); this.Children.Add(newItem); SetConnectorDecoratorTemplate(newItem); //update selection this.SelectionService.SelectItem(newItem); newItem.Focus(); } e.Handled = true; } } else { FlowChar flowChar = e.Data.GetData(typeof(FlowChar)) as FlowChar; if (flowChar != null) { Grid grid = new Grid(); grid.Width = 80; grid.Height = 70; RowDefinition row1 = new RowDefinition(); RowDefinition row2 = new RowDefinition(); row2.Height = GridLength.Auto; grid.RowDefinitions.Add(row1); grid.RowDefinitions.Add(row2); Image image = new Image(); image.Source = new BitmapImage(new Uri(flowChar.IcoImage, UriKind.RelativeOrAbsolute)); Button button = new Button(); button.Content = "编辑"; button.Margin = new Thickness(5, 2, 5, 2); button.Tag = flowChar; button.Click += OpenFlowChar; grid.Children.Add(image); grid.Children.Add(button); Grid.SetRow(image, 0); Grid.SetRow(button, 1); DesignerItem newItem = null; // Object content = XamlReader.Load(XmlReader.Create(new StringReader(dragObject.Xaml))); newItem = new DesignerItem(); newItem.Content = grid; Point position = e.GetPosition(this); // Size desiredSize = dragObject.DesiredSize.Value; newItem.Width = grid.Width; newItem.Height = grid.Height; DesignerCanvas.SetLeft(newItem, Math.Max(0, position.X - newItem.Width / 2)); DesignerCanvas.SetTop(newItem, Math.Max(0, position.Y - newItem.Height / 2)); //else //{ // DesignerCanvas.SetLeft(newItem, Math.Max(0, position.X)); // DesignerCanvas.SetTop(newItem, Math.Max(0, position.Y)); //} Canvas.SetZIndex(newItem, this.Children.Count); this.Children.Add(newItem); SetConnectorDecoratorTemplate(newItem); //update selection this.SelectionService.SelectItem(newItem); newItem.Focus(); e.Handled = true; } } }
public void GetFlowChar(FlowChar flowchar) { Model.Tumodel = flowchar; Open_Executed(flowchar.FlowcharPath); }