📄 query.cpp
字号:
// Query.cpp : implementation file
//
#include "stdafx.h"
#include "bxt.h"
#include "Query.h"
#include "SelPic.h"
#include "Pic.h"
#include "BxtDlg.h"
#include "Direct.h"
#include "rephoto.h"
#include "RecordFile.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include "glbfun.h"
/////////////////////////////////////////////////////////////////////////////
// Query dialog
Query::Query(CWnd* pParent /*=NULL*/)
: CDialog(Query::IDD, pParent)
{
//{{AFX_DATA_INIT(Query)
m_doctor = _T("");
m_illname = _T("");
m_result = _T("");
//}}AFX_DATA_INIT
m_bSortInc = TRUE;
m_bSaveWhenQuery = FALSE;
m_pCfg = ((CBxtApp *)(AfxGetApp()))->GetConfig();
m_bResultIsEmpty = TRUE;
m_bResultFromDatabase = FALSE;
}
void
Query::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(Query)
DDX_Control(pDX, IDC_RICHEDIT_REPORT, m_rich);
DDX_Control(pDX, IDC_MSFLEXGRID1, m_grd);
DDX_Text(pDX, IDC_EDIT_DOCTOR, m_doctor);
DDX_Text(pDX, IDC_EDIT_ILLNAME, m_illname);
DDX_Text(pDX, IDC_EDIT_RESULT, m_result);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(Query, CDialog)
//{{AFX_MSG_MAP(Query)
ON_BN_CLICKED(IDC_BUTTON_DELETERECORD, OnButtonDeleterecord)
ON_BN_CLICKED(IDC_BUTTON_PRINT_REPORT, OnButtonPrintReport)
ON_BN_CLICKED(IDC_BUTTON_PRINT_REPORT2, OnButtonPrintReport2)
ON_BN_CLICKED(IDC_BUTTON_DEAL_WITH_IMAGE, OnButtonDealWithImage)
ON_BN_CLICKED(IDC_BUTTON14, OnButton14)
ON_BN_CLICKED(IDC_BUTTON_SAVE_AS_FILE, OnButtonSaveAsFile)
//}}AFX_MSG_MAP
ON_MESSAGE(WX_QUERY, QueryRun)
ON_MESSAGE(WX_SETRECORDID, SetRecordID)
ON_MESSAGE(WX_RETRIEVERECORD, RetrieveRecord)
ON_MESSAGE(WX_SETORDER, SetSQLOrder)
ON_MESSAGE(WX_SETWHERE, SetSQLWhere)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// Query message handlers
BOOL
Query::OnInitDialog()
{
CDialog::OnInitDialog();
m_grd.SetRows(1);
m_grd.SetCols(9);
m_grd.SetRow(0);
m_grd.SetCol(1); m_grd.SetText("CT号");
m_grd.SetCol(2); m_grd.SetText("姓名");
m_grd.SetCol(3); m_grd.SetText("性别");
m_grd.SetCol(4); m_grd.SetText("年龄");
m_grd.SetCol(5); m_grd.SetText("科别");
m_grd.SetCol(6); m_grd.SetText("确诊疾病");
m_grd.SetCol(7); m_grd.SetText("检查部位");
m_grd.SetCol(8); m_grd.SetText("检查日期");
m_grd.SetColWidth(0,200);
m_grd.SetColWidth(1,1450);
m_grd.SetColWidth(2,1200);
m_grd.SetColWidth(3,600);
m_grd.SetColWidth(4,600);
m_grd.SetColWidth(5,1500);
m_grd.SetColWidth(6,1500);
m_grd.SetColWidth(7,1000);
m_grd.SetColWidth(8,2900);
if (m_pCfg->iUiType == UI_TYPE_SIMPLE)
{
GetDlgItem(IDC_BUTTON_SAVE_AS_FILE)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_BUTTON_DELETERECORD)->EnableWindow(FALSE);
}
return (TRUE);
}
void
Query::QueryRun(WPARAM wParam, LPARAM lParam)
{
BOOL bQueryDatabase = (BOOL)(wParam);
CBxtDlg *pMainWnd = (CBxtDlg *)(AfxGetMainWnd());
m_grd.SetRedraw(FALSE);
if (m_pCfg->iUiType == UI_TYPE_SIMPLE || !bQueryDatabase)
{
pMainWnd->m_imagepath = m_pCfg->sCDDatapath;
SimpleQuery((CWnd *)(lParam));
m_bResultFromDatabase = FALSE;
}
else
{
pMainWnd->m_imagepath = pMainWnd->m_fixedimagepath;
NormalQuery();
m_bResultFromDatabase = TRUE;
}
m_grd.SetRedraw(TRUE);
m_grd.Invalidate();
}
BEGIN_EVENTSINK_MAP(Query, CDialog)
//{{AFX_EVENTSINK_MAP(Query)
ON_EVENT(Query, IDC_MSFLEXGRID1, -600 /* Click */, OnClickMsflexgrid1, VTS_NONE)
ON_EVENT(Query, IDC_MSFLEXGRID1, -601 /* DblClick */, OnDblClickMsflexgrid1, VTS_NONE)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
void
Query::OnOK()
{
}
void
Query::OnCancel()
{
}
void
Query::OnButtonDeleterecord()
{
char sql[2000];
CString id;
if (m_bResultIsEmpty)
{
AfxMessageBox("没有可以删除的记录!");
return;
}
if (!m_bResultFromDatabase)
{
AfxMessageBox("不能删除光盘记录!");
return;
}
id = m_grd.GetTextMatrix(m_grd.GetRow(),1);
if (id.IsEmpty())
{
AfxMessageBox("请选择 CT 编号!");
return;
}
if (id == m_currentid)
{
AfxMessageBox("禁止删除当前记录!");
return;
}
sprintf(sql,"DELETE FROM REPORT WHERE ID='%s'",id.GetBuffer(id.GetLength()));
HENV henv;
HDBC hdbc;
HSTMT hStmt;
SQLAllocEnv(&henv);
SQLAllocConnect(henv,&hdbc);
SQLConnect(hdbc,(unsigned char *)"BXT",SQL_NTS,NULL,0,NULL,0);
SQLAllocStmt(hdbc,&hStmt);
RETCODE rt;
SQLFreeStmt(hStmt,SQL_CLOSE);
rt = SQLExecDirect(hStmt, (unsigned char*)sql, SQL_NTS);
SQLFreeStmt(hStmt,SQL_DROP);
SQLDisconnect(hdbc);
SQLFreeConnect(hdbc);
SQLFreeEnv(henv);
QueryRun((WPARAM)(TRUE), 0);
CString sPath;
sPath = ((CBxtDlg *)AfxGetMainWnd())->m_imagepath;
sPath += id;
DeleteDir(sPath.GetBuffer(sPath.GetLength()));
}
void
Query::OnClickMsflexgrid1()
{
ShowCurrentRecordInfo();
}
void
Query::SetRecordID(WPARAM wParm, LPARAM lParm)
{
strcpy(m_currentid, (CHAR *)(lParm));
}
void
Query::OnButtonPrintReport()
{
((CBxtDlg *)AfxGetMainWnd())->PrintReport(false,0);
}
void
Query::OnButtonPrintReport2()
{
((CBxtDlg *)AfxGetMainWnd())->PrintReport(false,1);
}
BOOL
Query::DeleteDir(char *path)
{
CFileFind tt;
BOOL FindSuccess;
char fn[1000];
sprintf(fn,"%s\\*.*",path);
FindSuccess = tt.FindFile(fn);
while(FindSuccess)
{
FindSuccess = tt.FindNextFile();
if (!tt.IsDirectory())
DeleteFile(tt.GetFilePath());
}
tt.Close();
RemoveDirectory(path);
return true;
}
void
Query::OnButtonDealWithImage()
{
CString picpath;
picpath = ((CBxtDlg *)AfxGetMainWnd())->m_imagepath;
picpath += m_id;
picpath += "\\";
((CBxtDlg *)AfxGetMainWnd())->imgpcs->refresh(picpath.GetBuffer(picpath.GetLength()));
if (m_pCfg->iUiType == UI_TYPE_SIMPLE)
((CBxtDlg *)AfxGetMainWnd())->m_m.SelectTab(0);
else
((CBxtDlg *)AfxGetMainWnd())->m_m.SelectTab(1);
((CBxtDlg *)AfxGetMainWnd())->TabSelChange(IDC_TAB1, 0);
}
BOOL
Query::ShowCurrentRecordInfo()
{
m_id = m_grd.GetTextMatrix(m_grd.GetRow(),1);
//if (m_id.GetLength() != 13) return;
HENV henv;
HDBC hdbc;
HSTMT hStmt;
SQLAllocEnv(&henv);
SQLAllocConnect(henv,&hdbc);
SQLConnect(hdbc,(unsigned char *)"BXT",SQL_NTS,NULL,0,NULL,0);
SQLAllocStmt(hdbc,&hStmt);
SQLFreeStmt(hStmt,SQL_CLOSE);
SQLFreeStmt(hStmt,SQL_CLOSE);
CHAR ts[68000];
RETCODE rt;
SDWORD cbValue;
sprintf(ts,"SELECT REPORT,RESULT,DOCTER,ILLNAME,HOSPID,BEDID,CLASS,NAME,SEX,AGE,DEVICE,CHECKSTYLE,CHECKPOS,CHECKDATE FROM REPORT WHERE ID='%s'",m_grd.GetTextMatrix(m_grd.GetRow(),1));
rt = SQLExecDirect(hStmt, (unsigned char *)ts, SQL_NTS);
rt = SQLFetch(hStmt);
strcpy(ts, "");
rt = SQLGetData(hStmt,1,SQL_C_CHAR,ts,sizeof(ts),&cbValue);
CString xtemp;
xtemp = ts;
EDITSTREAM es = {(DWORD)&xtemp, 0, EditStreamCallBack};
m_rich.StreamIn(SF_RTF, es);
rt = SQLGetData(hStmt,2,SQL_C_CHAR,ts,sizeof(ts),&cbValue);
m_result = ts;
rt = SQLGetData(hStmt,3,SQL_C_CHAR,ts,sizeof(ts),&cbValue);
m_doctor = ts;
rt = SQLGetData(hStmt,4,SQL_C_CHAR,ts,sizeof(ts),&cbValue);
m_illname = ts;
rt = SQLGetData(hStmt,5,SQL_C_CHAR,ts,sizeof(ts),&cbValue);
m_hospid = ts;
rt = SQLGetData(hStmt,6,SQL_C_CHAR,ts,sizeof(ts),&cbValue);
m_bedid = ts;
rt = SQLGetData(hStmt,7,SQL_C_CHAR,ts,sizeof(ts),&cbValue);
m_class = ts;
rt = SQLGetData(hStmt,8,SQL_C_CHAR,ts,sizeof(ts),&cbValue);
m_name = ts;
rt = SQLGetData(hStmt,9,SQL_C_CHAR,ts,sizeof(ts),&cbValue);
m_sex = ts;
rt = SQLGetData(hStmt,10,SQL_C_SLONG,&m_age,sizeof(m_age),&cbValue);
// m_age = ts;
rt = SQLGetData(hStmt,11,SQL_C_CHAR,ts,sizeof(ts),&cbValue);
m_device = ts;
rt = SQLGetData(hStmt,12,SQL_C_CHAR,ts,sizeof(ts),&cbValue);
m_checkstyle= ts;
rt = SQLGetData(hStmt,13,SQL_C_CHAR,ts,sizeof(ts),&cbValue);
m_checkpos = ts;
rt = SQLGetData(hStmt,14,SQL_C_CHAR,ts,sizeof(ts),&cbValue);
m_checkdate = ts;
SQLFreeStmt(hStmt,SQL_DROP);
SQLDisconnect(hdbc);
SQLFreeConnect(hdbc);
SQLFreeEnv(henv);
UpdateData(FALSE);
return (TRUE);
}
void
Query::OnButton14()
{
CString picpath;
if (m_pCfg->iUiType == UI_TYPE_SIMPLE)
{
CRecordFile rf;
picpath = rf.GetDataPath();
}
else
{
picpath = ((CBxtDlg *)AfxGetMainWnd())->m_imagepath;
picpath += m_id;
picpath += "\\";
}
CRePhoto dlg(picpath.GetBuffer(200));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -