ltwork 1 vuosi sitten
vanhempi
commit
af062f48fb

+ 14 - 0
BlankApp1/BizService/IUserService.cs

@@ -0,0 +1,14 @@
+using Model.Entities;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BizService
+{
+    public  interface IUserService : IBaseService<Users>
+    {
+        public bool FindDataByUserAndPass(String userName, String password);
+    }
+}

+ 27 - 0
BlankApp1/BizService/UserService.cs

@@ -0,0 +1,27 @@
+using Model;
+using Model.Entities;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BizService
+{
+    public class UserService : BaseService<Users>, IUserService
+    {
+        public bool FindDataByUserAndPass(string userName, string password)
+        {
+            var all = base.QueryList();
+            var user = base.QueryList().FirstOrDefault(x => ((x.UserName.Trim() == userName.Trim()) && (x.Password.Trim() == password.Trim())));
+            if (user != null)
+            {
+                return true;
+            }
+            else
+            {
+                return false;
+            }
+        }
+    }
+}

+ 13 - 2
BlankApp1/BlankApp1/App.xaml.cs

@@ -9,6 +9,7 @@ using DryIoc;
 using Microsoft.Extensions.DependencyInjection;
 using Microsoft.Extensions.Logging;
 using NLog.Extensions.Logging;
+using PLCTool.ViewModels;
 using PLCTool.ViewModels.BasicConfigViewModel;
 using PLCTool.ViewModels.BusinessManageViewModel;
 using PLCTool.ViewModels.MonitorManageViewModel;
@@ -20,7 +21,7 @@ using Prism.DryIoc;
 using Prism.Ioc;
 using Prism.Services.Dialogs;
 using SqlSugar;
-
+using System;
 using System.Configuration;
 using System.Data;
 using System.IO;
@@ -88,6 +89,7 @@ namespace BlankApp1
             containerRegistry.RegisterDialog<EditItemDetailView, EditItemDetailViewModel>();
             containerRegistry.RegisterDialog<ReadSchView, ReadSchViewModel>();
             containerRegistry.RegisterDialog<AddItemDetailView, AddItemDetailViewModel>();
+            containerRegistry.RegisterDialog<LoginView, LoginViewModel>();
         }
 
         private IMapper GetMapper(IContainerProvider container)
@@ -97,12 +99,21 @@ namespace BlankApp1
         }
         protected override void OnInitialized()
         {
-  
+            var dialog = Container.Resolve<IDialogService>();
+            dialog.ShowDialog("LoginView", callback =>
+            {
+                if (callback.Result != ButtonResult.OK)
+                {
+                    Environment.Exit(0);
+                    return;
+                }
                 //调试发现service为MainViewModel
                 var service = App.Current.MainWindow.DataContext as IConfigureService;
                 if (service != null)
                     service.Configure();
                 base.OnInitialized();
+            });
+         
           
         }
 

BIN
BlankApp1/BlankApp1/Assets/Images/login.png


+ 61 - 0
BlankApp1/BlankApp1/Common/Extension/PassWordExtensions.cs

@@ -0,0 +1,61 @@
+using Microsoft.Xaml.Behaviors;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+
+namespace PLCTool.Common.Extension
+{
+    public class PassWordExtensions
+    {
+        public static string GetPassWord(DependencyObject obj)
+        {
+            return (string)obj.GetValue(PassWordProperty);
+        }
+
+        public static void SetPassWord(DependencyObject obj, string value)
+        {
+            obj.SetValue(PassWordProperty, value);
+        }
+
+        public static readonly DependencyProperty PassWordProperty =
+            DependencyProperty.RegisterAttached("PassWord", typeof(string), typeof(PassWordExtensions), new FrameworkPropertyMetadata(string.Empty, OnPassWordPropertyChanged));
+
+        static void OnPassWordPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
+        {
+            var passWord = sender as PasswordBox;
+            string password = (string)e.NewValue;
+
+            if (passWord != null && passWord.Password != password)
+                passWord.Password = password;
+        }
+    }
+
+    public class PasswordBehavior : Behavior<PasswordBox>
+    {
+        protected override void OnAttached()
+        {
+            base.OnAttached();
+            AssociatedObject.PasswordChanged += AssociatedObject_PasswordChanged;
+        }
+
+        private void AssociatedObject_PasswordChanged(object sender, RoutedEventArgs e)
+        {
+            PasswordBox passwordBox = sender as PasswordBox;
+            string password = PassWordExtensions.GetPassWord(passwordBox);
+
+            if (passwordBox != null && passwordBox.Password != password)
+                PassWordExtensions.SetPassWord(passwordBox, passwordBox.Password); //
+        }
+
+        protected override void OnDetaching()
+        {
+            base.OnDetaching();
+            AssociatedObject.PasswordChanged -= AssociatedObject_PasswordChanged;
+        }
+    }
+}
+

+ 2 - 0
BlankApp1/BlankApp1/PLCTool.csproj

@@ -8,6 +8,7 @@
   </PropertyGroup>
   <ItemGroup>
     <None Remove="Assets\Fonts\iconfont.ttf" />
+    <None Remove="Assets\Images\login.png" />
     <None Remove="Assets\Images\Logo.png" />
     <None Remove="Assets\Images\NoPass.png" />
     <None Remove="Assets\Images\Pass.png" />
@@ -48,6 +49,7 @@
     <Resource Include="Assets\Fonts\iconfont.ttf">
       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     </Resource>
+    <Resource Include="Assets\Images\login.png" />
     <Resource Include="Assets\Images\Logo.png">
       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     </Resource>

+ 94 - 0
BlankApp1/BlankApp1/ViewModels/LoginViewModel.cs

@@ -0,0 +1,94 @@
+using BizService;
+using Prism.Commands;
+using Prism.Mvvm;
+using Prism.Services.Dialogs;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+
+namespace PLCTool.ViewModels
+{
+    public class LoginViewModel : BindableBase, IDialogAware
+    {
+        private readonly IUserService _iUserService;
+        public LoginViewModel(IUserService iUserService)
+        {
+            _iUserService = iUserService;
+            ExecuteCommand = new DelegateCommand<string>(Execute);
+        }
+        public string Title { set; get; } = "登录";
+
+        public event Action<IDialogResult> RequestClose;
+
+        public bool CanCloseDialog()
+        {
+            return true;
+        }
+
+        public void OnDialogClosed()
+        {
+
+        }
+
+        public void OnDialogOpened(IDialogParameters parameters)
+        {
+
+        }
+        private void Execute(string obj)
+        {
+            switch (obj)
+            {
+                case "Login": Login(); break;
+
+
+            }
+        }
+
+
+        /// <summary>
+        /// 登录
+        /// </summary>
+        async void Login()
+        {
+            if (string.IsNullOrWhiteSpace(UserName) ||
+                string.IsNullOrWhiteSpace(PassWord))
+            {
+                MessageBox.Show("请输入用户名和密码!", "确认", MessageBoxButton.OK, MessageBoxImage.Warning);
+                return;
+            }
+            //进度条设为可见
+
+            if (_iUserService.FindDataByUserAndPass(UserName, PassWord))
+            {
+                RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
+            }
+            else
+            {
+                MessageBox.Show("用户名或密码错误!", "提示", MessageBoxButton.OK, MessageBoxImage.Error);
+                return;
+
+            }
+
+        }
+        private string userName;
+
+        public string UserName
+        {
+            get { return userName; }
+            set { userName = value; RaisePropertyChanged(); }
+        }
+
+        private string password;
+
+        public string PassWord
+        {
+            get { return password; }
+            set { password = value; RaisePropertyChanged(); }
+        }
+
+        public DelegateCommand<string> ExecuteCommand { set; get; }
+    }
+}

+ 51 - 0
BlankApp1/BlankApp1/Views/LoginView.xaml

@@ -0,0 +1,51 @@
+<UserControl x:Class="PLCTool.Views.LoginView"
+             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
+             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+             xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
+             xmlns:pass="clr-namespace:PLCTool.Common.Extension"
+             xmlns:prism="http://prismlibrary.com/"
+             xmlns:local="clr-namespace:PLCTool.Views"
+             mc:Ignorable="d" 
+             Width="600" Height="350">
+<prism:Dialog.WindowStyle>
+        <Style TargetType="Window">
+            <Setter Property="Width" Value="600" />
+            <Setter Property="Height" Value="350" />
+            <Setter Property="SizeToContent" Value="WidthAndHeight" />
+            <Setter Property="ResizeMode" Value="NoResize" />
+            <Setter Property="prism:Dialog.WindowStartupLocation" Value="CenterScreen" />
+        </Style>
+</prism:Dialog.WindowStyle>
+<Grid Background="White">
+        <Grid.ColumnDefinitions>
+            <ColumnDefinition Width="1.5*" />
+            <ColumnDefinition />
+        </Grid.ColumnDefinitions>
+        <Image Margin="50" Source="../Assets/Images/login.png" />
+        <DockPanel Margin="15" VerticalAlignment="Center" Grid.Column="1" >
+            <TextBlock Margin="0,10" DockPanel.Dock="Top" FontSize="22" FontWeight="Bold" Text="欢迎使用" HorizontalAlignment="Center"/>
+            <StackPanel Orientation="Horizontal" DockPanel.Dock="Top">
+                <TextBlock Margin="0,10" Width="80"  TextAlignment="Right" FontSize="16" FontWeight="Bold" Text="用户名:" />
+                <TextBox Margin="0,10" Width="120" Height="25"  Text="{Binding UserName}" Cursor="IBeam" />
+            </StackPanel>
+            <StackPanel Orientation="Horizontal" DockPanel.Dock="Top">
+                <TextBlock Margin="0,10"  Width="80"  TextAlignment="Right"  FontSize="16" FontWeight="Bold" Text="密码:" />
+                <PasswordBox Margin="0,10" Width="120" Height="25" pass:PassWordExtensions.PassWord="{Binding PassWord, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
+        DockPanel.Dock="Top" Cursor="IBeam">
+                    <i:Interaction.Behaviors>
+                        <pass:PasswordBehavior/>
+                    </i:Interaction.Behaviors>
+                    <PasswordBox.InputBindings>
+
+                        <KeyBinding Key="Enter" Command="{Binding ExecuteCommand}"
+              CommandParameter="Login"/>
+                    </PasswordBox.InputBindings>
+                </PasswordBox>
+            </StackPanel>
+            <Button Command="{Binding ExecuteCommand}" CommandParameter="Login" Content="登录系统"  DockPanel.Dock="Top" Style="{StaticResource NormalButtonStyle}"  Cursor="Hand" />
+        </DockPanel>
+        <Border BorderBrush="AliceBlue" BorderThickness="0.5" Grid.Column="1"/>
+    </Grid>
+</UserControl>

+ 28 - 0
BlankApp1/BlankApp1/Views/LoginView.xaml.cs

@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+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.Navigation;
+using System.Windows.Shapes;
+
+namespace PLCTool.Views
+{
+    /// <summary>
+    /// LoginView.xaml 的交互逻辑
+    /// </summary>
+    public partial class LoginView : UserControl
+    {
+        public LoginView()
+        {
+            InitializeComponent();
+        }
+    }
+}

+ 41 - 0
BlankApp1/Model/Entities/RoleMenus.cs

@@ -0,0 +1,41 @@
+using System;
+using System.Linq;
+using System.Text;
+using SqlSugar;
+
+namespace Model.Entities
+{
+    ///<summary>
+    ///
+    ///</summary>
+    [SugarTable("rolemenus")]
+    public partial class RoleMenus
+    {
+           public RoleMenus(){
+
+
+           }
+           /// <summary>
+           /// Desc:
+           /// Default:
+           /// Nullable:False
+           /// </summary>           
+           [SugarColumn(IsPrimaryKey=true,IsIdentity=true)]
+           public int Id {get;set;}
+
+           /// <summary>
+           /// Desc:
+           /// Default:
+           /// Nullable:True
+           /// </summary>           
+           public int? RoleId {get;set;}
+
+           /// <summary>
+           /// Desc:
+           /// Default:
+           /// Nullable:True
+           /// </summary>           
+           public int? MenuId {get;set;}
+
+    }
+}

+ 41 - 0
BlankApp1/Model/Entities/Roles.cs

@@ -0,0 +1,41 @@
+using System;
+using System.Linq;
+using System.Text;
+using SqlSugar;
+
+namespace Model.Entities
+{
+    ///<summary>
+    ///
+    ///</summary>
+    [SugarTable("roles")]
+    public partial class Roles
+    {
+           public Roles(){
+
+
+           }
+           /// <summary>
+           /// Desc:
+           /// Default:
+           /// Nullable:False
+           /// </summary>           
+           [SugarColumn(IsPrimaryKey=true,IsIdentity=true)]
+           public int Id {get;set;}
+
+           /// <summary>
+           /// Desc:
+           /// Default:
+           /// Nullable:True
+           /// </summary>           
+           public string Name {get;set;}
+
+           /// <summary>
+           /// Desc:
+           /// Default:
+           /// Nullable:True
+           /// </summary>           
+           public string Description {get;set;}
+
+    }
+}

+ 41 - 0
BlankApp1/Model/Entities/UserRoles.cs

@@ -0,0 +1,41 @@
+using System;
+using System.Linq;
+using System.Text;
+using SqlSugar;
+
+namespace Model.Entities
+{
+    ///<summary>
+    ///
+    ///</summary>
+    [SugarTable("userroles")]
+    public partial class UserRoles
+    {
+           public UserRoles(){
+
+
+           }
+           /// <summary>
+           /// Desc:
+           /// Default:
+           /// Nullable:False
+           /// </summary>           
+           [SugarColumn(IsPrimaryKey=true,IsIdentity=true)]
+           public int Id {get;set;}
+
+           /// <summary>
+           /// Desc:
+           /// Default:
+           /// Nullable:True
+           /// </summary>           
+           public int? UserId {get;set;}
+
+           /// <summary>
+           /// Desc:
+           /// Default:
+           /// Nullable:True
+           /// </summary>           
+           public int? RoleId {get;set;}
+
+    }
+}

+ 48 - 0
BlankApp1/Model/Entities/Users.cs

@@ -0,0 +1,48 @@
+using System;
+using System.Linq;
+using System.Text;
+using SqlSugar;
+
+namespace Model.Entities
+{
+    ///<summary>
+    ///
+    ///</summary>
+    [SugarTable("users")]
+    public partial class Users
+    {
+           public Users(){
+
+
+           }
+           /// <summary>
+           /// Desc:
+           /// Default:
+           /// Nullable:False
+           /// </summary>           
+           [SugarColumn(IsPrimaryKey=true,IsIdentity=true)]
+           public int Id {get;set;}
+
+           /// <summary>
+           /// Desc:
+           /// Default:
+           /// Nullable:True
+           /// </summary>           
+           public string UserName {get;set;}
+
+           /// <summary>
+           /// Desc:
+           /// Default:
+           /// Nullable:True
+           /// </summary>           
+           public string Password {get;set;}
+
+           /// <summary>
+           /// Desc:
+           /// Default:
+           /// Nullable:True
+           /// </summary>           
+           public string Description {get;set;}
+
+    }
+}