Пример #1
0
        /// <summary>
        /// Handles the DeleteCommand event of the AssociationItemsGrid control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="ComponentArt.Web.UI.GridItemEventArgs"/> instance containing the event data.</param>
        void AssociationItemsGrid_DeleteCommand(object sender, ComponentArt.Web.UI.GridItemEventArgs e)
        {
            int id      = Int32.Parse(e.Item[_CatalogAssociationIdString].ToString());
            int entryId = Int32.Parse(e.Item[_CatalogEntryIdString].ToString());

            if (CurrentCatalogAssociationDto != null)
            {
                CatalogAssociationDto.CatalogEntryAssociationRow entryRow = CurrentCatalogAssociationDto.CatalogEntryAssociation.FindByCatalogAssociationIdCatalogEntryId(id, entryId);
                if (entryRow != null)
                {
                    entryRow.Delete();
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Handles the InsertCommand event of the AssociationItemsGrid control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="ComponentArt.Web.UI.GridItemEventArgs"/> instance containing the event data.</param>
        void AssociationItemsGrid_InsertCommand(object sender, ComponentArt.Web.UI.GridItemEventArgs e)
        {
            int id      = Int32.Parse(e.Item[_CatalogAssociationIdString].ToString());
            int entryId = Int32.Parse(e.Item[_CatalogEntryIdString].ToString());

            if (CurrentCatalogAssociationDto != null)
            {
                CatalogAssociationDto.CatalogEntryAssociationRow entryRow = CurrentCatalogAssociationDto.CatalogEntryAssociation.FindByCatalogAssociationIdCatalogEntryId(id, entryId);
                if (entryRow == null)
                {
                    entryRow = CurrentCatalogAssociationDto.CatalogEntryAssociation.NewCatalogEntryAssociationRow();
                    entryRow.CatalogAssociationId = id;
                    entryRow.CatalogEntryId       = entryId;
                }

                entryRow.SortOrder         = Int32.Parse(e.Item[_SortOrderString].ToString());
                entryRow.AssociationTypeId = e.Item[_AssociationTypeIdString].ToString();

                if (entryRow.RowState == DataRowState.Detached)
                {
                    CurrentCatalogAssociationDto.CatalogEntryAssociation.Rows.Add(entryRow);
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Loads the entry.
        /// </summary>
        /// <param name="row">The row.</param>
        /// <param name="recursive">if set to <c>true</c> [recursive].</param>
        /// <param name="responseGroup">The response group.</param>
        /// <param name="entryList">The entry list.</param>
        /// <returns></returns>
        internal static Entry LoadEntry(CatalogEntryDto.CatalogEntryRow row, bool recursive, CatalogEntryResponseGroup responseGroup, ref StringCollection entryList)
        {
            Entry entry = null;

            // Load entry
            if (row != null)
            {
                // Track entries added, to avoid circular dependencies
                entryList.Add(row.Code);

                entry = new Entry(row);

                // Populate association detailed info
                if (recursive && (responseGroup.ContainsGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull) || responseGroup.ContainsGroup(CatalogEntryResponseGroup.ResponseGroup.Associations)))
                {
                    if (entry.Associations != null)
                    {
                        CatalogAssociationDto associationDto = CatalogAssociationManager.GetCatalogAssociationDtoByEntryId(row.CatalogEntryId);

                        // If associations do not contain any entries, then we do not need to go through the rest
                        if (associationDto.CatalogEntryAssociation.Count > 0)
                        {
                            foreach (Association association in entry.Associations)
                            {
                                int associationId = 0;
                                // Find out association id
                                foreach (CatalogAssociationDto.CatalogAssociationRow associationRow in associationDto.CatalogAssociation)
                                {
                                    if (associationRow.AssociationName.Equals(association.Name))
                                    {
                                        associationId = associationRow.CatalogAssociationId;
                                        break;
                                    }
                                }

                                // Load association entries
                                List <EntryAssociation> entryAssociationList = new List <EntryAssociation>();
                                CatalogEntryDto         associatedEntries    = GetAssociatedCatalogEntriesDto(row.CatalogEntryId, association.Name, responseGroup);
                                foreach (CatalogEntryDto.CatalogEntryRow childRow in associatedEntries.CatalogEntry)
                                {
                                    EntryAssociation entryAssociation = new EntryAssociation();
                                    // Find appropriate row
                                    CatalogAssociationDto.CatalogEntryAssociationRow entryAssociationRow = associationDto.CatalogEntryAssociation.FindByCatalogAssociationIdCatalogEntryId(associationId, childRow.CatalogEntryId);
                                    if (entryAssociationRow != null)
                                    {
                                        entryAssociation.SortOrder       = entryAssociationRow.SortOrder;
                                        entryAssociation.AssociationType = entryAssociationRow.AssociationTypeId;
                                        entryAssociation.AssociationDesc = entryAssociationRow.AssociationTypeRow.Description;
                                    }

                                    // Check for circular dependencies here

                                    /*
                                     * if (row.CatalogEntryId == childRow.CatalogEntryId)
                                     *  throw new CircularDependencyException(String.Format("Circular dependency detected. Entry association \"{0}\" for \"{1}[{2}]\" contains reference to itself.", entryAssociation.AssociationDesc, childRow.Name, childRow.CatalogEntryId));
                                     * */

                                    bool loadRecursive = recursive;

                                    // do not load recursive if there is potential circular dependency
                                    if (entryList.Contains(row.Code))
                                    {
                                        loadRecursive = false;
                                    }

                                    Entry childEntry = LoadEntry(childRow, loadRecursive, responseGroup, ref entryList);
                                    childEntry.ParentEntry = null;
                                    entryAssociation.Entry = childEntry;

                                    entryAssociationList.Add(entryAssociation);
                                }

                                association.EntryAssociations             = new EntryAssociations();
                                association.EntryAssociations.Association = entryAssociationList.ToArray();
                            }
                        }
                    }
                }

                // Populate children
                if (recursive && (responseGroup.ContainsGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull) || responseGroup.ContainsGroup(CatalogEntryResponseGroup.ResponseGroup.Children)))
                {
                    bool loadRecursive = recursive;

                    // do not load recursive if there is potential circular dependency
                    if (entryList.Contains(row.Code))
                    {
                        loadRecursive = false;
                    }

                    CatalogEntryDto childrenDto = GetCatalogEntriesDto(row.CatalogEntryId, String.Empty, String.Empty, responseGroup);
                    Entries         entries     = LoadEntries(childrenDto, entry, loadRecursive, responseGroup, ref entryList);
                    entry.Entries = entries;
                }
            }

            /*
             * else
             *  entry = new Entry();
             * */

            return(entry);
        }
Пример #4
0
        protected override int CreateSystemRow(FillDataMode Mode, int RowIndex, params object[] Item)
        {
            int    i = 0;
            object objSysRowAction    = Item[i++];
            object objAssociationName = Item[i++];
            object objParentCode      = Item[i++];
            object objChildCode       = Item[i++];
            object objSortOrder       = Item[i++];
            object objAssociationType = Item[i++];

            try
            {
                RowAction sysRowAction = RowAction.Default;

                if (objSysRowAction != null)
                {
                    sysRowAction = GetRowActionEnum((string)objSysRowAction);
                }

                string AssociationName;
                if (!String.IsNullOrEmpty((string)objAssociationName))
                {
                    AssociationName = (string)objAssociationName;
                }
                else
                {
                    throw new AbsentValue("Association Name");
                }

                string parentCode;
                if (!String.IsNullOrEmpty((string)objParentCode))
                {
                    parentCode = (string)objParentCode;
                }
                else
                {
                    throw new AbsentValue("Parent Entry Code");
                }

                string childCode;
                if (!String.IsNullOrEmpty((string)objChildCode))
                {
                    childCode = (string)objChildCode;
                }
                else
                {
                    throw new AbsentValue("Child Entry Code");
                }

                bool bIsNew = false;

                //Parent Entry
                CatalogEntryDto.CatalogEntryRow parentEntryRow = null;
                CatalogEntryDto catalogEntryDto = CatalogEntryManager.GetCatalogEntryDto(parentCode, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.Associations));
                if (catalogEntryDto.CatalogEntry.Count > 0)
                {
                    parentEntryRow = catalogEntryDto.CatalogEntry[0];
                }
                else
                {
                    throw new MDPImportException(String.Format("The Parent Entry with code '{0}' does not exists.", parentCode));
                }

                //Child Entry
                CatalogEntryDto.CatalogEntryRow childEntryRow = null;
                CatalogEntryDto childEntryDto = CatalogEntryManager.GetCatalogEntryDto(childCode, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryInfo));
                if (childEntryDto.CatalogEntry.Count > 0)
                {
                    childEntryRow = childEntryDto.CatalogEntry[0];
                }
                else
                {
                    throw new MDPImportException(String.Format("The Child Entry with code '{0}' does not exists.", childCode));
                }

                //CatalogAssociation (define CatalogAssociationId)
                int catalogAssociationId = 0;
                CatalogEntryDto.CatalogAssociationRow[] catalogAssociationRows = (CatalogEntryDto.CatalogAssociationRow[])catalogEntryDto.CatalogAssociation.Select(String.Format("AssociationName = '{0}'", AssociationName));
                if (catalogAssociationRows.Length == 0)
                {
                    CatalogEntryDto.CatalogAssociationRow newCatalogAssociationRow = catalogEntryDto.CatalogAssociation.NewCatalogAssociationRow();
                    newCatalogAssociationRow.CatalogEntryId         = parentEntryRow.CatalogEntryId;
                    newCatalogAssociationRow.AssociationName        = AssociationName;
                    newCatalogAssociationRow.AssociationDescription = String.Empty;
                    newCatalogAssociationRow.SortOrder = 0;
                    catalogEntryDto.CatalogAssociation.AddCatalogAssociationRow(newCatalogAssociationRow);

                    CatalogContext.Current.SaveCatalogEntry(catalogEntryDto);

                    catalogAssociationId = newCatalogAssociationRow.CatalogAssociationId;
                }
                else
                {
                    catalogAssociationId = catalogAssociationRows[0].CatalogAssociationId;
                }

                //catalogEntryAssociationRow
                CatalogAssociationDto catalogAssociationDto = CatalogAssociationManager.GetCatalogAssociationDto(catalogAssociationId);
                CatalogAssociationDto.CatalogAssociationRow catalogAssociationRow = catalogAssociationDto.CatalogAssociation[0];

                CatalogAssociationDto.CatalogEntryAssociationRow catalogEntryAssociationRow = null;

                CatalogAssociationDto.CatalogEntryAssociationRow[] catalogEntryAssociationRows = (CatalogAssociationDto.CatalogEntryAssociationRow[])catalogAssociationDto.CatalogEntryAssociation.Select(String.Format("CatalogEntryId = {0}", childEntryRow.CatalogEntryId));
                if (catalogEntryAssociationRows.Length == 0)
                {
                    if (sysRowAction == RowAction.Update)
                    {
                        throw new MDPImportException(String.Format("The Catalog Entry Association with name '{0}' for entry code '{1}' and child code '{2}' does not exists.", AssociationName, parentCode, childCode));
                    }

                    if (sysRowAction == RowAction.Delete)
                    {
                        throw new MDPImportException(String.Format("The Catalog Entry Association with name '{0}' for entry code '{1}' and child code '{2}' does not exists.", AssociationName, parentCode, childCode));
                    }

                    catalogEntryAssociationRow = catalogAssociationDto.CatalogEntryAssociation.NewCatalogEntryAssociationRow();
                    catalogEntryAssociationRow.CatalogAssociationId = catalogAssociationId;
                    catalogEntryAssociationRow.CatalogEntryId       = childEntryRow.CatalogEntryId;
                    catalogEntryAssociationRow.SortOrder            = 0;
                    if (catalogAssociationDto.AssociationType.Count > 0)
                    {
                        catalogEntryAssociationRow.AssociationTypeId = catalogAssociationDto.AssociationType[0].AssociationTypeId;
                    }

                    bIsNew = true;
                }
                else
                {
                    if (sysRowAction == RowAction.Insert)
                    {
                        throw new MDPImportException(String.Format("The Catalog Entry Association with name '{0}' for entry code '{1}' and child code '{2}' already exists.", AssociationName, parentCode, childCode));
                    }

                    catalogEntryAssociationRow = catalogEntryAssociationRows[0];

                    if (sysRowAction == RowAction.Delete)
                    {
                        catalogEntryAssociationRow.Delete();
                        CatalogContext.Current.SaveCatalogAssociation(catalogAssociationDto);
                        return(0);
                    }
                }

                if (objSortOrder != null)
                {
                    catalogEntryAssociationRow.SortOrder = (int)objSortOrder;
                }

                if (objAssociationType != null)
                {
                    string associationType = (string)objAssociationType;
                    if (!catalogEntryAssociationRow.AssociationTypeId.Equals(associationType))
                    {
                        CatalogAssociationDto.AssociationTypeRow[] associationTypeRows = (CatalogAssociationDto.AssociationTypeRow[])catalogAssociationDto.AssociationType.Select(String.Format("AssociationTypeId = '{0}'", associationType));
                        if (associationTypeRows.Length > 0)
                        {
                            catalogEntryAssociationRow.AssociationTypeId = associationTypeRows[0].AssociationTypeId;
                        }
                    }
                }

                if (bIsNew)
                {
                    catalogAssociationDto.CatalogEntryAssociation.AddCatalogEntryAssociationRow(catalogEntryAssociationRow);
                }

                using (TransactionScope tx = new TransactionScope())
                {
                    // Save modifications
                    if (catalogAssociationDto.HasChanges())
                    {
                        CatalogContext.Current.SaveCatalogAssociation(catalogAssociationDto);
                    }

                    tx.Complete();
                }
            }
            catch (Exception ex)
            {
                throw new MDPImportException(ex.Message, null, RowIndex, null, null, Item);
            }

            return(1);
        }