// DlgDataUpload.cpp : 实现文件
//

#include "stdafx.h"
#include "Draw.h"
#include "DlgDataUpload.h"
#include "DBOperate.h"


// CDlgDataUpload 对话框

IMPLEMENT_DYNAMIC(CDlgDataUpload, CDialog)

CDlgDataUpload::CDlgDataUpload(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgDataUpload::IDD, pParent)
	, m_strMapName(_T(""))
	, m_pMap(NULL)
	, m_bIsUpload(FALSE)
{

}

CDlgDataUpload::~CDlgDataUpload()
{
}

void CDlgDataUpload::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_EDIT1, m_strMapName);
	DDX_Control(pDX, IDC_PROGRESS1, m_ctrlProgress);
}


BEGIN_MESSAGE_MAP(CDlgDataUpload, CDialog)
	ON_BN_CLICKED(IDC_BTN_UPLOAD, &CDlgDataUpload::OnBnClickedBtnUpload)
	ON_WM_TIMER()
END_MESSAGE_MAP()


// CDlgDataUpload 消息处理程序

void CDlgDataUpload::OnBnClickedBtnUpload()
{
	// TODO: 在此添加控件通知处理程序代码
	UpdateData(TRUE);
	if (m_strMapName.IsEmpty())
	{
		AfxMessageBox(_T("请填写图幅名字！"));
		return;
	}
	CDBOperate db;
	if (CDBOperate::m_nCount != 0)
	{
		CDBOperate::m_nCount = 0;
	}
	ASSERT(m_pMap);
	if (m_pMap->GetCount() == 0)
	{
		AfxMessageBox(_T("没有图元对象，不需要入库！"));
		return;
	}
	m_bIsUpload = TRUE;
	SetTimer(1,1,0);
	db.m_pConnection = g_pConnection;
	if (db.SaveMap(m_pMap,m_strMapName))
	{
		AfxMessageBox(_T("入库成功！"));
		OnOK();
	}
	else
	{
		AfxMessageBox(_T("入库失败！"));
		KillTimer(1);
	}
}

void CDlgDataUpload::OnTimer(UINT_PTR nIDEvent)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	if (nIDEvent == 1)
	{
		int nCount = m_pMap->GetCount();
		m_ctrlProgress.SetPos(CDBOperate::m_nCount/nCount*100);
	}

	CDialog::OnTimer(nIDEvent);
}

BOOL CDlgDataUpload::OnInitDialog()
{
	CDialog::OnInitDialog();

	// TODO:  在此添加额外的初始化
	m_ctrlProgress.SetPos(0);
	m_ctrlProgress.SetRange(0,100);

	return TRUE;  // return TRUE unless you set the focus to a control
	// 异常: OCX 属性页应返回 FALSE
}
