/// <summary> /// Calculate offer MOQ as maximum of moq and order_multiple fields in offer dict. /// </summary> /// <param name="offer">The offer to find the MOQ from</param> /// <returns>The MOQ, or -1 if not found</returns> public static int GetRealMoq(this ApiV4Schema.PartOffer offer) { int moq = -1; int order_multiple = -1; try { if (!string.IsNullOrEmpty(offer.moq)) { moq = Convert.ToInt32(offer.moq, CultureInfo.CreateSpecificCulture("en-US")); } if (!string.IsNullOrEmpty(offer.order_multiple)) { Convert.ToInt32(offer.order_multiple, CultureInfo.CreateSpecificCulture("en-US")); } } catch (FormatException) { /* Do nothing */ } catch (OverflowException) { /* Do nothing */ } if (order_multiple != -1) { if ((moq == -1) || (moq < order_multiple)) { moq = order_multiple; } } return(moq); }
/// <summary> /// Find the best price given the price break /// </summary> /// <param name="offer">The offer to search within</param> /// <param name="currency">The 3 character currency code</param> /// <param name="qty">The quantity to search for (i.e. QTY required)</param> /// <returns>The minimum price available for the specified QTY</returns> public static double MinPrice(this ApiV4Schema.PartOffer offer, string currency, int qty) { // Force format optional arguments if (currency == string.Empty) { currency = "USD"; } if (qty == 0) { qty = 1; } double minprice = double.MaxValue; try { string minpricestr = ApiV4.OffersMinPrice(currency, offer, qty, true); if (!string.IsNullOrEmpty(minpricestr)) { minprice = Convert.ToDouble(minpricestr, CultureInfo.CurrentCulture); } } catch (FormatException) { /* Do nothing */ } catch (OverflowException) { /* Do nothing */ } return(minprice); }
public static object OCTOPART_DISTRIBUTOR_SKU( [ExcelArgument(Description = "Part Number Lookup", Name = "MPN or SKU")] string mpn_or_sku, [ExcelArgument(Description = "Manufacturer of the part to query (optional)", Name = "Manufacturer")] string manuf = "", [ExcelArgument(Description = "Distributor for lookup (optional)", Name = "Distributor")] string distributor = "") { ApiV4Schema.PartOffer offer = GetOffer(mpn_or_sku, manuf, distributor); if (offer != null) { // ---- BEGIN Function Specific Information ---- return offer.sku; // ---- END Function Specific Information ---- } mpn_or_sku = mpn_or_sku.PadRight(mpn_or_sku.Length + _refreshhack.Length); object asyncResult = ExcelAsyncUtil.Run("OCTOPART_DISTRIBUTOR_SKU", new object[] { mpn_or_sku, manuf, distributor }, delegate { try { offer = SearchAndWaitOffer(mpn_or_sku, manuf, distributor); if (offer == null) { string err = QueryManager.GetLastError(mpn_or_sku); if (string.IsNullOrEmpty(err)) err = "Query did not provide a result. Please widen your search criteria."; return "ERROR: " + err; } // ---- BEGIN Function Specific Information ---- return offer.sku; // ---- END Function Specific Information ---- } catch (Exception ex) { log.Fatal(ex.ToString()); return "ERROR: " + OctopartQueryManager.FATAL_ERROR; } }); if (asyncResult.Equals(ExcelError.ExcelErrorNA)) { return "!!! Processing !!!"; } else if (!string.IsNullOrEmpty(QueryManager.GetLastError(mpn_or_sku)) || (offer == null)) { _refreshhack = string.Empty.PadRight(new Random().Next(0, 100)); } return asyncResult; }
public static int GetRealOrderMultiple(this ApiV4Schema.PartOffer offer) { int order_multiple = 1; try { if (!string.IsNullOrEmpty(offer.order_multiple)) { order_multiple = Convert.ToInt32(offer.order_multiple, CultureInfo.CreateSpecificCulture("en-US")); } } catch (FormatException) { /* Do nothing */ } catch (OverflowException) { /* Do nothing */ } return(order_multiple); }
/// <summary> /// Convert a string based factory lead days to an int. /// </summary> /// <param name="offer">The offer to find the MOQ from</param> /// <returns>The factory lead days, or Int.Max if not found</returns> public static int GetRealFactoryLeadDays(this ApiV4Schema.PartOffer offer) { int factory_lead_days = int.MaxValue; try { if (!string.IsNullOrEmpty(offer.factory_lead_days)) { factory_lead_days = Convert.ToInt32(offer.factory_lead_days, CultureInfo.CreateSpecificCulture("en-US")); } } catch (FormatException) { /* Do nothing */ } catch (OverflowException) { /* Do nothing */ } return(factory_lead_days); }