📄 400mfcdlg.cpp
字号:
// 400MFCDlg.cpp : implementation file
//
#include "stdafx.h"
#include "400MFC.h"
#include "400MFCDlg.h"
#include <afxdlgs.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//ADD BY LZX
#define STU_NUM_ALL 3001
#define SCH_NUM_ALL 51
#define CLA_NUM_ALL 100
#define STU_NUM_ALL40 1200
typedef struct _STUDENT_
{ // stu
short int NUM; //序号
char name[10]; //姓名
char sex[3]; //性别
char chinese; //语文成绩
char math; //数学成绩
char school[50]; //毕业学校
int classnum; //班级
unsigned int clssssign; //座号
} STUDENT;
int student_num = 0;
STUDENT stu[STU_NUM_ALL];
typedef struct _SCHOOL_
{ // sch
char school[50]; //毕业学校
int studentnum; //同一学校的人数
short int num[2000]; //同一学校人的序号表
} SCHOOL;
int school_num = 0;
SCHOOL sch[SCH_NUM_ALL];
typedef struct _CLASS_
{ // cla
int studentnum; //同一班级的人数
short int num[200]; //同一班级人的序号表
} CLASS;
int class_num = 0;
CLASS cla[CLA_NUM_ALL];
typedef struct _CHANGE_
{ // cla
unsigned int num; //要调整的序号
short int classnum; //要调去的班级
} CHANGE;
int change_num = 0;
CHANGE change[41];
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMy400MFCDlg dialog
CMy400MFCDlg::CMy400MFCDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMy400MFCDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMy400MFCDlg)
m_address_file = _T("");
m_nStuNum = 0;
m_nClaNum = 10;
m_SSaveFileName = _T("输出.txt");
m_bSaveMiddleFile = FALSE;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMy400MFCDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMy400MFCDlg)
DDX_Text(pDX, IDC_EDIT1, m_address_file);
DDX_Text(pDX, IDC_EDIT2, m_nStuNum);
DDX_Text(pDX, IDC_EDIT3, m_nClaNum);
DDX_Text(pDX, IDC_EDIT4, m_SSaveFileName);
DDX_Check(pDX, IDC_CHECK1, m_bSaveMiddleFile);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMy400MFCDlg, CDialog)
//{{AFX_MSG_MAP(CMy400MFCDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnChkChooseFile)
ON_BN_CLICKED(IDC_BUTTON3, OnStart)
ON_BN_CLICKED(IDC_BUTTON4, OnHelp_lzx)
ON_BN_CLICKED(IDC_BUTTON2, OnButMakeSample)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMy400MFCDlg message handlers
BOOL CMy400MFCDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CMy400MFCDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CMy400MFCDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CMy400MFCDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMy400MFCDlg::OnChkChooseFile()
{
// TODO: Add your control notification handler code here
// CFileDialog dlg(TRUE, NULL, NULL);//
CFileDialog dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY,"Text files(*.txt)|*.txt|All files(*.*)|*.*||",this);
if (IDOK != dlg.DoModal())
{
return;
}
UpdateData(TRUE);
m_address_file = dlg.GetPathName();
char rbuf[2] = {0};
char buf[50] = {0};
int i = 0;
int j = 0;
school_num = 0;
student_num = 0;
FH = fopen(m_address_file, "r+");
if (NULL == FH)
{
MessageBox("error 1\nfalse to open the file!");
return;
}
fseek(FH,0,SEEK_SET);
do //read fist line
{
if (1 != fread(rbuf, 1, 1, FH))
{
fclose(FH);
MessageBox("error 2\nthe file is null!");
return;
}
} while(0x0a != rbuf[0]);
while (1)
{
student_num++;
if (student_num > STU_NUM_ALL)
{
student_num--;
MessageBox("error 3\nStudent num to more!");
goto go_out_read_choose_file;
}
i = 0;
do //read NUM
{
if (1 != fread(rbuf, 1, 1, FH))
{
student_num--;
if (0 != i)
{
MessageBox("error 4\nthe last is not integrity!");
}
goto go_out_read_choose_file;
}
if (rbuf[0]>'9' || rbuf[0]<'0' || i>9)//
{
if (0x09 == rbuf[0]) // only read the tab key
{
buf[i] = 0;
stu[student_num].NUM = atoi(buf);
break;
}
else
{
student_num--;
MessageBox("error 5\nthe num is error!");
goto go_out_read_choose_file;
}
}
buf[i] = rbuf[0];
i++;
} while(1);
do //read the tab key behind the num
{
if (1 != fread(rbuf, 1, 1, FH))
{
student_num--;
MessageBox("error 6\nthis line no name");
goto go_out_read_choose_file;
}
if (0x09 == rbuf[0])
{
continue;
}
if (rbuf[0]>0 && rbuf[0]<0x20)
{
student_num--;
MessageBox("error 7\nthis line no name");
goto go_out_read_choose_file;
}
else
{
break;
}
} while(1);
stu[student_num].name[0] = rbuf[0];
i = 1;
do //read name
{
if (1 != fread(rbuf, 1, 1, FH))
{
student_num--;
MessageBox("error 8\nthis line no sex");
goto go_out_read_choose_file;
}
if (rbuf[0]>0 && rbuf[0]<0x20)
{
if (0x09 == rbuf[0])
{
stu[student_num].name[i] = 0;
break;
}
else
{
student_num--;
MessageBox("error 9\nthis line name have other char!");
goto go_out_read_choose_file;
}
}
stu[student_num].name[i] = rbuf[0];
i++;
if (i >= 9)//if is 9,then 0-8 is err
{
student_num--;
MessageBox("error 10\nthis line name more then 8 bytes!");
goto go_out_read_choose_file;
}
} while(1);
do //read the tab key behind the name
{
if (1 != fread(rbuf, 1, 1, FH))
{
student_num--;
MessageBox("error 11\nthis line no sex");
goto go_out_read_choose_file;
}
if (0x09 == rbuf[0])
{
continue;
}
if (rbuf[0]>0 && rbuf[0]<0x20)
{
student_num--;
MessageBox("error 12\nthis line no sex");
goto go_out_read_choose_file;
}
else
{
break;
}
} while(1);
stu[student_num].sex[0] = rbuf[0];
i = 1;
do //read sex
{
if (1 != fread(rbuf, 1, 1, FH))
{
student_num--;
MessageBox("error 13\nthis line no chinese");
goto go_out_read_choose_file;
}
if (rbuf[0]>0 && rbuf[0]<0x20)
{
if (0x09 == rbuf[0])
{
stu[student_num].sex[i] = 0;
break;
}
else
{
student_num--;
MessageBox("error 14\nthis line sex have other char!");
goto go_out_read_choose_file;
}
}
stu[student_num].sex[i] = rbuf[0];
i++;
if (i >= 3)
{
student_num--;
MessageBox("error 15\nthis line sex more then 2 bytes!");
goto go_out_read_choose_file;
}
} while(1);
if ((0 != strcmp(stu[student_num].sex, "男")) && (0 != strcmp(stu[student_num].sex, "女")))
{
student_num--;
MessageBox("error 16\nthis line sex is not men or women!");
goto go_out_read_choose_file;
}
do //read the tab key behind the sex
{
if (1 != fread(rbuf, 1, 1, FH))
{
student_num--;
MessageBox("error 17\nthis line no chinese!");
goto go_out_read_choose_file;
}
if (0x09 == rbuf[0])
{
continue;
}
if (rbuf[0]>0 && rbuf[0]<0x20)
{
student_num--;
MessageBox("error 18\nthis line no chinese!");
goto go_out_read_choose_file;
}
else
{
break;
}
} while(1);
if (rbuf[0]>='A' && rbuf[0]<='C')
{
stu[student_num].chinese = rbuf[0];//read chinese
}
else
{
student_num--;
MessageBox("error 19\nthis line chinese isn't A-C!");
goto go_out_read_choose_file;
}
if (1 != fread(rbuf, 1, 1, FH))
{
student_num--;
MessageBox("error 20\nthis line no math!");
goto go_out_read_choose_file;
}
if (0x09 != rbuf[0])
{
student_num--;
MessageBox("error 21\nthis line chinese is error!");
goto go_out_read_choose_file;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -