📄 loginform.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
using System.IO;
using System.Text;
using System.Net;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary ;
namespace Eboer.MIS.MF.WinForm
{
/// <summary>
/// LoginForm 的摘要说明。
/// </summary>
public class LoginForm : System.Windows.Forms.Form
{
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label4;
private System.ComponentModel.IContainer components;
private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.TextBox password;
private System.Windows.Forms.TextBox username;
//
private DeskConfig dc = null;
//
private string connStr = "";
public LoginForm()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
this.connStr = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + Application.StartupPath + "\\" + "DB2005.DLL";
Eboer.MIS.MF.WinForm.Public.connStr = this.connStr;
Public.NewConn();
this.LoadConfig();
//载入粮仪厂图标
try{
Image img = Image.FromFile(Application.StartupPath + "\\" + "lylogo.gif");
Public.lyLogo = img;
}catch{
//
}
//更新
this.timer1.Start();
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
/// <summary>
/// 由此开始运行程序
/// </summary>
[STAThread]
static void Main() {
Application.Run(new LoginForm());
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(LoginForm));
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.button2 = new System.Windows.Forms.Button();
this.button1 = new System.Windows.Forms.Button();
this.password = new System.Windows.Forms.TextBox();
this.username = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.SuspendLayout();
//
// pictureBox1
//
this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
this.pictureBox1.Location = new System.Drawing.Point(0, 0);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(574, 239);
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
//
// button2
//
this.button2.BackColor = System.Drawing.Color.LightSteelBlue;
this.button2.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.button2.Location = new System.Drawing.Point(392, 184);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(80, 23);
this.button2.TabIndex = 15;
this.button2.Text = "关 闭";
this.button2.Click += new System.EventHandler(this.button2_Click_1);
//
// button1
//
this.button1.BackColor = System.Drawing.Color.LightSteelBlue;
this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.button1.Location = new System.Drawing.Point(312, 184);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(72, 23);
this.button1.TabIndex = 3;
this.button1.Text = "登 录";
this.button1.Click += new System.EventHandler(this.button1_Click_1);
//
// password
//
this.password.Location = new System.Drawing.Point(312, 152);
this.password.Name = "password";
this.password.PasswordChar = '*';
this.password.Size = new System.Drawing.Size(160, 21);
this.password.TabIndex = 2;
this.password.Text = "";
//
// username
//
this.username.Location = new System.Drawing.Point(312, 128);
this.username.Name = "username";
this.username.Size = new System.Drawing.Size(160, 21);
this.username.TabIndex = 1;
this.username.Text = "001";
//
// label2
//
this.label2.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(224)), ((System.Byte)(224)), ((System.Byte)(224)));
this.label2.Location = new System.Drawing.Point(248, 160);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(64, 16);
this.label2.TabIndex = 9;
this.label2.Text = "登录密码";
//
// label1
//
this.label1.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(224)), ((System.Byte)(224)), ((System.Byte)(224)));
this.label1.Location = new System.Drawing.Point(248, 136);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(56, 16);
this.label1.TabIndex = 8;
this.label1.Text = "职员工号";
//
// label4
//
this.label4.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(224)), ((System.Byte)(224)), ((System.Byte)(224)));
this.label4.Location = new System.Drawing.Point(136, 96);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(280, 16);
this.label4.TabIndex = 16;
this.label4.Text = "正在检查是否有升级文件,请稍候....";
//
// timer1
//
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// LoginForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(574, 239);
this.Controls.Add(this.label4);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.password);
this.Controls.Add(this.username);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.pictureBox1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.KeyPreview = true;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "LoginForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "用户登录";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 关闭系统
/// </summary>
public void ExitApp(){
if(MessageBox.Show("确定关闭系统吗?","关闭确认",MessageBoxButtons.OKCancel,MessageBoxIcon.Question) == DialogResult.OK){
Application.Exit();
}
}
private void button1_Click_1(object sender, System.EventArgs e) {
if(this.username.Text.Trim() != "" && this.password.Text.Trim() != ""){
try{
string sql = "select * from SInfo where username='"+ this.username.Text +"' and pwd='"+ this.password.Text +"'";
OleDbDataAdapter adp = new OleDbDataAdapter(sql,Public.conn);
DataSet ds = new DataSet();
adp.Fill(ds,"user");
if(ds.Tables[0].Rows.Count == 1){
Public.userID = ds.Tables[0].Rows[0]["username"].ToString();
Public.cuUser = ds.Tables[0].Rows[0]["username"].ToString();
Public.passCH = ds.Tables[0].Rows[0]["pwd"].ToString();
}else{
MessageBox.Show("登录用户名或密码有误!");
return;
}
}catch(Exception ex){
MessageBox.Show(ex.Message.ToString());
return;
}
}else{
MessageBox.Show("请输入用户名和密码!");
return;
}
MainForm main = new MainForm(this);
main.Show();
this.Visible = false;
}
private void button2_Click_1(object sender, System.EventArgs e) {
this.ExitApp();
}
/// <summary>
/// 是否新版本
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CheckUpdate(){
String temp = "";
//寻找服务器地址
/*
try{
WebRequest Wrequest = WebRequest.Create("http://www.ESST.cn/SoftUpdate/NPMS/ServerColl.asp");
WebResponse Wresponse = Wrequest.GetResponse();
Stream Sm = Wresponse.GetResponseStream();
StreamReader Sr = new StreamReader(Sm,Encoding.GetEncoding("GB2312"));
temp = Sr.ReadToEnd().ToString();
Sr.Close();
if(temp != null && temp != "" && temp.IndexOf("ESST_NPMS_SERVER") > 0){
temp = temp.Replace("[ESST_NPMS_SERVER]","");
string[] temp_ = temp.Split(',');
string connStr_ = this.connStr.Replace("tzrbs-npms.vicp.net",temp_[0].ToString());
this.dba = DBAction.Instance(Config.connStr);
Config.connStr = connStr_;
this.connStr = Config.connStr;
}
}catch(Exception ex){
//MessageBox.Show("寻找替换服务器地址时出错:" + ex.Message.ToString());
}
try{
this.dba = DBAction.Instance(Config.connStr);
this.LoadCompany();
}catch{
MessageBox.Show("不能连接数据库服务器,请确认:\n1)数据库服务器是否打开;\n2)当前计算机是否连入Internet网。");
Application.Exit();
}
*/
try{
WebRequest Wrequest = WebRequest.Create("http://www.ESST.cn/SoftUpdate/TZLYIMS/softUpdate.htm");
WebResponse Wresponse = Wrequest.GetResponse();
Stream Sm = Wresponse.GetResponseStream();
StreamReader Sr = new StreamReader(Sm,Encoding.GetEncoding("GB2312"));
temp = Sr.ReadToEnd().ToString();
Sr.Close();
}catch{
this.label4.Visible = false;
this.label4.Text = "检查升级完毕!";
return;
}
int oneI = temp.IndexOf("]");
string softVer = temp.Substring(1,oneI-1).ToString();
try{
if(this.dc.softVer.IndexOf(softVer) != 0 && MessageBox.Show("系统检查到有升级文件可供更新,确定升级吗?","升级确认",MessageBoxButtons.OKCancel,MessageBoxIcon.Question) == DialogResult.OK){
dc.softVer = softVer;
string defaultDirectory = Application.StartupPath;
string fileName = defaultDirectory + "\\default.co";
Stream s = File.Open(fileName,FileMode.Create);
BinaryFormatter b =new BinaryFormatter();
b.Serialize(s,this.dc);
s.Close();
//打开升级窗口下载最新文件
System.Diagnostics.Process p = new Process();
p.StartInfo.FileName = Application.StartupPath + "\\UpdateEr.exe";
p.Start();
Application.Exit();
}else{
this.label4.Visible = false;
}
}catch(Exception ex){
MessageBox.Show("开始升级时出错:" + ex.Message.ToString());
}
}
//载入配置文件
private void LoadConfig(){
try{
string defaultDirectory = Application.StartupPath;
string fileName = defaultDirectory + "\\default.co";
if(File.Exists(fileName)){ //如果存在,打开文件
Stream s = File.Open(fileName,FileMode.Open);
BinaryFormatter b = new BinaryFormatter();
this.dc =(DeskConfig)b.Deserialize(s);
s.Close();
}else{
DeskConfig dc = new DeskConfig();
dc.softVer = "1.00";
defaultDirectory = Application.StartupPath;
fileName = defaultDirectory + "\\default.co";
Stream s = File.Open(fileName,FileMode.Create);
BinaryFormatter b =new BinaryFormatter();
b.Serialize(s,dc);
s.Close();
}
}catch{
MessageBox.Show("系统配置文件错误,不能从硬盘读取请联系系统管理员!");
}
}
/// <summary>
/// 检查更新
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void timer1_Tick(object sender, System.EventArgs e) {
this.timer1.Stop();
this.CheckUpdate();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -