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

📄 wocancel.cpp

📁 速达开源ERP系统
💻 CPP
字号:
//---------------------------------------------------------------------------

#include <vcl.h>
#include "WoCancel.h"
//---------------------------------------------------------------------------
#pragma hdrstop
#pragma package(smart_init)
#pragma link "DateEdit"
#pragma link "ListBaseForm"
#pragma link "SDComboBox"
#pragma link "SDEdit"
#pragma link "SDGrid"
#pragma resource "*.dfm"

TfrmWoCancel *frmWoCancel;
//---------------------------------------------------------------------------
__fastcall TfrmWoCancel::TfrmWoCancel(TComponent* Owner)
    : TListBaseForm(Owner,euSdWo,"")
{
}
//---------------------------------------------------------------------------

void __fastcall TfrmWoCancel::GetWhereStrToSQL()
{
    WhereStr="WoCheck=0 and WoClose=0 and WoCancel=0";

    if(Trim(scWoRoute->Text) != "")
      WhereStr = WhereStr + " and WoRoute='" + Trim(scWoRoute->Text) + "'";

    if(Trim(seWoGoods->Text) != "")
      WhereStr = WhereStr + " and WoGoods like '%" + Trim(seWoGoods->Text) + "%'";

    if(chkWoCode->Checked){
      if(seWoCodeT->Text.IsEmpty())
         WhereStr = WhereStr + " and WoCode>='" + Trim(seWoCodeF->Text) + "'";
      else{
         if(seWoCodeF->Text.IsEmpty())
             WhereStr = WhereStr + " and WoCode<='" + Trim(seWoCodeT->Text) + "'";
         else
             WhereStr = WhereStr + " and WoCode>='" + seWoCodeF->Text + "' and WoCode<='" + seWoCodeT->Text + "'";
      }
    }

    if(chkWoSdate->Checked){
      if(deWoSdateT->Text.IsEmpty())
         WhereStr = WhereStr + " and WoSdate>='" + FormatDateTime("yyyy-mm-dd",deWoSdateF->Date) + "'";
      else{
         if(deWoSdateF->Text.IsEmpty())
             WhereStr = WhereStr + " and WoSdate<='" + FormatDateTime("yyyy-mm-dd",deWoSdateT->Date) + "'";
         else
             WhereStr = WhereStr + " and WoSdate>='" + FormatDateTime("yyyy-mm-dd",deWoSdateF->Date) + "' and WoSdate<='" + FormatDateTime("yyyy-mm-dd",deWoSdateT->Date) + "'";
      }
    }

    if(chkWoRdate->Checked){
      if(deWoRdateT->Text.IsEmpty())
         WhereStr = WhereStr + " and WoRdate>='" + FormatDateTime("yyyy-mm-dd",deWoRdateF->Date) + "'";
      else{
         if(deWoRdateF->Text.IsEmpty())
             WhereStr = WhereStr + " and WoRdate<='" + FormatDateTime("yyyy-mm-dd",deWoRdateT->Date) + "'";
         else
         WhereStr = WhereStr + " and WoRdate>='" + FormatDateTime("yyyy-mm-dd",deWoRdateF->Date) + "' and WoRdate<='" + FormatDateTime("yyyy-mm-dd",deWoRdateT->Date) + "'";
      }
    }

    int j=0;
    for (int i=0;i < clbWoState->Items->Count;i++)
    {
        if(clbWoState->Checked[i])
        {
           if(j == 0)
           {
              WhereStr = WhereStr + " and (WoStatus=" + AnsiString(i+1);
              j = j + 1;
           }
           else
              WhereStr = WhereStr + " or WoStatus=" + AnsiString(i+1);
        }
    }

    if (j > 0)
       WhereStr = WhereStr + ")";

    j = 0;
    for (int i=0;i< clbWoType->Items->Count;i++)
    {
        if(clbWoType->Checked[i])
        {
           if(j == 0)
           {
              WhereStr = WhereStr + " and (WoType=" + AnsiString(i+1);
              j = j + 1;
           }
           else
              WhereStr = WhereStr + " or WoType=" + AnsiString(i+1);
        }
    }

    if (j > 0)
       WhereStr = WhereStr + ")";
}
//---------------------------------------------------------------------------
void __fastcall TfrmWoCancel::InitEditControl()
{
    sgWoCancel->RowCount=1;
    btnCancel->Enabled=false;

    scWoRoute->ItemIndex=-1;
    scWoRoute->Text="";
    seWoGoods->Text="";

    chkWoCode->Checked=false;
    seWoCodeF->Text="";
    seWoCodeT->Text="";

    chkWoSdate->Checked=false;
    deWoSdateF->Text="";
    deWoSdateT->Text=g_sdCurDate;

    chkWoRdate->Checked=false;
    deWoRdateF->Text="";
    deWoRdateT->Text=g_sdCurDate;

    sbBar->Panels->Items[0]->Text="操作员:"+g_sdUserCode;
    sbBar->Panels->Items[1]->Text=g_sdLoginTime;
    sbBar->Panels->Items[2]->Text=g_sdCurDate;
    sbBar->Panels->Items[3]->Text=g_sdCompanyName;
}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmWoCancel::GetFieldValue(int Index)
{
    return ReadFieldValue(comServer,Index);
}
//---------------------------------------------------------------------------

void __fastcall  TfrmWoCancel::ChangeToBrowseState(bool agree)
{
    return;
}
//---------------------------------------------------------------------------

void __fastcall TfrmWoCancel::btnClearClick(TObject *Sender)
{
    InitEditControl();
}
//---------------------------------------------------------------------------

void __fastcall TfrmWoCancel::btnQueryClick(TObject *Sender)
{
    GetWhereStrToSQL();
    FillGridWithData();
}
//---------------------------------------------------------------------------

void __fastcall TfrmWoCancel::FillGridWithData()
{

    AnsiString ItemStr,StatusCode,TypeCode;

    if(!WhereStr.IsEmpty())
        comServer->FilterString=WideString(WhereStr);
    else
        comServer->FilterString=WideString("");

    comServer->Query();
    if(comServer->RecordCount>0)
    {
        sgWoCancel->RowCount=1;
        for(int i=0;i<comServer->RecordCount;i++)
        {
            comServer->LocateByIndex(i);
            ItemStr=AnsiString(" ")+
                    "\t"+ GetFieldValue(fiWoCode)+
                    "\t"+ GetFieldValue(fiWoGoods)+
                    "\t"+ GetFieldValue(fiWoQty)+
                    "\t"+ GetFieldValue(fiWoRdate)+
                    "\t"+ GetFieldValue(fiWoSdate)+
                    "\t"+ GetFieldValue(fiWoRoute);
            TypeCode= GetFieldValue(fiWoType);
            ItemStr= ItemStr + "\t" + GetTypeNameBySwitch(TypeCode);
            StatusCode=GetFieldValue(fiWoStatus);
            ItemStr= ItemStr + "\t" + GetStatusNameBySwitch(StatusCode);
            sgWoCancel->AddItem(ItemStr);
        }
    }
    else
        sgWoCancel->RowCount=1;
}
//---------------------------------------------------------------------------

AnsiString __fastcall TfrmWoCancel::GetTypeNameBySwitch(AnsiString SwitchStr)
{
    int ch=StrToInt(SwitchStr);
    switch(ch)
    {
       case 1:
           return("常规");
       case 2:
           return("返工");
       case 3:
           return("改装");
       case 4:
           return("委外");
       case 5:
           return("副产品");
       default:
           return("");
    }
}
//---------------------------------------------------------------------------

AnsiString __fastcall TfrmWoCancel::GetStatusNameBySwitch(AnsiString SwitchStr)
{
    int ch=StrToInt(SwitchStr);
    switch(ch)
    {
       case 1:
           return("预备");
       case 2:
           return("确认");
       case 3:
           return("待下达");
       case 4:
           return("已下达");
       case 5:
           return("已完工");
       default:
           return("");
    }
}
//---------------------------------------------------------------------------

void __fastcall TfrmWoCancel::FormShow(TObject *Sender)
{
    FillComboBox(scWoRoute,"select RoutehCode from sdRouteh order by RoutehCode","RoutehCode");
    InitEditControl();
}
//---------------------------------------------------------------------------
void __fastcall TfrmWoCancel::btnExitClick(TObject *Sender)
{
    frmWoCancel->Close();
}
//---------------------------------------------------------------------------


void __fastcall TfrmWoCancel::btnCancelClick(TObject *Sender)
{
    long comErrNum;
    btnCancel->Enabled=false;
    for(int i=sgWoCancel->RowCount-1; i>0;i--)
    {
      if(sgWoCancel->Cells[0][i]=="√")
      {
         comServer->LocateByKey(WideString(sgWoCancel->Cells[1][i]));
         if(!comServer->Eof)
            comServer->Revoke(1);
         sgWoCancel->Cells[0][i]="";
         sgWoCancel->RemoveItem(i);
      }
    }
}
//---------------------------------------------------------------------------

void __fastcall TfrmWoCancel::sgWoCancelClick(TObject *Sender)
{
    int ARow=sgWoCancel->Row;
    int ACol=sgWoCancel->Col;
    if(ARow>0 && ACol == 0)
    {
      if(sgWoCancel->Cells[0][ARow]==" ")
      {
         btnCancel->Enabled=true;
         sgWoCancel->Cells[0][ARow]="√";
      }
      else
      {
         sgWoCancel->Cells[0][ARow]=" ";
         //找到有没有需要取消的
         for (int i=1;i<sgWoCancel->RowCount;i++)
         {
            if(sgWoCancel->Cells[0][i]=="√")
            {
               btnCancel->Enabled=true;
               break;
            }
            else
               btnCancel->Enabled=false;
         }
      }
    }
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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