首页 > 代码库 > 救命用的

救命用的

<Grid x:Name="LayoutRoot" Background="White">        <Grid.RowDefinitions>            <RowDefinition Height="*"></RowDefinition>            <RowDefinition Height="40"></RowDefinition>            <RowDefinition Height="40"></RowDefinition>            <RowDefinition Height="40"></RowDefinition>            <RowDefinition Height="*"></RowDefinition>        </Grid.RowDefinitions>        <Grid.ColumnDefinitions>            <ColumnDefinition Width="*"></ColumnDefinition>            <ColumnDefinition Width="100"></ColumnDefinition>            <ColumnDefinition Width="100"></ColumnDefinition>            <ColumnDefinition Width="*"></ColumnDefinition>        </Grid.ColumnDefinitions>        <TextBlock Text="用户名:" Grid.Row="1" Grid.Column="1" Margin="8" Height="30" Width="80" FontSize="20" HorizontalAlignment="Center" FontWeight="Bold" FontFamily="Arial"/>        <TextBlock Text="密   码:" Grid.Row="2" Grid.Column="1" Margin="8" Height="30" Width="80" FontSize="20" HorizontalAlignment="Center" FontWeight="Bold" FontFamily="Arial"/>        <TextBox Name="tb_username" Grid.Row="1" Grid.Column="2" Margin="6" Height="28" Width="85" FontSize="20" HorizontalAlignment="Center"  FontFamily="Arial"/>        <TextBox Name="password" Grid.Row="2" Grid.Column="2" Margin="6" Height="28" Width="85" FontSize="20" HorizontalAlignment="Center"  FontFamily="Arial"/>        <Button Content="登录" Name="Btn_Login" Grid.Row="3" Grid.Column="1" Margin="8" Height="28" Width="80" FontSize="15" HorizontalAlignment="Center"  FontFamily="Arial" Click="btn_Login_"/>        <Button Content="注册" Name="Btn_Regin" Grid.Row="3" Grid.Column="2" Margin="8" Height="28" Width="80" FontSize="15" HorizontalAlignment="Center"  FontFamily="Arial" />    </Grid>

  

 <!--定义上下两行-->        <Grid.RowDefinitions>            <RowDefinition Height="100"/>            <RowDefinition Height="*"/>        </Grid.RowDefinitions>        <Grid Grid.Row="0" Background="Beige"/>        <!--设置标题在第一行-->        <TextBlock Grid.Row="0" Text="再  现  丝  绸  之  路" HorizontalAlignment="Center" Margin="10" TextAlignment="Center" FontFamily="黑体"			FontWeight="Black" Foreground="Bisque" FontSize="37" FontStretch="ExtraCondensed"/>        <!--把第二行分为两列,添加按钮-->        <Grid Grid.Row="1" Margin="0,5,0,-5" Background="#FF2492D1">                        <Grid.ColumnDefinitions >                <ColumnDefinition Width="100"/>                <ColumnDefinition Width="*"/>            </Grid.ColumnDefinitions>                                                         <esri:Map Name="MyMap" Grid.Column="1" Background="White" WrapAround="True">                <esri:ArcGISDynamicMapServiceLayer Url="http://localhost/ArcGIS/rest/services/sczl/MapServer"/>            </esri:Map>            <!--添加按钮-->            <Button Content="书签" Name="Btn_SQ" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="75" RenderTransformOrigin="0,0" Click="Btn_SQ_Click_1"/>            <Button Content="渲染" Name="Btn_XR" HorizontalAlignment="Left" Margin="10,50,0,0" Grid.Row="1" VerticalAlignment="Top" Width="75" RenderTransformOrigin="0,0" Click="Btn_XR_Click_1"  />            <Button Content="查询" Name="Btn_CX" HorizontalAlignment="Left" Margin="10,93,0,0" VerticalAlignment="Top" Width="75" Click="Btn_CX_Click_1" />            <!--添加导航条-->            <esri:Navigation Map="{Binding ElementName=MyMap}" Grid.Column="1" HorizontalAlignment="Left" Margin="0,250,0,0" VerticalAlignment="Bottom" Height="120" Width="150"/>            <!--添加导鹰眼-->            <esri:OverviewMap HorizontalAlignment="Right" VerticalAlignment="Bottom" Map="{Binding ElementName=MyMap}" Grid.Column="1" Height="100" Width="100" Visibility="Visible" RenderTransformOrigin="0.65,0.8" >            <esri:OverviewMap.Layer>                    <esri:ArcGISDynamicMapServiceLayer ID="StreetLayer" Url="http://localhost/ArcGIS/rest/services/sczl/MapServer"/>            </esri:OverviewMap.Layer>            </esri:OverviewMap>                  </Grid>        <!--添加书签-->        <esri:Bookmark Name="书签" HorizontalAlignment="Left" Margin="100,0,0,0" Grid.Row="1" VerticalAlignment="Top" Visibility="Collapsed" Map="{Binding ElementName=MyMap}" />        <!--添加进度条-->        <esri:MapProgressBar Map="{Binding ElementName=MyMap}" HorizontalAlignment="Center" VerticalAlignment="Center" Height="30" Width="150" Visibility="Visible" Grid.Row="1"   />

  

IDBServicesusing System;using System.Collections.Generic;using System.Linq;using System.Runtime.Serialization;using System.ServiceModel;using System.Text;namespace MyWebSite.Web{    // 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码和配置文件中的接口名“IDBServices”。    [ServiceContract]    public interface IDBServices    {        [OperationContract]        void DoWork();        [OperationContract]        bool CheckUser(string sUser,string sPsd);    }}

  

DBservucessing System;using System.Collections.Generic;using System.Linq;using System.Runtime.Serialization;using System.ServiceModel;using System.Text;using System.Data;using System.Data.SqlClient;namespace MyWebSite.Web{    // 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码、svc 和配置文件中的类名“DBServices”。    // 注意: 为了启动 WCF 测试客户端以测试此服务,请在解决方案资源管理器中选择 DBServices.svc 或 DBServices.svc.cs,然后开始调试。    public class DBServices : IDBServices    {        private SqlConnection pSqlConn=null;        private string sSqlConnString = "Data Source=D410-JS;Initial Catalog=webgis;Integrated Security=True";        public void DoWork()        {        }        /// <summary>        /// 检查用户密码是否正确        /// </summary>        /// <param name="sUser"></param>        /// <param name="sPsd"></param>        /// <returns></returns>        public bool CheckUser(string sUser, string sPsd)         {            try            {                //连接数据库                if (CheckSQLConn())                {                    string sql = "select * from dbo.tb_UserInfo where UserName=‘{0}‘ and UserPsd=‘{1}‘";//表名  列名                      sql = String.Format(sql, sUser, sPsd);                    // 查询数据库里面的记录                    SqlDataAdapter pSQLDataAdapter = new SqlDataAdapter(sql, pSqlConn);                    DataSet pDataSet = new DataSet();                    pSQLDataAdapter.Fill(pDataSet);                    int ResultCount = pDataSet.Tables[0].Rows.Count;                    //判断该记录是否存在                    if (ResultCount > 0)                    {                        return true;                    }                    else                    {                        return false;                    }                }                return false;            }            catch             {                return false;            }                    }        /// <summary>        /// 连接数据库        /// </summary>        /// <returns></returns>        private bool CheckSQLConn()         {            try             {                //判断连接是否存在                if (pSqlConn == null)                {                    pSqlConn = new SqlConnection();                    pSqlConn.ConnectionString = sSqlConnString;                }                //判断连接有没有开启                if (pSqlConn.State != ConnectionState.Open)                {                    pSqlConn.Open();                }                return true;            }            catch             {                return false;            }                    }    }}

  

MainPageusing 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 MyWebSite.DBServerSR;namespace MyWebSite{    public partial class MainPage : UserControl    {        public MainPage()        {            InitializeComponent();        }        private void Login_Click_1(object sender, RoutedEventArgs e)        {            string sUserName = UserName.Text.Trim();            string sUserPsd = UserPsd.Text.Trim();                        DBServicesClient pDBServiceClient = new DBServicesClient();            //异步调用WCF服务            pDBServiceClient.CheckUserAsync(sUserName, sUserPsd);            pDBServiceClient.CheckUserCompleted += pDBServiceClient_CheckUserCompleted;        }        /// <summary>        /// checkUser回调事件        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        void pDBServiceClient_CheckUserCompleted(object sender, CheckUserCompletedEventArgs e)        {            try            {                if (e.Result)                {                    MessageBox.Show("用户存在");                }                else                {                    MessageBox.Show("用户名或密码不正确");                }            }            catch             {                MessageBox.Show("网络无法访问!");             }                    }        private void Cancel_Click_1(object sender, RoutedEventArgs e)        {            System.Windows.Browser.HtmlPage.Window.Invoke("close");        }    }}

  

救命用的