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

📄 dlgedisplay.cpp

📁 生生世世 生生世世 生生世世 生生世世 搜索
💻 CPP
字号:
// DlgEDisplay.cpp : implementation file
//

#include "stdafx.h"
#include "finalhomework.h"
#include "DlgEDisplay.h"
#include "DlgEA.h"
//#include "forlogin.h"

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

/////////////////////////////////////////////////////////////////////////////
// CDlgEDisplay dialog


CDlgEDisplay::CDlgEDisplay(int flag)
	: CDialog(CDlgEDisplay::IDD)
{
	//{{AFX_DATA_INIT(CDlgEDisplay)
	m_username = _T("");
	m_UserList = _T("");
	m_team = _T("");
	wenjian1=(char*)malloc(20*sizeof(char));
	wenjian2=(char*)malloc(20*sizeof(char));
	m_ChooseDialog=flag;
	//}}AFX_DATA_INIT
	switch(flag)
	{
	case 1:
		wenjian1="Data2.dat";
		wenjian2="DataN2.dat";
		break;
	case 2:
		wenjian1="Data3.dat";
		wenjian2="DataN3.dat";
		break;
	case 3:
		wenjian1="Data4.dat";
		wenjian2="DataN4.dat";
		break;
	case 4:
		wenjian1="Data5.dat";
		wenjian2="DataN5.dat";
		break;
	}
	FILE *fp;
	char temp[20];
	fp=fopen(wenjian2,"r");
	fscanf(fp,"%d",&m_userN);
	fclose(fp);
	fp=fopen(wenjian1,"r");
	for(int i=0;i<m_userN;i++)
	{
		fscanf(fp,"%s",temp);
		user[i].user=temp;
		m_UserList+=user[i].user;
		m_UserList+="\r\n";
		fscanf(fp,"%s",temp);
		user[i].password=temp;
	}
	fclose(fp);
//	qsort((void *)user,m_userN,sizeof(INF),comp);
}

/*int  CDlgEDisplay::comp(const void *a,const void *b)
{
	return ((INF*)a)->user>=(((INF*)b)->user);
}*/
void CDlgEDisplay::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgEDisplay)
	DDX_Text(pDX, IDC_ECHOOSENAME, m_username);
	DDX_Text(pDX, IDC_EDISPLAY, m_UserList);
	DDX_Text(pDX, IDC_TEAM, m_team);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgEDisplay, CDialog)
	//{{AFX_MSG_MAP(CDlgEDisplay)
	ON_BN_CLICKED(IDC_DELETEUSER, OnDeleteuser)
	ON_BN_CLICKED(IDC_ADDUSER, OnAdduser)
	ON_EN_CHANGE(IDC_ECHOOSENAME, OnChangeEchoosename)
	ON_EN_CHANGE(IDC_EDISPLAY, OnChangeEdisplay)
	ON_BN_CLICKED(IDC_CHANGEINF, OnChangeinf)
	ON_BN_CLICKED(IDC_REFRESH, OnRefresh)
	ON_EN_ERRSPACE(IDC_EDISPLAY, OnErrspaceEdisplay)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgEDisplay message handlers


/*void CDlgEDisplay::OnDisplayList() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	
}

void CDlgEDisplay::OnChooseUser() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
}*/

void CDlgEDisplay::OnDeleteuser() 
{
	// TODO: Add your control notification handler code here
	int flag=-1;
	FILE *fp;
	char temp[200];
	fp=fopen(wenjian1,"r");
	for(int i=0;i<m_userN;i++)
	{
		fscanf(fp,"%s",temp);
		user[i].user=temp;
		if(user[i].user==m_username)
		{
			user[i].user=m_username;
			char *t;
			t=(char *)(LPCSTR)(m_username+"5"+".dat");
			strcpy(temp,t);
			strcpy(temp,(LPCSTR)(m_username+"5"+".dat"));
			remove(temp);
			flag=i;
		}
		fscanf(fp,"%s",temp);
		user[i].password=temp;
	}
	fclose(fp);
	if(flag!=-1){
		fp=fopen(wenjian1,"w+");
		for(i=0;i<m_userN;i++)
		{
			if(i!=flag)
			{
				fprintf(fp,"%s\n",user[i].user);
				fprintf(fp,"%s\n",user[i].password);
			}
		}
		fclose(fp);
		m_userN--;
		fp=fopen(wenjian2,"w+");
		fprintf(fp,"%d",m_userN);
		fclose(fp);
	}
	else
		AfxMessageBox("用户名不存在",MB_OK,-1);
}


void CDlgEDisplay::OnAdduser() 
{
	// TODO: Add your control notification handler code here
	int flag=0;
	for(int i=0;i<m_userN;i++)
	{
		if(user[i].user==m_username)
		{
			flag=1;
			break;
		}
	}
	if(flag==0)
	{
		int N;
		FILE *fp;
		fp=fopen(wenjian2,"r");
		fscanf(fp,"%d",&N);
		fclose(fp);
		N++;
		m_userN=N;
		fp=fopen(wenjian2,"w+");
		fprintf(fp,"%d",N);
		fclose(fp);
		user[N-1].password="0";
		user[N-1].user=m_username;
		fp=fopen(wenjian1,"w+");
		for(i=0;i<N;i++)
		{
			fprintf(fp,"%s\n",user[i].user);
			fprintf(fp,"%s\n",user[i].password);
		}
		fclose(fp);
		switch(m_ChooseDialog)
		{
		/*//case 1:
			CDlgBA dlg;
			dlg.DoModal();
			break;
		//case 2:
			CDlgCA dlg;
			dlg.DoModal();
			break;
		//case 3:
			CDlgDA dlg;
			dlg.DoModal();
			break;*/
		case 4:
			CDlgEA dlg(m_username);
			dlg.DoModal();
			break;
		}
	}
	else
		AfxMessageBox("用户名已存在",MB_OK,-1);
}

void CDlgEDisplay::OnChangeEchoosename() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);	
}

void CDlgEDisplay::OnChangeEdisplay() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	UpdateData(FALSE);
	
}

void CDlgEDisplay::OnChangeinf() 
{
	// TODO: Add your control notification handler code here
	int flag=0;
	for(int i=0;i<m_userN;i++)
	{
		if(user[i].user==m_username)
		{
			flag=1;
			break;
		}
	}
	if(flag==1)
	{
		CDlgEA dlg(m_username);
		dlg.DoModal();
	}
	else
		AfxMessageBox("用户名不存在",MB_OK,-1);
	
}

void CDlgEDisplay::OnRefresh() 
{
	// TODO: Add your control notification handler code here
	FILE *fp;
	char temp[20];
	 m_UserList=_T("");

	fp=fopen(wenjian1,"r");
	for(int i=0;i<m_userN;i++)
	{
		fscanf(fp,"%s",temp);
		user[i].user=temp;
		m_UserList+=user[i].user;
		m_UserList+="\r\n";
		fscanf(fp,"%s",temp);
		user[i].password=temp;
	}
	fclose(fp);
	UpdateData(FALSE);
}

void CDlgEDisplay::OnErrspaceEdisplay() 
{
	// TODO: Add your control notification handler code here
	
}

⌨️ 快捷键说明

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