Silverlight实现和上一篇相同的登陆页面

来源:互联网 发布:socket server 阿里云 编辑:程序博客网 时间:2024/05/22 10:51

mainpage.xaml

<UserControl x:Class="Login.MainPage"    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"    mc:Ignorable="d"    d:DesignHeight="800"  d:DesignWidth="1366" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" Background="Red">    <Canvas Background="White">        <Border Background="#d1d1d1" CornerRadius="30" BorderBrush="Silver" BorderThickness="1" Canvas.Left="382" Canvas.Top="289" Height="338" Name="border1" Width="661" />        <Rectangle Fill="#3b3b3b" Canvas.Left="400" Canvas.Top="388" Height="220" Name="rectangle1" Stroke="Black" StrokeThickness="1" Width="513"/>        <Rectangle Fill="#00eeee" Canvas.Left="913" Canvas.Top="308" Height="300" Name="rectangle2" Stroke="Black" StrokeThickness="1" Width="108" />        <Rectangle Fill="Black" Canvas.Left="400" Canvas.Top="308" Height="80" Name="rectangle3" Stroke="Black" StrokeThickness="1" Width="513" />                <TextBlock Foreground="White" FontSize="56" FontWeight="Bold" Canvas.Left="419" Canvas.Top="308" Height="67" Name="textBlock1" Text="LOGIN" Width="222" />                <TextBlock Foreground="White" FontSize="20" FontWeight="Bold" Canvas.Left="434" Canvas.Top="433" Height="30" Name="textBlock2" Text="username:" Width="129" />        <TextBlock Foreground="White" FontSize="20" FontWeight="Bold" Canvas.Left="434" Canvas.Top="532" Height="30" Name="textBlock3" Text="password:" Width="129" />        <TextBox Canvas.Left="600" Canvas.Top="421" Height="50" Name="textBox1" Width="230" />        <TextBox Canvas.Left="600" Canvas.Top="521" Height="50" Name="textBox2" Width="230" />                <Image Canvas.Left="922" Canvas.Top="345" Height="123" Name="image1" Source="images/jiantou.png" Stretch="Fill" Width="95" />        <Button Click="button1_Click" Background="Blue" Canvas.Left="922" Canvas.Top="517" Content="Button" Height="88" Name="button1" Width="93" />    </Canvas></UserControl>

mainpage.xaml.cs

using System;using System.Collections.Generic;using System.Linq;using System.Net;using System.Windows;using System.Windows.Controls;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Animation;using System.Windows.Shapes;using Login.ServiceReference1;using System.ServiceModel;namespace Login{    public partial class MainPage : UserControl    {        public MainPage()        {            InitializeComponent();        }        private void button1_Click(object sender, RoutedEventArgs e)        {            Get();        }        private void Get()        {            User user = new User();            user.UserName = textBox1.Text;            user.PassWord = textBox2.Text;            EndpointAddress address = new EndpointAddress(new Uri(Application.Current.Host.Source, "/Login.Web/Service1.svc"));            //Login.ServiceReference1.Service1Client            Service1Client client = new Service1Client(/*new BasicHttpBinding(), address*/);            client.GetCompleted += client_GetCompleted;            client.GetAsync(user);         }        private void client_GetCompleted(object sender, GetCompletedEventArgs e)        {            if (e.Result)            {                MessageBox.Show("success");            }            else            {                MessageBox.Show("false");            }        }    }}

server.svc

using System;using System.Linq;using System.Runtime.Serialization;using System.ServiceModel;using System.ServiceModel.Activation;using System.Data;using System.Data.SqlClient;using System.Web.Configuration;using System.Data.OleDb;namespace Login.Web{    [ServiceContract(Namespace = "")]    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]    public class Service1    {        [OperationContract]        public void DoWork()        {            // 在此处添加操作实现            return;        }        // 在此处添加更多操作并使用 [OperationContract] 标记它们        private string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;DATA SOURCE=D:/Projects/3层登陆注册/11111/App_Data/数据库1.accdb";        [OperationContract]        public bool Get(User user)        {            OleDbConnection conn = new OleDbConnection(connectionString);            string sql = "select * from userinfo where username='" + user.UserName + "' and password='" + user.PassWord + "'";            OleDbCommand cmd = new OleDbCommand(sql, conn);            try            {                conn.Open();                OleDbDataReader dr = cmd.ExecuteReader();                if (dr.Read())                {                    return true;                }                else                {                    return false;                }            }            catch            {                return false;            }            finally            {                conn.Close();            }        }    }}

User.cs

using System;using System.Collections.Generic;using System.Linq;using System.Web;namespace Login.Web{    public class User    {        private string userName;        private string passWord;        public string UserName        {            get { return userName; }            set { userName = value; }        }        public string PassWord        {            get { return passWord; }            set { passWord = value; }        }        public User()        {            this.userName = string.Empty;            this.passWord = string.Empty;        }    }}


0 0
原创粉丝点击