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

📄 joblist.cpp

📁 该程序实现的是一个在织布厂用的提花机程序
💻 CPP
字号:
#include "stdafx.h"
#include "Wea2.h"
#include "resource.h"
//#include "dib.h"
#include "Wea.h"
//#include "Joblist.h"
//#include "running.h"
#include "global.h"

//extern LANGUAGE g_language;
//extern CJobList g_Job;
/*
Job::Job()
{
	nRepeat=1;
	StartPoint=CPoint(0,0);
}

Job::Job(CString WeaPath,CString WeaFile)
{
	WeaPathName=WeaPath;
	WeaFileName=WeaFile;
	nRepeat=1;
	StartPoint=CPoint(0,0);
}

Job::Job(CString lpszPathName)
{
	CString temp=lpszPathName;
	int n1=temp.ReverseFind('\\');
	int n=temp.GetLength();
	if(n1<0)
		n1=temp.ReverseFind(':');
	WeaFileName=temp.Right(n-n1-1);
	WeaPathName=temp.Left(n1+1);
	nRepeat=1;
	StartPoint=CPoint(0,0);
}

Job::~Job()
{
}
*/
CJobList::CJobList()
{
	m_Mode=HOLE2;
	m_nRepeat=1;
	RemoveAll();
}

CJobList::CJobList(CJobList& job)
{
	m_Mode=job.m_Mode;
	m_Width=job.m_Width;
	m_nRepeat=job.m_nRepeat;
	m_JobFileName=job.m_JobFileName;
	m_JobPathName=job.m_JobPathName;
	int n=GetSize();
	for(int i=0;i<n;i++)
	{
		CWea* pw=(CWea*)GetAt(i);
		delete pw;
	}
	RemoveAll();
	n=job.GetSize();
	for(i=0;i<n;i++)
	{
		CWea* pw=(CWea*)job.GetAt(i);
		CWea* wea=new CWea(*pw);
		Add(wea);
	}
}

CJobList::~CJobList()
{
	int n=GetSize();
	if(n==0)
		return;
	for(int i=0;i<n;i++)
	{
		CWea* wea=(CWea*)GetAt(i);
		delete wea;
	}
	RemoveAll();
}

BOOL CJobList::OpenDocument(CString PathName,CString FileName)
{
	m_JobFileName=FileName;
	m_JobPathName=PathName;
	return ReadFile(PathName+FileName);
}

BOOL CJobList::OpenDocument(LPCTSTR lpszPathName)
{
	CString temp;
	temp.Format(lpszPathName);
	int n1=temp.ReverseFind('\\');
	int n=temp.GetLength();
	if(n1<0)
		n1=temp.ReverseFind(':');
	m_JobFileName=temp.Right(n-n1-1);
	m_JobPathName=temp.Left(n1+1);
	return ReadFile(lpszPathName);
}

BOOL CJobList::SaveDocument()
{
	if(GetSize()==0)
		return FALSE;
	CString jn;
	jn=m_JobPathName+m_JobFileName;
	if(jn.IsEmpty())
		return FALSE;
	return SaveDocument(jn);
}

BOOL CJobList::SaveDocument(LPCTSTR lpszPathName)
{
	CString fullname;
	fullname.Format("%s",lpszPathName);
	int k=fullname.ReverseFind('\\')+1;
	m_JobFileName=fullname.Right(fullname.GetLength()-k);
	m_JobPathName=fullname.Left(k);
	CString fn;
	fn.Format(lpszPathName);
	CString r=fn.Right(3);
	r.MakeLower();
	if(r!=CString("job"))
	{
		AfxMessageBox(IDS_FILE_TYPE_ERROR+g_language);
		return false;
	}
	CStdioFile file;
	CFileException fe;
	if (!file.Open(lpszPathName, CFile::modeCreate| CFile::modeWrite , &fe))
	{
		AfxMessageBox(IDS_OPEN_ERROR+g_language);
		return FALSE;
	}
	CString buff;
	buff.Format("%d\n",m_Mode);  //m_Mode
	file.WriteString(buff);
	int n=GetSize();
	buff.Format("%d\n",n);       //number of weafile
	file.WriteString(buff);
	buff.Format("%d\n",m_Width);
	file.WriteString(buff);
	buff.Format("%d\n",m_nRepeat);//m_nRepeat of the job list
	file.WriteString(buff);
	for(int i=0;i<n;i++)
	{
		CWea* pw=(CWea*)GetAt(i);
		buff.Format("%s\n",pw->m_WeaPathName);
		char* temp=buff.GetBuffer(200);
		file.WriteString(temp);                //WeaPathName
		buff.ReleaseBuffer();
		buff.Format("%s\n",pw->m_WeaFileName);
		 temp=buff.GetBuffer(200);
		file.WriteString(temp);                //WeaFileName
		buff.ReleaseBuffer();
		buff.Format("%d\n",pw->m_StartPoint.x);  //StartPoint.x
		file.WriteString(buff);
		buff.Format("%d\n",pw->m_StartPoint.y);  //StartPoint.y
		file.WriteString(buff);
		buff.Format("%d\n",pw->m_Size.cx);   //WeaSize.cx
		file.WriteString(buff);
		buff.Format("%d\n",pw->m_Size.cy);   //WeaSize.cy
		file.WriteString(buff);
		buff.Format("%d\n",pw->m_nRepeat);       //nRepeat of weafile
		file.WriteString(buff);
	}
	file.Close();

	return TRUE;
}

BOOL CJobList::ReadFile(LPCTSTR lpszPathName)
{
	int n=GetSize();
	if(n>0)
		for(int i=0;i<n;i++)
		{
			CWea* wea=(CWea*)GetAt(i);
			delete wea;
		}
	RemoveAll();
	CString fn,pn,err;
	fn.Format(lpszPathName);
	CString r=fn.Right(3);
	r.MakeLower();
	if((r!=CString("job")) && (r!=CString("wea")))
	{
		AfxMessageBox(IDS_FILE_TYPE_ERROR+g_language);
		return false;
	}

	if(r==CString("wea"))
	{
		m_JobFileName.Empty();
		m_JobPathName.Empty();
		CWea* pw=new CWea;
		if(!pw->OpenDocument(lpszPathName))
		{
			AfxMessageBox(IDS_OPEN_ERROR+g_language);
			delete pw;
			return FALSE;
		}
		if(m_Width>pw->m_Size.cx)
		{
			AfxMessageBox(IDS_WEA_NOT_MATCH+g_language);
			delete pw;
			return FALSE;
		}
		if(pw->m_Size.cx % 4 != 0 )
		{
			err.Format(IDS_WEA_NOT_32MULTP+g_language,pw->m_WeaPathName,pw->m_WeaFileName);
			AfxMessageBox(err);
			delete pw;
			return FALSE;
		}
		pw->m_nRepeat=0;
		Add(pw);
		return TRUE;
	}


	CStdioFile file;
	CFileException fe;
	if (!file.Open(lpszPathName, CFile::modeRead , &fe))
	{
		AfxMessageBox(IDS_OPEN_ERROR+g_language);
		return FALSE;
	}
//	m_JobName.Format("%s",lpszPathName);
	char buff[200];
	file.ReadString(buff,20);
	m_Mode=(WeaMode)atol(buff);
	file.ReadString(buff,20);
	n=atol(buff);
	file.ReadString(buff,20);
	long width=atol(buff);
	if(m_Width!=width)
	{
		AfxMessageBox(IDS_JOB_NOT_MATCH+g_language);
		file.Close();
		return FALSE;
	}
	file.ReadString(buff,20);
	m_nRepeat=atol(buff);
	for(int i=0;i<n;i++)
	{
		CWea* pw=new CWea;
		file.ReadString(buff,200);   //WeaPathName
		pn.Format("%s",buff);
		pn=pn.Left(pn.GetLength()-1);
		file.ReadString(buff,200);  //WeaFileName
		fn.Format("%s",buff);
		fn=fn.Left(fn.GetLength()-1);
		if(!pw->OpenDocument(pn,fn))
		{
			CString s((LPCSTR)IDS_OPEN_ERROR+g_language);
			err.Format(": %s%s ",pw->m_WeaPathName,pw->m_WeaFileName);
			AfxMessageBox(s+err);
			delete pw;
			continue;
		}
		if(m_Width>pw->m_Size.cx)
		{
			AfxMessageBox(IDS_WEA_NOT_MATCH+g_language);
			delete pw;
			continue;
		}
		if(pw->m_Size.cx % 4 != 0 )
		{
			err.Format(IDS_WEA_NOT_32MULTP+g_language,pw->m_WeaPathName,pw->m_WeaFileName);
			AfxMessageBox(err);
			delete pw;
			continue;
		}
		file.ReadString(buff,20);  //StartPoint.x
		pw->m_StartPoint.x=atol(buff);		
		file.ReadString(buff,20);  //StartPoint.y
		pw->m_StartPoint.y=atol(buff);		
		file.ReadString(buff,20);  //WeaSize.cx
		pw->m_Size.cx=atol(buff);	
		file.ReadString(buff,20); //WeaSize.cy
		pw->m_Size.cy=atol(buff);	
		if(pw->m_Wea1->WeaSize!=pw->m_Size)
			pw->SetRange(pw->m_StartPoint,pw->m_Size);
		file.ReadString(buff,20);  //nRepeat of weafile
		pw->m_nRepeat=atol(buff);
		Add(pw);
	}
	file.Close();
	if(GetSize()==0)
		return FALSE;
	else
		return TRUE;
}



void CJobList::Delete(int num)
{
	int n=GetSize();
	if(num<0 || num>n-1)
		return;
	CWea* wea=(CWea*)GetAt(num);
	delete wea;
	RemoveAt(num);
}

BOOL CJobList::Append(CString lpszFullName)
{
	CWea* pw=new CWea;
	if(pw->OpenDocument(lpszFullName))
	{
		if(m_Width>pw->m_Size.cx)
		{
			AfxMessageBox(IDS_WEA_NOT_MATCH+g_language);
			delete pw;
			return FALSE;
		}
		if(m_Width<pw->m_Size.cx)
			pw->SetRange(CPoint(0,0),CSize(m_Width,pw->m_Size.cy));
		Add((CObject*)pw);
		return TRUE;
	}
	else
	{
		delete pw;
		return FALSE;
	}
}

BOOL CJobList::Insert(CString lpszFullName,int index)
{
	CWea* pw=new CWea;
	if(pw->OpenDocument(lpszFullName))
	{
		if(m_Width>pw->m_Size.cx)
		{
			AfxMessageBox(IDS_WEA_NOT_MATCH+g_language);
			delete pw;
			return FALSE;
		}
		if(m_Width<pw->m_Size.cx)
			pw->SetRange(CPoint(0,0),CSize(m_Width,pw->m_Size.cy));
		Insert(index,pw);
		return TRUE;
	}
	delete pw;
	return FALSE;
}
void CJobList::Insert(int num,CWea* pWea)
{
	if(num<0)
		num=0;
	int n=GetSize();
	if(num>=n)
	{
		Add((CObject*)pWea);
		return;
	}
	InsertAt(num,(CObject*)pWea,1);
}

BOOL CJobList::ReArrange()
{
	int n=GetSize();
	if(n==0)
		return FALSE;
	for(int i=0;i<n;i++)
	{
		CWea* pw=(CWea*)GetAt(i);
		pw->ReArrange(m_Mode,m_Width/4);
	}
	return TRUE;
}

CJobList CJobList::operator = (const CJobList& job)
{
	m_Mode=job.m_Mode;
	m_Width=job.m_Width;
	m_nRepeat=job.m_nRepeat;
	m_JobFileName=job.m_JobFileName;
	m_JobPathName=job.m_JobPathName;
	int n=GetSize();
	for(int i=0;i<n;i++)
	{
		CWea* pw=(CWea*)GetAt(i);
		delete pw;
	}
	RemoveAll();
	n=job.GetSize();
	for(i=0;i<n;i++)
	{
		CWea* pw=(CWea*)job.GetAt(i);
		CWea* wea=new CWea(*pw);
		Add(wea);
	}
	return *this;
}

⌨️ 快捷键说明

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