BOOL CXmlDocument::Load(LPCTSTR lpszFileName)
{
	CWaitCursor waitCursor;

	CString strXML;

	try
	{
		CFile inputFile(lpszFileName, CFile::modeRead);
	
		DWORD dwLength = inputFile.GetLength();

		//inputFile.Read(strXML.GetBuffer(dwLength), dwLength);

		LPTSTR buffer = strXML.GetBuffer(dwLength);
		inputFile.Read(buffer, dwLength);
		buffer[dwLength] = 0;
				
		strXML.ReleaseBuffer();

		inputFile.Close();
	}
	catch(CFileException *ex)
	{
		ex->Delete();
		return FALSE;
	}

	// remove endofline and tabs
	strXML.Remove('\n');
	strXML.Remove('\r');
	strXML.Remove('\t');

	return Parse(strXML);
}
Example #2
0
CString FormatNumber(CString number) {
	CString numberFormated = number;
	pjsua_acc_id acc_id;
	pj_str_t pj_uri;
	bool isLocal = SelectSIPAccount(number,acc_id,pj_uri) && acc_id == account_local;
	if (!isLocal) {
		BOOL isDigits = TRUE;
		for (int i=0;i<number.GetLength();i++)
		{
			if ( (number[i]>'9' || number[i]<'0') && number[i]!='*' && number[i]!='#' && number[i]!='.' && number[i]!='-' && number[i]!='(' && number[i]!=')' && number[i]!=' ' && number[0]!='+')
			{
				isDigits = FALSE;
				break;
			}
		}
		if (isDigits) {
			numberFormated.Remove('.');
			numberFormated.Remove('-');
			numberFormated.Remove('(');
			numberFormated.Remove(')');
			numberFormated.Remove(' ');
		}
	}
	return GetSIPURI(numberFormated,true,isLocal);
}
Example #3
0
BOOL CLogFactory::CreateLogName(BSTR AppName, 
								BSTR Configue, 
								BSTR Section, 
								LONG FileType, 
								CString &strLogName)
{
	CString strError;
	CString strAppPath(AppName);
	CString strFileName(Configue);
	CString strSection(Section);

	if (!IsFileExisted(strAppPath))
	{
		strError.Format(_T("AppName:%s is not existed. CLogFactory::CreateLogName return FALSE."), strAppPath);
		LOGGER_WRITE(strError.GetBuffer());
		LogEvent(strError);
		return FALSE;
	}

	strError.Format(_T("AppName:%s"), strAppPath);
	LOGGER_WRITE(strError.GetBuffer());

	int iIndex = strAppPath.ReverseFind(_T('\\'));
	ATLASSERT(-1 != iIndex);
	strAppPath = strAppPath.Left(iIndex + 1);

	CParameter Parameter;
	CConfigReader Reader;
	Reader.Read(strAppPath, strFileName, strSection, FileType, Parameter);

	CHAR Buffer[MAX_PATH] = { 0 };
#pragma warning(push)
#pragma warning(disable: 4996)
	strcat(Buffer, Parameter.m_cFixFolder);
	strcat(Buffer, Parameter.m_cCycleFolder);
	strcat(Buffer, Parameter.m_cCycleName);
	strcat(Buffer, Parameter.m_cCreateTime);
	strcat(Buffer, Parameter.m_cSaveTime);
	strcat(Buffer, Parameter.m_cExeName);
#pragma warning(pop)
	strLogName = CString(Buffer);
	strLogName.Remove(_T('\\'));
	strLogName.Remove(_T(':'));
	strLogName.Remove(_T('.'));
	strLogName.Remove(_T(' '));

	LOGGER_WRITE2(_T("LogName:") << strLogName.GetBuffer() << _T(" FileType:") << FileType);

	return TRUE;
}
Example #4
0
void CKademliaWnd::UpdateControlsState()
{
	CString strLabel;
	if (Kademlia::CKademlia::IsConnected())
		strLabel = GetResString(IDS_MAIN_BTN_DISCONNECT);
	else if (Kademlia::CKademlia::IsRunning())
		strLabel = GetResString(IDS_MAIN_BTN_CANCEL);
	else
		strLabel = GetResString(IDS_MAIN_BTN_CONNECT);
	strLabel.Remove(_T('&'));
	GetDlgItem(IDC_KADCONNECT)->SetWindowText(strLabel);

	CString strBootstrapIP;
	GetDlgItemText(IDC_BOOTSTRAPIP, strBootstrapIP);
	CString strBootstrapPort;
	GetDlgItemText(IDC_BOOTSTRAPPORT, strBootstrapPort);
	CString strBootstrapUrl;
	GetDlgItemText(IDC_BOOTSTRAPURL, strBootstrapUrl);

	GetDlgItem(IDC_BOOTSTRAPBUTTON)->EnableWindow(
		!Kademlia::CKademlia::IsConnected()
		&& (  (IsDlgButtonChecked(IDC_RADIP)>0 && !strBootstrapIP.IsEmpty()
				&& (strBootstrapIP.Find(_T(':')) != -1 || !strBootstrapPort.IsEmpty()))
		    || IsDlgButtonChecked(IDC_RADCLIENTS) != 0
			|| (IsDlgButtonChecked(IDC_RADNODESURL) != 0 && !strBootstrapUrl.IsEmpty() ))
			);
}
Example #5
0
/*
呼叫业务顾问
*/
void CCallThread::OnCallBusc(CallerCmd& callerCmd)
{
	UINT winID = callerCmd.GetWindowId();//窗口ID
	callerCmd.SetSuccess(TRUE);
	//playsound,display
	SLZWindow Window; 
	BOOL flag = m_rInlineQueData.m_rWindowTable.QueryWindowById(winID,Window);
	if(!flag)return;
	CString callName = Window.GetWindowCallName();
	CString strMsg;
	callName.Remove(_T('号'));
	callName.Remove(_T('窗'));
	callName.Remove(_T('口'));
	strMsg.Format(_T("#请#业务顾问#到#%s#号窗口"),callName);
	theApp.m_Controller.m_pPlaySound->DataPlay(strMsg);
}
Example #6
0
BOOL CHistoryDlg::OnInitDialog()
{
	CResizableStandAloneDialog::OnInitDialog();

	// calculate and set listbox width
	CDC* pDC=m_List.GetDC();
	CSize itemExtent;
	int horizExtent = 1;
	for (size_t i = 0; i < m_history->GetCount(); ++i)
	{
		CString sEntry = m_history->GetEntry(i);
		sEntry.Remove('\r');
		sEntry.Replace('\n', ' ');
		m_List.AddString(sEntry);
		itemExtent = pDC->GetTextExtent(sEntry);
		horizExtent = max(horizExtent, itemExtent.cx+5);
	}
	m_List.SetHorizontalExtent(horizExtent);
	ReleaseDC(pDC);

	AddAnchor(IDC_HISTORYLIST, TOP_LEFT, BOTTOM_RIGHT);
	AddAnchor(IDOK, BOTTOM_RIGHT);
	AddAnchor(IDCANCEL, BOTTOM_RIGHT);
	EnableSaveRestore(_T("HistoryDlg"));
	m_List.SetFocus();
	return FALSE;
}
int
ODBCStringsMatrix::CutToSmallStrings(char* szString, CStringArray& arrSmallStrings)
	{
	int nLoop	= 0;
	int	nStart	= 0;
	arrSmallStrings.RemoveAll();

	while( szString[nLoop] != '\0' )
		{
		if( szString[nLoop] == ' ' )
			{
			char	cOld	= szString[nLoop];
			szString[nLoop]	= '\0';
			CString sValue	= (LPCTSTR)&szString[nStart];
			szString[nLoop]	= cOld;

			if( sValue.GetLength() )
				arrSmallStrings.Add(sValue);
			nStart			= nLoop + 1;
			}

		nLoop ++;
		}

	CString sValue	= (LPCTSTR)&szString[nStart];
	sValue.Remove(' ');
	if( sValue.GetLength() )
		arrSmallStrings.Add(sValue);

	return (long)arrSmallStrings.GetCount();
	}
Example #8
0
int CTrivia::ContainsStringExact(CString strLine, CString strSubString, BOOL bCase, BOOL bExactMatch)
{
	
    if(strLine.IsEmpty()) return FALSE;
	if(strSubString.IsEmpty()) return TRUE;
	int nReturn = -1;
	BOOL bFound = FALSE;
	if(!bCase){

		strLine.MakeLower();
		strSubString.MakeLower();
	}
	if(bExactMatch){

		if(strLine == strSubString){

			return 0;
		}
		else{

			return -1;
		}
	}

	CString strSearch = strSubString;
	strSearch.Remove('*');
	
	int nIndex = -1;
	BOOL bFront, bEnd;

	if((nIndex = strLine.Find(strSearch, 0)) >= 0){

		//Check if there is a space or ( at front and end of searched item
		bEnd = (nIndex + strSearch.GetLength() >= strLine.GetLength() ? TRUE : strLine.GetAt(strSearch.GetLength() + nIndex) == ' ');
		bFront = (nIndex > 0 ? strLine.GetAt(nIndex-1) == ' ' : TRUE);

		if((strSubString.GetAt(0) == '*') && (strSubString.GetAt(strSubString.GetLength()-1) == '*')){

			bFound = TRUE;
		}
		else if((strSubString.GetAt(0) == '*') && (strSubString.GetAt(strSubString.GetLength()-1) != '*')){

			bFound = bEnd;
		}
		else if((strSubString.GetAt(0) != '*') && (strSubString.GetAt(strSubString.GetLength()-1) == '*')){

			bFound = bFront;
		}
		else{

			bFound = bFront && bEnd;
		}
		if(bFound){
			
			nReturn = nIndex;
		}
	}
	return nReturn;
}
Example #9
0
void MakeStringToNum(CString str,LONGLONG &Num)
{
	CString strNumber = str;
	strNumber.Remove(',');
	strNumber.Trim();
	_snscanf(strNumber.GetBuffer(),strNumber.GetLength(),_TEXT("%I64d"),&Num);

	return;
}
Example #10
0
// Get the name for the specified tab, made up of its view names (eg "Text, Contents")
//, could also store custom name for tab
BOOL BDataViews::GetTabName(int nTab, CString& strName, BDoc* pDoc)
{
	ASSERT_VALID(this);
	ASSERT_VALID(pDoc);

	// Walk through views to build up name for tab

	// Clear string first
	strName.Empty();

	// first we need to walk through the array till we get to the specified tab
	// then continue walking through array till we reach the end or hit a 0 0
	int nStart = GetTabIndex(nTab);
	int nIndex = nStart;
	int nItems = m_avi.GetSize();
	int nViews = 0;
	while (TRUE)
	{
		ViewInfo& rvi = GetViewInfo(nIndex);
		ULONG lngViewID = rvi.m_lngViewID;

		// Exit if we've reached the end of the views for this tab
		if (lngViewID == 0)
			break;

		ASSERT(lngViewID);

		BObject* pobjView = pDoc->GetObject(lngViewID);

		// Get view caption
		CString strView = pobjView->GetPropertyString(propCaption);
		if (strView.IsEmpty()) // if caption property is empty, just use the name
			strView = pobjView->GetPropertyString(propName);

		if (nViews > 0)
		{
			// Remove any ampersand so only first view name will get underline character.
			// (otherwise Windows will just underline the last &'d character in the string).
			strView.Remove(_T('&'));
			strName += ", "; 
			strName += strView;
		}
		else
		{			
			strName += strView;
		}

		nIndex++;
		nViews++;

		// Exit if we're past the end of the array
		if (nIndex >= nItems)
			break;
	}

	return TRUE;
}
Example #11
0
//转换数字
void MakeStringToNum(CString str,SCORE &Num)
{
	CString strNumber = str;
	strNumber.Remove(',');
	strNumber.Trim();

#ifndef _UNICODE
	_snscanf(strNumber.GetBuffer(),strNumber.GetLength(),_TEXT("%I64d"),&Num);
#else
	_snwscanf(strNumber.GetBuffer(),strNumber.GetLength(),_TEXT("%I64d"),&Num);
#endif
	strNumber.ReleaseBuffer();
}
Example #12
0
void CServerWnd::UpdateControlsState()
{
	CString strLabel;
	if(CGlobalVariable::serverconnect)
	{
		if (CGlobalVariable::serverconnect->IsConnected())
			strLabel = GetResString(IDS_MAIN_BTN_DISCONNECT);
		else if (CGlobalVariable::serverconnect->IsConnecting())
			strLabel = GetResString(IDS_MAIN_BTN_CANCEL);
	}
	if(strLabel.IsEmpty())
		strLabel = GetResString(IDS_MAIN_BTN_CONNECT);
	strLabel.Remove(_T('&'));
	GetDlgItem(IDC_ED2KCONNECT)->SetWindowText(strLabel);
}
void CMuleToolbarCtrl::OnTbnGetButtonInfo(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMTOOLBAR pNMTB = reinterpret_cast<LPNMTOOLBAR>(pNMHDR);
	if (pNMTB->iItem >= _countof(TBButtons))
	{
		*pResult = FALSE;
	}
	else
	{
		CString strText = TBStrings[pNMTB->iItem];
		strText.Remove(_T('&'));
		_tcsncpy(pNMTB->pszText, strText, pNMTB->cchText - 1);
		pNMTB->pszText[pNMTB->cchText - 1] = _T('\0');
		pNMTB->tbButton = TBButtons[pNMTB->iItem];
		if (m_eLabelType == LabelsRight)
			pNMTB->tbButton.fsStyle |= TBSTYLE_AUTOSIZE;
		*pResult = TRUE;
	}
}
Example #14
0
void CServerList::AddServersFromTextFile(const CString& strFilename)
{
	CStdioFile f;
	if (!f.Open(strFilename, CFile::modeRead | CFile::typeText | CFile::shareDenyWrite))
		return;

	CString strLine;
	while (f.ReadString(strLine))
	{
		// format is host:port,priority,Name
		if (strLine.GetLength() < 5)
			continue;
		if (strLine.GetAt(0) == _T('#') || strLine.GetAt(0) == _T('/'))
			continue;

		// fetch host
		int pos = strLine.Find(_T(':'));
		if (pos == -1){
			pos = strLine.Find(_T(','));
			if (pos == -1) 
			continue;
		}
		CString strHost = strLine.Left(pos);
		strLine = strLine.Mid(pos+1);
		// fetch  port
		pos = strLine.Find(_T(','));
		if (pos == -1)
			continue;
		CString strPort = strLine.Left(pos);
		strLine = strLine.Mid(pos+1);

		// Barry - fetch priority
		pos = strLine.Find(_T(','));
		int priority = SRV_PR_HIGH;
		if (pos == 1)
		{
			CString strPriority = strLine.Left(pos);
			priority = _tstoi(strPriority);
			if (priority < 0 || priority > 2)
				priority = SRV_PR_HIGH;
			strLine = strLine.Mid(pos+1);
		}
	
		// fetch name
		CString strName = strLine;
		strName.Remove(_T('\r'));
		strName.Remove(_T('\n'));

		// create server object and add it to the list
		CServer* nsrv = new CServer((uint16)_tstoi(strPort), strHost);
		nsrv->SetListName(strName);
		nsrv->SetIsStaticMember(true);
		nsrv->SetPreference(priority); 

		if(! ::SendMessage(CGlobalVariable::m_hListenWnd, WM_SERVER_ADD_SVR, (WPARAM)nsrv, 0x0101))
		{
			delete nsrv;
		}
		//  Comment UI
		/*if (!theApp.emuledlg->serverwnd->serverlistctrl.AddServer(nsrv, true))
		{
			delete nsrv;
			CServer* srvexisting = GetServerByAddress(strHost, (uint16)_tstoi(strPort));
			if (srvexisting) {
				srvexisting->SetListName(strName);
				srvexisting->SetIsStaticMember(true);
				srvexisting->SetPreference(priority); 
				if (theApp.emuledlg->serverwnd)
					theApp.emuledlg->serverwnd->serverlistctrl.RefreshServer(srvexisting);
			}

		}*/
	}

	f.Close();
}
Example #15
0
//===========================================================================
void CFAVReaderDlg::OnBnClickedReaderWrite()
//===========================================================================
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	GetDlgItem(IDC_READER_WRITE)->EnableWindow(FALSE);

	CComboBox* pCbox = (CComboBox*)GetDlgItem(IDC_READER_MEMBANK_DATA);
	CEdit* pEditA = (CEdit*)GetDlgItem(IDC_READER_ADDRESS_DATA);
	CEdit* pEditL = (CEdit*)GetDlgItem(IDC_READER_LENGTH_DATA);
	CEdit* pEditW = (CEdit*)GetDlgItem(IDC_READER_WRITE_DATA);
	CStatic* pStaticW = (CStatic*)GetDlgItem(IDC_READER_WRITE_INFO);
	CString strBuf = (_T(""));
	CString strBuf_ = (_T(""));
	char* pchWrite = nullptr;

	m_nMemBankIndex = pCbox->GetCurSel();
	pEditA->GetWindowText(m_strAddress);
	if(m_strAddress == _T("")){
		AfxMessageBox(_T("Can not be ' '(null character), Please setting the Address."), MB_ICONHAND);
		GotoDlgCtrl((CEdit*)GetDlgItem(IDC_READER_ADDRESS_DATA));
		GetDlgItem(IDC_READER_WRITE)->EnableWindow(TRUE);
		return;
	}

	pEditL->GetWindowText(m_strWordsLength);
	if(m_strWordsLength == _T("")){
		AfxMessageBox(_T("Can not be ' '(null character), Please setting the Length."), MB_ICONHAND);
		GotoDlgCtrl((CEdit*)GetDlgItem(IDC_READER_LENGTH_DATA));
		GetDlgItem(IDC_READER_WRITE)->EnableWindow(TRUE);
		return;
	}

	pEditW->GetWindowText(m_strWrite);
	int nWriteLength = m_strWrite.GetLength();
	int nWordsLength = CStringHexToInt(m_strWordsLength);

	if(nWriteLength > nWordsLength*4){
		AfxMessageBox(_T("Write data length is greater than the setting length.\r\nPlease reset the setting length."));
		GotoDlgCtrl((CEdit*)GetDlgItem(IDC_READER_LENGTH_DATA));
		GetDlgItem(IDC_READER_WRITE)->EnableWindow(TRUE);
		return;
	}

	if(nWriteLength < nWordsLength*4){
		int nZero;
		for(int i = 0; i < ( nWordsLength*4 - nWriteLength); i++){
			nZero = m_strWrite.Insert(nWriteLength+i,_T("0"));
		}
		m_editWriteData.SetSel(0,-1);
		m_editWriteData.Clear();
		m_editWriteData.ReplaceSel(m_strWrite);
	}

	m_strWriteList.Format(_T("W%1d,%s,%s,%s"), m_nMemBankIndex, m_strAddress, m_strWordsLength, m_strWrite);
	int nstrLength = m_strWriteList.GetLength(); 
	pchWrite = new char[nstrLength + 1];
	for(int i = 0; i < nstrLength; i++){
		*(pchWrite + i) = m_strWriteList[i];
	}
	*(pchWrite + nstrLength) = (char)0x0d;

	m_strWriteList = (_T(">>> ")) + m_strWriteList;
	uCnt = m_ListBox.AddLine((CFAVListBox::COLOR)m_nText, (CFAVListBox::COLOR)m_nBackground, m_strWriteList);

	if(m_SerialComm.WriteCMD(CMD_W, pchWrite, (nstrLength + 1), WRITE_TIMEOUT))
	{
		TRACE(_T(">>> Write Fail in Write Button.\n"));
		goto WRITEERROR;
	}
	if(m_SerialComm.ReadCMD(CMD_W, READ_TIMEOUT))
	{
		strBuf = m_SerialComm.GetCMDData(CMD_W);
		//strBuf.Remove('R');
		switch (strBuf[0]){
		case '0':
			if(strBuf.GetLength() == 1){
				strBuf_ = _T("(0: Other Error)");
			}
			else{
				strBuf.Remove('0');
				strBuf.Remove('Z');
				strBuf_.Format(_T("(0Z%s: Other Error, %s words is written)"), strBuf,strBuf);
			}
			break;//'0'
		case '3':
			if(strBuf.GetLength() == 1){
				strBuf_ = _T("(3: Memory Overrun)");
			}
			else{
				strBuf.Remove('3');
				strBuf.Remove('Z');
				strBuf_.Format(_T("(3Z%s: Memory Overrun, %s words is written)"), strBuf,strBuf);
			}
			break;//'3'
		case '4':
			if(strBuf.GetLength() == 1){
				strBuf_ = _T("(4: Memory Locked)");
			}
			else{
				strBuf.Remove('4');
				strBuf.Remove('Z');
				strBuf_.Format(_T("(4Z%s: Memory Locked, %s words is written)"), strBuf,strBuf);
			}
			break;//'4'
		case 'Z':
			strBuf.Remove('Z');
			strBuf_.Format(_T("(Z%s: %s words is written)"), strBuf,strBuf);
			break;//'Z'
		case 'B':
			if(strBuf.GetLength() == 1){
				strBuf_ = _T("(B: Insufficient Power)");
			}
			else{
				strBuf.Remove('B');
				strBuf.Remove('Z');
				strBuf_.Format(_T("(BZ%s: Insufficient power, %s words is written)"), strBuf,strBuf);
			}
			break;//'X'
		case 'W':
			if(strBuf.GetLength() == 1){
				strBuf_ = _T("(W: No Tag)");
			}
			else
				strBuf_ = strBuf;
			break;//'W'
		case 'X':
			strBuf_ = _T("(X: Out of spec.)");
			break;//'X'
		case 'F':
			if(strBuf.GetLength() == 1){
				strBuf_ = _T("(F: Non-specific error)");
			}
			else{
				strBuf.Remove('F');
				strBuf.Remove('Z');
				strBuf_.Format(_T("(FZ%s: Non-specific error, %s words is written)"), strBuf,strBuf);
			}
			break;//'F'
		default:
			strBuf_ = strBuf;
			break;
		}

		pStaticW->SetWindowText(strBuf_);
		RefreshControl(IDC_READER_WRITE_INFO);

		uCnt = m_ListBox.AddLine((CFAVListBox::COLOR)m_nRecText, (CFAVListBox::COLOR)m_nBackground, m_SerialComm.GetCMDData(CMD_W));

		ASSERT(uCnt != LB_ERR);

		if (uCnt != LB_ERR)
		{
			// verify colors
			int nText = m_ListBox.GetTextColor(uCnt);
			int nBackground = m_ListBox.GetBackgroundColor(uCnt);
			//TRACE(_T("from XListBox:  text=%d  background=%d\n"), nText, nBackground);
			if (((nText != m_nText) && (nText != m_nRecText)) || (nBackground != m_nBackground))
			{
				ASSERT(FALSE);
			}
		}
	}
WRITEERROR:
	if(pchWrite){
		delete [] pchWrite;
	}
	pchWrite = NULL;

	GetDlgItem(IDC_READER_WRITE)->EnableWindow(TRUE);
	GetDlgItem(IDC_READER_WRITE)->SetFocus();
}
Example #16
0
void CManageTagsDlg::OnBnClickedManageTagsAddBtn()
{
	CString lTags;
	CString lTag;
	CAddTagsDlg lAddTagsDlg;
	CAddMultipleTagsDlg lAddMultipleTagsDlg;
	int lPos;

	if (lAddTagsDlg.DoModal() == IDOK)
	{
		m_ManageTagsList.SelItemRange(FALSE, 0, m_ManageTagsList.GetCount() - 1);

		// Add Multiple Tags dialog
		if (lAddTagsDlg.NeedShowAddMultipleTagsDlg())
		{
			if (lAddMultipleTagsDlg.DoModal() == IDOK)
			{
				
				mAddedTags = lTags = lAddMultipleTagsDlg.GetText();				
				while ((lPos = lTags.Find(_T("\r\n"))) != -1)
				{
					lTag = lTags.Left(lPos);
					if (!lTag.IsEmpty())
					{
						if (m_ManageTagsList.FindStringExact(-1, lTag) == LB_ERR)
						{
							CString lStr;
							lStr = lTag;
							lStr.Remove(' ');
							if (!lStr.IsEmpty())
							{
								int lSelTagIdx = m_ManageTagsList.AddString(lTag);
								m_ManageTagsList.SetItemData(lSelTagIdx, MANAGETAGS_NEWTAGID);
								m_ManageTagsList.SetSel(lSelTagIdx);
							}
						}
					}
					lTags = lTags.Right(lTags.GetLength() - lPos - 2);
				}
				lTag = lTags;
				if (!lTag.IsEmpty())
				{
					if (m_ManageTagsList.FindStringExact(-1, lTag) == LB_ERR)
					{
						CString lStr;
						lStr = lTag;
						lStr.Remove(' ');
						if (!lStr.IsEmpty())
						{
							//m_ManageTagsList.SetFocus();
							//m_ManageTagsList.SetSel(-1);
							int lTagIdx = m_ManageTagsList.AddString(lTag);
							m_ManageTagsList.SetItemData(lTagIdx, MANAGETAGS_NEWTAGID);
							m_ManageTagsList.SetSel(lTagIdx);
						}
					}
				}
			}
		}

		// Add Tag
		else
		{
			mAddedTags = lTag = lAddTagsDlg.GetText();
			if (!lTag.IsEmpty())
			{
				if (m_ManageTagsList.FindStringExact(-1, lTag) == LB_ERR)
				{
					CString lStr;
					lStr = lTag;
					lStr.Remove(' ');
					if (!lStr.IsEmpty())
					{
						//m_ManageTagsList.SetFocus();
//						m_ManageTagsList.s SetSel(-1);
						int lTagIdx = m_ManageTagsList.AddString(lTag);
						m_ManageTagsList.SetItemData(lTagIdx, MANAGETAGS_NEWTAGID);
						m_ManageTagsList.SetSel(lTagIdx);
					}
				}
				else
				{
					// Show error message if it's necessary
				}
			}
		}
	}
	UpdateUI();
}
Example #17
0
//===========================================================================
void CFAVReaderDlg::OnTimer(UINT_PTR nIDEvent)
//===========================================================================
{
	// TODO: Add your message handler code here and/or call default
	CString	strBuf = (_T(""));
	char	chCMD[] = COMMAND_Q;

	KillTimer(nIDEvent);

	switch (nIDEvent){
	case MULTIEPC:
		// Counter the line
		uCnt = m_ListBox.AddLine((CFAVListBox::COLOR)m_nText, (CFAVListBox::COLOR)m_nBackground, _T(">>> Q"));

		// Write Q CMD for repeat.
		if(m_SerialComm.WriteCMD(CMD_Q, chCMD, sizeof(chCMD), WRITE_DEFAULT_TIMEOUT))
		{
			TRACE(_T(">> Write Fail in Repeat Read EPC Button."));
		}

		// Read file
		if(m_SerialComm.ReadCMD(CMD_Q, READ_DEFAULT_TIMEOUT))
		{
			strBuf = m_SerialComm.GetCMDData(CMD_Q);
			strBuf.Remove('Q');

			m_editEPCData.SetSel(0,-1);
			m_editEPCData.Clear();
			m_editEPCData.ReplaceSel(strBuf);

			// Counter the line
			uCnt = m_ListBox.AddLine((CFAVListBox::COLOR)m_nRecText, (CFAVListBox::COLOR)m_nBackground, 
				m_SerialComm.GetCMDData(CMD_Q));

			ASSERT(uCnt != LB_ERR);

			if (uCnt != LB_ERR)
			{
				// Verify colors
				int nText = m_ListBox.GetTextColor(uCnt);
				int nBackground = m_ListBox.GetBackgroundColor(uCnt);

				if (((nText != m_nText) && (nText != m_nRecText)) || (nBackground != m_nBackground))
				{
					ASSERT(FALSE);
				}
			}
			//SetTimer(MULTIEPC, 80, NULL);
		}
		/*else{
			// Read failed. stop the process and enable all button.
			m_bRunStop = FALSE;
			if(!m_SerialComm.m_bConnectFlag)
			{
				m_bRunStop = FALSE;
				GetDlgItem(IDC_READER_READEPC)->SetWindowText("Read &EPC");
				GetDlgItem(IDC_READER_REPEAT)->EnableWindow(TRUE);
				GetDlgItem(IDC_READER_READ)->EnableWindow(TRUE);
				GetDlgItem(IDC_READER_WRITE)->EnableWindow(TRUE);
				GetDlgItem(IDC_READER_LNO)->EnableWindow(TRUE);
				GetDlgItem(IDC_READER_LOGFILE)->EnableWindow(TRUE);
			}
		}*/
		if(IsDlgButtonChecked(IDC_READER_REPEAT) == BST_CHECKED && m_bRunStop){
			if(m_bConnectFlag)
				SetTimer(MULTIEPC, 80, NULL);
		}

		GetDlgItem(IDC_READER_READEPC)->EnableWindow(TRUE);
		break;// MULTIEPC

	case SINGLEEPC:
		GetDlgItem(IDC_READER_READEPC)->EnableWindow(TRUE);
		GetDlgItem(IDC_READER_REPEAT)->EnableWindow(TRUE);
		GetDlgItem(IDC_READER_READ)->EnableWindow(TRUE);
		GetDlgItem(IDC_READER_WRITE)->EnableWindow(TRUE);
		break;// SINGLEEPC
	}
	CDialogEx::OnTimer(nIDEvent);
}
static int ReadWriteASection(bool bToRead, short SectionID,
                             FILE* pFile, void* pData = nullptr)
{
    int nResult = 0;

    switch (SectionID)
    {
        case SECTION_SIGNATURE:
        {
            if (bToRead)
            {
                char acBuffer[LEN_SIG_FILE_START] = {'\0'};
                nResult = ReadAndValidateString(pFile, acBuffer, DATABASE_SIGNATURE);
                if (nResult != 0)
                {
                    ReadWriteASection(bToRead, SECTION_FILE_INVALID, nullptr);
                }
            }
            else
            {
                nResult = WriteAString(pFile, DATABASE_SIGNATURE);
            }
            if (nResult == 0)
            {
                nResult = ReadWriteASection(bToRead, SECTION_VERSION, pFile);
            }
        }
        break;
        case SECTION_VERSION:
        {
            if (bToRead)
            {
                char acBuffer[LEN_VERSION] = {'\0'};
                nResult = ReadAndValidateString(pFile, acBuffer, VERSIONLINE);
                if(nResult != 0)
                {
                    CString strVer = (const char*)acBuffer;
                    strVer.Remove('.');
                    strVer.Remove('*');
                    strVer.Remove('/');
                    strVer.Replace("Version", "");
                    strVer.Remove(' ');

                    // Get the cfx version info
                    INT nVer = 0;

                    nVer = atoi(strVer);

                    switch (nVer)
                    {
                        case 10:
                            // Successfull
                            nResult = 0;
                            break;
                        default:
                            // Invalid
                            nResult = INVALID_FORMAT_FILE;
                            break;
                    }
                }

                // If the newer version[1.1] file is opened
                else
                {
                    char acBuffer[LEN_APPLICATION_VERSION] = {'\0'};

                    // Reading Application version
                    ReadAndValidateString(pFile, acBuffer, APPLICATION_VERSION);
                }

                if (nResult != 0)
                {
                    ReadWriteASection(bToRead, SECTION_FILE_INVALID, nullptr);
                }
            }
            else
            {
                nResult = WriteAString(pFile, VERSIONLINE);
                // Writing Application version is added in the Version 1.1
                nResult = WriteAString(pFile, APPLICATION_VERSION);
            }
            if (nResult == 0)
            {
                nResult = ReadWriteASection(bToRead, SECTION_PROJECT_TABLE_SIGNATURE, pFile);
            }
        }
        break;
        case SECTION_PROJECT_TABLE_SIGNATURE:
        {
            if (bToRead)
            {
                char acBuffer[LEN_SIG_PROJ_TABLE] = {'\0'};
                nResult = ReadAndValidateString(pFile, acBuffer, PROJECT_TABLE_SIG);
                if (nResult != 0)
                {
                    ReadWriteASection(bToRead, SECTION_FILE_INVALID, nullptr);
                }
            }
            else
            {
                nResult = WriteAString(pFile, PROJECT_TABLE_SIG);
            }
            if (nResult == 0)
            {
                nResult = ReadWriteASection(bToRead, SECTION_PROJECT_TABLE_COUNT, pFile);
            }
        }
        break;
        case SECTION_PROJECT_TABLE_COUNT:
        {
            UCHAR Entries = 0;
            if (bToRead)
            {
                //fseek(pFile, sizeof("\n")-1, SEEK_CUR);
                if (fread(&Entries, sizeof(Entries), 1, pFile) == 1)
                {
                    nResult = ReadWriteASection(bToRead, SECTION_PROJECT_TABLE_ENTRY,
                                                pFile, &Entries);
                }
                else
                {
                    nResult = GetTheErrorType(pFile);
                }
            }
            else
            {
                Entries = (UCHAR) g_ProjCfgManager.GetProjectCount();
                //fputs("\n", pFile);
                if (fwrite(&Entries, sizeof(UCHAR), 1, pFile) == 1)
                {
                    nResult = ReadWriteASection(bToRead, SECTION_PROJECT_TABLE_ENTRY,
                                                pFile, &Entries);
                }
                else
                {
                    nResult = PROBLEM_IN_WRITING_READING;
                }
            }
        }
        break;
        case SECTION_PROJECT_TABLE_ENTRY:
        {
            UCHAR Entries = *((UCHAR*) pData);
            if (bToRead)
            {
                for (UCHAR i = 0; (i < Entries) && (nResult == 0); i++)
                {
                    PROJECTDATA sProjectDataTmp;
                    if (sProjectDataTmp.Read(pFile))
                    {
                        g_ProjCfgManager.AddModifyProjDetail(sProjectDataTmp);
                    }
                    else
                    {
                        nResult = GetTheErrorType(pFile);
                    }
                }
            }
            else
            {
                bool bAllWell = true;
                LISTSTR ProjectList;
                g_ProjCfgManager.GetProjectList(ProjectList);

                for (LISTSTR::iterator i = ProjectList.begin(); (i != ProjectList.end()) && bAllWell; ++i)
                {
                    PROJECTDATA ProjData;
                    if (bAllWell = g_ProjCfgManager.GetProjectData(*i, ProjData))
                    {
                        bAllWell = ProjData.Write(pFile);
                    }
                }
                if (!bAllWell)
                {
                    nResult = PROBLEM_IN_WRITING_READING;
                }
            }
            if (nResult == 0)
            {
                nResult = ReadWriteASection(bToRead, SECTION_SECTION_TABLE_ENTRY,
                                            pFile, &Entries);
            }
        }
        break;
        case SECTION_SECTION_TABLE_ENTRY:
        {
            bool bAllWell = true;
            if (bToRead)
            {
                UCHAR ProjectEntries = *((UCHAR*) pData);
                for (UCHAR i = 0; (i < ProjectEntries) && bAllWell; i++)
                {
                    std::string ProjectName;
                    bAllWell = ReadAString(pFile, ProjectName);
                    //ProjectName[ProjectName.length()-1] = '\0';
                    UCHAR SectionEntries = 0;
                    if (bAllWell)
                    {
                        //fseek(pFile, sizeof("\n")-1, SEEK_CUR);
                        bAllWell = (fread(&SectionEntries, sizeof(SectionEntries),
                                          1, pFile) == 1);
                    }
                    if (bAllWell)
                    {
                        for (UCHAR j = 0; (j < SectionEntries) && bAllWell; j++)
                        {
                            SECTIONDATA CurrSection;
                            if (bAllWell = CurrSection.Read(pFile))
                            {
                                g_ProjCfgManager.AddModifySection(
                                    ProjectName, CurrSection);
                            }
                            else
                            {
                                nResult = GetTheErrorType(pFile);
                            }
                        }
                    }
                }
                if (!bAllWell)
                {
                    nResult = PROBLEM_IN_WRITING_READING;
                }
            }
            else
            {
                LISTSTR ProjectList;
                g_ProjCfgManager.GetProjectList(ProjectList);

                for (LISTSTR::iterator i = ProjectList.begin(); (i != ProjectList.end()) && bAllWell; ++i)
                {
                    const char* str = i->c_str();
                    if ((nResult = WriteAString(pFile, (char*) str)) == 0)
                    {
                        LISTSTR SectionList;
                        UCHAR Sections = (UCHAR) g_ProjCfgManager.GetSectionList(*i, SectionList);
                        //fputs("\n", pFile);
                        if (fwrite(&Sections, sizeof(UCHAR), 1, pFile) != 1)
                        {
                            bAllWell = false;
                        }

                        for (LISTSTR::iterator j = SectionList.begin(); (j != SectionList.end()) && bAllWell; ++j)
                        {
                            SECTIONDATA CurrSecData;
                            bAllWell = g_ProjCfgManager.GetSectionData(*i, *j, CurrSecData);
                            if (bAllWell)
                            {
                                bAllWell = CurrSecData.Write(pFile);
                            }
                        }
                    }
                }
                if (!bAllWell)
                {
                    nResult = PROBLEM_IN_WRITING_READING;
                }
            }
            if (bAllWell)
            {
                nResult = ReadWriteASection(bToRead, SECTION_SIGNATURE_FILE_END, pFile);
            }
        }
        break;
        case SECTION_SIGNATURE_FILE_END:
        {
            if (bToRead)
            {
                char acBuffer[LEN_SIG_FILE_END] = {'\0'};
                nResult = ReadAndValidateString(pFile, acBuffer, DB_END_SIGNATURE);
                if (nResult != 0)
                {
                    ReadWriteASection(bToRead, SECTION_FILE_INVALID, nullptr);
                }
            }
            else
            {
                nResult = WriteAString(pFile, DB_END_SIGNATURE);
            }
        }
        break;


        default:
        {
            nResult = FILE_INVALID_SECTIONID;
        }
        break;
    }

    return nResult;
}
void CServerList::AddServersFromTextFile(const CString& strFilename)
{
	CStdioFile f;
	// open the text file either in ANSI (text) or Unicode (binary), this way we can read old and new files
	// with nearly the same code..
	bool bIsUnicodeFile = IsUnicodeFile(strFilename); // check for BOM
	if (!f.Open(strFilename, CFile::modeRead | CFile::shareDenyWrite | (bIsUnicodeFile ? CFile::typeBinary : 0)))
		return;

	try	{
		if (bIsUnicodeFile)
			f.Seek(sizeof(WORD), CFile::current); // skip BOM

		CString strLine;
		while (f.ReadString(strLine))
		{
			// format is host:port,priority,Name
			if (strLine.GetLength() < 5)
				continue;
			if (strLine.GetAt(0) == _T('#') || strLine.GetAt(0) == _T('/'))
				continue;

			// fetch host
			int pos = strLine.Find(_T(':'));
			if (pos == -1){
				pos = strLine.Find(_T(','));
				if (pos == -1) 
					continue;
			}
			CString strHost = strLine.Left(pos);
			strLine = strLine.Mid(pos+1);
			// fetch  port
			pos = strLine.Find(_T(','));
			if (pos == -1)
				continue;
			CString strPort = strLine.Left(pos);
			strLine = strLine.Mid(pos+1);

			// Barry - fetch priority
			pos = strLine.Find(_T(','));
			int priority = SRV_PR_HIGH;
			if (pos == 1)
			{
				CString strPriority = strLine.Left(pos);
				priority = _tstoi(strPriority);
				if (priority < 0 || priority > 2)
					priority = SRV_PR_HIGH;
				strLine = strLine.Mid(pos+1);
			}
		
			// fetch name
			CString strName = strLine;
			strName.Remove(_T('\r'));
			strName.Remove(_T('\n'));

			// create server object and add it to the list
			CServer* nsrv = new CServer((uint16)_tstoi(strPort), strHost);
			nsrv->SetListName(strName);
			nsrv->SetIsStaticMember(true);
			nsrv->SetPreference(priority); 
			if (!theApp.emuledlg->serverwnd->serverlistctrl.AddServer(nsrv, true))
			{
				delete nsrv;
				CServer* srvexisting = GetServerByAddress(strHost, (uint16)_tstoi(strPort));
				if (srvexisting) {
					srvexisting->SetListName(strName);
					srvexisting->SetIsStaticMember(true);
					srvexisting->SetPreference(priority); 
					if (theApp.emuledlg->serverwnd)
						theApp.emuledlg->serverwnd->serverlistctrl.RefreshServer(srvexisting);
				}
			}
		}
		f.Close();
	}
	catch (CFileException* ex) {
		ASSERT(0);
		ex->Delete();
	}
}
void CRTF_HTMLConverter::R2H_SetMetaData(CRTFNode& NodeRoot)
{
	//Initializing
	CString strRTFSource = (NodeRoot)->m_strThisCode;

	//Go thru RTF main string's global data
	for (int iStrPos = 0; iStrPos < strRTFSource.GetLength(); iStrPos++)
	{
		TCHAR ChTest = strRTFSource[iStrPos];

		if (ChTest == _T('\\'))
		{
			CString strTag = R2H_GetRTFTag(strRTFSource, iStrPos);
			CString strTestTag;

			strTestTag = _T("ansicpg");

			if ((strTag.GetLength() >= strTestTag.GetLength()) && (strTag.Left(strTestTag.GetLength()) == strTestTag))
			{
				m_strCharset = strTag;
				m_strCharset.Delete(0, strTestTag.GetLength());
			}

			iStrPos += strTag.GetLength();

			if (((iStrPos + 1) < strRTFSource.GetLength()) && (strRTFSource[iStrPos + 1] == _T(' ')))
			{
				iStrPos++;   //Ignore Blank after Tag
			}
		}
		else
		{
			//Normal character
		}
	} //loop thru string

	//Go thru 1st-level-nodes
	for (int iRTFNodes = 0; iRTFNodes < NodeRoot.Count; iRTFNodes++)
	{
		//Color table
		if (NodeRoot.Nodes[iRTFNodes]->m_strName == _T("colortbl"))
		{
			CString strColorTbl = NodeRoot.Nodes[iRTFNodes]->m_strThisCode;
			strColorTbl.Delete(0, NodeRoot.Nodes[iRTFNodes]->m_strName.GetLength() + 1); //+1=leading \ (backslash)
			//Palette entries are separated with semicolon ;
			CStringArray arrStrColors;
			StringToArray(strColorTbl, arrStrColors);

			for (int iColor = 0; iColor < arrStrColors.GetSize(); iColor++)
			{
				//RGB values within palette entry are \redXXX\greenXXX\blueXXX
				DWORD r = 0, g = 0, b = 0;
				CString strColorEntry = arrStrColors[iColor];
				strColorEntry.TrimLeft();
				strColorEntry.TrimRight();
				if (strColorEntry.GetLength() > 0)
				{
					//Loop thru base colors (r,g,b) and set them
					CStringArray arrStrRGBs;
					R2H_GetRTFTags(strColorEntry, arrStrRGBs);
					ASSERT(arrStrRGBs.GetSize() == 3); //RTF must contain exactly 3 entries for red/green/blue
					for (int iBaseColor = 0; iBaseColor < arrStrRGBs.GetSize(); iBaseColor++)
					{
						CString strBaseColor = arrStrRGBs[iBaseColor];
						CString strTestBaseColor;
						strTestBaseColor = _T("red");
						if ((strBaseColor.GetLength() >= strTestBaseColor.GetLength()) && (strBaseColor.Left(strTestBaseColor.GetLength()) == strTestBaseColor))
						{
							strBaseColor.Delete(0, strTestBaseColor.GetLength());
							r = StringToLong(strBaseColor);
						}
						strTestBaseColor = _T("green");
						if ((strBaseColor.GetLength() >= strTestBaseColor.GetLength()) && (strBaseColor.Left(strTestBaseColor.GetLength()) == strTestBaseColor))
						{
							strBaseColor.Delete(0, strTestBaseColor.GetLength());
							g = StringToLong(strBaseColor);
						}
						strTestBaseColor = _T("blue");
						if ((strBaseColor.GetLength() >= strTestBaseColor.GetLength()) && (strBaseColor.Left(strTestBaseColor.GetLength()) == strTestBaseColor))
						{
							strBaseColor.Delete(0, strTestBaseColor.GetLength());
							b = StringToLong(strBaseColor);
						}
					}
				}
				COLORREF ref = RGB(r, g, b);
				m_arrColors.Add(ref);
			}
			continue;
		}
		//Font Table
		if (NodeRoot.Nodes[iRTFNodes]->m_strName == _T("fonttbl"))
		{
			for (int iFontNodes = 0; iFontNodes < NodeRoot.Nodes[iRTFNodes].Count; iFontNodes++)
			{
				CString strFontName = NodeRoot.Nodes[iRTFNodes].Nodes[iFontNodes]->m_strName;
				CString strFont = NodeRoot.Nodes[iRTFNodes].Nodes[iFontNodes]->m_strPlain;
				ASSERT((strFontName.GetLength() >= 2) && (strFontName.Left(1) == _T("f"))); //No valid RTF
				ASSERT(strFont.GetLength() > 0);
				strFont.TrimLeft();
				strFont.TrimRight();
				strFont.Remove(_T(';'));
				m_mapFontNames.SetAt(strFontName, strFont);
			} //for-each-font
			continue;
		} //if font-table
	} //for each 1st-level-node
}
Example #21
0
//===========================================================================
void CFAVReaderDlg::OnBnClickedReaderRead()
//===========================================================================
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	GetDlgItem(IDC_READER_READ)->EnableWindow(FALSE);

	CComboBox* pCbox = (CComboBox*)GetDlgItem(IDC_READER_MEMBANK_DATA);
	CEdit* pEditA = (CEdit*)GetDlgItem(IDC_READER_ADDRESS_DATA);
	CEdit* pEditL = (CEdit*)GetDlgItem(IDC_READER_LENGTH_DATA);
	CString strBuf = (_T(""));

	m_nMemBankIndex = pCbox->GetCurSel();
	pEditA->GetWindowText(m_strAddress);
	if(m_strAddress == _T("")){
		AfxMessageBox(_T("Can not be ' '(null character), Please setting the Address."), MB_ICONHAND);
		GotoDlgCtrl((CEdit*)GetDlgItem(IDC_READER_ADDRESS_DATA));
		goto READEXIT;
	}

	pEditL->GetWindowText(m_strWordsLength);
	if(m_strWordsLength == _T("")){
		AfxMessageBox(_T("Can not be ' '(null character), Please setting the Length."), MB_ICONHAND);
		GotoDlgCtrl((CEdit*)GetDlgItem(IDC_READER_LENGTH_DATA));
		goto READEXIT;
	}

	char chRead[12];
	memset(chRead,'\0',12);
	//CString strRead;
	m_strRead.Format(_T("R%1d,%s,%s"), m_nMemBankIndex, m_strAddress, m_strWordsLength);
	int nstrLength = m_strRead.GetLength();
	for(int i = 0; i < nstrLength; i++){
		chRead[i] = m_strRead[i];
	}
	chRead[nstrLength] = (char)0x0d;

	m_strRead = (_T(">>> ")) + m_strRead;
	uCnt = m_ListBox.AddLine((CFAVListBox::COLOR)m_nText, (CFAVListBox::COLOR)m_nBackground, m_strRead);

	if(m_SerialComm.WriteCMD(CMD_R, chRead, (nstrLength+1), WRITE_DEFAULT_TIMEOUT))
	{
		TRACE(_T(">>> Write Fail in Read Button.\n"));
		goto READEXIT;
	}
	if(m_SerialComm.ReadCMD(CMD_R, READ_DEFAULT_TIMEOUT))
	{
		strBuf = m_SerialComm.GetCMDData(CMD_R);
		strBuf.Remove('R');
		if(strBuf == '0'){
			strBuf = _T("(0: Other Error)");
		}
		if(strBuf == '3'){
			strBuf = _T("(3: Memory Overrun)");
		}
		if(strBuf == '4'){
			strBuf = _T("(4: Memory Locked)");
		}
		if(strBuf == 'B'){
			strBuf = _T("(B: Insufficient Power)");
		}
		m_editReadData.SetSel(0,-1);
		m_editReadData.Clear();
		m_editReadData.ReplaceSel(strBuf);

		uCnt = m_ListBox.AddLine((CFAVListBox::COLOR)m_nRecText, (CFAVListBox::COLOR)m_nBackground, 
			m_SerialComm.GetCMDData(CMD_R));

		ASSERT(uCnt != LB_ERR);

		if (uCnt != LB_ERR)
		{
			// verify colors
			int nText = m_ListBox.GetTextColor(uCnt);
			int nBackground = m_ListBox.GetBackgroundColor(uCnt);
			//TRACE(_T("from XListBox:  text=%d  background=%d\n"), nText, nBackground);
			if (((nText != m_nText) && (nText != m_nRecText)) || (nBackground != m_nBackground))
			{
				ASSERT(FALSE);
			}
		}
	}

READEXIT:
	GetDlgItem(IDC_READER_READ)->EnableWindow(TRUE);
	GetDlgItem(IDC_READER_READ)->SetFocus();
}
Example #22
0
void CDlgBDSelectRezTL::OnBnClickedButtonExportExcel()
{
	
	CDatabase database;
	CString sDriver = "MICROSOFT EXCEL DRIVER (*.XLS)"; // exactly the same name as in the ODBC-Manager
	CString sExcelFile = "Тележки1067.xls";                // Filename and path for the file to be created
	if( iNewProc ) sExcelFile = "Тележки1067arx.xls";
	CString sSql;
  
	CString strColListInsert = "";
	CString strColListCreate = "";
	int iColCount = 0;
	LVITEM Item;
	HDITEM hItem;
	enum   { sizeOfBuffer = 256 };
	TCHAR  lpBuffer[sizeOfBuffer];
	bool   fFound = false;

	hItem.mask = HDI_TEXT;
	hItem.pszText = lpBuffer;
	hItem.cchTextMax = sizeOfBuffer;
	CHeaderCtrl *hcHeader = m_List.GetHeaderCtrl();
  
	iColCount =  hcHeader->GetItemCount();
	CString strTitle = "";
	for( int i = 0; i < iColCount; i++ )
	{
		if( i ) 
		{	  
			strColListInsert += ", ";
			strColListCreate += ", ";
		}
	  
		if( hcHeader->GetItem(i, &hItem) )
		{
			strTitle = hItem.pszText;
			strTitle.Remove('.');
			strColListInsert = strColListInsert + "[" + strTitle + "]";
			strColListCreate = strColListCreate + "[" + strTitle + "] TEXT";
		}
	}

  
    // Build the creation string for access without DSN
	DeleteFile(".\\" + sExcelFile);
    if( !CopyFile(".\\html\\" + sExcelFile, ".\\" + sExcelFile, 1) )
	{
		// Создам шаблон
		sSql.Format("DRIVER={%s};DSN='';FIRSTROWHASNAMES=1;READONLY=FALSE;CREATE_DB=\".\\html\\%s\";DBQ=.\\html\\%s",
                sDriver, sExcelFile, sExcelFile);
		database.OpenEx(sSql,CDatabase::noOdbcDialog);
		sSql = "CREATE TABLE [Тележки 1067] (" + strColListCreate + ")";
		database.ExecuteSQL(sSql);
		database.Close();
		CopyFile(".\\html\\" + sExcelFile, ".\\" + sExcelFile, 1);
	}

	sSql.Format("DRIVER={%s};DSN='';FIRSTROWHASNAMES=1;READONLY=FALSE;CREATE_DB=\".\\%s\";DBQ=%s",
                sDriver, sExcelFile, sExcelFile);

    // Create the database (i.e. Excel sheet)
    if( database.OpenEx(sSql,CDatabase::noOdbcDialog) )
    {
		/*
		TRY
		{
		sSql = "CREATE TABLE [Тележки 1067] (" + strColListCreate + ")";
		database.ExecuteSQL(sSql);
		}
		CATCH_ALL(e)
		{
		}
		END_CATCH_ALL
		*/
		

		for( int i = 0; i < m_List.GetItemCount(); i++ )
		{
			CString strLine = "";
			for( int j = 0; j < iColCount; j++ )
			{
				if( j ) strLine += ", ";
				strLine += "'" + m_List.GetItemText(i, j) + "'";
			}
			//sSql = "INSERT INTO [Тележки 1067] (" + strColListInsert + ") VALUES ( " + strLine + " )";
			sSql = "INSERT INTO [Тележки 1067] VALUES ( " + strLine + " )";
			database.ExecuteSQL(sSql);
		}
		
      
	}      

    database.Close();
	CString str = "excel.exe .\\" + sExcelFile;
	ShellExecute(NULL, "open", "excel.exe", 
                           sExcelFile, 
                           NULL, SW_SHOWNORMAL);

}
Example #23
0
//===========================================================================
void CFAVReaderDlg::OnBnClickedReaderReadepc()
//===========================================================================
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	GetDlgItem(IDC_READER_READEPC)->EnableWindow(FALSE);

	CString strBuf = (_T(""));

	if(!m_bRunStop)
	{
		if(IsDlgButtonChecked(IDC_READER_REPEAT) == BST_CHECKED)
		{
			m_bRunStop = TRUE;
			GetDlgItem(IDC_READER_READEPC)->SetWindowText(_T("&Stop"));
			GetDlgItem(IDC_READER_REPEAT)->EnableWindow(FALSE);
			GetDlgItem(IDC_READER_READ)->EnableWindow(FALSE);
			GetDlgItem(IDC_READER_WRITE)->EnableWindow(FALSE);
			GetDlgItem(IDC_READER_LNO)->EnableWindow(FALSE);
			GetDlgItem(IDC_READER_LOGFILE)->EnableWindow(FALSE);
			SetTimer(MULTIEPC, 100, NULL);
		}
		else
		{
			char chCMD[] = COMMAND_Q;
			uCnt = m_ListBox.AddLine((CFAVListBox::COLOR)m_nText, (CFAVListBox::COLOR)m_nBackground, _T(">>> Q"));

			if(m_SerialComm.WriteCMD(CMD_Q, chCMD, sizeof(chCMD), WRITE_DEFAULT_TIMEOUT))
			{
				TRACE(_T(">>> Write Fail in Read EPC Button.\n"));
				GetDlgItem(IDC_READER_READEPC)->EnableWindow(TRUE);
				return;
			}
			if(m_SerialComm.ReadCMD(CMD_Q, READ_DEFAULT_TIMEOUT))
			{
				strBuf = m_SerialComm.GetCMDData(CMD_Q);
				strBuf.Remove('Q');

				m_editEPCData.SetSel(0,-1);
				m_editEPCData.Clear();
				m_editEPCData.ReplaceSel(strBuf);

				uCnt = m_ListBox.AddLine((CFAVListBox::COLOR)m_nRecText, (CFAVListBox::COLOR)m_nBackground, 
					m_SerialComm.GetCMDData(CMD_Q));

				ASSERT(uCnt != LB_ERR);

				if (uCnt != LB_ERR)
				{
					// verify colors
					int nText = m_ListBox.GetTextColor(uCnt);
					int nBackground = m_ListBox.GetBackgroundColor(uCnt);
					//TRACE(_T("from XListBox:  text=%d  background=%d\n"), nText, nBackground);
					if (((nText != m_nText) && (nText != m_nRecText)) || (nBackground != m_nBackground))
					{
						ASSERT(FALSE);
					}
				}
			}
			GetDlgItem(IDC_READER_READEPC)->EnableWindow(TRUE);
		}
	}
	else//Stop run
	{
		m_bRunStop = FALSE;
		KillTimer(MULTIEPC);
		GetDlgItem(IDC_READER_READEPC)->SetWindowText(_T("Read &EPC"));
		GetDlgItem(IDC_READER_READEPC)->EnableWindow(TRUE);
		GetDlgItem(IDC_READER_REPEAT)->EnableWindow(TRUE);
		GetDlgItem(IDC_READER_READ)->EnableWindow(TRUE);
		GetDlgItem(IDC_READER_WRITE)->EnableWindow(TRUE);
		GetDlgItem(IDC_READER_LNO)->EnableWindow(TRUE);
		GetDlgItem(IDC_READER_LOGFILE)->EnableWindow(TRUE);
	}
	GetDlgItem(IDC_READER_READEPC)->SetFocus();
}