//[WebMethod(Description = "CallDT")]
 public DataTable CallDT(string URL)
 {
     try
     {
         _c_function fn = new _c_function();
         DataTable   dt = fn.CallSolr_DT(URL);
         dt.TableName = "t";
         return(dt);
     }
     catch
     { return(null); }
 }
        //[WebMethod(Description = "GenQuery")]
        public string GenQuery(string keyword, string AdminLevel3, string AdminLevel2, string AdminLevel1, string PostCode, string AdminLevel4, string category, string tag, string lat, string lon, string radius, string RowsPerPage, string PageNumber, string token)
        {
            List <string> array  = category.Split('|').ToList(); // Split by comma
            List <string> array2 = tag.Split('|').ToList();

            try
            {
                _c_function fn = new _c_function();

                // Declare Latlon and URI
                string latlon     = lat + "," + lon;
                string URI        = "";
                string Nearby     = ""; // For Search Nearby
                string cutsubnear = "";
                string cutsubre   = "";
                // result
                DataTable temp = new DataTable();



                //Get Synonym
                int synocheck = 0;
                temp = fn.synonymSearch(keyword, latlon, RowsPerPage, PageNumber, ref synocheck, array);

                //Fix &
                keyword = keyword.Trim().Replace("&", "%26");

                //Create Query String
                fn.createSolrQueryString(ref URI, keyword, latlon, radius, array, array2, AdminLevel4, "6", AdminLevel3, AdminLevel2, AdminLevel1, PostCode);

                //Fix Bug Page Number
                if (PageNumber == "1")
                {
                    PageNumber = "0";
                }
                else
                {
                    PageNumber = int.Parse(PageNumber) - 1 + "";
                }

                //Finally We Got QUERY STRING
                URI = URI + "&start=" + int.Parse(RowsPerPage) * (int.Parse(PageNumber)) + "&rows=" + RowsPerPage;

                return(URI);
            }
            catch (Exception e)
            {
                return("");
            }
        }
        public string Search_Nearby(string lat, string lon, string distance, string numreturn, string token)
        {
            try
            {
                if (token == "43f9952b429485e270ccf674f")
                {
                    double dist = (double.Parse(distance) / 1000);

                    _c_function fn = new _c_function();

                    string        latlon = lat + "," + lon;
                    string        URI    = "";
                    List <string> li     = new List <string>();
                    fn.createSolrQueryString(ref URI, "*", latlon, dist.ToString(), li, li, "", "5", "", "", "", "");
                    URI = URI + "&start=0&rows=" + numreturn;

                    DataTable result = fn.CallSolr_DT(URI);


                    StringBuilder sb = new StringBuilder();

                    try
                    {
                        if (result.Rows.Count == 0)
                        {
                            return("NotFound");
                        }
                    }
                    catch (Exception e) { }

                    for (int i = 0; i < result.Rows.Count; i++)
                    {
                        sb.Append(result.Rows[i]["Name_Local"] + "!" + result.Rows[i]["Name_English"] + "!" + (1000 * double.Parse(result.Rows[i]["dist"].ToString())).ToString("F2"));
                        sb.Append("|");
                    }

                    return(sb.ToString());
                }
                else
                {
                    return("you don't have permission");
                }
            }
            catch (Exception) {
                return("Error in code Please contact developer.");
            }
        }
        public DataTable SumPOIByLocalCat(string LocalCatCode, string lat, string lon, string radius, string token)
        {
            if (check_authen(token, GetIP(), "1"))
            {
            }
            else
            {
                DataTable connect = new DataTable();
                connect.Columns.Add("result");
                connect.Rows.Add("You don't have permission.");
                connect.TableName = "Fail to Connect";
                return(connect);
            }


            try
            {
                double r = Convert.ToDouble(radius);
                r = r * 1000;
                int buffer = Convert.ToInt32(System.Configuration.ConfigurationSettings.AppSettings["SumBuffer"].ToString());
                if (r > buffer)
                {
                    r = buffer;
                }
                _c_function fn    = new _c_function();
                string[]    input = LocalCatCode.Split('|');
                DataTable   dt    = new DataTable();
                dt.TableName = "Result";
                dt.Columns.Add("No", typeof(int));
                dt.Columns.Add("LocalCatCode", typeof(string));
                dt.Columns.Add("sum", typeof(int));

                string[] tmp = LocalCatCode.Split('|');

                for (int i = 0; i < tmp.Length; i++)
                {
                    if (!string.IsNullOrEmpty(tmp[i]))
                    {
                        {
                            GT_Socket gt_socket = new GT_Socket();

                            gt_socket.Server     = "127.0.0.1";
                            gt_socket.Port       = Convert.ToInt32(System.Configuration.ConfigurationSettings.AppSettings["port"].ToString());
                            gt_socket.ProviderID = 112;

                            gt_socket.Connect();
                            string message = "6;";
                            message += lat.Trim() + ";";
                            message += lon.Trim() + ";";
                            message += r.ToString().Trim() + ";";
                            message += tmp[i].ToString().Trim();

                            gt_socket.SendData(message + " \n", false);
                            string recieve = gt_socket.recieve(10000 * 60);

                            gt_socket.Disconnect();
                            DataRow dr = dt.NewRow();
                            dr["No"]           = i + 1;
                            dr["LocalCatCode"] = tmp[i].ToString();
                            dr["sum"]          = recieve.ToString().Trim();
                            dt.Rows.Add(dr);
                        }
                    }
                }


                return(dt);
            }
            catch (Exception e)
            {
                DataTable result = new DataTable();
                result.TableName = "Error";
                result.Columns.Add("Problem");
                result.Rows.Add(e);
                return(result);
            }
        }