我正忙于在UWP中做一个简单的登录系统,该系统允许用户选择要登录的学校。下拉列表中列出了不同的学校。现在的问题是,它保存了启动时选择的值。该值将保存到变量中。
试图按索引查找值。
public List<User> GetUsers(string connectionString)
{
string campus_selected = ((ComboBoxItem)campuscb.SelectedItem).Content.ToString();
if (campus_selected=="NewYork")
{
const string GetUserQuery = "SELECT username,password,TeacherID from NewYork.UserLogin";
var users = new ObservableCollection<User>();
try
{
using (SqlConnection conn = new SqlConnection(connectionString))
{
conn.Open();
if (conn.State == System.Data.ConnectionState.Open)
{
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = GetUserQuery;
using (SqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
var user = new User();
user.username = reader.GetString(0);
user.password = reader.GetString(1);
users.Add(user);
}
}
}
}
}
return users.ToList();
}
catch (Exception eSql)
{
Debug.WriteLine("Exception: " + eSql.Message);
}
return null;
}
else if (campus_selected == "LA")
{
const string GetUserQuery = "SELECT username,password,TeacherID from LA.UserLogin";
var users = new ObservableCollection<User>();
try
{
using (SqlConnection conn = new SqlConnection(connectionString))
{
conn.Open();
if (conn.State == System.Data.ConnectionState.Open)
{
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = GetUserQuery;
using (SqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
var user = new User();
user.username = reader.GetString(0);
user.password = reader.GetString(1);
//user.FacilitatorsID = reader.GetString(2);
users.Add(user);
}
}
}
}
}
return users.ToList();
}
catch (Exception eSql)
{
Debug.WriteLine("Exception: " + eSql.Message);
}
return null;
}
return null;
}
当用户更改下拉列表时,应转到相应的if语句。因此,如果他选择LA,它将在LA if语句下执行代码。
答案 0 :(得分:1)
您需要在XAML代码中添加func resultOfShuffle(firstCard : Int, secondCard : Int) -> UIImageView {
if firstCard > 33 {
return theResult.image = UIImage(named: cardResults)
}
}
事件处理程序。这是示例代码-
XAML
SelectionChanged
C#
<ComboBox x:Name="myCombo"
Header="Fonts"
Height="44"
Width="296"
SelectionChanged="myCombo_SelectionChanged"
DisplayMemberPath="Source">
<ComboBoxItem Name="NY">
<TextBlock Text="New York"/>
</ComboBoxItem>
<ComboBoxItem Name="CA">
<TextBlock Text="California"/>
</ComboBoxItem>
<ComboBoxItem Name="DC">
<TextBlock Text="Washington DC"/>
</ComboBoxItem>
</ComboBox>
<TextBlock Name="result"/>
希望我能够提供帮助。 :)