This repository has been archived on 2024-03-20. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
ContactBook/CB32Doc.cpp
2024-03-20 09:28:18 -05:00

1063 lines
33 KiB
C++

// CB32Doc.cpp : implementation of the CCB32Doc class
//
#include "stdafx.h"
#include <fstream.h>
#include "CB32.h"
#include "CB32Doc.h"
#include "CB32View.h"
#include "ConvertDlg.h"
#include "Parser.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCB32Doc
IMPLEMENT_DYNCREATE(CCB32Doc, CDocument)
BEGIN_MESSAGE_MAP(CCB32Doc, CDocument)
//{{AFX_MSG_MAP(CCB32Doc)
ON_COMMAND(ID_IMPORT_CSV, OnImportCsv)
ON_COMMAND(ID_IMPORT_TAB, OnImportTab)
ON_COMMAND(ID_EXPORT_CSV, OnExportCsv)
ON_COMMAND(ID_EXPORT_TAB, OnExportTab)
//}}AFX_MSG_MAP
ON_COMMAND(ID_FILE_SEND_MAIL, OnFileSendMail)
ON_UPDATE_COMMAND_UI(ID_FILE_SEND_MAIL, OnUpdateFileSendMail)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCB32Doc construction/destruction
CCB32Doc::CCB32Doc()
{
// TODO: add one-time construction code here
}
CCB32Doc::~CCB32Doc()
{
db.ClearDatabase();
}
/////////////////////////////////////////////////////////////////////////////
// CCB32Doc serialization
void CCB32Doc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: add storing code here
}
else
{
// TODO: add loading code here
}
}
/////////////////////////////////////////////////////////////////////////////
// CCB32Doc diagnostics
#ifdef _DEBUG
void CCB32Doc::AssertValid() const
{
CDocument::AssertValid();
}
void CCB32Doc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CCB32Doc commands
BOOL CCB32Doc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
db.ClearDatabase();
return TRUE;
}
BOOL CCB32Doc::OnOpenDocument(LPCTSTR lpszPathName)
{
theApp.SetStatusMsg(IDS_LOADING);
db.ClearDatabase();
if (!db.Read(lpszPathName))
return FALSE;
UpdateIniFileWithDocPath(lpszPathName);
return TRUE;
}
BOOL CCB32Doc::OnSaveDocument(LPCTSTR lpszPathName)
{
CView* pView;
theApp.SetStatusMsg(IDS_SAVING);
db.ClearDatabase();
POSITION pos = GetFirstViewPosition();
while (pos != NULL)
{
pView = GetNextView(pos);
CCB32View* pCB32View = DYNAMIC_DOWNCAST(CCB32View, pView);
if (pCB32View != NULL)
pCB32View->MakeDatabase();
}
if (!db.Write(lpszPathName))
return FALSE;
db.ClearDatabase();
UpdateIniFileWithDocPath(lpszPathName);
SetModifiedFlag(FALSE);
theApp.SetStatusMsg(AFX_IDS_IDLEMESSAGE);
return TRUE;
}
void CCB32Doc::UpdateIniFileWithDocPath(LPCTSTR lpszPathName)
{
theApp.UpdateIniFileWithDocPath(lpszPathName);
}
void CCB32Doc::OnImportCsv()
{
CString fileName;
CFileDialog FileDlg(TRUE, NULL, NULL,
OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST,
TEXT("CSV Files (*.txt;*.csv)|*.txt; *.csv|All Files (*.*)|*.*||"),
AfxGetMainWnd());
if (FileDlg.DoModal() == IDOK)
{
fileName = FileDlg.GetPathName();
char* whitesp={"\t"};
char* breakch={","};
FileImport(fileName, whitesp, breakch);
}
}
void CCB32Doc::OnImportTab()
{
CString fileName;
CFileDialog FileDlg(TRUE, NULL, NULL,
OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST,
TEXT("TDF Files (*.txt;*.tdf)|*.txt; *.tdf|All Files (*.*)|*.*||"),
AfxGetMainWnd());
if (FileDlg.DoModal() == IDOK)
{
fileName = FileDlg.GetPathName();
char* whitesp={" "};
char* breakch={"\t"};
FileImport(fileName, whitesp, breakch);
}
}
void CCB32Doc::OnExportCsv()
{
CString fileName;
CFileDialog FileDlg(FALSE, "csv", NULL, OFN_HIDEREADONLY |
OFN_OVERWRITEPROMPT,
TEXT("CSV Files (*.txt;*.csv)|*.txt; *.csv|All Files (*.*)|*.*||"),
AfxGetMainWnd());
if (FileDlg.DoModal() == IDOK)
{
fileName = FileDlg.GetPathName();
char* breakch = {","};
FileExport(fileName, breakch);
}
}
void CCB32Doc::OnExportTab()
{
CString fileName;
CFileDialog FileDlg(FALSE, "tdf", NULL, OFN_HIDEREADONLY |
OFN_OVERWRITEPROMPT,
TEXT("TDF Files (*.txt;*.tdf)|*.txt; *.tdf|All Files (*.*)|*.*||"),
AfxGetMainWnd());
if (FileDlg.DoModal() == IDOK)
{
fileName = FileDlg.GetPathName();
char* breakch = {"\t"};
FileExport(fileName, breakch);
}
}
////////////////////////////////////////////////////////////////
// Import/Export routines
BOOL CCB32Doc::FileImport(CString fileName, char* whitesp, char* breakch)
{
CStdioFile inFile;
CFileException e;
if (!inFile.Open(fileName, CFile::modeRead |
CFile::shareDenyWrite | CFile::typeText, &e))
{
AfxThrowFileException(e.m_cause, e.m_lOsError);
return FALSE;
}
char strLine[512];
char *newline;
int strpos;
CConvertDlg convertDlg;
if (inFile.ReadString(strLine,511)!=NULL)
{
newline = _tcsstr(strLine, "\n");
strpos = newline - strLine;
if (strpos != NULL)
strLine[strpos]='\0';
convertDlg.m_xline1 = strLine;
if (theApp.GetProfileInt(_T("Preferences"),_T("RememberImp"),1))
{
convertDlg.m_xadd1 = theApp.GetProfileInt(_T("Import"),
_T("ImportAddress1"),0);
convertDlg.m_xadd2 = theApp.GetProfileInt(_T("Import"),
_T("ImportAddress2"),0);
convertDlg.m_xcell = theApp.GetProfileInt(_T("Import"),
_T("ImportCellPhone"),0);
convertDlg.m_xcity = theApp.GetProfileInt(_T("Import"),
_T("ImportCity"),0);
convertDlg.m_xcountry = theApp.GetProfileInt(_T("Import"),
_T("ImportCountry"),0);
convertDlg.m_xemail1 = theApp.GetProfileInt(_T("Import"),
_T("ImportEmail1"),0);
convertDlg.m_xemail2 = theApp.GetProfileInt(_T("Import"),
_T("ImportEmail2"),0);
convertDlg.m_xfax = theApp.GetProfileInt(_T("Import"),
_T("ImportFaxPhone"),0);
convertDlg.m_xfaxx = theApp.GetProfileInt(_T("Import"),
_T("ImportFaxExt"),0);
convertDlg.m_xfname = theApp.GetProfileInt(_T("Import"),
_T("ImportFirstname"),0);
convertDlg.m_xhomep = theApp.GetProfileInt(_T("Import"),
_T("ImportHomePhone"),0);
convertDlg.m_xhomepx = theApp.GetProfileInt(_T("Import"),
_T("ImportHomeExt"),0);
convertDlg.m_xlname = theApp.GetProfileInt(_T("Import"),
_T("ImportLastname"),0);
convertDlg.m_xmi = theApp.GetProfileInt(_T("Import"),
_T("ImportMI"),0);
convertDlg.m_xnotes = theApp.GetProfileInt(_T("Import"),
_T("ImportNotes"),0);
convertDlg.m_xpager = theApp.GetProfileInt(_T("Import"),
_T("ImportPager"),0);
convertDlg.m_xpagerc = theApp.GetProfileInt(_T("Import"),
_T("ImportPagerCard"),0);
convertDlg.m_xpagerx = theApp.GetProfileInt(_T("Import"),
_T("ImportPagerExt"),0);
convertDlg.m_xstate = theApp.GetProfileInt(_T("Import"),
_T("ImportState"),0);
convertDlg.m_xtitle = theApp.GetProfileInt(_T("Import"),
_T("ImportTitle"),0);
convertDlg.m_xweb1 = theApp.GetProfileInt(_T("Import"),
_T("ImportWeb1"),0);
convertDlg.m_xweb2 = theApp.GetProfileInt(_T("Import"),
_T("ImportWeb2"),0);
convertDlg.m_xworkp = theApp.GetProfileInt(_T("Import"),
_T("ImportWorkPhone"),0);
convertDlg.m_xworkpx = theApp.GetProfileInt(_T("Import"),
_T("ImportWorkExt"),0);
convertDlg.m_xzip = theApp.GetProfileInt(_T("Import"),
_T("ImportZip"),0);
convertDlg.m_xcellx = theApp.GetProfileInt(_T("Import"),
_T("ImportCellExt"),0);
convertDlg.m_xcomp = theApp.GetProfileInt(_T("Import"),
_T("ImportComp"),0);
convertDlg.m_xdept = theApp.GetProfileInt(_T("Import"),
_T("ImportDept"),0);
convertDlg.m_xposn = theApp.GetProfileInt(_T("Import"),
_T("ImportPosn"),0);
convertDlg.m_xmgr = theApp.GetProfileInt(_T("Import"),
_T("ImportMgr"),0);
convertDlg.m_xcadd1 = theApp.GetProfileInt(_T("Import"),
_T("ImportCAdd1"),0);
convertDlg.m_xcadd2 = theApp.GetProfileInt(_T("Import"),
_T("ImportCAdd2"),0);
}
if (convertDlg.DoModal()==IDOK)
{
theApp.SetStatusMsg(IDS_IMPORTING);
CWaitCursor wait;
POSITION posIndex;
CStringList inList;
BOOL dodata = FALSE;
char strToken[1024];
char brkused, quoted;
char *quotech={"\""}; // double quote
char escape='\\'; // "backslash" is escape
if (theApp.GetProfileInt(_T("Preferences"),_T("RememberImp"),1))
{
theApp.WriteProfileInt(_T("Import"),_T("ImportAddress1"),
convertDlg.m_xadd1);
theApp.WriteProfileInt(_T("Import"),_T("ImportAddress2"),
convertDlg.m_xadd2);
theApp.WriteProfileInt(_T("Import"),_T("ImportCellPhone"),
convertDlg.m_xcell);
theApp.WriteProfileInt(_T("Import"),_T("ImportCity"),
convertDlg.m_xcity);
theApp.WriteProfileInt(_T("Import"),_T("ImportCountry"),
convertDlg.m_xcountry);
theApp.WriteProfileInt(_T("Import"),_T("ImportEmail1"),
convertDlg.m_xemail1);
theApp.WriteProfileInt(_T("Import"),_T("ImportEmail2"),
convertDlg.m_xemail2);
theApp.WriteProfileInt(_T("Import"),_T("ImportFaxPhone"),
convertDlg.m_xfax);
theApp.WriteProfileInt(_T("Import"),_T("ImportFaxExt"),
convertDlg.m_xfaxx);
theApp.WriteProfileInt(_T("Import"),_T("ImportFirstname"),
convertDlg.m_xfname);
theApp.WriteProfileInt(_T("Import"),_T("ImportHomePhone"),
convertDlg.m_xhomep);
theApp.WriteProfileInt(_T("Import"),_T("ImportHomeExt"),
convertDlg.m_xhomepx);
theApp.WriteProfileInt(_T("Import"),_T("ImportLastname"),
convertDlg.m_xlname);
theApp.WriteProfileInt(_T("Import"),_T("ImportMI"),
convertDlg.m_xmi);
theApp.WriteProfileInt(_T("Import"),_T("ImportNotes"),
convertDlg.m_xnotes);
theApp.WriteProfileInt(_T("Import"),_T("ImportPager"),
convertDlg.m_xpager);
theApp.WriteProfileInt(_T("Import"),_T("ImportPagerCard"),
convertDlg.m_xpagerc);
theApp.WriteProfileInt(_T("Import"),_T("ImportPagerExt"),
convertDlg.m_xpagerx);
theApp.WriteProfileInt(_T("Import"),_T("ImportState"),
convertDlg.m_xstate);
theApp.WriteProfileInt(_T("Import"),_T("ImportTitle"),
convertDlg.m_xtitle);
theApp.WriteProfileInt(_T("Import"),_T("ImportWeb1"),
convertDlg.m_xweb1);
theApp.WriteProfileInt(_T("Import"),_T("ImportWeb2"),
convertDlg.m_xweb2);
theApp.WriteProfileInt(_T("Import"),_T("ImportWorkPhone"),
convertDlg.m_xworkp);
theApp.WriteProfileInt(_T("Import"),_T("ImportWorkExt"),
convertDlg.m_xworkpx);
theApp.WriteProfileInt(_T("Import"),_T("ImportZip"),
convertDlg.m_xzip);
theApp.WriteProfileInt(_T("Import"),_T("ImportCellExt"),
convertDlg.m_xcellx);
theApp.WriteProfileInt(_T("Import"),_T("ImportComp"),
convertDlg.m_xcomp);
theApp.WriteProfileInt(_T("Import"),_T("ImportDept"),
convertDlg.m_xdept);
theApp.WriteProfileInt(_T("Import"),_T("ImportPosn"),
convertDlg.m_xposn);
theApp.WriteProfileInt(_T("Import"),_T("ImportMgr"),
convertDlg.m_xmgr);
theApp.WriteProfileInt(_T("Import"),_T("ImportCAdd1"),
convertDlg.m_xcadd1);
theApp.WriteProfileInt(_T("Import"),_T("ImportCAdd2"),
convertDlg.m_xcadd2);
}
db.ClearDatabase();
inFile.SeekToBegin();
int i=0;
while(inFile.ReadString(strLine, 1023)!=NULL)
{
newline = strstr(strLine, "\n");
strpos = newline - strLine;
if (strpos != NULL)
strLine[strpos]='\0';
int z=0, next=0;
BOOL addexpr = FALSE;
CExpr *expr = new CExpr(_T("contact"));
inList.RemoveAll();
while(parser(0,strToken,sizeof(strLine),strLine,whitesp,breakch,
quotech,escape,&brkused,&next,&quoted)==0)
{
inList.AddTail(strToken);
z++;
}
if (z>0)
z++;
if (convertDlg.m_xlname>0 && convertDlg.m_xlname<z)
{
posIndex = inList.FindIndex(convertDlg.m_xlname-1);
expr->AddAttributeValueString(_T("LastName"), inList.GetAt(posIndex));
addexpr = TRUE;
}
if (convertDlg.m_xfname>0 && convertDlg.m_xfname<z)
{
posIndex = inList.FindIndex(convertDlg.m_xfname-1);
expr->AddAttributeValueString("FirstName", inList.GetAt(posIndex));
addexpr = TRUE;
}
if (convertDlg.m_xmi>0 && convertDlg.m_xmi<z)
{
posIndex = inList.FindIndex(convertDlg.m_xmi-1);
expr->AddAttributeValueString("MiddleInitial", inList.GetAt(posIndex));
addexpr = TRUE;
}
if (convertDlg.m_xtitle>0 && convertDlg.m_xtitle<z)
{
posIndex = inList.FindIndex(convertDlg.m_xtitle-1);
expr->AddAttributeValueString("Title", inList.GetAt(posIndex));
addexpr = TRUE;
}
if (convertDlg.m_xadd1>0 && convertDlg.m_xadd1<z)
{
posIndex = inList.FindIndex(convertDlg.m_xadd1-1);
expr->AddAttributeValueString("Address1", inList.GetAt(posIndex));
addexpr = TRUE;
}
if (convertDlg.m_xadd2>0 && convertDlg.m_xadd2<z)
{
posIndex = inList.FindIndex(convertDlg.m_xadd2-1);
expr->AddAttributeValueString("Address2", inList.GetAt(posIndex));
addexpr = TRUE;
}
if (convertDlg.m_xcity>0 && convertDlg.m_xcity<z)
{
posIndex = inList.FindIndex(convertDlg.m_xcity-1);
expr->AddAttributeValueString("City", inList.GetAt(posIndex));
addexpr = TRUE;
}
if (convertDlg.m_xcountry>0 && convertDlg.m_xcountry<z)
{
posIndex = inList.FindIndex(convertDlg.m_xcountry-1);
expr->AddAttributeValueString("Country", inList.GetAt(posIndex));
addexpr = TRUE;
}
if (convertDlg.m_xstate>0 && convertDlg.m_xstate<z)
{
posIndex = inList.FindIndex(convertDlg.m_xstate-1);
expr->AddAttributeValueString("State", inList.GetAt(posIndex));
addexpr = TRUE;
}
if (convertDlg.m_xzip>0 && convertDlg.m_xzip<z)
{
posIndex = inList.FindIndex(convertDlg.m_xzip-1);
expr->AddAttributeValueString("ZipCode", inList.GetAt(posIndex));
addexpr = TRUE;
}
if (convertDlg.m_xcomp>0 && convertDlg.m_xcomp<z)
{
posIndex = inList.FindIndex(convertDlg.m_xcomp-1);
expr->AddAttributeValueString("Company", inList.GetAt(posIndex));
addexpr = TRUE;
}
if (convertDlg.m_xdept>0 && convertDlg.m_xdept<z)
{
posIndex = inList.FindIndex(convertDlg.m_xdept-1);
expr->AddAttributeValueString("Department", inList.GetAt(posIndex));
addexpr = TRUE;
}
if (convertDlg.m_xposn>0 && convertDlg.m_xposn<z)
{
posIndex = inList.FindIndex(convertDlg.m_xposn-1);
expr->AddAttributeValueString("Position", inList.GetAt(posIndex));
addexpr = TRUE;
}
if (convertDlg.m_xmgr>0 && convertDlg.m_xmgr<z)
{
posIndex = inList.FindIndex(convertDlg.m_xmgr-1);
expr->AddAttributeValueString("Manager", inList.GetAt(posIndex));
addexpr = TRUE;
}
if (convertDlg.m_xcadd1>0 && convertDlg.m_xcadd1<z)
{
posIndex = inList.FindIndex(convertDlg.m_xcadd1-1);
expr->AddAttributeValueString("Additional1", inList.GetAt(posIndex));
addexpr = TRUE;
}
if (convertDlg.m_xcadd2>0 && convertDlg.m_xcadd2<z)
{
posIndex = inList.FindIndex(convertDlg.m_xcadd2-1);
expr->AddAttributeValueString("Additional2", inList.GetAt(posIndex));
addexpr = TRUE;
}
if (convertDlg.m_xhomep>0 && convertDlg.m_xhomep<z)
{
posIndex = inList.FindIndex(convertDlg.m_xhomep-1);
expr->AddAttributeValueString("HomePhone", inList.GetAt(posIndex));
addexpr = TRUE;
}
if (convertDlg.m_xhomepx>0 && convertDlg.m_xhomepx<z)
{
posIndex = inList.FindIndex(convertDlg.m_xhomepx-1);
expr->AddAttributeValueString("HomeExt", inList.GetAt(posIndex));
addexpr = TRUE;
}
if (convertDlg.m_xworkp>0 && convertDlg.m_xworkp<z)
{
posIndex = inList.FindIndex(convertDlg.m_xworkp-1);
expr->AddAttributeValueString("WorkPhone", inList.GetAt(posIndex));
addexpr = TRUE;
}
if (convertDlg.m_xworkpx>0 && convertDlg.m_xworkpx<z)
{
posIndex = inList.FindIndex(convertDlg.m_xworkpx-1);
expr->AddAttributeValueString("WorkExt", inList.GetAt(posIndex));
addexpr = TRUE;
}
if (convertDlg.m_xcell>0 && convertDlg.m_xcell<z)
{
posIndex = inList.FindIndex(convertDlg.m_xcell-1);
expr->AddAttributeValueString("CellPhone", inList.GetAt(posIndex));
addexpr = TRUE;
}
if (convertDlg.m_xcellx>0 && convertDlg.m_xcellx<z)
{
posIndex = inList.FindIndex(convertDlg.m_xcellx-1);
expr->AddAttributeValueString("CellExt", inList.GetAt(posIndex));
addexpr = TRUE;
}
if (convertDlg.m_xpager>0 && convertDlg.m_xpager<z)
{
posIndex = inList.FindIndex(convertDlg.m_xpager-1);
expr->AddAttributeValueString("Pager", inList.GetAt(posIndex));
addexpr = TRUE;
}
if (convertDlg.m_xpagerc>0 && convertDlg.m_xpagerc<z)
{
posIndex = inList.FindIndex(convertDlg.m_xpagerc-1);
expr->AddAttributeValueString("PagerCard", inList.GetAt(posIndex));
addexpr = TRUE;
}
if (convertDlg.m_xpagerx>0 && convertDlg.m_xpagerx<z)
{
posIndex = inList.FindIndex(convertDlg.m_xpagerx-1);
expr->AddAttributeValueString("PagerExt", inList.GetAt(posIndex));
addexpr = TRUE;
}
if (convertDlg.m_xfax>0 && convertDlg.m_xfax<z)
{
posIndex = inList.FindIndex(convertDlg.m_xfax-1);
expr->AddAttributeValueString("FaxPhone", inList.GetAt(posIndex));
addexpr = TRUE;
}
if (convertDlg.m_xfaxx>0 && convertDlg.m_xfaxx<z)
{
posIndex = inList.FindIndex(convertDlg.m_xfaxx-1);
expr->AddAttributeValueString("FaxExt", inList.GetAt(posIndex));
addexpr = TRUE;
}
if (convertDlg.m_xemail1>0 && convertDlg.m_xemail1<z)
{
posIndex = inList.FindIndex(convertDlg.m_xemail1-1);
expr->AddAttributeValueString("Email1", inList.GetAt(posIndex));
addexpr = TRUE;
}
if (convertDlg.m_xemail2>0 && convertDlg.m_xemail2<z)
{
posIndex = inList.FindIndex(convertDlg.m_xemail2-1);
expr->AddAttributeValueString("Email2", inList.GetAt(posIndex));
addexpr = TRUE;
}
if (convertDlg.m_xweb1>0 && convertDlg.m_xweb1<z)
{
posIndex = inList.FindIndex(convertDlg.m_xweb1-1);
expr->AddAttributeValueString("Web1", inList.GetAt(posIndex));
addexpr = TRUE;
}
if (convertDlg.m_xweb2>0 && convertDlg.m_xweb2<z)
{
posIndex = inList.FindIndex(convertDlg.m_xweb2-1);
expr->AddAttributeValueString("Web2", inList.GetAt(posIndex));
addexpr = TRUE;
}
if (convertDlg.m_xnotes>0 && convertDlg.m_xnotes<z)
{
posIndex = inList.FindIndex(convertDlg.m_xnotes-1);
expr->AddAttributeValueString("Notes", inList.GetAt(posIndex));
addexpr = TRUE;
}
if (addexpr)
{
db.Append(expr);
dodata = TRUE;
i++;
}
}
if (dodata)
{
CView* pView;
POSITION pos = GetFirstViewPosition();
while (pos != NULL)
{
pView = GetNextView(pos);
CCB32View* pCB32View = DYNAMIC_DOWNCAST(CCB32View, pView);
if (pCB32View != NULL)
pCB32View->AddDatabase();
}
SetModifiedFlag(TRUE);
inFile.Close();
CString strTemp;
strTemp.Format(IDS_IMPCOUNT, i);
AfxMessageBox(strTemp, MB_ICONINFORMATION);
return TRUE;
}
else // no data to make dbf
{
inFile.Close();
AfxMessageBox(IDS_NOIMPORT);
return FALSE;
}
theApp.SetStatusMsg(AFX_IDS_IDLEMESSAGE);
}
else // chose CANCEL from dialog
{
inFile.Close();
return FALSE;
}
}
else // initial line was NULL
{
inFile.Close();
AfxMessageBox(IDS_NOREAD);
return FALSE;
}
}
BOOL CCB32Doc::FileExport(CString fileName, char* breakch)
{
CStdioFile outFile;
CFileException e;
if (!outFile.Open(fileName, CFile::modeCreate | CFile::modeWrite |
CFile::shareDenyRead | CFile::shareDenyWrite |
CFile::typeText, &e))
{
AfxThrowFileException(e.m_cause, e.m_lOsError);
return FALSE;
}
CConvertDlg convertDlg;
if (theApp.GetProfileInt(_T("Preferences"),_T("RememberExp"),1))
{
convertDlg.m_xadd1 = theApp.GetProfileInt(_T("Export"),
_T("ExportAddress1"),0);
convertDlg.m_xadd2 = theApp.GetProfileInt(_T("Export"),
_T("ExportAddress2"),0);
convertDlg.m_xcell = theApp.GetProfileInt(_T("Export"),
_T("ExportCellPhone"),0);
convertDlg.m_xcity = theApp.GetProfileInt(_T("Export"),
_T("ExportCity"),0);
convertDlg.m_xcountry = theApp.GetProfileInt(_T("Export"),
_T("ExportCountry"),0);
convertDlg.m_xemail1 = theApp.GetProfileInt(_T("Export"),
_T("ExportEmail1"),0);
convertDlg.m_xemail2 = theApp.GetProfileInt(_T("Export"),
_T("ExportEmail2"),0);
convertDlg.m_xfax = theApp.GetProfileInt(_T("Export"),
_T("ExportFaxPhone"),0);
convertDlg.m_xfaxx = theApp.GetProfileInt(_T("Export"),
_T("ExportFaxExt"),0);
convertDlg.m_xfname = theApp.GetProfileInt(_T("Export"),
_T("ExportFirstname"),0);
convertDlg.m_xhomep = theApp.GetProfileInt(_T("Export"),
_T("ExportHomePhone"),0);
convertDlg.m_xhomepx = theApp.GetProfileInt(_T("Export"),
_T("ExportHomeExt"),0);
convertDlg.m_xlname = theApp.GetProfileInt(_T("Export"),
_T("ExportLastname"),0);
convertDlg.m_xmi = theApp.GetProfileInt(_T("Export"),
_T("ExportMI"),0);
convertDlg.m_xnotes = theApp.GetProfileInt(_T("Export"),
_T("ExportNotes"),0);
convertDlg.m_xpager = theApp.GetProfileInt(_T("Export"),
_T("ExportPager"),0);
convertDlg.m_xpagerc = theApp.GetProfileInt(_T("Export"),
_T("ExportPagerCard"),0);
convertDlg.m_xpagerx = theApp.GetProfileInt(_T("Export"),
_T("ExportPagerExt"),0);
convertDlg.m_xstate = theApp.GetProfileInt(_T("Export"),
_T("ExportState"),0);
convertDlg.m_xtitle = theApp.GetProfileInt(_T("Export"),
_T("ExportTitle"),0);
convertDlg.m_xweb1 = theApp.GetProfileInt(_T("Export"),
_T("ExportWeb1"),0);
convertDlg.m_xweb2 = theApp.GetProfileInt(_T("Export"),
_T("ExportWeb2"),0);
convertDlg.m_xworkp = theApp.GetProfileInt(_T("Export"),
_T("ExportWorkPhone"),0);
convertDlg.m_xworkpx = theApp.GetProfileInt(_T("Export"),
_T("ExportWorkExt"),0);
convertDlg.m_xzip = theApp.GetProfileInt(_T("Export"),
_T("ExportZip"),0);
convertDlg.m_xcellx = theApp.GetProfileInt(_T("Export"),
_T("ExportCellExt"),0);
convertDlg.m_xcomp = theApp.GetProfileInt(_T("Export"),
_T("ExportComp"),0);
convertDlg.m_xdept = theApp.GetProfileInt(_T("Export"),
_T("ExportDept"),0);
convertDlg.m_xposn = theApp.GetProfileInt(_T("Export"),
_T("ExportPosn"),0);
convertDlg.m_xmgr = theApp.GetProfileInt(_T("Export"),
_T("ExportMgr"),0);
convertDlg.m_xcadd1 = theApp.GetProfileInt(_T("Export"),
_T("ExportCAdd1"),0);
convertDlg.m_xcadd2 = theApp.GetProfileInt(_T("Export"),
_T("ExportCAdd2"),0);
}
if (convertDlg.DoModal()==IDOK)
{
theApp.SetStatusMsg(IDS_EXPORTING);
CWaitCursor wait;
CView* pView;
if (theApp.GetProfileInt(_T("Preferences"),_T("RememberExp"),1))
{
theApp.WriteProfileInt(_T("Export"),_T("ExportAddress1"),
convertDlg.m_xadd1);
theApp.WriteProfileInt(_T("Export"),_T("ExportAddress2"),
convertDlg.m_xadd2);
theApp.WriteProfileInt(_T("Export"),_T("ExportCellPhone"),
convertDlg.m_xcell);
theApp.WriteProfileInt(_T("Export"),_T("ExportCity"),
convertDlg.m_xcity);
theApp.WriteProfileInt(_T("Export"),_T("ExportCountry"),
convertDlg.m_xcountry);
theApp.WriteProfileInt(_T("Export"),_T("ExportEmail1"),
convertDlg.m_xemail1);
theApp.WriteProfileInt(_T("Export"),_T("ExportEmail2"),
convertDlg.m_xemail2);
theApp.WriteProfileInt(_T("Export"),_T("ExportFaxPhone"),
convertDlg.m_xfax);
theApp.WriteProfileInt(_T("Export"),_T("ExportFaxExt"),
convertDlg.m_xfaxx);
theApp.WriteProfileInt(_T("Export"),_T("ExportFirstname"),
convertDlg.m_xfname);
theApp.WriteProfileInt(_T("Export"),_T("ExportHomePhone"),
convertDlg.m_xhomep);
theApp.WriteProfileInt(_T("Export"),_T("ExportHomeExt"),
convertDlg.m_xhomepx);
theApp.WriteProfileInt(_T("Export"),_T("ExportLastname"),
convertDlg.m_xlname);
theApp.WriteProfileInt(_T("Export"),_T("ExportMI"),
convertDlg.m_xmi);
theApp.WriteProfileInt(_T("Export"),_T("ExportNotes"),
convertDlg.m_xnotes);
theApp.WriteProfileInt(_T("Export"),_T("ExportPager"),
convertDlg.m_xpager);
theApp.WriteProfileInt(_T("Export"),_T("ExportPagerCard"),
convertDlg.m_xpagerc);
theApp.WriteProfileInt(_T("Export"),_T("ExportPagerExt"),
convertDlg.m_xpagerx);
theApp.WriteProfileInt(_T("Export"),_T("ExportState"),
convertDlg.m_xstate);
theApp.WriteProfileInt(_T("Export"),_T("ExportTitle"),
convertDlg.m_xtitle);
theApp.WriteProfileInt(_T("Export"),_T("ExportWeb1"),
convertDlg.m_xweb1);
theApp.WriteProfileInt(_T("Export"),_T("ExportWeb2"),
convertDlg.m_xweb2);
theApp.WriteProfileInt(_T("Export"),_T("ExportWorkPhone"),
convertDlg.m_xworkp);
theApp.WriteProfileInt(_T("Export"),_T("ExportWorkExt"),
convertDlg.m_xworkpx);
theApp.WriteProfileInt(_T("Export"),_T("ExportZip"),
convertDlg.m_xzip);
theApp.WriteProfileInt(_T("Export"),_T("ExportCellExt"),
convertDlg.m_xcellx);
theApp.WriteProfileInt(_T("Export"),_T("ExportComp"),
convertDlg.m_xcomp);
theApp.WriteProfileInt(_T("Export"),_T("ExportDept"),
convertDlg.m_xdept);
theApp.WriteProfileInt(_T("Export"),_T("ExportPosn"),
convertDlg.m_xposn);
theApp.WriteProfileInt(_T("Export"),_T("ExportMgr"),
convertDlg.m_xmgr);
theApp.WriteProfileInt(_T("Export"),_T("ExportCAdd1"),
convertDlg.m_xcadd1);
theApp.WriteProfileInt(_T("Export"),_T("ExportCAdd2"),
convertDlg.m_xcadd2);
}
// add firstline identifier
db.ClearDatabase();
CExpr *expr = new CExpr("contact");
expr->AddAttributeValueString(_T("LastName"), _T("LASTNAME"));
expr->AddAttributeValueString("FirstName", "FIRSTNAME");
expr->AddAttributeValueString("MiddleInitial", "MI");
expr->AddAttributeValueString("Title", "TITLE");
expr->AddAttributeValueString("Address1", "ADDRESS1");
expr->AddAttributeValueString("Address2", "ADDRESS2");
expr->AddAttributeValueString("City", "CITY");
expr->AddAttributeValueString("Country", "COUNTRY");
expr->AddAttributeValueString("State", "STATE");
expr->AddAttributeValueString("ZipCode", "ZIPCODE");
expr->AddAttributeValueString("Company", "COMPANY");
expr->AddAttributeValueString("Department", "DEPARTMENT");
expr->AddAttributeValueString("Position", "POSITION");
expr->AddAttributeValueString("Manager", "MANAGER");
expr->AddAttributeValueString("Additional1", "ADDITIONAL1");
expr->AddAttributeValueString("Additional2", "ADDITIONAL2");
expr->AddAttributeValueString("HomePhone", "HOMEPHONE");
expr->AddAttributeValueString("HomeExt", "HOMEEXT");
expr->AddAttributeValueString("WorkPhone", "WORKPHONE");
expr->AddAttributeValueString("WorkExt", "WORKEXT");
expr->AddAttributeValueString("CellPhone", "CELLPHONE");
expr->AddAttributeValueString("CellExt", "CELLEXT");
expr->AddAttributeValueString("Pager", "PAGER");
expr->AddAttributeValueString("PagerCard", "PAGERCARD");
expr->AddAttributeValueString("PagerExt", "PAGEREXT");
expr->AddAttributeValueString("FaxPhone", "FAXPHONE");
expr->AddAttributeValueString("FaxExt", "FAXEXT");
expr->AddAttributeValueString("Email1", "EMAIL1");
expr->AddAttributeValueString("Email2", "EMAIL2");
expr->AddAttributeValueString("Web1", "WEB1");
expr->AddAttributeValueString("Web2", "WEB2");
expr->AddAttributeValueString("Notes", "NOTES");
db.Append(expr);
POSITION pos = GetFirstViewPosition();
while (pos != NULL)
{
pView = GetNextView(pos);
CCB32View* pCB32View = DYNAMIC_DOWNCAST(CCB32View, pView);
if (pCB32View != NULL)
pCB32View->MakeDatabase();
}
CStringArray dataArray;
CString strTemp;
int i=0;
dataArray.SetSize(32);
wxNode *node = db.First();
while (node)
{
dataArray.RemoveAll();
CExpr *expr = (CExpr *)node->Data();
if (convertDlg.m_xlname>0)
{
expr->GetAttributeValue(_T("LastName"), strTemp);
dataArray.SetAtGrow(convertDlg.m_xlname, strTemp);
}
if (convertDlg.m_xfname>0)
{
expr->GetAttributeValue("FirstName", strTemp);
dataArray.SetAtGrow(convertDlg.m_xfname, strTemp);
}
if (convertDlg.m_xmi>0)
{
expr->GetAttributeValue("MiddleInitial", strTemp);
dataArray.SetAtGrow(convertDlg.m_xmi, strTemp);
}
if (convertDlg.m_xtitle>0)
{
expr->GetAttributeValue("Title", strTemp);
dataArray.SetAtGrow(convertDlg.m_xtitle, strTemp);
}
if (convertDlg.m_xadd1>0)
{
expr->GetAttributeValue("Address1", strTemp);
dataArray.SetAtGrow(convertDlg.m_xadd1, strTemp);
}
if (convertDlg.m_xadd2>0)
{
expr->GetAttributeValue("Address2", strTemp);
dataArray.SetAtGrow(convertDlg.m_xadd2, strTemp);
}
if (convertDlg.m_xcity>0)
{
expr->GetAttributeValue("City", strTemp);
dataArray.SetAtGrow(convertDlg.m_xcity, strTemp);
}
if (convertDlg.m_xcountry>0)
{
expr->GetAttributeValue("Country", strTemp);
dataArray.SetAtGrow(convertDlg.m_xcountry, strTemp);
}
if (convertDlg.m_xstate>0)
{
expr->GetAttributeValue("State", strTemp);
dataArray.SetAtGrow(convertDlg.m_xstate, strTemp);
}
if (convertDlg.m_xzip>0)
{
expr->GetAttributeValue("ZipCode", strTemp);
dataArray.SetAtGrow(convertDlg.m_xzip, strTemp);
}
if (convertDlg.m_xcomp>0)
{
expr->GetAttributeValue("Company", strTemp);
dataArray.SetAtGrow(convertDlg.m_xcomp, strTemp);
}
if (convertDlg.m_xdept>0)
{
expr->GetAttributeValue("Department", strTemp);
dataArray.SetAtGrow(convertDlg.m_xdept, strTemp);
}
if (convertDlg.m_xposn>0)
{
expr->GetAttributeValue("Position", strTemp);
dataArray.SetAtGrow(convertDlg.m_xposn, strTemp);
}
if (convertDlg.m_xmgr>0)
{
expr->GetAttributeValue("Manager", strTemp);
dataArray.SetAtGrow(convertDlg.m_xmgr, strTemp);
}
if (convertDlg.m_xcadd1>0)
{
expr->GetAttributeValue("Additional1", strTemp);
dataArray.SetAtGrow(convertDlg.m_xcadd1, strTemp);
}
if (convertDlg.m_xcadd2>0)
{
expr->GetAttributeValue("Additional2", strTemp);
dataArray.SetAtGrow(convertDlg.m_xcadd2, strTemp);
}
if (convertDlg.m_xhomep>0)
{
expr->GetAttributeValue("HomePhone", strTemp);
dataArray.SetAtGrow(convertDlg.m_xhomep, strTemp);
}
if (convertDlg.m_xhomepx>0)
{
expr->GetAttributeValue("HomeExt", strTemp);
dataArray.SetAtGrow(convertDlg.m_xhomepx, strTemp);
}
if (convertDlg.m_xworkp>0)
{
expr->GetAttributeValue("WorkPhone", strTemp);
dataArray.SetAtGrow(convertDlg.m_xworkp, strTemp);
}
if (convertDlg.m_xworkpx>0)
{
expr->GetAttributeValue("WorkExt", strTemp);
dataArray.SetAtGrow(convertDlg.m_xworkpx, strTemp);
}
if (convertDlg.m_xcell>0)
{
expr->GetAttributeValue("CellPhone", strTemp);
dataArray.SetAtGrow(convertDlg.m_xcell, strTemp);
}
if (convertDlg.m_xcellx>0)
{
expr->GetAttributeValue("CellExt", strTemp);
dataArray.SetAtGrow(convertDlg.m_xcellx, strTemp);
}
if (convertDlg.m_xpager>0)
{
expr->GetAttributeValue("Pager", strTemp);
dataArray.SetAtGrow(convertDlg.m_xpager, strTemp);
}
if (convertDlg.m_xpagerc>0)
{
expr->GetAttributeValue("PagerCard", strTemp);
dataArray.SetAtGrow(convertDlg.m_xpagerc, strTemp);
}
if (convertDlg.m_xpagerx>0)
{
expr->GetAttributeValue("PagerExt", strTemp);
dataArray.SetAtGrow(convertDlg.m_xpagerx, strTemp);
}
if (convertDlg.m_xfax>0)
{
expr->GetAttributeValue("FaxPhone", strTemp);
dataArray.SetAtGrow(convertDlg.m_xfax, strTemp);
}
if (convertDlg.m_xfaxx>0)
{
expr->GetAttributeValue("FaxExt", strTemp);
dataArray.SetAtGrow(convertDlg.m_xfaxx, strTemp);
}
if (convertDlg.m_xemail1>0)
{
expr->GetAttributeValue("Email1", strTemp);
dataArray.SetAtGrow(convertDlg.m_xemail1, strTemp);
}
if (convertDlg.m_xemail2>0)
{
expr->GetAttributeValue("Email2", strTemp);
dataArray.SetAtGrow(convertDlg.m_xemail2, strTemp);
}
if (convertDlg.m_xweb1>0)
{
expr->GetAttributeValue("Web1", strTemp);
dataArray.SetAtGrow(convertDlg.m_xweb1, strTemp);
}
if (convertDlg.m_xweb2>0)
{
expr->GetAttributeValue("Web2", strTemp);
dataArray.SetAtGrow(convertDlg.m_xweb2, strTemp);
}
if (convertDlg.m_xnotes>0)
{
expr->GetAttributeValue("Notes", strTemp);
dataArray.SetAtGrow(convertDlg.m_xnotes, strTemp);
}
dataArray.FreeExtra();
strTemp.Empty();
int total = dataArray.GetUpperBound();
if (total > -1)
{
for (int z=1;z <= total;z++)
{
strTemp += "\""; //add before quote
strTemp += dataArray.GetAt(z); // add data
strTemp += "\""; // add after quote
strTemp += breakch; // add break char
}
if (!strTemp.IsEmpty())
{
strTemp += "\n"; // add termintor
outFile.WriteString(strTemp);
i++;
}
}
node = node->Next();
}
db.ClearDatabase();
outFile.Close();
CString strTemp2;
strTemp2.Format(IDS_EXPCOUNT, i);
AfxMessageBox(strTemp2, MB_ICONINFORMATION);
theApp.SetStatusMsg(AFX_IDS_IDLEMESSAGE);
return TRUE;
}
else // chose CANCEL from ConvertDlg
{
outFile.Close();
return FALSE;
}
}