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

📄 listkcpd1.cpp

📁 进销存管理系统介绍了企业的现状以及进销存数据管理系统的特点、功能和使用对象
💻 CPP
字号:
// ListKCPD1.cpp: implementation of the CListKCPD class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "a1.h"
#include "ListKCPD1.h"
#include "myfunction.h"

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

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CListKCPD::CListKCPD()
{
	m_pstrlistKc=new CStringList[4];

	for(int i=0;i<100;i++)
	{
	m_iTheItemState[i]=0;
	m_iKcSelected[i]=-1;
	}

	this->InitValuesFromDB();

}

CListKCPD::~CListKCPD()
{
	delete [] m_pstrlistKc;
}
void CListKCPD::OnNewEditChange(const int& item,const int& subitem)
{
	TRACE("void CListXSDJ::OnNewEditChange()\n");
	if(this->m_bSetValue) return ;
		ASSERT(this->m_poplist!=NULL);
	CString str;
	m_edit.GetWindowText(str);
	CString str_sl=this->GetItemText(item,3);
//	if(!m_poplist->IsWindowVisible())
		m_poplist->ShowListPop();

	switch(subitem)
	{
	case 0:
		{		
			str.MakeUpper();
			CString id=this->GetItemText(item,1);

			int sl=0;
			sl=atoi(str_sl);
			if(sl&&str!=this->m_sSetFocus)
			{
				this->SetItemText(item,3,"");
				if(m_iKcSelected[item]>=0)
				this->CancelTheItem(item);
			}
			this->m_iTheItemState[item]=NOCK;
			this->m_iKcSelected[item]=-1;
	this->m_poplist->RefreshListCtrlView(1,id,0,str);

			break;
		}
	case 1:
		{
			str.MakeUpper();
			CString ck_name=this->GetItemText(item,0);
			int sl=0;
			sl=atoi(str_sl);
			if(sl&&str!=this->m_sSetFocus)
			{
				this->SetItemText(item,3,"");
				if(m_iKcSelected[item]>=0)
				this->CancelTheItem(item);
			}
			this->m_iTheItemState[item]=NOID;
			m_iKcSelected[item]=-1;
			this->m_poplist->RefreshListCtrlView(0,ck_name,1,str);

			break;
		}
	case 2:
		{
			CString ck_name=this->GetItemText(item,0);
			int sl=0;
			sl=atoi(str_sl);
			if(sl&&str!=this->m_sSetFocus)
			{
				this->SetItemText(item,3,"");
				if(m_iKcSelected[item]>=0)
				this->CancelTheItem(item);
			}
			this->m_iTheItemState[item]=NONAME;
			m_iKcSelected[item]=-1;
			this->m_poplist->RefreshListCtrlView(0,ck_name,2,str);

			break;
		}
	case 3:
		{

				CString ck_name=this->GetItemText(item,0);
				CString id=this->GetItemText(item,1);
				this->m_pstrlistKc[3].SetAt(this->m_pstrlistKc[3].FindIndex(FindKc(item)),str);
				this->m_poplist->RefreshListCtrlView(0,ck_name,1,id);

			break;
		}
	}
}
void CListKCPD::OnEditSetFocus(const int& item, const int& subitem)
{
	CString str;
	m_edit.m_dSetFocusValue=0;
	m_edit.GetWindowText(str);
	this->m_sSetFocus=str;
	m_edit.GetWindowRect(&this->m_rectWindow);
	str.MakeUpper();
	switch(subitem)
	{
	case 0:
		{
			CString id=this->GetItemText(item,1);
			this->m_poplist->ShowWindow(SW_HIDE);
				ASSERT(this->m_poplist!=NULL);
			this->m_poplist->SetShowPosition(this->m_rectWindow,&m_edit);
			this->m_poplist->RefreshListCtrlView(1,id,0,str);
			if(!m_poplist->IsWindowVisible())
			m_poplist->ShowListPop();
			break;
		}
	case 1:
		{
			this->m_poplist->ShowWindow(SW_HIDE);
				ASSERT(this->m_poplist!=NULL);
			this->m_poplist->SetShowPosition(this->m_rectWindow,&m_edit);
			CString ck_name=this->GetItemText(item,0);
			this->m_poplist->RefreshListCtrlView(0,ck_name,1,str);
			if(!m_poplist->IsWindowVisible())
			m_poplist->ShowListPop();
			break;
			
		}
	case 2:
		{
			this->m_poplist->ShowWindow(SW_HIDE);
				ASSERT(this->m_poplist!=NULL);
			this->m_poplist->SetShowPosition(this->m_rectWindow,&m_edit);
			CString ck_name=this->GetItemText(item,0);
			this->m_poplist->RefreshListCtrlView(0,ck_name,2,str);
			if(!m_poplist->IsWindowVisible())
			m_poplist->ShowListPop();
			break;
		}
	case 3:
		{
			if(this->CheckKc(item)&&(IsSelected(item)!=-1))
			{
				this->m_poplist->ShowWindow(SW_HIDE);
				CString ck_name=this->GetItemText(item,0);
				CString id=this->GetItemText(item,1);
				this->m_poplist->SetShowPosition(this->m_rectWindow,&m_edit);
				this->m_poplist->RefreshListCtrlView(0,ck_name,1,id);
				m_poplist->ShowListPop();
				this->m_edit.m_dSetFocusValue=atoi(str);
			}
			else
			{
					m_edit.ShowWindow(SW_HIDE);
					this->m_iEditedIndex=-1;
					this->SetNextItemFocus();
					MessageBox("请确定有此库存信息!并且该记录唯一!","错误");
			}

			break;
		}
	}
}
bool CListKCPD::OnEditReturn(const int& item, const int& subitem)
{
	CString str;
	m_edit.GetWindowText(str);
	switch(subitem)
	{
	case 0:
	case 1:
	case 2:
		{	
			if(this->m_poplist->IsWindowVisible()&&this->m_poplist->GetSelectedMark()>=0)
			{
				this->SetValueUnChange(m_poplist->GetListCtrlSel(subitem));
				this->SetItemText(m_nItem,0,this->m_poplist->GetListCtrlSel(0));
				this->SetItemText(m_nItem,1,this->m_poplist->GetListCtrlSel(1));
				this->SetItemText(m_nItem,2,this->m_poplist->GetListCtrlSel(2));
				this->SetItemText(m_nItem,3,this->m_poplist->GetListCtrlSel(3));
				m_iTheItemState[item]=NOWRONG;
//				m_iTheItemState[item]=NONE;	
//				m_iTheItemState[item]&=NOCK;
//				m_iTheItemState[item]|=YPTRUE;
			}
			else
				SetValueUnChange("");

			break;
		}
	case 4:
		{
				break;
		}
	}
	return CBaseList::OnEditReturn(item,subitem);
}
void CListKCPD::OnEditKillFocus(const int& item, const int& subitem)
{
	CString str;
	m_edit.GetWindowText(str);
	switch(subitem)
	{
	case 3:
		{
//			this->m_pstrlistKc[3].SetAt(
//				this->m_pstrlistKc[3].FindIndex(FindKc(item)),str);
//			this->m_poplist->SelectStringList(4,m_pstrlistKc);
			break;
		}
	}
	CBaseList::OnEditKillFocus(item,subitem);
}

bool CListKCPD::InitValuesFromDB()
{
	LRunSql m_runsql;
	CString sql;
	_variant_t value;

	m_pstrlistKc[0].AddTail("仓库名称");
	m_pstrlistKc[1].AddTail("药品编号");
	m_pstrlistKc[2].AddTail("药品名称");
	m_pstrlistKc[3].AddTail("库存数量");
	m_strlistNo.AddTail("");
	sql.Format("select tabkc.yp_id,tabkc.ck_name,tabkc.kc_number,\
		tabypinfo.yp_name from tabkc,tabypinfo \
		where tabkc.yp_id = tabypinfo.yp_id");

		m_runsql.CheckSQLResult(sql);
		while(!m_runsql.m_recordset->adoEOF)
		{
			value=m_runsql.m_recordset->GetCollect("ck_name");
			if(value.vt!=VT_NULL)
				m_pstrlistKc[0].AddTail((char*)(_bstr_t)value);
			value=m_runsql.m_recordset->GetCollect("yp_id");
			if(value.vt!=VT_NULL)
				m_pstrlistKc[1].AddTail((char*)(_bstr_t)value);
			value=m_runsql.m_recordset->GetCollect("yp_name");
			if(value.vt!=VT_NULL)
				m_pstrlistKc[2].AddTail((char*)(_bstr_t)value);
			value=m_runsql.m_recordset->GetCollect("kc_number");
			if(value.vt!=VT_NULL)
				m_pstrlistKc[3].AddTail((char*)(_bstr_t)value);
				m_strlistNo.AddTail((char*)(_bstr_t)value);
			m_runsql.m_recordset->MoveNext();
		}
//	this->m_poplist->SelectStringList(4,this->m_pstrlistKc);

	return true;
}

bool CListKCPD::Create(DWORD dwStyle, const RECT &rect, CWnd *pParentWnd, UINT nID)
{
	bool b=CBaseList::Create(dwStyle,rect,pParentWnd,nID);
	m_poplist->SelectStringList(4,this->m_pstrlistKc);
	return b;

}

void CListKCPD::OnEditUDNPMessage(const int& item, const int& subitem, UINT key)
{
	switch(subitem)
	{
	case 0:
	case 1:
	case 2:
		{
			this->m_poplist->SendTheUDNPMessage(key);
			break;
		}

	}
}

int CListKCPD::CheckKc(const int& item)
{
	if(m_iKcSelected[item]=FindKc(item)>=0)			
	{
			m_iTheItemState[item]=NOWRONG;
	}
	else 
	{
			TRACE("CKFALSE");
			m_iTheItemState[item]=0;
	}
	return m_iTheItemState[item];

}

int CListKCPD::FindKc(const int& item)
{	int n=this->GetItemCount();
	if(item<-1||item>=n)return -1;
	CString ck_name=this->GetItemText(item,0);
	CString yp_id=this->GetItemText(item,1);
	CString yp_name=this->GetItemText(item,2);
	
	bool result=false;
	POSITION pos=NULL;int i;
   for( pos = this->m_pstrlistKc[0].GetHeadPosition(),i=0; pos != NULL; i++)
   {
		if(ck_name== m_pstrlistKc[0].GetNext( pos ))
			if(this->m_pstrlistKc[1].GetAt(this->m_pstrlistKc[1].FindIndex(i))==yp_id)
				if(this->m_pstrlistKc[2].GetAt(this->m_pstrlistKc[2].FindIndex(i))==yp_name)
				{
					return i;			
				}
   }
   return -1;
}

void CListKCPD::OnESC(const int& item, const int& subitem)
{
	CString str;
	str.Format("%d",m_edit.m_dSetFocusValue);
	switch(this->m_nSubItem)
	{
	case 3:
		this->m_pstrlistKc[3].SetAt(
			this->m_pstrlistKc[3].FindIndex(
			this->m_iKcSelected[this->m_nItem])
			,str);
		this->m_poplist->SelectStringList(4,m_pstrlistKc);
		break;
	}
	CBaseList::OnESC(item,subitem);

}

int CListKCPD::IsSelected(const int& item)//if selected return -1, else return index;
{
	int index=this->FindKc(item);
	if(index<0)return m_iKcSelected[item]=-1;
	int n=this->GetItemCount();
	for(int i=0;i<n;i++)
	{
		if(i==item) continue;
		if(m_iKcSelected[i]==-1)
			if(!CheckKc(i)) continue;
		if(this->m_iKcSelected[i]==index)
			return m_iKcSelected[item]=-1;
	}
	return m_iKcSelected[item]=index;
}

void CListKCPD::PreOnEditChar(const int& item, const int& subitem, UINT &key)
{

	switch(subitem)
	{

	case 3:
		if((key>=0x30&&key<=0x39)||key==0x08)
		{
			;
		}
		else
		{
		key=VK_CONTROL;
		}
		break;
	}
}

bool CListKCPD::CheckAll()
{
	int n=GetItemCount();
	for(int i=0;i<n;i++)
	{
		if(GetItemText(i,0)==""&&GetItemText(i,1)=="")
		{
			DeleteItem(i);
			continue;
		}
		long number=0;
		if(!this->CheckTheItem(i))
		{
		return false;
		}
		if(this->IsSelected(i)==-1)
		{
			MessageBox("数据不唯一,请确认数据唯一","注意!");
			this->m_nItem=i;
			m_iEditedIndex=-1;
			PostMessage(SETNEXTITEMPHFOCUS,0,0);
			return false;
		}
	}
	return true;	
}

bool CListKCPD::CheckTheItem(const int& item)
{
	if(!this->CheckKc(item))
	{
		this->m_nItem=item;
		this->m_iEditedIndex=-1;
		MessageBox("请输入完整登记信息","注意");
		this->PostMessage(SETNEXTITEMPHFOCUS,0,0);	
		return false;
	}

	CString str=this->GetItemText(item,3);
	if(str=="")
	{
		TRACE("SL false");	this->m_nItem=item;
		this->m_iEditedIndex=2;
		MessageBox("若确实要清空该药品库存,请添0","注意");
		this->PostMessage(SETNEXTITEMPHFOCUS,0,0);
		return false; 
	}
	return true;

}

bool CListKCPD::DeleteSelected()
{	if(this->m_poplist->IsWindowVisible())
		this->m_poplist->ShowWindow(SW_HIDE);
	if(this->m_edit.IsWindowVisible())
		m_edit.ShowWindow(SW_HIDE);

	LVITEM* item=new LVITEM;
	int number=this->GetSelectedCount();
	for(int i=this->GetItemCount()-1;i>=0;i--)
	{
			this->m_nItem=i;
			item->iItem=i;
			item->mask=LVIF_STATE ;
			item->stateMask=LVIS_SELECTED ;
			GetItem(item);
		if(item->state==LVIS_SELECTED)
		{
			DeleteItem(i);
			if(m_iKcSelected[i]==-1)continue;
			m_pstrlistKc[3].SetAt(m_pstrlistKc[3].FindIndex(m_iKcSelected[i]),m_strlistNo.GetAt(m_strlistNo.FindIndex(m_iKcSelected[i])));
			this->m_poplist->SelectStringList(4,this->m_pstrlistKc);
			this->m_iTheItemState[i]=NONE;
			this->m_iKcSelected[i]=-1;

		}
	}
		if(GetItemCount()==0)
			InsertItem(0,"");
		this->m_nItem=0;
		Invalidate();
	return true;
}

bool CListKCPD::CancelTheItem(const int &item)
{
	m_pstrlistKc[3].SetAt(
		m_pstrlistKc[3].FindIndex(m_iKcSelected[item]),
		m_strlistNo.GetAt(m_strlistNo.FindIndex(m_iKcSelected[item]))
		);
//	this->m_poplist->SelectStringList(4,this->m_pstrlistKc);
	this->m_iTheItemState[item]=NONE;
	this->m_iKcSelected[item]=-1;
	this->SetItemText(item,3,"");
	return true;
}

⌨️ 快捷键说明

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