private static String[] GetDataset(DataTable dtroutes)
    {
        String[] returnval = new String[dtroutes.Rows.Count + 2];

        try
        {
            decimal max = 0; decimal min = 0; decimal dec = 0; decimal din = 0;

            #region Get bus rating

            ClsBAL objManabusBAL = new ClsBAL();
            DataTable dtRating = objManabusBAL.GetRatings().Tables[0];

            #endregion

            #region Get distinct travels

            DataTable dtTravels = ((DataTable)(HttpContext.Current.Session["dtRoutes"])).DefaultView.ToTable(true, "Travels");

            DataRow[] drTravels = dtTravels.Select("", "Travels ASC");

            StringBuilder sbTravels = new StringBuilder();

            if (drTravels.Length > 0)
            {
                sbTravels.Append("<select id=\"ddlOperator\" name=\"ddlOperator\"  multiple=\"multiple\"  class=\"Dropdownlist\" onchange=\"LoadFilteredRoutes(event,''); return false;\" >");//multiple=\"multiple\"

                //sbTravels.Append("<option value=''>All Operators</option>");

                string strOperator = "";
                if (HttpContext.Current.Session["travelOperatorSelected"] != null)
                {
                    strOperator = HttpContext.Current.Session["travelOperatorSelected"].ToString();
                }
                foreach (DataRow item in drTravels)
                {
                    if (strOperator != item["Travels"].ToString())
                    {
                        sbTravels.Append("<option value=" + "\"" + item["Travels"].ToString() + "\"" + ">" + item["Travels"].ToString() + "</option>");
                    }
                    else
                    {
                        sbTravels.Append("<option selected='selected' value=" + "\"" + item["Travels"].ToString() + "\"" + ">" + item["Travels"].ToString() + "</option>");
                    }
                }
                sbTravels.Append("</select>");
            }

            returnval[dtroutes.Rows.Count] = sbTravels.ToString();

            #endregion

            for (int i = 0; i < dtroutes.Rows.Count; i++)
            {
                DataRow[] dr = null;
                if (dtroutes.Rows[i]["Travels"].ToString().Length >= 5)
                {
                    dr = dtRating.Select("BusOperatorName LIKE '" + dtroutes.Rows[i]["Travels"].ToString().Substring(0, 5) + "%'");
                }
                else { dr = dtRating.Select("BusOperatorName LIKE '" + dtroutes.Rows[i]["Travels"].ToString() + "%'"); }

                String sRating = dr.Length > 0 ? "Images/star" + dr[0]["Rating"].ToString() + ".png" : "Images/star3.png";
                //sRating = "";

                string sDuration = dtroutes.Rows[i]["Duration"].ToString();
                if (sDuration == "") { sDuration = " - "; }
                string sArrTime = dtroutes.Rows[i]["ArrTime"].ToString();
                if (sArrTime == "") { sArrTime = " - "; }
                string sBusType = dtroutes.Rows[i]["BusType"].ToString();
                if (sBusType.Length > 50) { sBusType = sBusType.Substring(0, 48); }

                returnval[i] = dtroutes.Rows[i]["API"].ToString() + "~" + dtroutes.Rows[i]["SNo"].ToString() + "~"
                                + dtroutes.Rows[i]["Travels"].ToString() + "~" + sBusType + "~"
                                + dtroutes.Rows[i]["DepTime"].ToString() + "~" + sArrTime + "~"
                                + sDuration + "~" + dtroutes.Rows[i]["Fare"].ToString() + "~"
                                + dtroutes.Rows[i]["ReservationId"].ToString() + "~"
                                + dtroutes.Rows[i]["ServiceId"].ToString() + "~" + dtroutes.Rows[i]["CoachTypeId"].ToString() + "~"
                                + dtroutes.Rows[i]["ServiceNumber"].ToString() + "~"
                                + dtroutes.Rows[i]["BoardingPointsWithIds"].ToString() + "~" + dtroutes.Rows[i]["DropingPointsWithIds"].ToString() + "~"
                                + dtroutes.Rows[i]["lblS"].ToString() + "~"
                                + dtroutes.Rows[i]["lblB"].ToString() + "~"
                                + sRating + "~" + dtroutes.Rows[i]["AvailableSeats"].ToString();

                if (i == 0) { max = min = Convert.ToDecimal(Convert.ToDecimal(dtroutes.Rows[i]["Fare"].ToString()).ToString("0", System.Globalization.CultureInfo.InvariantCulture)); }
                dec = din = Convert.ToDecimal(Convert.ToDecimal(dtroutes.Rows[i]["Fare"].ToString()).ToString("0", System.Globalization.CultureInfo.InvariantCulture));
                if (dec > max) { max = dec; }
                if (din < min) { min = din; }
            }
            if (dtroutes.Rows.Count != 0)
            {
                returnval[dtroutes.Rows.Count + 1] = min + "|" + max;
            }
            else { returnval[dtroutes.Rows.Count + 1] = "1" + "|" + "2500"; }
        }
        catch (Exception e)
        {
            //
        }
        return returnval;
    }
Exemplo n.º 2
0
 void BindGrid()
 {
     objBAL = new ClsBAL();
     DataSet ds = objBAL.GetRatings();
     gvRating.DataSource = ds;
     ViewState["Rating"] = ds.Tables[0];
     gvRating.DataBind();
 }