예제 #1
0
/**
* Adds text to the end of the console output window.
* @param msg The text to append.
* \todo: BMatt Nerve: Fix scroll code so the output window will scroll as text
* is added if the cursor is at the end of the window.
*/
void ConsoleView::AddText( const char *msg ) {

	if(!editConsole.GetSafeHwnd())
		return;

	idStr work;
	CString work2;

	work = msg;
	work.RemoveColors();
	work = TranslateString( work.c_str() );

	editConsole.GetWindowText( work2 );
	int len = work2.GetLength();
	if ( len + work.Length() > (int)editConsole.GetLimitText() ) {
		work2 = work2.Right( editConsole.GetLimitText() * .75f );
		len = work2.GetLength();
		editConsole.SetWindowText(work2);
	}
	editConsole.SetSel( len, len );
	editConsole.ReplaceSel( work );
	
	//Hack: scrolls down a bit
	editConsole.LineScroll(100);
}
예제 #2
0
uint32_t CKeyboardTranslator::TranslateButton(const TiXmlElement *pButton)
{
  uint32_t button_id = 0;
  const char *szButton = pButton->Value();

  if (szButton == nullptr)
    return 0;

  const std::string strKey = szButton;
  if (strKey == "key")
  {
    std::string strID;
    if (pButton->QueryValueAttribute("id", &strID) == TIXML_SUCCESS)
    {
      const char *str = strID.c_str();
      char *endptr;
      long int id = strtol(str, &endptr, 0);
      if (endptr - str != (int)strlen(str) || id <= 0 || id > 0x00FFFFFF)
        CLog::Log(LOGDEBUG, "%s - invalid key id %s", __FUNCTION__, strID.c_str());
      else
        button_id = (uint32_t)id;
    }
    else
      CLog::Log(LOGERROR, "Keyboard Translator: `key' button has no id");
  }
  else
    button_id = TranslateString(szButton);

  // Process the ctrl/shift/alt modifiers
  std::string strMod;
  if (pButton->QueryValueAttribute("mod", &strMod) == TIXML_SUCCESS)
  {
    StringUtils::ToLower(strMod);

    std::vector<std::string> modArray = StringUtils::Split(strMod, ",");
    for (auto substr : modArray)
    {
      StringUtils::Trim(substr);

      if (substr == "ctrl" || substr == "control")
        button_id |= CKey::MODIFIER_CTRL;
      else if (substr == "shift")
        button_id |= CKey::MODIFIER_SHIFT;
      else if (substr == "alt")
        button_id |= CKey::MODIFIER_ALT;
      else if (substr == "super" || substr == "win")
        button_id |= CKey::MODIFIER_SUPER;
      else if (substr == "meta" || substr == "cmd")
        button_id |= CKey::MODIFIER_META;
      else if (substr == "longpress")
        button_id |= CKey::MODIFIER_LONG;
      else
        CLog::Log(LOGERROR, "Keyboard Translator: Unknown key modifier %s in %s", substr.c_str(), strMod.c_str());
    }
  }

  return button_id;
}
예제 #3
0
// static helper
BOOL CEnString::LoadString(UINT nID, HWND hwndRef, CString& sText)
{
	if (sText.LoadString(nID))
	{
		TranslateString(sText, hwndRef);
		return (!sText.IsEmpty());
	}

	return FALSE;
}
예제 #4
0
////////// GetTranslatedScalarStringFromMap
OP_STATUS
QuickUICreator::GetTranslatedScalarStringFromMap(const OpStringC8 & key, OpString & translated_string)
{
	OpString8 text_str;
	RETURN_IF_ERROR(GetScalarStringFromMap(key, text_str));

	if (text_str.HasContent())
	{
		return TranslateString(text_str, translated_string);
	}
	return OpStatus::OK;
}
예제 #5
0
BOOL UpdateSel(int iIndex, eclass_t *pec)
{
	int		i;
	brush_t	*b;

	if (selected_brushes.next == &selected_brushes)
	{
		edit_entity = world_entity;
		multiple_entities = false;
	}
	else
	{
		edit_entity = selected_brushes.next->owner;
		for (b=selected_brushes.next->next ; b != &selected_brushes ; b=b->next)
		{
			if (b->owner != edit_entity)
			{
				multiple_entities = true;
				break;
			}
		}
	}

	if (iIndex != LB_ERR)
		SendMessage(hwndEnt[EntList], LB_SETCURSEL, iIndex, 0);

	if (pec == NULL)
		return TRUE;

	// Set up the description

	SendMessage(hwndEnt[EntComment], WM_SETTEXT, 0, 
			(LPARAM)TranslateString(pec->comments));

	for (i=0 ; i<MAX_FLAGS ; i++)
	{
		HWND hwnd = hwndEnt[EntCheck1+i];
		if (pec->flagnames[i] && pec->flagnames[i][0] != 0)
		{
			EnableWindow(hwnd, TRUE);
			SendMessage(hwnd, WM_SETTEXT, 0, (LPARAM)pec->flagnames[i]);
		} else {

			// disable check box
			SendMessage(hwnd, WM_SETTEXT, 0, (LPARAM)" ");
			EnableWindow(hwnd, FALSE);
		}
	}

	SetSpawnFlags();
	SetKeyValuePairs();
	return TRUE;
}
/******************************************************************
 * Function: StringInterface
 *
 * This function gives the user the option of either Encrypting or
 * decrypting whichever string they enter.
 *
 *Inputs: None
 *Output: None
 ******************************************************************/
void StringInterface()
{
  /*The string choice which is going to contain the user choice*/
  /*and The newline character*/
  char *choice;
  choice = (char *) malloc(CHOICESIZE * sizeof(char)) ;
  if(choice == NULL)
    {
      fprintf(stderr, "Out of memory - getting space for choice\n");
      exit (-1);
    }

  PrintSMenu();
  /*Reads the choice from the user*/
  fscanf(stdin, "%s", choice);
    {
      /*For both lowercase and uppercase choices, launch Encryption*/
      /*or decryption modes*/
      switch(choice[0])
	{
	case 'E':
	  TranslateString();
	  break;
	case 'e':
	  TranslateString();
	  break;
	case'D':
	  DecryptString();
	  break;
	case 'd':
	  DecryptString();
	  break;
	default:
	  return;
	  break;
	}
    } 
  free(choice); 
  return;
}
예제 #7
0
int Transform_Msg(char *msg)
{
	int rv=0;
	FILE *xfh;

	if(*msg=='/')
	{
		if((xfh=fopen(msg,"r"))!=NULL)
		{
			fclose(xfh);
			strcpy(TMP_FILE,msg);
		}
		else
		{
			rv=1;
		}
	}
	else
	{
		size_t l = strlen(msg);
		char *t = (char *)alloca(l * 4 + 1);
		memcpy(t, msg, l + 1);
		TranslateString(t, l * 4);
		msg = t;

		if((xfh=fopen(TMP_FILE,"w"))!=NULL)
		{
			while(*msg)
			{
				if(*msg!='~')
				{
					fputc(*msg,xfh);
				}
				else
				{
					if(*(msg+1)=='n')
					{
						fputc(0x0A,xfh);
						++msg;
					}
					else
					{
						fputc(*msg,xfh);
					}
				}
				msg++;
			}
			fclose(xfh);
		}
	}
	return rv;
}
예제 #8
0
void Com_Printf( const char *msg, ... ) {
	va_list argptr;
	char	buf[32768];
	char	*out;

	va_start (argptr,msg);
	vsprintf (buf, msg,argptr);
	va_end (argptr);

	out = TranslateString (buf);

	Sys_Printf(buf);
}
예제 #9
0
void Com_Error( int level, const char *error, ... ) {
	va_list argptr;
	char	buf[32768];
	char	*out;

	va_start (argptr,error);
	vsprintf (buf, error,argptr);
	va_end (argptr);

	out = TranslateString (buf);

	Sys_Printf(buf);
}
예제 #10
0
void CEnString::Format(LPCTSTR lpszFormat, ...)
{
	CString strFormat(lpszFormat);
		
	if (!strFormat.IsEmpty())
	{
		TranslateString(strFormat, NULL);

		va_list argList;
		va_start(argList, lpszFormat);
		CString::FormatV(strFormat, argList);
		va_end(argList);

		CompareIgnoreString(strFormat);
	}
}
예제 #11
0
extern "C" void ConError(char *text, ...)
{
	char	buf[32768];		//this is ... cautious
	char	*out;
	va_list argptr;

	va_start(argptr, text);
	vsprintf(buf, text, argptr);
	va_end(argptr);

	out	=TranslateString(buf);

	if(ConHwnd)
	{
		SendMessage(ConHwnd, EM_REPLACESEL, 0, (LPARAM)out);
	}
}
예제 #12
0
int GetSelection(char *sptr)
{
	int rv=0,btn=0,run=1;
	char *pt1=strdup(sptr),*pt2=NULL,*pt3=NULL;

	pt2=pt1;
	while(*pt2 && run && btn<MAX_BUTTONS)
	{
		if((pt3=strchr(pt2,','))!=NULL)
		{
			*pt3=0;
			++pt3;
		}
		else
		{
			run=0;
		}
		++tbuttons;
		if(strlen(pt2))
		{	
			rbutt[btn]=tbuttons;
			size_t l = strlen(pt2);
			char *t = (char *)alloca(l * 4 + 1);
			memcpy(t, pt2, l + 1);
			TranslateString(t, l * 4);
			CatchLF(t);
			butmsg[btn]=strdup(t);
			CatchTabs(butmsg[btn++]);
		}
		if(run)
		{
			pt2=pt3;
		}
	}
	if(!btn)
	{
		rv=1;
	}
	else
	{
		buttons=btn;
	}
	free(pt1);
	return rv;
}
예제 #13
0
unsigned int CIRTranslator::TranslateButton(const std::string &szDevice, const std::string &szButton)
{
  // Find the device
  auto it = m_irRemotesMap.find(szDevice);
  if (it == m_irRemotesMap.end())
    return 0;

  // Find the button
  auto it2 = (*it).second->find(szButton);
  if (it2 == (*it).second->end())
    return 0;

  // Convert the button to code
  if (strnicmp((*it2).second.c_str(), "obc", 3) == 0)
    return TranslateUniversalRemoteString((*it2).second);

  return TranslateString((*it2).second);
}
int GetLine(char *buffer, int size, PFSTRUCT fstruct)
{
	int rv=0;
	char *pt1;

	if(fstruct->fnum<0)
	{
		return rv;
	}
	rv=(fgets(buffer, size, fstruct->fh[fstruct->fnum])!=NULL);
	if(!rv)
	{
		while(!rv)
		{
			if(!fstruct->fnum)
			{
				return rv;
			}
			else
			{
				fclose(fstruct->fh[fstruct->fnum]);
				--fstruct->fnum;
				rv=(fgets(buffer, size, fstruct->fh[fstruct->fnum])!=NULL);
			}
		}
	}
	if(rv)
	{
		TrimString(buffer);
		if(strstr(buffer,"INCLUDE=") && (fstruct->fnum<15) && ((pt1=strchr(buffer,'='))!=NULL))
		{
			if(((fstruct->fh[fstruct->fnum+1]=fopen(++pt1,"r"))!=NULL) && (fgets(buffer, BUFSIZE, fstruct->fh[fstruct->fnum+1])))
			{
				fstruct->fnum++;
				TrimString(buffer);
			}
		}
		TranslateString(buffer, size);
	}
	return rv;
}
예제 #15
0
void Sys_Printf (char *text, ...)
{
	va_list argptr;
	char	buf[32768];
	char	*out;

	va_start (argptr,text);
	vsprintf (buf, text,argptr);
	va_end (argptr);

	out = TranslateString (buf);

#ifdef LATER
	Sys_Status(out);
#else
	SendMessage (g_qeglobals.d_hwndEdit,
		EM_REPLACESEL,
		0,
		(LPARAM)out);
#endif

}
예제 #16
0
void Sys_Printf( char* text, ... )
{
	va_list argptr;
	char    buf[32768];
	char*   out;
	LRESULT result;             // PGM
	DWORD   oldPosS, oldPosE;   // PGM
	
	va_start( argptr, text );
	vsprintf( buf, text, argptr );
	va_end( argptr );
	
	out = TranslateString( buf );
	
#ifdef LATER
	Sys_Status( out );
#else
	//PGM
	result = SendMessage( g_qeglobals.d_hwndEdit, EM_GETLINECOUNT, 0, 0 );
	if ( result > SCROLLBACK_MAX_LINES )
	{
		char    replaceText[5];
	
		replaceText[0] = '\0';
	
		SendMessage( g_qeglobals.d_hwndEdit, WM_SETREDRAW, ( WPARAM )0, ( LPARAM )0 );
		SendMessage( g_qeglobals.d_hwndEdit, EM_GETSEL, ( WPARAM )&oldPosS, ( LPARAM )&oldPosE );
		SendMessage( g_qeglobals.d_hwndEdit, EM_SETSEL, 0, SCROLLBACK_DEL_CHARS );
		SendMessage( g_qeglobals.d_hwndEdit, EM_REPLACESEL, ( WPARAM )0, ( LPARAM )replaceText );
		SendMessage( g_qeglobals.d_hwndEdit, EM_SETSEL, oldPosS, oldPosE );
		SendMessage( g_qeglobals.d_hwndEdit, WM_SETREDRAW, ( WPARAM )1, ( LPARAM )0 );
	}
	//PGM
	
	SendMessage( g_qeglobals.d_hwndEdit, EM_REPLACESEL, 0, ( LPARAM )out );
#endif
	
}
void CFMUnlockPatientList::OnExportSelect()
{
	CHMSMainFrame *pMF = (CHMSMainFrame*) AfxGetMainWnd();
	
	UpdateData(true);

	CExcel xls;
	CRecord rs(&pMF->m_db);
	CRecord rss(&pMF->m_db);

	CString szSQL, tmpStr, szTemp;
	CString szClass;

	int nCol = 0, nRow = 0, nIdx = 0;
	double nAmount = 0;
	long double nTotal = 0;
	long double nGroupTotal = 0;

	m_nTotal = 0;

	szSQL = GetQueryString();
	rs.ExecSQL(szSQL);

	szSQL = GetDepositString();
	rss.ExecSQL(szSQL);

	if (rs.GetRecordCount() + rss.GetRecordCount() <= 0)
	{
		ShowMessageBox(_T("No Data"), MB_OK | MB_ICONERROR);
		return;
	}

	xls.CreateSheet(1);
	xls.SetWorksheet(0);

	xls.SetColumnWidth(0, 4);
	xls.SetColumnWidth(1, 25);
	xls.SetColumnWidth(2, 9);
	xls.SetColumnWidth(3, 8);
	xls.SetColumnWidth(4, 18);
	xls.SetColumnWidth(5, 15);

	xls.SetRowHeight(4, 40);
	
	//Header
	xls.SetCellMergedColumns(nCol, nRow, 3);
	xls.SetCellMergedColumns(nCol, nRow + 1, 3);

	xls.SetCellMergedColumns(nCol + 3, nRow, 4);
	xls.SetCellMergedColumns(nCol + 3, nRow + 1, 4);

	xls.SetCellMergedColumns(nCol, nRow + 2, 6);
	xls.SetCellMergedColumns(nCol, nRow + 3, 6);

	xls.SetCellText(nCol, nRow, pMF->m_CompanyInfo.sc_pname, FMT_TEXT | FMT_CENTER, true, 11);
	xls.SetCellText(nCol, nRow + 1, pMF->m_CompanyInfo.sc_name, FMT_TEXT | FMT_CENTER, true, 11);

	xls.SetCellText(nCol + 3, nRow, _T("\x43\x1ED8NG H\xD2\x41 \x58\xC3 H\x1ED8I \x43H\x1EE6 NGH\x128\x41 VI\x1EC6T N\x41M"), FMT_TEXT | FMT_CENTER, true);
	xls.SetCellText(nCol + 3, nRow + 1, _T("\x110\x1ED8\x43 L\x1EACP - T\x1EF0 \x44O - H\x1EA0NH PH\xDA\x43"), FMT_TEXT | FMT_CENTER, true);

	xls.SetCellText(nCol, nRow + 2, _T("\x42\x1EA2NG TH\x1ED0NG K\xCA \x44\x41NH S\xC1\x43H \x42\x1EC6NH NH\xC2N \x43H\x1AF\x41 KH\xD3\x41 S\x1ED4"),
		            FMT_TEXT | FMT_CENTER, true, 11);	
	tmpStr.Format(_T("T\x1EEB ng\xE0y %s \x111\x1EBFn ng\xE0y %s"),
		          CDateTime::Convert(m_szFromDate, yyyymmdd | hhmm, ddmmyyyy | hhmm),
				  CDateTime::Convert(m_szToDate, yyyymmdd | hhmm, ddmmyyyy | hhmm));

	xls.SetCellText(nCol, nRow + 3, tmpStr, FMT_TEXT | FMT_CENTER, false, 11);	
	
	//Column Header
	CStringArray arrCol;

	arrCol.Add(_T("STT"));
	arrCol.Add(_T("T\xEAn \x62\x1EC7nh nh\xE2n"));
	arrCol.Add(_T("S\x1ED1 h\x1ED3 s\x1A1"));
	arrCol.Add(_T("Kho\x61 / Ph\xF2ng kh\xE1m"));
	arrCol.Add(_T("Ng\x1B0\x1EDDi thu"));
	arrCol.Add(_T("S\x1ED1 ti\x1EC1n"));


	CString szGroup[] = {_T("I"), _T("II"), _T("III"), _T("IV")};
	int nIndex = 0;
	nRow = 4;

	for (int i = 0; i < arrCol.GetCount(); i++)
	{
		xls.SetCellText(nCol + i, nRow, arrCol.GetAt(i), FMT_TEXT | FMT_CENTER | FMT_VCENTER | FMT_WRAPING, true, 10); 
	}

	while (!rs.IsEOF())
	{
		if (szClass != rs.GetValue(_T("fclass")))
		{
			if (nGroupTotal > 0)
			{
				nRow++;
				TranslateString(_T("Total Amt"), tmpStr);
				tmpStr.AppendFormat(_T(" %s"), szGroup[nIndex++]);
				xls.SetCellMergedColumns(nCol, nRow, 5);

				xls.SetCellText(nCol, nRow, tmpStr, FMT_TEXT | FMT_CENTER, true, 11);

				tmpStr.Format(_T("%.2Lf"), nGroupTotal);
				xls.SetCellText(nCol + 5, nRow, tmpStr, FMT_NUMBER1 | FMT_WRAPING, true, 11);

				nTotal += nGroupTotal;
				nGroupTotal = 0;
			}
			nIdx = 1;
			rs.GetValue(_T("fclass"), szClass);
			if (szClass == _T("NO"))
			{
				nRow++;
				xls.SetCellMergedColumns(nCol, nRow, 6);
				xls.SetCellText(nCol, nRow, _T("\x43\xE1\x63 kho\x61 n\x1ED9i tr\xFA"),
					            FMT_TEXT | FMT_CENTER, true, 11);
			}
		}

		nIdx++;
		nRow++;

		tmpStr.Format(_T("%d"), nIdx);
		xls.SetCellText(nCol, nRow, tmpStr, FMT_INTEGER | FMT_WRAPING);

		rs.GetValue(_T("pname"), tmpStr);
		xls.SetCellText(nCol + 1, nRow, tmpStr, FMT_TEXT | FMT_WRAPING);

		rs.GetValue(_T("docno"), tmpStr);
		xls.SetCellText(nCol + 2, nRow, tmpStr, FMT_INTEGER | FMT_WRAPING);

		rs.GetValue(_T("deptid"), tmpStr);
		xls.SetCellText(nCol + 3, nRow, tmpStr, FMT_TEXT | FMT_WRAPING);

		rs.GetValue(_T("staff"), tmpStr);
		xls.SetCellText(nCol + 4, nRow, tmpStr, FMT_TEXT | FMT_WRAPING);

		rs.GetValue(_T("amount"), nAmount);
		tmpStr.Format(_T("%.2f"), nAmount);
		nGroupTotal += nAmount;
		xls.SetCellText(nCol + 5, nRow, tmpStr, FMT_NUMBER1 | FMT_WRAPING);

		rs.MoveNext();
	}

	if (nGroupTotal > 0)
	{
		nRow++;
		TranslateString(_T("Total Amt"), tmpStr);
		tmpStr.AppendFormat(_T(" %s"), szGroup[nIndex++]);
		xls.SetCellMergedColumns(nCol, nRow, 5);

		xls.SetCellText(nCol, nRow, tmpStr, FMT_TEXT | FMT_CENTER, true, 11);

		tmpStr.Format(_T("%.2Lf"), nGroupTotal);
		xls.SetCellText(nCol + 5, nRow, tmpStr, FMT_NUMBER1 | FMT_WRAPING, true, 11);

		nTotal += nGroupTotal;
		nGroupTotal = 0;
	}

	if (!rss.IsEOF())
	{
		nRow++;
		xls.SetCellMergedColumns(nCol, nRow, 6);
		xls.SetCellText(nCol, nRow, _T("Thu t\x1EA1m g\x1EEDi"), FMT_TEXT | FMT_CENTER, true, 11);

		nIdx = 1;

		while (!rss.IsEOF())
		{
			nRow++;
			tmpStr.Format(_T("%d"), nIdx++);
			xls.SetCellText(nCol, nRow, tmpStr, FMT_INTEGER | FMT_WRAPING);

			rss.GetValue(_T("pname"), tmpStr);
			xls.SetCellText(nCol + 1, nRow, tmpStr, FMT_TEXT | FMT_WRAPING);

			rss.GetValue(_T("docno"), tmpStr);
			xls.SetCellText(nCol + 2, nRow, tmpStr, FMT_INTEGER | FMT_WRAPING);

			rss.GetValue(_T("deptid"), tmpStr);
			xls.SetCellText(nCol + 3, nRow, tmpStr, FMT_TEXT | FMT_WRAPING);

			rss.GetValue(_T("staff"), tmpStr);
			xls.SetCellText(nCol + 4, nRow, tmpStr, FMT_TEXT | FMT_WRAPING);

			rss.GetValue(_T("amount"), nAmount);
			nGroupTotal += nAmount;
			tmpStr.Format(_T("%.2f"), nAmount);
			xls.SetCellText(nCol + 5, nRow, tmpStr, FMT_NUMBER1 | FMT_WRAPING);

			rss.MoveNext();
		}
	}

	if (nGroupTotal > 0)
	{
		nRow++;
		TranslateString(_T("Total Amt"), tmpStr);
		tmpStr.AppendFormat(_T(" %s"), szGroup[nIndex++]);
		xls.SetCellMergedColumns(nCol, nRow, 5);

		xls.SetCellText(nCol, nRow, tmpStr, FMT_TEXT | FMT_CENTER, true, 11);

		tmpStr.Format(_T("%.2Lf"), nGroupTotal);
		xls.SetCellText(nCol + 5, nRow, tmpStr, FMT_NUMBER1 | FMT_WRAPING, true, 11);

		nTotal += nGroupTotal;
		nGroupTotal = 0;
	}
	
	if (nTotal > 0)
	{
		nRow++;
		xls.SetCellMergedColumns(nCol, nRow, 5);
		xls.SetCellText(nCol, nRow, _T("T\x1ED5ng ti\x1EC1n"), FMT_TEXT | FMT_CENTER, true, 11);
		tmpStr.Format(_T("%.2Lf"), nTotal);
		xls.SetCellText(nCol + 5, nRow, tmpStr, FMT_NUMBER1 | FMT_WRAPING, true, 11);
	}

	xls.Save(_T("Exports\\DanhSachBNChuaKhoaSo.xls"));
} 
/*void CFMUnlockPatientList::OnClerkAddNew(){
	CHMSMainFrame *pMF = (CHMSMainFrame*) AfxGetMainWnd();
	
} */
void CFMUnlockPatientList::OnPrintPreviewSelect()
{
	CHMSMainFrame *pMF = (CHMSMainFrame*) AfxGetMainWnd();
	
	UpdateData(true);

	CReport rpt;
	CRecord rs(&pMF->m_db);
	CRecord rss(&pMF->m_db);

	CString szSQL, tmpStr, szSysDate;
	CString szTemp, szClass;

	int nIdx = 0;
	double nAmount = 0;
	long double nTotal = 0;
	long double nGroupTotal = 0;
	m_nTotal = 0;

	szSQL = GetQueryString();
	rs.ExecSQL(szSQL);

	szSQL = GetDepositString();
	rss.ExecSQL(szSQL);

	if (rs.GetRecordCount() + rss.GetRecordCount() <= 0)
	{
		ShowMessageBox(_T("No Data"), MB_OK | MB_ICONERROR);
		return;
	}

	if (!rpt.Init(_T("Reports/HMS/HF_DANHSACHBNCHUAKHOASO.RPT")))
		return;

	rpt.GetReportHeader()->SetValue(_T("HealthService"), pMF->m_CompanyInfo.sc_pname);
	rpt.GetReportHeader()->SetValue(_T("HospitalName"), pMF->m_CompanyInfo.sc_name);
	tmpStr.Format(rpt.GetReportHeader()->GetValue(_T("ReportDate")),
		          CDateTime::Convert(m_szFromDate, yyyymmdd | hhmm, ddmmyyyy | hhmm),
				  CDateTime::Convert(m_szToDate, yyyymmdd | hhmm, ddmmyyyy | hhmm));
	rpt.GetReportHeader()->SetValue(_T("ReportDate"), tmpStr);

	CReportSection *rptDetail;

	CString szGroup[] = {_T("I"), _T("II"), _T("III"), _T("IV")};

	int nIndex = 0;

	while (!rs.IsEOF())
	{
		if (szClass != rs.GetValue(_T("fclass")))
		{
			if (nGroupTotal > 0)
			{
				rptDetail = rpt.AddDetail(rpt.GetGroupHeader(1));
				TranslateString(_T("Total Amt"), tmpStr);
				tmpStr.AppendFormat(_T(" %s"), szGroup[nIndex++]);
				rptDetail->SetValue(_T("GroupName"), tmpStr);
				//tmpStr.Format(_T("%.2lf"), nGroupTotal);
				FormatCurrency(nGroupTotal, tmpStr);
				rptDetail->SetValue(_T("SumGroupName"), tmpStr);

				nTotal += nGroupTotal;
				nGroupTotal = 0;
			}

			nIdx = 1;

			rs.GetValue(_T("fclass"), szClass);
			if (szClass == _T("NO"))
			{
				rptDetail = rpt.AddDetail(rpt.GetGroupHeader(1));
				rptDetail->SetValue(_T("GroupName"), _T("\x43\xE1\x63 kho\x61 n\x1ED9i tr\xFA"));
			}
		}

		rptDetail = rpt.AddDetail();

		
		tmpStr.Format(_T("%d"), nIdx++);
		rptDetail->SetValue(_T("1"), tmpStr);

		
		rs.GetValue(_T("pname"), tmpStr);
		rptDetail->SetValue(_T("2"), tmpStr);

		
		rs.GetValue(_T("docno"), tmpStr);
		rptDetail->SetValue(_T("3"), tmpStr);


		rs.GetValue(_T("deptid"), tmpStr);
		rptDetail->SetValue(_T("4"), tmpStr);


		rs.GetValue(_T("staff"), tmpStr);
		rptDetail->SetValue(_T("6"), tmpStr);


		rs.GetValue(_T("amount"), nAmount);
		nGroupTotal += nAmount;
		FormatCurrency(nAmount, tmpStr);
		rptDetail->SetValue(_T("5"), tmpStr);

		rs.MoveNext();
	}

	if (nGroupTotal > 0)
	{
		rptDetail = rpt.AddDetail(rpt.GetGroupHeader(1));
		TranslateString(_T("Total Amt"), tmpStr);
		tmpStr.AppendFormat(_T(" %s"), szGroup[nIndex++]);
		rptDetail->SetValue(_T("GroupName"), tmpStr);
		//tmpStr.Format(_T("%.2lf"), nGroupTotal);
		FormatCurrency(nGroupTotal, tmpStr);
		rptDetail->SetValue(_T("SumGroupName"), tmpStr);

		nTotal += nGroupTotal;
		nGroupTotal = 0;
	}

	//szSQL = GetDepositString();
	//rs.ExecSQL(szSQL);

	if (!rss.IsEOF())
	{
		rptDetail = rpt.AddDetail(rpt.GetGroupHeader(1));
		rptDetail->SetValue(_T("GroupName"), _T("Thu t\x1EA1m g\x1EEDi"));

		nIdx = 1;
		while (!rss.IsEOF())
		{
			rptDetail = rpt.AddDetail();
		
			tmpStr.Format(_T("%d"), nIdx++);
			rptDetail->SetValue(_T("1"), tmpStr);

			rss.GetValue(_T("pname"), tmpStr);
			rptDetail->SetValue(_T("2"), tmpStr);

			rss.GetValue(_T("docno"), tmpStr);
			rptDetail->SetValue(_T("3"), tmpStr);

			rss.GetValue(_T("deptid"), tmpStr);
			rptDetail->SetValue(_T("4"), tmpStr);

			rss.GetValue(_T("staff"), tmpStr);
			rptDetail->SetValue(_T("6"), tmpStr);

			rss.GetValue(_T("amount"), nAmount);
			nGroupTotal += nAmount;
			FormatCurrency(nAmount, tmpStr);
			rptDetail->SetValue(_T("5"), tmpStr);

			rss.MoveNext();
		}
	}

	if (nGroupTotal > 0)
	{
		rptDetail = rpt.AddDetail(rpt.GetGroupHeader(1));
		TranslateString(_T("Total Amt"), tmpStr);
		tmpStr.AppendFormat(_T(" %s"), szGroup[nIndex++]);
		rptDetail->SetValue(_T("GroupName"), tmpStr);
		//tmpStr.Format(_T("%.2lf"), nGroupTotal);
		FormatCurrency(nGroupTotal, tmpStr);
		rptDetail->SetValue(_T("SumGroupName"), tmpStr);

		nTotal += nGroupTotal;
		nGroupTotal = 0;
	}

	//rptDetail = rpt.AddDetail(rpt.GetReportFooter());
	tmpStr.Format(_T("%s"), _T("T\x1ED5ng \x63\x1ED9ng"));
	rpt.GetReportFooter()->SetValue(_T("TotalAmount"), tmpStr);

	nTotal += 0.5;
	long double nTemp = floor(nTotal);

	m_nTotal = nTemp;

	FormatCurrency(nTemp, tmpStr);
	rpt.GetReportFooter()->SetValue(_T("SumTotalAmount"), tmpStr);

	tmpStr.Format(_T("%.0lf"), nTemp);
	CString szMoney = tmpStr;
	MoneyToString(szMoney, tmpStr);
	rpt.GetReportFooter()->SetValue(_T("SumInWord"), tmpStr);

	szSysDate = pMF->GetSysDate();
	tmpStr.Format(rpt.GetReportFooter()->GetValue(_T("PrintDate")),
		          szSysDate.Right(2), szSysDate.Mid(5, 2), szSysDate.Left(4));

	rpt.GetReportFooter()->SetValue(_T("PrintDate"), tmpStr);
	rpt.PrintPreview();
} 
예제 #19
0
BOOL CEnString::Translate(HWND hwndRef)
{
	return TranslateString(*this, hwndRef);
}
예제 #20
0
int main (int argc, char **argv)
{
int ix,tv,found=0, spr, resolution;
int dloop=1, rcc=-1;
char rstr[BUFSIZE]={0}, *rptr=NULL, *aptr=NULL;
time_t tm1,tm2;
#ifndef MARTII
FILE *fh;
#endif

		if(argc<2)
		{
			ShowUsage();
			return 0;
		}

		//init framebuffer before 1st scale2res
		fb = open(FB_DEVICE, O_RDWR);
#if HAVE_SPARK_HARDWARE || HAVE_DUCKBOX_HARDWARE
		if (fb < 0)
			fb = open(FB_DEVICE_FALLBACK, O_RDWR);
#endif
		if(fb == -1)
		{
			perror(__plugin__ " <open framebuffer device>");
			exit(1);
		}
		if(ioctl(fb, FBIOGET_FSCREENINFO, &fix_screeninfo) == -1)
		{
			perror(__plugin__ " <FBIOGET_FSCREENINFO>\n");
			return -1;
		}
		if(ioctl(fb, FBIOGET_VSCREENINFO, &var_screeninfo) == -1)
		{
			perror(__plugin__ " <FBIOGET_VSCREENINFO>\n");
			return -1;
		}
#if defined(HAVE_SPARK_HARDWARE) || defined(HAVE_DUCKBOX_HARDWARE)
		var_screeninfo.xres = DEFAULT_XRES;
		var_screeninfo.yres = DEFAULT_YRES;
#endif

		if(!(lfb = (uint32_t*)mmap(0, fix_screeninfo.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fb, 0)))
		{
			perror(__plugin__ " <mapping of Framebuffer>\n");
			return -1;
		}

		dloop=0;
		for(tv=1; !dloop && tv<argc; tv++)
		{
			aptr=argv[tv];
			if(!strcmp(aptr,"-v") || !strcmp(aptr,"--version"))
			{
				printf("%s Version %.2f\n", __plugin__, M_VERSION);
				return 0;
			}
			if((rptr=strchr(aptr,'='))!=NULL)
			{
				rptr++;
				if(strstr(aptr,"size=")!=NULL)
				{
					if(sscanf(rptr,"%d",&FSIZE_MED)!=1)
					{
						dloop=1;
					}
				}
				else
				{
					if(strstr(aptr,"title=")!=NULL)
					{
						size_t l = strlen(rptr);
						char *t = (char *)alloca(l * 4 + 1);
						memcpy(t, rptr, l + 1);
						TranslateString(t, l * 4);
						title = strdup(t);
						CatchTabs(title);

						if(strcmp(title,"none")==0)
						{
							header=0;
						}
					}
					else
					{
						if(strstr(aptr,"timeout=")!=NULL)
						{
							if(sscanf(rptr,"%d",&timeout)!=1)
							{
								dloop=1;
							}
						}
						else
						{
							if(strstr(aptr,"msg=")!=NULL)
							{
								dloop=Transform_Msg(rptr);
								if(timeout==0)
								{
										if((timeout=Read_Neutrino_Cfg("timing.epg"))<0)
											timeout=300;
								}
								type=1;
							}
							else
							{
								if(strstr(aptr,"popup=")!=NULL)
								{
									dloop=Transform_Msg(rptr);
									if(timeout==0)
									{
										if((timeout=Read_Neutrino_Cfg("timing.infobar"))<0)
											timeout=6;
									}
									type=2;
								}
								else
								{
									if(strstr(aptr,"refresh=")!=NULL)
									{
										if(sscanf(rptr,"%d",&refresh)!=1)
										{
											dloop=1;
										}
									}
									else
									{
										if(strstr(aptr,"select=")!=NULL)
										{
											dloop=GetSelection(rptr);
										}
										else
										{
											if(strstr(aptr,"default=")!=NULL)
											{
												if((sscanf(rptr,"%d",&selection)!=1) || selection<1)
												{
													dloop=1;
												}
											}
											else
											{
												if(strstr(aptr,"order=")!=NULL)
												{
													if(sscanf(rptr,"%d",&bpline)!=1)
													{
														dloop=1;
													}
												}
												else
												{
													if(strstr(aptr,"echo=")!=NULL)
													{
														if(sscanf(rptr,"%d",&echo)!=1)
														{
															dloop=1;
														}
													}
													else
													{
														if(strstr(aptr,"absolute=")!=NULL)
														{
															if(sscanf(rptr,"%d",&absolute)!=1)
															{
																dloop=1;
															}
														}
														else
														{
															if(strstr(aptr,"hide=")!=NULL)
															{
																if(sscanf(rptr,"%d",&mute)!=1)
																{
																	dloop=1;
																}
															}
															else
															{
																if(strstr(aptr,"cyclic=")!=NULL)
																{
																	if(sscanf(rptr,"%d",&cyclic)!=1)
																	{
																		dloop=1;
																	}
																}
																else
																{
																	if(strstr(aptr,"icon=")!=NULL)
																	{
																		icon=rptr;
																		dloop=Transform_Icon(icon)==0;
																	}
																	else
																	{
																		dloop=2;
																	}
																}
															}
														}
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
			switch (dloop)
			{
				case 1:
					printf("%s <param error: %s>\n", __plugin__, aptr);
					return 0;
					break;
				
				case 2:
					printf("%s <unknown command: %s>\n\n", __plugin__, aptr);
					ShowUsage();
					return 0;
					break;
			}
		}

		FSIZE_BIG=(float)FSIZE_MED*1.25;
		FSIZE_SMALL=(FSIZE_MED*4)/5;
		TABULATOR=2*FSIZE_MED;
		size=FSIZE_MED;
		
		/*
		if(!echo)
		{
			printf("\nMsgBox Version %.2f\n", M_VERSION);
		}
		*/
		if(!buttons)
		{
			butmsg[0]=strdup("OK");
			buttons=1;
		}
		if(!absolute)
		{
			for(tv=0; tv<buttons; tv++)
			{
				rbutt[tv]=tv+1;
			}
		}
		if(selection)
		{	
			for(tv=0; tv<buttons && !found; tv++)		
			{
				if(rbutt[tv]==selection)
				{
					selection=tv+1;
					found=1;
				}
			}
			if(!found)
			{
				printf("%s <param error: default=%d>\n", __plugin__, selection);
				return 0;
			}
		}
		else
		{
			for(tv=0; tv<buttons && !selection; tv++)
			{
				if(strlen(butmsg[tv]))
				{
					selection=tv+1;
				}
			}
		}
		if(!icon)
		{
			icon=strdup("info");
		}
		if(!title)
		{
			title=strdup("Information");
		}
		if((line_buffer=calloc(BUFSIZE+1, sizeof(char)))==NULL)
		{
			printf(NOMEM);
			return -1;
		}
	
		spr=Read_Neutrino_Cfg("screen_preset")+1;
		resolution=Read_Neutrino_Cfg("osd_resolution");

		if (resolution == -1)
			sprintf(line_buffer,"screen_StartX_%s", spres[spr]);
		else
			sprintf(line_buffer,"screen_StartX_%s_%d", spres[spr], resolution);
		if((sx=Read_Neutrino_Cfg(line_buffer))<0)
			sx=scale2res(100);

		if (resolution == -1)
			sprintf(line_buffer,"screen_EndX_%s", spres[spr]);
		else
			sprintf(line_buffer,"screen_EndX_%s_%d", spres[spr], resolution);
		if((ex=Read_Neutrino_Cfg(line_buffer))<0)
			ex=scale2res(1180);

		if (resolution == -1)
			sprintf(line_buffer,"screen_StartY_%s", spres[spr]);
		else
			sprintf(line_buffer,"screen_StartY_%s_%d", spres[spr], resolution);
		if((sy=Read_Neutrino_Cfg(line_buffer))<0)
			sy=scale2res(100);

		if (resolution == -1)
			sprintf(line_buffer,"screen_EndY_%s", spres[spr]);
		else
			sprintf(line_buffer,"screen_EndY_%s_%d", spres[spr], resolution);
		if((ey=Read_Neutrino_Cfg(line_buffer))<0)
			ey=scale2res(620);

		for(ix=CMCST; ix<=CMH; ix++)
		{
			sprintf(rstr,"menu_%s_alpha",menucoltxt[ix]);
			if((tv=Read_Neutrino_Cfg(rstr))>=0)
				tr[ix]=255-(float)tv*2.55;

			sprintf(rstr,"menu_%s_blue",menucoltxt[ix]);
			if((tv=Read_Neutrino_Cfg(rstr))>=0)
				bl[ix]=(float)tv*2.55;

			sprintf(rstr,"menu_%s_green",menucoltxt[ix]);
			if((tv=Read_Neutrino_Cfg(rstr))>=0)
				gn[ix]=(float)tv*2.55;

			sprintf(rstr,"menu_%s_red",menucoltxt[ix]);
			if((tv=Read_Neutrino_Cfg(rstr))>=0)
				rd[ix]=(float)tv*2.55;
		}

		int	cix=CMC;
		for(ix=COL_MENUCONTENT_PLUS_0; ix<=COL_MENUCONTENT_PLUS_3; ix++)
		{
			rd[ix]=rd[cix]+25;
			gn[ix]=gn[cix]+25;
			bl[ix]=bl[cix]+25;
			tr[ix]=tr[cix];
			cix=ix;
		}

		sprintf(rstr,"infobar_alpha");
		if((tv=Read_Neutrino_Cfg(rstr))>=0)
			tr[COL_SHADOW_PLUS_0]=255-(float)tv*2.55;

		sprintf(rstr,"infobar_blue");
		if((tv=Read_Neutrino_Cfg(rstr))>=0)
			bl[COL_SHADOW_PLUS_0]=(float)tv*2.55*0.4;

		sprintf(rstr,"infobar_green");
		if((tv=Read_Neutrino_Cfg(rstr))>=0)
			gn[COL_SHADOW_PLUS_0]=(float)tv*2.55*0.4;

		sprintf(rstr,"infobar_red");
		if((tv=Read_Neutrino_Cfg(rstr))>=0)
			rd[COL_SHADOW_PLUS_0]=(float)tv*2.55*0.4;

		for (ix = 0; ix <= COL_SHADOW_PLUS_0; ix++)
			bgra[ix] = (tr[ix] << 24) | (rd[ix] << 16) | (gn[ix] << 8) | bl[ix];

		if(Read_Neutrino_Cfg("rounded_corners")>0)
		{
			radius = scale2res(11);
			radius_small = scale2res(5);
		}
		else
			radius = radius_small = 0;

		InitRC();
		
		if((trstr=malloc(BUFSIZE))==NULL)
		{
			printf(NOMEM);
			return -1;
		}
		
	//init fontlibrary

		if((error = FT_Init_FreeType(&library)))
		{
			printf("%s <FT_Init_FreeType failed with Errorcode 0x%.2X>", __plugin__, error);
			munmap(lfb, fix_screeninfo.smem_len);
			return -1;
		}

		if((error = FTC_Manager_New(library, 1, 2, 0, &MyFaceRequester, NULL, &manager)))
		{
			printf("%s <FTC_Manager_New failed with Errorcode 0x%.2X>\n", __plugin__, error);
			FT_Done_FreeType(library);
			munmap(lfb, fix_screeninfo.smem_len);
			return -1;
		}

		if((error = FTC_SBitCache_New(manager, &cache)))
		{
			printf("%s <FTC_SBitCache_New failed with Errorcode 0x%.2X>\n", __plugin__, error);
			FTC_Manager_Done(manager);
			FT_Done_FreeType(library);
			munmap(lfb, fix_screeninfo.smem_len);
			return -1;
		}

		Read_Neutrino_Cfg("font_file=");
		if((error = FTC_Manager_LookupFace(manager, FONT, &face)))
		{
			if((error = FTC_Manager_LookupFace(manager, FONT2, &face)))
			{
				printf("%s <FTC_Manager_LookupFace failed with Errorcode 0x%.2X>\n", __plugin__, error);
				FTC_Manager_Done(manager);
				FT_Done_FreeType(library);
				munmap(lfb, fix_screeninfo.smem_len);
				return 2;
			}
			else
				desc.face_id = FONT2;
		}
		else
			desc.face_id = FONT;
		
		use_kerning = FT_HAS_KERNING(face);

		desc.flags = FT_LOAD_RENDER | FT_LOAD_FORCE_AUTOHINT;

		//init backbuffer
#if HAVE_SPARK_HARDWARE || HAVE_DUCKBOX_HARDWARE
		lbb = lfb + 1920 * 1080;
		fix_screeninfo.line_length = DEFAULT_XRES * sizeof(uint32_t);
		stride = DEFAULT_XRES;
#else
		stride = fix_screeninfo.line_length/sizeof(uint32_t);
		if(stride == 7680 && var_screeninfo.xres == 1280) {
			var_screeninfo.yres = 1080;
		}
		if(!(lbb = malloc(var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t))))
		{
			perror(__plugin__ " <allocating of Backbuffer>\n");
			FTC_Manager_Done(manager);
			FT_Done_FreeType(library);
			munmap(lfb, fix_screeninfo.smem_len);
			return -1;
		}
#endif
		if(!(obb = malloc(var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t))))
		{
			perror(__plugin__ " <allocating of Backbuffer>\n");
			FTC_Manager_Done(manager);
			FT_Done_FreeType(library);
			free(lbb);
			munmap(lfb, fix_screeninfo.smem_len);
			return -1;
		}
		if(!(hbb = malloc(var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t))))
		{
			perror(__plugin__ " <allocating of Backbuffer>\n");
			FTC_Manager_Done(manager);
			FT_Done_FreeType(library);
			free(lbb);
			free(obb);
			munmap(lfb, fix_screeninfo.smem_len);
			return -1;
		}
		if(!(ibb = malloc(var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t))))
		{
			perror(__plugin__ " <allocating of Backbuffer>\n");
			FTC_Manager_Done(manager);
			FT_Done_FreeType(library);
			free(lbb);
			free(obb);
			free(hbb);
			munmap(lfb, fix_screeninfo.smem_len);
			return -1;
		}

		if(refresh & 1)
		{
			memcpy(ibb, lbb, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t));
		}
		else
		{
			memset(ibb, TRANSP, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t));
		}
		if(mute==2)
		{
			memcpy(hbb, lbb, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t));
		}
		else
		{
			memset(hbb, TRANSP, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t));
		}
		if(refresh & 2)
		{
			memcpy(obb, lbb, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t));
		}
		else
		{
			memset(obb, TRANSP, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t));
		}

		startx = sx;
		starty = sy;


	/* scale to resolution */
	FSIZE_BIG = scale2res(FSIZE_BIG);
	FSIZE_MED = scale2res(FSIZE_MED);
	FSIZE_SMALL = scale2res(FSIZE_SMALL);

	TABULATOR = scale2res(TABULATOR);

	OFFSET_MED = scale2res(OFFSET_MED);
	OFFSET_SMALL = scale2res(OFFSET_SMALL);
	OFFSET_MIN = scale2res(OFFSET_MIN);

	size = scale2res(size);

	/* Set up signal handlers. */
	signal(SIGINT, quit_signal);
	signal(SIGTERM, quit_signal);
	signal(SIGQUIT, quit_signal);
	signal(SIGSEGV, quit_signal);

	put_instance(instance=get_instance()+1);

  	show_txt(0);	
	
	time(&tm1);
	tm2=tm1;
	
	//main loop
	while((rcc!=KEY_EXIT) && (rcc!=KEY_HOME) && (rcc!=KEY_OK) && ((timeout==-1)||((tm2-tm1)<timeout)))
	{
		rcc=GetRCCode(1000);
		if(rcc!=-1)
		{
			time(&tm1);
		}
		else
		{
			if(cyclic)
				show_txt(0);
#if 0
			if(++cupd>100)
			{
				if(cyclic)
				{
					show_txt(0);
					cupd=0;
				}
			}
			usleep(10000L);
#endif
		}
		if(mute && rcc==KEY_MUTE)
		{
			hide^=1;
			show_txt(0);
#if HAVE_SPARK_HARDWARE || HAVE_DUCKBOX_HARDWARE
			ClearRC();
#else

			while(GetRCCode(300)!=-1);
			if(hide)
			{
				if((fh=fopen(HDF_FILE,"w"))!=NULL)
				{
					fprintf(fh,"hidden");
					fclose(fh);
				}
			}
			else
			{
				remove(HDF_FILE);
			}
#endif
		}
		if((!hide) && (rcc!=KEY_EXIT) && (rcc!=KEY_HOME) && (rcc!=KEY_OK))
		{
			switch(rcc)
			{
				case KEY_LEFT:
					if(!hide && (--selection<1))
					{
						selection=buttons;
					}
					show_txt(1);
				break;
				
				case KEY_RIGHT:
					if(!hide && (++selection>buttons))
					{
						selection=1;
					}
					show_txt(1);
				break;
				
				case KEY_UP:
					if(!hide && ((selection-=bpline)<1))
					{
						selection=1;
					}
					show_txt(1);
				break;
				
				case KEY_DOWN:
					if(!hide && ((selection+=bpline)>buttons))
					{
						selection=buttons;
					}
					show_txt(1);
				break;

				default:
					flash^=1;
				break;
			}
		}
		time(&tm2);
		if(hide)
		{
			rcc=-1;
		}
	}
	if((type!=1) || (rcc!=KEY_OK))
	{
		selection=0;
	}
	
	
	//cleanup
#if HAVE_SPARK_HARDWARE || HAVE_DUCKBOX_HARDWARE
	memcpy(lbb, obb, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t));
	blit();
#else
	memcpy(lfb, obb, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t));
#endif
	munmap(lfb, fix_screeninfo.smem_len);
	close(fb);
#if !defined(HAVE_SPARK_HARDWARE) && !defined(HAVE_DUCKBOX_HARDWARE)
	free(lbb);
#endif

	put_instance(get_instance()-1);

	if(echo && selection>0)
	{
		printf("%s\n",butmsg[selection-1]);
	}

	for(tv=0; tv<buttons; tv++)
	{
		free(butmsg[tv]);
	}
	free(trstr);
	free(line_buffer);
	free(title);

	FTC_Manager_Done(manager);
	FT_Done_FreeType(library);

	free(obb);
	free(hbb);
	free(ibb);

	CloseRC();

	remove("/tmp/msgbox.tmp");

	if(selection)
	{
		return rbutt[selection-1];
	}
	return 0;
}
void CEMWeekSynthesisReport::OnExportSelect(){
	_debug(_T("%s"), CString(typeid(this).name()));
	CHMSMainFrame *pMF = (CHMSMainFrame*) AfxGetMainWnd();
	UpdateData(true);
	CExcel xls;
	CRecord rs(&pMF->m_db);
	CString szSQL, tmpStr, szTemp, szWhere;
	int nCol = 0, nRow = 0;
	int nTotal[12], nTemp = 0;
	szSQL = GetQueryString();
	int nCount = rs.ExecSQL(szSQL);
	if (nCount <= 0)
	{
		ShowMessage(150, MB_ICONSTOP);
		return;
	}
	xls.CreateSheet(1);
	xls.SetWorksheet(0);
	xls.SetColumnWidth(0, 30);
	xls.SetColumnWidth(1, 10);
	xls.SetColumnWidth(2, 10);
	xls.SetColumnWidth(3, 10);
	xls.SetColumnWidth(4, 10);
	xls.SetColumnWidth(5, 10);
	xls.SetColumnWidth(6, 10);
	xls.SetColumnWidth(7, 10);
	xls.SetColumnWidth(8, 10);
	xls.SetColumnWidth(9, 10);
	xls.SetColumnWidth(10, 10);
	xls.SetColumnWidth(11, 13);

	CellFormat df(&xls), hf(&xls), nf(&xls);
	df.SetItalic(true);
	df.SetCellStyle(FMT_TEXT | FMT_CENTER);
	hf.SetBold(true);
	hf.SetCellStyle(FMT_TEXT | FMT_CENTER);
	nf.SetCellStyle(FMT_NUMBER1);
	//Header
	xls.SetCellMergedColumns(nCol, nRow, 3);
	xls.SetCellMergedColumns(nCol, nRow + 1, 3);
	xls.SetCellMergedColumns(nCol, nRow + 2, 11);
	xls.SetCellMergedColumns(nCol, nRow + 3, 11);
	xls.SetCellText(nCol, nRow, pMF->m_CompanyInfo.sc_pname, FMT_TEXT | FMT_CENTER, true, 10);
	xls.SetCellText(nCol, nRow + 1, pMF->m_CompanyInfo.sc_name, FMT_TEXT | FMT_CENTER, true, 10);
	TranslateString(_T("Weekly Synthesis Report"), szTemp);
	StringUpper(szTemp, tmpStr);
	xls.SetCellText(nCol, nRow + 2, tmpStr, FMT_TEXT | FMT_CENTER, true, 12);	
	tmpStr.Format(_T("T\x1EEB ng\xE0y %s \x111\x1EBFn ng\xE0y %s"), CDateTime::Convert(m_szFromDate, yyyymmdd|hhmmss, ddmmyyyy|hhmmss), CDateTime::Convert(m_szToDate, yyyymmdd|hhmmss, ddmmyyyy|hhmmss));
	xls.SetCellText(nCol, nRow + 3, tmpStr, &df);	
	
	//Column Header
	CStringArray arrCol;
	arrCol.Add(_T("Ph\xF2ng"));
	arrCol.Add(_T("Qu\xE2n"));
	arrCol.Add(_T("\x42HYT Qu\xE2n"));
	arrCol.Add(_T("\x42\x1EA1n"));
	arrCol.Add(_T("Tr\x1EBB < \x36t"));
	arrCol.Add(_T("\x43h\xEDnh s\xE1\x63h"));
	arrCol.Add(_T("\x44\xE2n"));
	arrCol.Add(_T("\x42HYT kh\xE1\x63"));
	arrCol.Add(_T("\x42H TNSQ"));
	arrCol.Add(_T("\x42H Qu\xE2n \x111\x1ED9i"));
	arrCol.Add(_T("BHYT Qu\xE2n nh\xE2n"));
	arrCol.Add(_T("BHYT(N\x1EE3 th\x1EBB)"));
	arrCol.Add(_T("T\x1ED5ng \x63\x1ED9ng"));
	nRow = 4;
	for (int i = 0; i < arrCol.GetCount(); i++)
	{
		xls.SetCellText(nCol+i, nRow, arrCol.GetAt(i), FMT_TEXT | FMT_CENTER, true, 10); 
	}
	for (int i = 0; i< 12; i++)
	{
		nTotal[i] = 0;
	}
	nRow = 5;
	while (!rs.IsEOF()){
		rs.GetValue(_T("roomid"), tmpStr);
		xls.SetCellText(nCol, nRow, tmpStr, FMT_TEXT);
		for (int i = 0; i< 12; i++)
		{
			szTemp.Format(_T("c%d"), i+1);
			rs.GetValue(szTemp, nTemp);
			tmpStr.Format(_T("%d"), nTemp);
			xls.SetCellText(nCol+i+1, nRow, tmpStr, &nf);
			nTotal[i] += nTemp;
		}
		nRow++;
		rs.MoveNext();
	}
	TranslateString(_T("Total"), tmpStr);
	xls.SetCellText(nCol, nRow, tmpStr, FMT_TEXT | FMT_CENTER, true);
	for (int i = 0; i<12; i++)
	{
		tmpStr.Format(_T("%d"), nTotal[i]);
		xls.SetCellText(nCol+i+1, nRow, tmpStr, FMT_NUMBER1, true);
	}
	szWhere.Format(_T(" AND hcr_admitdate BETWEEN cast_string2timestamp('%s') AND cast_string2timestamp('%s')"), m_szFromDate, m_szToDate);
	if (pMF->GetModuleID() == _T("EM"))
		szWhere.AppendFormat(_T(" AND hd_enddept = '%s'"), pMF->GetCurrentDepartmentID());
	szSQL.Format(_T(" SELECT sum(c1) as c1,") \
				_T("        sum(c2) as c2,") \
				_T("        sum(c3) as c3,") \
				_T("        sum(c4) as c4,") \
				_T("        sum(c5) as c5,") \
				_T("        sum(c6) as c6,") \
				_T("        sum(c7) as c7,") \
				_T("        sum(c8) as c8,") \
				_T("        sum(c9) as c9,") \
				_T("        sum(c10) as c10,  ") \
				_T("        sum(c11) as c11,  ") \
				_T("        sum(c12) as c12  ") \
				_T(" FROM") \
				_T(" (") \
				_T("   SELECT") \
				_T("      case when hd_object=1 then 1 else 0 end as c1,") \
				_T("      case when hd_object=2 then 1 else 0 end as c2,") \
				_T("      case when hd_object=8 then 1 else 0 end as c3,") \
				_T("      case when hd_object in(6, 9) then 1 else 0 end as c4,") \
				_T("      case when hd_object=3 then 1 else 0 end as c5,") \
				_T("      case when hd_object=7 then 1 else 0 end as c6,") \
				_T("      case when hd_object=4 then 1 else 0 end as c7,") \
				_T("      case when hd_object=5 then 1 else 0 end as c8,") \
				_T("      case when hd_object=10 then 1 else 0 end as c9,") \
				_T("      case when hd_object=11 then 1 else 0 end as c10,") \
				_T("      case when hd_object=12 then 1 else 0 end as c11,") \
				_T("      1 as c12 ") \
				_T("    FROM hms_doc") \
				_T("	LEFT JOIN hms_exam ON (he_docno = hd_docno AND hd_doctor = he_doctor)") \
				_T("    LEFT JOIN hms_clinical_record ON(hcr_docno=hd_docno)") \
				_T("    WHERE hcr_numinward > 0 %s") \
				_T(" ) tbl"), szWhere);
	rs.ExecSQL(szSQL);
	_fmsg(_T("%s"), szSQL);
	if (!rs.IsEOF()){
		nRow++;
		xls.SetCellText(nCol, nRow, _T("V\xE0o vi\x1EC7n"), FMT_TEXT | FMT_CENTER, true);
		for (int i = 0; i< 12; i++)
		{
			szTemp.Format(_T("c%d"), i+1);
			rs.GetValue(szTemp, tmpStr);
			xls.SetCellText(nCol+i+1, nRow, tmpStr, FMT_NUMBER1, true);
		}
	}
	else
	{
		ShowMessage(150, MB_ICONSTOP);
		return;
	}
	xls.Save(_T("Exports\\Bao Cao Tong Hop Tuan C1_1.xls"));
	
} 
/*------------------------------------------------------------------------------------------------------------------------------
	Export To Excell Bao cao tong hop nhap xuat ton kho
------------------------------------------------------------------------------------------------------------------------------*/
void rptDonthuoctonghop::OnExportToXLS(){
	CMainFrame_E10 *pMF = (CMainFrame_E10 *) AfxGetMainWnd();
	CString tmpStr,szSQL, szWhere, szTemp;

	CString szType, szTypeName;
	for (int i=0 ; i<= m_wndType.GetCount(); i++)
	{
		 if(m_wndType.GetCheck(i))
		 {
			 m_wndType.SetCurSel(i);
			 if(!szType.IsEmpty())
			 {
				szType += _T(",");
				szTypeName +=_T(", ");

			 }
			 szType.AppendFormat(_T("'%s'"), m_wndType.GetCurrent(0));				
			 szTypeName.AppendFormat(_T("%s"), m_wndType.GetCurrent(1));
		}		
	 }
	

	if(!szType.IsEmpty())	
		szWhere.AppendFormat(_T(" and mp_producttype in(%s)"), szType);	
	else
		szTypeName.Format(_T("T\x1EA5t \x63\x1EA3 lo\x1EA1i thu\x1ED1\x63"));

	if(!m_szGroupKey.IsEmpty())
	{
		szWhere.AppendFormat(_T(" and substr(mp_product_class_id, 1, %d)= '%s' "), m_szGroupKey.GetLength(), m_szGroupKey);
	}

	if(str2int(m_szSourceKey) > 0)
	{
		szWhere.AppendFormat(_T(" and mpi_resource_id=%d "), str2int(m_szSourceKey));
	}
	if (!m_szStockKey.IsEmpty())
		szWhere.AppendFormat(_T(" and expstockid = %d"), ToInt(m_szStockKey));
	szSQL.Format(_T("  SELECT  ") \
				_T(" 	mp_name as name, ") \
				_T(" 	mpc_name as genericname, ") \
				_T(" 	get_uomname(mp_uom_id) as unit, ") \
				_T(" 	mpi_taxprice as price, ") \
				_T(" 	sum(expqty) as qty,") \
				_T(" 	sum(expqty*mpi_taxprice) as amount") \
				_T(" FROM mev") \
				_T(" LEFT JOIN m_product_item ON(mpi_product_item_id=sitemid)") \
				_T(" LEFT JOIN m_product ON(mpi_product_id=mp_product_id)") \
				_T(" LEFT JOIN m_product_class ON(mpc_product_class_id=mp_product_class_id) ") \
				_T(" WHERE sitemid > 0 AND iotype = 'PPO' and expdate between cast_string2timestamp('%s') and cast_string2timestamp('%s') %s ") \
				_T(" GROUP BY mp_name,mpc_name,mp_uom_id,mpi_taxprice") \
				_T(" ORDER BY name,unit"), m_szFromDate, m_szToDate, szWhere);	
	CReportSection* rptDetail=NULL;
	CRecord rs(&pMF->m_db);	
	double cost = 0;
	int nItem = 1;
				

	rs.ExecSQL(szSQL);
	if(rs.IsEOF()){
		ShowMessage(150, MB_ICONSTOP);
		return ;
	}
	
			
	CExcel xls;
	xls.CreateSheet(1);
	xls.SetWorksheet(0);
	CellFormat df(&xls), cf(&xls), hf(&xls);
	df.SetItalic(true);
	df.SetCellStyle(FMT_TEXT | FMT_CENTER);
	hf.SetBold(true);
	hf.SetCellStyle(FMT_TEXT | FMT_CENTER);
	cf.SetFontName(_T("Segoe UI"));

	xls.SetColumnWidth(0, 5);
	xls.SetColumnWidth(1, 35);
	xls.SetColumnWidth(2, 35);
	xls.SetColumnWidth(3, 10);
	xls.SetColumnWidth(4, 10);
	xls.SetColumnWidth(5, 10);
	xls.SetColumnWidth(6, 15);	
	xls.SetCellMergedColumns(0, 0, 2);
	xls.SetCellMergedColumns(0, 1, 2);
	xls.SetCellText(0, 0, pMF->m_szHealthService, FMT_TEXT | FMT_CENTER, true, 10);
	xls.SetCellText(0, 1, pMF->m_szHospitalName, FMT_TEXT | FMT_CENTER, true, 10);
	xls.SetCellMergedColumns(0, 2, 7);
	TranslateString(_T("General Prescription"), szTemp);
	StringUpper(szTemp, tmpStr);
	xls.SetCellText(0, 2, tmpStr,FMT_TEXT | FMT_CENTER, true, 12);
	xls.SetCellMergedColumns(0, 3, 7);
	tmpStr.Format(_T("T\x1EEB ngày %s \x111\x1EBFn ngày %s"), CDateTime::Convert(m_szFromDate, yyyymmdd|hhmm, ddmmyyyy|hhmm), CDateTime::Convert(m_szToDate, yyyymmdd|hhmm, ddmmyyyy|hhmm));
	xls.SetCellText(0, 3, tmpStr, &df);

	int nRow = 3;
	if (!m_szStockKey.IsEmpty())
	{
		nRow++;
		tmpStr.Format(_T("T\x1EEB kho: %s"), m_wndStock.GetCurrent(1));
		xls.SetCellMergedColumns(0, nRow, 7);
		xls.SetCellText(0, nRow, tmpStr, &cf);
	}
	if(!m_szTypeKey.IsEmpty())
	{
		nRow++;
		tmpStr.Format(_T("Lo\x1EA1i: %s"), m_wndType.GetCurrent(1));
		xls.SetCellMergedColumns(0, nRow, 7);
		xls.SetCellText(0, nRow, tmpStr, &cf);
	}
	if(!m_szGroupKey.IsEmpty())
	{
		nRow++;
		tmpStr.Format(_T("Nhóm: %s"), m_wndGroup.GetCurrent(1));
		xls.SetCellMergedColumns(0, nRow, 7);
		xls.SetCellText(0, nRow, tmpStr, &cf);
	}
	if(!m_szSourceKey.IsEmpty())
	{
		nRow++;
		tmpStr.Format(_T("Ngu\x1ED3n: %s"), m_wndSource.GetCurrent(1));
		xls.SetCellMergedColumns(0, nRow, 7);
		xls.SetCellText(0, nRow, tmpStr, &cf);
	}
	nRow++;
	xls.SetCellText(0, nRow, _T("STT"), &hf);	
	xls.SetCellText(1, nRow, _T("Tên thu\x1ED1\x63/ HL"), &hf);	
	xls.SetCellText(2, nRow, _T("T\xEAn ho\x1EA1t \x63h\x1EA5t"), &hf);	
	xls.SetCellText(3, nRow, _T("\x110\x1A1n v\x1ECB"), &hf);	
	xls.SetCellText(4, nRow, _T("\x110\x1A1n giá"), &hf);	
	xls.SetCellText(5, nRow, _T("S\x1ED1 l\x1B0\x1EE3ng"), &hf);	
	xls.SetCellText(6, nRow, _T("Th\xE0nh ti\x1EC1n"), &hf);	
		
	double Amount=0.0, ttCost =0.0;		
	while(!rs.IsEOF())
	{
		//rs.GetValue(_T("expinvoice"), szNewLine);
		//if(szNewLine != szOldLine && !szNewLine.IsEmpty())
		//{
		//	nRow++;
		//	CString szField, szAmount;
		//	xls.SetCellText(1, nRow, szNewLine, FMT_TEXT,true);			
		//	rs.GetValue(_T("iotype"), tmpStr);
		//	xls.SetCellText(2,nRow,pMF->GetSelectionString(_T("pms_export_type"), tmpStr),FMT_TEXT,true);
		//	rs.GetValue(_T("expdate"), tmpStr);
		//	xls.SetCellText(3, nRow, CDate::Convert(tmpStr,yyyymmdd,ddmmyyyy), FMT_DATE,true);
		//	rs.GetValue(_T("deptid"), tmpStr);
		//	xls.SetCellText(4,nRow,tmpStr,FMT_TEXT, true);			

		//	if (grpCost >0)
		//	{
		//		tmpStr.Format(_T("%.2f"), grpCost);
		//		xls.SetCellText(6,nRow-nItem,tmpStr,FMT_NUMBER1,true);
		//		ttCost += grpCost;	
		//	}

		//	szOldLine = szNewLine;
		//	nItem=1;
		//	grpCost= 0;
		//}

		nRow ++;
		tmpStr.Format(_T("%d"), nItem++);
		xls.SetCellText(0,nRow,tmpStr, FMT_NUMBER1);		
		rs.GetValue(_T("name"), tmpStr);
		xls.SetCellText(1,nRow,tmpStr, FMT_TEXT);
		rs.GetValue(_T("genericname"), tmpStr);
		xls.SetCellText(2,nRow,tmpStr, FMT_TEXT);
		rs.GetValue(_T("unit"), tmpStr);		
		xls.SetCellText(3,nRow,tmpStr, FMT_TEXT);
		rs.GetValue(_T("price"), tmpStr);
		xls.SetCellText(4,nRow,tmpStr, FMT_NUMBER1);		
		rs.GetValue(_T("qty"), tmpStr);
		xls.SetCellText(5,nRow,tmpStr, FMT_NUMBER1);		
		rs.GetValue(_T("amount"), Amount);		
		ttCost +=Amount;
		tmpStr.Format(_T("%.2f"), Amount);
		xls.SetCellText(6,nRow,tmpStr, FMT_NUMBER1);		
		rs.MoveNext();
	}

	//if (grpCost >0)
	//{	nRow++;
	//	tmpStr.Format(_T("%.2f"), grpCost);
	//	xls.SetCellText(6,nRow-nItem,tmpStr,FMT_NUMBER1,true);
	//	ttCost += grpCost;	
	//}
	
	if (ttCost >0)	{
		nRow++;
		xls.SetCellText(1,nRow,_T("T\x1ED5ng ti\x1EC1n:"), FMT_TEXT,true);
		tmpStr.Format(_T("%.2f"), ttCost);
		xls.SetCellText(6,nRow,tmpStr,FMT_NUMBER1,true);
	}
	
	xls.Save(_T("Exports\\Don Thuoc Tong Hop.XLS"));
}
void CTMTreatmentActivitybyDept::ExportHoatdongdieutri(CString szFromDate, CString szToDate, CString szDoctor)
{
	CHMSMainFrame *pMF = (CHMSMainFrame*) AfxGetMainWnd();
	CRecord rs(&pMF->m_db);
	CString szSQL, tmpStr, tmpStr1, szFromDateLabel, szToDateLabel, szWhere,szAmount, szOutpatient, m_szStatus;
	CString szDate, szSysDate;
	szSysDate = pMF->GetSysDate(); 
	CReport rpt; 
	
	szSQL = GetQueryString();

	BeginWaitCursor();
_fmsg(_T("%s"), szSQL);
	rs.ExecSQL(szSQL);
	if (rs.IsEOF())
	{
		AfxMessageBox(_T("No Data"));
		return;
	}	
	CExcel xls;	
	xls.CreateSheet(1);
	xls.SetWorksheet(0);
	xls.SetColumnWidth(1, 40);
	xls.SetCellMergedColumns(0, 1, 2);
	xls.SetCellMergedColumns(0, 2, 2);		
	xls.SetCellText(0, 1, pMF->m_CompanyInfo.sc_pname,4098,true,12,0);
	xls.SetCellText(0, 2, pMF->m_CompanyInfo.sc_name,4098,true,12,0);
	xls.SetCellMergedColumns(0,4,14);	
	xls.SetCellText(0, 4, _T("\x42\xC1O \x43\xC1O HO\x1EA0T \x110\x1ED8NG TH\x45O L\x1AF\x1EE2T \x110I\x1EC0U TR\x1ECA"),4098,true,16,0);
	xls.SetCellMergedColumns(0,5,12);
	tmpStr.Format(_T("T\x1EEB ng\xE0y %s \x111\x1EBFn ng\xE0y %s"), CDate::Convert(m_szFromDate, yyyymmdd, ddmmyyyy), CDate::Convert(m_szToDate, yyyymmdd, ddmmyyyy));
	xls.SetCellText(0, 5, tmpStr,4098,true,12,0);
	
	
	int nRow = 7, age=0;
	xls.SetCellText(0, nRow, _T("STT"), 528386,true);	
	TranslateString(_T("Dept"), tmpStr);
	xls.SetCellText(1, nRow, tmpStr, 528386,true);
	TranslateString(_T("Bed"), tmpStr);	
	xls.SetCellText(2, nRow, tmpStr, 528386,true);	
	TranslateString(_T("\x110\x1EA7u k\x1EF3"), tmpStr);
	xls.SetCellText(3, nRow, tmpStr, 528386,true);	
	TranslateString(_T("Total"), tmpStr);
	xls.SetCellText(4, nRow, tmpStr, 528386,true);	
	TranslateString(_T("Children < 6 Age"), tmpStr);
	xls.SetCellText(5, nRow, tmpStr, 528386,true);
	TranslateString(_T("Tr\x1EBB < 24 ng\xE0y"), tmpStr);
	xls.SetCellText(6, nRow, tmpStr, 528386,true);
	TranslateString(_T("Emergency"), tmpStr);
	xls.SetCellText(7, nRow, tmpStr, 528386,true);	
	TranslateString(_T("Ng\xE0y DT"), tmpStr);
	xls.SetCellText(8, nRow, tmpStr, 528386,true);
	TranslateString(_T("T\x1ED5ng s\x1ED1 t\x1EED vong"), tmpStr);
	xls.SetCellText(9, nRow, tmpStr, 528386,true);	

	TranslateString(_T("Tr\x1EBB < 6 tu\x1ED5i t\x1EED vong"), tmpStr);
	xls.SetCellText(10, nRow, tmpStr, 528386,true);

	TranslateString(_T("T\x1EED vong 24 ng\xE0y"), tmpStr);
	xls.SetCellText(11, nRow, tmpStr, 528386,true);	

	TranslateString(_T("T\x1EED vong tr\x1B0\x1EDB\x63 24 gi\x1EDD"), tmpStr);
	xls.SetCellText(12, nRow, tmpStr, 528386,true);	

	TranslateString(_T("T\x1EED vong s\x61u 24 gi\x1EDD"), tmpStr);
	xls.SetCellText(13, nRow, tmpStr, 528386,true);	

	TranslateString(_T("BHYT"), tmpStr);
	xls.SetCellText(14, nRow, tmpStr, 528386,true);	
	
	TranslateString(_T("Hospital Transfer"), tmpStr);
	xls.SetCellText(15, nRow, tmpStr, 528386,true);

	TranslateString(_T("T\x1ED3n \x63u\x1ED1i k\x1EF3"), tmpStr);
	xls.SetCellText(16, nRow, tmpStr, 528386,true);

	int nIndex = 1, SongayDT=0;
	int i=0,nTotal[17];
	for (i=0;i<=16;i++)
	{
		nTotal[i]=0;
	}
	while(!rs.IsEOF())
	{
		nRow++;
		tmpStr.Format(_T("%d"), nIndex++);
		xls.SetCellText(0, nRow, tmpStr, FMT_INTEGER);
		rs.GetValue(_T("Deptname"), tmpStr);
		xls.SetCellText(1, nRow, tmpStr, FMT_TEXT);
		rs.GetValue(_T("Totalbed"), tmpStr);
		nTotal[2] += ToInt(tmpStr);
		xls.SetCellText(2, nRow, tmpStr, FMT_NUMBER1);
		rs.GetValue(_T("oldpatient"), tmpStr);
		nTotal[3] += ToInt(tmpStr);
		xls.SetCellText(3, nRow, tmpStr, FMT_NUMBER1);
		rs.GetValue(_T("Admission"), tmpStr);
		nTotal[4] += ToInt(tmpStr);
		xls.SetCellText(4, nRow, tmpStr, FMT_NUMBER1);
		rs.GetValue(_T("tre15"), tmpStr);
		nTotal[5] += ToInt(tmpStr);
		xls.SetCellText(5, nRow, tmpStr, FMT_NUMBER1);
		rs.GetValue(_T("Tre24Day"), tmpStr);
		nTotal[6] += ToInt(tmpStr);
		xls.SetCellText(6, nRow, tmpStr, FMT_NUMBER1);
		rs.GetValue(_T("emergency"), tmpStr);
		nTotal[7] += ToInt(tmpStr);
		xls.SetCellText(7, nRow, tmpStr, FMT_NUMBER1);
		rs.GetValue(_T("SongayDT"), tmpStr);
		rs.GetValue(_T("SongayDTO"), tmpStr1);
		if (m_bCheckBed) 
			SongayDT=(ToInt(tmpStr));
		else
			SongayDT=(ToInt(tmpStr) + ToInt(tmpStr1));

		nTotal[8] += SongayDT;
		tmpStr.Format(_T("%ld"), SongayDT);
		xls.SetCellText(8, nRow, tmpStr, FMT_NUMBER1);
		rs.GetValue(_T("dead"), tmpStr);
		nTotal[9] += ToInt(tmpStr);
		xls.SetCellText(9, nRow, tmpStr, FMT_NUMBER1);
		rs.GetValue(_T("dead15"), tmpStr);
		nTotal[10] += ToInt(tmpStr);
		xls.SetCellText(10, nRow, tmpStr, FMT_NUMBER1);
		rs.GetValue(_T("Dead24Day"), tmpStr);
		nTotal[11] += ToInt(tmpStr);
		xls.SetCellText(11, nRow, tmpStr, FMT_NUMBER1);
		rs.GetValue(_T("Dead24h"), tmpStr);
		nTotal[12] += ToInt(tmpStr);
		xls.SetCellText(12, nRow, tmpStr, FMT_NUMBER1);
		rs.GetValue(_T("Dead24hf"), tmpStr);
		nTotal[13] += ToInt(tmpStr);
		xls.SetCellText(13, nRow, tmpStr, FMT_NUMBER1);

		rs.GetValue(_T("BHYT"), tmpStr);
		nTotal[14] += ToInt(tmpStr);
		xls.SetCellText(14, nRow, tmpStr, FMT_NUMBER1);

		rs.GetValue(_T("Chuyenvien"), tmpStr);		
		nTotal[15] += ToInt(tmpStr);
		xls.SetCellText(15, nRow, tmpStr, FMT_NUMBER1);

		rs.GetValue(_T("remain"), tmpStr);		
		nTotal[16] += ToInt(tmpStr);
		xls.SetCellText(16, nRow, tmpStr, FMT_NUMBER1);
		rs.MoveNext();
	}
	
	nRow++;
	TranslateString(_T("Total"),tmpStr);
	xls.SetCellText(1, nRow, tmpStr, FMT_TEXT, true);
	for (int i =2; i <= 16; i++){		
		tmpStr.Format(_T("%d"),nTotal[i] );		
		xls.SetCellText(i, nRow, tmpStr, FMT_NUMBER1, true);
	}

	xls.Save(_T("Exports\\Bao cao hoat dong dieu tri theo luot dieu tri.xls"));
	EndWaitCursor();
}
/*void CFMDischargeDepositUnpaidReport::OnClerkAddNew(){
	CHMSMainFrame *pMF = (CHMSMainFrame*) AfxGetMainWnd();
	
} */
void CFMDischargeDepositUnpaidReport::OnPrintSelect()
{
	CHMSMainFrame *pMF = (CHMSMainFrame*) AfxGetMainWnd();
	UpdateData(true);
	CReport rpt;
	CReportSection *rptDetail;
	CRecord rs(&pMF->m_db);
	CString szSQL, tmpStr, szTemp, szSysDate, szOldLine, szNewLine, szObjectNames;
	bool bCheckServ = false, bCheckIns = false;
	long double nGroupTotal[10];
	long double nTotal[10];
	double nCost;
	int nIndex = 1;
	CStringArray strArr;
	szSQL = GetQueryString();
	BeginWaitCursor();
	rs.ExecSQL(szSQL);

	if (rs.IsEOF())
	{
		ShowMessageBox(_T("No Data"), MB_OK | MB_ICONERROR);
		return;
	}

	if (!rpt.Init(_T("Reports/HMS/HF_DANHSACHBENHNHANTAMGUIDARAVIENCHUATHANHTOAN.RPT")))
		return;

	rpt.GetReportHeader()->SetValue(_T("HEALTHSERVICE"), pMF->m_CompanyInfo.sc_pname);
	rpt.GetReportHeader()->SetValue(_T("HOSPITALNAME"), pMF->m_CompanyInfo.sc_name);
	rpt.GetReportHeader()->SetValue(_T("Department"), pMF->GetCurrentDepartmentName());
	tmpStr.Format(rpt.GetReportHeader()->GetValue(_T("ReportDate")), CDateTime::Convert(m_szFromDate, yyyymmdd|hhmm, ddmmyyyy|hhmm),
	CDateTime::Convert(m_szToDate, yyyymmdd|hhmm, ddmmyyyy|hhmm));

	rpt.GetReportHeader()->SetValue(_T("ReportDate"), tmpStr);

	for (int i = 0; i < 10; i++)
	{
		nGroupTotal[i] = 0;
		nTotal[i] = 0;
	}

	szObjectNames.Empty();

	strArr.Add(_T("\x64\x1ECB\x63h v\x1EE5"));
	strArr.Add(_T("\x42\x110 - \x43S - \x42H"));

	for (int i = 0; i < m_wndObjectList.GetItemCount(); i++)
	{
		if (m_wndObjectList.GetCheck(i))
		{
			tmpStr = m_wndObjectList.GetItemText(i, 2);

			if (tmpStr == _T("S"))
				bCheckServ = true;
			else
				bCheckIns = true;
		}
	}

	if (bCheckServ || bCheckIns)
	{
		if (bCheckServ)
			szObjectNames.AppendFormat(_T("%s"), strArr[0]);

		if (bCheckIns)
		{
			if (!szObjectNames.IsEmpty())
				szObjectNames += _T(", ");
			szObjectNames.AppendFormat(_T("%s"), strArr[1]);
		}

		TranslateString(_T("Object"), szTemp);
		tmpStr.Format(_T("%s %s"), szTemp, szObjectNames);
		rpt.GetReportHeader()->SetValue(_T("Object"), tmpStr);
	}

	if (!bCheckIns && !bCheckServ)
		rpt.GetReportHeader()->SetValue(_T("Object"), _T("T\x1EA5t \x63\x1EA3 \x63\xE1\x63 \x111\x1ED1i t\x1B0\x1EE3ng"));

	while (!rs.IsEOF())
	{
		rs.GetValue(_T("dept"), szNewLine);

		if (!szNewLine.IsEmpty() && szNewLine != szOldLine)
		{
			if (nGroupTotal[4] > 0)
			{
				rptDetail = rpt.AddDetail(rpt.GetGroupFooter(1));
				//TranslateString(_T("\x43\x1ED9ng kho\x61"), tmpStr);
				rptDetail->SetValue(_T("TotalGroup"), _T("\x43\x1ED9ng kho\x61"));
				for (int i = 4; i < 10; i++)
				{
					FormatCurrency(nGroupTotal[i], tmpStr);
					szTemp.Format(_T("s%d"), i+1);
					rptDetail->SetValue(szTemp, tmpStr);
					nTotal[i] += nGroupTotal[i];
					nGroupTotal[i] = 0;
				}
			}
			/*rptDetail = rpt.AddDetail(rpt.GetGroupHeader(1));
			rs.GetValue(_T("objname"), tmpStr);
			rptDetail->SetValue(_T("GroupName"), tmpStr);
			rs.GetValue(_T("objid"), szObject);*/
			szOldLine = szNewLine;
		}

		rptDetail = rpt.AddDetail();

		tmpStr.Format(_T("%d"), nIndex++);
		rptDetail->SetValue(_T("1"), tmpStr);

		rs.GetValue(_T("pname"), tmpStr);
		rptDetail->SetValue(_T("2"), tmpStr);

		rs.GetValue(_T("recordno"), tmpStr);
		rptDetail->SetValue(_T("3"), tmpStr);

		if (nGroupTotal[4] == 0)
		{
			rs.GetValue(_T("dept"), tmpStr);
			rptDetail->SetValue(_T("4"), tmpStr);
		}

		rs.GetValue(_T("deposit"), nCost);
		nGroupTotal[4] += nCost;
		FormatCurrency(nCost, tmpStr);
		rptDetail->SetValue(_T("5"), tmpStr);

		rs.GetValue(_T("polamt"), nCost);
		nGroupTotal[5] += nCost;
		FormatCurrency(nCost, tmpStr);
		rptDetail->SetValue(_T("6"), tmpStr);

		rs.GetValue(_T("discountamt"), nCost);
		nGroupTotal[6] += nCost;
		FormatCurrency(nCost, tmpStr);
		rptDetail->SetValue(_T("7"), tmpStr);

		rs.GetValue(_T("feeamt"), nCost);
		nGroupTotal[7] += nCost;
		FormatCurrency(nCost, tmpStr);
		rptDetail->SetValue(_T("8"), tmpStr);

		rs.GetValue(_T("income"), nCost);
		nGroupTotal[8] += nCost;
		FormatCurrency(nCost, tmpStr);
		rptDetail->SetValue(_T("9"), tmpStr);

		rs.GetValue(_T("outlay"), nCost);
		nGroupTotal[9] += nCost;
		FormatCurrency(nCost, tmpStr);
		rptDetail->SetValue(_T("10"), tmpStr);
		
		rs.MoveNext();
	}

	if (nGroupTotal[4] > 0)
	{
		rptDetail = rpt.AddDetail(rpt.GetGroupFooter(1));
		//TranslateString(_T("\x43\x1ED9ng kho\x61"), tmpStr);
		rptDetail->SetValue(_T("TotalGroup"), _T("\x43\x1ED9ng kho\x61"));
		for (int i = 4; i < 10; i++)
		{
			FormatCurrency(nGroupTotal[i], tmpStr);
			szTemp.Format(_T("s%d"), i+1);
			rptDetail->SetValue(szTemp, tmpStr);
			nTotal[i] += nGroupTotal[i];
			nGroupTotal[i] = 0;
		}
	}

	if (nTotal[4] > 0)
	{
		rptDetail = rpt.AddDetail(rpt.GetGroupFooter(1));
		//TranslateString(_T("T\x1ED5ng \x63\x1ED9ng"), tmpStr);
		rptDetail->SetValue(_T("TotalGroup"), _T("T\x1ED5ng \x63\x1ED9ng"));
		for (int i = 4; i < 10; i++)
		{
			FormatCurrency(nTotal[i], tmpStr);
			szTemp.Format(_T("s%d"), i+1);
			rptDetail->SetValue(szTemp, tmpStr);
		}
	}

	if (!m_szClerkKey.IsEmpty())
	{
		tmpStr = m_wndClerk.GetCurrent(1);
		StringUpper(tmpStr, szTemp);
		rpt.GetReportFooter()->SetValue(_T("ReceiverBy"), szTemp);
	}

	szSysDate = pMF->GetSysDate();
	tmpStr.Format(rpt.GetReportFooter()->GetValue(_T("PrintDate")),
		          szSysDate.Right(2), szSysDate.Mid(5, 2), szSysDate.Left(4));
	rpt.GetReportFooter()->SetValue(_T("PrintDate"), tmpStr);

	EndWaitCursor();
	rpt.PrintPreview();
} 
void CTMTreatmentActivitybyDept::PrintHoatdongdieutri(CString szFromDate, CString szToDate, CString szDoctor, bool bPreview){
	CHMSMainFrame *pMF = (CHMSMainFrame*) AfxGetMainWnd();
	CRecord rs(&pMF->m_db);
	CString szSQL, tmpStr, tmpStr1, szFromDateLabel, szToDateLabel, szWhere,szAmount, szOutpatient, m_szStatus;
	CString szDate, szSysDate;
	szSysDate = pMF->GetSysDate(); 
	CReport rpt;
	
	szSQL = GetQueryString();			
	BeginWaitCursor();
	rs.ExecSQL(szSQL);
	if (rs.IsEOF())
	{
		AfxMessageBox(_T("No Data"));
		return;
	}
	if(!rpt.Init(_T("Reports/HMS/RPT_HOATDONGDIEUTRI.RPT"))) return ;
	//Report Header
	tmpStr = rpt.GetReportHeader()->GetValue(_T("ReportDate"));
	szDate.Format(tmpStr, CDate::Convert(szFromDate, yyyymmdd, ddmmyyyy),CDate::Convert(szToDate, yyyymmdd, ddmmyyyy));
	rpt.GetReportHeader()->SetValue(_T("ReportDate"), szDate);
	rpt.GetReportHeader()->SetValue(_T("HEALTHSERVICE"), pMF->m_CompanyInfo.sc_pname);
	rpt.GetReportHeader()->SetValue(_T("HOSPITALNAME"), pMF->m_CompanyInfo.sc_name);
	//Report Detail
	CReportSection* rptDetail = rpt.GetDetail(); 
	int nIndex = 1, SongayDT=0;
	int i=0,nTotal[18];
	for (i=0;i<18;i++)
	{
		nTotal[i]=0;
	}
	while(!rs.IsEOF())
	{
		rptDetail = rpt.AddDetail();			
		tmpStr.Format(_T("%d"), nIndex++);
		rptDetail->SetValue(_T("1"), tmpStr);
		rs.GetValue(_T("Deptname"), tmpStr);
		rptDetail->SetValue(_T("2"), tmpStr);
		rs.GetValue(_T("Totalbed"), tmpStr);
		nTotal[3] += ToInt(tmpStr);
		rptDetail->SetValue(_T("3"), tmpStr);
		rs.GetValue(_T("oldpatient"), tmpStr);
		nTotal[4] += ToInt(tmpStr);
		rptDetail->SetValue(_T("4"), tmpStr);
		rs.GetValue(_T("Admission"), tmpStr);
		nTotal[5] += ToInt(tmpStr);
		rptDetail->SetValue(_T("5"), tmpStr);
		rs.GetValue(_T("Tre15"), tmpStr);
		nTotal[6] += ToInt(tmpStr);
		rptDetail->SetValue(_T("6"), tmpStr);
		rs.GetValue(_T("Tre24Day"), tmpStr);
		nTotal[7] += ToInt(tmpStr);
		rptDetail->SetValue(_T("7"), tmpStr);
		rs.GetValue(_T("emergency"), tmpStr);
		nTotal[8] += ToInt(tmpStr);
		rptDetail->SetValue(_T("8"), tmpStr);
		rs.GetValue(_T("SongayDT"), tmpStr);
		rs.GetValue(_T("SongayDTO"), tmpStr1);
		if (m_bCheckBed) 
			SongayDT=(ToInt(tmpStr));
		else
			SongayDT=(ToInt(tmpStr) + ToInt(tmpStr1));

		nTotal[9] += SongayDT;
		tmpStr.Format(_T("%ld"), SongayDT);
		rptDetail->SetValue(_T("9"), tmpStr);				
		rs.GetValue(_T("dead"), tmpStr);
		nTotal[10] += ToInt(tmpStr);
		rptDetail->SetValue(_T("10"), tmpStr);		
		rs.GetValue(_T("dead15"), tmpStr);
		nTotal[11] += ToInt(tmpStr);
		rptDetail->SetValue(_T("11"), tmpStr);
		rs.GetValue(_T("dead24Day"), tmpStr);
		nTotal[12] += ToInt(tmpStr);
		rptDetail->SetValue(_T("12"), tmpStr);
		rs.GetValue(_T("dead24h"), tmpStr);
		nTotal[13] += ToInt(tmpStr);
		rptDetail->SetValue(_T("13"),tmpStr);

		rs.GetValue(_T("dead24hf"), tmpStr);
		nTotal[14] += ToInt(tmpStr);
		rptDetail->SetValue(_T("14"),tmpStr);

		rs.GetValue(_T("BHYT"), tmpStr);
		nTotal[15] += ToInt(tmpStr);
		rptDetail->SetValue(_T("15"), tmpStr);

		rs.GetValue(_T("Chuyenvien"), tmpStr);		
		nTotal[16] += ToInt(tmpStr);
		rptDetail->SetValue(_T("16"), tmpStr);
		
		rs.GetValue(_T("remain"), tmpStr);		
		nTotal[17] += ToInt(tmpStr);
		rptDetail->SetValue(_T("17"), tmpStr);
		rs.MoveNext();
	}
	
	rptDetail = rpt.AddDetail();	
	TranslateString(_T("Total"),tmpStr);
	rptDetail->GetItem(_T("2"))->SetBold(true);
	rptDetail->SetValue(_T("2"),tmpStr);
	for (int i =3; i < 18; i++){
		tmpStr.Format(_T("%d"), i);
		szAmount.Format(_T("%ld"),nTotal[i] );
		//rptDetail->GetItem(tmpStr)->SetBold(true);
		rptDetail->SetValue(tmpStr, szAmount);		
	}

	//Page Footer
	//Report Footer
	szDate.Format(rpt.GetReportFooter()->GetValue(_T("PrintDate")),szSysDate.Right(2),szSysDate.Mid(5,2),szSysDate.Left(4));
	rpt.GetReportFooter()->SetValue(_T("PrintDate"), szDate);
	EndWaitCursor();
	if(bPreview)
		rpt.PrintPreview();
	else
		rpt.Print();
}
void CFMDischargeDepositUnpaidReport::OnExportSelect()
{
	CHMSMainFrame *pMF = (CHMSMainFrame*) AfxGetMainWnd();
	CRecord rs(&pMF->m_db);
	CString szSQL;
	CString tmpStr, szTemp;

	UpdateData(TRUE);
	BeginWaitCursor();

	szSQL = GetQueryString();
	rs.ExecSQL(szSQL);
	if (rs.IsEOF())
	{
		ShowMessageBox(_T("No Data"), MB_ICONERROR | MB_OK);
		return;
	}

	CExcel xls;
	xls.CreateSheet(1);
	xls.SetWorksheet(0);

	xls.SetColumnWidth(0, 5);
	xls.SetColumnWidth(1, 18);
	xls.SetColumnWidth(2, 7);
	xls.SetColumnWidth(3, 20);
	xls.SetColumnWidth(4, 11);
	xls.SetColumnWidth(5, 11);
	xls.SetColumnWidth(6, 11);
	xls.SetColumnWidth(7, 11);
	xls.SetColumnWidth(8, 11);
	xls.SetColumnWidth(9, 11);

	int nRow = 1;
	int nCol = 0;

	xls.SetRowHeight(6, 45);

	xls.SetCellMergedColumns(0, 1, 4);
	xls.SetCellMergedColumns(0, 2, 4);

	xls.SetCellMergedColumns(6, 1, 4);
	xls.SetCellMergedColumns(6, 2, 4);

	xls.SetCellText(0, 1, pMF->m_CompanyInfo.sc_pname, FMT_TEXT | FMT_CENTER, true);
	xls.SetCellText(0, 2, pMF->m_CompanyInfo.sc_name, FMT_TEXT | FMT_CENTER, true);

	xls.SetCellText(6, 1, _T("\x43\x1ED8NG H\xD2\x41 \x58\xC3 H\x1ED8I \x43H\x1EE6 NGH\x128\x41 VI\x1EC6T N\x41M"), FMT_TEXT | FMT_CENTER, true);
	xls.SetCellText(6, 2, _T("\x110\x1ED8\x43 L\x1EACP - T\x1EF0 \x44O - H\x1EA0NH PH\xDA\x43"), FMT_TEXT | FMT_CENTER, true);

	xls.SetCellMergedColumns(nCol, nRow + 3, 10);
	xls.SetCellMergedColumns(nCol, nRow + 4, 10);

	xls.SetCellText(nCol, nRow + 3, _T("\x44\x41NH S\xC1\x43H \x42\x1EC6NH NH\xC2N T\x1EA0M G\x1EECI \x110\xC3 R\x41 VI\x1EC6N \x43H\x1AF\x41 TH\x41NH TO\xC1N"),
					FMT_TEXT | FMT_CENTER, true, 16, 0);

	tmpStr.Format(_T("T\x1EEB ng\xE0y %s \x111\x1EBFn ng\xE0y %s"),
		          CDateTime::Convert(m_szFromDate, yyyymmdd | hhmm, ddmmyyyy | hhmm),
				  CDateTime::Convert(m_szToDate, yyyymmdd | hhmm, ddmmyyyy | hhmm));
	xls.SetCellText(nCol, nRow + 4, tmpStr, FMT_TEXT | FMT_CENTER, true, 12, 0);

	TranslateString(_T("Index"), tmpStr);
	xls.SetCellText(nCol, nRow + 5, tmpStr, FMT_TEXT | FMT_CENTER | FMT_VCENTER | FMT_WRAPING, true, 11);

	TranslateString(_T("Patient Name"), tmpStr);
	xls.SetCellText(nCol + 1, nRow + 5, tmpStr, FMT_TEXT | FMT_CENTER | FMT_VCENTER | FMT_WRAPING, true, 11);

	TranslateString(_T("Admission No"), tmpStr);
	xls.SetCellText(nCol + 2, nRow + 5, tmpStr, FMT_TEXT | FMT_CENTER | FMT_VCENTER | FMT_WRAPING, true, 11);

	TranslateString(_T("Dept"), tmpStr);
	xls.SetCellText(nCol + 3, nRow + 5, tmpStr, FMT_TEXT | FMT_CENTER | FMT_VCENTER | FMT_WRAPING, true, 11);

	xls.SetCellText(nCol + 4, nRow + 5, _T("Ti\x1EC1n t\x1EA1m g\x1EEDi"), FMT_TEXT | FMT_CENTER | FMT_VCENTER | FMT_WRAPING, true, 11);

	TranslateString(_T("Total Policy"), tmpStr);
	xls.SetCellText(nCol + 5, nRow + 5, tmpStr, FMT_TEXT | FMT_CENTER | FMT_VCENTER | FMT_WRAPING, true, 11);

	xls.SetCellText(nCol + 6, nRow + 5, _T("Ti\x1EC1n \x63hi ph\xED \x111\x1B0\x1EE3\x63 gi\x1EA3m"), FMT_TEXT | FMT_CENTER | FMT_VCENTER | FMT_WRAPING, true, 11);

	TranslateString(_T("Hospital Fee"), tmpStr);
	xls.SetCellText(nCol + 7, nRow + 5, tmpStr, FMT_TEXT | FMT_CENTER | FMT_VCENTER | FMT_WRAPING, true, 11);

	xls.SetCellText(nCol + 8, nRow + 5, _T("Thu"), FMT_TEXT | FMT_CENTER | FMT_VCENTER | FMT_WRAPING, true, 11);

	xls.SetCellText(nCol + 9, nRow + 5, _T("\x43hi"), FMT_TEXT | FMT_CENTER | FMT_VCENTER | FMT_WRAPING, true, 11);

	int nIndex = 1;
	nRow = 6;
	CString szOldLine, szNewLine;
	long double nGroupTotal[10];
	long double nTotal[10];
	double nCost;

	for (int i = 0; i < 10; i++)
	{
		nGroupTotal[i] = 0;
		nTotal[i] = 0;
	}

	while (!rs.IsEOF())
	{
		rs.GetValue(_T("dept"), szNewLine);

		if (!szNewLine.IsEmpty() && szNewLine != szOldLine)
		{
			if (nGroupTotal[4] > 0)
			{
				nRow++;
				xls.SetCellText(nCol + 1, nRow, _T("\x43\x1ED9ng kho\x61"), FMT_TEXT | FMT_WRAPING, true);
				for (int i = 4; i < 10; i++)
				{
					tmpStr.Format(_T("%.2lf"), nGroupTotal[i]);
					xls.SetCellText(nCol + i, nRow, tmpStr, FMT_NUMBER1 | FMT_WRAPING, true);
					nTotal[i] += nGroupTotal[i];
					nGroupTotal[i] = 0;
				}
			}
			szOldLine = szNewLine;
		}

		nRow++;

		tmpStr.Format(_T("%d"), nIndex++);
		xls.SetCellText(nCol, nRow, tmpStr, FMT_INTEGER | FMT_WRAPING);

		rs.GetValue(_T("pname"), tmpStr);
		xls.SetCellText(nCol + 1, nRow, tmpStr, FMT_TEXT | FMT_WRAPING);

		rs.GetValue(_T("recordno"), tmpStr);
		xls.SetCellText(nCol + 2, nRow, tmpStr, FMT_TEXT | FMT_WRAPING);

		if (nGroupTotal[4] == 0)
		{
			rs.GetValue(_T("dept"), tmpStr);
			xls.SetCellText(nCol + 3, nRow, tmpStr, FMT_TEXT | FMT_WRAPING);
		}

		rs.GetValue(_T("deposit"), nCost);
		nGroupTotal[4] += nCost;
		tmpStr.Format(_T("%.2f"), nCost);
		xls.SetCellText(nCol + 4, nRow, tmpStr, FMT_NUMBER1 | FMT_WRAPING);

		rs.GetValue(_T("chedo"), nCost);
		nGroupTotal[5] += nCost;
		tmpStr.Format(_T("%.2f"), nCost);
		xls.SetCellText(nCol + 5, nRow, tmpStr, FMT_NUMBER1 | FMT_WRAPING);

		rs.GetValue(_T("miengiam"), nCost);
		nGroupTotal[6] += nCost;
		tmpStr.Format(_T("%.2f"), nCost);
		xls.SetCellText(nCol + 6, nRow, tmpStr, FMT_NUMBER1 | FMT_WRAPING);

		rs.GetValue(_T("feeamt"), nCost);
		nGroupTotal[7] += nCost;
		tmpStr.Format(_T("%.2f"), nCost);
		xls.SetCellText(nCol + 7, nRow, tmpStr, FMT_NUMBER1 | FMT_WRAPING);

		rs.GetValue(_T("income"), nCost);
		nGroupTotal[8] += nCost;
		tmpStr.Format(_T("%.2f"), nCost);
		xls.SetCellText(nCol + 8, nRow, tmpStr, FMT_NUMBER1 | FMT_WRAPING);

		rs.GetValue(_T("outlay"), nCost);
		nGroupTotal[9] += nCost;
		tmpStr.Format(_T("%.2f"), nCost);
		xls.SetCellText(nCol + 9, nRow, tmpStr, FMT_NUMBER1 | FMT_WRAPING);

		rs.MoveNext();
	}

	if (nGroupTotal[4] > 0)
	{
		nRow++;
		xls.SetCellText(nCol + 1, nRow, _T("\x43\x1ED9ng kho\x61"), FMT_TEXT | FMT_WRAPING, true);
		for (int i = 4; i < 10; i++)
		{
			tmpStr.Format(_T("%.2lf"), nGroupTotal[i]);
			xls.SetCellText(nCol + i, nRow, tmpStr, FMT_NUMBER1 | FMT_WRAPING, true);
			nTotal[i] += nGroupTotal[i];
			nGroupTotal[i] = 0;
		}
	}

	if (nTotal[4] > 0)
	{
		nRow++;
		xls.SetCellText(nCol + 1, nRow, _T("T\x1ED5ng \x63\x1ED9ng"), FMT_TEXT | FMT_WRAPING, true);
		for (int i = 4; i < 10; i++)
		{
			tmpStr.Format(_T("%.2lf"), nTotal[i]);
			xls.SetCellText(nCol + i, nRow, tmpStr, FMT_NUMBER1 | FMT_WRAPING, true);
		}
	}

	EndWaitCursor();
	xls.Save(_T("Exports\\DSBNTamGuiChuaTT.xls"));
} 
//Bao cao tong hop su dung dich vu ky thuat theo quu ( mau 21/BHYT)
void CHMSInsuraceRepor21aDialog::ExportTonghopsudungdichvukythuatBHYT()
{	
	CHMSMainFrame *pMF = (CHMSMainFrame*) AfxGetMainWnd();
	UpdateData(true);
	CExcel xls;
	CRecord rs(&pMF->m_db);
	CString szSQL, tmpStr, szOldLine, szNewLine;
	int nCol = 0, nRow = 0, j = 0, nIdx = 0, nCount = 0, nTemp = 0;
	double nAmount = 0, nGrp = 0, nTotalGrp = 0, nTotal = 0;
	xls.CreateSheet(1);
	xls.SetWorksheet(0);
	//xls.SetColumnWidth(0, 4);
	xls.SetColumnWidth(1, 30);
	//xls.SetColumnWidth(3, 10);
	//xls.SetColumnWidth(4, 15);
	
	//Header
	xls.SetCellMergedColumns(nCol, nRow, 3);
	xls.SetCellMergedColumns(nCol, nRow + 1, 3);
	xls.SetCellMergedColumns(nCol, nRow + 2, 5);
	xls.SetCellMergedColumns(nCol, nRow + 3, 5);
	xls.SetCellText(nCol, nRow, pMF->m_CompanyInfo.sc_pname, FMT_TEXT | FMT_CENTER, true, 10);
	xls.SetCellText(nCol, nRow + 1, pMF->m_CompanyInfo.sc_name, FMT_TEXT | FMT_CENTER, true, 10);
	xls.SetCellText(nCol, nRow + 2, _T("\x42\x1EA2NG TH\x1ED0NG K\xCA \x44\x41NH S\xC1\x43H \x42\x1EC6NH NH\xC2N N\x1ED8P TI\x1EC0N"), FMT_TEXT | FMT_CENTER, true, 11);	
	tmpStr.Format(_T("T\x1EEB ng\xE0y %s \x111\x1EBFn ng\xE0y %s"), CDate::Convert(m_szFromDate, yyyymmdd, ddmmyyyy), CDate::Convert(m_szToDate, yyyymmdd, ddmmyyyy));
	xls.SetCellText(nCol, nRow + 3, tmpStr, FMT_TEXT | FMT_CENTER, false, 11);	
	
	//Column Header
	CStringArray arrCol, arrFeeGrp, arrTitle;
	arrCol.Add(_T("STT"));
	arrCol.Add(_T("T\xEAn \x64\x1ECB\x63h v\x1EE5 k\x1EF9 thu\x1EADt"));
	arrCol.Add(_T("S\x1ED1 l\x1B0\x1EE3ng"));
	arrCol.Add(_T("\x110\x1A1n gi\xE1"));
	arrCol.Add(_T("Th\xE0nh ti\x1EC1n"));
	nRow = 4;
	for (int i = 0; i < arrCol.GetCount(); i++)
	{
		xls.SetCellText(nCol+i, nRow, arrCol.GetAt(i), FMT_TEXT | FMT_CENTER, true, 10); 
	}
	nRow = 5;
	arrFeeGrp.Add(_T("Test"));arrTitle.Add(_T("A"));
	arrFeeGrp.Add(_T("Diagnostic image"));arrTitle.Add(_T("B"));
	arrFeeGrp.Add(_T("Visiting the function rolls"));arrTitle.Add(_T("C"));
	arrFeeGrp.Add(_T("Surgery - procedures"));arrTitle.Add(_T("D"));
	arrFeeGrp.Add(_T("Consumables"));arrTitle.Add(_T("E"));
	arrFeeGrp.Add(_T("High-tech services"));arrTitle.Add(_T("F"));
	for (int i = 0; i < arrFeeGrp.GetCount(); i++)
	{
		nIdx = 0;
		nAmount = nGrp = nTotalGrp = 0;
		j = i + 2;
		szSQL = GetQueryString(j);
		rs.ExecSQL(szSQL);
		nCount = rs.GetRecordCount();
		if (!rs.IsEOF())
		{
			xls.SetCellMergedColumns(nCol + 1, nRow, 4);
			xls.SetCellText(nCol, nRow, arrTitle.GetAt(i), FMT_TEXT | FMT_CENTER, true, 12);
			TranslateString(arrFeeGrp.GetAt(i), tmpStr);
			xls.SetCellText(nCol + 1, nRow, tmpStr, FMT_TEXT, true, 12);
			nRow++;
			while (!rs.IsEOF())
			{
				rs.GetValue(_T("groupname"), szNewLine);
				if (szNewLine != szOldLine)
				{
					if (nGrp > 0)
					{
						xls.SetCellMergedColumns(nCol, nRow, 4);
						TranslateString(_T("Total Child Group"), tmpStr);
						xls.SetCellText(nCol, nRow, tmpStr, FMT_TEXT | FMT_CENTER, true, 10);
						FormatCurrency(nGrp, tmpStr);
						xls.SetCellText(nCol + 4, nRow, tmpStr, FMT_TEXT | FMT_RIGHT, true, 10);
						nTotalGrp += nGrp;
						nRow++;
					}
					xls.SetCellMergedColumns(nCol + 1, nRow, 4);
					xls.SetCellText(nCol + 1, nRow, szNewLine, FMT_TEXT, true, 10);
					szOldLine = szNewLine;
					nIdx = 0;
					nGrp = 0;
					nRow++;	
				}
				nIdx++;
				tmpStr.Format(_T("%d"), nIdx);
				xls.SetCellText(nCol, nRow, tmpStr, FMT_INTEGER);
				rs.GetValue(_T("pcmsname"), tmpStr);
				xls.SetCellText(nCol + 1, nRow, tmpStr, FMT_TEXT);
				rs.GetValue(_T("soluong"), tmpStr);
				xls.SetCellText(nCol + 2, nRow, tmpStr, FMT_INTEGER);
				nAmount = 0;
				rs.GetValue(_T("insprice"), nAmount);
				FormatCurrency(nAmount, tmpStr);
				xls.SetCellText(nCol + 3, nRow, tmpStr, FMT_TEXT | FMT_RIGHT);
				nAmount = 0;
				rs.GetValue(_T("suminsprice"), nAmount);
				FormatCurrency(nAmount, tmpStr);
				xls.SetCellText(nCol + 4, nRow, tmpStr, FMT_TEXT | FMT_RIGHT);
				nGrp += nAmount;
				nRow++;
				rs.MoveNext();
			}
			if (nGrp > 0)
			{
				xls.SetCellMergedColumns(nCol, nRow, 4);
				TranslateString(_T("Total Child Group"), tmpStr);
				xls.SetCellText(nCol, nRow, tmpStr, FMT_TEXT | FMT_CENTER, true, 10);
				FormatCurrency(nGrp, tmpStr);
				xls.SetCellText(nCol + 4, nRow, tmpStr, FMT_TEXT | FMT_RIGHT, true, 10);
				nTotalGrp += nGrp;
				nRow++;
			}
			if (nTotalGrp > 0)
			{
				xls.SetCellMergedColumns(nCol, nRow, 4);
				TranslateString(_T("Total Parent Group"), tmpStr);
				xls.SetCellText(nCol, nRow, tmpStr + _T("(") + arrTitle.GetAt(i) + _T(")"), FMT_TEXT | FMT_CENTER, true, 10);
				FormatCurrency(nTotalGrp, tmpStr);
				xls.SetCellText(nCol + 4, nRow, tmpStr, FMT_TEXT | FMT_RIGHT, true);
				nTotal += nTotalGrp;
				nRow++;				
			}
			nTemp += nCount;	
		}
	}
	if (nTemp == 0)
	{
		ShowMessageBox(_T("No Data."), MB_ICONSTOP);
		return;
	}
	if (nTotal > 0)
	{
		xls.SetCellMergedColumns(nCol, nRow, 4);
		TranslateString(_T("Total Amount"), tmpStr);
		xls.SetCellText(nCol, nRow, tmpStr + _T("(A+B+C+D+E+F)"), FMT_TEXT | FMT_CENTER, true, 10);
		FormatCurrency(nTotal, tmpStr);
		xls.SetCellText(nCol + 4, nRow, tmpStr, FMT_TEXT | FMT_RIGHT, true);
		nRow++;		
	}
	xls.Save(_T("Exports\\Thong Ke Dich Vu Ky Thuat Theo Quy.xls"));
}
//Bao cao tong hop su dung dich vu ky thuat theo quu ( mau 21/BHYT)
void CHMSInsuraceRepor21aDialog::PrintTonghopsudungdichvukythuatBHYT()
{	
	CHMSMainFrame *pMF = (CHMSMainFrame *)AfxGetMainWnd(); 
	UpdateData(true);
	CReport rpt;
	CRecord rs(&pMF->m_db);
	CString tmpStr, szSQL, szDate, szMoney;
	if(!rpt.Init(_T("Reports/HMS/HF_THONGKETONGHOPDICHVUKYTHUATTHEOQUY.RPT")) )	
	{
		return;
	}	
	StringUpper(pMF->m_CompanyInfo.sc_pname, tmpStr);
	rpt.GetReportHeader()->SetValue(_T("HEALTHSERVICE"), tmpStr);
	StringUpper(pMF->m_CompanyInfo.sc_name, tmpStr);
	rpt.GetReportHeader()->SetValue(_T("HOSPITALNAME"), tmpStr);
	rpt.GetReportHeader()->SetValue(_T("ObjectGroup"), _T(""));
	tmpStr.Format(rpt.GetReportHeader()->GetValue(_T("ReportDate")), CDateTime::Convert(m_szFromDate, yyyymmdd, ddmmyyyy), CDate::Convert(m_szToDate, yyyymmdd,ddmmyyyy));
	rpt.GetReportHeader()->SetValue(_T("ReportDate"), tmpStr);
	//Page Header
	//Report Detail
	int nIndex = 1;
	CString szOldLine, szNewLine,szAmount;
	CReportSection* rptDetail;
	long double grpCost=0, ttlCost=0, totalCost=0;
	double cost=0;
	//nID = 1-PhiKB
	//nID = 2-Xet nghiem
	//nID = 3-CDHA
	//nID = 4-TDCN
	//nID = 5-PTTT
	//nID = 6-VTTH
	//nID = 7-Ky thuat cao
	CStringArray arrFeeGrp, arrTitle;
	arrFeeGrp.Add(_T("Test"));arrTitle.Add(_T("A"));
	arrFeeGrp.Add(_T("Diagnostic image"));arrTitle.Add(_T("B"));
	arrFeeGrp.Add(_T("Visiting the function rolls"));arrTitle.Add(_T("C"));
	arrFeeGrp.Add(_T("Surgery - procedures"));arrTitle.Add(_T("D"));
	arrFeeGrp.Add(_T("Consumables"));arrTitle.Add(_T("E"));
	arrFeeGrp.Add(_T("High-tech services"));arrTitle.Add(_T("F"));
	
	//if (m_bInPatient != 1)
	//{
	//	/*Phi kham benh
	//-----------------------------------------------------------------------------------------------------------------------------*/
	//	szSQL.Format(_T(" select hfl_name as examname,hfl_unit as unit, ") \
	//	_T(" 	sum(soluong) as soluong, ") \
	//	_T(" 	insprice,sum(soluong * insprice) as suminsprice") \
	//	_T(" from (") \
	//	_T(" 	select he_docno,he_examtype,hfe_invoiceno as invoiceno, ") \
	//	_T(" 		sum(1) as soluong,hfe_insprice as insprice") \
	//	_T(" 	from hms_exam	") \
	//	_T(" 	left join hms_doc on(hd_docno=he_docno) ") \
	//	_T(" 	where hd_object in('1','2') and he_payment ='P'") \
	//	_T(" 	group by he_docno,he_examtype,insprice, invoiceno") \
	//	_T(" ) as tb1 ") \
	//	_T(" left join hms_fee_invoice on(hfi_docno = he_docno and hfi_type ='P' and invoiceno = hfi_invoiceno) ") \
	//	_T(" left join hms_fee_list on (hfl_feeid=he_examtype)") \
	//	_T(" where insprice > 0 and date(hfi_recvdate) between '%s' and '%s'  and hfl_inspaid ='Y'") \
	//	_T(" group by examname,unit, insprice,examname,hfl_unit ") \
	//	_T(" order by examname;"),m_szFromDate,m_szToDate);
	//	
	//	rs.ExecSQL(szSQL);
	//	if (!rs.IsEOF())
	//	{
	//		grpCost=ttlCost=cost=ttlCost=0;
	//		nIndex=1;
	//		rpt.GetGroupHeader(0)->GetItem(_T("GroupName"))->SetFaceSize(12);
	//		rpt.GetGroupHeader(0)->GetItem(_T("GroupName"))->SetBold(true);
	//		rpt.GetGroupHeader(0)->GetItem(_T("GroupName"))->SetItalic(false);
	//		rpt.GetGroupHeader(0)->GetItem(_T("Group"))->SetFaceSize(12);
	//		rpt.GetGroupHeader(0)->GetItem(_T("Group"))->SetBold(true);
	//		rpt.GetGroupHeader(0)->GetItem(_T("Group"))->SetItalic(false);
	//		rptDetail = rpt.AddDetail(rpt.GetGroupHeader(0));
	//		TranslateString(_T("Nh\xF3m ph\xED kh\xE1m \x62\x1EC7nh"), tmpStr);
	//		rptDetail->SetValue(_T("GroupName"),tmpStr );
	//		rptDetail->SetValue(_T("Group"),_T("E") );		
	//		
	//		while(!rs.IsEOF())
	//		{			
	//			rptDetail = rpt.AddDetail();
	//			tmpStr.Format(_T("%d"), nIndex++);
	//			rptDetail->SetValue(_T("1"), tmpStr);
	//			rs.GetValue(_T("examname"), tmpStr);
	//			rptDetail->SetValue(_T("2"), tmpStr);		
	//			rs.GetValue(_T("soluong"), tmpStr);					
	//			rptDetail->SetValue(_T("3"), tmpStr);
	//			rs.GetValue(_T("insprice"), cost);		
	//			FormatCurrency(cost, tmpStr);
	//			rptDetail->SetValue(_T("4"), tmpStr);		
	//			rs.GetValue(_T("suminsprice"), cost);
	//			grpCost += cost;
	//			FormatCurrency(cost, tmpStr);
	//			rptDetail->SetValue(_T("5"), tmpStr);
	//			
	//			rs.MoveNext();
	//		}
	//		ttlCost += grpCost;
	//		
	//		
	//		if(ttlCost > 0){
	//			CString szField, szAmount;
	//			TranslateString(_T("Total Amount"), szAmount);
	//			rptDetail = rpt.AddDetail(rpt.GetGroupFooter(1));
	//			rptDetail->SetValue(_T("TotalGroup"), szAmount + _T("(E)"));						
	//			FormatCurrency(ttlCost, tmpStr);
	//			rptDetail->SetValue(_T("s5"), tmpStr);
	//			totalCost+=ttlCost;
	//		}
	//	}

	//}		
	grpCost=ttlCost=cost=ttlCost=0;
	nIndex=1;
	int j = 0, nCount = 0, nTemp = 0;
	BeginWaitCursor();
	for (int i = 0; i < arrFeeGrp.GetCount(); i++)
	{
		grpCost=ttlCost=cost=ttlCost=0;
		nIndex=1;
		j = i+2;
		szSQL = GetQueryString(j);
		nCount = rs.ExecSQL(szSQL);
		if(!rs.IsEOF())
		{	
			rpt.GetGroupHeader(0)->GetItem(_T("GroupName"))->SetFaceSize(12);
			rpt.GetGroupHeader(0)->GetItem(_T("GroupName"))->SetBold(true);
			rpt.GetGroupHeader(0)->GetItem(_T("GroupName"))->SetItalic(false);
			rptDetail = rpt.AddDetail(rpt.GetGroupHeader(0));
			TranslateString(arrFeeGrp.GetAt(i), tmpStr);
			rptDetail->SetValue(_T("GroupName"), tmpStr);
			rptDetail->SetValue(_T("Group"), arrTitle.GetAt(i));		
			
			while(!rs.IsEOF())
			{
				rs.GetValue(_T("groupname"), szNewLine);
				if(szNewLine != szOldLine && !szNewLine.IsEmpty()){
					if(grpCost > 0)
					{				
						TranslateString(_T("Total Child Group"), tmpStr);
						rptDetail = rpt.AddDetail(rpt.GetGroupFooter(1));
						rptDetail->SetValue(_T("TotalGroup"), tmpStr);
						FormatCurrency(grpCost, tmpStr);
						rptDetail->SetValue(_T("s5"), tmpStr);
						ttlCost += grpCost;
						nIndex=1;
						grpCost = 0;				
					}
					rpt.GetGroupHeader(0)->GetItem(_T("GroupName"))->SetFaceSize(10);
					rpt.GetGroupHeader(0)->GetItem(_T("GroupName"))->SetBold(true);
					rpt.GetGroupHeader(0)->GetItem(_T("GroupName"))->SetItalic(true);
					rptDetail = rpt.AddDetail(rpt.GetGroupHeader(0));				
					rptDetail->SetValue(_T("GroupName"),szNewLine );
					szOldLine = szNewLine;
				}

				rptDetail = rpt.AddDetail();
				tmpStr.Format(_T("%d"), nIndex++);
				rptDetail->SetValue(_T("1"), tmpStr);
				rs.GetValue(_T("pcmsname"), tmpStr);
				rptDetail->SetValue(_T("2"), tmpStr);		
				rs.GetValue(_T("soluong"), tmpStr);					
				rptDetail->SetValue(_T("3"), tmpStr);
				rs.GetValue(_T("insprice"), cost);		
				FormatCurrency(cost, tmpStr);
				rptDetail->SetValue(_T("4"), tmpStr);		
				rs.GetValue(_T("suminsprice"), cost);
				grpCost += cost;
				FormatCurrency(cost, tmpStr);
				rptDetail->SetValue(_T("5"), tmpStr);
				
				rs.MoveNext();
			}
			
			
			if(grpCost > 0){	
				TranslateString(_T("Total Child Group"), tmpStr);
				rptDetail = rpt.AddDetail(rpt.GetGroupFooter(1));	
				rptDetail->SetValue(_T("TotalGroup"), tmpStr);
				FormatCurrency(grpCost, tmpStr);
				rptDetail->SetValue(_T("s5"), tmpStr);	
				ttlCost += grpCost;		
			}

			if(ttlCost > 0){
				TranslateString(_T("Total Parent Group"), szAmount);
				rptDetail = rpt.AddDetail(rpt.GetGroupFooter(1));
				rptDetail->SetValue(_T("TotalGroup"), szAmount + _T("(") + arrTitle.GetAt(i) + _T(")"));			
				FormatCurrency(ttlCost, tmpStr);
				rptDetail->SetValue(_T("S5"), tmpStr);	
				totalCost+=ttlCost;
			}
			nTemp += nCount;
		}
	}
	if (nTemp == 0)
	{
		ShowMessageBox(_T("No Data."), MB_ICONSTOP);
		return;
	}
	if(totalCost > 0){
		TranslateString(_T("Total Amount"), szAmount);
		rptDetail = rpt.AddDetail(rpt.GetGroupFooter(1));
		rptDetail->SetValue(_T("TotalGroup"), szAmount + _T("(A+B+C+D+E+F)"));						
		FormatCurrency(totalCost, tmpStr);
		rptDetail->SetValue(_T("s5"), tmpStr);
	}
	tmpStr = pMF->GetSysDateTime();
	szDate.Format(rpt.GetReportFooter()->GetValue(_T("PrintDate")), tmpStr.Mid(8, 2), tmpStr.Mid(5, 2), tmpStr.Left(4));
	rpt.GetReportFooter()->SetValue(_T("PrintDate"), szDate);			
	MoneyToString(szMoney, tmpStr);
	rpt.GetReportFooter()->SetValue(_T("SumInWord"), tmpStr);
	EndWaitCursor();
	rpt.PrintPreview();	
}
void CTMOperationFosteringList::OnExportSelect(){
	CHMSMainFrame *pMF = (CHMSMainFrame*) AfxGetMainWnd();
	UpdateData(true);
	CRecord rs(&pMF->m_db);
	CString szSQL, tmpStr, szMoneyInWord, szTemp;
	int nIdx = 1, nRow = 0;
	double nAmount = 0, nTotalAmount = 0;
	CStringArray arrCol;
	szSQL = GetQueryString();
	rs.ExecSQL(szSQL);
	if (rs.IsEOF())
	{
		AfxMessageBox(_T("No Data."));
		return;
	}
	CExcel xls;
	xls.CreateSheet(1);
	xls.SetWorksheet(0);
	//Header
	xls.SetColumnWidth(0, 5);
	xls.SetColumnWidth(1, 10);
	xls.SetColumnWidth(3, 20);
	xls.SetColumnWidth(4, 20);
	xls.SetColumnWidth(5, 20);
	xls.SetColumnWidth(6, 30);
	xls.SetColumnWidth(7, 10);
	xls.SetColumnWidth(8, 15);
	xls.SetColumnWidth(9, 15);
	xls.SetColumnWidth(10, 15);
	xls.SetColumnWidth(11, 15);
	xls.SetCellMergedColumns(0, 0, 3);
	xls.SetCellMergedColumns(0, 1, 3);
	xls.SetCellMergedColumns(0, 2, 3);
	xls.SetCellMergedColumns(0, 3, 11);
	xls.SetCellMergedColumns(0, 4, 11);
	xls.SetCellText(0, 0, pMF->m_CompanyInfo.sc_pname, 4098, true);
	xls.SetCellText(0, 1, pMF->m_CompanyInfo.sc_name, 4098, true);
	xls.SetCellText(0, 2, pMF->GetCurrentDepartmentName(), 4098, true);
	TranslateString(_T("Operation Fostering List"), szTemp);
	StringUpper(szTemp, tmpStr); 
	xls.SetCellText(0, 3, tmpStr, 4098, true, 12);
	tmpStr.Format(_T("T\x1EEB ng\xE0y %s \x111\x1EBFn ng\xE0y %s"), m_szFromDate, m_szToDate);
	xls.SetCellText(0, 4, tmpStr, 4098, true);
	arrCol.Add(_T("STT"));
	arrCol.Add(_T("S\x1ED1 h\x1ED3 s\x1A1"));
	arrCol.Add(_T("S\x1ED1 BA"));
	arrCol.Add(_T("H\x1ECD v\xE0 t\xEAn"));
	arrCol.Add(_T("N\x103m sinh"));
	arrCol.Add(_T("Th\x1EBB/Qu\xE2n h\xE0m"));
	arrCol.Add(_T("\x44\x61nh m\x1EE5\x63 PTTT"));
	arrCol.Add(_T("T\xEAn PTTT"));
	arrCol.Add(_T("Ph\xE2n lo\x1EA1i PT, TT"));
	//arrCol.Add(_T("K\xEDp th\x1EF1\x63 hi\x1EC7n"));
	arrCol.Add(_T("\x43h\xEDnh"));
	arrCol.Add(_T("Ph\x1EE5"));
	arrCol.Add(_T("Gi\xFAp vi\x1EC7\x63"));
	arrCol.Add(_T("S\x1ED1 l\x1B0\x1EE3ng"));
	arrCol.Add(_T("S\x1ED1 ti\x1EC1n"));
	for (int i = 0; i < arrCol.GetCount(); i++)
		xls.SetCellText(i, 5, arrCol.GetAt(i), 4098, true);
	//Detail
	nRow = 6;
	while (!rs.IsEOF())
	{
		xls.SetCellText(0, nRow, int2str(nIdx++), FMT_TEXT | FMT_RIGHT);
		xls.SetCellText(1, nRow, rs.GetValue(_T("doc_no")), 4098);
		xls.SetCellText(2, nRow, rs.GetValue(_T("record_no")), 4098);
		xls.SetCellText(3, nRow, rs.GetValue(_T("patient_name")), FMT_TEXT);
		xls.SetCellText(4, nRow, rs.GetValue(_T("yob")), 4098);
		xls.SetCellText(5, nRow, rs.GetValue(_T("extra_info")), FMT_TEXT);
		xls.SetCellText(6, nRow, rs.GetValue(_T("operation_name1")), FMT_TEXT);
		xls.SetCellText(7, nRow, rs.GetValue(_T("operation_name")), FMT_TEXT);
		xls.SetCellText(8, nRow, rs.GetValue(_T("operation_type")), 4098);
		xls.SetCellText(9, nRow, rs.GetValue(_T("practitioner")), FMT_TEXT);
		xls.SetCellText(10, nRow, rs.GetValue(_T("assistant")), FMT_TEXT);
		xls.SetCellText(11, nRow, rs.GetValue(_T("anethetist")), FMT_TEXT);
		xls.SetCellText(12, nRow, rs.GetValue(_T("quantity")), FMT_NUMBER1);
		rs.GetValue(_T("amount"), nAmount);
		nTotalAmount += nAmount;
		xls.SetCellText(13, nRow, double2str(nAmount), FMT_NUMBER1);
		nRow++;
		rs.MoveNext();
	}
	if (nTotalAmount > 0)
	{
		xls.SetCellMergedColumns(0, nRow, 13);
		xls.SetCellText(0, nRow, _T("\x43\x1ED9ng"), 4098, true);
		xls.SetCellText(13, nRow, double2str(nTotalAmount), FMT_NUMBER1);
		nRow++;
		MoneyToString(double2str(nTotalAmount), szMoneyInWord);
		tmpStr.Format(_T("S\x1ED1 ti\x1EC1n \x62\x1EB1ng \x63h\x1EEF: %s"), szMoneyInWord);
		xls.SetCellMergedColumns(0, nRow, 13);
		xls.SetCellText(0, nRow, tmpStr, FMT_TEXT, true);
	}

	xls.Save(_T("Exports\\Danh sach de nghi boi duong PTTT.xls"));
	
} 
void CFMTempSendPatientListByDay::OnExportSelect(){
	CHMSMainFrame *pMF = (CHMSMainFrame*) AfxGetMainWnd();
	CRecord rs(&pMF->m_db);
	CString szSQL;
	CString tmpStr, szTemp;

	UpdateData(TRUE);
	BeginWaitCursor();

	szSQL = GetQueryString();
	rs.ExecSQL(szSQL);
	if (rs.IsEOF())
	{
		ShowMessageBox(_T("No Data"), MB_ICONERROR | MB_OK);
		return;
	}

	CExcel xls;
	xls.CreateSheet(1);
	xls.SetWorksheet(0);

	xls.SetColumnWidth(0, 5);
	xls.SetColumnWidth(1, 18);
	xls.SetColumnWidth(2, 10);
	xls.SetColumnWidth(3, 20);
	xls.SetColumnWidth(4, 11);
	xls.SetColumnWidth(5, 15);

	int nRow = 1;
	int nCol = 0;
	int nIndex = 1;
	CString szOldLine, szNewLine;
	long double nGroupTotal = 0, nTotal = 0;
	double nCost = 0;

	xls.SetRowHeight(6, 45);

	xls.SetCellMergedColumns(0, 1, 4);
	xls.SetCellMergedColumns(0, 2, 4);

	xls.SetCellMergedColumns(6, 1, 4);
	xls.SetCellMergedColumns(6, 2, 4);

	xls.SetCellText(0, 1, pMF->m_CompanyInfo.sc_pname, FMT_TEXT | FMT_CENTER, true);
	xls.SetCellText(0, 2, pMF->m_CompanyInfo.sc_name, FMT_TEXT | FMT_CENTER, true);

	xls.SetCellText(6, 1, _T("\x43\x1ED8NG H\xD2\x41 \x58\xC3 H\x1ED8I \x43H\x1EE6 NGH\x128\x41 VI\x1EC6T N\x41M"), FMT_TEXT | FMT_CENTER, true);
	xls.SetCellText(6, 2, _T("\x110\x1ED8\x43 L\x1EACP - T\x1EF0 \x44O - H\x1EA0NH PH\xDA\x43"), FMT_TEXT | FMT_CENTER, true);

	xls.SetCellMergedColumns(nCol, nRow + 3, 6);
	xls.SetCellMergedColumns(nCol, nRow + 4, 6);

	xls.SetCellText(nCol, nRow + 3, _T("\x44\x41NH S\xC1\x43H \x42\x1EC6NH NH\xC2N T\x1EA0M G\x1EECI "),
					FMT_TEXT | FMT_CENTER, true, 16, 0);

	tmpStr.Format(_T("T\x1EEB ng\xE0y %s \x111\x1EBFn ng\xE0y %s"),
		          CDateTime::Convert(m_szFromDate, yyyymmdd | hhmm, ddmmyyyy | hhmm),
				  CDateTime::Convert(m_szToDate, yyyymmdd | hhmm, ddmmyyyy | hhmm));
	xls.SetCellText(nCol, nRow + 4, tmpStr, FMT_TEXT | FMT_CENTER, true, 12, 0);

	TranslateString(_T("Index"), tmpStr);
	xls.SetCellText(nCol, nRow + 5, tmpStr, FMT_TEXT | FMT_CENTER | FMT_VCENTER | FMT_WRAPING, true, 11);

	TranslateString(_T("Patient Name"), tmpStr);
	xls.SetCellText(nCol + 1, nRow + 5, tmpStr, FMT_TEXT | FMT_CENTER | FMT_VCENTER | FMT_WRAPING, true, 11);

	TranslateString(_T("Document No"), tmpStr);
	xls.SetCellText(nCol + 2, nRow + 5, tmpStr, FMT_TEXT | FMT_CENTER | FMT_VCENTER | FMT_WRAPING, true, 11);

	TranslateString(_T("Admission No"), tmpStr);
	xls.SetCellText(nCol + 3, nRow + 5, tmpStr, FMT_TEXT | FMT_CENTER | FMT_VCENTER | FMT_WRAPING, true, 11);

	TranslateString(_T("Dept"), tmpStr);
	xls.SetCellText(nCol + 4, nRow + 5, tmpStr, FMT_TEXT | FMT_CENTER | FMT_VCENTER | FMT_WRAPING, true, 11);

	xls.SetCellText(nCol + 5, nRow + 5, _T("Ng\xE0y n\x1ED9p ti\x1EC1n"), FMT_TEXT | FMT_CENTER | FMT_VCENTER | FMT_WRAPING, true, 11);
	xls.SetCellText(nCol + 6, nRow + 5, _T("S\x1ED1 ti\x1EC1n"), FMT_TEXT | FMT_CENTER | FMT_VCENTER | FMT_WRAPING, true, 11);
	nRow = 7;
	while (!rs.IsEOF())
	{
		rs.GetValue(_T("receiptdate"), tmpStr);
		szNewLine = CDate::Convert(tmpStr, yyyymmdd, ddmmyyyy);
		if (!szNewLine.IsEmpty() && szNewLine != szOldLine)
		{
			if (nGroupTotal > 0)
			{
				nRow++;
				xls.SetCellText(nCol + 1, nRow, _T("\x43\x1ED9ng ng\xE0y"), FMT_TEXT | FMT_WRAPING, true);
				tmpStr.Format(_T("%.2lf"), nGroupTotal);
				xls.SetCellText(nCol + 5, nRow, tmpStr, FMT_NUMBER1 | FMT_WRAPING, true);
				nTotal += nGroupTotal;
				nGroupTotal = 0;
			}
			szOldLine = szNewLine;
		}
		nRow++;

		tmpStr.Format(_T("%d"), nIndex++);
		xls.SetCellText(nCol, nRow, tmpStr, FMT_INTEGER | FMT_WRAPING);

		rs.GetValue(_T("pname"), tmpStr);
		xls.SetCellText(nCol + 1, nRow, tmpStr, FMT_TEXT | FMT_WRAPING);

		rs.GetValue(_T("docno"), tmpStr);
		xls.SetCellText(nCol + 2, nRow, tmpStr, FMT_TEXT | FMT_WRAPING);

		rs.GetValue(_T("recordno"), tmpStr);
		xls.SetCellText(nCol + 3, nRow, tmpStr, FMT_TEXT | FMT_WRAPING);
			
		rs.GetValue(_T("dept"), tmpStr);
		xls.SetCellText(nCol + 4, nRow, tmpStr, FMT_TEXT | FMT_WRAPING);

		if (nGroupTotal == 0)
		{
			tmpStr = CDate::Convert(rs.GetValue(_T("receiptdate")), yyyymmdd, ddmmyyyy);
			xls.SetCellText(nCol + 5, nRow, tmpStr, FMT_TEXT | FMT_WRAPING);
		}
		rs.GetValue(_T("deposit"), nCost);
		nGroupTotal += nCost;
		tmpStr.Format(_T("%.2f"), nCost);
		xls.SetCellText(nCol + 6, nRow, tmpStr, FMT_NUMBER1 | FMT_WRAPING);
		rs.MoveNext();
		
	}
	
	if (nGroupTotal > 0)
	{
		nRow++;
		xls.SetCellText(nCol + 1, nRow, _T("\x43\x1ED9ng kho\x61"), FMT_TEXT | FMT_WRAPING, true);
		tmpStr.Format(_T("%.2lf"), nGroupTotal);
		xls.SetCellText(nCol + 7, nRow, tmpStr, FMT_NUMBER1 | FMT_WRAPING, true);
		nTotal += nGroupTotal;
		nGroupTotal = 0;
	}

	EndWaitCursor();
	xls.Save(_T("Exports\\DSBNTamGui.xls"));
}