Example #1
0
 int RelationshipHeight(modelEntity currentEntity)
 {
     try
     {
         int value;
         var canGetValue = entityHeightProccessed.TryGetValue(currentEntity.name, out value);
         if (canGetValue)
         {
             return(value);
         }
         else if (currentEntity.relationship.Count == 0)
         {
             entityHeightProccessed[currentEntity.name] = 0;
             return(0);
         }
         else
         {
             var height = 0;
             foreach (var relation in currentEntity.relationship)
             {
                 if (relation != null)
                 {
                     if (relation.toMany == null)
                     {
                         relation.toMany = "False";
                     }
                     if (relation.toMany.ToLower().Equals("no") || relation.toMany.ToLower().Equals("false"))
                     {
                         int entityIndex = -1;
                         entityIndex = FindEntityIndex(relation.destinationEntity);
                         if (entityIndex > -1)
                         {
                             var relationEntity = XmlTemplateModel.entity[entityIndex];
                             entityHeightProccessed[currentEntity.name] = 1;
                             var relatedHeight = RelationshipHeight(relationEntity) + 1;
                             entityHeightProccessed[currentEntity.name] = relatedHeight;
                             if (relatedHeight > height)
                             {
                                 height = relatedHeight;
                             }
                         }
                     }
                 }
             }
             return(height);
         }
     }
     catch (Exception ex)
     {
         var error = ex.Message;
         return(0);
     }
 }
 /// <summary>
 /// Handles the Click event of the OKButton control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
 private void OKButton_Click(object sender, RoutedEventArgs e)
 {
     if (this.ValidateValues())
     {
         this.EntityRelationshipModel.name = this.RelationshipNameTextBox.Text;
         this.DialogResult = true;
         this.EntityRelationshipModel.clientKey         = clientKeys;
         this.EntityRelationshipModel.destinationEntity = destination;
         this.EntityRelationshipModel.toMany            = Helper.ConvertBoolToString(MultipleRelationshipsCheckBox.IsChecked);
         var inverseItem = InverseComboBox.SelectedItem.ToString();
         if (inverseItem.Equals("No Inverse"))
         {
             var messageResult = MessageBox.Show("Do you want to auto-generate it?", "Missing inverse relationship",
                                                 MessageBoxButton.YesNo, MessageBoxImage.Question);
             if (messageResult == MessageBoxResult.Yes)
             {
                 var inverseRelation = new modelEntityRelationship();
                 inverseRelation.name = "r_" + parentWindow.SelectedEntity.name;
                 inverseRelation.destinationEntity          = parentWindow.SelectedEntity.name;
                 inverseRelation.inverseName                = this.EntityRelationshipModel.name;
                 inverseRelation.inverseEntity              = destination;
                 inverseRelation.toMany                     = Helper.ConvertBoolToString(!MultipleRelationshipsCheckBox.IsChecked);
                 this.EntityRelationshipModel.inverseEntity = inverseRelation.destinationEntity;
                 this.EntityRelationshipModel.inverseName   = inverseRelation.name;
                 var         entities       = ((ViewModel)parentWindow.DataContext).XmlTemplateModel.entity;
                 modelEntity selectedEntity = null;
                 foreach (var currentEntity in entities)
                 {
                     if (currentEntity.name.Equals(destination))
                     {
                         selectedEntity = currentEntity;
                     }
                 }
                 if (selectedEntity != null)
                 {
                     selectedEntity.relationship.Add(inverseRelation);
                 }
             }
             else if (messageResult == MessageBoxResult.No)
             {
                 this.EntityRelationshipModel.inverseEntity = this.InverseComboBox.SelectedItem.ToString();
             }
         }
     }
     else
     {
         this.RelationshipNameTextBox.Text = this.EntityRelationshipModel.name;
     }
 }
Example #3
0
 void CheckIsRootRelated(modelEntity selectedEntity)
 {
     if (selectedEntity != null && selectedEntity.isRootRelated.Equals("True"))
     {
         List <modelEntityAttribute> parcelNumberAtts = selectedEntity.attribute.Where(a => a.name.Contains("parcelNbr_mb")).ToList();
         List <modelEntityAttribute> rootIdAtt        = selectedEntity.attribute.Where(a => a.name.Contains("rootId_mb")).ToList();
         foreach (var currentAtt in parcelNumberAtts)
         {
             selectedEntity.attribute.Remove(currentAtt);
             if (rootIdAtt.Count == 0)
             {
                 currentAtt.name = "rootId_mb";
                 selectedEntity.attribute.Add(currentAtt);
             }
         }
     }
 }
        /// <summary>
        /// Handles the SelectionChanged event of the InverseComboBox control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.Controls.SelectionChangedEventArgs"/> instance containing the event data.</param>
        private void InverseComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            string inverse = this.InverseComboBox.SelectedItem.ToString();

            // Logic to force the M:N relationships only possible via intermediary tables.
            string      selected    = this.DestinationComboBox.SelectedItem.ToString();
            modelEntity otherEntity = ((ViewModel)parentWindow.DataContext).XmlTemplateModel.entity.FirstOrDefault(ent => ent.name == selected);

            if (otherEntity != null)
            {
                modelEntityRelationship inverseRel = otherEntity.relationship.FirstOrDefault(r => r.name == inverse);
                if (inverseRel != null && Helper.ValidateBoolFromString(inverseRel.toMany))
                {
                    this.MultipleRelationshipsCheckBox.IsChecked = false;
                    this.MultipleRelationshipsCheckBox.IsEnabled = false;
                }
            }
        }
        /// <summary>
        /// Handles the SelectionChanged event of the DestinationComboBox control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.Controls.SelectionChangedEventArgs"/> instance containing the event data.</param>
        private void DestinationComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            string selected = this.DestinationComboBox.SelectedItem.ToString();

            destination = selected;
            clientKeys.Clear();
            if (destination == this.EntityRelationshipModel.destinationEntity && EntityRelationshipModel.clientKey != null)
            {
                this.EntityRelationshipModel.clientKey.ToList().ForEach(r => clientKeys.Add(r));
            }

            if (selected != WPFDesigner_XML.Resources.NoDestination)
            {
                modelEntity otherEntity = ((ViewModel)parentWindow.DataContext).XmlTemplateModel.entity.FirstOrDefault(ent => ent.name == selected);

                if (otherEntity != null)
                {
                    List <string> attrsName = new List <string>();
                    otherEntity.attribute.ToList().ForEach(a => attrsName.Add(a.name));
                    this.DestinationKeyComboBox.ItemsSource = new ObservableCollection <string>(attrsName);
                }


                List <string> relationships = new List <string>();
                if (otherEntity != null && otherEntity.relationship != null && parentWindow.SelectedEntity != null)
                {
                    otherEntity.relationship.Where(r => r.destinationEntity == parentWindow.SelectedEntity.name).ToList().ForEach(a => relationships.Add(a.name));
                }

                if (relationships.Count > 0)
                {
                    this.LoadInverseCombobox(relationships);
                }
                else
                {
                    this.LoadInverseCombobox(null);
                }
            }
            else
            {
                this.LoadInverseCombobox(null);
            }
        }