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

📄 gosd.cpp

📁 速达开源ERP系统
💻 CPP
字号:
//--------------------------------------------------------------------------
#include <vcl.h>
#include "Gosd.h"
#include "Gosh.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 resource "*.dfm"

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

void __fastcall TfrmGosd::btnOKClick(TObject *Sender)
{
  double FPrice,Ftmp,FQty,FAmt,FConv,FIQty;
  AnsiString sIUnitCode;
  int ErrNum;
  try
  {
    StartWaitForm("正在生成出库单,请稍候......");
    if(sgGosd->RowCount>1)
    {
     int j;
     j=comServer->ItemCount-1;
     if(j>=0)
     {
        comServer->LocateItemByIndex(j);
        j=StrToInt(frmGosh->GetDetailValue(fiGosdLine));
        j=j+1;
     }
     else
        j=1;
     try
     {
       for(int i=1;i<sgGosd->RowCount;i++)
       {
           if(sgGosd->Cells[1][i]=="√")
           {
               comServer->AddItem();
               SetDetailValue(fiGosdCode, frmGosh->seGoshCode->Text);            //入库单号
               SetDetailValue(fiGosdLine, AnsiString(j));             //行号
               SetDetailValue(fiGosdFrom, "1");            //行来源
               SetDetailValue(fiGosdFromCode, seGosdFromCode->Text);        //来源单号
               SetDetailValue(fiGosdFromLine, sgGosd->Cells[2][i]);        //来源行号

               SetDetailValue(fiGosdGoods, sgGosd->Cells[3][i]);           //物料编码
               if(g_sdRsGoods->LocateByKey(WideString(sgGosd->Cells[3][i]))==0)
                sIUnitCode=GetGoodsValue("GoodsUnitCode");
               else
                sIUnitCode="";
               Ftmp=StrToFloat(sgGosd->Cells[7][i]);  //单据未入库数量
               if(sgGosd->Cells[8][i] == "")
                throw Exception("请输入入库数量");
               FQty=StrToFloat(sgGosd->Cells[8][i]);  //单据入库数量
               if(FQty>Ftmp)
                throw Exception("入库数量不能超过未入库数量");
               if(sgGosd->Cells[6][i] == "")
                throw Exception("缺少单位转换系数");
               FConv=StrToFloat(sgGosd->Cells[6][i]); //转换系数
               if(sIUnitCode==sgGosd->Cells[5][i])
                SetDetailValue(fiGosdQty, sgGosd->Cells[8][i]);             //入库数量
               else
               {
                FIQty=FQty*FConv;                      //入库数量
                SetDetailValue(fiGosdQty, FloatToStr(FIQty));             //入库数量
               }
               SetDetailValue(fiGosdPrice, sgGosd->Cells[13][i]);           //入库单价
               if(sgGosd->Cells[13][i] == "")
                throw Exception("缺少货物单价");
               FPrice=StrToFloat(sgGosd->Cells[13][i]); //单价
               FAmt=FPrice*FQty;
               SetDetailValue(fiGosdAmt, FloatToStr(FAmt));             //入库金额
               SetDetailValue(fiGosdLoc, sgGosd->Cells[9][i]);             //货位
//               SetDetailValue(fiGosdState, sgGosd->Cells[][i]);           //行状态
               SetDetailValue(fiGosdBatch, sgGosd->Cells[10][i]);           //批号
               SetDetailValue(fiGosdSod, sgGosd->Cells[11][i]);             //订单号
               SetDetailValue(fiGosdSodLine, sgGosd->Cells[12][i]);         //订单行号
//               SetDetailValue(fiGosdDesc, sgGosd->Cells[][i]);            //备注
               comServer->AddToObject();
               j=j+1;
           }
       }
     }
     catch(Exception &e)
     {
      comServer->Cancel();
      this->ModalResult=0;
      throw Exception(e.Message);
     }
    }
  }
  __finally
  {
    EndWaitForm();
  }
  Close();
}
//---------------------------------------------------------------------------
void __fastcall TfrmGosd::btnCancelClick(TObject *Sender)
{
    Close();
}
//---------------------------------------------------------------------------
void __fastcall TfrmGosd::InitControlGroup()
{
    sgGosd->RowCount = 1;
    seGoshType->Text=frmGosh->scGoshType->Text;
    pv_GoshType=StrToIntDef(frmGosh->scGoshType->ItemData[1],-1);
    seGosdFromCode->Text="";
}
//---------------------------------------------------------------------------

void __fastcall TfrmGosd::FillGridWithData()
{

    AnsiString  ItemStr,s_SQL;
    if(seGosdFromCode->Text == "")
     return;
    switch(pv_GoshType)
    {
     case 1: //销售发货
      s_SQL =" select Line=SogdLine,Goods=SogdGoods,GoodsName,Unit=SogdUnit,Conv=SogdConv,Qty=SogdQty-SogdOQty,";
      s_SQL+=" Loc=SogdLoc,Price=SogdPrice,Batch=SogdBatch,So='',SodLine=0 from sdSogd,sdGoods ";
      s_SQL+=" where SogdGoods=GoodsCode and SogdClose=0 and SogdCode='"+seGosdFromCode->Text+"' and ";
      s_SQL+=" SogdQty>SogdOQty order by SogdLine";
      break;
     case 2: //采购退货
      s_SQL =" select Line=PretdLine,Goods=PretdGoods,GoodsName,Unit=PretdUnit,Conv=PretdConv,Qty=PretdQty,";
      s_SQL+=" Loc=PretdLoc,Price=PretdPrice,Batch=PretdBatch,So=PretdSo,SodLine=PretdSodLine from sdPretd,sdGoods ";
      s_SQL+=" where PretdGoods=GoodsCode and PretdClose=0 and PretdCode='"+seGosdFromCode->Text+"' and ";
      s_SQL+=" PretdQty>0 order by PretdLine";
      break;
     case 3: //领料
      s_SQL ="";
      break;
     default:
      s_SQL ="";
      break;
    }
    if(s_SQL=="")
     return;
    TComResultSet *RsGosd;
    sgGosd->RowCount=1;
    try
    {
      StartWaitForm("正在查询数据,请稍候......");
      RsGosd=NewResultSet();
      RsGosd->Open(s_SQL,"");
      while( RsGosd->Eof == 0)
      {
        ItemStr="\t"+AnsiString("") +
                "\t"+RsGosd->FieldByName("Line")+
                "\t"+RsGosd->FieldByName("Goods")+
                "\t"+RsGosd->FieldByName("GoodsName")+
                "\t"+RsGosd->FieldByName("Unit")+
                "\t"+RsGosd->FieldByName("Conv")+
                "\t"+RsGosd->FieldByName("Qty")+
                "\t"+RsGosd->FieldByName("Qty")+
                "\t"+RsGosd->FieldByName("Loc")+
                "\t"+RsGosd->FieldByName("Batch")+
                "\t"+RsGosd->FieldByName("So")+
                "\t"+RsGosd->FieldByName("SodLine")+
                "\t"+RsGosd->FieldByName("Price");
        sgGosd->AddItem(ItemStr);
        RsGosd->MoveNext();
      }
      RsGosd->Close();
    }
    __finally
    {
      EndWaitForm();
    }
    delete RsGosd;
}
//---------------------------------------------------------------------------
void __fastcall TfrmGosd::GetComObject(TComServer *comServerPtr)
{
    comServer = comServerPtr;
}
//---------------------------------------------------------------------------
void __fastcall TfrmGosd::SetDetailValue(int Index,AnsiString Value)
{
     WriteItemValue(comServer,Index,Value);
}
//---------------------------------------------------------------------------
void __fastcall TfrmGosd::sgGosdDblClick(TObject *Sender)
{
    AnsiString SqlStr;
    int ARow=sgGosd->Row;
    if (ARow >0)
    {
      if(sgGosd->Col==1)
      {
        if (sgGosd->Cells[1][ARow] == "√")
        {
         sgGosd->Cells[1][ARow] =  "";
         for (int i=1;i<sgGosd->RowCount;i++)
         {
            if(sgGosd->Cells[1][i]=="√")
            {
               btnOK->Enabled=true;
               break;
            }
            else
               btnOK->Enabled=false;
         }
        }
        else
        {
          sgGosd->Cells[1][ARow] =  "√";
          btnOK->Enabled=true;
        }
      }
      else if(sgGosd->Col==9 && sgGosd->Cells[1][ARow] == "√")
      {
        SqlStr="002[货位代码][货位名称]select loccode,locname from sdLoc,sdlg ";
        SqlStr+=" where lgLoccode=loccode and lggoodscode='"+sgGosd->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)
        {
          sgGosd->Cells[9][ARow]=p->ColData[1];
        }
        delete p;
      }
    }
}
//---------------------------------------------------------------------------

void __fastcall TfrmGosd::seGosdFromCodeButtonClick(TObject *Sender)
{
  AnsiString SqlStr;
  switch(pv_GoshType)
  {
   case 1: //销售发货
    SqlStr="006[销售发货单][发货日期][客户][币种][税码][操作员]";
    SqlStr+="select SoghCode,SoghDate,ClientName,CurrencyName,isnull(TaxName,''),SoghUser from sdSogh,sdClient,sdCurrency,sdTax";
    SqlStr+=" where Soghcurrency=currencycode and Soghtaxcode*=taxcode and Soghcheck=1 and Soghclose=0 and Soghcancel=0 ";
    SqlStr+=" and SoghClient=ClientCode order by Soghcode";
    break;
   case 2: //采购退货
    SqlStr="006[采购退货单][退货日期][供应商][币种][税码][操作员]";
    SqlStr+="select PrethCode,PrethDate,SupplyName,CurrencyName,isnull(TaxName,''),PrethUser from sdPreth,sdSupply,sdCurrency,sdTax";
    SqlStr+=" where Prethcurrency=currencycode and Prethtaxcode*=taxcode and Prethcheck=1 and Prethclose=0 and Prethcancel=0 ";
    SqlStr+=" and PrethSupply=SupplyCode order by Prethcode";
    break;
   case 3: //退料
    SqlStr="";
    break;
   default:
    SqlStr="";
    break;
  }
  if(SqlStr=="")
   return;
  TfrmWnQuery *p;
  try
  {
    StartWaitForm("正在查询,请稍候...");
    p=new TfrmWnQuery(this,"出库来源单据查询",SqlStr);
  }
  __finally
  {
    EndWaitForm();
  }
  if(p->ShowModal()==mrOk)
  {
    seGosdFromCode->Text=p->ColData[1];
    FillGridWithData();
  }
  delete p;
}
//---------------------------------------------------------------------------

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

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


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

void __fastcall TfrmGosd::sgGosdSetEditText(TObject *Sender,
      int ACol, int ARow, const AnsiString Value)
{
 if(sgGosd->Cells[1][ARow]=="√")
 {
  if(ACol == 7)
   sgGosd->Cells[8][ARow]=Value;
 }
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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