Esempio n. 1
0
        /// <summary>
        /// Determines if a coupon is valid for an order based on customer, customer level, coupon parameters, products, and order
        /// </summary>
        /// <param name="customer">Customer object representing the customer making the purchase</param>
        /// <param name="coupon">Coupon object representing the coupon and all of its settings</param>
        /// <param name="subTotalBeforeDiscounts">Subtotal of items in the shopping cart before any discounts have been applied</param>
        /// <returns>String 'AppLogic.ro_OK' if coupon is valid or there is no coupon, else returns reason why coupon is not valid</returns>
        public static string CheckIfCouponIsValidForOrder(Customer customer, CouponObject coupon, decimal subTotalBeforeDiscounts)
        {
            if (string.IsNullOrEmpty(coupon.CouponCode))
            {
                return(AppLogic.GetString("shoppingcart.cs.79", customer.SkinID, customer.LocaleSetting));
            }

            if (coupon.ExpirationDate == DateTime.MinValue)
            {
                return(AppLogic.GetString("shoppingcart.cs.79", customer.SkinID, customer.LocaleSetting));
            }

            if (coupon.Deleted)
            {
                return(AppLogic.GetString("shoppingcart.cs.79", customer.SkinID, customer.LocaleSetting));
            }

            if (coupon.StartDate > DateTime.Now)
            {
                return(AppLogic.GetString("shoppingcart.cs.79", customer.SkinID, customer.LocaleSetting));
            }

            if (coupon.ExpirationDate < DateTime.Now)
            {
                return(AppLogic.GetString("shoppingcart.cs.69", customer.SkinID, customer.LocaleSetting));
            }

            return(AppLogic.ro_OK);
        }
Esempio n. 2
0
        /// <summary>
        /// Determines if a coupon is valid for an order based on customer, customer level, coupon parameters, products, and order
        /// </summary>
        /// <param name="customer">Customer object representing the customer making the purchase</param>
        /// <param name="coupon">Coupon object representing the coupon and all of its settings</param>
        /// <param name="subTotalBeforeDiscounts">Subtotal of items in the shopping cart before any discounts have been applied</param>
        /// <returns>String 'AppLogic.ro_OK' if coupon is valid or there is no coupon, else returns reason why coupon is not valid</returns>
        public static string CheckIfCouponIsValidForOrder(Customer customer, CouponObject coupon, decimal subTotalBeforeDiscounts)
        {
            if (string.IsNullOrEmpty(coupon.CouponCode))
            {
                return("You have entered an invalid gift card");
            }

            if (coupon.ExpirationDate == DateTime.MinValue)
            {
                return("You have entered an invalid gift card");
            }

            if (coupon.Deleted)
            {
                return("You have entered an invalid gift card");
            }

            if (coupon.StartDate > DateTime.Now)
            {
                return("You have entered an invalid gift card");
            }

            if (coupon.ExpirationDate < DateTime.Now)
            {
                return("That promotion has expired");
            }

            return(AppLogic.ro_OK);
        }
Esempio n. 3
0
        public List <CouponObject> InitCoupon(String couponCode, Customer ThisCustomer)
        {
            List <CouponObject> cList = new List <CouponObject>();

            using (IDataReader rs = DB.GetRS("select * from coupon where CouponCode=" + DB.SQuote(couponCode), new SqlConnection(DB.GetDBConn())))
            {
                while (rs.Read())
                {
                    CouponObject co = new CouponObject();

                    co.m_couponcode      = DB.RSField(rs, "CouponCode");
                    co.m_coupontype      = (CouponTypeEnum)DB.RSFieldInt(rs, "CouponType");
                    co.m_description     = DB.RSField(rs, "Description");
                    co.m_startdate       = DB.RSFieldDateTime(rs, "StartDate");
                    co.m_expirationdate  = DB.RSFieldDateTime(rs, "ExpirationDate");
                    co.m_discountamount  = DB.RSFieldDecimal(rs, "DiscountAmount");
                    co.m_discountpercent = DB.RSFieldDecimal(rs, "DiscountPercent");
                    co.m_discountincludesfreeshipping       = DB.RSFieldBool(rs, "DiscountIncludesFreeShipping");
                    co.m_expiresonfirstusebyanycustomer     = DB.RSFieldBool(rs, "ExpiresOnFirstUseByAnyCustomer");
                    co.m_expiresafteroneusagebyeachcustomer = DB.RSFieldBool(rs, "ExpiresAfterOneUsageByEachCustomer");
                    co.m_expiresafternuses          = DB.RSFieldInt(rs, "ExpiresAfterNUses");
                    co.m_requiresminimumorderamount = DB.RSFieldDecimal(rs, "RequiresMinimumOrderAmount");

                    co.m_validforcustomers     = CommonLogic.BuildListFromCommaString(Regex.Replace(DB.RSField(rs, "ValidForCustomers"), "\\s+", "", RegexOptions.Compiled));
                    co.m_validforproducts      = CommonLogic.BuildListFromCommaString(Regex.Replace(DB.RSField(rs, "ValidForProducts"), "\\s+", "", RegexOptions.Compiled));
                    co.m_validforcategories    = CommonLogic.BuildListFromCommaString(Regex.Replace(DB.RSField(rs, "ValidForCategories"), "\\s+", "", RegexOptions.Compiled));
                    co.m_validforsections      = CommonLogic.BuildListFromCommaString(Regex.Replace(DB.RSField(rs, "ValidForSections"), "\\s+", "", RegexOptions.Compiled));
                    co.m_validformanufacturers = CommonLogic.BuildListFromCommaString(Regex.Replace(DB.RSField(rs, "ValidForManufacturers"), "\\s+", "", RegexOptions.Compiled));

                    co.m_validforproductsexpanded      = new List <int>();
                    co.m_validforcategoriesexpanded    = new List <int>();
                    co.m_validforsectionsexpanded      = new List <int>();
                    co.m_validformanufacturersexpanded = new List <int>();

                    if (co.m_coupontype == CouponTypeEnum.ProductCoupon && co.m_validforcategories.Count > 0)
                    {
                        co.m_validforcategoriesexpanded = AppLogic.LookupHelper("Category", 0).GetEntityList(CommonLogic.BuildCommaStringFromList(co.m_validforcategories), ThisCustomer.AffiliateID, ThisCustomer.CustomerLevelID);

                        List <int> pList = AppLogic.LookupHelper("Category", 0).GetProductList(CommonLogic.BuildCommaStringFromList(co.m_validforcategoriesexpanded), ThisCustomer.AffiliateID, ThisCustomer.CustomerLevelID);

                        co.m_validforproductsexpanded.AddRange(pList);
                    }
                    if (co.m_coupontype == CouponTypeEnum.ProductCoupon && co.m_validforsections.Count > 0)
                    {
                        co.m_validforsectionsexpanded = AppLogic.LookupHelper("Section", 0).GetEntityList(CommonLogic.BuildCommaStringFromList(co.m_validforsections), ThisCustomer.AffiliateID, ThisCustomer.CustomerLevelID);

                        List <int> pList = AppLogic.LookupHelper("Section", 0).GetProductList(CommonLogic.BuildCommaStringFromList(co.m_validforsectionsexpanded), ThisCustomer.AffiliateID, ThisCustomer.CustomerLevelID);

                        co.m_validforproductsexpanded.AddRange(pList);
                    }
                    if (co.m_coupontype == CouponTypeEnum.ProductCoupon && co.m_validformanufacturers.Count > 0)
                    {
                        co.m_validformanufacturersexpanded = AppLogic.LookupHelper("Manufacturer", 0).GetEntityList(CommonLogic.BuildCommaStringFromList(co.m_validformanufacturers), ThisCustomer.AffiliateID, ThisCustomer.CustomerLevelID);

                        List <int> pList = AppLogic.LookupHelper("Manufacturer", 0).GetProductList(CommonLogic.BuildCommaStringFromList(co.m_validformanufacturersexpanded), ThisCustomer.AffiliateID, ThisCustomer.CustomerLevelID);

                        co.m_validforproductsexpanded.AddRange(pList);
                    }

                    co.m_numuses = DB.RSFieldInt(rs, "NumUses");

                    cList.Add(co);
                }
            }

            return(cList);
        }
Esempio n. 4
0
        /// <summary>
        /// Determines if a coupon is valid for an order based on customer, customer level, coupon parameters, products, and order
        /// </summary>
        /// <param name="ThisCustomer">Customer object representing the customer making the purchase</param>
        /// <param name="co">Coupon object representing the coupon and all of its settings</param>
        /// <param name="subTotal">Subtotal of items in the shopping cart</param>
        /// <param name="subTotal">Subtotal of items in the shopping cart before any discounts have been applied</param>
        /// <returns>String 'AppLogic.ro_OK' if coupon is valid or there is no coupon, else returns reason why coupon is not valid</returns>
        public static String CheckIfCouponIsValidForOrder(Customer ThisCustomer, CouponObject co, Decimal subTotal, Decimal subTotalBeforeDiscounts)
        {
            String status = AppLogic.ro_OK;

            if (co.m_couponcode.Length != 0)
            {
                // we found a valid match for that coupon code with an expiration date greater than or equal to now, so check additional conditions on the coupon:
                // just return first reason for it not being valid, going from most obvious to least obvious:
                if (co.m_expirationdate == System.DateTime.MinValue || co.m_deleted)
                {
                    status = AppLogic.GetString("shoppingcart.cs.79", ThisCustomer.SkinID, ThisCustomer.LocaleSetting);
                }

                if (status == AppLogic.ro_OK)
                {
                    if (co.m_startdate > System.DateTime.Now)
                    {
                        status = AppLogic.GetString("shoppingcart.cs.79", ThisCustomer.SkinID, ThisCustomer.LocaleSetting);
                    }
                }

                if (status == AppLogic.ro_OK)
                {
                    if (co.m_expirationdate < System.DateTime.Now)
                    {
                        status = AppLogic.GetString("shoppingcart.cs.69", ThisCustomer.SkinID, ThisCustomer.LocaleSetting);
                    }
                }
                if (status == AppLogic.ro_OK)
                {
                    if (co.m_expiresonfirstusebyanycustomer && AppLogic.AnyCustomerHasUsedCoupon(co.m_couponcode))
                    {
                        status = AppLogic.GetString("shoppingcart.cs.70", ThisCustomer.SkinID, ThisCustomer.LocaleSetting);
                    }
                }
                if (status == AppLogic.ro_OK)
                {
                    if (co.m_expiresafteroneusagebyeachcustomer && Customer.HasUsedCoupon(ThisCustomer.CustomerID, ThisCustomer.CouponCode))
                    {
                        status = AppLogic.GetString("shoppingcart.cs.71", ThisCustomer.SkinID, ThisCustomer.LocaleSetting);
                    }
                }
                if (status == AppLogic.ro_OK)
                {
                    if (co.m_expiresafternuses > 0 && AppLogic.GetNumberOfCouponUses(ThisCustomer.CouponCode) > co.m_expiresafternuses)
                    {
                        status = AppLogic.GetString("shoppingcart.cs.72", ThisCustomer.SkinID, ThisCustomer.LocaleSetting);
                    }
                }
                if (status == AppLogic.ro_OK)
                {
                    if (co.m_requiresminimumorderamount > System.Decimal.Zero && subTotalBeforeDiscounts < co.m_requiresminimumorderamount)
                    {
                        status = String.Format(AppLogic.GetString("shoppingcart.cs.73", ThisCustomer.SkinID, ThisCustomer.LocaleSetting), ThisCustomer.CurrencyString(co.m_requiresminimumorderamount));
                    }
                }
                if (status == AppLogic.ro_OK)
                {
                    if (co.m_validforcustomers.Count() > 0 && !co.m_validforcustomers.Contains(ThisCustomer.CustomerID))
                    {
                        status = AppLogic.GetString("shoppingcart.cs.74", ThisCustomer.SkinID, ThisCustomer.LocaleSetting);
                    }
                }

                if (status == AppLogic.ro_OK)
                {
                    try
                    {
                        if (co.m_validforproductsexpanded.Count() > 0 && DB.GetSqlN("select count(productid) as N from ShoppingCart   with (NOLOCK)  where productid in (" + CommonLogic.BuildCommaStringFromList(co.m_validforproductsexpanded) + ") and CartType=" + ((int)CartTypeEnum.ShoppingCart).ToString() + " and customerid=" + ThisCustomer.CustomerID.ToString()) == 0)
                        {
                            status = AppLogic.GetString("shoppingcart.cs.75", ThisCustomer.SkinID, ThisCustomer.LocaleSetting);
                        }
                    }
                    catch
                    {
                        status = AppLogic.GetString("shoppingcart.cs.76", ThisCustomer.SkinID, ThisCustomer.LocaleSetting);
                    }
                }
                if (status == AppLogic.ro_OK)
                {
                    if (co.m_startdate > System.DateTime.Now)
                    {
                        status = AppLogic.GetString("shoppingcart.cs.79", ThisCustomer.SkinID, ThisCustomer.LocaleSetting);
                    }
                }
            }
            else
            {
                try
                {
                    string query = "select * from GiftCard  with (NOLOCK)  where StartDate<=getdate() and ExpirationDate>=getdate() and DisabledByAdministrator=0 and Balance>0 and SerialNumber=" + DB.SQuote(co.m_couponcode);

                    using (SqlConnection conn = new SqlConnection(DB.GetDBConn()))
                    {
                        conn.Open();

                        using (IDataReader rs = DB.GetRS(query, conn))
                        {
                            if (rs.Read())
                            {
                                status = AppLogic.ro_OK;
                            }
                            else
                            {
                                status = AppLogic.GetString("shoppingcart.cs.79", ThisCustomer.SkinID, ThisCustomer.LocaleSetting);
                            }
                        }
                    }
                }
                catch {}
            }
            return(status);
        }
Esempio n. 5
0
        public static String CheckIfCouponIsValidForProduct(Customer ThisCustomer, CouponObject co, CartItem ci)
        {
            String status = AppLogic.ro_OK;

            if (co.m_couponcode.Length != 0)
            {
                // we found a valid match for that coupon code with an expiration date greater than or equal to now, so check additional conditions on the coupon:
                // just return first reason for it not being valid, going from most obvious to least obvious:
                if (co.m_expirationdate == System.DateTime.MinValue || co.m_deleted)
                {
                    status = AppLogic.GetString("shoppingcart.cs.79", ThisCustomer.SkinID, ThisCustomer.LocaleSetting);
                }

                if (status == AppLogic.ro_OK)
                {
                    if (co.m_startdate > System.DateTime.Now)
                    {
                        status = AppLogic.GetString("shoppingcart.cs.79", ThisCustomer.SkinID, ThisCustomer.LocaleSetting);
                    }
                }

                if (status == AppLogic.ro_OK)
                {
                    if (co.m_expirationdate < System.DateTime.Now)
                    {
                        status = AppLogic.GetString("shoppingcart.cs.69", ThisCustomer.SkinID, ThisCustomer.LocaleSetting);
                    }
                }
                if (status == AppLogic.ro_OK)
                {
                    if (co.m_expiresonfirstusebyanycustomer && AppLogic.AnyCustomerHasUsedCoupon(co.m_couponcode))
                    {
                        status = AppLogic.GetString("shoppingcart.cs.70", ThisCustomer.SkinID, ThisCustomer.LocaleSetting);
                    }
                }
                if (status == AppLogic.ro_OK)
                {
                    if (co.m_expiresafteroneusagebyeachcustomer && Customer.HasUsedCoupon(ThisCustomer.CustomerID, ThisCustomer.CouponCode))
                    {
                        status = AppLogic.GetString("shoppingcart.cs.71", ThisCustomer.SkinID, ThisCustomer.LocaleSetting);
                    }
                }
                if (status == AppLogic.ro_OK)
                {
                    if (co.m_expiresafternuses > 0 && AppLogic.GetNumberOfCouponUses(ThisCustomer.CouponCode) > co.m_expiresafternuses)
                    {
                        status = AppLogic.GetString("shoppingcart.cs.72", ThisCustomer.SkinID, ThisCustomer.LocaleSetting);
                    }
                }
                if (status == AppLogic.ro_OK)
                {
                    if (co.m_validforcustomers.Count() > 0 && !co.m_validforcustomers.Contains(ThisCustomer.CustomerID))
                    {
                        status = AppLogic.GetString("shoppingcart.cs.74", ThisCustomer.SkinID, ThisCustomer.LocaleSetting);
                    }
                }

                if (status == AppLogic.ro_OK)
                {
                    try
                    {
                        if (co.m_validforproductsexpanded.Count() > 0)
                        {
                            if (!co.m_validforproductsexpanded.Contains(ci.ProductID))
                            {
                                status = AppLogic.GetString("shoppingcart.cs.75", ThisCustomer.SkinID, ThisCustomer.LocaleSetting);
                            }
                        }
                        else if (co.m_validforproducts.Count() > 0)
                        {
                            if (!co.m_validforproducts.Contains(ci.ProductID))
                            {
                                status = AppLogic.GetString("shoppingcart.cs.75", ThisCustomer.SkinID, ThisCustomer.LocaleSetting);
                            }
                        }
                    }
                    catch
                    {
                        status = AppLogic.GetString("shoppingcart.cs.76", ThisCustomer.SkinID, ThisCustomer.LocaleSetting);
                    }
                }
                if (status == AppLogic.ro_OK)
                {
                    if (co.m_startdate > System.DateTime.Now)
                    {
                        status = AppLogic.GetString("shoppingcart.cs.79", ThisCustomer.SkinID, ThisCustomer.LocaleSetting);
                    }
                }
            }
            else
            {
                try
                {
                    string query = "select * from GiftCard  with (NOLOCK)  where StartDate<=getdate() and ExpirationDate>=getdate() and DisabledByAdministrator=0 and Balance>0 and SerialNumber=" + DB.SQuote(co.m_couponcode);

                    using (SqlConnection conn = new SqlConnection(DB.GetDBConn()))
                    {
                        conn.Open();

                        using (IDataReader rs = DB.GetRS(query, conn))
                        {
                            if (rs.Read())
                            {
                                status = AppLogic.ro_OK;
                            }
                            else
                            {
                                status = AppLogic.GetString("shoppingcart.cs.79", ThisCustomer.SkinID, ThisCustomer.LocaleSetting);
                            }
                        }
                    }
                }
                catch { }
            }

            return(status);
        }
Esempio n. 6
0
        public static CouponObject GetCoupon(SqlTransaction DBTrans, Customer ThisCustomer)
        {
            CouponObject co = new CouponObject();

            co.m_couponset = false;

            using (SqlConnection couponCon = new SqlConnection(DB.GetDBConn()))
            {
                couponCon.Open();

                string query = "select * from coupon  with (NOLOCK)  where lower(couponcode)=" + DB.SQuote(ThisCustomer.CouponCode.ToLowerInvariant());
                using (IDataReader rscoup = DB.GetRS(query, couponCon))
                {
                    if (rscoup.Read())
                    {
                        co.m_couponset = true;

                        // either consumer level, or this level allows coupons, so load it if there are any:
                        co.m_couponcode      = DB.RSField(rscoup, "CouponCode");
                        co.m_coupontype      = (CouponTypeEnum)DB.RSFieldInt(rscoup, "CouponType");
                        co.m_description     = DB.RSField(rscoup, "Description");
                        co.m_startdate       = DB.RSFieldDateTime(rscoup, "StartDate");
                        co.m_expirationdate  = DB.RSFieldDateTime(rscoup, "ExpirationDate");
                        co.m_discountamount  = DB.RSFieldDecimal(rscoup, "DiscountAmount");
                        co.m_discountpercent = DB.RSFieldDecimal(rscoup, "DiscountPercent");
                        co.m_discountincludesfreeshipping       = DB.RSFieldBool(rscoup, "DiscountIncludesFreeShipping");
                        co.m_expiresonfirstusebyanycustomer     = DB.RSFieldBool(rscoup, "ExpiresOnFirstUseByAnyCustomer");
                        co.m_expiresafteroneusagebyeachcustomer = DB.RSFieldBool(rscoup, "ExpiresAfterOneUsageByEachCustomer");
                        co.m_expiresafternuses          = DB.RSFieldInt(rscoup, "ExpiresAfterNUses");
                        co.m_requiresminimumorderamount = DB.RSFieldDecimal(rscoup, "RequiresMinimumOrderAmount");

                        co.m_validforcustomers     = CommonLogic.BuildListFromCommaString(Regex.Replace(DB.RSField(rscoup, "ValidForCustomers"), "\\s+", "", RegexOptions.Compiled));
                        co.m_validforproducts      = CommonLogic.BuildListFromCommaString(Regex.Replace(DB.RSField(rscoup, "ValidForProducts"), "\\s+", "", RegexOptions.Compiled));
                        co.m_validforcategories    = CommonLogic.BuildListFromCommaString(Regex.Replace(DB.RSField(rscoup, "ValidForCategories"), "\\s+", "", RegexOptions.Compiled));
                        co.m_validforsections      = CommonLogic.BuildListFromCommaString(Regex.Replace(DB.RSField(rscoup, "ValidForSections"), "\\s+", "", RegexOptions.Compiled));
                        co.m_validformanufacturers = CommonLogic.BuildListFromCommaString(Regex.Replace(DB.RSField(rscoup, "ValidForManufacturers"), "\\s+", "", RegexOptions.Compiled));

                        co.m_validforproductsexpanded      = new List <int>();
                        co.m_validforcategoriesexpanded    = new List <int>();
                        co.m_validforsectionsexpanded      = new List <int>();
                        co.m_validformanufacturersexpanded = new List <int>();

                        co.m_deleted = DB.RSFieldBool(rscoup, "Deleted");

                        if (co.m_coupontype == CouponTypeEnum.ProductCoupon && co.m_validforcategories.Count() > 0)
                        {
                            co.m_validforcategoriesexpanded = AppLogic.LookupHelper("Category", 0).GetEntityList(CommonLogic.BuildCommaStringFromList(co.m_validforcategories), ThisCustomer.AffiliateID, ThisCustomer.CustomerLevelID);

                            List <int> pList = AppLogic.LookupHelper("Category", 0).GetProductList(CommonLogic.BuildCommaStringFromList(co.m_validforcategoriesexpanded), ThisCustomer.AffiliateID, ThisCustomer.CustomerLevelID);

                            foreach (int p in pList)
                            {
                                co.m_validforproductsexpanded.Add(p);
                            }
                        }
                        if (co.m_coupontype == CouponTypeEnum.ProductCoupon && co.m_validforsections.Count() > 0)
                        {
                            co.m_validforsectionsexpanded = AppLogic.LookupHelper("Section", 0).GetEntityList(CommonLogic.BuildCommaStringFromList(co.m_validforsections), ThisCustomer.AffiliateID, ThisCustomer.CustomerLevelID);

                            List <int> pList = AppLogic.LookupHelper("Section", 0).GetProductList(CommonLogic.BuildCommaStringFromList(co.m_validforsectionsexpanded), ThisCustomer.AffiliateID, ThisCustomer.CustomerLevelID);

                            foreach (int p in pList)
                            {
                                co.m_validforproductsexpanded.Add(p);
                            }
                        }
                        if (co.m_coupontype == CouponTypeEnum.ProductCoupon && co.m_validformanufacturers.Count() != 0)
                        {
                            co.m_validformanufacturersexpanded = AppLogic.LookupHelper("Manufacturer", 0).GetEntityList(CommonLogic.BuildCommaStringFromList(co.m_validformanufacturers), ThisCustomer.AffiliateID, ThisCustomer.CustomerLevelID);

                            List <int> pList = AppLogic.LookupHelper("Manufacturer", 0).GetProductList(CommonLogic.BuildCommaStringFromList(co.m_validformanufacturersexpanded), ThisCustomer.AffiliateID, ThisCustomer.CustomerLevelID);

                            foreach (int p in pList)
                            {
                                co.m_validforproductsexpanded.Add(p);
                            }
                        }

                        if (co.m_validforproducts.Count() > 0)
                        {
                            foreach (int p in co.m_validforproducts)
                            {
                                co.m_validforproductsexpanded.Add(p);
                            }
                        }

                        co.m_numuses = DB.RSFieldInt(rscoup, "NumUses");
                    }
                    else
                    {
                        using (SqlConnection gfCon = new SqlConnection(DB.GetDBConn()))
                        {
                            gfCon.Open();
                            //Check if the item is giftcardemail or not.
                            GiftCardTypes GiftCardTypeID = (GiftCardTypes)DB.GetSqlN(String.Format("select GiftCardTypeID N from GiftCard where lower(serialnumber)={0}", DB.SQuote(ThisCustomer.CouponCode.ToLowerInvariant())));
                            string        giftCardQuery  = string.Empty;

                            giftCardQuery = String.Format("select * from GiftCard  with (NOLOCK)  where StartDate<=getdate() and ExpirationDate>=getdate() and DisabledByAdministrator=0 and Balance>0 and SerialNumber={0}", DB.SQuote(ThisCustomer.CouponCode));

                            if (giftCardQuery != "")
                            {
                                using (IDataReader dr = DB.GetRS(giftCardQuery, gfCon))
                                {
                                    if (dr.Read())
                                    {
                                        co.m_couponset       = true;
                                        co.m_couponcode      = DB.RSField(dr, "SerialNumber");
                                        co.m_coupontype      = CouponTypeEnum.GiftCard;
                                        co.m_description     = "";
                                        co.m_startdate       = DB.RSFieldDateTime(dr, "StartDate");
                                        co.m_expirationdate  = DB.RSFieldDateTime(dr, "ExpirationDate");
                                        co.m_discountamount  = DB.RSFieldDecimal(dr, "Balance");
                                        co.m_discountpercent = 0;
                                        co.m_discountincludesfreeshipping       = false;
                                        co.m_expiresonfirstusebyanycustomer     = false;
                                        co.m_expiresafteroneusagebyeachcustomer = false;
                                        co.m_expiresafternuses          = 0;
                                        co.m_requiresminimumorderamount = System.Decimal.Zero;

                                        co.m_validforcustomers     = CommonLogic.BuildListFromCommaString(Regex.Replace(DB.RSField(dr, "ValidForCustomers"), "\\s+", "", RegexOptions.Compiled));
                                        co.m_validforproducts      = CommonLogic.BuildListFromCommaString(Regex.Replace(DB.RSField(dr, "ValidForProducts"), "\\s+", "", RegexOptions.Compiled));
                                        co.m_validforcategories    = CommonLogic.BuildListFromCommaString(Regex.Replace(DB.RSField(dr, "ValidForCategories"), "\\s+", "", RegexOptions.Compiled));
                                        co.m_validforsections      = CommonLogic.BuildListFromCommaString(Regex.Replace(DB.RSField(dr, "ValidForSections"), "\\s+", "", RegexOptions.Compiled));
                                        co.m_validformanufacturers = CommonLogic.BuildListFromCommaString(Regex.Replace(DB.RSField(dr, "ValidForManufacturers"), "\\s+", "", RegexOptions.Compiled));

                                        co.m_validforproductsexpanded      = new List <int>();
                                        co.m_validforcategoriesexpanded    = new List <int>();
                                        co.m_validforsectionsexpanded      = new List <int>();
                                        co.m_validformanufacturersexpanded = new List <int>();

                                        if (co.m_coupontype == CouponTypeEnum.ProductCoupon && co.m_validforcategories.Count() > 0)
                                        {
                                            co.m_validforcategoriesexpanded = AppLogic.LookupHelper("Category", 0).GetEntityList(CommonLogic.BuildCommaStringFromList(co.m_validforcategories), ThisCustomer.AffiliateID, ThisCustomer.CustomerLevelID);

                                            List <int> pList = AppLogic.LookupHelper("Category", 0).GetProductList(CommonLogic.BuildCommaStringFromList(co.m_validforcategoriesexpanded), ThisCustomer.AffiliateID, ThisCustomer.CustomerLevelID);

                                            foreach (int p in pList)
                                            {
                                                co.m_validforproductsexpanded.Add(p);
                                            }
                                        }
                                        if (co.m_coupontype == CouponTypeEnum.ProductCoupon && co.m_validforsections.Count() > 0)
                                        {
                                            co.m_validforsectionsexpanded = AppLogic.LookupHelper("Section", 0).GetEntityList(CommonLogic.BuildCommaStringFromList(co.m_validforsections), ThisCustomer.AffiliateID, ThisCustomer.CustomerLevelID);

                                            List <int> pList = AppLogic.LookupHelper("Section", 0).GetProductList(CommonLogic.BuildCommaStringFromList(co.m_validforsectionsexpanded), ThisCustomer.AffiliateID, ThisCustomer.CustomerLevelID);

                                            foreach (int p in pList)
                                            {
                                                co.m_validforproductsexpanded.Add(p);
                                            }
                                        }
                                        if (co.m_coupontype == CouponTypeEnum.ProductCoupon && co.m_validformanufacturers.Count() != 0)
                                        {
                                            co.m_validformanufacturersexpanded = AppLogic.LookupHelper("Manufacturer", 0).GetEntityList(CommonLogic.BuildCommaStringFromList(co.m_validformanufacturers), ThisCustomer.AffiliateID, ThisCustomer.CustomerLevelID);

                                            List <int> pList = AppLogic.LookupHelper("Manufacturer", 0).GetProductList(CommonLogic.BuildCommaStringFromList(co.m_validformanufacturersexpanded), ThisCustomer.AffiliateID, ThisCustomer.CustomerLevelID);

                                            foreach (int p in pList)
                                            {
                                                co.m_validforproductsexpanded.Add(p);
                                            }
                                        }

                                        co.m_numuses = 0;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(co);
        }