#pragma once
#pragma		warning (disable:4146)
#include "DotNetString.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;

namespace ObjDataEdit
{
	/// <summary> 
	/// Summary for DataExportForm
	///
	/// 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 DataExportForm : public System::Windows::Forms::Form
	{
	public: 
		DataExportForm(void)
		{
			InitializeComponent();
		}
        
	protected: 
		void Dispose(Boolean disposing)
		{
			if (disposing && components)
			{
				components->Dispose();
			}
			__super::Dispose(disposing);
		}




	private: System::Windows::Forms::GroupBox*  groupBox1;

	private: System::Windows::Forms::Label*  label3;
	private: System::Windows::Forms::Label*  label2;
	private: System::Windows::Forms::Label*  label1;
	private: System::Windows::Forms::ListBox*  LB_SelectColnum;

	private: System::Windows::Forms::ListBox*  LB_AllColnum;


	private: System::Windows::Forms::Button*  button1;
	private: System::Windows::Forms::TextBox*  TB_OutputFile;
	private: System::Windows::Forms::Button*  button3;
	private: System::Windows::Forms::Button*  button2;
	private: System::Windows::Forms::TextBox*  TB_EditSelection;
	private: System::Windows::Forms::Button*  button4;
	private: System::Windows::Forms::Button*  button5;







	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->groupBox1 = (new System::Windows::Forms::GroupBox());
			this->button3 = (new System::Windows::Forms::Button());
			this->button2 = (new System::Windows::Forms::Button());
			this->label3 = (new System::Windows::Forms::Label());
			this->label2 = (new System::Windows::Forms::Label());
			this->label1 = (new System::Windows::Forms::Label());
			this->LB_SelectColnum = (new System::Windows::Forms::ListBox());
			this->LB_AllColnum = (new System::Windows::Forms::ListBox());
			this->TB_OutputFile = (new System::Windows::Forms::TextBox());
			this->button1 = (new System::Windows::Forms::Button());
			this->TB_EditSelection = (new System::Windows::Forms::TextBox());
			this->button4 = (new System::Windows::Forms::Button());
			this->button5 = (new System::Windows::Forms::Button());
			this->groupBox1->SuspendLayout();
			this->SuspendLayout();
			// 
			// groupBox1
			// 
			this->groupBox1->Controls->Add(this->button3);
			this->groupBox1->Controls->Add(this->button2);
			this->groupBox1->Controls->Add(this->label3);
			this->groupBox1->Controls->Add(this->label2);
			this->groupBox1->Controls->Add(this->label1);
			this->groupBox1->Controls->Add(this->LB_SelectColnum);
			this->groupBox1->Controls->Add(this->LB_AllColnum);
			this->groupBox1->Location = System::Drawing::Point(1, 3);
			this->groupBox1->Name = S"groupBox1";
			this->groupBox1->Size = System::Drawing::Size(367, 409);
			this->groupBox1->TabIndex = 3;
			this->groupBox1->TabStop = false;
			this->groupBox1->Text = S"篩選條件";
			// 
			// button3
			// 
			this->button3->Location = System::Drawing::Point(280, 17);
			this->button3->Name = S"button3";
			this->button3->Size = System::Drawing::Size(75, 23);
			this->button3->TabIndex = 6;
			this->button3->Text = S"全部選取";
			this->button3->UseVisualStyleBackColor = true;
			this->button3->Click += new System::EventHandler(this, &DataExportForm::button3_Click);
			// 
			// button2
			// 
			this->button2->Location = System::Drawing::Point(95, 17);
			this->button2->Name = S"button2";
			this->button2->Size = System::Drawing::Size(75, 23);
			this->button2->TabIndex = 5;
			this->button2->Text = S"全部取消";
			this->button2->UseVisualStyleBackColor = true;
			this->button2->Click += new System::EventHandler(this, &DataExportForm::button2_Click);
			// 
			// label3
			// 
			this->label3->AutoSize = true;
			this->label3->Location = System::Drawing::Point(211, 22);
			this->label3->Name = S"label3";
			this->label3->Size = System::Drawing::Size(53, 12);
			this->label3->TabIndex = 4;
			this->label3->Text = S"輸出欄位";
			// 
			// label2
			// 
			this->label2->AutoSize = true;
			this->label2->Location = System::Drawing::Point(25, 22);
			this->label2->Name = S"label2";
			this->label2->Size = System::Drawing::Size(53, 12);
			this->label2->TabIndex = 3;
			this->label2->Text = S"所有欄位";
			// 
			// label1
			// 
			this->label1->AutoSize = true;
			this->label1->Location = System::Drawing::Point(176, 178);
			this->label1->Name = S"label1";
			this->label1->Size = System::Drawing::Size(23, 12);
			this->label1->TabIndex = 2;
			this->label1->Text = S"<=>";
			// 
			// LB_SelectColnum
			// 
			this->LB_SelectColnum->FormattingEnabled = true;
			this->LB_SelectColnum->ItemHeight = 12;
			this->LB_SelectColnum->Location = System::Drawing::Point(202, 47);
			this->LB_SelectColnum->Name = S"LB_SelectColnum";
			this->LB_SelectColnum->Size = System::Drawing::Size(153, 340);
			this->LB_SelectColnum->TabIndex = 1;
			this->LB_SelectColnum->SelectedIndexChanged += new System::EventHandler(this, &DataExportForm::RemoveDClock);
			// 
			// LB_AllColnum
			// 
			this->LB_AllColnum->FormattingEnabled = true;
			this->LB_AllColnum->ItemHeight = 12;
			this->LB_AllColnum->Location = System::Drawing::Point(17, 47);
			this->LB_AllColnum->Name = S"LB_AllColnum";
			this->LB_AllColnum->Size = System::Drawing::Size(153, 340);
			this->LB_AllColnum->Sorted = true;
			this->LB_AllColnum->TabIndex = 0;
			this->LB_AllColnum->DoubleClick += new System::EventHandler(this, &DataExportForm::SelectColmunDClick);
			// 
			// TB_OutputFile
			// 
			this->TB_OutputFile->Location = System::Drawing::Point(18, 421);
			this->TB_OutputFile->Name = S"TB_OutputFile";
			this->TB_OutputFile->Size = System::Drawing::Size(216, 22);
			this->TB_OutputFile->TabIndex = 7;
			this->TB_OutputFile->Text = S"Output.txt";
			// 
			// button1
			// 
			this->button1->Location = System::Drawing::Point(264, 419);
			this->button1->Name = S"button1";
			this->button1->Size = System::Drawing::Size(92, 24);
			this->button1->TabIndex = 6;
			this->button1->Text = S"輸出";
			this->button1->Click += new System::EventHandler(this, &DataExportForm::OKClick);
			// 
			// TB_EditSelection
			// 
			this->TB_EditSelection->Location = System::Drawing::Point(374, 12);
			this->TB_EditSelection->Multiline = true;
			this->TB_EditSelection->Name = S"TB_EditSelection";
			this->TB_EditSelection->Size = System::Drawing::Size(171, 115);
			this->TB_EditSelection->TabIndex = 8;
			// 
			// button4
			// 
			this->button4->Location = System::Drawing::Point(374, 133);
			this->button4->Name = S"button4";
			this->button4->Size = System::Drawing::Size(80, 24);
			this->button4->TabIndex = 9;
			this->button4->Text = S"匯入";
			this->button4->Click += new System::EventHandler(this, &DataExportForm::button4_Click);
			// 
			// button5
			// 
			this->button5->Location = System::Drawing::Point(460, 133);
			this->button5->Name = S"button5";
			this->button5->Size = System::Drawing::Size(85, 24);
			this->button5->TabIndex = 10;
			this->button5->Text = S"匯出";
			this->button5->Click += new System::EventHandler(this, &DataExportForm::button5_Click);
			// 
			// DataExportForm
			// 
			this->AutoScaleBaseSize = System::Drawing::Size(5, 15);
			this->ClientSize = System::Drawing::Size(552, 454);
			this->Controls->Add(this->button5);
			this->Controls->Add(this->button4);
			this->Controls->Add(this->TB_EditSelection);
			this->Controls->Add(this->groupBox1);
			this->Controls->Add(this->TB_OutputFile);
			this->Controls->Add(this->button1);
			this->Name = S"DataExportForm";
			this->Text = S"DataExportForm";
			this->groupBox1->ResumeLayout(false);
			this->groupBox1->PerformLayout();
			this->ResumeLayout(false);
			this->PerformLayout();

		}		
	protected:
	bool	_IsAccept;
	System::Void OKClick(System::Object*  sender, System::EventArgs*  e);
		
	public:
	static DataExportForm*  g_DataExportForm;
	static void Init( );
	static void	ShowForm( );
	static bool	IsAccept(){ return g_DataExportForm->_IsAccept; }
	static String* OutputFile();

	ListBox* GetList_All()	 { return LB_AllColnum;};
	ListBox* GetList_Select() { return LB_SelectColnum;};
	


private: System::Void SelectColmunDClick(System::Object*  sender, System::EventArgs*  e) 
		 {
			 if( LB_AllColnum->SelectedItem == NULL )
				 return;

			LB_SelectColnum->Items->Add( LB_AllColnum->SelectedItem );
			LB_AllColnum->Items->Remove( LB_AllColnum->SelectedItem );
		 }
private: System::Void RemoveDClock(System::Object*  sender, System::EventArgs*  e) 
		 {
			 if( LB_SelectColnum->SelectedItem == NULL )
				 return;

			 LB_AllColnum->Items->Add( LB_SelectColnum->SelectedItem );
			 LB_SelectColnum->Items->Remove( LB_SelectColnum->SelectedItem );
		 }


private: System::Void button3_Click(System::Object*  sender, System::EventArgs*  e) 
		 {
			 for( int i = 0 ; i < LB_AllColnum->Items->Count ; i++ )
			 {
				LB_SelectColnum->Items->Add(LB_AllColnum->Items->Item[i] );
			 }
			 LB_AllColnum->Items->Clear();
		 }
private: System::Void button2_Click(System::Object*  sender, System::EventArgs*  e) 
		 {
			 for( int i = 0 ; i < LB_SelectColnum->Items->Count ; i++ )
			 {
				 LB_AllColnum->Items->Add(LB_SelectColnum->Items->Item[i] );
			 }
			 LB_SelectColnum->Items->Clear();
		 }
private: System::Void button4_Click(System::Object*  sender, System::EventArgs*  e) 
		 {
			//所有資料匯入
			button2_Click( NULL , NULL );
			for( int i = 0 ; i < TB_EditSelection->Lines->Length ; i++ )
			{
				String* Str = TB_EditSelection->Lines[ i ];
				bool IsFind = false;
				//LB_AllColnum->Items->Find( 
				for( int i = 0 ; i < LB_AllColnum->Items->Count ; i++ )
				{
					String* TempStr = (String*)LB_AllColnum->Items->Item[i];
					if( String::Compare( Str , TempStr) == 0 )
					{
						LB_AllColnum->Items->RemoveAt( i );
						LB_SelectColnum->Items->Add( Str );
						IsFind = true;
						break;
					}
				}
				if( IsFind == false )
				{
					String* TempStr = String::Format( "欄位{0}找不到" , Str );
					MessageBox::Show( TempStr );
				}
			}
		 }

private: System::Void button5_Click(System::Object*  sender, System::EventArgs*  e) 
		 {
			 //資料匯出
			TB_EditSelection->Clear();
			 String* newLines[] = new String*[ LB_SelectColnum->Items->Count];
			
			for( int i = 0 ; i < LB_SelectColnum->Items->Count ; i++ )
			{
				newLines[i] = (String*)LB_SelectColnum->Items->Item[i];
			}
			TB_EditSelection->Lines = newLines;

		 }
};
}