懒羊羊
2023-12-28 e46d3baaf3e8d7d85f4bafec3aad75e52b078408
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using YX.BLL;
 
namespace YX
{
    public partial class FrmLogin : Form
    {
        SystemUserInfo_Bll user_bll = new SystemUserInfo_Bll();
        public FrmLogin()
        {
            InitializeComponent();
        }
        public static string loginUserName { get; set; }
        public static string LoginUserID { get; set; }
        public static string LocalIP { get; set; }
        /// <summary>
        /// 启动时隐藏窗口
        /// </summary>
        public void delay()
        {
            this.Hide();
        }
        private void btn_login_Click(object sender, EventArgs e)
        {
            try
            {
                var user = user_bll.UserLogin(txt_User_Account.Text, txt_UserPwd.Text);
                if (user != null)
                {
                    this.BeginInvoke(new ThreadStart(delay));
                    loginUserName = user.User_Name;
                    LoginUserID = user.User_ID;
                    LocalIP = GetLocalIP();
                    FrmMain main = new FrmMain();
                    main.WindowState = FormWindowState.Maximized;
                    main.Show();
                    //MessageBox.Show("登录成功!", "系统提醒");
                    LogHelper.WriteLog(typeof(FrmLogin), loginUserName + "登录成功!");
                    System_Bll.WriteLogToDB(
                        new Entity.Base_Log
                        {
                            CreateUserID = FrmLogin.LoginUserID,
                            CreateUserName = FrmLogin.loginUserName,
                            LocalIP = FrmLogin.LocalIP,
                            LogMessage = "登录成功!",
                            Type = "系统消息",
                            ClassName = typeof(FrmLogin).ToString()
 
                        });
                }
            }
            catch (Exception ex)
            {
 
                MessageBox.Show (ex.Message);
            }
        }
        public static string GetLocalIP()
        {
            try
            {
                string HostName = Dns.GetHostName(); //得到主机名
                IPHostEntry IpEntry = Dns.GetHostEntry(HostName);
                for (int i = 0; i < IpEntry.AddressList.Length; i++)
                {
                    //从IP地址列表中筛选出IPv4类型的IP地址
                    //AddressFamily.InterNetwork表示此IP为IPv4,
                    //AddressFamily.InterNetworkV6表示此地址为IPv6类型
                    if (IpEntry.AddressList[i].AddressFamily == AddressFamily.InterNetwork)
                    {
                        return IpEntry.AddressList[i].ToString();
                    }
                }
                return "";
            }
            catch (Exception ex)
            {
                MessageBox.Show("获取本机IP出错:" + ex.Message);
                return "";
            }
        }
 
        private void btn_concel_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("是否确认退出程序?", "退出", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
            {
                LogHelper.WriteLog(typeof(FrmMain), "************软件关闭***********");
                this.Dispose();
                Environment.Exit(0);
            }
        }
    }
}