📄 xundlg.cpp
字号:
// XunDlg.cpp : implementation file
//
#include "stdafx.h"
#include "kufangDBS.h"
#include "XunDlg.h"
extern CDatabase m_db;
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CXunDlg dialog
CXunDlg::CXunDlg(CWnd* pParent /*=NULL*/)
: CDialog(CXunDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CXunDlg)
m_strValue = _T("");
m_strZiduan = _T("");
//}}AFX_DATA_INIT
}
void CXunDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CXunDlg)
DDX_Control(pDX, IDC_LIST_CHAXUN, m_listChaxun);
DDX_Text(pDX, IDC_EDIT_VALUE, m_strValue);
DDX_CBString(pDX, IDC_COMBO_ZIDUAN, m_strZiduan);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CXunDlg, CDialog)
//{{AFX_MSG_MAP(CXunDlg)
ON_BN_CLICKED(IDC_BTN_CX_CHAXUN, OnBtnCxChaxun)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CXunDlg message handlers
void CXunDlg::OnBtnCxChaxun()
{
m_listChaxun.DeleteAllItems();
UpdateData();
//选择字段
CString sql ;//注意字段的描绘
//sql="Select * from sb where yqmc ='万用表' ";
//sql.Format ("Select * from sb where yqmc = '%s' ",m_strValue);
if(m_strZiduan == "仪器名称") sql.Format("Select * from sb where yqmc ='%s'",m_strValue);
else if(m_strZiduan =="型号") sql.Format("Select * from sb where xh ='%s'",m_strValue);
else if(m_strZiduan =="规格") sql.Format("Select * from sb where gg ='%s'",m_strValue);
else if(m_strZiduan =="厂家") sql.Format("Select * from sb where cj ='%s'",m_strValue);
else if(m_strZiduan =="国别") sql.Format("Select * from sb where gb ='%s'",m_strValue);
else if(m_strZiduan =="供应商") sql.Format("Select * from sb where gys ='%s'",m_strValue);
else if(m_strZiduan =="验收人") sql.Format("Select * from sb where ysr ='%s'",m_strValue);
else if(m_strZiduan =="领用单位")sql.Format("Select * from sb where lydw ='%s'",m_strValue);
else if(m_strZiduan =="领用人") sql.Format("Select * from sb where lyr ='%s'",m_strValue);
else if(m_strZiduan =="使用方向")sql.Format("Select * from sb where syfx ='%s'",m_strValue);
else if(m_strZiduan =="经手人") sql.Format("Select * from sb where fsr ='%s'",m_strValue);
else sql.Format("Select * from sb where yqmc ='%s'",m_strValue);
TRY{
//获取所有的设备记录集
CRecordset rs;
rs.m_pDatabase = & m_db;
rs.Open(CRecordset::dynaset, sql);
int yqbh;
CString xh,dj, cj , gb , ccrq , gys , gzrq , ysr , xz , lydw , lyr , syfx , jfkm , jsr, flh, yqmc, gg, cch;
while (!rs.IsEOF()){
CDBVariant var;
//获取成员字段值
rs.GetFieldValue((short)0,var,SQL_C_SLONG);
if (var.m_dwType !=DBVT_NULL)
yqbh = var.m_iVal;
var.Clear();
rs.GetFieldValue(1, flh);
rs.GetFieldValue(2, yqmc);
rs.GetFieldValue(3, xh);
rs.GetFieldValue(4,gg);
rs.GetFieldValue(5,dj);
rs.GetFieldValue(6,cj);
rs.GetFieldValue(7, gb);
rs.GetFieldValue(8, cch);
rs.GetFieldValue(9, ccrq);
rs.GetFieldValue(10, gys);
rs.GetFieldValue(11, gzrq);
rs.GetFieldValue(12, ysr);
rs.GetFieldValue(13, xz);
rs.GetFieldValue(14, lydw);
rs.GetFieldValue(15, lyr);
rs.GetFieldValue(16, syfx);
rs.GetFieldValue(17, jfkm);
rs.GetFieldValue(18, jsr);
InsertShebeiItem7(yqbh, flh, yqmc,xh, gg, dj,cj , gb , cch ,ccrq ,gys , gzrq ,ysr , xz ,lydw ,lyr ,syfx ,jfkm ,jsr);
rs.MoveNext();
}
rs.Close();
}
CATCH(CDBException,ex)
{
AfxMessageBox(ex->m_strError);
AfxMessageBox(ex->m_strStateNativeOrigin);
}
AND_CATCH(CMemoryException,pEx)
{
pEx->ReportError();
AfxMessageBox("memory exception");
}
AND_CATCH(CException,e){
TCHAR szError[100];
e->GetErrorMessage(szError,100);
AfxMessageBox(szError);
}
END_CATCH
}
BOOL CXunDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
//设置列表空间风格
DWORD dwExStyle = LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_HEADERDRAGDROP | LVS_EX_ONECLICKACTIVATE | LVS_EX_UNDERLINEHOT;
m_listChaxun.SetExtendedStyle(dwExStyle);
//初始化设备列表控件
m_listChaxun.InsertColumn(0,"仪器编号",LVCFMT_CENTER,60) ;
m_listChaxun.InsertColumn(1,"分类号",LVCFMT_CENTER,60) ;
m_listChaxun.InsertColumn(2,"仪器名称",LVCFMT_CENTER,60) ;
m_listChaxun.InsertColumn(3,"型号",LVCFMT_CENTER,60) ;
m_listChaxun.InsertColumn(4,"规格",LVCFMT_CENTER,60) ;
m_listChaxun.InsertColumn(5,"单价",LVCFMT_CENTER,60) ;
m_listChaxun.InsertColumn(6,"厂家",LVCFMT_CENTER,60) ;
m_listChaxun.InsertColumn(7,"国别",LVCFMT_CENTER,60) ;
m_listChaxun.InsertColumn(8,"出厂号",LVCFMT_CENTER,60) ;
m_listChaxun.InsertColumn(9,"出厂日期",LVCFMT_CENTER,60) ;
m_listChaxun.InsertColumn(10,"供应商",LVCFMT_CENTER,60) ;
m_listChaxun.InsertColumn(11,"购置日期",LVCFMT_CENTER,60) ;
m_listChaxun.InsertColumn(12,"验收人",LVCFMT_CENTER,60) ;
m_listChaxun.InsertColumn(13,"现状",LVCFMT_CENTER,60) ;
m_listChaxun.InsertColumn(14,"领用单位",LVCFMT_CENTER,60) ;
m_listChaxun.InsertColumn(15,"领用人",LVCFMT_CENTER,60) ;
m_listChaxun.InsertColumn(16,"使用方向",LVCFMT_CENTER,60) ;
m_listChaxun.InsertColumn(17,"经费科目",LVCFMT_CENTER,45) ;
m_listChaxun.InsertColumn(18,"经手人",LVCFMT_CENTER,60) ;
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CXunDlg::InsertShebeiItem7(int yqbh, CString flh, CString yqmc, CString xh, CString gg,CString dj,CString cj ,CString gb , CString cch ,CString ccrq ,CString gys , CString gzrq ,CString ysr ,CString xz ,CString lydw ,CString lyr ,CString syfx ,CString jfkm ,CString jsr)
{
//获取当前的显示条数
int nIndex = m_listChaxun.GetItemCount();
LV_ITEM lvItem;
lvItem.mask = LVIF_TEXT;
lvItem.iItem = nIndex;
lvItem.iSubItem = 0;
CString temp;
temp.Format("%d", yqbh);
lvItem.pszText = (char*)(LPCTSTR) temp;
//在nIndex一行插入数据
m_listChaxun . InsertItem(&lvItem);
m_listChaxun . SetItemText(nIndex,1, flh);
m_listChaxun . SetItemText(nIndex,2, yqmc);
m_listChaxun . SetItemText(nIndex,3, xh);
m_listChaxun . SetItemText(nIndex,4, gg);
m_listChaxun . SetItemText(nIndex,5, dj);
m_listChaxun . SetItemText(nIndex,6, cj);
m_listChaxun . SetItemText(nIndex,7, gb);
m_listChaxun . SetItemText(nIndex,8, cch);
m_listChaxun . SetItemText(nIndex,9, ccrq);
m_listChaxun . SetItemText(nIndex,10, gys);
m_listChaxun . SetItemText(nIndex,11, gzrq);
m_listChaxun . SetItemText(nIndex,12, ysr);
m_listChaxun . SetItemText(nIndex,13, xz);
m_listChaxun . SetItemText(nIndex,14, lydw);
m_listChaxun . SetItemText(nIndex,15, lyr);
m_listChaxun . SetItemText(nIndex,16, syfx);
m_listChaxun . SetItemText(nIndex,17, jfkm);
m_listChaxun . SetItemText(nIndex,18, jsr);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -