📄 medisale.cpp
字号:
// MediSale.cpp : implementation file
//
#include "stdafx.h"
#include "medicine.h"
#include "MediSale.h"
#include "MainFrame.h"
#include "MediInfo.h"
#include "_recordset.h"
#include "columns.h"
#include "column.h"
#include "COMDEF.H"
#include "User.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMediSale dialog
CMediSale::CMediSale(CWnd* pParent /*=NULL*/)
: CDialog(CMediSale::IDD, pParent)
{
//{{AFX_DATA_INIT(CMediSale)
m_AllPrice = 0.0f;
m_Amout = 0.0f;
m_VipDisc = 0.0f;
m_ChooseInfo = _T("");
m_Pay = 0.0f;
m_MediName = _T("");
m_SaleId = _T("");
m_WorkNo = _T("");
m_MediId = _T("");
//}}AFX_DATA_INIT
}
void CMediSale::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMediSale)
DDX_Control(pDX, IDC_CUSETOMTYPE, m_CustomType);
DDX_Control(pDX, IDC_FINDTYPE, m_FindType);
DDX_Control(pDX, IDC_PAYTYPE, m_PayType);
DDX_Control(pDX, IDC_ADODC1, m_Adodc);
DDX_Text(pDX, IDC_ALLPRICE, m_AllPrice);
DDX_Text(pDX, IDC_AMOUT, m_Amout);
DDX_Control(pDX, IDC_DATAGRID1, m_DataGrid);
DDX_Text(pDX, IDC_VIPDISC, m_VipDisc);
DDX_Text(pDX, IDC_FINDINFO, m_ChooseInfo);
DDX_Text(pDX, IDC_PAY, m_Pay);
DDX_Text(pDX, IDC_MEDINAME, m_MediName);
DDX_Text(pDX, IDC_SALEID, m_SaleId);
DDX_Text(pDX, IDC_WORKNO, m_WorkNo);
DDX_Text(pDX, IDC_MEDIID, m_MediId);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMediSale, CDialog)
//{{AFX_MSG_MAP(CMediSale)
ON_BN_CLICKED(IDC_EXACTFIND, OnExactFind)
ON_BN_CLICKED(IDC_LIKEFIND, OnLikeFind)
ON_BN_CLICKED(IDC_OK, OnOk)
ON_BN_CLICKED(IDC_FRESH, OnFresh)
ON_BN_CLICKED(IDC_BACK, OnBack)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMediSale message handlers
int CMediSale::DoModal()
{
// TODO: Add your specialized code here and/or call the base class
return CDialog::DoModal();
}
BOOL CMediSale::OnInitDialog()
{
CDialog::OnInitDialog();
m_FindType.SetCurSel(0);
m_PayType.SetCurSel(0);
m_CustomType.SetCurSel(0);
flag=0;
m_Amout=0;
m_WorkNo=glUser.WorkNo;
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 CMediSale::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 CMediSale::OnExactFind()
{
// 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_FindType.GetCurSel()==1)
{
cSql += " and MediInfo.MediName ='"+m_ChooseInfo+"'";
}
else if(m_FindType.GetCurSel()==2)
{
cSql += " and MediStore.MediId = '"+m_ChooseInfo+"'";
}
else if(m_FindType.GetCurSel()==3)
{
cSql += " and MediStore.SalerId = '"+m_ChooseInfo+"'";
}
else if(m_FindType.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 CMediSale::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_FindType.GetCurSel()==1)
{
cSql += " and MediInfo.MediName like '%"+m_ChooseInfo+"%'";
}
else if(m_FindType.GetCurSel()==2)
{
cSql += " and MediStore.MediId like '%"+m_ChooseInfo+"%'";
}
else if(m_FindType.GetCurSel()==3)
{
cSql += " and MediStore.SalerId like '%"+m_ChooseInfo+"%'";
}
else if(m_FindType.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);
}
BEGIN_EVENTSINK_MAP(CMediSale, CDialog)
//{{AFX_EVENTSINK_MAP(CMediSale)
ON_EVENT(CMediSale, IDC_DATAGRID1, -601 /* DblClick */, OnDblClickDataGrid, VTS_NONE)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
void CMediSale::OnDblClickDataGrid()
{
// TODO: Add your control notification handler code here
UpdateData(true);
if(m_Adodc.GetRecordset().GetEof()==1)
{
MessageBox("没有数据");
return;
}
CString sRecord;
CString s_InDate,s_LastDate,s_MediNo,s_Name,s_Unit,s_SalerId,s_InPrice,s_SalePrice,s_InAmout;
//将字符转换为CTime类型
float salePrice;
//if(flag==0)
//{
m_VipDisc= atof(m_DataGrid.GetItem(6));
//}
m_MediId=m_DataGrid.GetItem(0);
if(m_CustomType.GetCurSel()==0)
{
m_VipDisc= 100;
salePrice=atof(m_DataGrid.GetItem(3));
m_AllPrice=m_Amout*salePrice;
}
else
{
salePrice=atof(m_DataGrid.GetItem(3))*(0.01*m_VipDisc);
//CString test;
//test.Format("%f",salePrice);
//MessageBox(test);
m_AllPrice=m_Amout*salePrice;
}
m_MediName= m_DataGrid.GetItem(1);
CTime cTime=CTime::GetCurrentTime();
m_SaleId=cTime.Format("%Y-%m-%d-%H-%M-%S");
flag=1;
UpdateData(FALSE);
}
void CMediSale::OnOk()
{
// TODO: Add your control notification handler code here
/*CString SaleId,SaleDate;
float MediAmout;
int PayType;
//MediId, WorkNo,VipDisc*/
UpdateData(true);
CMediInfo mi;
mi.SaleId=m_SaleId;
float salePrice=atof(m_DataGrid.GetItem(3));
CTime cTime=CTime::GetCurrentTime();
mi.SaleDate=cTime.Format("%Y-%m-%d");
mi.MediAmout=m_Amout;//可能出现数据不一致
mi.PayType=m_PayType.GetCurSel();
mi.MediId=m_MediId;
mi.WorkNo=glUser.WorkNo;
//UpdateData(false);
mi.VipDisc=m_VipDisc;
CString s;
s.Format("%f",m_VipDisc);
MessageBox(s);
if(0.01*m_VipDisc*salePrice*m_Amout==m_Pay)
{
mi.sql_insertSale();
MessageBox("购买成功!");
}
else
{
MessageBox("请正确付款!");
return;
}
RefreshData();
}
void CMediSale::OnFresh()
{
// TODO: Add your control notification handler code here
UpdateData(true);
float salePrice=atof(m_DataGrid.GetItem(3));
m_AllPrice=0.01*m_VipDisc*salePrice*m_Amout;
UpdateData(FALSE);
}
void CMediSale::OnBack()
{
// TODO: Add your control notification handler code here
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -