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

📄 qc_checkresult_b.pas

📁 一个MRPII系统源代码版本
💻 PAS
字号:
unit Qc_CheckResult_B;

Interface

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

Type
  TFrm_Qc_CheckResult_B = Class(TFrm_Base_Outer)
    AdoQry_MainOncheckBillId: TIntegerField;
    AdoQry_MainItemFlag: TStringField;
    AdoQry_MainOnCheckBillLineNo: TIntegerField;
    AdoQry_MainItemName: TStringField;
    AdoQry_MainUomName: TStringField;
    AdoQry_MainQcItem: TStringField;
    AdoQry_MainOnCheckBillNo: TStringField;
    AdoQry_MainOnCheckDate: TDateTimeField;
    AdoQry_MaInvendorflag: TStringField;
    AdoQry_MainOnCheckQty: TFloatField;
    AdoQry_MainBatchNo: TStringField;
    AdoQry_MainOnCheckStatus: TIntegerField;
    AdoQry_MainReceivedQty: TFloatField;
    AdoQry_MainQcStatus: TIntegerField;
    AdoQry_MainOnCheckRemArk: TStringField;
    edt_QcBatchNo: TEdit;
    lbl_QcProblem: TLabel;
    Label1: TLabel;
    Label2: TLabel;
    Cmbo_Determinant: TComboBox;
    Label3: TLabel;
    Cmbo_QcClass: TComboBox;
    Label4: TLabel;
    Label5: TLabel;
    DBTxt_Vendor: TDBText;
    DBTxt_BatchNo: TDBText;
    Label6: TLabel;
    DBText1: TDBText;
    ExtEdt_Problem: TExtEdit;
    AdoQry_MainItemCode: TStringField;
    Edt_remArk: TEdit;
    Label7: TLabel;
    Medt_Date: TMaskEdit;
    procedure FormCreate(Sender: TObject);
    procedure ExtEdt_ProblemExit(Sender: TObject);
    procedure AdoQry_MainBeforePost(DataSet: TDataSet);
    procedure Act_SaveExecute(Sender: TObject);
    procedure Cmbo_DeterminantChange(Sender: TObject);
    procedure AdoQry_MainAfterScroll(DataSet: TDataSet);
    procedure FormActivate(Sender: TObject);
  private
    FBatchNo,Switch:string;
    procedure InitStatus;
    function save_Check: boolean;
    { Private declarations }
  public
    procedure InitForm(AdOConnection:TAdOConnection;ReadOnly: Boolean);OverRide;
    procedure SetParam(BatchNo:string);
    { Public declarations }
  end;

var
  Frm_Qc_CheckResult_B: TFrm_Qc_CheckResult_B;

implementation
uses Sys_Global,Qc_CheckResult;
{$R *.DFM}

{ TFrm_Base_Outer2 }


{ TFrm_Base_Outer2 }

procedure TFrm_Qc_CheckResult_B.InitForm(AdOConnection: TAdOConnection;
  ReadOnly: Boolean);
var
  Sql_Txt:string;
begin
  inherited;
  with DBGridEh do
    options:=options+[dgEditing]-[dgRowSelect];

    SQL_TXT:='select OnCheckBillLine.OncheckBillId,OnCheckBillLine.Receivestatus, '+
                        'case when OnCheckBillLine.BatchNo='''' then ''------'' else OnCheckBillLine.BatchNo end BatchNo,'+
                        'OncheckBillLine.ItemCode+'' ''+Item.ItemName ItemFlag,'+
                        'OnCheckBillLine.OnCheckBillLineNo, '+
                        'Item.ItemName, '+
                        'OncheckBillLine.ItemCode,'+
                        'Uom.UomName, '+
                        'OnCheckBill.OnCheckBillNo, '+
                        'OnCheckBill.OnCheckDate, '+
                        'OnCheckBillLine.QcItem,'+
                        'OnCheckBill.VendorCode+'' ''+v.VendorName Vendorflag,'+
                        'OnCheckBillLine.OnCheckQty, '+
                        'OnCheckBillLine.BatchNo,'+
                        'OnCheckBillLine.OnCheckStatus as OnCheckStatus, '+
                        'OnCheckBillLine.ReceivedQty as ReceivedQty, '+
                        'OnCheckBillLine.QcStatus as QcStatus, '+
                        'OnCheckBillLine.OnCheckRemArk as OnCheckRemArk '+
                   'from oncheckBillline '+
                 'Left join OnCheckBill '+
                   'on oncheckBill.OnCheckBillid=OnCheckBillLine.ONCheckBillId '+
                 'Join Item '+
                   'on Item.ItemCode=OnCheckBillLine.ItemCode '+
                 'JOin Uom '+
                   'on Uom.UomCode=Item.UomCode '+
                 'Join Vendor v '+
                   'on v.VendorCode=OnCheckBill.VendorCode'+
      ' where OnCheckBillLine.BatchNo='''+FBatchNo+''' and '+
      '       OnCheckBillLine.OnCheckStatus=''0'' '+
      ' Order By OnCheckBillLine.BatchNo,OnCheckBill.VendorCode,OnCheckBill.OnCheckDate,OncheckBillLine.ItemCode';
  with AdoQry_Main do
  begin
    Close;
    sql.clear;
    sql.Add(sql_txt);
    open;
  end;
  InitStatus;
end;

procedure TFrm_Qc_CheckResult_B.InitStatus;
begin
  edt_QcBatchNo.Text:=FBatchNo;
  Cmbo_Determinant.ItemIndex:=0;
  Cmbo_QcClass.ItemIndex:=0;
  DBGridEh.ReadOnly:=False;
  DBGridEh.Columns[0].ReadOnly:=True;
  DBGridEh.Columns[1].ReadOnly:=True;
  DBGridEh.Columns[2].ReadOnly:=True;
  DBGridEh.Columns[3].ReadOnly:=True;
  DBGridEh.Columns[4].ReadOnly:=True;
  DBGridEh.Columns[5].ReadOnly:=True;
  DBGridEh.Columns[6].ReadOnly:=True;
  DBGridEh.Columns[7].ReadOnly:=False;
end;

procedure TFrm_Qc_CheckResult_B.SetParam(BatchNo: string);
begin
  FBatchNo:=BatchNo;
end;

procedure TFrm_Qc_CheckResult_B.FormCreate(Sender: TObject);
begin
  inherited;
  ToolButton6.action:=act_Save;
end;

procedure TFrm_Qc_CheckResult_B.ExtEdt_ProblemExit(Sender: TObject);
begin
  inherited;
  If ExtEdt_Problem.text<>'' then
  QcProblemCheck(sender)
  else
  lbl_QcProblem.Caption:='';
end;

procedure TFrm_Qc_CheckResult_B.AdoQry_MainBeforePost(DataSet: TDataSet);
var
  a1,a2:real;
begin
  inherited;
  a1:=AdoQry_Main.fieldbyname('ReceivedQty').asfloat;
  a2:=AdoQry_Main.fieldbyname('OnCheckQty').asfloat;
  if a1>a2 then
  begin
    DispInfo('入库数量大于待检数量!',1);
    Abort;
  end;
  if a1<0 then
  begin
    DispInfo('入库数量不能小于零!',1);
    Abort;
  end;
end;

function TFrm_Qc_CheckResult_B.save_Check: boolean;
var
  QcstatusNO:integer;
  sql_txt,tmp,WarehouseCode,WhPositionCode,PoNo,PoLineNo :String;
begin
  tmp:=Cmbo_Determinant.Text;
  for QcstatusNO:=0 to Cmbo_Determinant.Items.Count-1 do
    if Cmbo_Determinant.Items.Strings[QcstatusNO]=tmp then break;

  If (AdoQry_Main.fieldbyname('ReceivedQty').AsFloat<0) or
     (AdoQry_Main.fieldbyname('ReceivedQty').AsFloat>
      AdoQry_Main.fieldbyname('OnCheckQty').AsFloat) then
  begin
    Result:=True;
    exit;
  end;
  With AdoQry_Tmp do
  begin
    Close;
    Sql.clear;
    sql_txt:='Update OnCheckBillLine '+
              ' Set ReceivedQty='+AdoQry_Main.fieldbyname('ReceivedQTy').Asstring+','+
                   ' QcStatus='+inttostr(QcstatusNO)+','+
                   ' QcBatchNo='''+FBatchNo+''','+
                   ' OnCheckStatus='''+Switch+''','+
                   ' OnCheckRemArk='''+AdoQry_Main.fieldbyname('OnCheckRemArk').AsString+''' '+
              ' Where OnCheckBillId='+AdoQry_Main.fieldbyname('OnCheckBillId').AsString+
                ' and OnCheckBillLineNo='+AdoQry_Main.fieldbyname('OnCheckBillLineNo').asstring;
    sql.Add(sql_txt);
    ExecSql;
  end;

  IF (QcstatusNO=2) then
    With AdoQry_Tmp do
    begin
      Close;
      Sql.clear;
      Sql.Add('Select WHCode From OnCheckBill Where OnCheckBillId='+AdoQry_Main.fieldbyname('OnCheckBillId').AsString);
      Open;
      WarehouseCode:=AdoQry_Tmp.fieldbyname('WHCode').AsString;

      Close;
      Sql.clear;
      Sql.Add('Select WhPositionCode From WhPosition Where WhCode='+format('''%s''',[WarehouseCode])+' and WhPositionType=1 ');
      Open;
      WhPositionCode:=AdoQry_Tmp.fieldbyname('WhPositionCode').AsString;

      Close;
      Sql.clear;
      Sql.Add('Update CurrentInv '+
              '  Set  OnCheckInv=OnCheckInv-('+AdoQry_Main.fieldbyname('OnCheckQty').AsString+') '+
              '  Where WhCode='''+WarehouseCode+''''+
              '    and ItemCode='''+AdoQry_Main.fieldbyname('ItemCode').AsString+''''+
              '    and WhPositionCode='''+WhPositionCode+'''');
      ExecSql;

      Close;
      SQl.clear;
      Sql.Add('Update Item '+
              '  Set CurrentOnCheckInv=CurrentOnCheckInv-('+AdoQry_Main.fieldbyname('OnCheckQty').AsString+') '+
              '  Where ItemCode='''+AdoQry_Main.fieldbyname('ItemCode').AsString+'''');
      ExecSql;

      Close;
      SQl.clear;
      Sql.Add('Select b.PoNo,bl.PoLineNo From  OnCheckBillLine bl,oncheckBill b '+
              '  Where bl.OnCheckBillId='+AdoQry_Main.fieldbyname('OnCheckBillId').AsString+
              '    and bl.OnCheckBillLineNo='+AdoQry_Main.fieldbyname('OnCheckBillLineNo').AsString+
              '    and bl.OnCheckBillid=b.oncheckBillid');
      Open;
      PoNo:=fieldbyname('PoNo').AsString;
      PoLineNo:=fieldbyname('PoLineNo').AsString;

      Close;
      Sql.clear;
      Sql.Add('Update PoLine '+
              '  Set PoInQty=PoInQty-('+AdoQry_Main.fieldbyname('OnCheckQty').AsString+')' +
              '  Where PONo='''+PoNo+''''+
              '    and PoLineNo='''+PoLineNo+'''');
      ExecSql;

      Close;
      sql.Text:='update OnCheckBillLine'+
                ' Set ReceivedQty='+AdoQry_Main.fieldbyname('ReceivedQTy').AsString+','+
                    ' QcStatus=2,'+
                    ' QcBatchNo='''+FBatchNo+''','+
                    ' OnCheckStatus=''1'','+
                    ' OnCheckRemArk='''+AdoQry_Main.fieldbyname('OnCheckRemArk').AsString+''' '+
                ' Where OnCheckBillId='+AdoQry_Main.fieldbyname('OnCheckBillId').AsString+
                 ' and OnCheckBillLineNo='+AdoQry_Main.fieldbyname('OnCheckBillLineNo').AsString+
                 ' and ItemCode='''+AdoQry_Main.fieldbyname('OnCheckBillLineNo').AsString+''' '+
                 ' and BatchNo='''+FBatchNo+'''';
      execsql;

    end;
end;

procedure TFrm_Qc_CheckResult_B.Act_SaveExecute(Sender: TObject);
var
  I,QcstatusNO:integer;
  Problem,tmp,Sql_Txt:string;
begin
  inherited;
  if (AdoQry_Main.State<>dsBrowse)then AdoQry_Main.post;

  If Cmbo_Determinant.Text='0 未处理' then
  begin
    DispInfo('不能保存未处理状态的物料!',1);
    Abort;
  end;

  If DispInfo('是否同时关闭该批物料?',2)='y' then Switch:='1'
  else Switch:='0';

  tmp:=Cmbo_Determinant.Text;
  for QcstatusNO:=0 to Cmbo_Determinant.Items.Count-1 do
    if Cmbo_Determinant.Items.Strings[QcstatusNO]=tmp then break;

  with AdoQry_Tmp do
  begin
    Close;
    sql.text:='select * from RawQcReport'+
              ' where QcBatchNo='''+FBatchNo+'''';
    open;
    if ExtEdt_Problem.Text='' then Problem:='Null'
    else Problem:=' '''+ExtEdt_Problem.Text+''' ';
    if IsEmpty then
    begin
      Close;
      Sql_Txt:='insert into RawQcReport(QcBatchNo,CheckBatchNo,QcStatus,QcLevel,QcReMArk,QcReportDate,QcProblemCode) '+
                  '     select '''+FBatchNo+''','+
                             ' '''+AdoQry_Main.fieldbyname('BatchNO').asstring+''','+
                             ' '''+inttostr(QcstatusNO)+''','+
                             ' '''+Cmbo_QcClass.Text+''','+
                             ' '''+Edt_remArk.Text+''','+
                             ' '''+Medt_Date.Text+''','+
                             Problem;

      sql.text:=Sql_Txt;
      execsql;
    end
    else
    begin
      Tmp:=ExtEdt_Problem.Text;

      If ExtEdt_Problem.Text='' then ExtEdt_Problem.Text:='Null'
      else
      ExtEdt_Problem.Text:=''''+ExtEdt_Problem.Text+'''';

      Close;
      sql.text:='update RawQcReport'+
                '   set '+
                '       QcStatus='''+inttostr(QcstatusNO)+''','+
                '       QcLevel='''+Cmbo_QcClass.Text+''','+
                '       QcReMArk='''+Edt_remArk.Text+''','+
                '       QcReportDate='''+Medt_Date.Text+''','+
                '       QcProblemCode='+ExtEdt_Problem.Text+
                ' where QcBatchNO='''+FBatchNo+'''';
      execsql;
      ExtEdt_Problem.Text:=Tmp;
    end;
  end;
  AdoQry_Main.First;
  AdoQry_Tmp.Connection.beginTrans;
  try
  for i:=0 to AdoQry_Main.RecordCount-1 do
  begin
    save_Check;
    AdoQry_Main.next;
  end;
  except
    AdoQry_Tmp.Connection.RollBackTrans;
    DispInfo('保存失败!请稍候再试!',1);
    abort;
  end;
  AdoQry_Tmp.Connection.CommitTrans;
  DBGridEh.ReadOnly:=True;
  edt_QcBatchNo.Enabled:=False;
  Cmbo_Determinant.Enabled:=False;
  Cmbo_QcClass.Enabled:=False;
  Edt_remArk.Enabled:=False;
  ExtEdt_Problem.Enabled:=False;
  Medt_Date.Enabled:=False;
{ DBGridEh.Columns[0].ReadOnly:=True;
  DBGridEh.Columns[1].ReadOnly:=True;
  DBGridEh.Columns[2].ReadOnly:=True;
  DBGridEh.Columns[3].ReadOnly:=True;
  DBGridEh.Columns[4].ReadOnly:=True;
  DBGridEh.Columns[5].ReadOnly:=True;
  DBGridEh.Columns[6].ReadOnly:=True;
  DBGridEh.Columns[7].ReadOnly:=True;
  DBGridEh.Columns[8].ReadOnly:=False;
  DBGridEh.Columns[9].ReadOnly:=False;
  DBGridEh.Columns[10].ReadOnly:=False;}
  act_Save.Enabled :=False;
end;

procedure TFrm_Qc_CheckResult_B.Cmbo_DeterminantChange(Sender: TObject);
var
  i:integer;
begin
  inherited;
  If Cmbo_Determinant.Text='2 拒收' then
    if DispInfo('是否关闭所有的行?',2)='y' then
    begin
    AdoQry_Main.First;
      for i:=0 to AdoQry_Main.RecordCount-1 do
      begin
        AdoQry_Main.Edit;
        AdoQry_Main.fieldbyname('OnCheckStatus').asinteger:=1;
        AdoQry_Main.fieldbyname('ReceivedQty').asfloat:=0;
        AdoQry_Main.Post;
        AdoQry_Main.next;
      end;
    end;
end;

procedure TFrm_Qc_CheckResult_B.AdoQry_MainAfterScroll(DataSet: TDataSet);
begin
  inherited;
  AdoQry_Main.Cancel;
end;

procedure TFrm_Qc_CheckResult_B.FormActivate(Sender: TObject);
begin
  inherited;
  Medt_Date.Text:=formatdatetime('YYYY.MM.DD',date);
end;

end.

⌨️ 快捷键说明

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