📄 frmlogin.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using DS.EMIS.StartPrepare.Common;
using System.Text.RegularExpressions;
using System.Configuration;
namespace DS.EMIS.StartPrepare
{
/// <summary>
/// FrmLogin 的摘要说明。
/// </summary>
public class FrmLogin : System.Windows.Forms.Form
{
#region ###控件变量###
private System.Windows.Forms.PictureBox PictureBox1;
private System.Windows.Forms.TextBox txtPassword;
private System.Windows.Forms.TextBox txtUserName;
private System.Windows.Forms.Label Label2;
private System.Windows.Forms.Timer fadeTimer;
private System.Windows.Forms.Label Label1;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Button btnCancel;
private System.Windows.Forms.Button btnOk;
private System.Windows.Forms.TextBox txtServiceName;
private System.ComponentModel.IContainer components;
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(FrmLogin));
this.PictureBox1 = new System.Windows.Forms.PictureBox();
this.txtPassword = new System.Windows.Forms.TextBox();
this.txtUserName = new System.Windows.Forms.TextBox();
this.Label2 = new System.Windows.Forms.Label();
this.fadeTimer = new System.Windows.Forms.Timer(this.components);
this.Label1 = new System.Windows.Forms.Label();
this.txtServiceName = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.btnCancel = new System.Windows.Forms.Button();
this.btnOk = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// PictureBox1
//
this.PictureBox1.Dock = System.Windows.Forms.DockStyle.Top;
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(320, 64);
this.PictureBox1.TabIndex = 17;
this.PictureBox1.TabStop = false;
//
// txtPassword
//
this.txtPassword.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.txtPassword.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.txtPassword.Location = new System.Drawing.Point(112, 112);
this.txtPassword.Name = "txtPassword";
this.txtPassword.PasswordChar = '*';
this.txtPassword.Size = new System.Drawing.Size(176, 21);
this.txtPassword.TabIndex = 12;
this.txtPassword.Text = "";
//
// txtUserName
//
this.txtUserName.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.txtUserName.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.txtUserName.Location = new System.Drawing.Point(112, 80);
this.txtUserName.Name = "txtUserName";
this.txtUserName.Size = new System.Drawing.Size(176, 21);
this.txtUserName.TabIndex = 11;
this.txtUserName.Text = "";
//
// Label2
//
this.Label2.AutoSize = true;
this.Label2.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.Label2.Location = new System.Drawing.Point(56, 112);
this.Label2.Name = "Label2";
this.Label2.Size = new System.Drawing.Size(42, 17);
this.Label2.TabIndex = 16;
this.Label2.Text = "密码:";
//
// fadeTimer
//
this.fadeTimer.Interval = 50;
//
// Label1
//
this.Label1.AutoSize = true;
this.Label1.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.Label1.Location = new System.Drawing.Point(48, 80);
this.Label1.Name = "Label1";
this.Label1.Size = new System.Drawing.Size(54, 17);
this.Label1.TabIndex = 15;
this.Label1.Text = "用户名:";
//
// txtServiceName
//
this.txtServiceName.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.txtServiceName.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.txtServiceName.Location = new System.Drawing.Point(112, 144);
this.txtServiceName.Name = "txtServiceName";
this.txtServiceName.Size = new System.Drawing.Size(176, 21);
this.txtServiceName.TabIndex = 18;
this.txtServiceName.Text = "";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label3.Location = new System.Drawing.Point(16, 144);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(86, 17);
this.label3.TabIndex = 19;
this.label3.Text = "Oracle服务名:";
//
// btnCancel
//
this.btnCancel.Anchor = System.Windows.Forms.AnchorStyles.None;
this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnCancel.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.btnCancel.Location = new System.Drawing.Point(208, 176);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(72, 23);
this.btnCancel.TabIndex = 21;
this.btnCancel.Text = "Cancel";
//
// btnOk
//
this.btnOk.Anchor = System.Windows.Forms.AnchorStyles.None;
this.btnOk.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.btnOk.Location = new System.Drawing.Point(112, 176);
this.btnOk.Name = "btnOk";
this.btnOk.Size = new System.Drawing.Size(80, 23);
this.btnOk.TabIndex = 20;
this.btnOk.Text = "OK";
this.btnOk.Click += new System.EventHandler(this.btnOk_Click);
//
// FrmLogin
//
this.AcceptButton = this.btnOk;
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.CancelButton = this.btnCancel;
this.ClientSize = new System.Drawing.Size(320, 214);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.btnOk);
this.Controls.Add(this.txtServiceName);
this.Controls.Add(this.txtPassword);
this.Controls.Add(this.txtUserName);
this.Controls.Add(this.label3);
this.Controls.Add(this.PictureBox1);
this.Controls.Add(this.Label2);
this.Controls.Add(this.Label1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "FrmLogin";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "登录开局工具";
this.Load += new System.EventHandler(this.FrmLogin_Load);
this.ResumeLayout(false);
}
#endregion
#endregion
#region ### CTOR & Dispose ###
#region CTOR
public FrmLogin()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
#endregion
#region Dispose
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#endregion
#endregion
#region ### 自定义变量 ###
public bool validate = false;
#endregion
#region ### 自定义方法 ###
public void Authenticate(string name,string pwd,string service)
{
string connStr = this.GetDBConnString();
if(DBAccess.TryConnect(connStr))
{
SaveConnStr(connStr);
DBAccess.UserID = name;
DBAccess.UserPD = pwd;
DBAccess.ServiceName = service;
validate = true;
this.Close();
}
else
{MessageBox.Show(this,"连接数据库失败!","提示");}
}
public string GetDBConnString()
{
return string.Format("data source={2};user id={0};password={1}",
this.txtUserName.Text.Trim(),this.txtPassword.Text.Trim(),this.txtServiceName.Text.Trim());
}
private void SaveConnStr(string cntString)
{
GlobalObject.Instance.LocalSession.UpdateConfig("OracleConnStr",cntString,"App.config");
}
public void LoadConfig(string cntString)
{
if(cntString != null)
{
Regex regex = new Regex(@"^data source=(?<datasource>\S*);user id=(?<userid>\S*);password=(?<password>\S*)$");
Match match = regex.Match(cntString);
this.txtServiceName.Text = match.Groups["datasource"].Value;
this.txtUserName.Text = match.Groups["userid"].Value;
this.txtPassword.Text = match.Groups["password"].Value;
}
}
#endregion
#region ### 自定义事件 ###
#endregion
#region ### 控件事件方法 ###
private void btnOk_Click(object sender, System.EventArgs e)
{
Authenticate(this.txtUserName.Text.Trim(),this.txtPassword.Text.Trim(),this.txtServiceName.Text.Trim());
}
private void FrmLogin_Load(object sender, System.EventArgs e)
{
this.LoadConfig( GlobalObject.Instance.LocalSession.GetConfig("OracleConnStr","App.Config") );
Refresh();
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -