> For the complete documentation index, see [llms.txt](https://doc.plustools.de/map+plus/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://doc.plustools.de/map+plus/print+plus/standorte.md).

# Standorte

Das nachfolgende Skript ermittelt umliegende Standorte für die Ausgabe in PRINT+PLUS.

```csharp
namespace Ruthardt.PrintPlus.Skripting
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.SqlClient;
    using System.IO;
    using System.Linq;
    using System.Windows.Forms;
    using Ruthardt.CobraBase.Functions.Access.Ado;
    using Ruthardt.CobraFramework.Ado;
    using Ruthardt.PrintPlus.Export.Context;
    using Ruthardt.PrintPlus.Model.Interfaces;
    using Ruthardt.PrintPlus.Model.Configuration;

    public class ExampleScript : IScriptAction
    {
        public void Execute(IPrintContext printContext, ICurrentContext currentContext, IChildContext childContext)
        {
            var currentAdoView = currentContext.AdoView;

            var addressAdoView = currentContext.ParentAdoViewByPrefix["Adresse"];
            string sql = 
                "DECLARE @origin geography " + 
                "SELECT @origin = (SELECT Location FROM Ruthardt_Locations WHERE SUPERID = @AdressId) " + 
                "SELECT TOP(3) Ruthardt_Locations.SuperId, Location.STDistance(@origin) as DISTANCE "+
                "FROM Ruthardt_Locations " +
                "JOIN [#Adressen#] ON Ruthardt_Locations.SuperId = [#Adressen.ID#] "+
                "WHERE Ruthardt_Locations.Location IS NOT NULL " +
                "AND Ruthardt_Locations.TotalScore > 70 " +
                "AND [#Adressen.Kundenart#] = 'Intern' " +
                "AND [#Adressen.Haupt#] = 'H' " +
                "ORDER BY Ruthardt_Locations.Location.STDistance(@origin) ASC";

            var table = printContext.AdoAccess.GetTable(sql, new SqlParameter("@AdressId", addressAdoView.CurrentKey));
            var addressIdsWithDistance = table.Rows.Cast<DataRow>().ToDictionary(row => (int)row["SuperId"], row => (double)row["DISTANCE"]);

            var standortTable = printContext.AdoAccess.GetTable("SELECT * FROM [#Adressen#] WHERE ID IN (" + string.Join(",", addressIdsWithDistance.Keys) + ")");

            var configNode = printContext.Config.Current.Children.First(node => node.Prefix == "Standorte");
            var standorte = new List<IChildContext>();
            foreach(DataRow row in standortTable.Rows)
            {
                var adoView = new AdoView(row, "Adressen", printContext.AdoAccess);

                var distance = addressIdsWithDistance[(int)row["ID"]];
                string stringDistance;
                if (distance == 0)
                {
                    stringDistance = string.Empty;
                }
                else if (distance < 1000)
                {
                    stringDistance = Math.Round(distance / 1000, 1).ToString("n1") + " km";
                }
                else
                {
                    stringDistance = Math.Round(distance / 1000, 0).ToString("n0") + " km";
                }

                adoView.SetValue("Distanz_Standort", stringDistance);
                adoView.SetValue("Distanz_Standort_Zahl", distance);

                standorte.Add(new ChildContext(adoView, currentContext, configNode));
            }

            currentContext.ChildContextByPrefix["Standorte"] = standorte.OrderBy(standort => standort.AdoView.GetDecimalValue("Distanz_Standort_Zahl")).ToList();
        }
    }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://doc.plustools.de/map+plus/print+plus/standorte.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
