📄 dlgproductquery.cpp
字号:
// DlgProductQuery.cpp : implementation file
//
#include "stdafx.h"
#include "Manage_WH.h"
#include "DlgProductQuery.h"
#include "DlgPreparent.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDlgProductQuery dialog
CDlgProductQuery::CDlgProductQuery(CWnd* pParent /*=NULL*/)
: CDialog(CDlgProductQuery::IDD, pParent)
{
//{{AFX_DATA_INIT(CDlgProductQuery)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_hIcon = AfxGetApp()->LoadIcon(IDI_MYICON);
}
void CDlgProductQuery::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgProductQuery)
DDX_Control(pDX, IDC_LIST_FROM, m_listFrom);
DDX_Control(pDX, IDC_LIST_MAIN, m_listMain);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDlgProductQuery, CDialog)
//{{AFX_MSG_MAP(CDlgProductQuery)
ON_CBN_SELCHANGE(IDC_FIELDS, OnSelchangeFields)
ON_BN_CLICKED(IDC_SEARCH, OnSearch)
ON_NOTIFY(NM_DBLCLK, IDC_LIST_MAIN, OnDblclkListMain)
ON_BN_CLICKED(IDC_PRINT, OnPrint)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDlgProductQuery message handlers
BOOL CDlgProductQuery::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message==WM_KEYDOWN && (pMsg->wParam==13 || pMsg->wParam==27))
return TRUE;
return CDialog::PreTranslateMessage(pMsg);
}
BOOL CDlgProductQuery::OnInitDialog()
{
CDialog::OnInitDialog();
SetIcon(m_hIcon,TRUE);
m_listMain.InsertColumn(0,"商品编码",LVCFMT_LEFT,100,-1);
m_listMain.InsertColumn(1,"商品名称",LVCFMT_LEFT,100,-1);
m_listMain.InsertColumn(2,"商品规格",LVCFMT_LEFT,100,-1);
m_listMain.InsertColumn(3,"商品颜色",LVCFMT_LEFT,100,-1);
m_listMain.InsertColumn(4,"商品价格(RMB)",LVCFMT_LEFT,120,-1);
m_listMain.InsertColumn(5,"商品重量(KG)",LVCFMT_LEFT,120,-1);
m_listMain.InsertColumn(6,"计量单位",LVCFMT_LEFT,100,-1);
m_listMain.InsertColumn(7,"供应商",LVCFMT_LEFT,120,-1);
m_listMain.InsertColumn(8,"库存数量",LVCFMT_LEFT,100,-1);
m_listMain.SetExtendedStyle( LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT);
m_listFrom.InsertColumn(0,"条形码",LVCFMT_LEFT,120,-1);
m_listFrom.InsertColumn(1,"商品名称",LVCFMT_LEFT,100,-1);
m_listFrom.InsertColumn(2,"托盘索引",LVCFMT_LEFT,120,-1);
m_listFrom.InsertColumn(3,"货位索引",LVCFMT_LEFT,120,-1);
m_listFrom.InsertColumn(4,"所属货区",LVCFMT_LEFT,120,-1);
m_listFrom.SetExtendedStyle(LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT);
return TRUE;
}
void CDlgProductQuery::OnSelchangeFields()
{
switch(static_cast<CComboBox *>(GetDlgItem(IDC_FIELDS))->GetCurSel())
{
case 0:m_sField = "F_Name"; break;
case 1:m_sField = "F_Index"; break;
case 2:m_sField = "F_Spec"; break;
case 3:m_sField = "F_Supplier"; break;
case 4:m_sField = "All"; break;
}
if (m_sField == "All")
static_cast<CButton *>(GetDlgItem(IDC_SEARCH))->SetFocus();
else
static_cast<CEdit *>(GetDlgItem(IDC_CONDITION))->SetFocus();
}
void CDlgProductQuery::OnSearch()
{
CAdoConnection cn;
CAdoRecordSet rs;
CString sField,sCondition,sSQL;
static_cast<CEdit *>(GetDlgItem(IDC_CONDITION))->GetWindowText(sCondition);
static_cast<CComboBox *>(GetDlgItem(IDC_FIELDS))->GetWindowText(sField);
if (sField.IsEmpty() || (m_sField != "All" && sCondition.IsEmpty())) return;
if (m_sField == "All")
sSQL = "select F_Index,F_Name,F_Spec,F_Color,F_Price,F_Weight,F_Unit,F_Supplier from V_GoodsStock";
else
sSQL.Format("select F_Index,F_Name,F_Spec,F_Color,F_Price,F_Weight,F_Unit,F_Supplier from V_GoodsStock where %s = '%s'",m_sField,sCondition);
cn.OpenUDLFile(gstrConSQLSer);
rs.SetAdoConnection(&cn);
rs.Open(sSQL,adCmdText);
if (rs.GetRecordCount() > 0)
{
rs.MoveFirst();
int row = 0,iVal = 0;
CString sVal;
m_listMain.DeleteAllItems();
while (!rs.IsEOF())
{
row = m_listMain.InsertItem(row,"");
for (int i=0;i<8;i++)
{
rs.GetCollect(i,sVal);
m_listMain.SetItemText(row,i,sVal);
}
row++;
rs.MoveNext();
}
}
rs.Close();
int iKind=0,bz=0,iSum,iNum=0,iSortNum;
CString sSum;
for (int i=0;i<m_listMain.GetItemCount();i++)
{
rs.Open("select * from V_GoodsStock where F_Index='"+m_listMain.GetItemText(i,0)+"'",adCmdText);
rs.MoveFirst();
rs.GetCollect("F_Kind",iKind);
rs.Close();
iSum = iSortNum = 0;
sSQL.Format("select * from T_Goods_Site_Manage where F_GoodsKind=%d and F_SiteState!=2",iKind);
rs.Open(sSQL,adCmdText);
if (rs.GetRecordCount() > 0)
{
bz = 1;
rs.MoveFirst();
while (!rs.IsEOF())
{
rs.GetCollect("F_GoodsCount",iNum);
iSum += iNum;
rs.MoveNext();
}
}
rs.Close();
if (bz == 1)
{
sSQL.Format("select * from T_Manager_Task where F_TaskState=0 and F_GoodsKind=%d and (F_TaskKind=2 or F_TaskKind=3 or F_TaskKind=5)",iKind);
rs.Open(sSQL,adCmdText);
if (rs.GetRecordCount() != 0)
{
rs.MoveFirst();
while (!rs.IsEOF())
{
rs.GetCollect("F_SortCount",iNum);
iSortNum += iNum;
rs.MoveNext();
}
}
rs.Close();
}
iSum = iSum - iSortNum;
sSum.Format("%d",iSum);
m_listMain.SetItemText(i,8,sSum);
}
cn.Close();
}
void CDlgProductQuery::OnDblclkListMain(NMHDR* pNMHDR, LRESULT* pResult)
{
m_listFrom.DeleteAllItems();
for (int i=0;i<m_listMain.GetItemCount();i++)
{
if (m_listMain.GetItemState(i,LVIS_SELECTED) == LVIS_SELECTED)
{
CString sName,sSQL,sSiteIndex,sTrayIndex,sGoodsIndex,sArea;
sName = m_listMain.GetItemText(i,1);
int iGoodsKind;
iGoodsKind = gfGetGoodsKind(sName);
CAdoConnection cn;
CAdoRecordSet rs;
cn.OpenUDLFile(gstrConSQLSer);
rs.SetAdoConnection(&cn);
sSQL.Format("select * from T_Goods_Site_Manage where F_GoodsKind = %d",iGoodsKind);
rs.Open(sSQL,adCmdText);
if (rs.GetRecordCount() != 0)
{
rs.MoveFirst();
CString s,sCode;
int row = 0,iArea = 0;
while (!rs.IsEOF())
{
rs.GetCollect("F_SiteIndex",sSiteIndex);
rs.GetCollect("F_TrayIndex",sTrayIndex);
rs.GetCollect("F_OfArea",iArea);
sArea.Format("%d",iArea);
for (int j=1;j<=8;j++)
{
row = m_listFrom.InsertItem(row,"");
s.Format("%d",j);
s = "F_Index"+s+"";
rs.GetCollect(s,sCode);
if (!sCode.IsEmpty())
{
m_listFrom.SetItemText(row,0,sCode);
m_listFrom.SetItemText(row,1,sName);
m_listFrom.SetItemText(row,2,sTrayIndex);
m_listFrom.SetItemText(row,3,sSiteIndex);
m_listFrom.SetItemText(row,4,sArea);
}
row++;
}
rs.MoveNext();
}
}
rs.Close();
cn.Close();
for (int j=0; j<m_listFrom.GetItemCount(); j++)
{
sArea = gfGetAreaName(atoi(m_listFrom.GetItemText(j,4)));
m_listFrom.SetItemText(j,4,sArea);
}
break;
}
}
*pResult = 0;
}
void CDlgProductQuery::OnPrint()
{
if(m_listMain.GetItemCount()<= 0)
return;
PRNINFO PrnInfo = {0};
PrnInfo.hListView = m_listMain.m_hWnd;
PrnInfo.hWnd = this->m_hWnd;
PrnInfo.IsPrint = FALSE;
PrnInfo.nCurPage = 1;
PrnInfo.nMaxLine = m_listMain.GetItemCount();
CDlgPreparent DlgPreView;
DlgPreView.SetCallBackFun(DrawInfo, PrnInfo);
DlgPreView.DoModal();
}
void CDlgProductQuery::DrawInfo(CDC &memDC, PRNINFO PrnInfo)
{
if(memDC.m_hDC == NULL)
return;
int nCurPage = PrnInfo.nCurPage; //当前页
BOOL IsPrint = PrnInfo.IsPrint; //是否打印
int nMaxPage = PrnInfo.nCountPage; //最大页码
HWND hWnd = PrnInfo.hWnd;
HWND hList = PrnInfo.hListView;
CString csLFinality, csRFinality;
CTime time;
time=CTime::GetCurrentTime();
csLFinality = time.Format("报表日期:%Y年%m月%d日");
csRFinality.Format("第 %i 页/共 %i 页", nCurPage, nMaxPage);
TCHAR szTitle[] = TEXT("库存商品报表");
CRect rc, rt1, rt2, rt3, rt4, rt5, rt6, rt7, rt8, rt9;
CPen *hPenOld;
CPen cPen;
CFont TitleFont, DetailFont, *oldfont;
//标题字体
TitleFont.CreateFont(-MulDiv(14,memDC.GetDeviceCaps(LOGPIXELSY),72),
0,0,0,FW_NORMAL,0,0,0,GB2312_CHARSET,
OUT_STROKE_PRECIS,CLIP_STROKE_PRECIS,DRAFT_QUALITY,
VARIABLE_PITCH|FF_SWISS,_T("黑体"));
//细节字体
DetailFont.CreateFont(-MulDiv(10,memDC.GetDeviceCaps(LOGPIXELSY),72),
0,0,0,FW_NORMAL,0,0,0,GB2312_CHARSET,
OUT_STROKE_PRECIS,CLIP_STROKE_PRECIS,DRAFT_QUALITY,
VARIABLE_PITCH|FF_SWISS,_T("宋体"));
//粗笔
cPen.CreatePen(PS_SOLID, 2, RGB(0, 0, 0));
int xP = GetDeviceCaps(memDC.m_hDC, LOGPIXELSX); //x方向每英寸像素点数
int yP = GetDeviceCaps(memDC.m_hDC, LOGPIXELSY); //y方向每英寸像素点数
DOUBLE xPix = (DOUBLE)xP*10/254; //每 mm 宽度的像素
DOUBLE yPix = (DOUBLE)yP*10/254; //每 mm 高度的像素
DOUBLE fAdd = 7*yPix; //每格递增量
DOUBLE nTop = 25*yPix; //第一页最上线
int iStart = 0; //从第几行开始读取
DOUBLE nBottom = nTop+A4_ONELINE*fAdd;
if(nCurPage != 1)
nTop = 25*yPix-fAdd; //非第一页最上线
if(nCurPage == 2)
iStart = A4_ONELINE;
if(nCurPage>2)
iStart = A4_ONELINE+(nCurPage - 2)*A4_OTHERLINE;
DOUBLE nLeft = 10*xPix; //最左线
DOUBLE nRight = xPix*(A4_W-10); //最右线
DOUBLE nTextAdd = 1.5*xPix;
if(IsPrint)
{
//真正打印部分
static DOCINFO di = {sizeof (DOCINFO), szTitle} ;
//开始文档打印
if(memDC.StartDoc(&di)<0)
{
::MessageBox(hWnd, "连接到打印机化败!", "错误", MB_ICONSTOP);
}
else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -