Created
July 6, 2016 13:59
-
-
Save maxlord/1c82002207e1dd7ccfbca2234301fc61 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var codes = new List<string>(); | |
codes.Add(db.Quote(config.Keyword.ToUpper())); | |
// Добавляем кроссы - если выбран соотв параметр | |
if (config.DisplayAnalogs) | |
{ | |
if (crossInfosIfCodeSearchMaked != null && crossInfosIfCodeSearchMaked.Any()) | |
{ | |
foreach (var ci in crossInfosIfCodeSearchMaked) | |
{ | |
codes.Add(db.Quote(ci.PartCode)); | |
} | |
} | |
} | |
var whereArticle = String.Join(", ", codes); | |
var sb = new StringBuilder(); | |
sb.Append(@" | |
SELECT | |
0 AS ""Id"", | |
COALESCE(pa.""Article"", '') AS ""Code"", | |
psi.""Name"" AS ""Name"", | |
COALESCE(pm.""Name"", '') AS ""Manufacturer"", | |
COALESCE(ps.""Stock"", 0) AS ""Count"", | |
ps.""PriceBase"" AS ""BasePrice"", | |
ps.""PriceSell"" AS ""SellPrice"", | |
ps.""IsSecHand"" AS ""IsSecHand"", | |
ps.""IsDefected"" AS ""IsDefected"", | |
nc.""name_ru"" AS ""City"", | |
pp.""CityId"" AS ""CityId"", | |
pp.""Id"" AS ""ProviderId"", | |
psi.""Number"" AS ""ItemNumber"", | |
pp.""Name"" AS ""ProviderName"", | |
COALESCE(pp.""Phones"", '') AS ""ProviderPhones"", | |
COALESCE(pp.""Address"", '') AS ""ProviderAddress"", | |
pp.""RetailMode"" AS ""IsRetail"", | |
ps.""UpdateDate"" AS ""UpdateDate"", | |
nc.""name_ru"" AS ""CityName"", | |
pp.""DeliveryMode"" AS ""DeliveryType"", | |
pp.""MinAmount"", | |
COALESCE(pp.""Rate"", 0) AS ""ShopRate"" | |
FROM pa_stock ps | |
INNER JOIN pa_article pa ON ps.""ArticleId"" = pa.""Id"" | |
INNER JOIN pa_stock_item psi ON ps.""ItemId"" = psi.""Id"" | |
INNER JOIN pa_manufacturer pm ON psi.""ManufacturerId"" = pm.""Id"" | |
INNER JOIN pa_pricelist ppr ON ps.""PricelistId"" = ppr.""Id"" | |
INNER JOIN pa_provider pp ON ppr.""Id"" = pp.""ActualPricelistId"" | |
INNER JOIN net_city nc ON pp.""CityId"" = nc.""id"" | |
INNER JOIN net_region nr ON nc.""region_id"" = nr.""id"" | |
LEFT JOIN pa_stock_item_description psid ON ps.""ItemDescriptionId"" = psid.""Id"" | |
WHERE pa.""Article"" IN (").Append(whereArticle).Append(")"); | |
if (config.Mode == MyPriceEvaluateConfig.SearchMode.Favorites) | |
{ | |
if (config.Favorites.Count == 1) | |
{ | |
sb.AppendFormat(" AND pp.\"Id\" = {0}", config.Favorites[0]); | |
} | |
else | |
{ | |
sb.Append(" AND pp.\"Id\" IN (").Append(String.Join(",", config.Favorites)).Append(")"); | |
} | |
} | |
else if (config.Mode == MyPriceEvaluateConfig.SearchMode.City) | |
{ | |
if (config.Cities.Count == 1) | |
{ | |
sb.AppendFormat(" AND pp.\"CityId\" = {0}", config.Cities[0]); | |
} | |
else | |
{ | |
sb.Append(" AND pp.\"CityId\" IN (").Append(String.Join(",", config.Cities)).Append(")"); | |
} | |
} | |
else if (config.Mode == MyPriceEvaluateConfig.SearchMode.Region) | |
{ | |
if (config.Regions.Count == 1) | |
{ | |
sb.AppendFormat(" AND nr.\"id\" = {0}", config.Regions[0]); | |
} | |
else | |
{ | |
sb.Append(" AND nr.\"id\" IN (").Append(String.Join(",", config.Regions)).Append(")"); | |
} | |
} | |
else if (config.Mode == MyPriceEvaluateConfig.SearchMode.Country) | |
{ | |
if (config.Countries.Count == 1) | |
{ | |
sb.AppendFormat(" AND nr.\"country_id\" = {0}", config.Countries[0]); | |
} | |
else | |
{ | |
sb.Append(" AND nr.\"country_id\" IN (").Append(String.Join(",", config.Countries)).Append(")"); | |
} | |
} | |
if (config.DisplayRatingShops) | |
{ | |
sb.Append(" AND COALESCE(pp.\"Rate\", 0) >= 3"); | |
} | |
if (!config.DisplayDefect) | |
{ | |
sb.Append(" AND ps.\"IsDefected\" = 0"); | |
} | |
if (config.DisplayNew && !config.DisplaySecondHand) // Если выбрано НОВЫЕ и не выбрано Б/У, отображаем только НЕ Б/У | |
{ | |
sb.Append(" AND ps.\"IsSecHand\" = 0"); | |
} | |
else if (!config.DisplayNew && config.DisplaySecondHand) // Если выбрано Б/У и не выбрано НОВЫЕ, отображаем только Б/У | |
{ | |
sb.Append(" AND ps.\"IsSecHand\" = 1"); | |
} | |
// Сортировка | |
sb.Append(" ORDER BY COALESCE(pm.\"Name\", '') ASC, psi.\"Name\" ASC"); | |
return sb.ToString(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment