WPF养老保险系统日志_登入界面
WPF养老保险系统登入界面前言思路XAML部分代码C#部分代码前言因 为数据库在做MVC版的养老保险系统时就已经做好了,所以这里直接用以前的,就不再重新做数据库了言归正传,因为MVC版的养老系统配色风格过于古老,所以这里我大胆的使用紫色为主的冷色调主题首先是登入界面的前端实现好的样式思路使用的Grid布局,将这个窗体一分为二然后再在Grid布局分割的两个区域内分别嵌套了一个border容器这个容器
·
前言
因 为数据库在做MVC版的养老保险系统时就已经做好了,所以这里直接用以前的,就不再重新做数据库了
言归正传,
因为MVC版的养老系统配色风格过于古老,所以这里我大胆的使用紫色为主的冷色调主题
首先是登入界面的前端实现好的样式
思路
使用的Grid布局,将这个窗体一分为二
然后再在Grid布局分割的两个区域内分别嵌套了一个border容器
这个容器主要的作用是为了实现窗体的圆角
因为退出登入的按钮位置已经放置了两个单选框
所以我就把左边整个紫色部分做成了退出登入按钮
注意: 要想让窗体没有窗体自带的哪些边框之类的
记得设置
WindowStyle=“None”
WindowStartupLocation=“CenterScreen”
Background=“Transparent”
AllowsTransparency=“True”
下面是XAML视图代码,
因为后台代码已经写了完整的注释了,所以这里就不在累述了
XAML部分代码
<Window x:Class="Wpf_TheOldAgeSystem.Login"
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"
xmlns:local="clr-namespace:Wpf_TheOldAgeSystem"
mc:Ignorable="d"
WindowStyle="None"
WindowStartupLocation="CenterScreen"
Background="Transparent"
AllowsTransparency="True"
Title="Login" Height="650" Width="1100" KeyDown="Window_KeyDown" ContentRendered="Window_ContentRendered"
>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"></ColumnDefinition>
<ColumnDefinition Width="1*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Border BorderThickness="5" Background="#FF8374E9" BorderBrush="#FF8374E9" CornerRadius="9,0,0,9" >
<Border BorderBrush="#FF8374E9" BorderThickness="20,200,320,280" x:Name="border_ZiSe">
<StackPanel HorizontalAlignment="Left" VerticalAlignment="Center" >
<TextBlock Text="欢迎登录" FontSize="48" Foreground="White"></TextBlock>
<TextBlock Text="养老保健系统" FontSize="20" Foreground="White"></TextBlock>
</StackPanel>
</Border>
</Border>
<Border Grid.Column="1" Background="White" BorderThickness="5" BorderBrush="White" CornerRadius="0,9,9,0">
<Border Background="White" BorderBrush="White" BorderThickness="40,40,120,40">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="13*"></RowDefinition>
<RowDefinition Height="5*"></RowDefinition>
<RowDefinition Height="1*"></RowDefinition>
<RowDefinition Height="5*"></RowDefinition>
<RowDefinition Height="1*"></RowDefinition>
<RowDefinition Height="5*"></RowDefinition>
<RowDefinition Height="1*"></RowDefinition>
<RowDefinition Height="8*"></RowDefinition>
<RowDefinition Height="12*"></RowDefinition>
</Grid.RowDefinitions>
<TextBox x:Name="textBox_JobNumber" FontSize="25" Grid.Row="1" Text="孙悟空" Foreground="#FFABADB3" BorderThickness="0,0,0,2" BorderBrush="#FF8374E9"/>
<PasswordBox x:Name="passwordBox_Password" FontSize="25" Grid.Row="3" Password="SunWuKong" Foreground="#FFABADB3" BorderThickness="0,0,0,2" BorderBrush="#FF8374E9"/>
<Border Grid.Row="5">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"></ColumnDefinition>
<ColumnDefinition Width="3*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Text="登入地点:" FontSize="19" Foreground="#FF7A6395"></TextBlock>
<ComboBox x:Name="comboBox_AreaID" Grid.Column="1" Margin="0,9">
</ComboBox>
</Grid>
</Border>
<Grid Grid.Row="7">
<Grid.RowDefinitions>
<RowDefinition Height="1*"></RowDefinition>
<RowDefinition Height="2*"></RowDefinition>
<RowDefinition Height="1*"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="76*"></ColumnDefinition>
<ColumnDefinition Width="279*"></ColumnDefinition>
<ColumnDefinition Width="25*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Border Grid.Row="1" Background="#FF8374E9" CornerRadius="5" BorderBrush="#FF8374E9" BorderThickness="3">
<Button x:Name="button_DengRu" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="White" FontSize="23" FontFamily="华文楷体" Content="登录">
</Button>
</Border>
<TextBlock Grid.Row="2" Text="没有账号?" Foreground="#FF938686"></TextBlock>
<Grid Grid.Column="1" Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition Height="1*"></RowDefinition>
<RowDefinition Height="1*"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="114*"></ColumnDefinition>
<ColumnDefinition Width="80*"></ColumnDefinition>
<ColumnDefinition Width="80*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<CheckBox x:Name="checkBox_JiZhuMM" Grid.Row="1" Grid.Column="1" FontSize="14" FontFamily="华文楷体">记住密码</CheckBox>
<CheckBox x:Name="checkBox_ZiDongDR" Grid.Row="1" Grid.Column="2" FontSize="14" FontFamily="华文楷体">自动登录</CheckBox>
</Grid>
</Grid>
</Grid>
</Border>
</Border>
</Grid>
</Window>
C#部分代码
C#代码如下,
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Wpf_TheOldAgeSystem.MyPublicLibrary;
namespace Wpf_TheOldAgeSystem
{
/// <summary>
/// Login.xaml 的交互逻辑
/// </summary>
public partial class Login : Window
{
private readonly Models.LYBJXTEntities myModels = new Models.LYBJXTEntities();
public Login()
{
InitializeComponent();
JiaZai();
//左边紫色页面鼠标左键键摁下事件
border_ZiSe.MouseLeftButtonDown += MyPublicLibrary.UtilityRelated.UtilityOff;
//登入按钮点击事件
button_DengRu.Click += Button_DengRu_Click;
Hello();
}
private void Hello()
{
}
private void Button_DengRu_Click(object sender, RoutedEventArgs e)
{
var loginTime = DateTime.Now;
var jobNumberId = textBox_JobNumber.Text.Trim();
var yuanGongMm = passwordBox_Password.Password.Trim();
//FangJianZhuangTaiData();
//byte intUserType = Convert.ToByte(comboBoxZhuangTaiChaXun.SelectedIndex);//输出索引
//string intUserTypes =Convert.ToString( comboBoxZhuangTaiChaXun.SelectedItem);//输出一个object.里面包含绑定的list
/// dynamic dyName = ((dynamic)comboBoxZhuangTaiChaXun.SelectedItem).ZhuangTaiMingcCheng;//取出object里面包含的一个属性
//string intUserTypess = Convert.ToString(comboBoxZhuangTaiChaXun.SelectedValue);//SelectedValuePath
//string intUserTypesss = Convert.ToString(comboBoxZhuangTaiChaXun.SelectedValuePath);//输出绑定的字段
//string intUserTypessss = Convert.ToString(comboBoxZhuangTaiChaXun.DisplayMemberPath);//输出绑定的字段
此时的 myComboxBox.SelectedValue = System.Windows.Controls.ComboBoxItem: 选项的内容
所以如果用SelectedValue这种方法获取选中的值,还需要切割字符串
//判断账户不为空
if (jobNumberId != string.Empty)
//判断用户输入密码不为空
if (yuanGongMm != string.Empty)
//判断用户是否选中区
if (comboBox_AreaID.SelectedItem != null)
{
//当用户区域选择不为空时获取用户选中的区域
int comboBoxAreaId = ((dynamic)comboBox_AreaID.SelectedItem).id;
try
{
//查询员工号是否输入正确,当员工号输入正确时,返回该员工数据,
var tbUser = (from dbUser in myModels.S_User
where dbUser.JobNum == jobNumberId
select new
{
dbUser.UserID,
dbUser.Password,
dbUser.UserMC,
dbUser.AreaID
}).Single();
//判断用户密码是否输入正确
if (tbUser.Password.Equals(yuanGongMm))
if (tbUser.AreaID == (comboBoxAreaId))
{
//判断用户类型:获取用户名和用户类型连表查询用户类型表的数据
var tbPosition = (from dbUser in myModels.S_User
join dbPosition in myModels.D_Position
on dbUser.PositionID equals dbPosition.PositionID
//根据账号和用户类型筛选数据
where dbUser.JobNum == jobNumberId
select new
{
dbPosition.PositionID,
dbPosition.Position
}).ToList();
//接着判断查询的表格是否有数据,有就代表用户类型是准确的
if (tbPosition.Count == 0) return;
//获取用户类型的名称
var userTypeName = tbPosition[0].Position.Trim();
//获取用户类型ID
int userTypeId = tbPosition[0].PositionID;
//用户是否选中记住账户密码
if (checkBox_JiZhuMM.IsChecked != null && checkBox_JiZhuMM.IsChecked.Value)
{
Properties.Settings.Default.DaranDassIch = true;
Properties.Settings.Default.JobNumberId = jobNumberId;
Properties.Settings.Default.JobPassword = yuanGongMm;
Properties.Settings.Default.comboBox_AreaID = comboBox_AreaID.SelectedIndex;
if (checkBox_ZiDongDR.IsChecked != null)
Properties.Settings.Default.ZiDongDR =
checkBox_ZiDongDR.IsChecked.Value;
}
else
{
Properties.Settings.Default.DaranDassIch = false;
Properties.Settings.Default.JobNumberId = string.Empty;
Properties.Settings.Default.JobPassword = string.Empty;
Properties.Settings.Default.comboBox_AreaID = -1;
Properties.Settings.Default.ZiDongDR = false;
}
Properties.Settings.Default.Save();
Properties.Settings.Default.Upgrade();
var userInformation = new Hashtable
{
{"UserID", tbUser.UserID},
{"UserTypeID",userTypeId },
{"UserMC",tbUser.UserMC },
{"LoginTime",loginTime },
{"UserTypeClass",userTypeName }
};
new MainWindow(userInformation).Show();
this.Close();
}
else
MessageBox.Show("请选择正确的员工区域", "提示");
else
MessageBox.Show("密码输入错误", "提示");
}
catch (Exception)
{
MessageBox.Show("没有查询到员工账户,请输入正确的员工账户", "提示");
}
}
else
MessageBox.Show("请选择区域");
else
MessageBox.Show("请输入员工密码", "提示");
else
MessageBox.Show("请输入正确的员工号", "提示");
}
public void JiaZai()
{
var myArealist = myModels.D_Area.
Select(m => new { id = m.AreaID, name = m.Area }).ToList();
comboBox_AreaID.ItemsSource = myArealist;
comboBox_AreaID.DisplayMemberPath = "name";
comboBox_AreaID.SelectedValuePath= "id";
#region 将保存在Settings里面的数据回填至登入窗体
textBox_JobNumber.Text = Properties.Settings.Default.JobNumberId;
passwordBox_Password.Password = Properties.Settings.Default.JobPassword;
comboBox_AreaID.SelectedIndex = Properties.Settings.Default.comboBox_AreaID;
checkBox_JiZhuMM.IsChecked = Properties.Settings.Default.DaranDassIch;
checkBox_ZiDongDR.IsChecked = Properties.Settings.Default.ZiDongDR;
#endregion
}
private void Window_KeyDown(object sender, KeyEventArgs e)
{
//判断用户是否输入了Enter键
if (e.Key.ToString() == "Return")
{
Button_DengRu_Click(sender, e);
}
return;
}
private void Window_ContentRendered(object sender, EventArgs e)
{
if (checkBox_ZiDongDR.IsChecked != null && checkBox_ZiDongDR.IsChecked.Value)
{
// Thread.Sleep(3000);//睡眠500毫秒,也就是0.5秒
Button_DengRu_Click(null, null);
}
}
}
}
更多推荐
已为社区贡献3条内容
所有评论(0)