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

📄 sogd_s_o.cpp

📁 速达开源ERP系统
💻 CPP
字号:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Sogd_S_O.h"
#include "Sogh_S_O.h"
#include "wnquery.h"
#include "func.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "fpanel"
#pragma link "SDComboBox"
#pragma link "SDEdit"
#pragma link "SDGrid"
#pragma link "StdBaseForm"
#pragma resource "*.dfm"
TfrmSogd_S_O *frmSogd_S_O;
//---------------------------------------------------------------------------
__fastcall TfrmSogd_S_O::TfrmSogd_S_O(TComponent* Owner)
  : TStdBaseForm(Owner)
{
  InitControlGroup();
}
//---------------------------------------------------------------------------
void __fastcall TfrmSogd_S_O::seSogdSoCodeButtonClick(TObject *Sender)
{
  AnsiString SqlStr;
  SqlStr="005[销售订单][开单日期][币种][税码][业务员]select sohcode,sohdate,currencyname,taxname,sohsaler from sdsoh,sdcurrency,sdtax";
  SqlStr+=" where Sohcurrency=currencycode and Sohtaxcode=taxcode and Sohcheck=1 and Sohclose=0 and Sohcancel=0 ";
  SqlStr+=" and SohClient='"+FSoghClient+"' and Sohcurrency='"+FSoghCurrency+"' ";
  if(cbSameTax->Checked)
    SqlStr+=" and SohtaxCode='"+FSoghTax+"' order by Sohcode";
  else
    SqlStr+=" order by Sohcode";
  TfrmWnQuery *p;
  try
  {
    StartWaitForm("正在查询,请稍候...");
    p=new TfrmWnQuery(this,"销售订单查询",SqlStr);
  }
  __finally
  {
    EndWaitForm();
  }
  if(p->ShowModal()==mrOk)
  {
    seSogdSoCode->Text=p->ColData[1];
    FillGridWithData();
  }
  delete p;
}
//---------------------------------------------------------------------------

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

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

void __fastcall TfrmSogd_S_O::btnOKClick(TObject *Sender)
{
  double FVal,FPrice,FQty,FTax,FAmt,FDisc;
  int ErrNum;
  try
  {
    StartWaitForm("正在生成发货单,请稍候...");
    if(sgSod->RowCount>1)
    {
       int j;
       j=comServer->ItemCount-1;
       if(j>=0)
       {
          comServer->LocateItemByIndex(j);
          j=StrToInt(frmSogh_S_O->GetDetailValue(fiSogdLine));
          j=j+1;
       }
       else
          j=1;
       for(int i=1;i<sgSod->RowCount;i++)
       {
           if(sgSod->Cells[1][i]=="√")
           {
               comServer->AddItem();
               SetDetailValue(fiSogdCode,frmSogh_S_O->seSoghCode->Text);
               SetDetailValue(fiSogdLine,AnsiString(j));
               SetDetailValue(fiSogdSoCode,seSogdSoCode->Text);
               SetDetailValue(fiSogdSodLine, sgSod->Cells[2][i]);
               SetDetailValue(fiSogdGoods, sgSod->Cells[3][i]);
               SetDetailValue(fiSogdUnit, sgSod->Cells[4][i]);
               SetDetailValue(fiSogdConv, sgSod->Cells[5][i]);
               SetDetailValue(fiSogdLoc, sgSod->Cells[6][i]);
               SetDetailValue(fiSogdQty, sgSod->Cells[8][i]);
               SetDetailValue(fiSogdPrice, sgSod->Cells[9][i]);
               FQty=sgSod->Cells[8][i].ToDouble();
               FPrice=sgSod->Cells[9][i].ToDouble();
               FVal=(FQty*FPrice)/(1+FSoghTaxRate);
               FAmt=DataCarry(FVal,2,0);
               FTax=DataCarry(FVal*FSoghTaxRate,2,0);
               SetDetailValue(fiSogdAmt,AnsiString(FAmt));
               SetDetailValue(fiSogdTaxAmt,AnsiString(FTax));
               SetDetailValue(fiSogdDisc,sgSod->Cells[12][i]);
               FDisc=sgSod->Cells[12][i].ToDouble();
               FVal=DataCarry((FQty*FPrice)*FDisc,2,0);
               SetDetailValue(fiSogdDAmt,AnsiString(FVal));
               SetDetailValue(fiSogdRecDate, sgSod->Cells[14][i]);
               try
               {
               comServer->AddToObject();
               }
               catch(Exception &e)
               {
                comServer->Cancel();
                this->ModalResult=0;
                throw Exception(e.Message);
               }
               j=j+1;
           }
       }
    }
  }
  __finally
  {
    EndWaitForm();
  }
  Close();
}
//---------------------------------------------------------------------------

void __fastcall TfrmSogd_S_O::btnCancelClick(TObject *Sender)
{
  Close();
}
//---------------------------------------------------------------------------

void __fastcall TfrmSogd_S_O::InitControlGroup()
{
    sgSod->RowCount = 1;
    seSogdSoCode->Text="";
    seSoghClient->Text=frmSogh_S_O->seSoghClient->Text;
    seSoghClient->Enabled=false;
    FSoghClient=frmSogh_S_O->seSoghClient->ItemData[cbItem2];
    seSoghCurrency->Text=frmSogh_S_O->seSoghCurrency->Text;
    seSoghCurrency->Enabled=false;
    FSoghCurrency=frmSogh_S_O->seSoghCurrency->ItemData[cbItem2];
    seSoghRate->Text=frmSogh_S_O->seSoghEnrate->Text;
    seSoghTax->Text=frmSogh_S_O->scSoghTaxCode->Text;
    seSoghTax->Enabled=false;
    FSoghTax=frmSogh_S_O->scSoghTaxCode->ItemData[cbItem2];
    if(frmSogh_S_O->scSoghTaxCode->ItemIndex==-1)
      FSoghTaxRate=0;
    else
      FSoghTaxRate=frmSogh_S_O->scSoghTaxCode->ItemData[cbItem3].ToDouble();
}
//---------------------------------------------------------------------------

void __fastcall TfrmSogd_S_O::FillGridWithData()
{

    double FVal,FQty,FPrice,FTax,FAmt,FDisc,FDAmt;
    AnsiString  ItemStr,s_SQL;
    s_SQL=AnsiString(" Select SodLine,SodGoods,SodUnit,SodConv,SodQty=SodQty-SodSQty,")
         +AnsiString(" SodPrice,SodRecDate,SodDisc from sdSod where SodCode='"+seSogdSoCode->Text+"'")
         +AnsiString(" and SodClose = 0 and SodQty-SodSQty>0 order by Sodline");

    TComResultSet *RsSogd;
    sgSod->RowCount=1;
    try
    {
      StartWaitForm("正在查询数据,请稍候...");
      RsSogd=NewResultSet();
      RsSogd->Open(WideString(s_SQL),WideString(""));
      while( RsSogd->Eof == 0)
      {
          FQty=RsSogd->FieldByName("SodQty").ToDouble();
          FPrice=RsSogd->FieldByName("SodPrice").ToDouble();
          FDisc=RsSogd->FieldByName("SodDisc").ToDouble();
          FVal=FQty*FPrice;
          FAmt=DataCarry(FVal,2,0);
          FTax=DataCarry(FAmt*FSoghTaxRate,2,0);
          FDAmt=DataCarry(FVal*FDisc,2,0);
          ItemStr="\t"+AnsiString("√") +
                 "\t"+RsSogd->FieldByName("SodLine")+
                 "\t"+RsSogd->FieldByName("SodGoods")+
                 "\t"+RsSogd->FieldByName("SodUnit")+
                 "\t"+RsSogd->FieldByName("SodConv")+
                 "\t"+""+
                 "\t"+RsSogd->FieldByName("SodQty")+
                 "\t"+RsSogd->FieldByName("SodQty")+
                 "\t"+RsSogd->FieldByName("SodPrice")+
                 "\t"+AnsiString(FAmt)+
                 "\t"+AnsiString(FTax)+
                 "\t"+RsSogd->FieldByName("SodDisc")+
                 "\t"+AnsiString(FDAmt)+
                 "\t"+RsSogd->FieldByName("SodRecDate");
         sgSod->AddItem(ItemStr);
       RsSogd->MoveNext();
      }
      RsSogd->Close();
      delete RsSogd;
    }
    __finally
    {
      EndWaitForm();
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmSogd_S_O::GetComObject(TComServer *comServerPtr)
{
    comServer = comServerPtr;
}
//---------------------------------------------------------------------------
void __fastcall TfrmSogd_S_O::SetDetailValue(int Index,AnsiString Value)
{
     WriteItemValue(comServer,Index,Value);
}
//---------------------------------------------------------------------------
void __fastcall TfrmSogd_S_O::sgSodDblClick(TObject *Sender)
{
    AnsiString SqlStr;
    int ARow=sgSod->Row;
    if (ARow >0)
    {
      if(sgSod->Col==1)
      {
        if (sgSod->Cells[1][ARow] == "√")
          sgSod->Cells[1][ARow] =  "";
        else
          sgSod->Cells[1][ARow] =  "√";
      }
      else if(sgSod->Col==6 && sgSod->Cells[1][ARow] == "√")
      {
        SqlStr="002[货位代码][货位名称]select loccode,locname from sdLoc,sdlg ";
        SqlStr+=" where lgLoccode=loccode and lggoodscode='"+sgSod->Cells[3][ARow]+"'";
        SqlStr+= " and LocType=1 order by locCode";
        TfrmWnQuery *p;
        try
        {
          StartWaitForm("正在查询,请稍候...");
          p=new TfrmWnQuery(this,"货位查询",SqlStr);
        }
        __finally
        {
          EndWaitForm();
        }
        if(p->ShowModal()==mrOk)
        {
          sgSod->Cells[6][ARow]=p->ColData[1];
        }
        delete p;
      }
    }
}
//---------------------------------------------------------------------------

void __fastcall TfrmSogd_S_O::sgSodSelectCell(TObject *Sender, int ACol,
      int ARow, bool &CanSelect)
{
  if(sgSod->Cells[ACol][ARow]=="√")
    sgSod->ReadOnly=true;
  else
    sgSod->ReadOnly=false;
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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