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

📄 mrp_enter_freepassmo.pas

📁 一个MRPII系统源代码版本
💻 PAS
📖 第 1 页 / 共 5 页
字号:
  Abort;
end;

procedure TFrm_Mrp_Enter_FreePassMo.Act_LookExecute(Sender: TObject);
begin
  inherited;
  if AdoQry_Head.RecordCount>0 then
 if  Frm_Mrp_Enter_MoSsParent=nil then
 begin
  Frm_Mrp_Enter_MoSsParent:=TFrm_Mrp_Enter_MoSsParent.Create(Self);
  Frm_Mrp_Enter_MoSsParent.SetSysParam(userCode,ModuleCode,menuid,formatdatetime('yyyy.mm.dd',now));
  Frm_Mrp_Enter_MoSsParent.ItemCode:=AdoQry_Head.fieldbyname('ItemCode').asstring;
  tmplowPmCode:=getPmCode(AdoQry_Head.fieldbyname('ItemCode').asstring);
  Frm_Mrp_Enter_MoSsParent.Qclt:=getQclt(AdoQry_Head.fieldbyname('ItemCode').asstring);
  Frm_Mrp_Enter_MoSsParent.duedate:=datetimetostr(AdoQry_Head.fieldbyname('MoLinedate').asdatetime);
  Frm_Mrp_Enter_MoSsParent.strpath:=AdoQry_Head.fieldbyname('ItemCode').asstring+',';
  Frm_Mrp_Enter_MoSsParent.InitForm(dbconnect,True);
 end
 else  Frm_Mrp_Enter_MoSsParent.Show;
end;

procedure TFrm_Mrp_Enter_FreePassMo.Act_DeleteExecute(Sender: TObject);
 var SqlText,BookMArk:String;
  I:Integer;
begin
  inherited;
  If AdoQry_Head.RecordCount=0 Then
    Abort;
  BookMArk:=AdoQry_Head.BookmArk;
  If DispInfo('确认删除选定生产订单吗?',2)='y' Then
  begin
    DbConnect.beginTrans;
          AdoQry_Head.First;
      while not AdoQry_Head.Eof do
       begin
        if (AdoQry_Head.fieldbyname('MoLineCheck').AsInteger=1) And (AdoQry_Head.fieldbyname('MoLineStatus').AsInteger<>5) then
           begin
             if dbconnect.InTransaction then
               dbconnect.RollBackTrans;
             DispInfo(AdoQry_Head.fieldbyname('mono').asstring+'--'+inttostr(AdoQry_Head.fieldbyname('MoLineno').asinteger)+'行状态不是准备状态,不可删除!',3);
             abort;
           end;
     if (AdoQry_Head.fieldbyname('MoLineCheck').AsInteger=1) And (AdoQry_Head.fieldbyname('byProduct').AsInteger=1) then
           begin
             if dbconnect.InTransaction then
               dbconnect.RollBackTrans;
             DispInfo(AdoQry_Head.fieldbyname('mono').asstring+'--'+inttostr(AdoQry_Head.fieldbyname('MoLineno').asinteger)+'行是副产品,不可删除!',3);
             abort;
           end;

        AdoQry_Head.Next;
       end;

    I:=1;
    Try
      AdoQry_Head.First;
      While Not AdoQry_Head.Eof Do
        If (AdoQry_Head.fieldbyname('MoLineCheck').AsInteger=1) And (AdoQry_Head.fieldbyname('MoLineStatus').AsInteger=5) Then
        begin
          sqltext:='select * from MoLine where MoLinestatus=5 '
                    +'and MoNo='''+AdoQry_Head.fieldbyname('MoNo').AsString+''''
                  +' And MoLineNo='''+IntToStr(AdoQry_Head.fieldbyname('MoLineNo').AsInteger)+'''';
           AdoQry_Tmp.Close;
          AdoQry_Tmp.SQL.Text:=SqlText;
          AdoQry_tmp.open;
          if AdoQry_tmp.RecordCount=0 then
            begin
             AdoQry_Head.Next;
             continue;
            end;

          sqltext:='delete from mnItemList'
                  +' where mono='+quotedstr(AdoQry_Head.fieldbyname('MoNo').asstring)
                  +' and MoLineNo='+inttostr(AdoQry_Head.fieldbyname('MoLineNo').asinteger);
             AdoQry_Tmp.Close;
          AdoQry_Tmp.SQL.Text:=SqlText;
          AdoQry_tmp.ExecSQL;
          saveMoLineHistory(dbconnect,AdoQry_Head.fieldbyname('mono').asstring,AdoQry_Head.fieldbyname('MoLineno').asinteger,userCode,2);
          SqlText:=' select * From MoLine '
                  +' Where MoNo='''+AdoQry_Head.fieldbyname('MoNo').AsString+''''
                  +' And ParentMoLineNo='''+IntToStr(AdoQry_Head.fieldbyname('MoLineNo').AsInteger)+''''
                  +' and byProduct=1';
          AdoQry_Tmp.Close;
          AdoQry_Tmp.SQL.Text:=SqlText;
          AdoQry_tmp.open;
          AdoQry_tmp.First;
          while not AdoQry_tmp.Eof do
           begin
            saveMoLineHistory(dbconnect,AdoQry_tmp.fieldbyname('mono').asstring,AdoQry_tmp.fieldbyname('MoLineno').asinteger,userCode,2);
            AdoQry_tmp.next;
           end;

          SqlText:=' delete From MoLine '
                  +' Where MoNo='''+AdoQry_Head.fieldbyname('MoNo').AsString+''''
                  +' And ParentMoLineNo='''+IntToStr(AdoQry_Head.fieldbyname('MoLineNo').AsInteger)+''''
                  +' and byProduct=1';
          AdoQry_Tmp.Close;
          AdoQry_Tmp.SQL.Text:=SqlText;
          AdoQry_tmp.ExecSQL;

          SqlText:=' delete From MoLine '
                  +' Where MoNo='''+AdoQry_Head.fieldbyname('MoNo').AsString+''''
                  +' And MoLineNo='''+IntToStr(AdoQry_Head.fieldbyname('MoLineNo').AsInteger)+''''
                  +' And MoLineStatus=5 ';
          AdoQry_Tmp.Close;
          AdoQry_Tmp.SQL.Text:=SqlText;
          AdoQry_tmp.ExecSQL;
          savemohistory(dbconnect,AdoQry_Head.fieldbyname('mono').asstring,userCode,2);
          SqlText:=' delete from  Mo '
                  +' Where MoNo='''+AdoQry_Head.fieldbyname('MoNo').AsString+''''
                  +' And not exists(select * from MoLine where  MoNo='''+AdoQry_Head.fieldbyname('MoNo').AsString+''''+')';
          AdoQry_Tmp.Close;
          AdoQry_Tmp.SQL.Text:=SqlText;
          AdoQry_tmp.ExecSQL;
          AdoQry_Head.delete;
          I:=I+1;
        end
        Else
        begin
          I:=I+1;
          AdoQry_Head.Next;
        end;
      DbConnect.CommitTrans;
    Except
      If DbConnect.InTransaction Then
        DbConnect.RollBackTrans;
      DispInfo('删除订单时发生错误,订单未删除,请重试!',1);
      AdoQry_Head.BookMArk:=BookmArk;
      Abort;
    end;
  end;
  AdoQry_Head.ReQuery;
 // if ((AdoQry_Head.RecordCount>0) and (not AdoQry_Head.Eof)) then
 try
  AdoQry_Head.BookMArk:=BookmArk;
 except
 end;

end;


function TFrm_Mrp_Enter_FreePassMo.getPmCode(ItemCode: string): integer;
begin
try
 Executesql(AdoQry_tmp,'select PmCode from Item where ItemCode='+quotedstr(ItemCode),0);
 Result:=AdoQry_tmp.fieldbyname('PmCode').asinteger;
except
 Result:=255;
end;
end;

function TFrm_Mrp_Enter_FreePassMo.getQclt(ItemCode: string): string;
begin
try
 Executesql(AdoQry_tmp,'select Qclt from Item where ItemCode='+quotedstr(ItemCode),0);
 Result:=inttostr(AdoQry_tmp.fieldbyname('Qclt').asinteger);
except
 Result:='9999999';
end;
end;

procedure TFrm_Mrp_Enter_FreePassMo.AdoQry_HeadBeforeEdit(
  DataSet: TDataSet);
begin
  inherited;
  if AdoQry_Head.fieldbyname('byProduct').asinteger=1 then
    begin
     DispInfo('这行是副产品,不能执行选定操作!',3);
     abort;
    end;
end;

function TFrm_Mrp_Enter_FreePassMo.checkCurrentonhandInv(mono: string;
  MoLineno: integer; var haveInv: integer; var strWhName: string): boolean;
var AdoQry:TAdoQuery;
    sqltext:string;
begin
  Result:=False;
  AdoQry:=TAdoQuery.Create(self);
  AdoQry.Connection:=dbconnect;
try
  sqltext:='Select ItemCode,Sum(MoCtrlQty) As MOCtrlQty  '
           +'  into #themnItemList '
           +'              From MNItemList     '
           +'              Where MoNO='+quotedstr(mono)
           +'                and MoLineno='+inttostr(MoLineno)
           +'              Group By ItemCode ';
  Executesql(AdoQry,sqltext,1);
  sqltext:='Select Item.ItemCode,(Item.CurrentOnHandInv-Item.BackFlushAllocInv)-#theMNItemList.MoCtrlQty As ReMainInv '
           +'   From Item       '
           +' Join #theMNItemList On Item.ItemCode=#theMNItemList.ItemCode   '
     +'  Where (Item.CurrentOnHandInv-Item.BackFlushAllocInv)<#theMNItemList.MoCtrlQty ';
  Executesql(AdoQry,sqltext,0);
  if AdoQry.RecordCount>0 then
   begin
    haveInv:=0;
    exit;
   end;

   sqltext:= 'Select CurrentInv.ItemCode,Sum(OnHandInv) As OnHandInv  '
             +'  into #tmpCurrentInv  '
             +'   From CurrentInv                                       '
             +'  Where CurrentInv.WHCode In (Select WHCode              '
             +'                             From WhPosition             '
             +'                             Where BackFlushWHP=1 And WhPositionType=0 And DeptCode='+quotedstr(getDeptCode(mono))+') '
             +'  Group By ItemCode ';
   Executesql(AdoQry,sqltext,1);

   sqltext:='Select Distinct WhPosition.WHCode,Warehouse.WHName  '
            +'    From WhPosition                                  '
            +'     Join Warehouse On WhPosition.WHCode=Warehouse.WHCode  '
            +'  Where WhPosition.WHCode In (Select Distinct WHCode      '
            +'                   From CurrentInv                       '
            +'                   Where ItemCode IN (select #themnItemList.ItemCode from #themnItemList '
                                                   +'  join #tmpCurrentInv '
                                                    +'   on  #themnItemList.ItemCode=#tmpCurrentInv.ItemCode '
                                                    +'   and #themnItemList.moCtrlqty>#tmpCurrentInv.onhandInv)        '
            +'                         And OnHandInv>0 )  '
            +' And WhPosition.WHCode Not IN (Select Distinct WHCode       '
            +'                                       From WhPosition      '
            +'                                       Where BackFlushWHP=1 And WhPositionType=0 And DeptCode='+quotedstr(getDeptCode(mono))+') ';
   Executesql(AdoQry,sqltext,0);
   if AdoQry.RecordCount>0 then
     begin
       strWHName:=AdoQry.fieldbyname('whName').asstring;
       exit;
     end;
   haveInv:=1;
   Result:=True;
finally
 try
 Executesql(AdoQry,'drop table #themnItemList,#tmpCurrentInv',1);
 except
 end;
 AdoQry.Free;
end;
end;

function TFrm_Mrp_Enter_FreePassMo.existssonItem(ItemCode:string):boolean;
var sqltext:string;
    AdoQry:TAdoQuery;
begin
 Result:=True;
 SqlText:=' Select * From Bom '
         +' Where ite_ItemCode='+quotedstr(ItemCode)
         +' And Bomstatus in (0,2)';
 AdoQry:=TAdoQuery.Create(self);
  AdoQry.Connection:=dbconnect;
 try
 AdoQry.Close;
 AdoQry.SQL.Text:=SqlText;
 AdoQry.Open;
 if AdoQry.RecordCount=0 then Result:=False;
 finally
 AdoQry.Free;
 end;

end;


function TFrm_Mrp_Enter_FreePassMo.existsnoPassmo(mono: string;
  MoLineno: integer): boolean;
var sqltext:string;
    AdoQry:TAdoQuery;
begin
 Result:=True;
 SqlText:=' Select * From MoLine '
         +' Where MoNo='''+mono+''''
         +' And MoLineNo='''+IntToStr(MoLineno)+''''
         +' And MoLineStatus=5 ';
 AdoQry:=TAdoQuery.Create(self);
  AdoQry.Connection:=dbconnect;
 try
 AdoQry.Close;
 AdoQry.SQL.Text:=SqlText;
 AdoQry.Open;
 if AdoQry.RecordCount=0 then Result:=False
 else isBackflush:=AdoQry.fieldbyname('Backflush').asinteger;
 finally
 AdoQry.Free;
 end;
end;

function TFrm_Mrp_Enter_FreePassMo.getDeptCode(mono: string): string;
var AdoQry:TAdoQuery;
    sqltext:string;
begin
  Result:='';
  AdoQry:=TAdoQuery.Create(self);
  AdoQry.Connection:=dbconnect;
  sqltext:='select DeptCode from mo where mono='+quotedstr(mono);
  try
    Executesql(AdoQry,sqltext,0);
    Result:=AdoQry.fieldbyname('DeptCode').asstring;
  finally
    AdoQry.Free;
  end;
end;

procedure TFrm_Mrp_Enter_FreePassMo.PassbyProduct;
var    tmpbeforeedit:Tdatasetnotifyevent;
begin

⌨️ 快捷键说明

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