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

📄 printsendlist.cpp

📁 自已做的简单的库存管理软件。包含员工信息管理等
💻 CPP
📖 第 1 页 / 共 2 页
字号:
				//Do something what you want to do:	......
				m_pRs->MoveNext(); 
			}	
		}
	}
	catch (_com_error &e)
	{
		::MessageBox(NULL,e.Description(),(LPCTSTR)(_T("警告")),MB_OK);
		
	}
	m_pRs->Close(); 
}

void CPrintSendList::OnBnClickedOk()
{
	// TODO: 在此添加控件通知处理程序代码
	//OnOK();
	_RecordsetPtr m_pRs; 
	CString m_strSql; 

	CWnd* pWnd;
	CString str_txcompany = _T("");
	CString str_txaddr = _T("");
	CString str_txpc = _T("");
	CString str_txtel = _T("");
	CString str_txfax = _T("");
	CString str_rxcompany = _T("");
	CString str_rxaddr = _T("");
	CString str_rxcontact = _T("");
	CString str_rxtel = _T("");
	CString str_transport = _T("");

	pWnd = GetDlgItem(IDC_COMBO_TXCOMPANY);
	pWnd->GetWindowText(str_txcompany);
	if ( str_txcompany.GetLength() == 0 )
	{
		AfxMessageBox(_T("请选择发货单位!"));
		return;
	}

	m_strSql.Format(_T("select ADDR,PC,TEL,FAX from COMPANY_TABLE where ( NAME ='") +str_txcompany+ _T("')") ); 
	m_pRs.CreateInstance( __uuidof(Recordset) ); 
	m_pRs->Open( _bstr_t(m_strSql), _variant_t((IDispatch *)pMyConnect,true), adOpenKeyset, adLockOptimistic, adCmdText);  
		
	
	try
	{	
		if ( m_pRs->GetRecordCount() > 0 )
		{
			_variant_t   TheValue;
			_bstr_t tmp;
		
			m_pRs->MoveFirst(); 
			while(m_pRs->adoEOF==VARIANT_FALSE)	
			{
				//Retrieve column's value: 	 									
			
				TheValue = m_pRs->Fields->GetItem(_variant_t("ADDR"))->Value;
				if( TheValue.vt != VT_NULL )
				{	
					tmp=(_bstr_t)TheValue; 			
					CString str_tmp1 = tmp;
					str_txaddr = str_tmp1;
				}

				TheValue = m_pRs->Fields->GetItem(_variant_t("PC"))->Value;
				if( TheValue.vt != VT_NULL )
				{
					tmp=(_bstr_t)TheValue; 			
					CString str_tmp2 = tmp;
					str_txpc = str_tmp2;
				}

				TheValue = m_pRs->Fields->GetItem(_variant_t("TEL"))->Value;
				if( TheValue.vt != VT_NULL )
				{
					tmp=(_bstr_t)TheValue; 			
					CString str_tmp3 = tmp;
					str_txtel = str_tmp3;
				}

				TheValue = m_pRs->Fields->GetItem(_variant_t("FAX"))->Value;
				if( TheValue.vt != VT_NULL )
				{
					tmp=(_bstr_t)TheValue; 			
					CString str_tmp4 = tmp;
					str_txfax = str_tmp4;
				}

				//Do something what you want to do:	......
				m_pRs->MoveNext(); 
			}	
		}
	}
	catch (_com_error &e)
	{
		::MessageBox(NULL,e.Description(),(LPCTSTR)(_T("警告")),MB_OK);
		
	}
	m_pRs->Close(); 


	pWnd = GetDlgItem(IDC_EDIT_RXCOMPANY);
	pWnd->GetWindowText(str_rxcompany);

	
	pWnd = GetDlgItem(IDC_EDIT_RXADDR);
	pWnd->GetWindowText(str_rxaddr);
	if ( str_rxaddr.GetLength() == 0 )
	{
		AfxMessageBox(_T("收货地址不能为空!"));
		return;
	}
	if ( str_rxaddr.GetLength() > 30 )
	{
		AfxMessageBox(_T("收货地址长度超出限制!"));
		return;
	}

	
	pWnd = GetDlgItem(IDC_COMBO_RXCONTACT);
	pWnd->GetWindowText(str_rxcontact);
	if ( str_rxcontact.GetLength() == 0 )
	{
		AfxMessageBox(_T("请选择收货人!"));
		return;
	}

	
	pWnd = GetDlgItem(IDC_EDIT_RXTEL);
	pWnd->GetWindowText(str_rxtel);
	if ( str_rxtel.GetLength() == 0 )
	{
		AfxMessageBox(_T("收货人电话不能为空!"));
		return;
	}
	if ( str_rxtel.GetLength() > 20 )
	{
		AfxMessageBox(_T("收货人电话长度超出限制!"));
		return;
	}

	
	pWnd = GetDlgItem(IDC_COMBO_TRANSPORT);
	pWnd->GetWindowText(str_transport);
	if ( str_transport.GetLength() == 0 )
	{
		AfxMessageBox(_T("请选择货运方式!"));
		return;
	}



	//开始打印
	CPrintRX m_Print;
	if (m_Print.InitToPrint(NULL, 1) == -1)
		return;
	m_Print.StartPrint();
	m_Print.StartPage();

	


	// start printing the lines
    //二维点阵
	//int x_pos[8];
	//int y_pos[30];
	int x_pos[6];
	int y_pos[22];


	int i;
	//设置横坐标
	//for (i=0; i<30; i++)
		//y_pos[i] = 80 + (24 * i);
	for (i=0; i<22; i++)
		y_pos[i] = 80 + (24 * i) + 24 * 3;

    //设置纵坐标
	/*x_pos[0] = 45;
	x_pos[1] = x_pos[0] + 84;
	x_pos[2] = x_pos[1] + 68;
	x_pos[3] = x_pos[2] + 48;
	x_pos[4] = x_pos[3] + 53;
	x_pos[5] = x_pos[4] + 58;
	x_pos[6] = x_pos[5] + 84;
	x_pos[7] = x_pos[6] + 75;*/

	x_pos[0] = 20;
	x_pos[1] = x_pos[0] + 40;
	x_pos[2] = x_pos[1] + 100;
	x_pos[3] = x_pos[2] + 270;
	x_pos[4] = x_pos[3] + 40;
	x_pos[5] = x_pos[4] + 90;

	
	CPen	newPen;
	newPen.CreatePen (PS_SOLID, 3, RGB(0,0,0));
	//打印30行
	/*for (i=0; i<30; i++)
	{
		m_Print.DrawHLine(x_pos[0], y_pos[i], x_pos[7], y_pos[i], newPen);
	}*/
	for (i=0; i<22; i++)
	{
		m_Print.DrawHLine(x_pos[0], y_pos[i], x_pos[5], y_pos[i], newPen);
	}
	//打印8列,其中0和7还有中间的要单独打
	/*for (i=1; i<7; i++)
	{
		m_Print.DrawVLine(x_pos[i], y_pos[2], x_pos[i], y_pos[29], newPen);

	}	
	m_Print.DrawVLine(x_pos[0], y_pos[0], x_pos[0], y_pos[29], newPen);
	m_Print.DrawVLine(x_pos[7], y_pos[0], x_pos[7], y_pos[29], newPen);
	m_Print.DrawVLine((x_pos[0] + x_pos[7])/ 2, y_pos[1], (x_pos[0] + x_pos[7]) / 2, y_pos[2], newPen);*/
	for (i=1; i<5; i++)
	{
		m_Print.DrawVLine(x_pos[i], y_pos[6], x_pos[i], y_pos[19], newPen);

	}
	//最先两行中间不需要画列
	m_Print.DrawVLine(x_pos[0], y_pos[0], x_pos[0], y_pos[21], newPen);
	m_Print.DrawVLine(x_pos[5], y_pos[0], x_pos[5], y_pos[21], newPen);

	m_Print.DrawVLine((x_pos[0] + x_pos[5])/ 2, y_pos[2], (x_pos[0] + x_pos[5]) / 2, y_pos[3], newPen);
	m_Print.DrawVLine((x_pos[0] + x_pos[5])/ 2, y_pos[3], (x_pos[0] + x_pos[5]) / 2, y_pos[4], newPen);
	m_Print.DrawVLine((x_pos[0] + x_pos[5])/ 2, y_pos[4], (x_pos[0] + x_pos[5]) / 2, y_pos[5], newPen);
	m_Print.DrawVLine((x_pos[0] + x_pos[5])/ 2, y_pos[5], (x_pos[0] + x_pos[5]) / 2, y_pos[6], newPen);

	//最后签名两行
	m_Print.DrawVLine((x_pos[0] + x_pos[5])/ 2, y_pos[19], (x_pos[0] + x_pos[5]) / 2, y_pos[20], newPen);
	m_Print.DrawVLine((x_pos[0] + x_pos[5])/ 2, y_pos[20], (x_pos[0] + x_pos[5]) / 2, y_pos[21], newPen);




	CSize Size;
	TCHAR m_str[7][10];
	CRect StrRect;              //Draw text in Rect

	_tcscpy(m_str[0], _T("箱号"));
	_tcscpy(m_str[1], _T("品牌"));
	_tcscpy(m_str[2], _T("品名规格"));
	_tcscpy(m_str[3], _T("数量"));
	_tcscpy(m_str[4], _T("产品编号"));
	//_tcscpy(m_str[5], _T("收时"));
	//_tcscpy(m_str[6], _T("备注"));
	/*for (i=0; i<7; i++)
	{
		StrRect.SetRect(x_pos[i], y_pos[2], x_pos[i+1], y_pos[3]);
		m_Print.DrawText(m_str[i], StrRect, 0, 0, FORMAT_HCENTER | FORMAT_VCENTER);
	}*/
	for (i=0; i<5; i++)
	{
		StrRect.SetRect(x_pos[i], y_pos[6], x_pos[i+1], y_pos[7]);
		m_Print.DrawText(m_str[i], StrRect, 0, 0, FORMAT_HCENTER | FORMAT_VCENTER);
	}

    CString str_print_temp[7];
	for ( int j = 0 ; j < iPrintsendlist_number; j++ )
	{
		str_print_temp[0] = _T("");
		str_print_temp[1] = m_list_printsendlist.GetItemText(  j, 1 );
		str_print_temp[2] = m_list_printsendlist.GetItemText(  j, 2 ) + _T("(") + m_list_printsendlist.GetItemText(  j, 4 ) + _T(")");
		str_print_temp[3] = m_list_printsendlist.GetItemText(  j, 3 );
		str_print_temp[4] = _T("");

		for (i=0; i<5; i++)
		{
			StrRect.SetRect(x_pos[i], y_pos[7+j], x_pos[i+1], y_pos[8+j]);
			m_Print.DrawText(str_print_temp[i], StrRect, 0, 0, FORMAT_HCENTER | FORMAT_VCENTER);
		}

	}

	// now end the page
	CString Title = _T("发货总装箱清单");         //标题
	CString Tail = _T("为确保产品完整无损,请收货人在收到上列货品后核对并签名传真至:") +str_txfax;  //尾注

	CString RxCompany = _T("收货单位:") + str_rxcompany; 	    
	CString RxAddr = _T("收货地址:") + str_rxaddr; 
	CString RxContact = _T("收货人:") + str_rxcontact ; 
	CString RxTel = _T("收货人电话:") + str_rxtel ; 
	
	CString Transprot = _T("货运方式:") + str_transport ; 
	CString ContractNO = _T("合同编号:")  ; 
	CString TxDate = _T("发货日期:") ; 
	CString BillSend = _T("票据寄送:") ; 
	CString Total = _T("总装箱数:") ; 
	CString Other = _T("其它:") ; 
	
	CString HeaderTxCompany= _T("发货单位:") + str_txcompany;    
	//CString HeaderRight = _T("");   
	CString HeaderAddrPC = _T("地址:") +str_txaddr +  _T("   邮编:") + str_txpc;   
	CString HeaderTelFax =  _T("电话:") +str_txtel +  _T("       传真:") +str_txfax; 

	CString TxOfficer = _T("发货单位经办人(签名):") ; 
	CString TxVerify = _T("发货单位负责人(签名):") ; 
	CString RxOfficer = _T("收货人(签名):") ; 
	CString RxDate = _T("收货日期:") ; 

	m_Print.SetFontFace(0, 3);
	StrRect.SetRect(x_pos[0] + 1, 20, x_pos[5], 56);
	m_Print.DrawText(Title, StrRect, 0, 0, FORMAT_HCENTER | FORMAT_VCENTER);

	//m_Print.SetFontFace(0, 0);
	m_Print.SetFontFace(0, 1);
	StrRect.SetRect(x_pos[0] + 1, 56, x_pos[5], 80);
	m_Print.DrawText(HeaderTxCompany, StrRect, 0, 0, FORMAT_LEFT | FORMAT_VCENTER);


	//StrRect.SetRect(x_pos[0] - 1, 56, x_pos[5], 80);
	//m_Print.DrawText(HeaderRight, StrRect, 0, 0, FORMAT_RIGHT | FORMAT_VCENTER);


	//打印发货单位名称、地址、PC、电话和传真
    m_Print.SetFontFace(0, 0);
	StrRect.SetRect(x_pos[0] + 1, 80, x_pos[5], 110);
	m_Print.DrawText(HeaderAddrPC, StrRect, 0, 0, FORMAT_LEFT | FORMAT_VCENTER);
	StrRect.SetRect(x_pos[0] + 1,104, x_pos[5], 134);
	m_Print.DrawText(HeaderTelFax, StrRect, 0, 0, FORMAT_LEFT | FORMAT_VCENTER);

    
    //打印收货单位名称、地址、收货人、电话
	StrRect.SetRect(x_pos[0] + 1, y_pos[0], x_pos[5], y_pos[1]);
	m_Print.DrawText(RxCompany, StrRect, 0, 0, FORMAT_LEFT | FORMAT_VCENTER);

	StrRect.SetRect(x_pos[0] + 1, y_pos[1], x_pos[5], y_pos[2]);
	m_Print.DrawText(RxAddr, StrRect, 0, 0, FORMAT_LEFT | FORMAT_VCENTER);


	StrRect.SetRect(x_pos[0] + 1, y_pos[2], x_pos[5], y_pos[3]);
	m_Print.DrawText(RxContact, StrRect, 0, 0, FORMAT_LEFT | FORMAT_VCENTER);
	StrRect.SetRect((x_pos[0] + x_pos[5])/2 + 1, y_pos[2], x_pos[5], y_pos[3]);
	m_Print.DrawText(RxTel, StrRect, 0, 0, FORMAT_LEFT | FORMAT_VCENTER);

	StrRect.SetRect(x_pos[0] + 1, y_pos[3], x_pos[5], y_pos[4]);
	m_Print.DrawText(Transprot, StrRect, 0, 0, FORMAT_LEFT | FORMAT_VCENTER);
	StrRect.SetRect((x_pos[0] + x_pos[5])/2 + 1, y_pos[3], x_pos[5], y_pos[4]);
	m_Print.DrawText(ContractNO, StrRect, 0, 0, FORMAT_LEFT | FORMAT_VCENTER);

	StrRect.SetRect(x_pos[0] + 1, y_pos[4], x_pos[5], y_pos[5]);
	m_Print.DrawText(TxDate, StrRect, 0, 0, FORMAT_LEFT | FORMAT_VCENTER);
	StrRect.SetRect((x_pos[0] + x_pos[5])/2 + 1, y_pos[4], x_pos[5], y_pos[5]);
	m_Print.DrawText(BillSend, StrRect, 0, 0, FORMAT_LEFT | FORMAT_VCENTER);

	StrRect.SetRect(x_pos[0] + 1, y_pos[5], x_pos[5], y_pos[6]);
	m_Print.DrawText(Total, StrRect, 0, 0, FORMAT_LEFT | FORMAT_VCENTER);
	StrRect.SetRect((x_pos[0] + x_pos[5])/2 + 1, y_pos[5], x_pos[5], y_pos[6]);
	m_Print.DrawText(Other, StrRect, 0, 0, FORMAT_LEFT | FORMAT_VCENTER);

	//签名处
	StrRect.SetRect(x_pos[0] + 1, y_pos[19], x_pos[5], y_pos[20]);
	m_Print.DrawText(TxOfficer, StrRect, 0, 0, FORMAT_LEFT | FORMAT_VCENTER);
	StrRect.SetRect((x_pos[0] + x_pos[5])/2 + 1, y_pos[19], x_pos[5], y_pos[20]);
	m_Print.DrawText(RxOfficer, StrRect, 0, 0, FORMAT_LEFT | FORMAT_VCENTER);

	StrRect.SetRect(x_pos[0] + 1, y_pos[20], x_pos[5], y_pos[21]);
	m_Print.DrawText(TxVerify, StrRect, 0, 0, FORMAT_LEFT | FORMAT_VCENTER);
	StrRect.SetRect((x_pos[0] + x_pos[5])/2 + 1, y_pos[20], x_pos[5], y_pos[21]);
	m_Print.DrawText(RxDate, StrRect, 0, 0, FORMAT_LEFT | FORMAT_VCENTER);
	

	//打印尾注
	m_Print.SetFontFace(0, 1);
	StrRect.SetRect(x_pos[0] + 1, y_pos[21], x_pos[5], y_pos[21] + 56);
	m_Print.DrawText(Tail, StrRect, 0, 0, FORMAT_LEFT | FORMAT_VCENTER);


	//结束打印
	m_Print.EndPage();
	m_Print.EndPrint();
}

⌨️ 快捷键说明

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