⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dlgstorepd3.cpp

📁 仓储管理系统主要提供一个仓储业务及其作业管理的信息存储和检索系统。通过入库管理、出库管理、报表生成管理、仓库人员管理、仓库位置信息管理等功能模块来实现仓库的综合管理
💻 CPP
字号:
// DlgStorePD3.cpp : implementation file
//

#include "stdafx.h"
#include "aaa.h"
#include "DlgStorePD3.h"
#include "CustomGrid.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern _ConnectionPtr m_pCon;  
extern _RecordsetPtr m_pRs; 
extern CAaaApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CDlgStorePD3 dialog


CDlgStorePD3::CDlgStorePD3(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgStorePD3::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlgStorePD3)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CDlgStorePD3::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgStorePD3)
	DDX_Control(pDX, IDC_STORE_PD_PERSON, memo);
	DDX_Control(pDX, IDC_STORE_MARK, checkman);
	DDX_Control(pDX, IDC_DATETIMEPICKER1, checktime);
	DDX_Control(pDX, IDC_COMBO2, checkspec);
	DDX_Control(pDX, IDC_LIST3, listinfo);
	DDX_Control(pDX, IDC_LIST1, list);
	DDX_Control(pDX, IDC_COMBO1, storagename);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgStorePD3, CDialog)
	//{{AFX_MSG_MAP(CDlgStorePD3)
	ON_NOTIFY(NM_DBLCLK, IDC_LIST3, OnDblclkList3)
	ON_NOTIFY(LVN_KEYDOWN, IDC_LIST3, OnKeydownList3)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgStorePD3 message handlers

void CDlgStorePD3::AddStorage()
{
	storagename.ResetContent();
	m_pRs->Close();
	CString sql;
	sql.Format("select storagename from tb_storageinfo");
	m_pRs->Open((_variant_t)sql,m_pCon.GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdText);
	while (! m_pRs->adoEOF)
	{
		storagename.AddString((TCHAR*)(_bstr_t)m_pRs->GetFields()->GetItem((long)0)->Value);
		m_pRs->MoveNext();
	}
}

BOOL CDlgStorePD3::OnInitDialog() 
{
	CDialog::OnInitDialog();
	//添加仓库名称
	AddStorage();
	list.InsertColumn(0,"商品编号");
	list.InsertColumn(1,"商品名称");
	list.InsertColumn(2,"规格");
	list.InsertColumn(3,"数量");

	listinfo.ModifyStyle(LVS_EDITLABELS,0);//禁止编辑标题
	listinfo.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_ONECLICKACTIVATE|LVS_EX_INFOTIP|LVS_EX_SUBITEMIMAGES|LVS_EX_GRIDLINES );
	listinfo.InsertColumn(0,"商品编号");
	listinfo.InsertColumn(1,"商品名称");
	listinfo.InsertColumn(2,"规格");
	listinfo.InsertColumn(3,"助记码");
	listinfo.InsertColumn(4,"默认价格");

	//设置列宽度
	list.SetColumnWidth(0,150);
	list.SetColumnWidth(1,250);
	list.SetColumnWidth(2,80);
	list.SetColumnWidth(3,80);

	listinfo.SetColumnWidth(0,80);
	listinfo.SetColumnWidth(1,100);
	listinfo.SetColumnWidth(2,60);
	listinfo.SetColumnWidth(3,60);
	listinfo.SetColumnWidth(4,60);
	//添加一行
	list.InsertItem(0,"");
	listinfo.SetParent(&list);
	return TRUE;  	              // EXCEPTION: OCX Property Pages should return FALSE
}

BOOL CDlgStorePD3::PreTranslateMessage(MSG* pMsg) 
{
	if (pMsg->message == WM_KEYDOWN)
	{
		if (pMsg->hwnd == list.edit.m_hWnd)
		{
			LimitEdit();
			if (pMsg->wParam == 34)
			{
				ShowListinfo();
			}
			else if (pMsg->wParam ==VK_DELETE)//按delete键删除表格当前行
				DeleteCurRow();
		}
		else if ((pMsg->hwnd ==listinfo.m_hWnd)&&(pMsg->wParam == 13))
		{
			OnDblclkList3(NULL,NULL);
			return true;
		}
		/****************************************************************
		说明:  表格中编辑框获得焦点时,按Enter键控制单元格焦点移动
		****************************************************************/
		if ((pMsg->wParam == 13)&&(pMsg->hwnd==list.edit.m_hWnd))
		{
			MoveFocus();
			return true;
		}
		if (pMsg->wParam==13)
			pMsg->wParam = 9;

	}
	/****************************************************************
	说明:  表格中编辑框改变时的事件
	****************************************************************/
	if ((pMsg->message == WM_KEYUP)&&(pMsg->hwnd == list.edit.m_hWnd))
	{
		EditChange();	
	}
	if (pMsg->message==WM_LBUTTONDOWN)
	{
		if (pMsg->hwnd!= listinfo.m_hWnd)
			listinfo.ShowWindow(SW_HIDE);	
	}
	/****************************************************************
	说明:  在单击表格时,根据当前列判断是否显示编辑框
	****************************************************************/
	if ((pMsg->message ==WM_LBUTTONDOWN)&&(pMsg->hwnd ==list.m_hWnd))
	{
		//当前列为商品编号,商品名称为空,显示编辑框,在当前列为商品名称,商品编号为空,显示编辑框,
		CString tempID,tempname;
		LVHITTESTINFO pos;
		pos.pt.x = LOWORD(pMsg->lParam);
		pos.pt.y = HIWORD(pMsg->lParam);
		pos.flags = LVHT_ABOVE;
		int row,col;
		row = -1;
		col = -1;
		if (list.SubItemHitTest(&pos)>=0)
		{
			list.SetFocus();
			row = pos.iItem;
			col = pos.iSubItem;		
			tempID = list.GetItemText(row,0);
			tempname = list.GetItemText(row,1);			
			list.showedit =true;	
			if ((tempname.IsEmpty()==false)&&(col == 0))
				list.showedit =false;
			else if((tempID.IsEmpty()==false)&&(col == 1))
				list.showedit =false;
		}
	}
	return CDialog::PreTranslateMessage(pMsg);
}

void CDlgStorePD3::OnOK()
{

}

void CDlgStorePD3::OnCancel()
{

}

void CDlgStorePD3::LimitEdit()
{
	list.edit.IsNumber = false;
	//在修改商品数据时只允许输入数字
	if (list.col ==3)
	{
		list.edit.IsNumber = true;
	}
}

void CDlgStorePD3::DeleteCurRow()
{
	int currow;
	currow = list.row;
	if (currow!=-1)
	{
		if (MessageBox("确实要删除当前行吗?","提示",MB_YESNO)==IDYES)
		{
			int m = list.GetItemCount();
			if (m >1)
			{
				for (int i = currow+1;i<list.GetItemCount();i++)
				{
					for(int c = 0; c<7 ;c++)
					{
						list.SetItemText(i-1,c,list.GetItemText(i,c));
					}
				}
				list.DeleteItem(list.GetItemCount()-1);
			}
			else
			{
				for (int i = 0;i< 7;i++)
				{
					list.SetItemText(0,i,"");
				}
			}
		}
	}
}

void CDlgStorePD3::EditChange()
{
	CString str;
	list.edit.GetWindowText(str);
		CString sql = "";
		switch (list.col)
		{
		case 0 : 
			{
				if (!str.IsEmpty())
					sql.Format("select * from tb_merchandiseinfo where id like '%s%%' or shortname like '%s%%' ",str,str);
				break;
			}
		case 1 : 
			{
				if (!str.IsEmpty())
					sql.Format("select * from tb_merchandiseinfo where name like '%s%%' or shortname like '%s%%'",str,str);
				break;
			}
		default:
			break;
		}
		if (! sql.IsEmpty())
		{
			m_pRs->raw_Close();
			m_pRs->Open((_bstr_t)sql,m_pCon.GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdText);
			if (m_pRs->RecordCount>0)
			{
				listinfo.DeleteAllItems();
				int i=0;
				while(! m_pRs->adoEOF)
				{
					listinfo.InsertItem(100,"");
					for (int m = 0;m<5;m++)
					listinfo.SetItemText(i,m,(TCHAR*)(_bstr_t)m_pRs->GetFields()->GetItem((long)m)->Value);
					m_pRs->MoveNext();
					i +=1;
				}
				ShowListInfo();
			}
			else
				listinfo.ShowWindow(SW_HIDE);
		}
		else
			listinfo.ShowWindow(SW_HIDE);
}

void CDlgStorePD3::ShowListInfo()
{
	CRect rect;
	list.GetSubItemRect(list.row,list.col,LVIR_BOUNDS,rect);
	listinfo.MoveWindow(rect.left,rect.bottom+1,300,150);
	listinfo.ShowWindow(SW_SHOW);
}

void CDlgStorePD3::OnDblclkList3(NMHDR* pNMHDR, LRESULT* pResult) 
{
	int row = listinfo.GetSelectionMark();
	if (row!=-1)
	{
		CString temp;
		temp = listinfo.GetItemText(row,0);
		//设置商品编号
		list.SetItemText(list.row,0,temp);
		//设置商品名称
		list.SetItemText(list.row,1,listinfo.GetItemText(row,1));
		list.SetItemText(list.row,2,listinfo.GetItemText(row,2));
		listinfo.ShowWindow(SW_HIDE);
	}

	//移动编辑框
	//MoveFocus();
	list.col =3;
	list.ShowEdit();	
	//*pResult = 0;
}

void CDlgStorePD3::OnKeydownList3(NMHDR* pNMHDR, LRESULT* pResult) 
{
	LV_KEYDOWN* pLVKeyDow = (LV_KEYDOWN*)pNMHDR;
	// TODO: Add your control notification handler code here
	
	*pResult = 0;
}

void CDlgStorePD3::MoveFocus()
{
	list.DisposeEdit(true);
	if (list.col <4)
	{
		list.col = list.col+1;
		CString tempID,tempname;
		tempID = list.GetItemText(list.row,0);
		tempname = list.GetItemText(list.row,1);
		list.showedit = true;
		if ((tempname.IsEmpty()==false)&&(list.col == 0))
			list.showedit =false;
		else if((tempID.IsEmpty()==false)&&(list.col == 1))
			list.showedit =false;
		list.ShowEdit();
	}
	else
	{
		AddNewRow();
	}
}

void CDlgStorePD3::AddNewRow()
{
	int counts = list.GetItemCount();
	if (list.row == counts-1)//当前行为最后一行
	{
		list.InsertItem(100,"");
		list.row+=1;			
		list.col = 0;
		list.ShowEdit();
	}
	else
	{
		list.row+=1;
		list.col = 0;
		list.ShowEdit();
	}
}

void CDlgStorePD3::ShowListinfo()
{
	if (listinfo.IsWindowVisible())
	{
		listinfo.SetFocus();
		listinfo.SetSelectionMark(1);
	}
}

bool CDlgStorePD3::InfoIsNull(int main)
{
	if (main ==0)
	{
		CString c_storage,c_checkspec,c_checkman,c_memo;
		storagename.GetWindowText(c_storage);
		checkspec.GetWindowText(c_checkspec);
		checkman.GetWindowText(c_checkman);
		memo.GetWindowText(c_memo);
		if (c_storage.IsEmpty()||c_checkspec.IsEmpty()||c_checkman.IsEmpty()||c_memo.IsEmpty())
			return true;
	}
	else if (main ==1)
	{
		int rowcount = list.GetItemCount();
		if (rowcount ==-1)
			return true;
		for (int r = 0;r <rowcount;r++)
			for (int i = 0;i<4;i++)
			{
				CString temp;
				temp = list.GetItemText(r,i);
				if (temp.IsEmpty()==true)
					return true;
			}	
	}
	return false;
}

void CDlgStorePD3::CheckOporate()
{
	if (InfoIsNull(0))
	{
		MessageBox("盘点信息不能为空.","提示",64);
		return;
	}
	if (InfoIsNull(1))
	{
		MessageBox("商品信息不能为空.","提示",64);
		return;
	}
	CString c_storage,c_checkspec,c_checkman,c_memo,c_time;
	CString c_mercandiseid,c_num;
	float f_num;

	int spec;
	spec = checkspec.GetCurSel(); //0报损 1 报溢

	storagename.GetWindowText(c_storage);
	checkspec.GetWindowText(c_checkspec);
	checkman.GetWindowText(c_checkman);
	memo.GetWindowText(c_memo);
	CTime temp;
	checktime.GetTime(temp);
	c_time = temp.Format("%Y-%m-%d");
	CString sql;
	sql.Format("sp_check '%s','%s','%s',%i,'%s','%s'",c_storage,c_checkman,c_time,spec,c_memo,"temp");
	try
	{
		m_pRs->raw_Close();
		m_pRs->Open((_variant_t)sql,m_pCon.GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdUnknown);
		CString id ;//记录盘点单号
		id =(TCHAR*)(_bstr_t) m_pRs->GetFields()->GetItem("tempid")->Value;
		int row = 0;
		int rows = list.GetItemCount();
		for (int i = 0;i<rows;i++)
		{
			c_mercandiseid = list.GetItemText(row,0);
			c_num = list.GetItemText(row,3);
			f_num = atof(c_num);

			sql.Format("insert into tb_check_sub values ('%s','%s',%f)",id,c_mercandiseid,f_num);
			m_pRs->raw_Close();
			
			m_pRs->Open((_variant_t)sql,m_pCon.GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdText);

			//修改商品库存
			if (spec == 0)//报损
			{
				sql.Format("update tb_merchandisestorage set storagenum = storagenum - %f where merchandiseid = '%s' and storagename = '%s'",f_num,c_mercandiseid,c_storage);
			}
			else //报溢
			{
				sql.Format("update tb_merchandisestorage set storagenum = storagenum + %f where merchandiseid = '%s' and storagename = '%s'",f_num,c_mercandiseid,c_storage);
			}
			m_pRs->raw_Close();
			m_pRs->Open((_variant_t)sql,m_pCon.GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdText);
			row +=1;
		}
		CancelOperate();
		MessageBox("操作成功,票号为 "+id,"提示",64);

	}
	catch(_com_error)
	{
		MessageBox("操作失败","提示",64);
	}
}



void CDlgStorePD3::CancelOperate()
{
	list.DeleteAllItems();
	list.InsertItem(0,"");
	storagename.SetCurSel(-1);
	checkspec.SetCurSel(-1);
	CTime time = CTime::GetCurrentTime();
	checktime.SetTime(&time);
	checkman.SetWindowText("");
	memo.SetWindowText("");
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -