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

📄 medicinesalemanagesdlg.cpp

📁 一个简易的医药销售管理系统源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
			if(!(str1.IsEmpty()))
				m_unit.SetCurSel(m_unit.FindString(0,str1.Right(2)));
		}
		else
			SetDlgItemText(IDC_STATICMONEYTEXT,_T("¥error"));
		m_pRecordset->Close();
	}
	m_pRecordset=NULL;
}

void CMedicineSaleManagesDlg::OnEnKillfocusMoney()//自动将单价转换为浮点数
{
	CString stri,strf;
	GetDlgItemText(IDC_MONEY,stri);
	//校验数据的有效性
	if(!theApp.Examination(stri))
	{
		AfxMessageBox(_T("输入单价错误!"));
		SetDlgItemText(IDC_MONEY,_T(""));
		GotoDlgCtrl(GetDlgItem(IDC_MONEY));
		return;
	}
	//校验结束
	strf.Format("%f",atof(stri));
	SetDlgItemText(IDC_MONEY,strf.Left(strf.Find('.',0)+1)+strf.Mid(strf.Find('.',0)+1,3));
}

void CMedicineSaleManagesDlg::OnBnClickedRecordsave()//销售记录存盘
{
	CString mac=_T("");
	if(modify_record)
	{
		CString message=_T("将要修改如下数据,是否继续?若在下次修改,请重新右击对应条目!\r\n销售时间:");
		message+=m_list1.GetItemText(modify_row,0);
		message+=_T("\r\n药品名称:");
		mac=m_list1.GetItemText(modify_row,1);
		message+=mac;
		if(AfxMessageBox(message,MB_YESNO|MB_ICONQUESTION)==IDNO)
		{
			modify_record=FALSE;
			ClsCtrl();
			return;
		}
	}
	theApp.BeginWaitCursor();
	OnEnKillfocusMoney();
	m_progress1.SetRange(0,19);
	m_progress1.SetStep(1);
	m_progress1.StepIt();
	CString str1,str2,str3,str4,str5,str6,str7;
	str1=str2=str3=str4=str5=str6=str7=_T("");
	if(m_name.GetCurSel()!=-1)
		m_name.GetLBText(m_name.GetCurSel(),str1);
	else
	{
		theApp.EndWaitCursor();
		AfxMessageBox("请录入药品名称!");
		GotoDlgCtrl(GetDlgItem(IDC_NAME));
		m_progress1.SetPos(0);
		return;
	}
	if(m_fication.GetCurSel()!=-1)
		m_fication.GetLBText(m_fication.GetCurSel(),str2);
	if(m_factory.GetCurSel()!=-1)
		m_factory.GetLBText(m_factory.GetCurSel(),str3);
	GetDlgItemText(IDC_MONEY,str4);
	if(str4.IsEmpty())
	{
		theApp.EndWaitCursor();
		AfxMessageBox("请录入药品单价!");
		GotoDlgCtrl(GetDlgItem(IDC_MONEY));
		m_progress1.SetPos(0);
		return;
	}
	if(!theApp.Examination(str4) || atof(str4)<=0.0)
	{
		theApp.EndWaitCursor();
		AfxMessageBox("单价值可能有误,请检查!");
		GotoDlgCtrl(GetDlgItem(IDC_MONEY));
		m_progress1.SetPos(0);
		return;
	}
	if(m_number.GetCurSel()!=-1)
		m_number.GetLBText(m_number.GetCurSel(),str5);
	else
	{
		theApp.EndWaitCursor();
		AfxMessageBox("请录入药品数量!");
		GotoDlgCtrl(GetDlgItem(IDC_NUMBER));
		m_progress1.SetPos(0);
		return;
	}
	if(m_unit.GetCurSel()!=-1)
		m_unit.GetLBText(m_unit.GetCurSel(),str6);
	else
	{
		theApp.EndWaitCursor();
		AfxMessageBox("请录入药品单位!");
		GotoDlgCtrl(GetDlgItem(IDC_UNIT));
		m_progress1.SetPos(0);
		return;
	}
	CString strmoney1,strmoney2;
	GetDlgItemText(IDC_MONEY,strmoney1);
	GetDlgItemText(IDC_STATICMONEYTEXT,strmoney2);
	if(atof(strmoney1)<atof(strmoney2.Right(strmoney2.GetLength()-2)))
		if(AfxMessageBox("售出价格小于进货价格,是否继续?",MB_YESNO|MB_ICONQUESTION)==IDNO)
		{
			theApp.EndWaitCursor();
			m_progress1.SetPos(0);
			return;
		}
	if(m_readem.GetCurSel()!=-1)
		m_readem.GetLBText(m_readem.GetCurSel(),str7);
	m_progress1.StepIt();
	CString strSQL,str00,str01,str02,str03,str04,str05,str06;
	strSQL=str00=str01=str02=str03=str04=str05=str06=_T("");
	strSQL="select product_id,serial_number,permitcode from products WHERE name='"+str1+"'";//找出编号,条形码,批准文号
	strSQL+=" and standard='"+str2+"'";
	strSQL+=" and makearea='"+str3+"'";
	HRESULT hTRes;
	hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
	if (SUCCEEDED(hTRes))
	{
		hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(strSQL.GetLength()+1),
				((CMedicineSaleManagesApp*)AfxGetApp())->m_pConn1.GetInterfacePtr(),
				adOpenDynamic,adLockPessimistic,adCmdText);
		if(!m_pRecordset->adoEOF)
		{
			str00=(LPCSTR)_bstr_t(m_pRecordset->GetCollect("product_id"));
			str01=(LPCSTR)_bstr_t(m_pRecordset->GetCollect("serial_number"));
			str02=(LPCSTR)_bstr_t(m_pRecordset->GetCollect("permitcode"));
		}
		m_pRecordset->Close();
	}
	strSQL="select * from products,productdetail WHERE products.name='"+str1+"'";//找出生产批号,生产日期,有效期
	strSQL+=" and products.standard='"+str2+"'";
	strSQL+=" and  products.makearea='"+str3+"'";
	strSQL+=" and  products.product_id=productdetail.p_id";
	if (SUCCEEDED(hTRes))
	{
		hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(strSQL.GetLength()+1),
				((CMedicineSaleManagesApp*)AfxGetApp())->m_pConn1.GetInterfacePtr(),
				adOpenDynamic,adLockPessimistic,adCmdText);
		if(!m_pRecordset->adoEOF)
		{
			str03=(LPCSTR)_bstr_t(m_pRecordset->GetCollect("batchno"));
			str04=(LPCSTR)_bstr_t(m_pRecordset->GetCollect("makedate"));
			str05=(LPCSTR)_bstr_t(m_pRecordset->GetCollect("validdate"));
		}
		m_pRecordset->Close();
	}
	CString date;
	if(modify_record)
		date=m_list1.GetItemText(modify_row,0);
	else
	{
		CTime t=CTime::GetCurrentTime(); //获得当前的系统时间
		date=t.Format("%Y年%m月%d日%H时%M分%S秒"); //格式可以参考MSDN中的strftime函数
	}
	m_progress1.StepIt();
	if(str04.IsEmpty())
		str04=_T("1900-01-01");
	if(str05.IsEmpty())
		str05=_T("1900-01-01");
	int row=0;
	if(modify_record)
	{
		row=modify_row;
		m_list1.SetItemText(row,0,date);
	}
	else
	{
		row=m_list1.GetItemCount();
		m_list1.InsertItem(row,date);
	}
	m_list1.SetItemText(row,1,str1);
	m_list1.SetItemText(row,2,str00);
	m_list1.SetItemText(row,3,str01);
	m_list1.SetItemText(row,4,str2);
	m_list1.SetItemText(row,5,str02);
	m_list1.SetItemText(row,6,str3);
	m_list1.SetItemText(row,7,str03);
	m_list1.SetItemText(row,8,str04);
	m_list1.SetItemText(row,9,str05);
	m_list1.SetItemText(row,10,str4);
	m_list1.SetItemText(row,11,str5);
	m_list1.SetItemText(row,12,str6);
	str06=theApp.GetIntNumber(atof(str4)*atof(str5));
	m_list1.SetItemText(row,13,str06.Left(str06.Find('.',0)+1)+str06.Mid(str06.Find('.',0)+1,2));
	m_list1.SetItemText(row,14,str7);
	CRect rect;
	m_list1.GetClientRect(rect);
	m_list1.Scroll(CSize(0,rect.Height()*row));
	if(modify_record)
	{
		strSQL="update saledata set ";
		m_progress1.StepIt();
		strSQL=strSQL+"saledate='"+date+"',";
		m_progress1.StepIt();
		strSQL=strSQL+"medicine_name='"+str1+"',";
		m_progress1.StepIt();
		strSQL=strSQL+"serial='"+str00+"',";
		m_progress1.StepIt();
		strSQL=strSQL+"bar_code='"+str01+"',";
		m_progress1.StepIt();
		strSQL=strSQL+"specifications='"+str2+"',";
		m_progress1.StepIt();
		strSQL=strSQL+"sanction='"+str02+"',";
		m_progress1.StepIt();
		strSQL=strSQL+"manufacture='"+str3+"',";
		m_progress1.StepIt();
		strSQL=strSQL+"batch_number='"+str03+"',";
		m_progress1.StepIt();
		strSQL=strSQL+"makedate=#"+str04+"#,";
		m_progress1.StepIt();
		strSQL=strSQL+"validity=#"+str05+"#,";
		m_progress1.StepIt();
		strSQL=strSQL+"price="+str4+",";
		m_progress1.StepIt();
		strSQL=strSQL+"quantity="+str5+",";
		m_progress1.StepIt();
		strSQL=strSQL+"unit='"+str6+"',";
		m_progress1.StepIt();
		strSQL=strSQL+"total="+m_list1.GetItemText(row,13)+",";
		strSQL=strSQL+"readem='"+str7+"'";
		strSQL=strSQL+" where saledate='";
		m_progress1.StepIt();
		strSQL=strSQL+date+"'";
		strSQL=strSQL+" AND medicine_name='";
		strSQL=strSQL+mac+"'";
		(((CMedicineSaleManagesApp*)AfxGetApp())->m_pConn1)->Execute((_bstr_t)strSQL,NULL,adCmdText);
	}
	else
	{
		strSQL="select * from saledata";
		m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(strSQL.GetLength()+1),((CMedicineSaleManagesApp*)AfxGetApp())->m_pConn1.GetInterfacePtr(),adOpenDynamic,adLockPessimistic,adCmdText);
		m_pRecordset->AddNew();
		m_pRecordset->PutCollect("saledate",_variant_t(date));
		m_progress1.StepIt();
		m_pRecordset->PutCollect("medicine_name",_variant_t(str1));
		m_progress1.StepIt();
		m_pRecordset->PutCollect("serial",_variant_t(str00));
		m_progress1.StepIt();
		m_pRecordset->PutCollect("bar_code",_variant_t(str01));
		m_progress1.StepIt();
		m_pRecordset->PutCollect("specifications",_variant_t(str2));
		m_progress1.StepIt();
		m_pRecordset->PutCollect("sanction",_variant_t(str02));
		m_progress1.StepIt();
		m_pRecordset->PutCollect("manufacture",_variant_t(str3));
		m_progress1.StepIt();
		m_pRecordset->PutCollect("batch_number",_variant_t(str03));
		m_progress1.StepIt();
		m_pRecordset->PutCollect("makedate",_variant_t(str04));
		m_progress1.StepIt();
		m_pRecordset->PutCollect("validity",_variant_t(str05));
		m_progress1.StepIt();
		m_pRecordset->PutCollect("price",_variant_t(str4));
		m_progress1.StepIt();
		m_pRecordset->PutCollect("quantity",_variant_t(str5));
		m_progress1.StepIt();
		m_pRecordset->PutCollect("unit",_variant_t(str6));
		m_progress1.StepIt();
		m_pRecordset->PutCollect("total",_variant_t(m_list1.GetItemText(row,13)));
		m_progress1.StepIt();
		m_pRecordset->PutCollect("readem",_variant_t(str7));
		m_progress1.StepIt();
		m_pRecordset->Update();
		m_pRecordset->Close();
		m_pRecordset=NULL;
	}
	m_progress1.StepIt();
	ClsCtrl();
	modify_record=FALSE;
	if(!theApp.excel_type.IsEmpty())
		GetTotal(theApp.strSQLpublic);
	theApp.EndWaitCursor();
	GotoDlgCtrl(GetDlgItem(IDC_FINDNAME));
}

void CMedicineSaleManagesDlg::OnBnClickedRecordinputoutexcel()//将记录导出为EXCEL文件并打开
{
	if(m_list1.GetItemCount()<1)
	{
		AfxMessageBox("当前没有销售记录,无数据可导出!");
		return;
	}
	else
	{
		CString Directory="";
		LPMALLOC lpMalloc;
		CHAR szDisplayName[MAX_PATH];
		CHAR szBuffer[MAX_PATH];
		if ( ::SHGetMalloc( &lpMalloc ) != NOERROR )
		{
			AfxMessageBox( "执行路径错误,请退出后重试!" );
			return;
		}
		BROWSEINFO BrowseInfo;
		ZeroMemory(&BrowseInfo,sizeof(BROWSEINFO));
		BrowseInfo.hwndOwner      = GetSafeHwnd();
		BrowseInfo.pidlRoot       = NULL;
		BrowseInfo.pszDisplayName = szDisplayName;
		BrowseInfo.lpszTitle      = "==== 选择存放导出文件的位置后单击[确定]按钮 ====";
		BrowseInfo.ulFlags        = BIF_USENEWUI;
		BrowseInfo.lpfn           = NULL;
		BrowseInfo.lParam         = 0;
		LPITEMIDLIST lpItemIDList;
		if ( ( lpItemIDList = ::SHBrowseForFolder( &BrowseInfo ) ) != NULL )
		{
			if ( ::SHGetPathFromIDList( lpItemIDList, szBuffer ) )
			{
				if ( szBuffer[0] == '\0' )
					AfxMessageBox( "无效路径,重新选择!");
				Directory = szBuffer;
			}
			else
				AfxMessageBox( "无效路径,请重新选择!");
			lpMalloc->Free( lpItemIDList );
			lpMalloc->Release();
			if(Directory.GetLength()>=1)
			{
				if(Directory.GetLength()>3)
					Directory+="\\";
				CTime t=CTime::GetCurrentTime();
				CString filename=t.Format("%Y年%m月%d日");
				filename+=_T("销售记录表.xls");
				CString strPath=Directory+filename;
				filename+=_T("\r\n\t工作表标签名:\r\n\t\t");
				filename+=_T("当日销售记录表");
				CString message=_T("请在确认以下信息后单击[是]按钮开始导出数据!!!\r\n");
				message+="\r\n\t导出Excel文件至:\r\n\t\t";
				message+=Directory;
				message+="\r\n\t导出Excel文件名:\r\n\t\t";
				message+=filename;
				if(AfxMessageBox(message,MB_YESNO|MB_ICONQUESTION)==IDYES)
				{
					if(theApp.MyGetDiskFreeSpace(Directory.Left(3))<3145728)
					{
						AfxMessageBox("目标磁盘空间太小,不能完成导出!");
						return;

⌨️ 快捷键说明

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