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

📄 qc_checkresult.pas

📁 一个MRPII系统源代码版本
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit Qc_CheckResult;

Interface

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

Type
  TFrm_Qc_CheckResult = Class(TFrm_Base_Outer)
    DbEdt_ItemName: TDBEdit;
    Label1: TLabel;
    Label3: TLabel;
    DBText2: TDBText;
    Label4: TLabel;
    DBtxt_Uom: TDBText;
    Label5: TLabel;
    DBTxt_Date: TDBText;
    Label6: TLabel;
    DBTxt_BatchNo: TDBText;
    Label7: TLabel;
    DBTxt_BillNo: TDBText;
    ToolButton7: TToolButton;
    ToolButton8: TToolButton;
    procedure DBGridEhKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure AdoQry_MainAfterInsert(DataSet: TDataSet);
    procedure AdoQry_MainBeforePost(DataSet: TDataSet);
    procedure DBGridEhExit(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Act_SaveExecute(Sender: TObject);
    procedure Act_QuitExecute(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure AdoQry_MainAfterPost(DataSet: TDataSet);
    procedure AdoQry_MainAfterScroll(DataSet: TDataSet);
    procedure Act_autoExecute(Sender: TObject);
    procedure Act_FilterExecute(Sender: TObject);
  private
    SaveSwitch:Boolean;
    display:integer;         //是否显示可采购入库数量栏位 =1 时不显示,否则显示;质检判定结果是否全部入库
    function save_Check:boolean;
    Function Check_QcBatchNo(QcBatchno,ItemCode,VendorCode:string):Boolean;
    { Private declarations }
  public
    procedure InitForm(AdOConnection:TAdOConnection;ReadOnly:Boolean);OverRide;
    { Public declarations }
  end;

var
  Frm_Qc_CheckResult: TFrm_Qc_CheckResult;

implementation
uses Qc_CheckResult_C,Sys_GloBal;
{$R *.DFM}

{ TFrm_Qc_CheckResult }

procedure TFrm_Qc_CheckResult.InitForm(AdOConnection: TAdOConnection;
  ReadOnly: Boolean);
begin
  inherited;
  display:=0;
  with DBGridEh do
  begin
    options:=options+[dgEditing]-[dgRowSelect];
  end;
  SelectFromSQL:='Select OnCheckBillLine.OncheckBillId,OnCheckBillLine.Receivestatus, '+
                        'OnCheckBillLine.BatchNo,'+
                        'OncheckBillLine.ItemCode+'' ''+Item.ItemName ItemFlag,'+
                        'OnCheckBillLine.QcLevel,'+
                        'OnCheckBillLine.ItemCode, '+
                        'OnCheckBillLine.OnCheckBillLineNo, '+
                        'Item.ItemName, '+
                        'Item.ItemClass1 ItemClass,'+
                        'Uom.UomName, '+
                        'OncheckBillLine.QcBatchNo,'+
                        'OnCheckBill.OnCheckBillNo, '+
                        'OnCheckBill.OnCheckDate, '+
                        'OnCheckBillLine.QcItem,'+
                        'OncheckBill.VendorCode,'+
                        'OnCheckBill.VendorCode+'' ''+v.VendorName Vendorflag,'+
                        'OnCheckBillLine.OnCheckQty, '+
                        'OnCheckBillLine.OnCheckStatus as OnCheckStatus, '+
                        'OnCheckBillLine.ReceivedQty as ReceivedQty, '+
                        'OnCheckBillLine.QcStatus as QcStatus, '+
                        'oncheckBill.VendorBillNo as  VendorBillNo ,'+
                        'OnCheckBillLine.QcRemArk as OnCheckRemArk '+
                   'From oncheckBillline '+
                        '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 ';
  OrderByFields:='BatchNo,VendorCode,OnCheckDate,ItemCode';
  ConditionUserDefine:='OnCheckType=1';
  with AdoQry_tmp do
  begin
    Close;
    sql.clear;
    sql.Add('select InvValuen from InvParam where InvParamCode=''oncheckfullin''' );
    open;
    display:=fieldbyname('InvValuen').asinteger;
    Close;
  end;
  if display=0 then
  begin
    toolbutton7.Visible:=False;
    Frm_Qc_CheckResult.DBGridEh.Columns[10].Visible :=False;
  end;
  Frm_Sys_Condition:=TFrm_Qc_CheckResult_C.Create(Application);
  Act_Filter.Execute ;
  act_Save.Enabled:=True;
  Frm_Qc_CheckResult.DBGridEh.Columns[9].ReadOnly:=True;
  Frm_Qc_CheckResult.DBGridEh.Columns[10].ReadOnly:=False;
end;

procedure TFrm_Qc_CheckResult.DBGridEhKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  inherited;
  if key=vk_return then keybd_event(Vk_tab,Vk_tab,0,0);
  if (lowercase(DBGridEh.selectedfield.Name)='AdoQry_MainQcstatus') and
     (key=vk_Space) then
  begin
    if  AdoQry_Main.fieldbyname('QcStatus').AsInteger<6 then
      with AdoQry_Main do
      begin
        edit;
        fieldbyname('Qcstatus').asinteger:=fieldbyname('Qcstatus').asinteger+1;
        post;
      end
      Else
      begin
        with AdoQry_Main do
        begin
          edit;
          fieldbyname('Qcstatus').asinteger:=0;
          post;
        end;
      end;
//  If AdoQry_Main.fieldbyname('Qcstatus').asinteger=2 then
//    AdoQry_MainOnCheckStatus.ReadOnly:=False
//  Else
//    AdoQry_MainOnCheckStatus.ReadOnly:=True;

{    If AdoQry_Main.fieldbyname('Qcstatus').asinteger=2 then
    begin
      with AdoQry_Main do
      begin
        edit;
        fieldbyname('OnCheckStatus').asinteger:=1;
        fieldbyname('ReceivedQty').asfloat:=0;
        post;
        AdoQry_MainReceivedQty.ReadOnly:=True;
      end;
    end
    Else
    begin
      with AdoQry_Main do
      begin
        edit;
        fieldbyname('OnCheckStatus').asinteger:=0;
        AdoQry_MainReceivedQty.ReadOnly:=False;
        post;
      end;
    end;
  end;
  if (lowercase(DBGridEh.selectedfield.Name)='AdoQry_Mainoncheckstatus') and
     (key=vk_Space) and (AdoQry_Main.fieldbyname('Qcstatus').AsInteger=2) then
  begin
    if (AdoQry_Main.fieldbyname('OnCheckStatus').AsInteger=0) then
    begin
      with AdoQry_Main do
      begin
        AdoQry_MainOnCheckStatus.ReadOnly:=False;
        edit;
        fieldbyname('OnCheckStatus').asinteger:=1;
        post;
      end;
    end;
}
  end;
end;

procedure TFrm_Qc_CheckResult.AdoQry_MainAfterInsert(DataSet: TDataSet);
begin
  inherited;
  AdoQry_Main.Cancel;
end;

procedure TFrm_Qc_CheckResult.AdoQry_MainBeforePost(DataSet: TDataSet);
begin
  inherited;
  if AdoQry_Main.fieldbyname('QcBatchNO').asstring<>'' then
  begin
    If not Check_QcBatchNo(AdoQry_Main.fieldbyname('QcBatchNo').asstring,
                       AdoQry_Main.fieldbyname('ItemCode').asstring,
                       AdoQry_Main.fieldbyname('VendorCode').asstring) then
    begin
      DispInfo('该控制号已经存在并不属于这个物料,请重新输入!',1);
      AdoQry_Main.edit;
      AdoQry_Main.fieldbyname('QcBatchNo').asstring:='';
      AdoQry_Main.fieldbyname('QcLevel').asstring:='';
      AdoQry_Main.fieldbyname('QcStatus').asstring:='0';
      AdoQry_Main.fieldbyname('ReceivedQty').asstring:='0';
      abort;
    end;
  end;
  If ((AdoQry_Main.fieldbyname('ReceivedQty').AsFloat<0) or
     (AdoQry_Main.fieldbyname('ReceivedQty').AsFloat>
      AdoQry_Main.fieldbyname('OnCheckQty').AsFloat)) and
      (Display=1)  then
  begin
    DispInfo('可入库数量不能大于到货数量,且不能小于零',1);
    //AdoQry_Main.Cancel;
    Abort;
  end;
  If (AdoQry_Main.fieldbyname('QcStatus').AsFloat<>0)and
     (AdoQry_Main.fieldbyname('QcBatchNo').AsString='')then
  begin
    DispInfo('质检控制号不能为空!',1);
    AdoQry_Main.fieldbyname('QcBatchNo').asstring:='';
    AdoQry_Main.fieldbyname('QcLevel').asstring:='';
    AdoQry_Main.fieldbyname('QcStatus').asstring:='0';
    AdoQry_Main.fieldbyname('ReceivedQty').asstring:='0';
    abort;
  end;
  IF (AdoQry_Main.fieldbyname('QcStatus').AsFloat=2)then
  begin
    AdoQry_Main.edit;
    AdoQry_Main.fieldbyname('OnCheckStatus').Asinteger:=1;
    AdoQry_Main.fieldbyname('ReceivedQty').AsFloat:=0;
  end
  else
  begin
    AdoQry_Main.edit;
    AdoQry_Main.fieldbyname('OnCheckStatus').Asinteger:=0; //如果不是拒收,则是否为没有检验
  end;
end;

procedure TFrm_Qc_CheckResult.DBGridEhExit(Sender: TObject);
begin
  inherited;
   if AdoQry_Main.state<>dsBrowse then       //如果当前用户改变了Grid中的值,还没有Post,主动Post
           AdoQry_Main.post;
end;

procedure TFrm_Qc_CheckResult.FormActivate(Sender: TObject);
begin
  inherited;
  if display<>1 then
    toolbutton7.left:=toolbutton6.left+toolbutton6.Width ;
  act_Save.Enabled:=True;
  DbGridEh.SetFocus;
end;

procedure TFrm_Qc_CheckResult.FormCreate(Sender: TObject);
begin
  inherited;
  TlBtn_Copy.Action:=act_Save;
end;

procedure TFrm_Qc_CheckResult.Act_SaveExecute(Sender: TObject);
var
  i:integer;
begin
  inherited;
  If AdoQry_Main.State<>dsBrowse then
  AdoQry_Main.Post;

  AdoQry_MainBeforePost(AdoQry_Main);
  AdoQry_Main.First;
  For I:=0 to AdoQry_Main.RecordCount-1 do
  begin
    If (AdoQry_Main.fieldbyname('Qcstatus').asstring<>'0') Then
    begin
      If AdoQry_Main.fieldbyname('QcStatus').asInteger<>2 then
        begin
          If ((AdoQry_Main.fieldbyname('ReceivedQty').AsFloat<=0) or
             (AdoQry_Main.fieldbyname('ReceivedQty').AsFloat>
              AdoQry_Main.fieldbyname('OnCheckQty').AsFloat)) And
              (Display=1) then
          begin
            DispInfo('可入库数量不能大于到货数量,且不能小于零',1);
            Abort;
          end;
        end
      Else
      begin
        AdoQry_Main.Edit;
        AdoQry_Main.fieldbyname('ReceivedQty').Value:=0;
      end;

      If AdoQry_Main.fieldbyname('QcBatchNo').asstring='' then
      begin
        DispInfo('质检判定后必须有质检控制号!',1);
        Abort;
      end;
    end;

    AdoQry_Main.next;
  end;

  AdoQry_Main.First;
  AdoQry_Tmp.Connection.beginTrans;
  Try
    For I:=0 to AdoQry_Main.RecordCount-1 do
    begin
      If AdoQry_Main.fieldbyname('QcStatus').asInteger<>0 then
      begin
        With AdoQry_Tmp do
        begin
          Close;
          Sql.Text:='select oncheckstatus '+
                            'from oncheckBillline '+
                            ' Where OnCheckBillId='+
                                    AdoQry_Main.fieldbyname('OnCheckBillId').asstring+
                                    ' and oncheckBilllineno='+AdoQry_Main.fieldbyname('oncheckBilllineno').asstring+
                                    ' and oncheckstatus=0 ';
          Open;
          If Not Eof then
            Save_Check;
        end;
      end;
      AdoQry_Main.next;
    end;
    AdoQry_Tmp.Connection.CommitTrans;
//    DBGridEh.ReadOnly:=True;
    act_Save.Enabled :=False;
    AdoQry_Main.First;
  Except
    AdoQry_Tmp.Connection.RollBackTrans;
    DispInfo('保存失败!请稍候再试!',1);
    abort;
  end;
  DBGridEh.Columns[10].ReadOnly:=False;
end;

function TFrm_Qc_CheckResult.Save_Check: Boolean;
var
  WarehouseCode,WhPositionCode,PoNo,PoLineNo :String;
begin
  With AdoQry_Tmp do  //保留历史记录
  begin
    Close;
    Sql.text:='Insert OnCheckBillLineHistory(OnCheckBillId,OnCheckBillLineNo,ItemCode,OnCheckQty,ReceivedQty,'+
                     'QcStatus,OnCheckStatus,POLineNo,BillLineRemArk,BatchNo,chgtime,chgEmployeeCode,chgType) '+
                        ' Select OnCheckBillId,OnCheckBillLineNo,ItemCode,OnCheckQty,ReceivedQty,'+
                                    'QcStatus,OnCheckStatus,POLineNo,BillLineRemArk,BatchNo,'+
                                    'Getdate(),'+QuotedStr(userCode)+
                                    ',''质检判定'' '+
                                    'From oncheckBillline '+
                                    'Where OnCheckBillId='+
                                           AdoQry_Main.fieldbyname('OnCheckBillId').asstring+
                                          'And oncheckBilllineno='+AdoQry_Main.fieldbyname('oncheckBilllineno').asstring;
    Execsql;
  end;

  If AdoQry_Main.fieldbyname('QcStatus').AsFloat<>2 then  //质量状态不等于拒收
  begin
    AdoQry_Tmp.Close;
    AdoQry_Tmp.Sql.clear;
    If Display=0 then//全部入库处理
       AdoQry_Tmp.Sql.Add('Update OnCheckBillLine '+
                                 ' Set ReceivedQty=OnCheckQty,'+
                                      ' QcStatus='+AdoQry_Main.fieldbyname('QcStatus').AsString+','+
                                      ' QcBatchNo='''+AdoQry_Main.fieldbyname('QcBatchNo').AsString+''','+

⌨️ 快捷键说明

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