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

📄 dlginputstoreback2.cpp

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

#include "stdafx.h"
#include "aaa.h"
#include "DlgInputStoreBack2.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDlgInputStoreBack2 dialog
extern _ConnectionPtr m_pCon;  
extern _RecordsetPtr m_pRs; 
extern CAaaApp theApp;

CDlgInputStoreBack2::CDlgInputStoreBack2(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgInputStoreBack2::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlgInputStoreBack2)
	//}}AFX_DATA_INIT
}


void CDlgInputStoreBack2::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgInputStoreBack2)
	DDX_Control(pDX, IDC_LIST1, list);
	DDX_Control(pDX, IDC_TOTALMONEY, totalmoney);
	DDX_Control(pDX, IDC_REBATE, rebate);
	DDX_Control(pDX, IDC_PAYMONEY, paymoney);
	DDX_Control(pDX, IDC_FACTMONEY, factmoney);
	DDX_Control(pDX, IDC_PROVIDERNAME, providername);
	DDX_Control(pDX, IDC_OPERATORNAME, operatorname);
	DDX_Control(pDX, IDC_LISTBOX2, storage);
	DDX_Control(pDX, IDC_LISTBOX, listbox);
	DDX_Control(pDX, IDC_LIST2, listinfo);
	DDX_Control(pDX, IDC_INPUTDATE, inputdate);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgInputStoreBack2, CDialog)
	//{{AFX_MSG_MAP(CDlgInputStoreBack2)
	ON_EN_CHANGE(IDC_REBATE, OnChangeRebate)
	ON_EN_CHANGE(IDC_TOTALMONEY, OnChangeTotalmoney)
	ON_NOTIFY(NM_DBLCLK, IDC_LIST2, OnDblclkList2)
	ON_LBN_KILLFOCUS(IDC_LISTBOX, OnKillfocusListbox)
	ON_NOTIFY(NM_KILLFOCUS, IDC_LIST2, OnKillfocusList2)
	ON_LBN_KILLFOCUS(IDC_LISTBOX2, OnKillfocusListbox2)
	ON_LBN_DBLCLK(IDC_LISTBOX, OnDblclkListbox)
	ON_LBN_DBLCLK(IDC_LISTBOX2, OnDblclkListbox2)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgInputStoreBack2 message handlers

BOOL CDlgInputStoreBack2::PreTranslateMessage(MSG* pMsg) 
{
	if (pMsg->message ==WM_KEYDOWN)	
	{		
		/****************************************************************
		说明:  在供应商编辑框获得焦点并按PageDown键,调用DoEditKeyDown方法
		****************************************************************/
		if ((pMsg->wParam == 34)&&(pMsg->hwnd==providername.m_hWnd))
		{
			DoEditKeyDown(34,IDC_PROVIDERNAME);

		}
		/****************************************************************
		说明:  表格中编辑框获得焦点时,按Enter键控制单元格焦点移动
		****************************************************************/
		if ((pMsg->wParam == 13)&&(pMsg->hwnd==list.edit.m_hWnd))
		{
			MoveFocus();
			return true;
		}	
		/****************************************************************
		说明:  表格中获得焦点时,按Enter键添加新行
		****************************************************************/		
		if ((pMsg->wParam == 13)&&(pMsg->hwnd == list.m_hWnd))
		{
			AddNewRow();
			return true;
		}
		if ((pMsg->wParam ==VK_DELETE)&&(pMsg->hwnd == list.m_hWnd))
		{
			DeleteCurRow();
			//return true;
		}		
		/****************************************************************
		说明:  列表框获得焦点时,按Enter键会将当前数据显示在编辑框中
		****************************************************************/
		else if ((pMsg->hwnd ==listbox.m_hWnd)&&(pMsg->wParam == 13))
		{
			OnDblclkListbox();
			return true;
		}
		/****************************************************************
		说明:  辅助录入表格获得焦点时,按Enter键会将当前数据显示在表格中
		****************************************************************/
		else if ((pMsg->hwnd ==listinfo.m_hWnd)&&(pMsg->wParam == 13))
		{
			OnDblclkList2(NULL,NULL);
			return true;
		}
		else if ((pMsg->wParam ==13)&&(pMsg->hwnd == storage.m_hWnd))
		{
			OnDblclkListbox2();
			return true;
		}
		else if (pMsg->wParam ==13)
		{
			pMsg->wParam = 9;
			//return;
		}						
		else if (pMsg->wParam == VK_ESCAPE)
			return true;
	}
	/****************************************************************
	说明:  表格中编辑框按键时的事件,用于判断是否限制字符输入,如果用户按
	PageDown键,将使辅助录入表格获得焦点
	****************************************************************/
	if ((pMsg->message == WM_KEYDOWN)&&(pMsg->hwnd == list.edit.m_hWnd))
	{
		LimitEdit();	
		if (pMsg->wParam == 34)
		{
			ShowListinfo();
			ShowStorage();
		}
		else if (pMsg->wParam ==VK_DELETE)//按delete键删除表格当前行
			DeleteCurRow();
	}	
	/****************************************************************
	说明:  表格中编辑框改变时的事件
	****************************************************************/
	if ((pMsg->message == WM_KEYUP)&&(pMsg->hwnd == list.edit.m_hWnd))
	{
		EditChage();	
	}
	/****************************************************************
	说明:  在窗体中控件获得焦点时,使提示列表不可见
	****************************************************************/
	if (pMsg->message==WM_LBUTTONDOWN)
	{
		if (pMsg->hwnd!= listinfo.m_hWnd)
			listinfo.ShowWindow(SW_HIDE);
		if (pMsg->hwnd != storage.m_hWnd)
			storage.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,1);
			tempname = list.GetItemText(row,2);			
			if (col==6) //如果单击金额列,不显示编辑框
				return true;
			list.showedit =true;	
			if ((tempname.IsEmpty()==false)&&(col == 1))
				list.showedit =false;
			else if((tempID.IsEmpty()==false)&&(col == 2))
				list.showedit =false;
		}
	}
	//处理折扣编辑框的按键消息,屏蔽非法字符
	if ((pMsg->message==WM_CHAR)&&(pMsg->hwnd == rebate.m_hWnd))
	{
		DWORD i = pMsg->wParam;
		if (i!= 8)
			if ((i<46)||(i>46)&&(i<47)||(i>57))
			{
				pMsg->wParam =0;
			}
	}
	return CDialog::PreTranslateMessage(pMsg);
}

BOOL CDlgInputStoreBack2::OnInitDialog() 
{
	CDialog::OnInitDialog();
	//添加供应商
	AddProvider();
	//添加仓库信息
	AddStorage();	
	storage.SetParent(&list);
	//读取操作员名称
	operatorname.SetWindowText(theApp.strUser);
	//设置表格风格
	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.InsertColumn(0,"仓库名称");
	list.InsertColumn(1,"商品编号");
	list.InsertColumn(2,"商品名称");
	list.InsertColumn(3,"单价");
	list.InsertColumn(4,"数量");
	list.InsertColumn(5,"折扣");
	list.InsertColumn(6,"金额");

	//设置列宽度
	listinfo.SetColumnWidth(0,80);
	listinfo.SetColumnWidth(1,100);
	listinfo.SetColumnWidth(2,60);
	listinfo.SetColumnWidth(3,60);
	listinfo.SetColumnWidth(4,60);

	list.SetColumnWidth(0,100);
	list.SetColumnWidth(1,140);
	list.SetColumnWidth(2,60);
	list.SetColumnWidth(3,60);
	list.SetColumnWidth(4,60);
	list.SetColumnWidth(5,60);
	list.SetColumnWidth(6,100);
	//添加空行
	list.InsertItem(1,"");
	list.SetItemText(0,5,"1.0");
	listinfo.SetParent(&list);

	rebate.SetWindowText("1.0");	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CDlgInputStoreBack2::AddNewRow()
{
	int counts = list.GetItemCount();
//	if (!CurrentRowIsNull()) //当前行不为空
		if (list.row == counts-1)//当前行为最后一行
		{
			list.InsertItem(100,"");
			list.row+=1;			
			list.SetItemText(list.row,5,"1.0");
			//list.SetFocus();
			list.col = 0;
			//list.SetHotItem(1);
			list.ShowEdit();

		}
		else
		{
			list.row+=1;
			list.col = 0;
			list.ShowEdit();
		}
}

void CDlgInputStoreBack2::AddProvider()
{
	listbox.SetRedraw(FALSE);
	listbox.ResetContent();//删除所有的数据
	CString sql;
	sql = "select providername from tb_providerinfo";
	m_pRs->Close();
	m_pRs->Open((_bstr_t)sql,m_pCon.GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdText);
	while (!m_pRs->adoEOF)
	{
		listbox.AddString((TCHAR *)(_bstr_t)m_pRs->GetFields()->GetItem("providername")->Value);
		m_pRs->MoveNext();
	}
	listbox.SetRedraw(TRUE);
	listbox.Invalidate();
}

float CDlgInputStoreBack2::CalculateMoney()
{
	float money,temp;
	money = 0.0;
	CString c_money;	
	int rowcounts = list.GetItemCount();
	for (int i = 0;i<rowcounts;i++)
	{
		c_money = list.GetItemText(i,6);
		if (!c_money.IsEmpty())
		{
			temp = atof(c_money);
			money += temp;
		}
	}
	return money;
}

void CDlgInputStoreBack2::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,"");
				}
			}
			CString temp;
			temp.Format("%10.2f",CalculateMoney());//重新统计数据
			temp.TrimLeft();
			totalmoney.SetWindowText(temp);
		}
	}
}

bool CDlgInputStoreBack2::DetailInfoIsNull()
{
	int rowcount = list.GetItemCount();
	if (rowcount ==-1)
		return true;
	for (int r = 0;r <rowcount;r++)
		for (int i = 0;i<7;i++)
		{
			CString temp;
			temp = list.GetItemText(r,i);
			if (temp.IsEmpty()==true)
				return true;
		}

⌨️ 快捷键说明

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