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

📄 filerw.cpp

📁 导致教室占用的变更
💻 CPP
字号:

#include "stdafx.h"
#include "FileRW.h"

using namespace ClassRoom;

FileRW::FileRW()
{
	Room = gcnew RoomInfo();
	RootRow = gcnew RoomInfo();
	tempName = "";
	tempRow = gcnew array<String^,2>(5,7);
	NullArray = gcnew array<String^,2>(5,7);
	subjectList = gcnew ArrayList();
	IdlesseClassRoomList = gcnew ArrayList();
}

array<String^,2>^ FileRW::getInfo()
{
	return Room->getInfo();
}

//创建二叉树函数
void FileRW::insertTree(RoomInfo^ root,array<String^,2>^ newRow ,String^ newName)
{
	if(newName->CompareTo(root->getName()) > 0 )
	{
		if(root->rightRoom==nullptr)
		{
			//如果右树为空,建一个右树,传出的值作为右树的根
			root->rightRoom = gcnew RoomInfo(newRow,newName);
		}
		else
		{
			//否则将传入的值放入右树中
			insertTree(root->rightRoom,newRow,newName);
		}
	}
	else if(newName->CompareTo(root->getName()) < 0)
	{
		if(root->leftRoom==nullptr)
		{
			root->leftRoom = gcnew RoomInfo(newRow,newName);
		}
		else
		{
			insertTree(root->leftRoom ,newRow,newName);
		}
	}
	else if(newName->CompareTo(root->getName()) == 0)
	{
		root->setInfo(newRow);
	}
}//End function

//遍历二叉树查找符合要求的教室
RoomInfo^ FileRW::searchRoom(RoomInfo^ root, String^ newClassRoomName )
{
	if(root==nullptr)
	{
		MessageBox::Show("没有相关教室记录!!!","信息提示",MessageBoxButtons::OK,
						 MessageBoxIcon::Information);
		return nullptr;
	}
	if( !root->getName()->CompareTo(newClassRoomName)) //如果根节点就是要找的key,返回true
	{
		return root;
	}
	else if(root->getName()->CompareTo(newClassRoomName) <= 0)//如果key值大于根,递归在右树中查找
	{
		return searchRoom(root->rightRoom , newClassRoomName);
	}

	//如果key值大于根,递归在左树中查找
	return searchRoom(root->leftRoom , newClassRoomName);

}//end functon


//选择教室函数
array<String^,2>^ FileRW::chooseRoom( String^ newClassRoomName)
{
	RoomInfo^ tempRoom = searchRoom(RootRow, newClassRoomName);
	if(tempRoom==nullptr)
		return NullArray;
	else
		return tempRoom->getInfo();

}//End  function

//遍历二叉树查找符合要求的科目名称
void FileRW::searchSubject( RoomInfo^ root, String^ newSubjectName, ArrayList^ subjectList )
{
	if(root != nullptr)
	{
		String^ newString = root->getSubjectInfo(newSubjectName);
		for(int i = 0; i<root->getCount(); i++)
		{
			subjectList->Add(newString->Substring(i*30,30));
		}
		searchSubject(root->rightRoom , newSubjectName, subjectList);
		searchSubject(root->leftRoom , newSubjectName, subjectList);
	}
}//end function

//选择科目函数
ArrayList^ FileRW::chooseSubject( String^ newSubjectName )
{ 
	subjectList->Clear();
	searchSubject( RootRow, newSubjectName, subjectList );
	return subjectList;
}//End

//遍历二叉树查找符合要求的空闲教室
void FileRW::searchIdlesseClassRoom( RoomInfo^ root, int TimeSegment,int Date, ArrayList^ IdlesseClassRoomList )
{
	if(root != nullptr)
	{
		if(!Convert::ToString(root->getInfo()->GetValue(TimeSegment, Date))->Trim()->CompareTo(""))
			IdlesseClassRoomList->Add(root->getName());
		searchIdlesseClassRoom(root->rightRoom, TimeSegment, Date, IdlesseClassRoomList);
		searchIdlesseClassRoom(root->leftRoom , TimeSegment, Date, IdlesseClassRoomList);
	}

}//end  function

ArrayList^ FileRW::chooseIdlesseClassRoom( int TimeSegment,int Date )
{
	IdlesseClassRoomList->Clear();
	searchIdlesseClassRoom( RootRow, TimeSegment,Date,IdlesseClassRoomList );
	return IdlesseClassRoomList;
}

//读取文件内容函数
void  FileRW::ReadText(String^ newPath,Int32^ ClassRoomNumber)
{
	array<Char>^c = gcnew array<Char>(10);
	String^ path = newPath ;
	String^ newString;
	int count = 0;
	int i = 0;
	int j = 0;
	try
	{
		StreamReader^ sr = gcnew StreamReader( path );
		try
		{
			tempRow = gcnew array<String^,2>(5,7);
			for(i=0; i<5; i++)
			{
				if(i==0)
				{
					sr->Read(c, 0, c->Length );
					newString = gcnew String(c,0,5);
					RootRow->setName(newString);
				}
				for(j=0; j<7; j++)
				{
					sr->Read(c, 0, c->Length );
					newString = gcnew String(c);
					tempRow->SetValue(newString,i,j);
				}
			}
			RootRow->setInfo(tempRow);

			for(count = 1; count<(int)ClassRoomNumber;count++)
			{
				tempRow = gcnew array<String^,2>(5,7);
				for(int i=0; i<5; i++)
				{
					if(i==0)
					{
						sr->Read(c, 0, c->Length );
						newString = gcnew String(c,0,5);
						Room->setName(newString);
					}
					for(int j=0; j<7; j++)
					{
						sr->Read(c, 0, c->Length );
						newString = gcnew String(c);
						tempRow->SetValue(newString,i,j);
					}
				}
				Room->setInfo(tempRow);
				insertTree(RootRow ,Room->getInfo() ,Room->getName());

			}
		}
		finally
		{
			delete sr;
		}
	}
	catch ( Exception^ e ) 
	{
		MessageBox::Show(e->Message);
	}

}//end function

⌨️ 快捷键说明

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