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

📄 wsgmcopy.cpp

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

TfrmWsgmCopy *frmWsgmCopy;
//---------------------------------------------------------------------------
__fastcall TfrmWsgmCopy::TfrmWsgmCopy(TComponent* Owner)
    : TStdBaseForm(Owner)
{
}
//---------------------------------------------------------------------------
__fastcall TfrmWsgmCopy::TfrmWsgmCopy(TComponent* Owner,AnsiString FWsgmWo)
    : TStdBaseForm(Owner)
{
    FWsgmCopyWo=FWsgmWo;
    seWsgmWo->Text=FWsgmCopyWo;
    sgWsgm->RowCount=1;
}
//---------------------------------------------------------------------------
void __fastcall TfrmWsgmCopy::FillGridWithData(AnsiString s_Code)
{
    AnsiString tempSQL,ItemStr;
    Rst=NewResultSet();
    if(rbtBomd->Checked) //按物料单(Bom表)生成
    {
      tempSQL=AnsiString("Select BomdSn,BomdGoods,GoodsName,BomdUnit,BomdFrom,")+
              AnsiString("BomdQty,BomdShl,BomdProcess from sdBomd,sdGoods ")+
              AnsiString("Where BomdGoods=GoodsCode and BomdPgoods='"+s_Code+"' Order By BomdSn");
      Rst->Open(tempSQL,"BomdSn");
      Rst->MoveFirst();
      while( Rst->Eof == 0 )
      {
          ItemStr=AnsiString("√")+
                  "\t"+ Rst->FieldByName("BomdSn")+
                  "\t"+ Rst->FieldByName("BomdGoods")+
                  "\t"+ Rst->FieldByName("GoodsName")+
                  "\t"+ Rst->FieldByName("BomdUnit");
          sgWsgm->AddItem(ItemStr);
          Rst->MoveNext();
      }
    }
    else
    {
      tempSQL=AnsiString("Select WsgmSn,WsgmGoods,GoodsName,WsgmUnit,WsgmQty,")+
              AnsiString("WsgmShl,WsgmLoc,WsgmBatch,WsgmProcess,")+
              AnsiString("WsgmFrom from sdWsgm,sdGoods ")+
              AnsiString("Where WsgmGoods=GoodsCode and WsgmWo='"+s_Code+"' Order By WsgmSn");
      Rst->Open(tempSQL,"WsgmSn");
      Rst->MoveFirst();
      while(Rst->Eof == 0)
      {
          ItemStr=AnsiString("√")+
                  "\t"+ Rst->FieldByName("WsgmSn")+
                  "\t"+ Rst->FieldByName("WsgmGoods")+
                  "\t"+ Rst->FieldByName("GoodsName")+
                  "\t"+ Rst->FieldByName("WsgmUnit");
          sgWsgm->AddItem(ItemStr);
          Rst->MoveNext();
      }
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmWsgmCopy::SetcomServer(TComServer *value)
{
    comServer=value;
}
//---------------------------------------------------------------------------
void __fastcall TfrmWsgmCopy::sgWsgmSelectCell(TObject *Sender, int ACol,
      int ARow, bool &CanSelect)
{
    if(ARow>0 && ACol==0)
    {
       if(sgWsgm->Cells[0][ARow]=="")
          sgWsgm->Cells[0][ARow]="√";
       else
          sgWsgm->Cells[0][ARow]="";
    }
    AnsiString m_Key;
    m_Key=sgWsgm->Cells[1][ARow];
    Rst->LocateByKey(WideString(m_Key));
    SetValueToControl();
}
//---------------------------------------------------------------------------

void __fastcall TfrmWsgmCopy::SetValueToControl()
{
    if(rbtBomd->Checked)
    {
        scWsgmCopyFrom->ItemIndex=StrToInt(Rst->FieldByName("BomdSn"))-1;
        seWsgmCopyQty->Text=Rst->FieldByName("BomdQty");
        seWsgmCopyShl->Text=Rst->FieldByName("BomdShl");
        seWsgmCopyPqty->Text="";
        scWsgmCopyLoc->Text="";
        scWsgmCopyBatch->Text="";
        scWsgmCopyProcess->Text="";
    }
    else
    {
        scWsgmCopyFrom->ItemIndex=StrToInt(Rst->FieldByName("WsgmSn"))-1;
        seWsgmCopyQty->Text=Rst->FieldByName("WsgmQty");
        seWsgmCopyShl->Text=Rst->FieldByName("WsgmShl");
        seWsgmCopyPqty->Text="";
        scWsgmCopyLoc->LocateKey(Rst->FieldByName("WsgmLoc"));
        scWsgmCopyBatch->LocateKey(Rst->FieldByName("WsgmBatch"));
        scWsgmCopyProcess->LocateKey(Rst->FieldByName("WsgmProcess"));
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmWsgmCopy::btnCancelClick(TObject *Sender)
{
    delete Rst;
    Close();
}
//---------------------------------------------------------------------------
void __fastcall TfrmWsgmCopy::FormShow(TObject *Sender)
{
    seWsgmWo->Text = FWsgmCopyWo;
    seWsgmWo->Enabled=false;
    Panel1->Enabled=false;
    rbtBomd->Checked=true;
    scWsgmCopyWoF->Visible =false; //不可见
    FillComboBox(scWsgmCopyBom,"select BomhGoods,memo=BomhGoods+space(18-Len(BomhGoods))+GoodsName from sdBomh,sdGoods where BomhGoods=GoodsCode order by BomhGoods","memo","BomhGoods");
    FillComboBox(scWsgmCopyWoF,"select WoCode,memo=WoCode+space(18-Len(WoCode))+WoGoods from sdWo where WoCheck=1 and WoCancel=0 order by WoCode","memo","WoCode");
    FillComboBox(scWsgmCopyLoc,"select LocCode,LocName FROM sdLoc order by LocCode","LocName","LocCode");
    FillComboBox(scWsgmCopyBatch,"select BatchCode,BatchDesc FROM sdBatch order by BatchCode","BatchDesc","BatchCode");
    FillComboBox(scWsgmCopyProcess,"select ProcessCode,ProcessName FROM sdProcess order by ProcessCode","ProcessName","ProcessCode");
    InitEditControl();
}
//---------------------------------------------------------------------------
void __fastcall TfrmWsgmCopy::SetFieldValue(int Index,AnsiString Value)
{
    WriteFieldValue(comServer,Index,Value);
}
//---------------------------------------------------------------------------
void __fastcall TfrmWsgmCopy::InitEditControl()
{
    scWsgmCopyBom->ItemIndex=-1;
    scWsgmCopyBom->Text = "";
    scWsgmCopyWoF->ItemIndex=-1;
    scWsgmCopyWoF->Text="";

    seWsgmCopyQty->Text ="";
    seWsgmCopyShl->Text ="";
    seWsgmCopyPqty->Text ="";

    scWsgmCopyLoc->ItemIndex=-1;
    scWsgmCopyLoc->Text = "";

    scWsgmCopyBatch->ItemIndex=-1;
    scWsgmCopyBatch->Text = "";

    scWsgmCopyProcess->ItemIndex=-1;
    scWsgmCopyProcess->Text = "";
}
//---------------------------------------------------------------------------
void __fastcall TfrmWsgmCopy::btnOKClick(TObject *Sender)
{
    AnsiString m_Keystr;
    if(sgWsgm->RowCount>0){
      for(int i=1;i<sgWsgm->RowCount;i++){
        int j;
        if(rbtBomd->Checked){
          if(sgWsgm->Cells[0][i]=="√"){
            j=comServer->RecordCount-1;
            if(j>=0)
            {
               comServer->LocateByIndex(j);
               j=StrToInt(frmWsgm->GetFieldValue(fiWsgmSn));
               j=j+1;
            }
            else
               j=1;
            m_Keystr=sgWsgm->Cells[1][i];
            Rst->LocateByKey(m_Keystr);
            comServer->AddNew();
            SetFieldValue(fiWsgmWo,frmWsgm->labWsgmWo->Caption);
            SetFieldValue(fiWsgmSn,AnsiString(j));
            SetFieldValue(fiWsgmGoods,Rst->FieldByName("BomdGoods"));
            SetFieldValue(fiWsgmQty,Rst->FieldByName("BomdQty"));
            SetFieldValue(fiWsgmShl,Rst->FieldByName("BomdShl"));
            SetFieldValue(fiWsgmProcess,Rst->FieldByName("BomdProcess"));
            SetFieldValue(fiWsgmFrom,"2");  //1-物料单,2-工单配套表
            SetFieldValue(fiWsgmUser,frmWsgm->labUserCode->Caption);
            try
            {
               comServer->Post();
            }
            catch(Exception &e)
            {
               comServer->Cancel();
               this->ModalResult=0;
               throw Exception(e.Message);
            }
            j=j+1;
          }
        }
        else{
          if(sgWsgm->Cells[0][i]=="√"){
            j=comServer->RecordCount-1;
            if(j>=0)
            {
               comServer->LocateByIndex(j);
               j=StrToInt(frmWsgm->GetFieldValue(fiWsgmSn));
               j=j+1;
            }
            else
               j=1;
            m_Keystr=sgWsgm->Cells[1][i];
            Rst->LocateByKey(m_Keystr);
            comServer->AddNew();
            SetFieldValue(fiWsgmWo,frmWsgm->labWsgmWo->Caption);
            SetFieldValue(fiWsgmSn,AnsiString(j));
            SetFieldValue(fiWsgmGoods,Rst->FieldByName("WsgmGoods"));
            SetFieldValue(fiWsgmUnit,Rst->FieldByName("WsgmUnit"));
            SetFieldValue(fiWsgmQty,Rst->FieldByName("WsgmQty"));
            SetFieldValue(fiWsgmShl,Rst->FieldByName("WsgmShl"));
            if(Rst->FieldByName("WsgmLoc") != "")
               SetFieldValue(fiWsgmLoc,Rst->FieldByName("WsgmLoc"));
            if(Rst->FieldByName("WsgmBatch") != "")
               SetFieldValue(fiWsgmBatch,Rst->FieldByName("WsgmBatch"));
            if(Rst->FieldByName("WsgmProcess") != "")
               SetFieldValue(fiWsgmProcess,Rst->FieldByName("WsgmProcess"));
            SetFieldValue(fiWsgmFrom,"2"); //1-物料单,2-工单配套表
            SetFieldValue(fiWsgmUser,frmWsgm->labUserCode->Caption);
            try
            {
               comServer->Post();
            }
            catch(Exception &e)
            {
               comServer->Cancel();
               this->ModalResult=0;
               throw Exception(e.Message);
            }
            j=j+1;
          }
        }
      }
    }
    Close();
}
//---------------------------------------------------------------------------
void __fastcall TfrmWsgmCopy::FormClose(TObject *Sender,
      TCloseAction &Action)
{
    delete Rst;
    Close();
}
//---------------------------------------------------------------------------
void __fastcall TfrmWsgmCopy::scWsgmCopyBomClick(TObject *Sender)
{
    AnsiString s_BomdGoods;
    s_BomdGoods=Trim(scWsgmCopyBom->ItemData[1]);
    if(s_BomdGoods.IsEmpty())
    {
       ::MessageBox(Handle,"复制时的来源的加工件编码不能为空!","错误",MB_OK|MB_ICONSTOP);
       return;
    }
    else
    {
       sgWsgm->RowCount=1;
       FillGridWithData(s_BomdGoods);
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmWsgmCopy::scWsgmCopyWoFClick(TObject *Sender)
{
    AnsiString s_WsgmCopyWoF;
    if(scWsgmCopyWoF->ItemIndex==-1)
    {
       ::MessageBox(Handle,"复制时的来源加工单编号不能为空!","错误",MB_OK|MB_ICONSTOP);
       return;
    }
    else
    {
       sgWsgm->RowCount=1;
       s_WsgmCopyWoF=Trim(scWsgmCopyWoF->ItemData[1]);
       FillGridWithData(s_WsgmCopyWoF);
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmWsgmCopy::rbtWsgmClick(TObject *Sender)
{
    if(rbtWsgm->Checked)
    {
      scWsgmCopyBom->Visible=false;
      scWsgmCopyWoF->Visible=true;
    }
    else
    {
      scWsgmCopyBom->Visible=true;
      scWsgmCopyWoF->Visible=false;
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmWsgmCopy::rbtBomdClick(TObject *Sender)
{
    if(rbtBomd->Checked)
    {
      scWsgmCopyBom->Visible=true;
      scWsgmCopyWoF->Visible=false;
    }
    else
    {
      scWsgmCopyBom->Visible=false;
      scWsgmCopyWoF->Visible=true;
    }
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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