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

📄 balance.cpp

📁 简单的MFC制作
💻 CPP
字号:
// Balance.cpp : 实现文件
//

#include "stdafx.h"
#include "电信收费系统.h"
#include "Balance.h"
#include "电信收费系统Dlg.h"
//#include "Pay.h"

// Balance 对话框

IMPLEMENT_DYNAMIC(Balance, CDialog)

Balance::Balance(CWnd* pParent /*=NULL*/)
	: CDialog(Balance::IDD, pParent)
	, Search_idc(_T(""))
	, Pay(0)
{
#ifndef _WIN32_WCE
	EnableActiveAccessibility();
#endif

}

Balance::~Balance()
{
}



BOOL Balance::OnInitDialog()
{
	CDialog::OnInitDialog();

	m_list_mb.InsertColumn(0,"用户姓名",LVCFMT_LEFT,90);
	m_list_mb.InsertColumn(1,"用户号码",LVCFMT_LEFT,85);
	m_list_mb.InsertColumn(2,"帐户余额",LVCFMT_LEFT,82);

	Pay =0;
	m_list_mb.SetExtendedStyle( LVS_EX_FULLROWSELECT);

	return TRUE;  // 除非将焦点设置到控件,否则返回 TRUE
}

void Balance::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_LIST1, m_list_mb);
	DDX_Text(pDX, IDC_EDIT_Search_ID, Search_idc);
	DDX_Text(pDX, IDC_EDIT_Pay, Pay);
}


BEGIN_MESSAGE_MAP(Balance, CDialog)
	ON_BN_CLICKED(ID_BUTTON_Search, &Balance::OnBnClickedButtonSearch)
END_MESSAGE_MAP()


// Balance 消息处理程序

void Balance::OnBnClickedButtonSearch()
{
	if( bLink&&UpdateData() )
	{
		if(Search_idc.GetLength() >0 )
		{
			CString Cmd = "Select * from Charge_info where Id_Card ="+Search_idc+"";

			_bstr_t bstrCmd = Cmd.AllocSysString();

			try{
				_RecordsetPtr Rec("ADODB.Recordset");

				Rec.CreateInstance(__uuidof(Recordset));
	
				Rec->Open(bstrCmd,m_pCon.GetInterfacePtr(),adOpenStatic,adLockOptimistic,adCmdText);

				Rec->MoveLast();
		
				m_list_mb.DeleteAllItems();
				_variant_t name,idc,balance;

				name = Rec->GetCollect("Sname");
				idc  = Rec->GetCollect("ID_Card");
				balance = Rec->GetCollect("Balance");

				int pos;

				pos = m_list_mb.InsertItem(100,(_bstr_t)name);
				m_list_mb.SetItem(pos,1,1,(_bstr_t)idc,NULL,0,0,0);
				m_list_mb.SetItem(pos,2,1,(_bstr_t)((float)balance+Pay),NULL,0,0,0);

				m_list_mb.SetFocus(); //对选中行 加亮
				m_list_mb.EnsureVisible(pos,FALSE);   //自动翻页
				m_list_mb.SetItemState(pos,LVIS_FOCUSED|LVIS_SELECTED,LVIS_FOCUSED|LVIS_SELECTED);

				
				CString ss;
				ss.Format("%f",Pay);
				if(Pay != 0)
				{
					
					CString Cmd = "Update Charge_info Set Balance = Balance +"+ss+" where Id_Card ="+Search_idc+"";

					_bstr_t bstrCmd = Cmd.AllocSysString();

					m_pCon->Execute(bstrCmd,NULL,0);

					AfxMessageBox("充值成功");

					Pay =0;

				}
				
	
     			Rec->Close();
			}
			catch(_com_error e)
			{
				AfxMessageBox("没有此用户");
				Pay =0;
			}
		}
	}

	if(!bLink) AfxMessageBox("没有连接");

}

⌨️ 快捷键说明

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