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

📄 stockinput.cpp

📁 一个简易的医药销售管理系统源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	m_unit.SetCurSel(-1);
	SetDlgItemText(IDC_STOCKMONEY,_T(""));
	SetDlgItemText(IDC_STATICPRICE,_T(""));
	CString vaual1,vaual2,vaual3,str;
	CString strSQL;
	m_name.GetLBText(m_name.GetCurSel(),vaual1);
	m_spec.GetLBText(m_spec.GetCurSel(),vaual2);
	m_stockfactory.GetLBText(m_stockfactory.GetCurSel(),vaual3);
	strSQL="select permitcode from products WHERE name='"+vaual1+"'";
	strSQL+=" and standard='"+vaual2+"'";
	strSQL+=" and makearea='"+vaual3+"'";
	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);
		while(!(m_pRecordset->adoEOF))
		{
			str=(LPCSTR)_bstr_t(m_pRecordset->GetCollect("permitcode"));
			if(!str.IsEmpty())
				SetDlgItemText(IDC_APPROVALNUMBER,str);
			if(!(m_pRecordset->adoEOF))
				m_pRecordset->MoveNext();
		}
		m_pRecordset->Close();
	}
	strSQL="select price.retailprice from price,products WHERE products.name='"+vaual1+"'";
	strSQL+=" and products.standard='"+vaual2+"'";
	strSQL+=" and products.makearea='"+vaual3+"'";
	strSQL+=" and products.permitcode='"+str+"'";
	strSQL+=" and price.price_id=products.product_id";
	m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(strSQL.GetLength()+1),
			((CMedicineSaleManagesApp*)AfxGetApp())->m_pConn1.GetInterfacePtr(),
			adOpenDynamic,adLockPessimistic,adCmdText);
	if(!(m_pRecordset->adoEOF))
	{
		str=(LPCSTR)_bstr_t(m_pRecordset->GetCollect("retailprice"));
		if(!str.IsEmpty())
			SetDlgItemText(IDC_STATICPRICE,_T("¥")+str);
		else
			SetDlgItemText(IDC_STATICPRICE,_T("¥error"));
	}
	m_pRecordset->Close();
	GetDlgItemText(IDC_APPROVALNUMBER,str);
	strSQL="select name from unit where unit_id=(";
	strSQL+="select unit1_id from products WHERE name='"+vaual1+"'";
	strSQL+=" and standard='"+vaual2+"'";
	strSQL+=" and makearea='"+vaual3+"'";
	strSQL+=" and permitcode='"+str+"')";
	m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(strSQL.GetLength()+1),
			((CMedicineSaleManagesApp*)AfxGetApp())->m_pConn1.GetInterfacePtr(),
			adOpenDynamic,adLockPessimistic,adCmdText);
	if(!(m_pRecordset->adoEOF))
	{
		str=(LPCSTR)_bstr_t(m_pRecordset->GetCollect("name"));
		if(!str.IsEmpty())
			m_unit.SetCurSel(m_unit.FindString(0,str));
	}
	m_pRecordset->Close();
	m_pRecordset=NULL;
}

void CStockInput::OnBnClickedOk()//保存数据
{
	CString str0,str1,str2,str3,str4,str5,str6,str7,str8,str9,str10,str11,stra,strb,strc,strd,stre,strfa;
	str0=str1=str2=str3=str4=str5=str6=str7=str8=str9=str10=str11=stra=strb=strc=strd=stre=strfa=_T("");
	CTime t=CTime::GetCurrentTime();
	str0=t.Format("%Y-%m-%d");
	if(m_name.GetCurSel()>=0)
		m_name.GetLBText(m_name.GetCurSel(),str1);
	else
	{
		AfxMessageBox("必须录入药品名称!");
		GotoDlgCtrl(GetDlgItem(IDC_NAME));
		return;
	}
	if(m_spec.GetCurSel()>=0)
		m_spec.GetLBText(m_spec.GetCurSel(),str2);
	else
	{
		if(AfxMessageBox("该药品没有规格,是否继续?",MB_YESNO|MB_ICONQUESTION)==IDNO)
		{
			GotoDlgCtrl(GetDlgItem(IDC_SPEC));
			return;
		}
	}
	if(m_stockfactory.GetCurSel()>=0)
		m_stockfactory.GetLBText(m_stockfactory.GetCurSel(),str3);
	else
	{
		AfxMessageBox("必须录入药品的生产厂家!");
		GotoDlgCtrl(GetDlgItem(IDC_STOCKFACTORY));
		return;
	}
	GetDlgItemText(IDC_APPROVALNUMBER,str4);
	if(str4.IsEmpty())
	{
		if(AfxMessageBox("该药品没有批准文号,是否继续?",MB_YESNO|MB_ICONQUESTION)==IDNO)
		{
			m_approvalnumber.SetReadOnly(0);
			GotoDlgCtrl(GetDlgItem(IDC_APPROVALNUMBER));
			return;
		}
	}
	m_approvalnumber.SetReadOnly(1);
	GetDlgItemText(IDC_BATCHNUMBER,str5);
	if(str5.IsEmpty())
	{
		AfxMessageBox("必须录入药品的生产批号!");
		GotoDlgCtrl(GetDlgItem(IDC_BATCHNUMBER));
		return;
	}
	CString str_t1,str_t2;
	m_makedate.GetTime(t);
	str6=t.Format("%Y年%m月%d日");
	str_t1=t.Format("%Y%m%d");
	m_validate.GetTime(t);
	str7=t.Format("%Y年%m月%d日");
	str_t2=t.Format("%Y%m%d");
	m_acce.GetTime(t);
	strfa=t.Format("%Y年%m月%d日");
	if(atof(str_t2)<=atof(str_t1) || (atof(str_t2)-atof(str_t1))<180)
	{
		AfxMessageBox("药品有效期或生产日期有误,或选择了效期小于6个月的药品!");
		GotoDlgCtrl(GetDlgItem(IDC_MAKEDATE));
		return;
	}
	if(m_number.GetCurSel()>=0)
		m_number.GetLBText(m_number.GetCurSel(),str8);
	else
	{
		AfxMessageBox("必须录入药品数量!");
		GotoDlgCtrl(GetDlgItem(IDC_NUMBER));
		return;
	}
	if(m_unit.GetCurSel()>=0)
		m_unit.GetLBText(m_unit.GetCurSel(),str9);
	else
	{
		AfxMessageBox("必须录入药品单位!");
		GotoDlgCtrl(GetDlgItem(IDC_UNIT));
		return;
	}
	GetDlgItemText(IDC_STOCKMONEY,str10);
	CString price_str=_T("");;
	GetDlgItemText(IDC_STATICPRICE,price_str);
	price_str=price_str.Right(price_str.GetLength()-2);
	if(atof(str10)<atof(price_str))
		if(AfxMessageBox("该药品现行价格低于原始价格,是否继续?",MB_YESNO|MB_ICONQUESTION)==IDNO)
		{
			GotoDlgCtrl(GetDlgItem(IDC_STOCKMONEY));
			return;
		}
	if(str10.IsEmpty() || atof(str10)<=0.0)
	{
		AfxMessageBox("请检查药品单价!");
		GotoDlgCtrl(GetDlgItem(IDC_STOCKMONEY));
		return;
	}
	if(m_type.GetCurSel()<0)
	{
		AfxMessageBox("必须选择药品剂型!");
		GotoDlgCtrl(GetDlgItem(IDC_TYPE));
		return;
	}
	else
		m_type.GetLBText(m_type.GetCurSel(),stra);
	if(m_condition.GetCurSel()<0)
	{
		AfxMessageBox("必须选择药品质量状况!");
		GotoDlgCtrl(GetDlgItem(IDC_CONDITION));
		return;
	}
	else
		m_condition.GetLBText(m_condition.GetCurSel(),strb);
	if(m_form.GetCurSel()<0)
	{
		AfxMessageBox("必须选择药品外观性状!");
		GotoDlgCtrl(GetDlgItem(IDC_FORM));
		return;
	}
	else
		m_form.GetLBText(m_form.GetCurSel(),strc);
	if(m_conclusion.GetCurSel()<0)
	{
		AfxMessageBox("必须选择药品验收结论!");
		GotoDlgCtrl(GetDlgItem(IDC_CONCLUSION));
		return;
	}
	else
		m_conclusion.GetLBText(m_conclusion.GetCurSel(),strd);
	GetDlgItemText(IDC_PER,stre);
	if(stre.IsEmpty())
	{
		AfxMessageBox("验收人员签字!");
		GotoDlgCtrl(GetDlgItem(IDC_PER));
		return;
	}
	CString strf;
	strf.Format("%f",atof(str10));
	SetDlgItemText(IDC_STOCKMONEY,strf.Left(strf.Find('.',0)+1)+strf.Mid(strf.Find('.',0)+1,2));
	GetDlgItemText(IDC_STOCKMONEY,str10);
	m_progress.SetRange(0,12);
	str11.Format("%f",atof(str8)*atof(str10));
	str11=str11.Left(str11.Find('.',0)+1)+str11.Mid(str11.Find('.',0)+1,2);
	theApp.makesqldatabase();
	//查询出该药的编号my_number,对应productdetaill表的p_id字段
	CString my_number=_T("");
	CString strSQL="select product_id from products WHERE name='"+str1+"'";
	strSQL+=" and standard='"+str2+"'";
	strSQL+=" and makearea='"+str3+"'";
	strSQL+=" and permitcode='"+str4+"'";
	m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
	m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(strSQL.GetLength()+1),
			((CMedicineSaleManagesApp*)AfxGetApp())->m_pConn1.GetInterfacePtr(),
			adOpenDynamic,adLockPessimistic,adCmdText);
	if(!(m_pRecordset->adoEOF))
	{
		my_number=(LPCSTR)_bstr_t(m_pRecordset->GetCollect("product_id"));
	}
	m_pRecordset->Close();
	///productdetaill表的p_id字段为my_number
	///全局单据编号billid已经自动生成,billidx及productdetaill表均有
	///productdetaill表s_id统一为9,billidx表的sout_id及sin_id统一为9
	///productdetaill表的quantity为进药数量
	///productdetaill表的price为单价,在此为str10
	///productdetaill表的costprice为单价,在此为str10
	///productdetaill表的total为金额合计,在此为str10*str8
	///productdetaill表的costtotal为金额合计,在此为str10*str8
	///productdetaill表的batchno为生产批号,在此为str5
	///productdetaill表的makedate为生产日期,在此为str6
	///productdetaill表的validdate为有效日期,在此为str7
	///productdetaill表的unitid为表unit的unit_id
	///productdetaill表的comment为str8+str9
	CString unitid=_T("");//找出单位编码unitid
	strSQL="select unit_id from unit WHERE name='"+str9+"'";
	m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(strSQL.GetLength()+1),
			((CMedicineSaleManagesApp*)AfxGetApp())->m_pConn1.GetInterfacePtr(),
			adOpenDynamic,adLockPessimistic,adCmdText);
	if(!(m_pRecordset->adoEOF))
	{
		unitid=(LPCSTR)_bstr_t(m_pRecordset->GetCollect("unit_id"));
	}
	m_pRecordset->Close();
	m_pRecordset=NULL;
	if(!window_type)//如果是进货
	{
		CString total;
		total.Format("%f",atof(str8)*atof(str10));
		total=total.Left(total.Find('.',0)+1)+total.Mid(total.Find('.',0)+1,2);
		m_pRecordset1.CreateInstance(_T("ADODB.Recordset"));
		strSQL="select * from productdetail";
		m_pRecordset1->Open((LPTSTR)strSQL.GetBuffer(strSQL.GetLength()+1),
			((CMedicineSaleManagesApp*)AfxGetApp())->m_pConn1.GetInterfacePtr(),
			adOpenDynamic,adLockPessimistic,adCmdText);
		m_pRecordset1->AddNew();
		m_pRecordset1->PutCollect("p_id",_variant_t(my_number));
		m_pRecordset1->PutCollect("billid",_variant_t(billid));
		m_pRecordset1->PutCollect("s_id",_variant_t("9"));
		m_pRecordset1->PutCollect("quantity",_variant_t(str8));
		m_pRecordset1->PutCollect("price",_variant_t(str10));
		m_pRecordset1->PutCollect("costprice",_variant_t(str10));
		m_pRecordset1->PutCollect("total",_variant_t(total));
		m_pRecordset1->PutCollect("costtotal",_variant_t(total));
		m_pRecordset1->PutCollect("batchno",_variant_t(str5));
		m_pRecordset1->PutCollect("makedate",_variant_t(str6));
		m_pRecordset1->PutCollect("validdate",_variant_t(str7));
		m_pRecordset1->PutCollect("unitid",_variant_t(unitid));
		m_pRecordset1->PutCollect("comment",_variant_t(str8+str9));
		m_pRecordset1->Update();
		m_pRecordset1->Close();
		m_pRecordset1=NULL;
		/*m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
		m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(strSQL.GetLength()+1),
			((CMedicineSaleManagesApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
			adOpenDynamic,adLockPessimistic,adCmdText);
		m_pRecordset->AddNew();
		m_pRecordset->PutCollect("p_id",_variant_t(my_number));
		m_pRecordset->PutCollect("billid",_variant_t(billid));
		m_pRecordset->PutCollect("s_id",_variant_t("9"));
		m_pRecordset->PutCollect("quantity",_variant_t(str8));
		m_pRecordset->PutCollect("price",_variant_t(str10));
		m_pRecordset->PutCollect("costprice",_variant_t(str10));
		m_pRecordset->PutCollect("total",_variant_t(total));
		m_pRecordset->PutCollect("costtotal",_variant_t(total));
		m_pRecordset->PutCollect("batchno",_variant_t(str5));
		m_pRecordset->PutCollect("makedate",_variant_t(str6));
		m_pRecordset->PutCollect("validdate",_variant_t(str7));
		m_pRecordset->PutCollect("unitid",_variant_t(unitid));
		m_pRecordset->PutCollect("comment",_variant_t(str8+str9));
		m_pRecordset->Update();
		m_pRecordset->Close();
		m_pRecordset=NULL;*/
	}
	int row=m_list.GetItemCount();
	m_list.InsertItem(row,str0);
	m_progress.StepIt();
	m_list.SetItemText(row,1,str1);
	m_progress.StepIt();
	m_list.SetItemText(row,2,str2);
	m_progress.StepIt();
	m_list.SetItemText(row,3,str3);
	m_progress.StepIt();
	m_list.SetItemText(row,4,str4);
	m_progress.StepIt();
	m_list.SetItemText(row,5,str5);
	m_progress.StepIt();
	m_list.SetItemText(row,6,str6);
	m_progress.StepIt();
	m_list.SetItemText(row,7,str7);
	m_progress.StepIt();
	m_list.SetItemText(row,8,str8);
	m_progress.StepIt();
	m_list.SetItemText(row,9,str9);
	m_progress.StepIt();
	m_list.SetItemText(row,10,str10);
	m_progress.StepIt();
	m_list.SetItemText(row,11,str11);
	m_progress.StepIt();
	m_list.SetCheck(row);
	m_progress.SetPos(0);
	theApp.m_pConn->Close();
	theApp.m_pConn=NULL;
}

void CStockInput::OnNMClickStocklist1(NMHDR *pNMHDR, LRESULT *pResult)//单击并响应SHIFT键实行勾选或不选
{
	POSITION pos=m_list.GetFirstSelectedItemPosition();
	int r=m_list.GetItemCount();
	if(pos && r>=1)
	{
		int row=m_list.GetNextSelectedItem(pos);
		if(m_list.GetCheck(row))
			m_list.SetCheck(row,0);
		else
			m_list.SetCheck(row,1);
	}
	*pResult = 0;
}

void CStockInput::OnBnClickedOutexcel()
{
	int rowcount=0,count=0;
	rowcount=m_list.GetItemCount();
	for(int i=0;i<rowcount;i++)
		if(m_list.GetCheck(i))
			count++;
	if(rowcount<1 || count<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));

⌨️ 快捷键说明

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