Welcome to MSDN Blogs Sign in | Join | Help

Cristiano WebLog

Microsoft Infrastructure & Development Tips and Tricks
Product Relationship Names: Easier for Business Users

If you are following my posts you probably have noticed the one showing how to create bundles for Commerce Server 2007. Bundles are created using product relationships with a specific name.

Some of my customers believe it is too complicated for business users to create relationships with a particular name in order to create bundles. So they asked to make a small change on the Catalog Manager to create combo boxes with enumeration options on the relationship name column of the product relationships tab (product detail).

The aim is to do something similar to the dialog below:

image

In order to change the free text box by a combo box on the relationship name during the creation of new product relationships the you need to change the code of the Commerce Server 2007 Catalog Manager.

The source code is available on the Partner SDK under the Applications\CatalogManager folder.

The datagrid for the Product Relationships is created by the CreateDatagrid function inside the CatalogItemRelationships.cs file.

The datagrid used to show the relationships is derived from the default DatagridView control and it is named ColumnBasedDatagrid. It is defined on the ColumnBasedDatagrid.cs file inside the UI control collection source code.

The display method of the ColumnBasedDatagrid named dataGridViewRelationships has a parameter PropertyStore. A Propertystore is a collection of PropertyInfo objects. Based on the type passed as the third parameters of each PropertyInfo object inside this collection, the datagrid columns are created to show the relationships.

The default PropertyInfo supports the Datatype.String and Datatype.Enumeration types. The default type used for the RelationshipName is Datatype.String. If the developer changes the datatype used to Datatype.Enumeration, the datagrid will be created with a combo-box instead a plain text box as expected.

Custom code is also necessary to deal with the enumeration definition. The enumeration that will be shown in the screen must be defined in a database or even inside the code. The following code was used to fill the enumeration with sample possible values: AWARD, GROUPRELATION, BUNDLECOMPONENT, COMPOSITECHILD, and CROSSSELL. It was included inside the CreateDataGrid function.

The code below shows the CreateDatagrid function already changed to use the combo box instead the regular text box.

   1: private void CreateDataGrid()
   2: {
   3:     if (this.dataGridViewRelationships.ColumnCount == 0)
   4:     {
   5:         PropertyStore propertyStore = new PropertyStore();
   6:  
   7:         StringCollection values = new StringCollection();
   8:         values.add (“AWARD”);
   9:         values.add (“GROUPRELATION”);
  10:         values.add (“BUNDLECOMPONENT”);
  11:         values.add (“COMPOSITECHILD”);
  12:         values.add (“CROSSSELL”);
  13:  
  14:         PropertyInfo propertyInfo = new PropertyInfo(true, true, DataType.Enumeration, values, “Name”, CatalogResourceFile.COLUMN_RELATIONSHIP_NAME, UIHelpers.relationship);
  15:         propertyInfo.ColumnDisplayWidth = 120;
  16:         propertyStore.Add(propertyInfo);
  17:         propertyInfo = new PropertyInfo(true, false, DataType.String, 1, 128, CatalogResourceFile.COLUMN_ITEM_NAME, UIHelpers.item, null);
  18:         propertyInfo.ColumnDisplayWidth = 120;
  19:         propertyStore.Add(propertyInfo);
  20:         propertyInfo = new PropertyInfo(true, false, DataType.String, 1, 128, CatalogResourceFile.COLUMN_ITEM_NAME, "ItemName", null);
  21:         propertyInfo.ColumnDisplayWidth = 120;
  22:         propertyStore.Add(propertyInfo);
  23:         propertyInfo = new PropertyInfo(true, false, DataType.String, 1, 128, CatalogResourceFile.COLUMN_CATALOG_NAME, UIHelpers.catalog, null);
  24:         propertyInfo.ColumnDisplayWidth = 120;
  25:         propertyStore.Add(propertyInfo);
  26:         propertyInfo = new PropertyInfo(true, false, DataType.String, 1, 128, CatalogResourceFile.COLUMN_CATALOG_NAME, "CatalogName", null);
  27:         propertyInfo.ColumnDisplayWidth = 120;
  28:         propertyStore.Add(propertyInfo);
  29:         propertyInfo = new PropertyInfo(false, false, DataType.String, 1, 128, CatalogResourceFile.COLUMN_ITEM_TYPE_NAME, UIHelpers.itemType, null);
  30:         propertyInfo.ColumnDisplayWidth = 120;
  31:         propertyStore.Add(propertyInfo);
  32:         propertyInfo = new PropertyInfo(false, true, DataType.String, 1, 128, CatalogResourceFile.COLUMN_DESCRIPTION_NAME, UIHelpers.relationshipDescription, null);
  33:         propertyInfo.ColumnDisplayWidth = 120;
  34:         propertyStore.Add(propertyInfo);
  35:         propertyInfo = new PropertyInfo(false, true, DataType.String, 1, 128, "OldRelationshipName", "OldRelationshipName", null);
  36:         propertyInfo.ColumnDisplayWidth = 120;
  37:         propertyStore.Add(propertyInfo);
  38:         propertyInfo = new PropertyInfo(true, true, DataType.Integer, null, null, SequenceColumn, SequenceColumn, null);
  39:         propertyInfo.ColumnDisplayWidth = 20;
  40:         propertyStore.Add(propertyInfo);
  41:         dataGridViewRelationships.Display(propertyStore, null);
  42:         dataGridViewRelationships.Columns["CatalogName"].Visible = false;
  43:         dataGridViewRelationships.Columns["ItemName"].Visible = false;
  44:         dataGridViewRelationships.Columns["OldRelationshipName"].Visible = false;
  45:         dataGridViewRelationships.Columns[SequenceColumn].Visible = false;
  46:         dataGridViewRelationships.Columns[SequenceColumn].SortMode = DataGridViewColumnSortMode.Automatic;
  47:         StringCollection uniqueColumns = new StringCollection();
  48:         uniqueColumns.Add(UIHelpers.relationship);
  49:         uniqueColumns.Add("ItemName");
  50:         uniqueColumns.Add("CatalogName");
  51:         uniqueColumns.Add(UIHelpers.itemType);
  52:         this.dataGridViewRelationships.SetUniqueCoulmns(uniqueColumns);
  53:     }
  54: }

Regards, Cris.

This posting is provided "AS IS" with no warranties, and confers no rights.

Posted: Tuesday, May 06, 2008 2:09 PM by crisag
Filed under:
Anonymous comments are disabled
Page view tracker