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

📄 setwin.cs

📁 食堂就餐提醒系统(含源码) 为一个单位开发的
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

using System.IO;
using System.Text;
using System.Data;

using System.Threading;

using Microsoft.Win32;

namespace XFMAS
{
	/// <summary>
	/// SetWin 的摘要说明。
	/// </summary>
	public class SetWin : System.Windows.Forms.Form
	{
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.Button button1;
		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.Windows.Forms.TextBox sqlPwd;
		private System.Windows.Forms.TextBox sqlUser;
		private System.Windows.Forms.TextBox sqlServer;
		private System.Windows.Forms.TextBox T;
		private System.Windows.Forms.Label state;
		private System.Windows.Forms.Button button2;
		private System.Windows.Forms.CheckBox checkBox1;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public SetWin()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			this.LoadConfig();
		}

		/// <summary>
		/// 载入配置
		/// </summary>
		private void LoadConfig(){
			if(Public.configXml != null){
				this.sqlServer.Text = Public.configXml.Rows[0]["SqlServer"].ToString();
				this.sqlUser.Text   = Public.configXml.Rows[0]["SqlUser"].ToString();
				this.sqlPwd.Text    = Public.DeCode("ESST_PWD",Public.configXml.Rows[0]["SqlPwd"].ToString());
			}
		}

		/// <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()
		{
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.checkBox1 = new System.Windows.Forms.CheckBox();
			this.T = new System.Windows.Forms.TextBox();
			this.sqlServer = new System.Windows.Forms.TextBox();
			this.sqlUser = new System.Windows.Forms.TextBox();
			this.sqlPwd = new System.Windows.Forms.TextBox();
			this.label4 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.label1 = new System.Windows.Forms.Label();
			this.button1 = new System.Windows.Forms.Button();
			this.state = new System.Windows.Forms.Label();
			this.button2 = new System.Windows.Forms.Button();
			this.groupBox1.SuspendLayout();
			this.SuspendLayout();
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.Add(this.checkBox1);
			this.groupBox1.Controls.Add(this.T);
			this.groupBox1.Controls.Add(this.sqlServer);
			this.groupBox1.Controls.Add(this.sqlUser);
			this.groupBox1.Controls.Add(this.sqlPwd);
			this.groupBox1.Controls.Add(this.label4);
			this.groupBox1.Controls.Add(this.label3);
			this.groupBox1.Controls.Add(this.label2);
			this.groupBox1.Controls.Add(this.label1);
			this.groupBox1.Location = new System.Drawing.Point(8, 8);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(352, 152);
			this.groupBox1.TabIndex = 0;
			this.groupBox1.TabStop = false;
			// 
			// checkBox1
			// 
			this.checkBox1.Checked = true;
			this.checkBox1.CheckState = System.Windows.Forms.CheckState.Checked;
			this.checkBox1.Location = new System.Drawing.Point(112, 120);
			this.checkBox1.Name = "checkBox1";
			this.checkBox1.TabIndex = 8;
			this.checkBox1.Text = "开机自动运行";
			// 
			// T
			// 
			this.T.Enabled = false;
			this.T.Location = new System.Drawing.Point(112, 24);
			this.T.Name = "T";
			this.T.Size = new System.Drawing.Size(224, 21);
			this.T.TabIndex = 7;
			this.T.Text = "消防支队食堂就餐提醒系统";
			// 
			// sqlServer
			// 
			this.sqlServer.Location = new System.Drawing.Point(112, 48);
			this.sqlServer.Name = "sqlServer";
			this.sqlServer.Size = new System.Drawing.Size(224, 21);
			this.sqlServer.TabIndex = 6;
			this.sqlServer.Text = "";
			// 
			// sqlUser
			// 
			this.sqlUser.Location = new System.Drawing.Point(112, 72);
			this.sqlUser.Name = "sqlUser";
			this.sqlUser.Size = new System.Drawing.Size(224, 21);
			this.sqlUser.TabIndex = 5;
			this.sqlUser.Text = "";
			// 
			// sqlPwd
			// 
			this.sqlPwd.Location = new System.Drawing.Point(112, 96);
			this.sqlPwd.Name = "sqlPwd";
			this.sqlPwd.PasswordChar = '*';
			this.sqlPwd.Size = new System.Drawing.Size(224, 21);
			this.sqlPwd.TabIndex = 4;
			this.sqlPwd.Text = "";
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(16, 104);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(112, 16);
			this.label4.TabIndex = 3;
			this.label4.Text = "服务器登录密码";
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(16, 80);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(112, 16);
			this.label3.TabIndex = 2;
			this.label3.Text = "服务器登录用户";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(16, 56);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(80, 16);
			this.label2.TabIndex = 1;
			this.label2.Text = "服务器IP地址";
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(16, 32);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(80, 16);
			this.label1.TabIndex = 0;
			this.label1.Text = "系统名称";
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(232, 168);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(64, 23);
			this.button1.TabIndex = 1;
			this.button1.Text = "确 定";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// state
			// 
			this.state.Location = new System.Drawing.Point(8, 176);
			this.state.Name = "state";
			this.state.Size = new System.Drawing.Size(192, 16);
			this.state.TabIndex = 2;
			// 
			// button2
			// 
			this.button2.Location = new System.Drawing.Point(296, 168);
			this.button2.Name = "button2";
			this.button2.Size = new System.Drawing.Size(64, 23);
			this.button2.TabIndex = 3;
			this.button2.Text = "取 消";
			this.button2.Click += new System.EventHandler(this.button2_Click);
			// 
			// SetWin
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(370, 207);
			this.Controls.Add(this.button2);
			this.Controls.Add(this.state);
			this.Controls.Add(this.button1);
			this.Controls.Add(this.groupBox1);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "SetWin";
			this.ShowInTaskbar = false;
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "参数设置";
			this.groupBox1.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// 存储设置
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void button1_Click(object sender, System.EventArgs e) {

			this.button1.Enabled = false;
			this.button2.Enabled = false;

			//验证必填数据是否为空
			if(this.sqlUser.Text.Trim() == "" || this.sqlServer.Text.Trim() == "" || this.sqlPwd.Text.Trim() == ""){

				MessageBox.Show("所有项填必须填写!");
				return;

			}else{
			
				Thread thread = new Thread(new ThreadStart(SaveConfig));
				thread.IsBackground = true;
				thread.Start();

				//this.SaveConfig();

			}

		}

		/// <summary>
		/// 保存配置
		/// </summary>
		private void SaveConfig(){
		


			this.state.Text = "正在保存配置....";

			if(Public.configXml == null){
				Public.configXml = SRXML.ConfigTable();
			}

			if(Public.configXml.Rows.Count == 1){

				Public.configXml.Rows[0]["SqlUser"]   = this.sqlUser.Text.Trim();
				Public.configXml.Rows[0]["SqlPwd"]    = Public.Encode("ESST_PWD",this.sqlPwd.Text.Trim());
				Public.configXml.Rows[0]["SqlServer"] = this.sqlServer.Text.Trim();

				if(this.checkBox1.Checked){
					
					//在注册表中处理开机自动运行
					string dir = Directory.GetCurrentDirectory();
					string exe = dir + "\\XFMAS.exe";

					//获取Run键
					RegistryKey key1 = Registry.LocalMachine;
					RegistryKey key2 = key1.CreateSubKey("SOFTWARE");
					RegistryKey key3 = key2.CreateSubKey("Microsoft");
					RegistryKey key4 = key3.CreateSubKey("Windows");
					RegistryKey key5 = key4.CreateSubKey("CurrentVersion");
					RegistryKey key6 = key5.CreateSubKey("Run");

					//在Run键中写入一个新的键值
					key6.SetValue("ESST_XFMAS",exe);

				}else{
					
					//删除随机启动
					RegistryKey key1 = Registry.LocalMachine;
					RegistryKey key2 = key1.CreateSubKey("SOFTWARE");
					RegistryKey key3 = key2.CreateSubKey("Microsoft");
					RegistryKey key4 = key3.CreateSubKey("Windows");
					RegistryKey key5 = key4.CreateSubKey("CurrentVersion");
					RegistryKey key6 = key5.CreateSubKey("Run");

					//在Run键中写入一个新的键值
					key6.SetValue("ESST_XFMAS",false);

				}

			}else{

				DataRow row = Public.configXml.NewRow();

				row["SqlUser"]   = this.sqlUser.Text.Trim();
				row["SqlPwd"]    = Public.Encode("ESST_PWD",this.sqlPwd.Text.Trim());
				row["SqlServer"] = this.sqlServer.Text.Trim();

				Public.configXml.Rows.Add(row);
			}

			//保存
			SRXML.SaveDataTableToXML(Public.configXml,Public.configFile);

			this.state.Text = "验证服务器连接参数....";

			//验证连接串
			try{
				Public.Conn(this.sqlServer.Text.Trim(),this.sqlUser.Text.Trim(),this.sqlPwd.Text.Trim());
				this.Close();
			}catch(Exception ex){
				MessageBox.Show(ex.Message.ToString());
				this.button1.Enabled = true;
				this.button2.Enabled = false;
			}

			this.state.Text = "";

		}

		private void button2_Click(object sender, System.EventArgs e) {
			this.Close();
		}

		/// <summary>
		///不
		/// </summary>
		/// <param name="show"></param>
		public void SetCheckBoxState(bool show){
			if(!show){
				this.checkBox1.Checked = false;
				this.checkBox1.Visible = false;
			}
		}
	}
}

⌨️ 快捷键说明

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