示例#1
0
        public static KitComponent Load(Int32 kitComponentId, bool useCache)
        {
            if (kitComponentId == 0)
            {
                return(null);
            }
            KitComponent kitComponent = null;
            string       key          = "KitComponent_" + kitComponentId.ToString();

            if (useCache)
            {
                kitComponent = ContextCache.GetObject(key) as KitComponent;
                if (kitComponent != null)
                {
                    return(kitComponent);
                }
            }
            kitComponent = new KitComponent();
            if (kitComponent.Load(kitComponentId))
            {
                if (useCache)
                {
                    ContextCache.SetObject(key, kitComponent);
                }
                return(kitComponent);
            }
            return(null);
        }
        public static KitComponentCollection LoadForMemberProduct(int productId)
        {
            KitComponentCollection kitComponents = new KitComponentCollection();
            //CREATE THE DYNAMIC SQL TO LOAD OBJECT
            StringBuilder selectQuery = new StringBuilder();

            selectQuery.Append("SELECT " + KitComponent.GetColumnNames("ac_KitComponents"));
            selectQuery.Append(" FROM ac_KitComponents, ac_KitProducts");
            selectQuery.Append(" WHERE ac_KitComponents.KitComponentId = ac_KitProducts.KitComponentId");
            selectQuery.Append(" AND ac_KitProducts.ProductId = @ProductId");
            Database  database      = Token.Instance.Database;
            DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString());

            database.AddInParameter(selectCommand, "@productId", System.Data.DbType.Int32, productId);
            //EXECUTE THE COMMAND
            using (IDataReader dr = database.ExecuteReader(selectCommand))
            {
                while (dr.Read())
                {
                    KitComponent kitKitComponent = new KitComponent();
                    KitComponent.LoadDataReader(kitKitComponent, dr);
                    kitComponents.Add(kitKitComponent);
                }
                dr.Close();
            }
            return(kitComponents);
        }
示例#3
0
        /// <summary>
        /// Removes from the list IDs of any kit product not currently associated with this kit
        /// </summary>
        /// <param name="kitProductIds">A list of kit product ids</param>
        private void RemoveInvalidKitProducts(List <int> kitProductIds)
        {
            // BUILD A MASTER LIST OF ALL KITPRODUCTS ASSOCIATED WITH THE KIT
            List <int> associatedKitProducts = new List <int>();

            foreach (ProductKitComponent pkc in _Product.ProductKitComponents)
            {
                KitComponent kc = pkc.KitComponent;
                foreach (KitProduct kp in kc.KitProducts)
                {
                    associatedKitProducts.Add(kp.KitProductId);
                }
            }

            // LOOP THE SPECIFIED KIT PRODUCTS TO REMOVE INVALID ONES
            for (int i = kitProductIds.Count - 1; i >= 0; i--)
            {
                // SEE WHETHER THIS KITPRODUCT IS ASSOCIATED WITH THE KIT
                int kitProductId = kitProductIds[i];
                if (!associatedKitProducts.Contains(kitProductId))
                {
                    kitProductIds.RemoveAt(i);
                }
            }
        }
示例#4
0
        /// <summary>
        /// Creates a copy of this KitComponent object
        /// </summary>
        /// <param name="productId">Id of the product to attach the new object to</param>
        /// <returns>A copy of this KitComponent object</returns>
        public KitComponent Copy(int productId)
        {
            KitComponent copiedComponent = this.InternalCopy();

            copiedComponent.ProductKitComponents.Add(new ProductKitComponent(productId, copiedComponent.KitComponentId));
            copiedComponent.Save();
            return(copiedComponent);
        }
示例#5
0
        /// <summary>
        /// Gets a list of KitProducts for this Kit
        /// </summary>
        /// <returns></returns>
        public List <KitProduct> GetDefaultKitProducts()
        {
            List <KitProduct> defaultKitProducts = new List <KitProduct>();

            foreach (ProductKitComponent pkc in _Product.ProductKitComponents)
            {
                KitComponent component = pkc.KitComponent;
                switch (component.InputType)
                {
                case KitInputType.IncludedHidden:
                case KitInputType.IncludedShown:
                    //ALL OF THESE GO INTO MINIMUM AND DEFAULT PRICES
                    foreach (KitProduct kp in component.KitProducts)
                    {
                        defaultKitProducts.Add(kp);
                    }
                    break;

                case KitInputType.CheckBox:
                    //NONE GO INTO MINIMUM
                    //ALL GO INTO MAXIMUM
                    //DEFAULT SELECTED
                    foreach (KitProduct kp in component.KitProducts)
                    {
                        if (kp.IsSelected)
                        {
                            defaultKitProducts.Add(kp);
                        }
                    }
                    break;

                case KitInputType.DropDown:
                case KitInputType.RadioButton:
                    KitProduct tempDefaultKp = null;
                    bool       foundDefault  = false;
                    int        index         = 0;
                    foreach (KitProduct kp in component.KitProducts)
                    {
                        if ((!foundDefault) && (kp.IsSelected))
                        {
                            tempDefaultKp = kp;
                            foundDefault  = true;
                        }
                        else if ((index == 0) && string.IsNullOrEmpty(component.HeaderOption))
                        {
                            tempDefaultKp = kp;
                        }
                        index++;
                    }
                    if (tempDefaultKp != null)
                    {
                        defaultKitProducts.Add(tempDefaultKp);
                    }
                    break;
                }
            }
            return(defaultKitProducts);
        }
示例#6
0
        public static bool Delete(Int32 kitComponentId)
        {
            KitComponent kitComponent = new KitComponent();

            if (kitComponent.Load(kitComponentId))
            {
                return(kitComponent.Delete());
            }
            return(false);
        }
示例#7
0
 /// <summary>
 /// Loads the given KitComponent object from the given database data reader.
 /// </summary>
 /// <param name="kitComponent">The KitComponent object to load.</param>
 /// <param name="dr">The database data reader to read data from.</param>
 public static void LoadDataReader(KitComponent kitComponent, IDataReader dr)
 {
     //SET FIELDS FROM ROW DATA
     kitComponent.KitComponentId = dr.GetInt32(0);
     kitComponent.StoreId        = dr.GetInt32(1);
     kitComponent.Name           = dr.GetString(2);
     kitComponent.UserPrompt     = NullableData.GetString(dr, 3);
     kitComponent.InputTypeId    = dr.GetInt16(4);
     kitComponent.Columns        = dr.GetByte(5);
     kitComponent.HeaderOption   = NullableData.GetString(dr, 6);
     kitComponent.IsDirty        = false;
 }
示例#8
0
        private KitComponent InternalCopy()
        {
            //CREATE AN EXACT DUPLICATE OF THIS KIT COMPONENT
            KitComponent copiedComponent = KitComponentDataSource.Load(this.KitComponentId, false);

            //MAKE COPIES OF THE ASSOCIATED PRODUCTS
            foreach (KitProduct item in copiedComponent.KitProducts)
            {
                item.KitProductId = 0;
            }
            //RESET THE COMPONENTID
            copiedComponent.KitComponentId = 0;
            //SAVE THE NEW COMPONENT
            copiedComponent.Save();
            return(copiedComponent);
        }
示例#9
0
        /// <summary>
        /// Checks the list of kit products and updates as necessary.
        /// </summary>
        /// <param name="kitList">The list of kit products to refresh.</param>
        /// <returns>An updated list of kit products.</returns>
        /// <remarks>
        /// 1. Ensures any included kit products are in the list
        /// 2. Any kit products that are no longer associated to the kit are removed.
        /// </remarks>
        internal string RefreshKitProducts(string kitList)
        {
            // PARSE THE ORIGINAL KIT LIST
            List <int> kitProductIds = new List <int>();

            if (!string.IsNullOrEmpty(kitList))
            {
                kitProductIds.AddRange(AlwaysConvert.ToIntArray(kitList));
            }

            // REMOVE INVALID KITPRODUCTS
            RemoveInvalidKitProducts(kitProductIds);

            // ENSURE REQUIRED CHOICES ARE IN THE KITLIST
            foreach (ProductKitComponent pkc in _Product.ProductKitComponents)
            {
                KitComponent kc = pkc.KitComponent;
                if (kc.InputType == KitInputType.IncludedShown || kc.InputType == KitInputType.IncludedHidden)
                {
                    // THIS IS AN INCLUDED COMPONENT, SO ALL ITEMS ARE REQUIRED
                    foreach (KitProduct kp in kc.KitProducts)
                    {
                        if (!kitProductIds.Contains(kp.KitProductId))
                        {
                            kitProductIds.Add(kp.KitProductId);
                        }
                    }
                }
                else if ((kc.InputType == KitInputType.DropDown || kc.InputType == KitInputType.RadioButton) &&
                         string.IsNullOrEmpty(kc.HeaderOption) && kc.KitProducts.Count == 1)
                {
                    // THIS TYPE OF CONTROL WITHOUT A HEADER OPTION AND A SINGLE KITPRODUCT FORCES CHOICE
                    KitProduct kp = kc.KitProducts[0];
                    if (!kitProductIds.Contains(kp.KitProductId))
                    {
                        kitProductIds.Add(kp.KitProductId);
                    }
                }
            }

            // RETURN THE REFRESHED KITLIST
            if (kitProductIds.Count == 0)
            {
                return(string.Empty);
            }
            return(AlwaysConvert.ToList(",", kitProductIds.ToArray()));
        }
示例#10
0
        public static KitComponentCollection LoadForProduct(Int32 productId, int maximumRows, int startRowIndex, string sortExpression)
        {
            //CREATE THE DYNAMIC SQL TO LOAD OBJECT
            StringBuilder selectQuery = new StringBuilder();

            selectQuery.Append("SELECT");
            if (maximumRows > 0)
            {
                selectQuery.Append(" TOP " + (startRowIndex + maximumRows).ToString());
            }
            selectQuery.Append(" " + KitComponent.GetColumnNames("ac_KitComponents"));
            selectQuery.Append(" FROM ac_KitComponents, ac_ProductKitComponents");
            selectQuery.Append(" WHERE ac_KitComponents.KitComponentId = ac_ProductKitComponents.KitComponentId");
            selectQuery.Append(" AND ac_ProductKitComponents.ProductId = @productId");
            selectQuery.Append(" AND StoreId = @storeId");
            if (!string.IsNullOrEmpty(sortExpression))
            {
                selectQuery.Append(" ORDER BY " + sortExpression);
            }
            Database  database      = Token.Instance.Database;
            DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString());

            database.AddInParameter(selectCommand, "@productId", System.Data.DbType.Int32, productId);
            database.AddInParameter(selectCommand, "@storeId", System.Data.DbType.Int32, Token.Instance.StoreId);
            //EXECUTE THE COMMAND
            KitComponentCollection results = new KitComponentCollection();
            int thisIndex = 0;
            int rowCount  = 0;

            using (IDataReader dr = database.ExecuteReader(selectCommand))
            {
                while (dr.Read() && ((maximumRows < 1) || (rowCount < maximumRows)))
                {
                    if (thisIndex >= startRowIndex)
                    {
                        KitComponent kitComponent = new KitComponent();
                        KitComponent.LoadDataReader(kitComponent, dr);
                        results.Add(kitComponent);
                        rowCount++;
                    }
                    thisIndex++;
                }
                dr.Close();
            }
            return(results);
        }
示例#11
0
        public static KitComponentCollection  LoadForCriteria(string sqlCriteria, int maximumRows, int startRowIndex, string sortExpression)
        {
            //CREATE THE DYNAMIC SQL TO LOAD OBJECT
            StringBuilder selectQuery = new StringBuilder();

            selectQuery.Append("SELECT");
            if (maximumRows > 0)
            {
                selectQuery.Append(" TOP " + (startRowIndex + maximumRows).ToString());
            }
            selectQuery.Append(" " + KitComponent.GetColumnNames(string.Empty));
            selectQuery.Append(" FROM ac_KitComponents");
            string whereClause = string.IsNullOrEmpty(sqlCriteria) ? string.Empty : " WHERE " + sqlCriteria;

            selectQuery.Append(whereClause);
            if (!string.IsNullOrEmpty(sortExpression))
            {
                selectQuery.Append(" ORDER BY " + sortExpression);
            }
            Database  database      = Token.Instance.Database;
            DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString());
            //EXECUTE THE COMMAND
            KitComponentCollection results = new KitComponentCollection();
            int thisIndex = 0;
            int rowCount  = 0;

            using (IDataReader dr = database.ExecuteReader(selectCommand))
            {
                while (dr.Read() && ((maximumRows < 1) || (rowCount < maximumRows)))
                {
                    if (thisIndex >= startRowIndex)
                    {
                        KitComponent kitComponent = new KitComponent();
                        KitComponent.LoadDataReader(kitComponent, dr);
                        results.Add(kitComponent);
                        rowCount++;
                    }
                    thisIndex++;
                }
                dr.Close();
            }
            return(results);
        }
示例#12
0
        /// <summary>
        /// Creates a new KitComponent object based on this KitComponent object and attaches it as a component to the given product
        /// </summary>
        /// <param name="productId">Id of the product to which to attach the branched component</param>
        /// <returns>The newly created KitComponent</returns>
        public KitComponent Branch(int productId)
        {
            //REMOVE SPECIFIED PRODUCT FROM ORIGINAL COMPONENT
            short orderBy = -1;
            int   index   = this.ProductKitComponents.IndexOf(productId, this.KitComponentId);

            if (index > -1)
            {
                orderBy = this.ProductKitComponents[index].OrderBy;
                this.ProductKitComponents.DeleteAt(index);
            }
            //CREATE A COPY
            KitComponent branchedComponent = this.InternalCopy();
            //ATTACH THE CURRENT PRODUCT
            ProductKitComponent pkc = new ProductKitComponent(productId, branchedComponent.KitComponentId);

            pkc.OrderBy = orderBy;
            branchedComponent.ProductKitComponents.Add(pkc);
            branchedComponent.Save();
            //RETURN THE BRANCHED COMPONENT
            return(branchedComponent);
        }
示例#13
0
        private void CopyChildren()
        {
            foreach (ProductAsset asset in Assets)
            {
                asset.ProductAssetId = 0;
            }

            foreach (ProductCustomField field in CustomFields)
            {
                field.ProductFieldId = 0;
            }

            foreach (ProductDigitalGood good in DigitalGoods)
            {
                good.ProductDigitalGoodId = 0;
            }

            foreach (ProductImage image in Images)
            {
                image.ProductImageId = 0;
            }

            foreach (ProductKitComponent comp in ProductKitComponents)
            {
                KitComponent kcomp = comp.KitComponent;
                kcomp.KitComponentId = 0;
                kcomp.Save();
                comp.KitComponentId = comp.KitComponentId;
            }

            foreach (ProductTemplateField field in TemplateFields)
            {
                field.ProductTemplateFieldId = 0;
            }

            foreach (Special special in Specials)
            {
                List <int> groupIds = new List <int>();
                foreach (SpecialGroup sg in special.SpecialGroups)
                {
                    groupIds.Add(sg.GroupId);
                }

                special.SpecialId = 0;
                special.Save();

                // ADD THE SPECIAL GROUPS
                special.SpecialGroups.Clear();
                foreach (int groudId in groupIds)
                {
                    special.SpecialGroups.Add(new SpecialGroup(special.SpecialId, groudId));
                }
            }

            List <int> oldChoiceIds = new List <int>();
            List <int> newChoiceIds = new List <int>();
            int        oldChoiceId, newChoiceId;

            foreach (ProductOption option in ProductOptions)
            {
                Option opt = option.Option;
                foreach (OptionChoice choice in opt.Choices)
                {
                    oldChoiceId           = choice.OptionChoiceId;
                    choice.OptionChoiceId = 0;
                    oldChoiceIds.Add(oldChoiceId);
                }

                opt.OptionId = 0;
                opt.Save();
                option.OptionId = opt.OptionId;

                foreach (OptionChoice choice in opt.Choices)
                {
                    newChoiceId = choice.OptionChoiceId;
                    newChoiceIds.Add(newChoiceId);
                }
            }

            Dictionary <int, int> optChoiceIdMap = new Dictionary <int, int>();

            if (oldChoiceIds.Count == newChoiceIds.Count)
            {
                for (int i = 0; i < oldChoiceIds.Count; i++)
                {
                    optChoiceIdMap.Add(oldChoiceIds[i], newChoiceIds[i]);
                }
            }

            foreach (ProductVariant pv in Variants)
            {
                pv.ProductVariantId = 0;
                pv.Option1          = GetNewChoiceId(pv.Option1, optChoiceIdMap);
                pv.Option2          = GetNewChoiceId(pv.Option2, optChoiceIdMap);
                pv.Option3          = GetNewChoiceId(pv.Option3, optChoiceIdMap);
                pv.Option4          = GetNewChoiceId(pv.Option4, optChoiceIdMap);
                pv.Option5          = GetNewChoiceId(pv.Option5, optChoiceIdMap);
                pv.Option6          = GetNewChoiceId(pv.Option6, optChoiceIdMap);
                pv.Option7          = GetNewChoiceId(pv.Option7, optChoiceIdMap);
                pv.Option8          = GetNewChoiceId(pv.Option8, optChoiceIdMap);
            }
        }
        private void Calculate()
        {
            Product product = ProductDataSource.Load(_ProductId);

            if (product != null)
            {
                if (string.IsNullOrEmpty(_OptionList))
                {
                    //NO VARIANT, SET VALUES FROM BASE PRODCUT
                    _Sku    = product.Sku;
                    _Price  = GetPriceFromRules(product);
                    _Weight = product.Weight;
                }
                else
                {
                    //VARIANT PRESENT, CHECK VARIANT FOR CORRECT VALUES
                    ProductVariant variant = ProductVariantDataSource.LoadForOptionList(_ProductId, _OptionList);
                    if (variant == null)
                    {
                        throw new InvalidOptionsException("The options specified for " + product.Name + " are invalid.");
                    }
                    _Sku = variant.Sku;
                    if (variant.Price != 0)
                    {
                        if (variant.PriceMode == ModifierMode.Modify)
                        {
                            _Price = GetPriceFromRules(product) + variant.Price;
                        }
                        else
                        {
                            _Price = variant.Price;
                        }
                    }
                    else
                    {
                        _Price = GetPriceFromRules(product);
                    }
                    if (variant.Weight != 0)
                    {
                        if (variant.WeightMode == ModifierMode.Modify)
                        {
                            _Weight = product.Weight + variant.Weight;
                        }
                        else
                        {
                            _Weight = variant.Weight;
                        }
                    }
                    else
                    {
                        _Weight = product.Weight;
                    }
                }

                // CALCULATE PRICE WITH TAX IF SPECIFIED
                if (_CalculateTax)
                {
                    _PriceWithTax = TaxHelper.GetShopPrice(_Price, product.TaxCodeId);
                }

                //CHECK FOR KIT PRODUCTS
                if (_KitProductIds != null)
                {
                    foreach (int kitProductId in _KitProductIds)
                    {
                        KitProduct kp = KitProductDataSource.Load(kitProductId);
                        if (kp != null)
                        {
                            _Price  += kp.CalculatedPrice;
                            _Weight += kp.CalculatedWeight;

                            // CALCULATE PRICE WITH TAX IF SPECIFIED
                            if (_CalculateTax)
                            {
                                int          taxCodeId = 0;
                                KitComponent component = kp.KitComponent;
                                if (component.InputType == KitInputType.IncludedHidden)
                                {
                                    taxCodeId = product.TaxCodeId;
                                }
                                else if (kp.Product != null)
                                {
                                    taxCodeId = kp.Product.TaxCodeId;
                                }
                                _PriceWithTax += TaxHelper.GetShopPrice(kp.CalculatedPrice, taxCodeId);
                            }
                        }
                    }
                }
                _Calculated = true;
            }
        }
        public static KitComponentCollection Search(string productName, string componentName, int maximumRows, int startRowIndex, string sortExpression)
        {
            KitComponentCollection componentList = new KitComponentCollection();

            //CREATE THE SQL STATEMENT
            productName   = StringHelper.FixSearchPattern(productName);
            componentName = StringHelper.FixSearchPattern(componentName);
            StringBuilder selectQuery = new StringBuilder();

            selectQuery.Append("SELECT");
            if (maximumRows > 0)
            {
                selectQuery.Append(" TOP " + (startRowIndex + maximumRows).ToString());
            }
            selectQuery.Append(" " + KitComponent.GetColumnNames(string.Empty));
            selectQuery.Append(" FROM ac_KitComponents WHERE KitComponentId IN (SELECT DISTINCT C.KitComponentId");
            selectQuery.Append(" FROM ((ac_KitComponents C INNER JOIN ac_ProductKitComponents PC ON C.KitComponentId = PC.KitComponentId)");
            selectQuery.Append(" INNER JOIN ac_Products P ON PC.ProductId = P.ProductId)");
            selectQuery.Append(" WHERE P.StoreId = @storeId");
            if (!string.IsNullOrEmpty(productName))
            {
                selectQuery.Append(" AND P.Name LIKE @productName");
            }
            if (!string.IsNullOrEmpty(componentName))
            {
                selectQuery.Append(" AND C.Name LIKE @componentName");
            }
            if (!string.IsNullOrEmpty(sortExpression))
            {
                selectQuery.Append(" ORDER BY " + sortExpression);
            }
            selectQuery.Append(")");
            //CREATE THE COMMAND
            Database  database      = Token.Instance.Database;
            DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString());

            database.AddInParameter(selectCommand, "@storeId", System.Data.DbType.Int32, Token.Instance.StoreId);
            if (!string.IsNullOrEmpty(productName))
            {
                database.AddInParameter(selectCommand, "@productName", System.Data.DbType.String, productName);
            }
            if (!string.IsNullOrEmpty(componentName))
            {
                database.AddInParameter(selectCommand, "@componentName", System.Data.DbType.String, componentName);
            }
            //EXECUTE THE COMMAND
            int thisIndex = 0;
            int rowCount  = 0;

            using (IDataReader dr = database.ExecuteReader(selectCommand))
            {
                while (dr.Read() && ((maximumRows < 1) || (rowCount < maximumRows)))
                {
                    if (thisIndex >= startRowIndex)
                    {
                        KitComponent component = new KitComponent();
                        KitComponent.LoadDataReader(component, dr);
                        componentList.Add(component);
                        rowCount++;
                    }
                    thisIndex++;
                }
                dr.Close();
            }
            return(componentList);
        }
示例#16
0
        /// <summary>
        /// Recalculates the kit
        /// </summary>
        /// <param name="optionList">Option list specifying the variant</param>
        public void Recalculate(string optionList)
        {
            //DETERMINE THE BASE PRICE OF THE PRODUCT
            LSDecimal basePrice  = 0;
            LSDecimal baseWeight = 0;
            //CHECK FOR A SPECIFIED VARIANT
            ProductVariant variant = ProductVariantDataSource.LoadForOptionList(_Product.ProductId, optionList);

            if (variant == null)
            {
                //NO VARIANT, SET VALUES FROM BASE PRODCUT
                _OptionList = string.Empty;
                basePrice   = _Product.Price;
                baseWeight  = _Product.Weight;
            }
            else
            {
                //VARIANT PRESENT, CHECK VARIANT FOR CORRECT VALUES
                _OptionList = optionList;
                basePrice   = (variant.Price == 0) ? _Product.Price : variant.Price;
                baseWeight  = (variant.Weight == 0) ? _Product.Weight : variant.Weight;
            }
            _MinPrice      = basePrice;
            _MaxPrice      = basePrice;
            _DefaultPrice  = basePrice;
            _MinWeight     = baseWeight;
            _MaxWeight     = baseWeight;
            _DefaultWeight = baseWeight;
            foreach (ProductKitComponent pkc in _Product.ProductKitComponents)
            {
                KitComponent component = pkc.KitComponent;
                if (component.KitProducts.Count > 0)
                {
                    switch (component.InputType)
                    {
                    case KitInputType.IncludedHidden:
                    case KitInputType.IncludedShown:
                        //ALL OF THESE GO INTO MINIMUM AND DEFAULT PRICES
                        foreach (KitProduct kp in component.KitProducts)
                        {
                            LSDecimal kpPrice  = kp.CalculatedPrice;
                            LSDecimal kpWeight = kp.CalculatedWeight;
                            _MinPrice      += kpPrice;
                            _MaxPrice      += kpPrice;
                            _DefaultPrice  += kpPrice;
                            _MinWeight     += kpWeight;
                            _MaxWeight     += kpWeight;
                            _DefaultWeight += kpWeight;
                        }
                        break;

                    case KitInputType.CheckBox:
                        //NONE GO INTO MINIMUM
                        //ALL GO INTO MAXIMUM
                        //DEFAULT SELECTED
                        foreach (KitProduct kp in component.KitProducts)
                        {
                            LSDecimal kpPrice  = kp.CalculatedPrice;
                            LSDecimal kpWeight = kp.CalculatedWeight;
                            _MaxPrice  += kpPrice;
                            _MaxWeight += kpWeight;
                            if (kp.IsSelected)
                            {
                                _DefaultPrice  += kpPrice;
                                _DefaultWeight += kpWeight;
                            }
                        }
                        break;

                    case KitInputType.DropDown:
                    case KitInputType.RadioButton:
                        //LOWEST PRICE / WEIGHT GOES INTO MINIMUM
                        //HIGHEST PRICE / WEIGHT GOES INTO MAXIMUM
                        //DEFAULT SELECTED
                        LSDecimal tempDefaultPrice;
                        LSDecimal tempDefaultWeight;
                        LSDecimal tempHighPrice;
                        LSDecimal tempLowPrice;
                        LSDecimal tempHighWeight;
                        LSDecimal tempLowWeight;
                        //GET FIRST KIT PRODUCT
                        KitProduct firstKp       = component.KitProducts[0];
                        LSDecimal  firstKpPrice  = firstKp.CalculatedPrice;
                        LSDecimal  firstKpWeight = firstKp.CalculatedWeight;
                        //CHECK FOR HEADER OPTION
                        if (string.IsNullOrEmpty(component.HeaderOption))
                        {
                            //NO HEADER OPTION, VALUES MUST START WITH FIRST KIT PRODUCT
                            tempHighPrice     = firstKpPrice;
                            tempHighWeight    = firstKpWeight;
                            tempLowPrice      = firstKpPrice;
                            tempLowWeight     = firstKpWeight;
                            tempDefaultPrice  = firstKpPrice;
                            tempDefaultWeight = firstKpWeight;
                        }
                        else
                        {
                            //HEADEROPTION IS PRESENT
                            tempHighPrice  = firstKpPrice > 0 ? firstKpPrice : 0;
                            tempHighWeight = firstKpWeight > 0 ? firstKpWeight : 0;
                            tempLowPrice   = firstKpPrice < 0 ? firstKpPrice : 0;
                            tempLowWeight  = firstKpWeight < 0 ? firstKpWeight : 0;
                            if (firstKp.IsSelected)
                            {
                                tempDefaultPrice  = firstKpPrice;
                                tempDefaultWeight = firstKpWeight;
                            }
                            else
                            {
                                tempDefaultPrice  = 0;
                                tempDefaultWeight = 0;
                            }
                        }
                        bool foundDefault = firstKp.IsSelected;
                        //LOOP THE REMAINING PRODUCTS IN COLLECTION TO CALCULATE VALUES
                        for (int index = 1; index < component.KitProducts.Count; index++)
                        {
                            KitProduct kp       = component.KitProducts[index];
                            LSDecimal  kpPrice  = kp.CalculatedPrice;
                            LSDecimal  kpWeight = kp.CalculatedWeight;
                            if (kpPrice > tempHighPrice)
                            {
                                tempHighPrice = kpPrice;
                            }
                            if (kpPrice < tempLowPrice)
                            {
                                tempLowPrice = kpPrice;
                            }
                            if (kpWeight > tempHighWeight)
                            {
                                tempHighWeight = kpWeight;
                            }
                            if (kpWeight < tempLowWeight)
                            {
                                tempLowWeight = kpWeight;
                            }
                            if ((!foundDefault) && (kp.IsSelected))
                            {
                                tempDefaultPrice  = kpPrice;
                                tempDefaultWeight = kpWeight;
                                foundDefault      = true;
                            }
                        }
                        _MinPrice      += tempLowPrice;
                        _MinWeight     += tempLowWeight;
                        _MaxPrice      += tempHighPrice;
                        _MaxWeight     += tempHighWeight;
                        _DefaultPrice  += tempDefaultPrice;
                        _DefaultWeight += tempDefaultWeight;
                        break;
                    }
                }
            }
            _Calculated = true;
        }
示例#17
0
        /// <summary>
        /// Checks the set of kit products selected for this kit to determine if they are valid and complete
        /// </summary>
        /// <param name="kitList">List of kit product ids</param>
        /// <returns>True if the kit choices represent a valid kit, false otherwise</returns>
        public bool ValidateChoices(string kitList)
        {
            // PARSE THE KIT LIST
            List <int> kitProductIds = new List <int>();

            if (!string.IsNullOrEmpty(kitList))
            {
                kitProductIds.AddRange(AlwaysConvert.ToIntArray(kitList));
            }

            // CHECK FOR INVALID KITPRODUCTS IN THE LIST
            int originalCount = kitProductIds.Count;

            RemoveInvalidKitProducts(kitProductIds);

            // IF ANY INVALID ITEMS WERE REMOVED, THIS IS NOT A VALID KITLIST
            if (kitProductIds.Count != originalCount)
            {
                return(false);
            }

            // LOOP THE KIT COMPONENTS
            foreach (ProductKitComponent pkc in _Product.ProductKitComponents)
            {
                KitComponent kc = pkc.KitComponent;
                switch (kc.InputType)
                {
                case KitInputType.IncludedHidden:
                case KitInputType.IncludedShown:
                    foreach (KitProduct kp in kc.KitProducts)
                    {
                        // IF THIS INCLUDED ITEM IS NOT IN THE KITLIST IT IS INVALID
                        if (!kitProductIds.Contains(kp.KitProductId))
                        {
                            return(false);
                        }
                    }
                    break;

                case KitInputType.DropDown:
                case KitInputType.RadioButton:
                    // WE EITHER NEED 0 OR 1 FROM THIS COMPONENT, CAN NEVER HAVE TWO
                    bool needOne  = kc.KitProducts.Count > 0 && string.IsNullOrEmpty(kc.HeaderOption);
                    bool foundOne = false;
                    foreach (KitProduct kp in kc.KitProducts)
                    {
                        // IF THIS INCLUDED ITEM IS NOT IN THE KITLIST IT IS INVALID
                        if (kitProductIds.Contains(kp.KitProductId))
                        {
                            // IF WE HAVE ALREADY FOUND ONE CHOICE FROM THIS LIST THIS KIT IS INVALID
                            if (foundOne)
                            {
                                return(false);
                            }
                            foundOne = true;
                        }
                    }
                    // IF A CHOICE IS REQUIRED BUT NOT FOUND THIS KIT IS INVALID
                    if (needOne && !foundOne)
                    {
                        return(false);
                    }
                    break;
                }
            }

            // IF WE DID NOT FIND ANY PROBLEMS THE KIT IS VALID
            return(true);
        }
示例#18
0
 public static bool Delete(KitComponent kitComponent)
 {
     return(kitComponent.Delete());
 }
示例#19
0
 public static SaveResult Insert(KitComponent kitComponent)
 {
     return(kitComponent.Save());
 }
示例#20
0
 public static SaveResult Update(KitComponent kitComponent)
 {
     return(kitComponent.Save());
 }