unit U_MJManageNewFDNewLable;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
  cxDataStorage, cxEdit, DB, cxDBData, cxCalendar, cxGridLevel,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxClasses,
  cxControls, cxGridCustomView, cxGrid, RM_Common, RM_Class, RM_GridReport,
  RM_System, RM_Dataset, ADODB, DBClient, cxGridCustomPopupMenu,
  cxGridPopupMenu, ExtCtrls, ComCtrls, ToolWin, cxTextEdit, Buttons,
  cxSplitter, cxCheckBox, MovePanel, RM_Preview;
{function CommOpen(fhandle:hwnd;sCommName:PAnsiChar;
                    IntTime:integer):integer;stdcall;external 'JCYData.DLL';
function CommClose(sCommName:PAnsiChar):integer;stdcall;external 'JCYData.DLL';
  function CommOpen(fhandle:hwnd;sCommName:PAnsiChar;
                    IntTime:integer;IsMessage:integer):integer;stdcall;external 'JCYData.DLL';
  function CommClose(sCommName:PAnsiChar):integer;stdcall;external 'JCYData.DLL';}
  {function CommOpen(fhandle:hwnd;sCommName:PAnsiChar;
                    IntTime:integer;IsMessage:integer):integer;stdcall;external 'JZCRS323C.DLL';
  function CommClose(sCommName:PAnsiChar):integer;stdcall;external 'JZCRS323C.DLL';

  function GetCommData(fhandle:hwnd;var defnum1,defnum2:double;var fisjz:integer):integer;stdcall;external 'JZCRS323C.DLL'; }


type
  TfrmMJManageNewFDNewLable = class(TForm)
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    cxStyle2: TcxStyle;
    cxGridPopupMenu1: TcxGridPopupMenu;
    DataSource1: TDataSource;
    Order_MJ: TClientDataSet;
    ADOQueryMain: TADOQuery;
    ADOCmd: TADOQuery;
    ADOTmp: TADOQuery;
    RMDB_Main: TRMDBDataSet;
    RM2: TRMGridReport;
    cxGrid3: TcxGrid;
    Tv3: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    DataSource2: TDataSource;
    CDS_MJCD: TClientDataSet;
    DataSource3: TDataSource;
    CDS_MJID: TClientDataSet;
    Timer1: TTimer;
    ADOQueryPrint: TADOQuery;
    cxStyleRepository2: TcxStyleRepository;
    cxStyle3: TcxStyle;
    cxStyleRepository3: TcxStyleRepository;
    cxStyle4: TcxStyle;
    cxStyleRepository4: TcxStyleRepository;
    cxStyle5: TcxStyle;
    cxStyleRepository5: TcxStyleRepository;
    cxStyle6: TcxStyle;
    cxGridPopupMenu2: TcxGridPopupMenu;
    ADOQueryMainDSC: TADOQuery;
    Panel2: TPanel;
    Label9: TLabel;
    MJFK: TEdit;
    Label3: TLabel;
    MJLen: TEdit;
    Label4: TLabel;
    MJMaoZ: TEdit;
    Label5: TLabel;
    Label6: TLabel;
    Label11: TLabel;
    BTPrint: TButton;
    Button5: TButton;
    Edit3: TEdit;
    Label10: TLabel;
    Edit4: TEdit;
    Label12: TLabel;
    Label13: TLabel;
    Label14: TLabel;
    MJQty1: TEdit;
    Label15: TLabel;
    Label22: TLabel;
    Label23: TLabel;
    MJSJKZ: TEdit;
    v3Column1: TcxGridDBColumn;
    v3Column2: TcxGridDBColumn;
    v3Column3: TcxGridDBColumn;
    Label27: TLabel;
    MJQty2: TEdit;
    Label28: TLabel;
    Edit5: TEdit;
    Label26: TLabel;
    Edit6: TEdit;
    Label29: TLabel;
    MJstr3: TEdit;
    Label30: TLabel;
    MJQty3: TEdit;
    Label31: TLabel;
    Label32: TLabel;
    MJQty4: TEdit;
    Label33: TLabel;
    Panel4: TPanel;
    Panel5: TPanel;
    Panel6: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    Label16: TLabel;
    Label24: TLabel;
    Label25: TLabel;
    APID: TEdit;
    BTAdd: TButton;
    BTEdit: TButton;
    ToolBar1: TToolBar;
    ToolButton1: TToolButton;
    TBCD: TToolButton;
    TBClose: TToolButton;
    Panel7: TPanel;
    Button3: TButton;
    Label34: TLabel;
    ComboBox1: TComboBox;
    Edit7: TEdit;
    Label35: TLabel;
    v3Column4: TcxGridDBColumn;
    Label36: TLabel;
    Edit8: TEdit;
    ToolButton2: TToolButton;
    Panel1: TPanel;
    BZNote: TRichEdit;
    RMPreview1: TRMPreview;
    ADOQueryLabel: TADOQuery;
    RMGridReport1: TRMGridReport;
    MJLenMa: TEdit;
    DuoPinNote: TEdit;
    ZSUnit: TComboBox;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure Tv2CellClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure TBCDClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Tv2CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure MJBanZuClick(Sender: TObject);
    procedure MJSJKZClick(Sender: TObject);
    procedure Tv1CellClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure Tv3CellClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure FormClick(Sender: TObject);
    procedure Button12Click(Sender: TObject);
    procedure BTAddClick(Sender: TObject);
    procedure BTEditClick(Sender: TObject);
    procedure BTPrintClick(Sender: TObject);
    procedure Tv2CDQtyPropertiesEditValueChanged(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure SpeedButton12Click(Sender: TObject);
    procedure SpeedButton13Click(Sender: TObject);
    procedure cxGridDBColumn2PropertiesChange(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure APIDKeyPress(Sender: TObject; var Key: Char);
    procedure MJLenMaClick(Sender: TObject);
    procedure Edit2Change(Sender: TObject);
    procedure Edit3Click(Sender: TObject);
    procedure Edit4Click(Sender: TObject);
    procedure Edit5Click(Sender: TObject);
    procedure Edit6Click(Sender: TObject);
    procedure MJstr3KeyPress(Sender: TObject; var Key: Char);
    procedure MJQty3Exit(Sender: TObject);
    procedure MJMaoZExit(Sender: TObject);
    procedure Label9Click(Sender: TObject);
    procedure MJLenExit(Sender: TObject);
    procedure MJQty4Exit(Sender: TObject);
    procedure MJQty4Change(Sender: TObject);
    procedure MJMaoZChange(Sender: TObject);
    procedure APIDClick(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure MJFKChange(Sender: TObject);
    procedure Edit7Click(Sender: TObject);
    procedure BTPrintKeyPress(Sender: TObject; var Key: Char);
    procedure MJQty4KeyPress(Sender: TObject; var Key: Char);
    procedure MJQty2KeyPress(Sender: TObject; var Key: Char);
    procedure MJLenKeyPress(Sender: TObject; var Key: Char);
    procedure MJMaoZKeyPress(Sender: TObject; var Key: Char);
    procedure Edit8Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure MJLenChange(Sender: TObject);
    procedure MJQty2Change(Sender: TObject);
  private
    { Private declarations }
    FInt,PState,PrintInt,SCInitGrid,FState,FCK:Integer;
    FColumn,FBanZu,FAPID,FMainId,FSubId,FFFMJID,KgZMiXS,KgZMaXS:String;
    MValue,FCDName:String;
    procedure InitJP();
    procedure InitCDGrid();
    procedure InitCDGridID();
    procedure AddCD(Fbtn:TButton);
    procedure AddSL(Fbtn:TButton);
    function  SaveData():Boolean;
    procedure BtnStatus(BSInt:Boolean);
    procedure AddSLNew(Fbtn:TSpeedButton);
    procedure AddCDNew(Fbtn:TSpeedButton);
    procedure SavedataCK();
    procedure PrtData(FMJID:String);
    procedure On1201(Var Message:Tmessage);Message 1201;
  public
    { Public declarations }

  end;

var
  frmMJManageNewFDNewLable: TfrmMJManageNewFDNewLable;

implementation
uses
  U_DataLink,U_RTFun,U_ZDYHelp,U_iniParam,U_OrderInPut;

{$R *.dfm}

procedure TfrmMJManageNewFDNewLable.FormDestroy(Sender: TObject);
begin
  frmMJManageNewFDNewLable:=nil;
end;
procedure TfrmMJManageNewFDNewLable.On1201(Var Message:Tmessage);
var
  i1,i2:integer;
  unitname:string;
  fdata:double;
begin
  i1:=message.WParam;
  i2:=message.LParam;

  //Edit1.Text:= floattostr(i1 *i2 /100000 );
  MJMaoZ.Text:= floattostr(i1 *i2 /100000 );
end;

procedure TfrmMJManageNewFDNewLable.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  //DataLink_WFBProducttion.ADOLink.Connected:=False;
  Action:=caFree;
  {if FCK=9 then
  begin
    CommClose(pchar(PortNoStr));
  end; }

end;
procedure TfrmMJManageNewFDNewLable.InitCDGrid();
begin
  with ADOQueryMain do
  begin
    Close;
    SQL.Clear;
    if PState=1 then
      sql.Add('select * from WFB_MJJY_CD where MJID='''' ')
    else
      sql.Add('select * from WFB_MJJY_CD where MJID='''+Trim(CDS_MJID.fieldbyname('MJID').AsString)+'''');
    Open;
  end;
  SCreateCDS20(ADOQueryMain,CDS_MJCD);
  SInitCDSData20(ADOQueryMain,CDS_MJCD);
end;
procedure TfrmMJManageNewFDNewLable.InitCDGridID();
begin
  with ADOQueryMain do
  begin
    Close;
    SQL.Clear;
    sql.Add('select ');
    sql.Add('Case when isnull(MJType,'''')=''次品'' then ''B''+RTrim(Cast(MJXH as varchar(20))) else Cast(MJXH as varchar(20)) end as MJXH ');
    sql.Add(', A.* from WFB_MJJY A where APID='''+Trim(FAPID)+'''');
    {if Trim(SCXFlag)<>'' then
      sql.Add(' and JTType='''+Trim(SCXFlag)+'''');  }
    Open;
  end;
  SCreateCDS20(ADOQueryMain,CDS_MJID);
  SInitCDSData20(ADOQueryMain,CDS_MJID);
end;

procedure TfrmMJManageNewFDNewLable.TBCloseClick(Sender: TObject);
var
  maxno:string;
begin
  if CDS_MJCD.IsEmpty=False then
  begin
    if Trim(CDS_MJCD.FieldByName('MCID').AsString)='' then
    begin
      //try
        //ADOCmd.Connection.BeginTrans;
        {with ADOCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('delete from WFB_MJJY_CD_Temp where JTType='''+Trim(SCXFlag)+'''');
          Execsql;
        end;
        with CDS_MJCD do
        begin
          First;
          while not Eof do
          begin
            if GetLSNo(ADOCmd,maxno,'LS','WFB_MJJY_CD_Temp',2,1)=False then
            begin
             // ADOCmd.Connection.RollbackTrans;
              Application.MessageBox('取疵点临时最大号失败！','提示',0);
              Exit;
            end;
            with ADOCmd do
            begin
              Close;
              sql.Clear;
              sql.Add('select * from WFB_MJJY_CD_Temp where 1<>1');
              Open;
            end;
            with ADOCmd do
            begin
              Append;
              FieldByName('MCID').Value:=Trim(maxno);
              SSetSaveDataCDSNew(ADOCmd,Tv2,CDS_MJCD,'WFB_MJJY_CD_Temp',0);
              FieldByName('JTType').Value:=Trim(SCXFlag);
              Post;
            end;
            Next;
          end;
        end; }
        close;
        //ADOCmd.Connection.CommitTrans;
        //ModalResult:=1;
      //except
        //ADOCmd.Connection.RollbackTrans;
        //Application.MessageBox('保存临时表失败！','提示',0);
      //end;
    end else
    begin
      Close;
    end;
  end else
  begin
    Close;
  end;



end;

procedure TfrmMJManageNewFDNewLable.Tv2CellClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
var
  fsj:string;
begin
  //FInt:=0;
  //Tv1.DataController.FocusedRecordIndex;
  //fsj:=Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName;
end;

procedure TfrmMJManageNewFDNewLable.TBCDClick(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='WFBCD';
      flagname:='疵点';
      fnote:=True;
      V1Note.Caption:='英文名称';
      if ShowModal=1 then
      begin
        Self.InitJP();
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmMJManageNewFDNewLable.FormShow(Sender: TObject);
begin
  //InitJP();
  {with ADOTmp do
  begin
    Close;
    sql.Clear;
    sql.Add('select BanZu from SY_User where UserId='''+Trim(DCode)+'''');
    Open;
    FBanZu:=Trim(Fieldbyname('BanZu').AsString);
  end; }
  {if Trim(FBanZu)='' then
  begin
    Application.MessageBox('班组为空，请设置班组！','提示',0);
    Exit;
  end;  }
  APID.SetFocus;
  {if CommOpen(frmMJManageNewFDNewSF.Handle,pchar(PortNoStr),500,1)<1 then
  begin
    FCK:=1;
    showmessage('串口打开失败!');
  end else
  begin
    FCk:=9;
  end; }
  if IsINIFile() then
    ReadINIFile()
end;
procedure TfrmMJManageNewFDNewLable.InitJP();
var
  AA:array[0..100] of string;
  i,j:Integer;
begin
  
end;

procedure TfrmMJManageNewFDNewLable.AddCD(Fbtn:TButton);
begin
  if PState<1 then Exit;
  if Order_MJ.IsEmpty then Exit;
  with CDS_MJCD do
  begin
    Append;
    FieldByName('cdname').Value:=Trim(TButton(Fbtn).Caption);
    Post;
  end;
end;
procedure TfrmMJManageNewFDNewLable.AddCDNew(Fbtn:TSpeedButton);
begin
  with CDS_MJCD do
  begin
    Append;
    FieldByName('cdname').Value:=Trim(TSpeedButton(Fbtn).Hint);
    Post;
  end;
end;
procedure TfrmMJManageNewFDNewLable.AddSL(Fbtn:TButton);
begin
  
end;
procedure TfrmMJManageNewFDNewLable.AddSLNew(Fbtn:TSpeedButton);
begin
  
end;

procedure TfrmMJManageNewFDNewLable.Tv2CellDblClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  //if Tv2.OptionsSelection.CellSelect=True then
  if CDS_MJCD.IsEmpty then Exit;

  if Trim(CDS_MJCD.fieldbyname('MCID').AsString)='' then
  begin
    if Application.MessageBox('确定要删除数据吗？','提示',32+4)<>IDYES then Exit;
    CDS_MJCD.Delete;
  end;

end;

procedure TfrmMJManageNewFDNewLable.MJBanZuClick(Sender: TObject);
begin
  FInt:=4;
end;

procedure TfrmMJManageNewFDNewLable.MJSJKZClick(Sender: TObject);
begin
  FInt:=4;
end;

procedure TfrmMJManageNewFDNewLable.Tv1CellClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  //DataLink_WFBProducttion.ADOLink.Connected:=False;
  FInt:=4;
 // if PState=1 then Exit;
  InitCDGridID();
  //InitCDGrid();
  {with ADOTmp do
  begin
    close;
    sql.Clear;
    sql.Add('select * from WFB_MJJY where MJID='''+Trim(CDS_MJID.fieldbyname('MJID').AsString)+'''');
    Open;
  end;
  if ADOTmp.IsEmpty then
  begin
    MJMaoZ.Text:='';
    MJLen.Text:='';
    MJFK.Text:='';
    MJSJKZ.Text:='';
  end else
    SSetWinData(ADOTmp,Panel5); }
end;

procedure TfrmMJManageNewFDNewLable.Tv3CellClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  if CDS_MJCD.IsEmpty=False then
  begin
    if Trim(CDS_MJCD.fieldbyname('MJID').AsString)='' then
    begin
      Application.MessageBox('数据未保存,不能浏览数据!','提示',0);
      Exit;
    end;
  end;

  FInt:=4;
  PState:=0;
  InitCDGrid();
  with ADOTmp do
  begin
    close;
    sql.Clear;
    sql.Add('select * from WFB_MJJY where MJID='''+Trim(CDS_MJID.fieldbyname('MJID').AsString)+'''');
    Open;
  end;
  MJFK.Text:=Trim(ADOTmp.fieldbyname('MJFK').AsString);
  MJSJKZ.Text:=Trim(ADOTmp.fieldbyname('MJSJKZ').AsString);

  MJQty1.Text:=Trim(ADOTmp.fieldbyname('MJQty1').AsString);
  MJQty2.Text:=Trim(ADOTmp.fieldbyname('MJQty2').AsString);
  MJMaoZ.Text:=Trim(ADOTmp.fieldbyname('MJMaoZ').AsString);
  DuoPinNote.Text:=Trim(ADOTmp.fieldbyname('DuoPinNote').AsString);
  ZSUnit.Text:=Trim(ADOTmp.fieldbyname('ZSUnit').AsString);
  Label15.Caption:=Trim(CDS_MJID.fieldbyname('MJID').AsString);
  MJLen.Text:=Trim(ADOTmp.fieldbyname('MJLen').AsString);
  if Trim(ADOTmp.fieldbyname('MJType').AsString)='正品' then
  begin
    Edit3.Text:='√';
    Edit4.Text:='';
    Edit5.Text:='';
  end else
  if Trim(ADOTmp.fieldbyname('MJType').AsString)='次品' then
  begin
    Edit4.Text:='√';
    Edit3.Text:='';
    Edit5.Text:='';
  end else
  if Trim(ADOTmp.fieldbyname('MJType').AsString)='留样' then
  begin
    Edit4.Text:='';
    Edit3.Text:='';
    Edit5.Text:='√';
  end;
  BtnStatus(False);
  Label16.Caption:='';
end;


procedure TfrmMJManageNewFDNewLable.FormClick(Sender: TObject);
begin
  FInt:=4;
end;

procedure TfrmMJManageNewFDNewLable.Button12Click(Sender: TObject);
var
  fsj:string;
begin
  
end;

function  TfrmMJManageNewFDNewLable.SaveData():Boolean;
var
  maxno,FMJID,BZID,strsql:String;
  FMJLen:Double;
  FOrder:Integer;
begin
  ReadINIFile();
  if PState=1 then
      FMJID:=''
  else if PState=2 then
     FMJID:=Trim(CDS_MJID.fieldbyname('MJID').AsString)
  else if PState<1 then Exit;
  try
    ADOCmd.Connection.BeginTrans;
    ///保存主表
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      SQL.Add('select * from WFB_MJJY where MJId='''+Trim(FMJID)+'''');
      Open;
    end;
    with ADOCmd do
    begin
      if Trim(FMJID)='' then
      begin
        Append;
        if GetLSNo(ADOTmp,maxno,Trim(SCXFlag),'WFB_MJJY',4,1)=False then
        begin
          ADOCmd.Connection.RollbackTrans;
          Application.MessageBox('生成流水号异常！','提示',0);
          exit;
        end;
      end
      else begin
        maxno:=Trim(FMJID);
        Edit;
      end;
      FieldByName('MainId').value:=Trim(FMainId);
      FieldByName('SubId').value:=Trim(FSubId);
      FieldByName('APId').value:=Trim(FAPID);
      FieldByName('MJID').Value:=Trim(maxno);
      FieldByName('MJStr2').Value:='未入库';
      FieldByName('MJBanZu').Value:=Trim(FBanZu);
      FieldByName('MJstr3').Value:=Trim(MJstr3.Text);
      FieldByName('DuoPinNote').Value:=Trim(DuoPinNote.Text);
      FieldByName('ZSunit').Value:=Trim(ZSunit.Text);
   //   FieldByName('MJQty4').Value:=StrToFloatdef(trim(MJQty4.Text),0);
      {if Trim(MJLen.Text)<>'' then
      begin
        FieldByName('MJLen').Value:=StrToFloat(MJLen.Text);
      end;
      if Trim(MJLenMa.Text)<>'' then
      begin
        FieldByName('MJLenMa').Value:=StrToFloat(MJLenMa.Text);
      end; }
      if Trim(KgZMiXS)<>'' then
      begin
        FieldByName('MiXS').Value:=StrToFloat(KgZMiXS);
      end;
      if Trim(KgZMaXS)<>'' then
      begin
        FieldByName('MaXS').Value:=StrToFloat(KgZMaXS);
      end;
      if Trim(MJQty1.Text)<>'' then
      begin
        FieldByName('MJQty1').Value:=StrToFloat(MJQty1.Text);
      end;
      if Trim(MJQty2.Text)<>'' then
      begin
        FieldByName('MJQty2').Value:=StrToFloat(MJQty2.Text);
      end else
      begin
        FieldByName('MJQty2').Value:=0;
      end;

      FieldByName('MJQty3').Value:=StrToFloatdef(trim(MJQty3.Text),0);
       FieldByName('MJQty4').Value:=StrToFloatdef(trim(MJQty4.Text),0);
      if Trim(MJFK.Text)<>'' then
      begin
        FieldByName('MJFK').Value:=StrToFloat(MJFK.Text);
      end;
      if Trim(MJMaoZ.Text)<>'' then
      begin
        FieldByName('MJMaoZ').Value:=StrToFloat(MJMaoZ.Text);
      end;
      if Trim(MJSJKZ.Text)<>'' then
      begin
        FieldByName('MJSJKZ').Value:=StrToFloat(MJSJKZ.Text);
      end;
      if Trim(Edit3.Text)<>'' then
      begin
        FieldByName('MJType').Value:='正品';
      end;
      if Trim(Edit4.Text)<>'' then
      begin
        FieldByName('MJType').Value:='次品';
      end;
      if Trim(Edit5.Text)<>'' then
      begin
        FieldByName('MJType').Value:='多拼';
      end;
      FieldByName('MJTypeOther').Value:=Trim(Label9.Caption);
      FieldByName('MJStr1').Value:=Trim(Label13.Caption);
      {if Trim(MJSJKZ.Text)<>'' then
      begin
        FieldByName('MJSJKZ').Value:=StrToFloat(MJSJKZ.Text);
      end; }
      if Trim(FMJID)='' then
      begin
        FieldByName('Filler').Value:=Trim(DName);
      end else
      begin
        FieldByName('Editer').Value:=Trim(DName);
        FieldByName('EditTime').Value:=SGetServerDateTime(ADOTmp);
      end;
      if Trim(SCXFlag)<>'' then
      begin
        FieldByName('JTType').Value:=Trim(SCXFlag);
      end;
      Post;

    end;
    if Trim(KgZMiXS)<>'' then
    begin
      with ADOCmd do
      begin
        Close;
        sql.Clear;
        sql.Add(' Update WFB_MJJY Set MJLen=MJQty4*MiXS');
        sql.Add(' ,MJLenMa=Cast(MJQty4*MiXS*1.0936 as decimal(18,1))');
        sql.Add(' where MJID='''+Trim(maxno)+'''');
        ExecSQL;
      end;
    end;
    if Trim(KgZMaXS)<>'' then
    begin
      with ADOCmd do
      begin
        Close;
        sql.Clear;
        sql.Add(' Update WFB_MJJY Set MJLen=MJQty4*MAXS*0.9144');
        sql.Add(' ,MJLenMa=Cast(MJQty4*MAXS as decimal(18,1))');
        sql.Add(' where MJID='''+Trim(maxno)+'''');
        ExecSQL;
      end;
    end;
    if (Trim(KgZMiXS)='') and (Trim(KgZMaXS)='')  then
    begin
      with ADOCmd do
      begin
        Close;
        sql.Clear;
        sql.Add(' Update WFB_MJJY Set MJLen=MJQty4*100*1000*1.00/(MJFK*MJSJKZ)');
        sql.Add(' ,MJLenMa=Cast(MJQty4*100*1000*1.00/(MJFK*MJSJKZ)*1.0936 as decimal(18,1))');
        sql.Add(' where MJID='''+Trim(maxno)+'''');
        ExecSQL;
      end;
    end;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      //SQL.Add(strsql);
      SQL.Add('UPdate WFB_MJJY Set MJXH=(select isnull(max(MJXH),0)+1 ');
      SQL.Add(' from  WFB_MJJY A  ');
      SQL.Add(' inner join JYOrder_Main_MD B on A.APID=B.MDID');
      sql.Add(' where A.SubID=WFB_MJJY.SubID');
      sql.Add(' and B.SelfGangNo='''+Trim(Label2.Caption)+'''');
      if Trim(Edit3.Text)<>'' then
      begin
        sql.Add(' and A.MJType in(''正品'',''多拼'')');
      end;
      if Trim(Edit4.Text)<>'' then
      begin
        sql.Add(' and A.MJType=''次品'' ');
      end;
      if Trim(Edit5.Text)<>'' then
      begin
        sql.Add(' and A.MJType in(''正品'',''多拼'')');
      end;
      {if Trim(Edit3.Text)<>'' then
      begin
        sql.Add(' and A.MJType=''正品''');
      end;
      if Trim(Edit4.Text)<>'' then
      begin
        sql.Add(' and A.MJType=''次品'' ');
      end;
      if Trim(Edit5.Text)<>'' then
      begin
        sql.Add(' and A.MJType=''多拼'' ');
      end; }
      sql.Add(' )where MJID='''+Trim(maxno)+'''');
      ExecSQL;
    end;
    FMJID:=Trim(maxno);
    FFFMJID:=Trim(maxno);
    ///保存母卷疵点表
    with CDS_MJCD do
    begin
      First;
      while not Eof do
      begin
        if Trim(CDS_MJCD.fieldbyname('MCID').AsString)='' then
        begin
          if GetLSNo(ADOTmp,maxno,'MC','WFB_MJJY_CD',5,1)=False then
          begin
            ADOCmd.Connection.RollbackTrans;
            Application.MessageBox('取子流水号失败！','提示',0);
            Exit;
          end;
        end else
        begin
          maxno:=Trim(CDS_MJCD.fieldbyname('MCID').AsString);
        end;
        with ADOCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from WFB_MJJY_CD  ');
          sql.Add(' where MCID='''+Trim(maxno)+'''');
          Open;
        end;
        with ADOCmd do
        begin
          if Trim(CDS_MJCD.fieldbyname('MCID').AsString)='' then
            Append
          else
            Edit;
          FieldByName('MJId').Value:=Trim(FMJID);
          FieldByName('MCID').Value:=Trim(maxno);
          //SSetSaveDataCDSNew(ADOCmd,Tv2,CDS_MJCD,'WFB_MJJY_CD',0);
          FieldByName('KouFenType').Value:=CDS_MJCD.fieldbyname('KouFenType').Value;
          Post;
        end;
        CDS_MJCD.Edit;
        CDS_MJCD.FieldByName('MCID').Value:=Trim(maxno);
        Next;
      end;
    end;
    with CDS_MJID do
    begin
      Append;
      FieldByName('MJID').Value:=Trim(FMJID);
      Post;
    end;
    
    //SavedataCK();
    ADOCmd.Connection.CommitTrans;
    Result:=True;
    PState:=0;
  except
    Result:=False;
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！','提示',0);
  end;
end;

procedure TfrmMJManageNewFDNewLable.BTAddClick(Sender: TObject);
begin
  //if Trim(Label2.Caption)='' then Exit;
  PState:=1;
  InitCDGridID();
  InitCDGrid();
  BtnStatus(True);
  Label16.Caption:='新增';
end;

procedure TfrmMJManageNewFDNewLable.BTEditClick(Sender: TObject);
begin
  if CDS_MJID.IsEmpty then Exit;
  PState:=2;
  Label16.Caption:='修改';
end;

procedure TfrmMJManageNewFDNewLable.BTPrintClick(Sender: TObject);
var
  fPrintFile:String;
  mvalue:Double;
  i:Integer;
begin
  if  trim(MJMaoZ.Text)='' then
  begin
     MJMaoZ.Text:=floattostr(strtofloatdef(trim(MJQty3.Text),0)+strtofloatdef(trim(MJQty4.Text),0) );
  end;

  if  trim(MJQty4.Text)='' then
  begin
     MJQty4.Text:=floattostr(strtofloatdef(trim(MJMaoZ.Text),0)-strtofloatdef(trim(MJQty3.Text),0) );
  end;

  if trim(MJQty3.Text)='' then
   MJQty3.Text:=floattostr(strtofloatdef(trim(MJMaoZ.Text),0)-strtofloatdef(trim(MJQty4.Text),0) );

  if Trim(FAPID)='' then Exit;
  if FInt=4  then
  begin
    if CDS_MJID.IsEmpty=False then
    begin
      Application.MessageBox('已打过条码？请尝试重打。','提示',0);
      Exit;
    end;
  end;


  if  (trim(MJMaoZ.Text)='') and (trim(MJQty4.Text)='')  then
  begin
    Application.MessageBox('净重，毛重不能都为空!','提示',0);
    Exit;
  end;


{  if Trim(MJMaoZ.Text)='' then
  begin
    Application.MessageBox('重量不能为空!','提示',0);
    Exit;
  end;     }
{  if TryStrToFloat(MJLen.Text,mvalue)=False then
  begin
    Application.MessageBox('重量录入错误!','提示',0);
    Exit;
  end;   }
  {if Trim(MJQty1.Text)='' then
  begin
    Application.MessageBox('原码不能为空!','提示',0);
    Exit;
  end; }
  if Trim(MJQty1.Text)<>'' then
  begin
    if TryStrToFloat(MJQty1.Text,mvalue)=False then
    begin
      Application.MessageBox('原码录入错误!','提示',0);
      Exit;
    end;
  end;

  if Trim(MJFK.Text)<>'' then
  begin
    if TryStrToFloat(MJFK.Text,mvalue)=False then
    begin
      Application.MessageBox('幅宽录入错误!','提示',0);
      Exit;
    end;
  end;
  if Trim(MJMaoZ.Text)<>'' then
  begin
    if TryStrToFloat(MJMaoZ.Text,mvalue)=False then
    begin
      Application.MessageBox('重量录入错误!','提示',0);
      Exit;
    end;
  end;
  if Trim(MJSJKZ.Text)<>'' then
  begin
    if TryStrToFloat(MJSJKZ.Text,mvalue)=False then
    begin
      Application.MessageBox('克重录入错误!','提示',0);
      Exit;
    end;
  end;
  if Trim(MJQty2.Text)<>'' then
  begin
    if TryStrToFloat(MJQty2.Text,mvalue)=False then
    begin
      Application.MessageBox('赠送长度录入错误!','提示',0);
      Exit;
    end;
  end;
  {if Trim(MJSJKZ.Text)<>'' then
  begin
    if TryStrToFloat(MJSJKZ.Text,mvalue)=False then
    begin
      Application.MessageBox('克重录入错误!','提示',0);
      Exit;
    end;
  end;  }
  if PState=1 then
  begin
    if Application.MessageBox('是否要打印条码？打印后数据将不能修改！','提示',32+4)<>IDYES then Exit;
  end;
  if SaveData() then
  begin
    //BtnStatus(False);
    //MJFK.Text:='';
    //MJSJKZ.Text:='';
    MJLen.Text:='';
    MJLenMa.Text:='';
    MJMaoZ.Text:='';
    MJQty1.Text:='';
    MJQty2.Text:='';
    //MJSJKZ.Text:='';
    Label15.Caption:='';
    //MJQty3.Text:='';
    MJQty4.Text:='';
    Edit3.Text:='√';
    Edit4.Text:='';
    Edit5.Text:='';
    DuoPinNote.Text:='';
  end;
  if Trim(Edit6.Text)='√' then
  begin
    for i:=1 to StrToInt(ComboBox1.Text) do
    begin
      PrtData(FFFMJID);
    end;
    {with ADOQueryPrint do
    begin
      Close;
      SQL.Clear;
      sql.Add('select A.MJID,A.MJXH,A.mjstr3,QtyUnit=A.MJTypeOther,B.orderNo,GangNo=D.AOrddefStr1,PRTColorEng=E.Note,B.LBName ');
      sql.Add(',case when MJQty2>0 then Cast(MJLen as varchar(20))+''+''+Cast(MJQty2 as varchar(20)) else Cast(MJLen as varchar(20)) end as Qty   ');
      sql.Add(',MPRTCodeNameEng=ISNULL((select Top 1 F.note from KH_Zdy F where F.zdyname=B.MPRTCodeName and F.Type=''PRTCodeName''),B.MPRTCodeName)');
      sql.Add('Case when ');
      sql.Add(',B.MPRTCF,B.MPRTMF,B.MPRTKZ,C.SOrddefstr4,B.MPRTCodeName,C.*,A.* ');
      sql.Add(',Case when A.MJSJKZ*A.MJFK<>0 then Cast(A.MJQty4*1000/A.MJSJKZ/(A.MJFK/100) as int) else 0 end as MQty');
      sql.Add(' from WFB_MJJY A') ;
      sql.Add(' inner join JYOrder_Main B On A.Mainid=B.Mainid');
      sql.Add(' inner join JYOrder_Sub C on A.SubId=C.SubId');
      sql.Add(' left join KH_Zdy E on C.PRTColor=E.ZdyName and E.Type=''OrdColor'' ');
      sql.Add(' inner join JYOrder_Sub_AnPai D on A.APId=D.APId ');
      SQL.Add(' where A.MJID='''+Trim(CDS_MJID.fieldbyname('MJID').AsString)+'''');
      Open;
    end;
    if Trim(ADOQueryPrint.fieldbyname('LBName').AsString)<>'' then
      fPrintFile:=ExtractFilePath(Application.ExeName)+'Report\'+Trim(ADOQueryPrint.fieldbyname('LBName').AsString)+'.rmf'
    else
      fPrintFile:=ExtractFilePath(Application.ExeName)+'Report\通用英文标签.rmf' ;
    if FileExists(fPrintFile) then
    begin
      RM2.LoadFromFile(fPrintFile);
      //RM2.ShowReport;
      RM2.PrintReport;
    end else
    begin
      Application.MessageBox(PChar('没有找'+ExtractFilePath(Application.ExeName)+'Report\'+Trim(ADOQueryPrint.fieldbyname('LBName').AsString)),'提示',0);
    end; }
  end;

  Label16.Caption:='';
  BTAdd.Click;
  //MJQty4.SetFocus;
  MJMaoZ.SetFocus;
end;
procedure TfrmMJManageNewFDNewLable.PrtData(FMJID:String);
var
   fPrintFile:String;
begin
  with ADOQueryPrint do
  begin
    Close;
    SQL.Clear;
    sql.Add('exec P_Print_Lable :MJID');
    Parameters.ParamByName('MJID').Value:=Trim(FMJID);
    Open;
  end;
  if Trim(Edit4.Text)='√' then
  begin
    fPrintFile:=ExtractFilePath(Application.ExeName)+'Report\次品标签.rmf' ;
  end else
  begin
    if Trim(ADOQueryPrint.fieldbyname('SLBName').AsString)<>'' then
      fPrintFile:=ExtractFilePath(Application.ExeName)+'Report\'+Trim(ADOQueryPrint.fieldbyname('SLBName').AsString)
    else
      fPrintFile:=ExtractFilePath(Application.ExeName)+'Report\通用英文标签.rmf' ;
  end;

  if FileExists(fPrintFile) then
  begin
    
    RM2.LoadFromFile(fPrintFile);
    //RM2.ShowReport;
    RM2.PrintReport;
  end else
  begin
    Application.MessageBox(PChar('没有找'+ExtractFilePath(Application.ExeName)+'Report\'+Trim(ADOQueryPrint.fieldbyname('SLBName').AsString)),'提示',0);
  end;
end;
procedure TfrmMJManageNewFDNewLable.SavedataCK();
var
  CRID:Integer;
  MaxCkNo,MaxCkSubNo:String;
begin
  //if Trim(Cds_Main.fieldbyname('SubType').AsString)='大卷' then
  //////////////////////////////////////////////////////////////保存到半成品仓库////////////////////////////////////////////////
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      SQL.add('Update CK_BanCP_CRID Set CRID=CRID+1');
      sql.Add('select * from CK_BanCP_CRID');
      Open;
    end;
    CRID:=ADOCmd.fieldbyname('CRID').Value;
    if GetLSNo(ADOCmd,MaxCkNo,'JR','CK_BanCP_CR',4,1)=False then
    begin
      ADOCmd.Connection.RollbackTrans;
      Application.MessageBox('取半成品仓库最大号失败！','提示',0);
      Exit;
    end;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from CK_BanCP_CR where 1<>1');
      Open;
    end;
    with ADOCmd do
    begin
      Append;
      FieldByName('MainId').Value:=Trim(FMainId);
      FieldByName('SubId').Value:=Trim(FSubId);
      FieldByName('APID').Value:=Trim(FAPID);
      FieldByName('MJID').Value:=Trim(CDS_MJID.fieldbyname('MJId').AsString);
      FieldByName('BCID').Value:=Trim(MaxCkNo);
      FieldByName('CRTime').Value:=SGetServerDateTime(ADOTmp);
      FieldByName('CRFlag').Value:='入库';
      FieldByName('CRType').Value:='检验入库';
      //FieldByName('JTType').Value:=Trim(XJFlag);
      FieldByName('CRID').Value:=CRID;
      if Trim(MJMaoZ.Text)<>'' then
      begin
        FieldByName('KGQty').Value:=StrToFloat(MJMaoZ.Text);
      end;
      if Trim(MJLen.Text)<>'' then
      begin
        FieldByName('Qty').Value:=StrToFloat(MJLen.Text);
      end;
      FieldByName('QtyUnit').Value:=Trim(Label9.Caption);
      FieldByName('Filler').Value:=Trim(DName);
      FieldByName('FillTime').Value:=SGetServerDateTime(ADOTmp);
      if Trim(Edit3.Text)<>'' then
      begin
        FieldByName('CPType').Value:='正品';
      end;
      if Trim(Edit4.Text)<>'' then
      begin
        FieldByName('CPType').Value:='次品';
      end;
      Post;
    end;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from CK_BanCP_KC where 1<>1');
      Open;
    end;
    with ADOCmd do
    begin
      Append;
      FieldByName('CRID').Value:=CRID;
      FieldByName('BCID').Value:=Trim(MaxCkNo);
      FieldByName('MJID').Value:=Trim(CDS_MJID.fieldbyname('MJID').AsString);
      if Trim(MJMaoZ.Text)<>'' then
      begin
        FieldByName('KCKGQty').Value:=StrToFloat(MJMaoZ.Text);
      end;
      if Trim(MJLen.Text)<>'' then
      begin
        FieldByName('KCQty').Value:=StrToFloat(MJLen.Text);
      end;
      FieldByName('KCQtyUnit').Value:=Trim(Label9.Caption);
      Post;
    end;
end;
procedure TfrmMJManageNewFDNewLable.BtnStatus(BSInt:Boolean);
begin
 // Tv2.OptionsSelection.CellSelect:=BSInt;
end;
procedure TfrmMJManageNewFDNewLable.Tv2CDQtyPropertiesEditValueChanged(Sender: TObject);
var
  mvalue:string;
begin
  try
    mvalue:=TcxTextEdit(Sender).EditingText;
    if Trim(mvalue)<>'' then
    begin
      CDS_MJCD.Edit;
      CDS_MJCD.FieldByName('CDQty').Value:=mvalue;
      CDS_MJCD.Post;
    end else
    begin
      CDS_MJCD.Edit;
      CDS_MJCD.FieldByName('CDQty').Value:=0;
      CDS_MJCD.Post;
    end;
    CDS_MJCD.Edit;
    CDS_MJCD.FieldByName('CDQtyS').Value:=mvalue;
  except
    Application.MessageBox('非法数字！','提示',0);
  end;
end;

procedure TfrmMJManageNewFDNewLable.SpeedButton1Click(Sender: TObject);
var
  fsj:string;
begin
  fsj:=Trim(TSpeedButton(Sender).Hint);
  if Trim(fsj)='' then Exit;
  fsj:=Trim(TEdit(FindComponent(Trim(TSpeedButton(Sender).Hint))).Text);
  TEdit(FindComponent(Trim(TSpeedButton(Sender).Hint))).Text:=fsj+Trim(TSpeedButton(Sender).Caption);
  TEdit(FindComponent(Trim(TSpeedButton(Sender).Hint))).SelectAll;
end;

procedure TfrmMJManageNewFDNewLable.SpeedButton12Click(Sender: TObject);
var
  fsj:string;
begin
  fsj:=Trim(TEdit(FindComponent(Trim(TSpeedButton(Sender).Hint))).Text);
  if Trim(fsj)='' then Exit;
  TEdit(FindComponent(Trim(TSpeedButton(Sender).Hint))).Text:=Copy(fsj,1,Length(fsj)-1);
  TEdit(FindComponent(Trim(TSpeedButton(Sender).Hint))).SelectAll;
end;

procedure TfrmMJManageNewFDNewLable.SpeedButton13Click(Sender: TObject);
var
  i:Integer;
begin
  

end;

procedure TfrmMJManageNewFDNewLable.cxGridDBColumn2PropertiesChange(Sender: TObject);
var
  fsj:String;
begin

  fsj:=Trim(Order_MJ.fieldbyname('SubId').AsString);
  Order_MJ.DisableControls;
  with Order_MJ do
  begin
    First;
    while not Eof do
    begin
      if Trim(Order_MJ.fieldbyname('SubId').AsString)<>fsj then
      begin
        Edit;
        FieldByName('SSel').Value:=False;
      end;
      Next;
    end;
  end;
  Order_MJ.EnableControls;
  Order_MJ.Locate('SubId',fsj,[]);
end;

procedure TfrmMJManageNewFDNewLable.Button1Click(Sender: TObject);
var
  mvalue:Double;
begin

end;

procedure TfrmMJManageNewFDNewLable.ToolButton1Click(Sender: TObject);
begin
  //InitGrid();
 // InitJP();

  MJLen.Text:='';
  MJMaoZ.Text:='';
  MJQty1.Text:='';
  MJQty2.Text:='';
  Label15.Caption:='';
  MJQty4.Text:='';
  Edit3.Text:='√';
  Edit4.Text:='';
  Edit5.Text:='';
  DuoPinNote.Text:='';
  BTAdd.Click;
  FInt:=11;
  MJMaoZ.SetFocus;
end;

procedure TfrmMJManageNewFDNewLable.Button5Click(Sender: TObject);
var
   fPrintFile:String;
   i:Integer;
begin
  if CDS_MJID.IsEmpty then Exit;
  with ADOCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('Update WFB_MJJY Set PrtAgnFlag=1,PrtAgnDate=getdate(),PrtAgnPerson='''+Trim(DName)+'''');
    sql.Add(' where MJID='''+Trim(CDS_MJID.fieldbyname('MJID').AsString)+'''');
    ExecSQL;
  end;
  for i:=1 to StrToInt(ComboBox1.Text) do
  begin
    PrtData(Trim(CDS_MJID.fieldbyname('MJID').AsString));
  end;

  PState:=1;
  MJLen.Text:='';
  MJMaoZ.Text:='';
  MJQty1.Text:='';
  MJQty2.Text:='';
  Label15.Caption:='';
  MJQty4.Text:='';
  Edit3.Text:='√';
  Edit4.Text:='';
  Edit5.Text:='';
  BTAdd.Click;
  FInt:=11;
  MJMaoZ.SetFocus;
 { with ADOQueryPrint do
  begin
    Close;
    SQL.Clear;
    with ADOQueryPrint do
    begin
      Close;
      SQL.Clear;
      sql.Add('select A.MJID,A.MJXH,A.mjstr3,QtyUnit=A.MJTypeOther,B.orderNo,GangNo=D.AOrddefStr1,PRTColorEng=E.Note,B.LBName ');
      sql.Add(',case when MJQty2>0 then Cast(MJLen as varchar(20))+''+''+Cast(MJQty2 as varchar(20)) else Cast(MJLen as varchar(20)) end as Qty   ');
      sql.Add(',MPRTCodeNameEng=ISNULL((select Top 1 F.note from KH_Zdy F where F.zdyname=B.MPRTCodeName and F.Type=''PRTCodeName''),B.MPRTCodeName)');
      sql.Add(',B.MPRTCF,B.MPRTMF,B.MPRTKZ,C.SOrddefstr4,B.MPRTCodeName,C.*,A.* ');
      sql.Add(',Case when A.MJSJKZ*A.MJFK<>0 then Cast(A.MJQty4*1000/A.MJSJKZ/(A.MJFK/100) as int) else 0 end as MQty');
      sql.Add(' from WFB_MJJY A') ;
      sql.Add(' inner join JYOrder_Main B On A.Mainid=B.Mainid');
      sql.Add(' inner join JYOrder_Sub C on A.SubId=C.SubId');
      sql.Add(' left join KH_Zdy E on C.PRTColor=E.ZdyName and E.Type=''OrdColor'' ');
      sql.Add(' inner join JYOrder_Sub_AnPai D on A.APId=D.APId ');
      SQL.Add(' where A.MJID='''+Trim(CDS_MJID.fieldbyname('MJID').AsString)+'''');
      Open;
    end;
    //SQL.Add(' where A.MJID='''+Trim(CDS_MJID.fieldbyname('MJID').AsString)+'''');
    //Open;
  end;
  if Trim(ADOQueryPrint.fieldbyname('LBName').AsString)<>'' then
    fPrintFile:=ExtractFilePath(Application.ExeName)+'Report\'+Trim(ADOQueryPrint.fieldbyname('LBName').AsString)+'.rmf'
  else
    fPrintFile:=ExtractFilePath(Application.ExeName)+'Report\通用英文标签.rmf' ;
  if FileExists(fPrintFile) then
  begin
    RM2.LoadFromFile(fPrintFile);
    //RM2.ShowReport;
    RM2.PrintReport;
  end else
  begin
    Application.MessageBox(PChar('没有找'+ExtractFilePath(Application.ExeName)+'Report\卷标签.rmf'),'提示',0);
  end; }

end;

procedure TfrmMJManageNewFDNewLable.APIDKeyPress(Sender: TObject; var Key: Char);
var
  fPrintFile:String;
begin
  if Key=#13 then
  begin
    with ADOTmp do
    begin
      Close;
      sql.Clear;
      sql.Add('select A.*,B.MPRTCodeName,B.MPRTMF,B.MPRTKZ,B.BZNote,B.PiZhong  ');
      sql.Add(',B.MPRTMF,B.MPRTKZ,OrderNoM=B.OrderNo,C.PRTHX,C.PRTColor,C.PRTColorNo');
      sql.add(',B.ZGLen,B.ZGHD,B.ZGKg,B.NRDHD,B.ZGNote,B.KgZMiXs,B.KgZMaXs');
      sql.Add('from JYOrder_Main_MD A');
      SQL.Add(' inner join JYOrder_Main B on A.OrdMainId=B.MainId');
      sql.Add(' inner join JYOrder_Sub C on A.OrdSubId=C.SubId');
      sql.Add('where MDID='''+Trim(APID.Text)+'''');
      Open;
    end;
    if ADOTmp.IsEmpty=False then
    begin
      Label2.Visible:=True;
      Label2.Caption:=Trim(ADOTmp.fieldbyname('SelfGangNo').AsString);
      Label24.Visible:=True;
      Label24.Caption:=Trim(ADOTmp.fieldbyname('OrderNoM').AsString);
      Label25.Visible:=True;
      Label25.Caption:=Trim(ADOTmp.fieldbyname('PRTColor').AsString);
      FAPID:=Trim(APID.Text);
      FMainId:=Trim(ADOTmp.fieldbyname('OrdMainId').AsString);
      FSubId:=Trim(ADOTmp.fieldbyname('OrdSubId').AsString);
      BZNote.Text:='纸管长度: '+Trim(ADOTmp.fieldbyname('ZGLen').AsString)+'cm'+
                 ',纸管厚度: '+Trim(ADOTmp.fieldbyname('ZGHD').AsString)+'cm'+
                 ',纸管重量: '+Trim(ADOTmp.fieldbyname('ZGKg').AsString)+'Kg'+#13+
                 '呢绒袋厚度: '+Trim(ADOTmp.fieldbyname('NRDHD').AsString)+'丝'+#13+
                 '折算系数: '+Trim(ADOTmp.fieldbyname('KgZMiXS').AsString)+'(每公斤几米)'+#13+
                 '特殊说明:'+Trim(ADOTmp.fieldbyname('ZGNote').AsString)+#13+
                 Trim(ADOTmp.fieldbyname('BZNote').AsString);
      MJFK.Text:=Trim(ADOTmp.fieldbyname('MPRTMF').AsString);
      MJSJKZ.Text:=Trim(ADOTmp.fieldbyname('MPRTKZ').AsString);
      MJQty3.Text:=Trim(ADOTmp.fieldbyname('PiZhong').AsString);
      KgZMiXs:=Trim(ADOTmp.fieldbyname('KgZMiXs').AsString);
      KgZMaXS:=Trim(ADOTmp.fieldbyname('KgZMaXS').AsString);
      with ADOQueryLabel do
      begin
        Close;
        sql.Clear;
        sql.Add('select * from P_Label');
        sql.Add('where valid=''Y''');
        sql.Add(' and labelCaption=');
        sql.Add('(select SLBName from JYorder_Sub A where A.SubId='''+Trim(FSubId)+''')');
        Open;
      end;
      if ADOQueryLabel.IsEmpty then exit;
      with ADOQueryPrint do
      begin
        Close;
        SQL.Clear;
        sql.Add('select * from JYOrder_Sub where SubId='''+Trim(FSubId)+'''');
        Open;
      end;
      if Trim(ADOQueryPrint.fieldbyname('SLBName').AsString)<>'' then
        fPrintFile:=ExtractFilePath(Application.ExeName)+'Report\'+Trim(ADOQueryPrint.fieldbyname('SLBName').AsString)
      else
        fPrintFile:=ExtractFilePath(Application.ExeName)+'Report\通用英文标签.rmf' ;
      if FileExists(fPrintFile) then
      begin
        with RMGridReport1 do
        begin
          LoadFromBlobField(tblobfield(ADOQueryLabel.fieldbyname('labelFile')));
          //Preview :=RMPreview1;
          ShowReport ;
        end;
      end else
      begin
        Application.MessageBox(PChar('没有找'+ExtractFilePath(Application.ExeName)+'Report\'+Trim(ADOQueryPrint.fieldbyname('SLBName').AsString)),'提示',0);
      end;

      {if Trim(ADOTmp.fieldbyname('AOrddefstr3').AsString)<>'' then
      begin
        Label9.Caption:=Trim(ADOTmp.fieldbyname('AOrddefstr3').AsString);
        Label19.Caption:=Label9.Caption;
        Label20.Caption:=Label9.Caption;
        Label7.Caption:=Label9.Caption;
      end;
      Label13.Caption:=Trim(ADOTmp.fieldbyname('AOrddefstr2').AsString);
      if ADOTmp.FieldByName('JYMF').Value>0 then
        MJFK.Text:=Trim(ADOTmp.fieldbyname('JYMF').AsString);
      if ADOTmp.FieldByName('JYKZ').Value>0 then
        MJSJKZ.Text:=Trim(ADOTmp.fieldbyname('JYKZ').AsString);  }
      MJMaoZ.SetFocus;
    end else
    begin
      Application.MessageBox('条码错误!','提示',0);
      Label2.Visible:=False;
      Label2.Caption:='';
      APID.Text:='';
      FAPID:='';
      FMainId:='';
      FSubId:='';
      BZNote.Text:='';
      Exit;
    end;
    {if Trim(SCXFlag)<>Trim(ADOTmp.fieldbyname('AOrdDefNote29').AsString) then
    begin
      APID.Text:='';
      if Application.MessageBox('分配机台与当前机台不一致,'+#13+'是否继续检验？','提示',32+4)<>IDYES then
      begin
        Label2.Visible:=False;
        Label2.Caption:='';
        FAPID:='';
        FMainId:='';
        FSubId:='';
        Exit;
      end;

    end; }
    APID.Text:='';
    BTAdd.Click;
  end;
end;

procedure TfrmMJManageNewFDNewLable.MJLenMaClick(Sender: TObject);
var
  i:Integer;
begin
  {Panel3.Visible:=True;
  with Panel3 do
  begin
    for i:=0 to ControlCount-1 do
    begin
      if Controls[i] is TSpeedButton then
      begin
        TSpeedButton(Controls[i]).Hint:=Trim(TEdit(Sender).Name);
      end;
    end;
  end; }
end;

procedure TfrmMJManageNewFDNewLable.Edit2Change(Sender: TObject);
var
  mvalue:Double;
begin
  
end;

procedure TfrmMJManageNewFDNewLable.Edit3Click(Sender: TObject);
begin
  if Trim(Edit3.Text)='' then
  begin
    Edit3.Text:='√';
    Edit4.Text:='';
    Edit5.Text:='';
  end else
  begin
    Edit3.Text:='';
    Edit4.Text:='√';
    Edit5.Text:='';
  end;
end;

procedure TfrmMJManageNewFDNewLable.Edit4Click(Sender: TObject);
begin
  if Trim(Edit4.Text)='' then
  begin
    Edit4.Text:='√';
    Edit3.Text:='';
    Edit5.Text:='';
  end else
  begin
    Edit4.Text:='';
    Edit3.Text:='√';
    Edit5.Text:='';
  end;
end;

procedure TfrmMJManageNewFDNewLable.Edit5Click(Sender: TObject);
begin
  if Trim(Edit5.Text)='' then
  begin
    Edit5.Text:='√';
    Edit3.Text:='';
    Edit4.Text:='';
  end else
  begin
    Edit5.Text:='';
    Edit3.Text:='√';
    Edit4.Text:='';
  end;
end;

procedure TfrmMJManageNewFDNewLable.Edit6Click(Sender: TObject);
begin
  if Trim(Edit6.Text)='' then
  begin
    Edit6.Text:='√';
  end else
  begin
    Edit6.Text:='';
  end;
end;

procedure TfrmMJManageNewFDNewLable.MJstr3KeyPress(Sender: TObject;
  var Key: Char);
begin
	if Key = #13 then
	begin
		Key:= #0;
    //MJQty2.SetFocus;
	 	SelectNext(ActiveControl as TWinControl, True, True);
	end;
end;

procedure TfrmMJManageNewFDNewLable.MJQty3Exit(Sender: TObject);
begin
  if (trim(MJMaoZ.Text)='') and (trim(MJQty4.Text)='') then exit;
  if (trim(MJMaoZ.Text)='') and (trim(MJQty3.Text)='') then exit;
  if (trim(MJQty4.Text)='') and (trim(MJQty3.Text)='') then exit;

  if (trim(MJQty3.Text)='') then exit;

  if (trim(MJQty4.Text)<>'') then
  begin
    MJMaoZ.Text:=floattostr(strtofloatdef(trim(MJQty3.Text),0)+strtofloatdef(trim(MJQty4.Text),0) );
    exit;
  end;

end;

procedure TfrmMJManageNewFDNewLable.MJMaoZExit(Sender: TObject);
begin
  {if (trim(MJMaoZ.Text)='') and (trim(MJQty4.Text)='') then exit;
  if (trim(MJMaoZ.Text)='') and (trim(MJQty3.Text)='') then exit;
  if (trim(MJQty4.Text)='') and (trim(MJQty3.Text)='') then exit;

  if (trim(MJQty3.Text)='') then exit;

  if (trim(MJMaoZ.Text)<>'') then
  begin
    MJQty4.Text:=floattostr(strtofloatdef(trim(MJMaoZ.Text),0)-strtofloatdef(trim(MJQty3.Text),0) );
    if MJQty2.Text<>'' then
    begin
      if Trim(ZSUnit.Text)='KG' then
      begin
        MJQty4.Text:=floattostr(strtofloatdef(trim(MJQty4.Text),0)-strtofloatdef(trim(MJQty2.Text),0) );
      end;
    end;
    exit;
  end;  }
end;

procedure TfrmMJManageNewFDNewLable.Label9Click(Sender: TObject);
begin
  {if  trim(Label9.Caption)='M' then
  begin
  Label9.Caption:='Y';
  Label19.Caption:='Y';
  Label20.Caption:='Y';
  Label7.Caption:='Y';
  end
  else
  begin
  Label9.Caption:='M';
  Label19.Caption:='M';
  Label20.Caption:='M';
  Label7.Caption:='M';
  end;  }
end;

procedure TfrmMJManageNewFDNewLable.MJLenExit(Sender: TObject);
begin
  //MJQty3.OnExit(self);
end;

procedure TfrmMJManageNewFDNewLable.MJQty4Exit(Sender: TObject);
begin
  {if (trim(MJMaoZ.Text)='') and (trim(MJQty4.Text)='') then exit;
  if (trim(MJMaoZ.Text)='') and (trim(MJQty3.Text)='') then exit;
  if (trim(MJQty4.Text)='') and (trim(MJQty3.Text)='') then exit;

  if (trim(MJQty3.Text)='') then exit;

  if (trim(MJQty4.Text)<>'') then
  begin
    MJMaoZ.Text:=floattostr(strtofloatdef(trim(MJQty3.Text),0)+strtofloatdef(trim(MJQty4.Text),0) );
    exit;
  end;  }
end;

procedure TfrmMJManageNewFDNewLable.MJQty4Change(Sender: TObject);
var
  FReal:Double;
begin

  {if Trim(MJQty4.Text)='' then
  begin
    MJLen.Text:='';
    MJMaoZ.Text:='';
    Exit;
  end;
  if TryStrToFloat(MJQty4.Text,FReal)=False then Exit;
  if Trim(MJQty3.Text)<>'' then
  begin
    if TryStrToFloat(MJQty3.Text,FReal)=True then
      MJMaoZ.Text:=FloatToStr(StrToFloat(MJQty4.Text)+StrToFloat(MJQty3.Text));
  end else
  begin
    MJMaoZ.Text:=MJQty4.Text;
  end;
  if Trim(MJSJKZ.Text)='' then Exit;
  if TryStrToFloat(MJSJKZ.Text,FReal)=False then
  begin
    Application.MessageBox('克重录入错误!','提示',0);
    Exit;
  end;
  if Trim(MJFK.Text)='' then Exit;
  if TryStrToFloat(MJFK.Text,FReal)=False then
  begin
    Application.MessageBox('幅宽录入错误!','提示',0);
    Exit;
  end;
  if StrToFloat(MJSJKZ.Text)*StrToFloat(MJFK.Text)=0 then Exit;
  if Trim(KgZMiXS)='' then
  begin
    if Trim(KgZMaXS)='' then
      MJLen.Text:=FormatFloat('0.0',StrToFloat(MJQty4.Text)*1000*100/StrToFloat(MJSJKZ.Text)/StrToFloat(MJFK.Text))
    else
      MJLen.Text:=FormatFloat('0.0',StrToFloat(MJQty4.Text)*StrToFloat(KgZMaXS)*0.9144);
  end
  else
    MJLen.Text:=FormatFloat('0.0',StrToFloat(MJQty4.Text)*StrToFloat(KgZMiXS));
  if Trim(KgZMaXS)='' then
  begin
    if Trim(KgZMiXS)='' then
      MJLenMa.Text:=FormatFloat('0.0',StrToFloat(MJQty4.Text)*1000*100/StrToFloat(MJSJKZ.Text)/StrToFloat(MJFK.Text)*1.0936)
    else
     MJLenMa.Text:=FormatFloat('0.0',StrToFloat(MJQty4.Text)*StrToFloat(KgZMiXS)*1.0936);
  end
  else
    MJLenMa.Text:=FormatFloat('0.0',StrToFloat(MJQty4.Text)*StrToFloat(KgZMaXS)); }
end;

procedure TfrmMJManageNewFDNewLable.MJMaoZChange(Sender: TObject);
var
  FReal:Double;
begin
 // if StrToFloat(MJSJKZ.Text)*StrToFloat(MJFK.Text)=0 then Exit;
  if Trim(MJMaoZ.Text)='' then
  begin
    MJLen.Text:='';
    MJQty4.Text:='';
    Exit;
  end;
  if TryStrToFloat(MJMaoZ.Text,FReal)=False then Exit;
  if Trim(MJQty3.Text)<>'' then
  begin
    if TryStrToFloat(MJQty3.Text,FReal)=False then Exit;
    MJQty4.Text:=FloatToStr(StrToFloat(MJMaoZ.Text)-StrToFloat(MJQty3.Text));
  end else
  begin
    MJQty4.Text:=MJMaoZ.Text;
  end;
  if Trim(MJQty2.Text)<>'' then
  begin
    if Trim(ZSUnit.Text)='KG' then
    begin
      MJQty4.Text:=floattostr(strtofloatdef(trim(MJQty4.Text),0)-strtofloatdef(trim(MJQty2.Text),0) );
    end;
  end else
  begin
    if Trim(ZSUnit.Text)='KG' then
    begin
      MJQty4.Text:=floattostr(strtofloatdef(trim(MJMaoZ.Text),0)-strtofloatdef(trim(MJQty3.Text),0) );
    end;
  end;
  if Trim(MJSJKZ.Text)='' then Exit;
  if TryStrToFloat(MJSJKZ.Text,FReal)=False then
  begin
    Application.MessageBox('克重录入错误!','提示',0);
    Exit;
  end;
  if Trim(MJFK.Text)='' then Exit;
  if TryStrToFloat(MJFK.Text,FReal)=False then
  begin
    Application.MessageBox('幅宽录入错误!','提示',0);
    Exit;
  end;
  if StrToFloat(MJSJKZ.Text)*StrToFloat(MJFK.Text)=0 then Exit;
  if StrToFloat(MJSJKZ.Text)*StrToFloat(MJFK.Text)=0 then Exit;
  if Trim(KgZMiXS)='' then
  begin
    if Trim(KgZMaXS)='' then
      MJLen.Text:=FormatFloat('0.0',StrToFloat(MJQty4.Text)*1000*100/StrToFloat(MJSJKZ.Text)/StrToFloat(MJFK.Text))
    else
      MJLen.Text:=FormatFloat('0.0',StrToFloat(MJQty4.Text)*StrToFloat(KgZMaXS)*0.9144);
  end
  else
    MJLen.Text:=FormatFloat('0.0',StrToFloat(MJQty4.Text)*StrToFloat(KgZMiXS));
  if Trim(KgZMaXS)='' then
  begin
    if Trim(KgZMiXS)='' then
      MJLenMa.Text:=FormatFloat('0.0',StrToFloat(MJQty4.Text)*1000*100/StrToFloat(MJSJKZ.Text)/StrToFloat(MJFK.Text)*1.0936)
    else
     MJLenMa.Text:=FormatFloat('0.0',StrToFloat(MJQty4.Text)*StrToFloat(KgZMiXS)*1.0936);
  end
  else
    MJLenMa.Text:=FormatFloat('0.0',StrToFloat(MJQty4.Text)*StrToFloat(KgZMaXS));
end;

procedure TfrmMJManageNewFDNewLable.APIDClick(Sender: TObject);
var
  i:Integer;
begin
 { Panel3.Visible:=True;
  with Panel3 do
  begin
    for i:=0 to ControlCount-1 do
    begin
      if Controls[i] is TSpeedButton then
      begin
        TSpeedButton(Controls[i]).Hint:=Trim(TEdit(Sender).Name);
      end;
    end;
  end; }
end;


procedure TfrmMJManageNewFDNewLable.Button3Click(Sender: TObject);
begin
  with ADOTmp do
  begin
    Close;
    sql.Clear;
    sql.Add('select A.*,B.MPRTCodeName,B.MPRTMF,B.MPRTKZ,B.BZNote,B.PiZhong  ');
    sql.Add(',B.MPRTMF,B.MPRTKZ,OrderNoM=B.OrderNo,C.PRTHX,C.PRTColor,C.PRTColorNo');
    sql.add(',B.ZGLen,B.ZGHD,B.ZGKg,B.NRDHD,B.ZGNote,B.KgZMiXS,B.KgZMaXS');
    sql.Add('from JYOrder_Main_MD A');
    SQL.Add(' inner join JYOrder_Main B on A.OrdMainId=B.MainId');
    sql.Add(' inner join JYOrder_Sub C on A.OrdSubId=C.SubId');
    sql.Add('where MDID='''+Trim(APID.Text)+'''');
    Open;
  end;
  if ADOTmp.IsEmpty=False then
  begin
    Label2.Visible:=True;
    Label2.Caption:=Trim(ADOTmp.fieldbyname('SelfGangNo').AsString);
    Label24.Visible:=True;
    Label24.Caption:=Trim(ADOTmp.fieldbyname('OrderNoM').AsString);
    Label25.Visible:=True;
    Label25.Caption:=Trim(ADOTmp.fieldbyname('PRTColor').AsString);
    FAPID:=Trim(APID.Text);
    FMainId:=Trim(ADOTmp.fieldbyname('OrdMainId').AsString);
    FSubId:=Trim(ADOTmp.fieldbyname('OrdSubId').AsString);
    BZNote.Text:='纸管长度: '+Trim(ADOTmp.fieldbyname('ZGLen').AsString)+'cm'+
                 ',纸管厚度: '+Trim(ADOTmp.fieldbyname('ZGHD').AsString)+'cm'+
                 ',纸管重量: '+Trim(ADOTmp.fieldbyname('ZGKg').AsString)+'Kg'+#13+
                 '尼龙袋厚度: '+Trim(ADOTmp.fieldbyname('NRDHD').AsString)+'丝'+#13+
                 '折算系数: '+Trim(ADOTmp.fieldbyname('KgZMiXS').AsString)+'(每公斤几米)'+#13+
                 '特殊说明:'+Trim(ADOTmp.fieldbyname('ZGNote').AsString)+#13+
                 Trim(ADOTmp.fieldbyname('BZNote').AsString);
    MJFK.Text:=Trim(ADOTmp.fieldbyname('MPRTMF').AsString);
    MJSJKZ.Text:=Trim(ADOTmp.fieldbyname('MPRTKZ').AsString);
    MJQty3.Text:=Trim(ADOTmp.fieldbyname('PiZhong').AsString);
    KgZMiXs:=Trim(ADOTmp.fieldbyname('KgZMiXs').AsString);
    KgZMaXS:=Trim(ADOTmp.fieldbyname('KgZMaXS').AsString);
    with ADOQueryLabel do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from P_Label');
      sql.Add('where valid=''Y''');
      sql.Add(' and labelCaption=');
      sql.Add('(select SLBName from JYorder_Sub A where A.SubId='''+Trim(FSubId)+''')');
      Open;
    end;
    if ADOQueryLabel.IsEmpty then exit;
    with RMGridReport1 do
    begin
      LoadFromBlobField(tblobfield(ADOQueryLabel.fieldbyname('labelFile')));
      //Preview :=RMPreview1;
      ShowReport ;
    end;
    {if Trim(ADOTmp.fieldbyname('AOrddefstr3').AsString)<>'' then
    begin
      Label9.Caption:=Trim(ADOTmp.fieldbyname('AOrddefstr3').AsString);
      Label19.Caption:=Label9.Caption;
      Label20.Caption:=Label9.Caption;
      Label7.Caption:=Label9.Caption;
    end;
    Label13.Caption:=Trim(ADOTmp.fieldbyname('AOrddefstr2').AsString);
    if ADOTmp.FieldByName('JYMF').Value>0 then
      MJFK.Text:=Trim(ADOTmp.fieldbyname('JYMF').AsString);
    if ADOTmp.FieldByName('JYKZ').Value>0 then
      MJSJKZ.Text:=Trim(ADOTmp.fieldbyname('JYKZ').AsString);  }
    MJMaoZ.SetFocus;
  end else
  begin
    Application.MessageBox('条码错误!','提示',0);
    Label2.Visible:=False;
    Label2.Caption:='';
    APID.Text:='';
    FAPID:='';
    FMainId:='';
    FSubId:='';
    BZNote.Text:='';
    Exit;
  end;
  APID.Text:='';
  BTAdd.Click;
end;

procedure TfrmMJManageNewFDNewLable.MJFKChange(Sender: TObject);
var
  FReal:Double;
begin
 // if StrToFloat(MJSJKZ.Text)*StrToFloat(MJFK.Text)=0 then Exit;

  if TryStrToFloat(MJQty4.Text,FReal)=False then Exit;
  if Trim(MJSJKZ.Text)='' then Exit;
  if TryStrToFloat(MJSJKZ.Text,FReal)=False then
  begin
    Exit;
  end;
  if Trim(MJFK.Text)='' then Exit;
  if TryStrToFloat(MJFK.Text,FReal)=False then
  begin
    Exit;
  end;
  if StrToFloat(MJSJKZ.Text)*StrToFloat(MJFK.Text)=0 then Exit;
  if Trim(Label9.Caption)='M' then
  begin
    //MJLen.Text:=FloatToStr(StrToFloat(MJQty4.Text)*1000*100/StrToFloat(MJSJKZ.Text)/StrToFloat(MJFK.Text));
    MJLen.Text:=IntToStr(Round(StrToFloat(MJQty4.Text)*1000*100/StrToFloat(MJSJKZ.Text)/StrToFloat(MJFK.Text)));
  end else
  begin
    //MJLen.Text:=FloatToStr(StrToFloat(MJQty4.Text)*1000*100/StrToFloat(MJSJKZ.Text)/StrToFloat(MJFK.Text)*1.0936);
    MJLen.Text:=IntToStr(Round(StrToFloat(MJQty4.Text)*1000*100/StrToFloat(MJSJKZ.Text)/StrToFloat(MJFK.Text)*1.0936));
  end;
end;

procedure TfrmMJManageNewFDNewLable.Edit7Click(Sender: TObject);
begin
  {if Trim(Edit7.Text)='' then
  begin
    Edit7.Text:='√';
    if FCK=9 then
    begin
      if CommOpen(frmMJManageNewFDNewSF.Handle,pchar(PortNoStr),500,1)<1 then
      begin
        FCK:=1;
        showmessage('串口打开失败!');
        Exit;
      end
      else
      begin
        FCK:=9;
      end;
    end;
  end else
  begin
    Edit7.Text:='';
    if FCK=9 then
      CommClose(pchar(PortNoStr))
    else begin
      Exit;
    end;
  end;  }
end;

procedure TfrmMJManageNewFDNewLable.BTPrintKeyPress(Sender: TObject;
  var Key: Char);
begin
  if Key=#13 then
  begin
    BTPrint.Click;
  end;
end;

procedure TfrmMJManageNewFDNewLable.MJQty4KeyPress(Sender: TObject;
  var Key: Char);
begin
  if Key = #13 then
	begin
		Key:= #0;
    MJLen.SetFocus;
	 //	SelectNext(ActiveControl as TWinControl, True, True);
	end;
end;

procedure TfrmMJManageNewFDNewLable.MJQty2KeyPress(Sender: TObject;
  var Key: Char);
begin
  if Key = #13 then
	begin
		Key:= #0;
    BTPrint.SetFocus;
	 	//SelectNext(ActiveControl as TWinControl, True, True);
	end;
end;

procedure TfrmMJManageNewFDNewLable.MJLenKeyPress(Sender: TObject;
  var Key: Char);
begin
  if Key = #13 then
	begin
		Key:= #0;
    MJQty2.SetFocus;
	 //	SelectNext(ActiveControl as TWinControl, True, True);
	end;
end;

procedure TfrmMJManageNewFDNewLable.MJMaoZKeyPress(Sender: TObject;
  var Key: Char);
begin
  if Key = #13 then
	begin
		Key:= #0;
    MJLen.SetFocus;
	 	//SelectNext(ActiveControl as TWinControl, True, True);
	end;
end;

procedure TfrmMJManageNewFDNewLable.Edit8Click(Sender: TObject);
begin
  if Trim(Edit8.Text)='' then
  begin
    Edit8.Text:='√';
  end else
  begin
    Edit8.Text:='';
  end;
end;

procedure TfrmMJManageNewFDNewLable.ToolButton2Click(Sender: TObject);
begin
  try
    frmOrderInPut:=TfrmOrderInPut.Create(Application);
    with frmOrderInPut do
    begin
      frmOrderInPut.FMainId:=Trim(Self.FMainId);
      frmOrderInPut.PState:=1;
      frmOrderInPut.cxPageControl1.Pages[2].TabVisible:=False;
      frmOrderInPut.cxPageControl1.Pages[3].TabVisible:=False;
      frmOrderInPut.cxPageControl1.Pages[4].TabVisible:=False;
      frmOrderInPut.ToolBar2.Visible:=False;
      frmOrderInPut.ToolButton18.Visible:=False;
      frmOrderInPut.ToolButton13.Visible:=False;
      frmOrderInPut.TBSave.Visible:=False;
      frmOrderInPut.ToolBar7.Visible:=False;
      frmOrderInPut.JYInt:=99;
      frmOrderInPut.Panel1.Enabled:=False;
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmOrderInPut.Free;
  end;
end;

procedure TfrmMJManageNewFDNewLable.MJLenChange(Sender: TObject);
begin
  MJLenMa.Text:='';
end;

procedure TfrmMJManageNewFDNewLable.MJQty2Change(Sender: TObject);
var
  FReal:Double;
begin
 // if TryStrToFloat(MJQty2.Text,FReal)=False then Exit;
  if Trim(MJMaoZ.Text)='' then Exit;
  if Trim(MJQty2.Text)<>'' then
  begin
    if Trim(ZSUnit.Text)='KG' then
    begin
      MJQty4.Text:=FloatToStr(StrToFloat(MJQty4.Text)-StrToFloat(MJQty2.Text)) ;
    end;
  end else
  begin
    if Trim(ZSUnit.Text)='KG' then
    begin
      MJQty4.Text:=FloatToStr(StrToFloat(MJMaoZ.Text)-StrToFloat(MJQty3.Text)) ;
    end;
  end;
  if Trim(MJSJKZ.Text)='' then Exit;
  if TryStrToFloat(MJSJKZ.Text,FReal)=False then
  begin
    Application.MessageBox('克重录入错误!','提示',0);
    Exit;
  end;
  if Trim(MJFK.Text)='' then Exit;
  if TryStrToFloat(MJFK.Text,FReal)=False then
  begin
    Application.MessageBox('幅宽录入错误!','提示',0);
    Exit;
  end;
  if StrToFloat(MJSJKZ.Text)*StrToFloat(MJFK.Text)=0 then Exit;
  if StrToFloat(MJSJKZ.Text)*StrToFloat(MJFK.Text)=0 then Exit;
  if Trim(KgZMiXS)='' then
  begin
    if Trim(KgZMaXS)='' then
      MJLen.Text:=FormatFloat('0.0',StrToFloat(MJQty4.Text)*1000*100/StrToFloat(MJSJKZ.Text)/StrToFloat(MJFK.Text))
    else
      MJLen.Text:=FormatFloat('0.0',StrToFloat(MJQty4.Text)*StrToFloat(KgZMaXS)*0.9144);
  end
  else
    MJLen.Text:=FormatFloat('0.0',StrToFloat(MJQty4.Text)*StrToFloat(KgZMiXS));
  if Trim(KgZMaXS)='' then
  begin
    if Trim(KgZMiXS)='' then
      MJLenMa.Text:=FormatFloat('0.0',StrToFloat(MJQty4.Text)*1000*100/StrToFloat(MJSJKZ.Text)/StrToFloat(MJFK.Text)*1.0936)
    else
     MJLenMa.Text:=FormatFloat('0.0',StrToFloat(MJQty4.Text)*StrToFloat(KgZMiXS)*1.0936);
  end
  else
    MJLenMa.Text:=FormatFloat('0.0',StrToFloat(MJQty4.Text)*StrToFloat(KgZMaXS));
end;

end.
