📄 loginapp.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.IO;
using System.Text;
using System.Xml;
using System.Data;
using System.Net;
using Microsoft.Win32;
using System.Diagnostics;
namespace XFMAS
{
/// <summary>
/// LoginApp 的摘要说明。
/// </summary>
public class LoginApp : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox pwd;
private System.Windows.Forms.Button b222;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.CheckBox autoLogin;
private System.Windows.Forms.Button button2;
private System.Timers.Timer timer1;
private System.Windows.Forms.TextBox IP;
private System.Windows.Forms.ComboBox user;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.NotifyIcon notifyIcon1;
private System.Windows.Forms.ContextMenu contextMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.ComponentModel.IContainer components;
//是否关机或注销
private bool isExitApp = false;
/// <summary>
/// 主窗口
/// </summary>
private Form1 mainForm = null;
private System.Timers.Timer timer2;
/// <summary>
/// 托盘图标文件
/// </summary>
private string iconFile = Application.StartupPath + "\\";
private bool isLoadConfig = false;
public LoginApp()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//系统中只能存在一个进程
//this.CheckProcess();
//配置文件路径
Public.configFile = Application.StartupPath + "\\" + Public.configFile;
//读取本地配置文件
this.timer1.Start();
this.timer2.Start();
//IP地址
//得到主机信息
IPHostEntry ipInfo = Dns.GetHostByName(Dns.GetHostName());
//取得IPAddress[]
IPAddress[] ipAddr = ipInfo.AddressList;
this.IP.Text = ipAddr[0].ToString();
//Public.loginWin = this;
//this.Visible = false;
//Loading load = new Loading();
//load.Show();
//this.CheckProcess();
}
/// <summary>
/// 检查进程是否重复,重复则关闭当前进程
/// </summary>
private void CheckProcess(){
bool flag=false;
System.Threading.Mutex mutex=new System.Threading.Mutex(true,"XFMAS",out flag);
if ( !flag ) {
Application.Exit();
return;
}
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing ){
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
/// <summary>
/// 获取系统关机或注销事件
/// </summary>
/// <param name="m"></param>
protected override void WndProc(ref System.Windows.Forms.Message m) {
switch (m.Msg) {
case 0x0011://系统询问是否可以关闭
this.isExitApp = true;
break;
case 0x0016://系统指示:关掉
this.notifyIcon1.Visible = false;
this.notifyIcon1.Dispose();
Application.Exit();
break;
default:
break;
}
base.WndProc(ref m);
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(LoginApp));
this.button1 = new System.Windows.Forms.Button();
this.autoLogin = new System.Windows.Forms.CheckBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.IP = new System.Windows.Forms.TextBox();
this.pwd = new System.Windows.Forms.TextBox();
this.b222 = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.label3 = new System.Windows.Forms.Label();
this.user = new System.Windows.Forms.ComboBox();
this.button2 = new System.Windows.Forms.Button();
this.timer1 = new System.Timers.Timer();
this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
this.contextMenu1 = new System.Windows.Forms.ContextMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.timer2 = new System.Timers.Timer();
this.groupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.timer1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.timer2)).BeginInit();
this.SuspendLayout();
//
// button1
//
this.button1.Enabled = false;
this.button1.Location = new System.Drawing.Point(8, 112);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(160, 23);
this.button1.TabIndex = 6;
this.button1.Text = "注册本机IP地址到服务器";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// autoLogin
//
this.autoLogin.Checked = true;
this.autoLogin.CheckState = System.Windows.Forms.CheckState.Checked;
this.autoLogin.Enabled = false;
this.autoLogin.Location = new System.Drawing.Point(8, 144);
this.autoLogin.Name = "autoLogin";
this.autoLogin.Size = new System.Drawing.Size(112, 24);
this.autoLogin.TabIndex = 5;
this.autoLogin.Text = "下次自动登录";
//
// label1
//
this.label1.Location = new System.Drawing.Point(16, 48);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(80, 16);
this.label1.TabIndex = 2;
this.label1.Text = "内网用户名";
//
// label2
//
this.label2.Location = new System.Drawing.Point(16, 72);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(80, 16);
this.label2.TabIndex = 3;
this.label2.Text = "内网登录密码";
//
// IP
//
this.IP.Location = new System.Drawing.Point(104, 16);
this.IP.Name = "IP";
this.IP.Size = new System.Drawing.Size(152, 21);
this.IP.TabIndex = 1;
this.IP.Text = "";
this.IP.Leave += new System.EventHandler(this.IP_Leave);
//
// pwd
//
this.pwd.Enabled = false;
this.pwd.Location = new System.Drawing.Point(104, 64);
this.pwd.Name = "pwd";
this.pwd.PasswordChar = '*';
this.pwd.Size = new System.Drawing.Size(152, 21);
this.pwd.TabIndex = 3;
this.pwd.Text = "";
//
// b222
//
this.b222.Enabled = false;
this.b222.Location = new System.Drawing.Point(168, 112);
this.b222.Name = "b222";
this.b222.Size = new System.Drawing.Size(112, 23);
this.b222.TabIndex = 4;
this.b222.Text = "登录使用提醒服务";
this.b222.Click += new System.EventHandler(this.b222_Click);
//
// groupBox1
//
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.user);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Controls.Add(this.pwd);
this.groupBox1.Controls.Add(this.IP);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Location = new System.Drawing.Point(8, 0);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(272, 100);
this.groupBox1.TabIndex = 7;
this.groupBox1.TabStop = false;
//
// label3
//
this.label3.Location = new System.Drawing.Point(16, 24);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(80, 16);
this.label3.TabIndex = 7;
this.label3.Text = "IP";
//
// user
//
this.user.Enabled = false;
this.user.Location = new System.Drawing.Point(104, 40);
this.user.Name = "user";
this.user.Size = new System.Drawing.Size(152, 20);
this.user.TabIndex = 2;
//
// button2
//
this.button2.Enabled = false;
this.button2.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.button2.Location = new System.Drawing.Point(168, 144);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(112, 23);
this.button2.TabIndex = 7;
this.button2.Text = "服务器设置";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// timer1
//
this.timer1.Enabled = true;
this.timer1.Interval = 1000;
this.timer1.SynchronizingObject = this;
this.timer1.Elapsed += new System.Timers.ElapsedEventHandler(this.timer1_Elapsed);
//
// notifyIcon1
//
this.notifyIcon1.ContextMenu = this.contextMenu1;
this.notifyIcon1.Icon = ((System.Drawing.Icon)(resources.GetObject("notifyIcon1.Icon")));
this.notifyIcon1.Text = "登录";
this.notifyIcon1.Visible = true;
this.notifyIcon1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.notifyIcon1_MouseDown);
//
// contextMenu1
//
this.contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.Text = "关于(&A)";
this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);
//
// timer2
//
this.timer2.Interval = 500;
this.timer2.SynchronizingObject = this;
this.timer2.Elapsed += new System.Timers.ElapsedEventHandler(this.timer2_Elapsed);
//
// LoginApp
//
this.AcceptButton = this.b222;
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(290, 175);
this.Controls.Add(this.button2);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.b222);
this.Controls.Add(this.autoLogin);
this.Controls.Add(this.button1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.KeyPreview = true;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "LoginApp";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "登录";
this.Closing += new System.ComponentModel.CancelEventHandler(this.LoginApp_Closing);
this.groupBox1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.timer1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.timer2)).EndInit();
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 设置参数
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void linkLabel1_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e) {
SetWin sw = new SetWin();
sw.ShowDialog();
}
/// <summary>
/// 使用本机IP地址登录
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, System.EventArgs e) {
RegisterIP rip = new RegisterIP();
rip.ShowDialog();
this.LoadUserName();
}
/// <summary>
/// 使用用户名登录
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void b222_Click(object sender, System.EventArgs e) {
if(this.user.Text.Trim() == ""){
MessageBox.Show("用户名不能为空!");
return;
}
bool loginResult = DBConn.UserIsRight(this.user.Text.Trim(),Public.AddSec(this.pwd.Text));
if(loginResult){
//取值
Public.currentUserID = this.user.Text.Trim();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -