// ChooseDesignSkin.cpp : implementation file
//

#include "stdafx.h"
#include "ChooseDesignSkin.h"
#include "YLGL.h"
#include "./helper/ffsco.h"
#include ".\MenuBarXP\MenuXP.h"
#include "ChoosePhotoSkin3.h"
#include "ShowPic22.h"
#include "ClientRequirement.h"
#include "MyLock.h"
#include "ComparePhoto.h"
#include "ReplaceDesignNo.h"
#include "Login2.h"
#include "TimeOutDlg.h"
#include "ShowEffect.h"
#include "SelBrunDevice.h"
#include "ProductChooseFilter.h"
#include "NewFolderDlg.h"
#include "NetShareInfo.h"
#include "ShowMsg3.h"
using namespace helper_coffs;

#ifdef _DEBUG
//#define new DEBUG_NEW				(�������newʱ��������������)
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


using namespace helper_coffs;


extern int GetOrientation(Image *image);
extern HCURSOR g_cursorhand;
/////////////////////////////////////////////////////////////////////////////
// ChooseDesignSkin message handlers
extern void SizeToContent(HWND hwnd, Image *img);

//mode
//0 ȫ��
//1 ѡ��
//2 δѡ
//3 ɾ��
//4 ���
//5 ���
/////////////////////////////////////////////////////////////////////////////

// ChooseDesignSkin dialog IDC_EDITzs
ChooseDesignSkin::ChooseDesignSkin(CWnd* pParent /*=NULL*/)	: ChoosePhotoBase(ChooseDesignSkin::IDD, pParent)
{
	m_time4 = g_date;
	g_pMainWnd->GetSkin();
	m_bChooseBig = 0;
	m_Runingmode = 1;
}

ChooseDesignSkin::ChooseDesignSkin(DWORD id, CWnd* pParent)	: ChoosePhotoBase(id, pParent)
{
	m_time4 = g_date;
	g_pMainWnd->GetSkin();
	m_bChooseBig = 0;
	m_Runingmode = 1;
}

void ChooseDesignSkin::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(ChooseDesignSkin)
	DDX_Control(pDX, IDC_COMBO1, m_combo1);
	DDX_Control(pDX, IDC_LIST3, m_List3);
	DDX_Control(pDX, IDC_LIST2, m_List2);
	DDX_Control(pDX, IDC_LIST1, m_List1);
	DDX_Text(pDX, IDC_EDITname1, m_name1);
	DDX_Text(pDX, IDC_EDITname2, m_name2);
	DDX_Text(pDX, IDC_EDITtime4, m_time4);
	DDX_Text(pDX, IDC_EDITwaiter3, m_waiter3);
	DDX_Text(pDX, IDC_EDITzs, m_takezs);
	DDX_Text(pDX, IDC_EDITzs2, m_taoxizs);
	DDX_Text(pDX, IDC_EDITzs3, m_choosezs);
	DDX_Text(pDX, IDC_EDITmoney3, m_money3);
	DDX_Text(pDX, IDC_EDITid, m_strOrderNumber);
	DDX_Text(pDX, IDC_EDITbz3, m_bz3);
	//}}AFX_DATA_MAP}
}

BEGIN_MESSAGE_MAP(ChooseDesignSkin, CDialog)
	//{{AFX_MSG_MAP(ChooseDesignSkin)
	ON_WM_PAINT()
	ON_WM_DESTROY()
	ON_WM_ERASEBKGND()
	ON_NOTIFY(NM_DBLCLK, IDC_LIST1, OnDblclkList1)
	ON_WM_CLOSE()
	ON_NOTIFY(NM_RCLICK, IDC_LIST1, OnRclickList1)
	ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
	ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
	ON_MESSAGE(WM_USER + 1101, OnBtnClick)
	ON_COMMAND_RANGE(IDM_MENUsp1 - 1, IDM_MENUsp1 + 200, OnCommandMenu)
	ON_MESSAGE(WM_USER + 200, UpdateTakeZS)
	
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// ChooseDesignSkin message handlers
BOOL ChooseDesignSkin::OnInitDialog() //��ʼ��ѡƬ*�����
{
	ChoosePhotoBase::OnInitDialog();

	//������Ƭ���ļ���icon
	LoadImageFromRes(&m_pHideImg, MAKEINTRESOURCE(IDR_JPG5), _T("JPG"));
	if(m_pHideImg == NULL)
	{
		MessageBox(_T("����ͼ��ʧ��"));
		return FALSE;
	}

	// 1.����liaƤ����Ϣ;
	g_bInSkin = 1;
	m_ticks = ::GetTickCount();
	if (g_cursorhand == NULL)
		g_cursorhand = AfxGetApp()->LoadCursor(IDC_CURSORHAND);
	BYTE *pData = NULL;
	BYTE *pDataBegin;

	//printf("Jeff:loadLia·��:%s\n\n",g_mainpath+"\\skin\\"+m_liapath);//Jeff Printf;
	if (!LoadLia(g_mainpath + _T("\\skin\\") + m_liapath, &pData, &pDataBegin, &m_pBk, m_hWnd))
	{
		EndDialog(0);
		return false;
	}

	//��ʼ����ť��λ��
	//printf("Jeff:g_resdata2.nPicCount=%d\n\n",g_resdata2.nPicCount); // Jeff Printf,���nPicCount����һֱ��15;
	for (int i = 0; i < g_resdata2.nPicCount; i++)
	{
		g_resdata2.rect[i].left *= g_fscalex;
		g_resdata2.rect[i].right *= g_fscalex;
		g_resdata2.rect[i].top *= g_fscaley;
		g_resdata2.rect[i].bottom *= g_fscaley;

		if (i == 8)
			g_resdata2.rect[i] = g_resdata2.rect[2];
		else if (i == 9)
			g_resdata2.rect[i] = g_resdata2.rect[3];
		else if (i == 10)
			g_resdata2.rect[i] = g_resdata2.rect[1];
		if (g_resdata2.nPicBmpCount[i])
		{
			MyBmpButton2 *pic = new MyBmpButton2;
			m_picarray.Add((DWORD)pic);
			CRect rc = g_resdata2.rect[i];
			CString str;
			str.Format(_T("%d"), i + 1);
			pic->Create(str, WS_CHILD | WS_VISIBLE | BS_OWNERDRAW, rc, this, i + 100);
			pic->m_bmpcount = g_resdata2.nPicBmpCount[i];
			pic->ReadBmp(&pData, NULL, this);

#ifdef SZWNS_VERSION//����ά��˹
			if(i==3 && m_mode2==0)
			{
				Image *img=NULL;
				LoadImageFromRes(&img, MAKEINTRESOURCE(IDR_JPG6), _T("JPG"));
				delete pic->m_bmp;
				pic->m_bmp=img->Clone();
				delete img;

				img=NULL;
				LoadImageFromRes(&img, MAKEINTRESOURCE(IDR_JPG7), _T("JPG"));
				delete pic->m_bmpfocus;
				pic->m_bmpfocus=img->Clone();
				delete img;

				img=NULL;
				LoadImageFromRes(&img, MAKEINTRESOURCE(IDR_JPG8), _T("JPG"));
				delete pic->m_bmpfocused;
				pic->m_bmpfocused=img->Clone();
				delete img;
			}
#endif//SZWNS_VERSION

		}
		else
			m_picarray.Add(NULL);
		m_rcarray.Add(g_resdata2.rect[i]);
	}
	delete[]pDataBegin;


	//��ʼ����ťλ��
	{
		//�����
		m_bHide = 0;
		//		printf("Jeff:g_cominfoarray.ElementAt(0).ElementAt(86)=%s\n\n",g_cominfoarray.ElementAt(0).ElementAt(86)); // Jeff Printf;
		if (atoi(g_cominfoarray.ElementAt(0).ElementAt(86)))
		{
			((MyBmpButton2*)m_picarray.ElementAt(3))->ShowWindow(SW_HIDE);
			CRect rc, rc2;
			((MyBmpButton2*)m_picarray.ElementAt(3))->GetWindowRect(rc);
			((MyBmpButton2*)m_picarray.ElementAt(1))->GetWindowRect(rc2);
			int dtx = rc.right - rc2.right;
			ScreenToClient(rc2);
			rc2.left += dtx;
			rc2.right += dtx;
			((MyBmpButton2*)m_picarray.ElementAt(1))->MoveWindow(rc2);
			((MyBmpButton2*)m_picarray.ElementAt(0))->GetWindowRect(rc2);
			ScreenToClient(rc2);
			rc2.left += dtx;
			rc2.right += dtx;
			((MyBmpButton2*)m_picarray.ElementAt(0))->MoveWindow(rc2);
		}

		CRect rc, rc2;
		((MyBmpButton2*)m_picarray.ElementAt(5))->GetWindowRect(rc);
		((MyBmpButton2*)m_picarray.ElementAt(4))->GetWindowRect(rc2);
		int dtx = rc.right - rc2.right;
		rc2 = rc;
		//	if(atoi(g_cominfoarray.ElementAt(0).ElementAt(86))==0)
		{
			float scale = 0.9;
			dtx *= scale;
			int wid = rc2.Width()*scale;
			int hei = rc2.Height()*scale;
			int dty = rc2.Height() - hei;
			dty /= 2;
			rc2.left = rc2.right - wid;
			rc2.top += dty;
			rc2.bottom = rc2.top + hei;
		}

		ScreenToClient(rc2);
		((MyBmpButton2*)m_picarray.ElementAt(5))->MoveWindow(rc2);
		rc2.left -= dtx;
		rc2.right -= dtx;
		((MyBmpButton2*)m_picarray.ElementAt(4))->MoveWindow(rc2);
		rc2.left -= dtx;
		rc2.right -= dtx;
		((MyBmpButton2*)m_picarray.ElementAt(14))->MoveWindow(rc2);

		rc2.left -= dtx;
		rc2.right -= dtx;
		((MyBmpButton2*)m_picarray.ElementAt(2))->MoveWindow(rc2);
		if (atoi(g_cominfoarray.ElementAt(0).ElementAt(86)) == 0)
		{
			rc2.left -= dtx;
			rc2.right -= dtx;
			((MyBmpButton2*)m_picarray.ElementAt(3))->MoveWindow(rc2);
		}

		rc2.left -= dtx;
		rc2.right -= dtx;
		((MyBmpButton2*)m_picarray.ElementAt(1))->MoveWindow(rc2);
		rc2.left -= dtx;
		rc2.right -= dtx;
		((MyBmpButton2*)m_picarray.ElementAt(0))->MoveWindow(rc2);

		rc2.left -= dtx;
		rc2.right -= dtx;
		((MyBmpButton2*)m_picarray.ElementAt(8))->MoveWindow(rc2);

		((MyBmpButton2*)m_picarray.ElementAt(11))->ShowWindow(SW_HIDE);
	}

	if (1)//m_mode2==0)
	{
		((MyBmpButton2*)m_picarray.ElementAt(7))->ShowWindow(SW_HIDE);
		((MyBmpButton2*)m_picarray.ElementAt(8))->ShowWindow(SW_HIDE);
		((MyBmpButton2*)m_picarray.ElementAt(9))->ShowWindow(SW_HIDE);
		((MyBmpButton2*)m_picarray.ElementAt(10))->ShowWindow(SW_HIDE);
		((MyBmpButton2*)m_picarray.ElementAt(11))->ShowWindow(SW_HIDE);
	}
	else
	{
		((MyBmpButton2*)m_picarray.ElementAt(7))->EnableWindow(0);
		((MyBmpButton2*)m_picarray.ElementAt(0))->ShowWindow(SW_HIDE);
		((MyBmpButton2*)m_picarray.ElementAt(1))->ShowWindow(SW_HIDE);
		((MyBmpButton2*)m_picarray.ElementAt(2))->ShowWindow(SW_HIDE);
		((MyBmpButton2*)m_picarray.ElementAt(3))->ShowWindow(SW_HIDE);
		((MyBmpButton2*)m_picarray.ElementAt(11))->ShowWindow(SW_HIDE);

		if (IsHasRights2new(37) == 0)
		{
			((MyBmpButton2*)m_picarray.ElementAt(8))->ShowWindow(SW_HIDE);
			((MyBmpButton2*)m_picarray.ElementAt(9))->ShowWindow(SW_HIDE);
		}
	}

	((MyBmpButton2*)m_picarray.ElementAt(8))->ShowWindow(SW_SHOW);
	//	((MyBmpButton2*)m_picarray.ElementAt (8))->SetPushDown (1);
	((MyBmpButton2*)m_picarray.ElementAt(12))->ShowWindow(SW_HIDE);
	((MyBmpButton2*)m_picarray.ElementAt(13))->ShowWindow(SW_HIDE);

#ifndef MNLS_VERSION//mnls
	((MyBmpButton2*)m_picarray.ElementAt(7))->ShowWindow(SW_HIDE);
	((MyBmpButton2*)m_picarray.ElementAt(7))->EnableWindow(0);
	Graphics graph(m_pBk);

	Image *img = NULL;
	::LoadImageFromBuf(&img, g_mainpath + _T("\\ͼƬ\\����-�����.jpg"));
	if (img)
	{
		if (img->GetWidth() == 2000)
		{
			graph.SetSmoothingMode(SmoothingModeHighQuality);
			graph.DrawImage(img, 0, 0);
		}
		delete img;
	}
#endif//MNLS_VERSION

	//��ʼ���б�λ��
	CRect listrc = m_rcarray.ElementAt(6);
	CRect rc;
	GetClientRect(rc);
	rc.top = listrc.top;
	m_List1.MoveWindow(rc);

	//����ͼ���б��ؼ�
	m_ImageListThumb.Create(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, ILC_COLOR24, 0, 1);
	m_List1.SetImageList(&m_ImageListThumb, LVSIL_NORMAL);

	m_List2.InitStyle();
	m_List2.InsertColumn(0, _T("���"), LVCFMT_LEFT, 45);
	m_List2.InsertColumn(1, _T("��Ʒ����"), LVCFMT_LEFT, 150);
	m_List2.InsertColumn(2, _T("����"), LVCFMT_LEFT, 45);

	m_List3.InitStyle();
	m_List3.InsertColumn(0, _T("autoid"), LVCFMT_LEFT, 0);
	m_List3.InsertColumn(1, _T("���"), LVCFMT_LEFT, 45);
	m_List3.InsertColumn(2, _T("��Ʒ����"), LVCFMT_LEFT, 150);
	m_List3.InsertColumn(3, _T("�۸�"), LVCFMT_LEFT, 45);
	m_List3.InsertColumn(4, _T("����"), LVCFMT_LEFT, 45);
#ifdef LKAY_VERSION
	m_List3.InsertColumn(5,_T("P��"),LVCFMT_LEFT,55);
	m_List3.InsertColumn(6,_T("����"),LVCFMT_LEFT,55);
	m_List3.InsertColumn(7,_T("��Ƭ���"),LVCFMT_LEFT,365);
#else
	m_List3.InsertColumn(5, _T("��Ƭ���"), LVCFMT_LEFT, 365);
	// 2015.11.13 �����б����Ӷ�һ����Ʒ��עѡ��;
	m_List3.InsertColumn(6, _T("��ע"), LVCFMT_LEFT, 300);
#endif//LKAY_VERSION

	CString path, str;
	m_path = g_path3 + _T("\\");
	m_path += m_strOrderNumber;
	m_path += _T("\\");
	GetPhotos();

	{
		//ѡ���ģʽ
		GetData();
		if (m_checkstatus != _T("�"))
		{
			if (atoi(g_cominfoarray.ElementAt(0).ElementAt(85)) && IsHasRights2new(20) == 0)
			{
				Login2 dlg;
				if (dlg.DoModal() != IDOK)
				{
					MyBmpButton2 *btn = ((MyBmpButton2*)m_picarray.ElementAt(4));
					btn->m_bmpdisable = btn->m_bmp->Clone();

					Graphics graph(btn->m_bmpdisable);
					CPoint pt1, pt2, pt3;
					pt1.x = 0;
					pt1.y = 0;
					pt2.x = btn->m_bmp->GetWidth();
					pt2.y = 0;
					pt3.x = 0;
					pt3.y = btn->m_bmp->GetHeight();
					Point destinationPoints[] = {
						Point(pt1.x, pt1.y),   // destination for upper-left point of original
						Point(pt2.x, pt2.y),  // destination for upper-right point of original
						Point(pt3.x, pt3.y) };  // destination for lower-left point of original
						ColorMatrix colorMatrix = \
						{0.33f, 0.33f, 0.33f, 0.0f, 0.0f,
						0.33f, 0.33f, 0.33f, 0.0f, 0.0f,
						0.33f, 0.33f, 0.33f, 0.0f, 0.0f,
						0.0f, 0.0f, 0.0f, 1.0f, 0.0f,
						0.0f, 0.0f, 0.0f, 0.0f, 1.0f};

					ImageAttributes imageAtt;
					imageAtt.SetColorMatrix(&colorMatrix, ColorMatrixFlagsDefault, ColorAdjustTypeBitmap);
					graph.DrawImage(btn->m_bmp,
						destinationPoints,
						3,
						0,
						0,
						btn->m_bmp->GetWidth(),
						btn->m_bmp->GetHeight(),
						UnitPixel,
						&imageAtt);
					btn->EnableWindow(0);
					m_bCanSave = 0;
					//		CDialog::OnCancel ();
					//		return 1;
				}
				else if (IsHasRightsnew2(20, dlg.m_rights) == 0)
				{
					MyBmpButton2 *btn = ((MyBmpButton2*)m_picarray.ElementAt(4));
					btn->m_bmpdisable = btn->m_bmp->Clone();

					Graphics graph(btn->m_bmpdisable);
					CPoint pt1, pt2, pt3;
					pt1.x = 0;
					pt1.y = 0;
					pt2.x = btn->m_bmp->GetWidth();
					pt2.y = 0;
					pt3.x = 0;
					pt3.y = btn->m_bmp->GetHeight();
					Point destinationPoints[] = {
						Point(pt1.x, pt1.y),   // destination for upper-left point of original
						Point(pt2.x, pt2.y),  // destination for upper-right point of original
						Point(pt3.x, pt3.y) };  // destination for lower-left point of original
						ColorMatrix colorMatrix = \
						{0.33f, 0.33f, 0.33f, 0.0f, 0.0f,
						0.33f, 0.33f, 0.33f, 0.0f, 0.0f,
						0.33f, 0.33f, 0.33f, 0.0f, 0.0f,
						0.0f, 0.0f, 0.0f, 1.0f, 0.0f,
						0.0f, 0.0f, 0.0f, 0.0f, 1.0f};

					ImageAttributes imageAtt;
					imageAtt.SetColorMatrix(&colorMatrix, ColorMatrixFlagsDefault, ColorAdjustTypeBitmap);
					graph.DrawImage(btn->m_bmp,
						destinationPoints,
						3,
						0,
						0,
						btn->m_bmp->GetWidth(),
						btn->m_bmp->GetHeight(),
						UnitPixel,
						&imageAtt);
					btn->EnableWindow(0); m_bCanSave = 0;
					//	CDialog::OnCancel ();
					//	return 1;
				}
			}
		}

		//��¼��ɾ������Ƭ
		RecordDeletedPhotos(&m_delphotos, m_DelPhotoPath);
	}

	//�ڽ�������ʾͼƬ;
	LoadPhotos();

	if (atoi(g_cominfoarray.ElementAt(0).ElementAt(95)) || g_cominfoarray.ElementAt(0).ElementAt(95) == _T(""))
	{
		int timer1 = atoi(g_cominfoarray.ElementAt(0).ElementAt(96));
		m_timer = atoi(g_cominfoarray.ElementAt(0).ElementAt(97));
		if (timer1 == 0)
			timer1 = 60;

		if (m_timer == 0)
			m_timer = 20;

		SetTimer(1, timer1 * 60000, NULL);
	}
	return false;  
}

void ChooseDesignSkin::OnPaint()
{
	try
	{
		CPaintDC dc(this); // device context for painting
		// TODO: Add your message handler code here
		if (m_pBk == NULL)
		{
			return;
		}
		CRect rc;
		GetClientRect(rc);
		Graphics graph(dc.GetSafeHdc());
		Rect destinationRect(0, 0, rc.Width(), rc.Height());
		int width = m_pBk->GetWidth();
		int height = m_pBk->GetHeight();
		graph.SetSmoothingMode(SmoothingModeHighQuality);
		graph.DrawImage(m_pBk, destinationRect, 0, 0, width, height, UnitPixel);
		// Do not call CDialog::OnPaint() for painting messages
	}
	catch (...)
	{
	}
}

void ChooseDesignSkin::OnDestroy()
{
	try
	{
		TerminateThread();
		if (m_pBk)delete m_pBk;
		MyBmpButton2 *pic = NULL;
		for (int i = 0; i < m_picarray.GetSize(); i++)
		{
			pic = (MyBmpButton2*)m_picarray.ElementAt(i);
			if (pic)
			{
				pic->DestroyWindow();
				delete pic;
			}
		}
		m_picarray.RemoveAll();
		if (m_selphotownd.GetSafeHwnd())
		{
			m_selphotownd.DestroyWindow();
		}
		if (m_selphotownd2.GetSafeHwnd())
		{
			m_selphotownd2.DestroyWindow();
		}

		//�����Դ��·��
		ClearResData();
		
		if(m_pHideImg)
			delete m_pHideImg;
		
		CDialog::OnDestroy();
	}
	catch (...)
	{
	}
}

#ifdef VC60
void ChooseDesignSkin::OnBtnClick(WPARAM wParam, LPARAM lParam) 
{
	// WM_USER + 1101
	// F5��������ʾɾ����Ƭ
	int id = lParam;
	id -= 99;
	switch (id)
	{
	case 1:		// �鿴ȫ����Ƭ��ť�¼�;
	case 2:		// �鿴ѡ�е���Ƭ��ť�¼�;
	case 4:		// F5�鿴ɾ������Ƭ;
		{
			if (m_SelectCategory == id - 1 && m_SelectCategory != 1)
				return;

			m_SelectCategory = id - 1;
			if(INDX_SEL == m_SelectCategory)
				OnSelPhoto();
			LoadPhotos();
		}
		break;
	case 3://�鿴δѡ��ť�¼�;
		{
			m_SelectCategory = INDX_NOSEL;
			m_sChooseFilter = _T("");
			UpdateChooseZS();
			GetNoSelPhoto();
			LoadPhotos();
		}
		break;
	case 13:	// �鿴�����Ƭ��ť�¼�;
		GetAlbumPhoto();
		LoadPhotos();
		break;
	case 14:	// �鿴�����Ƭ��ť�¼�;
		GetDiskPhoto();
		LoadPhotos();
		break;
	case 15:		// Ч��ͼ��ť�¼�;
		{
			ShowEffectDlg dlg;
			dlg.m_pPhotopatharray = this->GetCurArray(m_SelectCategory);
			dlg.DoModal();
		}
		break;
	case 5:		// ���水ť�¼�;
		OnButton4();
		break;
	case 9:		//�����->�Ŵ�ť
		{
			if (((MyBmpButton2*)m_picarray.ElementAt(8))->GetPushDown())
				((MyBmpButton2*)m_picarray.ElementAt(8))->SetPushDown(0);
			else
				((MyBmpButton2*)m_picarray.ElementAt(8))->SetPushDown(1);

			ReLoadPhoto();
		}
		break;
	case 6:		// �رհ�ť�¼� ;
		if (m_bModify && m_bCanSave)
		{
			ShowMsg3 dlg;
			dlg.m_strMsg = _T("����, ѡƬ�޸�δ����, �Ƿ񱣴�����˳�?");
		//	if (AfxMessageBox(_T("����, ѡƬ�޸�δ����, �Ƿ񱣴�����˳�?"), MB_YESNO | MB_ICONINFORMATION) == IDYES)
			if(dlg.DoModal() == IDOK)
			{
				OnButton4();
				if (m_bSaveFail)
				{
					AfxMessageBox(_T("���ӷ�����ʧ��, ����ʧ��, �������ڱ��������½���ѡƬ�ָ���ѡ��״̬!"));
					CDialog::OnCancel(); 
					return;
				}
				return;
			}
			else
			{
				CString savepath = _T("");
				savepath.Format(_T("%s\\%s-2.dat"), g_mainpath, m_strOrderNumber);
				::DeleteFile(savepath);		// ɾ��*.dat�ļ�; 
			}

		}
		CDialog::OnCancel();
		break;
	case 11:
		if (m_selphotownd.GetSafeHwnd() == NULL)
		{
			m_selphotownd.m_id = m_strOrderNumber;
			m_selphotownd.m_rc = m_rcarray.ElementAt(6);
			m_selphotownd.Create(IDD_DLGShowSelPhoto, this);
		}
		m_selphotownd.ShowWindow(1);
		break;
	case 12:
		ReplaceDesignNo dlg;
		dlg.m_id = this->m_strOrderNumber;
		dlg.DoModal();
		break;
	}
}
#else
LRESULT ChooseDesignSkin::OnBtnClick(WPARAM wParam, LPARAM lParam) 
{
	// WM_USER + 1101
	// F5��������ʾɾ����Ƭ
	int id = lParam;
	id -= 99;
	switch (id)
	{
	case 1:		// �鿴ȫ����Ƭ��ť�¼�;
	case 2:		// �鿴ѡ�е���Ƭ��ť�¼�;
	case 4:		// F5�鿴ɾ������Ƭ;
		{
			if (m_SelectCategory == id - 1 && m_SelectCategory != 1)
				return 0;

			m_SelectCategory = id - 1;
			if(INDX_SEL == m_SelectCategory)
				OnSelPhoto();
			LoadPhotos();
		}
		break;
	case 3://�鿴δѡ��ť�¼�;
		{
			m_SelectCategory = INDX_NOSEL;
			m_sChooseFilter = _T("");
			UpdateChooseZS();
			GetNoSelPhoto();
			LoadPhotos();
		}
		break;
	case 13:	// �鿴�����Ƭ��ť�¼�;
		GetAlbumPhoto();
		LoadPhotos();
		break;
	case 14:	// �鿴�����Ƭ��ť�¼�;
		GetDiskPhoto();
		LoadPhotos();
		break;
	case 15:		// Ч��ͼ��ť�¼�;
		{
			ShowEffectDlg dlg;
			dlg.m_pPhotopatharray = this->GetCurArray(m_SelectCategory);
			dlg.DoModal();
		}
		break;
	case 5:		// ���水ť�¼�;
		OnButton4();
		break;
	case 9:		//�����->�Ŵ�ť
		{
			if (((MyBmpButton2*)m_picarray.ElementAt(8))->GetPushDown())
				((MyBmpButton2*)m_picarray.ElementAt(8))->SetPushDown(0);
			else
				((MyBmpButton2*)m_picarray.ElementAt(8))->SetPushDown(1);

			ReLoadPhoto();
		}
		break;
	case 6:		// �رհ�ť�¼� ;
		if (m_bModify && m_bCanSave)
		{
			ShowMsg3 dlg;
			dlg.m_strMsg = _T("����, ѡƬ�޸�δ����, �Ƿ񱣴�����˳�?");
		//	if (AfxMessageBox(_T("����, ѡƬ�޸�δ����, �Ƿ񱣴�����˳�?"), MB_YESNO | MB_ICONINFORMATION) == IDYES)
			if(dlg.DoModal() == IDOK)
			{
				OnButton4();
				if (m_bSaveFail)
				{
					AfxMessageBox(_T("���ӷ�����ʧ��, ����ʧ��, �������ڱ��������½���ѡƬ�ָ���ѡ��״̬!"));
					CDialog::OnCancel(); 
					return 0;
				}
				return 0;
			}
			else
			{
				CString savepath = _T("");
				savepath.Format(_T("%s\\%s-2.dat"), g_mainpath, m_strOrderNumber);
				::DeleteFile(savepath);		// ɾ��*.dat�ļ�; 
			}

		}
		CDialog::OnCancel();
		break;
	case 11:
		if (m_selphotownd.GetSafeHwnd() == NULL)
		{
			m_selphotownd.m_id = m_strOrderNumber;
			m_selphotownd.m_rc = m_rcarray.ElementAt(6);
			m_selphotownd.Create(IDD_DLGShowSelPhoto, this);
		}
		m_selphotownd.ShowWindow(1);
		break;
	case 12:
		ReplaceDesignNo dlg;
		dlg.m_id = this->m_strOrderNumber;
		dlg.DoModal();
		break;
	}

	return 0;
}
#endif

BOOL ChooseDesignSkin::OnEraseBkgnd(CDC* pDC)
{
	return 1;
}


BEGIN_EVENTSINK_MAP(ChooseDesignSkin, CDialog)
	ON_EVENT(ChooseDesignSkin, 100, 150 /* FSCommand */, OnFSCommandShockwaveflash1, VTS_BSTR VTS_BSTR)
END_EVENTSINK_MAP()

void ChooseDesignSkin::OnFSCommandShockwaveflash1(LPCTSTR command, LPCTSTR args)
{
}

//------------------------------------------------------------------
// ������OnDblclkList1
// ����������˫���ͻس�ʱ��ͼƬ��ʾЧ��;�뺯���������ı������岻һ�£��������壡
// ������
// ���أ�
//------------------------------------------------------------------
void ChooseDesignSkin::OnDblclkList1()
{
	// 1.��˫���е��б����л�ȡ��Ƭ��;
	POSITION pos;
	pos = m_List1.GetFirstSelectedItemPosition();
	if (pos == NULL)
		return;

	int iItem = m_List1.GetNextSelectedItem(pos);

#if JEFF_TEST_OFF
	// ˫���б������Ͳ���������ѡ���,˫��ֻ��ѡ��һ������GetNextSelectedItem(pos)��pos=NULL
	// ����������������ò����Ǹ�������һ�£��������ط��õ���
#else	// ��һ����������ڴ����س���;

	CArray<int, int>posarray;
	posarray.Add(iItem);
	// ��ȡʣ�µ�ͼƬλ��;
	while (pos)
	{
		int iItem = m_List1.GetNextSelectedItem(pos);
		posarray.Add(iItem);
		if (posarray.GetSize() > 3)
			break;
	}

	if (posarray.GetSize() >= 2)
	{
		CStringArray* pPtahArray = NULL;
		pPtahArray = GetCurArray(m_SelectCategory);
		
		CComparePhoto dlg;
		dlg.m_path1 = pPtahArray->ElementAt(posarray.ElementAt(0));
		dlg.m_path2 = pPtahArray->ElementAt(posarray.ElementAt(1));

		if (posarray.GetSize() > 2)
			dlg.m_path3 = pPtahArray->ElementAt(posarray.ElementAt(2));
		if (posarray.GetSize() > 3)
			dlg.m_path4 = pPtahArray->ElementAt(posarray.ElementAt(3));
		dlg.DoModal();
		return;
	}
#endif //JEFF_TEST_OFF

	CString title = m_List1.GetItemText(iItem, 0);
	if (title.Find("Flash") != -1)
	{
		title.Replace("Flash", "delgabook");
		CString str = m_path + title + "\\delgaBook.exe";
		ShellExecute(NULL, _T("open"), str, NULL, NULL, SW_SHOWNORMAL);
		return;
	}

	m_showpichwd = NULL;

	// ˫��Сͼ�鿴��ͼ;
	ShowPic22 dlg;
	dlg.m_bShowImgInfo = 1;
	dlg.m_pParent = this;
	dlg.m_nCurImgPos = iItem;

	CStringArray* pArray = GetCurArray(m_SelectCategory);
	if(pArray == NULL)
		return;

	dlg.m_AryOfImgPath = pArray;
	dlg.DoModal();
	m_showpichwd = NULL;
}

void ChooseDesignSkin::OnDblclkList1(NMHDR* pNMHDR, LRESULT* pResult)	// ˫��ͼƬ�б���
{
	OnDblclkList1();
	*pResult = 0;
}

/************************************************************************/
/*	
	����: GetData
	����: ѡƬģʽ
	����: 
	����: 
	ע��: 
*/
/************************************************************************/
BOOL ChooseDesignSkin::GetData()//ѡƬģʽ;
{
	m_List2.DeleteAllItems();
	m_List3.DeleteAllItems();
	m_noarray.RemoveAll();
	m_no2array.RemoveAll();
	m_oldsparray.RemoveAll();

	//ѡ���
	CString filter = _T("");
#ifdef CHILD_VERSION
	filter = "id='" + m_strOrderNumber + "';id='" + m_strOrderNumber + "';;;id='" + m_strOrderNumber + "'";
#else
	filter = "id='" + m_strOrderNumber + "' and kind<>'2';id='" + m_strOrderNumber + "';;;id='" + m_strOrderNumber + "'";
#endif //CHILD_VERSION

	//�����š���Ʒ��š���Ʒ�۸񡢶�����Ʒ��������Ʒ���͡���Ʒ���ơ�ѡƬѡ����Ƭ��������id��ѡ���ѡ����Ƭ��;
	g_sendhead.code[0] = 50;	// dindansp;
	g_sendhead.code[1] = 11;	// dindan
	g_sendhead.code[2] = 4;		// shangpin
	g_sendhead.code[3] = 8;			// shangpin	
	g_sendhead.code[4] = 182;		// dindansp3	
	g_sendhead.tabcount = 5;
	g_sendhead.bsql = 0;

	g_pMainWnd->ProcessChatMessageRequest2(filter); 
	if (g_bSendOK == 0)
		return 0;

	CArray<CStringArray, CStringArray> sparray; //dindansp��;//�����š���Ʒ��š���Ʒ�۸񡢶�����Ʒ��������Ʒ���͡���Ʒ���ơ�ѡƬѡ����Ƭ��������id��ѡ���ѡ����Ƭ��;
	DataToArray(&sparray, &g_List1array, &m_sparray, &m_List2array, &m_oldsparray);

	m_SelPhotoPath.RemoveAll();

	CString str(_T("")), kind(_T(""));
	int nchoosezs = 0;
	int list2pos = 0;
	int list3pos = 0;

	CString savepath = _T("");
	savepath.Format(_T("%s\\%s-2.dat"), g_mainpath, m_strOrderNumber);
	CString stm1 = GetModifyTime2(savepath);
	CTime tm1 = CTime::GetCurrentTime();
	tm1 -= CTimeSpan(60, 0, 0, 0);
		
	CString stm2 = tm1.Format(_T("%Y%m%d"));
	BOOL bLoadHistory = 0;
	if (PathFileExists(savepath) && stm1 > stm2)
	{
		if (AfxMessageBox(_T("���ѣ����������\r\n�ϴ�ѡƬδ�����˳�, �Ƿ�ԭ���ϴ�ѡƬ״̬?"), MB_YESNO | MB_ICONINFORMATION) == IDYES)
			bLoadHistory = 1;
	}

	int i = 0;
	if (bLoadHistory)
	{
		//��ԭ���ϴ�ѡƬ״̬
		CArray<CStringArray, CStringArray> List1array;

		//��ȡ����
		CFile fp;
		fp.Open(savepath, CFile::modeRead);
		DWORD nMessageLen = fp.GetLength();
		BYTE *szChatMessage = new BYTE[nMessageLen];
		fp.Read(szChatMessage, nMessageLen);
		fp.Close();

		int count = 0;
		memcpy(&count, szChatMessage + (nMessageLen - sizeof(int)), sizeof(int));
		CMemFile memfile;
		memfile.Attach(szChatMessage, nMessageLen);
		CArchive ar(&memfile, CArchive::load);
		List1array.SetSize(count);
		for ( i = 0; i < List1array.GetSize(); i++)
			List1array.ElementAt(i).Serialize(ar);

		ar.Close();
		memfile.Detach();
		delete[]szChatMessage;

		list2pos = 0;
		list3pos = 0;
		for (i = 0; i < List1array.GetSize(); i++)
		{
			if (0)//List1array.ElementAt (i).GetSize ()==6)
			{
				kind = "0";
				m_List2.InsertItem(list2pos, List1array.ElementAt(i).ElementAt(1));
				m_List2.SetItemText(list2pos, 1, List1array.ElementAt(i).ElementAt(2));
				m_List2.SetItemText(list2pos, 2, List1array.ElementAt(i).ElementAt(3));
				m_List2.SetItemText(list2pos, 3, List1array.ElementAt(i).ElementAt(4));
				m_List2.SetItemText(list2pos, 4, List1array.ElementAt(i).ElementAt(5));
				str = List1array.ElementAt(i).ElementAt(5);
				list2pos++;
			}
			else
			{
				kind = "4";
				m_List3.InsertItem(list3pos, List1array.ElementAt(i).ElementAt(1));
				m_List3.SetItemText(list3pos, 1, List1array.ElementAt(i).ElementAt(2));
				m_List3.SetItemText(list3pos, 2, List1array.ElementAt(i).ElementAt(3));
				m_List3.SetItemText(list3pos, 3, List1array.ElementAt(i).ElementAt(4));
				m_List3.SetItemText(list3pos, 4, List1array.ElementAt(i).ElementAt(5));
				m_List3.SetItemText(list3pos, 5, List1array.ElementAt(i).ElementAt(6));
				m_List3.SetItemText(list3pos, 6, List1array.ElementAt(i).ElementAt(9));
#ifdef LKAY_VERSION
				m_List3.SetItemText(list3pos, 6, List1array.ElementAt (i).ElementAt (7));
				m_List3.SetItemText(list3pos, 7, List1array.ElementAt (i).ElementAt (8));
				str=List1array.ElementAt (i).ElementAt (8);
#else
				str = List1array.ElementAt(i).ElementAt(6);
#endif //#ifdef LKAY_VERSION
				list3pos++;
			}

			nchoosezs += GetZS(str);
			GetPathAddToSel(str);

			if (!str.IsEmpty())
			{
#ifdef USE_SEP_VEB
				str = SEPS_VEB + str + SEPS_VEB;
#else
				str = SEPS_CMA + str + SEPS_CMA;
#endif //#ifdef USE_SEP_VEB
			}
			str.MakeLower();
			if (kind == _T("4"))
				m_no2array.Add(str);
			else
				m_noarray.Add(str);
		}
	}
	else
	{
		for ( i = 0; i < sparray.GetSize(); i++)
		{
			kind = _T("4");//sparray.ElementAt (i).ElementAt (4);
			if (kind == _T("4"))
			{
				m_List3.InsertItem(list3pos, sparray.ElementAt(i).ElementAt(7));		// dindansp��autoid;
				m_List3.SetItemText(list3pos, 1, sparray.ElementAt(i).ElementAt(1));	// ��Ʒ���;
				m_List3.SetItemText(list3pos, 2, sparray.ElementAt(i).ElementAt(5));	// ��Ʒ����;	
				m_List3.SetItemText(list3pos, 3, sparray.ElementAt(i).ElementAt(2));	// ��Ʒ�۸�;
				m_List3.SetItemText(list3pos, 4, sparray.ElementAt(i).ElementAt(3));	// ��Ʒ����;
#ifdef LKAY_VERSION
				m_List3.SetItemText(list3pos, 5, sparray.ElementAt (i).ElementAt (9));	// 
				m_List3.SetItemText(list3pos, 6, sparray.ElementAt (i).ElementAt (10));
				m_List3.SetItemText(list3pos, 7, sparray.ElementAt (i).ElementAt (8));
#else
				m_List3.SetItemText(list3pos, 5, sparray.ElementAt(i).ElementAt(8));	// ѡ���ʱѡ�е���Ƭ��;

				m_List3.SetItemText(list3pos, 6, sparray.ElementAt(i).ElementAt(9));		// ��Ʒ��ע;
#endif
				list3pos++;
			}
			else
			{
				m_List2.InsertItem(list2pos, sparray.ElementAt(i).ElementAt(7));		// dindansp��autoid;
				m_List2.SetItemText(list2pos, 1, sparray.ElementAt(i).ElementAt(1));	// ��Ʒ���;
				m_List2.SetItemText(list2pos, 2, sparray.ElementAt(i).ElementAt(5));	// ��Ʒ����;
				m_List2.SetItemText(list2pos, 3, sparray.ElementAt(i).ElementAt(3));	// ��Ʒ����;
				m_List2.SetItemText(list2pos, 4, sparray.ElementAt(i).ElementAt(8));	// ѡ���ʱѡ�е���Ƭ��;

				list2pos++;
			}

			str = sparray.ElementAt(i).ElementAt(8);
			str.MakeLower();
			nchoosezs += GetZS(str);	// ��ȡno��no2�ֶ��а�������Ƭ������;
			GetPathAddToSel(str);
			if (!str.IsEmpty())
			{
#ifdef USE_SEP_VEB
				str = SEPS_VEB + str + SEPS_VEB;
#else
				str = SEPS_CMA + str + SEPS_CMA;
#endif //#ifdef USE_SEP_VEB
			}
			if (kind == _T("4"))
				m_no2array.Add(str);
			else
				m_noarray.Add(str);
		}
	}

	if (g_List1array.GetSize())
	{
		m_name1 = g_List1array.ElementAt(0).ElementAt(4);
		m_name2 = g_List1array.ElementAt(0).ElementAt(5);

		m_phone1 = g_List1array.ElementAt(0).ElementAt(61);
		m_phone2 = g_List1array.ElementAt(0).ElementAt(62);

		

#ifdef USE_SEP_VEB
		if (!m_name1.IsEmpty())
			m_name = m_name1 + SEPS_VEB;

		m_name += m_name2;
		m_name.TrimRight(SEPS_VEB);
#else
		if (!m_name1.IsEmpty())
			m_name = m_name1 + SEPS_CMA;

		m_name += m_name2;
		m_name.TrimRight(SEPS_CMA);
#endif //#ifdef USE_SEP_VEB

		m_waiter3 = g_user.name;
		m_taoxizs = g_List1array.ElementAt(0).ElementAt(9);
		m_time5 = g_List1array.ElementAt(0).ElementAt(22);
		m_takezs = g_List1array.ElementAt(0).ElementAt(23);
		m_choosezs = g_List1array.ElementAt(0).ElementAt(24);
		m_money3 = g_List1array.ElementAt(0).ElementAt(3);
		m_oldmoney3 = m_money3;

		m_bz3 = g_List1array.ElementAt(0).ElementAt(57);
		m_urgent = g_List1array.ElementAt(0).ElementAt(40);
		
		m_delphotos = g_List1array.ElementAt(0).ElementAt(56);// Jeff��ȡѡ���ʱ,��ɾ������Ƭ,ѡȡ���ֶ�delphotos2;.��ȡ����������ʱδ����ȷ���浽delphotos2�ֶ�;
		if ( m_delphotos.GetAt(0) != SEPC_VEB || m_delphotos.GetAt(m_delphotos.GetLength() -1) != SEPC_VEB )
		{
			m_delphotos.TrimLeft(SEPC_VEB);
			m_delphotos.TrimRight(SEPC_VEB);

			m_delphotos = SEPS_VEB + m_delphotos + SEPS_VEB;
		}
		m_status8 = g_List1array.ElementAt(0).ElementAt(55);

		m_time6 = g_List1array.ElementAt(0).ElementAt(48);

		m_time5old = m_time5;
		m_time6old = m_time6;

		m_checkstatus = g_List1array.ElementAt(0).ElementAt(55);
		UpdateData(false);
	}
	else
	{
		m_name1 = _T("");
		m_name2 = _T("");
		m_waiter3 = _T("");
		m_taoxizs = _T("");
		m_time5 = _T("");
		m_takezs = _T("");
		m_choosezs = _T("");
		m_money3 = "";
		m_bz3 = _T("");
		m_urgent = _T("");
		UpdateData(false);
	}
	return 1;
}

void ChooseDesignSkin::OnClose()
{
	/*
	if (m_bModify)
	{
		ShowMsg3 dlg;
		dlg.m_strMsg = _T("����, ѡƬ�޸�δ����, �Ƿ񱣴�����˳�?");
		if(dlg.DoModal() == IDOK)
			OnButton4();
	}
	*/
	CDialog::OnClose();
}

BOOL ChooseDesignSkin::PreTranslateMessage(MSG* pMsg)
{
	if (pMsg->message == WM_LBUTTONDOWN)
	{
		g_bNeedDrawParent = 2;
		if (0)
		{//list3
			CPoint pt;
			CRect rc, rc2;
			::GetCursorPos(&pt);
			m_List3.GetWindowRect(rc2);
			if (rc2.PtInRect(pt) == 0)	return CDialog::PreTranslateMessage(pMsg);
			SetTimer(3, 300, NULL);
		}
	}
	else if (0)//pMsg->message==WM_LBUTTONDBLCLK)
	{
		{//list1
			CPoint pt;
			CRect rc, rc2;
			::GetCursorPos(&pt);
			m_List2.GetWindowRect(rc2);
			if (rc2.PtInRect(pt))
				return 1;
		}
		{//list3
			CPoint pt;
			CRect rc, rc2;
			::GetCursorPos(&pt);
			m_List3.GetWindowRect(rc2);
			if (rc2.PtInRect(pt) == 0)return CDialog::PreTranslateMessage(pMsg);
			pt.x -= rc2.left;
			pt.y -= rc2.top;
			int iItem = m_List3.GetItemCount() - 1;
			if (iItem < 0)
			{
				m_List3.GetHeaderCtrl()->GetItemRect(0, rc);
				int hei = rc.Height();
				rc.top += hei;
				rc.bottom += hei;
				if (rc.PtInRect(pt))
				{
					m_List3.InsertItem(m_List3.GetItemCount(), "");
				}
			}
			else
			{
				m_List3.GetSubItemRect(iItem, 0, LVIR_BOUNDS, rc);
				int hei = rc.Height();
				rc.top += hei;
				rc.bottom += hei;
				if (rc.PtInRect(pt))
				{
					if (m_List3.GetItemText(iItem, 1).IsEmpty() && m_List3.GetItemText(iItem, 2).IsEmpty())
						return CDialog::PreTranslateMessage(pMsg);
					m_List3.InsertItem(m_List3.GetItemCount(), "");
				}
				POSITION pos;
				pos = m_List3.GetFirstSelectedItemPosition();
				if (pos)
				{
					iItem = m_List3.GetNextSelectedItem(pos);
					m_List3.GetSubItemRect(iItem, 4, LVIR_BOUNDS, rc);
					if (rc.PtInRect(pt))return 1;
				}
			}
		}
	}
	else if (pMsg->message == WM_KEYDOWN)
	{
		if (m_showpichwd)return 1;
		switch (pMsg->wParam)
		{
		case VK_DELETE:
			{
				OnDel();
				//���»���
				DrawInterface();
			//	LoadPhotos();
			}
			return 1;
		case VK_RETURN:
			OnDblclkList1();
			return 1;
		case VK_F4:
			if (m_bChooseBig == 0)
				return 1;

			if (atoi(g_cominfoarray.ElementAt(0).ElementAt(62)))
			{
				if (m_SelectCategory == INDX_SEL)
					UpdateChooseZS();
				SortArray();
			}
			return 1;
		case VK_F5:
			if (atoi(g_cominfoarray.ElementAt(0).ElementAt(86)))
			{
				OnBtnClick(0, 99 + 4);
			}
			return 1;
		case VK_F1:
			{
				if (m_selphotownd2.GetSafeHwnd() == NULL)
				{
					m_selphotownd2.m_id = m_strOrderNumber;
					m_selphotownd2.m_bGrowthTX = m_bGrowthTX;
					m_selphotownd2.m_seltxname = m_seltxname;
					m_selphotownd2.m_rc = m_rcarray.ElementAt(6);
					m_selphotownd2.Create(IDD_DLGShowSelPhoto2, this);
				}
				m_selphotownd2.ShowWindow(1);
			}
			return 1;
		case VK_F2:							//����ͼ
			if (m_bChooseBig == 0)
				return 1;

			if (atoi(g_cominfoarray.ElementAt(0).ElementAt(60)))
			{
				m_bHide = !m_bHide;
				LoadPhotos();
			}
			return 1;
		case VK_F6:
			{
				ReplaceDesignNo dlg;
				dlg.m_id = this->m_strOrderNumber;
				dlg.DoModal();
			}
			return 1;
		case VK_ESCAPE:
			{
				return TRUE;
			}
			break;
		}
	}
	else if(pMsg->message == WM_LBUTTONUP)
	{
		CDialog::PreTranslateMessage(pMsg);
		return TRUE;
	}
	return CDialog::PreTranslateMessage(pMsg);
}


// �Ҽ�ѡƬģʽ;
void ChooseDesignSkin::OnRclickList1()
{
	if (m_bRunning)
		return;

	CMenuXP	*pPopup = NULL;
	POSITION pos;
	pos = m_List1.GetFirstSelectedItemPosition();
	if (pos == NULL)
		return;

	CString path = _T("");
	CStringArray* pArray = NULL;
	int iItem = m_List1.GetNextSelectedItem(pos);
	pArray = GetCurArray(m_SelectCategory);
	path = pArray->ElementAt(iItem);					//path//��ӡ����Ƭ����·����;

	// �Ҽ������ģʽ;
	if (!m_bChooseBig)
		path = path.Right(path.GetLength() - m_path.GetLength());
	else
		path = path.Right(path.GetLength() - path.ReverseFind('\\') - 1);
	path = path.Left(path.ReverseFind('.'));
#ifdef USE_SEP_VEB
	path = SEPS_VEB + path + SEPS_VEB; // 
#else
	path = SEPS_CMA + path + SEPS_CMA; // 
#endif //#ifdef USE_SEP_VEB

	// TODO: Add your control notification handler code here
	// 1.�����˵�����;
	// 1.�����˵�����;
	pPopup = new CMenuXP;
	pPopup->CYBUTTONMARGIN = 3;				// 1.0.��ť��Χ0~3; 4���˵�;
	pPopup->CreatePopupMenu();				// 1.1.����ʽ�˵�;
	pPopup->SetMenuStyle(CMenuXP::STYLE_XP);// 1.2.�����˵���ʽ;		

	// Jeff:m_List2������ͷ����š���Ʒ���ơ���Ʒ����;
	//����˵�����ַ�����
	int i = 0;
	int maxleng = 1;
	{
		CString name, no;
		int count = 0;
		for ( i = 0; i < m_List2.GetItemCount(); i++)
		{
			// name��Ʒ����
			name = m_List2.GetItemText(i, 2);
			no = m_noarray.ElementAt(i);
			maxleng = max(maxleng, name.GetLength());
		}
		count = i;
		for (; i < count + m_no2array.GetSize(); i++)
		{
			name = m_List3.GetItemText(i - count, 2);
			maxleng = max(maxleng, name.GetLength());
		}
	}
	maxleng += 3;
	
	// Jeff:m_List2������ͷ����š���Ʒ���ơ���Ʒ����;
	CString scount = _T("");
	CString name, no;
	int count = 0;
	for ( i = 0; i < m_List2.GetItemCount(); i++)
	{
		name = m_List2.GetItemText(i, 2);
		//��䳤��
		FillLength(name, maxleng);
		// Jeff,no��Ϊ��Ʒ����ѡ�е���Ƭ
		no = m_noarray.ElementAt(i);
		GetSelCountFromName(no, scount);

		//���Ӳ˵���
		pPopup->AppendODMenu2(0, new CMenuXPText(IDM_MENUsp1 + i, name + scount, NULL));// 2.ʹ��AppendODMenu2�����Ӳ˵���;

		//���¼�ID
		if (no.Find(path) != -1)
			pPopup->CheckMenuItem(IDM_MENUsp1 + i, MF_BYCOMMAND | MF_CHECKED);
	}

	count = i;
	for (; i < count + m_no2array.GetSize(); i++)
	{
		name = m_List3.GetItemText(i - count, 2);
		FillLength(name, maxleng);
		no = m_no2array.ElementAt(i - count);
		GetSelCountFromName(no, scount);
		pPopup->AppendODMenu2(0, new CMenuXPText(IDM_MENUsp1 + i, name + scount, NULL));
		if (no.Find(path) != -1)
			pPopup->CheckMenuItem(IDM_MENUsp1 + i, MF_BYCOMMAND | MF_CHECKED);
	}

	pPopup->AppendODMenu2(0, new CMenuXPText(32794, "�޸�Ҫ��", NULL));

	//��ȡ��ǰ���λ��
	CPoint pt;
	::GetCursorPos(&pt);

	// 3.ʹ��TrackPopupMenu�����������˵�;
	pPopup->TrackPopupMenu(TPM_RIGHTBUTTON, pt.x, pt.y, this, 0);
	delete pPopup;
}

void ChooseDesignSkin::OnRclickList1(NMHDR* pNMHDR, LRESULT* pResult)
{
	if (m_showpichwd)
		return;

	OnRclickList1();
	*pResult = 0;
}

//
/************************************************************************/
/*	
	����: OnCommandMenu
	����: �����˵�����;
	����: 
		UINT nID			�¼�ID
	����: 
	ע��: 
*/
/************************************************************************/
void ChooseDesignSkin::OnCommandMenu(UINT nID)
{
	//������¼�
	OnCommandMenu2(nID);
	return;
}

/************************************************************************/
/*	
	����: OnCommandMenu2
	����: �����,�����˵�����;
	����: 
		UINT nID			�¼�ID
	����: 
	ע��: 
*/
/************************************************************************/
void ChooseDesignSkin::OnCommandMenu2(UINT nID)
{
	if (32794 == nID)// �����˵������޸�Ҫ��;
	{
		//�޸�Ҫ��
		POSITION pos;
		pos = m_List1.GetFirstSelectedItemPosition();
		if (pos == NULL)
		{
			return;
		}
		int iItem = m_List1.GetNextSelectedItem(pos);
		CStringArray *pArray = GetCurArray(m_SelectCategory);
		CString path = pArray->ElementAt(iItem);
		path = path.Right(path.GetLength() - path.ReverseFind('\\') - 1);
		path = path.Left(path.Find('.'));

		UpdateData();
		CClientRequirement dlg;
		dlg.m_no = "��ǰ��Ƭ:" + path;
		dlg.m_bz2 = m_bz3;
		dlg.m_bSave = 0;
		dlg.m_nMode = 2;
		if (dlg.DoModal() == IDOK)
		{
			m_bz3 = dlg.m_bz2;
			UpdateData(false);
		}
		return;
	}

	POSITION pos;
	pos = m_List1.GetFirstSelectedItemPosition();
	if (pos == NULL)
	{
		return;
	}

	CString temp;
	m_combo1.ResetContent();
	int aa = 0;
	while (pos) // ��ʼ��ȡ��Ƭ;
	{
		//	if(aa && m_mode==1)break;
		//	if(aa && m_mode==2)break;
		aa++;
		int iItem = m_List1.GetNextSelectedItem(pos);
		CStringArray *pArray = GetCurArray(m_SelectCategory);

		// path:
		CString path = pArray->ElementAt(iItem);
		//AfxMessageBox(path);//Jeff box

		if (m_bChooseBig)//ѡ�Ŵ�
			path = path.Right(path.GetLength() - path.ReverseFind('\\') - 1);
		else//ѡ���
			path = path.Right(path.GetLength() - m_path.GetLength());
		path = path.Left(path.ReverseFind('.'));
#ifdef USE_SEP_VEB
		path = SEPS_VEB + path + SEPS_VEB; // 
#else
		path = SEPS_CMA + path + SEPS_CMA; // 
#endif //#ifdef USE_SEP_VEB

		int idpos = nID - IDM_MENUsp1;
		BOOL bSel = 0;//ѡ�л���ȡ��
		if (idpos < m_noarray.GetSize())
		{
			//MessageBox("1");
			CString no = m_noarray.ElementAt(idpos); // no:Ϊdindansp�ֶ�no;
			//AfxMessageBox(no);//Jeff box

			if (no.Find(path) != -1)
			{
				int pos = no.Find(path);
				no.Delete(pos, path.GetLength() - 1);
			}
			else if (no.GetLength() > 4000)
			{
				AfxMessageBox("���̫��,ѡ��ʧ��!", MB_ICONSTOP); return;
			}
			else
			{
				bSel = 1;
#ifdef USE_SEP_VEB
				no.TrimRight(SEPS_VEB);
#else
				no.TrimRight(SEPS_CMA);
#endif //#ifdef USE_SEP_VEB
				no += path;
			}
#ifdef USE_SEP_VEB
			no.TrimLeft(SEPS_VEB);
			no.TrimRight(SEPS_VEB);
#else
			no.TrimLeft(SEPS_CMA);
			no.TrimRight(SEPS_CMA);
#endif //#ifdef USE_SEP_VEB
			m_List2.SetItemText(idpos, 4, no);

			if (no.IsEmpty())
				m_noarray.SetAt(idpos, no);
			else
			{
#ifdef USE_SEP_VEB
				m_noarray.SetAt(idpos, SEPS_VEB + no + SEPS_VEB);
#else
				m_noarray.SetAt(idpos, SEPS_CMA + no + SEPS_CMA);
#endif //#ifdef USE_SEP_VEB
			}
		}
		else
		{
			idpos -= m_noarray.GetSize();
			CString no = m_no2array.ElementAt(idpos);

			if (no.Find(path) != -1)
			{
				int pos = no.Find(path);
				no.Delete(pos, path.GetLength() - 1);
			}
			else if (no.GetLength() > 4000)
			{
				AfxMessageBox("���̫��,ѡ��ʧ��!", MB_ICONSTOP); return;
			}
			else
			{
				bSel = 1;
#ifdef USE_SEP_VEB
				no.TrimRight(SEPS_VEB);
#else
				no.TrimRight(SEPS_CMA);
#endif //#ifdef USE_SEP_VEB
				no += path;
			}
#ifdef USE_SEP_VEB
			no.TrimLeft(SEPS_VEB);
			no.TrimRight(SEPS_VEB);
#else
			no.TrimLeft(SEPS_CMA);
			no.TrimRight(SEPS_CMA);
#endif //#ifdef USE_SEP_VEB

#ifdef LKAY_VERSION
			m_List3.SetItemText (idpos, 7, no);
#else
			m_List3.SetItemText(idpos, 5, no);
#endif //#ifdef LKAY_VERSION

			if (no.IsEmpty())
				m_no2array.SetAt(idpos, no);
			else
			{
#ifdef USE_SEP_VEB
				m_no2array.SetAt(idpos, SEPS_VEB + no + SEPS_VEB);
#else
				m_no2array.SetAt(idpos, SEPS_CMA + no + SEPS_CMA);
#endif //#ifdef USE_SEP_VEB
			}
		}

		m_bModify = 1;

		if (bSel == 0 && m_SelectCategory == INDX_SEL && IsSelPhoto(path) == 0)
		{
			temp.Format("%d", iItem);
			m_combo1.AddString(temp);
			continue;
		}
		else if (bSel == 1 && m_SelectCategory == INDX_NOSEL)
		{
			temp.Format("%d", iItem);
			m_combo1.AddString(temp);
			continue;
		}
		else if (bSel == 1 && m_SelectCategory == INDX_DEL)
		{
			temp.Format("%d", iItem);
			m_combo1.AddString(temp);
			continue;
		}
		/////////////////////////
		CString no, dir;
		no = pArray->ElementAt(iItem);
		if (m_bChooseBig)//ѡ�Ŵ�
			no = no.Right(no.GetLength() - no.ReverseFind('\\') - 1);
		else//ѡ���
			no = no.Right(no.GetLength() - m_path.GetLength());

		no = no.Left(no.ReverseFind('.'));

		no += GetSelName(no);

		m_List1.SetItemText(iItem, 0, no);
	}


	CArray<int, int>posarray;
	for (int i = m_combo1.GetCount() - 1; i >= 0; i--)
	{
		m_combo1.GetLBText(i, temp);
		posarray.Add(atoi(temp));
	}
	SortArray2(posarray);


	if (posarray.GetSize())
	{
		if (m_SelectCategory == INDX_SEL)
		{
			for (int i = 0; i < posarray.GetSize(); i++)
			{
				m_List1.DeleteItem(posarray.ElementAt(i));
				m_NoSelPhotoPath.Add(m_SelPhotoPath.ElementAt(posarray.ElementAt(i)));
				m_SelPhotoPath.RemoveAt(posarray.ElementAt(i));
			}

			if (m_showpichwd)
				::SendMessage(m_showpichwd, WM_CLOSE, 0, 0);
		}
		else if (m_SelectCategory == INDX_NOSEL)
		{
			for (int i = 0; i < posarray.GetSize(); i++)
			{
				m_List1.DeleteItem(posarray.ElementAt(i));
				m_NoSelPhotoPath.RemoveAt(posarray.ElementAt(i));
			}

			if (m_showpichwd)
				::SendMessage(m_showpichwd, WM_CLOSE, 0, 0);
		}
		else if (m_SelectCategory == INDX_DEL)
		{
			for (int i = 0; i < posarray.GetSize(); i++)
			{
				m_List1.DeleteItem(posarray.ElementAt(i));
				m_AllPhotoPath.Add(m_DelPhotoPath.ElementAt(posarray.ElementAt(i)));
				m_DelPhotoPath.RemoveAt(posarray.ElementAt(i));
			}

			if (m_showpichwd)
				::SendMessage(m_showpichwd, WM_CLOSE, 0, 0);
		}
	}

	CString strFile = m_strOrderNumber + _T("-2.dat");
	Save(g_mainpath, strFile);
	DrawInterface();
	if (m_showpichwd)
		::SendMessage(m_showpichwd, WM_USER + 200, 0, 0);

}

long ChooseDesignSkin::UpdateTakeZS(WPARAM inWParam, LPARAM inLParam)
{
	if (m_SelectCategory == INDX_ALL && m_List1.GetItemCount() > atoi(m_takezs))
	{
		UpdateData();
		m_takezs.Format("%d", m_List1.GetItemCount());
		UpdateData(false);
	}

	//����
	DrawInterface();
	return 1;
}

/************************************************************************/
/*	
	����: UpdateChooseZS
	����: ����ѡ����Ƭ
	����: 
	����: 
	ע��: 
*/
/************************************************************************/
void ChooseDesignSkin::UpdateChooseZS()
{
	int i = 0;
	CString str = _T("");
	CStringArray* pSelArr = NULL;
	CStringArray* pAllArr = NULL;

	pSelArr = GetCurArray(INDX_SEL);
	pAllArr = GetCurArray(INDX_ALL);

	pSelArr->RemoveAll();
	if (m_sChooseFilter != _T("") && m_sChooseFilter != _T("ȫ��"))
	{
		for ( i = 0; i < m_List3.GetItemCount(); i++)
		{
			if (m_List3.GetItemText(i, 2) != m_sChooseFilter)
				continue;

			str = m_no2array.ElementAt(i);
			GetPathAddToSel(pSelArr, str, pAllArr);
		}
		return;
	}

	for ( i = 0; i < m_noarray.GetSize(); i++)
	{
		str = m_noarray.ElementAt(i);
		GetPathAddToSel(pSelArr, str, pAllArr);
	}
	for (i = 0; i < m_no2array.GetSize(); i++)
	{
		str = m_no2array.ElementAt(i);
		GetPathAddToSel(pSelArr, str, pAllArr);
	}
}

// ���水ť;
void ChooseDesignSkin::OnButton4()// ���水ť;
{
	UpdateData();
	if (m_SelectCategory != INDX_SEL)
		CalChooseZS(&m_SelPhotoPath, &m_AllPhotoPath);

	CString zs = m_taoxizs;
	int pos = zs.Find("\\");
	if (pos != -1)
	{
		zs = zs.Left(pos);
	}
	m_choosezs.Format("%d", max(0, m_SelPhotoPath.GetSize() - atoi(zs)));

	m_bSaveFail = 0;
	ChoosePhotoSkin3 dlg;
	dlg.m_pParent = this;
	dlg.DoModal();
	if (dlg.m_bSave)
		m_bModify = 0;
	if (dlg.m_bPushedSave == 0 && dlg.m_bSaveFail == 0)
	{
		CString savepath = _T("");
		savepath.Format("%s\\%s-2.dat", g_mainpath, m_strOrderNumber);
		::DeleteFile(savepath);		// ɾ��*.dat�ļ�;
	}
	m_bSaveFail = dlg.m_bSaveFail;

	if (dlg.m_bExit)
	{
		m_bModify = 0;
		CDialog::OnCancel();
	}
}

// ɾ����Ƭ;
BOOL ChooseDesignSkin::OnDel()			// ɾ����Ƭ;
{
	//	printf("Jeff:m_mode=%d,m_mode2=%d.\n\n",m_mode,m_mode2);//Jeff Printf
	if (m_SelectCategory == INDX_SEL)
	{
		AfxMessageBox("ѡ����Ƭ����ɾ��, ����ȡ��ѡ��״̬!", MB_ICONINFORMATION);
		return 0;
	}
	else if (m_SelectCategory == INDX_DEL)
	{
		return 0;
	}

	POSITION pos;
	pos = m_List1.GetFirstSelectedItemPosition();
	if (pos == NULL)
		return 0;

	if (m_bRunning)
		return 0;

	CStringArray* pArray = NULL;
	CString strDelPhotoName = _T("");
	CString strSelPhotoPath = _T("");
	int iItem = m_List1.GetNextSelectedItem(pos);
	int nItemIdx = iItem;
	pArray = GetCurArray(m_SelectCategory);

	strSelPhotoPath = pArray->ElementAt(nItemIdx);
	strDelPhotoName = strSelPhotoPath;
	if(strDelPhotoName == _T("") || pArray == NULL)
		return 0;

	strDelPhotoName = strDelPhotoName.Right(strDelPhotoName.GetLength() - strDelPhotoName.ReverseFind('\\') - 1);
	strDelPhotoName = strDelPhotoName.Left(strDelPhotoName.Find('.'));

	if (IsSelPhoto(strDelPhotoName))	// Jeff ����������,��Щ����ɾ��δѡ�е���Ƭʱ,����ʾbox���ݡ�״̬:δ����;
	{
		AfxMessageBox(_T("ѡ�е���Ƭ����ɾ��, ����ȡ��ѡ��״̬!"), MB_ICONINFORMATION);
		return 0;
	}

	if (AfxMessageBox(_T("�Ƿ�ɾ������Ƭ?"), MB_YESNO | MB_ICONINFORMATION) != IDYES)
		return 0;

	//��Ҫɾ������Ƭ���ӵ�ɾ��������
#if JEFF_TEST_ON
	if(PathFileExists(strSelPhotoPath))
		m_DelPhotoPath.Add(strSelPhotoPath);
#else
	m_DelPhotoPath.Add(strSelPhotoPath);
#endif //#if JEFF_TEST_ON

	//	printf("Jeff:��Ҫɾ������Ƭ=%s\n\n",name);// Jeff Printf;
	for(int i = 0; i < pArray->GetSize(); i++)
	{
		//�ַ����Ƚ���ͬ=0
		if(strSelPhotoPath.CollateNoCase(pArray->ElementAt(i)) == 0)
		{
			pArray->RemoveAt(i);
			m_List1.DeleteItem(iItem);
			break;
		}
	}

	if(m_SelectCategory == INDX_NOSEL)
		DelPhotoFromName(m_AllPhotoPath, strDelPhotoName);

	m_bModify = 1;
	//����Ĭ��ѡ��
	if(iItem >= pArray->GetSize())
		iItem = 0;
	m_List1.SetItemState(iItem, LVIS_SELECTED, LVIS_SELECTED);
	return 1;
}

void ChooseDesignSkin::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult)
{
	*pResult = 0;
}

void ChooseDesignSkin::OnTimer(UINT nIDEvent)
{
	if (nIDEvent == 1)
	{
		KillTimer(nIDEvent);
		if (m_showpichwd)
			::SendMessage(m_showpichwd, WM_USER + 200, 1, 0);
		TimeOutDlg dlg;
		dlg.m_ticks = m_ticks;
		dlg.DoModal();
		SetTimer(2, m_timer * 60000, NULL);
	}
	else if (nIDEvent == 2)	// ��ʱ��������ʱ����Ի���;
	{
		KillTimer(nIDEvent);
		if (m_showpichwd)
			::SendMessage(m_showpichwd, WM_USER + 200, 1, 0);
		TimeOutDlg dlg;
		dlg.m_ticks = m_ticks;
		dlg.DoModal();
		SetTimer(2, m_timer * 60000, NULL);
	}
	else if (nIDEvent == 3)
	{
		KillTimer(nIDEvent);
		//SetSPName3();
	}
}


/************************************************************************/
/*	
	����: LoadPhotos
	����: ����ͼƬ
	����: 
	����: 
*/
/************************************************************************/
void ChooseDesignSkin::LoadPhotos()
{
	TerminateThread();

	//�����Դ��·��
	ClearResData();

	DWORD tm1(0), tm2(0);
	tm1 = GetTickCount();
	//��ȡ��ǰ�鿴����Ƭ
	CStringArray *pArray = GetCurArray(m_SelectCategory);
	for (int i = 0; i < pArray->GetSize(); i++)
	{
		CString filePath = pArray->ElementAt(i);
		if(filePath == _T(""))
			continue;

		SResData* pRes = new SResData();
		pRes->nType = (int)TYPE_ICON;
		
		//תΪСд
		filePath.MakeLower();
		pRes->strFilePath = filePath;
		m_vResData.push_back(pRes);
	}

	tm2 = GetTickCount();
	printf("����ͼƬ��׼��ʱ�䣺%dms\n", (tm2-tm1));
	//�����滭�߳�LoadThumbNail3
	LoadThumbImages();
}

/************************************************************************/
/*
	����: GetNoSelPhoto
	����: δѡ�е���Ƭ
	����: 
	����: 
	ע��: 
*/
/************************************************************************/
void ChooseDesignSkin::GetNoSelPhoto()
{
	CStringArray* pNoSelArr = NULL;
	CStringArray* pAllArr = NULL;
	CStringArray* pSelArr = NULL;

	pNoSelArr = GetCurArray(INDX_NOSEL);
	pAllArr = GetCurArray(INDX_ALL);
	pSelArr = GetCurArray(INDX_SEL);

	if(pNoSelArr == NULL || pAllArr == NULL || pSelArr == NULL)
		return;

	pNoSelArr->RemoveAll();

	CString str1(_T("")), str2(_T(""));
	for (int i = 0; i < pAllArr->GetSize(); i++)
	{
		BOOL bFind = 0;
		for (int j = 0; j < pSelArr->GetSize(); j++)
		{
			str1 = pAllArr->ElementAt(i);
			str2 = pSelArr->ElementAt(j);
			if (str1.CollateNoCase(str2) == 0)
			{
				bFind = 1;
				break;
			}
		}
		if (bFind == 0)
			pNoSelArr->Add(pAllArr->ElementAt(i));
	}
}

/************************************************************************/
/*
	����: OnSelPhoto
	����: �鿴ѡ����Ƭ
	����: 
	����: 
	ע��: 
*/
/************************************************************************/
void ChooseDesignSkin::OnSelPhoto()
{
	ProductChooseFilter dlg;
	CString name = _T("");

	int i = 0;
	for ( i = 0; i < m_List2.GetItemCount(); i++)
	{
		name = m_List2.GetItemText(i, 2);
		dlg.m_array.Add(name);
	}

	for (i = 0; i < m_List3.GetItemCount(); i++)
	{
		name = m_List3.GetItemText(i, 2);
		dlg.m_array.Add(name);
	}
	if(dlg.DoModal() == IDCANCEL)
	{
		m_SelectCategory = INDX_ALL;
		return;
	}
	m_sChooseFilter = dlg.m_sChooseFilter;
	UpdateChooseZS();
}

/************************************************************************/
/*	
	����: GetCurArray
	����: ��ȡҪ�鿴������
	����: 
		const int nIndx					ѡ����������
		SFolderInfo*	m_pForder		���
	����: 
	ע��: 
*/
/************************************************************************/
CStringArray* ChooseDesignSkin::GetCurArray(const int nIndx)
{
	CStringArray* pArray = NULL;
	switch (nIndx)
	{
	case INDX_ALL:			//ȫ��
		pArray = &m_AllPhotoPath;
		break;
	case INDX_SEL:			//ѡ��
		pArray = &m_SelPhotoPath;
		break;
	case INDX_NOSEL:		//δѡ
		pArray = &m_NoSelPhotoPath;
		break;
	case INDX_DEL:			//ɾ��
		pArray = &m_DelPhotoPath;
		break;
	case INDX_INTOALBUM:	//���
		pArray = &m_IntoAlbumPath;
		break;
	case INDX_ENTRYPHASSE:	//���
		pArray = &m_EntryPhasepath;
		break;
	}
	return pArray;
}


/************************************************************************/
/*	
	����: SortArray
	����: ��F4���������
	����: 
	����: 
*/
/************************************************************************/
void ChooseDesignSkin::SortArray()
{
	int i = 0;
	int j = 0;
	m_bSort = !m_bSort;

	CStringArray *pArray[6] = { &m_AllPhotoPath, &m_SelPhotoPath, &m_NoSelPhotoPath, &m_DelPhotoPath, &m_IntoAlbumPath, &m_EntryPhasepath };

	if (m_bSort == 0)
	{
		for ( i = 0; i < 6; i++)
		{
			if (pArray[i]->GetSize())
			{
				int size = pArray[i]->GetSize() - 1;
				CString sTemp;
				int nPos;
				for (int ii = 0; ii < size; ii++)
				{
					nPos = rand() % (size - ii);
					sTemp = pArray[i]->ElementAt(size - ii);
					pArray[i]->SetAt(size - ii, pArray[i]->ElementAt(nPos));
					pArray[i]->SetAt(nPos, sTemp);
				}
			}
		}
	}
	else
	{	// ʹ��CCombobox��Sort������;
		for ( i = 0; i < 6; i++)
		{
			m_combo1.ResetContent();
			CString Temp;
			for ( j = 0; j < pArray[i]->GetSize(); j++)
			{
				m_combo1.AddString(pArray[i]->ElementAt(j));
			}
			for (j = 0; j < pArray[i]->GetSize(); j++)
			{
				m_combo1.GetLBText(j, Temp);
				pArray[i]->SetAt(j, Temp);
			}
		}
	}

	//��ֹ�߳�
	TerminateThread();

	//�����Դ��·��
	ClearResData();

	//��ȡ��ǰ�鿴����Ƭ
	CStringArray *pArr = GetCurArray(m_SelectCategory);
	if(pArr == NULL)
		return;

	for ( i = 0; i < pArr->GetSize(); i++)
	{
		SResData* pRes = new SResData();
		pRes->nType = (int)TYPE_ICON;
		CString filePath = pArr->ElementAt(i);
		//תΪСд
		filePath.MakeLower();
		pRes->strFilePath = filePath;
		m_vResData.push_back(pRes);
	}
	//�����滭�߳�LoadThumbNail3
	LoadThumbImages();
}

/*-------------------------------------------------------
������:	DrawInterface
����:	���ƽ���
����:
����ֵ:
-------------------------------------------------------*/
void ChooseDesignSkin::DrawInterface()
{
	CRect rc(0, 0, 0, 0), rt(0, 0, 0, 0);
	((MyBmpButton2*)m_picarray.ElementAt(3))->GetWindowRect(rc);
	ScreenToClient(rc);
	int nH = rc.bottom - rc.top;
	rc.right -= (rc.left + 100);
	rc.left = 5;
	rc.top += 10;
	rc.right += 220;
	rc.bottom = rc.top + nH - 10;
	rt.CopyRect(&rc);
	CDC *pDC = GetDC();
	Graphics graph(pDC->GetSafeHdc());

	Rect destinationRect(rc.left, rc.top, rc.Width(), rc.Height());
	RectF layoutRect(rc.left, rc.top, rc.Width(), rc.Height());
	rc.left /= g_fscalex;
	rc.right /= g_fscalex;
	rc.top /= g_fscaley;
	rc.bottom /= g_fscaley;

	//	graph.SetSmoothingMode(SmoothingModeHighQuality);
	graph.DrawImage(m_pBk, destinationRect, rc.left, rc.top, rc.Width(), rc.Height(), UnitPixel);

	StringFormat format;
	format.SetAlignment(StringAlignmentNear);
	SolidBrush *Brush = new SolidBrush(Color(255, 255, 255, 255));

	//��ʾ����
	CString str = _T("");
	str.Format(_T("����:%d"), m_List1.GetItemCount());

	int leng = GetLengthEx(str);
	BSTR bstr = str.AllocSysString();
	Gdiplus::Font* pFont = new Gdiplus::Font(L"����", 11);

	graph.SetTextRenderingHint(TextRenderingHintAntiAlias);
	graph.DrawString(
		bstr,
		leng,
		pFont,
		layoutRect,
		&format,
		Brush);
	SysFreeString(bstr);
	
	delete Brush;
	delete pFont;
	ReleaseDC(pDC);
}

CString ChooseDesignSkin::GetZSInfo(int iItem)
{
	if (m_SelectCategory != INDX_SEL)
		CalChooseZS(GetCurArray(INDX_SEL), GetCurArray(INDX_ALL));

	CString str = _T("");
	CString scount = m_List1.GetItemText(iItem, 0);
	int ncount = 0;
	int npos = scount.Find(_T("\r\n"));
	while (npos != -1)
	{
		ncount++;
		scount = scount.Right(scount.GetLength() - npos - 2);
		npos = scount.Find(_T("\r\n"));
	}

	CString zs = m_taoxizs;
	int pos = zs.Find("\\");
	if (pos != -1)
		zs = zs.Left(pos);

	str.Format(_T("X:%d"), ncount);
	return str;
}

/************************************************************************/
/*	
	����: GetPathAddToSel
	����: ��ȡ·�����ӵ�ѡ����Ƭ
	����: 
		strName��dindansp����no��no2�ֶ�ֵ;��Ƭ����ʹ�ö��ŷָ�;
	����: 1�ɹ���0ʧ��
*/
/************************************************************************/
int	ChooseDesignSkin::GetPathAddToSel(const CString& strName)
{
	if(strName == _T(""))
		return 0;

	CStringArray* pSelArr = NULL;
	CStringArray* pAllArr = NULL;

	pSelArr = GetCurArray(INDX_SEL);
	pAllArr = GetCurArray(INDX_ALL);
	GetPathAddToSel(pSelArr, strName, pAllArr);
	return 1;
}

/************************************************************************/
/*	
	����: GetPathAddToSel
	����: ��ȡ·�����ӵ�ѡ����Ƭ
	����: 
		CStringArray* pSelArr
		const CString& str
	����: 1�ɹ���0ʧ��
*/
/************************************************************************/
int ChooseDesignSkin::GetPathAddToSel(CStringArray* pSelArr, const CString& strName, CStringArray* pAllArr)
{
	return ChoosePhotoBase::GetPathAddToSel(pSelArr, strName, pAllArr);
}

/************************************************************************/
/*	
	����: GetAlbumPhoto
	����: �鿴�����Ƭ
	����: 
	����: 
*/
/************************************************************************/
void ChooseDesignSkin::GetAlbumPhoto()
{
	if (m_SelectCategory == INDX_INTOALBUM)
		return;

	m_SelectCategory = INDX_INTOALBUM;

	CStringArray* pArr = NULL;
	pArr = GetCurArray(m_SelectCategory);
	pArr->RemoveAll();
	CString photosName = _T("");
	int i = 0;
	for (i= 0; i < m_List3.GetItemCount(); i++)
	{
		if (m_List3.GetItemText(i, 2) != _T("���"))
			continue;

		photosName = m_no2array.ElementAt(i); 
		break;
	}

	CStringArray* pAllArry = NULL;
	pAllArry = GetCurArray(INDX_ALL);

	//��������Ƭ��
#ifdef USE_SEP_VEB
	photosName = SEPS_VEB + photosName + SEPS_VEB;
#else
	photosName = SEPS_CMA + photosName + SEPS_CMA;
#endif //#ifdef USE_SEP_VEB
	for (i = pAllArry->GetSize() - 1; i >= 0; i--)
	{
		CString strName = _T("");
		strName = pAllArry->ElementAt(i);
		strName = strName.Right(strName.GetLength() - strName.ReverseFind('\\') - 1);
		strName = strName.Left(strName.Find('.'));
#ifdef USE_SEP_VEB
		strName = SEPS_VEB + strName + SEPS_VEB;
#else
		strName = SEPS_CMA + strName + SEPS_CMA;
#endif //#ifdef USE_SEP_VEB
		if (photosName.Find(strName) != -1)
		{
			strName = pAllArry->ElementAt(i);
			pArr->Add(strName);
		}
	}
}

/************************************************************************/
/*	
	����: GetDiskPhoto
	����: �鿴�����Ƭ
	����: 
	����: 
*/
/************************************************************************/
void ChooseDesignSkin::GetDiskPhoto()
{
	if (m_SelectCategory == INDX_ENTRYPHASSE)
		return;

	m_SelectCategory = INDX_ENTRYPHASSE;

	CStringArray* pArr = NULL;
	pArr = GetCurArray(m_SelectCategory);

	int i = 0;
	pArr->RemoveAll();
	CString photosName = _T("");
	for ( i = 0; i < m_List3.GetItemCount(); i++)
	{
		if (m_List3.GetItemText(i, 2) != _T("���"))
			continue;

		photosName = m_no2array.ElementAt(i);
		break;
	}

	CStringArray* pAllArry = NULL;
	pAllArry = GetCurArray(INDX_ALL);
#ifdef USE_SEP_VEB
	photosName = SEPS_VEB + photosName + SEPS_VEB;
#else
	photosName = SEPS_CMA + photosName + SEPS_CMA;
#endif //#ifdef USE_SEP_VEB
	for (i = pAllArry->GetSize() - 1; i >= 0; i--)
	{
		CString strName = _T("");
		strName = pAllArry->ElementAt(i);
		strName = strName.Right(strName.GetLength() - strName.ReverseFind('\\') - 1);
		strName = strName.Left(strName.Find('.'));
#ifdef USE_SEP_VEB
		strName = SEPS_VEB + strName + SEPS_VEB;
#else
		strName = SEPS_CMA + strName + SEPS_CMA;
#endif //#ifdef USE_SEP_VEB
		if (photosName.Find(strName) != -1)
		{
			strName = pAllArry->ElementAt(i);
			pArr->Add(strName);
		}
	}
}

/************************************************************************/
/*
������:	ReLoad
����:	���¼�������
����:
����ֵ:
*/
/************************************************************************/
BOOL ChooseDesignSkin::ReLoad()
{
	return GetData();
}

/************************************************************************/
/*	
	����: ReLoadPhoto
	����: ���¼�����Ƭ
	����: 
	����: 
*/
/************************************************************************/
void ChooseDesignSkin::ReLoadPhoto()
{
	if (!((MyBmpButton2*)m_picarray.ElementAt(8))->GetPushDown())
	{
		m_path = g_path3 + _T("\\");
		m_path += m_strOrderNumber;
		m_path += _T("\\");
		GetPhotos();
		m_bChooseBig = 0;
	}
	else
	{
		m_bChooseBig = 1;
		//ѡ��˴���������DLG(�磺���㾰��)
		GetTXName(&m_strOrderNumber, 1, m_bGrowthTX, m_seltxname);

		m_AllPhotoPath.RemoveAll();
		if (IsThereACacheImg()) //
			m_bFromLocal = 1;

		if (m_AllPhotoPath.GetSize() == 0)
		{
			if (IsPhoto2Exist())
			{
				SelBrunDevice dlg;
				dlg.m_mode = 0;
				if (dlg.DoModal() == IDOK)
					m_nChoosePhotoType = dlg.m_sel;
				else
					m_nChoosePhotoType = 0;
				//m_nChoosePhotoType=0 ԭƬ+��Ƭ 1����Ƭ 2��ԭƬ
			}
			else 
				AfxMessageBox("��ܰ��ʾ��\r\nδ�ҵ�����Ƭ����ʹ��ԭƬѡƬ", MB_ICONINFORMATION);

			{
				CString path, path2;
				m_path = g_path1 + _T("\\");
				m_path += m_strOrderNumber;
				m_path += _T("\\");
				if (m_seltxname != "" && m_seltxname != _T("ȫ��"))
				{
					m_path += m_seltxname;
					m_path += _T("\\");
				}
				if (m_nChoosePhotoType == 1)	// ѡƬ:��Ƭ
				{
					m_path = g_path2 + _T("\\");
					m_path += m_strOrderNumber;
					m_path += _T("\\");
				}
				CString filename = _T("");
				
				ffsco o;
				o.dirs(1);
				o.find(LPCSTR(m_path), LPCSTR("*.*"));
				ffsco::typeT coo;
				ffsco::typeT::iterator it;
				coo = o.co_file();
				for (it = coo.begin(); coo.end() != it; it++)
				{
					path = (*it).c_str();

					if (path.GetAt(path.ReverseFind('\\') + 1) != 's' && path.GetAt(path.ReverseFind('\\') + 1) != 'm')
					{
						path.MakeLower();

						filename = path.Right(path.GetLength() - path.ReverseFind('\\') - 1);
						if (filename.Find(".") != -1)
							filename = filename.Left(filename.Find("."));
						if (!myisdigit(filename))continue;

						if (m_nChoosePhotoType == 1)
						{
#if JEFF_TEST_ON
							if (PathFileExists(path))
								m_AllPhotoPath.Add(path);
#else
							m_AllPhotoPath.Add(path);
#endif //#if JEFF_TEST_ON
						}
						else
						{
							path2 = path;

							if (m_nChoosePhotoType == 0)
								path2.Replace("�ͻ�ԭƬ", "�޺õ�Ƭ");
							if (m_bGrowthTX == 0)
							{
								int pos = path2.Find(m_strOrderNumber);
								pos += m_strOrderNumber.GetLength();
								int pos2 = path2.ReverseFind('\\');
								path2 = path2.Left(pos) + path2.Right(path2.GetLength() - pos2);
							}

							if (m_nChoosePhotoType == 0 && ::PathFileExists(path2))
							{
								m_AllPhotoPath.Add(path2);
							}
							else
							{
								path2.Replace(".raw", _T(".jpg"));
								if (PathFileExists(path2))
								{
									m_AllPhotoPath.Add(path2);
									continue;
								}
								path2.Replace(".nef", _T(".jpg"));
								if (PathFileExists(path2))
								{
									m_AllPhotoPath.Add(path2); 
									continue;
								}
								path2.Replace(".cr2", _T(".jpg"));
								if (PathFileExists(path2))
								{
									m_AllPhotoPath.Add(path2);
									continue;
								}
								else
								{
									if (path.Right(3) != "jpg")
										continue;
#if JEFF_TEST_ON
									if (PathFileExists(path))
										m_AllPhotoPath.Add(path);
#else
									m_AllPhotoPath.Add(path);
#endif //#if JEFF_TEST_ON
								}
							}
						}
					}
				}
			}

			//	if(0)
			{//�����޺õ�Ч��
				CString path, path2;
				path2 = g_path2 + _T("\\");
				path2 += m_strOrderNumber;
				path2 += _T("\\");
				
				ffsco o;
				o.dirs(0);
				o.find(LPCSTR(path2), LPCSTR("*.jpg"));
				ffsco::typeT coo;
				ffsco::typeT::iterator it;
				coo = o.co_file();
				for (it = coo.begin(); coo.end() != it; it++)
				{
					path = (*it).c_str();
					if (path.GetAt(path.ReverseFind('\\') + 1) != 's' && path.GetAt(path.ReverseFind('\\') + 1) != 'm')
					{
						path.MakeLower();
						path2 = path.Right(path.GetLength() - path.ReverseFind('\\') - 1);
						if (path2.Find(_T("-")) != -1)
						{
#if JEFF_TEST_ON
							if (PathFileExists(path))
								m_AllPhotoPath.Add(path);
#else
							m_AllPhotoPath.Add(path);
#endif //#if JEFF_TEST_ON
						}
					}
				}
			}
		}
		if (m_AllPhotoPath.GetSize() && atoi(g_cominfoarray.ElementAt(0).ElementAt(61)))
		{
			int size = m_AllPhotoPath.GetSize() - 1;
			CString sTemp;
			int nPos;
			for (int i = 0; i < size; i++)
			{
				nPos = rand() % (size - i);
				sTemp = m_AllPhotoPath.ElementAt(size - i);
				m_AllPhotoPath.SetAt(size - i, m_AllPhotoPath.ElementAt(nPos));
				m_AllPhotoPath.SetAt(nPos, sTemp);
			}
		}
	}
	m_SelectCategory = INDX_ALL;
	LoadPhotos();
}


/************************************************************************/
/*	
	����: DrawImageWork
	����: ���ƹ���
	����: 
	����: 
*/
/************************************************************************/
void ChooseDesignSkin::DrawImageWork()
{
	CListCtrl* ListCtrl = &m_List1;
	CImageList* pImgList = &m_ImageListThumb;
	try
	{
		// reset our image list
		for (int i = 0; i < pImgList->GetImageCount(); i++)
			pImgList->Remove(i);

		// remove all items from list view
		ListCtrl->DeleteAllItems();

		pImgList->SetImageCount(m_vResData.size());

		// Set redraw to FALSE to avoid flickering during adding new items
		ListCtrl->SetRedraw(FALSE);

		//���������
		AddListItemName(ListCtrl);

		//�����ػ沢ˢ��
		ListCtrl->SetRedraw(TRUE);
		ListCtrl->Invalidate();

		//����ͼ��
		DrawImage(ListCtrl, pImgList);

		m_bRunning = false;
		m_bTerminate = false;
		PostMessage(WM_USER + 200, 0, 0);

		return;
	}
	catch (...)
	{
		ListCtrl->Invalidate();
		m_bRunning = false;
		m_bTerminate = false;
		PostMessage(WM_USER + 200, 0, 0);
	}
}

/************************************************************************/
/*	
	����: AddListItemName
	����: ���������
	����: 
	����: 1�ɹ���0ʧ��
*/
/************************************************************************/
int ChooseDesignSkin::AddListItemName(CListCtrl* pListCtrl)
{
	if(pListCtrl == NULL)
		return 0;

	int nIndex = 0;
	CString str(_T("")), spath(_T(""));

	//�������
	vector<SResData*>::iterator iter;
	for(iter = m_vResData.begin(); iter != m_vResData.end() && m_bTerminate != true; iter++, nIndex++)
	{
		SResData* pRes = (*iter);
		if(pRes == NULL)
			continue;

		str = pRes->strFilePath;
		if (str.Left(str.ReverseFind('\\') + 1) != m_path)
		{
			spath = str.Left(str.ReverseFind('\\') + 1);
			spath = spath.Right(spath.GetLength() - m_path.GetLength());
		}

		str = str.Right(str.GetLength() - str.ReverseFind('\\') - 1);

		//��������
		if (str.Find("delgabook") != -1)
		{
			str.TrimRight(_T("\\"));
			str = str.Right(str.GetLength() - str.ReverseFind('\\') - 1);
			str.Replace("delgabook", "Flash");
			pListCtrl->InsertItem(nIndex, str, nIndex);
		}
		else
		{
			str = spath + str.Left(str.GetLength() - 4);
			CString temp = GetSelName(str);
			pListCtrl->InsertItem(nIndex, str + temp, nIndex);
		}
	}
	return 1;
}

/************************************************************************/
/*	
	����: DrawImage
	����: ����
	����: 
	����: 
*/
/************************************************************************/
void ChooseDesignSkin::DrawImage(CListCtrl* pListCtrl, CImageList* pImgList)
{
	if(pListCtrl == NULL)
		return;

	int nIndex = 0;
	Image* pHideImg = NULL;				//��Ƭͼ��
	CString str(_T("")), spath(_T(""));

	vector<SResData*>::iterator iter;
	for (iter = m_vResData.begin(); iter != m_vResData.end() && m_bTerminate != true; iter++, nIndex++)
	{
		// Load Image File 
		Image *image = NULL;
		Bitmap *pBmp = NULL;

		SResData* pRes = (*iter);
		if(pRes == NULL)
			continue;

		BOOL bNullimg = FALSE;
		//������Ƭͼ��res\δ����-1.jpg
		switch(pRes->nType)
		{
		case TYPE_ICON:							//��Ƭͼ��
			{
				if(m_bHide && pHideImg == NULL)
					pHideImg = m_pHideImg;

				//�Ƿ�Ҫ���¼�����Դ
				if(pHideImg == NULL)
				{
					ReLoadImageFromRes(&image, pRes->strFilePath, bNullimg);
					if(image == NULL)
						continue;
				}
				else
					image = pHideImg;
			}
			break;
		}

		//����bitmapʹ����ɫ�������
		SolidBrush whitebrush(Color(255, 255, 255, 255));
		pBmp = new Bitmap(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, PixelFormat24bppRGB);
		Graphics graph2(pBmp);
		graph2.Clear(Color(255, 192, 192, 192));
		graph2.FillRectangle(&whitebrush, 1, 1, THUMBNAIL_WIDTH - 2, THUMBNAIL_HEIGHT - 2);

		// ����ͼƬ���ϻ�����С
		Rect desRect(0, 0, 0, 0);
		ZoomImage(image, desRect);
		
		// ����ͼ��res\δ����-1.jpg
		Graphics graph(pBmp);
		graph.DrawImage(image, desRect, 0, 0, image->GetWidth(), image->GetHeight(), UnitPixel);

		// ��ͼƬ�滻bitmap���ӵ�ͼ���б�
		CBitmap bitmap;
		HBITMAP hbmp;
		pBmp->GetHBITMAP(Color(255, 255, 255, 255), &hbmp);
		bitmap.Attach(hbmp);
		pImgList->Replace(nIndex, &bitmap, NULL);

		if(pBmp)
			delete pBmp;

		// Redraw only a current item for removing flickering and fast speed.
		pListCtrl->RedrawItems(nIndex, nIndex);
		// Release used DC and Object

		if(image && pRes->nType == TYPE_ICON && pHideImg == NULL)
			delete image;
	}

	pListCtrl->Invalidate();
}