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

📄 mfcd.cpp

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

TfrmMfcd  *frmMfcd;
//--------------------------------------------------------------------------
__fastcall TfrmMfcd::TfrmMfcd(TComponent* Owner)
                   : TStdBaseForm(Owner)
{
   btnOK->Enabled = false;
}
//--------------------------------------------------------------------------

void __fastcall TfrmMfcd::btnOKClick(TObject *Sender)
{
  AnsiString sMemo;
  int ErrNum;
  try
  {
    StartWaitForm("正在生成费用分摊明细,请稍候......");
    if(sgMfcd->RowCount>1)
    {
     int j;
     j=comServer->ItemCount-1;
     if(j>=0)
     {
        comServer->LocateItemByIndex(j);
        j=StrToInt(GetDetailValue(fiMfcdLine));
        j=j+1;
     }
     else
        j=1;
     try
     {
       for(int i=1;i<sgMfcd->RowCount;i++)
       {
           if(sgMfcd->Cells[0][i]=="√")
           {
               comServer->AddItem();
               SetDetailValue(fiMfcdCode,frmMfch->seMfchCode->Text);
               SetDetailValue(fiMfcdLine,IntToStr(j));
               SetDetailValue(fiMfcdWoCode,sgMfcd->Cells[1][i]);
               if(sgMfcd->Cells[6][i] == "")
                throw Exception("请输入费用类型");
               SetDetailValue(fiMfcdExpense,sgMfcd->Cells[6][i]);
               if(sgMfcd->Cells[7][i] == "")
                throw Exception("请输入分摊费用");
               SetDetailValue(fiMfcdAmt,sgMfcd->Cells[7][i]);
               SetDetailValue(fiMfcdState,"2");
               SetDetailValue(fiMfcdDesc,"");
               try{
                  comServer->AddToObject();
               }
               catch(Exception &e)
               {
                  throw Exception(e.Message);
               }
               j=j+1;
           }
       }
     }
     catch(Exception &e)
     {
      comServer->Cancel();
      this->ModalResult=0;
      throw Exception(e.Message);
     }
    }
  }
  __finally
  {
    EndWaitForm();
  }
  Close();
}
//---------------------------------------------------------------------------
void __fastcall TfrmMfcd::btnCancelClick(TObject *Sender)
{
    Close();
}
//---------------------------------------------------------------------------
void __fastcall TfrmMfcd::FormShow(TObject *Sender)
{
    InitControlGroup();
}
//---------------------------------------------------------------------------
void __fastcall TfrmMfcd::InitControlGroup()
{
    sgMfcd->RowCount = 1;
    deBegDate->Text="";
    deEndDate->Text="";
}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmMfcd::GetSqlString()
{
    AnsiString  s_SQL,s_Temp;
    s_SQL =" select WoCode,WoDate,WoGoods,GoodsName,WoQty from sdWo,sdGoods ";
    s_SQL+=" where WoGoods=GoodsCode and WoCheck=1 ";
    s_Temp="";
    if(deBegDate->Text != "")
     s_Temp+=" and WoDate >='"+deBegDate->Text+"'";
    if(deEndDate->Text != "")
     s_Temp+=" and WoDate <='"+deEndDate->Text+"'";
    s_SQL+=s_Temp;
    s_SQL+=" order by WoCode ";
    return(s_SQL);
}
//---------------------------------------------------------------------------

void __fastcall TfrmMfcd::FillGridWithData()
{
    AnsiString  ItemStr,s_SQL;
    s_SQL =GetSqlString();
    sgMfcd->RowCount=1;
    TComResultSet *RsMfcd;
    RsMfcd=NewResultSet();
    RsMfcd->Open(s_SQL,"");
    while(RsMfcd->Eof == 0)
    {
     ItemStr = AnsiString("") +
               "\t"+RsMfcd->FieldByName("WoCode")+
               "\t"+RsMfcd->FieldByName("WoDate")+
               "\t"+RsMfcd->FieldByName("WoGoods")+
               "\t"+RsMfcd->FieldByName("GoodsName")+
               "\t"+RsMfcd->FieldByName("WoQty")+
               "\t"+RsMfcd->FieldByName("")+
               "\t"+RsMfcd->FieldByName("0");

     sgMfcd->AddItem(ItemStr);
     RsMfcd->MoveNext();
    }
    RsMfcd->Close();
    delete RsMfcd;
}
//---------------------------------------------------------------------------
void __fastcall TfrmMfcd::GetComObject(TComServer *comServerPtr)
{
    comServer = comServerPtr;
}
//---------------------------------------------------------------------------
void __fastcall TfrmMfcd::SetDetailValue(int Index,AnsiString Value)
{
     WriteItemValue(comServer,Index,Value);
}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmMfcd::GetDetailValue(int Index)
{
     return ReadItemValue(comServer,Index);
}
//---------------------------------------------------------------------------

void __fastcall TfrmMfcd::sgMfcdDblClick(TObject *Sender)
{
    int ARow=sgMfcd->Row;
    int ACol=sgMfcd->Col;
    if (ARow > 0 && ACol == 0)
    {
      if (sgMfcd->Cells[0][ARow] == "√")
      {
       sgMfcd->Cells[0][ARow] =  "";
       for (int i=1;i<sgMfcd->RowCount;i++)
       {
          if(sgMfcd->Cells[0][i]=="√")
          {
             btnOK->Enabled=true;
             break;
          }
          else
             btnOK->Enabled=false;
       }
      }
      else
      {
          sgMfcd->Cells[0][ARow] =  "√";
          btnOK->Enabled = true;
      }
    }
    if(ARow > 0 && ACol == 6 && sgMfcd->Cells[0][ARow] == "√")
    {
      AnsiString SqlStr;
      SqlStr="002[费用类型][费用名称]";
      SqlStr+=" select ExpenseCode,ExpenseName from sdExpense ";
      TfrmWnQuery *p;
      try
      {
        StartWaitForm("正在查询,请稍候...");
        p=new TfrmWnQuery(this,"费用类型查询",SqlStr);
      }
      __finally
      {
        EndWaitForm();
      }
      if(p->ShowModal()==mrOk)
      {
       sgMfcd->Cells[6][ARow]=p->ColData[1];
      }
      delete p;
    }
}
//---------------------------------------------------------------------------

void __fastcall TfrmMfcd::bbQueryClick(TObject *Sender)
{
  FillGridWithData();
}
//---------------------------------------------------------------------------

void __fastcall TfrmMfcd::bbAllClick(TObject *Sender)
{
  if(sgMfcd->RowCount <=1)
    return;
  for(int i=1;i<sgMfcd->RowCount;i++)
    sgMfcd->Cells[0][i] = "√";
  btnOK->Enabled = true;
}
//---------------------------------------------------------------------------

void __fastcall TfrmMfcd::bbNoneClick(TObject *Sender)
{
  for(int i=1;i<sgMfcd->RowCount;i++)
    sgMfcd->Cells[0][i] = " ";
  btnOK->Enabled = false;
}
//---------------------------------------------------------------------------
void __fastcall TfrmMfcd::sgMfcdSelectCell(TObject *Sender, int ACol,
      int ARow, bool &CanSelect)
{
 if(sgMfcd->Cells[0][ARow]=="√")
  sgMfcd->ReadOnly=false;
 else
  sgMfcd->ReadOnly=true;
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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