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

📄 clogin.h

📁 MFC程序开发参考大全 【明日科技】宋坤 刘锐宁 李伟明 【丛 书 名】 软件工程师典藏 【出 版 社】 人民邮电出版社 本书详细介绍了MFC框架中所有常用类及控件的应用
💻 H
字号:
#pragma once
#include "CDataManage.h"




namespace BOOKMANAGE {
	
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;



	/// <summary>
	/// CLogin 摘要
	///
	/// 警告: 如果更改此类的名称,则需要更改
	///          与此类所依赖的所有 .resx 文件关联的托管资源编译器工具的
	///          “资源文件名”属性。否则,
	///          设计器将不能与此窗体的关联
	///          本地化资源正确交互。
	/// </summary>
	public ref class CLogin : public System::Windows::Forms::Form
	{
	public:
		CLogin(void)
		{
			InitializeComponent();
			//
			//TODO: 在此处添加构造函数代码
			//
		}
	static bool    Islogined ; //是否进行过重新登录
	static String^ CurUser;    //当前用户
	CDataManage    DataManage; //数据管理对象

	protected:
		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		~CLogin()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::GroupBox^  groupBox1;
	private: System::Windows::Forms::TextBox^  UserPass;
	private: System::Windows::Forms::TextBox^  UserName;
	private: System::Windows::Forms::Label^  label2;
	private: System::Windows::Forms::Label^  label1;
	private: System::Windows::Forms::Button^  ButtonLogin;
	private: System::Windows::Forms::Button^  ButtonCancel;
	protected: 

	private:
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// 设计器支持所需的方法 - 不要
		/// 使用代码编辑器修改此方法的内容。
		/// </summary>
		void InitializeComponent(void)
		{
			System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(CLogin::typeid));
			this->groupBox1 = (gcnew System::Windows::Forms::GroupBox());
			this->UserPass = (gcnew System::Windows::Forms::TextBox());
			this->UserName = (gcnew System::Windows::Forms::TextBox());
			this->label2 = (gcnew System::Windows::Forms::Label());
			this->label1 = (gcnew System::Windows::Forms::Label());
			this->ButtonLogin = (gcnew System::Windows::Forms::Button());
			this->ButtonCancel = (gcnew System::Windows::Forms::Button());
			this->groupBox1->SuspendLayout();
			this->SuspendLayout();
			// 
			// groupBox1
			// 
			this->groupBox1->BackColor = System::Drawing::Color::Transparent;
			this->groupBox1->Controls->Add(this->UserPass);
			this->groupBox1->Controls->Add(this->UserName);
			this->groupBox1->Controls->Add(this->label2);
			this->groupBox1->Controls->Add(this->label1);
			this->groupBox1->Location = System::Drawing::Point(12, 8);
			this->groupBox1->Name = L"groupBox1";
			this->groupBox1->Size = System::Drawing::Size(302, 102);
			this->groupBox1->TabIndex = 0;
			this->groupBox1->TabStop = false;
			this->groupBox1->Text = L"登录信息";
			this->groupBox1->Enter += gcnew System::EventHandler(this, &CLogin::groupBox1_Enter);
			// 
			// UserPass
			// 
			this->UserPass->Location = System::Drawing::Point(132, 60);
			this->UserPass->Name = L"UserPass";
			this->UserPass->PasswordChar = '*';
			this->UserPass->Size = System::Drawing::Size(133, 21);
			this->UserPass->TabIndex = 3;
			// 
			// UserName
			// 
			this->UserName->Location = System::Drawing::Point(132, 28);
			this->UserName->Name = L"UserName";
			this->UserName->Size = System::Drawing::Size(133, 21);
			this->UserName->TabIndex = 2;
			// 
			// label2
			// 
			this->label2->AutoSize = true;
			this->label2->BackColor = System::Drawing::Color::Transparent;
			this->label2->Location = System::Drawing::Point(61, 65);
			this->label2->Name = L"label2";
			this->label2->Size = System::Drawing::Size(53, 12);
			this->label2->TabIndex = 1;
			this->label2->Text = L"登录密码";
			// 
			// label1
			// 
			this->label1->AutoSize = true;
			this->label1->BackColor = System::Drawing::Color::Transparent;
			this->label1->Location = System::Drawing::Point(61, 35);
			this->label1->Name = L"label1";
			this->label1->Size = System::Drawing::Size(53, 12);
			this->label1->TabIndex = 0;
			this->label1->Text = L"用户名称";
			// 
			// ButtonLogin
			// 
			this->ButtonLogin->BackColor = System::Drawing::Color::Transparent;
			this->ButtonLogin->FlatStyle = System::Windows::Forms::FlatStyle::Popup;
			this->ButtonLogin->Location = System::Drawing::Point(108, 125);
			this->ButtonLogin->Name = L"ButtonLogin";
			this->ButtonLogin->Size = System::Drawing::Size(75, 23);
			this->ButtonLogin->TabIndex = 1;
			this->ButtonLogin->Text = L"登录";
			this->ButtonLogin->UseVisualStyleBackColor = false;
			this->ButtonLogin->Click += gcnew System::EventHandler(this, &CLogin::ButtonLogin_Click);
			// 
			// ButtonCancel
			// 
			this->ButtonCancel->BackColor = System::Drawing::Color::Transparent;
			this->ButtonCancel->FlatStyle = System::Windows::Forms::FlatStyle::Popup;
			this->ButtonCancel->Location = System::Drawing::Point(200, 125);
			this->ButtonCancel->Name = L"ButtonCancel";
			this->ButtonCancel->Size = System::Drawing::Size(75, 23);
			this->ButtonCancel->TabIndex = 2;
			this->ButtonCancel->Text = L"取消";
			this->ButtonCancel->UseVisualStyleBackColor = false;
			this->ButtonCancel->Click += gcnew System::EventHandler(this, &CLogin::ButtonCancel_Click);
			// 
			// CLogin
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->BackgroundImage = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"$this.BackgroundImage")));
			this->ClientSize = System::Drawing::Size(328, 198);
			this->Controls->Add(this->ButtonCancel);
			this->Controls->Add(this->ButtonLogin);
			this->Controls->Add(this->groupBox1);
			this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedSingle;
			this->KeyPreview = true;
			this->MaximizeBox = false;
			this->Name = L"CLogin";
			this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
			this->Text = L"系统登录";
			this->FormClosed += gcnew System::Windows::Forms::FormClosedEventHandler(this, &CLogin::CLogin_FormClosed);
			this->FormClosing += gcnew System::Windows::Forms::FormClosingEventHandler(this, &CLogin::CLogin_FormClosing);
			this->KeyDown += gcnew System::Windows::Forms::KeyEventHandler(this, &CLogin::CLogin_KeyDown);
			this->Load += gcnew System::EventHandler(this, &CLogin::CLogin_Load);
			this->groupBox1->ResumeLayout(false);
			this->groupBox1->PerformLayout();
			this->ResumeLayout(false);

		}
#pragma endregion
	private: System::Void groupBox1_Enter(System::Object^  sender, System::EventArgs^  e) {
			 }
	private: System::Void CLogin_Load(System::Object^  sender, System::EventArgs^  e) {

				 			 
				 DataManage.ConStr ="Data Source=.;Initial Catalog=BookManage;User ID=sa";
				 DataManage.ConnectDataBase();

			 }
private: System::Void CLogin_KeyDown(System::Object^  sender, System::Windows::Forms::KeyEventArgs^  e) {

			 if (e->KeyValue==13)
			 {
				 if (ActiveControl->GetType()->Name=="TextBox")
				 {
					Control^ temp = GetNextControl(ActiveControl,true) ;
					temp->Focus();
				}
			 }
		 }
		 //取消
private: System::Void ButtonCancel_Click(System::Object^  sender, System::EventArgs^  e) {
			 Close();
			 
		 }

		//系统登录
private: System::Void ButtonLogin_Click(System::Object^  sender, System::EventArgs^  e) {
			
	 if (UserName->Text->Trim()==""||UserPass->Text->Trim()=="")
	 {
		 MessageBox::Show("用户名或密码不能为空");
		 return;
	 }

	 String^ sql = "select * from userInfo where username = @p1 and password = @p2";

	 DataManage.Command->CommandText = sql;
	 SqlParameter^ param1 =  DataManage.Command->CreateParameter();
	 SqlParameter^ param2 = DataManage.Command->CreateParameter();

	 DataManage.Command->Parameters->Clear();
	
	 DataManage.Command->Parameters->Add(param1);
	 DataManage.Command->Parameters->Add(param2);

	 param1->ParameterName = "p1";
	 param2->ParameterName = "p2";
	 param1->Value = UserName->Text->Trim();
	 param2->Value = UserPass->Text->Trim();
	 
	 DataManage.DataReader =  DataManage.Command->ExecuteReader();
	 if (DataManage.DataReader->HasRows) //表示登录成功
	 {
		 Islogined  = true;
		 CurUser = UserName->Text->Trim();
		 Close();
	 }
	 else
	 {
		 MessageBox::Show("用户名或密码不正确");
	 
	 }
	 DataManage.DataReader->Close();


		 }
private: System::Void CLogin_FormClosed(System::Object^  sender, System::Windows::Forms::FormClosedEventArgs^  e) {
		 }
private: System::Void CLogin_FormClosing(System::Object^  sender, System::Windows::Forms::FormClosingEventArgs^  e) {
			if (Islogined ==false)
				Application::Exit();
		 }
};
}

⌨️ 快捷键说明

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