unit U_JYResult;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, DB, ADODB, Buttons, ExtCtrls;

type
  TfrmJYResult = class(TForm)
    Label1: TLabel;
    KZ1: TEdit;
    KZ2: TEdit;
    KZ3: TEdit;
    KZ4: TEdit;
    KZ5: TEdit;
    Label2: TLabel;
    HD1: TEdit;
    HD2: TEdit;
    HD3: TEdit;
    HD4: TEdit;
    HD5: TEdit;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    XSWater: TComboBox;
    Label6: TLabel;
    QiWei: TComboBox;
    Button1: TButton;
    Button2: TButton;
    ADOQueryCmd: TADOQuery;
    ADOQueryTemp: TADOQuery;
    Panel3: TPanel;
    SpeedButton1: TSpeedButton;
    SpeedButton2: TSpeedButton;
    SpeedButton3: TSpeedButton;
    SpeedButton4: TSpeedButton;
    SpeedButton5: TSpeedButton;
    SpeedButton6: TSpeedButton;
    SpeedButton7: TSpeedButton;
    SpeedButton8: TSpeedButton;
    SpeedButton9: TSpeedButton;
    SpeedButton10: TSpeedButton;
    SpeedButton11: TSpeedButton;
    SpeedButton12: TSpeedButton;
    Label7: TLabel;
    SeLD: TComboBox;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormDestroy(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure KZ1Click(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure SpeedButton12Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure KZ2Click(Sender: TObject);
    procedure KZ3Click(Sender: TObject);
    procedure KZ4Click(Sender: TObject);
    procedure KZ5Click(Sender: TObject);
    procedure HD1Click(Sender: TObject);
    procedure HD2Click(Sender: TObject);
    procedure HD3Click(Sender: TObject);
    procedure HD4Click(Sender: TObject);
    procedure HD5Click(Sender: TObject);
  private
    Fint:Integer;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmJYResult: TfrmJYResult;

implementation
uses
U_DataLink,U_Fun,U_iniParam;

{$R *.dfm}

procedure TfrmJYResult.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  DataLink_WFBProducttion.ADOLink.Connected:=False;
  Action:=caFree;
end;

procedure TfrmJYResult.FormDestroy(Sender: TObject);
begin
  frmJYResult:=nil;
end;

procedure TfrmJYResult.Button1Click(Sender: TObject);
var
  MJIDInt:Integer;
  maxno,maxno10,maxno20,FBanZu:String;
begin
  if( (Trim(KZ1.Text)<>'') and  (Trim(KZ2.Text)<>'') and (Trim(KZ3.Text)<>'') and
     (Trim(KZ4.Text)<>'') and  (Trim(KZ5.Text)<>'') )=False    then
  begin
    Application.MessageBox('克重数据不全！','提示',0);
    Exit;
  end;
  if( (Trim(HD1.Text)<>'') and  (Trim(HD2.Text)<>'') and (Trim(HD3.Text)<>'') and
     (Trim(HD4.Text)<>'') and  (Trim(HD5.Text)<>'') )=False    then
  begin
    Application.MessageBox('厚度数据不全！','提示',0);
    Exit;
  end;
  if Trim(XSWater.Text)='' then
  begin
    Application.MessageBox('吸水不能为空！','提示',0);
    Exit;
  end;
  if Trim(QiWei.Text)='' then
  begin
    Application.MessageBox('气味不能为空！','提示',0);
    Exit;
  end;
  if Trim(SeLD.Text)='' then
  begin
    Application.MessageBox('色牢度不能为空！','提示',0);
    Exit;
  end;
  DataLink_WFBProducttion.ADOLink.Connected:=False;
  DataLink_WFBProducttion.ADOLink.Connected:=True;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    SQL.Add('select * from WFB_MJJY where Cast(MJID as int)=');
    sql.Add('(select Max(Cast(MJID as int) ) from WFB_JYResult');
    if Trim(SCXFlag)<>'' then
    begin
      sql.Add(' where JTType='''+Trim(SCXFlag)+'''');
    end;
    sql.Add(')');
    if Trim(SCXFlag)<>'' then
    begin
      sql.Add(' and JTType='''+Trim(SCXFlag)+'''');
    end;
    Open;
  end;
  if ADOQueryTemp.IsEmpty then
  begin
    with ADOQueryCmd do
    begin
      close;
      SQL.Clear;
      SQL.Add('select Top 1* from WFB_JYResult');
      if Trim(SCXFlag)<>'' then
      begin
        sql.Add(' where JTType='''+Trim(SCXFlag)+'''');
      end;
      Open;
    end;
    if ADOQueryCmd.IsEmpty=False then
    begin
      Application.MessageBox('上卷未打印标签，不能越卷检验！','提示',0);
      Exit;
    end;
  end;
  if Application.MessageBox('确定要执行操作吗？确定后数据将不能修改！','提示',32+4)<>IDYES then Exit;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select isnull(Max(Cast(MJID as int)),0) MJIDInt from WFB_MJJY');
    if Trim(SCXFlag)<>'' then
    begin
      sql.Add(' where JTType='''+Trim(SCXFlag)+'''');
    end;
    Open;
  end;
 // 112091201   20120914
  MJIDInt:=ADOQueryTemp.fieldbyname('MJIDInt').Value;
  maxno10:=Trim(FormatDateTime('yyyyMMdd',SGetServerDateTime(ADOQueryTemp)));
  maxno10:=Trim(SCXFlag)+Trim(Copy(maxno10,3,6));
  maxno20:=IntToStr(MJIDInt);
  maxno20:=Copy(maxno20,1,7);
  try
    ADOQueryCmd.Connection.BeginTrans;
    if MJIDInt>0 then
    begin
      if StrToInt(maxno10)>StrToInt(maxno20) then
      begin
        if GetLSNo(ADOQueryCmd,maxno,Trim(SCXFlag),'WFB_MJJY',2,1)=False then
        begin
          ADOQueryCmd.Connection.RollbackTrans;
          Application.MessageBox('取检验最大号失败！','提示',0);
          Exit;
        end;
      end else
        maxno:=Trim(IntToStr(MJIDInt+1))
    end else
    begin
      with ADOQueryTemp do
      begin
        Close;
        SQL.Clear;
        SQL.Add('select * from WFB_JB ');
        Open;
      end;
      if ADOQueryTemp.IsEmpty then
      begin
        if GetLSNo(ADOQueryCmd,maxno,Trim(SCXFlag),'WFB_MJJY',2,1)=False then
        begin
          ADOQueryCmd.Connection.RollbackTrans;
          Application.MessageBox('取检验最大号失败！','提示',0);
          Exit;
        end;
      end else
      begin
        maxno:=Trim(ADOQueryTemp.fieldbyname('MJID').AsString);
      end;
    end;
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from WFB_JYResult where MJID='''+Trim(maxno)+'''');
      Open;
    end;
    if ADOQueryTemp.IsEmpty=False then
    begin
      ADOQueryCmd.Connection.RollbackTrans;
      Application.MessageBox('已经检验！','提示',0);
      Exit;
    end;
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      SQL.Add('select * from SY_User where UserId='''+Trim(DCode)+'''');
      Open;
    end;
    FBanZu:=Trim(ADOQueryTemp.fieldbyname('BanZu').AsString);
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from WFB_JYResult where 1<>1');
      Open;
    end;
    with ADOQueryCmd do
    begin
      Append;
      FieldByName('MJID').Value:=Trim(maxno);
      FieldByName('Filler').Value:=Trim(DName);
      FieldByName('BanZu').Value:=Trim(FBanZu);
      FieldByName('KZ1').Value:=Trim(KZ1.Text);
      FieldByName('KZ2').Value:=Trim(KZ2.Text);
      FieldByName('KZ3').Value:=Trim(KZ3.Text);
      FieldByName('KZ4').Value:=Trim(KZ4.Text);
      FieldByName('KZ5').Value:=Trim(KZ5.Text);
      FieldByName('HD1').Value:=Trim(HD1.Text);
      FieldByName('HD2').Value:=Trim(HD2.Text);
      FieldByName('HD3').Value:=Trim(HD3.Text);
      FieldByName('HD4').Value:=Trim(HD4.Text);
      FieldByName('HD5').Value:=Trim(HD5.Text);
      FieldByName('XSWater').Value:=Trim(XSWater.Text);
      FieldByName('QiWei').Value:=Trim(QiWei.Text);
      FieldByName('SeLD').Value:=Trim(SeLD.Text);
      if Trim(SCXFlag)<>'' then
      begin
        FieldByName('JTType').Value:=Trim(SCXFlag);
      end;
      Post;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    //Application.MessageBox('检验成功！','提示',0);
    Exit;
  except
    DataLink_WFBProducttion.ADOLink.Connected:=False;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('检验异常！','提示',0);
  end;
  DataLink_WFBProducttion.ADOLink.Connected:=False;
end;

procedure TfrmJYResult.Button2Click(Sender: TObject);
begin
  Close;
end;

procedure TfrmJYResult.KZ1Click(Sender: TObject);
begin
  Fint:=1;
end;

procedure TfrmJYResult.SpeedButton1Click(Sender: TObject);
begin
  if Fint=1 then
  begin
    KZ1.Text:=Trim(KZ1.Text)+Trim(TSpeedButton(Sender).Caption);
    KZ1.SelectAll;
  end else
  if Fint=2 then
  begin
    KZ2.Text:=Trim(KZ2.Text)+Trim(TSpeedButton(Sender).Caption);
    KZ2.SelectAll;
  end else
  if Fint=3 then
  begin
    KZ3.Text:=Trim(KZ3.Text)+Trim(TSpeedButton(Sender).Caption);
    KZ3.SelectAll;
  end else
  if Fint=4 then
  begin
    KZ4.Text:=Trim(KZ4.Text)+Trim(TSpeedButton(Sender).Caption);
    KZ4.SelectAll;
  end else
  if Fint=5 then
  begin
    KZ5.Text:=Trim(KZ5.Text)+Trim(TSpeedButton(Sender).Caption);
    KZ5.SelectAll;
  end else
  if Fint=6 then
  begin
    HD1.Text:=Trim(HD1.Text)+Trim(TSpeedButton(Sender).Caption);
    HD1.SelectAll;
  end else
  if Fint=7 then
  begin
    HD2.Text:=Trim(HD2.Text)+Trim(TSpeedButton(Sender).Caption);
    HD2.SelectAll;
  end else
  if Fint=8 then
  begin
    HD3.Text:=Trim(HD3.Text)+Trim(TSpeedButton(Sender).Caption);
    HD3.SelectAll;
  end else
  if Fint=9 then
  begin
    HD4.Text:=Trim(HD4.Text)+Trim(TSpeedButton(Sender).Caption);
    HD4.SelectAll;
  end else
  if Fint=10 then
  begin
    HD5.Text:=Trim(HD5.Text)+Trim(TSpeedButton(Sender).Caption);
    HD5.SelectAll;
  end;
end;

procedure TfrmJYResult.SpeedButton12Click(Sender: TObject);
begin
  if Fint=1 then
  begin
    if Trim(KZ1.Text)<>'' then
    begin
      KZ1.Text:=Copy(Trim(KZ1.Text),1,Length(Trim(KZ1.Text))-1);
      KZ1.SelectAll;
    end;
  end else
  if Fint=2 then
  begin
    if Trim(KZ2.Text)<>'' then
    begin
      KZ2.Text:=Copy(Trim(KZ2.Text),1,Length(Trim(KZ2.Text))-1);
      KZ2.SelectAll;
    end;
  end else
  if Fint=3 then
  begin
    if Trim(KZ3.Text)<>'' then
    begin
      KZ3.Text:=Copy(Trim(KZ3.Text),1,Length(Trim(KZ3.Text))-1);
      KZ3.SelectAll;
    end;
  end else
  if Fint=4 then
  begin
    if Trim(KZ4.Text)<>'' then
    begin
      KZ4.Text:=Copy(Trim(KZ4.Text),1,Length(Trim(KZ4.Text))-1);
      KZ4.SelectAll;
    end;
  end else
  if Fint=5 then
  begin
    if Trim(KZ5.Text)<>'' then
    begin
      KZ5.Text:=Copy(Trim(KZ5.Text),1,Length(Trim(KZ5.Text))-1);
      KZ5.SelectAll;
    end;
  end else
  if Fint=6 then
  begin
    if Trim(HD1.Text)<>'' then
    begin
      HD1.Text:=Copy(Trim(HD1.Text),1,Length(Trim(HD1.Text))-1);
      HD1.SelectAll;
    end;
  end else
  if Fint=7 then
  begin
    if Trim(HD2.Text)<>'' then
    begin
      HD2.Text:=Copy(Trim(HD2.Text),1,Length(Trim(HD2.Text))-1);
      HD2.SelectAll;
    end;
  end else
  if Fint=8 then
  begin
    if Trim(HD3.Text)<>'' then
    begin
      HD3.Text:=Copy(Trim(HD3.Text),1,Length(Trim(HD3.Text))-1);
      HD3.SelectAll;
    end;
  end else
  if Fint=9 then
  begin
    if Trim(HD4.Text)<>'' then
    begin
      HD4.Text:=Copy(Trim(HD4.Text),1,Length(Trim(HD4.Text))-1);
      HD4.SelectAll;
    end;
  end else
  if Fint=10 then
  begin
    if Trim(HD5.Text)<>'' then
    begin
      HD5.Text:=Copy(Trim(HD5.Text),1,Length(Trim(HD5.Text))-1);
      HD5.SelectAll;
    end;
  end;
end;

procedure TfrmJYResult.FormShow(Sender: TObject);
begin
  Fint:=1;
  KZ1.SetFocus;
end;

procedure TfrmJYResult.KZ2Click(Sender: TObject);
begin
  Fint:=2;
end;

procedure TfrmJYResult.KZ3Click(Sender: TObject);
begin
  Fint:=3;
end;

procedure TfrmJYResult.KZ4Click(Sender: TObject);
begin
  Fint:=4;
end;

procedure TfrmJYResult.KZ5Click(Sender: TObject);
begin
  Fint:=5;
end;

procedure TfrmJYResult.HD1Click(Sender: TObject);
begin
  Fint:=6;
end;

procedure TfrmJYResult.HD2Click(Sender: TObject);
begin
  Fint:=7;
end;

procedure TfrmJYResult.HD3Click(Sender: TObject);
begin
  Fint:=8;
end;

procedure TfrmJYResult.HD4Click(Sender: TObject);
begin
  Fint:=9;
end;

procedure TfrmJYResult.HD5Click(Sender: TObject);
begin
  Fint:=10;
end;

end.
