📄 frmlogin.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;
using System.Web;
using ControlSQLsrv2000.WSSQLsrv20004;
namespace ControlSQLsrv2000
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class frmLogin : System.Windows.Forms.Form
{
private System.Windows.Forms.Button cmdConnect;
private System.Windows.Forms.TextBox txtServerName;
private System.Windows.Forms.Label lblServer;
private System.Windows.Forms.Label lblLogin;
private System.Windows.Forms.Label lblPassword;
private System.Windows.Forms.Button cmdCancel;
private System.Windows.Forms.TextBox txtLoginName;
private System.Windows.Forms.TextBox txtPassword;
private System.Windows.Forms.StatusBar stbStatus;
private Microsoft.WindowsCE.Forms.InputPanel inputPanel1;
private System.Windows.Forms.MainMenu mainMenu1;
public struct LoginInfo
{
public string sServer;
public string sLoginName;
public string sPassword;
public string sDatabase;
}
public LoginInfo oLoginInfo;
public frmLogin()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.cmdConnect = new System.Windows.Forms.Button();
this.txtServerName = new System.Windows.Forms.TextBox();
this.lblServer = new System.Windows.Forms.Label();
this.lblLogin = new System.Windows.Forms.Label();
this.txtLoginName = new System.Windows.Forms.TextBox();
this.lblPassword = new System.Windows.Forms.Label();
this.txtPassword = new System.Windows.Forms.TextBox();
this.cmdCancel = new System.Windows.Forms.Button();
this.stbStatus = new System.Windows.Forms.StatusBar();
this.inputPanel1 = new Microsoft.WindowsCE.Forms.InputPanel();
//
// cmdConnect
//
this.cmdConnect.Location = new System.Drawing.Point(131, 133);
this.cmdConnect.Text = "Connect";
this.cmdConnect.Click += new System.EventHandler(this.cmdConnect_Click);
//
// txtServerName
//
this.txtServerName.Location = new System.Drawing.Point(82, 38);
this.txtServerName.Text = "in-db-srv04";
//
// lblServer
//
this.lblServer.Location = new System.Drawing.Point(30, 40);
this.lblServer.Size = new System.Drawing.Size(46, 16);
this.lblServer.Text = "Server";
//
// lblLogin
//
this.lblLogin.Location = new System.Drawing.Point(4, 70);
this.lblLogin.Size = new System.Drawing.Size(72, 16);
this.lblLogin.Text = "Login Name";
//
// txtLoginName
//
this.txtLoginName.Location = new System.Drawing.Point(82, 68);
this.txtLoginName.Text = "pims";
//
// lblPassword
//
this.lblPassword.Location = new System.Drawing.Point(16, 98);
this.lblPassword.Size = new System.Drawing.Size(60, 16);
this.lblPassword.Text = "Password";
//
// txtPassword
//
this.txtPassword.Location = new System.Drawing.Point(82, 96);
this.txtPassword.PasswordChar = '*';
this.txtPassword.Text = "pims32";
//
// cmdCancel
//
this.cmdCancel.Location = new System.Drawing.Point(50, 132);
this.cmdCancel.Text = "Cancel";
this.cmdCancel.Click += new System.EventHandler(this.cmdCancel_Click);
//
// stbStatus
//
this.stbStatus.Location = new System.Drawing.Point(0, 248);
this.stbStatus.Size = new System.Drawing.Size(240, 22);
//
// frmLogin
//
this.BackColor = System.Drawing.Color.Gainsboro;
this.Controls.Add(this.stbStatus);
this.Controls.Add(this.cmdCancel);
this.Controls.Add(this.lblPassword);
this.Controls.Add(this.txtPassword);
this.Controls.Add(this.lblLogin);
this.Controls.Add(this.txtLoginName);
this.Controls.Add(this.lblServer);
this.Controls.Add(this.txtServerName);
this.Controls.Add(this.cmdConnect);
this.Menu = this.mainMenu1;
this.Text = "Login";
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main()
{
Application.Run(new frmLogin());
}
#region "Form events"
private void cmdConnect_Click(object sender, System.EventArgs e)
{
try
{
UpdateStatus("Connecting to the database...");
oLoginInfo.sServer = txtServerName.Text;
oLoginInfo.sLoginName = txtLoginName.Text;
oLoginInfo.sPassword = txtPassword.Text;
oLoginInfo.sDatabase = "";
ConnectDB oConDb = new ConnectDB();
//if (oConDb.fnConnect(oLoginInfo.sServer.ToString() ,oLoginInfo.sLoginName.ToString() ,oLoginInfo.sPassword.ToString()))
if (oConDb.fnConnect(txtServerName.Text ,txtLoginName.Text ,txtPassword.Text))
{
UpdateStatus("Connected...");
frmMain ofrmMain = new frmMain();
ofrmMain.FillTreeView(oLoginInfo);
ofrmMain.Show();
this.Hide();
}
else
{
UpdateStatus("Not Connected...");
}
}
catch (Exception ex)
{
MessageBox.Show (ex.Message.ToString());
}
}
private void cmdCancel_Click(object sender, System.EventArgs e)
{
try
{
Application.Exit();
}
catch (Exception ex)
{
MessageBox.Show (ex.Message.ToString());
}
}
#endregion
#region "Additional Functions"
private void UpdateStatus(string sStatus)
{
stbStatus.Text = sStatus;
stbStatus.Refresh();
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -