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

📄 gmth_w.cpp

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

TfrmGmth_W *frmGmth_W;
//---------------------------------------------------------------------------
__fastcall TfrmGmth_W::TfrmGmth_W(TComponent* Owner)
    : TGenBaseForm(Owner,euSdGmth_W,"")
{
    AutoCtl=seGmthCode;
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_W::InitEditControl()
{
    ClientGroup->AddComponent(1,false,false,true,PnlGmth,PnlGmth->Name);
    ClientGroup->AddComponent(1,true,true,true,scGmthType,scGmthType->Name);
    ClientGroup->AddComponent(1,false,true,false,seGmthCode,seGmthCode->Name);
    ClientGroup->AddComponent(1,false,true,true,seGmthWo,seGmthWo->Name);
    ClientGroup->AddComponent(1,true,true,true,scGmthFmonth,scGmthFmonth->Name);
    //
    scGmthType->ClearAll();
    scGmthType->AddItems("R-工单定额领料","1");
    scGmthType->AddItems("W-工单自由领料","2");
    scGmthType->AddItems("A-工单工序补料","3");
    scGmthType->AddItems("C-共用材料领料","4");
    scGmthType->AddItems("D-部门直接领料","5");
    //
    FillComboBox(scGmthFmonth,"SELECT FcMonth FROM sdFc order by FcMonth","FcMonth");
    FillComboBox(scGmthPosType,"SELECT PosTypeCode,PosTypeName FROM sdPosType where PosTypeFlg=3 order by PosTypeName","PosTypeName","PosTypeCode");
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_W::RefreshUpdateData(int MsgSrc,int MsgType)
{
    try
    {
       switch(MsgSrc)
       {
         case euSdFc:
           if(ShowUpdateMessage(MsgSrc,MsgType)){
	           StartWaitForm("正在刷新引用数据!");
	           FillComboBox(scGmthFmonth,"SELECT FcMonth FROM sdFc order by FcMonth","FcMonth");
	           EndWaitForm();
	           break;
           }
         case euSdPosType:
           if(ShowUpdateMessage(MsgSrc,MsgType)){
	           StartWaitForm("正在刷新引用数据!");
	           FillComboBox(scGmthPosType,"SELECT PosTypeCode,PosTypeName FROM sdPosType order by PosTypeCode","PosTypeName","PosTypeCode");
	           EndWaitForm();
	           break;
           }
         default:
           break;
       }
    }
    __finally
    {
        //AddCode;
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_W::ClearControl(int Section,bool BringToNext)
{
    if(Section == 1)
    {
      if(!BringToNext)
      {
        seGmthCode->Text="";
        deGmthDate->Text=g_sdCurDate;
        scGmthFmonth->LocateKey(g_sdMMonth);
        scGmthPosType->ItemIndex=-1;
        scGmthType->ItemIndex=1;
        seGmthWo->Text="";
        labUser->Caption=g_sdUserCode;
        chkGmthCheck->Checked=false;
        labChecker->Caption="";
        labCheckDate->Caption="";
        memGmthDesc->Text="";
      }
      sgGmth->RowCount=1;
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_W::GetDataFromComObject(int Section)
{
    if(Section==1){
      seGmthCode->Text=GetHeadValue(fiGmthCode);
      deGmthDate->Text=GetHeadValue(fiGmthDate);
      scGmthFmonth->LocateKey(GetHeadValue(fiGmthFmonth));
      scGmthPosType->LocateKey(GetHeadValue(fiGmthPosType));
      scGmthType->LocateKey(GetHeadValue(fiGmthType));
      seGmthWo->Text=GetHeadValue(fiGmthWoCode);
      memGmthDesc->Text=GetHeadValue(fiGmthDesc);
      chkGmthCheck->Checked=GetHeadValue(fiGmthCheck)=="1";
      if(chkGmthCheck->Checked)
         SetCheckToolbarStatus(true);
      else
         SetCheckToolbarStatus(false);
      labChecker->Caption=GetHeadValue(fiGmthChecker);
      labCheckDate->Caption=GetHeadValue(fiGmthCheckDate);
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_W::SendDataToComObject(int Section)
{
    if(Section==1){
       SetHeadValue(fiGmthCode,seGmthCode->Text);
       SetHeadValue(fiGmthDate,deGmthDate->Text);
       SetHeadValue(fiGmthFmonth,scGmthFmonth->Text);
       SetHeadValue(fiGmthPosType,scGmthPosType->ItemData[1]);
       SetHeadValue(fiGmthWoCode,seGmthWo->Text);
       SetHeadValue(fiGmthUser,labUser->Caption);
       SetHeadValue(fiGmthDesc,memGmthDesc->Text);
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_W::WaitUserInput(int Section)
{
    if(Section ==1)
    {
      if(seGmthCode->Enabled)
         seGmthCode->SetFocus();
      else
         deGmthDate->SetFocus();
    }
}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmGmth_W::GetDataToGrid()
{
    AnsiString ItemStr;
    ItemStr=AnsiString("√");
    ItemStr+="\t"+GetDetailValue(fiGmtdLine)+
             "\t"+GetDetailValue(fiGmtdGoods)+
             "\t"+GetDetailValue(fiGmtdUnit)+
             "\t"+GetDetailValue(fiGmtdPQty)+
             "\t"+GetDetailValue(fiGmtdGQty)+
             "\t"+GetDetailValue(fiGmtdQty)+
             "\t"+GetDetailValue(fiGmtdSLoc);
    return ItemStr;
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_W::RefreshGridData(int mAction)
{
    int i;
    AnsiString ItemStr=GetDataToGrid();
    switch(mAction)
    {
       case 0: //Add
         sgGmth->AddItem(ItemStr);
         sgGmth->Row=sgGmth->RowCount-1;
         break;
       case 1: //Edit
         sgGmth->ChangeItem(ItemStr,sgGmth->Row);
         break;
       case 2: //Delete
         sgGmth->RemoveItem(sgGmth->Row);
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_W::FillGridWithData()
{
    int i;
    AnsiString ItemStr;
    sgGmth->RowCount=1;
    if(comServer->RecordCount > 0){
      for(i=0;i<comServer->ItemCount;i++)
      {
         comServer->LocateItemByIndex(i);
         RefreshGridData(0);
      }
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_W::DisplayBill()
{
    if(comServer->RecordCount>0)
    {
      GetDataFromComObject(1);
      FillGridWithData();
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_W::GetBill(AnsiString BillID)
{
    bool iRow;
    iRow=comServer->Find("GmthCode='"+BillID+"'");
    if(iRow)      //FIND THIS BILL
    {
       DisplayBill();
    }
    else
       if (ShowMessageWindow("在数据库中没有查到记录:"+BillID+",要增加吗?",mwsConfirmation)==IDYES)
       {
          AddHeadRecord();
       }
}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmGmth_W::GetHeadValue(int Index)
{
    return ReadFieldValue(comServer,Index);
}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmGmth_W::GetDetailValue(int Index)
{
    return ReadItemValue(comServer,Index);
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_W::SetHeadValue(int Index,AnsiString Value)
{
    WriteFieldValue(comServer,Index,Value);
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_W::SetDetailValue(int Index,AnsiString Value)
{
    WriteItemValue(comServer,Index,Value);
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_W::FormShow(TObject *Sender)
{
    //单据不能删除行
    tbAddDetail->Visible=false;
    tbEditDetail->Visible=false;
    tbDeleteDetail->Visible=false;
    tbEditAll->Visible=true;
    sgGmth->ReadOnly=true;
    ClearControl(1,false);
    MoveToFirst();
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_W::ChangeToBrowseState(bool t_browse)
{
    sgGmth->ReadOnly=true;
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_W::GenrateBill()
{
    if(comServer->ItemCount>0)
    {
       ::MessageBox(Handle,"当前的单据已经存在,不能再执行生成操作...","错误",MB_OK|MB_ICONSTOP);
       SetControlToBrowseState(1);
       SetControlState(caCancel);
       return;
    }
    try
    {
        StartWaitForm("正在生成,请稍侯...");
        SaveRecord();
    }
    __finally
    {
        EndWaitForm();
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_W::EditBill()
{
    if(sgGmth->RowCount>1)
    {
       sgGmth->SetFocus();
       sgGmth->ReadOnly=false;
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_W::SendAllDetailValue()
{
    if(sgGmth->RowCount>1)
    {
       for(int i=1;i<sgGmth->RowCount;i++)
       {
         if(sgGmth->Cells[0][i]=="√")
         {
           AnsiString Keystr;
           Keystr=sgGmth->Cells[1][i];
           comServer->LocateItemByKey(WideString(Keystr));
           comServer->EditItem();
           SetDetailValue(fiGmtdQty,sgGmth->Cells[6][i]);
           SetDetailValue(fiGmtdSLoc,sgGmth->Cells[7][i]);
           try
           {
               comServer->AddToObject();
           }
           catch(Exception &e)
           {
              throw Exception(e.Message);
           }
         }
       }
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_W::sgGmthClick(TObject *Sender)
{
    int iRow=sgGmth->Row;
    int iCol=sgGmth->Col;
    if(iRow>0 && iCol==0 && CurrentState==caEditBill)
    {
       if(sgGmth->Cells[0][iRow]=="√")
          sgGmth->Cells[0][iRow]="";
       else
          sgGmth->Cells[0][iRow]="√";
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_W::sgGmthDblClick(TObject *Sender)
{
    int ARow=sgGmth->Row;
    int ACol=sgGmth->Col;

    if(sgGmth->Cells[0][ARow]!="√" || comServer->ItemCount<=0)
       return;

    if(ARow>0 && ACol==2)
    {
       TfrmDml *Dmlfrm;
       try{
          StartWaitForm("正在启动<工序材料分摊>界面...");
          comServer->LocateItemByKey(WideString(sgGmth->Cells[1][ARow]));
          AnsiString t_GmthCode=GetDetailValue(fiGmtdCode);
          int        t_GmthCheck=GetHeadValue(fiGmthCheck).ToInt();
          int        t_GmtdLine=GetDetailValue(fiGmtdLine).ToInt();
          AnsiString t_GmtdWo=GetDetailValue(fiGmtdWoCode);
          AnsiString t_GmtdGoods=GetDetailValue(fiGmtdGoods);
          double     t_GmtdQty=GetDetailValue(fiGmtdQty).ToDouble();
          Dmlfrm=new TfrmDml(this,t_GmthCode,t_GmthCheck,t_GmtdLine,t_GmtdWo,t_GmtdGoods,t_GmtdQty);
          EndWaitForm();
          Dmlfrm->ShowModal();
       }
       __finally{
          delete Dmlfrm;
       }
    }

    if(ARow>0 && ACol==7 && CurrentState!=caNormal)
    {
      AnsiString SqlStr;
      SqlStr="003[货位编码][货位名称][货位类型]SELECT LgLocCode,LocName,LocType";
      SqlStr+=" FROM sdLoc,sdLg WHERE LocCode=LgLocCode and LocType=1 and";
      SqlStr+=" LgGoodsCode='"+sgGmth->Cells[2][ARow]+"' ORDER BY LgLocCode";
      TfrmWnQuery *p;
      try
      {
         StartWaitForm("正在查询,请稍候...");
         p=new TfrmWnQuery(this,"物料在制货位查询",SqlStr);
      }
      __finally
      {
         EndWaitForm();
      }
      if(p->ShowModal()==mrOk)
      {
         sgGmth->Cells[7][ARow]=p->ColData[1];
      }
      delete p;
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_W::sgGmthSelectCell(TObject *Sender, int ACol,
      int ARow, bool &CanSelect)
{
    if(ARow > 0)
    {
       FCurRow=ARow;
       comServer->LocateItemByKey(WideString(sgGmth->TextMatrix[ARow][1]));
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_W::seGmthCodeKeyDown(TObject *Sender, WORD &Key,
      TShiftState Shift)
{
    AnsiString tempS=seGmthCode->Text;
    if(Key==13 && CurrentState==caNormal && !tempS.IsEmpty())
    {
       comServer->LocateByKey(WideString(tempS));
       DisplayBill();
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_W::seGmthWoButtonClick(TObject *Sender)
{
    AnsiString SqlStr;
    SqlStr="006[加工单号][加工件码][要求数量][要求日期][订单单号][订单行号]SELECT WoCode,WoGoods,WoQty,WoRDate,";
    SqlStr=SqlStr+"WoSoCode,WoSodLine from sdWo where WoCheck=1 and WoClose=0 ORDER BY WoCode";
    TfrmWnQuery *p;
    try
    {
       StartWaitForm("正在查询,请稍候...");
       p=new TfrmWnQuery(this,"加工订单查询",SqlStr);
    }
    __finally
    {
       EndWaitForm();
    }
    if(p->ShowModal()==mrOk)
    {
       seGmthWo->Text=p->ColData[1];
    }
    delete p;
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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