#pragma once
#pragma		warning (disable:4146)
#include <Windows.h>

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::Text;
using namespace System::Data::SqlClient;

namespace ObjDataEdit
{
	/// <summary> 
	/// Summary for LoginForm
	///
	/// WARNING: If you change the name of this class, you will need to change the 
	///          'Resource File Name' property for the managed resource compiler tool 
	///          associated with all .resx files this class depends on.  Otherwise,
	///          the designers will not be able to interact properly with localized
	///          resources associated with this form.
	/// </summary>
	public __gc class LoginForm : public System::Windows::Forms::Form
	{
	public: 
        String* Account()  { return TB_Account->Text;};
        String* Password() { return TB_PassWord->Text;};
        bool    IsAccept() { return _IsAccept; }



		LoginForm(void)
		{
            _IsAccept = false;
			InitializeComponent();
			sqlConnection->ConnectionString = Global::GetDBSource();
            sqlConnection->Open();    
		}
        
	protected: 
		void Dispose(Boolean disposing)
		{
			if (disposing && components)
			{
				components->Dispose();
			}
			__super::Dispose(disposing);
		}
    private: bool   _IsAccept;
    private: System::Windows::Forms::Panel *  panel1;
    private: System::Windows::Forms::Label *  label1;
    private: System::Windows::Forms::Label *  label2;
	private: System::Windows::Forms::TextBox*  TB_Account;
	private: System::Windows::Forms::TextBox*  TB_PassWord;


    private: System::Windows::Forms::Button *  button1;
    private: System::Windows::Forms::Button *  button2;
    protected: System::Data::SqlClient::SqlCommand *  sqlCommand;
    protected: System::Data::SqlClient::SqlConnection *  sqlConnection;

	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>
		System::ComponentModel::Container* components;

		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			this->panel1 = (new System::Windows::Forms::Panel());
			this->button2 = (new System::Windows::Forms::Button());
			this->button1 = (new System::Windows::Forms::Button());
			this->TB_PassWord = (new System::Windows::Forms::TextBox());
			this->TB_Account = (new System::Windows::Forms::TextBox());
			this->label2 = (new System::Windows::Forms::Label());
			this->label1 = (new System::Windows::Forms::Label());
			this->sqlCommand = (new System::Data::SqlClient::SqlCommand());
			this->sqlConnection = (new System::Data::SqlClient::SqlConnection());
			this->panel1->SuspendLayout();
			this->SuspendLayout();
			// 
			// panel1
			// 
			this->panel1->Controls->Add(this->button2);
			this->panel1->Controls->Add(this->button1);
			this->panel1->Controls->Add(this->TB_PassWord);
			this->panel1->Controls->Add(this->TB_Account);
			this->panel1->Controls->Add(this->label2);
			this->panel1->Controls->Add(this->label1);
			this->panel1->Dock = System::Windows::Forms::DockStyle::Fill;
			this->panel1->Location = System::Drawing::Point(0, 0);
			this->panel1->Name = S"panel1";
			this->panel1->Size = System::Drawing::Size(208, 102);
			this->panel1->TabIndex = 0;
			// 
			// button2
			// 
			this->button2->DialogResult = System::Windows::Forms::DialogResult::Cancel;
			this->button2->Location = System::Drawing::Point(112, 72);
			this->button2->Name = S"button2";
			this->button2->Size = System::Drawing::Size(75, 24);
			this->button2->TabIndex = 5;
			this->button2->Text = S"取消";
			this->button2->Click += new System::EventHandler(this, &LoginForm::button2_Click);
			// 
			// button1
			// 
			this->button1->Location = System::Drawing::Point(24, 72);
			this->button1->Name = S"button1";
			this->button1->Size = System::Drawing::Size(75, 24);
			this->button1->TabIndex = 4;
			this->button1->Text = S"確定";
			this->button1->Click += new System::EventHandler(this, &LoginForm::button1_Click);
			// 
			// TB_PassWord
			// 
			this->TB_PassWord->Location = System::Drawing::Point(64, 40);
			this->TB_PassWord->MaxLength = 31;
			this->TB_PassWord->Name = S"TB_PassWord";
			this->TB_PassWord->PasswordChar = '*';
			this->TB_PassWord->Size = System::Drawing::Size(120, 22);
			this->TB_PassWord->TabIndex = 3;
			// 
			// TB_Account
			// 
			this->TB_Account->Location = System::Drawing::Point(64, 8);
			this->TB_Account->MaxLength = 31;
			this->TB_Account->Name = S"TB_Account";
			this->TB_Account->Size = System::Drawing::Size(120, 22);
			this->TB_Account->TabIndex = 2;
			// 
			// label2
			// 
			this->label2->AutoSize = true;
			this->label2->Location = System::Drawing::Point(16, 48);
			this->label2->Name = S"label2";
			this->label2->Size = System::Drawing::Size(41, 12);
			this->label2->TabIndex = 1;
			this->label2->Text = S"密碼：";
			// 
			// label1
			// 
			this->label1->AutoSize = true;
			this->label1->Location = System::Drawing::Point(16, 16);
			this->label1->Name = S"label1";
			this->label1->Size = System::Drawing::Size(41, 12);
			this->label1->TabIndex = 0;
			this->label1->Text = S"帳號：";
			// 
			// sqlCommand
			// 
			this->sqlCommand->Connection = this->sqlConnection;
			// 
			// sqlConnection
			// 
			this->sqlConnection->ConnectionString = S"workstation id=HSIANG;packet size=4096;user id=hsiangren;persist security info=Tr" 
				S"ue;initial catalog=ObjectData;password=2ddilxxl;data source=GS1";
			this->sqlConnection->FireInfoMessageEventOnUserErrors = false;
			// 
			// LoginForm
			// 
			this->AcceptButton = this->button1;
			this->AutoScaleBaseSize = System::Drawing::Size(5, 15);
			this->CancelButton = this->button2;
			this->ClientSize = System::Drawing::Size(208, 102);
			this->Controls->Add(this->panel1);
			this->Name = S"LoginForm";
			this->StartPosition = System::Windows::Forms::FormStartPosition::CenterParent;
			this->Text = S"登入";
			this->TopMost = true;
			this->Load += new System::EventHandler(this, &LoginForm::LoginForm_Load);
			this->panel1->ResumeLayout(false);
			this->panel1->PerformLayout();
			this->ResumeLayout(false);

		}		
    private: System::Void button2_Click(System::Object *  sender, System::EventArgs *  e)
             {
                 this->Close();
             }

    private: System::Void button1_Click(System::Object *  sender, System::EventArgs *  e)
            {
                if( Account()->Length == 0 )
                {
                    MessageBox::Show( "Account 資料不可以是空的" , "錯誤" );
                    return;
                }
                if( Password()->Length == 0 )
                {
                    MessageBox::Show( "Password 資料不可以是空的" , "錯誤" );
                    return;
                }
                if( CheckAccountInfo() == false )
                {
                    MessageBox::Show( "帳號密碼不符合" , "錯誤" );
                    return;

                }

                this->Close();
                _IsAccept = true;
                LoginFormSaveIni();
            }

    private: System::Void LoginForm_Load(System::Object *  sender, System::EventArgs *  e)
            {
                LoginForm_LoadIni();
            }
            void LoginFormSaveIni( );
            void LoginForm_LoadIni( );
            bool CheckAccountInfo();


};
}