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); }
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); }