Files

1119 lines
23 KiB
C++

// XferDlg.cpp : implementation file
//
#include "stdafx.h"
#include "sp.h"
#include "XferDlg.h"
#include "stringparser.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CXferDlg dialog
CXferDlg::CXferDlg(CWnd* pParent /*=NULL*/)
: CDialog(CXferDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CXferDlg)
//}}AFX_DATA_INIT
m_pApp = (CSpApp*)AfxGetApp();
//Initialize recordset pointers
rs=m_pApp->rsPool->GetRS("CXferDlg RS");
}
CXferDlg::~CXferDlg()
{
m_pApp->rsPool->ReleaseRS(&rs->m_nID);
}
void CXferDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CXferDlg)
DDX_Control(pDX, IDC_CBFIELDS, m_cbFields);
DDX_Control(pDX, IDC_EDPATH, m_edPath);
DDX_Control(pDX, IDC_CKFIRSTROWFIELDNAMES, m_ckFirstRowFieldNames);
DDX_Control(pDX, IDC_CBTEMPLATE, m_cbTemplates);
DDX_Control(pDX, IDC_CBDELIMITER, m_cbDelimiters);
DDX_Control(pDX, IDC_LIST1, m_ls);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CXferDlg, CDialog)
//{{AFX_MSG_MAP(CXferDlg)
ON_COMMAND(ID_XFER_EXIT, OnXferExit)
ON_COMMAND(ID_XFER_SELECT_EXPORT_FILE, OnXferSelectExportFile)
ON_COMMAND(ID_XFER_SELECT_IMPORT_DATA, OnXferSelectImportData)
ON_CBN_CLOSEUP(IDC_CBTEMPLATE, OnCloseupCbtemplate)
ON_COMMAND(ID_XFER_SAMPLE_EXPORT_DATA, OnXferSampleExportData)
ON_CBN_CLOSEUP(IDC_CBFIELDS, OnCloseupCbfields)
ON_COMMAND(ID_XFER_EXPORT_SCREEN, OnXferExportScreen)
ON_COMMAND(ID_XFER_EXPORT_FILE, OnXferExportFile)
ON_COMMAND(ID_XFER_SAMPLE_IMPORT_DATA, OnXferSampleImportData)
ON_COMMAND(ID_XFER_IMPORT, OnXferImport)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CXferDlg message handlers
BOOL CXferDlg::OnInitDialog()
{
CDialog::OnInitDialog();
//change list control to allow drag n' drop
m_ls.SetExtendedStyle(m_ls.GetExtendedStyle()|LVS_EX_HEADERDRAGDROP);
CMenu* mmenu = GetMenu();
if(m_bExportMode)
{
mmenu->EnableMenuItem(0, MF_BYPOSITION | MF_DISABLED | MF_GRAYED);
}
else
{
mmenu->EnableMenuItem(1, MF_BYPOSITION | MF_DISABLED | MF_GRAYED);
}
m_strLastTemplate.Empty();
FillDelimiters();
FillTemplateList();
//===================================================
// SET WINDOW SIZE TO MATCH WORK AREA
ShowWindow(SW_SHOWMAXIMIZED);
CRect workarea;
SystemParametersInfo(SPI_GETWORKAREA,0,&workarea,0);
SetWindowPos(NULL,workarea.left,workarea.top,workarea.Width(),workarea.Height(),SWP_NOZORDER);
CRect rectCtl,rectWhole;
GetWindowRect(rectWhole);
int nOffset=rectWhole.top;
m_ls.GetWindowRect(rectCtl);
rectCtl.right=rectWhole.right-73;
rectCtl.top-=nOffset;
rectCtl.left=13;
rectCtl.bottom=rectWhole.bottom-50-nOffset;
m_ls.MoveWindow(rectCtl,TRUE);
//===================================================
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
//fill field chooser combo box
void CXferDlg::FillAvailableFields()
{
//CStringParser p(m_strAvailableFields, ',', '\"');
CStringParser p(m_strFields, ',', '\"');
BOOL BSelected;
CString sBuffer = "";
int nCount = p.GetCount();
m_cbFields.ResetContent();
if (nCount > 0)
{
for (int i = 1; i <= nCount; i++)
{
sBuffer = p.GetField(i);
sBuffer.Remove(_T('\"'));
if(sBuffer.Left(1)=="+")
{
BSelected=TRUE;
sBuffer.TrimLeft('+');
}
else
{
BSelected=FALSE;
sBuffer.TrimLeft('-');
}
m_cbFields.AddString(sBuffer);
m_cbFields.SetCheck(i-1,BSelected);
}
}
}
//fill template list
void CXferDlg::FillTemplateList()
{
CString q, strData;//,strIndex;
//long lData;
//fill templates
m_cbTemplates.Clear();
q.Format("SELECT xfertempl.* FROM xfertempl WHERE (((xfertempl.import)=%s)) ORDER BY xfertempl.name;",m_bExportMode ? "False":"True");
rs->QueryReadOnly(q);
if(!rs->IsEmpty())
{
do
{
rs->FetchField("name",&strData);
//rs->FetchField("table",&lData);
//strIndex.Format("%u",lData);
m_cbTemplates.AddRow(strData,strData);
}while(rs->MoveForward());
m_cbTemplates.SetCurSel(0);
}
OnCloseupCbtemplate();
}
void CXferDlg::OnXferExit()
{
CDialog::OnOK();
}
void CXferDlg::OnXferSelectExportFile()
{
GetFile(false);
}
void CXferDlg::OnXferSelectImportData()
{
GetFile(true);
}
void CXferDlg::GetFile(bool bOpen)
{
static char BASED_CODE szFilter[] = "Text files (*.txt,*.asc,*.tab,*.csv,*.iif)|*.txt;*.asc;*.tab;*.csv;*.iif|All Files (*.*)|*.*||";
CString ReportSelected;
CFileDialog f(bOpen,"txt",NULL,OFN_HIDEREADONLY,szFilter,NULL);
f.DoModal();
m_strPath=f.GetPathName();
if(m_strPath.GetLength()>0)
m_edPath.SetWindowText(m_strPath);
}
void CXferDlg::OnCloseupCbtemplate()
{
CString q,strData;
bool bData;
strData=m_cbTemplates.GetCurrentRowText();
if(strData!=m_strLastTemplate)
m_strLastTemplate=strData;
else
return;
if(strData.IsEmpty()) return;
//q.Format("SELECT xfertempl.* FROM xfertempl WHERE (((xfertempl.name)=\"%s\"));",m_cbTemplates.GetCurrentRowText());
q.Format("SELECT xfertempl.* FROM xfertempl WHERE (((xfertempl.name)=\"%s\"));",m_cbTemplates.GetCurrentRowText());
//m_pApp->ShowStuff(q);
rs->QueryReadOnly(q);
rs->FetchField("fields",&m_strFields);
rs->FetchField("table",&m_strCurrentTable);
rs->FetchField("sql",&m_strSQL);
rs->FetchField("delimiter",&strData);
m_cbDelimiters.Select(strData);
rs->FetchField("fieldnames",&bData);
m_ckFirstRowFieldNames.SetCheck(bData?TRUE:FALSE);
rs->FetchField("path",&m_strPath);
m_edPath.SetWindowText(m_strPath);
if(m_bExportMode)
{
FillAvailableFields();
SetColumns(',');
}
else//Set import mode control availability depending upon type
{
m_ckFirstRowFieldNames.EnableWindow(TRUE);
m_cbDelimiters.EnableWindow(TRUE);
m_cbFields.EnableWindow(TRUE);
if(m_strCurrentTable=="QBCLIENTS")
{
m_ckFirstRowFieldNames.EnableWindow(FALSE);
m_cbDelimiters.EnableWindow(FALSE);
m_cbFields.EnableWindow(FALSE);
}
}
}
void CXferDlg::FillDelimiters()
{
m_cbDelimiters.Clear();
m_cbDelimiters.AddRow("Comma",",");
m_cbDelimiters.AddRow("Tab","T");
m_cbDelimiters.AddRow("Space","S");
m_cbDelimiters.AddRow("Semicolon",";");
m_cbDelimiters.Select(",");
}
//Fill all columns
void CXferDlg::SetColumns(char chDelimiter)
{
m_ls.DeleteAllItems();
int nColumnCount = m_ls.GetHeaderCtrl()->GetItemCount();
// Delete all of the columns.
for (int i=0;i < nColumnCount;i++)
{
m_ls.DeleteColumn(0);
}
CStringParser p;
if(m_strFields.Find("\"")>-1)
p.ResetOriginalString(m_strFields, chDelimiter, '\"');
else
p.ResetOriginalString(m_strFields, chDelimiter);
CString sBuffer = "";
int nCount = p.GetCount();
if (nCount > 0)
{
for (int i = 1; i <= nCount; i++)
{
sBuffer = p.GetField(i);
sBuffer.Remove(_T('\"'));
if(sBuffer.Left(1)=="-")
{
sBuffer.TrimLeft('-');
sBuffer="---"+sBuffer;
m_ls.InsertColumn(i-1,sBuffer,LVCFMT_LEFT,0,-1);
}
else
{
sBuffer.TrimLeft('+');
m_ls.InsertColumn(i-1,sBuffer,LVCFMT_LEFT,75,-1);
}
}
}
}
//Fill list from export table within AyaNova
void CXferDlg::FillListExport()
{
CString q,strData,strFields;
//Get the order to retrieve columns in
GetSelectedColumnOrder();
strFields=GetOriginalColumnOrder();
CStringParser p(strFields, ',', '\"');
CString sBuffer = "";
m_ls.DeleteAllItems();
int nCount;
int nRecordCount=0;
/*
Problem: retrieving and filling in selected column order rather than original order
Solution: retrieve in original column order, not selected order
*/
//cycle through table headings and retrieve data from current table
rs->QueryReadOnly(m_strSQL);
if(rs->IsEmpty())
{
AfxMessageBox("No data to export");
return;
}
//cycle through all records or a max of 100
do
{
//Cycle through all column headings
//find matching field and retrieve/insert into row
m_ls.InsertItem(nRecordCount,"");
nCount = p.GetCount();
if (nCount > 0)
{
for (int i = 1; i <= nCount; i++)
{
sBuffer = p.GetField(i);
sBuffer.Remove(_T('\"'));
//sBuffer.Remove('+');
//sBuffer.Remove('-');
rs->FetchAnyFieldAsString(sBuffer,&strData);
m_ls.SetItemText(nRecordCount,i-1,strData);
}
}
nRecordCount++;
}while(rs->MoveForward() && nRecordCount< 100);
}
void CXferDlg::OnXferSampleExportData()
{
FillListExport();
}
/*
void CXferDlg::OnColumnclickList1(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
int x=pNMListView->iSubItem;
LOGFONT plFont;
CFont* pFont;
CFont Font;
LVCOLUMN* pColumn=NULL;
m_ls.GetColumn(x,pColumn);
pFont=m_ls.GetHeaderCtrl()->GetFont();
pFont->GetLogFont(&plFont);
plFont.lfWeight=FW_BOLD;// : FW_NORMAL;
Font.CreateFontIndirect(&plFont);
m_ls.GetHeaderCtrl()->SetFont(&Font);
*pResult = 0;
}
*/
/*
*/
void CXferDlg::OnCloseupCbfields()
{
//refill fields variable based on what's selected in the combo box
//make sure were in order first
GetSelectedColumnOrder();
int nCurrent=0;
int nColumnCount;
int nElement=0;
int nMasterFieldCount=0;
CString strCurrent,strTemp,strFields,strNewMaster;
CHeaderCtrl* h;
h=m_ls.GetHeaderCtrl();
LVCOLUMN* pColumn=NULL;
HDITEM hdi;
TCHAR lpBuffer[256];
bool fFound = false;
bool bShow;
hdi.pszText = lpBuffer;
hdi.cchTextMax = 256;
//nItems=m_cbFields.GetCount();
m_cbFields.GetWindowText(strFields);
strFields="\"-"+strFields;
strFields+='\"';
strFields.Replace(", ","\",\"-");
//selected field list
CStringParser selected(strFields, ',', '\"');
//master field list
CStringParser master(m_strFields,',','\"');
//update column list
strTemp.Empty();
nMasterFieldCount=master.GetCount();
//loop through all the master fields
//compare with selected fields
//insert in strTemp with + or - prefix as appropriate
for(int x=1;x<nMasterFieldCount+1;x++)
{
strTemp=master.GetField(x);
strTemp.Replace('+','-');
//strTemp.Remove('\"');
selected.FindExact(strTemp,&nElement);
if(nElement>0)//selected
strTemp.Replace('-','+');
strTemp+=",";
strNewMaster+=strTemp;
}
strNewMaster.TrimRight(',');
//replace master field list with new corrected one.
m_strFields=strNewMaster;
//At this point m_strFields contains all fields with
//correct selection and order
//master field list
CStringParser master2(m_strFields,',','\"');
//Show/hide columns
nColumnCount=h->GetItemCount();
for(nCurrent=0;nCurrent<nColumnCount;nCurrent++)
{
//Get column text
hdi.mask = HDI_TEXT;
h->GetItem(nCurrent,&hdi);
strCurrent=hdi.pszText;
strCurrent.TrimLeft('-');
//strCurrent.Trimleft('+');
//Fetch the field from the master list
strCurrent="\"+" + strCurrent + "\"";
master2.FindExact(strCurrent,&nElement);
if(nElement>0)//it's a show
bShow=true;
else
bShow=false;
if(bShow)
{
strCurrent.Remove('\"');
strCurrent.Remove('+');
hdi.mask = HDI_TEXT;
hdi.pszText=strCurrent.GetBuffer(255);
h->SetItem(nCurrent,&hdi);
hdi.mask = HDI_WIDTH;
hdi.cxy=75;
h->SetItem(nCurrent,&hdi);
}
else//it's not selected
{
strCurrent.Remove('\"');
strCurrent.Remove('+');
strCurrent="---"+strCurrent;
hdi.mask = HDI_TEXT;
hdi.pszText=strCurrent.GetBuffer(255);
h->SetItem(nCurrent,&hdi);
hdi.mask = HDI_WIDTH;
hdi.cxy=0;
h->SetItem(nCurrent,&hdi);
}
}
}
//retrieve the column order
void CXferDlg::GetSelectedColumnOrder()
{
int nCurrent=0,nCurrent2=0;
int nColumnCount;
int nElement=0;
bool bShow;
CString strCurrent,strTemp;
CHeaderCtrl* h;
h=m_ls.GetHeaderCtrl();
LVCOLUMN* pColumn=NULL;
HDITEM hdi;
TCHAR lpBuffer[256];
bool fFound = false;
hdi.pszText = lpBuffer;
hdi.cchTextMax = 256;
m_strFields.Empty();
//Get columns in order and build
nColumnCount=h->GetItemCount();
for(nCurrent=0;nCurrent<nColumnCount;nCurrent++)
{
for(nCurrent2=0;nCurrent2<nColumnCount;nCurrent2++)
{
//See if were on the correct column
hdi.mask = HDI_ORDER;
h->GetItem(nCurrent2,&hdi);
if(hdi.iOrder==nCurrent)
{
//Get column text
hdi.mask = HDI_TEXT;
h->GetItem(nCurrent2,&hdi);
strCurrent=hdi.pszText;
if(strCurrent.Left(1)=="-")
bShow=false;
else
bShow=true;
strCurrent.TrimLeft('-');
strTemp = "\"";
strTemp += bShow ? "+" : "-";
strTemp+=strCurrent;
strTemp+="\",";
m_strFields+=strTemp;
}
}
}
m_strFields.TrimRight(',');
// AfxMessageBox(m_strFields);
}
//return the columns in original order
//used by the fill data functions
CString CXferDlg::GetOriginalColumnOrder()
{
int nCurrent=0;
int nColumnCount;
CString strCurrent,strTemp,strColumnFields;
CHeaderCtrl* h;
h=m_ls.GetHeaderCtrl();
LVCOLUMN* pColumn=NULL;
HDITEM hdi;
TCHAR lpBuffer[256];
hdi.pszText = lpBuffer;
hdi.cchTextMax = 256;
//Get columns in order and build
nColumnCount=h->GetItemCount();
for(nCurrent=0;nCurrent<nColumnCount;nCurrent++)
{
//Get column text
hdi.mask = HDI_TEXT;
h->GetItem(nCurrent,&hdi);
strCurrent=hdi.pszText;
strCurrent.TrimLeft('-');
strTemp = "\"";
strTemp+=strCurrent;
strTemp+="\",";
strColumnFields+=strTemp;
}
strColumnFields.TrimRight(',');
return strColumnFields;
}
//export data to screen
void CXferDlg::OnXferExportScreen()
{
CString strExport;
if(BuildExportData(&strExport))
m_pApp->ShowStuff(strExport);
}
bool CXferDlg::BuildExportData(CString *strExport)
{
CString q,strData,strFields;
//Get the order to retrieve columns in
GetSelectedColumnOrder();
CStringParser p(m_strFields, ',', '\"');
CString sBuffer = "";
CString strDelimiter;
/*m_cbDelimiters.AddRow("Comma",",");
m_cbDelimiters.AddRow("Tab","T");
m_cbDelimiters.AddRow("Space","S");
m_cbDelimiters.AddRow("Semicolon",";");
m_cbDelimiters.Select(",");*/
//Get delimiter, in the case of semicolor or comma no translation is required
strDelimiter=m_cbDelimiters.GetCurrentRowID();
if(strDelimiter=="T") strDelimiter="\t";
if(strDelimiter=="S") strDelimiter=" ";
if(strDelimiter.IsEmpty()) strDelimiter=",";
int nCount;
int nRecordCount=0;
strExport->Empty();
if(m_ckFirstRowFieldNames.GetCheck())
{
nCount = p.GetCount();
if (nCount > 0)
{
for (int i = 1; i <= nCount; i++)
{
sBuffer = p.GetField(i);
//sBuffer.Remove(_T('\"'));
//sBuffer.Remove('+');
//sBuffer.Remove('-');
if(sBuffer.Left(2)=="\"+")
{
sBuffer.Remove('+');
*strExport+=sBuffer + strDelimiter;
}
}
strExport->TrimRight(strDelimiter);
*strExport+="\r\n";
}
}
//cycle through table headings and retrieve data from current table
rs->QueryReadOnly(m_strSQL);
if(rs->IsEmpty())
{
AfxMessageBox("No data to export");
return false;
}
//cycle through all records
do
{
nCount = p.GetCount();
if (nCount > 0)
{
for (int i = 1; i <= nCount; i++)
{
sBuffer = p.GetField(i);
sBuffer.Remove(_T('\"'));
//sBuffer.Remove('+');
//sBuffer.Remove('-');
if(sBuffer.Left(1)=="+")
{
sBuffer.Remove('+');
rs->FetchAnyFieldAsString(sBuffer,&strData);
//avoid errors caused by quotation marks in field data
strData.Replace("\"","''");
*strExport+="\""+strData + "\"" + strDelimiter;
}
}
}
strExport->TrimRight(strDelimiter);
*strExport+="\r\n";
nRecordCount++;
}while(rs->MoveForward() && nRecordCount< 100);
return true;
}
void CXferDlg::OnXferExportFile()
{
//Export to file
m_edPath.GetWindowText(m_strPath);
if(m_strPath.IsEmpty())
{
GetFile(false);
return;
}
CString strExport;
if(!BuildExportData(&strExport)) return;
CFile exFile(m_strPath,CFile::modeCreate | CFile::modeWrite);
exFile.Write(strExport.GetBuffer(strExport.GetLength()),strExport.GetLength());
strExport.Empty();
strExport.Format("Saved: %s",m_strPath);
AfxMessageBox(strExport);
}
//---------------------------------------------------------------------------------
// PURPOSE: Qualify then fetch clients from quick books 2001 client export file
//
// PARMETERS: None
//
// RETURNS: None
//
// CHANGE LOG:
// DATE DESCRIPTION
// ---------- --------------------------------------------------------------
// 04/25/2001 Added function.
//---------------------------------------------------------------------------------
bool CXferDlg::QBSelectClientData()
{
//qualify import file
//see if there is an import file defined
m_edPath.GetWindowText(m_strPath);
if(m_strPath.IsEmpty())
{
GetFile(true);
return false;
}
CFile imFile(m_strPath,CFile::modeRead);
CArchive ar(&imFile,CArchive::load);
CString strCurrentLine,str,strTemp;
bool bNotDone=true;
CStringParser p;
int nRow=0;
//fetch and fill array of fields
while (bNotDone)
{
if(!ar.ReadString(strCurrentLine)) bNotDone=false;
if(strCurrentLine.Left(6)=="!CUST\t")
{
bNotDone=false;
}
}
//Remove the first "column"
if(strCurrentLine.Replace("!CUST\t","")==0)
{
AfxMessageBox("No customers found in this import file");
return false;
}
//fill columns
m_strFields="Customer\tContact\tPhone\tFax\tAddress\tNotes\tAccount";
SetColumns('\t');
//fill data
while(ar.ReadString(strCurrentLine))
{
strCurrentLine.Remove('\"');
p.ResetOriginalString(strCurrentLine,'\t');
m_ls.InsertItem(nRow,"");
//Get customer name FIELD 2
str=p.GetField(2);
m_ls.SetItemText(nRow,0,str);
//CONTACT NAME
str=p.GetField(20);
m_ls.SetItemText(nRow,1,str);
//bizphone
str=p.GetField(15);
m_ls.SetItemText(nRow,2,str);
//fax
str=p.GetField(17);
m_ls.SetItemText(nRow,3,str);
//address
str=p.GetField(5)+"\r\n";
strTemp=p.GetField(6);
if(!strTemp.IsEmpty())
{
strTemp+="\r\n";
str+=strTemp;
}
strTemp=p.GetField(7);
if(!strTemp.IsEmpty())
{
strTemp+="\r\n";
str+=strTemp;
}
strTemp=p.GetField(8);
if(!strTemp.IsEmpty())
{
strTemp+="\r\n";
str+=strTemp;
}
strTemp=p.GetField(9);
if(!strTemp.IsEmpty())
{
strTemp+="\r\n";
str+=strTemp;
}
str.TrimLeft("\r\n");
str.TrimRight("\r\n");
m_ls.SetItemText(nRow,4,str);
//NOTES
str=p.GetField(29);
m_ls.SetItemText(nRow,5,str);
//ACCOUNT
str=p.GetField(3);
m_ls.SetItemText(nRow,6,str);
nRow++;
}
return true;
}
//---------------------------------------------------------------------------------
// PURPOSE: Fill columns with sample import data
//
// PARMETERS: None
//
// RETURNS: None
//
// CHANGE LOG:
// DATE DESCRIPTION
// ---------- --------------------------------------------------------------
// 04/25/2001 Added function.
//---------------------------------------------------------------------------------
void CXferDlg::OnXferSampleImportData()
{
if(m_strCurrentTable=="QBCLIENTS")
QBSelectClientData();
}
//---------------------------------------------------------------------------------
// PURPOSE: import data
//
// PARMETERS: None
//
// RETURNS: None
//
// CHANGE LOG:
// DATE DESCRIPTION
// ---------- --------------------------------------------------------------
// 04/26/2001 Added function.
//---------------------------------------------------------------------------------
void CXferDlg::OnXferImport()
{
if(m_strCurrentTable=="QBCLIENTS")
{
QBSelectClientData();
QBImportClientData();
}
}
//---------------------------------------------------------------------------------
// PURPOSE: import QB Client data
//
// PARMETERS: None
//
// RETURNS: true on success, false on fail
//
// CHANGE LOG:
// DATE DESCRIPTION
// ---------- --------------------------------------------------------------
// 04/26/2001 Added function.
//---------------------------------------------------------------------------------
bool CXferDlg::QBImportClientData()
{
//fetch row by row and insert into the clients table
CString strData,q,strErrors,strTemp,strCompany;
int nRows=m_ls.GetItemCount();
for(int x=0;x<nRows;x++)
{
strCompany=m_ls.GetItemText(x,0);
q.Format("SELECT clients.company FROM clients "
"WHERE (((clients.company)=\"%s\"));",strCompany);
rs->QueryReadOnly(q);
if(!rs->IsEmpty())
{
//already exists
strTemp.Format("Can't import company: %s - Already exists.\r\n",strCompany);
strErrors+=strTemp;
}
else
{
q="INSERT INTO clients ( company, [last], bizphone, fax, mailaddress, generalnotes, acctnumber ) SELECT ";
//"company", "Contact", "phone" , "Fax", "Address", "notes", "Account";
//COMPANY
strData=m_ls.GetItemText(x,0);
strData="\""+strData+"\", ";
q+=strData;
//CONTACT
strData=m_ls.GetItemText(x,1);
if(strData.IsEmpty()) strData="?";
strData="\""+strData+"\", ";
q+=strData;
//PHONE
strData=m_ls.GetItemText(x,2);
if(strData.IsEmpty()) strData="?";
strData="\""+strData+"\", ";
q+=strData;
//FAX
strData=m_ls.GetItemText(x,3);
if(strData.IsEmpty()) strData="?";
strData="\""+strData+"\", ";
q+=strData;
//MAIL ADDRESS
strData=m_ls.GetItemText(x,4);
if(strData.IsEmpty()) strData="?";
strData="\""+strData+"\", ";
q+=strData;
//NOTES
strData=m_ls.GetItemText(x,5);
if(strData.IsEmpty()) strData="?";
strData="\""+strData+"\", ";
q+=strData;
//ACCOUNT
strData=m_ls.GetItemText(x,6);
if(strData.IsEmpty()) strData="?";
strData="\""+strData+"\";";
q+=strData;
//RUN THE QUERY
if(rs->Ex(q))
{
strTemp.Format("Imported company: %s.\r\n",strCompany);
strErrors+=strTemp;
}
else
{
strTemp.Format("Can't import company: %s - unknown error.\r\n",strCompany);
strErrors+=strTemp;
}
}
}
//Show log of success or errors or duplicates to display after completed
m_pApp->ShowStuff(strErrors);
return true;
}