0

我正在创建一个登录页面,并且已经将它与 Web 服务连接起来。

每当我想放置/插入“角色”时,我都会收到错误消息。在 Web 服务中,Web 服务具有学生、讲师、管理员和管理的角色,其中应用程序我只使用学生角色。

我的设计

<Image x:Name="imgLinton" HorizontalAlignment="Left" Height="141" Margin="27,24,0,0" VerticalAlignment="Top" Width="398" Source="/Assets/Kolej.png" Grid.ColumnSpan="2"/>

<TextBlock x:Name="loginlbl_UserName" HorizontalAlignment="Left" Margin="10,216,0,0" TextWrapping="Wrap" Text="User Name" VerticalAlignment="Top"/>

 <TextBox x:Name="logintxt_UserName" HorizontalAlignment="Left" Height="65" Margin="125,197,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="265" FontSize="20" RenderTransformOrigin="0.492,-0.623"/>

 <TextBlock x:Name="loginlbl_UserName1" HorizontalAlignment="Left" Height="27" Margin="10,281,0,0" TextWrapping="Wrap" Text="Password" VerticalAlignment="Top" Width="98"/>

  <Button x:Name="login_btnlogin" Content="Login" HorizontalAlignment="Left" Margin="125,399,0,0" VerticalAlignment="Top" Click="login_btnlogin_Click" Height="71" Width="221">

  </Button>
  <Button x:Name="login_btnback" Content="Back" HorizontalAlignment="Left" Height="71" Margin="125,475,0,0" VerticalAlignment="Top" Width="221">
  <i:Interaction.Triggers>
  <i:EventTrigger EventName="Click">
  <ec:NavigateToPageAction TargetPage="/MainPage.xaml"/>
  </i:EventTrigger>
  </i:Interaction.Triggers>
  </Button>

  <TextBlock x:Name="login_lblerror" HorizontalAlignment="Left" Height="35" Margin="27,327,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Width="398" Foreground="#FFFF0006" FontWeight="Bold"/>
  <PasswordBox x:Name="logintxt_Password" HorizontalAlignment="Left" Height="64" Margin="125,263,0,0" VerticalAlignment="Top" Width="265" RenderTransformOrigin="1.455,-0.432"/>

这是我的代码

    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Navigation;
    using Microsoft.Phone.Controls;
    using Microsoft.Phone.Shell;
    using System.Threading;

    namespace project2
     {
public partial class login : PhoneApplicationPage
{
    string userID = null;

    public login()
    {            
        InitializeComponent();            

    }

    private void login_btnlogin_Click(object sender, RoutedEventArgs e)
    {
        ServiceReference2.Service1SoapClient myClient = new ServiceReference2.Service1SoapClient();   
        myClient.loginwebCompleted += new EventHandler<ServiceReference2.loginwebCompletedEventArgs>(myClient_loginCompleted);
        myClient.loginwebAsync(logintxt_UserName.Text, logintxt_Password.Password);

        string loginstatus = null;
        string[] words = myClient.Split(".");
        string userrole = words(0);

        if (Information.IsNumeric(words(0)))
        {
            string userID = words(1);

            if (userrole == "1")
            {
                NavigationService.Cookies("logincookie").Value = userID;
                NavigationService.Navigate(new Uri("/myprofile.xaml?ID=" + userID, UriKind.Relative));
            }

            else if ((userrole == "2" | userrole == "3" | userrole == "0"))
            {
                login_lblerror.Text = "Please Login via Website (lecturer, management and Admin)";

            }
            else
            {
                login_lblerror.Text = loginstatus;
            }
        }

        else
        {
            login_lblerror.Text = loginstatus;
        }
    }
}
4

0 回答 0