Share via


Popolamento di elenco di fusi orari

Se è necessario rendere disponibile un elenco di fusi orari nell'interfaccia di gestione delle sottoscrizioni in modo che i sottoscrittori possano selezionare fusi orari validi, utilizzare le classi TimeZone e TimeZoneEnumeration. Negli esempi seguenti viene illustrato come elencare i fusi orari per una lingua utilizzando codice gestito e Microsoft Visual Basic Scripting Edition (VBScript) per illustrare l'interoperatività COM.

Esempio di codice gestito

Nell'esempio di codice seguente viene illustrato come utilizzare un oggetto TimeZoneEnumeration nel codice gestito per elencare i nomi dei fusi orari per l'impostazione della lingua corrente per il computer client:

string instanceName = "Tutorial";

// Create the NSInstance object.
NSInstance testInstance = new NSInstance(instanceName);

// Create the TimeZoneEnumeration.
TimeZoneEnumeration testTimeZoneEnumeration =
    new TimeZoneEnumeration(testInstance,
    System.Globalization.CultureInfo.CurrentUICulture.Parent.Name);

// Step through the enumeration, populating
// the drop-down list as you go. Note that the TimeZone
// reference must include the namespace, because there is
// an identically named class in the System namespace.
foreach(Microsoft.SqlServer.NotificationServices.TimeZone
thisTimeZone in testTimeZoneEnumeration)
{
    Console.WriteLine(thisTimeZone.TimeZoneName);
}

Esempio di interoperatività COM

Nell'esempio di codice seguente viene illustrato come utilizzare un oggetto TimeZoneEnumeration nel codice non gestito per elencare gli identificatori dei fusi orari per i fusi orari con un identificatore tra 2 e 40 corrispondente alle impostazioni internazionali "en":

Dim testInstance, testTimeZoneEnumeration, timeZones
const instanceName = "Tutorial"

' Create the NSInstance object.
set testInstance = WScript.CreateObject( _ 
    "Microsoft.SqlServer.NotificationServices.NSInstance")
testInstance.Initialize instanceName

' Create the TimeZoneEnumeration object.
set testTimeZoneEnumeration = WScript.CreateObject( _ 
    "Microsoft.SqlServer.NotificationServices.timeZoneEnumeration")
testTimeZoneEnumeration.Initialize (testInstance), "en" 

' Print the valid time zone IDs between 2 and 40
for each thisTimeZone in testTimeZoneEnumeration
    if thisTimeZone.TimeZoneId >=2 _
        and thisTimeZone.TimeZoneId <=40 then
        timeZones = timeZones & thisTimeZone.TimeZoneId & ", "
    end if
next
WScript.echo timeZones

Vedere anche

Concetti

Creazione di un oggetto di sottoscrizione
Aggiunta di una sottoscrizione
Aggiornamento di una sottoscrizione
Eliminazione di una sottoscrizione
Recupero di informazioni sul campo sottoscrizione
Popolamento di un elenco delle impostazioni internazionali dei sottoscrittori

Altre risorse

Vista NS<SubscriptionClassName>

Guida in linea e informazioni

Assistenza su SQL Server 2005