public static string LookingForShipper(double x, double y, string noidung, string tieude, int donhangId, int khachhangId)
        {
            List <int>    arr    = db.NguoiDiChoOnline.Where(m => m.Online == true && m.Refuse != donhangId && m.Id != khachhangId).Select(m => m.Id).ToList();
            List <double> list   = new List <double>();
            double        d      = 0;
            double        result = 0;

            double[,] arr2 = new double[arr.Count(), 2];
            double min    = Double.MaxValue;
            double arrmin = 0;

            for (int i = 0; i < arr.Count(); i++)
            {
                d = arr[i];
                var nguoidicho = db.NguoiDiChoOnline.Single(a => a.Id == d);
                result     = CalculateDistance.DistanceFrom(x, y, nguoidicho.X, nguoidicho.Y);
                arr2[i, 0] = arr[i];
                arr2[i, 1] = result;
            }
            for (int i = 0; i < arr.Count(); i++)
            {
                if (arr2[i, 1] < min)
                {
                    min    = arr2[i, 1];
                    arrmin = arr2[i, 0];
                }
            }
            var nguoidichothichhop = db.NguoiDiCho.SingleOrDefault(u => u.Id == arrmin);

            SendNotification.SendNotifications(noidung, tieude, nguoidichothichhop.Id);
            string result1 = "Người đi chợ thích hợp là: " + nguoidichothichhop.Ten;

            return(result1);
        }
示例#2
0
        public static List <int> LookingForSupplier(double x, double y)
        {
            List <int> arr    = db.NhaCungUng.Where(n => n.Id != 0).Select(s => s.Id).ToList();
            List <int> list   = new List <int>();
            double     d      = 0;
            double     result = 0;

            double[,] arr2 = new double[arr.Count(), 2];
            for (int i = 0; i < arr.Count(); i++)
            {
                d = arr[i];
                var ncu = db.NhaCungUng.Single(a => a.Id == d);
                result     = CalculateDistance.DistanceFrom(x, y, ncu.X, ncu.Y);
                arr2[i, 0] = arr[i];
                arr2[i, 1] = result;
                if (result < 200000)
                {
                    list.Add(arr[i]);
                }
                //list.Add(arr[i]);
            }
            return(list);
        }