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

📄 dlgbookinput2.cpp

📁 这是一个图书管理系统,实现了图书馆中日常管理用到的所有操作.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// DlgBookInput2.cpp : implementation file
//

#include "stdafx.h"
#include "bbb.h"
#include "DlgBookInput2.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern _ConnectionPtr m_pCon;  //ADO连接对象
extern _RecordsetPtr m_pRs; 
extern _RecordsetPtr m_pRs1; 
extern _CommandPtr m_pCom;
extern CString user;
/////////////////////////////////////////////////////////////////////////////
// CDlgBookInput2 dialog



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


void CDlgBookInput2::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgBookInput2)
	DDX_Control(pDX, IDC_SUMMONEY, m_summoney);
	DDX_Control(pDX, IDC_STORAGELIST, m_storagelist);
	DDX_Control(pDX, IDC_REBATE, m_rebate);
	DDX_Control(pDX, IDC_PROVIDERLIST, m_providerlist);
	DDX_Control(pDX, IDC_PAYMONEY, m_paymoney);
	DDX_Control(pDX, IDC_OPERATOR, m_operator);
	DDX_Control(pDX, IDC_LIST2, m_auxilist);
	DDX_Control(pDX, IDC_LIST1, m_list);
	DDX_Control(pDX, IDC_FACTMONEY, m_factmoney);
	DDX_Control(pDX, IDC_DATETIME, m_date);
	DDX_Control(pDX, IDC_PROVIDER, m_provider);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgBookInput2, CDialog)
	//{{AFX_MSG_MAP(CDlgBookInput2)
	ON_EN_CHANGE(IDC_REBATE, OnChangeRebate)
	ON_EN_CHANGE(IDC_SUMMONEY, OnChangeSummoney)
	ON_NOTIFY(NM_DBLCLK, IDC_LIST2, OnDblclkList2)
	ON_LBN_DBLCLK(IDC_PROVIDERLIST, OnDblclkProviderlist)
	ON_LBN_DBLCLK(IDC_STORAGELIST, OnDblclkStoragelist)
	ON_NOTIFY(NM_KILLFOCUS, IDC_LIST2, OnKillfocusList2)
	ON_LBN_KILLFOCUS(IDC_PROVIDERLIST, OnKillfocusProviderlist)
	ON_LBN_KILLFOCUS(IDC_STORAGELIST, OnKillfocusStoragelist)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgBookInput2 message handlers

BOOL CDlgBookInput2::OnInitDialog() 
{
	CDialog::OnInitDialog();
	//添加供应商
	LoadProvider();
	//添加仓库信息
	LoadStorage();
	m_storagelist.SetParent(&m_list);
	//读取操作员名称
	m_operator.SetWindowText(user);
	
	//设置编辑框颜色
	SetEditColor(RGB(255,0,0));

	m_auxilist.ModifyStyle(LVS_EDITLABELS,0);//禁止编辑标题
	m_auxilist.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_ONECLICKACTIVATE|LVS_EX_INFOTIP|LVS_EX_SUBITEMIMAGES|LVS_EX_GRIDLINES );

	//向表格中添加列
	m_list.InsertColumn(0,"仓库名称",LVCFMT_LEFT,80);
	m_list.InsertColumn(1,"条形码",LVCFMT_LEFT,100);
	m_list.InsertColumn(2,"书籍名称",LVCFMT_LEFT,80);
	m_list.InsertColumn(3,"单价",LVCFMT_LEFT,60);
	m_list.InsertColumn(4,"数量",LVCFMT_LEFT,60);
	m_list.InsertColumn(5,"折扣",LVCFMT_LEFT,60);
	m_list.InsertColumn(6,"金额",LVCFMT_LEFT,60);

	m_auxilist.InsertColumn(0,"条形码",LVCFMT_LEFT,100);
	m_auxilist.InsertColumn(1,"书籍名称",LVCFMT_LEFT,80);
	m_auxilist.InsertColumn(2,"作者",LVCFMT_LEFT,60);
	m_auxilist.InsertColumn(3,"助记码",LVCFMT_LEFT,60);
	m_auxilist.InsertColumn(4,"默认价格",LVCFMT_LEFT,60);

	//添加空行
	m_list.InsertItem(1,"");
	m_list.SetItemText(0,5,"1.0");
	m_auxilist.SetParent(&m_list);

	m_rebate.SetWindowText("1.0");

	m_rebate.IsNumber = true;
	m_factmoney.IsNumber = true;
	
	m_providerlist.SetParent(&m_list);
	//m_list.SetParent(&m_provider);
	return TRUE; 
}

void CDlgBookInput2::OnOK()
{
//
}

void CDlgBookInput2::SetEditColor(COLORREF Color)
{
	CWnd* temp;
	temp = this;
	for (int i = 0;i<11;i++)
	{
		temp = GetNextDlgTabItem(temp);
		if (temp->IsKindOf(RUNTIME_CLASS(CKeyEdit))==true)
		{
			((CKeyEdit*)(temp))->SetEditTextColor(Color);
		}
	}
}

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

void CDlgBookInput2::LoadStorage()
{
	m_storagelist.SetRedraw(FALSE);
	m_storagelist.ResetContent();//删除所有的数据
	CString sql;
	sql = "select distinct storagename from tb_storageinfo";
	m_pRs->raw_Close();
	m_pRs->Open((_bstr_t)sql,m_pCon.GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdText);
	while (!m_pRs->adoEOF)
	{
		m_storagelist.AddString((TCHAR *)(_bstr_t)m_pRs->GetFields()->GetItem("storagename")->Value);
		m_pRs->MoveNext();
	}
	m_storagelist.SetRedraw(TRUE);
	m_storagelist.Invalidate();	
}

void CDlgBookInput2::AddNewRow()
{
	int counts = m_list.GetItemCount();
		if (m_list.row == counts-1)//当前行为最后一行
		{
			m_list.InsertItem(100,"");
			m_list.row+=1;			
			m_list.SetItemText(m_list.row,5,"1.0");

			m_list.col = 0;
			m_list.ShowEdit();

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

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

bool CDlgBookInput2::CurrentRowIsNull()
{
	int row = m_list.GetSelectionMark();
	if (row !=-1)
	{
		for (int index = 0;index <7;index++)
		{
			CString str;
			str = m_list.GetItemText(m_list.row,index);
			if (str.IsEmpty())
			{
				return true;
			}
		}
	}
	else
		return true;
	return false;
}

void CDlgBookInput2::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<7 ;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< 7;i++)
				{
					m_list.SetItemText(0,i,"");
				}
			}
			CString temp;
			temp.Format("%10.2f",CalculateMoney());//重新统计数据
			temp.TrimLeft();
			m_summoney.SetWindowText(temp);
		}
	}
}

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

void CDlgBookInput2::DoEditKeyDown(UINT nChar, UINT CtrlID)
{
	if ((nChar ==34)&&(CtrlID ==IDC_PROVIDER))
	{
		
	//	CRect rect,rect1;
	//	m_providerlist.GetWindowRect(rect1);
	//	m_provider.GetWindowRect(rect);
	//	ScreenToClient(rect);
	//	ScreenToClient(rect1);
	//	m_providerlist.MoveWindow(rect.left,rect.bottom+2,rect.right-rect.left,rect1.bottom-rect1.top);	
		m_providerlist.ShowWindow(SW_SHOW);
	//	m_providerlist.BringWindowToTop();
	//	SetWindowPos(&m_providerlist,rect.left,rect.bottom+2,rect.right-rect.left,rect1.bottom-rect1.top,SWP_SHOWWINDOW);
		m_providerlist.SetSel(0);
		m_providerlist.SetFocus();
			
	}
}

void CDlgBookInput2::EditChange()
{
	CString str;
	m_list.edit.GetWindowText(str);
		CString sql = "";
		switch (m_list.col)
		{
		case 1 : 
			{
				if (!str.IsEmpty())
					sql.Format("select barcode,bookname,author,shortname,price from tb_bookinfo where barcode like '%s%%' or shortname like '%s%%' ",str,str);
				break;
			}
		case 2 : 
			{
				if (!str.IsEmpty())
					sql.Format("select barcode,bookname,author,shortname,price from tb_bookinfo where bookname like '%s%%' or shortname like '%s%%'",str,str);
				break;
			}
		case 3:
			{
				CString c_price,c_num,c_rebate,c_money;
				float f_price,f_num,f_rebate,f_money;
				c_price = str;
				c_num = m_list.GetItemText(m_list.row,4);
				c_rebate = m_list.GetItemText(m_list.row,5);
				if (c_price.IsEmpty()||c_num.IsEmpty()||c_rebate.IsEmpty())
				{
					//如果单价\数量\折扣为空,金额将为空
					m_list.SetItemText(m_list.row,6,""); 
				}
				else
				{
					f_price = atof(c_price);
					f_num = atof(c_num);
					f_rebate = atof(c_rebate);
					f_money = f_price*f_num*f_rebate;
					c_money.Format("%10.2f",f_money);
					c_money.TrimLeft();
					m_list.SetItemText(m_list.row,6,c_money);
				}
				str.Format("%10.2f",CalculateMoney());
				str.TrimLeft();
				m_summoney.SetWindowText(str);
				break;
			}

		case 4:
			{
				CString c_price,c_num,c_rebate,c_money;
				float f_price,f_num,f_rebate,f_money;
				c_price = m_list.GetItemText(m_list.row,3);
				c_num = str;
				c_rebate = m_list.GetItemText(m_list.row,5);
				if (c_price.IsEmpty()||c_num.IsEmpty()||c_rebate.IsEmpty())
				{
					//如果单价\数量\折扣为空,金额将为空
					m_list.SetItemText(m_list.row,6,""); 
				}
				else
				{
					f_price = atof(c_price);
					f_num = atof(c_num);
					f_rebate = atof(c_rebate);
					f_money = f_price*f_num*f_rebate;
					c_money.Format("%10.2f",f_money);
					c_money.TrimLeft();
					m_list.SetItemText(m_list.row,6,c_money);
				}
				str.Format("%10.2f",CalculateMoney());
				str.TrimLeft();
				m_summoney.SetWindowText(str);
				break;
			}
		case 5:
			{
				CString c_price,c_num,c_rebate,c_money;
				float f_price,f_num,f_rebate,f_money;
				c_price = m_list.GetItemText(m_list.row,3);
				c_num = m_list.GetItemText(m_list.row,4);
				c_rebate = str;
				if (c_price.IsEmpty()||c_num.IsEmpty()||c_rebate.IsEmpty())
				{
					//如果单价\数量\折扣为空,金额将为空
					m_list.SetItemText(m_list.row,6,""); 
				}
				else
				{
					f_price = atof(c_price);
					f_num = atof(c_num);
					f_rebate = atof(c_rebate);
					f_money = f_price*f_num*f_rebate;
					c_money.Format("%10.2f",f_money);
					c_money.TrimLeft();
					m_list.SetItemText(m_list.row,6,c_money);
				}
				str.Format("%10.2f",CalculateMoney());
				str.TrimLeft();
				m_summoney.SetWindowText(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)
			{
				m_auxilist.DeleteAllItems();
				int i=0;
				while(! m_pRs->adoEOF)
				{
					m_auxilist.InsertItem(100,"");
					for (int m = 0;m<5;m++)
					m_auxilist.SetItemText(i,m,(TCHAR*)(_bstr_t)m_pRs->GetFields()->GetItem((long)m)->Value);

⌨️ 快捷键说明

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