Beispiel #1
0
        public List <SupplierNew> GetScannerRates(string url)
        {
            string responseFromServer = GetSource(url);

            int remove = Regex.Match(responseFromServer, "(\\w)*\\[\\],").Captures[0].Index + 3;;

            string subJson = "{" + responseFromServer.Substring(remove, responseFromServer.Length - 2 - remove);

            JToken entireJson = JToken.Parse(subJson);

            JArray vehVendorAvails = entireJson["VehAvailRSCore"]["VehVendorAvails"].Value <JArray>();// Get suppliers

            List <SupplierNew> offers = new List <SupplierNew>();

            foreach (var item in vehVendorAvails)
            {
                string supplier = item["Vendor"]["@CompanyShortName"].ToString();
                foreach (var vehicle in item["VehAvails"])
                {
                    string      category = vehicle["VehAvailCore"]["Vehicle"]["@Code"].ToString();                // category
                    string      price    = vehicle["VehAvailCore"]["TotalCharge"]["@RateTotalAmount"].ToString(); //price
                    SupplierNew offer    = new SupplierNew(supplier, price);
                    offer.SetCategory(category);
                    offers.Add(offer);
                }
            }
            return(offers);
        }
Beispiel #2
0
        public List <SupplierNew> ExtractOffers(HtmlNodeCollection resultGroups)
        {
            List <SupplierNew> offers = new List <SupplierNew>();

            if (resultGroups != null)
            {
                foreach (HtmlNode mainNode in resultGroups)
                {
                    string price    = ParsePrice(mainNode);
                    string supplier = ParseSupplier(mainNode);
                    string category = ParseCategory(mainNode);
                    string transm   = ParseTransm(mainNode);
                    string seats    = ParseSeats(mainNode);
                    string carName  = ParseCarname(mainNode);

                    SupplierNew o = new SupplierNew(supplier, price, category, transm, seats, carName);
                    //if (carName.ToLower().Contains("renault clio estate") && o.Transmission.Equals("A"))
                    //    o.Category = "Economy";
                    offers.Add(o);
                }
            }
            else
            {
                Debug.WriteLine("JSOURCEREDAER 0 offer number ");
            }

            return(offers);
        }
Beispiel #3
0
        public List <SupplierNew> GetNorwRates(string url)
        {
            string responseFromServer = GetSource(url);

            int remove = Regex.Match(responseFromServer, "(\\w)*\\[\\],").Captures[0].Index + 3;

            string subJson = "{" + responseFromServer.Substring(remove, responseFromServer.Length - 2 - remove);

            JToken entireJson = JToken.Parse(subJson);

            JArray vehVendorAvails = entireJson["VehAvailRSCore"]["VehVendorAvails"].Value <JArray>();// Get suppliers

            List <SupplierNew> offers = new List <SupplierNew>();

            foreach (var item in vehVendorAvails)
            {
                string supplier = item["Vendor"]["@CompanyShortName"].ToString();
                foreach (var vehicle in item["VehAvails"])
                {
                    string      category = vehicle["VehAvailCore"]["Vehicle"]["@Code"].ToString();                             // category
                    string      price    = vehicle["VehAvailCore"]["TotalCharge"]["@RateTotalAmount"].ToString();              //price
                    string      transm   = vehicle["VehAvailCore"]["Vehicle"]["@TransmissionType"].ToString().Substring(0, 1); //transm
                    string      carName  = vehicle["VehAvailCore"]["Vehicle"]["VehMakeModel"]["@Name"].ToString();             // carname
                    float       seats    = int.Parse(vehicle["VehAvailCore"]["Vehicle"]["@PassengerQuantity"].ToString());     //seats
                    SupplierNew offer    = new SupplierNew(supplier, price);
                    offer.CarName = carName;
                    offer.SetCategory(category);
                    //offer.Transmission = transm;
                    offer.Seats = seats;
                    offers.Add(offer);
                }
            }
            return(offers);
        }
Beispiel #4
0
 protected string IsEmptySupplier(SupplierNew sup)
 {
     if (sup != null && sup.SupplierName != null)
     {
         if (sup.SupplierName.Equals(""))
         {
             return("-" + " " + sup.Price + "\n");
         }
         else
         {
             return((sup.SupplierName.Length > 3 ? sup.SupplierName.ToLower().Substring(0, 4) : sup.SupplierName.ToLower().Substring(0, 3)) + " " + sup.Price + "\n");
         }
     }
     return("");
 }
Beispiel #5
0
    public string GetOffer()
    {
        try
        {
            string output = string.Empty;

            SupplierNew other = Suppliers.OrderBy(s => s.Price).FirstOrDefault(f => f.SupplierType == 4);
            SupplierNew best  = Suppliers.OrderBy(s => s.Price).FirstOrDefault(f => f.SupplierType == 3);
            SupplierNew cr    = Suppliers.OrderBy(s => s.Price).FirstOrDefault(f => f.SupplierType == 2);
            SupplierNew gm    = Suppliers.OrderBy(s => s.Price).FirstOrDefault(f => f.SupplierType == 1);

            List <SupplierNew> suppliersNew = new List <SupplierNew>();//Suppliers.GroupBy(g => g.SupplierType, (key, s) => s.OrderBy(e => e.Price).First()).ToList();

            if (Suppliers.Count(s => s.SupplierType == 4) > 1)
            {
                suppliersNew.AddRange(Suppliers.Where(s => s.SupplierType == 4).OrderBy(p => p.Price).Take(2).ToList());
            }
            else if (Suppliers.FirstOrDefault(s => s.SupplierType == 4) != null)
            {
                suppliersNew.Add(other);
            }

            if (gm != null)
            {
                suppliersNew.Add(gm);
            }
            if (cr != null)
            {
                suppliersNew.Add(cr);
            }
            if (best != null)
            {
                suppliersNew.Add(best);
            }
            //if (other != null)
            //    suppliersNew.Add(other);

            foreach (SupplierNew sup in suppliersNew.OrderBy(t => t.Price))
            {
                output += IsEmptySupplier(sup);
            }
            return(output);
        }
        catch (Exception e)
        {
            return(null);
        }
    }
Beispiel #6
0
    public List <SupplierNew> GetDistinctSuppliers()
    {
        SupplierNew        gm           = Suppliers.FirstOrDefault(s => s.SupplierType == 1);
        SupplierNew        cr           = Suppliers.FirstOrDefault(s => s.SupplierType == 2);
        SupplierNew        best         = Suppliers.FirstOrDefault(s => s.SupplierType == 3);
        List <SupplierNew> suppliersNew = new List <SupplierNew>();//Suppliers.GroupBy(g => g.SupplierType, (key, s) => s.OrderBy(e => e.Price).First()).ToList();

        if (Suppliers.Count(s => s.SupplierType == 4) > 1)
        {
            suppliersNew.AddRange(Suppliers.Where(s => s.SupplierType == 4).OrderBy(p => p.Price).Take(2).ToList());
        }
        else if (Suppliers.FirstOrDefault(s => s.SupplierType == 4) != null)
        {
            suppliersNew.Add(Suppliers.FirstOrDefault(s => s.SupplierType == 4));
        }

        return(suppliersNew);
    }
Beispiel #7
0
        public string GetExcel(SiteBase s, Dictionary <string, Dictionary <string, JOffer> > offerMap)
        {
            FileInfo template = new FileInfo(HttpContext.Current.Server.MapPath(@"\Content\ExcelPackageTemplate.xlsx"));
            string   filename = @"\output\" + s.GetTitle() + s.GetPuMonth() + "-" + s.GetPuDay() + s.GetCity() + ".xlsx";
            FileInfo newFile  = new FileInfo(HttpContext.Current.Server.MapPath(filename));

            using (ExcelPackage excelPackage = new ExcelPackage(newFile, template))
            {
                ExcelWorkbook  myWorkbook  = excelPackage.Workbook;          // Getting the complete workbook...
                ExcelWorksheet myWorksheet = myWorkbook.Worksheets["Rates"]; // Getting the worksheet by its name...

                int      rowNum = 2;
                DateTime doDate = new DateTime(Convert.ToInt32(s.GetPuYear()), Convert.ToInt32(s.GetPuMonth()), Convert.ToInt32(s.GetPuDay()));
                foreach (string link in offerMap.Keys.ToList())
                {
                    Dictionary <string, JOffer> map = offerMap[link];
                    List <JOffer> offers            = OffersToArray(map, link);
                    int           colNum            = 2;
                    myWorksheet.Cells[rowNum, 1].Value = s.GetPuMonth() + "-" + s.GetPuDay() + "/" + doDate.AddDays(rowNum - 1).Day + "\n" + (rowNum - 1);
                    for (int i = 0; i < offers.Count; i++)
                    {
                        myWorksheet.Row(rowNum).Height = 50;
                        //myWorksheet.Row(rowNum + 1).Height = 50;
                        //myWorksheet.Row(rowNum + 2).Height = 50;

                        JOffer      o     = offers.ElementAt(i);
                        SupplierNew other = o.GetOtherSupplier();
                        SupplierNew gm    = o.GetGmSupplier();
                        SupplierNew cr    = o.GetCrSupplier();

                        myWorksheet.Cells[rowNum, colNum].Value     = (gm != null ? gm.ToString() : "");
                        myWorksheet.Cells[rowNum, colNum + 1].Value = (cr != null ? cr.ToString() : "");
                        myWorksheet.Cells[rowNum, colNum + 2].Value = (other != null ? other.ToString() : "");
                        colNum += 3;
                    }
                    rowNum++;
                }
                excelPackage.Save();// Saving the change...
                return(filename);
            }
        }
Beispiel #8
0
 public void AddCar(SupplierNew s)
 {
     using (RatesDBContext ctx = new RatesDBContext())
     {
         Cars c = ctx.Cars.FirstOrDefault(o => o.CarName.Contains(s.CarName));
         if (c == null)
         {
             ctx.Cars.Add(new Cars
             {
                 CarName      = s.CarName,
                 Category     = s.Category.Contains("skip") ? s.Category.Substring(4) : s.Category,
                 Seats        = s.Seats,
                 Transmission = s.Transmission,
                 SupplierName = s.SupplierName,
                 SupplierType = s.SupplierType,
                 IsAssigned   = true
             });
             ctx.SaveChanges();
         }
     }
 }
Beispiel #9
0
 public void AddSupplier(SupplierNew sp)
 {
     Suppliers.Add(sp);
 }
Beispiel #10
0
    public float GetMinGmPrice()
    {
        SupplierNew s = Suppliers.OrderBy(t => t.Price).FirstOrDefault(s1 => s1.SupplierType == 1 && s1.Price > 0);

        return(s != null ? s.Price : 0);
    }
Beispiel #11
0
        public void AddRow(JOffer[] offers)
        {
            try
            {
                PdfPCell cell = new PdfPCell(new Phrase(puMonth + "-" + puDay + "/" + doDate.AddDays(dayNum).Day + "\n" + dayNum, font));
                dayNum++;
                cell.HorizontalAlignment = 1;
                cell.VerticalAlignment   = 1;
                table.AddCell(cell);
                for (int i = 0; i < offers.Length; i++)
                {
                    JOffer o = offers[i];
                    cell = new PdfPCell(new Phrase(o.GetOffer(), font));

                    var chunk = new Chunk(o.GetOffer(), font);

                    SupplierNew other = o.GetOtherSupplier();
                    SupplierNew gm    = o.GetGmSupplier();
                    SupplierNew cr    = o.GetCrSupplier();
                    SupplierNew best  = o.GetBestSupplier();

                    if (other != null)
                    {
                        AddSuppliers(other.SupplierName);//best
                    }
                    if (best != null)
                    {
                        AddSuppliers(best.SupplierName);//best
                    }
                    if (cr != null)
                    {
                        AddSuppliers(cr.SupplierName);// carsrent
                    }
                    if (i == 0)
                    {
                        chunk.SetAnchor(o.GetSiteName());// if mini add site name
                    }
                    cell.AddElement(chunk);
                    if (gm != null && other != null && other.Price > gm.Price && gm.Price > 0)
                    {
                        cell.BackgroundColor = new BaseColor(77, 148, 255);
                        if (other.Price - gm.Price < 2.5f && other.Price - gm.Price > 0)
                        {
                            cell.BackgroundColor = new BaseColor(255, 255, 179);
                            if (other.Price - gm.Price < 1.5f && other.Price - gm.Price > 0)
                            {
                                cell.BackgroundColor = new BaseColor(128, 255, 128);
                            }
                        }
                    }
                    else
                    {
                        cell.BackgroundColor = new BaseColor(255, 102, 102);
                    }

                    table.AddCell(cell);
                }
                table.CompleteRow();
            }
            catch (Exception e) {
                Log.Instance.Warn("-PdfBuilder.AddRow-" + e.InnerException + e.Message);
            }
        }