Exemplo n.º 1
0
void CCompilerDlg::OnBnClickedCompile()
{
	// TODO: 在此添加控件通知处理程序代码
	CStdioFile myFile;
	CFileException fileException;
	CString DiyText;
	//获得EDIT  
	CEdit* pDiyText; 
	pDiyText = (CEdit*) GetDlgItem(IDC_EDIT1); 
	pDiyText-> GetWindowText(DiyText);

	CopyFile((CString)"DiyRaw.txt",(CString)"Diy.c",false);
	
 	if (!myFile.Open(_T("Diy.c"), CFile::modeNoTruncate |  CFile::typeText |  CFile::modeReadWrite, &fileException )){
		MessageBox(_T("代码生成失败,请重试"),_T("编译"),MB_OK);
	}
	myFile.Seek(0,CFile::end);
	myFile.WriteString(DiyText);
	myFile.Seek(0,CFile::end);
	myFile.WriteString((LPCTSTR)"}");

	ShellExecute(NULL,_T("open"),_T("compile.bat"),NULL,NULL,SW_SHOW);

	myFile.Close();
	DiyText.ReleaseBuffer();
}
Exemplo n.º 2
0
/******************************************************************
 *  此删除主要使用与此路径名相同长度的空格串来覆盖                *
 ******************************************************************/
BOOL CStaticAssistant::DeleteUncryptInfo(CString path,CString fileName){
		CStdioFile File;
		CString spacei="                                                                                                                               ";
		CString temp=_T("");
		int     tempLen=0;
	try{
		File.Open(fileName,CFile::modeReadWrite|CFile::modeCreate|CFile::modeNoTruncate);
		File.SeekToBegin();
		//遍历文件数据获取插入位置
		while(File.ReadString(temp)==true){
			tempLen=temp.GetLength()+2;         //重要,考虑换行符占2字节
			temp.TrimLeft(); temp.TrimRight(); //消除左右空格
			if(temp==path){
				int len=temp.GetLength();
				spacei=spacei.Left(len);
				File.Seek(-tempLen,CFile::current); //回退文件内部指针
			    File.WriteString(spacei);           //写入要加入的路径名
			    return TRUE;
			}
		}
		File.Close();   
		return FALSE;//关闭文件并返回
	}catch(...){
		File.Close();
		return FALSE;
	}
}
Exemplo n.º 3
0
/******************************************************************
 *   如过文件中有空格行,则加到第一个空格行处,否则               *
 * 加到文件的末尾,为了方面后面的删除行操作,应该再添加路径末尾   *
 * 自动添加足够(超过需要加密的最长路径的长度)多的空格           *
 ******************************************************************/
BOOL CStaticAssistant::StoreEncryptInfo(CString path,CString fileName){
		CStdioFile File;
		CString spacei="                                                                                                                      ";
		CString temp=_T("");
		int     tempLen=0;
	try{
		File.Open(fileName,CFile::modeReadWrite|CFile::modeCreate|CFile::modeNoTruncate);
		File.SeekToBegin();
		//遍历文件数据获取插入位置
		while(File.ReadString(temp)==true){
			tempLen=temp.GetLength()+2;         //重要,考虑换行符占2字节
			temp.TrimLeft(); temp.TrimRight(); //消除左右空格
			if(temp==""){
				File.Seek(-tempLen,CFile::current);
			    File.WriteString(path);  //写入要加入的路径名
			    return TRUE;
			}
		}
		File.WriteString(path+spacei+"\n");  ///写入末尾
		return TRUE;
	}catch(...){
		File.Close();
		return FALSE;
		AfxMessageBox("保存重要文件失败,请重试!");
	}
	return true;
}
Exemplo n.º 4
0
void COTDKView::gAddSigInTest(CString csNameNode, CString csBuf, int iCountT)
{
	LPTSTR p=NULL; DWORD dwPosition=NULL;
	CString s1=' '; CStdioFile Fl;
	COTDKDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc); 
	s1 = csBuf.Mid(0,4);
	p =  s1.GetBuffer(4);
	//здесь добавить блок сравнения первой и второй сигнатуры
	Fl.Open(csNameNode + ".sig", CFile::modeReadWrite); 
	if (iCountT == 1) {
		if (iCountTest==1) dwPosition = pDoc->gGetPosString(0, "ffff", &Fl);
		else dwPosition = pDoc->stPos.dwPos1;
	}
	else if (iCountT == 2) {
		if (iCountTest==2) {
			pDoc->stPos.dwPos1 = pDoc->gGetPosString(0, "ffff", &Fl);
			pDoc->stPos.dwPos2 = pDoc->gGetPosString(pDoc->stPos.dwPos1, "ffff", &Fl);
		}
		dwPosition = pDoc->stPos.dwPos2;
	}
	else {
		pDoc->stPos.dwPos1 = pDoc->gGetPosString(0, "ffff", &Fl);
		pDoc->stPos.dwPos2 = pDoc->gGetPosString(pDoc->stPos.dwPos1, "ffff", &Fl);
		pDoc->stPos.dwPos3 = pDoc->gGetPosString(pDoc->stPos.dwPos2, "ffff", &Fl);
		dwPosition = pDoc->stPos.dwPos3;
	}
	Fl.Seek((LONG)dwPosition-1, CFile::begin);
	Fl.Write(p,4); 	Fl.Close();
}
Exemplo n.º 5
0
/**
 *  Writes a debug string to a file or an Edit box
 *
 *  For speed purposes this code is #define out.
 *  
 *  Uncomment the appropriate #define section when debug
 *  is required
 */
void ManifestXML_Handler::Debug(CString debugMessage)
{
//#define DEBUG_TO_EDIT 
#ifdef DEBUG_TO_EDIT

    if (m_OutputEdit->m_hWnd != 0)
    {
	    CString tempString;
	    this->m_OutputEdit->GetWindowText(tempString);
	    this->m_OutputEdit->SetWindowText(tempString + debugMessage + "\r\n");
    }

#endif

//#define DEBUG_TO_FILE
#ifdef DUBUG_TO_FILE

    CStdioFile* errorFile = new CStdioFile("C:\\debug.txt", CFile::modeCreate 
                                                          | CFile::modeNoTruncate
                                                          | CFile::modeWrite );
    LPCTSTR errorMessage = (LPCTSTR)debugMessage;
    errorFile->Seek(0, CFile::end);
    errorFile->WriteString(errorMessage);
    errorFile->WriteString("\n");
    errorFile->Close();
#endif
}
Exemplo n.º 6
0
void CBlokRtf::GetStdPWS(CString strBuf, CStdioFile &inF, CStdioFile &otF, CString strFnd, int &curPrv, CString &strOut)
{
	int tPos,iCnt;
	CString strWrt,s;
	inF.ReadString(strBuf);

	if((tPos = strBuf.Find(strFnd))!=-1){
		strWrt = strBuf.Left(tPos);   //Считал для записи в цел. файл

		iCnt = strWrt.GetLength();

//		s.Format("после читки curPrv = %i",curPrv);
//		AfxMessageBox("GetStdPWt "+strFnd+'\n'+"strWrt = "+strWrt +'\n'+ s+'\n'+"strBuf = "+strBuf);
//		AfxMessageBox(strWrt);

		strOut+=strWrt;

		curPrv+=iCnt;
		//Перемещаю указатель на новою позицию от нач.файла !!!
		inF.Seek(curPrv,CFile::begin);
			curPrv = inF.GetPosition();
//			s.Format(" после смещения Seek curPrv = %i назад на iCnt = %i",curPrv,iCnt);
//		AfxMessageBox(s);
		return;// curPos;
	}
	else{						// Не нашёл, можно читать дальше
//AfxMessageBox("Не нашёл \n"+strBuf);
//		otF.WriteString(strBuf);	// Записал
		strOut+=strBuf;
		curPrv = inF.GetPosition();
		GetStdPWS(strBuf, inF, otF, strFnd,curPrv,strOut);
		return;
	}

}
Exemplo n.º 7
0
void CCompilerDlg::OnBnClickedRestore2()
{
	// TODO: Add your control notification handler code here
	CStdioFile myFile;
	CFileException fileException;
	CString DiyText;
	//获得EDIT  
	CEdit* pDiyText; 
	pDiyText = (CEdit*) GetDlgItem(IDC_EDIT1); 
	pDiyText-> GetWindowText(DiyText);

	
 	if (!myFile.Open(_T("backup.txt"), CFile::modeCreate |  CFile::typeText |  CFile::modeReadWrite, &fileException )){
		MessageBox(_T("备份失败,请重试"),_T("备份"),MB_OK);
	}
	myFile.Seek(0,CFile::end);
	myFile.WriteString(DiyText);
	MessageBox(_T("备份成功!"),_T("备份"),MB_OK);

	myFile.Close();
	DiyText.ReleaseBuffer();
}
Exemplo n.º 8
0
//写到指定的行,及替换原来的行
BOOL faceRecognition::addFaceImgArray(char *name,bool flag,int row){
	CStdioFile  fwrite;
    CString S1="";
	row=row-1;
	CString  temp=CString(name);
	//temp=temp+"\n";//自动加上换行符号
	try{
		if(flag==true) 
		{//for train
			if(fwrite.Open(learnFileListPath,CStdioFile::modeReadWrite|CStdioFile::modeCreate|CStdioFile::modeNoTruncate)==FALSE)
				AfxMessageBox("打开文件 "+CString(learnFileListPath)+" 失败!!");
		}else{
			if(fwrite.Open(testFileListPath,CStdioFile::modeReadWrite)==FALSE)
				AfxMessageBox("打开文件 "+CString(testFileListPath)+" 失败!!");
		}
		fwrite.SeekToBegin();
		for(int i=0; i<row; i++){
			fwrite.ReadString(S1);
		}
        fwrite.ReadString(S1); //指针指向第row+1行开头
		///fwrite.ReadString(S2);
        fwrite.Seek(-S1.GetLength()-2,CFile::current);  //考虑回车换行符//指针指向第row行开头
        fwrite.WriteString(temp);
		// AfxMessageBox(S2);
		//fwrite.WriteString(temp);
// 		int len=S1.GetLength()-2-temp.GetLength();
// 		if(len>0)       //用指定符号覆盖多余字符
		fwrite.SeekToBegin();
		fwrite.Close();
	}catch(CFileException e)
	{
        fwrite.Close();
		AfxMessageBox("文件写入失败::"+CString(name));
	}	 
	return true;
}
Exemplo n.º 9
0
void COTDKView::gAddDiaInTest(CString csNameNode, CString csBuf, int iCountDT)
{
	LPTSTR p=NULL; DWORD dwPosSch = 0, dwPosO2 = 0; char buf[2];
	CString csS, csW, csNameOfFind; CStdioFile Fl; int iCycle = 0;
	int j = 0, x = 0; int i=1, k=0;
	COTDKDoc* pDoc = GetDocument(); 
	ASSERT_VALID(pDoc); 
	// открываем файл диаг.теста для соответствующ. узла
	Fl.Open(csNameNode + ".dia", CFile::modeReadWrite); 
	//itoa - перевод числа в строку
	// выбираем # теста 
	itoa(iCountDT,buf,10);
	csNameOfFind = "ИмяТеста"; csNameOfFind +=  buf; 
	csNameOfFind.AnsiToOem(); // переводим в OEM стандарт 
	dwPosSch = pDoc->gGetPosString(0, csNameOfFind, &Fl);
	/*// выбираем место задания количества циклов в тесте
	csNameOfFind = "ЧислоЦиклов"; 	csNameOfFind.AnsiToOem(); 
	dwPosSch = pDoc->gGetPosString(dwPosSch, csNameOfFind, &Fl);
	//выбираем число циклов
	Fl.Seek((LONG)dwPosSch+10,CFile::begin);
	Fl.Read(buf, 2);	iCycle = atoi(buf);*/
	// ищем вхождение первого входного слова = о1
	dwPosSch = pDoc->gGetPosString(dwPosSch, "o1=signatura", &Fl);
	// а в нем ищем вхождение шаблона ffff
	Fl.ReadString(csS); Fl.ReadString(csS); 
	dwPosSch = Fl.GetPosition();
	dwPosO2 = pDoc->gGetPosString(dwPosSch, "o2=counter", &Fl);
	Fl.ReadString(csS); Fl.ReadString(csS); 
	dwPosO2 = Fl.GetPosition();
	// здесь будет часть выбирающая номер цикла и передающая что вставить
	//dwPosSch = (DWORD)Fl.Seek((LONG)1, CFile::current);
	iCycle = (int)csBuf.GetLength()/12;
	while(i <= iCycle) {
		// берем что писать
		//j = j + 4;	
		csS = csBuf.Mid(j,4);
		// берем номер цикла
		j = j + 4;	csW = csBuf.Mid(j,2); j = j + 2; 
		if (csW.Find("0a") == 0) csW = "10";
		else if	(csW.Find("0b") == 0) csW = "11";
		else if	(csW.Find("0c") == 0) csW = "12";
		else if	(csW.Find("0d") == 0) csW = "13";
		else if	(csW.Find("0e") == 0) csW = "14"; 
		else if	(csW.Find("0f") == 0) csW = "15";
		x = atoi(csW.GetBuffer(2));
		if (i == x + 1) {
			if (k == 0) {
				Fl.Seek((LONG)dwPosSch+x*6, CFile::begin);  
				if (i < iCycle) csS+="\n\r";
				p =  csS.GetBuffer(6); k = 1;
			}
			else {
				Fl.Seek((LONG)dwPosO2+x*6, CFile::begin);   
				if (i < iCycle) csS+="\n\r";
				p =  csS.GetBuffer(6); k = 0; i++;
			}
			Fl.WriteString(p); //Write(p,4); 
		}
		else while (i < x + 1) i++;	
	}// while i
	Fl.Close();
}
Exemplo n.º 10
0
/*****************************************************************************
  Function Name    :  COM_bSetCheckSum                                          
  Input(s)         :  omStrConfigFileName : reference to File name          
                      pucCheckSum : Returns computed check sum              
  Output           :  BOOL                                                  
  Functionality    :  This method computes the checksum for a given bytes   
                      in a file. The file is opened and checksum is computed
                      for all bytes except the last byte. Returns TRUE for  
                      sucess and FALSE for failure. The same checksum is    
                      overwritten at the last byte in file. For COM Support                                      
  Member of        :  CComputeCheckSum                                      
  Friend of        :      -        
  Author		   : Anish kr
  Creation Date	   : 6/05/10
  Modifications	   :                                              
******************************************************************************/
BOOL CComputeCheckSum::COM_bSetCheckSum(CString &omStrConfigFileName,
                                        UCHAR* pucCheckSum, CString &strError)
{
    CStdioFile omStdiofile;
    CFileException omException;
    DWORD dwSize                 = 0;
    DWORD dwRead                 = 0;
    BOOL bReturn                 = FALSE;
    BOOL bFileOpen               = FALSE;
    CString omStrStrErrorMessage = _T("");
    TCHAR  acErrorMsg[defSIZE_OF_ERROR_BUFFER];

    // Open the configration file template.
    TRY
    {
        bFileOpen = omStdiofile.Open(omStrConfigFileName,
                                     CFile::modeReadWrite| CFile::typeBinary,
                                     &omException);
        if(bFileOpen!=FALSE)
        {
            UCHAR *pucBuff   = NULL;
            UCHAR  ucCheckSum = 0;
            // Get the size of file
            dwSize = (DWORD)omStdiofile.GetLength();        
            pucBuff = static_cast<UCHAR*> (new UCHAR[dwSize]);
            if(pucBuff!=NULL)
            {
                // Read the whole file and put the content to pucBuff;
                dwRead = omStdiofile.Read(pucBuff,dwSize);
                // compute the checksum
                bReturn = bComputeCheckSum(pucBuff,dwSize, &ucCheckSum);
                if(bReturn == TRUE)
                {
                    // Seek to the last byte to store checksum
                    omStdiofile.Seek(dwSize,CFile::begin);
                    // Write one byte checksum
                    omStdiofile.Write(&ucCheckSum,1);
                    // return the checksum
                    if(pucCheckSum!= NULL )
                    {
                        *pucCheckSum = ucCheckSum;
                    }
                    else
                    {
                        bReturn = FALSE;
                    }
                }
                delete [] pucBuff;
                pucBuff = NULL;
            }
            omStdiofile.Close();
        }
        else
        {
          // Get the exception error message
          omException.GetErrorMessage(acErrorMsg,sizeof(acErrorMsg));
          // configuration file open error notification 
        }
    
    }
    CATCH_ALL(pomE)
    {
      if(pomE != NULL )
      {
        // Get the exception error message
        pomE->GetErrorMessage(acErrorMsg,sizeof(acErrorMsg));
      }
    }
    END_CATCH_ALL
 
    strError = acErrorMsg;
     
    return bReturn;
}
Exemplo n.º 11
0
void CServerList::AddServersFromTextFile(const CString& strFilename)
{
	CStdioFile f;
	// open the text file either in ANSI (text) or Unicode (binary), this way we can read old and new files
	// with nearly the same code..
	bool bIsUnicodeFile = IsUnicodeFile(strFilename); // check for BOM
	if (!f.Open(strFilename, CFile::modeRead | CFile::shareDenyWrite | (bIsUnicodeFile ? CFile::typeBinary : 0)))
		return;

	try	{
		if (bIsUnicodeFile)
			f.Seek(sizeof(WORD), CFile::current); // skip BOM

		CString strLine;
		while (f.ReadString(strLine))
		{
			// format is host:port,priority,Name
			if (strLine.GetLength() < 5)
				continue;
			if (strLine.GetAt(0) == _T('#') || strLine.GetAt(0) == _T('/'))
				continue;

			// fetch host
			int pos = strLine.Find(_T(':'));
			if (pos == -1){
				pos = strLine.Find(_T(','));
				if (pos == -1) 
					continue;
			}
			CString strHost = strLine.Left(pos);
			strLine = strLine.Mid(pos+1);
			// fetch  port
			pos = strLine.Find(_T(','));
			if (pos == -1)
				continue;
			CString strPort = strLine.Left(pos);
			strLine = strLine.Mid(pos+1);

			// Barry - fetch priority
			pos = strLine.Find(_T(','));
			int priority = SRV_PR_HIGH;
			if (pos == 1)
			{
				CString strPriority = strLine.Left(pos);
				priority = _tstoi(strPriority);
				if (priority < 0 || priority > 2)
					priority = SRV_PR_HIGH;
				strLine = strLine.Mid(pos+1);
			}
		
			// fetch name
			CString strName = strLine;
			strName.Remove(_T('\r'));
			strName.Remove(_T('\n'));

			// create server object and add it to the list
			CServer* nsrv = new CServer((uint16)_tstoi(strPort), strHost);
			nsrv->SetListName(strName);
			nsrv->SetIsStaticMember(true);
			nsrv->SetPreference(priority); 
			if (!theApp.emuledlg->serverwnd->serverlistctrl.AddServer(nsrv, true))
			{
				delete nsrv;
				CServer* srvexisting = GetServerByAddress(strHost, (uint16)_tstoi(strPort));
				if (srvexisting) {
					srvexisting->SetListName(strName);
					srvexisting->SetIsStaticMember(true);
					srvexisting->SetPreference(priority); 
					if (theApp.emuledlg->serverwnd)
						theApp.emuledlg->serverwnd->serverlistctrl.RefreshServer(srvexisting);
				}
			}
		}
		f.Close();
	}
	catch (CFileException* ex) {
		ASSERT(0);
		ex->Delete();
	}
}
Exemplo n.º 12
0
//搜索并形成插件列表文件.
bool FormPluginLstFile(const char *pFilePath)
{
	CStdioFile OutFile;
	CString    FindFileName, PlgLstFileName, Text;
	CFileFind  finder;
	BOOL       bWorking;
    DWORD      FilePos=0;
	long       FuncPlgNum=0, DataPlgNum=0;

	//判断插件是否存在.
	FindFileName=pFilePath;
	FindFileName+="*.fpl";
	if(!finder.FindFile(FindFileName))
	{
		FindFileName=pFilePath;
		FindFileName+="*.dpl";
		if(!finder.FindFile(FindFileName)) return false;
	}
	
	PlgLstFileName=pFilePath;
	PlgLstFileName+="Plugins.lst";
	
	//写文件头.
	if(!OutFile.Open(PlgLstFileName, CFile::modeCreate|CFile::modeWrite|CFile::typeText)) return false;
	OutFile.WriteString("PLUGIN_LST_HEADER\n");
	
	//搜索功能插件数目.
	FilePos=OutFile.Seek(0L, CFile::current);
	Text.Format("FUNC_PLUGIN_NUM=%ld\n", FuncPlgNum);
	OutFile.WriteString(Text);

	//搜索功能插件.
	FindFileName=pFilePath;
	FindFileName+="*.fpl";
	bWorking=finder.FindFile(FindFileName);
	while(bWorking)
	{
		bWorking = finder.FindNextFile();
		OutFile.WriteString(finder.GetFilePath());
		OutFile.WriteString("\n");
		FuncPlgNum++;
	}
	//回写插件个数.
	if(FuncPlgNum>0)
	{
		OutFile.Seek(FilePos, CFile::begin);
		Text.Format("FUNC_PLUGIN_NUM=%ld\n", FuncPlgNum);
		OutFile.WriteString(Text);
		OutFile.Seek(0L, CFile::end);
	}

	//搜索数据插件数目.
	FilePos=OutFile.Seek(0L, CFile::current);
	Text.Format("DATA_PLUGIN_NUM=%ld\n", DataPlgNum);
	OutFile.WriteString(Text);

	//搜索数据插件.
	FindFileName=pFilePath;
	FindFileName+="*.dpl";
	bWorking=finder.FindFile(FindFileName);
	while(bWorking)
	{
		bWorking = finder.FindNextFile();
		OutFile.WriteString(finder.GetFilePath());
		OutFile.WriteString("\n");
		DataPlgNum++;
	}
	//回写插件个数.
	if(DataPlgNum>0)
	{
		OutFile.Seek(FilePos, CFile::begin);
		Text.Format("DATA_PLUGIN_NUM=%ld\n", DataPlgNum);
		OutFile.WriteString(Text);
		OutFile.Seek(0L, CFile::end);
	}

	OutFile.Close();
	return true;
}
Exemplo n.º 13
0
extern "C" _declspec(dllexport) BOOL startRprCmdTsk(CString strNT, _ConnectionPtr ptrCon, char* strCd, char* strPthOt, char* strAc, WCHAR* strNZ){

//	HINSTANCE hInstResClnt;
//	hInstResClnt = AfxGetResourceHandle();
//AfxMessageBox(_T("startRprCmdTsk"));
	AfxSetResourceHandle(::GetModuleHandle("RprCmdTsk.dll"));

//	char* sANZ;
	CStringArray strANZ;
	strANZ.SetSize(1);
	for(int n=0;n<1;n++){
		strANZ.SetAt(n,_T(""));
	}

	CString curStr,strTmp,m_strNZ;
	CString strCod,strAcc,strPathOut;

	m_strNZ    = _T("");
	strCod	   = strCd;
	strCod.TrimLeft();
	strCod.TrimRight();

	strPathOut = strPthOt;
	strPathOut.TrimLeft();
	strPathOut.TrimRight();

	strAcc     = strAc;
	strAcc.TrimLeft();
	strAcc.TrimRight();

	CString strCur,strSql,strCSls;
	CString m_strNT;
	CString m_strCR;	 		//Код грузополучателя
	CString m_strCRAdr;			//Код адреса доставки
	CString m_strCSA;	 		//Код расч.сч. продовца
	CString m_strCREm;			//Код e-mail

//	bPrint =false;
//CCmdTarget c;
//c.BeginWaitCursor();

	_variant_t m_vNULL;
	_RecordsetPtr ptrRs1;
	_CommandPtr ptrCmd1;
	_ConnectionPtr ptrCnn;

	COleVariant vC;
	CBlokRtf m_Blk;
	CWords m_W;

	ptrCnn    = ptrCon;	//Соединение

	CRecSetProc* pR=NULL;
	CString m_strNum,m_strDate,m_strDecDate,sEnd,strCopy;
	CString s,sPrv,m_strNumDec,strSls;

	CString m_strWe1,m_strWe2,m_strInd,m_strOKOHX,m_strOKOH;
	CString m_strVnd,m_strIndVnd,m_strOKOHXV,m_strOKOHV;

//	CString m_strBN;
//	char* m_bsConn;

	int k=0;							//Число складов для наряд заданий
	bool m_bBN;
	int iFind,iNum,i;
										//  № нак
	iFind=strCod.Find('~');
	m_strNum  = strCod.Left(iFind);
	m_strNumDec = m_strNum;
										//  дата
	iNum = strCod.Find('~',iFind+1);
	m_strDecDate = strCod.Mid(iFind+1,iNum-iFind-1);
	iFind = iNum;
										//  код продовца
	iNum = strCod.Find('~',iFind+1);
	strSls = strCod.Mid(iFind+1,iNum-iFind-1);
	iFind = iNum;
		
	iFind   = strCod.ReverseFind('~');
	m_strDate = strCod.Mid(iFind+1);

	m_strNT  = strNT;

// Имена исходящих файлов
	CString strFlNmCmdTsk;
	CString strPath;
	
	strPath =  _T(""); //_T("D:\\MyProjects\\Strg\\Debug\\"); 
	s = m_strDate;
	s.Remove('-');

//AfxMessageBox(strAcc);
	iFind=strAcc.Find('~');				// код грузополучателя
	m_strCR  = strAcc.Left(iFind);

	iNum = strAcc.Find('~',iFind+1);	// Код адреса доставки
	m_strCRAdr = strAcc.Mid(iFind+1,iNum-iFind-1);
	iFind = iNum;

	iNum = strAcc.Find('~',iFind+1);	// Код расч.сч. продовца
	m_strCSA = strAcc.Mid(iFind+1,iNum-iFind-1);
	iFind = iNum;

	iFind   = strAcc.ReverseFind('~');	// Код e-mail
	m_strCREm = strAcc.Mid(iFind+1);

// Входящие шаблоны
	CStdioFile inCmdTsk;  //Наряд-Задание
// Исходящий файл
	CStdioFile otCmdTsk;

	const int iMAX = 1024;
	const int iMIN = 512;

	m_vNULL.vt = VT_ERROR;
	m_vNULL.scode = DISP_E_PARAMNOTFOUND;

	ptrCmd1 = NULL;
	ptrRs1 = NULL;

	ptrCmd1.CreateInstance(__uuidof(Command));
	ptrCmd1->ActiveConnection = ptrCnn;
	ptrCmd1->CommandType = adCmdText;

	ptrRs1.CreateInstance(__uuidof(Recordset));
	ptrRs1->CursorLocation = adUseClient;
	ptrRs1->PutRefSource(ptrCmd1);

	CStringArray aHd;

	int iRpl = 6;	//  строки которые будут меняться (на 1 больше)
	aHd.SetSize(iRpl);
	for(i=0;i<iRpl;i++){
		aHd.SetAt(i,_T(""));
	}

	strCur = m_strNum + _T(",'");
	strCur+= m_strDate + _T("'");

	aHd.SetAt(1,m_strNumDec+_T("      ")+m_strDecDate);

	strSql = _T("RT24NCmdTsk  ");
	strSql+=strCur;
//AfxMessageBox(strSql);

	ptrCmd1->CommandText = (_bstr_t)strSql;
	try{
		if(ptrRs1->State==adStateOpen) ptrRs1->Close();
		ptrRs1->Open(m_vNULL,m_vNULL,adOpenDynamic,adLockOptimistic,adCmdText);

		if(!pR->IsEmptyRec(ptrRs1)){
			i=4;	//Основание
			vC=pR->GetValueRec(ptrRs1,i);
			vC.ChangeType(VT_BSTR);
			s = vC.bstrVal;

			aHd.SetAt(4,s);				// Основание
//AfxMessageBox(s);
			i = 9;
			vC = pR->GetValueRec(ptrRs1,i);
			vC.ChangeType(VT_BSTR);
			s = vC.bstrVal;

			aHd.SetAt(3,s);		// Покупатель


//			bsCmd = _T("RT38 ");	//Они
//			bsCmd+= (_bstr_t)s + _T(",2");
//AfxMessageBox(bsCmd);
//			if(rsWe->State==adStateOpen) rsWe->Close();
//
//			rsWe->Open(bsCmd,cn->ConnectionString,adOpenKeyset,adLockReadOnly,adCmdText);//adCmdStoredProc
//			if(!pR->IsEmptyRec(rsWe)){

				CString strAdr;

				int Num =ptrRs1->GetRecordCount();

				typedef CArray<int,int&> aRec; //Сколько записей
												 //по складу
				ptrRs1->MoveFirst();	
				vC = pR->GetValueRec(ptrRs1,5); // № Склада
				vC.ChangeType(VT_BSTR);
				sPrv = vC.bstrVal;

				aRec aRecSt;
				int r=1;
				aRecSt.Add(r);
				s=_T("");
				for(i=2;i<=Num;i++){
					ptrRs1->MoveNext();
					vC = pR->GetValueRec(ptrRs1,5); 
					vC.ChangeType(VT_BSTR);
					s = vC.bstrVal;
					if(sPrv!=s){
						k++;
						r=1;
						aRecSt.Add(r);
						sPrv=s;
					}
					else{
						r++;
						aRecSt.SetAt(k,r);
//						s.Format("k = %i, r = %i",k,r);
//AfxMessageBox(s);
					}
				}
				k = aRecSt.GetSize();
//s.Format("k = %i",k);
//AfxMessageBox(s);
				i=0;
				ptrRs1->MoveFirst();

				while(i<k){
					CString strNum=_T("");
					CString strStg = _T("");
					vC = pR->GetValueRec(ptrRs1,5); // № Склада
					vC.ChangeType(VT_BSTR);
					strStg = vC.bstrVal;
					aHd.SetAt(2,strStg);
//********************************* Работа с файлами
					int curPos = 0;
					CString strBuf = _T("");
					s = m_strDate;
					s.Remove('-');

					strFlNmCmdTsk = strPathOut;
					strFlNmCmdTsk+=	_T("НЗ_");
					strFlNmCmdTsk+= m_strNumDec + _T("_");
					strFlNmCmdTsk+=	s + _T("_");
					strFlNmCmdTsk+= strStg + _T(".rtf");
					if(strANZ.GetAt(0)==_T("")){
						strANZ.SetAt(0,strFlNmCmdTsk);
					}
					else{
						strANZ.Add(strFlNmCmdTsk);
					}
//AfxMessageBox((LPCTSTR)strNZ.GetAt(i));

					try{
//						strFlNmCmdTsk+= s + _T(".rtf");
//AfxMessageBox(strFlNmCmdTsk);
						otCmdTsk.Open(strFlNmCmdTsk,CFile::modeCreate|CFile::modeReadWrite|CFile::typeText);

						s = strPath + _T("CmdTsk.rtf");
						inCmdTsk.Open(s,CFile::modeRead|CFile::shareDenyNone);
//AfxMessageBox(s);
						CString strBuf=_T("");
						CString strRpl=_T("");
						int j=1;
						CString strFnd;
						bool theEnd=true;
//---------------------------Заполняю Шаку
						strFnd.Format("~%i~",j);
						while(theEnd){ 
							inCmdTsk.ReadString(strBuf);
//s=strBuf;
							strFnd.Format("~%i~",j);
							m_Blk.SetRplStrR(strBuf,strFnd,j,aHd);
							curPos = inCmdTsk.GetPosition();

//AfxMessageBox("ВХОД = "+s+'\n'+'\n'+"ВЫХОД = "+strBuf+'\n'+'\n'+strFnd);
							otCmdTsk.WriteString(strBuf);
							if(j==5){
								theEnd = false;
							}
						}
//------------------------------------ Конец Шапки
						//{\cell }

						m_Blk.GetStdPWt(strBuf,inCmdTsk,otCmdTsk, _T("{\\cell }"),curPos);
//						m_Blk.Control(inCmdTsk,300);

						CString strSrc=_T("");

						m_Blk.GetStdPWS(strBuf,inCmdTsk,otCmdTsk, _T("\\pard \\ql"),curPos,strSrc);
						curPos++;
						inCmdTsk.Seek(curPos,CFile::begin);
						strSrc+=_T("\\");
						m_Blk.GetStdPWS(strBuf,inCmdTsk,otCmdTsk, _T("\\pard \\ql"),curPos,strSrc);
//		s.Format("Поиск strSrc После  GetStdPWS curPos = %i",curPos);
//AfxMessageBox(s+'\n'+"strSrc = "+strSrc);
//		m_Blk.Control(inCmdTsk,100);

						CString strPst=_T("");

						m_Blk.GetStdPWS(strBuf,inCmdTsk,otCmdTsk, _T("\\trowd"),curPos,strPst);
						curPos++;
						inCmdTsk.Seek(curPos,CFile::begin);
						strPst+=_T("\\");
						m_Blk.GetStdPWS(strBuf,inCmdTsk,otCmdTsk, _T("\\trowd"),curPos,strPst);
//		s.Format("Поиск strPst После  GetStdPWS curPos = %i",curPos);
//AfxMessageBox(s+'\n'+"strPst = "+strPst);
//		m_Blk.Control(inCmdTsk,100);
//		s.Format("i =%i",aRecSt.GetAt(i));
//AfxMessageBox(s);
						int i5=0;
						CString strNew=_T("");
						for(int x=1;x<=aRecSt.GetAt(i);x++){
							strNew = pR->OnFillRow(ptrRs1,strSrc,5,x,i5);
//AfxMessageBox(_T("strSrc = ")+'\n'+strSrc+'\n'+_T("strNew = ")+'\n'+strNew);
							otCmdTsk.WriteString(strNew);
							otCmdTsk.WriteString(strPst);
							ptrRs1->MoveNext();
//							s.Format("x = %i",x);
//AfxMessageBox(s);
						}

						m_Blk.GetStdPWt(strBuf,inCmdTsk,otCmdTsk, _T("\\cell }\\pard"),curPos);
//						m_Blk.Control(inCmdTsk,300);

						CString strSrc2=_T("");
						m_Blk.GetStdPWS(strBuf,inCmdTsk,otCmdTsk, _T("\\pard \\ql"),curPos,strSrc2);
//						s.Format("Поиск strSrc2 После  GetStdPWS curPos = %i",curPos);
//				AfxMessageBox(s+'\n'+"strSrc2 = "+strSrc2);
//						m_Blk.Control(inCmdTsk,100);

						CString strNew2=_T("");
						strNew2 = pR->OnFillTtl(strSrc2,i5,1);
//				AfxMessageBox("strNew2 = "+'\n'+strNew2);
						otCmdTsk.WriteString(strNew2);

						s = m_W.GetWords(i5,false,false,true);
						aHd.SetAt(5,s);  // Общее кол-во

//						while(inCmdTsk.ReadString(strBuf)){ 
//							otCmdTsk.WriteString(strBuf);
//						}

						while(inCmdTsk.ReadString(strBuf)){ 

				//			s= strBuf;
							strFnd.Format("~%i~",j);
							m_Blk.SetRplStrR(strBuf,strFnd,j,aHd);
				//AfxMessageBox("ВХОД = "+s+'\n'+'\n'+"ВЫХОД = "+strBuf+'\n'+'\n'+strFnd);
							otCmdTsk.WriteString(strBuf);
						}
					otCmdTsk.Close();


					}
					catch(CFileException* fx){
						TCHAR buf[255];
						fx->GetErrorMessage(buf,255);
				//		AfxMessageBox(buf);
						fx->Delete();
					}

					i++;
					inCmdTsk.Close();
//s.Format("i = %i",i);
//AfxMessageBox(s);
//				}
			}
/*AfxMessageBox(_T("Begin"));
for(int c=0;c<strNZ.GetSize();c++){
	s.Format(_T("c=%i Size = %i"),c,strNZ.GetSize());
	AfxMessageBox(s);
		AfxMessageBox((LPCTSTR)strNZ.GetAt(c));
	AfxMessageBox(s);
}
AfxMessageBox(_T("End"));*/
		}
	}
	catch(_com_error& e){
		AfxMessageBox(e.ErrorMessage());
		if(ptrRs1->State == adStateOpen) ptrRs1->Close();
		ptrRs1 = NULL;
	}

//c.EndWaitCursor();
//	AfxSetResourceHandle(hInstResClnt);

	if(ptrRs1->State == adStateOpen) ptrRs1->Close();
	ptrRs1 = NULL;
	i = 0;
	while(i<k){
		if(i==0){
			m_strNZ =strANZ.GetAt(i);
		}
		else{
			m_strNZ+= _T("~")+strANZ.GetAt(i);
		}
		i++;
	}
//AfxMessageBox(m_strNZ);
//strNZ = m_strNZ.GetBufferSetLength(m_strNZ.GetLength());
	int lw;
	lw = MultiByteToWideChar(CP_ACP,0,m_strNZ,-1,NULL,0);
//	s.Format(_T("lw = %i"),lw);
//	AfxMessageBox(s);
	WCHAR* strW = new WCHAR[lw];
	MultiByteToWideChar(CP_ACP,0,m_strNZ,-1,strW,lw);
//	strNZ = m_strNZ;
	wcscpy_s(strNZ,lw,strW);
//	strNZ=strW;
//AfxMessageBox("exit from RprCmdTs");
//AfxMessageBox(strNZ);
	delete strW;
	return TRUE;
}
Exemplo n.º 14
0
extern "C" _declspec(dllexport) BOOL startRprBill(CString strNT, _ConnectionPtr ptrCon, char* strCd, char* strPthOt, char* strAc, WCHAR* strWDoc){
//	HINSTANCE hInstResClnt;

	//hInstResClnt = AfxGetResourceHandle();
	AfxSetResourceHandle(::GetModuleHandle("RprBill.dll"));
	CString curStr,strTmp;
	CString strCod,strAcc,strPathOut;

	strCod	   = strCd;
	strCod.TrimLeft();
	strCod.TrimRight();

	strPathOut = strPthOt;
	strPathOut.TrimLeft();
	strPathOut.TrimRight();

	strAcc     = strAc;
	strAcc.TrimLeft();
	strAcc.TrimRight();

/*AfxMessageBox(strCod);
AfxMessageBox(strPathOut);
AfxMessageBox(strAcc);

return FALSE;
*/
	CString strCur,strSql,strCSls;
	CString m_strNT;
	CString m_strCR;	 		//Код грузополучателя
	CString m_strCRAdr;			//Код адреса доставки
	CString m_strCSA;	 		//Код расч.сч. продовца
	CString m_strCREm;			//Код e-mail

	_variant_t m_vNULL;
	_RecordsetPtr ptrRs1,ptrRs2,ptrRs3,ptrRs4;
	_CommandPtr ptrCmd1,ptrCmd2,ptrCmd3,ptrCmd4;
	_ConnectionPtr ptrCnn;

	COleVariant vC;
	CBlokRtf m_Blk;
	CWords m_W;
//	CCnvrt16 m_Ch16;

//CCmdTargetPrn c;
//c.BeginWaitCursor();
	ptrCnn    = ptrCon;	//Соединение

	CRecSetProc* pR=new CRecSetProc;
	CString m_strNum,m_strDate,m_strDecDate,s,sEnd,strCopy;
	CString m_strNumDec,strSls,strO;

	CString m_strWe1,m_strWe2,m_strInd,m_strOKOHX,m_strOKOH;
	CString m_strVnd,m_strIndVnd,m_strOKOHXV,m_strOKOHV,strCst,m_strCnsgr;

//	char* m_bsConn;
	bool m_bBN;
	int iFind,iNum,i;
										//  № нак
	iFind=strCod.Find('~');
	m_strNum  = strCod.Left(iFind);
	m_strNumDec = m_strNum;
										//  дата
	iNum = strCod.Find('~',iFind+1);
	m_strDecDate = strCod.Mid(iFind+1,iNum-iFind-1);
	iFind = iNum;
										//  код продовца
	iNum = strCod.Find('~',iFind+1);
	strSls = strCod.Mid(iFind+1,iNum-iFind-1);
	iFind = iNum;
		
	iFind   = strCod.ReverseFind('~');
	m_strDate = strCod.Mid(iFind+1);

	m_strNT  = strNT;
//	m_bsConn = bsConn;

//AfxMessageBox(strAcc);
	iFind=strAcc.Find('~');				// код грузополучателя
	m_strCR  = strAcc.Left(iFind);

	iNum = strAcc.Find('~',iFind+1);	// Код адреса доставки
	m_strCRAdr = strAcc.Mid(iFind+1,iNum-iFind-1);
	iFind = iNum;

	iNum = strAcc.Find('~',iFind+1);	// Код расч.сч. продовца
	m_strCSA = strAcc.Mid(iFind+1,iNum-iFind-1);
	iFind = iNum;

	iFind   = strAcc.ReverseFind('~');	// Код e-mail
	m_strCREm = strAcc.Mid(iFind+1);
	
	CString strFlNmBill;
	CString strPath;

	strPath =  _T("");  //_T("D:\\MyProjects\\Strg\\Debug\\");
	s = m_strDate;//
	s.Remove('-');

	strFlNmBill = strPathOut;
	strFlNmBill+=	_T("СЧ_");
	strFlNmBill+= m_strNum + _T("_");
	strFlNmBill+= s + _T(".rtf");

	int lw;
	lw = MultiByteToWideChar(CP_ACP,0,strFlNmBill,-1,NULL,0);
//	s.Format(_T("lw = %i"),lw);
//	AfxMessageBox(s);
	WCHAR* strW = new WCHAR[lw];
	MultiByteToWideChar(CP_ACP,0,strFlNmBill,-1,strW,lw);
//	strNZ = m_strNZ;
	wcscpy_s(strWDoc,lw,strW);
//	strNZ=strW;
//AfxMessageBox("exit from RprCmdTs");
//AfxMessageBox(strNZ);
	delete strW;

//	strDoc = strFlNmBill;

	m_vNULL.vt = VT_ERROR;
	m_vNULL.scode = DISP_E_PARAMNOTFOUND;

	ptrCmd4 = NULL;
	ptrRs4 = NULL;

	ptrCmd4.CreateInstance(__uuidof(Command));
	ptrCmd4->ActiveConnection = ptrCnn;
	ptrCmd4->CommandType = adCmdText;

	ptrRs4.CreateInstance(__uuidof(Recordset));
	ptrRs4->CursorLocation = adUseClient;
	ptrRs4->PutRefSource(ptrCmd4);

	ptrCmd3 = NULL;
	ptrRs3 = NULL;

	ptrCmd3.CreateInstance(__uuidof(Command));
	ptrCmd3->ActiveConnection = ptrCnn;
	ptrCmd3->CommandType = adCmdText;

	ptrRs3.CreateInstance(__uuidof(Recordset));
	ptrRs3->CursorLocation = adUseClient;
	ptrRs3->PutRefSource(ptrCmd3);

	ptrCmd2 = NULL;
	ptrRs2 = NULL;

	ptrCmd2.CreateInstance(__uuidof(Command));
	ptrCmd2->ActiveConnection = ptrCnn;
	ptrCmd2->CommandType = adCmdText;

	ptrRs2.CreateInstance(__uuidof(Recordset));
	ptrRs2->CursorLocation = adUseClient;
	ptrRs2->PutRefSource(ptrCmd2);

	ptrCmd1 = NULL;
	ptrRs1 = NULL;

	ptrCmd1.CreateInstance(__uuidof(Command));
	ptrCmd1->ActiveConnection = ptrCnn;
	ptrCmd1->CommandType = adCmdText;

	ptrRs1.CreateInstance(__uuidof(Recordset));
	ptrRs1->CursorLocation = adUseClient;
	ptrRs1->PutRefSource(ptrCmd1);

// Входящие шаблоны
	CStdioFile inBill;  // Счёт
// Исходящий файл
	CStdioFile otBill;

	strCur = m_strNum + _T(",'");
	strCur+= m_strDate + _T("'");

	strSql = _T("RT24NBill ");	//RT24Bill
	strSql+= strCur;

//AfxMessageBox(strSql );
//AfxMessageBox(strAcc);
	ptrCmd1->CommandText = (_bstr_t)strSql;
	try{
		if(ptrRs1->State==adStateOpen) ptrRs1->Close();
		ptrRs1->Open(m_vNULL,m_vNULL,adOpenDynamic,adLockOptimistic,adCmdText);
		if(!pR->IsEmptyRec(ptrRs1))	{

			i = 9;		//Код продовца
			vC=pR->GetValueRec(ptrRs1,i);
			vC.ChangeType(VT_BSTR);
			strSls = vC.bstrVal;
			strSls.TrimLeft();
			strSls.TrimRight();

			i = 8;		//Код покупателя
			vC=pR->GetValueRec(ptrRs1,i);
			vC.ChangeType(VT_BSTR);
			strCst = vC.bstrVal;
			strCst.TrimLeft();
			strCst.TrimRight();
		}
	}
	catch(_com_error& e){
		AfxMessageBox(e.ErrorMessage());
		if(ptrRs1->State==adStateOpen) ptrRs1->Close();
		ptrRs1=NULL;
		if(ptrRs2->State==adStateOpen) ptrRs2->Close();
		ptrRs2=NULL;
		if(ptrRs3->State==adStateOpen) ptrRs3->Close();
		ptrRs3=NULL;
		if(ptrRs4->State==adStateOpen) ptrRs4->Close();
		ptrRs4=NULL;
		return FALSE;
	}

	CStringArray aHd;
	int iRpl = 25;	//  строки которые будут меняться (на 1 больше)
	aHd.SetSize(iRpl);
	for(i=0;i<iRpl;i++){
		aHd.SetAt(i,_T(""));
	}
	CString m_strSls;
/*----------------------------- ПРОДАВЕЦ-----------------------*/
/*	bsCmd = _T("RT38Sls "); 
	bsCmd+= (_bstr_t)strSls +_T(",");
	bsCmd+= _T("2,");		// Юридический адрес
	bsCmd+= (_bstr_t)strAcc;
*/
	strSql = _T("RT38Sls_1 ");		//Мы RT38Sls
	strSql+= strSls + _T(",2,");	//Юр адрес - 2
	strSql+= m_strCSA;				//Код расч.сч. продовца

	ptrCmd2->CommandText = (_bstr_t)strSql;
//AfxMessageBox(strSql);
	try{
		//---------------------------------------Про Продовца
		if(ptrRs2->State==adStateOpen) ptrRs2->Close();
		ptrRs2->Open(m_vNULL,m_vNULL,adOpenDynamic,adLockOptimistic,adCmdText);
		if(!pR->IsEmptyRec(ptrRs2))	{
			i=1;
			vC=pR->GetValueRec(ptrRs2,i);
			vC.ChangeType(VT_BSTR);
			m_strSls = vC.bstrVal;
			m_strSls.TrimLeft();
			m_strSls.TrimRight();
			m_strSls+= _T(" ");

			i=2;
			vC=pR->GetValueRec(ptrRs2,i);
			vC.ChangeType(VT_BSTR);
			s = vC.bstrVal;
			s.TrimLeft();
			s.TrimRight();
			m_strSls+= s;

			aHd.SetAt(1,m_strSls);	// Наименование

			i=3;					//Индекс
			vC=pR->GetValueRec(ptrRs2,i);
			vC.ChangeType(VT_BSTR);
			m_strSls = vC.bstrVal;
			m_strSls.TrimLeft();
			m_strSls.TrimRight();
			m_strSls+= _T(",");

			i=4;					//Адрес юридический
			vC=pR->GetValueRec(ptrRs2,i);
			vC.ChangeType(VT_BSTR);
			s = vC.bstrVal;
			s.TrimLeft();
			s.TrimRight();
			m_strSls+=s + _T(", ");		

			i=5;					// тел
			vC=pR->GetValueRec(ptrRs2,i);
			vC.ChangeType(VT_BSTR);
			s = vC.bstrVal;
			s.TrimLeft();
			s.TrimRight();
//			m_strSls+=_T("тел.: ") + s;		
			m_strSls+= s;

			aHd.SetAt(2,m_strSls);	// Адрес,тел

			i=8;
			vC=pR->GetValueRec(ptrRs2,i);
			vC.ChangeType(VT_BSTR);
			s = vC.bstrVal;
			s.TrimLeft();
			s.TrimRight();
//			m_strSls=_T("ИНН/КПП ");
			m_strSls+= s;
			aHd.SetAt(3,m_strSls);	// ИНН/КПП

			aHd.SetAt(4,aHd.GetAt(1));
			
			i=6;					// Расч. счёт
			vC=pR->GetValueRec(ptrRs2,i);
			vC.ChangeType(VT_BSTR);
			m_strSls = vC.bstrVal;
			m_strSls.TrimLeft();
			m_strSls.TrimRight();
			aHd.SetAt(5,m_strSls);	

			i=7;					//Банк
			vC=pR->GetValueRec(ptrRs2,i);
			vC.ChangeType(VT_BSTR);
			m_strSls = vC.bstrVal;
			m_strSls.TrimLeft();
			m_strSls.TrimRight();
			aHd.SetAt(8,m_strSls);	// Банк

			i=11;					//БИК
			vC=pR->GetValueRec(ptrRs2,i);
			vC.ChangeType(VT_BSTR);
			m_strSls = vC.bstrVal;
			m_strSls.TrimLeft();
			m_strSls.TrimRight();
			aHd.SetAt(9,m_strSls);	// БИК

			i=12;					// Кор.счёт
			vC=pR->GetValueRec(ptrRs2,i);
			vC.ChangeType(VT_BSTR);
			m_strSls = vC.bstrVal;
			m_strSls.TrimLeft();
			m_strSls.TrimRight();
			aHd.SetAt(11,m_strSls);	// Кор.счёт
		}
	}
	catch(_com_error& e){
		AfxMessageBox(e.ErrorMessage());
		if(ptrRs1->State==adStateOpen) ptrRs1->Close();
		ptrRs1=NULL;
		if(ptrRs2->State==adStateOpen) ptrRs2->Close();
		ptrRs2=NULL;
		if(ptrRs3->State==adStateOpen) ptrRs3->Close();
		ptrRs3=NULL;
		if(ptrRs4->State==adStateOpen) ptrRs4->Close();
		ptrRs4=NULL;
		return FALSE;
	}
	ptrRs2->Close();
/*--------------------------- ПОКУПАТЕЛЬ-----------------------*/
	CString m_strCst;
/*	bsCmd = _T("RT38Cst "); 
	bsCmd+= (_bstr_t)strCst +_T(",");
	bsCmd+= _T("2,");		// Юридический адрес
	bsCmd+= _T("1");		// Только Наименование
*/
	strSql = _T("RT38Cst_1 ");	//Они
	strSql+= strCst + _T(",2,");
	strSql+= _T("0");

//AfxMessageBox(strSql);
	ptrCmd3->CommandText = (_bstr_t)strSql;

	try{
		if(ptrRs3->State==adStateOpen) ptrRs3->Close();
//AfxMessageBox(strSql);
		ptrRs3->Open(m_vNULL,m_vNULL,adOpenDynamic,adLockOptimistic,adCmdText);
		if(!pR->IsEmptyRec(ptrRs3)){
			i=1;
			vC=pR->GetValueRec(ptrRs3,i);
			vC.ChangeType(VT_BSTR);
			m_strCst = vC.bstrVal;
			m_strCst+= _T(" ");

			i=2;
			vC=pR->GetValueRec(ptrRs3,i);
			vC.ChangeType(VT_BSTR);
			s = vC.bstrVal;
			m_strCst+= s;

			aHd.SetAt(15,m_strCst);	// Плательщик
		}
	}
	catch(_com_error& e){
		AfxMessageBox(e.ErrorMessage());
		if(ptrRs1->State==adStateOpen) ptrRs1->Close();
		ptrRs1=NULL;
		if(ptrRs2->State==adStateOpen) ptrRs2->Close();
		ptrRs2=NULL;
		if(ptrRs3->State==adStateOpen) ptrRs3->Close();
		ptrRs3=NULL;
		if(ptrRs4->State==adStateOpen) ptrRs4->Close();
		ptrRs4=NULL;
		return FALSE;
	}
//------------------------------------- про Грузополучателей
		strSql = _T("RT38Cnsgr ");		
		strSql+= m_strCR   + _T(",");	//Код грузополучателя
		strSql+= m_strCRAdr+ _T(",");	//Код адреса доставки
		strSql+= _T("1");				//не полная инф

//AfxMessageBox(strSql);
		ptrCmd4->CommandText = (_bstr_t)strSql;

		try{
			if(ptrRs4->State==adStateOpen) ptrRs4->Close();
			ptrRs4->Open(m_vNULL,m_vNULL,adOpenDynamic,adLockOptimistic,adCmdText);
			if(!pR->IsEmptyRec(ptrRs4)){

					i=1;	//Вид собственности
					vC=pR->GetValueRec(ptrRs4,i);
					vC.ChangeType(VT_BSTR);
					s = vC.bstrVal;
					s.TrimLeft();
					s.TrimRight();
					m_strCnsgr+= s +_T(" ");

					i=2;	//Наименование
					vC=pR->GetValueRec(ptrRs4,i);
					vC.ChangeType(VT_BSTR);
					s = vC.bstrVal;
					s.TrimLeft();
					s.TrimRight();
					m_strCnsgr+= s;

					aHd.SetAt(16,m_strCnsgr);	// Грузополучатель
//AfxMessageBox(m_strCnsgr);
			}
		}
		catch(_com_error& e){
			AfxMessageBox(e.ErrorMessage());
			if(ptrRs1->State==adStateOpen) ptrRs1->Close();
			ptrRs1=NULL;
			if(ptrRs2->State==adStateOpen) ptrRs2->Close();
			ptrRs2=NULL;
			if(ptrRs3->State==adStateOpen) ptrRs3->Close();
			ptrRs3=NULL;
			if(ptrRs4->State==adStateOpen) ptrRs4->Close();
			ptrRs4=NULL;
			return FALSE;
		}

	aHd.SetAt(12,m_strNum);			// №
	CString sD,sMY,sDMY;
	sD = m_strDecDate.Left(m_strDecDate.Find(_T(".")));
	sD = _T("\" ")+sD;
	sD+= _T(" \"");

	aHd.SetAt(13,sD);

	sDMY= m_W.GetWrdMnth(m_strDecDate,1,true);
	sMY = sDMY.Mid(sDMY.Find(" "));
	aHd.SetAt(14,sMY);
	aHd.SetAt(23,_T("Головина О.В."));	//Фильцов Д.Н.
	aHd.SetAt(24,_T("Радостева М.С."));	//Ермакова Е.В.

//************************* Работа с файлами
	int curPos = 0;
	CString strBuf = _T("");
	try{
		s = strPath + _T("Bill.rtf");
		otBill.Open(strFlNmBill,CFile::modeCreate|CFile::modeReadWrite|CFile::typeText);
		inBill.Open(s,CFile::modeRead|CFile::shareDenyNone);

		CString strBuf=_T("");
		CString strRpl=_T("");
		int j=1;
		CString strFnd;
		bool theEnd=true;
//---------------------------заполняю Шапку
		strFnd.Format("~%i~",j);
		while(theEnd){ 
			inBill.ReadString(strBuf);

//			s=strBuf;

			strFnd.Format("~%i~",j);
			m_Blk.SetRplStrR(strBuf,strFnd,j,aHd);
			curPos = inBill.GetPosition();

//AfxMessageBox("ВХОД = "+s+'\n'+'\n'+"ВЫХОД = "+strBuf+'\n'+'\n'+strFnd);
			otBill.WriteString(strBuf);
			if(j==17){
				theEnd = false;
//				AfxMessageBox("ok");
			}
		}
//		m_Blk.Control(inBill,300);

		m_Blk.GetStdPWt(strBuf,inBill,otBill, _T("\\row }\\trowd"),curPos);
//		m_Blk.Control(inBill,300);
		m_Blk.GetStdPWt(strBuf,inBill,otBill, _T("{1\\cell "),curPos);
//		m_Blk.Control(inBill,300);
		m_Blk.GetStdPWt(strBuf,inBill,otBill, _T("\\pard \\qc "),curPos);
//		m_Blk.Control(inBill,300);

		CString strSrc=_T("");

		m_Blk.GetStdPWS(strBuf,inBill,otBill, _T("\\pard \\ql"),curPos,strSrc);
//		s.Format("Поиск strSrc После  GetStdPWS curPos = %i",curPos);
//AfxMessageBox(s+'\n'+"strSrc = "+strSrc);
//		m_Blk.Control(inBill,300);

		CString strPst=_T("");

		m_Blk.GetStdPWS(strBuf,inBill,otBill, _T("\\trowd"),curPos,strPst);
		curPos++;
		inBill.Seek(curPos,CFile::begin);
		strPst+=_T("\\");
		m_Blk.GetStdPWS(strBuf,inBill,otBill, _T("\\trowd"),curPos,strPst);
//		s.Format("Поиск strPst После  GetStdPWS curPos = %i",curPos);
//AfxMessageBox(s+'\n'+"strPst = "+strPst);
//		m_Blk.Control(inBill,300);

		CString strNew;
		long Num = ptrRs1->GetRecordCount();
//		s = m_W.GetWords(Num,false,false,true);
		s.Format("%i",Num);
		s.TrimRight();
		aHd.SetAt(20,s);  // Порядковых номеров
//AfxMessageBox(s);
		double d17,d18,d19,dT;
		d17=d18=d19=dT=0;
		for(int x=1;x<=Num;x++){
//			otInvOrd.WriteString(strPrv);
//AfxMessageBox(strSrc);
			strNew = pR->OnFillRow(ptrRs1,strSrc,6,x, d17, d18, d19);
//AfxMessageBox(strNew);
			vC = pR->GetValueRec(ptrRs1,5);
			vC.ChangeType(VT_R8);
			dT = vC.dblVal;
			d18 +=dT;

			vC = pR->GetValueRec(ptrRs1,6);
			vC.ChangeType(VT_R8);
			dT = vC.dblVal;
			d19 +=dT;
			otBill.WriteString(strNew);
			otBill.WriteString(strPst);
			ptrRs1->MoveNext();
		}

		s.Format("%16.4f",d17);
		s.TrimRight();
		s.TrimLeft();
		aHd.SetAt(17,s);  // Итого

		s.Format("%16.4f",d18);
		s.TrimRight();
		s.TrimLeft();
		aHd.SetAt(18,s);  // Итого НДС

		s.Format("%16.2f",d19);
		s.TrimRight();
		s.TrimLeft();
		aHd.SetAt(19,s);  // Всего к оплате
		aHd.SetAt(21,s);  // на сумму

		s = m_W.GetWords(d19,true,true,true);
		aHd.SetAt(22,s);  // на сумму прописью
		

		while(inBill.ReadString(strBuf)){ 

//			s= strBuf;
			strFnd.Format("~%i~",j);
			m_Blk.SetRplStrR(strBuf,strFnd,j,aHd);
//AfxMessageBox("ВХОД = "+s+'\n'+'\n'+"ВЫХОД = "+strBuf+'\n'+'\n'+strFnd);
			otBill.WriteString(strBuf);
		}
		inBill.Close();
		otBill.Close();
	}
	catch(CFileException* fx){
		TCHAR buf[255];
		fx->GetErrorMessage(buf,255);
//		AfxMessageBox(buf);
		fx->Delete();
	}

	delete pR;
//c.EndWaitCursor();
//	AfxSetResourceHandle(hInstResClnt);
	if(ptrRs1->State==adStateOpen) ptrRs1->Close();
	ptrRs1=NULL;
	if(ptrRs2->State==adStateOpen) ptrRs2->Close();
	ptrRs2=NULL;
	if(ptrRs3->State==adStateOpen) ptrRs3->Close();
	ptrRs3=NULL;
	if(ptrRs4->State==adStateOpen) ptrRs4->Close();
	ptrRs4=NULL;
	return TRUE;
}