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

📄 gsp.cpp

📁 速达开源ERP系统
💻 CPP
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#include "Gsp.h"
//---------------------------------------------------------------------------
#pragma hdrstop
#pragma package(smart_init)
#pragma link "fpanel"
#pragma link "RecBaseForm"
#pragma link "SDComboBox"
#pragma link "SDEdit"
#pragma link "SDGrid"
#pragma link "CSPIN"
#pragma link "SDTreeView"
#pragma resource "*.dfm"
TfrmGsp *frmGsp;
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmGsp::GetFieldValue(int FieldIndex)
{
    return  ReadFieldValue(comServer,FieldIndex);
}
//---------------------------------------------------------------------------
void __fastcall TfrmGsp::ClearControl(bool BringToNext)
{
}
//---------------------------------------------------------------------------
void __fastcall TfrmGsp::GetDataFromComObject()
{
}
//---------------------------------------------------------------------------
void __fastcall TfrmGsp::SendDataToComObject()
{
    AnsiString m;
    m=tvGoods->Selected->Text;
    m = m.SubString(2,m.AnsiPos(")")-2);
    WriteFieldValue(comServer,fiGspGoods,WideString(m));
    WriteFieldValue(comServer,fiGspYear,WideString(csGspYear->Text));
    WriteFieldValue(comServer,fiGspFmonth,WideString(sgGsp->TextMatrix[sgGsp->Row][1]));
    WriteFieldValue(comServer,fiGspPQty,WideString(sgGsp->TextMatrix[sgGsp->Row][2]));
    WriteFieldValue(comServer,fiGspPAmt,WideString(sgGsp->TextMatrix[sgGsp->Row][3]));
}
//---------------------------------------------------------------------------
void __fastcall TfrmGsp::WaitUserInput()
{
    sgGsp->SetFocus();
}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmGsp::GetDataToGrid()
{
    AnsiString  s;
    return(s);
}
//---------------------------------------------------------------------------
void __fastcall TfrmGsp::RefreshGridData(int mAction)
{
    AnsiString ItemStr;
    if(mAction ==2)
    {
      sgGsp->TextMatrix[sgGsp->Row][2]="0";
      sgGsp->TextMatrix[sgGsp->Row][3]="0";
    }
    else
    {
      ItemStr="\t" + GetFieldValue(fiGspFmonth)+
              "\t" + GetFieldValue(fiGspPQty)+
              "\t" + GetFieldValue(fiGspPAmt)+
              "\t" + GetFieldValue(fiGspRQty)+
              "\t" + GetFieldValue(fiGspRAmt);
      sgGsp->ChangeItem(ItemStr,sgGsp->Row);
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmGsp::FillGridWithData()
{
    AnsiString ItemStr;
    int iRow=0;
    sgGsp->RowCount=1;
    for(int i=1;i<13;i++)
    {
      if(i<10)
        sgGsp->AddItem("\t"+csGspYear->Text+"0"+IntToStr(i)+"\t0\t0\t0\t0");
      else
        sgGsp->AddItem("\t"+csGspYear->Text+IntToStr(i)+"\t0\t0\t0\t0");
    }
    comServer->MoveFirst();
    while (comServer->Eof==0)
    {
      ItemStr=GetFieldValue(fiGspFmonth);
      ItemStr=ItemStr.SubString(5,2);
      iRow=ItemStr.ToInt();
      ItemStr="\t" + GetFieldValue(fiGspFmonth)+
              "\t" + GetFieldValue(fiGspPQty)+
              "\t" + GetFieldValue(fiGspPAmt)+
              "\t" + GetFieldValue(fiGspRQty)+
              "\t" + GetFieldValue(fiGspRAmt);
       sgGsp->ChangeItem(ItemStr,iRow);
       comServer->MoveNext();
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmGsp::InitEditControl()
{
    ClientGroup->AddComponent(2,true,true,false, FloatPanel2,FloatPanel2->Name);
    ClientGroup->AddComponent(2,true,true,false, Panel1,Panel1->Name);
}
//---------------------------------------------------------------------------
__fastcall TfrmGsp::TfrmGsp(TComponent* Owner)
    : TRecBaseForm(Owner,euSdGsp,"")
{
}
//---------------------------------------------------------------------------
void __fastcall TfrmGsp::SetGoodsValue(AnsiString value)
{
    if(FGoodsValue!=value)
       FGoodsValue=value;
}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmGsp::GetGoodsValue()
{
    return FGoodsValue;
}
//---------------------------------------------------------------------------
void  __fastcall TfrmGsp::RefreshUpdateData(int MsgSrc,int MsgType)
{
}
//---------------------------------------------------------------------------
void __fastcall TfrmGsp::muSaveClick(TObject *Sender)
{
    AnsiString m;
    m=tvGoods->Selected->Text;
    m = m.SubString(2,m.AnsiPos(")")-2);
    for(int i=1;i<13;i++)
    {
      sgGsp->Row=i;
      if(sgGsp->TextMatrix[i][2].IsEmpty())
        sgGsp->TextMatrix[i][2]="0";
      if(sgGsp->TextMatrix[i][3].IsEmpty())
        sgGsp->TextMatrix[i][3]="0";
      if(comServer->LocateByKey(WideString(m+sgGsp->TextMatrix[i][1])))
      {
         if(sgGsp->TextMatrix[i][3].ToDouble()!=GetFieldValue(fiGspPAmt).ToDouble()||sgGsp->TextMatrix[i][2].ToDouble()!=GetFieldValue(fiGspPQty).ToDouble())
         {
            comServer->Edit();
            SendDataToComObject();
            SaveComObject();
         }
      }
      else
      {
         comServer->AddNew();
         SendDataToComObject();
         SaveComObject();
      }
    }
    SetControlState(caSave);
    FloatPanel2->Enabled=true;
    sgGsp->ReadOnly=true;
    sgGsp->Options>>goEditing;
}
//---------------------------------------------------------------------------
void __fastcall TfrmGsp::tvGoodsChange(TObject *Sender, TTreeNode *Node)
{
   AnsiString m;
   m = Node->Text;
   m = m.SubString(2,m.AnsiPos(")")-2);
   if(tvGoods->Selected->StateIndex != 1)
   {
      GoodsValue="";
      sgGsp->RowCount=1;
      return;
   }
   if(tvGoods->Selected==NULL || Node==tvGoods->Items->Item[0] || tvGoods->Selected->StateIndex!=1)
   {
      GoodsValue="";
      return;
   }
   if((m+csGspYear->Text)!=GoodsValue)
   {
      WideString s;
      s="GspGoods='" +m+"'and GspYear="+csGspYear->Text;
      comServer->FilterString=s;
      comServer->Query();
      FillGridWithData();
      GoodsValue=m+csGspYear->Text;
   }
}
//---------------------------------------------------------------------------
void __fastcall TfrmGsp::csGspYearChange(TObject *Sender)
{
   if(tvGoods->Selected!=NULL)
     tvGoodsChange(Sender,tvGoods->Selected);
}
//---------------------------------------------------------------------------
void __fastcall TfrmGsp::FillGoods(TTreeNode *SelectedPmpcNode)
{
  AnsiString sSQL,sPmpcCode,ItemStr;
  TTreeNode *TempNode;
  long RsErrNum;
  if(SelectedPmpcNode==NULL)
   return;
  SelectedPmpcNode->DeleteChildren();
  sPmpcCode = SelectedPmpcNode->Text;
  sPmpcCode = sPmpcCode.SubString(2,sPmpcCode.AnsiPos(")")-2);
  if(sPmpcCode=="")
   return;
  TComResultSet *RsGoods;
  sSQL=" select goodscode,goodsname from sdgoods where GoodsSale=1 and GoodsCancel=0 and goodspmpccode ='"
      +sPmpcCode+"'";
  try
  {
    RsGoods=NewResultSet();
    RsGoods->Open(WideString(sSQL),WideString(""));
    while( RsGoods->Eof == 0)
    {
      ItemStr="("+RsGoods->FieldByName("GoodsCode")+
              ")"+RsGoods->FieldByName("GoodsName");
      TempNode= tvGoods->Items->AddChild(SelectedPmpcNode,ItemStr);
      TempNode->StateIndex = 1;
      TempNode->SelectedIndex = 1;
      TempNode->Text=ItemStr;
      RsGoods->MoveNext();
    }
  }
  catch(...)
  {
   delete RsGoods;
   throw Exception("查询该类物料时出错!");
  }
  SelectedPmpcNode->Expand(false);
  SelectedPmpcNode->StateIndex=3;
  SelectedPmpcNode->SelectedIndex=3;
}
//---------------------------------------------------------------------------

void __fastcall TfrmGsp::muCancelClick(TObject *Sender)
{
 if(Application->MessageBox("确认要放弃本次操作?","取消对话框",+MB_ICONQUESTION+MB_OKCANCEL)==IDOK)
   {
    SetControlState(caSave);
    FillGridWithData();
    FloatPanel2->Enabled=true;
    sgGsp->ReadOnly=true;
    sgGsp->Options>>goEditing;
    }
}
//---------------------------------------------------------------------------

void __fastcall TfrmGsp::muEditDetailClick(TObject *Sender)
{
    if(tvGoods->Selected->StateIndex != 1)
    {
        ::MessageBox(Handle,"该节点不是物品,不能编辑.","操作错误",MB_OK|MB_ICONSTOP);
        return;
    }
     SetControlState(caEditDetail);
     FloatPanel2->Enabled=false;
     sgGsp->SetFocus();
     sgGsp->ReadOnly=false;
     sgGsp->Options<<goEditing;
}
//---------------------------------------------------------------------------

void __fastcall TfrmGsp::tvGoodsDblClick(TObject *Sender)
{
  if(tvGoods->Selected->StateIndex==1)
     return;
  if(!tvGoods->Selected->HasChildren)
        FillGoods(tvGoods->Selected);
}
//---------------------------------------------------------------------------

void __fastcall TfrmGsp::sgGspSelectCell(TObject *Sender, int ACol,
      int ARow, bool &CanSelect)
{
  if(CurrentState!=caNormal)
  {
  if(sgGsp->Cells[1][ARow]<g_sdSMonth)
    sgGsp->ReadOnly=true;
  else
    sgGsp->ReadOnly=false;
  }
}
//---------------------------------------------------------------------------

void __fastcall TfrmGsp::FormShow(TObject *Sender)
{
   TTreeNode *TempNode[7];
   int mLevel;
   TComResultSet *RsPmpc=NewResultSet();
   try
   {
     tvGoods->Items->Clear();
     TempNode[0]=tvGoods->Items->Add(NULL,"所有的物料");
     TempNode[0]->StateIndex = 0;
     TempNode[0]->SelectedIndex = 0;

     RsPmpc->Open(WideString("select PmpcCode,PmpcName,PmpcLevel,PmpcEnd from sdPmpc order by PmpcCode,PmPcLevel"),WideString(""));
     RsPmpc->MoveFirst();
     while( RsPmpc->Eof == 0 )
     {
        mLevel=RsPmpc->FieldByName("PmpcLevel").ToInt();
        TempNode[mLevel] = tvGoods->Items->AddChild(TempNode[mLevel-1],"(" + RsPmpc->FieldByName("PmpcCode") + ")" +RsPmpc->FieldByName("PmpcName"));
        if(RsPmpc->FieldByName("PmpcEnd")=="1")
        {
         TempNode[mLevel]->StateIndex = 2;
         TempNode[mLevel]->SelectedIndex = 2;
        }
        else
        {
         TempNode[mLevel]->StateIndex = 0;
         TempNode[mLevel]->SelectedIndex = 0;
        }
        TempNode[mLevel]->Text= "(" + RsPmpc->FieldByName("PmpcCode") + ")"+RsPmpc->FieldByName("PmpcName");
        RsPmpc->MoveNext();
     }
     RsPmpc->Close();
     delete RsPmpc;
     TempNode[0]->Expand(false);
     comServer->MoveFirst();
     if(!comServer->Eof)
       FillGridWithData();
   }
   catch(...)
   {
   throw Exception("插入物料分类码时出错");
   }
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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