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

📄 medistore.cpp

📁 一个VC写的药品管理系统
💻 CPP
📖 第 1 页 / 共 2 页
字号:
			cSql += " and MediStore.SalerId like '%"+m_ChooseInfo+"%'";
		}
		else if(m_ChooseType.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+"'";*/
			MessageBox("无法对日期进行模糊查找");
		}
	}
	m_Adodc.SetRecordSource(cSql);
	m_Adodc.Refresh();

	// 设置列宽度
	_variant_t vIndex;
	//long将整数转换为_variant_t类型,从而可以在CColumns::GetItem()函数中使用
	vIndex = long(0);//药品编号
	m_DataGridChoose.GetColumns().GetItem(vIndex).SetWidth(60);
	vIndex = long(1);  //药品名称
	m_DataGridChoose.GetColumns().GetItem(vIndex).SetWidth(60);
	vIndex = long(2);  //药品简称
	m_DataGridChoose.GetColumns().GetItem(vIndex).SetWidth(60);
	vIndex = long(3);  //售价
	m_DataGridChoose.GetColumns().GetItem(vIndex).SetWidth(60);
	vIndex = long(4);  //进价
	m_DataGridChoose.GetColumns().GetItem(vIndex).SetWidth(60);
	vIndex = long(5);  //单位
	m_DataGridChoose.GetColumns().GetItem(vIndex).SetWidth(60);
	vIndex = long(6); //库存量
	m_DataGridChoose.GetColumns().GetItem(vIndex).SetWidth(60);
	vIndex = long(7);  //VIP折扣(%)
	m_DataGridChoose.GetColumns().GetItem(vIndex).SetWidth(60);
	vIndex = long(8);  //生产日期
	m_DataGridChoose.GetColumns().GetItem(vIndex).SetWidth(60);
	vIndex = long(9);  //过期日期
	m_DataGridChoose.GetColumns().GetItem(vIndex).SetWidth(60);
	vIndex = long(10);  //销售商编号
	m_DataGridChoose.GetColumns().GetItem(vIndex).SetWidth(60);
	vIndex = long(11); //库存下限
	m_DataGridChoose.GetColumns().GetItem(vIndex).SetWidth(60);
	vIndex = long(12); //详细说明
	m_DataGridChoose.GetColumns().GetItem(vIndex).SetWidth(100);

}

void CMediStore::OnDblClickDatagridChoose() 
{
	// TODO: Add your control notification handler code here
	if(m_Adodc.GetRecordset().GetEof()==1)
	{
		MessageBox("没有数据");
		return;
	}
	CString sRecord;
	//sRecord=m_DataGridChoose.GetItem(0)+m_DataGridChoose.GetItem(0)+m_DataGridChoose.GetItem(0);
	//MessageBox(sRecord);
	CString s_InDate,s_LastDate,s_MediNo,s_Name,s_Unit,s_SalerId,s_InPrice,s_SalePrice,s_InAmout;
	s_InDate=m_DataGridChoose.GetItem(8);//获取进药日期
	s_LastDate=m_DataGridChoose.GetItem(9);//获取过期日期
	//将字符转换为CTime类型
	int    y,m,d    ;
	sscanf(s_InDate.GetBuffer(s_InDate.GetLength()),"%d-%d-%d",&y,&m,&d);   
	CTime    itime(y,m,d,0,0,0);  
	m_InDate=itime;
	sscanf(s_LastDate.GetBuffer(s_LastDate.GetLength()),"%d-%d-%d",&y,&m,&d);   
	CTime    ltime(y,m,d,0,0,0);  
	m_LastDate=ltime;

	m_MediNo = m_DataGridChoose.GetItem(0);
	m_Name = m_DataGridChoose.GetItem(1);
	m_Unit = m_DataGridChoose.GetItem(5);
	m_SalerId =m_DataGridChoose.GetItem(10);
	m_InPrice = atof(m_DataGridChoose.GetItem(4));
	m_SalePrice = atof(m_DataGridChoose.GetItem(3));
	m_InAmout = 0;
	//m_StoreAmout=atof(m_DataGridChoose.GetItem(5));
	UpdateData(FALSE);
}

/*void CMediStore::OnEdit() 
{
	// TODO: Add your control notification handler code here
	if (m_Adodc.GetRecordset().GetEof()) 
	{
		MessageBox("请选择要修改的数据");
		return;
	}
	CMediInfoEdit dlg;
	/*m_LeastAmout = 0.0f;
	m_MediId = _T("");
	m_Name = _T("");
	m_Short = _T("");
	m_VipDisc = 0.0f;
	m_AllAmout = 0.0f;*/
/*	dlg.m_MediId=m_DataGridChoose.GetItem(0);
	dlg.m_Name=m_DataGridChoose.GetItem(1);
	dlg.m_Short=m_DataGridChoose.GetItem(2);
	dlg.m_AllAmout=atof(m_DataGridChoose.GetItem(6));
	dlg.m_VipDisc=atof(m_DataGridChoose.GetItem(7));
	dlg.DoModal();
}*/



void CMediStore::OnChange() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	CMediInfo mi;
	mi.InPrice=m_InPrice;
    mi.InAmout=m_InAmout;
	mi.InDate=m_InDate.Format("%Y-%m-%d");//化时间类型为CString类型
	//CString test;
	//test.Format("%f",m_InAmout); 
	//MessageBox(mi.InDate);
	mi.MediPrice=m_SalePrice;
	mi.LastDate=m_LastDate.Format("%Y-%m-%d");
	mi.SalerId=m_SalerId;
	mi.MediId=m_MediNo;
	mi.MediName=m_Name;
	mi.Unit=m_Unit;
	mi.Short=m_Short;

	if((m_MediNo!="")&&(mi.SalerId!=""))
	{	
	    if(mi.HaveMedi(m_MediNo)==-1)
		{
			MessageBox("不存在这样的药品");
			return;
		}
		else
		{
			mi.GetData(m_MediNo);
			mi.InPrice=m_InPrice;
			mi.InAmout=m_InAmout;
			mi.InDate=m_InDate.Format("%Y-%m-%d");//化时间类型为CString类型
			mi.MediPrice=m_SalePrice;
			mi.LastDate=m_LastDate.Format("%Y-%m-%d");
			mi.SalerId=m_SalerId;
			mi.MediId=m_MediNo;
			mi.MediName=m_Name;
			mi.Unit=m_Unit;
			mi.Short=m_Short;
			mi.sql_updata();
		}
	}
	else
	{
		MessageBox("请完整信息!");
		return;
	}
	RefreshData();
}


/*	//入库记录
	float InPrice,InAmout;
	CString InDate,WorkNo,SalerId;

	//药品信息
	CString MediName,Short,Unit;
	float MediPrice,LeastAmout, AllAmout,VipDisc;
	CString LastDate,Detail;*/
void CMediStore::OnAdd() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	CMediInfo mi;
	if((m_MediNo!="")&&(m_MediNo!=""))
	{	
		mi.MediId=m_MediNo;
		mi.InDate=m_InDate.Format("%Y-%m-%d");//化时间类型为CString类型
		if(mi.HaveMedi(m_MediNo)==-1)//新购入记录
		{

			if(mi.MediHaveMedi(m_MediNo)==1)//药品库里有
			{
				mi.GetDataMedi(m_MediNo);
				mi.GetData(m_MediNo);
				mi.AllAmout=mi.AllAmout+m_InAmout;
				mi.InAmout=m_InAmout;//库存刚开始为0
				mi.InPrice=m_InPrice;//进价可调	
				mi.MediPrice=m_SalePrice;
				CString test;
				test.Format("%f",mi.InAmout); 
				MessageBox(test);
				//mi.LastDate=m_LastDate.Format("%Y-%m-%d");
				mi.sql_updataMedi();//修改药品信息
				mi.sql_insert();
			}
			else//药品库里没有
			{
				mi.GetData(m_MediNo);
				mi.InPrice=m_InPrice;
				mi.InAmout=m_InAmout;
				mi.AllAmout=m_InAmout;
				mi.InDate=m_InDate.Format("%Y-%m-%d");//化时间类型为CString类型
				mi.LastDate=m_LastDate.Format("%Y-%m-%d");	
				mi.SalerId=m_SalerId;	
				mi.MediName=m_Name;
				mi.Short=m_Short;
				mi.Unit=m_Unit;
				mi.Detail="未添加";
				mi.LeastAmout=0;
				mi.VipDisc=100;
				mi.MediPrice=m_SalePrice;
				mi.sql_insert();
				mi.sql_insertMedi();
			}
		}
		else//库存记录里有的药品
		{
			mi.GetData(m_MediNo);
			mi.InAmout+=m_InAmout;
			mi.sql_updata();
			//MessageBox(mi.InAmout);
		}
	}
	else
	{
		MessageBox("请完整信息!");
		return;
	}
	RefreshData();
}

void CMediStore::OnNewStore() 
{
	// TODO: Add your control notification handler code here
	m_MediNo = _T("");
	m_Name = _T("");
	m_Unit = _T("");
	m_SalerId = _T("");
	m_Short=_T("");
	m_InPrice = 0.0f;
	m_SalePrice = 0.0f;
	m_InAmout = 0.0f;
	UpdateData(FALSE);
}



BEGIN_EVENTSINK_MAP(CMediStore, CDialog)
    //{{AFX_EVENTSINK_MAP(CMediStore)
	ON_EVENT(CMediStore, IDC_DATAGRIDCHOOSE, -601 /* DblClick */, OnDblClickDatagridChoose, VTS_NONE)
	//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()


void CMediStore::OnChangeMedi() 
{
	// TODO: Add your control notification handler code here
	CMediInfoEdit dlg;
	dlg.m_MediId=m_DataGridChoose.GetItem(0);
	CMediInfo mi;
	mi.sql_getAllAmout(dlg.m_MediId);
	//dlg.m_AllAmout=
	/*	m_LeastAmout = 0.0f;
	m_MediId = _T("");
	m_Name = _T("");
	m_Short = _T("");
	m_VipDisc = 0.0f;
	m_AllAmout = 0.0f;*/
	dlg.m_LeastAmout=(atof(m_DataGridChoose.GetItem(11)));
	dlg.m_Name=m_DataGridChoose.GetItem(1);
	dlg.m_Short=m_DataGridChoose.GetItem(2);
	dlg.m_VipDisc=(atof(m_DataGridChoose.GetItem(7)));
	dlg.m_AllAmout=mi.AllAmout;
	dlg.m_Other=m_DataGridChoose.GetItem(12);
	if(dlg.DoModal()==IDOK)//跳回后更新信息
		RefreshData();	
}

⌨️ 快捷键说明

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