📄 storagedlg.cpp
字号:
// StorageDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Storage.h"
#include "StorageDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CStorageDlg dialog
CStorageDlg::CStorageDlg(CWnd* pParent /*=NULL*/)
: CDialog(CStorageDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CStorageDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CStorageDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CStorageDlg)
DDX_Control(pDX, IDC_LIST2, m_listCtrl2);
DDX_Control(pDX, IDC_LIST1, m_listCtrl1);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CStorageDlg, CDialog)
//{{AFX_MSG_MAP(CStorageDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST1, OnItemchangedList1)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_BTN_COMFIRM, OnBtnComfirm)
ON_BN_CLICKED(IDC_BTN_CANCEL, OnBtnCancel)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CStorageDlg message handlers
BOOL CStorageDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
//定制列表框样式
m_listCtrl1.ModifyStyle(0,LVS_REPORT|LVS_SHOWSELALWAYS|LVS_SINGLESEL);
m_listCtrl1.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES|LVS_EX_HEADERDRAGDROP);
//添加列表框列
m_listCtrl1.InsertColumn(0,"点单编号",LVCFMT_LEFT,70);
m_listCtrl1.InsertColumn(1,"会员昵称",LVCFMT_LEFT,100);
m_listCtrl1.InsertColumn(2,"包间编号",LVCFMT_LEFT,70);
m_listCtrl1.InsertColumn(3,"操作人员",LVCFMT_LEFT,70);
m_listCtrl1.InsertColumn(4,"点单日期",LVCFMT_LEFT,100);
m_listCtrl2.ModifyStyle(0,LVS_REPORT|LVS_SHOWSELALWAYS|LVS_SINGLESEL);
m_listCtrl2.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES|LVS_EX_HEADERDRAGDROP|LVS_EX_CHECKBOXES);
//添加列表框列
m_listCtrl2.InsertColumn(0,"编号",LVCFMT_LEFT,50);
m_listCtrl2.InsertColumn(1,"商品名称",LVCFMT_LEFT,80);
m_listCtrl2.InsertColumn(2,"商品单价",LVCFMT_LEFT,60);
m_listCtrl2.InsertColumn(3,"单位",LVCFMT_LEFT,40);
m_listCtrl2.InsertColumn(4,"数量",LVCFMT_LEFT,40);
Retrieve();
this->SetTimer(1, 20*1000, NULL);
return TRUE; // return TRUE unless you set the focus to a control
}
void CStorageDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CStorageDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CStorageDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CStorageDlg::Retrieve()
{
m_listCtrl1.DeleteAllItems();
_RecordsetPtr m_pRecordset;
m_pRecordset.CreateInstance(__uuidof(Recordset));
CString strSQL;
strSQL.Format("SELECT distinct 会员点单.*,会员.会员昵称 会员昵称 from 会员,会员点单,点单明细 where 会员.会员编号=会员点单.会员编号 and 会员点单.点单编号=点单明细.点单编号 and 点单明细.点单状态=0 order by 点单日期 desc");
// 在ADO操作中建议语句中要常用try...catch()来捕获错误信息,
// 因为它有时会经常出现一些想不到的错误。
try
{
m_pRecordset->Open(_variant_t(strSQL),
((CStorageApp*)AfxGetApp())->m_pConnection.GetInterfacePtr(), // 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error e)
{
AfxMessageBox("数据库连接有误,请检查网络是否中断或者服务器是否正常启动。");
return;
}
int nCount,nItem;
while(!m_pRecordset->adoEOF)
{
nCount = m_listCtrl1.GetItemCount();
nItem = m_listCtrl1.InsertItem(nCount,_T(""));
if(m_pRecordset->GetCollect("点单编号").vt != VT_NULL)
m_listCtrl1.SetItemText(nItem,0,(LPCTSTR)(_bstr_t)(m_pRecordset->GetCollect("点单编号")));
if(m_pRecordset->GetCollect("会员昵称").vt != VT_NULL)
m_listCtrl1.SetItemText(nItem,1,(LPCTSTR)(_bstr_t)(m_pRecordset->GetCollect("会员昵称")));
if(m_pRecordset->GetCollect("包间编号").vt != VT_NULL)
m_listCtrl1.SetItemText(nItem,2,(LPCTSTR)(_bstr_t)(m_pRecordset->GetCollect("包间编号")));
if(m_pRecordset->GetCollect("操作人员").vt != VT_NULL)
m_listCtrl1.SetItemText(nItem,3,(LPCTSTR)(_bstr_t)(m_pRecordset->GetCollect("操作人员")));
if(m_pRecordset->GetCollect("点单日期").vt != VT_NULL)
m_listCtrl1.SetItemText(nItem,4,(LPCTSTR)(_bstr_t)(m_pRecordset->GetCollect("点单日期")));
m_pRecordset->MoveNext();
}
m_pRecordset->Close();
if(m_listCtrl1.GetItemCount() > 0)
{
CString buyGoodsNO = m_listCtrl1.GetItemText(0,0);
strNick = m_listCtrl1.GetItemText(0,1);
RetrieveDetail(buyGoodsNO);
}
else
m_listCtrl2.DeleteAllItems();
}
void CStorageDlg::RetrieveDetail(CString buyGoodsNO)
{
m_listCtrl2.DeleteAllItems();
_RecordsetPtr m_pRecordset;
m_pRecordset.CreateInstance(__uuidof(Recordset));
CString strSQL;
strSQL.Format("SELECT * from 点单明细 where 点单编号=%s and 点单状态=0",buyGoodsNO);
// 在ADO操作中建议语句中要常用try...catch()来捕获错误信息,
// 因为它有时会经常出现一些想不到的错误。
try
{
m_pRecordset->Open(_variant_t(strSQL),
((CStorageApp*)AfxGetApp())->m_pConnection.GetInterfacePtr(), // 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error e)
{
AfxMessageBox("数据库连接有误,请检查网络是否中断或者服务器是否正常启动。");
return;
}
int nCount,nItem;
while(!m_pRecordset->adoEOF)
{
nCount = m_listCtrl2.GetItemCount();
nItem = m_listCtrl2.InsertItem(nCount,_T(""));
if(m_pRecordset->GetCollect("明细编号").vt != VT_NULL)
m_listCtrl2.SetItemText(nItem,0,(LPCTSTR)(_bstr_t)(m_pRecordset->GetCollect("明细编号")));
if(m_pRecordset->GetCollect("商品名称").vt != VT_NULL)
m_listCtrl2.SetItemText(nItem,1,(LPCTSTR)(_bstr_t)(m_pRecordset->GetCollect("商品名称")));
if(m_pRecordset->GetCollect("商品单价").vt != VT_NULL)
m_listCtrl2.SetItemText(nItem,2,(LPCTSTR)(_bstr_t)(m_pRecordset->GetCollect("商品单价")));
if(m_pRecordset->GetCollect("单位").vt != VT_NULL)
m_listCtrl2.SetItemText(nItem,3,(LPCTSTR)(_bstr_t)(m_pRecordset->GetCollect("单位")));
if(m_pRecordset->GetCollect("数量").vt != VT_NULL)
m_listCtrl2.SetItemText(nItem,4,(LPCTSTR)(_bstr_t)(m_pRecordset->GetCollect("数量")));
m_pRecordset->MoveNext();
}
m_pRecordset->Close();
m_pRecordset = NULL;
}
void CStorageDlg::OnItemchangedList1(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
POSITION position = m_listCtrl1.GetFirstSelectedItemPosition();
if(position == NULL) return;
int index = m_listCtrl1.GetNextSelectedItem(position);
CString buyGoodsNO = m_listCtrl1.GetItemText(index,0);
strNick = m_listCtrl1.GetItemText(index,1);
RetrieveDetail(buyGoodsNO);
*pResult = 0;
}
void CStorageDlg::OnOK()
{
// TODO: Add extra validation here
if(AfxMessageBox("您真的要退出点单管理系统吗?",MB_YESNO) == IDNO)
return;
CDialog::OnOK();
}
void CStorageDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
Retrieve();
CDialog::OnTimer(nIDEvent);
}
void CStorageDlg::OnBtnComfirm()
{
// TODO: Add your control notification handler code here
int count = 0;
for(int i=0;i<m_listCtrl2.GetItemCount();i++)
{
if(m_listCtrl2.GetCheck(i)) count++;
}
if(count == 0)
{
AfxMessageBox("请选择点单明细");
return;
}
if(AfxMessageBox("您真的要确认点单明细吗?",MB_YESNO) == IDNO)
return;
for(i=0;i<m_listCtrl2.GetItemCount();i++)
{
if(m_listCtrl2.GetCheck(i))
{
CString detailNO = (m_listCtrl2.GetItemText(i,0));
_RecordsetPtr m_pRecordset;
m_pRecordset.CreateInstance(__uuidof(Recordset));
CString strSQL;
strSQL.Format("SELECT * from 点单明细 where 明细编号=%s",detailNO);
// 在ADO操作中建议语句中要常用try...catch()来捕获错误信息,
// 因为它有时会经常出现一些想不到的错误。
try
{
m_pRecordset->Open(_variant_t(strSQL),
((CStorageApp*)AfxGetApp())->m_pConnection.GetInterfacePtr(), // 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error e)
{
AfxMessageBox("数据库连接有误,请检查网络是否中断或者服务器是否正常启动。");
return;
}
m_pRecordset->PutCollect("点单状态",_variant_t("1"));
m_pRecordset->Update();
m_pRecordset->Close();
}
}
AfxMessageBox("点单确认保存成功!");
Retrieve();
}
void CStorageDlg::OnBtnCancel()
{
// TODO: Add your control notification handler code here
if(((CStorageApp*)AfxGetApp())->USER_RIGHT != 1000 && ((CStorageApp*)AfxGetApp())->USER_RIGHT != 6000)
{
AfxMessageBox("您没有退单特权!");
return;
}
int count = 0;
for(int i=0;i<m_listCtrl2.GetItemCount();i++)
{
if(m_listCtrl2.GetCheck(i)) count++;
}
if(count == 0)
{
AfxMessageBox("请选择点单明细");
return;
}
if(AfxMessageBox("您真的要退单吗?",MB_YESNO) == IDNO)
return;
_RecordsetPtr m_pRecordset;
m_pRecordset.CreateInstance(__uuidof(Recordset));
CString strSQL;
float SumMoney = 0.0;
for(i=0;i<m_listCtrl2.GetItemCount();i++)
{
if(m_listCtrl2.GetCheck(i))
{
CString detailNO = (m_listCtrl2.GetItemText(i,0));
SumMoney += atof(m_listCtrl2.GetItemText(i,2))*atof(m_listCtrl2.GetItemText(i,4));
strSQL.Format("SELECT * from 点单明细 where 明细编号=%s",detailNO);
// 在ADO操作中建议语句中要常用try...catch()来捕获错误信息,
// 因为它有时会经常出现一些想不到的错误。
try
{
m_pRecordset->Open(_variant_t(strSQL),
((CStorageApp*)AfxGetApp())->m_pConnection.GetInterfacePtr(), // 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error e)
{
AfxMessageBox("数据库连接有误,请检查网络是否中断或者服务器是否正常启动。");
return;
}
m_pRecordset->PutCollect("点单状态",_variant_t("2"));
m_pRecordset->Update();
m_pRecordset->Close();
}
}
//退还金额
strSQL.Format("SELECT 金劵余额 FROM 会员 where 会员昵称='%s'",strNick);
// 在ADO操作中建议语句中要常用try...catch()来捕获错误信息,
// 因为它有时会经常出现一些想不到的错误。
try
{
m_pRecordset->Open(_variant_t(strSQL),
((CStorageApp*)AfxGetApp())->m_pConnection.GetInterfacePtr(), // 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error e)
{
AfxMessageBox("数据库连接有误,请检查网络是否中断或者服务器是否正常启动。");
return;
}
CString strBalance1 = (LPCTSTR)(_bstr_t)(m_pRecordset->GetCollect("金劵余额"));
CString str;
str.Format("%f",atof(strBalance1) + SumMoney);
m_pRecordset->PutCollect("金劵余额",_variant_t(str));
AfxMessageBox("退单保存成功!");
Retrieve();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -