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

📄 pm_enter_autopo.pas

📁 一个MRPII系统源代码版本
💻 PAS
📖 第 1 页 / 共 3 页
字号:
  begin
    DispInfo('没有行数据,不能保存!',3);
    Abort;
  end;
  AdoQry_Body.First;
  I:=1;
  While Not AdoQry_Body.Eof Do
  begin
    If StrToFloat(FormatFloat('##0.##',AdoQry_Body.fieldbyname('PoQty').AsFloat))<=0 Then
    begin
      DispInfo('第'+IntToStr(I)+'行数据的约定交货量小于等于了0,不能保存!',3);
      Abort;
    end;
    If (AdoQry_Body.fieldbyname('POStArtWorkDate').AsDateTime<Date()) Then
    begin
      DispInfo('第'+IntToStr(AdoQry_Body.RecNo)+'行数据约定开工日日小于了系统工作日,请修改!',1);
      Abort;
    end;
     If (AdoQry_Body.fieldbyname('PoLineDate').AsDateTime<Date()) Then
    begin
      DispInfo('第'+IntToStr(AdoQry_Body.RecNo)+'行数据约定交货日小于了系统工作日,请修改!',1);
      Abort;
    end;
    SqlText:=' Select PcLine.* '
          +' From PcLine '
          +' Where (ItemCode='''+Trim(AdoQry_Body.fieldbyname('ItemCode').AsString)+''''
          +' )And (PcNo='''+Trim(Edt_PcNo.Text)+''')';
    AdoQry_Tmp.Close;
    AdoQry_Tmp.SQL.Text:=SqlText;
    AdoQry_Tmp.Open;
    If AdoQry_Tmp.Eof Then
    begin
      DispInfo('第'+IntToStr(I)+'行物料代码在相应的采购合同中找不到,不能存盘!',1);
      Abort;
    end
    Else
    begin
      SqlText:=' Select PcLine.PcTaxPrice,PcLine.PcNoTaxPrice,PcLine.PcReferencedPrice '
              +' From PcLine '
              +' Where ('''+DateTimeToStr(AdoQry_Body.fieldbyname('PoLineDate').AsDateTime) +'''>= PcStArtDate '
              +' And '''+DateTimeToStr(AdoQry_Body.fieldbyname('PoLineDate').AsDateTime) +'''<= PcendDate) '
              +' And (('''+FloatToStr(AdoQry_Body.fieldbyname('PoQty').AsFloat)+'''>= PcStArtQty '
              +' And '''+FloatToStr(AdoQry_Body.fieldbyname('PoQty').AsFloat)+'''<PcendQty)'
              +' Or (PcStArtQty=0 And PcendQty=0)) '
              +' And (ItemCode='''+Trim(AdoQry_Body.fieldbyname('ItemCode').AsString)+''''
              +' )And (PcNo='''+Trim(Edt_PcNo.Text)+''')'
              +' And (PcLine.PcLineStatus=1)';
      AdoQry_Tmp.Close;
      AdoQry_Tmp.SQL.Text:=SqlText;
      AdoQry_Tmp.Open;
      If Not AdoQry_Tmp.Eof Then
      begin
        With AdoQry_Body Do
        begin
          Edit;
          fieldbyname('POREFERENCEDPRICE').AsInteger:=AdoQry_Tmp.fieldbyname('PcREFERENCEDPRICE').AsInteger;
          fieldbyname('PoNoTaxPrice').AsFloat:=AdoQry_Tmp.fieldbyname('PcNoTaxPrice').AsFloat;
          fieldbyname('PONoTaxAmount').AsFloat:=AdoQry_Tmp.fieldbyname('PcNoTaxPrice').AsFloat*fieldbyname('PoQty').AsFloat;
          fieldbyname('PoTaxPrice').AsFloat:=AdoQry_Tmp.fieldbyname('PcTaxPrice').AsFloat;
          fieldbyname('PoTaxAmount').AsFloat:=AdoQry_Tmp.fieldbyname('PcTaxPrice').AsFloat*fieldbyname('PoQty').AsFloat;
          Post;
        end;
      end //在该段时间及数量内存在数据
      Else
      begin
        DispInfo('第'+IntTostr(I)+'行数据交货量或约定交货日与采购合同不匹配,请修改!',1);
        Abort;
      end;
    end;
    AdoQry_Body.Next;
    I:=I+1;
  end; // end While


  Application.ProcessMessages;
  DbConnect.beginTrans;
  Try
    AdoQry_Body.First;
    BookmArk:=AdoQry_Body.BookmArk;
{    While Not AdoQry_Body.Eof Do
    begin
     // If AdoQry_Head.fieldbyname('SScheck').AsInteger=1 Then
      //begin
        SqlText:=' Select * From Ss Where SsId='''+IntToStr(AdoQry_Body.fieldbyname('LimItOut').AsInteger)+''''
                +' And convert(decimal(14,2),ReMainQty)>=convert(decimal(14,2),'''+FloatToStr(AdoQry_Body.fieldbyname('SsQty').AsFloat)+''')';
        AdoQry_Tmp.Close;
        AdoQry_Tmp.SQL.Text:=SqlText;
        AdoQry_Tmp.Open;
        If AdoQry_Tmp.Eof Then
        begin
          SqlText:= 'Select * From ss Where SsId='''+IntToStr(AdoQry_Body.fieldbyname('LimItOut').AsInteger)+'''';
          AdoQry_Tmp.Close;
          AdoQry_Tmp.SQL.Text := SqlText;
          AdoQry_Tmp.Open;
          if AdoQry_Tmp.fieldbyname('ReMainQty').AsFloat = 0 then
          begin
           If DbConnect.InTransaction Then
            DbConnect.RollBackTrans;
            DispInfo('数据已被修改,系统建议余量为0,您不可以保存此记录',3);
            abort;
          end
          else
          begin
            If DbConnect.InTransaction Then
                DbConnect.RollBackTrans;
            if DispInfo('数据已被修改,系统建议余量为'+AdoQry_Tmp.fieldbyname('ReMainQty').AsString+chr(13)+'是否确定保存数据!',2) ='y' then
              begin
              If  AdoQry_Body.fieldbyname('ssqty').AsFloat>AdoQry_Tmp.fieldbyname('ReMainQty').AsFloat then
              begin
                AdoQry_Body.Edit;
                AdoQry_Body.fieldbyname('SsQty').AsFloat:=AdoQry_Tmp.fieldbyname('ReMainQty').AsFloat;
                AdoQry_Body.Post;
              end;
                toolbutton2.OnClick(sender);
              end;
                 exit;
             end;
        end;
     // end;
      AdoQry_Body.Next;
    end;}
    If CurrentFormStatus='Add' Then
    begin
      PoNO:='P'+Trim(Copy(FormatDateTime('yyyy.mm.dd',Now),3,2))+Trim(Copy(FormatDateTime('yyyy.mm.dd',Now),6,2));
      Edt_PoNo.Text:=GetNo(DbConnect,PoNo,'Po');

      Act_Save.Enabled:=False;
      Act_InsertLine.Enabled:=False;
      Act_DeleteLine.Enabled:=False;
      Act_Modify.Enabled:=False;

      if edt_Pono.Text='' then
      abort;
      Application.ProcessMessages;
      SqlText:='Insert Po '
              +' (PoNo,VendorCode,PcNO,POType,PODate,'
              +'  POTaxRate_Percent,CurrencyCode,EmployeeCode, PoSpecial,CreateEmpolyeeCode,PORemArk)'
              +'  Values('
              +''''+Trim(Edt_PoNo.Text)+''''+','
              +''''+Trim(Edt_VendorCode.Text)+''''+','
              +''''+Trim(Edt_PcNo.Text)+''''+','
              +''''+IntToStr(Cmbx_PoType.ItemIndex)+''''+','
              +''''+Medt_PoDate.Text+''''+','
              +''''+Trim(Edt_PoTax.Text)+''''+','
              +''''+Trim(Edt_CurrencyCode.Text)+''''+','
              +''''+Trim(Edt_EmployeeCode.Text)+''''+','
              +''''+'0'+''''+','
              +''''+UserCode+''','
              +''''+Trim(Edt_PoReMArk.Text)+''''+')';
      AdoQry_Tmp.Close;
      AdoQry_Tmp.SQL.Text:=SqlText;
      AdoQry_Tmp.ExecSQL;   // Insert Po Table
      if not  SavePoHistory('Add') then
        abort;
      AdoQry_Body.First;
      While Not AdoQry_Body.Eof Do
      begin
        SqlText:='Insert PoLine '
                +' (PoNo,PoLineNo,ItemCode,POLineDate,PoStArtWorkDate,SsQty,POQty,POTaxPrice, '
                +' POTaxAmount,PONoTaxPrice,PONoTaxAmount,PONoFinishQty,POReferencedPrice,POLineStatus )'
                +' Values('
                +''''+Trim(Edt_PoNo.Text)+''','
                +''''+IntToStr(AdoQry_Body.fieldbyname('PoLineNo').AsInteger)+''','
                +''''+AdoQry_Body.fieldbyname('ItemCode').AsString+''','
                +''''+DatetimeToStr(AdoQry_Body.fieldbyname('PoLineDate').AsDateTime)+''','
                +''''+DatetimeToStr(AdoQry_Body.fieldbyname('PoStArtWorkDate').AsDateTime)+''',';
        If AdoQry_Body.fieldbyname('PoQty').AsFloat<=AdoQry_Body.fieldbyname('ssQty').AsFloat Then
          SqlText:=SqlText+''''+FloatToStr(AdoQry_Body.fieldbyname('PoQty').AsFloat)+''','
        Else
          SqlText:=SqlText+''''+FloatToStr(AdoQry_Body.fieldbyname('SsQty').AsFloat)+''',';
        SQlText:=SqlText+''''+FloatToStr(AdoQry_Body.fieldbyname('PoQty').AsFloat)+''','
                +''''+FloatToStr(AdoQry_Body.fieldbyname('POTaxPrice').AsFloat)+''','
                +''''+FloatToStr(AdoQry_Body.fieldbyname('POTaxAmount').AsFloat)+''','
                +''''+FloatToStr(AdoQry_Body.fieldbyname('PONoTaxPrice').AsFloat)+''','
                +''''+FloatToStr(AdoQry_Body.fieldbyname('PONoTaxAmount').AsFloat)+''','
                +''''+FloatToStr(AdoQry_Body.fieldbyname('PONoFinishQty').AsFloat)+''','
                +''''+IntToStr(AdoQry_Body.fieldbyname('POReferencedPrice').AsInteger)+''','
                +''''+IntToStr(AdoQry_Body.fieldbyname('POLineStatus').AsInteger)+''')';
        AdoQry_Tmp.Close;
        AdoQry_Tmp.SQL.Text:=SqlText;
        AdoQry_Tmp.ExecSQL;
        If  not SavePoLineHistory('Add') Then //保存历史记录
          Abort;
        If Cmbx_PoType.ItemIndex=1 Then //委外加工
          IF Not AutoBuildopListOrder(DbConnect,Trim(Edt_PoNo.Text),Trim(AdoQry_Body.fieldbyname('ItemCode').AsString),IntToStr(AdoQry_Body.fieldbyname('PoLineNo').AsInteger),
                'Add','Po',AdoQry_Body.fieldbyname('PoQty').Asfloat) Then  //自动产生领料单
           Abort;
        AdoQry_Body.Next;
      end;
    end;
    AdoQry_Body.First;
    While Not AdoQry_Body.Eof Do
    begin
      If AdoQry_Body.fieldbyname('PoQty').AsFloat<=AdoQry_Body.fieldbyname('SsQty').AsFloat Then
      begin
        AdoQry_Body.Edit;
        AdoQry_Body.fieldbyname('SsQty').AsFloat:=AdoQry_Body.fieldbyname('PoQty').AsFloat;
        AdoQry_Body.Post;
      end;
      SqlText:='Update Ss '
              +'Set ReMainQty= case when ReMainQty-'''+(FloatToStr(AdoQry_Body.fieldbyname('SsQty').AsFloat))+'''> 0 then '
              +' ReMainQty-'''+(FloatToStr(AdoQry_Body.fieldbyname('SsQty').AsFloat))+''''
              +' else '
              +' 0'
              +' end '
              +'where Ssid='''+IntToStr(AdoQry_Body.fieldbyname('LimItOut').AsInteger)+'''';
      AdoQry_Tmp.Close;
      AdoQry_Tmp.SQL.Text:=SqlText;
      AdoQry_Tmp.ExecSQL;
      If AdoQry_Head.Locate('SsId',AdoQry_Body.fieldbyname('LimItOut').AsInteger,[loCaseInsensitive]) Then
         begin
          BookmArk:=AdoQry_Head.BookmArk;
          AdoQry_Head.edit;
          AdoQry_Head.fieldbyname('ReMainQty').AsFloat:=AdoQry_Head.fieldbyname('ReMainQty').AsFloat-AdoQry_Body.fieldbyname('ssQty').AsFloat;
          AdoQry_Head.fieldbyname('SScheck').AsInteger:=0;
          AdoQry_Head.Post;

          SqlText:='Update #Ss '
              +'Set ssReMainQty= case when ssReMainQty-'''+(FloatToStr(AdoQry_Body.fieldbyname('SsQty').AsFloat))+''' >0 then'
              +' ssReMainQty-'''+(FloatToStr(AdoQry_Body.fieldbyname('SsQty').AsFloat))+''''
              +' else '
              +' 0 '
              +' end ,'
              +' ReMainQty= case when ReMainQty-'''+(FloatToStr(AdoQry_Body.fieldbyname('SsQty').AsFloat))+''' >0 then'
              +' ReMainQty-'''+(FloatToStr(AdoQry_Body.fieldbyname('SsQty').AsFloat))+''''
              +' else '
              +' 0 '
              +' end '
              +'where Ssid='''+IntToStr(AdoQry_Body.fieldbyname('LimItOut').AsInteger)+'''';
         AdoQry_Tmp.Close;
         AdoQry_Tmp.SQL.Text:=SqlText;
         AdoQry_Tmp.ExecSQL;

          AdoQry_Body.Next;
         end;
    end;//更新表头数据
    DbConnect.CommitTrans;
    DispInfo('数据已保存!',3);
    if Frm_Pm_Enter_SsPoInfo<> nil then
    begin
      if Frm_Pm_Enter_SsPoInfo.frentform=1 then
      begin
        Frm_Pm_Enter_SsPoInfo.Initselect;
        Frm_Pm_Enter_SsPoInfo.falg :=0;
      end;
    end;
    if Frm_Pm_Enter_SsPoInfo1<> nil then
      if Frm_Pm_Enter_SsPoInfo1.frentform=1 then
      begin
        Frm_Pm_Enter_SsPoInfo1.Initselect;
        Frm_Pm_Enter_SsPoInfo1.falg :=0;
      end;
    if Frm_Pm_Enter_SsPoInfo2<> nil then
      if Frm_Pm_Enter_SsPoInfo2.frentform=1 then
      begin
        Frm_Pm_Enter_SsPoInfo2.Initselect ;
        Frm_Pm_Enter_SsPoInfo2.falg :=0;
      end;
    if Frm_Pm_Enter_SsPoInfo3<> nil then
      if Frm_Pm_Enter_SsPoInfo3.frentform=1 then
      begin
        Frm_Pm_Enter_SsPoInfo3.Initselect ;
        Frm_Pm_Enter_SsPoInfo3.falg :=0;
      end;

    AdoQry_Head.BookmArk:= BookmArk;
  Except
    on e:Exception do
    begin
      If DbConnect.InTransaction Then
        DbConnect.RollBackTrans;
        Edt_Pono.Text:='';
        RecOrderror(Self,AdoQry_tmp,E.message);
        DispInfo('保存数据失败,请重试!',1);
        Abort;
    end ;
  end;
  ActiveControl:=DBGridEh1;
  Act_InsertLine.Enabled:=False;
  Act_DeleteLine.Enabled:=False;
  Act_Modify.Enabled:=False;
  Act_Save.Enabled:=False;
  Edt_PcNo.Enabled:=False;
  Cmbx_PoType.Enabled:=False;
  Edt_EmployeeCode.Enabled:=False;
  DbGridEh1.Enabled:=False;
  Medt_PoDate.Enabled:=False;
  Act_Preview.Enabled:=True;
  Act_Print.Enabled:=True;
end;

procedure TFrm_Pm_Enter_AutoPo.Edt_MoRemArkExit(Sender: TObject);
begin
  inherited;
  If (ActiveControl.Name='DBGridEh1') Or (ActiveControl.Name='ControlBar')  Then
    Exit;
  If (Not BlankCheck(TEdit(Sender).Text,'备注'))
    Or (Not checksymbol(TEdit(Sender).Text,'备注')) Then
  begin
    Twincontrol(Sender).SetFocus;
    Abort;
  end;

end;

procedure TFrm_Pm_Enter_AutoPo.FormCreate(Sender: TObject);
begin
  inherited;
  ExtendCaption:=False;
  Frm_Entry_Detail:=TFrm_Pm_Enter_AutoPo_D.Create(Self);
  Medt_PoDate.Text:=FormatDateTime('yyyy.mm.dd',Date);
  With Cmbx_PoType Do
  begin

⌨️ 快捷键说明

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