Example #1
0
        public KeyWord getCategory(String keyword)
        {
            connect();
            string query = "SELECT * FROM TUKHOADICHVU";

            adapter = new SqlDataAdapter(query, connection);
            DataSet dataset = new DataSet();

            adapter.Fill(dataset);
            ArrayList ls = ConvertDataSetToArrayList(dataset);
            KeyWord   kw = new KeyWord();

            foreach (Object o in ls)
            {
                KeyCategory key = (KeyCategory)o;
                keyword = FormatString.FormatSrt(keyword);
                String str = FormatString.FormatSrt(key.NameKeyCategory);
                int    ps  = keyword.IndexOf(str);
                if (keyword == str)
                {
                    kw.Id          = key.IdCateggory;
                    kw.StrKeyFirst = "";
                    kw.StrKeyLast  = "";
                    return(kw);
                }
                if (ps == 0 && keyword.Length > str.Length)
                {
                    kw.Id          = key.IdCateggory;
                    kw.StrKeyFirst = "";
                    kw.StrKeyLast  = keyword.Substring(str.Length - ps);
                    return(kw);
                }
                if (ps > 0 && ((ps + str.Length) <= keyword.Length))
                {
                    kw.Id          = key.IdCateggory;
                    kw.StrKeyFirst = keyword.Substring(ps + str.Length);
                    kw.StrKeyLast  = keyword.Substring(0, ps);
                    return(kw);
                }
                if (ps > 0)
                {
                    kw.Id          = key.IdCateggory;
                    kw.StrKeyFirst = "";
                    kw.StrKeyLast  = keyword.Substring(0, ps);
                    return(kw);
                }
            }
            disconnect();
            return(null);
        }
Example #2
0
        public List <Place> Search(String str)
        {
            List <Place>   listPlace      = new List <Place>();
            KeyCategoryDAO keyCategoryDAO = new KeyCategoryDAO();
            KeyWord        kw             = keyCategoryDAO.getCategory(str);

            if (kw != null)

            {
                if (kw.StrKeyFirst == "" && kw.StrKeyLast == "")
                {
                    listPlace = getDsDiaDiem(kw.Id, "DICHVU.MaDichVu");
                    return(listPlace);
                }
                else
                {
                    KeyDistrictDAO keyDistrictDAO = new KeyDistrictDAO();
                    if (kw.StrKeyFirst == "")
                    {
                        int t = keyDistrictDAO.getDistrict(kw.StrKeyLast);
                        if (t != -1)
                        {
                            listPlace = getDsDiaDiem(kw.Id, t, "QUANHUYEN.MaQuanHuyen");
                            return(listPlace);
                        }
                    }
                    if (kw.StrKeyLast == "")
                    {
                        int t = keyDistrictDAO.getDistrict(kw.StrKeyFirst);
                        if (t != -1)
                        {
                            listPlace = getDsDiaDiem(kw.Id, t, "QUANHUYEN.MaQuanHuyen");
                            return(listPlace);
                        }
                    }


                    else
                    {
                        KeyWardDAO keyWardDAO = new KeyWardDAO();
                        if (kw.StrKeyFirst == "")
                        {
                            int t = keyWardDAO.getWard(kw.StrKeyLast);
                            if (t != -1)
                            {
                                listPlace = getDsDiaDiem(kw.Id, t, "QUANHUYEN.MaQuanHuyen");
                                return(listPlace);
                            }
                        }
                        if (kw.StrKeyLast == "")
                        {
                            int t = keyWardDAO.getWard(kw.StrKeyFirst);
                            if (t != -1)
                            {
                                listPlace = getDsDiaDiem(kw.Id, t, "QUANHUYEN.MaQuanHuyen");
                                return(listPlace);
                            }
                        }
                        else
                        {
                            listPlace = getDsDiaDiem(kw.Id, "DICHVU.MaDichVu");
                            return(listPlace);
                        }
                    }
                }
            }
            else
            {
                KeyDistrictDAO keyDistrictDAO = new KeyDistrictDAO();
                int            t = keyDistrictDAO.getDistrict(str);
                if (t != -1)
                {
                    listPlace = getDsDiaDiem(t, "QUANHUYEN.MaQuanHuyen");
                    return(listPlace);
                }
                else
                {
                    KeyWardDAO keyWardDAO = new KeyWardDAO();
                    t = keyWardDAO.getWard(str);
                    if (t != -1)
                    {
                        listPlace = getDsDiaDiem(t, "PHUONG.MaPhuong");
                        return(listPlace);
                    }
                    else
                    {
                        KeyPlaceDAO keyPlace = new KeyPlaceDAO();
                        List <int>  list     = keyPlace.getPlace(str);
                        if (list.Count != 0)
                        {
                            for (int j = 0; j < list.Count; j++)
                            {
                                listPlace = getDsDiaDiem(list[j], "TenDiaDiem.MaTenDiaDiem");
                                return(listPlace);
                            }
                        }
                        else
                        {
                            return(null);
                        }
                    }
                }
            }

            return(null);
        }