コード例 #1
0
        /// <summary>
        /// Compares dimension values for sorting purpose. Sorting is made by display order, and then by name.
        /// Values with zero display orders should be at the beginning of list.
        /// E.g. we have the following values:
        /// Name = Black, DisplayOrder = 3
        /// Name = Silver, DisplayOrder = 0
        /// Name = White, DisplayOrder = 1
        /// Name = Gold, DisplayOrder = 2
        /// Name = Red, DisplayOrder = 0
        /// Result sorted list should be: Red(0), Silver(0), White (1), Gold (2), Black (3).
        /// </summary>
        /// <returns></returns>
        internal static int CompareDisplayOrders(DimensionValue v1, DimensionValue v2)
        {
            // values with different dimension types (e.g. color vs style) should not be compared by this comparison
            if (v1.Dimension != v2.Dimension)
            {
                return(0);
            }

            // if display orders are equal, compare by name
            if (v1.DisplayOrder == v2.DisplayOrder)
            {
                return(v1.Name.CompareTo(v2.Name));
            }

            // in all other cases common compare by display order values
            return(v1.DisplayOrder.CompareTo(v2.DisplayOrder));
        }
コード例 #2
0
        private void LoadVariants(DataTable dataTable, DimensionType dimType, string tableName, string dimensionId, string dimensionName, string dimensionDisplayOrder)
        {
            using (DataTable dt = SelectDistinct(tableName, dataTable, string.Empty, dimensionId, dimensionName, dimensionDisplayOrder))
            {
                DataRow[] rows = dt.Select(string.Empty);
                if (rows.Length > 0)
                {
                    activeDimensions.Add(dimType, null);

                    foreach (DataRow row in rows)
                    {
                        DimensionValue dv = new DimensionValue(row["ID"].ToString(), row["NAME"].ToString(), dimType,
                                                               string.IsNullOrWhiteSpace(dimensionDisplayOrder) ? 0 : Convert.ToDecimal(row["DISPLAYORDER"].ToString()));
                        allVariants.Add(dv);
                    }
                }
            }
        }