public void GetPricingInfoTest() { try { rswebtools rswt = new rswebtools(@"http://za.rs-online.com/web/p/microcontrollers/"); rswt.SetPartNumberData("7925934"); PricingInfo[] priceinfo; string page1; string page2; using (IWebDriver webdriver = new FirefoxDriver()) { webdriver.Navigate().GoToUrl(rswt.Url); var wait = new WebDriverWait(webdriver, TimeSpan.FromSeconds(60)); page1 = webdriver.PageSource; } using (IWebDriver webdriver = new FirefoxDriver()) { webdriver.Navigate().GoToUrl(rswt.UrlProductionQty); var wait = new WebDriverWait(webdriver, TimeSpan.FromSeconds(60)); page2 = webdriver.PageSource; } string merged = WebPage.Merge(page1, page2); rswt.SetPageData(merged); Currency.AddExhangeRate("USD", rswt.DefDestCurrency); priceinfo = rswt.GetPricingInfo(); Assert.IsTrue( (priceinfo.Count() == 5) && (priceinfo[0].minqty == 5) && (priceinfo[0].maxqty == 24) && (priceinfo[0].SrcCost == 37.31) && (priceinfo[1].minqty == 25) && (priceinfo[1].maxqty == 99) && (priceinfo[1].SrcCost == 39.662) && (priceinfo[2].minqty == 100) && (priceinfo[2].maxqty == 249) && (priceinfo[2].SrcCost == 38.076) && (priceinfo[3].minqty == 250) && (priceinfo[3].maxqty == 2499) && (priceinfo[3].SrcCost == 36.552) && (priceinfo[4].minqty == 2500) && (priceinfo[4].maxqty == 999999) && (priceinfo[4].SrcCost == 35.09) ); } catch (Exception ex) { Assert.Fail("RS GetPricingInfoTest Failed: " + ex.ToString()); } }
private void ProcessPart(List <OutputFields> BOMOut, string unique_id, string[] cols, int qty, int number_of_parts, string refdesignators) { try { partspurchasedata ppd = GetPurchaseInfo(unique_id); WriteStatus("Purchase info: id=" + ppd.id.ToString() + ", " + "comment=" + ppd.comment + ", " + "digikeypn=" + ppd.digikey_pn + ", " + "digikeymoq=" + ppd.digikeymoq.ToString() + ", " + "rs_pn=" + ppd.rs_pn + ", " + "rs_url=" + ppd.rs_url + ", " + "mouser_pn=" + ppd.mouser_pn + ", " + "farnellpn=" + ppd.farnell_pn + ", " + "rfdesignpn=" + ppd.rfdesign_pn + ", " + "mantechpn=" + ppd.mantech_pn + ", " + "ottopn=" + ppd.ottopn + ", " + "otherpn=" + ppd.otherpn + ", " + "notes=" + ppd.notes); bool fSupplierFound = false; PricingInfo[] dk_prices = new PricingInfo[0]; PricingInfo[] rfd_prices = new PricingInfo[0]; PricingInfo[] mt_prices = new PricingInfo[0]; PricingInfo[] om_prices = new PricingInfo[0]; PricingInfo[] rs_prices = new PricingInfo[0]; PricingInfo[] ms_prices = new PricingInfo[0]; PricingInfo[] other_prices = new PricingInfo[0]; // **** DIGIKEY ***** DigikeyTools dkt = new DigikeyTools(); if (ppd.digikey_pn != "") { if (ppd.digikey_pn.Contains("PIC18")) { ppd.digikey_pn = ppd.digikey_pn.Trim(); } //dkt.LoadPageData(webBrowser1,ppd.digikey_pn); dkt.LoadPageData(geckoWebBrowser1, ppd.digikey_pn); dk_prices = dkt.GetPricingInfo(); WriteStatus("Digikey Prices:"); WriteStatus("----------------"); if (dk_prices.Count() > 0) { foreach (PricingInfo p in dk_prices) { WriteStatus("Price: " + p.SrcCost.ToString("#0.000") + p.srcCurr + "(" + p.DestCost.ToString("#0.000") + p.destCurr + ") (" + p.minqty.ToString() + "-" + p.maxqty.ToString() + ")"); } fSupplierFound = true; } else { WriteStatus("INFO: no digikey prices!"); } WriteStatus("*"); } // **** RS COMPONENTS ***** rswebtools rswt = new rswebtools(ppd.rs_url); if (ppd.rs_pn != "") { rswt.LoadPageData(ppd.rs_pn); rs_prices = rswt.GetPricingInfo(); WriteStatus("RS prices Prices:"); WriteStatus("----------------"); if (rs_prices.Count() > 0) { foreach (PricingInfo p in rs_prices) { WriteStatus("Price: " + p.SrcCost.ToString("#0.000") + p.srcCurr + "(" + p.DestCost.ToString("#0.000") + p.destCurr + ") (" + p.minqty.ToString() + "-" + p.maxqty.ToString() + ")"); } fSupplierFound = true; } else { WriteStatus("INFO: no Rs component prices!"); } WriteStatus("*"); } // **** MOUSER ***** MouserWebtools mswt = new MouserWebtools(); if (ppd.mouser_pn != "") { mswt.LoadPageData(ppd.mouser_pn); ms_prices = mswt.GetPricingInfo(); WriteStatus("Mouser Prices:"); WriteStatus("----------------"); if (ms_prices.Count() > 0) { foreach (PricingInfo p in ms_prices) { WriteStatus("Price: " + p.SrcCost.ToString("#0.000") + p.srcCurr + "(" + p.DestCost.ToString("#0.000") + p.destCurr + ") (" + p.minqty.ToString() + "-" + p.maxqty.ToString() + ")"); } fSupplierFound = true; } else { WriteStatus("INFO: no Mouser component prices!"); } WriteStatus("*"); } // **** FARNELL ***** // **** RF Design **** RFDesignWebTools rfdwt = new RFDesignWebTools(); if (ppd.rfdesign_pn != "") { rfdwt.LoadPageData(ppd.rfdesign_pn); rfd_prices = rfdwt.GetPricingInfo(); WriteStatus("RF Design Prices:"); WriteStatus("----------------"); if (rfd_prices.Count() > 0) { foreach (PricingInfo p in rfd_prices) { WriteStatus("Price: " + p.SrcCost.ToString("#0.000") + p.srcCurr + "(" + p.DestCost.ToString("#0.000") + p.destCurr + ") (" + p.minqty.ToString() + "-" + p.maxqty.ToString() + ")"); } fSupplierFound = true; } else { WriteStatus("INFO: no RF Design prices!"); } WriteStatus("*"); } // **** Mantech electronics **** MantechWebTools mtwt = new MantechWebTools(); if (ppd.mantech_pn != "") { mtwt.LoadPageData(ppd.mantech_pn); mt_prices = mtwt.GetPricingInfo(); WriteStatus("Mantech Prices:"); WriteStatus("----------------"); if (mt_prices.Count() > 0) { foreach (PricingInfo p in mt_prices) { WriteStatus("Price: " + p.SrcCost.ToString("#0.000") + p.srcCurr + "(" + p.DestCost.ToString("#0.000") + p.destCurr + ") (" + p.minqty.ToString() + "-" + p.maxqty.ToString() + ")"); } fSupplierFound = true; } else { WriteStatus("INFO: no Mantech prices!"); } WriteStatus("*"); } // **** Otto Marketing **** OttoMarketingWebTools omwt = new OttoMarketingWebTools(); if (ppd.ottopn != "") { omwt.LoadPageData(ppd.ottopn); om_prices = omwt.GetPricingInfo(); WriteStatus("Otto marketing Prices:"); WriteStatus("----------------"); if (om_prices.Count() > 0) { foreach (PricingInfo p in om_prices) { WriteStatus("Price: " + p.SrcCost.ToString("#0.000") + p.srcCurr + "(" + p.DestCost.ToString("#0.000") + p.destCurr + ") (" + p.minqty.ToString() + "-" + p.maxqty.ToString() + ")"); } fSupplierFound = true; } else { WriteStatus("INFO: no Otto marketing prices!"); } WriteStatus("*"); } other_comp_tools ocdbt = new other_comp_tools(); if (ppd.otherpn != "") { ocdbt.LoadPricingInfo(ppd.otherpn, conn); other_prices = ocdbt.GetPricingInfo(); WriteStatus("Other sources Prices:"); WriteStatus("---------------------"); if (other_prices.Count() > 0) { foreach (PricingInfo p in other_prices) { WriteStatus("Price: " + p.SrcCost.ToString("#0.000") + p.srcCurr + "(" + p.DestCost.ToString("#0.000") + p.destCurr + ") (" + p.minqty.ToString() + "-" + p.maxqty.ToString() + ")"); } fSupplierFound = true; } else { WriteStatus("INFO: no other sources prices!"); } WriteStatus("*"); } if (PartsToIgnoreList.Contains(unique_id)) { fSupplierFound = true; } if (!fSupplierFound) { throw new Exception("No supplier found for part (will not be included on BOM!): " + ppd.comment); } // AJTODO: choose lowest cost supplier OutputFields of = new OutputFields(); of.Comment = unique_id; of.Descr = cols[1].Replace("\"", "").Trim(); of.bomqty = qty; of.Designators = refdesignators; if (ppd.digikey_pn != "") { // only add to order if digikey has it! WriteStatus("Using Digikey as supplier"); of.Manufacturer = dkt.GetManufacturer(); of.Manuf_pn = dkt.GetManufacturerPartNo(); of.supplier = "Digikey"; of.suppliercode = ppd.digikey_pn; of.unitprices = new double[quantities.Count()]; of.extprices = new double[quantities.Count()]; of = AddPricingInfoToBOMLine(of, dk_prices); dk_order.AddToOrder(of.suppliercode, of.Manufacturer, of.Manuf_pn, of.bomqty * number_of_parts, of.Comment, ppd.digikeymoq); } else if (ppd.rs_pn != "") { // add to rs order WriteStatus("Using RS Components as supplier"); of.Manufacturer = rswt.GetManufacturer(); of.Manuf_pn = rswt.GetManufacturerPartNo(); of.supplier = "RS Components"; of.suppliercode = ppd.rs_pn; of.unitprices = new double[quantities.Count()]; of.extprices = new double[quantities.Count()]; of = AddPricingInfoToBOMLine(of, rs_prices); rs_order.AddToOrder(of.suppliercode, of.bomqty * number_of_parts); } else if (ppd.rfdesign_pn != "") { // add rfdesign order WriteStatus("Using RF Design as supplier"); of.Manufacturer = rfdwt.GetManufacturer(); of.Manuf_pn = rfdwt.GetManufacturerPartNo(); of.supplier = "RF Design"; of.suppliercode = ppd.rfdesign_pn; of.unitprices = new double[quantities.Count()]; of.extprices = new double[quantities.Count()]; of = AddPricingInfoToBOMLine(of, rfd_prices); rfd_order.AddToOrder(of.suppliercode, of.bomqty * number_of_parts); } else if (ppd.mantech_pn != "") { // add mantech order WriteStatus("Using Mantech Electronics as supplier"); of.Manufacturer = mtwt.GetManufacturer(); of.Manuf_pn = mtwt.GetManufacturerPartNo(); of.supplier = "Mantech Electronics"; of.suppliercode = ppd.mantech_pn; of.unitprices = new double[quantities.Count()]; of.extprices = new double[quantities.Count()]; of = AddPricingInfoToBOMLine(of, mt_prices); mt_order.AddToOrder(of.suppliercode, of.bomqty * number_of_parts); } else if (ppd.ottopn != "") { // add otto marketing order WriteStatus("Using Otto Marketing as supplier"); of.Manufacturer = omwt.GetManufacturer(); of.Manuf_pn = omwt.GetManufacturerPartNo(); of.supplier = "Otto Marketing"; of.suppliercode = ppd.comment; // NOTE: we take a shortcut here! of.unitprices = new double[quantities.Count()]; of.extprices = new double[quantities.Count()]; of = AddPricingInfoToBOMLine(of, om_prices); om_order.AddToOrder(of.suppliercode, of.bomqty * number_of_parts); } else if (ppd.otherpn != "") { // add to other orders WriteStatus("Using other supplier"); of.Manufacturer = ocdbt.GetManufacturer(); of.Manuf_pn = ocdbt.GetManufacturerPartNo(); of.supplier = ocdbt.GetSupplier(); of.suppliercode = ocdbt.GetSupplierCode(); of.unitprices = new double[quantities.Count()]; of.extprices = new double[quantities.Count()]; of = AddPricingInfoToBOMLine(of, other_prices); other_order.AddToOrder(of.suppliercode, of.bomqty * number_of_parts); } else if (ppd.mouser_pn != "") { // add to mouser orders WriteStatus("Using Mouser as supplier"); of.Manufacturer = mswt.GetManufacturer(); of.Manuf_pn = mswt.GetManufacturerPartNo(); of.supplier = "Mouser Electronics"; of.suppliercode = ppd.mouser_pn; // NOTE: we take a shortcut here! of.unitprices = new double[quantities.Count()]; of.extprices = new double[quantities.Count()]; of = AddPricingInfoToBOMLine(of, ms_prices); ms_order.AddToOrder(of.suppliercode, of.bomqty * number_of_parts); } else { WriteStatus("Unknown supplier"); of.Manufacturer = "Unknown"; of.Manuf_pn = "Unknown"; of.supplier = "Unknown"; of.suppliercode = "Unknown"; of.unitprices = new double[quantities.Count()]; of.extprices = new double[quantities.Count()]; } WriteStatus("Writing output BOM"); BOMOut.Add(of); } catch (Exception ex) { if (PartsToIgnoreList.Contains(unique_id)) { WriteStatus("Purchase pricing info for " + unique_id + " ignored"); } else { ErrorCount++; WriteStatus("ERROR: Cannot get purchase info for " + unique_id + " - " + ex.ToString()); } } }