Example #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        Database db = new Database();
        string fromCity = Request.QueryString["from"];
        string toCity = Request.QueryString["to"];
        string start = Request.QueryString["start"];
        string company = Request.QueryString["company"];
        string direct = Request.QueryString["direct"];
        string filter = Request.QueryString["filter"];
        string end = "-1";
        string addon = "";
        if (company != "Any")
        {
            addon += " and companyname='" + company + "'";

        }
        if (filter == "cost")
        {
            addon += " order by price";
        }
        else
        {
            addon += " order by lengthminutes";
        }
        if (!String.IsNullOrEmpty(Request.QueryString["end"]))
        {
            end = Request.QueryString["end"];
        }
        else
        {
            Session.Remove("end");
        }

        if (direct == true.ToString())
        {
            foreach (LinkedList<string> row in db.query("select fromcity, tocity, starttime, lengthminutes, price, companyname, flightid from (" + Database.flightTable + " where fromCity='" + fromCity + "' and toCity='" + toCity + "' and starttime>to_timestamp('" + start + "', 'DD MON, YYYY')-1 and starttime>current_timestamp and availableseats>0" + addon + ") where rownum<4"))
            {
                string back = "";
                string times = "";
                string timee = "";
                string cost = "";
                string id = "";
                DateTime li = DateTime.Parse(row.ElementAt(2));
                li.AddMinutes(Int32.Parse(row.ElementAt(3)));
                if (end != "-1")
                {
                    back = "<div class='crta'>-</div>" + "<div class='from'>" + row.ElementAt(0) + "</div>";
                    foreach (LinkedList<string> row2 in db.query("select fromcity, tocity, starttime, lengthminutes, price, companyname, flightid from (" + Database.flightTable + " where fromCity='" + toCity + "' and toCity='" + fromCity + "' and starttime>to_timestamp('" + end + "', 'DD MON, YYYY')-1 and starttime>to_timestamp('" + row.ElementAt(2) + "', 'DD.MM.YYYY HH24:MI:SS') and starttime>current_timestamp and availableseats>0" + addon + ") where rownum<2"))
                    {
                        DateTime li2 = DateTime.Parse(row2.ElementAt(2));
                        li2.AddMinutes(Int32.Parse(row2.ElementAt(3)));
                        times = "<div class='od' style='margin-left: 20px;'>Време на полетување:</div>" + "<div class='fromtime'>" + row2.ElementAt(2) + "</div>";
                        timee = "<div class='od' style='margin-left: 20px;'>Време на слетување:</div>" + "<div class='fromtime'>" + li2.ToString("d.MM.yyyy HH:MM:s") + "</div>";
                        cost = "<div class='text'>Цена:</div>" + "<div class='cena'>" + row2.ElementAt(4) + " &euro;</div>" + "<div class='text'>&nbsp;&nbsp;&nbsp;Компанија:</div>" + "<div class='cena'>" + row2.ElementAt(5) + "</div>";
                        id = "-" + row2.ElementAt(6);
                    }
                }
                holder.InnerHtml += "<div class='result1' onclick='window.location.href=\"Bagage.aspx?q=" + row.ElementAt(6) + id + "\"'>" +
            "<div class='from'>" + row.ElementAt(0) + "</div>" +
            "<div class='crta'>-</div>" +
            "<div class='to'>" + row.ElementAt(1) + "</div>" + back +
            "<div class='time'>" +
                "<div class='eden'>" +
                    "<div class='od' style='width:20%; text-align:left'>Време на полетување:</div>" +
                    "<div class='fromtime' style='width:20%; text-align:left'>" + row.ElementAt(2) + "</div>" + times +
                "</div>" +
                "<div class='dva'>" +
                    "<div class='do' style='width:20%; text-align:left'>Време на слетување:</div>" +
                    "<div class='totime' style='width:20%; text-align:left'>" + li.ToString("d.MM.yyyy HH:MM:s") + "</div>" + timee +
                "</div>" +
                "<div class='tri'>" +
                    "<div class='text'>Цена:</div>" +
                    "<div class='cena' style='width:10%; text-align:left'>" + row.ElementAt(4) + " &euro;</div>" +
                    "<div class='text' style='width:10%; text-align:left'>Компанија:</div>" +
                    "<div class='cena' style='width:15%; text-align:left'>" + row.ElementAt(5) + "</div>" + cost +
                "</div>" +
            "</div>" +
        "</div>";
            }
        }
        else
        {
            Flights flights = new Flights(db.query("select fromcity, tocity, starttime, lengthminutes, price, flightid from (" + Database.flightTable + " where starttime>to_timestamp('" + start + "', 'DD MON, YYYY')-1 and starttime>current_timestamp and availableseats>0 order by starttime asc)"));

            LinkedList<Path> res1 = flights.getAllPaths(fromCity, toCity);
            if (res1 == null)
            {
                holder.InnerHtml = "<span style='color: black; font-size: 14px;'><a href='Default.aspx'>Нема таков лет</a></span>";
                return;
            }
            foreach (Path p in res1)
            {
                if (p.path == null) break;
                string back = "";
                string times = "";
                string timee = "";
                int cost = 0;
                int cost2 = 0;
                string costaddon = "";
                string id = "";
                foreach (Flight f in p.path)
                {
                    id += f.id + "-";
                    cost += f.price;
                }
                if (end != "-1")
                {
                    Flights flights2 = new Flights(db.query("select fromcity, tocity, starttime, lengthminutes, price, flightid from (" + Database.flightTable + " where starttime>to_timestamp('" + start + "', 'DD MON, YYYY')-1 and starttime>current_timestamp and starttime>to_timestamp('" + p.path.Last().end().ToString("dd.MM.yyyy HH:mm:ss") + "', 'DD.MM.YYYY HH24:MI:SS') and availableseats>0 order by starttime asc)"));
                    LinkedList<Path> res2 = flights2.getAllPaths(fromCity, toCity);
                    if (res2 == null)
                    {
                        holder.InnerHtml = "<span style='color: black; font-size: 14px;'><a href='Default.aspx'>Нема таков лет</a></span>";
                        return;
                    }
                    foreach (Path p2 in res2)
                    {
                        if (p2.path == null)
                        {
                            continue;
                        }
                        times = "<div class='od' style='margin-left: 20px;'>Време на полетување:</div>" + "<div class='fromtime'>" + p2.path.First().at.ToString("d.MM.yyyy HH:MM:s") + "</div>";
                        timee = "<div class='od' style='margin-left: 20px;'>Време на слетување:</div>" + "<div class='fromtime'>" + p2.path.Last().end().ToString("d.MM.yyyy HH:MM:s") + "</div>";

                        foreach (Flight f in p2.path)
                        {
                            id += f.id + "-";
                            cost2 += f.price;
                        }
                        costaddon = "<div class='cena' style='width:10%; text-align:left'>" + cost2.ToString() + " &euro;</div>";
                    }
                    back = "<div class='crta'>-</div>" + "<div class='from'>" + fromCity + "</div>";
                }
                id = id.Substring(0, id.Length - 1);
                holder.InnerHtml += "<div class='result1' onclick='window.location.href=\"Bagage.aspx?q=" + id + "\"'>" +
            "<div class='from'>" + fromCity + "</div>" +
            "<div class='crta'>-</div>" +
            "<div class='to'>" + toCity + "</div>" + back +
            "<div class='time'>" +
                "<div class='eden'>" +
                    "<div class='od' style='width:20%; text-align:left'>Време на полетување:</div>" +
                    "<div class='fromtime' style='width:20%; text-align:left'>" + p.path.First().at.ToString("d.MM.yyyy HH:MM:s") + "</div>" + times +
                "</div>" +
                "<div class='dva'>" +
                    "<div class='do' style='width:20%; text-align:left'>Време на слетување:</div>" +
                    "<div class='totime' style='width:20%; text-align:left'>" + p.path.Last().end().ToString("d.MM.yyyy HH:MM:s") + "</div>" + timee +
                "</div>" +
                "<div class='tri'>" +
                    "<div class='text'>Цена:</div>" +
                    "<div class='cena' style='width:10%; text-align:left'>" + cost.ToString() + " &euro;</div>" +
                    costaddon +
                "</div>" +
            "</div>" +
        "</div>";
            }
        }
        if (holder.InnerHtml.Length < 1)
        {
            holder.InnerHtml = "<span style='color: black; font-size: 14px;'><a href='Default.aspx'>Нема таков лет</a></span>";
        }
    }