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

📄 dlgbookadjust2.cpp

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

#include "stdafx.h"
#include "bbb.h"
#include "DlgBookAdjust2.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;

/////////////////////////////////////////////////////////////////////////////
// CDlgBookAdjust2 dialog


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


void CDlgBookAdjust2::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgBookAdjust2)
	DDX_Control(pDX, IDC_LIST2, m_auxilist);
	DDX_Control(pDX, IDC_STORAGE, m_storage);
	DDX_Control(pDX, IDC_OPERATOR, m_operator);
	DDX_Control(pDX, IDC_LIST, m_list);
	DDX_Control(pDX, IDC_DATE, m_date);
	DDX_Control(pDX, IDC_COUNTER, m_counter);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgBookAdjust2, CDialog)
	//{{AFX_MSG_MAP(CDlgBookAdjust2)
	ON_NOTIFY(NM_DBLCLK, IDC_LIST2, OnDblclkList2)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgBookAdjust2 message handlers

BOOL CDlgBookAdjust2::OnInitDialog() 
{
	CDialog::OnInitDialog();

	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(1,"条形码",LVCFMT_LEFT,100);
	m_list.InsertColumn(2,"书籍名称",LVCFMT_LEFT,120);
	m_list.InsertColumn(3,"作者",LVCFMT_LEFT,80);
	m_list.InsertColumn(4,"出版社",LVCFMT_LEFT,100);
	m_list.InsertColumn(5,"数量",LVCFMT_LEFT,80);

	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_auxilist.SetParent(&m_list);	

	LoadStorageInfo();
	LoadCounterInfo();

	m_operator.SetWindowText(user);
	CancelOperate();//exeute cancel operate
	return TRUE;  
}

void CDlgBookAdjust2::LoadStorageInfo()
{
	m_storage.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_storage.AddString((TCHAR *)(_bstr_t)m_pRs->GetFields()->GetItem("storagename")->Value);
		m_pRs->MoveNext();
	}
}


void CDlgBookAdjust2::LoadCounterInfo()
{
	m_counter.ResetContent();//删除所有的数据
	CString sql;
	sql = "select distinct counter from tb_counterinfo";
	m_pRs->raw_Close();
	m_pRs->Open((_bstr_t)sql,m_pCon.GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdText);
	while (!m_pRs->adoEOF)
	{
		m_counter.AddString((TCHAR *)(_bstr_t)m_pRs->GetFields()->GetItem("counter")->Value);
		m_pRs->MoveNext();
	}
}

void CDlgBookAdjust2::CancelOperate()
{
	m_storage.SetCurSel(-1);
	m_counter.SetCurSel(-1);
	m_list.DeleteAllItems();
	CTime date = CTime::GetCurrentTime();
	m_date.SetTime(&date);
	m_list.InsertItem(1,"");
	m_list.edit.SetWindowText("");
}

void CDlgBookAdjust2::OnOK()
{

//prevent pressing enter key to close form
}

void CDlgBookAdjust2::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();
	}
}

bool CDlgBookAdjust2::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 CDlgBookAdjust2::DeleteCurRow()
{
	int currow;
	currow = m_list.row;
	if (currow!=-1)
	{		
	//	m_list.SetFocus();		
		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<5 ;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< 5;i++)
				{
					m_list.SetItemText(0,i,"");
				}
			}
			m_auxilist.ShowWindow(SW_HIDE);
		}
	}
}

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

void CDlgBookAdjust2::EditChange()
{
	CString str;
	m_list.edit.GetWindowText(str);
		CString sql = "";
		switch (m_list.col)
		{
		case 0 : 
			{
				if (!str.IsEmpty())
					sql.Format("select barcode,bookname,author,bookconcern,price from tb_bookinfo where barcode like '%s%%' or shortname like '%s%%' ",str,str);
				break;
			}
		case 1 : 
			{
				if (!str.IsEmpty())
					sql.Format("select barcode,bookname,author,bookconcern,price from tb_bookinfo where bookname like '%s%%' or shortname like '%s%%'",str,str);
				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 CDlgBookAdjust2::ShowListInfo()
{
	CRect rect;
	m_list.GetSubItemRect(m_list.row,m_list.col,LVIR_BOUNDS,rect);
	m_auxilist.MoveWindow(rect.left,rect.bottom+1,300,150);
	m_auxilist.ShowWindow(SW_SHOW);
}

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

void CDlgBookAdjust2::ShowListinfo()
{
	if (m_auxilist.IsWindowVisible())
	{
		m_auxilist.SetFocus();
		m_auxilist.PostMessage(WM_KEYDOWN,VK_UP);
	}
}

void CDlgBookAdjust2::MoveFocus()
{
	m_list.SetFocus();
	if (m_list.col <5)

⌨️ 快捷键说明

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