Beispiel #1
0
        public bool SendToEngine(string message)
        {
            try
            {
                GT_Socket gt_socket = new GT_Socket();
                gt_socket.Server     = IP;   // "127.0.0.1";
                gt_socket.Port       = PORT; // 9999;
                gt_socket.ProviderID = 112;
                gt_socket.Connect();

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

                //string[] tmp = recieve.Split(new string[] { "#@@#" }, StringSplitOptions.None);
                //int i = tmp[1].Length ;

                gt_socket.Disconnect();
                return(true);
            }
            catch
            {
                return(false);
            }
        }
        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);
            }
        }
        public string Search(string keyword, string AdminLevel3, string AdminLevel2, string AdminLevel1, string PostCode, string AdminLevel4, string category, string LocalCatCode, string tag, string lat, string lon, string radius, string RowsPerPage, string PageNumber, string token)
        {
            //Thread.CurrentThread.CurrentCulture = new CultureInfo("th-TH");
            //Filter parameter
            if (string.IsNullOrEmpty(RowsPerPage))
            {
                RowsPerPage = "20";
            }
            if (string.IsNullOrEmpty(PageNumber))
            {
                PageNumber = "1";
            }

            int indexEnd   = Convert.ToInt32(RowsPerPage) * Convert.ToInt32(PageNumber);
            int indexStart = (indexEnd - Convert.ToInt32(RowsPerPage)) + 1;

            Stopwatch sw = new Stopwatch();

            sw.Start();
            //Check Permission
            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(null);
            }

            try
            {
                string rs = "";
                if (!string.IsNullOrEmpty(radius))
                {
                    double r = Convert.ToDouble(radius);
                    r  = r * 1000;
                    rs = r.ToString();
                }
                GT_Socket gt_socket = new GT_Socket();

                // Initial server information
                //gt_socket.Server = "192.168.1.67";//"globetech.gps.be-mobile.biz"; //
                //gt_socket.Port = 10002;//8085;//
                //gt_socket.Server = "127.0.0.1";
                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 syno_replace = syn.Dup(keyword.Trim());

                string message = "";
                message += "1;";//type
                message += keyword.Trim() + ";";
                message += syno_replace.Trim() + ";";
                message += ";";                                                                                         //th
                message += ";";                                                                                         //other
                message += ";";                                                                                         //nostraid
                message += AdminLevel4 + ";";                                                                           //adminlv4
                message += AdminLevel3 + ";";                                                                           //adminlv3
                message += AdminLevel2 + ";";                                                                           //adminlv2
                message += AdminLevel1 + ";";                                                                           //adminlv1

                message += category + ";";                                                                              //cat
                message += LocalCatCode + ";";                                                                          //subcode,localCatCode
                message += tag + ";";                                                                                   //tag
                message += PostCode + ";";                                                                              //PostCode

                message += lat + ";";                                                                                   //lat
                message += lon + ";";                                                                                   //lon
                message += rs + ";";                                                                                    //r
                message += System.Configuration.ConfigurationSettings.AppSettings["MaxReturnSearch"].ToString().Trim(); //return

                bool   stat    = gt_socket.SendData(message + " \n", false);
                string recieve = gt_socket.recieve(10000 * 60);
                int    kk      = recieve.Length;
                //string recieve2 = gt_socket.recieve(10000 * 60);

                gt_socket.Disconnect();

                //recieve += recieve2;
                string[] line = recieve.Split('|');

                DataTable dt     = new DataTable();
                string[]  header = line[0].Split('^');
                for (int i = 0; i < header.Length; i++)
                {
                    if (header[i] == "dist" || header[i] == "score")
                    {
                        dt.Columns.Add(header[i], typeof(double));
                    }
                    else
                    {
                        dt.Columns.Add(header[i], typeof(string));
                    }
                }

                for (int i = indexStart; i < line.Length; i++)
                {
                    if (line[i].Trim() == "")
                    {
                        break;
                    }
                    string[] tmp = line[i].Split('^');
                    dt.Rows.Add(tmp);
                    if (i == indexEnd)
                    {
                        break;
                    }
                }

                dt.Columns.Add("No", typeof(string));
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    dt.Rows[i]["No"] = indexStart.ToString();
                    indexStart++;
                }

                //return recieve;

                long ij = sw.ElapsedMilliseconds;
                dt.TableName = "res" + ij.ToString() + "ms";
                dt.Columns.Remove("hitscore");
                dt.Columns.Remove("NAME_THEN");
                dt.Columns.Remove("NAME_ENTH");
                dt.Columns.Remove("text_search");
                dt.Columns.Remove("Name_E_sort");
                dt.Columns.Remove("Name_L_sort");
                dt.Columns.Remove("Sort_Group");
                dt.Columns.Remove("table");

                //dt.Columns["Catcode"].ColumnName = "CatCode";
                //dt.Columns["dist"].ColumnName = "Dist";
                //dt.Columns["score"].ColumnName = "Score";
                //dt.Columns["subcode"].ColumnName = "LocalCatCode";

                dt.Columns.Remove("HouseNo");
                dt.Columns.Remove("LatLon");
                dt.Columns.Remove("LatLon_Route1");
                dt.Columns.Remove("LatLon_Route2");
                dt.Columns.Remove("LatLon_Route3");
                dt.Columns.Remove("LatLon_Route4");


                dt.TableName = "result";
                dt.AcceptChanges();


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

                DataTable connect = new DataTable();
                connect.Columns.Add("result");
                connect.Rows.Add("NotFound");
                connect.TableName = "NotFound";
                return(null);
            }
        }
        public DataTable AutoComplete(string keyword, string numreturn, 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);
            }



            //string select = "";
            string message = "";

            string[] lang = Detect_Language(keyword);
            if (string.IsNullOrEmpty(lang[0]))
            {
                message += "3;";//eng
            }
            else
            {
                message += "2;";//thai
            }


            try
            {
                Stopwatch sw = new Stopwatch();
                sw.Start();
                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();

                message += keyword.Trim() + ";";
                message += numreturn.ToString();

                bool   stat    = gt_socket.SendData(message + " \n", false);
                string recieve = gt_socket.recieve(10000 * 60);
                int    kk      = recieve.Length;

                gt_socket.Disconnect();

                string[] line = recieve.Split('|');

                DataTable dt = new DataTable();
                dt.Columns.Add("name", typeof(string));

                for (int i = 0; i < line.Length; i++)
                {
                    if (line[i].ToUpper().Trim() == "NULL")
                    {
                        break;
                    }
                    dt.Rows.Add(line[i]);
                }

                //return recieve;

                long ij = sw.ElapsedMilliseconds;
                dt.TableName = "res" + ij.ToString() + "ms";
                return(dt);
            }
            catch (Exception)
            {
                DataTable connect = new DataTable();
                connect.Columns.Add("result");
                connect.Rows.Add("NotFound");
                connect.TableName = "NotFound";
                return(connect);
            }
        }