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

📄 dlginputback2.cpp

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

#include "stdafx.h"
#include "bbb.h"
#include "DlgInputBack2.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;
/////////////////////////////////////////////////////////////////////////////
// CDlgInputBack2 dialog


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


void CDlgInputBack2::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgInputBack2)
	DDX_Control(pDX, IDC_FACTMONEY, m_factmoney);
	DDX_Control(pDX, IDC_LIST1, m_list);
	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_PROVIDER, m_provider);
	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_DATETIME, m_date);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgInputBack2, CDialog)
	//{{AFX_MSG_MAP(CDlgInputBack2)
	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_STORAGELIST, OnKillfocusStoragelist)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgInputBack2 message handlers

void CDlgInputBack2::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 CDlgInputBack2::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 CDlgInputBack2::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 CDlgInputBack2::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 CDlgInputBack2::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 CDlgInputBack2::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);
					m_pRs->MoveNext();
					i +=1;
				}
				ShowListInfo();
			}
			else
				m_auxilist.ShowWindow(SW_HIDE);
		}
		else
			m_auxilist.ShowWindow(SW_HIDE);
}

void CDlgInputBack2::InputCancel()
{
	m_rebate.SetWindowText("1.0");
	CTime time = CTime::GetCurrentTime();
	m_date.SetTime(&time);
	m_list.DeleteAllItems();
	m_list.InsertItem(1,"");
	m_list.SetItemText(0,5,"1.0");
	m_provider.SetWindowText("");
	m_factmoney.SetWindowText("");
	m_summoney.SetWindowText("");
}

bool CDlgInputBack2::InputInfoIsNull()
{
	CString c_provider,c_totalmoney,c_rebate,c_paymoney,c_factmoney;
	m_provider.GetWindowText(c_provider);
	m_summoney.GetWindowText(c_totalmoney);
	m_rebate.GetWindowText(c_rebate);
	m_paymoney.GetWindowText(c_paymoney);
	m_factmoney.GetWindowText(c_factmoney);
	if ((c_provider.IsEmpty())||(c_totalmoney.IsEmpty())||(c_rebate.IsEmpty())||(c_paymoney.IsEmpty())||(c_factmoney.IsEmpty()))
		return true;
	else
		return false;
}

void CDlgInputBack2::LimitEdit()
{
	m_list.edit.IsNumber = false;
	//在修改商品数据,价格,折扣时只允许输入数字
	if ((m_list.col ==3)||(m_list.col ==4)||(m_list.col==5))
	{
		m_list.edit.IsNumber = true;
	}
}

void CDlgInputBack2::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 CDlgInputBack2::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 CDlgInputBack2::MoveFocus()
{
	m_list.SetFocus();
	if (m_list.col <7)
	{
		m_list.col = m_list.col+1;
		CString tempID,tempname;
		tempID = m_list.GetItemText(m_list.row,1);
		tempname = m_list.GetItemText(m_list.row,2);
		m_list.showedit = true;
		if ((tempname.IsEmpty()==false)&&(m_list.col == 1))
			m_list.showedit =false;
		else if((tempID.IsEmpty()==false)&&(m_list.col == 2))
			m_list.showedit =false;
		m_list.ShowEdit();
	}
	else
	{
		AddNewRow();
	}
}

void CDlgInputBack2::OnChangeRebate() 
{
	CString c_totalmoney,c_rebate,c_paymoney;
	float f_totalmoney,f_rebate,f_paymoney;
	m_summoney.GetWindowText(c_totalmoney);
	m_rebate.GetWindowText(c_rebate);
	if(!c_totalmoney.IsEmpty()&&!c_rebate.IsEmpty())
	{
		f_totalmoney = atof(c_totalmoney);
		f_rebate = atof(c_rebate);
		f_paymoney = f_totalmoney *f_rebate;
		c_paymoney.Format("%10.2f",f_paymoney);
		c_paymoney.TrimLeft();
		m_paymoney.SetWindowText(c_paymoney);
	}
	else
	{
		m_paymoney.SetWindowText("");
	}	
}

void CDlgInputBack2::OnChangeSummoney() 
{
	//调用折扣改变时的事件
	OnChangeRebate();	
}

⌨️ 快捷键说明

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