#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 DelAccount
	///
	/// 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 DelAccount : public System::Windows::Forms::Form
	{
	public: 
		DelAccount(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::Button *  button2;
    private: System::Windows::Forms::Button *  button1;
    protected: System::Data::SqlClient::SqlCommand *  sqlCommand;
    protected: System::Data::SqlClient::SqlConnection *  sqlConnection;
    private: System::Windows::Forms::ComboBox *  CB_AccountList;

	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->CB_AccountList = new System::Windows::Forms::ComboBox();
            this->button2 = new System::Windows::Forms::Button();
            this->button1 = new System::Windows::Forms::Button();
            this->sqlCommand = new System::Data::SqlClient::SqlCommand();
            this->sqlConnection = new System::Data::SqlClient::SqlConnection();
            this->SuspendLayout();
            // 
            // CB_AccountList
            // 
            this->CB_AccountList->Location = System::Drawing::Point(24, 24);
            this->CB_AccountList->Name = S"CB_AccountList";
            this->CB_AccountList->Size = System::Drawing::Size(232, 20);
            this->CB_AccountList->TabIndex = 0;
            // 
            // button2
            // 
            this->button2->DialogResult = System::Windows::Forms::DialogResult::Cancel;
            this->button2->Location = System::Drawing::Point(144, 56);
            this->button2->Name = S"button2";
            this->button2->Size = System::Drawing::Size(75, 24);
            this->button2->TabIndex = 21;
            this->button2->Text = S"¨ú®ø";
            // 
            // button1
            // 
            this->button1->Location = System::Drawing::Point(56, 56);
            this->button1->Name = S"button1";
            this->button1->Size = System::Drawing::Size(75, 24);
            this->button1->TabIndex = 20;
            this->button1->Text = S"½T©w";
            this->button1->Click += new System::EventHandler(this, &ObjDataEdit::DelAccount::OK_Click);
            // 
            // 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";
            // 
            // DelAccount
            // 
            this->AutoScaleBaseSize = System::Drawing::Size(5, 15);
            this->ClientSize = System::Drawing::Size(292, 86);
            this->Controls->Add(this->button2);
            this->Controls->Add(this->button1);
            this->Controls->Add(this->CB_AccountList);
            this->Name = S"DelAccount";
            this->Text = S"DelAccount";
            this->Load += new System::EventHandler(this, &ObjDataEdit::DelAccount::DelAccount_Load);
            this->Activated += new System::EventHandler(this, &ObjDataEdit::DelAccount::DelAccount_Activated);
            this->ResumeLayout(false);

        }		
    private: System::Void DelAccount_Load(System::Object *  sender, System::EventArgs *  e)
             {



             }

    private: System::Void OK_Click(System::Object *  sender, System::EventArgs *  e)
             {
                if( CB_AccountList->Text->Length == 0 )
                {
                    return;
                }
                sqlCommand->CommandText = String::Format( "DELETE FROM AccountDB WHERE (Account_id = '{0}')" , CB_AccountList->Text );
                sqlCommand->ExecuteReader()->Close();        
                Close();     
             }

    private: System::Void DelAccount_Activated(System::Object *  sender, System::EventArgs *  e)
            {
                SqlDataReader* myReader;

                sqlCommand->CommandText = "Select Account_Id From AccountDB";
                myReader = sqlCommand->ExecuteReader();        

                while( myReader->Read() )
                {
                    String* Str =  myReader->GetString( 0 ) ;
                    System::Object* AddItem[] = new System::Object*[1];
                    AddItem[0] = Str;
                    CB_AccountList->Items->AddRange(AddItem);
                }

                myReader->Close();
            }

};
}