Пример #1
0
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.stackPanel1 = ((System.Windows.Controls.StackPanel)(target));
                return;

            case 2:
                this.label1 = ((System.Windows.Controls.Label)(target));
                return;

            case 3:
                this.source = ((BSky.Controls.DragDropList)(target));
                return;

            case 4:
                this.stackPanel2 = ((System.Windows.Controls.StackPanel)(target));
                return;

            case 5:
                this.label2 = ((System.Windows.Controls.Label)(target));
                return;

            case 6:
                this.funcat = ((System.Windows.Controls.ListBox)(target));
                return;

            case 7:
                this.stackPanel3 = ((System.Windows.Controls.StackPanel)(target));
                return;

            case 8:
                this.label3 = ((System.Windows.Controls.Label)(target));
                return;

            case 9:
                this.func = ((System.Windows.Controls.ListBox)(target));
                return;

            case 10:
                this.stackPanel4 = ((System.Windows.Controls.StackPanel)(target));
                return;

            case 11:
                this.label4 = ((System.Windows.Controls.Label)(target));
                return;

            case 12:
                this.funcdetails = ((System.Windows.Controls.TextBlock)(target));
                return;

            case 13:
                this.stackPanel5 = ((System.Windows.Controls.StackPanel)(target));
                return;

            case 14:
                this.label5 = ((System.Windows.Controls.Label)(target));
                return;

            case 15:
                this.expression = ((System.Windows.Controls.TextBox)(target));
                return;

            case 16:
                this.stackPanel6 = ((System.Windows.Controls.StackPanel)(target));
                return;

            case 17:
                this.label6 = ((System.Windows.Controls.Label)(target));
                return;

            case 18:
                this.target = ((System.Windows.Controls.TextBox)(target));
                return;

            case 19:
                this.textBlock1 = ((System.Windows.Controls.TextBlock)(target));
                return;
            }
            this._contentLoaded = true;
        }
        //private void ListBox_MouseMove(object sender, MouseButtonEventArgs e)
        //{
        //    if (e.LeftButton == MouseButtonState.Pressed)
        //    {
        //        object data = ((ListBox)(FrameworkElement)sender).SelectedItem;
        //        if (data != null)
        //            DragDrop.DoDragDrop(this, data, DragDropEffects.Copy);
        //    }
        //}

        public override void ListBox_Drop(object sender, DragEventArgs e)
        {
            DragDropList             tempDragDropList             = null;
            DragDropListForSummarize tempDragDropListForSummarize = null;
            Boolean autoVarTemp = false;

            if (BSkyCanvas.sourceDrag is DragDropList)
            {
                tempDragDropList = BSkyCanvas.sourceDrag as DragDropList;
                autoVarTemp      = tempDragDropList.AutoVar;
            }
            else if (BSkyCanvas.sourceDrag is DragDropListForSummarize)
            {
                tempDragDropListForSummarize = BSkyCanvas.sourceDrag as DragDropListForSummarize;
                autoVarTemp = tempDragDropListForSummarize.AutoVar;
            }

            string[] formats = e.Data.GetFormats();

            //BSkyCanvas.destDrag = (ListBox)sender;
            //The code below disables drag and drop on the source list, added June 16th
            int destindex, i, j, sourceindex, noofitems;

            System.Windows.Forms.DialogResult diagResult;
            //object[] newlist =null;
            //Aaron Modified 11/04
            //Code below prevents me from doing a move where the source and destination are the source list
            if (AutoVar == false && this == (ListBox)BSkyCanvas.sourceDrag)
            {
                e.Effects = DragDropEffects.None;
                return;
            }
            if (formats.Length > 0)
            {
                object             sourcedata = e.Data.GetData(formats[0]) as object;
                ListCollectionView list       = this.ItemsSource as ListCollectionView;

                if (sourcedata != null)
                {
                    //Soure and destination are different. I copy the selected item to the target
                    if ((this != (ListBox)BSkyCanvas.sourceDrag) && (AutoVar == false))
                    {
                        if (list.IndexOf(sourcedata) < 0)
                        {
                            list.AddNewItem(sourcedata);
                            list.CommitNew();

                            //this.SelectedItem = d;
                            //e.Effects =  DragDropEffects.All;
                            this.ScrollIntoView(sourcedata);//AutoScroll
                        }

                        else
                        {
                            e.Effects = DragDropEffects.None;
                        }
                        //this.UnselectAll();
                        //02/24 Aaron
                        //This is to signify that since the source and destination are different, we have finished the copy.
                        //We will go back to the initiation of the drag and drop to see if the source needs to be removed or kept
                        // in the source listbox. This will be determined by the value of movevariables property
                        //e.Effects is set to DragDropEffects.Copy to signify that the selected item has been copies to the destination control
                        e.Effects         = DragDropEffects.Copy;
                        this.SelectedItem = sourcedata;
                        Focus();
                    }

                    //Aaron 09/11/2013
                    //Here I am moving to a target that has 0 or 1 item
                    //If the target has 1 item (it cannot have more than one as I prevent this)
                    //I remove the itemin the target and add it back to the source
                    //ONE OF THE LISTBOXES MUST BE THE SOURCE LISTBOXES
                    else if ((this != (ListBox)BSkyCanvas.sourceDrag) && (AutoVar == true) && (autoVarTemp == false))
                    {
                        ListCollectionView srcList = BSkyCanvas.sourceDrag.ItemsSource as ListCollectionView;
                        noofitems = list.Count;
                        object[] arr = new object[noofitems];

                        //Adding the items in the target to the source before adding new item to the target
                        for (i = 0; i < noofitems; i++)
                        {
                            arr[i] = list.GetItemAt(i);
                            srcList.AddNewItem(arr[i]);
                            srcList.CommitNew();
                        }
                        //Removing all items from the target
                        for (i = 0; i < noofitems; i++)
                        {
                            list.Remove(arr[i]);
                        }
                        //Adding new item to the target
                        list.AddNewItem(sourcedata);
                        list.CommitNew();
                        // list.Refresh();
                        this.SelectedItem = sourcedata;
                        e.Effects         = DragDropEffects.Copy;
                        Focus();
                    }

                    //Aaron 09/11/2013
                    //If the grouping variable target list box has an item, we want to disallow dragging and dropping from another target to the grouping variable target.
                    //This could crate problems with filter handling
                    //We want to prompt the user to move the variable in teh grouping variable to the source
                    else if ((this != (ListBox)BSkyCanvas.sourceDrag) && (autoVarTemp == true) && (AutoVar == true))
                    {
                        ListCollectionView srcList = BSkyCanvas.sourceDrag.ItemsSource as ListCollectionView;
                        noofitems = list.Count;
                        object[] arr = new object[noofitems];

                        if (noofitems == 1)
                        {
                            diagResult = System.Windows.Forms.MessageBox.Show("Please remove the variable from the grouping variable list before initiating the drag and drop", "Message", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Question);
                            e.Effects  = DragDropEffects.None;
                            BSkyCanvas.sourceDrag.SelectedItem = null;
                            this.Focus();
                            return;
                        }

                        //Adding the items in the target to the source before adding new item to the target
                        for (i = 0; i < noofitems; i++)
                        {
                            arr[i] = list.GetItemAt(i);
                            srcList.AddNewItem(arr[i]);
                            srcList.CommitNew();
                        }
                        //Removing all items from the target
                        for (i = 0; i < noofitems; i++)
                        {
                            list.Remove(arr[i]);
                        }
                        //Adding new item to the target
                        list.AddNewItem(sourcedata);
                        list.CommitNew();
                        // list.Refresh();
                        // this.Focus();
                        this.SelectedItem = sourcedata;
                        e.Effects         = DragDropEffects.Copy;
                        this.Focus();
                    }
                    //The source and the destination are the same i.e. the target variable
                    else
                    {
                        e.Effects = DragDropEffects.None;
                    }
                } //sourcedata |=null
            }
        }
 void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) {
     switch (connectionId)
     {
     case 1:
     this.stackPanel1 = ((System.Windows.Controls.StackPanel)(target));
     return;
     case 2:
     this.label1 = ((System.Windows.Controls.Label)(target));
     return;
     case 3:
     this.source = ((BSky.Controls.DragDropList)(target));
     return;
     case 4:
     this.stackPanel2 = ((System.Windows.Controls.StackPanel)(target));
     return;
     case 5:
     this.label2 = ((System.Windows.Controls.Label)(target));
     return;
     case 6:
     this.funcat = ((System.Windows.Controls.ListBox)(target));
     return;
     case 7:
     this.stackPanel3 = ((System.Windows.Controls.StackPanel)(target));
     return;
     case 8:
     this.label3 = ((System.Windows.Controls.Label)(target));
     return;
     case 9:
     this.func = ((System.Windows.Controls.ListBox)(target));
     return;
     case 10:
     this.stackPanel4 = ((System.Windows.Controls.StackPanel)(target));
     return;
     case 11:
     this.label4 = ((System.Windows.Controls.Label)(target));
     return;
     case 12:
     this.funcdetails = ((System.Windows.Controls.TextBlock)(target));
     return;
     case 13:
     this.stackPanel5 = ((System.Windows.Controls.StackPanel)(target));
     return;
     case 14:
     this.label5 = ((System.Windows.Controls.Label)(target));
     return;
     case 15:
     this.expression = ((System.Windows.Controls.TextBox)(target));
     return;
     case 16:
     this.stackPanel6 = ((System.Windows.Controls.StackPanel)(target));
     return;
     case 17:
     this.label6 = ((System.Windows.Controls.Label)(target));
     return;
     case 18:
     this.target = ((System.Windows.Controls.TextBox)(target));
     return;
     case 19:
     this.textBlock1 = ((System.Windows.Controls.TextBlock)(target));
     return;
     }
     this._contentLoaded = true;
 }