コード例 #1
0
        //Danh sach cac tinh thanh la diem den
        private List <SelectListItem> GetCityDestination(int StartID, int SelectedID)
        {
            List <SelectListItem> items = new List <SelectListItem>();
            RepositoryOBTRS       db    = new RepositoryOBTRS();
            List <int>            city  = db.GetCityEnd(StartID);

            for (int i = 0; i < city.Count; i++)
            {
                if (Convert.ToInt32(city[i]) == SelectedID)
                {
                    items.Add(new SelectListItem {
                        Text = db.GetCityName(city[i]), Value = city[i].ToString(), Selected = true
                    });
                }
                else
                {
                    items.Add(new SelectListItem {
                        Text = db.GetCityName(city[i]), Value = city[i].ToString()
                    });
                }
            }
            return(items);
        }
コード例 #2
0
        //Ham lay danh sach cac tinh thanh lam diem di
        private List <SelectListItem> GetCityDeparture()
        {
            List <SelectListItem> items = new List <SelectListItem>();
            RepositoryOBTRS       db    = new RepositoryOBTRS();
            List <int>            city  = db.GetCityStart();

            for (int i = 0; i < city.Count; i++)
            {
                items.Add(new SelectListItem {
                    Text = db.GetCityName(city[i]), Value = city[i].ToString()
                });
            }
            return(items);
        }
コード例 #3
0
        public ActionResult SearchDetail(FormCollection form)
        {
            try
            {
                //Kiem tra va lay ID cua dia diem khoi hanh
                if (form["CityDeparture"] != null)
                {
                    //Lay thong tin dia diem di va den truyen cho Title
                    RepositoryOBTRS dbrep      = new RepositoryOBTRS();
                    int             cityDepart = Convert.ToInt16(form["CityDeparture"]);
                    ViewData["Title_Departure"] = dbrep.GetCityName(cityDepart);
                    int cityDesti = Convert.ToInt16(form["CityDestination"]);
                    ViewData["Title_Destination"] = dbrep.GetCityName(cityDesti);
                    //Ket thuc lay thong tin

                    int id = Convert.ToInt16(form["CityDeparture"]);
                    ViewData["CityStart"] = GetCityDeparture(id);
                    if (form["CityDestination"] != null)
                    {
                        int DestinationID = Convert.ToInt16(form["CityDestination"]);
                        ViewData["CityEnd"] = GetCityDestination(id, DestinationID);
                    }
                    else
                    {
                        ViewData["CityEnd"] = GetCityDestination(id);
                        //ViewData["CityDestination"] = "?";
                    }
                }
                else
                {
                    ViewData["CityStart"] = GetCityDeparture();
                    ViewData["CityEnd"]   = GetCityDestination(1);
                }

                if (form["CityDeparture"] != null && form["CityDestination"] != null)
                {
                    db_OBTRSDataContext db = new db_OBTRSDataContext();
                    int Departure          = Convert.ToInt32(form["CityDeparture"]);
                    int Destination        = Convert.ToInt32(form["CityDestination"]);

                    string Depart = "%%";
                    if (form["txtDepartureDate"] != null && form["txtDepartureDate"] != "")
                    {
                        DateTime dt = DateTime.Parse(form["txtDepartureDate"].ToString());
                        Depart = "%" + dt.DayOfWeek.ToString().Substring(0, 2).ToUpper() + "%";
                    }
                    var tblRoute = db.sp_GetRouteMatch(Departure, Destination, Depart);
                    ViewData["DataRoute"] = tblRoute;
                }
                else
                {
                    ViewData["DataRoute"] = null;
                }
                if (form["txtDepartureDate"] == null)
                {
                    String currentDate = DateTime.Now.ToShortDateString();
                    ViewData["DateDepart"] = currentDate;
                    //Setup session date ngay ma khach hang chon khoi hanh
                    Session["DateDeparture"] = currentDate;
                }
                else
                {
                    ViewData["DateDepart"]   = form["txtDepartureDate"];
                    Session["DateDeparture"] = form["txtDepartureDate"];
                }
            }catch (Exception)
            {
                Response.Write("<strong style='font-size:12pt'>Have a error in during request to server!</strong>");
                Response.Write("<br>Sorry for this inconvenience! Please<a href='/Home'> click here</a> to HOME PAGE.");
                //throw;
                return(null);
            }

            return(View());
        }