Esempio n. 1
0
//---------------------------------------------------------------------------
void __fastcall TDicExchargeForm::btnOK0Click(TObject *Sender)
{
  char strName[80],*ptr,strTemp[80];
  int nState;

  edtName->Text=edtName->Text.Trim();

  if(edtName->Text.IsEmpty())
  {
  	ShowMessage("请输入名称");
    if(edtName->CanFocus())	edtName->SetFocus();
    return;
  }

  strcpy(strName,edtName->Text.c_str());

  char strSQL[1024];

  switch(m_enWorkState)
  {
    case EN_ADDNEW:
      sprintf(strSQL,"insert into DicExcharge values('%s')",strName);
      break;
    case EN_EDIT:
     {TListItem *pItem = ListView1->Selected;
      sprintf(strSQL,"update DicExcharge set exname='%s' where exname='%s'",strName,pItem->Caption.c_str());
      }break;
    default:
      ShowMessage("Work State not AddNew or Edit");
      return;
  }

  if(!dm1->OpenDatabase())  return;

  try
  {
    if(m_enWorkState==EN_ADDNEW)
    {
      char strAddSQL[256];
      sprintf(strAddSQL,"select * from DicExcharge where exname='%s'",strName);
      RunSQL(strAddSQL,true);
      if(dm1->Query1->RecordCount>0)
      {
        ShowMessage("数据库中已有该编号的记录!");
        edtName->SetFocus();
        return;
      }
    }
    RunSQL(strSQL);
  }
  catch(...)
  {
    ShowMessage("数据库操作错误!");
    return;
  }

  TListItem *pItem;
  if(m_enWorkState==EN_ADDNEW)
  {
  	pItem=ListView1->Items->Add();
    pItem->Caption=edtName->Text;
    ListView1->Selected=pItem;
  }
  else if(m_enWorkState==EN_EDIT)
  {
  	pItem=ListView1->Selected;
    if(pItem!=NULL)
    {
    	pItem->Caption=edtName->Text;
    }
  }

  nState=m_enWorkState;
  m_enWorkState=EN_IDLE;
  ResetCtrl();
  msgState->Caption="工作状态:查询";
  switch(nState)
  { //设置确定後的光标位置
    case EN_ADDNEW: btnAddNew->SetFocus();  break;
    case EN_EDIT:   btnEdit->SetFocus();    break;
    default:  break;
  }
}
Esempio n. 2
0
File: main.cpp Progetto: qdac/QDAC
//---------------------------------------------------------------------------
void __fastcall TForm3::DoMainThreadJob(TQJob *AJob)
{
ShowMessage(L"主线程作业已经执行。");
}
///////////////////////////////////////////////////////////////////
// Panel::CannyDetection() 
// Description: This function is called by DetectEdges() and it
//  is the Canny edge detection function which does not contain
//  debugging statements. We run the image through several different 
//  image processing functions to prepare the image before edge
//  detection. After detection the edges we run Hough lines which 
//  approximates lines of minimum length as specified in 
//  Settings.xml. We find all intersections of the Hough lines 
//  then make a minimum area rectangle around the intersections to 
//  approximate the edges of the panel which we are trying to
//  measure. From there we use the unit conversion calculated 
//  in DetectFeatures() to find a length and width of the current
//  panel. We report the length and width with a message box. 
///////////////////////////////////////////////////////////////////
Mat Panel::CannyDetection(Mat image, bool showImg)
{
	Mat greyImage;
	cvtColor(image, greyImage, CV_BGR2GRAY);

	Mat eroded, dilated, thresh, blurredThresh, edges, edgesGray;
	vector<Vec2f> lines;

		threshold(greyImage, thresh, m_lowCannyThreshold, 255, THRESH_BINARY);
		erode(thresh, eroded, Mat());
		dilate(eroded, dilated, Mat());
		GaussianBlur(thresh, blurredThresh, Size(7, 7), m_sigmaX, m_sigmaY);
		Canny(blurredThresh, edges, m_cannyLow, m_cannyLow*m_ratio, 3);
		HoughLines(edges, lines, 1, CV_PI / 180, m_houghLength, 0, 0);

		cvtColor(edges, edgesGray, CV_GRAY2BGR);
		for (size_t i = 0; i < lines.size(); i++)
		{
			float rho = lines[i][0], theta = lines[i][1];
			Point pt1, pt2;
			double a = cos(theta), b = sin(theta);
			double x0 = a*rho, y0 = b*rho;
			pt1.x = cvRound(x0 + 1000 * (-b));
			pt1.y = cvRound(y0 + 1000 * (a));
			pt2.x = cvRound(x0 - 1000 * (-b));
			pt2.y = cvRound(y0 - 1000 * (a));
			line(edgesGray, pt1, pt2, Scalar(0, 0, 255), 3, CV_AA);
		}

		////////////////////////////////////////////////////////
		// Compute the intersection from the lines detected
		////////////////////////////////////////////////////////
		vector<Point2f> intersections;
		for (size_t i = 0; i < lines.size(); i++)
		{
			for (size_t j = 0; j < lines.size(); j++)
			{
				Vec2f line1 = lines[i];
				Vec2f line2 = lines[j];
				if (acceptLinePair(line1, line2, (float)CV_PI / 32))
				{
					Point2f intersection = computeIntersect(line1, line2);
					if (intersection.x >= 0 && intersection.y >= 0)
						intersections.push_back(intersection);
				}
			}
		}

		if (intersections.size() > 0)
		{
			vector<Point2f>::iterator i;
			for (i = intersections.begin(); i != intersections.end(); ++i)
			{
				cout << "Intersection is " << i->x << ", " << i->y << endl;
				circle(image, *i, 2, Scalar(0, 255, 0), 3);
			}
			// Find the minimum bounding rectangle
			RotatedRect rect;
			Point2f rectPoints[4];
			Scalar color = Scalar(255, 0, 0);
			if (intersections.size() == 4)
			{
				// TODO
			}
			rect = minAreaRect(intersections);
			rect.points(rectPoints);
			int j = 0;
			for (j; j < 4; j++)
				line(image, rectPoints[j], rectPoints[(j + 1) % 4], color, 5, 8);

			float topLength = (float)norm(rectPoints[1] - rectPoints[0]);
			float botLength = (float)norm(rectPoints[3] - rectPoints[2]);
			float panelWidthPixels = topLength < botLength ? topLength : botLength;

			float leftHeight = (float)norm(rectPoints[3] - rectPoints[0]);
			float rightHeight = (float)norm(rectPoints[2] - rectPoints[1]);
			float panelHeightPixels = leftHeight < rightHeight ? leftHeight : rightHeight;

			string dimensionDisplayPixels = "Pixels:\nWidth: " + to_string(panelWidthPixels) + " pixels\nHeight: " + to_string(panelHeightPixels) + " pixels";
			// ShowMessage(dimensionDisplayPixels);
			if (m_conversionRate)
			{
				float panelWidthReal = panelWidthPixels / m_conversionRate;
				float panelHeightReal = panelHeightPixels / m_conversionRate;
				string dimensionDisplayActual = "Actual:\nWidth: " + to_string(panelWidthReal) + " cm\nHeight: " + to_string(panelHeightReal) + " cm";
				ShowMessage(dimensionDisplayActual);
			}

		}

		if (showImg){
			namedWindow("Intersections", CV_WINDOW_KEEPRATIO);
			imshow("Intersections", image);
		}
		/////////////////////////////////////////////////////////////
		// End of Computing the intersection from the lines detected
		/////////////////////////////////////////////////////////////
	return edges;
}
Esempio n. 4
0
int DownloadFiles(char *szInputIniFile,
                  char *szDownloadDir,
                  char *szProxyServer,
                  char *szProxyPort,
                  char *szProxyUser,
                  char *szProxyPasswd,
                  BOOL bShowRetryMsg,
                  BOOL bIgnoreAllNetworkErrors,
                  char *szFailedFile,
                  DWORD dwFailedFileSize)
{
    char      szBuf[MAX_BUF];
    char      szCurrentFile[MAX_BUF];
    char      szSection[MAX_INI_SK];
    char      szKey[MAX_INI_SK];
    char      szSavedCwd[MAX_BUF_MEDIUM];
    int       iCounter;
    int       rv;
    int       iFileDownloadRetries;
    int       iIgnoreFileNetworkError;
    int       iLocalTimeOutCounter;
    DWORD     dwTotalEstDownloadSize;
    char      szPartiallyDownloadedFilename[MAX_BUF];
    BOOL      bDownloadInitiated;
    char      szTempURL[MAX_BUF];
    char      szWorkingURLPathOnly[MAX_BUF];
    siC       *siCCurrentFileObj = NULL;

    ZeroMemory(szTempURL, sizeof(szTempURL));
    ZeroMemory(szWorkingURLPathOnly, sizeof(szWorkingURLPathOnly));
    if(szInputIniFile == NULL)
        return(WIZ_ERROR_UNDEFINED);

    if(szFailedFile)
        ZeroMemory(szFailedFile, dwFailedFileSize);

    InitTickInfo();
    GetCurrentDirectory(sizeof(szSavedCwd), szSavedCwd);
    SetCurrentDirectory(szDownloadDir);

    rv                        = WIZ_OK;
    dwTotalEstDownloadSize    = 0;
    giTotalArchivesToDownload = 0;
    glLastBytesSoFar          = 0;
    glAbsoluteBytesSoFar      = 0;
    glBytesResumedFrom        = 0;
    gdwTickStart              = 0; /* Initialize the counter used to
                                  * calculate download rate */
    gbStartTickCounter        = FALSE; /* used to determine when to start
                                      * the tick counter used to calculate
                                      * the download rate */
    gbUrlChanged              = TRUE;
    gbDlgDownloadMinimized    = FALSE;
    gbDlgDownloadJustMinimized = FALSE;
    gdwDownloadDialogStatus   = CS_NONE;
    gbShowDownloadRetryMsg    = bShowRetryMsg;
    gszConfigIniFile          = szInputIniFile;
    bDownloadInitiated        = FALSE;

    GetTotalArchivesToDownload(&giTotalArchivesToDownload,
                               &dwTotalEstDownloadSize);
    glTotalKb                 = dwTotalEstDownloadSize;
    GetSetupCurrentDownloadFile(szPartiallyDownloadedFilename,
                                sizeof(szPartiallyDownloadedFilename));

    ShowMessage(NULL, FALSE);
    InitDownloadDlg();

    for(giIndex = 0; giIndex < giTotalArchivesToDownload; giIndex++)
    {
        /* set (or reset) the counter to 0 in order to read the
         * next files's 0'th url from the .idi file */
        iCounter     = 0;
        gbUrlChanged = TRUE; /* Update the download dialog with new URL */
        wsprintf(szSection, "File%d", giIndex);
        wsprintf(szKey,     "url%d",  iCounter);
        GetPrivateProfileString(szSection,
                                szKey,
                                "",
                                szTempURL,
                                sizeof(szTempURL),
                                gszConfigIniFile);

        if(*szTempURL == '\0')
            continue;

        if(!bDownloadInitiated)
        {
            ParsePath(szTempURL,
                      szWorkingURLPathOnly,
                      sizeof(szWorkingURLPathOnly),
                      TRUE, //use '/' as the path delimiter
                      PP_PATH_ONLY);
        }

        GetPrivateProfileString(szSection,
                                "desc",
                                "",
                                gszCurrentDownloadFileDescription,
                                sizeof(gszCurrentDownloadFileDescription),
                                gszConfigIniFile);
        iIgnoreFileNetworkError = GetPrivateProfileInt(szSection,
                                  "Ignore File Network Error",
                                  0,
                                  gszConfigIniFile);

        /* save the file name to be downloaded */
        ParsePath(szTempURL,
                  szCurrentFile,
                  sizeof(szCurrentFile),
                  TRUE, //use '/' as the path delimiter
                  PP_FILENAME_ONLY);

        RemoveSlash(szWorkingURLPathOnly);
        wsprintf(gszUrl, "%s/%s", szWorkingURLPathOnly, szCurrentFile);

        /* retrieve the file's data structure */
        siCCurrentFileObj = GetObjectFromArchiveName(szCurrentFile);

        if((*szPartiallyDownloadedFilename != 0) &&
                (lstrcmpi(szPartiallyDownloadedFilename, szCurrentFile) == 0))
        {
            struct stat statBuf;

            if(stat(szPartiallyDownloadedFilename, &statBuf) != -1)
            {
                glAbsoluteBytesSoFar += statBuf.st_size;
                glBytesResumedFrom    = statBuf.st_size;
            }
        }

        lstrcpy(gszTo, szDownloadDir);
        AppendBackSlash(gszTo, sizeof(gszTo));
        lstrcat(gszTo, szCurrentFile);

        if(gbDlgDownloadMinimized)
            SetMinimizedDownloadTitle((int)GetPercentSoFar());
        else
        {
            SetStatusUrl();
            SetRestoredDownloadTitle();
        }

        SetSetupCurrentDownloadFile(szCurrentFile);
        iFileDownloadRetries = 0;
        iLocalTimeOutCounter = 0;
        do
        {
            ProcessWindowsMessages();
            /* Download starts here */
            if((szProxyServer != NULL) && (szProxyPort != NULL) &&
                    (*szProxyServer != '\0') && (*szProxyPort != '\0'))
                /* If proxy info is provided, use HTTP proxy */
                rv = DownloadViaProxy(gszUrl,
                                      szProxyServer,
                                      szProxyPort,
                                      szProxyUser,
                                      szProxyPasswd);
            else
            {
                /* is this an HTTP URL? */
                if(strncmp(gszUrl, kHTTP, lstrlen(kHTTP)) == 0)
                    rv = DownloadViaHTTP(gszUrl);
                /* or is this an FTP URL? */
                else if(strncmp(gszUrl, kFTP, lstrlen(kFTP)) == 0)
                    rv = DownloadViaFTP(gszUrl);
            }

            bDownloadInitiated = TRUE;
            if((rv == nsFTPConn::E_USER_CANCEL) ||
                    (gdwDownloadDialogStatus == CS_PAUSE))
            {
                if(gdwDownloadDialogStatus == CS_PAUSE)
                {
                    CloseSocket(szProxyServer, szProxyPort);

                    /* rv needs to be set to something
                     * other than E_USER_CANCEL or E_OK */
                    rv = nsFTPConn::E_CMD_UNEXPECTED;

                    PauseTheDownload(rv, &iFileDownloadRetries);
                    bDownloadInitiated = FALSE; /* restart the download using
                                       * new socket connection */
                }
                else
                {
                    /* user canceled; break out of the do loop */
                    break;
                }
            }
            else if((rv != nsFTPConn::OK) &&
                    (rv != nsFTPConn::E_CMD_FAIL) &&
                    (rv != nsSocket::E_BIND) &&
                    (rv != nsHTTPConn::E_HTTP_RESPONSE) &&
                    (gdwDownloadDialogStatus != CS_CANCEL))
            {
                /* We timed out.  No response from the server, or
                 * we somehow lost connection. */

                char szTitle[MAX_BUF_SMALL];
                char szMsgDownloadPaused[MAX_BUF];

                /* Incrememt the time out counter on E_TIMEOUT */
                if(rv == nsSocket::E_TIMEOUT)
                {
                    ++siCCurrentFileObj->iNetTimeOuts;
                    ++iLocalTimeOutCounter;
                }

                CloseSocket(szProxyServer, szProxyPort);

                /* If the number of timeouts is %3 == 0, then let's pause
                 * the download process.  Otherwise, just close the
                 * connection and open a new one to see if the download
                 * can be restarted automatically. */
                if((rv != nsSocket::E_TIMEOUT) ||
                        (rv == nsSocket::E_TIMEOUT) && ((iLocalTimeOutCounter % kModTimeOutValue) == 0))
                {
                    /* Start the pause tick counter here because we don't know how
                     * long before the user will dismiss the MessageBox() */
                    if(!gtiPaused.bTickStarted)
                    {
                        gtiPaused.dwTickBegin          = GetTickCount();
                        gtiPaused.bTickStarted         = TRUE;
                        gtiPaused.bTickDownloadResumed = FALSE;
                    }

                    /* The connection unexepectedly dropped for some reason, so inform
                     * the user that the download will be Paused, and then update the
                     * Download dialog to show the Paused state. */
                    GetPrivateProfileString("Messages",
                                            "MB_WARNING_STR",
                                            "",
                                            szTitle,
                                            sizeof(szTitle),
                                            szFileIniInstall);
                    GetPrivateProfileString("Strings",
                                            "Message Download Paused",
                                            "",
                                            szMsgDownloadPaused,
                                            sizeof(szMsgDownloadPaused),
                                            szFileIniConfig);
                    MessageBox(dlgInfo.hWndDlg,
                               szMsgDownloadPaused,
                               szTitle,
                               MB_ICONEXCLAMATION);

                    /* Let's make sure we're in a paused state */
                    gdwDownloadDialogStatus = CS_PAUSE;
                    PauseTheDownload(rv, &iFileDownloadRetries);
                }
                else
                    /* Let's make sure we're _not_ in a paused state */
                    gdwDownloadDialogStatus = CS_NONE;
            }

            /* We don't count time outs as normal failures.  We're
             * keeping track of time outs differently. */
            if(rv != nsSocket::E_TIMEOUT)
                ++iFileDownloadRetries;

            if((iFileDownloadRetries > MAX_FILE_DOWNLOAD_RETRIES) &&
                    (rv != nsFTPConn::E_USER_CANCEL) &&
                    (gdwDownloadDialogStatus != CS_CANCEL))
            {
                /* since the download retries maxed out, increment the counter
                 * to read the next url for the current file */
                ++iCounter;
                wsprintf(szKey, "url%d",  iCounter);
                GetPrivateProfileString(szSection,
                                        szKey,
                                        "",
                                        szTempURL,
                                        sizeof(szTempURL),
                                        gszConfigIniFile);
                if(*szTempURL != '\0')
                {
                    /* Found more urls to download from for the current file.
                     * Update the dialog to show the new url and reset the
                     * file download retries to 0 since it's a new url. */
                    gbUrlChanged = TRUE;
                    iFileDownloadRetries = 0;
                    bDownloadInitiated = FALSE; // restart the download using new socket connection
                    CloseSocket(szProxyServer, szProxyPort);
                    ParsePath(szTempURL,
                              szWorkingURLPathOnly,
                              sizeof(szWorkingURLPathOnly),
                              TRUE, //use '/' as the path delimiter
                              PP_PATH_ONLY);
                    RemoveSlash(szWorkingURLPathOnly);
                    wsprintf(gszUrl, "%s/%s", szWorkingURLPathOnly, szCurrentFile);
                    SetStatusUrl();
                }
            }
        } while((rv != nsFTPConn::E_USER_CANCEL) &&
                (rv != nsFTPConn::OK) &&
                (gdwDownloadDialogStatus != CS_CANCEL) &&
                (iFileDownloadRetries <= MAX_FILE_DOWNLOAD_RETRIES));

        /* Save the number of retries for each file */
        siCCurrentFileObj->iNetRetries = iFileDownloadRetries < 1 ? 0:iFileDownloadRetries - 1;

        if((rv == nsFTPConn::E_USER_CANCEL) ||
                (gdwDownloadDialogStatus == CS_CANCEL))
        {
            /* make sure rv is E_USER_CANCEL when gdwDownloadDialogStatus
             * is CS_CANCEL */
            rv = nsFTPConn::E_USER_CANCEL;

            if(szFailedFile && ((DWORD)lstrlen(szCurrentFile) <= dwFailedFileSize))
                lstrcpy(szFailedFile, gszCurrentDownloadFileDescription);

            /* break out of for() loop */
            break;
        }

        if((rv != nsFTPConn::OK) &&
                (iFileDownloadRetries > MAX_FILE_DOWNLOAD_RETRIES) &&
                !bIgnoreAllNetworkErrors &&
                !iIgnoreFileNetworkError)
        {
            /* too many retries from failed downloads */
            char szMsg[MAX_BUF];

            if(szFailedFile && ((DWORD)lstrlen(szCurrentFile) <= dwFailedFileSize))
                lstrcpy(szFailedFile, gszCurrentDownloadFileDescription);

            GetPrivateProfileString("Strings",
                                    "Error Too Many Network Errors",
                                    "",
                                    szMsg,
                                    sizeof(szMsg),
                                    szFileIniConfig);
            if(*szMsg != '\0')
            {
                wsprintf(szBuf, szMsg, szCurrentFile);
                PrintError(szBuf, ERROR_CODE_HIDE);
            }

            iFileDownloadRetries = 0; // reset the file download retries counter since
            // we'll be restarting the download again.
            bDownloadInitiated = FALSE; // restart the download using new socket connection
            CloseSocket(szProxyServer, szProxyPort);
            --giIndex; // Decrement the file index counter because we'll be trying to
            // download the same file again.  We don't want to go to the next
            // file just yet.

            /* Let's make sure we're in a paused state. */
            /* The pause state will be unset by DownloadDlgProc(). */
            gdwDownloadDialogStatus = CS_PAUSE;
            PauseTheDownload(rv, &iFileDownloadRetries);
        }
        else if(bIgnoreAllNetworkErrors || iIgnoreFileNetworkError)
            rv = nsFTPConn::OK;

        UnsetSetupCurrentDownloadFile();
    }

    CloseSocket(szProxyServer, szProxyPort);
    DeInitDownloadDlg();
    SetCurrentDirectory(szSavedCwd);
    return(rv);
}
Esempio n. 5
0
void __fastcall TForm1::Button3Click(TObject *Sender)
{
  ShowMessage("For use with STK200+/300, written by Anton Prins (21 march 2011)");  
}
//---------------------------------------------------------------------------
void MatrizNotas::CargaFicheroTexto(AnsiString fichero)
{
ifstream archivo;
//AnsiString fichero="prueba.txt";
archivo.open(fichero.c_str());
char temporal[16];
String A_Comparar="VOCES ";
for (int i=0;i<5;i++)
{
  archivo>>temporal[i];
  if (temporal[i]!=A_Comparar[i+1]){ShowMessage("Archivo Corrupto/No válido");return;}
}
//comparamos que pone "Voces "
int voces_archivo;
int columnas_archivo;
archivo>>voces_archivo;
A_Comparar="COLUMNAS ";
for (int i=0;i<8;i++)
{
  archivo>>temporal[i];
  if (temporal[i]!=A_Comparar[i+1]){ShowMessage("Archivo Corrupto/No válido");return;}
}
archivo>>columnas_archivo;
A_Comparar="RESOLUCION ";
for (int i=0;i<10;i++)
{
  archivo>>temporal[i];
  if (temporal[i]!=A_Comparar[i+1]){ShowMessage("Archivo Corrupto/No válido");return;}
}
archivo>>Resolucion;
//queda cargar todos los patrones rítmicos, eso si, antes tenemos que limpiar las listas :)
Cancion.clear();
int velocity;
for (int voz=0;voz<voces_archivo;voz++)//por cada fila
{
  for (int columna=0;columna<columnas_archivo;columna++)//por cada elemento de la fila
  {//leemos 6
    for (int i=0;i<6;i++)
    {
      archivo>>temporal[i];
    }
    switch (temporal[2])
    {
      case 'L':
      {
        archivo>>temporal[6];archivo>>temporal[7];
        break;
      }
      case 'G':
      {
        archivo>>velocity;
        Inserta(columna,voz,LIGADO,velocity);
        break;
      }
      case 'M':
      {
        archivo>>velocity;
        Inserta(columna,voz,SIMPLE,velocity);
        break;
      }
    }
  }
  for (int i=0;i<3;i++)
  {
    archivo>>temporal[i];
  }   //Esto es fin
}
archivo.close();
CambiaResolucion(128);
/*
archivo<<"VOCES "<<Voces<<"\n";
archivo<<"COLUMNAS "<<Columnas<<"\n";
archivo<<"RESOLUCION "<<Resolucion;
for (int voz=0;voz<Voces;voz++)
{
archivo<<"\n";
  for (int col=0;col<Columnas;col++)
  {
    TipoNotaCompuesto temporal=Dame(col,voz);
    switch (temporal.Duracion)
    {
      case SIMPLE:{archivo<<"SIMPLE ";break;}
      case SILENCIO:{archivo<<"SILENCIO ";break;}
      case LIGADO:{archivo<<"LIGADO ";break;}
    }
    //Ahora tendríamos que añadir el velocity
    if (temporal.Duracion!=SILENCIO){archivo<<temporal.Velocity<<" ";}
  }
  archivo<<"FIN";
}
  */

}
void CEMExaminationListReport::OnExportSelect(){
	_debug(_T("%s"), CString(typeid(this).name()));
	CHMSMainFrame  *pMF = (CHMSMainFrame *) AfxGetMainWnd();
	UpdateData(true);
	CExcel xls;
	CRecord rs(&pMF->m_db);
	CString szSQL, tmpStr;
	int nIdx = 0, nCol = 0, nRow = 0;
	int c1 = 0, c2 = 0, c3 = 0, c4 = 0, c5 = 0, c6 =0;
	int c7 = 0, c8 = 0, c9 = 0, c10 = 0, c11 = 0;
	szSQL = GetQueryString();
	int nCount = rs.ExecSQL(szSQL);
	_fmsg(_T("%s"), szSQL);
	if (nCount <= 0)
	{
		ShowMessage(150, MB_ICONSTOP);
		return;
	}
	xls.CreateSheet(1);
	xls.SetWorksheet(0);
	xls.SetColumnWidth(0, 4);
	xls.SetColumnWidth(1, 25);
	xls.SetColumnWidth(3, 15);
	xls.SetColumnWidth(4, 30);
	xls.SetColumnWidth(5, 20);

	xls.SetColumnWidth(6, 20);
	xls.SetColumnWidth(7, 20);
	xls.SetColumnWidth(8, 20);
	//Header
	xls.SetCellMergedColumns(nCol, nRow, 3);
	xls.SetCellMergedColumns(nCol, nRow + 1, 3);
	xls.SetCellMergedColumns(nCol, nRow + 2, 9);
	xls.SetCellMergedColumns(nCol, nRow + 3, 9);
	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("\x44\x41NH S\xC1\x43H \x42\x1EC6NH NH\xC2N KH\xC1M \x42\x1EC6NH"), FMT_TEXT | FMT_CENTER, true, 11);	
	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, FMT_TEXT | FMT_CENTER, false, 11);	
	
	
	
	CStringArray arrCol;
	arrCol.Add(_T("STT"));
	arrCol.Add(_T("T\xEAn \x62\x1EC7nh nh\xE2n"));
	arrCol.Add(_T("N\x103m sinh"));
	arrCol.Add(_T("\x43\x1EA5p \x62\x1EAD\x63"));
	arrCol.Add(_T("\x110\x1A1n v\x1ECB"));
	arrCol.Add(_T("\x43h\x1EA9n \x111o\xE1n"));
	arrCol.Add(_T("Ph\xE1t thu\x1ED1\x63"));
	arrCol.Add(_T("V\xE0o kho\x61"));
	arrCol.Add(_T("\x110\x1ED1i t\x1B0\x1EE3ng"));
	arrCol.Add(_T("S\x1ED1 th\x1EBB"));

	nRow = 7;
	for (int i = 0; i < arrCol.GetCount(); i++)
	{
		xls.SetCellText(nCol+i, nRow, arrCol.GetAt(i), FMT_TEXT | FMT_CENTER, true, 10); 
	}
	nRow = 8;
	while (!rs.IsEOF())
	{
		nIdx++;
		tmpStr.Format(_T("%d"), nIdx);
		xls.SetCellText(nCol, nRow, tmpStr, FMT_INTEGER);
		
		rs.GetValue(_T("pname"), tmpStr);
		xls.SetCellText(nCol + 1, nRow, tmpStr, FMT_TEXT);
		
		rs.GetValue(_T("yob"), tmpStr);
		xls.SetCellText(nCol + 2, nRow, tmpStr, FMT_INTEGER);
		
		rs.GetValue(_T("rank"), tmpStr);
		xls.SetCellText(nCol + 3, nRow, tmpStr, FMT_TEXT);

		rs.GetValue(_T("workplace"), tmpStr);
		xls.SetCellText(nCol + 4, nRow, tmpStr, FMT_TEXT);
		
		rs.GetValue(_T("diagno"), tmpStr);
		xls.SetCellText(nCol + 5, nRow, tmpStr, FMT_TEXT);
		
		rs.GetValue(_T("drugdeliver"), tmpStr);
		if(!tmpStr.IsEmpty()) c4++;
		xls.SetCellText(nCol + 6, nRow, tmpStr, FMT_TEXT | FMT_CENTER);

		rs.GetValue(_T("drugquan"), tmpStr);
		if(!tmpStr.IsEmpty()) c5++;

		rs.GetValue(_T("drugbhytquan"), tmpStr);
		if(!tmpStr.IsEmpty()) c6++;
		
		rs.GetValue(_T("drugbhytquancothe"), tmpStr);
		if(!tmpStr.IsEmpty()) c7++;

		rs.GetValue(_T("inward"), tmpStr);
		if(!tmpStr.IsEmpty()) c8++;
		xls.SetCellText(nCol + 7, nRow, tmpStr, FMT_TEXT);

		rs.GetValue(_T("inwardquan"), tmpStr);
		if(!tmpStr.IsEmpty()) c9++;

		rs.GetValue(_T("inwardbhytquan"), tmpStr);
		if(!tmpStr.IsEmpty()) c10++;

		rs.GetValue(_T("inwardquancothe"), tmpStr);
		if(!tmpStr.IsEmpty()) c11++;


		rs.GetValue(_T("hd_object"), tmpStr);
		if(tmpStr == _T("1")) 
		{
			c1++;
		}
		else if(tmpStr == _T("2")) 
		{
			c2++;
		}
		else if(tmpStr == _T("11"))
		{
			c3++;
		}


		rs.GetValue(_T("obj"), tmpStr);
		xls.SetCellText(nCol + 8, nRow,tmpStr , FMT_TEXT);
		
		rs.GetValue(_T("card_no"), tmpStr);
		xls.SetCellText(nCol + 9, nRow,tmpStr , FMT_TEXT);
		nRow++;
		rs.MoveNext();
	}

	CString szTemp;

	szTemp.Format(_T("Qu\xE2n: %d"),c1++);
	xls.SetCellText(1, 4, szTemp, FMT_TEXT, true, 12);

	xls.SetCellMergedColumns(2, 4, 2);
	szTemp.Format(_T("H\x1B0u: %d"),c2++);
	xls.SetCellText(2, 4, szTemp, FMT_TEXT, true, 12);

	szTemp.Format(_T("\x42HYT Qu\xE2n nh\xE2n: %d"),c3++);
	xls.SetCellText(4, 4, szTemp, FMT_TEXT, true, 12);

	szTemp.Format(_T("T\x1ED5ng s\x1ED1: %d"),nIdx++);
	xls.SetCellText(5, 4, szTemp, FMT_TEXT, true, 12);

	szTemp.Format(_T("Ph\xE1t thu\x1ED1\x63 qu\xE2n: %d"),c5++);
	xls.SetCellText(1, 5, szTemp, FMT_TEXT, true, 12);

	xls.SetCellMergedColumns(2, 5, 2);
	szTemp.Format(_T("Ph\xE1t thu\x1ED1\x63 h\x1B0u: %d"),c6++);
	xls.SetCellText(2, 5, szTemp, FMT_TEXT, true, 12);

	szTemp.Format(_T("Ph\xE1t thu\x1ED1\x63 Q\x43T(\x31\x31): %d"),c7++);
	xls.SetCellText(4, 5, szTemp, FMT_TEXT, true, 12);

	szTemp.Format(_T("T\x1ED5ng ph\xE1t thu\x1ED1\x63: %d"),c4++);
	xls.SetCellText(5, 5, szTemp, FMT_TEXT, true, 12);

	szTemp.Format(_T("V\xE0o vi\x1EC7n qu\xE2n: %d"),c9++);
	xls.SetCellText(1, 6, szTemp, FMT_TEXT, true, 12);

	xls.SetCellMergedColumns(2, 6, 2);
	szTemp.Format(_T("V\xE0o vi\x1EC7n h\x1B0u: %d"),c10++);
	xls.SetCellText(2, 6, szTemp, FMT_TEXT, true, 12);

	szTemp.Format(_T("V\xE0o vi\x1EC7n Q\x43T(\x31\x31): %d"),c11++);
	xls.SetCellText(4, 6, szTemp, FMT_TEXT, true, 12);

	szTemp.Format(_T("T\x1ED5ng v\xE0o vi\x1EC7n: %d"),c8++);
	xls.SetCellText(5, 6, szTemp, FMT_TEXT, true, 12);


	xls.Save(_T("Exports\\Danh Sach Benh Nhan Kham Benh.xls"));

	
} 
void CEMExaminationListReport::OnPrintSelect(){
	CHMSMainFrame  *pMF = (CHMSMainFrame *) AfxGetMainWnd();

	UpdateData(true);
	CReport rpt;
	CRecord rs(&pMF->m_db);
	CString szSQL, tmpStr, szSysDate;
	int nIdx = 0, nDrug = 0, nInward = 0;
	double nAmount = 0, nTotal = 0;
	szSQL = GetQueryString();
	//QueryOpener(szSQL);
	int nCount = rs.ExecSQL(szSQL);
	if (nCount <= 0)
	{
		ShowMessage(150, MB_ICONSTOP);
		return;
	}
	if (!rpt.Init(_T("Reports/HMS/HE_DANHSACHBENHNHANKHAMBENH.rpt")))
		return;
	int nRes = rs.GetRecordCount();
	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|hhmmss, ddmmyyyy|hhmmss), CDateTime::Convert(m_szToDate, yyyymmdd|hhmmss, ddmmyyyy|hhmmss));
	rpt.GetReportHeader()->SetValue(_T("ReportDate"), tmpStr);
	FormatCurrency(nRes, tmpStr);
	rpt.GetReportHeader()->SetValue(_T("TotalPatient"), tmpStr);
	CReportSection *rptDetail;
	while (!rs.IsEOF())
	{
		rptDetail = rpt.AddDetail();
		nIdx++;
		tmpStr.Format(_T("%d"), nIdx);
		rptDetail->SetValue(_T("1"), tmpStr);
		
		rs.GetValue(_T("docno"), tmpStr);
		rptDetail->SetValue(_T("2"), tmpStr);
		
		rs.GetValue(_T("pname"), tmpStr);	
		rptDetail->SetValue(_T("3"), tmpStr);
		
		rs.GetValue(_T("yob"), tmpStr);
		rptDetail->SetValue(_T("4"), tmpStr);
		
		rs.GetValue(_T("rank"), tmpStr);
		rptDetail->SetValue(_T("5"), tmpStr);
		
		rs.GetValue(_T("workplace"), tmpStr);
		rptDetail->SetValue(_T("6"), tmpStr);
		
		rs.GetValue(_T("diagno"), tmpStr);
		rptDetail->SetValue(_T("7"), tmpStr);
		
		rs.GetValue(_T("drugdeliver"), tmpStr);
		//_debug(_T("drug:%s"), tmpStr);
		if (!tmpStr.IsEmpty())
			nDrug++;
		rptDetail->SetValue(_T("8"), tmpStr);
		rs.GetValue(_T("inward"), tmpStr);
		//_debug(_T("in:%s"), tmpStr);
		if (!tmpStr.IsEmpty())
			nInward++;
		rptDetail->SetValue(_T("9"), tmpStr);
		rs.MoveNext();
	}
	tmpStr.Format(_T("%d"), nDrug);
	rpt.GetReportHeader()->SetValue(_T("Drug"), tmpStr);
	tmpStr.Format(_T("%d"), nInward);
	rpt.GetReportHeader()->SetValue(_T("Inward"), 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();
} 
Esempio n. 9
0
//---------------------------------------------------------------------------
TTreeNode* __fastcall TExceptionMessages::AddFFL( AnsiString Str,
  AnsiString File, AnsiString Func, int Line)
{
  MainForm->StatBar->Panels->Items[2]->Text = "E";

  if (!OutTree) {
    AnsiString Mess = "[" + DateTimeToStr(Now()) + "] : " + Str +
      "\nFile = " + ExtractFileName(File) + " (" + IntToStr(Line) + ")" +
      "\nFunction = " + Func;
    ShowMessage(Mess);
    return NULL;
    }

  TTreeNode *TN = OutTree->Items->Add( NULL,
    "[" + DateTimeToStr(Now()) + "] : " + Str);
  OutTree->Items->AddChild( TN, AnsiString("File = ") + ExtractFileName(File) +
    " (" + IntToStr(Line) + ")");
  OutTree->Items->AddChild( TN, "Function = " + Func);

  if (exxp) {
    OutTree->Items->AddChild( TN, ExceptionString(er.ExceptionCode));
    TTreeNode *tn1 = OutTree->Items->AddChild( TN, "Context");
    OutTree->Items->AddChild( tn1, "Flags = 0x" +
      IntToHex((int)cntxt.ContextFlags,8) + ", " +
      ContextFlagsString(cntxt.ContextFlags));
    if ((cntxt.ContextFlags & CONTEXT_CONTROL) == CONTEXT_CONTROL) {
      TTreeNode *tn2 = OutTree->Items->AddChild( tn1, "Control");
      OutTree->Items->AddChild( tn2, "Ebp = 0x" + IntToHex((int)cntxt.Ebp,8));
      OutTree->Items->AddChild( tn2, "Eip = 0x" + IntToHex((int)cntxt.Eip,8));
      OutTree->Items->AddChild( tn2, "SegCs = 0x" + IntToHex((int)cntxt.SegCs,8));
      OutTree->Items->AddChild( tn2, "EFlags = 0x" + IntToHex((int)cntxt.EFlags,8));
      OutTree->Items->AddChild( tn2, "Esp = 0x" + IntToHex((int)cntxt.Esp,8));
      OutTree->Items->AddChild( tn2, "SegSs = 0x" + IntToHex((int)cntxt.SegSs,8));
      }
    if ((cntxt.ContextFlags & CONTEXT_INTEGER) == CONTEXT_INTEGER) {
      TTreeNode *tn2 = OutTree->Items->AddChild( tn1, "Integer");
      OutTree->Items->AddChild( tn2, "Edi = 0x" + IntToHex((int)cntxt.Edi,8));
      OutTree->Items->AddChild( tn2, "Esi = 0x" + IntToHex((int)cntxt.Esi,8));
      OutTree->Items->AddChild( tn2, "Ebx = 0x" + IntToHex((int)cntxt.Ebx,8));
      OutTree->Items->AddChild( tn2, "Edx = 0x" + IntToHex((int)cntxt.Edx,8));
      OutTree->Items->AddChild( tn2, "Ecx = 0x" + IntToHex((int)cntxt.Ecx,8));
      OutTree->Items->AddChild( tn2, "Eax = 0x" + IntToHex((int)cntxt.Eax,8));
      }
    if ((cntxt.ContextFlags & CONTEXT_SEGMENTS) == CONTEXT_SEGMENTS) {
      TTreeNode *tn2 = OutTree->Items->AddChild( tn1, "Segments");
      OutTree->Items->AddChild( tn2, "SegGs = 0x" + IntToHex((int)cntxt.SegGs,8));
      OutTree->Items->AddChild( tn2, "SegFs = 0x" + IntToHex((int)cntxt.SegFs,8));
      OutTree->Items->AddChild( tn2, "SegEs = 0x" + IntToHex((int)cntxt.SegEs,8));
      OutTree->Items->AddChild( tn2, "SegDs = 0x" + IntToHex((int)cntxt.SegDs,8));
      }
    if ((cntxt.ContextFlags & CONTEXT_FLOATING_POINT) == CONTEXT_FLOATING_POINT) {
      TTreeNode *tn2 = OutTree->Items->AddChild( tn1, "Floating point");
      OutTree->Items->AddChild( tn2, "Control word = 0x" + IntToHex((int)cntxt.FloatSave.ControlWord,8));
      OutTree->Items->AddChild( tn2, "Status word = 0x" + IntToHex((int)cntxt.FloatSave.StatusWord,8));
      OutTree->Items->AddChild( tn2, "Tag word = 0x" + IntToHex((int)cntxt.FloatSave.TagWord,8));
      OutTree->Items->AddChild( tn2, "Error offset = 0x" + IntToHex((int)cntxt.FloatSave.ErrorOffset,8));
      OutTree->Items->AddChild( tn2, "Error selector = 0x" + IntToHex((int)cntxt.FloatSave.ErrorSelector,8));
      OutTree->Items->AddChild( tn2, "Data offset = 0x" + IntToHex((int)cntxt.FloatSave.DataOffset,8));
      OutTree->Items->AddChild( tn2, "Data selector = 0x" + IntToHex((int)cntxt.FloatSave.DataSelector,8));
      OutTree->Items->AddChild( tn2, "Cr0NpxState = 0x" + IntToHex((int)cntxt.FloatSave.Cr0NpxState,8));
      }
    if ((cntxt.ContextFlags & CONTEXT_DEBUG_REGISTERS) == CONTEXT_DEBUG_REGISTERS) {
      TTreeNode *tn2 = OutTree->Items->AddChild( tn1, "Debug registers");
      OutTree->Items->AddChild( tn2, "Dr0 = 0x" + IntToHex((int)cntxt.Dr0,8));
      OutTree->Items->AddChild( tn2, "Dr1 = 0x" + IntToHex((int)cntxt.Dr1,8));
      OutTree->Items->AddChild( tn2, "Dr2 = 0x" + IntToHex((int)cntxt.Dr2,8));
      OutTree->Items->AddChild( tn2, "Dr3 = 0x" + IntToHex((int)cntxt.Dr3,8));
      OutTree->Items->AddChild( tn2, "Dr6 = 0x" + IntToHex((int)cntxt.Dr6,8));
      OutTree->Items->AddChild( tn2, "Dr7 = 0x" + IntToHex((int)cntxt.Dr7,8));
      }
    if ((cntxt.ContextFlags & CONTEXT_EXTENDED_REGISTERS) == CONTEXT_EXTENDED_REGISTERS) {
      OutTree->Items->AddChild( tn1, "Extended registers");
      }
    exxp = NULL;
    }

  return TN;
}