示例#1
0
        void myLine_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (MessageBox.Show("Delete Relationship?", "", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
            {
                Line line = (Line)sender;
                mainCanvas.Children.Remove(line);

                var query =
                    from entrys in Mapping
                    where GetLineName(entrys.Source, entrys.Target) == line.Name
                    select entrys;

                var todelete = query.FirstOrDefault();

                if (todelete != null)
                {
                    ListViewItem sourceItem = null;

                    foreach (ListViewItem sitem in ListBoxSource.Items)
                    {
                        if (sitem.Content.ToString() == todelete.Source)
                        {
                            sourceItem = sitem;
                        }
                    }

                    sourceItem.Height     = ITEMHEIGHT;
                    sourceItem.Background = Brushes.White;

                    DataMapping r = new DataMapping()
                    {
                        Source = todelete.Source,
                        Target = todelete.Target
                    };

                    Mapping.Remove(todelete);

                    if (this.MappingRowDeleted != null)
                    {
                        MappingRowDeleted(r);
                    }
                }
            }
        }
示例#2
0
        public void DrawLine(ListViewItem sourceItem, ListViewItem targetItem, bool isnew)
        {
            try
            {
                if (sourceItem != null)
                {
                    DrawingGroup hu       = VisualTreeHelper.GetDrawing(sourceItem);
                    Line         drawLine = new Line();
                    int          position = (ListBoxSource.Items.IndexOf(sourceItem));

                    drawLine.X1 = ListBoxSource.ActualWidth;   //X of LineStart
                    drawLine.Y1 = 9 + (position * ITEMHEIGHT); //Y of LineStart
                    double test = ListBoxTarget.Margin.Left;

                    drawLine.X2  = mainCanvas.ActualWidth; //X of LineEnd
                    drawLine.Y2  = 9;                      //Y of LineEnd
                    drawLine.Y2 -= (verticaloffset * 1);   //1.0021
                    drawLine.Y2 += (verticaoffsets * 1);
                    int post = (ListBoxTarget.Items.IndexOf(targetItem));
                    drawLine.Y2    += (post * ITEMHEIGHT);
                    drawLine.Stroke = new SolidColorBrush(Color.FromRgb(58, 162, 230));

                    sourceItem.Height     = ITEMHEIGHT;
                    sourceItem.Background = new SolidColorBrush(Color.FromRgb(58, 162, 230));
                    sourceItem.Foreground = Brushes.White;

                    drawLine.StrokeThickness = 1;

                    String name = GetLineName(sourceItem.Content.ToString(), targetItem.Content.ToString());

                    drawLine.Name = name;

                    if (!isnew)
                    {
                        mainCanvas.Children.Add(drawLine);
                    }

                    drawLine.MouseDown += new MouseButtonEventHandler(myLine_MouseDown);

                    if (isnew)
                    {
                        Boolean isallredimapped = false;
                        foreach (DataMapping item in mapping)
                        {
                            if (GetLineName(item.Source, item.Target) == name)
                            {
                                isallredimapped = true;
                            }
                        }
                        if (!isallredimapped)
                        {
                            mainCanvas.Children.Add(drawLine);
                            DataMapping r = new DataMapping()
                            {
                                Target = StoreTooltipInTargetMappingInsteadOfContent == false?targetItem.Content.ToString() : targetItem.ToolTip.ToString(),
                                             Source = StoreTooltipInSourceMappingInsteadOfContent == false?sourceItem.Content.ToString() : sourceItem.ToolTip.ToString()
                            };
                            Mapping.Add(r);

                            if (this.MappingRowAdded != null)
                            {
                                MappingRowAdded(r);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }