/// <summary> /// Handles the <see cref="UIElement.MouseDown"/> event for the hosted <see /// cref="MapView"/>.</summary> /// <param name="sender"> /// The <see cref="Object"/> where the event handler is attached.</param> /// <param name="args"> /// A <see cref="MouseButtonEventArgs"/> object containing event data.</param> /// <remarks><para> /// <b>OnMapMouseDown</b> changes the selected <see cref="Site"/> on left button clicks and /// selects the corresponding item in the "Site" list view if it exists. /// </para><para> /// Left clicks outside the map area deselect the currently selected <see cref="Site"/> and /// the selected item in the "Site" list view instead.</para></remarks> private void OnMapMouseDown(object sender, MouseButtonEventArgs args) { args.Handled = true; // left mouse button moves selection if (args.ChangedButton == MouseButton.Left) { // select site clicked on, if any PointI site = this._mapView.MouseToSite(args); this._mapView.SelectedSite = site; // clear list view selection SiteList.SelectedIndex = -1; if (site == Site.InvalidLocation) { return; } // select corresponding item in Site list view for (int i = 0; i < SiteList.Items.Count; i++) { SiteListItem item = (SiteListItem)SiteList.Items[i]; if (item.Item3 == site) { SiteList.SelectedIndex = i; SiteList.ScrollIntoView(item); break; } } } }
/// <summary> /// Handles the <see cref="ButtonBase.Click"/> event for the "Remove Entry" <see /// cref="Button"/>.</summary> /// <param name="sender"> /// The <see cref="Object"/> where the event handler is attached.</param> /// <param name="args"> /// A <see cref="RoutedEventArgs"/> object containing event data.</param> /// <remarks> /// <b>OnSiteRemove</b> calls <see cref="RemoveSite"/> with the first selected item in the /// "Site" list view, if any.</remarks> private void OnSiteRemove(object sender, RoutedEventArgs args) { args.Handled = true; // retrieve selected site, if any int index = SiteList.SelectedIndex; if (index < 0) { return; } SiteListItem item = (SiteListItem)SiteList.Items[index]; RemoveSite(item); }
/// <summary> /// Handles the <see cref="Selector.SelectionChanged"/> event for the "Site" <see /// cref="ListView"/>.</summary> /// <param name="sender"> /// The <see cref="Object"/> where the event handler is attached.</param> /// <param name="args"> /// A <see cref="SelectionChangedEventArgs"/> object containing event data.</param> /// <remarks> /// <b>OnSiteSelected</b> calls <see cref="SelectSite"/> with the map location associated /// with the first selected item in the "Site" list view, if any.</remarks> private void OnSiteSelected(object sender, SelectionChangedEventArgs args) { args.Handled = true; // retrieve selected site, if any int index = SiteList.SelectedIndex; if (index < 0) { return; } SiteListItem item = (SiteListItem)SiteList.Items[index]; // update map view and Site group box SelectSite(item.Item3, true); // enable Remove Site button RemoveSiteButton.IsEnabled = true; }
/// <summary> /// Removes the specified item from the "Site" <see cref="ListView"/>.</summary> /// <param name="item"> /// The <see cref="SiteListItem"/> to remove.</param> /// <remarks> /// <b>RemoveSite</b> also removes the map location stored with the specified <paramref /// name="item"/> from the <see cref="MapView.SelectedRegion"/> of the hosted <see /// cref="MapView"/>, and sets the <see cref="AreasChanged"/> flag unless the dialog is /// still initializing.</remarks> private void RemoveSite(SiteListItem item) { // remove site from list view SiteList.Items.Remove(item); PointI site = item.Item3; SelectSite(site, false); // remove site from selected region if (Finder.MapGrid.Contains(site)) { this._mapView.SelectedRegion[site.X, site.Y] = false; this._mapView.Redraw(); } // broadcast data changes, if any if (this._initialized) { AreasChanged = true; } }
/// <summary> /// Handles the <see cref="UIElement.MouseDown"/> event for the hosted <see /// cref="MapView"/>.</summary> /// <param name="sender"> /// The <see cref="Object"/> where the event handler is attached.</param> /// <param name="args"> /// A <see cref="MouseButtonEventArgs"/> object containing event data.</param> /// <remarks><para> /// <b>OnMapMouseDown</b> changes the selected <see cref="Site"/> on left button clicks and /// selects the corresponding item in the "Site" list view if it exists. /// </para><para> /// If the user double-clicked, <b>OnMapMouseDown</b> removes the corresponding item from /// the "Site" list view if one is found, and adds a new item otherwise. /// </para><para> /// Single or double left clicks outside the map area deselect the currently selected <see /// cref="Site"/> instead.</para></remarks> private void OnMapMouseDown(object sender, MouseButtonEventArgs args) { args.Handled = true; // left mouse button moves selection if (args.ChangedButton != MouseButton.Left) { return; } // determine site clicked on, if any PointI site = this._mapView.MouseToSite(args); // select corresponding item in Faction list view SiteListItem selected = FindSite(site); // add or remove site on double click if (selected == null) { if (args.ClickCount >= 2) { AddSite(site, true); } else { SelectSite(site, false); } } else { if (args.ClickCount >= 2) { RemoveSite(selected); } else { SiteList.SelectAndShow(selected); } } }
/// <summary> /// Adds an item for the specified map location to the "Site" <see cref="ListView"/>. /// </summary> /// <param name="location"> /// The coordinates of the <see cref="Site"/> to store in the new <see /// cref="SiteListItem"/>.</param> /// <param name="select"> /// <c>true</c> if the new <see cref="SiteListItem"/> should be selected; otherwise, /// <c>false</c>.</param> /// <returns> /// The <see cref="SiteListItem"/> that was added to the "Site" <see cref="ListView"/>. /// </returns> /// <remarks> /// <b>AddSite</b> also adds the specified <paramref name="location"/> to the <see /// cref="MapView.SelectedRegion"/> of the hosted <see cref="MapView"/>, and sets the <see /// cref="AreasChanged"/> flag unless the dialog is still initializing.</remarks> private SiteListItem AddSite(PointI location, bool select) { // get site at specified coordinates Site site = this._mapView.WorldState.GetSite(location); // get owner of this site, if any string owner = Global.Strings.LabelOwnerNone; if (site != null && site.Owner != null) { owner = site.Owner.Id; } // add new site to list view var item = new SiteListItem(owner, Site.Format(location), location); int index = SiteList.Items.Add(item); if (select) { SiteList.SelectAndShow(index); } // add site to selected region if (Finder.MapGrid.Contains(location)) { this._mapView.SelectedRegion[location.X, location.Y] = true; this._mapView.Redraw(); } // broadcast data changes, if any if (this._initialized) { AreasChanged = true; } return(item); }
/// <summary> /// Handles the <see cref="Selector.SelectionChanged"/> event for the "Site" <see /// cref="ListView"/>.</summary> /// <param name="sender"> /// The <see cref="Object"/> where the event handler is attached.</param> /// <param name="args"> /// A <see cref="SelectionChangedEventArgs"/> object containing event data.</param> /// <remarks> /// <b>OnSiteSelected</b> sets the <see cref="MapView.SelectedSite"/> of the hosted <see /// cref="MapView"/> to the selected item in the "Site" list view, if any.</remarks> private void OnSiteSelected(object sender, SelectionChangedEventArgs args) { args.Handled = true; // retrieve selected site, if any int index = SiteList.SelectedIndex; if (index < 0) { return; } SiteListItem item = (SiteListItem)SiteList.Items[index]; // select site in map view if (this._initialSiteShown) { this._mapView.SelectedSite = item.Item3; } else { this._initialSiteShown = true; this._mapView.CenterAndSelect(item.Item3); } }
public IHttpActionResult List(string accessToken, int channel, int platform, string ver) { Logger.WriterLogger("Site.List, Params: " + string.Format("accessToken={0}&channel={1}&platform={2}&ver={3}", accessToken, channel, platform, ver), LoggerType.Info); // 保存访问信息 base.SaveVisitInfo("", channel, platform, ver); // 验证令牌 int accessTookenCode = VerifyAccessToken(accessToken); if (accessTookenCode > 0) { return(base.JsonFaultResult(new CommonException(accessTookenCode).GetMessage(), "Site.List")); } DataTable dt = SitesManagementHelper.GetSites(); int defaultSiteId = 0; string defaultSiteName = ""; List <SiteListItem> items = new List <SiteListItem>(); if (dt != null) { SiteListItem item = null; foreach (DataRow current in dt.Rows) { //SitesId,SitesName,City,IsDefault,Province,Sort item = new SiteListItem(); item.SiteId = 0; if (current["SitesId"] != DBNull.Value) { item.SiteId = (int)current["SitesId"]; } item.SiteName = ""; if (current["SitesName"] != DBNull.Value) { item.SiteName = (string)current["SitesName"]; } item.RegionId = 0; if (current["City"] != DBNull.Value) { item.RegionId = (int)current["City"]; } else { if (current["Province"] != DBNull.Value) { item.RegionId = (int)current["Province"]; } } item.IsDefault = false; if (current["IsDefault"] != DBNull.Value) { item.IsDefault = ((int)current["IsDefault"]).Equals(1); } if (item.IsDefault) { defaultSiteId = item.SiteId; defaultSiteName = item.SiteName; } item.DisplaySequence = 0; if (current["Sort"] != DBNull.Value) { item.DisplaySequence = (int)current["Sort"]; } items.Add(item); } } SiteListResult siteResult = new SiteListResult(); siteResult.TotalNumOfRecords = items.Count; siteResult.DefaultSiteId = defaultSiteId; siteResult.DefaultSiteName = defaultSiteName; siteResult.Results = items; StandardResult <SiteListResult> result = new StandardResult <SiteListResult>() { code = 0, msg = "", data = siteResult }; return(base.JsonActionResult(result)); }