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

📄 dlgfrmdba.cs

📁 报刊广告管理系统。CSharp编写
💻 CS
字号:
using System;using System.Collections;using System.ComponentModel;using System.Drawing;using System.Windows.Forms;namespace WWAM.Forms.Dlg{	public class DlgFrmDBA : WWAM.Forms.Dlg.DlgBase	{
		#region DlgFrmDBA
		private DevExpress.XtraEditors.SimpleButton btnTest;
		private DevExpress.XtraEditors.TextEdit txtServer;
		private DevExpress.XtraEditors.TextEdit txtDatabase;
		private DevExpress.XtraEditors.TextEdit txtUser;
		private DevExpress.XtraEditors.TextEdit txtPassword;
		private DevExpress.XtraEditors.CheckEdit chkBlankPassword;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label4;		private System.ComponentModel.IContainer components = null;		public DlgFrmDBA()		{			// 该调用是 Windows 窗体设计器所必需的。			InitializeComponent();			// TODO: 在 InitializeComponent 调用后添加任何初始化		}		public DlgFrmDBA(Form form):base(form)		{			// 该调用是 Windows 窗体设计器所必需的。			InitializeComponent();			// TODO: 在 InitializeComponent 调用后添加任何初始化		}		/// <summary>		/// 清理所有正在使用的资源。		/// </summary>		protected override void Dispose( bool disposing )		{			if( disposing )			{				if (components != null) 				{					components.Dispose();				}			}			base.Dispose( disposing );		}		#region 设计器生成的代码		/// <summary>		/// 设计器支持所需的方法 - 不要使用代码编辑器修改		/// 此方法的内容。		/// </summary>		private void InitializeComponent()		{			this.btnTest = new DevExpress.XtraEditors.SimpleButton();
			this.txtServer = new DevExpress.XtraEditors.TextEdit();
			this.txtDatabase = new DevExpress.XtraEditors.TextEdit();
			this.txtUser = new DevExpress.XtraEditors.TextEdit();
			this.txtPassword = new DevExpress.XtraEditors.TextEdit();
			this.chkBlankPassword = new DevExpress.XtraEditors.CheckEdit();
			this.label1 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.label4 = new System.Windows.Forms.Label();
			((System.ComponentModel.ISupportInitialize)(this.txtServer.Properties)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.txtDatabase.Properties)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.txtUser.Properties)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.txtPassword.Properties)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.chkBlankPassword.Properties)).BeginInit();
			this.SuspendLayout();
			// 
			// btnAccept
			// 
			this.btnAccept.Location = new System.Drawing.Point(168, 184);
			this.btnAccept.LookAndFeel.Style = DevExpress.LookAndFeel.LookAndFeelStyle.Skin;
			this.btnAccept.LookAndFeel.UseWindowsXPTheme = false;
			this.btnAccept.Name = "btnAccept";
			this.btnAccept.TabIndex = 6;
			// 
			// btnCancel
			// 
			this.btnCancel.Location = new System.Drawing.Point(256, 184);
			this.btnCancel.LookAndFeel.Style = DevExpress.LookAndFeel.LookAndFeelStyle.Skin;
			this.btnCancel.LookAndFeel.UseWindowsXPTheme = false;
			this.btnCancel.Name = "btnCancel";
			this.btnCancel.TabIndex = 7;
			// 
			// btnTest
			// 
			this.btnTest.Location = new System.Drawing.Point(80, 184);
			this.btnTest.LookAndFeel.Style = DevExpress.LookAndFeel.LookAndFeelStyle.Skin;
			this.btnTest.LookAndFeel.UseWindowsXPTheme = false;
			this.btnTest.Name = "btnTest";
			this.btnTest.TabIndex = 5;
			this.btnTest.Text = "测 试";
			this.btnTest.Click += new System.EventHandler(this.btnTest_Click);
			// 
			// txtServer
			// 
			this.txtServer.EditValue = "";
			this.txtServer.Location = new System.Drawing.Point(104, 24);
			this.txtServer.Name = "txtServer";
			// 
			// txtServer.Properties
			// 
			this.txtServer.Properties.AppearanceFocused.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(224)), ((System.Byte)(192)));
			this.txtServer.Properties.AppearanceFocused.Options.UseBackColor = true;
			this.txtServer.Properties.LookAndFeel.Style = DevExpress.LookAndFeel.LookAndFeelStyle.Skin;
			this.txtServer.Properties.LookAndFeel.UseWindowsXPTheme = false;
			this.txtServer.Size = new System.Drawing.Size(200, 21);
			this.txtServer.TabIndex = 0;
			// 
			// txtDatabase
			// 
			this.txtDatabase.EditValue = "";
			this.txtDatabase.Location = new System.Drawing.Point(104, 56);
			this.txtDatabase.Name = "txtDatabase";
			// 
			// txtDatabase.Properties
			// 
			this.txtDatabase.Properties.AppearanceFocused.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(224)), ((System.Byte)(192)));
			this.txtDatabase.Properties.AppearanceFocused.Options.UseBackColor = true;
			this.txtDatabase.Properties.LookAndFeel.Style = DevExpress.LookAndFeel.LookAndFeelStyle.Skin;
			this.txtDatabase.Properties.LookAndFeel.UseWindowsXPTheme = false;
			this.txtDatabase.Size = new System.Drawing.Size(200, 21);
			this.txtDatabase.TabIndex = 1;
			// 
			// txtUser
			// 
			this.txtUser.EditValue = "";
			this.txtUser.Location = new System.Drawing.Point(104, 88);
			this.txtUser.Name = "txtUser";
			// 
			// txtUser.Properties
			// 
			this.txtUser.Properties.AppearanceFocused.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(224)), ((System.Byte)(192)));
			this.txtUser.Properties.AppearanceFocused.Options.UseBackColor = true;
			this.txtUser.Properties.LookAndFeel.Style = DevExpress.LookAndFeel.LookAndFeelStyle.Skin;
			this.txtUser.Properties.LookAndFeel.UseWindowsXPTheme = false;
			this.txtUser.Size = new System.Drawing.Size(200, 21);
			this.txtUser.TabIndex = 2;
			// 
			// txtPassword
			// 
			this.txtPassword.EditValue = "";
			this.txtPassword.Location = new System.Drawing.Point(104, 120);
			this.txtPassword.Name = "txtPassword";
			// 
			// txtPassword.Properties
			// 
			this.txtPassword.Properties.AppearanceFocused.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(224)), ((System.Byte)(192)));
			this.txtPassword.Properties.AppearanceFocused.Options.UseBackColor = true;
			this.txtPassword.Properties.LookAndFeel.Style = DevExpress.LookAndFeel.LookAndFeelStyle.Skin;
			this.txtPassword.Properties.LookAndFeel.UseWindowsXPTheme = false;
			this.txtPassword.Properties.PasswordChar = '*';
			this.txtPassword.Size = new System.Drawing.Size(200, 21);
			this.txtPassword.TabIndex = 3;
			// 
			// chkBlankPassword
			// 
			this.chkBlankPassword.Location = new System.Drawing.Point(104, 152);
			this.chkBlankPassword.Name = "chkBlankPassword";
			// 
			// chkBlankPassword.Properties
			// 
			this.chkBlankPassword.Properties.Caption = "空白密码";
			this.chkBlankPassword.Size = new System.Drawing.Size(80, 19);
			this.chkBlankPassword.TabIndex = 4;
			this.chkBlankPassword.TabStop = false;
			this.chkBlankPassword.CheckedChanged += new System.EventHandler(this.chkBlankPassword_CheckedChanged);
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(16, 24);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(80, 23);
			this.label1.TabIndex = 8;
			this.label1.Text = "服务器名:";
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(16, 56);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(80, 23);
			this.label2.TabIndex = 9;
			this.label2.Text = "数据库名:";
			this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(16, 88);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(80, 23);
			this.label3.TabIndex = 10;
			this.label3.Text = "登陆用户:";
			this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(16, 120);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(80, 23);
			this.label4.TabIndex = 11;
			this.label4.Text = "登陆密码:";
			this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// DlgFrmDBA
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(346, 224);
			this.Controls.Add(this.label4);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.chkBlankPassword);
			this.Controls.Add(this.txtPassword);
			this.Controls.Add(this.txtUser);
			this.Controls.Add(this.txtDatabase);
			this.Controls.Add(this.txtServer);
			this.Controls.Add(this.btnTest);
			this.Name = "DlgFrmDBA";
			this.Text = "数据库连接配置";
			this.Controls.SetChildIndex(this.btnTest, 0);
			this.Controls.SetChildIndex(this.txtServer, 0);
			this.Controls.SetChildIndex(this.btnCancel, 0);
			this.Controls.SetChildIndex(this.btnAccept, 0);
			this.Controls.SetChildIndex(this.txtDatabase, 0);
			this.Controls.SetChildIndex(this.txtUser, 0);
			this.Controls.SetChildIndex(this.txtPassword, 0);
			this.Controls.SetChildIndex(this.chkBlankPassword, 0);
			this.Controls.SetChildIndex(this.label1, 0);
			this.Controls.SetChildIndex(this.label2, 0);
			this.Controls.SetChildIndex(this.label3, 0);
			this.Controls.SetChildIndex(this.label4, 0);
			((System.ComponentModel.ISupportInitialize)(this.txtServer.Properties)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.txtDatabase.Properties)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.txtUser.Properties)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.txtPassword.Properties)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.chkBlankPassword.Properties)).EndInit();
			this.ResumeLayout(false);

		}		#endregion		#endregion

		#region Variable
		WWAM.DBA.SqlConn sqlconn = new WWAM.DBA.SqlConn("");
		WWAM.Forms.Dlg.DlgFrmMsg msg;
		public WWAM.DBA.SqlConn SqlConDB
		{
			get
			{
				return sqlconn;
			}
		}
		public string DBServer
		{
			get{return this.txtServer.Text.Trim();}
		}
		public string DBDatabase
		{
			get{return this.txtDatabase.Text.Trim();}
		}
		public string DBUser
		{
			get{return this.txtUser.Text.Trim();}
		}
		public string DBPassword
		{
			get{return this.txtPassword.Text.Trim();}
		}
		#endregion

		#region OnLoad		protected override void OnLoad(EventArgs e)
		{
			base.OnLoad (e);
			msg = new DlgFrmMsg(this);
		}		#endregion		#region CanClose		protected override bool CanClose()
		{
			if(this.txtPassword.Enabled && this.txtPassword.Text.Trim() == string.Empty)			{				this.txtPassword.Focus();				return false;			}			string s = WWAM.DBA.SqlConn.MakeConnString(				this.txtServer.Text.Trim(),				this.txtDatabase.Text.Trim(),				this.txtUser.Text.Trim(),				this.txtPassword.Text.Trim()				);
			sqlconn.ReLoadConString(s);
			if(sqlconn.TryConn())
			{
				WWAM.XMLConfig.SetNode("DBServer",this.txtServer.Text.Trim());
				WWAM.XMLConfig.SetNode("DBDatabase",this.txtDatabase.Text.Trim());
				WWAM.XMLConfig.SetNode("DBUser",this.txtUser.Text.Trim());
				WWAM.XMLConfig.SetNode("DBPassword",this.txtPassword.Text.Trim());
			}
			else
			{
				sqlconn.ReLoadConString("");
				msg.ShowWarning("数据库连接失败!\r\n"+sqlconn.LastError);
				this.txtServer.Focus();
				return false;
			}
			return base.CanClose ();
		}
		#endregion
		#region OnFormShow
		protected override void OnFormShow()
		{
			base.OnFormShow ();
			this.txtServer.Focus();
		}

		#endregion

		#region ShowDialog
		public new DialogResult ShowDialog()
		{
			this.txtServer.Text = WWAM.XMLConfig.GetNodeValue("DBServer");
			this.txtDatabase.Text = WWAM.XMLConfig.GetNodeValue("DBDatabase");
			this.txtUser.Text = WWAM.XMLConfig.GetNodeValue("DBUser");
			this.txtPassword.Text = WWAM.XMLConfig.GetNodeValue("DBPassword");
			this.txtPassword.Enabled = true;
			this.chkBlankPassword.Checked = false;
			return base.ShowDialog();
		}
		#endregion

		#region Control Event
		private void chkBlankPassword_CheckedChanged(object sender, System.EventArgs e)
		{
			if(this.chkBlankPassword.Checked)
			{
				this.txtPassword.Text = "";
			}
			this.txtPassword.Enabled = !this.chkBlankPassword.Checked;
		}

		private void btnTest_Click(object sender, System.EventArgs e)
		{
			string s = WWAM.DBA.SqlConn.MakeConnString(				this.txtServer.Text.Trim(),				this.txtDatabase.Text.Trim(),				this.txtUser.Text.Trim(),				this.txtPassword.Text.Trim()				);
			sqlconn.ReLoadConString(s);
			if(!sqlconn.TryConn())
			{
				sqlconn.ReLoadConString("");
				msg.ShowWarning("数据库连接失败!\r\n"+sqlconn.LastError);
			}
			else
			{
				msg.ShowInfo("数据库连接成功!");
			}
		}
		#endregion

	}}

⌨️ 快捷键说明

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