⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmconnectparams.cs

📁 LLBLGen 1.21 Sourcecode
💻 CS
字号:
//////////////////////////////////////////////////////////////////////
// Part of LLBLGen sourcecode. See version information
//////////////////////////////////////////////////////////////////////
// COPYRIGHTS:
// Copyright (c)2002 Solutions Design. All rights reserved.
// 
// Released under the following license: (BSD2)
// -------------------------------------------
// Redistribution and use in source and binary forms, with or without modification, 
// are permitted provided that the following conditions are met: 
//
// 1) Redistributions of source code must retain the above copyright notice, this list of 
//    conditions and the following disclaimer. 
// 2) Redistributions in binary form must reproduce the above copyright notice, this list of 
//    conditions and the following disclaimer in the documentation and/or other materials 
//    provided with the distribution. 
// 
// THIS SOFTWARE IS PROVIDED BY SOLUTIONS DESIGN ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 
// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOLUTIONS DESIGN OR CONTRIBUTORS BE LIABLE FOR 
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
//
// The views and conclusions contained in the software and documentation are those of the authors 
// and should not be interpreted as representing official policies, either expressed or implied, 
// of Solutions Design. 
//
//////////////////////////////////////////////////////////////////////
// Contributers to the code:
//		- Frans Bouma [FB]
//////////////////////////////////////////////////////////////////////
// VERSION INFORMATION.
//
// v1.0: First version
//////////////////////////////////////////////////////////////////////
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace LLBLGen
{
	/// <summary>
	/// Purpose: general SQL Server connection form
	/// </summary>
	public class frmConnect : System.Windows.Forms.Form
	{
		#region Class Member Declaration
		private System.Windows.Forms.TextBox tbxServer;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.RadioButton rbtWindowsAuthentication;
		private System.Windows.Forms.RadioButton rbtSQLAuthentication;
		private System.Windows.Forms.GroupBox grpSQLServerCredentials;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.TextBox tbxLoginID;
		private System.Windows.Forms.TextBox tbxPassword;
		private System.Windows.Forms.Button btnOK;
		private System.Windows.Forms.Button btnCancel;
		private System.ComponentModel.Container components = null;
		private	bool				m_bCancelClicked;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.TextBox tbxCatalog;
		private clsConnectParams	m_cpConnectParams;
		#endregion

		public frmConnect(clsConnectParams	cpConnectParams)
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
			m_cpConnectParams = cpConnectParams;
			m_bCancelClicked = false;
			tbxServer.Text = m_cpConnectParams.m_sServerName;
			tbxLoginID.Text = m_cpConnectParams.m_sSQLUID;
			tbxPassword.Text = m_cpConnectParams.m_sSQLPWD;
			rbtWindowsAuthentication.Checked = m_cpConnectParams.m_bUseWindowsAuthentication;
			rbtSQLAuthentication.Checked = !m_cpConnectParams.m_bUseWindowsAuthentication;
			tbxCatalog.Text = m_cpConnectParams.m_sCatalog;
		}
	

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			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.tbxServer = new System.Windows.Forms.TextBox();
			this.label1 = new System.Windows.Forms.Label();
			this.rbtWindowsAuthentication = new System.Windows.Forms.RadioButton();
			this.rbtSQLAuthentication = new System.Windows.Forms.RadioButton();
			this.grpSQLServerCredentials = new System.Windows.Forms.GroupBox();
			this.tbxPassword = new System.Windows.Forms.TextBox();
			this.tbxLoginID = new System.Windows.Forms.TextBox();
			this.label4 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.btnOK = new System.Windows.Forms.Button();
			this.btnCancel = new System.Windows.Forms.Button();
			this.label5 = new System.Windows.Forms.Label();
			this.tbxCatalog = new System.Windows.Forms.TextBox();
			this.grpSQLServerCredentials.SuspendLayout();
			this.SuspendLayout();
			// 
			// tbxServer
			// 
			this.tbxServer.Location = new System.Drawing.Point(57, 6);
			this.tbxServer.Name = "tbxServer";
			this.tbxServer.Size = new System.Drawing.Size(273, 20);
			this.tbxServer.TabIndex = 0;
			this.tbxServer.Text = "";
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(9, 9);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(45, 18);
			this.label1.TabIndex = 1;
			this.label1.Text = "Server";
			// 
			// rbtWindowsAuthentication
			// 
			this.rbtWindowsAuthentication.CheckAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.rbtWindowsAuthentication.Checked = true;
			this.rbtWindowsAuthentication.Location = new System.Drawing.Point(9, 60);
			this.rbtWindowsAuthentication.Name = "rbtWindowsAuthentication";
			this.rbtWindowsAuthentication.Size = new System.Drawing.Size(156, 18);
			this.rbtWindowsAuthentication.TabIndex = 2;
			this.rbtWindowsAuthentication.TabStop = true;
			this.rbtWindowsAuthentication.Text = "Windows Authentication";
			// 
			// rbtSQLAuthentication
			// 
			this.rbtSQLAuthentication.CheckAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.rbtSQLAuthentication.Location = new System.Drawing.Point(9, 81);
			this.rbtSQLAuthentication.Name = "rbtSQLAuthentication";
			this.rbtSQLAuthentication.Size = new System.Drawing.Size(156, 18);
			this.rbtSQLAuthentication.TabIndex = 3;
			this.rbtSQLAuthentication.Text = "SQL Server Authentication";
			this.rbtSQLAuthentication.CheckedChanged += new System.EventHandler(this.rbtSQLAuthentication_CheckedChanged);
			// 
			// grpSQLServerCredentials
			// 
			this.grpSQLServerCredentials.Controls.AddRange(new System.Windows.Forms.Control[] {
																								  this.tbxPassword,
																								  this.tbxLoginID,
																								  this.label4,
																								  this.label3});
			this.grpSQLServerCredentials.Enabled = false;
			this.grpSQLServerCredentials.Location = new System.Drawing.Point(30, 108);
			this.grpSQLServerCredentials.Name = "grpSQLServerCredentials";
			this.grpSQLServerCredentials.Size = new System.Drawing.Size(300, 96);
			this.grpSQLServerCredentials.TabIndex = 4;
			this.grpSQLServerCredentials.TabStop = false;
			this.grpSQLServerCredentials.Text = "SQL Server credentials";
			// 
			// tbxPassword
			// 
			this.tbxPassword.Location = new System.Drawing.Point(78, 54);
			this.tbxPassword.Name = "tbxPassword";
			this.tbxPassword.PasswordChar = '*';
			this.tbxPassword.Size = new System.Drawing.Size(99, 20);
			this.tbxPassword.TabIndex = 1;
			this.tbxPassword.Text = "";
			// 
			// tbxLoginID
			// 
			this.tbxLoginID.Location = new System.Drawing.Point(78, 30);
			this.tbxLoginID.Name = "tbxLoginID";
			this.tbxLoginID.Size = new System.Drawing.Size(99, 20);
			this.tbxLoginID.TabIndex = 0;
			this.tbxLoginID.Text = "";
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(15, 57);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(63, 18);
			this.label4.TabIndex = 1;
			this.label4.Text = "Password";
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(15, 33);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(63, 18);
			this.label3.TabIndex = 0;
			this.label3.Text = "LoginID";
			// 
			// btnOK
			// 
			this.btnOK.DialogResult = System.Windows.Forms.DialogResult.Cancel;
			this.btnOK.Location = new System.Drawing.Point(96, 210);
			this.btnOK.Name = "btnOK";
			this.btnOK.Size = new System.Drawing.Size(69, 24);
			this.btnOK.TabIndex = 5;
			this.btnOK.Text = "OK";
			this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
			// 
			// btnCancel
			// 
			this.btnCancel.CausesValidation = false;
			this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
			this.btnCancel.Location = new System.Drawing.Point(171, 210);
			this.btnCancel.Name = "btnCancel";
			this.btnCancel.Size = new System.Drawing.Size(69, 24);
			this.btnCancel.TabIndex = 6;
			this.btnCancel.Text = "Cancel";
			this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(9, 33);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(45, 18);
			this.label5.TabIndex = 10;
			this.label5.Text = "Catalog";
			// 
			// tbxCatalog
			// 
			this.tbxCatalog.Location = new System.Drawing.Point(57, 30);
			this.tbxCatalog.Name = "tbxCatalog";
			this.tbxCatalog.Size = new System.Drawing.Size(273, 20);
			this.tbxCatalog.TabIndex = 1;
			this.tbxCatalog.Text = "";
			this.tbxCatalog.Validating += new System.ComponentModel.CancelEventHandler(this.tbxCatalog_Validating);
			// 
			// frmConnect
			// 
			this.AcceptButton = this.btnOK;
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.CancelButton = this.btnCancel;
			this.ClientSize = new System.Drawing.Size(336, 242);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.label5,
																		  this.tbxCatalog,
																		  this.btnCancel,
																		  this.btnOK,
																		  this.grpSQLServerCredentials,
																		  this.rbtSQLAuthentication,
																		  this.rbtWindowsAuthentication,
																		  this.label1,
																		  this.tbxServer});
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
			this.Name = "frmConnect";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
			this.Text = "Database Server Connection Parameters";
			this.grpSQLServerCredentials.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		private void btnOK_Click(object sender, System.EventArgs e)
		{
			m_bCancelClicked = false;
			
			// Fill cpConnectParams. Class is created by caller, should be modified.
			m_cpConnectParams.m_bUseWindowsAuthentication = rbtWindowsAuthentication.Checked;
			// TODO: handle textual inputs
			m_cpConnectParams.m_sServerName = tbxServer.Text;
			m_cpConnectParams.m_sSQLPWD = tbxPassword.Text;
			m_cpConnectParams.m_sSQLUID = tbxLoginID.Text;
			m_cpConnectParams.m_sCatalog = tbxCatalog.Text;
		}

		private void rbtSQLAuthentication_CheckedChanged(object sender, System.EventArgs e)
		{
			if(rbtSQLAuthentication.Checked)
			{
				grpSQLServerCredentials.Enabled=true;
			}
			else
			{
				grpSQLServerCredentials.Enabled=false;
			}
		}


		private void btnCancel_Click(object sender, System.EventArgs e)
		{
			m_bCancelClicked=true;
			
			// make validation event throwing fields to shutup, because
			// the form itself will validate every field, no matter what you
			// specify. (probably CLR bug)
			tbxCatalog.CausesValidation = false;
			this.Close();
		}

		private void tbxCatalog_Validating(object sender, System.ComponentModel.CancelEventArgs e)
		{
			if(tbxCatalog.Text.Length<=0)
			{
				e.Cancel=true;
				MessageBox.Show("Catalog should have a value.","Validation Error",
					MessageBoxButtons.OK, MessageBoxIcon.Error);
			}
		}
		
	
		// Properties
		public bool bCancelClicked
		{
			get
			{
				return m_bCancelClicked;
			}
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -