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

📄 dlgstoreadjust3.cpp

📁 主要功能 企业仓库管理系统由基本信息管理模块、入库管理模块、库存管理模块、查询管理模块等几部分组成。 &#61553 基本信息管理模块 该模块主要包括操作员管理、商品信息管理、库存信息管理、供
💻 CPP
字号:
// DlgStoreAdjust3.cpp : implementation file
//

#include "stdafx.h"
#include "aaa.h"
#include "DlgStoreAdjust3.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;

/////////////////////////////////////////////////////////////////////////////
// CDlgStoreAdjust3 dialog


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


void CDlgStoreAdjust3::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgStoreAdjust3)
	DDX_Control(pDX, IDC_LIST1, m_listinfo);
	DDX_Control(pDX, IDC_DETAILLIST, m_list);
	DDX_Control(pDX, IDC_COMTOSTORAGE, m_tostorage);
	DDX_Control(pDX, IDC_COMFROMSTORAGE, m_fromstorage);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgStoreAdjust3, CDialog)
	//{{AFX_MSG_MAP(CDlgStoreAdjust3)
	ON_NOTIFY(NM_DBLCLK, IDC_LIST1, OnDblclkList1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgStoreAdjust3 message handlers

BOOL CDlgStoreAdjust3::OnInitDialog() 
{
	CDialog::OnInitDialog();
	//添加列
	m_list.InsertColumn(0,"商品编号",LVCFMT_LEFT,200);
	m_list.InsertColumn(1,"商品名称",LVCFMT_LEFT,180);
	m_list.InsertColumn(2,"商品数量",LVCFMT_LEFT,80);

	m_listinfo.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES|LVS_EX_FLATSB);

	m_listinfo.InsertColumn(0,"商品编号",LVCFMT_LEFT,80);
	m_listinfo.InsertColumn(1,"商品名称",LVCFMT_LEFT,80);
	m_listinfo.InsertColumn(2,"规格",LVCFMT_LEFT,80);
	m_listinfo.InsertColumn(4,"助记码",LVCFMT_LEFT,80);

	//添加空行
	m_list.InsertItem(0,"");

	m_listinfo.SetParent(&m_list);

	AddStorage();
	return TRUE; 
}

BOOL CDlgStoreAdjust3::PreTranslateMessage(MSG* pMsg) 
{
	if (pMsg->message ==WM_KEYDOWN)	
	{
		 if ((pMsg->hwnd ==m_listinfo.m_hWnd)&&(pMsg->wParam == 13))
		{
			OnDblclkList1(NULL,NULL);
			return true;
		}
		/****************************************************************
		说明:  表格中编辑框获得焦点时,按Enter键控制单元格焦点移动
		****************************************************************/
		if ((pMsg->wParam == 13)&&(pMsg->hwnd==m_list.edit.m_hWnd))
		{
			MoveFocus();
			return true;
		}	
		/****************************************************************
		说明:  表格中获得焦点时,按Enter键添加新行
		****************************************************************/		
		if ((pMsg->wParam == 13)&&(pMsg->hwnd == m_list.m_hWnd))
		{
			AddNewRow();
			return true;
		}
	}

	/****************************************************************
	说明:  表格中编辑框按键时的事件,用于判断是否限制字符输入,如果用户按
	PageDown键,将使辅助录入表格获得焦点
	****************************************************************/
	if ((pMsg->message == WM_KEYDOWN)&&(pMsg->hwnd == m_list.edit.m_hWnd))
	{
		LimitEdit();	
		if (pMsg->wParam == 34)
		{
			ShowListinfo();
		}
		else if (pMsg->wParam ==VK_DELETE)//按delete键删除表格当前行
			DeleteCurRow();
	}	

	/****************************************************************
	说明:  表格中编辑框改变时的事件
	****************************************************************/
	if ((pMsg->message == WM_KEYUP)&&(pMsg->hwnd == m_list.edit.m_hWnd))
	{
		OnEditChange();	
	}

	/****************************************************************
	说明:  在窗体中控件获得焦点时,使提示列表不可见
	****************************************************************/
	if (pMsg->message==WM_LBUTTONDOWN)
	{
		if (pMsg->hwnd!= m_listinfo.m_hWnd)
			m_listinfo.ShowWindow(SW_HIDE);
	}	
	/****************************************************************
	说明:  在单击表格时,根据当前列判断是否显示编辑框
	****************************************************************/
	if ((pMsg->message ==WM_LBUTTONDOWN)&&(pMsg->hwnd ==m_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 (m_list.SubItemHitTest(&pos)>=0)
		{
			m_list.SetFocus();
			row = pos.iItem;
			col = pos.iSubItem;		
			tempID = m_list.GetItemText(row,0);
			tempname = m_list.GetItemText(row,1);			
			m_list.showedit =true;	
			if ((tempname.IsEmpty()==false)&&(col == 0))
				m_list.showedit =false;
			else if((tempID.IsEmpty()==false)&&(col == 1))
				m_list.showedit =false;
		}
	}
	return CDialog::PreTranslateMessage(pMsg);
}

void CDlgStoreAdjust3::OnEditChange()
{
	CString str;
	m_list.edit.GetWindowText(str);
	CString sql = "";
	switch (m_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;	
		}
	break;
	}
	if (! sql.IsEmpty())
	{
		m_pRs->raw_Close();
		m_pRs->Open((_variant_t)sql,m_pCon.GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdText);
		if (m_pRs->RecordCount>0)
		{
			m_listinfo.DeleteAllItems();
			int i=0;
			while(! m_pRs->adoEOF)
			{
				m_listinfo.InsertItem(100,"");
				for (int m = 0;m<4;m++)
				m_listinfo.SetItemText(i,m,(TCHAR*)(_bstr_t)m_pRs->GetFields()->GetItem((long)m)->Value);
				m_pRs->MoveNext();
				i +=1;
			}
			ShowListInfo();
		}
		else
			m_listinfo.ShowWindow(SW_HIDE);
	}
	else
		m_listinfo.ShowWindow(SW_HIDE);

}

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

void CDlgStoreAdjust3::LimitEdit()
{
	m_list.edit.IsNumber = false;
	//在修改商品数量时只允许输入数字
	if (m_list.col ==2)
	{
		m_list.edit.IsNumber = true;
	}
}

void CDlgStoreAdjust3::ShowListinfo()
{
	if (m_listinfo.IsWindowVisible())
	{
		m_listinfo.SetFocus();
		m_listinfo.PostMessage(WM_KEYDOWN,VK_HOME,0);
		//listinfo.SetSelectionMark(1);
	}
}

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

void CDlgStoreAdjust3::OnOK()
{
//prevent from pressing enter key to close form
}

void CDlgStoreAdjust3::OnDblclkList1(NMHDR* pNMHDR, LRESULT* pResult) 
{
	int row = m_listinfo.GetSelectionMark();
	if (row!=-1)
	{
		CString temp;
		temp = m_listinfo.GetItemText(row,0);
		//设置商品编号
		m_list.SetItemText(m_list.row,0,temp);
		//设置商品名称
		m_list.SetItemText(m_list.row,1,m_listinfo.GetItemText(row,1));
		m_listinfo.ShowWindow(SW_HIDE);
	}
	m_list.col =2;
	m_list.ShowEdit();
}

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

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

void CDlgStoreAdjust3::OnCancel()
{
	//prevent from pressing esc key to close form
}

void CDlgStoreAdjust3::AddStorage()
{
	m_fromstorage.ResetContent();//删除所有的数据
	m_tostorage.ResetContent();
	CString sql;
	sql = "select distinct storagename from tb_storageinfo";
	m_pRs->Close();
	m_pRs->Open((_bstr_t)sql,m_pCon.GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdText);
	while (!m_pRs->adoEOF)
	{
		m_tostorage.AddString((TCHAR *)(_bstr_t)m_pRs->GetFields()->GetItem("storagename")->Value);
		m_fromstorage.AddString((TCHAR *)(_bstr_t)m_pRs->GetFields()->GetItem("storagename")->Value);
		m_pRs->MoveNext();
	}
}

//取消操作
void CDlgStoreAdjust3::CancelOperate()
{
	m_fromstorage.SetCurSel(0);
	m_tostorage.SetCurSel(0);
	m_list.DeleteAllItems();
	m_list.InsertItem(100,"");
}

//保存操作
void CDlgStoreAdjust3::AddOperator()
{
	if (CheckInfo()) //通过检查
	{
		CString sql,SQL;
		CString c_sum,fromstorage,tostorage,merchandiseid;
		float f_sum;//mercandise number
		m_fromstorage.GetWindowText(fromstorage);
		m_tostorage.GetWindowText(tostorage);
		int row = m_list.GetItemCount();
		for (int i = 0;i<row;i++)
		{
			c_sum = m_list.GetItemText(i,2);
			f_sum = atof(c_sum);
			merchandiseid=m_list.GetItemText(i,0);
			sql.Format("update tb_merchandisestorage set Storagenum = Storagenum- %f where merchandiseID = '%s' and storagename = '%s'",f_sum,merchandiseid,fromstorage);
			SQL.Format("select * from tb_merchandisestorage  where merchandiseID = '%s' and storagename = '%s'",merchandiseid,tostorage);						
			try
			{
				m_pRs->raw_Close();
				m_pRs->Open((_variant_t)sql,m_pCon.GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdText);
				m_pRs->raw_Close();
				m_pRs->Open((_variant_t)SQL,m_pCon.GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdText);
				if (m_pRs->RecordCount>0)
				{
					m_pRs->raw_Close();
					SQL.Format("update tb_merchandisestorage set Storagenum = Storagenum+ %f where merchandiseID = '%s' and storagename = '%s' ",f_sum,merchandiseid,tostorage);
					m_pRs->Open((_variant_t)SQL,m_pCon.GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdText);
					
				}
				else
				{
					m_pRs->raw_Close();
					SQL.Format("insert tb_merchandisestorage values('%s','%s',%f,default,default)",merchandiseid,tostorage,f_sum);
					m_pRs->Open((_variant_t)SQL,m_pCon.GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdText);				
				}
				
				CancelOperate();
				MessageBox("操作成功.","提示",64);
			}
			catch(_com_error &e)
			{
				MessageBox(e.ErrorMessage(),"提示",64);
			}			
		}				
	}
}

//检查信息
bool CDlgStoreAdjust3::CheckInfo()
{
	CString str,fromstorage,tostorage;
	m_fromstorage.GetWindowText(fromstorage);
	m_tostorage.GetWindowText(tostorage);
	if ((fromstorage.IsEmpty())||(tostorage.IsEmpty()))
	{
		MessageBox("请设置仓库信息.","提示",64);
		return false;
	}
	if (fromstorage == tostorage)
	{
		MessageBox("调拨的仓库信息不能相同.","提示",64);
		return false;
	}
	int row,col;
	for (row = 0;row< m_list.GetItemCount();row++)
		for(col = 0;col <3;col++)
		{
			str = m_list.GetItemText(row,col);
			if (str.IsEmpty())
			{
				MessageBox("商品信息列表不能为空.","提示",64);
				return false;
			}
		}
	return true;
}


⌨️ 快捷键说明

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