#pragma once
#include <Windows.h>
#include "Global.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::Data::SqlClient;

namespace ObjDataEdit
{
	/// <summary> 
	/// Summary for ModifyAccount
	///
	/// 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 ModifyAccount : public System::Windows::Forms::Form
	{
	public: 
		ModifyAccount(void)
		{
			InitializeComponent();
			this->sqlConnection->ConnectionString = Global::GetDBSource();
			sqlConnection->Open();            
		}
        
	protected: 
		void Dispose(Boolean disposing)
		{
			if (disposing && components)
			{
				components->Dispose();
			}
			__super::Dispose(disposing);
		}

    private: System::Windows::Forms::Label *  label3;
    private: System::Windows::Forms::Button *  button2;
    private: System::Windows::Forms::Button *  button1;


    private: System::Windows::Forms::Label *  label2;
    private: System::Windows::Forms::Label *  label1;
    private: System::Windows::Forms::GroupBox *  groupBox1;

    private: System::Windows::Forms::Label *  label4;
    private: System::Windows::Forms::GroupBox *  groupBox2;
    protected: System::Data::SqlClient::SqlCommand *  sqlCommand;
    protected: System::Data::SqlClient::SqlConnection *  sqlConnection;
    private: System::Windows::Forms::TextBox *  TB_Password2;
    private: System::Windows::Forms::TextBox *  TB_OrgPassword;
    private: System::Windows::Forms::TextBox *  TB_Account;
    private: System::Windows::Forms::TextBox *  TB_Password1;

	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->TB_Password2 = new System::Windows::Forms::TextBox();
            this->label3 = new System::Windows::Forms::Label();
            this->button2 = new System::Windows::Forms::Button();
            this->button1 = new System::Windows::Forms::Button();
            this->TB_OrgPassword = 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->groupBox1 = new System::Windows::Forms::GroupBox();
            this->TB_Password1 = new System::Windows::Forms::TextBox();
            this->label4 = new System::Windows::Forms::Label();
            this->groupBox2 = new System::Windows::Forms::GroupBox();
            this->sqlCommand = new System::Data::SqlClient::SqlCommand();
            this->sqlConnection = new System::Data::SqlClient::SqlConnection();
            this->groupBox1->SuspendLayout();
            this->groupBox2->SuspendLayout();
            this->SuspendLayout();
            // 
            // TB_Password2
            // 
            this->TB_Password2->Location = System::Drawing::Point(80, 56);
            this->TB_Password2->MaxLength = 31;
            this->TB_Password2->Name = S"TB_Password2";
            this->TB_Password2->PasswordChar = '*';
            this->TB_Password2->Size = System::Drawing::Size(120, 22);
            this->TB_Password2->TabIndex = 21;
            this->TB_Password2->Text = S"";
            // 
            // label3
            // 
            this->label3->AutoSize = true;
            this->label3->Location = System::Drawing::Point(8, 64);
            this->label3->Name = S"label3";
            this->label3->Size = System::Drawing::Size(66, 18);
            this->label3->TabIndex = 20;
            this->label3->Text = S"確認密碼：";
            // 
            // button2
            // 
            this->button2->DialogResult = System::Windows::Forms::DialogResult::Cancel;
            this->button2->Location = System::Drawing::Point(136, 232);
            this->button2->Name = S"button2";
            this->button2->Size = System::Drawing::Size(75, 24);
            this->button2->TabIndex = 19;
            this->button2->Text = S"取消";
            this->button2->Click += new System::EventHandler(this, &ObjDataEdit::ModifyAccount::Cancel_Click);
            // 
            // button1
            // 
            this->button1->Location = System::Drawing::Point(48, 232);
            this->button1->Name = S"button1";
            this->button1->Size = System::Drawing::Size(75, 24);
            this->button1->TabIndex = 18;
            this->button1->Text = S"確定";
            this->button1->Click += new System::EventHandler(this, &ObjDataEdit::ModifyAccount::OK_Click);
            // 
            // TB_OrgPassword
            // 
            this->TB_OrgPassword->Location = System::Drawing::Point(80, 64);
            this->TB_OrgPassword->MaxLength = 31;
            this->TB_OrgPassword->Name = S"TB_OrgPassword";
            this->TB_OrgPassword->PasswordChar = '*';
            this->TB_OrgPassword->Size = System::Drawing::Size(120, 22);
            this->TB_OrgPassword->TabIndex = 17;
            this->TB_OrgPassword->Text = S"";
            // 
            // TB_Account
            // 
            this->TB_Account->Location = System::Drawing::Point(80, 32);
            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 = 16;
            this->TB_Account->Text = S"";
            // 
            // label2
            // 
            this->label2->AutoSize = true;
            this->label2->Location = System::Drawing::Point(28, 64);
            this->label2->Name = S"label2";
            this->label2->Size = System::Drawing::Size(42, 18);
            this->label2->TabIndex = 15;
            this->label2->Text = S"密碼：";
            // 
            // label1
            // 
            this->label1->AutoSize = true;
            this->label1->Location = System::Drawing::Point(28, 32);
            this->label1->Name = S"label1";
            this->label1->Size = System::Drawing::Size(42, 18);
            this->label1->TabIndex = 14;
            this->label1->Text = S"帳號：";
            // 
            // groupBox1
            // 
            this->groupBox1->Controls->Add(this->TB_OrgPassword);
            this->groupBox1->Controls->Add(this->TB_Account);
            this->groupBox1->Controls->Add(this->label2);
            this->groupBox1->Controls->Add(this->label1);
            this->groupBox1->Location = System::Drawing::Point(8, 8);
            this->groupBox1->Name = S"groupBox1";
            this->groupBox1->Size = System::Drawing::Size(224, 100);
            this->groupBox1->TabIndex = 22;
            this->groupBox1->TabStop = false;
            this->groupBox1->Text = S"原始資料";
            // 
            // TB_Password1
            // 
            this->TB_Password1->Location = System::Drawing::Point(80, 24);
            this->TB_Password1->MaxLength = 31;
            this->TB_Password1->Name = S"TB_Password1";
            this->TB_Password1->PasswordChar = '*';
            this->TB_Password1->Size = System::Drawing::Size(120, 22);
            this->TB_Password1->TabIndex = 24;
            this->TB_Password1->Text = S"";
            // 
            // label4
            // 
            this->label4->AutoSize = true;
            this->label4->Location = System::Drawing::Point(32, 24);
            this->label4->Name = S"label4";
            this->label4->Size = System::Drawing::Size(42, 18);
            this->label4->TabIndex = 23;
            this->label4->Text = S"密碼：";
            // 
            // groupBox2
            // 
            this->groupBox2->Controls->Add(this->label4);
            this->groupBox2->Controls->Add(this->TB_Password2);
            this->groupBox2->Controls->Add(this->label3);
            this->groupBox2->Controls->Add(this->TB_Password1);
            this->groupBox2->Location = System::Drawing::Point(8, 120);
            this->groupBox2->Name = S"groupBox2";
            this->groupBox2->Size = System::Drawing::Size(224, 100);
            this->groupBox2->TabIndex = 25;
            this->groupBox2->TabStop = false;
            this->groupBox2->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=True;initial catalog=ObjectData;password=2ddilxxl;data source=GS1";
            // 
            // ModifyAccount
            // 
            this->AutoScaleBaseSize = System::Drawing::Size(5, 15);
            this->ClientSize = System::Drawing::Size(240, 270);
            this->Controls->Add(this->groupBox2);
            this->Controls->Add(this->groupBox1);
            this->Controls->Add(this->button2);
            this->Controls->Add(this->button1);
            this->Name = S"ModifyAccount";
            this->Text = S"密碼修改";
            this->groupBox1->ResumeLayout(false);
            this->groupBox2->ResumeLayout(false);
            this->ResumeLayout(false);

        }		
    private: System::Void Cancel_Click(System::Object *  sender, System::EventArgs *  e)
             {
                 Close();
             }

    private: System::Void OK_Click(System::Object *  sender, System::EventArgs *  e)
            {
                if( TB_Account->Text->Length == 0 )
                {
                    //::MessageBox( NULL , "帳號沒輸入" ,"錯誤" , MB_OK );
					MessageBox::Show( "帳號沒輸入" ,"錯誤" );
                    return;
                }
                else
                {
                    int Count = 0;                 
                    sqlCommand->CommandText = String::Format( "Select Account_ID from AccountDB where Account_ID = '{0}' AND Password = '{1}' " , TB_Account->Text , TB_OrgPassword->Text );
                    SqlDataReader* myReader = sqlCommand->ExecuteReader();

                    while( myReader->Read())
                    {
                        Count++;
                    }
                    myReader->Close();
                    if( Count == 0 )
                    {
                        MessageBox::Show( "帳號密碼錯誤" ,"錯誤" );
                        return;
                    }
                }

                if( String::Compare( TB_Password1->Text , TB_Password2->Text ) != 0 )
                {
                    MessageBox::Show( "密碼輸入不相同 " ,"錯誤" );
                    return;
                }

                if( TB_Password1->Text->Length < 4 )
                {
                    MessageBox::Show( "密碼輸入至少要四個字" ,"錯誤" );
                    return;
                }

                sqlCommand->CommandText = String::Format( "UPDATE AccountDB Set Password = '{0}' WHERE Account_ID = '{1}' " 
                    , TB_Password1->Text , TB_Account->Text ) ;

                sqlCommand->ExecuteReader()->Close();
                Close();

            }

};
}