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

📄 pod.cpp

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

TfrmPod  *frmPod;
//--------------------------------------------------------------------------
__fastcall TfrmPod::TfrmPod(TComponent* Owner)
        : TStdBaseForm(Owner)
{
  InitControlGroup();
  btnOK->Enabled = false;
}

//--------------------------------------------------------------------------
void __fastcall TfrmPod::btnOKClick(TObject *Sender)
{
  AnsiString sMemo;
  int ErrNum;
  try
  {
    StartWaitForm("正在生成采购单,请稍候......");
    if(sgPod->RowCount>1)
    {
     int j;
     j=comServer->ItemCount-1;
     if(j>=0)
     {
        comServer->LocateItemByIndex(j);
        j=StrToInt(GetDetailValue(fiPodLine));
        j=j+1;
     }
     else
        j=1;
     try
     {
       for(int i=1;i<sgPod->RowCount;i++)
       {
           if(sgPod->Cells[1][i]=="√")
           {
               comServer->AddItem();
               SetDetailValue(fiPodLine,IntToStr(j));             //采购单行号
               SetDetailValue(fiPodCode,frmPoh->sePohCode->Text);             //采购单号
               SetDetailValue(fiPodGoods,sgPod->Cells[3][i]);            //货物编码
               SetDetailValue(fiPodUnit,sgPod->Cells[4][i]);             //采购单位
               SetDetailValue(fiPodConvRate,sgPod->Cells[5][i]);         //换算比率
               SetDetailValue(fiPodFrom,sgPod->Cells[6][i]);             //需求来源
               if(sgPod->Cells[7][i] == "")
                throw Exception("请输入采购数量");
               SetDetailValue(fiPodQty,sgPod->Cells[7][i]);              //采购数量
               if(sgPod->Cells[8][i] == "")
                throw Exception("请输入采购单价");
               SetDetailValue(fiPodPrice,sgPod->Cells[8][i]);            //采购单价
               SetDetailValue(fiPodType,"2");             //行类型
               SetDetailValue(fiPodFromCode,seRpohCode->Text);
               SetDetailValue(fiPodFromLine,sgPod->Cells[2][i]);
               SetDetailValue(fiPodStatus,"1");           //订单行状态
               SetDetailValue(fiPodSendDate,sgPod->Cells[10][i]);         //发货日期
               SetDetailValue(fiPodRecDate,sgPod->Cells[10][i]);          //交货日期
               SetDetailValue(fiPodReqDate,sgPod->Cells[9][i]);          //需求日期
               SetDetailValue(fiPodLoc,sgPod->Cells[11][i]);              //需求货位
               SetDetailValue(fiPodDept,sgPod->Cells[12][i]);             //需求部门
               sMemo="来源于请购单'"+seRpohCode->Text+"'的第"+sgPod->Cells[2][i]+"行";
               SetDetailValue(fiPodDesc,sMemo);             //备注
               SetDetailValue(fiPodClose,"0");            //结清标志
               SetDetailValue(fiPodCloseDate,"");        //结清日期
               SetDetailValue(fiPodSo,"");               //订单号
               SetDetailValue(fiPodSodLine,"0");          //订单行号
               SetDetailValue(fiPodBatch,"");            //批号
               comServer->AddToObject();
               j=j+1;
           }
       }
     }
     catch(Exception &e)
     {
      comServer->Cancel();
      this->ModalResult=0;
      throw Exception(e.Message);
     }
    }
  }
  __finally
  {
    EndWaitForm();
  }
  Close();
}
//---------------------------------------------------------------------------
void __fastcall TfrmPod::btnCancelClick(TObject *Sender)
{
    Close();
}
//---------------------------------------------------------------------------
void __fastcall TfrmPod::InitControlGroup()
{
    sgPod->RowCount = 1;
    FSupplyCode=frmPoh->scPohSupply->ItemData[1];
    sePohSupply->Text=frmPoh->scPohSupply->ItemData[0];
    sePohSupply->Enabled=false;
    seRpohCode->Text="";
}
//---------------------------------------------------------------------------

void __fastcall TfrmPod::FillGridWithData()
{

  AnsiString  ItemStr,s_SQL;
  s_SQL=AnsiString(" Select RpodLine,RpodGoodsCode,RpodUnitCode,RpodConvRate,")
       +AnsiString(" RpodFrom,RpodQty,RpodPrice,RpodPQty,RpodReqDate,RpodRecDate,RpodLocCode,RpodDept from sdRpod ")
       +AnsiString(" where RpodCode='"+seRpohCode->Text+"'")
       +AnsiString(" and RpodClose = 0 and Rpodqty-rpodpqty>0 order by RpodLine");
  sgPod->RowCount=1;
  TComResultSet *RsRpod;
  RsRpod=NewResultSet();
  try
  {
    StartWaitForm("正在查询数据,请稍候......");
    RsRpod->Open(s_SQL,"");
    while( RsRpod->Eof == 0)
    {
     ItemStr = "\t"+AnsiString("") +
               "\t"+RsRpod->FieldByName("RpodLine")+
               "\t"+RsRpod->FieldByName("RpodGoodsCode")+
               "\t"+RsRpod->FieldByName("RpodUnitCode")+
               "\t"+RsRpod->FieldByName("RpodConvRate")+
               "\t"+RsRpod->FieldByName("RpodFrom")+
               "\t"+AnsiString(RsRpod->FieldByName("RpodQty").ToDouble()-RsRpod->FieldByName("RpodPQty").ToDouble())+
               "\t"+RsRpod->FieldByName("RpodPrice")+
               "\t"+RsRpod->FieldByName("RpodReqDate")+
               "\t"+RsRpod->FieldByName("RpodRecDate")+
               "\t"+RsRpod->FieldByName("RpodLocCode")+
               "\t"+RsRpod->FieldByName("RpodDept");

     sgPod->AddItem(ItemStr);
     RsRpod->MoveNext();
    }
    RsRpod->Close();
  }
  __finally
  {
    EndWaitForm();
  }
  delete RsRpod;
}
//---------------------------------------------------------------------------
void __fastcall TfrmPod::GetComObject(TComServer *comServerPtr)
{
    comServer = comServerPtr;
}
//---------------------------------------------------------------------------
void __fastcall TfrmPod::SetDetailValue(int Index,AnsiString Value)
{
     WriteItemValue(comServer,Index,Value);
}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmPod::GetDetailValue(int Index)
{
     return ReadItemValue(comServer,Index);
}
//---------------------------------------------------------------------------

void __fastcall TfrmPod::sgPodDblClick(TObject *Sender)
{
    int ARow=sgPod->Row;
    int ACol=sgPod->Col;
    if (ARow > 0 && ACol == 1)
    {
      if (sgPod->Cells[1][ARow] == "√")
      {
       sgPod->Cells[1][ARow] =  "";
       for (int i=1;i<sgPod->RowCount;i++)
       {
          if(sgPod->Cells[1][i]=="√")
          {
             btnOK->Enabled=true;
             break;
          }
          else
             btnOK->Enabled=false;
       }
      }
      else
      {
          sgPod->Cells[1][ARow] =  "√";
          btnOK->Enabled = true;
      }
    }
}
//---------------------------------------------------------------------------

void __fastcall TfrmPod::bbSelAllClick(TObject *Sender)
{
  if(sgPod->RowCount <=1)
   return;
  for(int i=1;i<sgPod->RowCount;i++)
    sgPod->Cells[1][i] = "√";
  btnOK->Enabled = true;
}
//---------------------------------------------------------------------------

void __fastcall TfrmPod::bbSelNoneClick(TObject *Sender)
{
  for(int i=1;i<sgPod->RowCount;i++)
    sgPod->Cells[1][i] = "";
  btnOK->Enabled = false;
}
//---------------------------------------------------------------------------


void __fastcall TfrmPod::seRpohCodeButtonClick(TObject *Sender)
{
  AnsiString SqlStr;
  SqlStr="003[请购单号][请购日期][币种]select rpohcode,rpohdate,currencyname from sdrpoh,sdCurrency";
  SqlStr+=" where rpohcurrencycode=currencycode and rpohcheck=1 and rpohclose=0 and rpohcancel=0 ";
  SqlStr+=" and rpohsupplycode='"+FSupplyCode+"' order by rpohcode";
  TfrmWnQuery *p;
  try
  {
    StartWaitForm("正在查询,请稍候...");
    p=new TfrmWnQuery(this,"请购单查询",SqlStr);
  }
  __finally
  {
    EndWaitForm();
  }
  if(p->ShowModal()==mrOk)
  {
    seRpohCode->Text=p->ColData[1];
    FillGridWithData();
  }
  delete p;
}
//---------------------------------------------------------------------------

void __fastcall TfrmPod::sgPodSelectCell(TObject *Sender, int ACol,
      int ARow, bool &CanSelect)
{
 if(sgPod->Cells[1][ARow]=="√")
  sgPod->ReadOnly=false;
 else
  sgPod->ReadOnly=true;

}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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