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

📄 tsh.cpp

📁 一个以前收集的基于C/S架构的ERP客户端源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#include "Tsh.h"
#include "Tsd.h"
//---------------------------------------------------------------------------
#pragma hdrstop
#pragma package(smart_init)
#pragma link "GenBaseForm"
#pragma link "fpanel"
#pragma link "SDGrid"
#pragma link "DateEdit"
#pragma link "SDComboBox"
#pragma link "SDEdit"
#pragma resource "*.dfm"

TfrmTsh *frmTsh;
//---------------------------------------------------------------------------
__fastcall TfrmTsh::TfrmTsh(TComponent* Owner, HWND chWnd, AnsiString MidCode,AnsiString WhereStr)
        : TGenBaseForm(Owner,chWnd,MidCode,WhereStr)
{
 //AutoCtl=seTshCode;
 SetAutoCodeString(seTshCode,"Acm-037");
}
//---------------------------------------------------------------------------

void __fastcall TfrmTsh::InitEditControl()
{
    ClientGroup->AddComponent(1,false,false,true,FloatPanel1,FloatPanel1->Name);
    ClientGroup->AddComponent(1,false,true,false,seTshCode,seTshCode->Name);
    ClientGroup->AddComponent(1,false,true,true,scTshDept,scTshDept->Name);
    ClientGroup->AddComponent(1,true,true,true,scTshFmonth,scTshFmonth->Name);
    ClientGroup->AddComponent(1,true,true,true,chkTshInvFlg,chkTshInvFlg->Name);

    ClientGroup->AddComponent(2,false,false,true,FloatPanel2,FloatPanel2->Name);
    ClientGroup->AddComponent(2,false,true,true,seTsdLine,seTsdLine->Name);
    ClientGroup->AddComponent(2,false,true,true,scTsdLoc,scTsdLoc->Name);
    ClientGroup->AddComponent(2,false,true,true,seTsdGoods,seTsdGoods->Name);
    ClientGroup->AddComponent(2,true,true,true,scTsdUnit,scTsdUnit->Name);
    ClientGroup->AddComponent(2,true,true,true,seTsdAQty,seTsdAQty->Name);
    ClientGroup->AddComponent(2,true,true,true,seTsdAPrice,seTsdAPrice->Name);
    ClientGroup->AddComponent(2,true,true,true,seTsdAAmt,seTsdAAmt->Name);
    ClientGroup->AddComponent(2,true,true,true,seTsdTPrice,seTsdTPrice->Name);
    ClientGroup->AddComponent(2,true,true,true,seTsdDQty,seTsdDQty->Name);
    ClientGroup->AddComponent(2,true,true,true,seTsdIOQty,seTsdIOQty->Name);
    ClientGroup->AddComponent(2,true,true,true,chkTsdFlg1,chkTsdFlg1->Name);
    ClientGroup->AddComponent(2,true,true,true,chkTsdFlg2,chkTsdFlg2->Name);
    ClientGroup->AddComponent(2,false,false,false,btnCancel,btnCancel->Name);
    ClientGroup->AddComponent(2,false,true,true,btnOk,btnOk->Name);
    //Tsh
    FillComboBox(Handle,scTshFmonth,"Select FcMonth from sdFc order by fcmonth","FcMonth");
    FillComboBox(Handle,scTshDept,"select DeptName memo,DeptCode from sdDept where DeptEnd=1 order by deptcode","memo","DeptCode");
    FillComboBox(Handle,scTshPosType,"select postypename memo,postypecode from sdPosType where PosTypeFlg=6 order by PosTypeCode","memo","PosTypeCode");
    FillComboBox(Handle,scTshKeeper,"select UserCode,UserName from sdKeeper,sduser where UserCode=KeeperCode order by UserCode","UserName","UserCode");

    scTshType->ClearAll();
    scTshType->AddItems("1-常规盘点","1");
    scTshType->AddItems("2-循环盘点","2");

    //Tsd
    FillComboBox(Handle,scTsdUnit,"select unitname memo,unitcode from sdunit order by UnitCode","memo","UnitCode");
    FillComboBox(Handle,scTsdBatch,"Select BatchCode from sdBatch order by BatchCode","BatchCode");
    if(Trim(GetParamValue("10520"))=='Y')
      FillComboBox(Handle,scTsdLoc,"select locname memo,loccode from sdloc where LocCode in(select LrLoc from KsLocRight where LrUser= '"+g_sdUserCode+"')  order by LocCode","memo","LocCode");
    else
      FillComboBox(Handle,scTsdLoc,"select locname memo,loccode from sdloc order by LocCode","memo","LocCode");
}
//---------------------------------------------------------------------------

void __fastcall TfrmTsh::ClearControl(int Section,bool BringToNext)
{
    if (Section == 1)
    {
       if (! BringToNext)
       {
          seTshCode->Text       ="";
          scTshFmonth->Text=g_sdIMonth;
          deTshDate->Text       =g_sdCurDate;
          scTshType->ItemIndex  =0;
          scTshDept->ItemIndex   =-1;
          scTshDept->Text="";
          labTshUser->Caption   =g_sdUserCode;
          scTshKeeper->LocateKey(g_sdUserCode);
          deTshEiDate->Text     =g_sdCurDate;
          deTshEoDate->Text     =g_sdCurDate;
          deTshCDate->Text      =g_sdCurDate;
          scTshPosType->ItemIndex   =-1;
          scTshPosType->Text="";
          cbxTshCheck->Checked  =false;
          labTshChecker->Caption    ="";
          labSysDate->Caption="";
          cbxTshCancel->Checked =false;
          chkTshInvFlg->Checked =false;
          memTshDesc->Text      ="";
          //新增单据,工具栏使能
          SetCheckToolbarStatus(false);
       }
       sgTsd->RowCount=1;
    }
    else if (Section==2)
    {
        if (!BringToNext)
        {
           seTsdLine->Text     =AnsiString(comServer->ItemCount+1);
          scTsdLoc->ItemIndex   =-1;
          scTsdLoc->Text="";
          seTsdGoods->Text="";
          pv_GoodsCode="";
          labTsdGoodsName->Caption="";
          labTsdGoodsSpec->Caption="";
          scTsdUnit->ItemIndex   =-1;
          scTsdUnit->Text="";
          seTsdAQty->Text     ="0.00";
          seTsdTQty->Text     ="0.00";
          seTsdAPrice->Text   ="0.00";
          seTsdTPrice->Text   ="0.00";
          seTsdAAmt->Text     ="0.00";
          seTsdTAmt->Text     ="0.00";
          seTsdIOQty->Text     ="0.00";
          seTsdSod->Text      ="";
          seTsdSodLine->Text="";
          scTsdBatch->ItemIndex=-1;
          seTsdDQty->Text     ="0";
          chkTsdFlg1->Checked=false;
          chkTsdFlg2->Checked=false;
          memTsdDesc->Text    ="";
        }
    }
}
//---------------------------------------------------------------------------

void __fastcall TfrmTsh::GetDataFromComObject(int Section)
{
        AnsiString s;
        if (Section==1)
        {
          seTshCode->Text     =GetHeadValue("TshCode");
          deTshDate->Text     =GetHeadValue("TshDate");
          scTshFmonth->Text   =GetHeadValue("TshFmonth");
          scTshType->LocateKey(GetHeadValue("TshType"));
          s = GetHeadValue("TshDept");
          scTshDept->LocateKey(s);
          scTshPosType->LocateKey(GetHeadValue("TshPosType"));
          labTshUser->Caption     =GetHeadValue("TshUser");
          scTshKeeper->LocateKey(GetHeadValue("TshKeeper"));
          deTshEiDate->Text   =GetHeadValue("TshEiDate");
          deTshEoDate->Text   =GetHeadValue("TshEoDate");
          deTshCDate->Text    =GetHeadValue("TshCDate");
          cbxTshCheck->Checked=GetHeadValue("TshCheck")=="1";
          labTshChecker->Caption  =GetHeadValue("TshChecker");
          cbxTshCancel->Checked=GetHeadValue("TshCancel")=="1";
          chkTshInvFlg->Checked=GetHeadValue("TshInvFlg")=="2";
          labSysDate->Caption=GetHeadValue("TshSysDate");
          memTshDesc->Text     =GetHeadValue("TshDesc");
          //根据审核、取消状态,设置工具栏
          if((GetHeadValue("TshCheck")=="1")||(GetHeadValue("TshCancel")=="1"))
           SetCheckToolbarStatus(true);
          else
           SetCheckToolbarStatus(false);
        }
        else
        {
          seTsdLine->Text     =GetDetailValue("TsdLine");
          scTsdLoc->LocateKey(GetDetailValue("TsdLoc"));
            seTsdGoods->Text    =GetDetailValue("TsdGoods");
            labTsdGoodsName->Caption=GetDetailValue("GoodsName");
            labTsdGoodsSpec->Caption=GetDetailValue("GoodsSpec");
            scTsdUnit->LocateKey(GetDetailValue("TsdUnit"));
          //}
          //else
          //{
           // seTsdGoods->Text    ="";
           // labTsdGoodsName->Caption="";
           // scTsdUnit->ItemIndex=-1;
          //}
          seTsdSod->Text      =GetDetailValue("TsdSod");
          seTsdSodLine->Text  =GetDetailValue("TsdSodLine");
          scTsdBatch->LocateKey(GetDetailValue("TsdBatch"));
          seTsdAQty->Text     =GetDetailValue("TsdAQty");
          seTsdAPrice->Text     =GetDetailValue("TsdAPrice");
          seTsdAAmt->Text     =GetDetailValue("TsdAAmt");
          seTsdTQty->Text     =GetDetailValue("TsdTQty");
          seTsdTPrice->Text     =GetDetailValue("TsdTPrice");
          seTsdTAmt->Text     =GetDetailValue("TsdTAmt");
          seTsdDQty->Text     =GetDetailValue("TsdDQty");
          seTsdIOQty->Text    =GetDetailValue("TsdIoQty");
          chkTsdFlg1->Checked =GetDetailValue("TsdFlg")=="1";  //盘盈
          chkTsdFlg2->Checked =GetDetailValue("TsdFlg")=="-1"; //盘亏
          memTsdDesc->Text    =GetDetailValue("TsdDesc");
        }
}
//---------------------------------------------------------------------------

void __fastcall TfrmTsh::SendDataToComObject(int Section)
{
     AnsiString s;
      if (Section==1)
      {
        SetHeadValue("TshCode",seTshCode->Text);
        SetHeadValue("TshFmonth",scTshFmonth->Text);
        if(scTshType->ItemData[1] == "")
         throw Exception("请选择盘点类型");
        SetHeadValue("TshType",scTshType->ItemData[1]);
        SetHeadValue("TshDept",scTshDept->ItemData[1]);
        SetHeadValue("TshDate",deTshDate->Text);
        SetHeadValue("TshUser",labTshUser->Caption);
        SetHeadValue("TshKeeper",scTshKeeper->ItemData[1]);
        SetHeadValue("TshEiDate",deTshEiDate->Text);
        SetHeadValue("TshEoDate",deTshEoDate->Text);
        SetHeadValue("TshCDate",deTshCDate->Text);
        SetHeadValue("TshPosType",scTshPosType->ItemData[1]);
        SetHeadValue("TshDesc",memTshDesc->Text);
      }
      else
      {
        //计算盘点差额
        BackDisp();

        SetDetailValue("TsdCode",seTshCode->Text);
        if(seTsdLine->Text == "")
         throw Exception("请输入盘点单行号");
        SetDetailValue("TsdLine",seTsdLine->Text);
        SetDetailValue("TsdLoc",scTsdLoc->ItemData[1],false);
        SetDetailValue("TsdGoods",seTsdGoods->Text,false);
        SetDetailValue("GoodsName",labTsdGoodsName->Caption,false);
        SetDetailValue("GoodsSpec",labTsdGoodsSpec->Caption,false);

        SetDetailValue("TsdSod",seTsdSod->Text);
        if(seTsdSodLine->Text == "")
         SetDetailValue("TsdSodLine","0");
        else
         SetDetailValue("TsdSodLine",seTsdSodLine->Text);
        SetDetailValue("TsdBatch",scTsdBatch->Text);
        SetDetailValue("TsdUnit",scTsdUnit->ItemData[1],false);
        if(seTsdAQty->Text == "")
         seTsdAQty->Text="0";
        SetDetailValue("TsdAQty",seTsdAQty->Text);
        if(seTsdTQty->Text == "")
         throw Exception("请输入实盘数量");
        SetDetailValue("TsdTQty",seTsdTQty->Text);
        if(seTsdAPrice->Text == "")
         seTsdAPrice->Text="0";
        SetDetailValue("TsdAPrice",seTsdAPrice->Text);
        if(seTsdAAmt->Text == "")
         seTsdAAmt->Text="0";
        SetDetailValue("TsdAAmt",seTsdAAmt->Text);
        if(seTsdTPrice->Text == "")
         throw Exception("请输入实盘单价");
        SetDetailValue("TsdTPrice",seTsdTPrice->Text);
        if(seTsdTAmt->Text == "")
         throw Exception("请输入实盘金额");
        SetDetailValue("TsdTAmt",seTsdTAmt->Text);
        if(seTsdDQty->Text == "")
         seTsdDQty->Text="0";
        SetDetailValue("TsdDQty",seTsdDQty->Text);
        if(seTsdIOQty->Text == "")
         seTsdIOQty->Text="0";
        SetDetailValue("TsdIoQty",seTsdIOQty->Text);
        if(chkTsdFlg1->Checked)
         SetDetailValue("TsdFlg","1");
        else if(chkTsdFlg2->Checked)
         SetDetailValue("TsdFlg","-1");
        else
         SetDetailValue("TsdFlg","0");
        SetDetailValue("TsdDesc",memTsdDesc->Text);
     }
}
//---------------------------------------------------------------------------

void __fastcall TfrmTsh::WaitUserInput(int Section)
{
    TComResultSet *pRst;
    AnsiString m_Sql;
    if (Section ==1)
    {
      if(seTshCode->Enabled)
        seTshCode->SetFocus();
    }
    else
    {
      sgTsd->Visible=false;
      FloatPanel2->Visible=true;
      pv_GoodsCode=Trim(seTsdGoods->Text);
      if(scTsdLoc->Enabled)
        scTsdLoc->SetFocus();
      else
        seTsdGoodsExit(NULL);
    }
    m_Sql=" select parametervalue from sdparameter where parametercode='10508' ";
    try
    {
     pRst=new  TComResultSet(Handle,g_ClientHandle);
     try
     {
      pRst->Open(m_Sql,"");
      if(pRst->RecordCount<1)
      {
        CancelRecord();
        throw Exception("系统库存状态参数被破坏");
      }
      pRst->MoveFirst();
      m_InvState = pRst->FieldByName("parametervalue");
      if(m_InvState!="2")
      {
        if(Application->MessageBox("系统尚未进入盘点状态,是否自动进入盘点状态?","确认盘点对话框",+MB_ICONQUESTION+MB_OKCANCEL)==IDOK)
        {
          pRst->Close();
          m_Sql="update sdparameter set parametervalue='2' where ParameterCode='10508'";
          pRst->Execute(m_Sql);
        }
        else
          CancelRecord();
      }
     }
     catch(Exception &e)
     {
      throw Exception(e.Message);
     }
    }
    __finally
    {
     delete pRst;
    }
}
//---------------------------------------------------------------------------

void __fastcall TfrmTsh::RefreshGridData(int mAction)
{

    int i;
    AnsiString ItemStr;
    switch(mAction)
    {
       case 0:
         ItemStr=GetDataToGrid();
         sgTsd->AddItem(ItemStr);
         break;
       case 1:
         i=sgTsd->Row;
         ItemStr=GetDataToGrid();
         sgTsd->ChangeItem(ItemStr,i);
         break;
       case 2:
         sgTsd->RemoveItem(sgTsd->Row);
    }
}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmTsh::GetDataToGrid()
{
    AnsiString ItemStr;

    ItemStr="\t"+GetDetailValue("TsdLine")
           +"\t"+GetDetailValue("TsdGoods")
           +"\t"+GetDetailValue("GoodsName")
           +"\t"+GetDetailValue("GoodsSpec")
           +"\t"+GetDetailValue("TsdUnit")
           +"\t"+GetDetailValue("TsdAQty")
           +"\t"+GetDetailValue("TsdTQty")
           +"\t"+GetDetailValue("TsdDQty");
    return ItemStr;
}
//---------------------------------------------------------------------------

void __fastcall TfrmTsh::DisplayBill()
{
    GetDataFromComObject(1);
    FillGridWithData();
}
//---------------------------------------------------------------------------

void __fastcall TfrmTsh::GetBill(AnsiString BillID)
{
    int iRow;

    iRow=comServer->Find("TshCode='"+BillID+"'");
    if (iRow>0)      //FIND THIS BILL
    {
       DisplayBill();
    }
    else
       if (ShowMessageWindow("在数据库中没有查到记录:"+BillID+",要增加吗?",mwsConfirmation)==IDYES)
       {
           AddHeadRecord();
       }
}
//---------------------------------------------------------------------------

void __fastcall TfrmTsh::FillGridWithData()
{
    int i;
    AnsiString ItemStr;
    sgTsd->RowCount=1;
    if(comServer->RecordCount > 0)
     for (i=0;i<comServer->ItemCount;i++)
     {
        comServer->LocateItemByIndex(i);
        RefreshGridData(0);
     }
}
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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