📄 frmlogo.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Diagnostics;
using System.Threading;
namespace WWAM.Forms
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class FrmLogo : System.Windows.Forms.Form
{
#region FrmLogo
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.PictureBox pictureBox1;
private System.ComponentModel.IContainer components = null;
public FrmLogo()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <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()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(FrmLogo));
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.SuspendLayout();
//
// label1
//
this.label1.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(240)), ((System.Byte)(237)), ((System.Byte)(237)));
this.label1.Location = new System.Drawing.Point(304, 112);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(40, 24);
this.label1.TabIndex = 0;
this.label1.Text = "...";
//
// label2
//
this.label2.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(240)), ((System.Byte)(237)), ((System.Byte)(237)));
this.label2.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label2.Location = new System.Drawing.Point(136, 112);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(160, 24);
this.label2.TabIndex = 1;
this.label2.Text = "正在打开程序";
this.label2.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// pictureBox1
//
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(420, 152);
this.pictureBox1.TabIndex = 2;
this.pictureBox1.TabStop = false;
//
// FrmLogo
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(420, 152);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.pictureBox1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Name = "FrmLogo";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.ResumeLayout(false);
}
#endregion
#endregion
#region OnLoad
protected override void OnLoad(EventArgs e)
{
base.OnLoad (e);
thdWait =new Thread(new ThreadStart(WaitProcess));
thdRun =new Thread(new ThreadStart(RunProcess));
thdRun.Start();
thdWait.Start();
}
#endregion
#region Variable
Thread thdWait;
Thread thdRun;
int status = 0;
int loginTime = 0;
ActionString acstr = new ActionString();
WWAM.DBA.SqlConn sqlconn = new WWAM.DBA.SqlConn("");
public bool WaitContinue = true;
int loginid = 0;
string usercode ="";
#endregion
#region Thread Process Method
void WaitProcess()
{
while(WaitContinue)
{
acstr.Next();
this.label1.Text = acstr.Current;
Thread.Sleep(500);
}
this.Close();
}
void RunProcess()
{
bool run = true;
while(run)
{
if(status == 0)
{
#region 检查是否是第一次启动
this.label2.Text = "正在打开程序";
try
{
Process[] ps = Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName);
if(ps!=null && ps.Length>1)
{
using(WWAM.Forms.Dlg.DlgFrmMsg msg1 = new WWAM.Forms.Dlg.DlgFrmMsg(this))
{
msg1.ShowWarning("程序已启动!");
}
status = -1;
}
else
{
status = 1;
}
}
catch{status = 1;}
#endregion
}
if(status == 1)
{
#region 检查是否注册
this.label2.Text = "正在检查注册信息";
if(WWAM.BLL.Verify.CheckLocalVerify())
{
status = 2;
}
else
{
using(WWAM.Forms.Dlg.DlgFrmReg reg = new WWAM.Forms.Dlg.DlgFrmReg(this))
{
if(reg.ShowDialog()==DialogResult.OK)
{
status = 2;
}
else
{
status = -1;
}
}
}
#endregion
}
if(status == 2)
{
#region 检查是否能连接数据库
this.label2.Text = "正在数据库连接";
string s = WWAM.DBA.SqlConn.MakeConnString(
WWAM.XMLConfig.GetNoteValueWithDefault("DBServer","."),
WWAM.XMLConfig.GetNoteValueWithDefault("DBDatabase","WWAdvMgr"),
WWAM.XMLConfig.GetNoteValueWithDefault("DBUser","sa"),
WWAM.XMLConfig.GetNoteValueWithDefault("DBPassword",""));
sqlconn.ReLoadConString(s);
if(sqlconn.TryConn())
{
status = 3;
}
else
{
using(WWAM.Forms.Dlg.DlgFrmDBA dba = new WWAM.Forms.Dlg.DlgFrmDBA(this))
{
if(dba.ShowDialog()==DialogResult.OK)
{
sqlconn = dba.SqlConDB;
WWAM.XMLConfig.SetNode("DBServer",dba.DBServer);
WWAM.XMLConfig.SetNode("DBDatabase",dba.DBDatabase);
WWAM.XMLConfig.SetNode("DBUser",dba.DBUser);
WWAM.XMLConfig.SetNode("DBPassword",dba.DBPassword);
status = 3;
}
else
{
status = -1;
}
}
}
#endregion
}
if(status==3)
{
#region 用户登录
this.label2.Text = "正在登录系统";
if(loginTime == 3)
{
status = -1;
}
else
{
using(WWAM.Forms.Dlg.DlgFrmLogin login = new WWAM.Forms.Dlg.DlgFrmLogin(this))
{
if(login.ShowDialog()==DialogResult.OK)
{
int re = WWAM.DBA.Common.DBLogin(login.UserCode,login.UserPassword,WWAM.SysInfo.HardWare.IPString,sqlconn);
if(re>0)
{
status = 4;
loginid = re;
usercode = login.UserCode;
}
else
{
using(WWAM.Forms.Dlg.DlgFrmMsg msg1 = new WWAM.Forms.Dlg.DlgFrmMsg(this))
{
switch(re)
{
case -1:
msg1.ShowWarning("用户帐号不存在!");
break;
case -2:
msg1.ShowWarning("用户帐号已停用!");
break;
case -3:
msg1.ShowWarning("用户帐号禁止登录!");
break;
case -4:
msg1.ShowWarning("用户密码不正确!");
break;
case -5:
msg1.ShowWarning("用户在别处登陆!");
break;
case -99:
msg1.ShowWarning(string.Format("数据库错误!\r\n{0}",sqlconn.LastError));
break;
default:
msg1.ShowWarning(string.Format("未知错误,错误码:{0}",re));
break;
}
}
loginTime++;
}
}
else
{
status = -1;
}
}
}
#endregion
}
if(status==4)
{
#region 启动主程序
this.label2.Text = "正在启动主窗口";
run = false;
Application.Run(new FrmMain(this,sqlconn,loginid,usercode));
#endregion
}
if(status == -1)
{
#region 退出
run = false;
WaitContinue = false;
#endregion
}
Thread.Sleep(200);
}
}
#endregion
#region ActionString Class
class ActionString
{
int times = 0;
public ActionString()
{
}
public void Reset()
{
times = 0;
}
public string Current
{
get
{
string s = "";
for(int i = 0 ; i < times ; i++)
{
s+=".";
}
return s;
}
}
public void Next()
{
times = times ==3 ? 0:times+1;
}
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -