Esempio n. 1
0
        //private frmEditSubEntity GetSubEntityForm(TableDrivedEntityDTO e)
        //{
        //    foreach (var item in tabControl.Items)
        //    {
        //        if ((item as TabItem).Content is frmEditSubEntity)
        //        {
        //            if (((item as TabItem).Content as frmEditSubEntity).Message == e)
        //                return (item as TabItem).Content as frmEditSubEntity;
        //        }
        //    }
        //    return null;
        //}

        //private void MoveColumnFromBaseToDrived(frmEditSubEntity view, ColumnDTO column, bool showMessage)
        //{


        //}


        //private void MoveColumnFromDrivedToBase(frmEditSubEntity view, ColumnDTO column, bool showMessage)
        //{

        //    if (column.PrimaryKey)
        //    {
        //        if (showMessage)
        //            MessageBox.Show("ستون کلید اصلی میباشد");
        //        return;
        //    }
        //    Message.BaseEntity.Columns.Add(column);
        //    view.RemoveColumn(column);
        //    dtgColumns.ItemsSource = null;
        //    dtgColumns.ItemsSource = Message.BaseEntity.Columns;
        //}

        void AddRelationship(TableDrivedEntityDTO sourceEntity, RelationshipDTO sourceRelationship, TableDrivedEntityDTO targetEntity, bool move
                             , RadGridView sourceRelationshipDataGrid, RadGridView targetRelationshipDataGrid, RadGridView sourceColumnDataGrid, RadGridView targetColumnDataGrid)
        {
            BizRelationship bizRelationship = new BizRelationship();

            if (sourceEntity == Message.BaseEntity && bizRelationship.RelationshipIsNotNulable(sourceRelationship.ID))
            {
                var message = " این رابطه اجباری میباشند و امکان انتخاب شدن برای موجودیت های مشتق شده را ندارند";
                MessageBox.Show(message, "روابط اجباری");
                return;
            }

            if (sourceRelationship.MastertTypeEnum == Enum_MasterRelationshipType.FromForeignToPrimary)
            {
                if (!sourceRelationship.RelationshipColumns.Any(x => x.FirstSideColumn.PrimaryKey))
                {
                    foreach (var col in sourceRelationship.RelationshipColumns)
                    {
                        var fColumn = sourceEntity.Columns.FirstOrDefault(x => x.ID == col.FirstSideColumnID);
                        if (fColumn != null)
                        {
                            AddColumn(sourceEntity, fColumn, targetEntity, move, sourceColumnDataGrid, targetColumnDataGrid, false);
                        }
                    }
                }
            }
            if (!targetEntity.Relationships.Any(x => x.ID == sourceRelationship.ID))
            {
                targetEntity.Relationships.Add(sourceRelationship);
                targetRelationshipDataGrid.ItemsSource = null;
                targetRelationshipDataGrid.ItemsSource = targetEntity.Relationships;
            }
            if (move)
            {
                sourceEntity.Relationships.Remove(sourceRelationship);
                sourceRelationshipDataGrid.ItemsSource = null;
                sourceRelationshipDataGrid.ItemsSource = sourceEntity.Relationships;
            }
        }