private void frmShowMap_Load(object sender, EventArgs e) { #region Проверка режима работы if (sMode != "T" && sMode != "P") { Close(); return; } #endregion #region Получение установок "Координаты центра карты" и "Координаты базы" Logistics.Properties.Settings set = new Logistics.Properties.Settings(); #region Установка центра карты try { nMapCenterLatitude = Convert.ToDouble(set.MapCenterLatitude); nMapCenterLongitude = Convert.ToDouble(set.MapCenterLongitude); wfpRadMapControl.SetMapCenter(nMapCenterLatitude, nMapCenterLongitude); } catch (Exception ex) { RFMMessage.MessageBoxError("Координаты центра карты указаны неверно!\r\n" + ex.Message); return; } #endregion #region Установка координат базы try { nBaseLat = Convert.ToDouble(set.MapBaseLatitude); nBaseLng = Convert.ToDouble(set.MapBaseLongitude); wfpRadMapControl.SetBaseLocation(nBaseLat, nBaseLng); } catch (Exception ex) { RFMMessage.MessageBoxError("Координаты базы указаны неверно!\r\n" + ex.Message); return; } #endregion #endregion #region ежим "Маршрут" if (sMode == "T") { if (!ShowTrip()) { Close(); return; } } #endregion #region ежим "Партнер" if (sMode == "P") { if (!ShowPartner()) { Close(); return; } } #endregion }
/// <summary> /// Расчет длины маршрута /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnCalcRoute_Click(object sender, EventArgs e) { // Установка координат базы Logistics.Properties.Settings set = new Logistics.Properties.Settings(); double nBaseLat, nBaseLng; try { nBaseLat = Convert.ToDouble(set.MapBaseLatitude); nBaseLng = Convert.ToDouble(set.MapBaseLongitude); } catch (Exception ex) { RFMMessage.MessageBoxError("Координаты базы указаны неверно!\r\n" + ex.Message); return; } RFMCursorWait.Set(true); // Входящие параметры Location locOrigin, locDestination; locOrigin = locDestination = new Location(); locOrigin.Latitude = locDestination.Latitude = nBaseLat; locOrigin.Longitude = locDestination.Longitude = nBaseLng; List <int> listPartners = new List <int>(); List <Location> listWayPoints = new List <Location>(); foreach (DataRow r in tableEfficiency.Rows) { // Пропуск статусной строки string sPartnerID = r["PartnerID"].ToString(); if (sPartnerID.Length == 0) { continue; } int nPartnerID = Convert.ToInt32(sPartnerID); string sLat = r["Latitude"].ToString(), sLng = r["Longitude"].ToString(); if (listPartners.IndexOf(nPartnerID) < 0 && sLat.Length > 0 && sLng.Length > 0) { listPartners.Add(nPartnerID); Location loc = new Location(); loc.Latitude = Convert.ToDouble(sLat); loc.Longitude = Convert.ToDouble(sLng); listWayPoints.Add(loc); } } // Исходящие параметры int nDistance = 0, nDuration = 0; string sDistance = "", sDuration = "", sErrorText = ""; List <Location> polyline = new List <Location>(); // Расчет маршрута bool bResult = GoogleService.CalcRoute(locOrigin, locDestination, listWayPoints, out nDistance, out sDistance, out nDuration, out sDuration, out polyline, out sErrorText); RFMCursorWait.Set(false); if (!bResult) { RFMMessage.MessageBoxError(sErrorText); return; } numDistance.Value = (decimal)nDistance / 1000; numTripCost.Value = numDistance.Value * numNormDistance.Value; }