📄 marketmanagerview.cpp
字号:
// MarketManagerView.cpp : implementation of the CMarketManagerView class
//
#include "stdafx.h"
#include "MarketManager.h"
#include "MarketManagerDoc.h"
#include "MarketManagerView.h"
/////////////////////////////////
//peter statements
#include "MainFrm.h"
#include "LoginDialog.h"
#include "AddGoodsDlg.h"
#include "DeleteGoodsDlg.h"
#include "PersonSystemDlg.h"
#include "StatDlg.h"
#include "SaleDlg.h"
extern CMarketManagerApp theApp;
//peter statements
//////////////////////////////////
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMarketManagerView
IMPLEMENT_DYNCREATE(CMarketManagerView, CListView)
BEGIN_MESSAGE_MAP(CMarketManagerView, CListView)
//{{AFX_MSG_MAP(CMarketManagerView)
ON_NOTIFY_REFLECT(NM_DBLCLK, OnDblclk)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CListView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CListView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CListView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMarketManagerView construction/destruction
CMarketManagerView::CMarketManagerView()
{
// TODO: add construction code here
}
CMarketManagerView::~CMarketManagerView()
{
}
BOOL CMarketManagerView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
//////////////////////////////////////////////////////////////////////////////
//peter statements
cs.style|=LVS_REPORT|LVS_SINGLESEL;
//peter statements
//////////////////////////////////////////////////////////////////////////////
return CListView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMarketManagerView drawing
void CMarketManagerView::OnDraw(CDC* pDC)
{
CMarketManagerDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
void CMarketManagerView::OnInitialUpdate()
{
//////////////////////////////////////////////////////////////////////////////
//peter statements
CListCtrl * ctrl;
// long oldstyle,newstyle;
ctrl=&GetListCtrl();
ctrl->SetTextColor(RGB(0,0,255));
// newstyle=LVS_REPORT|LVS_SHOWSELALWAYS|LVS_EDITLABELS;
// oldstyle=GetWindowLong(ctrl->m_hWnd,GWL_STYLE);
// oldstyle&=~(LVS_TYPEMASK);
// oldstyle|=newstyle;
// SetWindowLong(ctrl->m_hWnd,GWL_STYLE,oldstyle);
ctrl->InsertColumn(0,"货物编号",LVCFMT_LEFT,100);
ctrl->InsertColumn(1,"货物名称",LVCFMT_LEFT,100);
ctrl->InsertColumn(2,"库存量",LVCFMT_LEFT,80);
ctrl->InsertColumn(3,"单价",LVCFMT_LEFT,60);
m_pRecordset.CreateInstance(__uuidof(Recordset));
m_bManager=false;
m_Date.Empty();
CMainFrame *pFrame=(CMainFrame *)::AfxGetMainWnd();
pFrame->m_pListView=this;
//peter statements
//////////////////////////////////////////////////////////////////////////////
CListView::OnInitialUpdate();
// TODO: You may populate your ListView with items by directly accessing
// its list control through a call to GetListCtrl().
}
/////////////////////////////////////////////////////////////////////////////
// CMarketManagerView printing
BOOL CMarketManagerView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMarketManagerView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMarketManagerView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CMarketManagerView diagnostics
#ifdef _DEBUG
void CMarketManagerView::AssertValid() const
{
CListView::AssertValid();
}
void CMarketManagerView::Dump(CDumpContext& dc) const
{
CListView::Dump(dc);
}
CMarketManagerDoc* CMarketManagerView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMarketManagerDoc)));
return (CMarketManagerDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMarketManagerView message handlers
void CMarketManagerView::SysLogin()
{
CLoginDialog dlg;
CString str;
CString Date;
if(!m_Date.IsEmpty())
{
MessageBox("每次只允许一个用户登陆!\n请先退出系统!","系统提示",MB_OK|MB_ICONSTOP);
return;
}
//弹出登陆界面
if(dlg.DoModal()==IDOK)
{
UpdateData();
Date=dlg.m_time;//暂时保存登陆时间
str.Format("select * from Person where person_no=\'%s\' and person_code=\'%s\'",dlg.m_uid,dlg.m_code);
try
{
//打开人事纪录表
m_pRecordset->Open(str.AllocSysString(),theApp.m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
if(m_pRecordset->BOF)
AfxMessageBox("用户不存在或密码错误!\n请确认输入!");
else
{
_variant_t var;
CString LoginInfo;
int limit;
//判断登陆者的身份:limit=0 为管理员
var=m_pRecordset->GetCollect("person_limit");
if(var.vt!=VT_NULL)
limit=var.intVal;
if(limit==0)
m_bManager=true;
else
m_bManager=false;
//组成欢迎信息
var=m_pRecordset->GetCollect("person_name");
if(var.vt!=VT_NULL)
LoginInfo=(LPCSTR)_bstr_t(var);
LoginInfo.TrimRight(" ");
LoginInfo+=" 登陆系统!";
MessageBox(LoginInfo,"系统提示",MB_OK|MB_ICONINFORMATION);
if(m_bManager==true)
MessageBox("您现在以管理员身份登陆","系统提示",MB_OK|MB_ICONINFORMATION);
m_Date=Date;//保存登陆日期,即有人登陆系统
}
m_pRecordset->Close();//关闭表
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
}
}
void CMarketManagerView::SysLogout()
{
CListCtrl *ctrl;
if(m_Date.IsEmpty())
{
MessageBox("用户尚未登陆","系统提示",MB_OK|MB_ICONINFORMATION);
return;
}
//清除仓储纪录列表
ctrl=&GetListCtrl();
ctrl->DeleteAllItems();
//清除登陆日期,即用户退出
m_Date.Empty();
MessageBox("用户退出系统","系统提示",MB_OK|MB_ICONINFORMATION);
}
void CMarketManagerView::GoodsList()
{
int i=0;
CString str,tmp;
_variant_t var;
CListCtrl *ctrl;
if(m_Date.IsEmpty())
{
MessageBox("尚未登陆系统!","系统提示",MB_OK|MB_ICONSTOP);
return;
}
if(m_bManager==false)
{
MessageBox("权限不够!","系统提示",MB_OK|MB_ICONSTOP);
return;
}
ctrl=&GetListCtrl();
str.Format("select * from Goods order by goods_quantity desc");
ClearList();
try
{
//打开货物纪录表
m_pRecordset->Open(str.AllocSysString(),theApp.m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
if(m_pRecordset->BOF)
AfxMessageBox("仓储纪录已被清空!");
else
{
m_pRecordset->MoveFirst();
while(!m_pRecordset->adoEOF)
{//循环遍历数据库,显示输出
var=m_pRecordset->GetCollect("goods_no");
tmp=(LPCSTR)_bstr_t(var);
ctrl->InsertItem(i,tmp);
var=m_pRecordset->GetCollect("goods_name");
tmp=(LPCSTR)_bstr_t(var);
ctrl->SetItemText(i,1,tmp);
var=m_pRecordset->GetCollect("goods_quantity");
tmp.Format("%d",var.intVal);
ctrl->SetItemText(i,2,tmp);
var=m_pRecordset->GetCollect("goods_price");
tmp.Format("%d",var.intVal);
ctrl->SetItemText(i,3,tmp);
i++;
m_pRecordset->MoveNext();
}
}
m_pRecordset->Close();//关闭数据库
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
}
void CMarketManagerView::ClearList()
{//清除货物纪录显示
CListCtrl *ctrl;
ctrl=&GetListCtrl();
ctrl->DeleteAllItems();
}
bool CMarketManagerView::GoodsAdd()
{
CAddGoodsDlg dlg;
CString str;
CString gno,gname;
_variant_t var;
bool rn=false;
bool iscopy=false;
int gquantity,gprice;
if(m_Date.IsEmpty())
{
MessageBox("尚未登陆系统!","系统提示",MB_OK|MB_ICONSTOP);
return false;
}
if(m_bManager==false)
{
MessageBox("权限不够!","系统提示",MB_OK|MB_ICONSTOP);
return false;
}
str.Format("select * from Goods");
dlg.m_title.Format("添加仓储纪录");
if(dlg.DoModal()==IDOK)
{
UpdateData();
gno=dlg.m_no;
gname=dlg.m_name;
gquantity=dlg.m_quantity;
gprice=dlg.m_price;
//检查输入信息有效性:编号&货物名称非空
if(gno.IsEmpty()||gname.IsEmpty())
{
MessageBox("货物信息错误\n请确认输入","系统提示",MB_OK|MB_ICONINFORMATION);
return false;
}
try
{ //打开货物记录表
m_pRecordset->Open(str.AllocSysString(),theApp.m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
if(!m_pRecordset->BOF)
{
//循环遍历数据库,保证编号唯一
m_pRecordset->MoveFirst();
while(!m_pRecordset->adoEOF&&!iscopy)
{
var=m_pRecordset->GetCollect("goods_no");
str=(LPCSTR)_bstr_t(var);
str.TrimRight(" ");
if(str==gno)
{
MessageBox("货物编号重复!\n不能添加!","系统提示",MB_OK|MB_ICONSTOP);
iscopy=true;
}
m_pRecordset->MoveNext();
}
if(iscopy==false)
{//加入新的货物纪录
m_pRecordset->AddNew();
m_pRecordset->PutCollect("goods_no",_variant_t(gno));
m_pRecordset->PutCollect("goods_name",_variant_t(gname));
var.iVal=gquantity;
m_pRecordset->PutCollect("goods_quantity",var.iVal);
var.iVal=gprice;
m_pRecordset->PutCollect("goods_price",var.iVal);
m_pRecordset->Update();
m_pRecordset->MoveLast();
MessageBox("新货物纪录添加成功","系统提示",MB_OK|MB_ICONINFORMATION);
rn=true;
}
}
else
{//对空表直接加入第一个记录
m_pRecordset->AddNew();
m_pRecordset->PutCollect("goods_no",_variant_t(gno));
m_pRecordset->PutCollect("goods_name",_variant_t(gname));
var.iVal=gquantity;
m_pRecordset->PutCollect("goods_quantity",var.iVal);
var.iVal=gprice;
m_pRecordset->PutCollect("goods_price",var.iVal);
m_pRecordset->Update();
m_pRecordset->MoveLast();
MessageBox("新货物纪录添加成功","系统提示",MB_OK|MB_ICONINFORMATION);
rn=true;
}
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
m_pRecordset->Close();
}
return rn;
}
bool CMarketManagerView::GoodsDelete()
{
_variant_t var;
CString str,no;
bool rn=false;
bool isexist=false;
CDeleteGoodsDlg dlg;
if(m_Date.IsEmpty())
{
MessageBox("尚未登陆系统!","系统提示",MB_OK|MB_ICONSTOP);
return false;
}
if(m_bManager==false)
{
MessageBox("权限不够!","系统提示",MB_OK|MB_ICONSTOP);
return false;
}
dlg.m_title.Format("删除仓储纪录");
if(dlg.DoModal()==IDOK)
{
UpdateData();
no=dlg.m_no;
str.Format("select * from Goods");
try
{
//打开货物纪录表
m_pRecordset->Open(str.AllocSysString(),theApp.m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
if(!m_pRecordset->BOF)
{
//循环遍历Database,查找指定删除的纪录
m_pRecordset->MoveFirst();
while(!isexist&&!m_pRecordset->adoEOF)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -