示例#1
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (tbUsername.Text == "")
            {
                MessageBox.Show("请输入用户名!");
                return;
            }
            if (tbPassword.Text == "")
            {
                MessageBox.Show("请输入密码!");
                return;
            }
            Database       db     = new Database();
            DatabaseStatus status = db.Login(tbUsername.Text, tbPassword.Text);

            if (status == DatabaseStatus.WrongPassword)
            {
                MessageBox.Show("密码错误!");
            }
            if (status == DatabaseStatus.Success)
            {
                ContactList formContact = new Contacts.ContactList(db);
                formContact.Show();
                this.Hide();
            }
            if (status == DatabaseStatus.UserNotExists)
            {
                MessageBox.Show("用户不存在");
            }
        }
示例#2
0
        public void CalculateRoute(Contacts.ContactList contacts)
        {
            Distance = 0;
            contacts = FilterEmptyNames(contacts);
            MapURL   = CreateURL(contacts);

            if (contacts.Count == 0)
            {
                return;
            }

            NamesVisited.Clear();
            foreach (Contacts.Contact con in contacts)
            {
                NamesVisited.Add(con.Name);
            }

            DirectionsRequest req = new DirectionsRequest();

            req.Origin      = contacts[0].Address;
            req.Destination = contacts[contacts.Count - 1].Address;

            if (contacts.Count > 2)
            {
                List <string> waypoints = new List <string>();
                for (int i = 1; i < contacts.Count - 1; i++)
                {
                    waypoints.Add(contacts[i].Address);
                }
                req.Waypoints = waypoints.ToArray();
            }
            double          dist      = 0;
            List <Location> locations = new List <Location>();

            DirectionsResponse resp = GoogleMapsApi.MapsAPI.GetDirections(req);



            foreach (Route r in resp.Routes)
            {
                foreach (Leg l in r.Legs)
                {
                    locations.Add(l.StartLocation);
                    locations.Add(l.EndLocation);
                    dist += l.Distance.Value;
                }
            }
            Distance = dist / 1000;
        }
示例#3
0
 public string CreateURL(Contacts.ContactList contacts)
 {
     contacts = FilterEmptyNames(contacts);
     MapURL   = "http://maps.google.com/";
     if (contacts.Count == 0)
     {
         return(MapURL);
     }
     MapURL += "?saddr=" + contacts[0].Address;
     MapURL += "&daddr=";
     if (contacts.Count > 2)
     {
         for (int i = 1; i < contacts.Count - 1; i++)
         {
             MapURL += contacts[i].Address + "+to:";
         }
     }
     MapURL += contacts[contacts.Count - 1].Address;
     MapURL  = MapURL.Replace("\n", ",");
     return(MapURL);
 }
示例#4
0
 private Contacts.ContactList FilterEmptyNames(Contacts.ContactList contacts)
 {
     Contacts.ContactList ret = new Contacts.ContactList(contacts);
     ret.RemoveAll(p => string.IsNullOrWhiteSpace(p.Name));
     return ret;
 }
示例#5
0
 private Contacts.ContactList FilterEmptyNames(Contacts.ContactList contacts)
 {
     Contacts.ContactList ret = new Contacts.ContactList(contacts);
     ret.RemoveAll(p => string.IsNullOrWhiteSpace(p.Name));
     return(ret);
 }