/// <summary> /// Binds the form. /// </summary> /// <param name="reset">if set to <c>true</c> [reset].</param> private void BindForm(bool reset) { CatalogAssociationDto.CatalogAssociationRow selectedAssociationRow = null; if (AssociationId != 0) { selectedAssociationRow = _CatalogAssociationDto.CatalogAssociation.FindByCatalogAssociationId(AssociationId); } if (selectedAssociationRow != null) { if (reset) { SetFormFieldsValues(selectedAssociationRow.AssociationName, selectedAssociationRow.AssociationDescription, selectedAssociationRow.SortOrder); } } else if (reset) { SetFormFieldsValues("", "", 1); /*if (_CatalogAssociationDto != null) * { * } * else * SetFormFieldsValues("", "", 1);*/ } }
/// <summary> /// Deletes the association items. /// </summary> /// <param name="catalogAssociation">The catalog association.</param> private void DeleteAssociationItems(CatalogAssociationDto.CatalogAssociationRow catalogAssociation) { if (catalogAssociation != null) { CatalogAssociationDto.CatalogEntryAssociationRow[] entryRows = catalogAssociation.GetCatalogEntryAssociationRows(); foreach (CatalogAssociationDto.CatalogEntryAssociationRow entryRow in entryRows) { entryRow.Delete(); } } }
/// <summary> /// Gets the association row. /// </summary> /// <param name="catalogAssociationId">The catalog association id.</param> /// <returns></returns> private CatalogAssociationDto.CatalogAssociationRow GetAssociationRow(int catalogAssociationId) { // load selected item CatalogAssociationDto dto = CurrentCatalogAssociationDto; CatalogAssociationDto.CatalogAssociationRow row = null; if (dto != null) { row = CurrentCatalogAssociationDto.CatalogAssociation.FindByCatalogAssociationId(catalogAssociationId); } return(row); }
/// <summary> /// Sets the association items grid data source. /// </summary> /// <param name="associationId">The association id.</param> private void SetAssociationItemsGridDataSource(int associationId) { CatalogAssociationDto dto = CurrentCatalogAssociationDto; CatalogAssociationDto.CatalogAssociationRow row = GetAssociationRow(associationId); if (row != null) { CatalogAssociationDto.CatalogEntryAssociationRow[] entryAssociationRows = row.GetCatalogEntryAssociationRows(); DataTable dt = new DataTable("CatalogEntryAssociation"); dt.Columns.AddRange(new DataColumn[5] { new DataColumn(_CatalogAssociationIdString, typeof(int)), new DataColumn(_CatalogEntryIdString, typeof(int)), new DataColumn("EntryName", typeof(string)), new DataColumn(_SortOrderString, typeof(int)), new DataColumn(_AssociationTypeIdString, typeof(string)) }); foreach (CatalogAssociationDto.CatalogEntryAssociationRow entryRow in entryAssociationRows) { DataRow dr = dt.NewRow(); dr[_CatalogAssociationIdString] = entryRow.CatalogAssociationId; dr[_CatalogEntryIdString] = entryRow.CatalogEntryId; dr["EntryName"] = GetEntryNameById(entryRow.CatalogEntryId); dr[_SortOrderString] = entryRow.SortOrder; dr[_AssociationTypeIdString] = entryRow.AssociationTypeId; dt.Rows.Add(dr); } CatalogAssociationDto.AssociationTypeDataTable associationTypeTable = new CatalogAssociationDto.AssociationTypeDataTable(); List <CatalogAssociationDto.AssociationTypeRow> associationTypeRows = new List <CatalogAssociationDto.AssociationTypeRow>(); foreach (CatalogAssociationDto.AssociationTypeRow associationTypeRow in dto.AssociationType.Rows) { associationTypeTable.ImportRow(associationTypeRow); } DataSet dsSrc = new DataSet(); dsSrc.Tables.Add(dt); dsSrc.Tables.Add(associationTypeTable); dsSrc.Relations.Add(dsSrc.Tables["AssociationType"].Columns["AssociationTypeId"], dsSrc.Tables["CatalogEntryAssociation"].Columns["AssociationTypeId"]); AssociationItemsGrid.DataSource = dsSrc; } else { AssociationItemsGrid.DataSource = null; } }
/// <summary> /// Handles the Click event of the SaveChangesButton control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void SaveChangesButton_Click(object sender, EventArgs e) { CatalogAssociationDto.CatalogAssociationRow row = null; if (AssociationId != 0) // find existing { row = _CatalogAssociationDto.CatalogAssociation.FindByCatalogAssociationId(AssociationId); } // if not found, create new if (row == null) { row = _CatalogAssociationDto.CatalogAssociation.NewCatalogAssociationRow(); if (_CatalogEntryDto != null && _CatalogEntryDto.CatalogEntry.Rows.Count > 0) { row.CatalogEntryId = ((CatalogEntryDto.CatalogEntryRow)_CatalogEntryDto.CatalogEntry.Rows[0]).CatalogEntryId; } else { row.CatalogEntryId = 0; } } // update Association fields if (row != null) { row.AssociationName = tbAssociationName.Text; row.AssociationDescription = tbDescription.Text; row.SortOrder = Int32.Parse(tbSortOrder.Text); if (row.RowState == DataRowState.Detached) { _CatalogAssociationDto.CatalogAssociation.Rows.Add(row); } } System.Text.StringBuilder closeDialog = new System.Text.StringBuilder("EntryAssociationEdit_CloseDialog"); if (row != null) { closeDialog.AppendFormat("({0}, '{1}');", row.CatalogAssociationId, row.AssociationName); } else { closeDialog.Append("(0, '');"); } ScriptManager.RegisterStartupScript(MetaDataTab, typeof(EntryAssociationEditPopup), "DialogClose", closeDialog.ToString(), true); }
/// <summary> /// Handles the ValueChanged event of the ItemsPanelTrigger control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> void ItemsPanelTrigger_ValueChanged(object sender, EventArgs e) { int id = 0; if (Int32.TryParse(ItemsPanelTrigger.Value, out id) && id != 0) { pnlSelectedAssociation.Visible = true; CatalogAssociationDto.CatalogAssociationRow row = GetAssociationRow(id); //SelectedAssociationId); if (row != null) { lblAssociationName.Text = row.AssociationName; lblAssociationDescription.Text = row.AssociationDescription; BindGrid(); } } else { pnlSelectedAssociation.Visible = false; } }
/// <summary> /// Handles the Click event of the btnDelete control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> void btnDelete_Click(object sender, EventArgs e) { CatalogAssociationDto dto = CurrentCatalogAssociationDto; if (SelectedAssociationId != 0 && dto != null) { CatalogAssociationDto.CatalogAssociationRow row = dto.CatalogAssociation.FindByCatalogAssociationId(SelectedAssociationId); if (row != null) { /* * // delete asosciation items since there's no cascade delete in this relationship * DeleteAssociationItems(row); * */ // delete association row.Delete(); } } AssociationsFilter.SelectedIndex = -1; AssociationsFilter.Text = ""; BindForm(); pnlSelectedAssociation.Visible = false; }
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); }