📄 pivoh.cpp
字号:
sgPivoh->ChangeItem(ItemStr,i);
CalculateAmt('+', i); // Add
break;
case 2:
CalculateAmt('-', sgPivoh->Row); // Substract
sgPivoh->RemoveItem(sgPivoh->Row);
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmPivoh::DisplayBill()
{
if (comServer->RecordCount > 0)
{
GetDataFromComObject(1); //向抬头中增加记录
FillGridWithData();
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmPivoh::GetBill(AnsiString BillID)
{
int iRow;
iRow=comServer->Find("PivohCode='"+BillID+"'");
if (iRow>0) //FIND THIS BILL
{
DisplayBill();
}
else
if (ShowMessageWindow("在数据库中没有查到记录:"+BillID+",要增加吗?",mwsConfirmation)==IDYES)
{
AddHeadRecord();
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmPivoh::FillGridWithData()
{
int i;
AnsiString ItemStr;
sgPivoh->RowCount=1;
sePivohAmt->Text = "0";
sePivohTaxAmt->Text = "0";
sePivohSumAmt->Text = "0";
sePivohZkAmt->Text = "0";
if(comServer->RecordCount>0)
{
for (i=0;i<comServer->ItemCount;i++) {
comServer->LocateItemByIndex(i);
RefreshGridData(0);
}
}
}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmPivoh::GetHeadValue(int Index)
{
WideString S;
S = ReadFieldValue(comServer,Index);
return S;
}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmPivoh::GetDetailValue(int Index)
{
WideString S;
S = ReadItemValue(comServer,Index);
return AnsiString(S);
}
//---------------------------------------------------------------------------
void __fastcall TfrmPivoh::SetHeadValue(int Index,AnsiString Value)
{
WriteFieldValue(comServer,Index,Value);
}
//---------------------------------------------------------------------------
void __fastcall TfrmPivoh::SetDetailValue(int Index,AnsiString Value)
{
WriteItemValue(comServer,Index,Value);
}
//---------------------------------------------------------------------------
void __fastcall TfrmPivoh::FormCreate(TObject *Sender)
{
FormIniFile="D:\Test.Ini";
SetGridWidth(Name,sgPivoh,FormIniFile);
}
//---------------------------------------------------------------------------
void __fastcall TfrmPivoh::FormShow(TObject *Sender)
{
ClearControl(1,false);
ClearControl(2,false);
ChangeToBrowseState(true);
TBillBaseForm::MoveToFirst();
}
//---------------------------------------------------------------------------
void __fastcall TfrmPivoh::ChangeToBrowseState(bool Browse)
{
if (Browse) {
sgPivoh->Visible = true;
sgPivoh->Align = alClient;
FloatPanel2->Visible = false;
FloatPanel2->Align = alNone;
}
else {
sgPivoh->Visible = false;
sgPivoh->Align = alNone;
FloatPanel2->Visible = true;
FloatPanel2->Align = alClient;
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmPivoh::btnOKClick(TObject *Sender)
{
try
{
if (CurrentState==caAddDetail||CurrentState==caAddBill)
{
if(DetailState==caAddDetail)
comServer->AddItem();
SendDataToComObject(2);
comServer->AddToObject();
ClearControl(2,false);
if(scPivodPodLine->Enabled)
scPivodPodLine->SetFocus();
else
sePivodGoods->SetFocus();
}
else
ChangeToBrowseState();
}
catch(Exception &e)
{
throw Exception(e.Message);
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmPivoh::btnCancelClick(TObject *Sender)
{
CancelChange();
}
//---------------------------------------------------------------------------
void __fastcall TfrmPivoh::WaitUserInput(int Section)
{
if (Section ==1)
{ // Head
if (CurrentState == caEditHead)
{
dePivohDate->SetFocus();
}
else
{
sePivohCode->SetFocus();
}
//选择了采购单,就不允许修改供应商等
if(scPivohPoCode->Text!="")
{
sePivohContract->Enabled=false;
scPivohSettleMode->Enabled=false;
}
else
{
sePivohContract->Enabled=true;
scPivohSettleMode->Enabled=true;
}
}
else
{ // Detail
AnsiString m_Sql;
if (CurrentState == caAddBill || CurrentState == caAddDetail)
{
ClearControl(2, false);
sePivodLine->Text = AnsiString(GetNewPivodLine());
}
ChangeToBrowseState(false);
scPivodPodLine->SetFocus();
if(scPivohPoCode->Text!="")
{
scPivodPodLine->Enabled=true;
sePivodGoods->Enabled=false;
}
else
{
scPivodPodLine->Enabled=false;
sePivodGoods->Enabled=true;
}
} // if
}
//---------------------------------------------------------------------------
/*
void __fastcall TfrmPivoh::scPivodPoCodeClick(TObject *Sender)
{
AnsiString m_Sql;
m_Sql=AnsiString("select PodLine")+
AnsiString(" FROM sdPoh,sdPod")+
AnsiString(" where PohCode=PodCode ")+
AnsiString(" and PohSupply = '"+ Trim(scPivohSupply->Text) +"'")+
AnsiString(" and podQty-PodThQty>PodInvQty")+
AnsiString(" and PodCode = '"+ Trim(scPivodPoCode->Text) +"' order by podline");
FillComboBox(scPivodPodLine,m_Sql,"PodLine");
}
//---------------------------------------------------------------------------
void __fastcall TfrmPivoh::scPivodPodLineClick(TObject *Sender)
{
TCOMIKResultSet pRst;
pRst=NewResultSet();
AnsiString m_Sql;
m_Sql=AnsiString("SELECT DISTINCT PodGoods,GoodsName,PodUnit,PodConvRate,PodQty,PodPrice")+
AnsiString(" FROM sdPod,sdGoods")+
AnsiString(" where PodGoods=GoodsCode")+
AnsiString(" and PodCode = '"+ Trim(scPivodPoCode->Text) +"'")+
AnsiString(" and PodLine = '"+ Trim(scPivodPodLine->Text) +"'");
pRst->Open(WideString(m_Sql),WideString(""));
pRst->MoveFirst();
scPivodGoods->Text = ReadColumnValueByName(pRst,"PodGoods");
sePivodGoodsName->Text = ReadColumnValueByName(pRst,"GoodsName");
sePivodUnit->Text = ReadColumnValueByName(pRst,"PodUnit"); //单位
sePivodConvRate->Text = ReadColumnValueByName(pRst,"PodConvRate"); //换算比率
sePivodPoQty->Text = ReadColumnValueByName(pRst,"PodQty"); //采购数量
sePivodPrice->Text = ReadColumnValueByName(pRst,"PodPrice");
pRst->Close();
}
//---------------------------------------------------------------------------
*/
void __fastcall TfrmPivoh::sgPivohSelectCell(TObject *Sender, int ACol,
int ARow, bool &CanSelect)
{
if (ARow > 0)
{
comServer->LocateItemByKey(WideString(sgPivoh->TextMatrix[ARow][1]));
}
if (!comServer->Eof)
{
GetDataFromComObject(2);
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmPivoh::sgPivohDblClick(TObject *Sender)
{
int iRow;
iRow=sgPivoh->Row;
if (iRow == 0)
{
return;
}
ChangeToBrowseState(false);
}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmPivoh::GetDataToGrid()
{
AnsiString ItemStr;
ItemStr="\t"+GetDetailValue(fiPivodLine);
ItemStr=ItemStr+"\t"+GetDetailValue(fiPivodGoods); //物料编码
ItemStr=ItemStr+"\t"+GetDetailValue(fiPivodUnit); //计量单位
ItemStr=ItemStr+"\t"+GetDetailValue(fiPivodQty);
ItemStr=ItemStr+"\t"+GetDetailValue(fiPivodPrice);
ItemStr=ItemStr+"\t"+GetDetailValue(fiPivodAmt);
ItemStr=ItemStr+"\t"+GetDetailValue(fiPivodTaxPrice);
ItemStr=ItemStr+"\t"+GetDetailValue(fiPivodTaxAmt);
ItemStr=ItemStr+"\t"+GetDetailValue(fiPivodSumAmt);
ItemStr=ItemStr+"\t"+GetDetailValue(fiPivodZkAmt);
return ItemStr;
}
//---------------------------------------------------------------------------
/*
void __fastcall TfrmPivoh::GenrateBill()
{
SetControlState(caAddBill);
TfrmPivod *p;
p = new TfrmPivod(this);
p->GetComObject(comServer);
p->ShowModal();
ChangeToBrowseState(true);
delete p;
if(comServer->ItemCount>0)
{
SetControlState(caSave);
TGenBaseForm::SaveComObject(1);
FillGridWithData();
}
else
TGenBaseForm::CancelChange();
}
//---------------------------------------------------------------------------
*/
int __fastcall TfrmPivoh::GetNewPivodLine()
{
int i;
i = comServer->ItemCount;
if(i > 0) {
comServer->LocateItemByIndex(i-1);
i = StrToInt(GetDetailValue(fiPivodLine));
i ++;
}
else i = 1;
return i;
}
//---------------------------------------------------------------------------
void __fastcall TfrmPivoh::scPivohSupplyClick(TObject *Sender)
{
AnsiString m_Sql;
m_Sql=AnsiString("select distinct PsdBankName")
+AnsiString(" FROM sdPsd")
+AnsiString(" where PsdSupplyCode = '"+ Trim(scPivohSupply->ItemData[1]) +"' order by psdbankname");
FillComboBox(scPivohBankName,m_Sql,"PsdBankName");
scPivohBankName->ItemIndex=-1;
scPivohBankNameClick(NULL);
if(scPivohTaxCode->Enabled)
{
scPivohTaxCode->LocateKey(scPivohSupply->ItemData[2]);
scPivohTaxCodeExit(NULL);
sePivohTaxNo->Text=scPivohSupply->ItemData[3];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -