private void DataGrid_CellDrop(object sender, DragEventArgs e)
        {
            DataGridCell dgc = sender as DataGridCell;

            if (_draggedData != null && !_isMultipleCells)
            {
                MappedValue selectedCell = _draggedData as MappedValue;

                RowViewModel     sourceRowModel    = (selectedCell.RowBinding as RowViewModel);
                ColumnsViewModel sourceColumnModel = (selectedCell.ColumnBinding as ColumnsViewModel);


                RowViewModel     targetRowModel    = ((BindableColumn.ViewModel.RowViewModel)(dgc.DataContext));
                ColumnsViewModel targetColumnModel = ((BindableColumn.ViewModel.ColumnsViewModel)((dgc.Column).Header));

                targetCell = targetRowModel.Name + targetColumnModel.Currency;
                sourceCell = sourceRowModel.Name + sourceColumnModel.Currency;


                if (sourceCell == targetCell)
                {
                    RemoveDraggedAdorner();
                    RemoveInsertionAdorner();
                    (this._sourceItemsControl as DataGrid).UnselectAllCells();
                    dgc.IsSelected = false;
                    return;
                }

                MappedValueCollection mappedValueCollection = this._mappedValueCollection;
                var movingCellData = mappedValueCollection.ReturnIfExistAddIfNot(sourceColumnModel, sourceRowModel);

                if (mappedValueCollection.AddCellValue(targetRowModel, targetColumnModel, movingCellData))
                {
                    if (movingCellData.Value != null)
                    {
                        dgc.IsSelected = true;
                    }

                    mappedValueCollection.EmptyCellValue(sourceRowModel, sourceColumnModel);
                }
            }
            else if (_draggedData != null && _isMultipleCells)
            {
                RowViewModel     targetRowModel    = ((BindableColumn.ViewModel.RowViewModel)(dgc.DataContext));
                ColumnsViewModel targetColumnModel = ((BindableColumn.ViewModel.ColumnsViewModel)((dgc.Column).Header));

                targetCell = targetRowModel.Name + targetColumnModel.Currency;

                if (MoveMultipleCells(targetCell, this._multipleDraggedData.Count))
                {
                    this._multipleDraggedData.Clear();
                }
            }

            RemoveDraggedAdorner();
            RemoveInsertionAdorner();
            this._multipleDraggedData.Clear();
            (this._sourceItemsControl as DataGrid).UnselectAllCells();
        }
        private Dictionary <string, object> GetNextAvailableCells(string targetCell, int countOfCells)
        {
            string rowPosition;
            string columnPosition;

            Dictionary <string, object> _availableCells = new Dictionary <string, object>();

            char[]   arrayofAlphabets = new char[] { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P' };
            string[] arrayofNumbers   = new string[] { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12" };

            bool isRowAlphabet = !String.IsNullOrEmpty(targetCell) && Char.IsLetter(targetCell.ToCharArray()[0]);

            GetPlate_RowColumnPosition(isRowAlphabet, targetCell, out rowPosition, out columnPosition);


            int rowCount    = isRowAlphabet ? Array.IndexOf(arrayofAlphabets, Convert.ToChar(rowPosition)) : Convert.ToInt32(rowPosition);
            int columnCount = !isRowAlphabet?Array.IndexOf(arrayofNumbers, Convert.ToChar(columnPosition)) : Convert.ToInt32(columnPosition);

            ObservableCollection <RowViewModel>     RowCollection     = (this._sourceDataContext as MainWindowViewModel).RowCollection;
            ObservableCollection <ColumnsViewModel> ColumnsCollection = (this._sourceDataContext as MainWindowViewModel).ColumnsCollection;
            MappedValueCollection RowColumnValues = (this._sourceDataContext as MainWindowViewModel).RowColumnValues;


            for (int currentRow = rowCount; currentRow < RowCollection.Count; currentRow++)
            {
                string row            = isRowAlphabet ? Convert.ToString(arrayofAlphabets[currentRow]) : string.Format("{0:D2}", currentRow);
                var    tempRowBinding = RowCollection.Where(q => q.Name.Equals(row)).FirstOrDefault();

                for (int currentColumn = columnCount; currentColumn < ColumnsCollection.Count; currentColumn++)
                {
                    if (countOfCells == _availableCells.Count)
                    {
                        break;
                    }
                    else
                    {
                        string column = !isRowAlphabet?Convert.ToString(arrayofAlphabets[currentColumn]) : string.Format("{0:D2}", currentColumn);

                        var         tempColumnBinding = ColumnsCollection.Where(p => p.Currency.Equals(column)).FirstOrDefault();
                        string      currentCell       = row + column;
                        MappedValue tempRowColumn     = RowColumnValues.Where(Z => Z.RowBinding == tempRowBinding && Z.ColumnBinding == tempColumnBinding).FirstOrDefault();

                        if (tempRowColumn.Value == null || (tempRowColumn.Value != null && (tempRowColumn.Value as CellData).ColorName == null))
                        {
                            _availableCells.Add(currentCell, tempRowColumn);
                        }
                    }
                }

                if (countOfCells == _availableCells.Count)
                {
                    break;
                }
            }


            return(_availableCells);
        }
Beispiel #3
0
 public override string GetValue()
 {
     if (!IsAnonymous)
     {
         return(MappedValue.GetValue());
     }
     else
     {
         return(VarName);
     }
 }
        private object GetDataForBinding()
        {
            if (_multipleDraggedData.Count >= 1)
            {
                var         key        = this._multipleDraggedData.First();
                MappedValue dataToSend = this._multipleDraggedData[key.Key] as MappedValue;
                _multipleDraggedData.Remove(key.Key);

                return(dataToSend);
            }

            return(null);
        }
        private bool ExchangeData(Dictionary <string, object> availableCells)
        {
            if (availableCells.Count > 1)
            {
                foreach (KeyValuePair <string, object> movingCellData in availableCells)
                {
                    MappedValueCollection mappedValueCollection = this._mappedValueCollection;
                    var CellData    = mappedValueCollection.ReturnIfExistAddIfNot((movingCellData.Value as MappedValue).ColumnBinding, (movingCellData.Value as MappedValue).RowBinding);
                    var bindingData = GetDataForBinding();

                    if (bindingData != null)
                    {
                        CellData.Value = (bindingData as MappedValue).Value;
                        MappedValue value = this._mappedValueCollection.ReturnIfExistAddIfNot((bindingData as MappedValue).ColumnBinding, (bindingData as MappedValue).RowBinding);
                        value.Value = null;
                    }
                }
                return(true);
            }
            return(false);
        }
        private void DragSource_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
        {
            IList <DataGridCellInfo> selectedCells = (sender as DataGrid).SelectedCells;

            this._multipleDraggedData.Clear();

            selectedCells.ToList().ForEach(x =>
            {
                RowViewModel rowModel        = x.Item as RowViewModel;
                ColumnsViewModel columnModel = x.Column.Header as ColumnsViewModel;
                MappedValue value            = AttachedColumnBehavior.GetMappedValues(sender as DependencyObject).ReturnIfExistAddIfNot(columnModel, rowModel);

                var selectedCell = rowModel.Name + columnModel.Currency;

                if (value.Value != null && selectedCells.Count > 1 && !_multipleDraggedData.ContainsKey(selectedCell))
                {
                    this._multipleDraggedData.Add(selectedCell, value);
                }
            });

            _isMultipleCells = selectedCells.Count > 1;
        }
        private void DropTarget_PreviewDrop(object sender, DragEventArgs e)
        {
            object draggedItem = e.Data.GetData(this._format.Name);

            int indexRemoved = -1;

            if (draggedItem != null)
            {
                if ((e.Effects & DragDropEffects.Move) != 0 && (this._sourceItemsControl == this._targetItemsControl || GetIsDropRejectFromOthers(this._targetItemsControl)))
                {
                    this._targetDataContext = (sender as DataGrid).DataContext;

                    // Remove the selected Cell here from Mapped Values
                    DataGrid dgc = sender as DataGrid;

                    RowViewModel     sourceRowHeader    = ((RowViewModel)(dgc.CurrentItem));
                    ColumnsViewModel sourceColumnHeader = ((ColumnsViewModel)((dgc.CurrentColumn).Header));
                    string           srcCell            = sourceRowHeader.Name + sourceColumnHeader.Currency;


                    MappedValueCollection sourceCell  = AttachedColumnBehavior.GetMappedValues(sender as DependencyObject);
                    MappedValue           mappedValue = sourceCell.ReturnIfExistAddIfNot(sourceColumnHeader, sourceRowHeader);
                    int getIndex = sourceCell.IndexOf(mappedValue);

                    //var hitTestInfo = (sender as DataGrid).InputHitTest(new Point{ X = e.})

                    sourceCell[getIndex].Value = (draggedItem as MappedValue).Value;


                    //indexRemoved = RemoveItemFromItemsControl(this._sourceItemsControl, draggedItem);
                }
                // This happens when we drag an item to a later position within the same ItemsControl.
                if (indexRemoved != -1 && this._sourceItemsControl == this._targetItemsControl && indexRemoved < this._insertionIndex)
                {
                    this._insertionIndex--;
                }
                if (!GetIsDropRejectFromOthers(this._targetItemsControl))
                {
                    IEnumerable itemsSource      = _targetItemsControl.ItemsSource;
                    Type        type             = itemsSource.GetType();
                    Type        genericIListType = type.GetInterface("IList`1");
                    int         elementsCount    = 0;
                    if (genericIListType != null)
                    {
                        elementsCount = (int)type.GetProperty("Count").GetValue(itemsSource, null);
                    }
                    if (elementsCount > this._insertionIndex)
                    {
                        RemoveItemFromItemsControlByIndex(this._targetItemsControl, this._insertionIndex);
                        InsertItemInItemsControl(this._targetItemsControl, draggedItem, this._insertionIndex);

                        if (this._sourceItemsControl == this._targetItemsControl)
                        {
                            Type   draggedType = draggedItem.GetType();
                            object newitem     = Activator.CreateInstance(draggedType);
                            InsertItemInItemsControl(this._sourceItemsControl, newitem, indexRemoved);
                        }
                    }
                }
                else
                {
                    Type   draggedType = draggedItem.GetType();
                    object newitem     = Activator.CreateInstance(draggedType);
                    //InsertItemInItemsControl(this._sourceItemsControl, newitem, indexRemoved);
                }

                RemoveDraggedAdorner();
                RemoveInsertionAdorner();
            }
            e.Handled = true;
        }
        private void recursive_process_file(XmlReader readerXml, Stack <GenericXmlNode> currentStack, GenericXmlMappingSet set, GenericXmlReaderResults returnValue)
        {
            // Create the list of nodes to this point from the stack
            List <GenericXmlNode> currentReverseList = currentStack.ToList();

            // THis is now on THIS element, so move to the next, unless there were none
            if (!readerXml.Read())
            {
                return;
            }

            // Create the path for this
            GenericXmlPath currentPath = new GenericXmlPath();

            for (int j = currentReverseList.Count - 1; j >= 0; j--)
            {
                currentPath.PathNodes.Add(currentReverseList[j]);
            }

            //// First, handle any attributes
            //if (readerXml.HasAttributes)
            //{
            //    // Create the list of nodes to this point
            //    for (int i = 0; i < readerXml.AttributeCount; i++)
            //    {
            //        // Move to this attribute
            //        readerXml.MoveToAttribute(i);

            //        // Create the path for this
            //        GenericXmlPath thisPath = new GenericXmlPath();
            //        for (int j = currentReverseList.Count - 1; j >= 0; j--)
            //        {
            //            thisPath.PathNodes.Add(currentReverseList[j]);
            //        }
            //        thisPath.AttributeName = readerXml.Name;

            //        // Get the value for this path
            //        string attributeValue = readerXml.Value;

            //        // Does mapping exist for this path?
            //        PathMappingInstructions instructions = set.Get_Matching_Path_Instructions(thisPath);

            //        // If instructions, this was mapped
            //        if ((instructions != null) && (!String.IsNullOrEmpty(instructions.SobekMapping)))
            //        {
            //            MappedValue thisMappedValue = new MappedValue();
            //            thisMappedValue.Mapping = instructions.SobekMapping;
            //            thisMappedValue.Path = thisPath;
            //            thisMappedValue.Value = attributeValue;

            //            returnValue.MappedValues.Add(thisMappedValue);
            //        }
            //    }

            //    // Move back to the main element after handing the attributes
            //    readerXml.MoveToElement();
            //}



            // Now, iterate through all the child elements that may exist
            while (readerXml.Read())
            {
                //if (readerXml.NodeType == XmlNodeType.Text)
                //{
                //    // Create the path for this
                //    GenericXmlPath thisPath = new GenericXmlPath();
                //    for (int j = currentReverseList.Count - 1; j >= 0; j--)
                //    {
                //        thisPath.PathNodes.Add(currentReverseList[j]);
                //    }

                //    // Does mapping exist for this path?
                //    PathMappingInstructions instructions = set.Get_Matching_Path_Instructions(thisPath);

                //    // Get the value for this path
                //    string textValue = readerXml.Value;

                //    // If instructions, this was mapped
                //    if ((instructions != null) && ( !String.IsNullOrEmpty(instructions.SobekMapping)))
                //    {
                //        MappedValue thisMappedValue = new MappedValue();
                //        thisMappedValue.Mapping = instructions.SobekMapping;
                //        thisMappedValue.Path = thisPath;
                //        thisMappedValue.Value = textValue;

                //        returnValue.MappedValues.Add(thisMappedValue);
                //    }
                //}

                bool text_found = false;
                if (readerXml.NodeType == XmlNodeType.Element)
                {
                    // Create the node for this top-level element
                    string         nodeName = readerXml.Name;
                    GenericXmlNode topNode  = new GenericXmlNode {
                        NodeName = nodeName
                    };

                    // Add this to the stack
                    currentStack.Push(topNode);

                    if (topNode.NodeName == "text")
                    {
                        text_found = true;
                    }

                    // It may be that mapping exists right here at this level
                    // Create the path for this
                    currentReverseList = currentStack.ToList();
                    GenericXmlPath thisPath = new GenericXmlPath();
                    for (int j = currentReverseList.Count - 1; j >= 0; j--)
                    {
                        thisPath.PathNodes.Add(currentReverseList[j]);
                    }

                    // Does mapping exist for this path?
                    if (set.Contains_Path(thisPath))
                    {
                        // Collect the attributes FIRST
                        List <Tuple <string, string> > attributes = null;
                        if (readerXml.HasAttributes)
                        {
                            attributes = new List <Tuple <string, string> >();
                            readerXml.MoveToFirstAttribute();
                            attributes.Add(new Tuple <string, string>(readerXml.Name, readerXml.Value));
                            while (readerXml.MoveToNextAttribute())
                            {
                                attributes.Add(new Tuple <string, string>(readerXml.Name, readerXml.Value));
                            }
                            readerXml.MoveToElement();
                        }

                        // Does mapping exist for this path?
                        PathMappingInstructions instructions = set.Get_Matching_Path_Instructions(thisPath);

                        // If instructions, this was mapped
                        if ((instructions != null) && (!String.IsNullOrEmpty(instructions.SobekMapping)) && (instructions.IgnoreSubTree))
                        {
                            MappedValue thisMappedValue = new MappedValue();
                            thisMappedValue.Mapping = instructions.SobekMapping;
                            thisMappedValue.Path    = thisPath;

                            if (instructions.RetainInnerXmlTags)
                            {
                                thisMappedValue.Value = readerXml.ReadInnerXml();
                            }
                            else
                            {
                                StringBuilder builder     = new StringBuilder();
                                XmlReader     innerReader = readerXml.ReadSubtree();
                                while (innerReader.Read())
                                {
                                    if (innerReader.NodeType == XmlNodeType.Text)
                                    {
                                        builder.Append(innerReader.Value);
                                    }
                                }
                                thisMappedValue.Value = builder.ToString();
                            }

                            returnValue.MappedValues.Add(thisMappedValue);

                            //// Actually, there is something here about skipping this
                            //readerXml.Skip();
                        }
                        else
                        {
                            // Recursively read this and all children
                            recursive_process_file(readerXml.ReadSubtree(), currentStack, set, returnValue);
                        }

                        // Now, handle the attributes
                        if ((attributes != null) && (attributes.Count > 0))
                        {
                            foreach (Tuple <string, string> attribute in attributes)
                            {
                                // Does mapping exist for this path?
                                PathMappingInstructions attrInstructions = set.Get_Matching_Path_Instructions(thisPath, attribute.Item1);

                                // If instructions, this was mapped
                                if ((attrInstructions != null) && (!String.IsNullOrEmpty(attrInstructions.SobekMapping)))
                                {
                                    MappedValue thisMappedValue = new MappedValue();
                                    thisMappedValue.Mapping            = attrInstructions.SobekMapping;
                                    thisMappedValue.Path               = thisPath;
                                    thisMappedValue.Path.AttributeName = attribute.Item1;
                                    thisMappedValue.Value              = attribute.Item2;

                                    returnValue.MappedValues.Add(thisMappedValue);
                                }
                            }
                        }
                    }

                    // Since this node was handled, pop it off the stack
                    currentStack.Pop();
                }
            }
        }
Beispiel #9
0
        private void BCreate_Click(object sender, EventArgs e)
        {
            String path     = file.FullName.Replace(file.Name, "");
            String fileName = file.Name.Replace(file.Extension, "") + ".dld";
            String dldFile  = path + fileName;

            // TODO: !IMPLEMENTED: Validation on not filled data - mapped.
            List <MappedValue> inputMappedValues = new List <MappedValue>();

            foreach (DataGridViewRow row in dgvInputMapping.Rows)
            {
                if (row.Cells[0].Value != null)
                {
                    if (row.Cells[0].Value.ToString() != "")
                    {
                        MappedValue mappedValue = new MappedValue()
                        {
                            OriginalValue = row.Cells[0].Value.ToString(),
                            NewValue      = row.Cells[1].Value == null ? "" : row.Cells[1].Value.ToString()
                        };

                        inputMappedValues.Add(mappedValue);
                    }
                }
            }

            List <MappedValue> outputMappedValues = new List <MappedValue>();

            foreach (DataGridViewRow row in dgvOutputMapping.Rows)
            {
                if (row.Cells[0].Value != null)
                {
                    if (row.Cells[0].Value.ToString() != "")
                    {
                        MappedValue mappedValue = new MappedValue()
                        {
                            OriginalValue = row.Cells[0].Value.ToString(),
                            NewValue      = row.Cells[1].Value == null ? "" : row.Cells[1].Value.ToString()
                        };

                        outputMappedValues.Add(mappedValue);
                    }
                }
            }


            DataLearnDecription dld = new DataLearnDecription()
            {
                InputQuantity            = (int)nudInputQuantity.Value,
                OutputQuantity           = (int)nudOutputQuantity.Value,
                InputPossibleDimensions  = inputPossibleDimensions,
                OutputPossibleDimensions = outputPossibleDimensions,
                InputDimensionIndex      = cbInputDimensions.SelectedIndex,
                OutputDimensionIndex     = cbOutputDimensions.SelectedIndex,
                MappedInputs             = inputMappedValues,
                MappedOutputs            = outputMappedValues
            };

            try
            {
                Tools.SerializeObject(dld, dldFile);
                MessageBox.Show(this, "File " + fileName + " created successfully!", "File created", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Hide();
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, "Error while creating dld file: " + ex.Message, "Something went wrong...", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }