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

📄 cmhdl.cpp

📁 科思ERP部分源码及控件
💻 CPP
📖 第 1 页 / 共 5 页
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstoFp
#define _YW_SDERP_DLL
#include "Cmhdl.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
//====================================================
//         (TKSCd)  成本初始化
//====================================================
TKSCd::TKSCd(TDataComm *DC)
:TKSStandard(DC)
{
   try
   {
      EmptyValue(0);
      EmptyValue(1);
      QueryString="SELECT cdfmonth,cdgoods,cdgoodsname=goodsname,CdpmpcCode=goodspmpcCode,cdBopprice,cdBopqty=stockbopqty,cdbopamt,CdInitFlg FROM Sdcd,sdgoods,sdstock";
      FilterString="";
      OrderString=" cdfmonth,cdgoods";
    }
    catch(...)
    {
       throw Exception("构造函数出错!");
    };
}
//------------------------------------------------------------------------------
TKSCd::TKSCd()
:TKSStandard()
{
   try
   {
      EmptyValue(0);
      EmptyValue(1);
      QueryString="SELECT cdfmonth,cdgoods,cdgoodsname=goodsname,CdpmpcCode=goodspmpcCode,cdBopprice,cdBopqty=stockbopqty,cdbopamt,CdInitFlg FROM Sdcd,sdgoods,sdstock";
      FilterString="";
      OrderString=" cdfmonth,cdgoods";
    }
    catch(...)
    {
       throw Exception("构造函数出错!");
    };
}
//------------------------------------------------------------------------------
void __fastcall TKSCd::SetCdFmonth(AnsiString value)
{
    AnsiString s;
    if(value.IsEmpty())
      throw Exception("财务月份不能为空");
    if(value!=l_CdFmonth)
    {
      l_Query->Close();
      l_Query->SQL->Clear();
      l_Query->SQL->Add("select fcmonth from sdfc where fcmonth='"+value+"'");
      l_Query->Open();
      if(l_Query->RecordCount<=0)
      {
        l_Query->Close();
        throw Exception("财务月份:"+value+"未定义");
      }
      l_Query->Close();
      l_Query->SQL->Clear();
      l_Query->SQL->Add("select fcmonth from sdfc where fccurrent=1");
      l_Query->Open();
      if(l_Query->RecordCount<=0)
      {
        l_Query->Close();
        throw Exception("未定义当前财务月份");
      }
      s=l_Query->FieldValues["FcMonth"];
      if(value<s)
      {
        l_Query->Close();
        throw Exception("财务月份不能小于当前月份");
      }
      l_Query->Close();
    }
    l_CdFmonth =   value;
}
void __fastcall TKSCd::SetCdGoods(AnsiString value)
{
    if(value.IsEmpty())
      throw Exception("物料编码不能为空");
    if(value.Length()>18)
      throw Exception("物料编码长度不能大于18");
    if(value!=l_CdGoods)
    {
      l_Query->Close();
      l_Query->SQL->Clear();
      l_Query->SQL->Add("select goodsName from sdgoods where goodsCode='"+value+"'");
      l_Query->Open();
      if(l_Query->RecordCount<=0)
      {
        l_Query->Close();
        throw Exception("物料编码 "+value+"未定义");
      }
      l_Query->Close();
    }
    l_CdGoods=value;
}
void __fastcall TKSCd::SetCdBopPrice(double value)
{
    if(value<0)
      throw Exception("期初单价不能小于零");
    l_CdBopPrice=value;
}
void __fastcall TKSCd::SetCdBopAmt(double value)
{
    if(value<0)
      throw Exception("期初金额不能小于零");
    l_CdBopAmt=value;
}
void __fastcall TKSCd::SetCdInitFlg(int value)
{
    if(value!=0 && value!=1)
      throw Exception("初始化标志只能取值0-未初始化1-已初始化");
    l_CdInitFlg=value;
}

void  TKSCd::SetFieldValue(euCd sdFieldName, AnsiString value)
{
    switch(sdFieldName)
    {
      case fiCdFmonth:
         CdFmonth=value;
         break;
      case fiCdGoods:
         CdGoods=value;
        break;
      case fiCdBopPrice:
        CdBopPrice=value.ToDouble();
        break;
      case fiCdBopAmt:
        CdBopAmt=value.ToDouble();
        break;
      case fiCdInitFlg:
        CdInitFlg=value.ToInt();
        break;
    default:
         throw Exception("当前字段未定义可赋值");
    }
}
//------------------------------------------------------------------------------
AnsiString TKSCd::GetFieldValue(euCd sdFieldName)
{
    switch(sdFieldName)
    {
      case fiCdFmonth:
        return CdFmonth;
      case fiCdGoods:
        return CdGoods;
      case fiCdGoodsName:
        return CdGoodsName;
      case fiCdPmpcCode:
        return CdPmpcCode;
      case fiCdBopPrice:
        return CdBopPrice;
      case fiCdBopQty:
        return CdBopQty;
      case fiCdBopAmt:
        return CdBopAmt;
      case fiCdInitFlg:
        return CdInitFlg;
      default:
           throw Exception("当前未定义可取值");
    }
}
//------------------------------------------------------------------------------
void TKSCd::BackupValue()
{
    b_CdFmonth=l_CdFmonth;
    b_CdGoods=l_CdGoods;
    b_CdGoodsName=l_CdGoodsName;
    b_CdPmpcCode=l_CdPmpcCode;
    b_CdBopPrice=l_CdBopPrice;
    b_CdBopQty=l_CdBopQty;
    b_CdBopAmt=l_CdBopAmt;
    b_CdInitFlg=l_CdInitFlg;
}
//------------------------------------------------------------------------------
void TKSCd::RestoreValue()
{
    l_CdFmonth=b_CdFmonth;
    l_CdGoods=b_CdGoods;
    l_CdGoodsName=b_CdGoodsName;
    l_CdPmpcCode=b_CdPmpcCode;
    l_CdBopPrice=b_CdBopPrice;
    l_CdBopQty=b_CdBopQty;
    l_CdBopAmt=b_CdBopAmt;
    l_CdInitFlg=b_CdInitFlg;
}
//------------------------------------------------------------------------------
void TKSCd::EmptyValue(int Index)
{
    switch (Index)
    {
      case 0:
          l_CdFmonth="";
          l_CdGoods="";
          l_CdGoodsName="";
          l_CdPmpcCode="";
          l_CdBopPrice=0;
          l_CdBopQty=0;
          l_CdBopAmt=0;
          l_CdInitFlg=0;
        break;
      case 1:
          b_CdFmonth="";
          b_CdGoods="";
          b_CdGoodsName="";
          b_CdPmpcCode="";
          b_CdBopPrice=0;
          b_CdBopQty=0;
          b_CdBopAmt=0;
          b_CdInitFlg=0;
        }
}
//------------------------------------------------------------------------------
void TKSCd::BatchLetValue()
{
    l_CdFmonth=l_Query->FieldValues["Cdfmonth"];
    l_CdGoods=l_Query->FieldValues["CdGoods"];
    l_CdGoodsName=l_Query->FieldValues["CdGoodsName"];
    l_CdPmpcCode=l_Query->FieldValues["cdpmpcCode"];
    l_CdBopPrice=l_Query->FieldValues["CdBopPrice"];
    l_CdBopQty=l_Query->FieldValues["CdBopQty"];
    l_CdBopAmt=l_Query->FieldValues["CdBopAmt"];
    l_CdInitFlg=l_Query->FieldValues["cdInitFlg"];
    BackupValue();
}
//------------------------------------------------------------------------------
void TKSCd::Assign(TKSCd *p)
{
    this->SetActionID(p->CurStatus);
    this->l_CdFmonth=p->l_CdFmonth;
    this->l_CdGoods=p->l_CdGoods;
    this->l_CdGoodsName=p->l_CdGoodsName;
    this->l_CdPmpcCode=p->l_CdPmpcCode;
    this->l_CdBopPrice=p->l_CdBopPrice;
    this->l_CdBopQty=p->CdBopQty;
    this->l_CdBopAmt=p->l_CdBopAmt;
    this->l_CdInitFlg=p->l_CdInitFlg;
    this->BackupValue();
}
//------------------------------------------------------------------------------
void TKSCd:: AssignValue()
{
    TKSCd *p=(TKSCd *)Records(CurRecNo);
    Assign(p);
}
//------------------------------------------------------------------------------
int TKSCd::Query()
{
    AnsiString l_SqlStr;
    l_SqlStr=QueryString;
    if(FilterString.IsEmpty()==false)
        l_SqlStr=l_SqlStr+" where goodscode=Stockgoodscode and goodscode=cdgoods and "+FilterString;
    else
        l_SqlStr=l_SqlStr+" where goodscode=stockgoodscode and cdgoods=goodscode ";
    if(OrderString.IsEmpty()==false)
        l_SqlStr=l_SqlStr+" Order by "+OrderString;
    l_Query->Close();
    l_Query->SQL->Clear();
    l_Query->SQL->Add(l_SqlStr);
    l_Query->Open();
    ClearRecord();
    if(l_Query->RecordCount>0)
    {
          l_Query->First();
          while(!l_Query->Eof)
          {
            BatchLetValue();
            TKSCd *p=new TKSCd();
            SetActionID(1);
            p->Assign(this);
            AddRecord((void *)p,p->CdGoods);
            l_Query->Next();
          }
          MoveFirst();
    }
    l_Query->Close();
    return Count;
}
//------------------------------------------------------------------------------
bool TKSCd::Find(AnsiString WhereStr)
{
    AnsiString l_SqlStr;
    if(WhereStr.IsEmpty()==true)
        throw Exception("查找表达式不能为空");
    l_SqlStr="SELECT * FROM sdCd WHERE "+WhereStr;
    l_Query->Close();
    l_Query->SQL->Clear();
    l_Query->SQL->Add(l_SqlStr);
    l_Query->Open();
    if(l_Query->RecordCount!=1)
    {
        l_Query->Close();
        return false;
    }
    else
    {
        BatchLetValue();
        l_Query->Close();
        return true;
    }
}
//------------------------------------------------------------------------------
void TKSCd::Update()
{
    if(CurStatus==0||CurStatus==1)
        throw Exception("当前不是编辑状态,不能进行存盘操作!");
    l_StoredProc->Close();
    l_StoredProc->ProcedureName="sdCd_InitInv";
    l_StoredProc->Parameters->Clear();
    l_StoredProc->Parameters->CreateParameter("@CdFmonth",ftString,pdInput,6,l_CdFmonth);
    l_StoredProc->Parameters->CreateParameter("@CdGoods",ftString,pdInput,18,l_CdGoods);
    l_StoredProc->Parameters->CreateParameter("@CdBopPrice",ftFloat,pdInput,12,l_CdBopPrice);
    l_StoredProc->Parameters->CreateParameter("@CdBopAmt",ftFloat,pdInput,12,l_CdBopAmt);
    l_StoredProc->ExecProc();
    l_StoredProc->Close();

    TKSCd *p=new TKSCd();
    SetActionID(1);
    p->Assign(this);
    ChangeRecord((void *)p,p->CdGoods,this->b_CdGoods);
}
//------------------------------------------------------------------------------
void TKSCd::Delete()
{
    //没有删除功能
}

TKSCd::~TKSCd()
{
    try
    {
    }
    catch(...)
    {
       throw Exception("析构函数出错!");
    }
}
//=============================================
//		(TKSAdjCoh)入库调整单
//=============================================
void __fastcall TKSAdjCoh:: SetAdjCohCode(AnsiString value)
{
    if(value.IsEmpty())
        throw Exception("调整单号不能为空");
    if(value.Length()>18)
        throw Exception("调整单号长度不能超过18");
    if(value!=l_AdjCohCode)
    {
        l_Query->Close();
        l_Query->SQL->Clear();
        l_Query->SQL->Add("SELECT AdjcohCODE FROM SDadjcoh WHERE AdjcohCODE='" +value+"'");
        l_Query->Open();
        if(l_Query->RecordCount>0)
        {
            l_Query->Close();
            throw Exception("调整单号'"+value+"'未定义");
        }
        l_Query->Close();
    }
    l_AdjCohCode=value;
}
void __fastcall TKSAdjCoh:: SetAdjCohDate(AnsiString value)
{
    if (value.IsEmpty())
      throw Exception("调整日期不能为空");
    if(value.Length()>10)
      throw Exception("调整日期长度不能超过10");
    l_AdjCohDate=Validate(value);
}
void __fastcall TKSAdjCoh:: SetAdjCohFmonth(AnsiString value)
{
    if(value.IsEmpty()==true)
      throw Exception("财务月份不能为空");
    if(value.Length()>8)
      throw Exception("财务月份长度不能超过8");
    if (value!=l_AdjCohFmonth)
    {
      l_Query->Close();
      l_Query->SQL->Clear();
      l_Query->SQL->Add("SELECT Fcmonth FROM sdFc Where Fcmonth='"+value+"'");
      l_Query->Open();
      if(l_Query->RecordCount<=0)
      {
        l_Query->Close();
        throw Exception("财务月份 "+value+" 未定义");
      }
     l_Query->Close();
    }
    l_AdjCohFmonth=value;
}
void __fastcall TKSAdjCoh:: SetAdjCohPosType(AnsiString value)
{
    if (value.IsEmpty())
      throw Exception("收发类型编码不能为空");
    if(value.Length()>18)
      throw Exception("收发类型编码长度不能超过18");
    if (value!=l_AdjCohPosType)
    {
      l_Query->Close();
      l_Query->SQL->Clear();
      l_Query->SQL->Add("select postypecode from sdpostype where postypecode='"+value+"'");
      l_Query->Open();

⌨️ 快捷键说明

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