📄 clientmainview.cpp
字号:
// clientMainView.cpp : implementation of the CClientMainView class
//
#include "stdafx.h"
#include "clientMain.h"
#include "clientMainDoc.h"
#include "clientMainView.h"
#include "CommPrintDlg.h"
#include <string>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
using namespace std;
/////////////////////////////////////////////////////////////////////////////
// CClientMainView
IMPLEMENT_DYNCREATE(CClientMainView, CFormView)
BEGIN_MESSAGE_MAP(CClientMainView, CFormView)
//{{AFX_MSG_MAP(CClientMainView)
ON_BN_CLICKED(IDC_BTN_FIRST, OnBtnFirst)
ON_BN_CLICKED(IDC_BTN_ADD, OnBtnAdd)
ON_BN_CLICKED(IDC_BTN_VIEW, OnBtnView)
ON_BN_CLICKED(IDC_BTN_CANCEL, OnBtnCancel)
ON_BN_CLICKED(IDC_BTN_FIND, OnBtnFind)
ON_BN_CLICKED(IDC_BTN_LAST, OnBtnLast)
ON_BN_CLICKED(IDC_BTN_PREVIOUS, OnBtnPrevious)
ON_BN_CLICKED(IDC_BTN_NEXT, OnBtnNext)
ON_BN_CLICKED(IDC_BTN_MODIFY, OnBtnModify)
ON_BN_CLICKED(IDC_BTN_DELETE, OnBtnDelete)
ON_BN_CLICKED(IDC_BTN_QUERY, OnBtnQuery)
ON_BN_CLICKED(IDC_BTN_PRINT, OnBtnPrint)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CClientMainView construction/destruction
CClientMainView::CClientMainView()
: CFormView(CClientMainView::IDD)
{
//{{AFX_DATA_INIT(CClientMainView)
m_strID = _T("");
m_strName = _T("");
m_fPrice = 0.0;
m_strSql = L"select * from V_Material";
//}}AFX_DATA_INIT
// TODO: add construction code here
m_strVSql = L"select * from V_Material";
m_strPSql = m_strVSql;
}
CClientMainView::~CClientMainView()
{
}
void CClientMainView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CClientMainView)
DDX_Control(pDX, IDC_BTN_PRINT, m_btnPrint);
DDX_Control(pDX, IDC_BTN_QUERY, m_btnQuery);
DDX_Control(pDX, IDC_BTN_FIND, m_btnFind);
DDX_Control(pDX, IDC_BTN_VIEW, m_btnViewAll);
DDX_Control(pDX, IDC_BTN_PREVIOUS, m_btnPrev);
DDX_Control(pDX, IDC_BTN_NEXT, m_btnNext);
DDX_Control(pDX, IDC_BTN_MODIFY, m_btnModify);
DDX_Control(pDX, IDC_BTN_LAST, m_btnLast);
DDX_Control(pDX, IDC_BTN_FIRST, m_btnFirst);
DDX_Control(pDX, IDC_BTN_DELETE, m_btnDel);
DDX_Control(pDX, IDC_BTN_CANCEL, m_btnCancel);
DDX_Control(pDX, IDC_BTN_ADD, m_btnAddNew);
DDX_Text(pDX, IDC_EDIT_ID, m_strID);
DDX_Text(pDX, IDC_EDIT_NAME, m_strName);
DDX_Text(pDX, IDC_EDIT_PRICE, m_fPrice);
DDX_Control(pDX, IDC_GRID_VIEWALL, m_grdViewAll);
//}}AFX_DATA_MAP
}
BOOL CClientMainView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CFormView::PreCreateWindow(cs);
}
void CClientMainView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
//ResizeParentToFit();
CString strTitle ;
strTitle = "材料基本信息管理";
GetParentFrame()->SetWindowText(strTitle);
//g_pAdoServer->CloseRecordset();
//g_pAdoServer->OpenRecordset(m_strSql);
//GetParentFrame()->RecalcLayout();
//ResizeParentToFit(FALSE);
//ResizeParentToFit(TRUE);
// 进行有关界面初始化的工作。为按钮设置图标
m_btnAddNew.SetIcon(AfxGetApp()->LoadIcon(IDI_ADDNEW));
m_btnModify.SetIcon(AfxGetApp()->LoadIcon(IDI_MODIFY));
m_btnDel.SetIcon(AfxGetApp()->LoadIcon(IDI_DELETE));
m_btnCancel.SetIcon(AfxGetApp()->LoadIcon(IDI_CANCEL));
m_btnFirst.SetIcon(AfxGetApp()->LoadIcon(IDI_FIRST));
m_btnPrev.SetIcon(AfxGetApp()->LoadIcon(IDI_PREVIOUS));
m_btnNext.SetIcon(AfxGetApp()->LoadIcon(IDI_NEXT));
m_btnLast.SetIcon(AfxGetApp()->LoadIcon(IDI_LAST));
m_btnViewAll.SetIcon(AfxGetApp()->LoadIcon(IDI_VIEWALL));
m_btnFind.SetIcon(AfxGetApp()->LoadIcon(IDI_FIND));
m_btnQuery.SetIcon(AfxGetApp()->LoadIcon(IDI_QUERY));
m_btnPrint.SetIcon(AfxGetApp()->LoadIcon(IDI_PRINT));
GetParentFrame()->ShowWindow(SW_SHOWMAXIMIZED);
}
/////////////////////////////////////////////////////////////////////////////
// CClientMainView printing
BOOL CClientMainView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CClientMainView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CClientMainView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
void CClientMainView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
// TODO: add customized printing code here
}
/////////////////////////////////////////////////////////////////////////////
// CClientMainView diagnostics
#ifdef _DEBUG
void CClientMainView::AssertValid() const
{
CFormView::AssertValid();
}
void CClientMainView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
CClientMainDoc* CClientMainView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CClientMainDoc)));
return (CClientMainDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CClientMainView message handlers
void CClientMainView::OnBtnFirst()
{
// TODO: Add your control notification handler code here
//g_pAdoServer->OpenRecordset();
HRESULT hr;
VARIANT_BOOL bEmpty;
hr = g_pAdoServer->get_Empty(&bEmpty);
if(bEmpty)
{
MessageBox("当前记录集为空!", "Client Error:", MB_OK);
return;
}
string strID;
string strName;
g_pAdoServer->First();
strID = (_bstr_t)g_pAdoServer->Field["M_ID"];
strName = (_bstr_t)g_pAdoServer->Field["Name"];
m_fPrice = g_pAdoServer->Field["Price"];
m_strID = strID.c_str();
m_strName = strName.c_str();
UpdateData(FALSE);
}
void CClientMainView::OnBtnAdd()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
if((m_strID == "") || (m_strName == ""))
{
MessageBox("材料名称、编号以及价格不能为空!", NULL, MB_OK);
return;
}
g_pAdoServer->AddNew();
g_pAdoServer->Field["M_ID"] = LPCSTR(m_strID);
g_pAdoServer->Field["Name"] = LPCSTR(m_strName);
g_pAdoServer->Field["Price"] = m_fPrice;
// 顺便初始化该材料的库存情况
g_pAdoServer->Field["SM_ID"] = LPCSTR(m_strID);
g_pAdoServer->Field["Total"] = (long)0;
g_pAdoServer->Update();
}
void CClientMainView::OnBtnView()
{
// TODO: Add your control notification handler code here
HRESULT hr;
IDispatch* pDisp;
_bstr_t strSql("Select * from T_Material");
//strSql = L"Select * from T_";
hr = g_pAdoServer->raw_GetRs(_variant_t(strSql), &pDisp);
//g_pAdoServer->GetRs();
m_grdViewAll.SetRefDataSource(pDisp);
}
void CClientMainView::OnBtnCancel()
{
// TODO: Add your control notification handler code here
g_pAdoServer->CancelUpdate();
}
void CClientMainView::OnBtnFind()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
HRESULT hr;
if(m_strID == "")
{
MessageBox("请输入材料编号!", NULL, MB_OK);
return;
}
VARIANT_BOOL bEmpty;
hr = g_pAdoServer->get_Empty(&bEmpty);
if(bEmpty)
{
MessageBox("当前记录集为空!", "Client Error:", MB_OK);
return;
}
g_pAdoServer->First();
CString strTemp;
strTemp = "M_ID = '" + m_strID + "'";
_bstr_t strFind(strTemp);
hr = g_pAdoServer->Find(strFind);
if(SUCCEEDED(hr))
{
hr = g_pAdoServer->get_ADOEOF(&bEmpty);
if(bEmpty)
{
MessageBox("没有找到记录!", NULL, MB_OK);
return;
}
string strID;
string strName;
m_fPrice = g_pAdoServer->Field["Price"];
strID = (_bstr_t)g_pAdoServer->Field["M_ID"];
strName = (_bstr_t)g_pAdoServer->Field["Name"];
m_strID = strID.c_str();
m_strName = strName.c_str();
}
UpdateData(FALSE);
}
void CClientMainView::OnBtnLast()
{
// TODO: Add your control notification handler code here
HRESULT hr;
VARIANT_BOOL bEmpty;
hr = g_pAdoServer->get_Empty(&bEmpty);
if(bEmpty)
{
MessageBox("当前记录集为空!", "Client Error:", MB_OK);
return;
}
string strID;
string strName;
g_pAdoServer->Last();
strID = (_bstr_t)g_pAdoServer->Field["M_ID"];
strName = (_bstr_t)g_pAdoServer->Field["Name"];
m_fPrice = g_pAdoServer->Field["Price"];
m_strID = strID.c_str();
m_strName = strName.c_str();
UpdateData(FALSE);
// g_pAdoServer->get_BookMark(&m_vBookMark);
}
void CClientMainView::OnBtnPrevious()
{
// TODO: Add your control notification handler code here
HRESULT hr;
VARIANT_BOOL bEmpty;
hr = g_pAdoServer->get_Empty(&bEmpty);
if(bEmpty)
{
MessageBox("当前记录集为空!", "Client Error:", MB_OK);
return;
}
g_pAdoServer->Prev();
hr = g_pAdoServer->get_BOF(&bEmpty);
if(bEmpty)
{
MessageBox("已经到记录集头部!", NULL, MB_OK);
g_pAdoServer->First();
}
string strID;
string strName;
strID = (_bstr_t)g_pAdoServer->Field["M_ID"];
strName = (_bstr_t)g_pAdoServer->Field["Name"];
m_fPrice = g_pAdoServer->Field["Price"];
m_strID = strID.c_str();
m_strName = strName.c_str();
UpdateData(FALSE);
}
void CClientMainView::OnBtnNext()
{
// TODO: Add your control notification handler code here
HRESULT hr;
VARIANT_BOOL bEmpty;
hr = g_pAdoServer->get_Empty(&bEmpty);
if(bEmpty)
{
MessageBox("当前记录集为空!", "Client Error:", MB_OK);
return;
}
g_pAdoServer->Next();
hr = g_pAdoServer->get_ADOEOF(&bEmpty);
if(bEmpty)
{
MessageBox("已经到记录集尾部!", NULL, MB_OK);
g_pAdoServer->Last();
}
string strID;
string strName;
strID = (_bstr_t)g_pAdoServer->Field["M_ID"];
strName = (_bstr_t)g_pAdoServer->Field["Name"];
m_fPrice = g_pAdoServer->Field["Price"];
m_strID = strID.c_str();
m_strName = strName.c_str();
//m_BookMark = g_pAdoServer->BookMark;
UpdateData(FALSE);
}
void CClientMainView::OnBtnModify()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
if((m_strID == "") || (m_strName == ""))
{
MessageBox("材料名称、编号以及价格不能为空!", NULL, MB_OK);
return;
}
g_pAdoServer->Field["M_ID"] = LPCSTR(m_strID);
g_pAdoServer->Field["Name"] = LPCSTR(m_strName);
g_pAdoServer->Field["Price"] = m_fPrice;
// 库存情况初始化
g_pAdoServer->Field["SM_ID"] = LPCSTR(m_strID);
g_pAdoServer->Update();
}
void CClientMainView::OnBtnDelete()
{
// TODO: Add your control notification handler code here
HRESULT hr;
VARIANT_BOOL bEmpty;
hr = g_pAdoServer->get_Empty(&bEmpty);
if(bEmpty)
{
MessageBox("当前记录集为空!", "Client Error:", MB_OK);
return;
}
g_pAdoServer->Delete();
g_pAdoServer->Update();
hr = g_pAdoServer->get_ADOEOF(&bEmpty);
if(bEmpty)
{
MessageBox("已经到记录集尾部!", NULL, MB_OK);
g_pAdoServer->Last();
}
else
{
g_pAdoServer->Next();
hr = g_pAdoServer->get_ADOEOF(&bEmpty);
if(bEmpty)
{
MessageBox("已经到记录集尾部!", NULL, MB_OK);
g_pAdoServer->Last();
}
}
string strID;
string strName;
strID = (_bstr_t)g_pAdoServer->Field["M_ID"];
strName = (_bstr_t)g_pAdoServer->Field["Name"];
m_fPrice = g_pAdoServer->Field["Price"];
m_strID = strID.c_str();
m_strName = strName.c_str();
UpdateData(FALSE);
}
void CClientMainView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView)
{
// TODO: Add your specialized code here and/or call the base class
if(bActivate == FALSE)
{
HRESULT hr;
VARIANT_BOOL bEmpty;
hr = g_pAdoServer->get_Empty(&bEmpty);
if(bEmpty)
{
return;
}
else
{
g_pAdoServer->get_BookMark(&m_vBookMark);
return;
}
}
else
{
g_pAdoServer->CloseRecordset();
g_pAdoServer->OpenRecordset(m_strSql);
// OnBtnFind();
HRESULT hr;
VARIANT_BOOL bEmpty;
hr = g_pAdoServer->get_Empty(&bEmpty);
if(bEmpty)
{
return;
}
else
{
g_pAdoServer->put_BookMark(m_vBookMark);
}
string strID;
string strName;
strID = (_bstr_t)g_pAdoServer->Field["M_ID"];
strName = (_bstr_t)g_pAdoServer->Field["Name"];
m_fPrice = g_pAdoServer->Field["Price"];
m_strID = strID.c_str();
m_strName = strName.c_str();
UpdateData(FALSE);
}
CFormView::OnActivateView(bActivate, pActivateView, pDeactiveView);
}
void CClientMainView::OnBtnQuery()
{
// TODO: Add your control notification handler code here
HRESULT hr;
IGxp_adoQueryPtr pQuery;
MULTI_QI MultiQI;
MultiQI.hr = NOERROR; MultiQI.pItf = NULL;
MultiQI.pIID = &__uuidof(IGxp_adoQuery);
hr = CoCreateInstanceEx( __uuidof(Gxp_adoQuery), NULL, CLSCTX_LOCAL_SERVER, NULL, 1, &MultiQI);
if(SUCCEEDED(hr))
{
pQuery = (IGxp_adoQuery *)MultiQI.pItf;
//MessageBox(NULL,"CoCreateInstance Successful.",NULL,MB_OK);
}
else
{
MessageBox("CoCreateInstance Failed","Client Error:",MB_OK);
return ;
}
IDispatch* pDisp;
// 下面是一系列的处理过程,包括了调用通用查询对话框,处理字符串等
string strSpace = " where ";
string strSource;
string strResult;
hr = g_pAdoServer->raw_GetRs(_variant_t(m_strVSql), &pDisp);
strResult = pQuery->GetQuery(pDisp);
if(strResult.empty())
{
m_strPSql = m_strVSql;
return;
}
strSource = m_strVSql;
strResult = strSource + strSpace + strResult;
_bstr_t strDest(strResult.c_str());
m_strPSql = strDest;
hr = g_pAdoServer->raw_GetRs(_variant_t(strDest), &pDisp);
m_grdViewAll.SetRefDataSource(pDisp);
}
void CClientMainView::OnBtnPrint()
{
// TODO: Add your control notification handler code here
CCommPrintDlg printDlg;
printDlg.m_strSql = m_strPSql;
printDlg.DoModal();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -