Choosedbdlg.cpp 4.83 KB
// Choosedbdlg.cpp : implementation file
//

#include "stdafx.h"
#include "sn writer.h"
#include "Choosedbdlg.h"
#include "Common.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

extern META_Common_struct g_sMetaComm;


/////////////////////////////////////////////////////////////////////////////
// CChoosedbdlg dialog


CChoosedbdlg::CChoosedbdlg(CWnd* pParent /*=NULL*/)
	: CDialog(CChoosedbdlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CChoosedbdlg)
	my_str_ap_path = _T("");
	my_str_bp_path = _T("");
	myversion = _T("");
	//}}AFX_DATA_INIT
}


void CChoosedbdlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CChoosedbdlg)
	DDX_Text(pDX, IDC_EDIT1, my_str_ap_path);
	DDX_Text(pDX, IDC_EDIT2, my_str_bp_path);
	DDX_Text(pDX, IDC_EDT_VERSION, myversion);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CChoosedbdlg, CDialog)
	//{{AFX_MSG_MAP(CChoosedbdlg)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CChoosedbdlg message handlers

void CChoosedbdlg::OnButton1() 
{
    char szFilter[]="AP Database(APDB*.*)|*.*";

	CString mystr_path;
	WIN32_FIND_DATA FileData;
    HANDLE    hSearch;
    int        nCount=0;
    BOOL    fFinished = FALSE;    

	CFileDialog dlg(TRUE, NULL, NULL,
        OFN_FILEMUSTEXIST|OFN_EXPLORER|OFN_ENABLESIZING|0x10000000/*OFN_FORCESHOWHIDDEN*/,
        szFilter, this);
    dlg.m_ofn.lpstrTitle = _T("Select Modem_1 database file...");
    if(dlg.DoModal() == IDOK)
    {
        g_sMetaComm.sDBFileOption.bDBInitModem_1 = false;
        my_str_ap_path = dlg.GetPathName();
		mystr_path = my_str_ap_path;
		mystr_path.SetAt(mystr_path.ReverseFind('\\')+1,0);
    }
	GetDlgItem(IDC_EDIT1)->SetWindowText(my_str_ap_path);
    strcpy(g_sMetaComm.sDBFileOption.strAPDbpath,my_str_ap_path.GetBuffer(my_str_ap_path.GetLength()));


	{
		char path_ext_name[512];
		memset(path_ext_name,0,512);
		strcpy(path_ext_name,mystr_path.GetBuffer(mystr_path.GetLength()));
		strcat(path_ext_name, "BPLG*");
		hSearch = FindFirstFile(path_ext_name, &FileData);
		if(hSearch == INVALID_HANDLE_VALUE)
			return;
		else
		{
			my_str_bp_path.Format("%s%s",mystr_path , FileData.cFileName);
			strcpy(g_sMetaComm.sDBFileOption.strMD1Dbpath,my_str_bp_path.GetBuffer(my_str_bp_path.GetLength()));
			GetDlgItem(IDC_EDIT2)->SetWindowText(my_str_bp_path);
		}
   		


	}
	
}

void CChoosedbdlg::OnButton4() 
{
    char szFilter[]="BP Database(BPLG*.*)|*.*";

	CString mystr_path;
	WIN32_FIND_DATA FileData;
    HANDLE    hSearch;
    int        nCount=0;
    BOOL    fFinished = FALSE;    

    
	CFileDialog dlg(TRUE, NULL, NULL,
        OFN_FILEMUSTEXIST|OFN_EXPLORER|OFN_ENABLESIZING|0x10000000/*OFN_FORCESHOWHIDDEN*/,
        szFilter, this);
    dlg.m_ofn.lpstrTitle = _T("Select Modem_1 database file...");
    if(dlg.DoModal() == IDOK)
    {
        g_sMetaComm.sDBFileOption.bDBInitModem_1 = false;
        my_str_bp_path = dlg.GetPathName();
		mystr_path = my_str_bp_path;
		mystr_path.SetAt(mystr_path.ReverseFind('\\')+1,0);
    }
	GetDlgItem(IDC_EDIT2)->SetWindowText(my_str_bp_path);
	
	strcpy(g_sMetaComm.sDBFileOption.strMD1Dbpath,my_str_bp_path.GetBuffer(my_str_bp_path.GetLength()));

	
	
	{
		char path_ext_name[512];
		memset(path_ext_name,0,512);
		strcpy(path_ext_name,mystr_path.GetBuffer(mystr_path.GetLength()));
		strcat(path_ext_name, "APDB*");
		hSearch = FindFirstFile(path_ext_name, &FileData);
		if(hSearch == INVALID_HANDLE_VALUE)
			return;
		else
		{
			my_str_ap_path.Format("%s%s",mystr_path , FileData.cFileName);
			strcpy(g_sMetaComm.sDBFileOption.strAPDbpath,my_str_ap_path.GetBuffer(my_str_ap_path.GetLength()));
			GetDlgItem(IDC_EDIT1)->SetWindowText(my_str_ap_path);
		}
		
		
		
	}


	
}

BOOL CChoosedbdlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	my_str_ap_path = CString(g_sMetaComm.sDBFileOption.strAPDbpath);
	my_str_bp_path = CString(g_sMetaComm.sDBFileOption.strMD1Dbpath);
	SetDlgItemText(IDC_STR_AP_PATH,my_str_ap_path);
	SetDlgItemText(IDC_STR_BP_PATH,my_str_bp_path);
	//
	
	myversion = CString(g_sMetaComm.check_sw_ver);
	GetDlgItem(IDC_EDT_VERSION)->SetWindowText(myversion);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CChoosedbdlg::OnOK() 
{
	UpdateData(TRUE);
    // TODO: Add your control notification handler code here
	//    OnSelchangeComboTargetType();
	if (my_str_ap_path== "" ||my_str_bp_path== "")
	{
		MessageBox("please set DB file");
		return;
	}
	if (myversion == "")
	{
		MessageBox("please set DB file");
	}
	
	memset(g_sMetaComm.check_sw_ver,0x0,sizeof(g_sMetaComm.check_sw_ver));
	memcpy(g_sMetaComm.check_sw_ver,myversion.GetBuffer(myversion.GetLength()),myversion.GetLength());
	SaveParaToSetupFile();
	CDialog::OnOK();
}