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

📄 sretd.cpp

📁 速达开源ERP系统
💻 CPP
字号:
//--------------------------------------------------------------------------
#include <vcl.h>
#include "Sretd.h"
#include "Sreth.h"
#include "wnquery.h"
#include "func.h"
//--------------------------------------------------------------------------
#pragma hdrstop
#pragma package(smart_init)
#pragma link "fpanel"
#pragma link "SDEdit"
#pragma link "SDGrid"
#pragma link "SDComboBox"
#pragma link "StdBaseForm"
#pragma resource "*.dfm"

TfrmSretd  *frmSretd;
//--------------------------------------------------------------------------
__fastcall TfrmSretd::TfrmSretd(TComponent* Owner)
        : TStdBaseForm(Owner)
{
  InitControlGroup();
}
//--------------------------------------------------------------------------

void __fastcall TfrmSretd::btnOKClick(TObject *Sender)
{
  double FVal,FPrice,FQty,FTax,FAmt;
  int ErrNum;
  try
  {
    StartWaitForm("正在生成退货单,请稍候...");
    if(sgSretd->RowCount>1)
    {
       int j;
       j=comServer->ItemCount-1;
       if(j>=0)
       {
          comServer->LocateItemByIndex(j);
          j=StrToInt(frmSreth->GetDetailValue(fiSretdLine));
          j=j+1;
       }
       else
          j=1;
       for(int i=1;i<sgSretd->RowCount;i++)
       {
           if(sgSretd->Cells[1][i]=="√")
           {
               comServer->AddItem();
               SetDetailValue(fiSretdCode,frmSreth->seSrethCode->Text);
               SetDetailValue(fiSretdLine,AnsiString(j));
               SetDetailValue(fiSretdSogCode,seSretdSogCode->Text);
               SetDetailValue(fiSretdSogdLine, sgSretd->Cells[2][i]);
               SetDetailValue(fiSretdGoods, sgSretd->Cells[3][i]);
               SetDetailValue(fiSretdUnit, sgSretd->Cells[4][i]);
               SetDetailValue(fiSretdConv, sgSretd->Cells[5][i]);
               SetDetailValue(fiSretdQty, sgSretd->Cells[7][i]);
               SetDetailValue(fiSretdPrice, sgSretd->Cells[8][i]);
               FQty=sgSretd->Cells[7][i].ToDouble();
               FPrice=sgSretd->Cells[8][i].ToDouble();
               FVal=(FQty*FPrice)/(1+FSrethTaxRate);
               FAmt=DataCarry(FVal,2,0);
               FTax=DataCarry(FVal*FSrethTaxRate,2,0);
               SetDetailValue(fiSretdAmt,AnsiString(FAmt));
               SetDetailValue(fiSretdTaxAmt,AnsiString(FTax));
               SetDetailValue(fiSretdLoc, sgSretd->Cells[9][i]);
               SetDetailValue(fiSretdBatch, sgSretd->Cells[10][i]);
               SetDetailValue(fiSretdState, "1");
               try{
                  comServer->AddToObject();
                  }
                catch(Exception &e)
                  {
                   comServer->Cancel();
                   this->ModalResult=0;
                   throw Exception(e.Message);
                   }
                 j=j+1;
           }
       }
    }
  }
  __finally
  {
    EndWaitForm();
  }
  Close();
}
//---------------------------------------------------------------------------
void __fastcall TfrmSretd::btnCancelClick(TObject *Sender)
{
    Close();
}
//---------------------------------------------------------------------------
void __fastcall TfrmSretd::InitControlGroup()
{
    sgSretd->RowCount = 1;
    seSretdSogCode->Text="";
    seSrethClient->Text=frmSreth->seSrethClient->Text;
    seSrethClient->Enabled=false;
    FSrethClient=frmSreth->seSrethClient->ItemData[cbItem2];
    seSrethCurrency->Text=frmSreth->seSrethCurrency->Text;
    seSrethCurrency->Enabled=false;
    FSrethCurrency=frmSreth->seSrethCurrency->ItemData[cbItem2];
    seSrethRate->Text=frmSreth->seSrethEnrate->Text;
    seSrethTax->Text=frmSreth->scSrethTaxCode->Text;
    seSrethTax->Enabled=false;
    FSrethTax=frmSreth->scSrethTaxCode->ItemData[cbItem2];
    if(frmSreth->scSrethTaxCode->ItemData[cbItem3] == "")
     FSrethTaxRate=0;
    else
     FSrethTaxRate=frmSreth->scSrethTaxCode->ItemData[cbItem3].ToDouble();
}
//---------------------------------------------------------------------------

void __fastcall TfrmSretd::FillGridWithData()
{

    AnsiString  ItemStr,s_SQL;
    double d_SogdQty;
    s_SQL=AnsiString(" Select SogdLine,sogdGoods,sogdUnit,SogdConv,SogdQty=SogdQty-SogdBQty,")
         +AnsiString(" SogdLoc,SogdBatch,SogdPrice from sdSogd where SogdCode='"+seSretdSogCode->Text+"'")
         +AnsiString(" and SogdClose = 0 and SogdQty-SogdBQty>0 order by Sogdline");

    sgSretd->RowCount=1;
    TComResultSet *RsSretd;
    try
    {
      StartWaitForm("正在查询数据,请稍候......");
      RsSretd=NewResultSet();
      RsSretd->Open(WideString(s_SQL),WideString(""));
      sgSretd->RowCount=1;
      while( RsSretd->Eof == 0)
      {
       d_SogdQty=StrToFloat(RsSretd->FieldByName("SogdQty"));
       if(d_SogdQty > 0)
       {
         ItemStr="\t"+AnsiString("√") +
                 "\t"+RsSretd->FieldByName("SogdLine")+
                 "\t"+RsSretd->FieldByName("SogdGoods")+
                 "\t"+RsSretd->FieldByName("SogdUnit")+
                 "\t"+RsSretd->FieldByName("SogdConv")+
                 "\t"+RsSretd->FieldByName("SogdQty")+
                 "\t"+RsSretd->FieldByName("SogdQty")+
                 "\t"+RsSretd->FieldByName("SogdPrice")+
                 "\t"+RsSretd->FieldByName("SogdLoc")+
                 "\t"+RsSretd->FieldByName("SogdBatch");
         sgSretd->AddItem(ItemStr);
       }
       RsSretd->MoveNext();
      }
      RsSretd->Close();
      delete RsSretd;
    }
    __finally
    {
      EndWaitForm();
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmSretd::GetComObject(TComServer *comServerPtr)
{
    comServer = comServerPtr;
}
//---------------------------------------------------------------------------
void __fastcall TfrmSretd::SetDetailValue(int Index,AnsiString Value)
{
     WriteItemValue(comServer,Index,Value);
}
//---------------------------------------------------------------------------
void __fastcall TfrmSretd::sgSretdDblClick(TObject *Sender)
{
    AnsiString SqlStr;
    int ARow=sgSretd->Row;
    if (ARow >0)
    {
      if(sgSretd->Col==1)
      {
        if (sgSretd->Cells[1][ARow] == "√")
          sgSretd->Cells[1][ARow] =  "";
        else
          sgSretd->Cells[1][ARow] =  "√";
      }
      else if(sgSretd->Col==9 && sgSretd->Cells[1][ARow] == "√")
      {
        SqlStr="002[货位代码][货位名称]select loccode,locname from sdLoc,sdlg ";
        SqlStr+=" where lgLoccode=loccode and lggoodscode='"+sgSretd->Cells[3][ARow]+"' order by loccode";
        TfrmWnQuery *p;
        try
        {
          StartWaitForm("正在查询,请稍候...");
          p=new TfrmWnQuery(this,"货位查询",SqlStr);
        }
        __finally
        {
          EndWaitForm();
        }
        if(p->ShowModal()==mrOk)
        {
          sgSretd->Cells[9][ARow]=p->ColData[1];
        }
        delete p;
      }
    }
}

//---------------------------------------------------------------------------

void __fastcall TfrmSretd::bbSelAllClick(TObject *Sender)
{
  for(int i=1;i<sgSretd->RowCount;i++)
    sgSretd->Cells[1][i] = "√";
}
//---------------------------------------------------------------------------

void __fastcall TfrmSretd::bbSelNoneClick(TObject *Sender)
{
  for(int i=1;i<sgSretd->RowCount;i++)
    sgSretd->Cells[1][i] = "";
}
//---------------------------------------------------------------------------


void __fastcall TfrmSretd::seSretdSogCodeButtonClick(TObject *Sender)
{
  AnsiString SqlStr;
  SqlStr="005[发货单号][发货日期][币种][税码][业务员]select Soghcode,Soghdate,currencyname,taxname,SoghUser from sdSogh,sdCurrency,sdtax";
  SqlStr+=" where Soghcurrency=currencycode and Soghtaxcode=taxcode and Soghcheck=1 and Soghclose=0 and Soghcancel=0 ";
  SqlStr+=" and SoghClient='"+FSrethClient+"' and Soghcurrency='"+FSrethCurrency+"' ";
  if(cbSameTax->Checked)
    SqlStr+=" and SoghtaxCode='"+FSrethTax+"' order by Soghcode";
  else
    SqlStr+=" order by Soghcode";
  TfrmWnQuery *p;
  try
  {
    StartWaitForm("正在查询,请稍候...");
    p=new TfrmWnQuery(this,"发货单查询",SqlStr);
  }
  __finally
  {
    EndWaitForm();
  }
  if(p->ShowModal()==mrOk)
  {
    seSretdSogCode->Text=p->ColData[1];
    FillGridWithData();
  }
  delete p;  
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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