|
马上注册,即可查看完整内容,享用更多功能,让你轻松玩转潜山论坛。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using System.Collections;
using System.Xml;
using System.Management;
namespace DomainSysData
{
public partial class MainFrm : Form
{
Boolean exitApp;
public string IpAddress;
string GetCpuID()
{
try
{
//获取CPU序列号代码
string cpuInfo = "";//cpu序列号
ManagementClass mc = new ManagementClass("Win32_Processor");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
cpuInfo = mo.Properties["ProcessorId"].Value.ToString();
}
moc = null;
mc = null;
return cpuInfo;
}
catch
{
return "unknow";
}
finally
{
}
}
/// <summary>
/// 计算机名称
/// </summary>
/// <returns></returns>
string GetComputerName()
{
try
{
return System.Environment.GetEnvironmentVariable("ComputerName");
}
catch
{
return "unknow";
}
finally
{
}
}
string GetMacAddress()
{
try
{
//获取网卡Mac地址
string mac = "";
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
if ((bool)mo["IPEnabled"] == true)
{
mac = mo["MacAddress"].ToString();
break;
}
}
moc = null;
mc = null;
return mac;
}
catch
{
return "unknow";
}
finally
{
}
}
string GetIPAddress()
{
try
{
//获取IP地址
string st = "";
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
if ((bool)mo["IPEnabled"] == true)
{
//st=mo["IpAddress"].ToString();
System.Array ar;
ar = (System.Array)(mo.Properties["IpAddress"].Value);
st = ar.GetValue(0).ToString();
break;
}
}
moc = null;
mc = null;
return st;
}
catch
{
return "unknow";
}
finally
{
}
}
string GetDiskID()
{
try
{
//获取硬盘ID
String HDid = "";
ManagementClass mc = new ManagementClass("Win32_DiskDrive");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
HDid = (string)mo.Properties["Model"].Value;
}
moc = null;
mc = null;
return HDid;
}
catch
{
return "unknow";
}
finally
{
}
}
/// <summary>
/// 操作系统的登录用户名
/// </summary>
/// <returns></returns>
string GetUserName()
{
try
{
string st = "";
ManagementClass mc = new ManagementClass("Win32_ComputerSystem");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
st = mo["UserName"].ToString();
}
moc = null;
mc = null;
return st;
}
catch
{
return "unknow";
}
finally
{
}
}
/// <summary>
/// PC类型
/// </summary>
/// <returns></returns>
string GetSystemType()
{
try
{
string st = "";
ManagementClass mc = new ManagementClass("Win32_ComputerSystem");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
st = mo["SystemType"].ToString();
}
moc = null;
mc = null;
return st;
}
catch
{
return "unknow";
}
finally
{
}
}
/// <summary>
/// 物理内存
/// </summary>
/// <returns></returns>
string GetTotalPhysicalMemory()
{
try
{
string st = "";
ManagementClass mc = new ManagementClass("Win32_ComputerSystem");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
st = mo["TotalPhysicalMemory"].ToString();
}
moc = null;
mc = null;
return st;
}
catch
{
return "unknow";
}
finally
{
}
}
public MainFrm()
{
InitializeComponent();
txtCenterNo.Text = ConfigurationManager.AppSettings["centerName"].Trim();
txtDB.Text = ConfigurationManager.AppSettings["Database"].Trim();
label1.Text= ConfigurationManager.AppSettings["centerName"].Trim() + "信息管理系统";
txtIP.Text = ConfigurationManager.AppSettings["Server"].Trim();
txtUser.Text = ConfigurationManager.AppSettings["uid"].Trim();
txtUserPass.Text = ConfigurationManager.AppSettings["pwd"].Trim();
}
MingCJModel.BLL.Dom_user UserBll = new MingCJModel.BLL.Dom_user();
private void MainFrm_Load(object sender, EventArgs e)
{
this.Text = ConfigurationManager.AppSettings["centerName"].Trim() + "信息管理登录系统";
exitApp = true;
panel1.Visible = false;
}
private void btIP_Click(object sender, EventArgs e)
{
panel1.Visible = true;
Configuration configuration = null; //Configuration对象
AppSettingsSection appSection = null; //AppSection对象
configuration = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath);
appSection = configuration.AppSettings;
txtCenterNo.Text = ConfigurationManager.AppSettings["centerName"].Trim();
txtDB.Text = ConfigurationManager.AppSettings["Database"].Trim();
txtIP.Text = ConfigurationManager.AppSettings["Server"].Trim();
txtUser.Text = ConfigurationManager.AppSettings["uid"].Trim();
txtUserPass.Text = ConfigurationManager.AppSettings["pwd"].Trim();
}
private void btReturn_Click(object sender, EventArgs e)
{
panel1.Visible = false;
}
private void btCom_Click(object sender, EventArgs e)
{
DialogResult result;
result = MessageBox.Show("是否确定当前服务器连接设置?", "提示", MessageBoxButtons.YesNo);
if (result == DialogResult.Yes)
{
Configuration configuration = null; //Configuration对象
AppSettingsSection appSection = null; //AppSection对象
configuration = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath);
//取得AppSetting节
appSection = configuration.AppSettings;
//赋值并保存
appSection.Settings["ConnectionString"].Value = "Data Source=" + txtIP.Text.Trim() + ";Initial Catalog=" + txtDB.Text.Trim() + ";Persist Security Info=True;User ID=" + txtUser.Text.Trim() + ";Password='" + txtUserPass.Text.Trim() + "'";
appSection.Settings["Server"].Value = txtIP.Text;
appSection.Settings["Database"].Value = txtDB.Text;
appSection.Settings["uid"].Value = txtUser.Text;
appSection.Settings["pwd"].Value = txtUserPass.Text;
appSection.Settings["centerName"].Value = txtCenterNo.Text.Trim();
configuration.Save();
MessageBox.Show("用户配置保存成功!");
}
}
private void btOut_Click(object sender, EventArgs e)
{
DialogResult result;
result = MessageBox.Show("是否确认退出?", "信息提示", MessageBoxButtons.YesNo);
if (result == DialogResult.Yes)
{
Application.Exit();
}
}
private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox2.Text.Trim() == "")
{
MessageBox.Show("用户登录账号为空!");
return;
}
try
{
MingCJModel.Model.Dom_user sUser = new MingCJModel.Model.Dom_user ();
MingCJModel.Model.Dom_user su = new MingCJModel.Model.Dom_user();
sUser = UserBll.GetModel(textBox2.Text.Trim(), textBox1.Text.Trim());
if (sUser != null)
{
WorkClass.UserClass.username = sUser.username.Trim();
WorkClass.UserClass.realname = sUser.realname.Trim();
WorkClass.UserClass.id = sUser.id;
WorkClass.UserClass.lastip = sUser.lastip.Trim();
WorkClass.UserClass.lasttime = sUser.lasttime;
WorkClass.UserClass.lognum =int.Parse(sUser.lognum.ToString().Trim())+1;
WorkClass.UserClass.logtime = sUser.logtime;
WorkClass.UserClass.logip = sUser.logip.Trim();
su.username = sUser.username;
su.realname = sUser.realname;
su.password = sUser.password;
su.localtion = sUser.localtion;
su.lastip = GetIPAddress();
su.lognum = int.Parse(sUser.lognum.ToString().Trim()) + 1;
su.logip = GetIPAddress();
su.remark = "登录IP:" + GetIPAddress() + " " + "操作系统的登录用户名:" + GetUserName() + "获取网卡Mac地址:" + GetMacAddress() + " " + "物理内存:" + GetTotalPhysicalMemory() + " " + "获取硬盘:" + GetDiskID() + " " + "计算机名称:" + GetComputerName() + " " + "CPU序列号代码" + GetCpuID();
su.id = sUser.id;
su.lasttime =DateTime.Parse(DateTime.Now.ToString());
su.logtime =DateTime.Parse( DateTime.Now.ToString());
UserBll.Update(su);
exitApp = false;
this.Close();
}
else
{
MessageBox.Show("用户信息或配置信息不正确!");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void MainFrm_FormClosed(object sender, FormClosedEventArgs e)
{
if (exitApp)
{
Application.Exit();
}
}
}
}
|
|