?? arrangerdlg.cpp
字號:
// ArrangerDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Arranger.h"
#include "ArrangerDlg.h"
#include "MyDlg1.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// CArrangerDlg dialog
CArrangerDlg::CArrangerDlg(CWnd* pParent /*=NULL*/)
: CDialog(CArrangerDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CArrangerDlg)
m_L11 = _T("");
m_L12 = _T("");
m_L13 = _T("");
m_L14 = _T("");
m_L15 = _T("");
m_L17 = _T("");
m_L16 = _T("");
m_L18 = _T("");
m_L19 = _T("");
m_L21 = _T("");
m_L22 = _T("");
m_L23 = _T("");
m_L24 = _T("");
m_L25 = _T("");
m_L26 = _T("");
m_L27 = _T("");
m_L28 = _T("");
m_L29 = _T("");
m_L31 = _T("");
m_L32 = _T("");
m_L33 = _T("");
m_L34 = _T("");
m_L35 = _T("");
m_L36 = _T("");
m_L37 = _T("");
m_L38 = _T("");
m_L39 = _T("");
m_L41 = _T("");
m_L42 = _T("");
m_L43 = _T("");
m_L44 = _T("");
m_L45 = _T("");
m_L46 = _T("");
m_L47 = _T("");
m_L48 = _T("");
m_L49 = _T("");
m_L52 = _T("");
m_L51 = _T("");
m_L53 = _T("");
m_L54 = _T("");
m_L55 = _T("");
m_L56 = _T("");
m_L57 = _T("");
m_L58 = _T("");
m_L59 = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CArrangerDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CArrangerDlg)
DDX_Text(pDX, IDC_L11, m_L11);
DDX_Text(pDX, IDC_L12, m_L12);
DDX_Text(pDX, IDC_L13, m_L13);
DDX_Text(pDX, IDC_L14, m_L14);
DDX_Text(pDX, IDC_L15, m_L15);
DDX_Text(pDX, IDC_L17, m_L17);
DDX_Text(pDX, IDC_L16, m_L16);
DDX_Text(pDX, IDC_L18, m_L18);
DDX_Text(pDX, IDC_L19, m_L19);
DDX_Text(pDX, IDC_L21, m_L21);
DDX_Text(pDX, IDC_L22, m_L22);
DDX_Text(pDX, IDC_L23, m_L23);
DDX_Text(pDX, IDC_L24, m_L24);
DDX_Text(pDX, IDC_L25, m_L25);
DDX_Text(pDX, IDC_L26, m_L26);
DDX_Text(pDX, IDC_L27, m_L27);
DDX_Text(pDX, IDC_L28, m_L28);
DDX_Text(pDX, IDC_L29, m_L29);
DDX_Text(pDX, IDC_L31, m_L31);
DDX_Text(pDX, IDC_L32, m_L32);
DDX_Text(pDX, IDC_L33, m_L33);
DDX_Text(pDX, IDC_L34, m_L34);
DDX_Text(pDX, IDC_L35, m_L35);
DDX_Text(pDX, IDC_L36, m_L36);
DDX_Text(pDX, IDC_L37, m_L37);
DDX_Text(pDX, IDC_L38, m_L38);
DDX_Text(pDX, IDC_L39, m_L39);
DDX_Text(pDX, IDC_L41, m_L41);
DDX_Text(pDX, IDC_L42, m_L42);
DDX_Text(pDX, IDC_L43, m_L43);
DDX_Text(pDX, IDC_L44, m_L44);
DDX_Text(pDX, IDC_L45, m_L45);
DDX_Text(pDX, IDC_L46, m_L46);
DDX_Text(pDX, IDC_L47, m_L47);
DDX_Text(pDX, IDC_L48, m_L48);
DDX_Text(pDX, IDC_L49, m_L49);
DDX_Text(pDX, IDC_L52, m_L52);
DDX_Text(pDX, IDC_L51, m_L51);
DDX_Text(pDX, IDC_L53, m_L53);
DDX_Text(pDX, IDC_L54, m_L54);
DDX_Text(pDX, IDC_L55, m_L55);
DDX_Text(pDX, IDC_L56, m_L56);
DDX_Text(pDX, IDC_L57, m_L57);
DDX_Text(pDX, IDC_L58, m_L58);
DDX_Text(pDX, IDC_L59, m_L59);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CArrangerDlg, CDialog)
//{{AFX_MSG_MAP(CArrangerDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTONnew, OnBUTTONnew)
ON_BN_CLICKED(IDC_BUTTONread, OnBUTTONread)
ON_BN_CLICKED(IDC_BUTTONsave, OnBUTTONsave)
ON_BN_CLICKED(IDC_BUTTONchange, OnBUTTONchange)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CArrangerDlg message handlers
BOOL CArrangerDlg::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 CArrangerDlg::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 CArrangerDlg::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 CArrangerDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CArrangerDlg::OnBUTTONnew()
{
// TODO: Add your control notification handler code here
CMyDlg1 MyDlg1;
MyDlg1.DoModal();
}
void CArrangerDlg::OnBUTTONread()
{
// TODO: Add your control notification handler code here
CString FilePathName;
CFileDialog dlg(TRUE,"*.dat",NULL,OFN_OVERWRITEPROMPT,"Data Files (*.dat)|*.dat");
if(dlg.DoModal()==IDOK)
{
FilePathName=dlg.GetPathName();
CFile readList;
if(!readList.Open(FilePathName, CFile::modeReadWrite)||readList.GetLength()==0)
{
MessageBox("讀取信息出錯!","錯誤");
}
else
{
Lesson LesArray[100];
int counter;
CArchive arGetcount( &readList, CArchive::load);
arGetcount >> counter;
arGetcount.Close();
CArchive arRead( &readList, CArchive::load );
for ( int i=0; i < counter; i++)
{
arRead >> LesArray[i].no;
arRead >> LesArray[i].name;
arRead >> LesArray[i].num;
}
arRead.Close();
readList.Close();
int t=0;
for(i=0;t<counter;t++)
{
for(int j=0;j<LesArray[t].num;j++)
{
Les[i+j]=LesArray[t].name;
}
i+=j;
}
while(i<45)
{
Les[i]="自習";
i++;
}
m_L11 = Les[0];
m_L12 = Les[1];
m_L13 = Les[2];
m_L14 = Les[3];
m_L15 = Les[4];
m_L16 = Les[5];
m_L17 = Les[6];
m_L18 = Les[7];
m_L19 = Les[8];
m_L21 = Les[9];
m_L22 = Les[10];
m_L23 = Les[11];
m_L24 = Les[12];
m_L25 = Les[13];
m_L26 = Les[14];
m_L27 = Les[15];
m_L28 = Les[16];
m_L29 = Les[17];
m_L31 = Les[18];
m_L32 = Les[19];
m_L33 = Les[20];
m_L34 = Les[21];
m_L35 = Les[22];
m_L36 = Les[23];
m_L37 = Les[24];
m_L38 = Les[25];
m_L39 = Les[26];
m_L41 = Les[27];
m_L42 = Les[28];
m_L43 = Les[29];
m_L44 = Les[30];
m_L45 = Les[31];
m_L46 = Les[32];
m_L47 = Les[33];
m_L48 = Les[34];
m_L49 = Les[35];
m_L52 = Les[36];
m_L51 = Les[37];
m_L53 = Les[38];
m_L54 = Les[39];
m_L55 = Les[40];
m_L56 = Les[41];
m_L57 = Les[42];
m_L58 = Les[43];
m_L59 = Les[44];
UpdateData(FALSE);
}
}
}
void CArrangerDlg::OnBUTTONsave()
{
// TODO: Add your control notification handler code here
CString FileName;
CFileDialog dlg(FALSE,"*.dat",NULL,OFN_OVERWRITEPROMPT,"Data Files (*.dat)|*.dat");
if(dlg.DoModal()==IDOK)
{
FileName=dlg.GetPathName();
CFile saveList;
saveList.Open(FileName,CFile::modeCreate | CFile::modeReadWrite);
saveList.SeekToBegin();
CArchive arGetCount( &saveList, CArchive::store );
arGetCount << 45;
arGetCount.Close();
for(int n=0;n<45;n++)
{
CArchive arWrite(&saveList,CArchive::store);
saveList.SeekToEnd();
arWrite << n+1 << Les[n] << 1 ;
arWrite.Close();
}
saveList.Close();
}
}
void CArrangerDlg::OnBUTTONchange()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
CString arrLesson[5][9];
for(int k=0;k<5;k++)
{
for(int l=0;l<9;l++ )
{
arrLesson[k][l]="0";
}
}
CFile readList;
if(!readList.Open("list.dat", CFile::modeReadWrite)||readList.GetLength()==0)
{
MessageBox("讀取信息出錯!","錯誤");
}
else
{
Lesson LesArray[100];
int counter;
CArchive arGetcount( &readList, CArchive::load);
arGetcount >> counter;
arGetcount.Close();
CArchive arRead( &readList, CArchive::load );
for ( int i=0; i < counter; i++)
{
arRead >> LesArray[i].no;
arRead >> LesArray[i].name;
arRead >> LesArray[i].num;
}
arRead.Close();
readList.Close();
//以下開始排課*******************
srand(time(0));
for(i=0;i<counter;i++)
{
k=rand()%5;
for(int j=0;j<LesArray[i].num;j++)
{
while(arrLesson[k][0]!="0" && arrLesson[k][1]!="0" && arrLesson[k][2]!="0" && arrLesson[k][3]!="0" && arrLesson[k][4]!="0" && arrLesson[k][5]!="0" && arrLesson[k][6]!="0" && arrLesson[k][7]!="0" && arrLesson[k][8]!="0" )
{
k=rand()%5;
}
int l=rand()%9;
while(arrLesson[k][l]!="0")
{
l=rand()%9;
}
arrLesson[k][l]=LesArray[i].name;
k=(k+3)%5;
}
}
}
int c=0;
for( k=0;k<5;k++)
{
for(int l=0;l<9;l++ )
{
if(arrLesson[k][l]=="0")
{
Les[c]="自習";
}
else{
Les[c]=arrLesson[k][l];
}
c++;
}
}
m_L11 = Les[0];
m_L12 = Les[1];
m_L13 = Les[2];
m_L14 = Les[3];
m_L15 = Les[4];
m_L16 = Les[5];
m_L17 = Les[6];
m_L18 = Les[7];
m_L19 = Les[8];
m_L21 = Les[9];
m_L22 = Les[10];
m_L23 = Les[11];
m_L24 = Les[12];
m_L25 = Les[13];
m_L26 = Les[14];
m_L27 = Les[15];
m_L28 = Les[16];
m_L29 = Les[17];
m_L31 = Les[18];
m_L32 = Les[19];
m_L33 = Les[20];
m_L34 = Les[21];
m_L35 = Les[22];
m_L36 = Les[23];
m_L37 = Les[24];
m_L38 = Les[25];
m_L39 = Les[26];
m_L41 = Les[27];
m_L42 = Les[28];
m_L43 = Les[29];
m_L44 = Les[30];
m_L45 = Les[31];
m_L46 = Les[32];
m_L47 = Les[33];
m_L48 = Les[34];
m_L49 = Les[35];
m_L52 = Les[36];
m_L51 = Les[37];
m_L53 = Les[38];
m_L54 = Les[39];
m_L55 = Les[40];
m_L56 = Les[41];
m_L57 = Les[42];
m_L58 = Les[43];
m_L59 = Les[44];
UpdateData(FALSE);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -