📄 imdoc.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#define _YW_SDERP_DLL
#include "Imdoc.h"
//---------------------------------------------------------------------------
#pragma hdrstop
#pragma package(smart_init)
//==========================================
// (TsdPmPc)物品类别
//==========================================
void TsdPmpc::SetPmpcName(AnsiString value)
{
if(value.IsEmpty()==true)
throw Exception("物品类别编码名称不能为空。");
if(value.Length()>20)
throw Exception("物品类别编码名称长度不能超过20");
if(value.UpperCase()!=m_PmpcName.UpperCase())
{
m_Query->Close();
m_Query->SQL->Clear();
m_Query->SQL->Add("select pmpcname from sdpmpc where PmpcName='"+value+"'");
m_Query->Open();
if(m_Query->RecordCount>0)
{
m_Query->Close();
throw Exception("类别名称:'"+value+"'已存在");
}
m_Query->Close();
}
m_PmpcName=value;
}
//---------------------------------------------------------------------------
void TsdPmpc::SetPmpcDesc(AnsiString value)
{
if(value.Length()>40)
throw Exception("备注长度不能大于40");
m_PmpcDesc=value;
}
//---------------------------------------------------------------------------
void TsdPmpc::SetPmpcUpperCode(AnsiString value)
{
if(value.IsEmpty()==false)
{
if(value.Length()>18)
throw Exception("类别上级编码长度不能超过18");
m_Query->Close();
m_Query->SQL->Clear();
m_Query->SQL->Add("select * from sdPmpc where pmpccode='"+value+"'");
m_Query->Open();
if(m_Query->RecordCount<=0)
{
m_Query->Close();
throw Exception("上级编码'"+value+"'未定义");
}
m_PmpcLevel=m_Query->FieldValues["PmpcLevel"]+1;
m_Query->Close();
}
else
m_PmpcLevel=1;
m_PmpcUpperCode=value;
}
//---------------------------------------------------------------------------
void TsdPmpc::SetPmpcLevel(int value)
{
if(value<=0)
throw Exception("物料类别的层级码必须大于零!");
m_PmpcLevel=value;
}
//---------------------------------------------------------------------------
void TsdPmpc::SetPmpcItem(AnsiString value)
{
if(value.IsEmpty())
throw Exception("物品类别编码名不能为空");
if(value.Length()+m_PmpcUpperCode.Length()>18)
throw Exception("物品类别编码长度超长");
if (m_PmpcUpperCode+value.UpperCase()!=m_PmpcCode.UpperCase())
{
m_Query->Close();
m_Query->SQL->Clear();
m_Query->SQL->Add("SELECT PmpcCode FROM SDPmPc WHERE PmPcCODE='"+Trim(m_PmpcUpperCode)+Trim(value)+"'");
m_Query->Open();
if(m_Query->RecordCount>0)
{
m_Query->Close();
throw Exception("物品类别编码'"+value+"'已定义!");
}
m_Query->Close();
}
m_PmpcItem =value;
}
void TsdPmpc::SetPmpcEnd(int value)
{
if(value!=0&&value!=1)
throw Exception("末级标志只取值0-非末级 1-末级");
if(m_PmpcEnd==0 && value==1)
{
m_Query->Close();
m_Query->SQL->Clear();
m_Query->SQL->Add("select * from sdPmpc where PmpcUpperCode='"+Trim(m_PmpcUpperCode)+Trim(m_PmpcItem)+"'");
m_Query->Open();
if(m_Query->RecordCount>0)
{
m_Query->Close();
throw Exception("已有下级不能设置为末级");
}
m_Query->Close();
}
m_PmpcEnd=value;
}
//---------------------------------------------------------------------------
TsdPmpc::TsdPmpc(TDataComm *DC)
:TsdStandard(DC)
{
try
{
QueryString="SELECT * FROM SDPmPc";
FilterString="";
OrderString="PmPcCODE,PmPcLEVEL";
EmptyValue(0);
EmptyValue(1);
}
catch(Exception &e)
{
throw Exception("构造函数出错");
}
}
//---------------------------------------------------------------------------
TsdPmpc::TsdPmpc()
:TsdStandard()
{
try
{
QueryString="SELECT * FROM SDPmPc";
FilterString="";
OrderString="PmPcCODE,PmPcLEVEL";
EmptyValue(0);
EmptyValue(1);
}
catch(Exception &e)
{
throw Exception("构造函数出错");
}
}
//---------------------------------------------------------------------------
AnsiString TsdPmpc::GetFieldValue(euPmpc sdFieldName)
{
switch(sdFieldName)
{
case fiPmpcCode:
return PmpcCode;
case fiPmpcName:
return PmpcName;
case fiPmpcDesc:
return PmpcDesc;
case fiPmpcLevel:
return AnsiString(PmpcLevel);
case fiPmpcUpperCode:
return PmpcUpperCode;
case fiPmpcItem:
return PmpcItem;
case fiPmpcEnd:
return PmpcEnd;
default:
throw Exception("当前字段未定义可取值");
}
}
//---------------------------------------------------------------------------
void TsdPmpc::SetFieldValue(euPmpc sdFieldName, AnsiString Value)
{
switch(sdFieldName)
{
case fiPmpcName:
PmpcName=Value;
break;
case fiPmpcDesc:
PmpcDesc=Value;
break;
case fiPmpcUpperCode:
PmpcUpperCode=Value;
break;
case fiPmpcItem:
PmpcItem=Value;
break;
case fiPmpcLevel:
PmpcLevel=Value.ToInt();
break;
case fiPmpcEnd:
PmpcEnd=Value.ToInt();
break;
default:
throw Exception("当前字段未定义可赋值");
}
}
//---------------------------------------------------------------------------
void TsdPmpc::Update()
{
if(CurStatus==0||CurStatus==1)
{
throw Exception("当前不是编辑状态,不能进行存盘操作!");
}
m_PmpcCode=Trim(m_PmpcUpperCode)+Trim(m_PmpcItem);
if(m_PmpcCode.IsEmpty()==true)
throw Exception("物品分类码的编码不能为空!");
m_StoredProc->Close();
if(CurStatus==2||CurStatus==4)
{
m_StoredProc->ProcedureName="sdPmpc_Insert";
m_StoredProc->Parameters->Clear();
m_StoredProc->Parameters->CreateParameter("@PmpcCode",ftString,pdInput,18,m_PmpcCode);
m_StoredProc->Parameters->CreateParameter("@PmpcName",ftString,pdInput,20,m_PmpcName);
m_StoredProc->Parameters->CreateParameter("@PmpcDesc",ftString,pdInput,40,m_PmpcDesc);
m_StoredProc->Parameters->CreateParameter("@PmpcItem",ftString,pdInput,18,m_PmpcItem);
m_StoredProc->Parameters->CreateParameter("@PmpcUpperCode",ftString,pdInput,18,m_PmpcUpperCode);
m_StoredProc->Parameters->CreateParameter("@PmpcLevel",ftInteger,pdInput,10,m_PmpcLevel);
m_StoredProc->Parameters->CreateParameter("@PmpcEnd",ftInteger,pdInput,1,m_PmpcEnd);
m_StoredProc->ExecProc();
}
else
{
m_StoredProc->ProcedureName="sdPmpc_Update";
m_StoredProc->Parameters->Clear();
m_StoredProc->Parameters->CreateParameter("@W_PmpcCode",ftString,pdInput,18,b_PmpcCode);
m_StoredProc->Parameters->CreateParameter("@PmpcCode",ftString,pdInput,18,m_PmpcCode);
m_StoredProc->Parameters->CreateParameter("@PmpcName",ftString,pdInput,20,m_PmpcName);
m_StoredProc->Parameters->CreateParameter("@PmpcDesc",ftString,pdInput,40,m_PmpcDesc);
m_StoredProc->Parameters->CreateParameter("@PmpcItem",ftString,pdInput,18,m_PmpcItem);
m_StoredProc->Parameters->CreateParameter("@PmpcUpperCode",ftString,pdInput,18,m_PmpcUpperCode);
m_StoredProc->Parameters->CreateParameter("@PmpcLevel",ftInteger,pdInput,10,m_PmpcLevel);
m_StoredProc->Parameters->CreateParameter("@PmpcEnd",ftInteger,pdInput,1,m_PmpcEnd);
m_StoredProc->ExecProc();
}
TsdPmpc *p=new TsdPmpc();
if(CurStatus==2)
{
SetActionID(1);
p->Assign(this);
AddRecord((void *)p,p->PmpcCode);
}
else
{
SetActionID(1);
p->Assign(this);
ChangeRecord((void *)p,p->PmpcCode,this->b_PmpcCode);
}
}
//---------------------------------------------------------------------------
void TsdPmpc::Delete()
{
if(CurStatus!=1)
throw Exception("当前状态不能进行删除操作!");
if(m_PmpcCode.IsEmpty()==true)
throw Exception("当前没有记录可以删除!");
m_StoredProc->Close();
m_StoredProc->ProcedureName="sdPmpc_Delete";
m_StoredProc->Parameters->Clear();
m_StoredProc->Parameters->CreateParameter("@W_PmpcCode",ftString,pdInput,18,b_PmpcCode);
m_StoredProc->ExecProc();
DeleteRecord(this->b_PmpcCode);
}
//---------------------------------------------------------------------------
void TsdPmpc::BackupValue()
{
b_PmpcCode=m_PmpcCode;
b_PmpcName=m_PmpcName;
b_PmpcDesc=m_PmpcDesc;
b_PmpcLevel=m_PmpcLevel;
b_PmpcUpperCode=m_PmpcUpperCode;
b_PmpcItem=m_PmpcItem;
b_PmpcEnd=m_PmpcEnd;
}
//---------------------------------------------------------------------------
void TsdPmpc::RestoreValue()
{
m_PmpcCode=b_PmpcCode;
m_PmpcName=b_PmpcName;
m_PmpcDesc=b_PmpcDesc;
m_PmpcLevel=b_PmpcLevel;
m_PmpcUpperCode=b_PmpcUpperCode;
m_PmpcItem=b_PmpcItem;
m_PmpcEnd=b_PmpcEnd;
}
//---------------------------------------------------------------------------
void TsdPmpc::EmptyValue(int Index)
{
switch(Index)
{
case 0:
m_PmpcCode="";
m_PmpcName="";
m_PmpcDesc="";
m_PmpcLevel=0;
m_PmpcUpperCode="";
m_PmpcItem="";
m_PmpcEnd=0;
break;
case 1:
b_PmpcCode="";
b_PmpcName="";
b_PmpcDesc="";
b_PmpcLevel=0;
b_PmpcUpperCode="";
b_PmpcItem="";
b_PmpcEnd=0;
break;
}
}
//---------------------------------------------------------------------------
void TsdPmpc::BatchLetValue()
{
m_PmpcCode=m_Query->FieldValues["PmPcCode"];
m_PmpcName=m_Query->FieldValues["PmPcName"];
m_PmpcDesc=m_Query->FieldValues["PmPcDesc"];
m_PmpcLevel=m_Query->FieldValues["PmPcLevel"];
m_PmpcUpperCode=m_Query->FieldValues["PmPcUpperCode"];
m_PmpcItem=m_Query->FieldValues["PmPcItem"];
m_PmpcEnd=m_Query->FieldValues["PmpcEnd"];
BackupValue();
}
//---------------------------------------------------------------------------
void TsdPmpc::Assign(TsdPmpc *p)
{
SetActionID(p->CurStatus);
m_PmpcCode=p->m_PmpcCode;
m_PmpcName=p->m_PmpcName;
m_PmpcDesc=p->m_PmpcDesc;
m_PmpcLevel=p->m_PmpcLevel;
m_PmpcUpperCode=p->m_PmpcUpperCode;
m_PmpcItem=p->m_PmpcItem;
m_PmpcEnd=p->m_PmpcEnd;
BackupValue();
}
//---------------------------------------------------------------------------
void TsdPmpc::AssignValue()
{
TsdPmpc *p=(TsdPmpc *)Records(CurRecNo);
Assign(p);
}
//---------------------------------------------------------------------------
int TsdPmpc::Query()
{
AnsiString m_SqlStr;
m_SqlStr=QueryString;
if(FilterString.IsEmpty()==false)
m_SqlStr=m_SqlStr+" where "+FilterString;
if(OrderString.IsEmpty()==false)
m_SqlStr=m_SqlStr+" Order by "+OrderString;
m_Query->Close();
m_Query->SQL->Clear();
m_Query->SQL->Add(m_SqlStr);
m_Query->Open();
ClearRecord();
if(m_Query->RecordCount>0)
{
m_Query->First();
while(!m_Query->Eof)
{
BatchLetValue();
TsdPmpc *p=new TsdPmpc();
SetActionID(1);
p->Assign(this);
AddRecord((void *)p,p->PmpcCode);
m_Query->Next();
}
MoveFirst();
}
m_Query->Close();
return Count;
}
//---------------------------------------------------------------------------
bool TsdPmpc::Find(AnsiString WhereStr)
{
AnsiString m_SqlStr;
if(WhereStr.IsEmpty()==true)
throw Exception("查找表达式不能为空");
m_SqlStr="SELECT * FROM SDPmPc WHERE "+WhereStr;
m_Query->Close();
m_Query->SQL->Clear();
m_Query->SQL->Add(m_SqlStr);
m_Query->Open();
if(m_Query->RecordCount!=1)
{
m_Query->Close();
return false;
}
else
{
BatchLetValue();
m_Query->Close();
return true;
}
}
//---------------------------------------------------------------------------
TsdPmpc::~TsdPmpc()
{
try
{
}
catch(...)
{
throw Exception("析构函数出错");
}
}
//---------------------------------------------------------------------------
//////////////////////////////////////////////////
// (仓库编码维护)Sth implement
//////////////////////////////////////////////////
void __fastcall TsdSth::SetSthCode(AnsiString value)
{
if (value.IsEmpty() )
throw Exception("仓库编码不能为空!");
if(value.Length()>18)
throw Exception("仓库编码长度不能大于18");
if(value.UpperCase()!=m_SthCode.UpperCase())
{
m_Query->Close();
m_Query->SQL->Clear();
m_Query->SQL->Add("SELECT SthCODE FROM SDSth WHERE SthCODE='" +value+"'");
m_Query->Open();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -