/// <summary>
        /// Get the pricing info on the part from the website
        /// </summary>
        /// <returns></returns>
        public override PricingInfo[] GetPricingInfo()
        {
            try
            {
                List <PricingInfo> priceslist = new List <PricingInfo>(10);

                foreach (string line in WebPageLines)
                {
                    string m1 = "<SPAN id=productPrice>";
                    string m2 = "</SPAN>";
                    if (line.Contains(m1))
                    {
                        int p1 = line.IndexOf(m1);
                        int p2 = line.IndexOf(m2, p1);
                        p1 += m1.Length;
                        string      pricestr = line.Substring(p1, p2 - p1);
                        PricingInfo p        = new PricingInfo();
                        Double.TryParse(pricestr, out p.DestCost);
                        Double.TryParse(pricestr, out p.SrcCost);
                        p.destCurr = "ZAR";
                        p.srcCurr  = "ZAR";
                        p.minqty   = 1;
                        p.maxqty   = 999999;

                        priceslist.Add(p);
                    }
                }
                return(priceslist.ToArray());
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 /// <summary>
 /// Constructor for other_comp_tools
 /// </summary>
 public OtherSuppliersWebTools()
 {
     m_pricearr     = new PricingInfo[2];
     m_Supplier     = "";
     m_Suppliercode = "";
     m_Manuf        = "";
     m_Manufpn      = "";
 }
Example #3
0
        /// <summary>
        /// Fix the maximum price quantities
        /// </summary>
        /// <param name="p"></param>
        public void FixMaximumQtys(ref List <PricingInfo> p)
        {
            int i;

            // fix the maximum values
            for (i = 0; i < (p.Count() - 1); i++)
            {
                PricingInfo tp = p[i];
                tp.maxqty = p[i + 1].minqty - 1;
                p[i]      = tp;
            }
        }
        /// <summary>
        /// Load the pricing info for"other" parts from database
        /// </summary>
        /// <param name="pn"></param>
        /// <param name="toCurrency"></param>
        /// <param name="conn"></param>
        public void LoadPricingInfo(string pn, MySqlConnection conn, string toCurrency = "ZAR")
        {
            try
            {
                bool            OK  = false;
                string          sql = "SELECT * FROM partspriceinfo WHERE partdesc = '" + pn + "'";
                MySqlCommand    cmd = new MySqlCommand(sql, conn);
                MySqlDataReader rdr = cmd.ExecuteReader();

                List <PricingInfo> prices = new List <PricingInfo>();

                PricingInfo p = new PricingInfo();

                while (rdr.Read())
                {
                    m_Supplier     = rdr[2].ToString().Trim();
                    m_Suppliercode = rdr[3].ToString().Trim();
                    m_Manuf        = rdr[4].ToString().Trim();
                    m_Manufpn      = rdr[5].ToString().Trim();

                    Int32.TryParse(rdr[6].ToString(), out p.minqty);
                    Int32.TryParse(rdr[7].ToString(), out p.maxqty);
                    p.srcCurr = rdr[8].ToString().Trim();
                    Double.TryParse(rdr[9].ToString(), out p.SrcCost);

                    p.DestCost = Currency.Convert(p.srcCurr, toCurrency, p.SrcCost);

                    prices.Add(p);
                    OK = true;
                }
                rdr.Close();

                if (!OK)
                {
                    throw new Exception(pn + " not found in database");
                }

                m_pricearr = prices.ToArray();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #5
0
        /// <summary>
        /// Obtain pricing information from Digikey website
        /// </summary>
        /// <returns></returns>
        public override PricingInfo[] GetPricingInfo()
        {
            try
            {
                List <PricingInfo> priceslist = new List <PricingInfo>(50);

                HtmlDocument htmlDoc = new HtmlDocument();
                htmlDoc.LoadHtml(WebPageData);

                HtmlNode           node      = htmlDoc.GetElementbyId("product-dollars");
                HtmlNodeCollection tablerows = node.SelectNodes("tbody//tr");

                foreach (HtmlNode row in tablerows)
                {
                    HtmlNodeCollection tablecolumns = row.SelectNodes("td");

                    if (!ReferenceEquals(tablecolumns, null))
                    {
                        if (tablecolumns.Count() > 2)
                        {
                            HtmlNode[] cols = tablecolumns.ToArray();

                            string minqtystr = cols[0].InnerText;
                            minqtystr = minqtystr.Replace(",", "");
                            int    minqty       = Int32.Parse(minqtystr);
                            double srcunitprice = Double.Parse(cols[1].InnerText);
                            double destprice    = Currency.Convert("USD", DefDestCurrency, srcunitprice);

                            PricingInfo p = new PricingInfo("USD", DefDestCurrency, srcunitprice, destprice, minqty, 999999);
                            priceslist.Add(p);
                        }
                    }
                }

                FixMaximumQtys(ref priceslist);

                return(priceslist.ToArray());
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private void m_GetPricingInfo(string content, bool IsHigherQuantitiesPage = false)
        {
            try
            {
                bool         Done    = false;
                HtmlDocument htmlDoc = new HtmlDocument();
                htmlDoc.LoadHtml(WebPageData);

                HtmlNodeCollection pricetablenodes = htmlDoc.DocumentNode.SelectNodes(@"//div[@class='price-table']");

                foreach (HtmlNode pricedetablenode in pricetablenodes)
                {
                    for (int i = 0; (i < 1000) && (!Done); i++)
                    {
                        string qstr = @"div[@id='value-row-" + i.ToString() + "']";

                        HtmlNodeCollection noderows = pricedetablenode.SelectNodes(qstr);

                        if (noderows != null)
                        {
                            HtmlNode noderow = noderows[0];

                            HtmlNodeCollection minmaxrangenodes = noderow.SelectNodes(@"div[@itemprop='eligibleQuantity']");
                            HtmlNodeCollection pricenodes       = noderow.SelectNodes(@"div[@class='unitPrice']");

                            if ((minmaxrangenodes != null) && (pricenodes != null))
                            {
                                if (!minmaxrangenodes[0].InnerText.Contains("+"))
                                {
                                    string[] minmaxstr = minmaxrangenodes[0].InnerText.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries);
                                    int      minqty    = int.Parse(minmaxstr[0]);
                                    int      maxqty    = int.Parse(minmaxstr[1]);

                                    string pricetext    = pricenodes[0].InnerText.Replace("R", "").Trim();
                                    double srcunitprice = double.Parse(pricetext);
                                    double destprice    = Currency.Convert("ZAR", DefDestCurrency, srcunitprice);

                                    PricingInfo p = new PricingInfo("ZAR", DefDestCurrency, srcunitprice, destprice, minqty, 999999);
                                    lp.Add(p);
                                }
                                else if (!minmaxrangenodes[0].InnerText.Contains("-"))
                                {
                                    string[] minmaxstr = minmaxrangenodes[0].InnerText.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries);
                                    minmaxstr[0] = minmaxstr[0].Replace("+", "").Trim();
                                    int minqty = int.Parse(minmaxstr[0]);

                                    string pricetext    = pricenodes[0].InnerText.Replace("R", "").Trim();
                                    double srcunitprice = double.Parse(pricetext);
                                    double destprice    = Currency.Convert("ZAR", DefDestCurrency, srcunitprice);

                                    PricingInfo p = new PricingInfo("ZAR", DefDestCurrency, srcunitprice, destprice, minqty, 999999);
                                    lp.Add(p);
                                }
                            }
                            else
                            {
                                Done = true;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }


            /*
             * try
             * {
             *  int idx = 0;
             *  int p1 = 0;
             *  string m1 = "class=\"dr-table-cell rich-table-cell quantity\">";
             *  string m2 = "</td>";
             *  string qtystr = "";
             *  string pricestr = "";
             *  string pr1 = "<span itemprop='price'><span class=\"nowrap\">R ";
             *  string pr2 = "</span>";
             *
             *  bool HasMoreprices = true;
             *  while (HasMoreprices)
             *  {
             *      p1 = content.IndexOf(m1, p1);
             *
             *      if (p1 >= 0)
             *      {
             *          int p2 = content.IndexOf(m2, p1);
             *          p1 += m1.Length;
             *          qtystr = content.Substring(p1, p2 - p1);
             *
             *          p1 = content.IndexOf(pr1, p1);
             *          p2 = content.IndexOf(pr2, p1);
             *
             *          p1 += pr1.Length;
             *          pricestr = content.Substring(p1, p2 - p1);
             *
             *          if ((IsHigherQuantitiesPage && (idx > 0)) || (!IsHigherQuantitiesPage))
             *          {
             *              PricingInfo p = new PricingInfo();
             *              p.destCurr = "ZAR";
             *              p.srcCurr = "ZAR";
             *              Double.TryParse(pricestr, out p.DestCost);
             *              p.SrcCost = p.DestCost;
             *
             *              Int32.TryParse(qtystr, out p.minqty);
             *              p.maxqty = 999999;
             *              lp.Add(p);
             *          }
             *          idx++;
             *      }
             *      else
             *      {
             *          HasMoreprices = false;
             *      }
             *  }
             * }
             * catch (Exception ex)
             * {
             *  throw ex;
             * }
             */
        }
        /// <summary>
        /// Return pricing info from the mouser website
        /// </summary>
        /// <returns></returns>
        public override PricingInfo[] GetPricingInfo()
        {
            try
            {
                List <PricingInfo> priceslist = new List <PricingInfo>(50);
                bool Done = false;

                HtmlDocument htmlDoc = new HtmlDocument();
                htmlDoc.LoadHtml(WebPageData);

                for (int i = 1; (i < 1000) && (!Done); i++)
                {
                    string qstr = string.Format("ctl00_ContentMain_ucP_rptrPriceBreaks_ctl0{0}_lnkQuantity", i);
                    string pstr = string.Format("ctl00_ContentMain_ucP_rptrPriceBreaks_ctl0{0}_lblPrice", i);

                    HtmlNode nodeqty   = htmlDoc.GetElementbyId(qstr);
                    HtmlNode nodeprice = htmlDoc.GetElementbyId(pstr);

                    if ((nodeprice != null) && (nodeprice != null))
                    {
                        string qtystr   = nodeqty.InnerText.Replace(",", "");   // AJTODO correctly parse thousands separator
                        string pricestr = nodeprice.InnerText.Replace("$", ""); // AJTODO write a generic currency parser - or use an existing one

                        if ((qtystr != "") && (pricestr != ""))
                        {
                            int min = Int32.Parse(qtystr);
                            if (!pricestr.Contains("Quote"))
                            {
                                double srcunitprice = double.Parse(pricestr);
                                double destprice    = Currency.Convert("USD", DefDestCurrency, srcunitprice);

                                PricingInfo p = new PricingInfo("USD", DefDestCurrency, srcunitprice, destprice, min, 999999);
                                priceslist.Add(p);
                            }
                        }
                    }
                    else
                    {
                        Done = true;
                    }
                }

                FixMaximumQtys(ref priceslist);

                return(priceslist.ToArray());
            }
            catch (Exception ex)
            {
                throw ex;
            }

            /*
             *
             *          int i = 0;
             *          int state = 0;
             *          int qty = 0;
             *          double price;
             *          List<PricingInfo> priceslist = new List<PricingInfo>(50);
             *
             *          try
             *          {
             *              while ((i < WebPageLines.Count()) && (state < 2))
             *              {
             *                  switch (state)
             *                  {
             *                      case 0:
             *                          if (WebPageLines[i].Contains(@"<table class=""PriceBreaks"" cellspacing=""0"">"))
             *                          {
             *                              state = 1;
             *                              i += 11;
             *                          }
             *                          else
             *                          {
             *                              i++;
             *                          }
             *                          break;
             *
             *                      case 1:
             *                          string res = StringUtils.GetTextBetweenMarkers(WebPageLines[i], @""">", "</a>");
             *                          res = StringUtils.StringToNumericsOnly(res);
             *                          if (!Int32.TryParse(res, out qty))
             *                          {
             *                              throw new Exception("Invalid qty in mouser webpage.");
             *                          }
             *
             *                          string pricestr;
             *                          if (!WebPageLines[i + 3].Contains(@"Quote</></span>"))
             *                          {
             *                              pricestr = StringUtils.GetTextBetweenMarkers(WebPageLines[i + 3], @""">$", "</span>");
             *                              if (!Double.TryParse(pricestr, out price))
             *                              {
             *                                  throw new Exception("Invalid price in mouser webpage.");
             *                              }
             *                              double destprice = Currency.Convert("USD", "ZAR", price);
             *                              PricingInfo p = new PricingInfo("USD", "ZAR", price, destprice, qty, 9999999);
             *                              priceslist.Add(p);
             *
             *                          }
             *                          if ((WebPageLines[i + 16] == "<tr>") &&
             *                              (!WebPageLines[i + 3].Contains(@"Quote</></span>")))
             *                          {
             *                              i += 19;
             *                          }
             *                          else
             *                          {
             *                              state = 2;
             *                          }
             *                          break;
             *
             *                      default:
             *                          break;
             *                  }
             *              }
             *
             *              // fix the maximum values
             *              for (i = 0; i < (priceslist.Count() - 1); i++)
             *              {
             *                  PricingInfo tp = priceslist[i];
             *                  tp.maxqty = priceslist[i + 1].minqty - 1;
             *                  priceslist[i] = tp;
             *              }
             *
             *              return priceslist.ToArray();
             *          }
             *          catch (Exception e)
             *          {
             *              throw e;
             *          }
             */
        }
Example #8
0
        /// <summary>
        /// Get the pricing information from the otto marketing website
        /// </summary>
        /// <returns></returns>
        public override PricingInfo[] GetPricingInfo()
        {
            try
            {
                List <PricingInfo> l = new List <PricingInfo>(5);

                HtmlDocument htmlDoc = new HtmlDocument();
                htmlDoc.LoadHtml(WebPageData);

                HtmlNodeCollection prices = htmlDoc.DocumentNode.SelectNodes(@"//span[@itemprop='price']");

                if ((prices != null) && (prices.Count == 1))
                {
                    foreach (HtmlNode pricenode in prices)
                    {
                        string pricestr    = pricenode.InnerText;
                        double sourceprice = double.Parse(pricestr);
                        double destprice   = sourceprice;

                        PricingInfo p = new PricingInfo("ZAR", "ZAR", destprice, sourceprice, 1, 999999);
                        l.Add(p);
                    }
                }

                return(l.ToArray());
            }
            catch (Exception ex)
            {
                throw ex;
            }

            /*
             * try
             * {
             *  int state = 0;
             *  List<PricingInfo> l = new List<PricingInfo>(5);
             *  foreach (string line in WebPageLines)
             *  {
             *      switch (state)
             *      {
             *          case 0:
             *              if (line.Contains("<b>Code:</b>"))
             *              {
             *                  if (StringUtils.GetTextBetweenMarkers(line, "<b>Code:</b>", "</a>").Trim() == PartNumber)
             *                  {
             *                      state = 1;
             *                  }
             *              }
             *              break;
             *
             *          case 1:
             *              if (line.Contains(" <a href="))
             *              {
             *                  string pricetxt = StringUtils.GetTextBetweenMarkers(line, "/\">R", "</a>").Trim();
             *                  PricingInfo p = new PricingInfo();
             *                  Double.TryParse(pricetxt, out p.DestCost);
             *                  p.SrcCost = p.DestCost;
             *                  p.destCurr = "ZAR";
             *                  p.srcCurr = "ZAR";
             *                  p.minqty = 1;
             *                  p.maxqty = 999999;
             *                  l.Add(p);
             *                  state = 2;
             *              }
             *              break;
             *      }
             *  }
             *  return l.ToArray();
             * }
             * catch (Exception ex)
             * {
             *  throw ex;
             * }
             */
        }
Example #9
0
        /// <summary>
        ///  Get the pricing of the part from the Mantech website
        /// </summary>
        /// <returns>PricingInfo[] array</returns>
        public override PricingInfo[] GetPricingInfo()
        {
            try
            {
                List <PricingInfo> priceslist = new List <PricingInfo>(50);

                HtmlDocument htmlDoc = new HtmlDocument();
                htmlDoc.LoadHtml(WebPageData);

                HtmlNodeCollection tablerows = htmlDoc.DocumentNode.SelectNodes(@"//div[@id='ctl00_ContentPlaceHolder1_FormView1_Panel2']//tr");

                if (tablerows != null)
                {
                    foreach (HtmlNode tablerow in tablerows)
                    {
                        HtmlNodeCollection tablecols = tablerow.SelectNodes(@".//td");

                        if (tablecols != null)
                        {
                            if (tablecols.Count == 2)
                            {
                                HtmlNodeCollection rowqtys   = tablecols[0].SelectNodes(@".//span");
                                HtmlNodeCollection pricenode = tablecols[1].SelectNodes(@".//span");

                                if ((rowqtys != null) && (pricenode != null))
                                {
                                    int    minqty        = int.Parse(rowqtys[0].InnerText.Trim());
                                    int    maxqty        = int.Parse(rowqtys[2].InnerText.Trim());
                                    double srcunitprice  = double.Parse(pricenode[1].InnerText.Trim());
                                    double destunitprice = Currency.Convert("ZAR", DefDestCurrency, srcunitprice);

                                    PricingInfo p = new PricingInfo("ZAR", DefDestCurrency, srcunitprice, destunitprice, minqty, 999999);
                                    priceslist.Add(p);
                                }
                            }
                        }
                    }
                }

                FixMaximumQtys(ref priceslist);
                return(priceslist.ToArray());

                /*
                 *              int state = 0;
                 *              List<PricingInfo> priceslist = new List<PricingInfo>(50);
                 *
                 *              for (int i = 0; (i < WebPageLines.Count()) && (state < 2); i++)
                 *              {
                 *                  string line = WebPageLines[i];
                 *                  switch (state)
                 *                  {
                 *                      case 0: // look for price marker
                 *                          if (line.Contains("Price</td>"))
                 *                          {
                 *                              state = 1;
                 *                          }
                 *                          break;
                 *
                 *                      case 1: //
                 *                          if (line.Contains("On Request"))
                 *                          {
                 *                              PricingInfo p = new PricingInfo(true);
                 *                              priceslist.Add(p);
                 *                              state = 2;
                 *                          }
                 *                          else if (line.Contains("<span id=\""))
                 *                          {
                 *                              // we have the start of pricing info
                 *                              string t = "";
                 *                              PricingInfo p = new PricingInfo();
                 *
                 *                              t = StringUtils.GetTextBetweenMarkers(WebPageLines[i], "\">", "</span>");
                 *                              Int32.TryParse(t, out p.minqty);
                 *
                 *                              t = StringUtils.GetTextBetweenMarkers(WebPageLines[i + 2], "\">", "</span>");
                 *                              Int32.TryParse(t, out p.maxqty);
                 *
                 *                              t = StringUtils.GetTextBetweenMarkers(WebPageLines[i + 6], "\">", "</span>");
                 *                              Double.TryParse(t, out p.SrcCost);
                 *                              p.DestCost = p.SrcCost;
                 *                              p.destCurr = "ZAR";
                 *                              p.srcCurr = "ZAR";
                 *                              priceslist.Add(p);
                 *                              i += 8;
                 *                          }
                 *                          else if (line.Contains("</table>"))
                 *                          {
                 *                              // we are done with pricing for this part
                 *                              state = 2;
                 *                          }
                 *                          break;
                 *
                 *                      case 2:
                 *                          break;
                 *
                 *                      default:
                 *                          state = 0;
                 *                          break;
                 *                  }
                 *              }
                 *              return priceslist.ToArray();
                 *
                 */
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }