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