bas_batch_b.pas

来自「一个MRPII系统源代码版本」· PAS 代码 · 共 429 行

PAS
429
字号
unit Bas_Batch_B;

Interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Base_Entry_Body, Db, ActnList, AdODB, Grids, DBGridEh, StdCtrls,
  ExtCtrls, ComCtrls, ToolWin, ExtEdit, DBCtrls, Mask, ExtPrintReport, jpeg;

Type
  TFrm_Bas_Batch_B = Class(TFrm_Base_Entry_Body)
    Label2: TLabel;
    Label3: TLabel;
    Label5: TLabel;
    Lbl_ItemName: TLabel;
    ExtEdt_ItemCode: TExtEdit;
    Edt_RemArk: TEdit;
    ActionList1: TActionList;
    Lbl_UomName: TLabel;
    Label1: TLabel;
    cmbx_Backflush: TComboBox;
    AdoQry_BodyBatchno: TStringField;
    AdoQry_BodyBatchName: TStringField;
    AdoQry_BodyVendorCode: TStringField;
    AdoQry_BodyVendorBatchno: TStringField;
    AdoQry_BodyusefulCtrl: TIntegerField;
    AdoQry_Bodyusefuldate: TIntegerField;
    AdoQry_BodyBatchstatus: TIntegerField;
    AdoQry_BodyBatchlineremArk: TStringField;
    AdoQry_BodyVendorName: TStringField;
    AdoQry_BodyFirstindate: TDateTimeField;
    AdoQry_Bodytmpfield: TIntegerField;
    procedure FormCreate(Sender: TObject);
    procedure Act_DeleteLineExecute(Sender: TObject);
    procedure ExtEdt_ItemCodeChange(Sender: TObject);
    procedure Act_SaveExecute(Sender: TObject);
    procedure ExtEdt_ItemCodeExit(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure ExtEdt_ItemCodeKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure Act_QuitExecute(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    n:integer;
    Batchno:string;
    delItem:Array of string;
    { Private declarations }
  public
    { Public declarations }
    Bill_ID,str1,str2,str3:String;
    procedure InitReport; Override;
    procedure SetStatus(CurrentStatus:String;var AnswerStatus,
      EnableControls:String); Override;//设置各种状态下那些控件Enable
    procedure InitControls; Override;//初始化Form上所有控件
    procedure SaveHeadData; Override;//把表头控件值写入缓存,不要Post
    procedure SaveData; Override;//把表头控件写入缓存,不要Post
//    procedure InOutItemCodeCheck(sender:tobject); Override;
  end;

var

  Frm_Bas_Batch_B: TFrm_Bas_Batch_B;

implementation

uses Bas_Batch_D,Sys_Global;

{$R *.DFM}

{ TFrm_Pm_Pc_Entry_D }

procedure TFrm_Bas_Batch_B.InitControls;
begin
 { if Status='Add' then
    SetFocus_Control:=ExtEdt_ItemCode
  else
    SetFocus_Control:=Edt_RemArk;
  ExtendCaption:=False; }
  inherited;
  n:=0;
  setlength(delItem,30);
  if Status='ReadOnly' then
  begin
    Caption:='批次主文件查询';
    Pnl_Title.Caption:='批次主文件查询';
  end
  else
  begin
    Caption:='批次主文件维护';
    Pnl_Title.Caption:='批次主文件维护';
  end;
  if Status<>'Add' then
    Bill_ID:=AdoQry_Head.fieldbyname('Batchid').AsString
  else
    Bill_ID:='';
//  PriceFields:='PcTaxPrice,PcNoTaxPrice,';
  AdoQry_Body.Close;
  AdoQry_Body.sql.clear;
  AdoQry_Body.SQL.text:='select a.Firstindate,a.Batchno,a.BatchName,a.VendorCode,a.VendorBatchno,'+
           ' a.usefulCtrl,a.usefuldate,a.Batchstatus,a.BatchlineremArk,a.tmpfield,'+
           ' b.VendorName from BatchLine a ,Vendor b '+
           ' Where a.VendorCode=b.VendorCode '+
           ' and a.Batchid='''+Bill_ID+''' ';
  AdoQry_Body.Open;
  AdoQry_Body.Sort:='Batchno';
  AdoQry_Head.Active :=True;
  with AdoQry_Head do
  begin
    ExtEdt_ItemCode.Text:=fieldbyname('ItemCode').AsString;
    Lbl_ItemName.Caption:=fieldbyname('ItemName').AsString;
    lbl_UomName.Caption :=fieldbyname('UomName').asstring;
    cmbx_Backflush.ItemIndex:=fieldbyname('Backflush').asinteger;
    Edt_RemArk.Text:=fieldbyname('BatchRemArk').AsString;
  end;
  if status='Add' then
     cmbx_Backflush.ItemIndex :=1;
end;

procedure TFrm_Bas_Batch_B.SaveHeadData;
begin
  inherited;
  AdoQry_Head.edit;
  with AdoQry_Head do
  begin
    fieldbyname('ItemCode').asstring:=Extedt_ItemCode.Text ;
    fieldbyname('ItemName').asstring:=lbl_ItemName.Caption;
    fieldbyname('Backflush').asinteger:=cmbx_Backflush.Itemindex;
    fieldbyname('BatchremArk').asstring:=edt_remArk.Text ;
    fieldbyname('UomName').asstring:=lbl_UomName.Caption ;
  end;

end;

procedure TFrm_Bas_Batch_B.SetStatus(CurrentStatus: String;
  var AnswerStatus, EnableControls: String);
begin
  inherited;
  EnableControls:='Edt_RemArk,Extedt_ItemCode,cmbx_Backflush';
//   enablecontrols:='';
end;

procedure TFrm_Bas_Batch_B.FormCreate(Sender: TObject);
begin
  inherited;
  Frm_Entry_Detail:=TFrm_Bas_Batch_D.Create(Self);//设置弹出Detail
end;

procedure TFrm_Bas_Batch_B.SaveData;
var
  Bill_No,ItemCode,DispStr,StatusStr:String;
  StArtQty,endQty:Double;
  StArtDate,endDate:TDateTime;
  i:integer;
begin
  inherited;
  DBConnect.beginTrans;
  DispStr:=' 保存失败,请重试 ';
  try
    if(Status<>'Add')then
      StatusStr:='修改'
    else
      StatusStr:='新增';

    if(Status<>'Add')then
    begin
      Bill_id:=AdoQry_Head.fieldbyname('Batchid').AsString;
      AdoQry_Tmp.Close;
      AdoQry_Tmp.SQL.Text:='Update Batch Set'
        +' ItemCode='''+Extedt_ItemCode.Text+''''
        +',BatchRemArk='''+edt_remArk.Text+''''
        +',Backflush='+inttostr(cmbx_Backflush.Itemindex)+''
        +' Where Batchid='''+Bill_id+'''';
      AdoQry_Tmp.ExecSQL;
    end
    else
    begin
      AdoQry_tmp.Close;
      AdoQry_tmp.SQL.Text:='insert Batch (ItemCode,Backflush,BatchremArk) Values '+
                      '('''+Extedt_ItemCode.Text+''','+inttostr(cmbx_Backflush.Itemindex)+','''+
                      edt_remArk.text+''')';
      AdoQry_tmp.ExecSQL;
      AdoQry_Tmp.Close;
      AdoQry_Tmp.SQL.Text:='Select @@identity as Bill_Id';
      AdoQry_Tmp.Open;
      Bill_Id:=AdoQry_Tmp.fieldbyname('Bill_Id').AsString;
    end;
    with AdoQry_Body do
    begin
      First;
      while not eof do
      begin
       if fieldbyname('tmpfield').asinteger=1 then
        begin
          if fieldbyname('BatchNo').asstring='' then
            BatchNo:=getno(DBConnect,formatdatetime('yyyy-mm-',now),'BT')
          else
            BatchNo:=fieldbyname('BatchNo').asstring;
          AdoQry_tmp.Close;
          AdoQry_tmp.SQL.Text:='insert Batchline (Batchid,Batchno,BatchName,VendorCode'
            +',VendorBatchno,usefulCtrl,usefuldate,BatchlineremArk)'
            +' Values ('
            +' '+Bill_id+','
            +' '''+BatchNo+''''
            +','''+fieldbyname('BatchName').asstring+''''
            +','''+fieldbyname('VendorCode').asstring+''''
            +','''+fieldbyname('VendorBatchno').asstring+''''
            +','''+fieldbyname('usefulCtrl').asstring+''''
            +','''+fieldbyname('usefuldate').asstring+''''
            +','''+fieldbyname('BatchlineremArk').asstring+''')';
          AdoQry_tmp.ExecSQL ;
        end
       else
       if fieldbyname('tmpfield').asinteger=2 then
        begin
          if fieldbyname('BatchNo').asstring='' then
            BatchNo:=getno(DBConnect,formatdatetime('yyyy-mm-',now),'BT')
          else
            BatchNo:=fieldbyname('BatchNo').asstring;
          AdoQry_tmp.Close;
          AdoQry_tmp.SQL.Text:='update Batchline set '+
                               ' BatchName='''+fieldbyname('BatchName').asstring+''''+
                               ',VendorCode='''+fieldbyname('VendorCode').asstring+''''+
                               ',VendorBatchno='''+fieldbyname('VendorBatchno').asstring+''''+
                               ',usefulCtrl='''+fieldbyname('usefulCtrl').asstring+''''+
                               ',usefuldate='''+fieldbyname('usefuldate').asstring+''''+
                               ',BatchlineremArk='''+fieldbyname('BatchlineremArk').asstring+''''+
                               ' where Batchno='''+Batchno+'''' ;

          AdoQry_tmp.ExecSQL ;
        end;
        next;
      end;
    end;
    if n>0 then
    for i:=0 to n do
    begin
        AdoQry_tmp.Close;
        AdoQry_tmp.sql.Text :='delete from Batchline where Batchno='''+delItem[i]+'''';
        AdoQry_tmp.execsql;
    end;
    DBConnect.CommitTrans;
    n:=0;
  except
    DBConnect.RollBackTrans;
    DispInfo(DispStr,3);
    Abort;
  end;
end;

procedure TFrm_Bas_Batch_B.Act_DeleteLineExecute(Sender: TObject);
var
  ItemCode:String;
  CanDelete:Boolean;
  i:Integer;
begin
  if AdoQry_Body.fieldbyname('Firstindate').Asstring<>'' then
  begin
    DispInfo(' 该批次号有出入库业务发生,不允许删除!',3);
    Abort;
  end;
  CanDelete:=False;
  if(not AdoQry_Body.IsEmpty)then
  begin
    if(not AdoQry_Body.Eof)then
    begin
      ItemCode:=AdoQry_Body.fieldbyname('Batchno').AsString;
      AdoQry_Body.Next;
      if(ItemCode<>AdoQry_Body.fieldbyname('Batchno').AsString)then
      begin
        CanDelete:=True;
      end;
      if(not AdoQry_Body.Eof)then
        AdoQry_Body.Prior
      else
        CanDelete:=True;
    end
    else
      CanDelete:=True;
    if(CanDelete=True)and(DispInfo(' 真的删除当前记录吗? ',2)='y')then
    begin
      delItem[n]:=AdoQry_Body.fieldbyname('Batchno').asstring;
      AdoQry_Body.Delete;
      n:=n+1;
      Act_Save.Enabled:=True;
      if AdoQry_Body.IsEmpty then
        for i:=0 to Pnl_Head.ControlCount-1 do
        begin
          if(not(Pnl_Head.Controls[i] is TLabel))then
            Pnl_Head.Controls[i].Enabled:=True;
        end;
    end
    else if(CanDelete=False)then
      DispInfo(' 不能从中间删除连续的项目 ',3);
  end;
end;

procedure TFrm_Bas_Batch_B.ExtEdt_ItemCodeChange(Sender: TObject);
begin
  inherited;
  AdoQry_Tmp.Close;
  AdoQry_Tmp.SQL.Text:='Select Item.ItemName,Uom.UomName'
    +' From Item,Uom '
    +' Where Item.UomCode=Uom.UomCode and Item.ItemCode='''+TExtEdit(Sender).Text+'''';
  AdoQry_Tmp.Open;
  Lbl_ItemName.Caption:=AdoQry_Tmp.fieldbyname('ItemName').AsString;
  lbl_UomName.Caption :=AdoQry_Tmp.fieldbyname('UomName').AsString;
  AllChange(Sender);
end;

procedure TFrm_Bas_Batch_B.InitReport;
var
  s1,s2,s3:String;
  i:Integer;
begin
  for i:=Length(ExtEdt_ItemCode.Text+' '+Lbl_ItemName.Caption) to 60 do
    s1:=s1+' ';
  inherited;
  ExtPrintReport.Subtitle2:='  '+Label2.Caption+' '+ExtEdt_ItemCode.Text+' '+Lbl_ItemName.Caption;
  ExtPrintReport.Subtitle3:='  '+Label3.Caption+' '+Lbl_UomName.Caption+' '+label1.Caption+' '+cmbx_Backflush.Text;
  ExtPrintReport.Subtitle4:='  '+Label5.Caption+' '+Edt_RemArk.Text;
end;
procedure TFrm_Bas_Batch_B.Act_SaveExecute(Sender: TObject);
var
  ItemCodes:string;
begin
  inherited;
  ItemCodes:=ExtEdt_ItemCode.Text;
  AdoQry_Head.DisableControls ;
  AdoQry_Head.Close;
  AdoQry_Head.Open;
  AdoQry_Head.Sort:='ItemCode';
  AdoQry_Head.Locate('ItemCode',ItemCodes,[]);
  AdoQry_Head.EnableControls ;
  AdoQry_Body.DisableControls ;
  Bill_id:=AdoQry_Head.fieldbyname('Batchid').asstring;
  AdoQry_Body.Close;
  AdoQry_Body.sql.clear;
  AdoQry_Body.SQL.text:='select a.Firstindate,a.Batchno,a.BatchName,a.VendorCode,a.VendorBatchno,'+
           ' a.usefulCtrl,a.usefuldate,a.Batchstatus,a.BatchlineremArk,a.tmpfield,'+
           ' b.VendorName from BatchLine a ,Vendor b '+
           ' Where a.VendorCode=b.VendorCode '+
           ' and a.Batchid='''+Bill_ID+''' ';
  AdoQry_Body.Open;
  AdoQry_Body.EnableControls ;
  AdoQry_Body.Locate('Batchno',Batchno,[]);
end;

procedure TFrm_Bas_Batch_B.ExtEdt_ItemCodeExit(Sender: TObject);
var
  Bookm:tBookmArk;
begin
  InOutItemCodeCheck(sender);
  if status='Add' then
  begin
  Bookm:=AdoQry_Head.GetBookmArk ;
  AdoQry_Head.DisableControls ;
  if AdoQry_Head.Locate('ItemCode',Extedt_ItemCode.text,[]) then
  begin
    with AdoQry_tmp do
    begin
      Close;
      sql.Text :='select Count(*) num from Batch where ItemCode='''+Extedt_ItemCode.text+'''';
      open;
      if fieldbyname('num').asinteger>0 then
      begin
        DispInfo('该物料的批次定义已经存在,不允许增加。',3);
        Extedt_ItemCode.SetFocus ;
        abort;
      end
      else
      Bookm:=AdoQry_Head.GetBookmArk ;
    end;
  end
  else
  AdoQry_Head.Append ;
  AdoQry_Head.EnableControls;
  AdoQry_Head.GotoBookmArk(Bookm);
  end;
  with AdoQry_tmp do
  begin
    Close;
    sql.Text :='select BatchCtrl from Item where ItemCode='''+Extedt_ItemCode.Text+'''';
    open;
    if fieldbyname('BatchCtrl').asinteger=0 then
    begin
       DispInfo('该物料无须进行批次控制',3);
       Extedt_ItemCode.SetFocus ;
       abort;
    end;
  end;
end;

procedure TFrm_Bas_Batch_B.FormActivate(Sender: TObject);
begin
  inherited;
  if Extedt_ItemCode.Enabled then
     Extedt_ItemCode.SetFocus ;
end;

procedure TFrm_Bas_Batch_B.ExtEdt_ItemCodeKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  inherited;
  if key=VK_F9 then
  commonHint(sender,AdoQry_tmp,'ItemName','物料名称','ItemCode','物料代码','Item',' BatchCtrl=1');
end;
procedure TFrm_Bas_Batch_B.Act_QuitExecute(Sender: TObject);
begin
  inherited;
  AdoQry_Head.Locate('ItemCode',ExtEdt_ItemCode.Text,[]);
end;

procedure TFrm_Bas_Batch_B.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  inherited;
  if act_Save.Enabled then
  begin
    AdoQry_Head.DisableControls ;
    AdoQry_Head.Close;
    AdoQry_Head.Open;
    AdoQry_Head.Sort:='ItemCode';
    AdoQry_Head.Locate('ItemCode',Extedt_ItemCode.Text,[]);
    AdoQry_Head.EnableControls ;
  end;
end;

end.

⌨️ 快捷键说明

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