/// <summary> /// Returns where condition based on webpart fields. /// </summary> private WhereCondition GetWhereCondition() { // Orders from current site var where = new WhereCondition() .WhereEquals("OrderSiteID", SiteContext.CurrentSiteID); // Order status filter var status = OrderStatusInfoProvider.GetOrderStatusInfo(OrderStatus, SiteContext.CurrentSiteName); if (status != null) { where.WhereEquals("OrderStatusID", status.StatusID); } // Customer or company like filter if (!string.IsNullOrEmpty(CustomerOrCompany)) { where.WhereIn("OrderCustomerID", new IDQuery<CustomerInfo>() .Where("CustomerFirstName + ' ' + CustomerLastName + ' ' + CustomerFirstName LIKE N'%"+ SqlHelper.EscapeLikeText(SqlHelper.EscapeQuotes(CustomerOrCompany)) + "%'") .Or() .WhereContains("CustomerCompany", CustomerOrCompany)); } // Filter for orders with note if (HasNote) { where.WhereNotEmpty("OrderNote"); } // Payment method filter var payment = PaymentOptionInfoProvider.GetPaymentOptionInfo(PaymentMethod, SiteContext.CurrentSiteName); if (payment != null) { where.WhereEquals("OrderPaymentOptionID", payment.PaymentOptionID); } // Payment status filter switch (PaymentStatus.ToLowerCSafe()) { case PAY_STATUS_NOT_PAID: where.Where(new WhereCondition().WhereFalse("OrderIsPaid").Or().WhereNull("OrderIsPaid")); break; case PAY_STATUS_PAID: where.WhereTrue("OrderIsPaid"); break; } // Currency filter var currencyObj = CurrencyInfoProvider.GetCurrencyInfo(Currency, SiteContext.CurrentSiteName); if (currencyObj != null) { where.WhereEquals("OrderCurrencyID", currencyObj.CurrencyID); } // Min price in main currency filter if (MinPriceInMainCurrency > 0) { where.Where("OrderTotalPriceInMainCurrency", QueryOperator.LargerOrEquals, MinPriceInMainCurrency); } // Max price in main currency filter if (MaxPriceInMainCurrency > 0) { where.Where("OrderTotalPriceInMainCurrency", QueryOperator.LessOrEquals, MaxPriceInMainCurrency); } // Shipping option filter var shipping = ShippingOptionInfoProvider.GetShippingOptionInfo(ShippingOption, SiteContext.CurrentSiteName); if (shipping != null) { where.WhereEquals("OrderShippingOptionID", shipping.ShippingOptionID); } // Shipping country filter if (!string.IsNullOrEmpty(ShippingCountry) && ShippingCountry != "0") { AddCountryWhereCondition(where); } // Date filter AddDateWhereCondition(where); return where; }
/// <summary> /// Returns where condition based on webpart fields. /// </summary> private WhereCondition GetWhereCondition() { // Orders from current site var where = new WhereCondition() .WhereEquals("OrderSiteID", SiteContext.CurrentSiteID); // Order status filter var status = OrderStatusInfoProvider.GetOrderStatusInfo(OrderStatus, SiteContext.CurrentSiteName); if (status != null) { where.WhereEquals("OrderStatusID", status.StatusID); } // Customer or company like filter if (!string.IsNullOrEmpty(CustomerOrCompany)) { where.WhereIn("OrderCustomerID", new IDQuery <CustomerInfo>() .Where("CustomerFirstName + ' ' + CustomerLastName + ' ' + CustomerFirstName LIKE N'%" + SqlHelper.EscapeLikeText(SqlHelper.EscapeQuotes(CustomerOrCompany)) + "%'") .Or() .WhereContains("CustomerCompany", CustomerOrCompany)); } // Filter for orders with note if (HasNote) { where.WhereNotEmpty("OrderNote"); } // Payment method filter var payment = PaymentOptionInfoProvider.GetPaymentOptionInfo(PaymentMethod, SiteContext.CurrentSiteName); if (payment != null) { where.WhereEquals("OrderPaymentOptionID", payment.PaymentOptionID); } // Payment status filter switch (PaymentStatus.ToLowerCSafe()) { case PAY_STATUS_NOT_PAID: where.Where(new WhereCondition().WhereFalse("OrderIsPaid").Or().WhereNull("OrderIsPaid")); break; case PAY_STATUS_PAID: where.WhereTrue("OrderIsPaid"); break; } // Currency filter var currencyObj = CurrencyInfoProvider.GetCurrencyInfo(Currency, SiteContext.CurrentSiteName); if (currencyObj != null) { where.WhereEquals("OrderCurrencyID", currencyObj.CurrencyID); } // Min price in main currency filter if (MinPriceInMainCurrency > 0) { where.Where("OrderTotalPriceInMainCurrency", QueryOperator.LargerOrEquals, MinPriceInMainCurrency); } // Max price in main currency filter if (MaxPriceInMainCurrency > 0) { where.Where("OrderTotalPriceInMainCurrency", QueryOperator.LessOrEquals, MaxPriceInMainCurrency); } // Shipping option filter var shipping = ShippingOptionInfoProvider.GetShippingOptionInfo(ShippingOption, SiteContext.CurrentSiteName); if (shipping != null) { where.WhereEquals("OrderShippingOptionID", shipping.ShippingOptionID); } // Shipping country filter if (!string.IsNullOrEmpty(ShippingCountry) && ShippingCountry != "0") { AddCountryWhereCondition(where); } // Date filter AddDateWhereCondition(where); return(where); }