📄 磁盘管理doc.cpp
字号:
// 磁盘管理Doc.cpp : implementation of the CMyDoc class
//
#include "stdafx.h"
#include "磁盘管理.h"
#include "磁盘管理Doc.h"
#include "FreeCrateDlg.h"
#include "FreeDelDlg.h"
#include "BitCreateDlg.h"
#include "BitDelDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMyDoc
IMPLEMENT_DYNCREATE(CMyDoc, CDocument)
BEGIN_MESSAGE_MAP(CMyDoc, CDocument)
//{{AFX_MSG_MAP(CMyDoc)
ON_COMMAND(ID_CREATEFILE, OnCreatefile)
ON_COMMAND(ID_DELFILE, OnDelfile)
ON_COMMAND(ID_BITCREATEFILE, OnBitcreatefile)
ON_COMMAND(ID_BITDELFILE, OnBitdelfile)
ON_COMMAND(ID_FREEINIT, OnFreeinit)
ON_COMMAND(ID_BITINIT, OnBitinit)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyDoc construction/destruction
CMyDoc::CMyDoc()
{
// TODO: add one-time construction code here
int i ;
DT[0].FreeBlocks = 10 ;
DT[0].OrderNum = 1 ;
DT[0].StarBlock = 1 ;
DT[0].status = 0 ;
for( i = 1 ; i < 10 ; i++ )
{
DT[i].OrderNum = i + 1 ;
DT[i].StarBlock = DT[i-1].FreeBlocks + DT[i-1].StarBlock ;
DT[i].FreeBlocks = 20 * ( i + 1 ) ;
DT[i].status = 0 ;
}
disk.m_CylNum = 0;
disk.m_DiskNum = 0 ;
disk.m_PhyNum = 0 ;
NeedBlock = 0 ;
showfree = 0 ;
showbit = 0 ;
bitred = 0 ;
//j = 0;
//head->next = 0 ;
//head->m_CylNum = 0 ;
//head->m_DiskNum = 0 ;
//head->m_PhyNum = 0 ;
//p = head;
for(i=0;i<200;i++)
{
BitAry[i] = 0 ;
}
}
CMyDoc::~CMyDoc()
{
}
BOOL CMyDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMyDoc serialization
void CMyDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: add storing code here
ar<<NeedBlock;
}
else
{
// TODO: add loading code here
ar>>NeedBlock;
}
}
/////////////////////////////////////////////////////////////////////////////
// CMyDoc diagnostics
#ifdef _DEBUG
void CMyDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CMyDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMyDoc commands
void CMyDoc::OnCreatefile()
{
// TODO: Add your command handler code here
int need;
need = NeedBlock;
CFreeCrateDlg dlg;
showfree = 1 ;
showbit = 0 ;
if(dlg.DoModal()==IDOK)
{
//UpdateData(0);
int i ;
NeedBlock = dlg.m_NeedBlk ;
for(i = 0 ; i < 10 ; i++)
{
if(DT[i].FreeBlocks >= NeedBlock)
{
Red = i ;
break ;
}
}
if(i != 10)
{
DT[i].StarBlock = DT[i].StarBlock + NeedBlock ;
if ( DT[i].FreeBlocks == NeedBlock )
DT[i].status = 1 ;
DT[i].FreeBlocks = DT[i].FreeBlocks - NeedBlock ;
disk.m_CylNum = DT[i].StarBlock/120 ; //20*6=120
disk.m_DiskNum = (DT[i].StarBlock%120)/6 ;
disk.m_PhyNum = ((DT[i].StarBlock%120)-6*disk.m_DiskNum)%6 ;
//UpdateAllViews(NULL);
//j++;
/*newp = new DiskDate ;
newp->m_CylNum = disk.m_CylNum;
newp->m_DiskNum = disk.m_DiskNum;
newp->m_PhyNum = disk.m_PhyNum;
newp->m_phys = NeedBlock;
newp->next = 0 ;
p->next = newp;
p = newp;*/
}
else {
MessageBox(AfxGetApp()->GetMainWnd()->m_hWnd,"没有足够的内存空间",NULL,MB_OK);
NeedBlock = need;
}
//MessageBox("没有足够的存储空间");
}
UpdateAllViews(NULL);
}
void CMyDoc::OnDelfile()
{
// TODO: Add your command handler code here
int i;
int med = 0 ;
int begainblock;
int m;
int d;
int p;
int n;
//int physics;
m=disk.m_CylNum;
d=disk.m_DiskNum;
p=disk.m_PhyNum;
n=NeedBlock;
CFreeDelDlg dlg;
showfree = 1 ;
showbit = 0 ;
if(dlg.DoModal() == IDOK)
{
disk.m_CylNum = dlg.m_cyl;
disk.m_DiskNum = dlg.m_track;
disk.m_PhyNum = dlg.m_physic;
NeedBlock = dlg.m_phys ;
begainblock = ((dlg.m_cyl*20)+dlg.m_track)*6+dlg.m_physic ;
for(i=0;i < 10 ;i++)
{
if( med > begainblock )
{
Red = i - 1;
break;
}
med += 20*(i+1) ;
}
if(begainblock <= DT[i-1].StarBlock)
{
DT[i-1].StarBlock = DT[i-1].StarBlock - NeedBlock;
DT[i-1].FreeBlocks = DT[i-1].FreeBlocks + NeedBlock ;
if(DT[i-1].status == 1)
{
DT[i-1].status = 0 ;
}
//j--;
}
else {
MessageBox(AfxGetApp()->GetMainWnd()->m_hWnd,"该文件不存在!!",NULL,MB_OK);
disk.m_CylNum = m;
disk.m_DiskNum = d;
disk.m_PhyNum = p;
NeedBlock = n ;
}
/*DT[i-1].StarBlock = DT[i-1].StarBlock - NeedBlock;
DT[i-1].FreeBlocks = DT[i-1].FreeBlocks + NeedBlock ;
if(DT[i-1].status == 1)
{
DT[i-1].status = 0 ;
}*/
}
UpdateAllViews(NULL);
}
void CMyDoc::OnBitcreatefile()
{
// TODO: Add your command handler code here
int cyl;
int track;
int physic;
showfree = 0 ;
showbit = 1 ;
CBitCreateDlg dlg;
if(dlg.DoModal() == IDOK)
{
cyl = dlg.m_bitcyl;
track = dlg.m_bitrack;
physic = dlg.m_bitphy ;
bitred = (2*cyl+track)*8 + physic;
if(BitAry[bitred] == 1)
{
MessageBox(AfxGetApp()->GetMainWnd()->m_hWnd,"该块已经被占用!!",NULL,MB_OK);
}
else
{
BitAry[bitred] = 1 ;
}
}
UpdateAllViews(NULL);
}
void CMyDoc::OnBitdelfile()
{
// TODO: Add your command handler code here
int cyl;
int track;
int physic;
showfree = 0 ;
showbit = 1 ;
CBitDelDlg dlg;
if(dlg.DoModal() == IDOK)
{
cyl = dlg.m_bitdelcyl;
track = dlg.m_bitdeltrack;
physic = dlg.m_bitdelphy ;
bitred = (2*cyl+track)*8 + physic;
if(BitAry[bitred] == 0)
{
MessageBox(AfxGetApp()->GetMainWnd()->m_hWnd,"该文件不存在,释放失败!!",NULL,MB_OK);
}
else
{
BitAry[bitred] = 0 ;
}
}
UpdateAllViews(NULL);
}
void CMyDoc::OnFreeinit()
{
// TODO: Add your command handler code here
showfree = 1;
showbit = 0 ;
Red = 111;
int i ;
DT[0].FreeBlocks = 10 ;
DT[0].OrderNum = 1 ;
DT[0].StarBlock = 1 ;
DT[0].status = 0 ;
for( i = 1 ; i < 10 ; i++ )
{
DT[i].OrderNum = i + 1 ;
DT[i].StarBlock = DT[i-1].FreeBlocks + DT[i-1].StarBlock ;
DT[i].FreeBlocks = 20 * ( i + 1 ) ;
DT[i].status = 0 ;
}
UpdateAllViews(NULL);
}
void CMyDoc::OnBitinit()
{
// TODO: Add your command handler code here
int i;
showfree = 0 ;
showbit = 1 ;
bitred = 300;
for(i=0;i<200;i++)
{
BitAry[i] = 0 ;
}
UpdateAllViews(NULL);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -