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

📄 writerec.cpp

📁 基于WIN CE 的抄表系统,环境wince .net
💻 CPP
字号:
// WriteRec.cpp : implementation file
//

#include "stdafx.h"
#include "Cbsystem.h"
#include "WriteRec.h"
#include "WPower.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

extern BOOL WhUpdateDB(LPWSTR lpsz,LPWSTR lpsz1);
extern LPTSTR WhSearchMultiRecord(LPWSTR lpsz);
extern LPTSTR WhSearchMultiRecordID(LPWSTR lpsz);
extern LPTSTR WhSearchMultiRecordNAMEID(LPWSTR lpsz);
extern LPTSTR WhSearchMultiRecordJCH(LPWSTR lpsz);
extern int CountChar(CString str,char ch);
extern CString *SplitString(CString Str,char ch);
extern void LvMultiInsertData(LVITEM lvitem, CListCtrl *pList, LPTSTR lpsz1, LPTSTR lpsz2, LPTSTR lpsz3, LPTSTR lpsz4,LPTSTR lpsz5);
/////////////////////////////////////////////////////////////////////////////
// CWriteRec dialog
CWriteRec::CWriteRec(CWnd* pParent /*=NULL*/)
	: CDialog(CWriteRec::IDD, pParent)
{
	//{{AFX_DATA_INIT(CWriteRec)
	m_bh = _T("");
	m_name = _T("");
	m_id = _T("");
	m_Jch = _T("");
	//}}AFX_DATA_INIT
}


void CWriteRec::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CWriteRec)
	DDX_Text(pDX, IDC_EDIT1, m_bh);
	DDX_Text(pDX, IDC_EDIT2, m_name);
	DDX_Text(pDX, IDC_EDIT3, m_id);
	DDX_Text(pDX, IDC_EDIT4, m_Jch);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CWriteRec, CDialog)
	//{{AFX_MSG_MAP(CWriteRec)
	ON_BN_CLICKED(IDC_SEARCH, OnSearch)
	ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CWriteRec message handlers

void CWriteRec::OnSearch() 
{
	// TODO: Add your control notification handler code here
	CString szrec;
	CString *Split,*Split1;
	LPTSTR lpsz;

	LVITEM lvitem;
	CListCtrl * pList;
	pList = (CListCtrl *)GetDlgItem(IDC_LIST1);

	this->UpdateData(TRUE);
	if (((m_bh!="")&&(m_name!=""))||((m_bh!="")&&(m_id!=""))||((m_name!="")&&(m_id!=""))||((m_Jch!="")&&(m_bh!=""))||((m_Jch!="")&&(m_id!=""))||((m_Jch!="")&&(m_name!="")))
	{
		AfxMessageBox(TEXT("不能多条件查询???"));
		return;
	}
	else if(m_name!="")
		{
			pList->DeleteAllItems();
			lpsz = (LPWSTR)(LPCTSTR)m_name;
			szrec = (LPTSTR)WhSearchMultiRecord(lpsz);
			if((szrec) && (szrec != ""))
			{
				int i = CountChar(szrec,'@');
				Split = SplitString(szrec,'@');
				for(int j=0;j<i;j++)
				{
					Split1 = SplitString(Split[j],'|');
					LvMultiInsertData(lvitem, pList, (LPTSTR)(LPCTSTR)Split1[0],(LPTSTR)(LPCTSTR)Split1[1],(LPTSTR)(LPCTSTR)Split1[2],(LPTSTR)(LPCTSTR)Split1[3],(LPTSTR)(LPCTSTR)Split1[4]);
				}
				
			}
			//if((!szrec)||(szrec = ""))
			else
			{
				return;
			}
		}
			else if(m_bh!="")
				{
					pList->DeleteAllItems();
					lpsz = (LPWSTR)(LPCTSTR)m_bh;
					szrec = (LPTSTR)WhSearchMultiRecordID(CharUpper(lpsz));
					if((szrec) && (szrec != ""))
					{
						Split1 = SplitString(szrec,'|');
						LvMultiInsertData(lvitem, pList, (LPTSTR)(LPCTSTR)Split1[0],(LPTSTR)(LPCTSTR)Split1[1],(LPTSTR)(LPCTSTR)Split1[2],(LPTSTR)(LPCTSTR)Split1[3],(LPTSTR)(LPCTSTR)Split1[4]);
					}
					else
					{
						return;
					}
				}

					else if(m_id!="")
						{
							pList->DeleteAllItems();
							lpsz = (LPWSTR)(LPCTSTR)m_id;
							szrec = (LPTSTR)WhSearchMultiRecordNAMEID(lpsz);
							if((szrec) && (szrec != ""))
							{
								Split1 = SplitString(szrec,'|');
								LvMultiInsertData(lvitem, pList, (LPTSTR)(LPCTSTR)Split1[0],(LPTSTR)(LPCTSTR)Split1[1],(LPTSTR)(LPCTSTR)Split1[2],(LPTSTR)(LPCTSTR)Split1[3],(LPTSTR)(LPCTSTR)Split1[4]);
									
							}
							else
							{
								return;
							}
						}
							else if(m_Jch!="")
							{
								pList->DeleteAllItems();
								lpsz = (LPWSTR)(LPCTSTR)m_Jch;
								szrec = (LPTSTR)WhSearchMultiRecordJCH(lpsz);
								if((szrec) && (szrec != ""))
								{
									int i = CountChar(szrec,'@');
									Split = SplitString(szrec,'@');
									for(int j=0;j<i;j++)
									{
										Split1 = SplitString(Split[j],'|');
										LvMultiInsertData(lvitem, pList, (LPTSTR)(LPCTSTR)Split1[0],(LPTSTR)(LPCTSTR)Split1[1],(LPTSTR)(LPCTSTR)Split1[2],(LPTSTR)(LPCTSTR)Split1[3],(LPTSTR)(LPCTSTR)Split1[4]);
									}
									
								}
								else
								{
									return;
								}
							}
							else
								return;

}

void CWriteRec::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	NM_LISTVIEW * phdn = (NM_LISTVIEW *)pNMHDR;
	CListCtrl * pList; 
	int num = phdn->iItem;
	pList = (CListCtrl *)GetDlgItem(IDC_LIST1);
	CString s  = pList->GetItemText(num,0);
	CString s1 = pList->GetItemText(num,1);
	CString s2 = pList->GetItemText(num,2);
	CString s3 = pList->GetItemText(num,3);
	CString s4 = pList->GetItemText(num,4);

	//CWriteRecord * dlg = new CWriteRecord;
	CWPower * dlg = new  CWPower;
		UpdateData(TRUE);
		dlg->m_bh		= s;
		dlg->m_id		= s1;
		dlg->m_name		= s2;
		dlg->m_powerold	= s3;
		dlg->m_power	= s4;

		UpdateData(FALSE);
		if(dlg->DoModal() == IDOK)
		{
			CString szPower;
			if(WhUpdateDB((LPWSTR)(LPCTSTR)dlg->m_bh,(LPWSTR)(LPCTSTR)dlg->m_power))
			{
				pList->SetItemText(num, 4, (LPWSTR)(LPCTSTR)dlg->m_power);
				szPower.Format(TEXT("本月用电量为 :  %d  [度]"),_wtol(dlg->m_power) - _wtol(s3));
				if((_wtol(dlg->m_power) - _wtol(s3)) <= 0)
				{
					szPower += TEXT("[注意]:\n 此月电表过周或输入有误???");
					AfxMessageBox(szPower);
				}
				else
				{
					AfxMessageBox(szPower);
				}
			}
			else
			{
				AfxMessageBox(TEXT("更新数据库失败!!!"));
				return;
			}
		}
		else
		{
			return;
		}
	*pResult = 0;
}

BOOL CWriteRec::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	((CButton*)GetDlgItem(IDC_SEARCH))->ShowWindow(SW_SHOW);

	CListCtrl * pList;
	LV_COLUMN lvc;
	pList = (CListCtrl *)GetDlgItem(IDC_LIST1);
	
	pList->SetExtendedStyle(LVS_EX_FULLROWSELECT);
	lvc.mask = LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH;
	lvc.fmt = LVCFMT_CENTER;
  	lvc.iSubItem = 0;
	lvc.pszText = TEXT("计量表号");
	lvc.cx = 85;
	pList->InsertColumn(0,&lvc);
	lvc.iSubItem = 1;
	lvc.pszText = TEXT("用户名称");
	lvc.cx = 80;
	pList->InsertColumn(1,&lvc);
	lvc.iSubItem = 2;
	lvc.pszText = TEXT("户号");
	lvc.cx = 75;
	pList->InsertColumn(2,&lvc);
	lvc.iSubItem = 3;
	lvc.pszText = TEXT("上期抄见");
	lvc.cx = 68;
	pList->InsertColumn(3,&lvc);
	lvc.iSubItem = 4;
	lvc.pszText = TEXT("本期抄见");
	lvc.cx = 68;
	pList->InsertColumn(4,&lvc);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

⌨️ 快捷键说明

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