pisd.cpp

来自「科思ERP部分源码及控件」· C++ 代码 · 共 557 行 · 第 1/2 页

CPP
557
字号
//--------------------------------------------------------------------------
#include <vcl.h>
#include "Pisd.h"
#include "Pish.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"

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

void __fastcall TfrmPisd::btnOKClick(TObject *Sender)
{
  double FPrice,Ftmp,FQty,FAmt,FConv,FIQty;
  AnsiString sIUnitCode,l_GoodsSpec;
  int ErrNum;
  try
  {
    StartWaitForm("正在生成入库单,请稍候......");
    if(sgPisd->RowCount>1)
    {
     int j;
     j=comServer->ItemCount-1;
     if(j>=0)
     {
        comServer->LocateItemByIndex(j);
        j=StrToInt(frmPish->GetDetailValue("PisdLine"));
        j=j+1;
     }
     else
        j=1;
     try
     {
       for(int i=1;i<sgPisd->RowCount;i++)
       {
           if(sgPisd->Cells[1][i]=="√")
           {
               comServer->AddItem();
               SetDetailValue("PisdCode", frmPish->sePishCode->Text);            //入库单号
               SetDetailValue("PisdLine", AnsiString(j));             //行号
               SetDetailValue("PisdFrom", "1");            //行来源
               SetDetailValue("PisdFromCode", sePisdFromCode->Text);        //来源单号
               SetDetailValue("PisdFromLine", sgPisd->Cells[2][i]);        //来源行号

               SetDetailValue("PisdGoods", sgPisd->Cells[3][i]);            //物料编码
               SetDetailValue("GoodsName", sgPisd->Cells[4][i]);            //物料编码


               if(InitRsGoods(WideString(sgPisd->Cells[3][i])))
               {
                sIUnitCode=GetGoodsValue(gtInitRs,"GoodsUnitCode");
                l_GoodsSpec=GetGoodsValue(gtInitRs,"GoodsSpec");
                }
               else
               {
                sIUnitCode="";
                l_GoodsSpec=" ";
               }
               if(Trim(l_GoodsSpec)=="")
               l_GoodsSpec=" ";
               SetDetailValue("GoodsSpec",l_GoodsSpec);
               SetDetailValue("PisdUnit",sIUnitCode);
               Ftmp=StrToFloat(sgPisd->Cells[7][i]);  //单据未入库数量
               if(sgPisd->Cells[8][i] == "")
                throw Exception("请输入入库数量");
               FQty=StrToFloat(sgPisd->Cells[8][i]);  //单据入库数量
               if(FQty>Ftmp)
                throw Exception("入库数量不能超过未入库数量");
               if(sgPisd->Cells[6][i] == "")
                throw Exception("缺少单位转换系数");
               FConv=StrToFloat(sgPisd->Cells[6][i]); //转换系数
               if(sIUnitCode==sgPisd->Cells[5][i])
                SetDetailValue("PisdQty", sgPisd->Cells[8][i]);             //入库数量
               else
               {
                FIQty=FQty*FConv;                      //入库数量
                SetDetailValue("PisdQty", FloatToStr(FIQty));             //入库数量
               }
               SetDetailValue("PisdPrice", sgPisd->Cells[13][i]);           //入库单价
               if(sgPisd->Cells[13][i] == "")
                throw Exception("缺少货物单价");
               FPrice=StrToFloat(sgPisd->Cells[13][i]); //单价
               FAmt=FPrice*FQty;
               SetDetailValue("PisdAmt", FloatToStr(FAmt));             //入库金额
               SetDetailValue("PisdLoc", sgPisd->Cells[9][i]);             //货位
//               SetDetailValue("PisdState", sgPisd->Cells[][i]);           //行状态
               SetDetailValue("PisdBatch", sgPisd->Cells[10][i]);           //批号
               SetDetailValue("PisdSod", sgPisd->Cells[11][i]);             //订单号
               SetDetailValue("PisdSodLine", sgPisd->Cells[12][i]);         //订单行号
//             SetDetailValue("PisdDesc", sgPisd->Cells[][i]);
               SetDetailValue("PisdDesc", " ");           //备注
               comServer->AddToObject();
               j=j+1;
           }
       }
     }
     catch(Exception &e)
     {
      comServer->FreeItem();
      this->ModalResult=0;
      throw Exception(e.Message);
     }
    }
  }
  __finally
  {
    EndWaitForm();
  }
  Close();
}
//---------------------------------------------------------------------------
void __fastcall TfrmPisd::btnCancelClick(TObject *Sender)
{
    Close();
}
//---------------------------------------------------------------------------
void __fastcall TfrmPisd::InitControlGroup()
{
    sgPisd->RowCount = 1;
    sePishType->Text=frmPish->scPishType->Text;
    pv_PishType=StrToIntDef(frmPish->scPishType->ItemData[1],-1);
    sePisdFromCode->Text="";
}
//---------------------------------------------------------------------------

void __fastcall TfrmPisd::FillGridWithData()
{

    AnsiString  ItemStr,s_SQL;
    if(sePisdFromCode->Text == "")
     return;
    switch(pv_PishType)
    {
     case 1: //采购收货
      s_SQL =" select Line=PrecdLine,Goods=PrecdGoods,GoodsName,Unit=PrecdUnit,Conv=PrecdConv,Qty=PrecdQty-PrecdIQty,";
      s_SQL+=" Loc=PrecdLoc,Price=PrecdPrice,Batch=PrecdBatch,So=PrecdSo,SodLine=PrecdSodLine from sdPrecd,sdGoods ";
      s_SQL+=" where PrecdGoods=GoodsCode and PrecdClose=0 and PrecdCode='"+sePisdFromCode->Text+"' and ";
      if(Trim(GetParamValue("10520"))=='Y')
      s_SQL+=" PrecdLoc in(select LrLoc from KsLocRight where LrUser= '"+g_sdUserCode+"') and ";
      s_SQL+=" PrecdQty>PrecdIQty order by PrecdLine";
      break;
     case 2: //生产入库
      s_SQL =" select Line=WepdLine,Goods=WepdGoods,GoodsName,Unit=GoodsUnitCode,Conv='1',Qty=WepdCQty-WepdIQty,";
      s_SQL+=" Loc=WepdLoc,Price=0,Batch=WepdBatch,So=WepdSod,SodLine=WepdSodLine from sdWepd,sdGoods ";
      s_SQL+=" where WepdGoods=GoodsCode and WepdCode='"+sePisdFromCode->Text+"' and ";
      if(Trim(GetParamValue("10520"))=='Y')
      s_SQL+=" WepdLoc in(select LrLoc from KsLocRight where LrUser= '"+g_sdUserCode+"') and ";

      s_SQL+=" WepdCQty>WepdIQty order by WepdLine";
      break;
     case 3: //销售退货
      s_SQL =" select Line=SretdLine,Goods=SretdGoods,GoodsName,Unit=SretdUnit,Conv=SretdConv,Qty=SretdQty-SretdOQty,";
      s_SQL+=" Loc=SretdLoc,Price=SretdPrice,Batch=SretdBatch,So='',SodLine=0 from sdSretd,sdGoods ";
      s_SQL+=" where SretdGoods=GoodsCode and SretdClose=0 and SretdCode='"+sePisdFromCode->Text+"' and ";
      if(Trim(GetParamValue("10520"))=='Y')
      s_SQL+=" SretdLoc in(select LrLoc from KsLocRight where LrUser= '"+g_sdUserCode+"') and ";

      s_SQL+=" SretdQty>SretdOQty order by SretdLine";
      break;
     case 4: //退料
      s_SQL =" SELECT Line=RmbdLine,Goods=RmbdGoods,GoodsName,Unit=RmbdUnit,Conv='1',Qty=RmbdQty,";
      s_SQL+=" Loc=RmbdLoc,Price=0,Batch=RmbdBatch,So='',SodLine=0 FROM sdRmbd,sdGoods ";
      s_SQL+=" WHERE RmbdGoods=GoodsCode and RmbdCode='"+sePisdFromCode->Text+"'" ;
      if(Trim(GetParamValue("10520"))=='Y')
      s_SQL+="  and RmbdLoc in(select LrLoc from KsLocRight where LrUser= '"+g_sdUserCode+"')  ";

      s_SQL+=" ORDER BY RmbdLine";
      break;
     default:
      s_SQL ="";
      break;
    }
    if(s_SQL=="")
     return;
    TComResultSet *RsPisd;
    sgPisd->RowCount=1;
    try
    {
      StartWaitForm("正在查询数据,请稍候......");
      RsPisd=new  TComResultSet(Handle,g_ClientHandle);
      RsPisd->Open(s_SQL,"");
      ll_YearMonth= FillQueryBatch();
      while( RsPisd->Eof == 0)
      {
        if(wetherBatch(RsPisd->FieldByName("Goods"))&&Trim(RsPisd->FieldByName("Batch"))=="")
         {
            ll_YearMonth =IntToStr(StrToInt(ll_YearMonth)+1);
            ItemStr="\t"+AnsiString("") +
                "\t"+RsPisd->FieldByName("Line")+
                "\t"+RsPisd->FieldByName("Goods")+
                "\t"+RsPisd->FieldByName("GoodsName")+
                "\t"+RsPisd->FieldByName("Unit")+
                "\t"+RsPisd->FieldByName("Conv")+
                "\t"+RsPisd->FieldByName("Qty")+
                "\t"+RsPisd->FieldByName("Qty")+
                "\t"+RsPisd->FieldByName("Loc")+
                "\t"+ll_YearMonth+
                "\t"+RsPisd->FieldByName("So")+
                "\t"+RsPisd->FieldByName("SodLine")+
                "\t"+RsPisd->FieldByName("Price");
        }
       else
        {
        ItemStr="\t"+AnsiString("") +
                "\t"+RsPisd->FieldByName("Line")+
                "\t"+RsPisd->FieldByName("Goods")+
                "\t"+RsPisd->FieldByName("GoodsName")+
                "\t"+RsPisd->FieldByName("Unit")+
                "\t"+RsPisd->FieldByName("Conv")+
                "\t"+RsPisd->FieldByName("Qty")+
                "\t"+RsPisd->FieldByName("Qty")+
                "\t"+RsPisd->FieldByName("Loc")+
                "\t"+RsPisd->FieldByName("Batch")+
                "\t"+RsPisd->FieldByName("So")+
                "\t"+RsPisd->FieldByName("SodLine")+
                "\t"+RsPisd->FieldByName("Price");
       }
        sgPisd->AddItem(ItemStr);
        RsPisd->MoveNext();
      }
      RsPisd->Close();
    }
    __finally
    {
      EndWaitForm();
    }
    delete RsPisd;
}
//---------------------------------------------------------------------------
void __fastcall TfrmPisd::GetComObject(TComServer *comServerPtr)
{
    comServer = comServerPtr;
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
void __fastcall TfrmPisd::sgPisdDblClick(TObject *Sender)
{
    AnsiString SqlStr;
    int ARow=sgPisd->Row;
    if (ARow >0)
    {
      if(sgPisd->Col==1)
      {
        if (sgPisd->Cells[1][ARow] == "√")
        {
         sgPisd->Cells[1][ARow] =  "";
         for (int i=1;i<sgPisd->RowCount;i++)
         {
            if(sgPisd->Cells[1][i]=="√")
            {
               btnOK->Enabled=true;
               break;
            }
            else
               btnOK->Enabled=false;
         }
        }
        else
        {
          sgPisd->Cells[1][ARow] =  "√";
          btnOK->Enabled=true;
        }
      }
      else if(sgPisd->Col==9 && sgPisd->Cells[1][ARow] == "√")
      {
        SqlStr="002[货位代码][货位名称]select loccode,locname from sdLoc,sdlg ";

⌨️ 快捷键说明

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