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

📄 medifind.cpp

📁 一个VC写的药品管理系统
💻 CPP
字号:
// MediFind.cpp : implementation file
//

#include "stdafx.h"
#include "medicine.h"
#include "MediFind.h"
#include "columns.h"
#include "column.h"
#include "COMDEF.H"
#include "MainFrame.h"
#include "MediInfo.h"
#include "_recordset.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMediFind dialog


CMediFind::CMediFind(CWnd* pParent /*=NULL*/)
	: CDialog(CMediFind::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMediFind)
	m_ChooseInfo = _T("");
	//}}AFX_DATA_INIT
}


void CMediFind::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMediFind)
	DDX_Control(pDX, IDC_COMBO1, m_Type);
	DDX_Control(pDX, IDC_DATAGRID1, m_DataGrid);
	DDX_Control(pDX, IDC_ADODC1, m_Adodc);
	DDX_Text(pDX, IDC_SEARCHINFO, m_ChooseInfo);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CMediFind, CDialog)
	//{{AFX_MSG_MAP(CMediFind)
	ON_BN_CLICKED(IDC_CORRECTFIND, OnCorrectFind)
	ON_BN_CLICKED(IDC_LIKEFIND, OnLikeFind)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMediFind message handlers

int CMediFind::DoModal() 
{
	// TODO: Add your specialized code here and/or call the base class
	
	return CDialog::DoModal();
}

BOOL CMediFind::OnInitDialog() 
{
	CDialog::OnInitDialog();
	m_Type.SetCurSel(0);
    UpdateData(FALSE);//把变量信息及时更新到控件上
	// TODO: Add extra initialization here
	RefreshData();
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CMediFind::RefreshData()
{
	UpdateData(TRUE);// 将控件上的信息及时更新到对应的变量
	CString cSql;
	cSql = "select  MediStore.MediId as'药品编号',MediInfo.MediName as";
	cSql+="'药品名称',MediInfo.Short as'药品简称', MediInfo.MediPrice as ";
	cSql+="'售价',MediInfo.Unit as'单位', MediStore.InAmout as";
	cSql+="'库存量',MediInfo.VipDisc as'VIP折扣(%)', MediStore.InDate as";
	cSql+="'生产日期',MediInfo.LastDate as'过期日期',MediStore.SalerId as";
	cSql+="'销售商编号',MediInfo.LeastAmout as";//,MediInfo.Short as'药品简码'
	cSql+="'库存下限', MediInfo.Detail as";
	cSql+="'详细说明'from MediStore,MediInfo where MediStore.MediId=MediInfo.MediId";
	m_Adodc.SetRecordSource(cSql);
	m_Adodc.Refresh();

	//	MessageBox(cSql);
	m_Adodc.SetRecordSource((LPCTSTR)(_bstr_t)cSql);
	m_Adodc.Refresh();
	// 设置列宽度
	_variant_t vIndex;
	//long将整数转换为_variant_t类型,从而可以在CColumns::GetItem()函数中使用
	vIndex = long(0);
	m_DataGrid.GetColumns().GetItem(vIndex).SetWidth(60);
	vIndex = long(1);  
	m_DataGrid.GetColumns().GetItem(vIndex).SetWidth(60);
	vIndex = long(2); 
	m_DataGrid.GetColumns().GetItem(vIndex).SetWidth(60);
	vIndex = long(3); 
	m_DataGrid.GetColumns().GetItem(vIndex).SetWidth(60);
	vIndex = long(4); 
	m_DataGrid.GetColumns().GetItem(vIndex).SetWidth(60);
	vIndex = long(5); 
	m_DataGrid.GetColumns().GetItem(vIndex).SetWidth(60);
	vIndex = long(6); 
	m_DataGrid.GetColumns().GetItem(vIndex).SetWidth(60);
	vIndex = long(7);  
	m_DataGrid.GetColumns().GetItem(vIndex).SetWidth(60);
	vIndex = long(8); 
	m_DataGrid.GetColumns().GetItem(vIndex).SetWidth(60);
	vIndex = long(9);  
	m_DataGrid.GetColumns().GetItem(vIndex).SetWidth(60);
	vIndex = long(10);  
	m_DataGrid.GetColumns().GetItem(vIndex).SetWidth(60);

}

void CMediFind::OnCorrectFind() 
{
	// TODO: Add your control notification handler code here
	/*全部
	按药名
	按药品编号
	按销售商编号
	按生产日期
	按药品简称*/
	UpdateData(TRUE);
	CString cSql;
	cSql = "select  MediStore.MediId as'药品编号',MediInfo.MediName as";
	cSql+="'药品名称',MediInfo.Short as'药品简称', MediInfo.MediPrice as ";
	cSql+="'售价',MediInfo.Unit as'单位', MediStore.InAmout as";
	cSql+="'库存量',MediInfo.VipDisc as'VIP折扣(%)', MediStore.InDate as";
	cSql+="'生产日期',MediInfo.LastDate as'过期日期',MediStore.SalerId as";
	cSql+="'销售商编号',MediInfo.LeastAmout as";//,MediInfo.Short as'药品简码'
	cSql+="'库存下限', MediInfo.Detail as";
	cSql+="'详细说明'from MediStore,MediInfo where MediStore.MediId=MediInfo.MediId";

	if(m_ChooseInfo!="")
	{
		if(m_Type.GetCurSel()==1)
		{
			cSql += " and MediInfo.MediName ='"+m_ChooseInfo+"'";
		}
		else if(m_Type.GetCurSel()==2)
		{
			cSql += " and MediStore.MediId = '"+m_ChooseInfo+"'";
		}
		else if(m_Type.GetCurSel()==3)
		{
			cSql += " and MediStore.SalerId = '"+m_ChooseInfo+"'";
		}
		else if(m_Type.GetCurSel()==4)
		{
			/*int    a,b,c    ;   
			sscanf(m_ChooseInfo.GetBuffer(m_ChooseInfo.GetLength()),"%d-%d-%d",&a,&b,&c);   
			CTime    time(a,b,c,0,0,0); 

			CTime t;
			t.Format(m_ChooseInfo);
			CString s;
			s.Format(t);*/
			cSql += " and MediStore.InDate='"+m_ChooseInfo+"'";
		}
	}
	m_Adodc.SetRecordSource(cSql);
	m_Adodc.Refresh();

	// 设置列宽度
	_variant_t vIndex;
	//long将整数转换为_variant_t类型,从而可以在CColumns::GetItem()函数中使用
	vIndex = long(0);//药品编号
	m_DataGrid.GetColumns().GetItem(vIndex).SetWidth(60);
	//MessageBox(m_DataGrid.GetColumns().GetItem(vIndex));
	vIndex = long(0);
	m_DataGrid.GetColumns().GetItem(vIndex).SetWidth(60);
	vIndex = long(1);  
	m_DataGrid.GetColumns().GetItem(vIndex).SetWidth(60);
	vIndex = long(2); 
	m_DataGrid.GetColumns().GetItem(vIndex).SetWidth(60);
	vIndex = long(3); 
	m_DataGrid.GetColumns().GetItem(vIndex).SetWidth(60);
	vIndex = long(4); 
	m_DataGrid.GetColumns().GetItem(vIndex).SetWidth(60);
	vIndex = long(5); 
	m_DataGrid.GetColumns().GetItem(vIndex).SetWidth(60);
	vIndex = long(6); 
	m_DataGrid.GetColumns().GetItem(vIndex).SetWidth(60);
	vIndex = long(7);  
	m_DataGrid.GetColumns().GetItem(vIndex).SetWidth(60);
	vIndex = long(8); 
	m_DataGrid.GetColumns().GetItem(vIndex).SetWidth(60);
	vIndex = long(9);  
	m_DataGrid.GetColumns().GetItem(vIndex).SetWidth(60);
	vIndex = long(10);  
	m_DataGrid.GetColumns().GetItem(vIndex).SetWidth(60);
}

void CMediFind::OnLikeFind() 
{
	// TODO: Add your control notification handler code here
	/*全部
	按药名
	按药品编号
	按销售商编号
	按生产日期*/
	UpdateData(TRUE);
	CString cSql;
	cSql = "select  MediStore.MediId as'药品编号',MediInfo.MediName as";
	cSql+="'药品名称',MediInfo.Short as'药品简称', MediInfo.MediPrice as ";
	cSql+="'售价',MediInfo.Unit as'单位', MediStore.InAmout as";
	cSql+="'库存量',MediInfo.VipDisc as'VIP折扣(%)', MediStore.InDate as";
	cSql+="'生产日期',MediInfo.LastDate as'过期日期',MediStore.SalerId as";
	cSql+="'销售商编号',MediInfo.LeastAmout as";//,MediInfo.Short as'药品简码'
	cSql+="'库存下限', MediInfo.Detail as";
	cSql+="'详细说明'from MediStore,MediInfo where MediStore.MediId=MediInfo.MediId";
	if(m_ChooseInfo!="")
	{
		if(m_Type.GetCurSel()==1)
		{
			cSql += " and MediInfo.MediName like '%"+m_ChooseInfo+"%'";
		}
		else if(m_Type.GetCurSel()==2)
		{
			cSql += " and MediStore.MediId like '%"+m_ChooseInfo+"%'";
		}
		else if(m_Type.GetCurSel()==3)
		{
			cSql += " and MediStore.SalerId like '%"+m_ChooseInfo+"%'";
		}
		else if(m_Type.GetCurSel()==4)//巧妙运用类型转换,实现模糊查找
		{
			int i=atoi(m_ChooseInfo);//先将字符换成整形,只找字符串中第一个连续的数字字符串
			CString s;
			s.Format("%d",i);//再换为字符串,删除了其中的非数字符,用于sql查询
			//cSql += " where year(MadeDate)='"+m_ChooseInfo+"' or month(MadeDate)='"+m_ChooseInfo;
			//cSql+="' or day(MadeDate)='"+m_ChooseInfo+"'";
			cSql += " and year(MediStore.InDate)='"+s+"' or month(MediStore.InDate)='"+s;
			cSql+="' or day(MediStore.InDate)='"+s+"'";
		}
	}
	m_Adodc.SetRecordSource(cSql);
	m_Adodc.Refresh();

	// 设置列宽度
	_variant_t vIndex;
	//long将整数转换为_variant_t类型,从而可以在CColumns::GetItem()函数中使用
	vIndex = long(0);//药品编号
	m_DataGrid.GetColumns().GetItem(vIndex).SetWidth(60);
	//MessageBox(m_DataGrid.GetColumns().GetItem(vIndex));
	vIndex = long(0);
	m_DataGrid.GetColumns().GetItem(vIndex).SetWidth(60);
	vIndex = long(1);  
	m_DataGrid.GetColumns().GetItem(vIndex).SetWidth(60);
	vIndex = long(2); 
	m_DataGrid.GetColumns().GetItem(vIndex).SetWidth(60);
	vIndex = long(3); 
	m_DataGrid.GetColumns().GetItem(vIndex).SetWidth(60);
	vIndex = long(4); 
	m_DataGrid.GetColumns().GetItem(vIndex).SetWidth(60);
	vIndex = long(5); 
	m_DataGrid.GetColumns().GetItem(vIndex).SetWidth(60);
	vIndex = long(6); 
	m_DataGrid.GetColumns().GetItem(vIndex).SetWidth(60);
	vIndex = long(7);  
	m_DataGrid.GetColumns().GetItem(vIndex).SetWidth(60);
	vIndex = long(8); 
	m_DataGrid.GetColumns().GetItem(vIndex).SetWidth(60);
	vIndex = long(9);  
	m_DataGrid.GetColumns().GetItem(vIndex).SetWidth(60);
	vIndex = long(10);  
	m_DataGrid.GetColumns().GetItem(vIndex).SetWidth(60);
}

⌨️ 快捷键说明

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