//函數功能:讀Sybase第一二類
//傳入參數:無
//返回值:是否成功
bool __fastcall TFMain::GetSyBase()
{
Press->CGPress->AddProgress(1);
Application->ProcessMessages();
FileCount=0;//初始化
// GetCounter();
//
try{
//讀odxDocument表
RE->Lines->Add(DateTimeToStr(Now())+":讀Sybase第一二類...");
RE->Lines->Add(DateTimeToStr(Now())+":讀odxDocument表...");
adoqSyBase->Close();
String sql =" select * from odxDocument ";
sql=sql+" where systemCode="+DM(systemCode)+" and docTxnNo="+docTxnNo+" and dataSource="+DM(dataSource);
adoqSyBase->SQL->Text=sql;
adoqSyBase->Open();
[h1][red]在這邊會出現:Eaccessviolation[/red][/h1]
//為什么,大家能不能help me
RE->Lines->Add(DateTimeToStr(Now())+":讀odxDocument表..."+sql);
if(adoqSyBase->Eof)//找不到相應的記錄退出
{
RE->Lines->Add("找不到相應的記錄");
RE->Lines->SaveToFile(ExtractFilePath(Application->ExeName)+"//Process.ini");
ShowMessage("找不到相應的記錄");
return false;
}
isRegistered=false;
if( adoqSyBase->FieldByName("isRegistered")->AsString=="Y" )//判斷是否已經挂號
{
ShowMessage("該文已經掛號了");
isRegistered=true;
return false;
}
else
{
Added=ReadDBF(nocountdbf);//讀no_coount.dbf 并加一
if(Added==false)
return false; //讀失敗返回
}
String tmpPATH=FILEPATH.Trim();//用于存放Sybase的下載的附件的路徑
RE->Lines->Add(DateTimeToStr(Now())+":讀Sybase第一二類...");
Press->CGPress->AddProgress(2);
Application->ProcessMessages();
//讀數據
systemCode=adoqSyBase->FieldByName("systemCode")->AsString;
docTxnNo=adoqSyBase->FieldByName("docTxnNo")->AsString;
dataSource=adoqSyBase->FieldByName("dataSource")->AsString;
senderOrgId=adoqSyBase->FieldByName("senderOrgId")->AsString;
classId=adoqSyBase->FieldByName("classId")->AsString;
securityId=adoqSyBase->FieldByName("securityId")->AsString;
speedId=adoqSyBase->FieldByName("speedId")->AsString;
docDate=adoqSyBase->FieldByName("docDate")->AsString;
dtTemp=adoqSyBase->FieldByName("docDate")->AsDateTime;
docYear=adoqSyBase->FieldByName("docYear")->AsString;
docWord=adoqSyBase->FieldByName("docWord")->AsString;
docId=adoqSyBase->FieldByName("docId")->AsString;
typeId=adoqSyBase->FieldByName("typeId")->AsString;
docSubject=adoqSyBase->FieldByName("docSubject")->AsString;
fileDesc=adoqSyBase->FieldByName("fileDesc")->AsString;
RE->Lines->Add(DateTimeToStr(Now())+":讀odxDocument表 Ok!");
Press->CGPress->AddProgress(5);
Application->ProcessMessages();
RE->Lines->Add(DateTimeToStr(Now())+"讀 ID Doc");
TypeFile=adoqSyBase->FieldByName("fileDesc")->AsString.Trim();
TrueFileName[FileCount]=TypeFile;
RE->Lines->Add(DateTimeToStr(Now())+"讀 ID Doc:"+TypeFile);
TBlobField *FieldPtr;
FieldPtr=(TBlobField*)adoqSyBase->FieldByName("Contents");
int i=0;
RE->Lines->Add(DateTimeToStr(Now())+":查找Temp下的文件");
//生成要壓縮的文件名
while(FileExists(ExtractFilePath(Application->ExeName) + "temp"+"//"+AnsiString(i)+".z")||FileExists(ExtractFilePath(Application->ExeName) + "temp"+"//"+AnsiString(i)))
{
Press->CGPress->AddProgress(5);
FMain->Cursor=crHourGlass;
i++;
}
RE->Lines->Add(DateTimeToStr(Now())+":查完Temp下的文件");
TempFileName[FileCount]=AnsiString(i);//壓縮的文件名放入數組
FMain->Cursor=crDrag;
String tmpFile=ExtractFilePath(Application->ExeName) + "temp"+"//"+AnsiString(i)+".z";
RE->Lines->Add(DateTimeToStr(Now())+":Create di :"+tmpFile);
FieldPtr->SaveToFile(tmpFile);
RE->Lines->Add(DateTimeToStr(Now())+":解壓臨時Di:"+tmpFile);
DeCompress(tmpFile);//解壓文件
RE->Lines->Add(DateTimeToStr(Now())+"讀 ID Doc:"+TypeFile+"ok!");
FileCount++;
Press->CGPress->AddProgress(5);
Application->ProcessMessages();
//*********************************************************************
//處理PDF本文檔
//讀odxDocPdf表
RE->Lines->Add(DateTimeToStr(Now())+":讀odxDocPdf表...");
adoqSyBase->Close();
sql=" select * from odxDocPdf ";
sql=sql+" where systemCode="+DM(systemCode)+" and docTxnNo="+docTxnNo+" and dataSource="+DM(dataSource);
adoqSyBase->SQL->Text=sql;
adoqSyBase->Open();
[h1][red]在這邊會出現:Eaccessviolation[/red][/h1]
//為什么,大家能不能help me
Press->CGPress->AddProgress(5);
Application->ProcessMessages();
if(adoqSyBase->Eof) //找相應的odxDocPdf記錄
{
RE->Lines->Add("找不到相應的odxDocPdf記錄");
RE->Lines->SaveToFile(ExtractFilePath(Application->ExeName)+"//Process.ini");
}
else
{
fileDesc=adoqSyBase->FieldByName("fileDesc")->AsString;
RE->Lines->Add(DateTimeToStr(Now())+":讀odxDocPdf表 Ok!");
Press->CGPress->AddProgress(10);
Application->ProcessMessages();
RE->Lines->Add(DateTimeToStr(Now())+"讀 Pdf Doc");
PDFFile=adoqSyBase->FieldByName("fileDesc")->AsString.Trim();
if(PDFFile.Pos(".di")>0)
PDFFile=PDFFile.SubString(1,PDFFile.Length()-2)+"PDF";
if(PDFFile.Pos(".DI")>0)
PDFFile=PDFFile.SubString(1,PDFFile.Length()-2)+"PDF";
TrueFileName[FileCount]=PDFFile;
RE->Lines->Add(DateTimeToStr(Now())+"讀 Pdf Doc:"+PDFFile);
//存PDF 檔
TBlobField *FieldPtr;
FieldPtr=(TBlobField*)adoqSyBase->FieldByName("Contents");
int i=0;
RE->Lines->Add(DateTimeToStr(Now())+":查找Temp下的文件");
//成生臨時文件名
while(FileExists(ExtractFilePath(Application->ExeName) + "temp"+"//"+AnsiString(i)+".z")||FileExists(ExtractFilePath(Application->ExeName) + "temp"+"//"+AnsiString(i)))
{
Press->CGPress->AddProgress(5);
FMain->Cursor=crHourGlass;
i++;
}
RE->Lines->Add(DateTimeToStr(Now())+":查完Temp下的文件");
TempFileName[FileCount]=AnsiString(i);//存臨時文件名
FMain->Cursor=crDrag;
String tmpFile=ExtractFilePath(Application->ExeName) + "temp"+"//"+AnsiString(i)+".z";
RE->Lines->Add(DateTimeToStr(Now())+":Create PDF :"+tmpFile);
FieldPtr->SaveToFile(tmpFile);
RE->Lines->Add(DateTimeToStr(Now())+":解壓臨時PDF:"+tmpFile);
DeCompress(tmpFile);//解壓
RE->Lines->Add(DateTimeToStr(Now())+"讀 PDF Doc:"+PDFFile+"ok!");
FileCount++;
Press->CGPress->AddProgress(5);
Application->ProcessMessages();
}
//處理PDF本文檔
//*********************************************************************
//讀附件表(odxAttach)
RE->Lines->Add(DateTimeToStr(Now())+"讀附件表");
fileDesc="";
sql="select * from odxAttach";
sql=sql+" where systemCode="+DM(systemCode)+" and docTxnNo="+docTxnNo+" and dataSource="+DM(dataSource);
adoqSyBase->Close();
adoqSyBase->SQL->Text=sql;
adoqSyBase->Open();
attachCount=adoqSyBase->RecordCount;
strSERIAL="";//用于存放附件序號
RE->Lines->Add(DateTimeToStr(Now())+":生成附件的循環開始");
while(!adoqSyBase->Eof)
{
SERIAL=adoqSyBase->FieldByName("attachSeq")->AsString;
//fileDesc=adoqSyBase->FieldByName("fileDesc")->AsString.Trim();
if(fileDesc!="")
fileDesc=fileDesc+","+adoqSyBase->FieldByName("fileDesc")->AsString.Trim();
else
fileDesc=adoqSyBase->FieldByName("fileDesc")->AsString.Trim();
if(strSERIAL!="")
strSERIAL=strSERIAL+","+adoqSyBase->FieldByName("attachSeq")->AsString;
else
strSERIAL=adoqSyBase->FieldByName("attachSeq")->AsString;
TBlobField *FieldPtr;
FieldPtr=(TBlobField*)adoqSyBase->FieldByName("Contents");
TrueFileName[FileCount]=adoqSyBase->FieldByName("fileDesc")->AsString.Trim();
int i=0;
//生成臨時文件名
RE->Lines->Add(DateTimeToStr(Now())+":查找Temp下的文件以取得臨時附件的文件名");
while(FileExists(ExtractFilePath(Application->ExeName) + "temp"+"//"+AnsiString(i)+".z")||FileExists(ExtractFilePath(Application->ExeName) + "temp"+"//"+AnsiString(i)))
{
FMain->Cursor=crHourGlass;
i++;
}
RE->Lines->Add(DateTimeToStr(Now())+":查找完Temp下的文件以取得臨時附件的文件名");
TempFileName[FileCount]=AnsiString(i);////存臨時文件名
String tmpFile=ExtractFilePath(Application->ExeName) + "temp"+"//"+AnsiString(i)+".z";
FieldPtr->SaveToFile(tmpFile);//保存
RE->Lines->Add(DateTimeToStr(Now())+":生成附臨時文件:"+tmpFile);
DeCompress(tmpFile);//解壓
RE->Lines->Add(DateTimeToStr(Now())+":解壓臨時文件:"+tmpFile);
FileCount++;//附件數加一
Press->CGPress->AddProgress(1);
Application->ProcessMessages();
adoqSyBase->Next();
}
RE->Lines->Add(DateTimeToStr(Now())+":生成附件的循環結束");
RE->Lines->Add(DateTimeToStr(Now())+":完成附件");
Press->CGPress->AddProgress(10);
Application->ProcessMessages();
//查出相應的機關全銜
sql=" select * From TORG where (ORG_NO+ORG_DEPTNO)='"+senderOrgId.Trim()+"'";
adoqSyBase->Close();
adoqSyBase->SQL->Text=sql;
adoqSyBase->Open();
if(!adoqSyBase->Eof)
{
senderOrgId=adoqSyBase->FieldByName("ORG_NAME")->AsString;
}
adoqSyBase->Close();
}
catch(Exception &e)
{
RE->Lines->Add("讀Sybase失敗:"+e.Message);
RE->Lines->SaveToFile(ExtractFilePath(Application->ExeName)+"//Process.ini");
AddTxt("Error:"+e.Message);
ShowMessage("讀Sybase失敗:"+e.Message);
return false;
}
DeCompressAll();//解壓
RE->Lines->Add(DateTimeToStr(Now())+":讀完Sybase的數據");
return true;
}
//函數功能:讀Sybase第三類
//傳入參數:無
//返回值:是否成功