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

📄 pieced_t.cpp

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

TfrmPieced_T *frmPieced_T;
//---------------------------------------------------------------------------
__fastcall TfrmPieced_T::TfrmPieced_T(TComponent* Owner)
    : TStdBaseForm(Owner)
{
}
//---------------------------------------------------------------------------
__fastcall TfrmPieced_T::TfrmPieced_T(TComponent* Owner,AnsiString FPieceShop,AnsiString FPieceTeam)
    : TStdBaseForm(Owner)
{
    v_PiecehShop=FPieceShop;
    v_PiecehTeam=FPieceTeam;
}
//---------------------------------------------------------------------------
void __fastcall TfrmPieced_T::FormShow(TObject *Sender)
{
    scPiecedDType->ClearAll();
    scPiecedDType->AddItems("0-手工录入","0");
    scPiecedDType->AddItems("1-平均分配","1");

    FillEdit(sePiecedProcess,"SELECT ProcessCode,ProcessName FROM sdProcess order by ProcessCode","ProcessName","ProcessCode");

    InitEditControl();
    FillDataToGrid();
    sePiecedWo->SetFocus();
}
//---------------------------------------------------------------------------

void __fastcall TfrmPieced_T::FillDataToGrid()
{
    TComResultSet *Rst;
    AnsiString  m_SQL,m_STR;
    Rst= NewResultSet();
    m_SQL=AnsiString("Select distinct WpeEmployee,EmployeeName from sdWpe,")+
          AnsiString("sdEmployee where WpeEmployee=EmployeeCode and WpeShop='"+v_PiecehShop+"' and WpeTeam='"+v_PiecehTeam+"' ")+
          AnsiString("Order by WpeEmployee");
    Rst->Open(WideString(m_SQL),WideString(""));
    Rst->MoveFirst();
    sgPieced->RowCount=1;
    while(Rst->Eof == 0)
    {
       m_STR=AnsiString("√")+
             "\t"+Rst->FieldByName("WpeEmployee")+
             "\t"+Rst->FieldByName("EmployeeName")+
             "\t"+AnsiString("0.00");
       sgPieced->AddItem(m_STR);
       Rst->MoveNext();
    }
    Rst->Close();
    delete Rst;
}
//---------------------------------------------------------------------------
void __fastcall TfrmPieced_T::InitEditControl()
{
    sePiecedWo->Text="";
    sePiecedProcess->ItemIndex=-1;
    sePiecedQty->Text="0.00";
    sePiecedPrice->Text="0.00";
    scPiecedDType->ItemIndex=-1;
}
//---------------------------------------------------------------------------
void __fastcall TfrmPieced_T::btCacelClick(TObject *Sender)
{
    Close();
}
//---------------------------------------------------------------------------
void __fastcall TfrmPieced_T::SetcomServer(TComServer *value)
{
    comServer=value;
}
//---------------------------------------------------------------------------
void __fastcall TfrmPieced_T::scPiecedDTypeClick(TObject *Sender)
{
    AnsiString tempS;
    double totalQty;
    totalQty=sePiecedQty->Text.ToDouble();
    if(totalQty<=0)
       throw Exception("团体工时的数量不能小于或等于零!");
    tempS=Trim(scPiecedDType->Text);
    if(scPiecedDType->ItemData[1]==1)
    {
       sgPieced->ReadOnly=true;
       AverageTotalQty();
    }
    else
    {
       sgPieced->ReadOnly=false;
       sgPieced->Options<<goEditing;
       sgPieced->Options<<goAlwaysShowEditor;
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmPieced_T::AverageTotalQty()
{
    int iRowCount=0;
    double aveQty,totalQty,lastQty;
    totalQty=sePiecedQty->Text.ToDouble();
    if(sgPieced->RowCount>1)
    {
       //统计选择的员工编码
       for(int i=1;i<sgPieced->RowCount;i++)
       {
         if(sgPieced->Cells[0][i]=="√")
            iRowCount=iRowCount+1;
       }
       if(iRowCount>0){
         aveQty=totalQty/iRowCount;
         aveQty=DataCarry(aveQty,2,1);
         for(int i=1;i<sgPieced->RowCount;i++)
         {
            if(sgPieced->Cells[0][i]=="√")
               sgPieced->Cells[3][i]=aveQty;
            else
               sgPieced->Cells[3][i]="0.00";
         }
         //查找最后一个选择的员工编码
         for(int i=sgPieced->RowCount;i>0;i--)
         {
            if(sgPieced->Cells[0][i]=="√"){
               lastQty=sgPieced->Cells[3][i].ToDouble();
               sgPieced->Cells[3][i]=lastQty+totalQty-aveQty*iRowCount;
               return;
            }
         }
       }
       else
          throw Exception("没有选择可分摊的员工!");
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmPieced_T::SetDetailValue(int Index,AnsiString Value)
{
    frmPieceh_T->SetDetailValue(Index,Value);
}
//---------------------------------------------------------------------------
void __fastcall TfrmPieced_T::sgPiecedSelectCell(TObject *Sender, int ACol,
      int ARow, bool &CanSelect)
{
    if(ARow>0 && ACol==0)
    {
       if(sgPieced->Cells[0][ARow]=="")
       {
          sgPieced->Cells[0][ARow]="√";
          if(scPiecedDType->ItemIndex==0)
             AverageTotalQty();
       }
       else
       {
          sgPieced->Cells[0][ARow]="";
          sgPieced->Cells[3][ARow]="0.00";
          if(scPiecedDType->ItemData[1]==1)
             AverageTotalQty();
       }
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmPieced_T::btOkClick(TObject *Sender)
{
    double TotalQty,v_Qty;
    TotalQty = 0;
    for(int i=1;i<sgPieced->RowCount;i++)
    {
       if(sgPieced->Cells[0][i]=="√")
         TotalQty=TotalQty+sgPieced->Cells[3][i].ToDouble();
    }
    v_Qty= sePiecedQty->Text.ToDouble();
    if(TotalQty != v_Qty)
       throw Exception("工时分配后的总和不等于团体总工时,请重新分配.");
    if(sgPieced->RowCount>1)
    {
       int j;
       j=comServer->ItemCount-1;
       if(j>0)
       {
          comServer->LocateItemByIndex(j);
          j=StrToInt(frmPieceh_T->GetDetailValue(fiPiecedLine));
          j=j+1;
       }
       else
          j=1;
       for(int i=1;i<sgPieced->RowCount;i++)
       {
          if(sgPieced->Cells[0][i]=="√")
          {
            comServer->AddItem();
            SetDetailValue(fiPiecedCode,frmPieceh_T->sePiecehCode->Text);
            SetDetailValue(fiPiecedLine,AnsiString(j));
            SetDetailValue(fiPiecedWo,sePiecedWo->Text);
            SetDetailValue(fiPiecedDType,scPiecedDType->ItemData[1]);
            SetDetailValue(fiPiecedProcess,sePiecedProcess->ItemData[1]);
            SetDetailValue(fiPiecedEmployee,sgPieced->Cells[1][i]);
            SetDetailValue(fiPiecedQty,sgPieced->Cells[3][i]);
            SetDetailValue(fiPiecedPrice,sePiecedPrice->Text);
            try{
               comServer->AddToObject();
            }
            catch(Exception &e)
            {
               comServer->Cancel();
               this->ModalResult=0;
               throw Exception(e.Message);
            }
            j=j+1;
          }
       }
    }
    Close();
}
//---------------------------------------------------------------------------
void __fastcall TfrmPieced_T::sePiecedWoButtonClick(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)
    {
       sePiecedWo->Text=p->ColData[1];
    }
    delete p;
}
//---------------------------------------------------------------------------
void __fastcall TfrmPieced_T::sePiecedProcessButtonClick(TObject *Sender)
{
    AnsiString SqlStr;
    SqlStr="003[序号][工序代码][工序名称]SELECT WrgNo,WrgProcess,ProcessName FROM sdWrg,sdProcess ";
    SqlStr=SqlStr+"where WrgProcess=ProcessCode and WrgWo='"+sePiecedWo->Text+"' ORDER BY WrgNo";
    TfrmWnQuery *p;
    try
    {
       StartWaitForm("正在查询,请稍候...");
       p=new TfrmWnQuery(this,"工序资料查询",SqlStr);
    }
    __finally
    {
       EndWaitForm();
    }
    if(p->ShowModal()==mrOk)
    {
       sePiecedProcess->LocateKey(p->ColData[2]);
    }
    delete p;
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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