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

📄 scoresentermassdlg.cpp

📁 学生管理系统 学生管理系统
💻 CPP
字号:
// ScoresEnterMassDlg.cpp : implementation file
//

#include "stdafx.h"
#include "学生成绩管理系统.h"
//以下是手工添加的
#include "ScoresRS1.h"
//以上是手工添加的
#include "ScoresEnterMassDlg.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

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

/////////////////////////////////////////////////////////////////////////////
// CScoresEnterMassDlg dialog


CScoresEnterMassDlg::CScoresEnterMassDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CScoresEnterMassDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CScoresEnterMassDlg)
	m_scoresEnterMassAddress = _T("");
	//}}AFX_DATA_INIT
}


void CScoresEnterMassDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CScoresEnterMassDlg)
	DDX_Text(pDX, IDC_SCORES_ENTER_MASS_ADDRESS, m_scoresEnterMassAddress);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CScoresEnterMassDlg, CDialog)
	//{{AFX_MSG_MAP(CScoresEnterMassDlg)
	ON_BN_CLICKED(IDC_GET_ADRRESS, OnGetAdrress)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CScoresEnterMassDlg message handlers

void CScoresEnterMassDlg::OnGetAdrress() 
{
	// TODO: Add your control notification handler code here	
	CString m_strDlgPath;
	CFileDialog dlg(TRUE, _T("*.txt"), _T("*.txt"), OFN_HIDEREADONLY |OFN_OVERWRITEPROMPT,
        _T("文本文件(*.txt)|*.txt|数据文件(*.dat)|*.dat|所有文件(*.*)|*.*|"));    
	if (IDOK== dlg.DoModal())
    {
		m_strDlgPath = dlg.GetPathName();
		//m_ctrDlgPath.SetWindowText(m_strDlgPath);
		m_scoresEnterMassAddress= dlg.GetPathName();
		UpdateData(false);
		//	WinExec("notepad   "+m_strDlgPath,SW_SHOWNORMAL);
    }

}

void CScoresEnterMassDlg::OnOK() 
{
	// TODO: Add extra validation here
	try{
		UpdateData();
		int error=0;
		if(m_scoresEnterMassAddress=="")
			throw error;

		string filename;
		filename=m_scoresEnterMassAddress;
		if (!m_scoresSet.IsOpen())
		{
			m_scoresSet.Open();
		}
		
		ifstream in(filename.c_str());
		char s1[40];
		char s2[40];
		char s3[40];
		char s4[40];
		
		int num;
		double credit;
		
		CString cs1,cs2,cs4,cs5;
		if (!in)
		{
			AfxMessageBox("导入的文件不存在!");
			CDialog::OnOK();
			return ;
		}
		while (!in.eof())
		{
			m_scoresSet.AddNew();
			in.getline(s1, 60,',');
			cs1.Format("%s",s1);
			m_scoresSet.m_ID=cs1;
			
			in.getline(s2,60,',');
			cs2.Format("%s",s2);
			m_scoresSet.m_subject=cs2;
			
			in.getline(s3, 60,',');
			sscanf(s3,"%d",&num);
			m_scoresSet.m_score=num;
			
			if (num>=95)
			{
				credit=5.0;
			}
			else if(num>45)
			{
				credit=(num-45)*0.1;
			}
			else
				credit=0.0;	
			cs5.Format("%.1lf",credit);
			m_scoresSet.m_credit=cs5;
			
			in.getline(s4,40,'\n');
			cs4.Format("%s",s4);
			m_scoresSet.m_category=cs4;
			m_scoresSet.Update();
		}
		AfxMessageBox("批量导入成功!");
		in.close();
		CDialog::OnOK();
	}
	catch(int)
	{
		AfxMessageBox("请先点击“......”,再单击“确定”");
	}
}

⌨️ 快捷键说明

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