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

📄 clsdlgedit.cpp

📁 利用MFC,实现投票系统
💻 CPP
字号:
// clsDlgEdit.cpp : implementation file
//

#include "stdafx.h"
#include "ballot.h"
#include "clsDlgEdit.h"
#include "clsBallot.h"

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

/////////////////////////////////////////////////////////////////////////////
// clsDlgEdit dialog


clsDlgEdit::clsDlgEdit(CWnd* pParent /*=NULL*/)
	: CDialog(clsDlgEdit::IDD, pParent)
{
	//{{AFX_DATA_INIT(clsDlgEdit)
	m_Num = _T("");
	m_Name = _T("");
	m_synopsis = _T("");
	m_enounce = _T("");
	//}}AFX_DATA_INIT
}


void clsDlgEdit::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(clsDlgEdit)
	DDX_Control(pDX, IDC_NUM, m_Num_Edit_edit);
	DDX_Text(pDX, IDC_NUM, m_Num);
	DDX_Text(pDX, IDC_NAME, m_Name);
	DDX_Text(pDX, IDC_SYNOPSIS, m_synopsis);
	DDX_Text(pDX, IDC_ENOUNCE, m_enounce);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(clsDlgEdit, CDialog)
	//{{AFX_MSG_MAP(clsDlgEdit)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// clsDlgEdit message handlers

void clsDlgEdit::OnCancel() 
{
	clsBallot show ;
	CDialog::OnCancel();
	show.DoModal();
}

void clsDlgEdit::OnOK() 
{  
	clsBallot show ;
	CStringArray strArray;
	CStdioFile readFile;
	CString    strText;
	CString    strWrite;
	CFile      addFile;
	CString Temp;
	UpdateData(TRUE);
	if(strlen(m_Name)==0)
	{
		MessageBox("候选人的姓名修改时不能为空","电子投票系统",MB_OK); 
	}
    else if(strlen(m_Num)==0)
	{
		MessageBox("候选人的编号修改时不能为空","电子投票系统",MB_OK); 
	}
	else
	{
		readFile.Open("candidate.dat",CStdioFile::modeRead | CStdioFile::typeText);
		while(readFile.ReadString(strText))
		{
			strArray.Add(strText);
		}
	    readFile.Close();
		strWrite=m_Num+","+m_Name+","+m_synopsis+","+m_enounce;
		strArray.SetAt(int_List_Index,strWrite);
		addFile.Open("candidate.dat",CFile::modeCreate|CFile::modeWrite);
		for(int i=0;i<strArray.GetSize();i++)
		{
			Temp=(CString)strArray[i];
			addFile.Write((Temp+"\r\n"),strlen(Temp+"\r\n"));
		}
		addFile.Close();
		MessageBox("信息已经被成功修改","电子投票系统",MB_OK);
	}
	CDialog::OnCancel();
	show.DoModal();
}

BOOL clsDlgEdit::OnInitDialog() 
{
	CDialog::OnInitDialog();
	m_Num=str_Num;
	m_Name=str_Name;
	m_enounce=str_enounce;
	m_synopsis=str_synopsis;
	m_Num_Edit_edit.SetFocus();
	UpdateData(FALSE);
	// TODO: Add extra initialization here
	return FALSE;  // 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 + -