📄 clientfinanceview.cpp
字号:
// ClientFinanceView.cpp : implementation file
//
#include "stdafx.h"
#include "clientMain.h"
#include "ClientFinanceView.h"
#include <string>
#include "CommPrintDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
using namespace std;
/////////////////////////////////////////////////////////////////////////////
// CClientFinanceView
IMPLEMENT_DYNCREATE(CClientFinanceView, CFormView)
CClientFinanceView::CClientFinanceView()
: CFormView(CClientFinanceView::IDD)
{
//{{AFX_DATA_INIT(CClientFinanceView)
m_fPrice = 0.0;
m_blnPay = FALSE;
m_strOID = _T("");
//}}AFX_DATA_INIT
m_strSql = L"select * from T_Finance";
m_strVSql = L"select * from V_Finance";
m_strPSql = m_strVSql;
}
CClientFinanceView::~CClientFinanceView()
{
}
void CClientFinanceView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CClientFinanceView)
DDX_Control(pDX, IDC_BTN_PRINT, m_btnPrint);
DDX_Control(pDX, IDC_BTN_QUERY, m_btnQuery);
DDX_Control(pDX, IDC_COMBO_OID, m_cmbOID);
DDX_Control(pDX, IDC_CHECK_PAY, m_chkPay);
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_FIND, m_btnFind);
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_Control(pDX, IDC_GRID_VIEWALL, m_grdViewAll);
DDX_Text(pDX, IDC_EDIT_PRICE, m_fPrice);
DDX_Check(pDX, IDC_CHECK_PAY, m_blnPay);
DDX_CBString(pDX, IDC_COMBO_OID, m_strOID);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CClientFinanceView, CFormView)
//{{AFX_MSG_MAP(CClientFinanceView)
ON_BN_CLICKED(IDC_BTN_FIND, OnBtnFind)
ON_BN_CLICKED(IDC_BTN_ADD, OnBtnAdd)
ON_BN_CLICKED(IDC_BTN_MODIFY, OnBtnModify)
ON_BN_CLICKED(IDC_BTN_DELETE, OnBtnDelete)
ON_BN_CLICKED(IDC_BTN_CANCEL, OnBtnCancel)
ON_BN_CLICKED(IDC_BTN_FIRST, OnBtnFirst)
ON_BN_CLICKED(IDC_BTN_PREVIOUS, OnBtnPrevious)
ON_BN_CLICKED(IDC_BTN_NEXT, OnBtnNext)
ON_BN_CLICKED(IDC_BTN_LAST, OnBtnLast)
ON_BN_CLICKED(IDC_BTN_VIEW, OnBtnView)
ON_CBN_KILLFOCUS(IDC_COMBO_OID, OnKillfocusComboOid)
ON_BN_CLICKED(IDC_BTN_QUERY, OnBtnQuery)
ON_BN_CLICKED(IDC_BTN_PRINT, OnBtnPrint)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CClientFinanceView diagnostics
#ifdef _DEBUG
void CClientFinanceView::AssertValid() const
{
CFormView::AssertValid();
}
void CClientFinanceView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
CClientMainDoc* CClientFinanceView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CClientMainDoc)));
return (CClientMainDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CClientFinanceView message handlers
void CClientFinanceView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
CString strTitle ;
strTitle = "财务管理";
GetParentFrame()->SetWindowText(strTitle);
CString strField;
_bstr_t strOrder("select Distinct O_ID from T_Orders");
strField = "O_ID";
CClientMainApp::InitCmbBox(strOrder, strField, &m_cmbOID);
//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);
}
void CClientFinanceView::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 strOID;
g_pAdoServer->First();
strOID = (_bstr_t)g_pAdoServer->Field["O_ID"];
m_fPrice = g_pAdoServer->Field["Money"];
m_blnPay = abs((VARIANT_BOOL)g_pAdoServer->Field["Payment"]);
m_strOID = strOID.c_str();
UpdateData(FALSE);
}
void CClientFinanceView::OnBtnAdd()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
if(m_strOID == "")
{
MessageBox("记录的每个字段都不能为空!", NULL, MB_OK);
return;
}
///////////////////////用来生成订单的总金额//////////////////////////////////
g_pAdoServer->CloseRecordset();
_bstr_t strSql("select * from T_Orders where O_ID = '" + m_strOID + "'");
g_pAdoServer->OpenRecordset(strSql);
long nQuantity;
string strMID;
CString str;
nQuantity = g_pAdoServer->Field["Quantity"];
strMID = (_bstr_t)g_pAdoServer->Field["M_ID"];
str = strMID.c_str();
g_pAdoServer->CloseRecordset();
strSql = "select * from T_Material where M_ID = '" + str + "'";
g_pAdoServer->OpenRecordset(strSql);
double fPrice;
fPrice = g_pAdoServer->Field["Price"];
m_fPrice = nQuantity * fPrice;
g_pAdoServer->CloseRecordset();
g_pAdoServer->OpenRecordset(m_strSql);
//////////////////////////////////////////////////////////////////////////////
g_pAdoServer->AddNew();
g_pAdoServer->Field["O_ID"] = LPCSTR(m_strOID);
g_pAdoServer->Field["Money"] = m_fPrice;
g_pAdoServer->Field["Payment"] = (VARIANT_BOOL)m_blnPay;
g_pAdoServer->Update();
UpdateData(FALSE);
}
void CClientFinanceView::OnBtnView()
{
// TODO: Add your control notification handler code here
HRESULT hr;
IDispatch* pDisp;
_bstr_t strSql("Select * from T_Finance");
//strSql = L"Select * from T_";
hr = g_pAdoServer->raw_GetRs(_variant_t(strSql), &pDisp);
//g_pAdoServer->GetRs();
m_grdViewAll.SetRefDataSource(pDisp);
}
void CClientFinanceView::OnBtnCancel()
{
// TODO: Add your control notification handler code here
g_pAdoServer->CancelUpdate();
}
void CClientFinanceView::OnBtnFind()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
HRESULT hr;
if(m_strOID == "")
{
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 = "O_ID = '" + m_strOID + "'";
_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 strOID;
strOID = (_bstr_t)g_pAdoServer->Field["O_ID"];
m_fPrice = g_pAdoServer->Field["Money"];
m_blnPay = abs((VARIANT_BOOL)g_pAdoServer->Field["Payment"]);
m_strOID = strOID.c_str();
}
UpdateData(FALSE);
}
void CClientFinanceView::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 strOID;
g_pAdoServer->Last();
strOID = (_bstr_t)g_pAdoServer->Field["O_ID"];
m_fPrice = g_pAdoServer->Field["Money"];
m_blnPay = abs((VARIANT_BOOL)g_pAdoServer->Field["Payment"]);
m_strOID = strOID.c_str();
UpdateData(FALSE);
}
void CClientFinanceView::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 strOID;
strOID = (_bstr_t)g_pAdoServer->Field["O_ID"];
m_fPrice = g_pAdoServer->Field["Money"];
m_blnPay = abs((VARIANT_BOOL)g_pAdoServer->Field["Payment"]);
m_strOID = strOID.c_str();
UpdateData(FALSE);
}
void CClientFinanceView::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 strOID;
strOID = (_bstr_t)g_pAdoServer->Field["O_ID"];
m_fPrice = g_pAdoServer->Field["Money"];
m_blnPay = abs((VARIANT_BOOL)g_pAdoServer->Field["Payment"]);
m_strOID = strOID.c_str();
UpdateData(FALSE);
}
void CClientFinanceView::OnBtnModify()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
if(m_strOID == "")
{
MessageBox("记录的每个字段都不能为空!", NULL, MB_OK);
return;
}
///////////////////////用来生成订单的总金额//////////////////////////////////
g_pAdoServer->get_BookMark(&m_vBookMark); // 当前记录信息
g_pAdoServer->CloseRecordset();
_bstr_t strSql("select * from T_Orders where O_ID = '" + m_strOID + "'");
g_pAdoServer->OpenRecordset(strSql);
long nQuantity;
string strMID;
CString str;
nQuantity = g_pAdoServer->Field["Quantity"];
strMID = (_bstr_t)g_pAdoServer->Field["M_ID"];
str = strMID.c_str();
g_pAdoServer->CloseRecordset();
strSql = "select * from T_Material where M_ID = '" + str + "'";
g_pAdoServer->OpenRecordset(strSql);
double fPrice;
fPrice = g_pAdoServer->Field["Price"];
m_fPrice = nQuantity * fPrice;
g_pAdoServer->CloseRecordset();
g_pAdoServer->OpenRecordset(m_strSql);
g_pAdoServer->put_BookMark(m_vBookMark); // 恢复原始的记录信息
//////////////////////////////////////////////////////////////////////////////
g_pAdoServer->Field["O_ID"] = LPCSTR(m_strOID);
g_pAdoServer->Field["Money"] = m_fPrice;
g_pAdoServer->Field["Payment"] = (VARIANT_BOOL)m_blnPay;
g_pAdoServer->Update();
}
void CClientFinanceView::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 strOID;
g_pAdoServer->First();
strOID = (_bstr_t)g_pAdoServer->Field["O_ID"];
m_fPrice = g_pAdoServer->Field["Money"];
m_blnPay = abs((VARIANT_BOOL)g_pAdoServer->Field["Payment"]);
m_strOID = strOID.c_str();
UpdateData(FALSE);
}
void CClientFinanceView::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 strOID;
strOID = (_bstr_t)g_pAdoServer->Field["O_ID"];
m_fPrice = g_pAdoServer->Field["Money"];
m_blnPay = abs((VARIANT_BOOL)g_pAdoServer->Field["Payment"]);
m_strOID = strOID.c_str();
UpdateData(FALSE);
}
CFormView::OnActivateView(bActivate, pActivateView, pDeactiveView);
}
void CClientFinanceView::OnKillfocusComboOid()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
long nQuantity;
double fPrice;
nQuantity = g_pAdoServer->Field["Quantity"];
fPrice = g_pAdoServer->Field["Price"];
m_fPrice = nQuantity * fPrice;
UpdateData(FALSE);
}
void CClientFinanceView::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())
{
return;
}
strSource = m_strVSql;
strResult = strSource + strSpace + strResult;
_bstr_t strDest(strResult.c_str());
hr = g_pAdoServer->raw_GetRs(_variant_t(strDest), &pDisp);
m_grdViewAll.SetRefDataSource(pDisp);
}
void CClientFinanceView::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 + -