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

📄 cbsystemview.cpp

📁 基于WIN CE 的抄表系统,环境wince .net
💻 CPP
字号:
// CbsystemView.cpp : implementation of the CCbsystemView class
//

#include "stdafx.h"
#include "Cbsystem.h"
#include "DlgCb.h"
//#include "Serial.h"

#include "CbsystemDoc.h"
#include "CbsystemView.h"
#include "RecordSearch.h"
#include "Send.h"
#include "WriteRec.h"
#include "LogonMod.h" 
#include "SetComm.h"
#include "DbSet.h"

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

extern CEOID	poid;
extern CCeDBDatabase db;
extern CString * SplitString(CString str,char ch);
extern int CountChar(CString str, char ch);
extern void SearchRecordNum();
extern void Emptydb();
extern void Deletedb();
extern BOOL DataFresh();
extern BOOL InsertTable(LPTSTR lpsz1,LPTSTR lpsz2,LPTSTR lpsz3,LPTSTR lpsz4,LPTSTR lpsz5,LPTSTR lpsz6);
/////////////////////////////////////////////////////////////////////////////
// CCbsystemView

IMPLEMENT_DYNCREATE(CCbsystemView, CListView)

BEGIN_MESSAGE_MAP(CCbsystemView, CListView)
	//{{AFX_MSG_MAP(CCbsystemView)
	ON_NOTIFY_REFLECT(NM_DBLCLK, OnDblclk)
	ON_COMMAND(IDC_SYS_PASSWORD, OnSysPassword)
	ON_COMMAND(IDC_SYS_SET, OnSysSet)
	ON_COMMAND(IDC_SJ_BROWSE, OnSjBrowse)
	ON_COMMAND(IDC_SJ_WRITE, OnSjWrite)
	ON_COMMAND(IDC_SJ_QUERY, OnSjQuery)
	ON_COMMAND(IDC_SJ_EMPTY, OnSjEmpty)
	ON_COMMAND(IDC_SJ_JZ, OnSjJz)
	ON_COMMAND(IDC_TX_DR, OnTxDr)
	ON_COMMAND(IDC_TX_DC, OnTxDc)
	ON_COMMAND(IDC_TX_SET, OnTxSet)
	ON_COMMAND(IDC_TX_CB, OnTxCb)
	ON_COMMAND(IDC_HELP1_ABOUT, OnHelpAbout)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCbsystemView construction/destruction

CCbsystemView::CCbsystemView()
{
	// TODO: add construction code here

}

CCbsystemView::~CCbsystemView()
{
}

BOOL CCbsystemView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs
	 
	return CListView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CCbsystemView drawing

void CCbsystemView::OnDraw(CDC* pDC)
{
	CCbsystemDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	// TODO: add draw code for native data here
}

void CCbsystemView::OnInitialUpdate()
{
	CListView::OnInitialUpdate();

	// TODO: You may populate your ListView with items by directly accessing
	//  its list control through a call to GetListCtrl().
	HICON hIcon[11];
	CListCtrl  *pList;
	hIcon[0]=AfxGetApp()->LoadIcon(IDI_ICON5);
	hIcon[1]=AfxGetApp()->LoadIcon(IDI_ICON15);
	hIcon[2]=AfxGetApp()->LoadIcon(IDI_ICON10);
	hIcon[3]=AfxGetApp()->LoadIcon(IDI_ICON3);
	hIcon[4]=AfxGetApp()->LoadIcon(IDI_ICON19);
	hIcon[5]=AfxGetApp()->LoadIcon(IDI_ICON12);
	hIcon[6]=AfxGetApp()->LoadIcon(IDI_ICON11);
	hIcon[7]=AfxGetApp()->LoadIcon(IDI_ICON2);
	hIcon[8]=AfxGetApp()->LoadIcon(IDI_ICON7);
	hIcon[9]=AfxGetApp()->LoadIcon(IDI_ICON17);
	hIcon[10]=AfxGetApp()->LoadIcon(IDI_ICON1);
	m_imagelist.Create(32,32,TRUE,32,32);
	for(int i =0;i<11;i++)
	{
		m_imagelist.Add(hIcon[i]);
	}
	(CListCtrl *)pList = &GetListCtrl();
	pList->SetImageList ( &m_imagelist, LVS_ICON );
	CString  title[11]={"数据浏览","手工录入","数据查询","数据库清空","数据导入","数据导出","通信设置","电表设置","电表抄见","更改口令","数据结转"};
	for (int j = 0; j<11; j++)
	{
		pList->InsertItem(j,title[j],j);
	}
	//pList->SetBkColor(RGB(0,255,255));
}


/////////////////////////////////////////////////////////////////////////////
// CCbsystemView diagnostics

#ifdef _DEBUG
void CCbsystemView::AssertValid() const
{
	CListView::AssertValid();
}

void CCbsystemView::Dump(CDumpContext& dc) const
{
	CListView::Dump(dc);
}

CCbsystemDoc* CCbsystemView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCbsystemDoc)));
	return (CCbsystemDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CCbsystemView message handlers

void CCbsystemView::OnDblclk(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	NM_LISTVIEW * phdn = (NM_LISTVIEW *)pNMHDR;
	CListCtrl * pList; 
	int num = phdn->iItem;
	(CListCtrl *)pList = &GetListCtrl();
	CString s = pList->GetItemText(num,0);
	
	if(TEXT("数据浏览") == s)
	{
			
		if(AfxMessageBox(s, MB_YESNO) == IDYES)
		{
			OnSjBrowse();
		}
		else
			return;
	
	}
	else if(TEXT("手工录入") == s)
		{
			if(AfxMessageBox(s, MB_YESNO) == IDYES)
			{
				OnSjWrite();
			}
			else
				return;
		}
		else if(TEXT("数据查询") == s)
			{
				 OnSjQuery();
			}
			else if(TEXT("数据库清空") == s)
				{
					 OnSjEmpty();
				}
				else if(TEXT("数据导入") == s)
					{
						OnTxDr();
					}
					else if(TEXT("数据导出") == s)
						{
							OnTxDc();
						} 
						else if(TEXT("通信设置") == s)
							{
								if(AfxMessageBox(s, MB_YESNO) == IDYES)
								{				
										OnSysSet();
								}
								else
									return;
							}
							else if(TEXT("电表设置") == s)
								{
									if(AfxMessageBox(s, MB_YESNO) == IDYES)
									{				
											OnTxSet();
									}
									else
										return;
								}
								else if(TEXT("电表抄见") == s)
									{
										if(AfxMessageBox(s, MB_YESNO) == IDYES)
										{				
											OnTxCb();
										}
										else
											return;
									}
									else if(TEXT("更改口令") == s)
										{
											if(AfxMessageBox(s, MB_YESNO) == IDYES)
											{				
												OnSysPassword();
											}
											else
												return;
										}
										else if(TEXT("数据结转") == s)
											{
												DataFresh();
											}
											else
												return;
	*pResult = 0;
}


void CCbsystemView::OnSysPassword() 
{
	// TODO: Add your command handler code here
	CLogonMod * dlg = new CLogonMod;
	if(dlg->DoModal()==IDOK)
	{
		CString szname,szold;
		CWinApp * pApp = AfxGetApp();
		szname	= pApp->GetProfileString(TEXT("Lgkj\\cbsystem"), TEXT("name"));
		szold	= pApp->GetProfileString(TEXT("Lgkj\\cbsystem"), TEXT("pass"));
		if((szname != dlg->m_name) || (szold != dlg->m_old))
		{
			AfxMessageBox(TEXT("用户名或口令不匹配,更改不成功!!!"));
		}
		else
		{
			pApp->WriteProfileString(TEXT("Lgkj\\cbsystem"), TEXT("pass"), dlg->m_new);
			return;
		}
	}
	else
		return;
}

void CCbsystemView::OnSysSet() 
{
	// TODO: Add your command handler code here
	CSetComm *dlg=new CSetComm(this);
	CWinApp * pApp = AfxGetApp();
	if(dlg->DoModal()==IDOK)
	{
		//sprintf(szCom,"%s-%s-%s-%s-%s",dlg->m_strPort,dlg->m_strBand,dlg->m_strParity,dlg->m_strBitData,dlg->m_strStopBit);
		//Comm.InitPort(this, dlg->m_strPort, atoi(dlg->m_strBand),dlg->m_strParity,atoi(dlg->m_strBitData),atoi(dlg->m_strStopBit),NULL,512);
		pApp->WriteProfileString(TEXT("Lgkj\\com"),TEXT("Port"),dlg->m_strPort);
		pApp->WriteProfileString(TEXT("Lgkj\\com"),TEXT("Band"),dlg->m_strBand);
		pApp->WriteProfileString(TEXT("Lgkj\\com"),TEXT("BitData"),dlg->m_strBitData);
		pApp->WriteProfileString(TEXT("Lgkj\\com"),TEXT("StopBit"),dlg->m_strStopBit);
	}
}

void CCbsystemView::OnSjBrowse() 
{
	// TODO: Add your command handler code here
	CRecordSearch * dlg = new CRecordSearch;
	dlg->DoModal();
}

void CCbsystemView::OnSjWrite() 
{
	// TODO: Add your command handler code here
	CWriteRec dlg;
	if(dlg.DoModal() == IDOK)
	{
		
	}
	else
	{
		return;
	}
}

void CCbsystemView::OnSjQuery() 
{
	// TODO: Add your command handler code here
	SearchRecordNum();
}

void CCbsystemView::OnSjEmpty() 
{
	// TODO: Add your command handler code here
	if(MessageBox(TEXT("[注意]:\n  此操作将删除数据库里的所有数据,并且不能恢复\n   此操作暂时无效!!!"),TEXT("信息提示:"),MB_OKCANCEL)==1)
	{
		Emptydb();
		return;
	}
	else
		return;
}

void CCbsystemView::OnSjJz() 
{
	// TODO: Add your command handler code here
	DataFresh();
}

void CCbsystemView::OnTxDr() 
{
	// TODO: Add your command handler code here
	CFileDialog cfd(TRUE,NULL,NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,_T("文本文件(*.txt)|*.txt|所有文件(*.*)|*.*||"));
	
	if(cfd.DoModal()==IDCANCEL)
		return;

	CFile cf;
	CFileException cfe;
	//TCHAR *tc;
	char *tc;
	if(cf.Open(cfd.GetPathName(),CFile::modeRead,&cfe)==FALSE)
	{
		AfxMessageBox("不能读取文件:"+cfd.GetPathName());
		return;
	}

	tc=new char[cf.GetLength()+1];
	memset(tc,0,cf.GetLength()+1);
	cf.Read(tc,cf.GetLength()+1);
	
	CString str1=tc;
	delete [] tc;
	cf.Close();
	if(!db.Open(TEXT("NEWPOWER"))) 
	{
		AfxMessageBox(TEXT("数据库打开失败!!"));
		//return false;
	}
	AfxGetApp()->BeginWaitCursor();
	//AfxMessageBox(str1);
	CString *sptr=SplitString(str1,'\n');
	int i=0;
	while(sptr[i] != "")
	{

		CString *sp=SplitString(sptr[i],'	');
		InsertTable((LPTSTR)(LPCTSTR)sp[0], (LPTSTR)(LPCTSTR)sp[1], (LPTSTR)(LPCTSTR)sp[2],(LPTSTR)(LPCTSTR)sp[3],(LPTSTR)(LPCTSTR)sp[4],(LPTSTR)(LPCTSTR)sp[5]);
		i++;
	}
	AfxGetApp()->EndWaitCursor();
	AfxMessageBox(_T("数据导入完成"));
}

void CCbsystemView::OnTxDc() 
{
	// TODO: Add your command handler code here
	CSend dlg;
	dlg.DoModal();
}

void CCbsystemView::OnTxSet() 
{
	// TODO: Add your command handler code here
			
	CDbSet *dlg=new CDbSet;
	dlg->DoModal();

}

void CCbsystemView::OnTxCb() 
{
	// TODO: Add your command handler code here
		CDlgCb *dlg=new CDlgCb;
		dlg->DoModal();	
}

void CCbsystemView::OnHelpAbout() 
{
	// TODO: Add your command handler code here
	
}

BOOL CCbsystemView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) 
{
	// TODO: Add your specialized code here and/or call the base class
	
	return CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
}

⌨️ 快捷键说明

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