// DinDanForm2.cpp : implementation file
//

#include "stdafx.h"
#include "ylgl.h"
#include "DinDanForm2.h"
#include "DinDanForm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// DinDanForm2 dialog


DinDanForm2::DinDanForm2(CWnd* pParent /*=NULL*/)
	: CDialog(DinDanForm2::IDD, pParent)
{
	//{{AFX_DATA_INIT(DinDanForm2)
	m_radio1 = 0;
	//}}AFX_DATA_INIT
}


void DinDanForm2::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(DinDanForm2)
	DDX_Control(pDX, IDC_LIST5, m_List2);
	DDX_Control(pDX, IDC_LIST1, m_List1);
	DDX_Radio(pDX, IDC_RADIO1, m_radio1);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(DinDanForm2, CDialog)
	//{{AFX_MSG_MAP(DinDanForm2)
	ON_LBN_SELCHANGE(IDC_LIST1, OnSelchangeList1)
	ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
	ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
	ON_LBN_SELCHANGE(IDC_LIST5, OnSelchangeList5)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// DinDanForm2 message handlers

void DinDanForm2::Init()
{
	CRect rc;	
	GetDlgItem(IDC_RADIO1)->GetWindowRect(rc);
	ScreenToClient(rc);
	rc.left=5;
	GetDlgItem(IDC_RADIO1)->MoveWindow(rc);
	int botoom=rc.bottom;

	GetClientRect(rc);
	rc.left+=5;
	rc.top=botoom+5;
	rc.right-=5;
	rc.bottom-=5;
	m_List1.MoveWindow(rc);


	m_rc=rc;
	m_List1.GetWindowRect(rc);
	ScreenToClient(rc);
	int hei=rc.Height()/2;
	rc.bottom-=hei;
	m_List1.MoveWindow(rc);

	rc.top=rc.bottom;
	rc.bottom+=hei;
	m_List2.MoveWindow(rc);


}

void DinDanForm2::TypeChange(CStringArray *pArray)
{
	m_array.Copy(*pArray);
	m_List1.ResetContent();
	for(int i=0; i<pArray->GetSize(); i++)
	{
		m_List1.AddString(pArray->ElementAt(i));
		if(i<10)
		    m_List1.SetSel(i);
	}m_radio1 = 0;UpdateData(0);
	FilterChange();

}
void DinDanForm2::TypeChange2(CStringArray *pArray)
{
	m_List2.ResetContent();
	for(int i=0; i<pArray->GetSize(); i++)
	{
		m_List2.AddString(pArray->ElementAt(i));
		if(i<1)
		    m_List2.SetSel(i);
	}
}
void DinDanForm2::FilterChange()
{
	m_pfilterarray->RemoveAll();
	int count= m_List1.GetSelCount() ;
	if(count==0)return;
	if(count>10)
	{	
		for(int i=0; i<m_List1.GetCount(); i++)
		{
		   if(m_List1.GetSel(i))
		   {
			   m_List1.SetSel(i, 0);
			   break;
		   }
	 
		}
		FilterChange();
		return;
	}
	int *pIndex=new int[count];
	m_List1.GetSelItems(count, pIndex);
	CString str;
	for(int i=0; i<count; i++)
	{
		m_List1.GetText (pIndex[i], str);
		m_pfilterarray->Add (str);
	}
	delete []pIndex;

	if(m_pfilterarray2->GetSize()==0)
		m_pfilterarray2->Add("ȫ��(ǰ��+����)");
	((DinDanForm*)m_parent)->KindChange();
}

void DinDanForm2::OnSelchangeList1() 
{
	// TODO: Add your control notification handler code here
	FilterChange();
}

void DinDanForm2::OnRadio2() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	m_List1.ResetContent();
	if(m_radio1==0)
	{
	for(int i=0; i<m_array.GetSize(); i++)
	{
		m_List1.AddString(m_array.ElementAt(i));
		if(i<10)
		    m_List1.SetSel(i);
	}
	}
	else
	{
	for(int i=m_array.GetSize()-1; i>=0; i--)
	{
		m_List1.AddString(m_array.ElementAt(i));
		if(i>=m_array.GetSize()-10)
		    m_List1.SetSel(m_array.GetSize()-1-i);
	}
	}
	FilterChange();	
}

void DinDanForm2::OnRadio1() 
{
	// TODO: Add your control notification handler code here
	OnRadio2();
}

void DinDanForm2::OnSelchangeList5() 
{
	// TODO: Add your control notification handler code here
	m_pfilterarray2->RemoveAll();
	CString str;
 
	int pos=m_List2.GetCurSel();
	if(pos!=-1 && m_List2.GetSel(pos) )
	{	
		m_List2.GetText (pos, str);
		if(str=="ԤԼ�տ�" || str=="ԤԼ����")
		{
			m_List2.SetSel(0, 0);
			m_List2.SetSel(1, 0);
		}
		if(str!="ԤԼ�տ�" && str!="ԤԼ����" && pos>2)
		{
			m_List2.SetSel(0, 0);
			m_List2.SetSel(2, 0);
		}	
		if(pos==1 || pos==2)
		{
			m_List2.SetSel(0, 0);
		 
		}
	}
		



	BOOL bAll=0;
	BOOL bAll1=0;
 	BOOL bAll2=0;
	if(m_List2.GetSel(0))bAll=1;
	if(m_List2.GetSel(1))bAll1=1;
	if(m_List2.GetSel(2))bAll2=1;



	if(bAll)
	{
		for(int i=1; i<m_List2.GetCount(); i++)
		{
			m_List2.SetSel(i, 0);
		}
	}
 	else 
	{

		if(bAll1)
		{
		  for(int i=3; i<m_List2.GetCount(); i++)
		  {
			  m_List2.GetText (i, str);
			  if(str=="ԤԼ�տ�" || str=="ԤԼ����")
			      m_List2.SetSel(i, 0);
		  }
		}
		if(bAll2)
		{
		  for(int i=3; i<m_List2.GetCount(); i++)
		  {
			  m_List2.GetText (i, str);
			  if(str!="ԤԼ�տ�" && str!="ԤԼ����")
			      m_List2.SetSel(i, 0);
		  }
		}
	}


 	int count= m_List2.GetSelCount() ;
	if(count==0)
	{
		m_List2.SetSel(0);
		OnSelchangeList5();
		return;
	}
	int *pIndex=new int[count];
	m_List2.GetSelItems(count, pIndex);

	for(int i=0; i<count; i++)
	{
		m_List2.GetText (pIndex[i], str);
		m_pfilterarray2->Add (str);
	}
	delete []pIndex;
m_pfilterarray->RemoveAll();
	((DinDanForm*)m_parent)->KindChange();	
}

void DinDanForm2::ModeChange(int mode)
{
	if(mode==0||mode==1||mode==8)
	{
		ShowWindow(SW_SHOW);
		m_List2.ShowWindow(SW_HIDE);
	    m_List1.MoveWindow(m_rc);
	}
	else if(mode==7)
	{
	CRect rc=m_rc;
	int hei=rc.Height()/2;
	rc.bottom-=hei;
	m_List1.MoveWindow(rc);

	rc.top=rc.bottom;
	rc.bottom+=hei;
	m_List2.MoveWindow(rc);

		ShowWindow(SW_SHOW);
		m_List2.ShowWindow(SW_SHOW);
	}
	else
		ShowWindow(SW_HIDE);
}