mAlfh.cpp
Upload User: xgxgxg8
Upload Date: 2007-02-22
Package Size: 6882k
Code Size: 15k
Development Platform:

Delphi

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "mAlfh.h"
  5. //---------------------------------------------------------------------------
  6. #pragma package(smart_init)
  7. TKSAlfh *sdAlfh;
  8. //---------------------------------------------------------------------------
  9. __fastcall TKSAlfh::TKSAlfh()
  10.   :TKSMidBase()
  11. {
  12. }
  13. //---------------------------------------------------------------------------
  14. void __fastcall TKSAlfh::ValidHeadValues()
  15. {
  16.   AnsiString  m_AlfhCode;
  17.    AnsiString  b_AlfhCode;
  18.    m_AlfhCode=GetMasterValue("AlfhCode");
  19.    b_AlfhCode=GetMasterOldValue("AlfhCode");
  20.     if(m_AlfhCode.IsEmpty())
  21.         throw Exception("调拔单编码不能为空!");
  22.     if(m_AlfhCode.Length()>18)
  23.       throw Exception("调拔单号长度不能大于18");
  24.     b_AlfhCode = m_AlfhCode;
  25.    AnsiString  m_AlfhDate;
  26.    m_AlfhDate=GetMasterValue("AlfhDate");
  27.     if(m_AlfhDate.IsEmpty())
  28.       throw Exception("调拔日期不能为空");
  29.    AnsiString  m_AlfhFmonth;
  30.    AnsiString  b_AlfhFmonth;
  31.    m_AlfhFmonth=GetMasterValue("AlfhFmonth");
  32.    b_AlfhFmonth=GetMasterOldValue("AlfhFmonth");
  33. //    AnsiString s;
  34.     if(m_AlfhFmonth.IsEmpty())
  35.       throw Exception("财务月份不能为空");
  36. /*
  37.     if(m_AlfhFmonth!=b_AlfhFmonth)
  38.     {
  39.       Query->Close();
  40.       Query->SQL->Clear();
  41.       Query->SQL->Add("select fcmonth from sdfc where fcmonth='"+m_AlfhFmonth+"'");
  42.       Query->Open();
  43.       if(Query->RecordCount<=0)
  44.       {
  45.         Query->Close();
  46.         throw Exception("财务月份:"+m_AlfhFmonth+"未定义");
  47.       }
  48.       Query->Close();
  49.       Query->SQL->Clear();
  50.       Query->SQL->Add("select fcmonth from sdfc where fccurrent=1");
  51.       Query->Open();
  52.       if(Query->RecordCount<=0)
  53.       {
  54.         Query->Close();
  55.         throw Exception("未定义当前财务月份");
  56.       }
  57.       s=Query->FieldValues["FcMonth"];
  58.       if(m_AlfhFmonth<s)
  59.       {
  60.         Query->Close();
  61.         throw Exception("财务月份不能小于当前月份");
  62.       }
  63.       Query->Close();
  64.     }
  65. */
  66.    AnsiString  m_AlfhPosType;
  67.    AnsiString  b_AlfhPosType;
  68.    m_AlfhPosType=GetMasterValue("AlfhPosType");
  69.    b_AlfhPosType=GetMasterOldValue("AlfhPosType");
  70.     if(m_AlfhPosType.IsEmpty())
  71.       throw Exception("收发存项目编码不能为空");
  72.     if(m_AlfhPosType.Length()>18)
  73.       throw Exception("项目编码长度不能大于18");
  74.     if(m_AlfhPosType!=b_AlfhPosType)
  75.     {
  76.       Query->Close();
  77.       Query->SQL->Clear();
  78.       Query->SQL->Add("select postypecode from sdpostype where postypecode='"+m_AlfhPosType+"'");
  79.       Query->Open();
  80.       if(Query->RecordCount<=0)
  81.       {
  82.         Query->Close();
  83.         throw Exception("收发存项目编码:"+m_AlfhPosType+"未定义");
  84.       }
  85.       Query->Close();
  86.     }
  87.    AnsiString  m_AlfhODept;
  88.    AnsiString  b_AlfhODept;
  89.    m_AlfhODept=GetMasterValue("AlfhODept");
  90.    b_AlfhODept=GetMasterOldValue("AlfhODept");
  91.     if(m_AlfhODept.IsEmpty())
  92.       throw Exception("转出部门编码不能为空");
  93.     if(m_AlfhODept.Length()>18)
  94.       throw Exception("转出部门编码长度不能大于18");
  95.     if(m_AlfhODept!=b_AlfhODept)
  96.     {
  97.       Query->Close();
  98.       Query->SQL->Clear();
  99.       Query->SQL->Add("select deptcode from sddept where deptcode='"+m_AlfhODept+"'");
  100.       Query->Open();
  101.       if(Query->RecordCount<=0)
  102.       {
  103.         Query->Close();
  104.         throw Exception("转出部门编码:"+m_AlfhODept+"未定义");
  105.       }
  106.       Query->Close();
  107.     }
  108.    AnsiString  m_AlfhIDept;
  109.    AnsiString  b_AlfhIDept;
  110.    m_AlfhIDept=GetMasterValue("AlfhIDept");
  111.    b_AlfhIDept=GetMasterOldValue("AlfhIDept");
  112.     if(m_AlfhIDept.IsEmpty())
  113.       throw Exception("转入部门编码不能为空");
  114.     if(m_AlfhIDept.Length()>18)
  115.       throw Exception("转入部门编码长度不能大于18");
  116.     if(m_AlfhIDept!=b_AlfhIDept)
  117.     {
  118.       Query->Close();
  119.       Query->SQL->Clear();
  120.       Query->SQL->Add("select deptcode from sddept where deptcode='"+m_AlfhIDept+"'");
  121.       Query->Open();
  122.       if(Query->RecordCount<=0)
  123.       {
  124.         Query->Close();
  125.         throw Exception("转入部门编码:"+m_AlfhIDept+"未定义");
  126.       }
  127.       Query->Close();
  128.     }
  129.    int m_AlfhType;
  130.    m_AlfhType=GetMasterValue("AlfhType");
  131.     if(m_AlfhType!=1)
  132.       throw Exception("调拔类型只能取值1-库存调拔");
  133.    AnsiString  m_AlfhDesc;
  134.    m_AlfhDesc=GetMasterValue("AlfhDesc");
  135.     if(m_AlfhDesc.Length()>40)
  136.       throw Exception("备注长度不能大于40");
  137.    int m_AlfhCheck;
  138.    m_AlfhCheck=GetMasterValue("AlfhCheck");
  139.     if(m_AlfhCheck!=0 && m_AlfhCheck!=1)
  140.       throw Exception("审核标志只能取值0-未审核1-已审");
  141. /*
  142.    AnsiString  m_AlfhChecker;
  143.    AnsiString  b_AlfhChecker;
  144.    m_AlfhChecker=GetMasterValue("AlfhChecker");
  145.    b_AlfhChecker=GetMasterOldValue("AlfhChecker");
  146.    int  m_AlfhCheck;
  147.    m_AlfhCheck=GetMasterValue("AlfhCheck");
  148.     if(m_AlfhCheck==1)
  149.     {
  150.       if(m_AlfhChecker.IsEmpty())
  151.         throw Exception("审核员代码不能为空");
  152.       if(m_AlfhChecker.Length()>18)
  153.         throw Exception("审核员代码长度不能大于18");
  154.       if(m_AlfhChecker!=b_AlfhChecker)
  155.       {
  156.         Query->Close();
  157.         Query->SQL->Clear();
  158.         Query->SQL->Add("select keepercode from sdkeeper where keepercode='"+m_AlfhChecker+"' and Keepercheck=1");
  159.         Query->Open();
  160.         if(Query->RecordCount<=0)
  161.         {
  162.           Query->Close();
  163.           throw Exception("审核员代码未定义或没有审核权限");
  164.         }
  165.         Query->Close();
  166.       }
  167.     }
  168.     else
  169.       b_AlfhChecker="";
  170. */
  171.    AnsiString  m_AlfhCheckDate;
  172.    m_AlfhCheckDate=GetMasterValue("AlfhCheckDate");
  173.    m_AlfhCheck=GetMasterValue("AlfhCheck");
  174.     if(m_AlfhCheck==1)
  175.     {
  176.       if(m_AlfhCheckDate.IsEmpty())
  177.         throw Exception("审核日期不能为空");
  178.     }
  179.    int m_AlfhInvFlg;
  180.    m_AlfhInvFlg=GetMasterValue("AlfhInvFlg");
  181.     //库存控制不能录入
  182. /*
  183.    AnsiString  m_AlfhUser;
  184.    AnsiString  b_AlfhUser;
  185.    m_AlfhUser=GetMasterValue("AlfhUser");
  186.    b_AlfhUser=GetMasterOldValue("AlfhUser");
  187.     if(m_AlfhUser.IsEmpty())
  188.       throw Exception("操作员代码不能为空");
  189.     if(m_AlfhUser.Length()>18)
  190.       throw Exception("操作员代码长度不能大于18");
  191.     if(m_AlfhUser!=b_AlfhUser)
  192.     {
  193.       Query->Close();
  194.       Query->SQL->Clear();
  195.       Query->SQL->Add("select usercode from sduser where usercode='"+m_AlfhUser+"'");
  196.       Query->Open();
  197.       if(Query->RecordCount<=0)
  198.       {
  199.         Query->Close();
  200.         throw Exception("操作员代码:"+m_AlfhUser+"未定义");
  201.       }
  202.       Query->Close();
  203.     }
  204. */
  205. /*
  206.    AnsiString  m_AlfhKeeper;
  207.    AnsiString  b_AlfhKeeper;
  208.    m_AlfhKeeper=GetMasterValue("AlfhKeeper");
  209.    b_AlfhKeeper=GetMasterOldValue("AlfhKeeper");
  210.     if(m_AlfhKeeper.IsEmpty())
  211.       throw Exception("仓管员代码不能为空");
  212.     if(m_AlfhKeeper.Length()>18)
  213.       throw Exception("仓管员代码长度不能大于18");
  214.     if(m_AlfhKeeper!=b_AlfhKeeper)
  215.     {
  216.       Query->Close();
  217.       Query->SQL->Clear();
  218.       Query->SQL->Add("select keepercode from sdkeeper where keepercode='"+m_AlfhKeeper+"'");
  219.       Query->Open();
  220.       if(Query->RecordCount<=0)
  221.       {
  222.         Query->Close();
  223.         throw Exception("仓管员:"+m_AlfhKeeper+"未定义");
  224.       }
  225.       Query->Close();
  226.     }
  227. */
  228.    int m_AlfhCancel;
  229.    m_AlfhCancel=GetMasterValue("AlfhCancel");
  230.     if(m_AlfhCancel!=0 && m_AlfhCancel!=1)
  231.       throw Exception("取消标志只能取值0-正常 1-取消");
  232.    AnsiString  m_AlfhCancelDate;
  233.    AnsiString  b_AlfhCancelDate;
  234.    m_AlfhCancelDate=GetMasterValue("AlfhCancelDate");
  235.    m_AlfhCancel=GetMasterValue("AlfhCancel");
  236.     if(m_AlfhCancel==1)
  237.     {
  238.       if(m_AlfhCancelDate.IsEmpty())
  239.         throw Exception("取消日期不能为空");
  240.     }
  241. }
  242. //---------------------------------------------------------------------------
  243. void __fastcall TKSAlfh::ValidItemValues()
  244. {
  245.    AnsiString  m_AlfdCode;
  246.    m_AlfdCode=GetDetailValue("AlfdCode");
  247.     if(m_AlfdCode.IsEmpty())
  248.        throw Exception("调拔单号不能为空!");
  249.     if(m_AlfdCode.Length()>18)
  250.       throw Exception("调拔单号长度不能大于18");
  251.    int m_AlfdLine;
  252.    int b_AlfdLine;
  253.    m_AlfdLine=GetDetailValue("AlfdLine");
  254.    b_AlfdLine=GetDetailOldValue("AlfdLine");
  255.     if(m_AlfdLine<=0)
  256.       throw Exception("调拨单行号不能小于等于零");
  257.    /* if(m_AlfdLine !=b_AlfdLine)
  258.      if(FindKey(AnsiString(m_AlfdLine)))         //???????????????????????????
  259.         throw Exception("行号已存在,行号不能重复");    */
  260.    AnsiString  m_AlfdOLoc;
  261.    AnsiString  b_AlfdOLoc;
  262.    m_AlfdOLoc=GetDetailValue("AlfdOLoc");
  263.    b_AlfdOLoc=GetDetailOldValue("AlfdOLoc");
  264.    AnsiString  m_AlfdILoc;
  265.    m_AlfdILoc=GetDetailValue("AlfdILoc");
  266.     if(m_AlfdOLoc.IsEmpty())
  267.       throw Exception("转出货位不能为空");
  268.     if(m_AlfdOLoc.Length()>18)
  269.       throw Exception("转出货位编码长度不能大于18");
  270.     if(m_AlfdOLoc==m_AlfdILoc)
  271.       throw Exception("转出货位不能与转入货位相同");
  272.     if(m_AlfdOLoc!=b_AlfdOLoc)
  273.     {
  274.       Query->Close();
  275.       Query->SQL->Clear();
  276.       Query->SQL->Add("select loccode from sdloc where loccode='"+m_AlfdOLoc+"'");
  277.       Query->Open();
  278.       if(Query->RecordCount<=0)
  279.       {
  280.         Query->Close();
  281.         throw Exception("货位编码:"+m_AlfdOLoc+"未定义");
  282.       }
  283.       Query->Close();
  284.     }
  285.    AnsiString  b_AlfdILoc;
  286.    m_AlfdILoc=GetDetailValue("AlfdILoc");
  287.    b_AlfdILoc=GetDetailOldValue("AlfdILoc");
  288.    m_AlfdOLoc=GetDetailValue("AlfdOLoc");
  289.     if(m_AlfdILoc.IsEmpty())
  290.       throw Exception("转入货位不能为空");
  291.     if(m_AlfdILoc.Length()>18)
  292.       throw Exception("转入货位编码长度不能大于18");
  293.     if(m_AlfdILoc==m_AlfdOLoc)
  294.       throw Exception("转入货位不能与转出货位相同");
  295.     if(m_AlfdILoc!=b_AlfdILoc)
  296.     {
  297.       Query->Close();
  298.       Query->SQL->Clear();
  299.       Query->SQL->Add("select loccode from sdloc where loccode='"+m_AlfdILoc+"'");
  300.       Query->Open();
  301.       if(Query->RecordCount<=0)
  302.       {
  303.         Query->Close();
  304.         throw Exception("货位编码:"+m_AlfdILoc+"未定义");
  305.       }
  306.       Query->Close();
  307.     }
  308.    AnsiString  m_AlfdGoods;
  309.    AnsiString  b_AlfdGoods;
  310.    AnsiString  m_AlfdUnit;
  311.    AnsiString  m_AlfdConv;
  312.    m_AlfdGoods=GetDetailValue("AlfdGoods");
  313.    b_AlfdGoods=GetDetailOldValue("AlfdGoods");
  314.    m_AlfdOLoc=GetDetailValue("AlfdOLoc");
  315.    m_AlfdILoc=GetDetailValue("AlfdILoc");
  316.     if(m_AlfdOLoc.IsEmpty())
  317.       throw Exception("转出货位不能为空");
  318.     if(m_AlfdILoc.IsEmpty())
  319.       throw Exception("转入货位不能为空");
  320.     if(m_AlfdGoods.IsEmpty())
  321.       throw Exception("物料编码不能为空");
  322.     if(m_AlfdGoods.Length()>18)
  323.       throw Exception("物料编码长度不能大于18");
  324.     if(m_AlfdGoods!=b_AlfdGoods)
  325.     {
  326.       Query->Close();
  327.       Query->SQL->Clear();
  328.       Query->SQL->Add(" select goodscode,goodsunitcode from sdgoods,sdlg where lgstate=1  and goodscode=lggoodscode and ");
  329.       Query->SQL->Add(" goodscode='"+m_AlfdGoods+"' and lgloccode='"+m_AlfdOLoc+"'");
  330.       Query->Open();
  331.       if(Query->RecordCount<=0)
  332.       {
  333.         Query->Close();
  334.         throw Exception("物料编码:"+m_AlfdGoods+"无效,或转出货位:"+m_AlfdOLoc+"未定义该物料");
  335.       }
  336.       Query->Close();
  337.       Query->SQL->Clear();
  338.       Query->SQL->Add(" select goodscode,goodsunitcode from sdgoods,sdlg where lgstate=1  and goodscode=lggoodscode and ");
  339.       Query->SQL->Add(" goodscode='"+m_AlfdGoods+"' and lgloccode='"+m_AlfdILoc+"'");
  340.       Query->Open();
  341.       if(Query->RecordCount<=0)
  342.       {
  343.         Query->Close();
  344.         throw Exception("物料编码:"+m_AlfdGoods+"无效,或转入货位:"+m_AlfdILoc+"未定义该物料");
  345.       }
  346.       m_AlfdUnit=Query->FieldValues["goodsunitcode"];
  347.       m_AlfdConv=1;
  348.       Query->Close();
  349.     }
  350.    AnsiString  b_AlfdUnit;
  351.    m_AlfdUnit=GetDetailValue("AlfdUnit");
  352.    b_AlfdUnit=GetDetailOldValue("AlfdUnit");
  353.    m_AlfdGoods=GetDetailValue("AlfdGoods");
  354.     if(m_AlfdGoods.IsEmpty())
  355.       throw Exception("物料编码不能为空");
  356.     if(m_AlfdUnit.IsEmpty())
  357.       throw Exception("计量单位不能为空");
  358.     if(m_AlfdUnit.Length()>18)
  359.       throw Exception("计量单位长度不能大于18");
  360.     Query->Close();
  361.     Query->SQL->Clear();
  362.     if(m_AlfdUnit!=b_AlfdUnit)
  363.     {
  364.       Query->Close();
  365.       Query->SQL->Clear();
  366.       Query->SQL->Add("Select Unitcode from sdUnit where Unitcode='"+m_AlfdUnit+"'");
  367.       Query->Open();
  368.       if(Query->RecordCount<=0)
  369.       {
  370.         Query->Close();
  371.         throw Exception("计量单位:"+m_AlfdUnit+"不存在");
  372.       }
  373.       Query->Close();
  374.     }
  375.   double m_AlfdQty;
  376.    m_AlfdQty=GetDetailValue("AlfdQty");
  377.     if(m_AlfdQty<=0)
  378.       throw Exception("调拨数量必须大于零");
  379.    AnsiString  m_AlfdSBatch;
  380.    AnsiString  b_AlfdSBatch;
  381.    m_AlfdSBatch=GetDetailValue("AlfdSBatch");
  382.    b_AlfdSBatch=GetDetailOldValue("AlfdSBatch");
  383.    m_AlfdOLoc=GetDetailValue("AlfdOLoc");
  384.   
  385.    m_AlfdGoods=GetDetailValue("AlfdGoods");
  386.    m_AlfdQty=GetDetailValue("AlfdQty");
  387.    int IsBatch;
  388.     if(m_AlfdGoods.IsEmpty())
  389.       throw Exception("调拔物料不能为空");
  390.     if(m_AlfdSBatch.Length()>18)
  391.       throw Exception("批号编码长度不能大于18");
  392.         Query->Close();
  393.     Query->SQL->Clear();
  394.     Query->SQL->Add("select GoodsBatch from sdgoods where goodscode='"+m_AlfdGoods+"'");
  395.     Query->Open();
  396.     if(Query->RecordCount<=0)
  397.     {
  398.       Query->Close();
  399.       throw Exception("调拔物料不存在");
  400.     }
  401.     else
  402.     {
  403.       IsBatch=Query->FieldValues["GoodsBatch"];
  404.       Query->Close();
  405.     }
  406.     if(IsBatch==0)
  407.     {
  408.       if(!m_AlfdSBatch.IsEmpty())
  409.         throw Exception("物料:"+m_AlfdGoods+" 不需批次管理");
  410.     }
  411.     if(IsBatch==1&&m_AlfdSBatch.IsEmpty())
  412.     {
  413.         throw Exception("物料:"+m_AlfdGoods+" 需批次管理,必须填上调出批号");
  414.     }
  415.     if(m_AlfdSBatch.IsEmpty()==false && m_AlfdSBatch!=b_AlfdSBatch)
  416.     {
  417.       AnsiString BatchSSql;
  418.       AnsiString CurFmonth;
  419.     //  CurFmonth=GetCurMonth();
  420.     //  AnsiString CurFmonth;
  421.       Query->Close();
  422.       Query->SQL->Clear();
  423.       Query->SQL->Add("select CSCMMONTH from sdcscm where CSCMClASSID='Inventory'");
  424.       Query->Open();
  425.       CurFmonth=Query->FieldValues["CSCMMONTH"];
  426.       Query->Close();
  427.       Query->SQL->Clear();
  428.     // m_Query->SQL->Add("select Batchcode from sdBatch where Batchcode='"+value+"'");
  429.       BatchSSql="select BthtAoyQty from sdBtht where BthtBatch='"+m_AlfdSBatch+"' and BthtFmonth='"+CurFmonth+"' and BthtLoc='"+m_AlfdOLoc+"' and BthtGoods='"+Trim(m_AlfdGoods)+"'";
  430.       Query->SQL->Add(BatchSSql);
  431.       Query->Open();
  432.       if(Query->RecordCount<=0)
  433.       {
  434.         Query->Close();
  435.         throw Exception("批号编码:"+m_AlfdSBatch+"未定义");
  436.       }
  437.       double FQty;
  438.       FQty=Query->FieldValues["BthtAoyQty"];
  439.       if (FQty<m_AlfdQty)
  440.       {
  441.         Query->Close();
  442.         throw Exception("转出货位物料的批次数量不够");
  443.       }  
  444.       Query->Close();
  445.     }
  446.    AnsiString  m_AlfdDesc;
  447.    m_AlfdDesc=GetDetailValue("AlfdDesc");
  448.     if(m_AlfdDesc.Length()>40)
  449.       throw Exception("备注长度不能大于40");
  450. }
  451. //---------------------------------------------------------------------------
  452. void __fastcall TKSAlfh::CmdExec(AnsiString Param)
  453. {
  454. }
  455. //---------------------------------------------------------------------------