📄 registerip.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.IO;
using System.Text;
using System.Net;
using System.Data;
namespace XFMAS
{
/// <summary>
/// RegisterIP 的摘要说明。
/// </summary>
public class RegisterIP : System.Windows.Forms.Form
{
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox user;
private System.Windows.Forms.TextBox pwd;
private System.Windows.Forms.ComboBox ip;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public RegisterIP()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//得到主机信息
IPHostEntry ipInfo = Dns.GetHostByName(Dns.GetHostName());
//取得IPAddress[]
IPAddress[] ipAddr = ipInfo.AddressList;
if(ipAddr.Length > 0) this.ip.Text = ipAddr[0].ToString();
//得到ip
for(int i=0;i<ipAddr.Length;i++){
IPAddress ip = ipAddr[i];
this.ip.Items.Add(ip.ToString());
}
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.ip = new System.Windows.Forms.ComboBox();
this.pwd = new System.Windows.Forms.TextBox();
this.user = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.ip);
this.groupBox1.Controls.Add(this.pwd);
this.groupBox1.Controls.Add(this.user);
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Location = new System.Drawing.Point(8, 0);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(304, 112);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
//
// ip
//
this.ip.Location = new System.Drawing.Point(104, 24);
this.ip.Name = "ip";
this.ip.Size = new System.Drawing.Size(184, 20);
this.ip.TabIndex = 6;
//
// pwd
//
this.pwd.Location = new System.Drawing.Point(104, 72);
this.pwd.Name = "pwd";
this.pwd.PasswordChar = '*';
this.pwd.Size = new System.Drawing.Size(184, 21);
this.pwd.TabIndex = 5;
this.pwd.Text = "";
//
// user
//
this.user.Location = new System.Drawing.Point(104, 48);
this.user.Name = "user";
this.user.Size = new System.Drawing.Size(184, 21);
this.user.TabIndex = 4;
this.user.Text = "";
//
// label3
//
this.label3.Location = new System.Drawing.Point(16, 80);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(88, 16);
this.label3.TabIndex = 2;
this.label3.Text = "内网登录密码";
//
// label2
//
this.label2.Location = new System.Drawing.Point(16, 56);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(88, 16);
this.label2.TabIndex = 1;
this.label2.Text = "内网用户名";
//
// label1
//
this.label1.Location = new System.Drawing.Point(16, 32);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(88, 16);
this.label1.TabIndex = 0;
this.label1.Text = "IP 地址";
//
// button1
//
this.button1.Location = new System.Drawing.Point(168, 120);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(80, 23);
this.button1.TabIndex = 1;
this.button1.Text = "提交注册";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(248, 120);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(64, 23);
this.button2.TabIndex = 2;
this.button2.Text = "取 消";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// RegisterIP
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(320, 159);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.groupBox1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Name = "RegisterIP";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "注册IP地址到服务器";
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 保存注册的IP
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, System.EventArgs e) {
//检查IP是否符合要求
string ipStr = this.ip.Text.Trim();
string[] xx = ipStr.Split('.');
for(int i=0;i<xx.Length;i++){
string xxx = xx[i].ToString();
try{
if(xxx.Length > 3) throw new Exception("IP输入不符合要求");
int __xx = Int32.Parse(xxx);
}catch{
MessageBox.Show("IP地址输入不正确!");
return;
}
}
//检查用户名和密码是否正确
bool isUser = DBConn.UserIsRight(this.user.Text.Trim(),Public.AddSec(this.pwd.Text));
if(!isUser){
MessageBox.Show("内网登录用户名或密码不正确!");
return;
}
//一切就绪则保存入MAX系统的系统库中
string saveResult = DBConn.SaveUserIP(this.user.Text.Trim(),this.ip.Text.Trim());
if(saveResult == "OK"){
MessageBox.Show("注册成功!");
this.Close();
}else{
MessageBox.Show("注册失败:" + saveResult +"!");
}
}
private void button2_Click(object sender, System.EventArgs e) {
this.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -