public static ShipZoneCollection LoadForCountry2(String countryCode) { ShipZoneCollection ShipZones = new ShipZoneCollection(); //CREATE THE DYNAMIC SQL TO LOAD OBJECT StringBuilder selectQuery = new StringBuilder(); selectQuery.Append("SELECT " + ShipZone.GetColumnNames("ac_ShipZones")); selectQuery.Append(" FROM ac_ShipZones LEFT JOIN ac_ShipZoneCountries ON ac_ShipZones.ShipZoneId = ac_ShipZoneCountries.ShipZoneId"); selectQuery.Append(" WHERE StoreId = @storeId"); selectQuery.Append(" AND (ac_ShipZoneCountries.CountryCode IS NULL OR ac_ShipZoneCountries.CountryCode = @CountryCode)"); Database database = Token.Instance.Database; DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString()); database.AddInParameter(selectCommand, "@countryCode", System.Data.DbType.String, countryCode); database.AddInParameter(selectCommand, "@storeId", System.Data.DbType.Int32, Token.Instance.StoreId); //EXECUTE THE COMMAND using (IDataReader dr = database.ExecuteReader(selectCommand)) { while (dr.Read()) { ShipZone shipZone = new ShipZone(); ShipZone.LoadDataReader(shipZone, dr); ShipZones.Add(shipZone); } dr.Close(); } return(ShipZones); }
public static ShipZone Load(Int32 shipZoneId, bool useCache) { if (shipZoneId == 0) { return(null); } ShipZone shipZone = null; string key = "ShipZone_" + shipZoneId.ToString(); if (useCache) { shipZone = ContextCache.GetObject(key) as ShipZone; if (shipZone != null) { return(shipZone); } } shipZone = new ShipZone(); if (shipZone.Load(shipZoneId)) { if (useCache) { ContextCache.SetObject(key, shipZone); } return(shipZone); } return(null); }
public static bool Delete(Int32 shipZoneId) { ShipZone shipZone = new ShipZone(); if (shipZone.Load(shipZoneId)) { return(shipZone.Delete()); } return(false); }
/// <summary> /// Loads the given ShipZone object from the given database data reader. /// </summary> /// <param name="shipZone">The ShipZone object to load.</param> /// <param name="dr">The database data reader to read data from.</param> public static void LoadDataReader(ShipZone shipZone, IDataReader dr) { //SET FIELDS FROM ROW DATA shipZone.ShipZoneId = dr.GetInt32(0); shipZone.StoreId = dr.GetInt32(1); shipZone.Name = dr.GetString(2); shipZone.CountryRuleId = dr.GetByte(3); shipZone.ProvinceRuleId = dr.GetByte(4); shipZone.PostalCodeFilter = NullableData.GetString(dr, 5); shipZone.ExcludePostalCodeFilter = NullableData.GetString(dr, 6); shipZone.IsDirty = false; }
public static ShipZoneCollection LoadForTaxRule(Int32 taxRuleId, 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(" " + ShipZone.GetColumnNames("ac_ShipZones")); selectQuery.Append(" FROM ac_ShipZones, ac_TaxRuleShipZones"); selectQuery.Append(" WHERE ac_ShipZones.ShipZoneId = ac_TaxRuleShipZones.ShipZoneId"); selectQuery.Append(" AND ac_TaxRuleShipZones.TaxRuleId = @taxRuleId"); 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, "@taxRuleId", System.Data.DbType.Int32, taxRuleId); database.AddInParameter(selectCommand, "@storeId", System.Data.DbType.Int32, Token.Instance.StoreId); //EXECUTE THE COMMAND ShipZoneCollection results = new ShipZoneCollection(); int thisIndex = 0; int rowCount = 0; using (IDataReader dr = database.ExecuteReader(selectCommand)) { while (dr.Read() && ((maximumRows < 1) || (rowCount < maximumRows))) { if (thisIndex >= startRowIndex) { ShipZone shipZone = new ShipZone(); ShipZone.LoadDataReader(shipZone, dr); results.Add(shipZone); rowCount++; } thisIndex++; } dr.Close(); } return(results); }
public static ShipZoneCollection 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(" " + ShipZone.GetColumnNames(string.Empty)); selectQuery.Append(" FROM ac_ShipZones"); 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 ShipZoneCollection results = new ShipZoneCollection(); int thisIndex = 0; int rowCount = 0; using (IDataReader dr = database.ExecuteReader(selectCommand)) { while (dr.Read() && ((maximumRows < 1) || (rowCount < maximumRows))) { if (thisIndex >= startRowIndex) { ShipZone shipZone = new ShipZone(); ShipZone.LoadDataReader(shipZone, dr); results.Add(shipZone); rowCount++; } thisIndex++; } dr.Close(); } return(results); }
/// <summary> /// Loads a collection of ShipZone objects for the given address /// </summary> /// <param name="countryCode">The country code; this value is required</param> /// <param name="provinceId">The ID for the province, or 0 if none</param> /// <param name="postalCode">The postal code or empty string if none</param> /// <returns>A collection of ShipZone objects for the given address</returns> public static ShipZoneCollection LoadForAddress(string countryCode, int provinceId, string postalCode) { // VALIDATE INPUT if (string.IsNullOrEmpty(countryCode)) { throw new ArgumentNullException("countryCode"); } // LOAD UP ANY SHIPZONES THAT MATCH THE COUNTRY AND PROVINCE FILTERS // BUILD THE SELECT STATEMENT StringBuilder selectSQL = new StringBuilder(); selectSQL.Append("SELECT " + ShipZone.GetColumnNames(string.Empty) + @" FROM ac_ShipZones WHERE StoreId = @storeId AND (CountryRuleId = 0 OR (CountryRuleId = 1 AND ShipZoneId IN (SELECT ShipZoneId FROM ac_ShipZoneCountries WHERE CountryCode = @countryCode)) OR (CountryRuleId = 2 AND ShipZoneId NOT IN (SELECT ShipZoneId FROM ac_ShipZoneCountries WHERE CountryCode = @countryCode))) AND (ProvinceRuleId = 0 OR (ProvinceRuleId = 1 AND ShipZoneId IN (SELECT ShipZoneId FROM ac_ShipZoneProvinces WHERE ProvinceId = @provinceId)) OR (ProvinceRuleId = 2 AND ShipZoneId NOT IN (SELECT ShipZoneId FROM ac_ShipZoneProvinces WHERE ProvinceId = @provinceId)))"); // DETERMINE WHETHER A POSTAL CODE IS PROVIDED FOR THE ADDRESS if (string.IsNullOrEmpty(postalCode)) { // NO POSTAL CODE IS PROVIDED, ELIMINATE SHIPZONES THAT CANNOT BE MATCHED selectSQL.Append("AND ((PostalCodeFilter IS NULL AND UsePCPM = 0) OR UsePCPM = 1)"); } else { // POSTAL CODE IS PROVIDED, ONLY INCLUDE SHIPZONES THAT MAY BE MATCHED selectSQL.Append(@"AND (((PostalCodeFilter IS NULL OR PostalCodeFilter = @postalCode) AND (ExcludePostalCodeFilter IS NULL OR ExcludePostalCodeFilter <> @postalCode) AND UsePCPM = 0) OR UsePCPM = 1)"); } // CREATE COMMAND AND POPULATE PARAMETERS Database database = Token.Instance.Database; DbCommand selectCommand = database.GetSqlStringCommand(string.Format(selectSQL.ToString(), countryCode, provinceId, postalCode)); database.AddInParameter(selectCommand, "@storeId", DbType.Int32, Token.Instance.StoreId); database.AddInParameter(selectCommand, "@countryCode", DbType.String, countryCode); database.AddInParameter(selectCommand, "@provinceId", DbType.Int32, provinceId); if (!string.IsNullOrEmpty(postalCode)) { database.AddInParameter(selectCommand, "@postalCode", DbType.String, postalCode); } // EXECUTE THE COMMAND ShipZoneCollection shipZones = new ShipZoneCollection(); using (IDataReader dr = database.ExecuteReader(selectCommand)) { // LOOP THE QUERY RESULTS while (dr.Read()) { // CONVERT QUERY RECORD TO SHIPZONE OBJECT ShipZone shipZone = new ShipZone(); ShipZone.LoadDataReader(shipZone, dr); // IF POSTAL CODE PATTERN MATCHING (PCPM) IS NOT REQUIRED // OR IF THE POSTAL CODE MATCHES THE PATTERN, THIS SHIP ZONE APPLIES TO THE ADDRESS if (!shipZone.UsePCPM || shipZone.IncludesPostalCode(postalCode)) { shipZones.Add(shipZone); } } dr.Close(); } // RETURN THE SHIPZONES THAT APPLY TO THIS ADDRESS return(shipZones); }
public static SaveResult Update(ShipZone shipZone) { return(shipZone.Save()); }
public static SaveResult Insert(ShipZone shipZone) { return(shipZone.Save()); }
public static bool Delete(ShipZone shipZone) { return(shipZone.Delete()); }