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

📄 mediedit.cpp

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

#include "stdafx.h"
#include "medicine.h"
#include "MediEdit.h"
#include "MediStore.h"
#include "MainFrame.h"
#include "MediInfo.h"
#include "_recordset.h"
#include "columns.h"
#include "column.h"
#include "COMDEF.H"
#include "MediInfoEdit.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMediEdit dialog


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


void CMediEdit::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMediEdit)
	DDX_Control(pDX, IDC_CHOOSECOMB, m_Type);
	DDX_Text(pDX, IDC_CHOOSEINFO, m_ChooseInfo);
	DDX_Control(pDX, IDC_ADODC1, m_Adodc);
	DDX_Control(pDX, IDC_DATAGRID1, m_DataGrid);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CMediEdit, CDialog)
	//{{AFX_MSG_MAP(CMediEdit)
	ON_BN_CLICKED(IDC_CHOOSE, OnExactChoose)
	ON_BN_CLICKED(IDC_SOMECHOOSE, OnSomeChoose)
	ON_BN_CLICKED(IDC_DELETE, OnDelete)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMediEdit message handlers

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

	if(m_ChooseInfo!="")
	{/*全部
按药名
按药品编号
按销售商编号
按生产日期
按药品简称*/
		if(m_Type.GetCurSel()==1)
		{
			cSql += " and MediName ='"+m_ChooseInfo+"'";
		}
		else if(m_Type.GetCurSel()==2)
		{
			cSql += " and MediId = '"+m_ChooseInfo+"'";
		}
		else if(m_Type.GetCurSel()==3)
		{
			cSql += " and 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 InDate='"+m_ChooseInfo+"'";
		}
		else if(m_Type.GetCurSel()==4)
		{
			cSql += " and Short='"+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);
	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(200);
}

void CMediEdit::OnSomeChoose() 
{
	// TODO: Add your control notification handler code here
	/*全部
	按药名
	按药品编号
	按销售商编号
	按生产日期*/
	UpdateData(TRUE);
	CString cSql;
	cSql = "select  MediId as'药品编号',MediName as";
	cSql+="'药品名称',Short as'药品简称',Unit as'单位', MediPrice as ";
	cSql+="'预售价',AllAmout as'总量',LeastAmout as";
	cSql+="'库存下限',VipDisc as'VIP折扣(%)', Detail as";
	cSql+="'详细说明'from MediInfo";
	if(m_ChooseInfo!="")
	{
		if(m_Type.GetCurSel()==1)
		{
			cSql += " and MediName like '%"+m_ChooseInfo+"%'";
		}
		else if(m_Type.GetCurSel()==2)
		{
			cSql += " and MediId like '%"+m_ChooseInfo+"%'";
		}
		else if(m_Type.GetCurSel()==3)
		{
			cSql += " and SalerId like '%"+m_ChooseInfo+"%'";
		}
		else if(m_Type.GetCurSel()==4)//巧妙运用类型转换,实现模糊查找
		{
			MessageBox("无法进行此查询");
			return;
		}
	}
	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(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(200);
}


void CMediEdit::RefreshData()
{
	UpdateData(TRUE);// 将控件上的信息及时更新到对应的变量
	CString cSql;
	cSql = "select  MediId as'药品编号',MediName as";
	cSql+="'药品名称',Short as'药品简称',Unit as'单位', MediPrice as ";
	cSql+="'预售价',AllAmout as'总量',LeastAmout as";
	cSql+="'库存下限',VipDisc as'VIP折扣(%)', Detail as";
	cSql+="'详细说明'from MediInfo";
	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);
	//MessageBox(m_DataGrid.GetColumns().GetItem(vIndex));
	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(200);

}

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



void CMediEdit::OnDelete() 
{
	// TODO: Add your control notification handler code here
	CMediInfo mi;
	if(atof(m_DataGrid.GetItem(5))>0)
	{
		MessageBox("还有库存,不能删除此字典!");
		return;
	}
	mi.sql_deleteMediInfo();
}

⌨️ 快捷键说明

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