//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "GlobalUnit.h"
#include "ManageSongFormUnit.h"
#include "QRcodePanel.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "PNGButton"
#pragma link "GeneralDialogPanel"
#pragma link "TextButton"
#pragma resource "*.dfm"

TManageSongForm *ManageSongForm;
const static COLORREF Enter = RGB( 100,180,236 ),
					  Leave = RGB( 67,117,233 );

TQRcodePanel * QRPanel = NULL;

//---------------------------------------------------------------------------
__fastcall TManageSongForm::TManageSongForm(TComponent* Owner, bool bUpload, UINT idSong)
	: TForm(Owner)
{
	m_pQRdata = NULL;
	char strURL[1024];

	if( bUpload ){
		if( idSong>0 ){
			String strMsg = L"歌曲上传成功\n\n请进入网站";
			if( f_QR_Encode ){
				char strURL[256], strID[20];
				f_CS_GetWebPageURL( URL_SHAREPLAY, strURL );
				sprintf( strID, "%d", idSong );
				strcat( strURL, strID );

				m_pQRdata = new unsigned char[100*100];
				int qrWidth = f_QR_Encode( strURL, m_pQRdata );
				QRPanel = new TQRcodePanel( NULL, "歌曲二维码" );
				if( QRPanel ){
					Width += Height;
					QRPanel->Parent = this;
					QRPanel->SetBounds( Width-Height, 0, Height, Height );
					QRPanel->SetQRData( qrWidth, m_pQRdata );
					QRPanel->Show();

					strMsg += L"（或扫描二维码）";
				}
			}

			strMsg += L"试听和分享";

			f_CS_GetWebPageURL( URL_SONGPLAY, strURL );
			m_strGo = strURL;
			m_strGo += "&musicId=" + IntToStr( (int)idSong );

			m_lbMsg->Caption = strMsg;
		}
	}
	else{
		m_lbMsg->Caption = L"您上传的未发布歌曲数量已达上限\n\n请进入网站处理";
		f_CS_GetWebPageURL( URL_SONGMANAGE, strURL );
		m_strGo = strURL;
	}

	Font->Color = RGB(60,43,23);
	m_lbGoManage->Font->Color = Leave;

	SetTransparent( this );
}

//---------------------------------------------------------------------------

void __fastcall TManageSongForm::GoManageMouseEnter(TObject *Sender)
{
	Screen->Cursor = crHandPoint;
	m_lbGoManage->Font->Color = Enter;
}
//---------------------------------------------------------------------------
void __fastcall TManageSongForm::GoManageMouseLeave(TObject *Sender)
{
	Screen->Cursor = crDefault;
	m_lbGoManage->Font->Color = Leave;
}
//---------------------------------------------------------------------------
void __fastcall TManageSongForm::GoManageClick(TObject *Sender)
{
//	char strURL[256];
//	f_CS_GetWebPageURL( URL_SONGMANAGE, strURL );
//	ShellExecute(Handle, NULL, ((String)strURL).c_str(), NULL, NULL, SW_SHOWNORMAL);
	ShellExecute(Handle, NULL, m_strGo.c_str(), NULL, NULL, SW_SHOWNORMAL);

	ModalResult = mrOk;
}
//---------------------------------------------------------------------------

void __fastcall TManageSongForm::FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift)
{
	switch( Key ){
	case VK_RETURN:
		return GoManageClick(NULL);
		break;

	case VK_ESCAPE:
		ModalResult = mrCancel;
		break;
	}
}
//---------------------------------------------------------------------------

void __fastcall TManageSongForm::FormDestroy(TObject *Sender)
{
	if( QRPanel ){
		delete QRPanel;
		QRPanel = NULL;
	}

	if( m_pQRdata ){
		delete[] m_pQRdata;
		m_pQRdata = NULL;
	}
}
//---------------------------------------------------------------------------

