unit U_ZJManageNew;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, ExtCtrls, cxStyles, cxCustomData, cxGraphics,
  cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, cxTextEdit,
  cxGridLevel, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
  cxClasses, cxControls, cxGridCustomView, cxGrid, MovePanel, ADODB,
  DBClient, ComCtrls, RM_Common, RM_Class, RM_GridReport, RM_System,
  RM_Dataset;

type
  TfrmZJManageNew = class(TForm)
    MJID: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    ScrollBox1: TScrollBox;
    SpeedButton13: TSpeedButton;
    SpeedButton14: TSpeedButton;
    SpeedButton15: TSpeedButton;
    SpeedButton16: TSpeedButton;
    SpeedButton17: TSpeedButton;
    SpeedButton18: TSpeedButton;
    SpeedButton19: TSpeedButton;
    SpeedButton20: TSpeedButton;
    SpeedButton21: TSpeedButton;
    SpeedButton22: TSpeedButton;
    SpeedButton23: TSpeedButton;
    SpeedButton24: TSpeedButton;
    SpeedButton25: TSpeedButton;
    SpeedButton26: TSpeedButton;
    SpeedButton27: TSpeedButton;
    SpeedButton28: TSpeedButton;
    Button1: TButton;
    Button3: TButton;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    tv2CDType: TcxGridDBColumn;
    tv2CDWZ: TcxGridDBColumn;
    v2Column2: TcxGridDBColumn;
    Tv2CDQty: TcxGridDBColumn;
    Tv2CDReason: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    cxStyleRepository5: TcxStyleRepository;
    cxStyle6: TcxStyle;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    cxStyle2: TcxStyle;
    cxGrid3: TcxGrid;
    Tv3: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    Button6: TButton;
    Panel6: TPanel;
    Panel1: TPanel;
    SmalMF1: TEdit;
    SmalMF2: TEdit;
    SmalMF3: TEdit;
    SmalMF4: TEdit;
    SmalMF5: TEdit;
    SmalMF6: TEdit;
    SmalMF7: TEdit;
    SmalMF8: TEdit;
    SmalMF9: TEdit;
    SmalMF10: TEdit;
    SmalMF11: TEdit;
    SmalMF12: TEdit;
    Panel2: TPanel;
    XJLen1: TEdit;
    XJLen2: TEdit;
    XJLen3: TEdit;
    XJLen4: TEdit;
    XJLen5: TEdit;
    XJLen6: TEdit;
    XJLen7: TEdit;
    XJLen8: TEdit;
    XJLen9: TEdit;
    XJLen10: TEdit;
    XJLen11: TEdit;
    XJLen12: TEdit;
    Panel3: TPanel;
    XJMaoZ1: TEdit;
    XJMaoZ2: TEdit;
    XJMaoZ3: TEdit;
    XJMaoZ4: TEdit;
    XJMaoZ5: TEdit;
    XJMaoZ6: TEdit;
    XJMaoZ7: TEdit;
    XJMaoZ8: TEdit;
    XJMaoZ9: TEdit;
    XJMaoZ10: TEdit;
    XJMaoZ11: TEdit;
    XJMaoZ12: TEdit;
    Panel4: TPanel;
    Sel1: TEdit;
    Sel2: TEdit;
    Sel3: TEdit;
    Sel4: TEdit;
    Sel5: TEdit;
    Sel6: TEdit;
    Sel7: TEdit;
    Sel8: TEdit;
    Sel9: TEdit;
    Sel10: TEdit;
    Sel11: TEdit;
    Sel12: TEdit;
    ADOQueryTemp: TADOQuery;
    Panel5: 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;
    SpeedButton49: TSpeedButton;
    cxGrid4: TcxGrid;
    TvSel: TcxGridDBTableView;
    vSelColumn1: TcxGridDBColumn;
    vSelColumn4: TcxGridDBColumn;
    vSelColumn6: TcxGridDBColumn;
    vSelColumn5: TcxGridDBColumn;
    cxGridDBColumn7: TcxGridDBColumn;
    vSelColumn7: TcxGridDBColumn;
    cxGridDBColumn5: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    vSelColumn2: TcxGridDBColumn;
    cxGridLevel3: TcxGridLevel;
    vSelColumn3: TcxGridDBColumn;
    vSelColumn8: TcxGridDBColumn;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    DataSource1: TDataSource;
    Cds_Main: TClientDataSet;
    Button2: TButton;
    MJCDHZ: TRichEdit;
    DataSource3: TDataSource;
    CDS_XJID: TClientDataSet;
    DataSource2: TDataSource;
    CDS_XJCD: TClientDataSet;
    v2Column3: TcxGridDBColumn;
    v3Column1: TcxGridDBColumn;
    cxStyleRepository2: TcxStyleRepository;
    cxStyle3: TcxStyle;
    SmalNote: TRichEdit;
    Label7: TLabel;
    RMDB_Main: TRMDBDataSet;
    RM2: TRMGridReport;
    ADOQueryPrint: TADOQuery;
    MovePanel2: TMovePanel;
    Label8: TLabel;
    cxGrid1: TcxGrid;
    TvHJ: TcxGridDBTableView;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridLevel4: TcxGridLevel;
    DSHJ: TDataSource;
    CDS_HJ: TClientDataSet;
    vHJColumn1: TcxGridDBColumn;
    vHJColumn2: TcxGridDBColumn;
    vHJColumn3: TcxGridDBColumn;
    Label9: TLabel;
    HJMJID: TEdit;
    Button7: TButton;
    Button8: TButton;
    vHJColumn4: TcxGridDBColumn;
    vHJColumn5: TcxGridDBColumn;
    vHJColumn6: TcxGridDBColumn;
    vHJColumn7: TcxGridDBColumn;
    vHJColumn8: TcxGridDBColumn;
    vHJColumn9: TcxGridDBColumn;
    vHJColumn10: TcxGridDBColumn;
    vHJColumn11: TcxGridDBColumn;
    Panel7: TPanel;
    XJFree1: TEdit;
    XJFree2: TEdit;
    XJFree3: TEdit;
    XJFree4: TEdit;
    XJFree5: TEdit;
    XJFree6: TEdit;
    XJFree7: TEdit;
    XJFree8: TEdit;
    XJFree9: TEdit;
    XJFree10: TEdit;
    XJFree11: TEdit;
    XJFree12: TEdit;
    MovePanel1: TMovePanel;
    Label17: TLabel;
    Label18: TLabel;
    Label19: TLabel;
    Label20: TLabel;
    Label21: TLabel;
    CDBeg: TEdit;
    Button4: TButton;
    Button5: TButton;
    CDEnd: TEdit;
    Panel8: TPanel;
    XjJt1: TEdit;
    XjJt2: TEdit;
    XjJt3: TEdit;
    XjJt4: TEdit;
    XjJt5: TEdit;
    XjJt6: TEdit;
    XjJt7: TEdit;
    XjJt8: TEdit;
    XjJt9: TEdit;
    XjJt10: TEdit;
    XjJt11: TEdit;
    XjJt12: TEdit;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    MovePanel3: TMovePanel;
    Button9: TButton;
    Button10: TButton;
    Password: TEdit;
    Label13: TLabel;
    procedure Sel1Click(Sender: TObject);
    procedure Edit64Click(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure SpeedButton12Click(Sender: TObject);
    procedure SpeedButton49Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormDestroy(Sender: TObject);
    procedure XJLen1Click(Sender: TObject);
    procedure MJIDKeyPress(Sender: TObject; var Key: Char);
    procedure Button2Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure SpeedButton13Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Tv2CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure Button3Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure Tv3CellClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure Button1Click(Sender: TObject);
    procedure Button8Click(Sender: TObject);
    procedure Button7Click(Sender: TObject);
    procedure HJMJIDKeyPress(Sender: TObject; var Key: Char);
    procedure TvHJCellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure Button9Click(Sender: TObject);
    procedure Button10Click(Sender: TObject);
    procedure PasswordClick(Sender: TObject);
  private
    { Private declarations }
    FCDName:string;
    procedure ClearSpenndHit();
    procedure VisbleControl(Panel55:TWinControl;XS:Boolean;SXCount:Integer);
    function ChkEditNULL(panel55:TWinControl):Boolean;
    procedure InitJP();
    procedure InitGridCD();
    procedure InitGridCDID();
    procedure ClearControl(Panel55:TWinControl;ConValue:String;SXCount:Integer);
    procedure PrintData(FXJID:string;CDFlag:String);
  public
    { Public declarations }
  end;

var
  frmZJManageNew: TfrmZJManageNew;

implementation
uses
U_DataLink,U_Fun,U_ZDYHelp,U_iniParam,AES,ElAES,U_LabelPrint;

{$R *.dfm}

procedure TfrmZJManageNew.Sel1Click(Sender: TObject);
begin
  if Trim(TcxTextEdit(Sender).Text)='' then
  begin
    TcxTextEdit(Sender).Text:='√';
  end else
  begin
    TcxTextEdit(Sender).Text:='';
  end;
end;

procedure TfrmZJManageNew.Edit64Click(Sender: TObject);
var
  i:Integer;
begin
  Panel5.Visible:=True;
  with Panel5 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 TfrmZJManageNew.ClearSpenndHit();
var
  i:Integer;
begin
  with Panel5 do
  begin
    for i:=0 to ControlCount-1 do
    begin
      if Controls[i] is TSpeedButton then
      begin
        TSpeedButton(Controls[i]).Hint:='';
      end;
    end;
  end;
end;
procedure TfrmZJManageNew.VisbleControl(Panel55:TWinControl;XS:Boolean;SXCount:Integer);
var
  i:Integer;
begin
  with Panel55 do
  begin
    for i:=0 to SXCount-1 do
    begin
      Controls[i].Visible:=XS;
    end;
  end;
end;
procedure TfrmZJManageNew.ClearControl(Panel55:TWinControl;ConValue:String;SXCount:Integer);
var
  i:Integer;
begin
  with Panel55 do
  begin
    for i:=0 to SXCount-1 do
    begin
      TEdit(Controls[i]).Text:=ConValue;
    end;
  end;
end;

procedure TfrmZJManageNew.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 TfrmZJManageNew.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 TfrmZJManageNew.SpeedButton49Click(Sender: TObject);
begin
  Panel5.Visible:=false;
end;

function TfrmZJManageNew.ChkEditNULL(panel55:TWinControl):Boolean;
var
  i:Integer;
begin
  Result:=False;
  with panel55 do
  begin
    for i:=0 to panel55.ControlCount-1 do
    begin
      if Controls[i].Visible=True then
      begin
        if Trim(TEdit(Controls[i]).Text)='' then
        begin
          Result:=False;
          Break;
        end else
        begin
          Result:=True;
        end;
      end;

    end;
  end;

end;

procedure TfrmZJManageNew.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  Action:=caFree;
end;

procedure TfrmZJManageNew.FormDestroy(Sender: TObject);
begin
  frmZJManageNew:=nil;
end;

procedure TfrmZJManageNew.XJLen1Click(Sender: TObject);
var
  i:Integer;
begin
  if CDS_XJID.IsEmpty=False then
  begin
    if CDS_XJID.Locate('XJInt',TEdit(Sender).tag,[])=True then
    begin
      TEdit(Sender).Text:=Trim(CDS_XJID.fieldbyname(Copy(Trim(TEdit(Sender).Name),1,Length(Trim(TEdit(Sender).Name))-1)).AsString);
      Panel5.Visible:=False;
      Exit;
    end;
  end;
  Panel5.Visible:=True;
  with Panel5 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;
 // Panel5.Left:=Edit14.Left;
  //Panel5.top:=Edit14.top+Edit14.Height;
end;

procedure TfrmZJManageNew.MJIDKeyPress(Sender: TObject; var Key: Char);
var
  FCount,i:Integer;
  FXJXH:String;
begin
  if Key=#13 then
  begin
    MJID.SelectAll;
    ClearControl(Panel1,'',Panel1.ControlCount);
    ClearControl(Panel2,'',Panel2.ControlCount);
    ClearControl(Panel3,'',Panel3.ControlCount);
    Label12.Visible:=True;
    Label12.Caption:=Trim(MJID.Text);
    try
      ADOQueryMain.DisableControls;
      with ADOQueryMain do
      begin
        Close;
        sql.Clear;
        sql.add('select MJCDHZ=dbo.F_Get_WFBOrder_SubStr(A.MJID,''MJCDHZ''), ');
        SQL.Add('A.*,B.*,C.OrderNo from WFB_MJJY A inner join WFBOrder_Sub B on A.SubId=B.SubId');
        sql.Add('inner join WFBOrder_Main C on A.MainId=C.MainId');
        sql.Add('where A.MJID='''+Trim(MJID.Text)+'''');
        sql.Add(' and A.Valie=''Y'' ');
        Open;
      end;
      SCreateCDS20(ADOQueryMain,Cds_Main);
      SInitCDSData20(ADOQueryMain,Cds_Main);
      if Cds_Main.IsEmpty then
      begin
        MJCDHZ.Text:='';
        InitGridCDID();
        InitGridCD();
        Label12.Visible:=False;
        MJID.Text:='';
        Application.MessageBox('条码错误！','提示',0);
        Exit;
      end;
      MJCDHZ.Visible:=True;
      MJCDHZ.Text:=Trim(Cds_Main.fieldbyname('MJCDHZ').AsString);
      SmalNote.Text:=Trim(Cds_Main.fieldbyname('SmalNote').AsString);
      if Cds_Main.FieldByName('SmalCount').Value<1 then
      begin
        Application.MessageBox('分切个数不能小于1','提示',0);
        Exit;
      end else
      begin
        FCount:=Cds_Main.FieldByName('SmalCount').Value;
        VisbleControl(Panel1,False,Panel1.ControlCount);
        VisbleControl(Panel2,False,Panel2.ControlCount);
        VisbleControl(Panel3,False,Panel3.ControlCount);
        VisbleControl(Panel4,False,Panel4.ControlCount);
        VisbleControl(Panel1,True,FCount);
        VisbleControl(Panel2,True,FCount);
        VisbleControl(Panel3,True,FCount);
        VisbleControl(Panel4,True,FCount);
        VisbleControl(Panel7,True,FCount);
        VisbleControl(Panel8,True,FCount);
        SCSHDataCDS(Cds_Main,Panel1,0);
      end;
      InitGridCDID();
      InitGridCD();
    finally
      ADOQueryMain.EnableControls;
    end;
    MJID.Text:='';
    {if CDS_XJID.IsEmpty=False then
    begin
      with CDS_XJID do
      begin
        First;
        while not Eof do
        begin

          FXJXH:=Trim(CDS_XJID.fieldbyname('XJInt').AsString);
          (FindComponent('XJLen'+FXJXH) as TEdit).Text:=Trim(CDS_XJID.fieldbyname('XJLen').AsString);
          (FindComponent('XJMaoZ'+FXJXH) as TEdit).Text:=Trim(CDS_XJID.fieldbyname('XJMaoZ').AsString);
          (FindComponent('XJFree'+FXJXH) as TEdit).Text:=Trim(CDS_XJID.fieldbyname('XJFree').AsString);
          (FindComponent('XJJt'+FXJXH) as TEdit).Text:=Trim(CDS_XJID.fieldbyname('XJJt').AsString);
          Next;
        end;
      end;
    end; }
  end;
end;

procedure TfrmZJManageNew.Button2Click(Sender: TObject);
begin
  WriteCxGrid('大卷提示信息',TvSel,'无纺布生产管理');
  Close;
end;

procedure TfrmZJManageNew.FormShow(Sender: TObject);
begin
  ReadCxGrid('大卷提示信息',TvSel,'无纺布生产管理');
  InitJP();
end;

procedure TfrmZJManageNew.InitJP();
var
  AA:array[0..100] of string;
  i,j:Integer;
begin
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select ZDYName from KH_Zdy where Type=''WFBCDZJ'' order by ZDYNO ');
    Open;
  end;
  if ADOQueryTemp.IsEmpty then
  begin
    Application.MessageBox('没有定义小卷疵点！','提示',0);
    Exit;
  end;
  with ADOQueryTemp do
  begin
    First;
    i:=0;
    while not Eof do
    begin
      AA[i]:=Trim(fieldbyname('ZDYName').AsString);
      i:=i+1;
      Next;
    end;
  end;
  i:=i-1;
  if i>17 then
  begin
    i:=29;
  end;
  for j:=0 to i do
  begin
    with ScrollBox1 do
    begin
      TSpeedButton(Controls[j]).Visible:=True;
      TSpeedButton(Controls[j]).Hint:=AA[j];
      if Length(AA[j])>4 then
      begin
        TSpeedButton(Controls[j]).Caption:=Copy(Trim(AA[j]),1,4)+#13+Copy(Trim(AA[j]),5,Length(AA[j])-4);
      end else
        TSpeedButton(Controls[j]).Caption:=AA[j];
    end;
  end;
end;

procedure TfrmZJManageNew.Button4Click(Sender: TObject);
var
  i:Integer;
begin
  if Trim(CDBeg.Text)='' then
  begin
    Application.MessageBox('位置不能为空！','提示',0);
    exit;
  end;
  with Panel4 do
  begin
    for i:=0 to Cds_Main.fieldbyname('SmalCount').AsInteger-1 do
    begin
      if TEdit(Controls[i]).Text='√' then
      begin
        with CDS_XJCD do
        begin
          Append;
          FieldByName('cdname').Value:=Trim(FCDName);
          FieldByName('CDbeg').Value:=Trim(CDBeg.Text);
          FieldByName('CDEnd').Value:=Trim(CDEnd.Text);
          if Trim(CDEnd.Text)<>'' then
          begin
            FieldByName('CDQty').Value:=StrToFloat(CDEnd.Text)-StrToFloat(CDBeg.Text);
          end else
          begin
            FieldByName('CDQty').Value:=0;
          end;
          FieldByName('XJInt').Value:=i+1;
          Post;
        end;
      end;
    end;
  end;
  CDBeg.Text:='';
  CDEnd.Text:='';
  MovePanel1.Visible:=False;
end;

procedure TfrmZJManageNew.SpeedButton13Click(Sender: TObject);
var
  i,j:Integer;
begin
  if Cds_Main.IsEmpty then Exit;
  j:=0;
  with Panel4 do
  begin
    for i:=0 to Cds_Main.fieldbyname('SmalCount').AsInteger-1 do
    begin
      if Controls[i].Visible=True then
      begin
        if TEdit(Controls[i]).Text='√' then
        begin
          j:=9;
        end;
      end;
    end;
  end;
  if j=0 then
  begin
    Application.MessageBox('没有选择小卷','提示',0);
    Exit;
  end;
  FCDName:=Trim(TSpeedButton(Sender).Hint);
  MovePanel1.Visible:=True;
  Label21.Caption:=Trim(FCDName);
  CDBeg.SetFocus;

  Panel5.Visible:=True;
  with Panel5 do
  begin
    for i:=0 to ControlCount-1 do
    begin
      if Controls[i] is TSpeedButton then
      begin
        TSpeedButton(Controls[i]).Hint:=Trim('CDBeg');
      end;
    end;
  end;
end;
procedure TfrmZJManageNew.InitGridCD();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      if Trim(CDS_XJID.fieldbyname('XJID').AsString)<>'' then
      begin
        sql.Add('select A.*,B.XJInt from WFB_XJJY_CD A inner join WFB_XJJY B on A.XJID=B.XJID');
        sql.Add('  where B.MJID='''+Trim(MJID.Text)+'''');
      end
      else
        sql.Add('select A.*,B.XJInt from WFB_XJJY_CD A inner join WFB_XJJY B on A.XJID=B.XJID where 1<>1');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_XJCD);
    SInitCDSData20(ADOQueryMain,CDS_XJCD);
  finally
    ADOQueryMain.EnableControls;
  end;
end;
procedure TfrmZJManageNew.InitGridCDID();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from WFB_XJJY where MJID='''+Trim(MJID.Text)+'''');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_XJID);
    SInitCDSData20(ADOQueryMain,CDS_XJID);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmZJManageNew.Button5Click(Sender: TObject);
begin
  MovePanel1.Visible:=False;
end;

procedure TfrmZJManageNew.Tv2CellDblClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  if Trim(CDS_XJCD.fieldbyname('XJID').AsString)<>'' then Exit;
  if Application.MessageBox('确定要删除数据吗？','提示',32+4)<>IDYES then Exit;
  CDS_XJCD.Delete;
end;

procedure TfrmZJManageNew.Button3Click(Sender: TObject);
var
  i,j,FXJInt,CRID:Integer;
  FXJSJKZ:Double;
  maxno,maxnocd,MaxCkNo,MaxCkSubNo,XJBanZu,FFXJLen,FFXJMaoZ,FFXJFk,FFXJFree,FFXJJt:String;
begin
  if Cds_Main.IsEmpty then Exit;
  with Panel2 do
  begin
    for i:=0 to  Cds_Main.fieldbyname('SmalCount').AsInteger-1 do
    begin
      if TEdit(Controls[i]).Text='' then
      begin
        Application.MessageBox('长度未全部录入，不能打印！','提示',0);
        Exit;
      end;
    end;
  end;
  with Panel3 do
  begin
    for i:=0 to  Cds_Main.fieldbyname('SmalCount').AsInteger-1 do
    begin
      if TEdit(Controls[i]).Text='' then
      begin
        Application.MessageBox('重量未全部录入，不能打印！','提示',0);
        Exit;
      end;
    end;
  end;
  j:=0;
  with Panel4 do
  begin
    for i:=0 to Cds_Main.fieldbyname('SmalCount').AsInteger-1 do
    begin
      if Controls[i].Visible=True then
      begin
        if TEdit(Controls[i]).Text='√' then
        begin
          if j=0 then
          begin
            j:=9;
            FXJInt:=i+1;
          end
          else
            j:=j+1;
        end;
      end;
    end;
  end;
  if j=0 then
  begin
    Application.MessageBox('没有选择小卷！','提示',0);
    Exit;
  end else
  if j>9 then
  begin
    Application.MessageBox('不能选择多个小卷！','提示',0);
    Exit;
  end;
  if Trim(TEdit(FindComponent('XJLen'+Trim(IntToStr(FXJInt)))).Text)='' then
  begin
    Application.MessageBox('长度不能为空！','提示',0);
    Exit;
  end else
  begin
    FFXJLen:=Trim(TEdit(FindComponent('XJLen'+Trim(IntToStr(FXJInt)))).Text);
  end;
  if Trim(TEdit(FindComponent('XJMaoZ'+Trim(IntToStr(FXJInt)))).Text)='' then
  begin
    Application.MessageBox('毛重不能为空！','提示',0);
    Exit;
  end else
  begin
    FFXJMaoZ:=Trim(TEdit(FindComponent('XJMaoZ'+Trim(IntToStr(FXJInt)))).Text);
  end;
  if Trim(TEdit(FindComponent('SmalMF'+Trim(IntToStr(FXJInt)))).Text)='' then
  begin
    Application.MessageBox('毛重不能为空！','提示',0);
    Exit;
  end else
  begin
    FFXJFk:=Trim(TEdit(FindComponent('SmalMF'+Trim(IntToStr(FXJInt)))).Text);
  end;
  if Trim(TEdit(FindComponent('XJFree'+Trim(IntToStr(FXJInt)))).Text)='' then
  begin
    FFXJFree:='0';
  end else
  begin
    FFXJFree:=Trim(TEdit(FindComponent('XJFree'+Trim(IntToStr(FXJInt)))).Text);
  end;
  if Trim(TEdit(FindComponent('XJJt'+Trim(IntToStr(FXJInt)))).Text)='' then
  begin
    FFXJJt:='0';
  end else
  begin
    FFXJJt:=Trim(TEdit(FindComponent('XJJt'+Trim(IntToStr(FXJInt)))).Text);
  end;
  with ADOQueryTemp do
  begin
    Close;
    SQL.Clear;
    sql.Add('select * from WFB_XJJY where MJID='''+Trim(Cds_Main.fieldbyname('MJID').AsString)+'''');
    SQL.Add(' and XJInt='+Inttostr(FXJInt));
    Open;
  end;
  if ADOQueryTemp.IsEmpty=False then
  begin
    Application.MessageBox('已打过条码，请尝试重新打印！','',0);
    Exit;
  end;
  FXJSJKZ:=StrToFloat(FFXJMaoZ)/(StrToFloat(FFXJLen)*StrToFloat(FFXJFk)/100)*1000;
  if( (FXJSJKZ-Cds_Main.FieldByName('MJSJKZ').Value)/Cds_Main.FieldByName('MJSJKZ').Value )<-0.3 then
  begin
    Application.MessageBox('输入错误，请检查数据！','提示',0);
    Exit;
  end;
  if( (FXJSJKZ-Cds_Main.FieldByName('MJSJKZ').Value)/Cds_Main.FieldByName('MJSJKZ').Value )>0.3 then
  begin
    Application.MessageBox('输入错误，请检查数据！','提示',0);
    Exit;
  end;
  try
    ADOQueryCmd.Connection.BeginTrans;
    //////////////////////////////////////////////////////////////保存小卷主数据
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from SY_User where UserId='''+Trim(DCode)+'''');
      Open;
    end;
    XJBanZu:=Trim(ADOQueryTemp.fieldbyname('BanZu').AsString);
    if GetLSNo(ADOQueryCmd,maxno,Trim(XJFlag),'WFB_XJJY',4,1)=false then
    begin
      ADOQueryCmd.Connection.RollbackTrans;
      Application.MessageBox('取小卷最大号异常！','提示',0);
      Exit;
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.add('select * from WFB_XJJY where 1<>1');
      Open;
    end;
    with ADOQueryCmd do
    begin
      Append;
      FieldByName('MJID').Value:=Trim(Cds_Main.fieldbyname('MJID').AsString);
      FieldByName('XJID').Value:=Trim(maxno);
      FieldByName('XJInt').Value:=FXJInt;
      FieldByName('XJLen').Value:=StrToFloat(FFXJLen);
      FieldByName('XJMaoZ').Value:=StrToFloat(FFXJMaoZ);
      FieldByName('XJFK').Value:=StrToFloat(FFXJFk);
      FieldByName('XJFree').Value:=StrToFloat(FFXJFree);
      FieldByName('XJJt').Value:=StrToFloat(FFXJJt);
      FieldByName('XJBanZu').Value:=Trim(XJBanZu);
      FieldByName('JTTYpe').Value:=Trim(XJFlag);
      FieldByName('Filler').Value:=Trim(DName);
      FieldByName('XJSJKZ').Value:=StrToFloat(FFXJMaoZ)/(StrToFloat(FFXJLen)*StrToFloat(FFXJFk)/100)*1000;
      //FieldByName('')
      Post;
    end;
    with CDS_XJID do
    begin
      Append;
      FieldByName('XJID').Value:=Trim(maxno);
      FieldByName('XJInt').Value:=FXJInt;
      FieldByName('XJLen').Value:=StrToFloat(FFXJLen);
      FieldByName('XJMaoZ').Value:=StrToFloat(FFXJMaoZ);
      FieldByName('XJFK').Value:=StrToFloat(FFXJFk);
      FieldByName('XJFree').Value:=StrToFloat(FFXJFree);
      FieldByName('XJJt').Value:=StrToFloat(FFXJJt);
      Post;
    end;
    //////////////////////////////////////////////////////////////保存小卷主数据
    //////////////////////////////////////////////////////////////保存小卷疵点数据
    with CDS_XJCD do
    begin
      First;
      while not Eof do
      begin
        if CDS_XJCD.FieldByName('XJInt').Value=FXJInt then
        begin
          if GetLSNo(ADOQueryCmd,maxnocd,'XC','WFB_XJJY_CD',5,1)=False then
          begin
            ADOQueryCmd.Connection.RollbackTrans;
            Application.MessageBox('取小卷疵点号失败！','提示',0);
            Exit;
          end;
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            SQL.Add('select * from WFB_XJJY_CD where 1<>1');
            Open;
          end;
          with ADOQueryCmd do
          begin
            Append;
            FieldByName('XJID').Value:=Trim(maxno);
            FieldByName('XCID').Value:=Trim(maxnocd);
            FieldByName('CDName').Value:=CDS_XJCD.fieldbyname('CDName').Value;
            FieldByName('CDBeg').Value:=CDS_XJCD.fieldbyname('CDBeg').Value;
            FieldByName('CDEnd').Value:=CDS_XJCD.fieldbyname('CDEnd').Value;
            FieldByName('CDQty').Value:=CDS_XJCD.fieldbyname('CDQty').Value;
            Post;
          end;
        end;
        Next;
      end;
    end;
    //////////////////////////////////////////////////////////////保存小卷疵点数据
    //////////////////////////////////////////////////////////////保存到半成品仓库////////////////////////////////////////////////
    with ADOQueryCmd 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:=ADOQueryCmd.fieldbyname('CRID').Value;
    if GetLSNo(ADOQueryTemp,MaxCkNo,'JR','CK_BanCP_CR',4,1)=False then
    begin
      ADOQueryCmd.Connection.RollbackTrans;
      Application.MessageBox('取半成品仓库最大号失败！','提示',0);
      Exit;
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from CK_BanCP_CR where 1<>1');
      Open;
    end;
    with ADOQueryCmd do
    begin
      Append;
      FieldByName('MainId').Value:=Trim(Cds_Main.fieldbyname('MainId').AsString);
      FieldByName('SubId').Value:=Trim(Cds_Main.fieldbyname('SubId').AsString);
      FieldByName('MJID').Value:=Trim(Cds_Main.fieldbyname('MJId').AsString);
      FieldByName('XJID').Value:=Trim(maxno);
      FieldByName('BCID').Value:=Trim(MaxCkNo);
      FieldByName('CRTime').Value:=SGetServerDateTime(ADOQueryTemp);
      FieldByName('CRFlag').Value:='入库';
      FieldByName('CRType').Value:='检验入库';
      FieldByName('JTType').Value:=Trim(XJFlag);
      FieldByName('CRID').Value:=CRID;
      FieldByName('KGQty').Value:=StrToFloat(FFXJMaoZ);
      FieldByName('MQty').Value:=StrToFloat(FFXJLen);
      FieldByName('Filler').Value:=Trim(DName);
      FieldByName('FillTime').Value:=SGetServerDateTime(ADOQueryTemp);
      Post;
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from CK_BanCP_KC where 1<>1');
      Open;
    end;
    with ADOQueryCmd do
    begin
      Append;
      FieldByName('CRID').Value:=CRID;
      FieldByName('BCID').Value:=Trim(MaxCkNo);
      FieldByName('XJID').Value:=Trim(maxno);
      FieldByName('KCKGQty').Value:=StrToFloat(FFXJMaoZ);
      FieldByName('KCMQty').Value:=StrToFloat(FFXJLen);
      Post;
    end;
    //////////////////////////////////////////////////////////////保存到半成品仓库////////////////////////////////////////////////
    ADOQueryCmd.Connection.CommitTrans;
    PrintData(Trim(maxno),'');
    //Application.MessageBox('操作成功！','提示',0);
    //MJID.SelectAll;
    Exit;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('保存异常！','提示',0);
  end;
end;
procedure TfrmZJManageNew.PrintData(FXJID:string;CDFlag:String);
var
   fPrintFile,LabInt,LabName:String;
begin
  if Trim(FXJID)='' then exit;
  DataLink_WFBProducttion.ADOLink.Connected:=False;
  DataLink_WFBProducttion.ADOLink.Connected:=True;
  if Trim(CDFlag)<>'' then
  begin
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('Update WFB_XJJY Set PrtAgnFlag=1,PrtAgnDate=getdate(),PrtAgnPerson='''+Trim(DName)+'''');
      sql.Add(' where XJID='''+Trim(FXJID)+'''');
      ExecSQL;
    end;
  end;
  with ADOQueryTemp do
  begin
    Close;
    SQL.Clear;
    sql.Add(' select C.LbXInt,C.LbXName from WFB_XJJY A');
    sql.Add(' inner join WFB_MJJY B on A.MJID=B.MJID');
    sql.Add(' inner join WFBOrder_Main C on B.MainId=C.MainId');
    sql.Add(' where A.XJID='''+Trim(FXJID)+'''');
    Open;
  end;
  if ADOQueryTemp.IsEmpty=False  then
  begin
    LabInt:=ADOQueryTemp.fieldbyname('LbXInt').AsString;
    LabName:=ADOQueryTemp.fieldbyname('LbXName').AsString;
  end ;
  if Trim(LabName)='' then 
  begin
    Application.MessageBox('小卷标签未设置！','提示',0);
    Exit;
  end;
 { try
    frmLabelPrint:=TfrmLabelPrint.Create(Application);
    with frmLabelPrint do
    begin
      fLabelId:=LabInt;
      FFCDFlag:=Trim(CDFlag);
      fKeyNo:=Trim(FXJID);
      fIsPreviewPrint:=True;
      frmLabelPrint.Button1.Click;
     // if ShowModal=1 then
      //begin

     // end;
    end;
  finally
    frmLabelPrint.Free;
  end;  }
  with ADOQueryPrint do
  begin
    Close;
    sql.Clear;
    sql.Add('select RTrim(AA.XJID) XJID,RTrim(Cast(AA.XJSJKZ as varchar(20))) XJSJKZ,RTrim(cast(Cast(AA.XJFK*10 as int) as varchar(20))) XJFK,RTrim(B.OrderNo)+'''+Trim(CDFlag)+''' OrderNo');
    sql.Add(',Rtrim(C.SWFBColor) SWFBColor, YLPB=dbo.F_Get_WFBOrder_SubStr(C.SubId,''YLPBSZ'')');
    SQL.Add(',EngColor=(select Top 1 note from KH_Zdy where ZdyName=C.SWFBColor)');
    sql.Add(',Rtrim(Cast(AA.XJlen as varchar(20))) XJlen,Rtrim(Cast(AA.XJMaoZ as varchar(20))) XJMaoZ');
    sql.Add(',Rtrim(Cast(AA.XJFree as varchar(20))) XJFree,Rtrim(Cast( Cast(AA.XJlen*AA.XJFK/100 as int) as varchar(20))) XJPFM');
    sql.Add(',Rtrim(Cast(Cast(C.SWFBKZ as int) as varchar(20))) SWFBKZ');
    sql.Add(',Rtrim(Cast(Cast(AA.XJJt as int) as varchar(20))) XJJt');
    sql.Add(',RTrim(B.LbEngName) LbEngName');
    sql.Add(',RTrim(C.SWFBCodeName) SWFBCodeName from WFB_XJJY AA ');
    sql.add(' inner join WFB_MJJY A on AA.MJID=A.MJID') ;
    sql.add(' inner join WFBOrder_Main B on A.MainId=B.MainId');
    sql.Add(' inner join WFBOrder_Sub C on A.SubId=C.SubId');
    sql.Add(' where AA.XJID='''+Trim(FXJID)+'''');
    Open;
  end;
  fPrintFile:=ExtractFilePath(Application.ExeName)+'Report\'+Trim(LabName)+'.rmf' ;
  if FileExists(fPrintFile) then
  begin
    RM2.LoadFromFile(fPrintFile);
    //RM2.ShowReport;
    Rm2.PrintReport;
  end else
  begin
    Application.MessageBox(PChar('没有找'+ExtractFilePath(Application.ExeName)+'Report\'+Trim(LabName)+'.rmf'),'提示',0);
  end;
  DataLink_WFBProducttion.ADOLink.Connected:=False;
end;

procedure TfrmZJManageNew.Button6Click(Sender: TObject);
var
  i,j,FXJInt:Integer;
begin
  if Cds_Main.IsEmpty then Exit;
  j:=0;
  with Panel4 do
  begin
    for i:=0 to Cds_Main.fieldbyname('SmalCount').AsInteger-1 do
    begin
      if Controls[i].Visible=True then
      begin
        if TEdit(Controls[i]).Text='√' then
        begin
          if j=0 then
          begin
            j:=9;
            FXJInt:=i+1;
          end
          else
            j:=j+1;
        end;
      end;
    end;
  end;
  if j=0 then
  begin
    Application.MessageBox('没有选择小卷！','提示',0);
    Exit;
  end else
  if j>9 then
  begin
    Application.MessageBox('不能选择多个小卷！','提示',0);
    Exit;
  end;

  with ADOQueryTemp do
  begin
    Close;
    SQL.Clear;
    sql.Add('select * from WFB_XJJY where MJID='''+Trim(Cds_Main.fieldbyname('MJId').AsString)+'''');
    SQL.Add(' and XJInt='+Inttostr(FXJInt));
    Open;
  end;
  if ADOQueryTemp.IsEmpty=True then
  begin
    Application.MessageBox('未打过条码，不能重新打印！','提示',0);
    Exit;
  end;
  MovePanel3.Visible:=True;
 // PrintData(Trim(ADOQueryTemp.fieldbyname('XJID').AsString),'重打');
  //MJID.SelectAll;
end;

procedure TfrmZJManageNew.Tv3CellClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
var
  FXJXH:String;
begin
  FXJXH:=Trim(CDS_XJID.fieldbyname('XJInt').AsString);
  (FindComponent('XJLen'+FXJXH) as TEdit).Text:=Trim(CDS_XJID.fieldbyname('XJLen').AsString);
  (FindComponent('XJMaoZ'+FXJXH) as TEdit).Text:=Trim(CDS_XJID.fieldbyname('XJMaoZ').AsString);
  (FindComponent('XJFree'+FXJXH) as TEdit).Text:=Trim(CDS_XJID.fieldbyname('XJFree').AsString);
  (FindComponent('XJJt'+FXJXH) as TEdit).Text:=Trim(CDS_XJID.fieldbyname('XJJt').AsString);
end;

procedure TfrmZJManageNew.Button1Click(Sender: TObject);
begin
  MovePanel2.Visible:=True;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    SQL.Add('select A.*,B.OrderNo,C.SWFBCode,C.SWFBCodeName,C.SWFBColor,C.WKMS,C.SWFBHW,C.SubId,C.MainId,C.SWFBKZ  ');
    sql.Add(',YLPB=dbo.F_Get_WFBOrder_SubStr(C.SubId,''YLPB'')');
    sql.add('from WFB_MJJY A ');
    Sql.add(' inner join WFBOrder_Main B on A.MainId=B.MainId');
    Sql.add(' inner join WFBOrder_Sub C on A.SubId=C.SubId');
    sql.add('where 1<>1');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,CDS_HJ);
  SInitCDSData20(ADOQueryTemp,CDS_HJ);
end;

procedure TfrmZJManageNew.Button8Click(Sender: TObject);
begin
  MovePanel2.Visible:=False;
end;

procedure TfrmZJManageNew.Button7Click(Sender: TObject);
var
  maxno,fPrintFile,maxnosub:String;
  i:Double;
begin
  if Application.MessageBox('确定要合卷吗？合卷后数据将不能修改！','提示',32+4)<>IDYES then Exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
    if GetLSNo(ADOQueryCmd,maxno,'','WFB_MJJY',2,1)=False then
    begin
      ADOQueryCmd.Connection.RollbackTrans;
      Application.MessageBox('取大卷最大号失败！','提示',0);
      Exit;
    end;
    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('select * from WFB_MJJY where 1<>1');
      Open;
    end;
    with ADOQueryCmd do
    begin
      Append;
      FieldByName('MainId').Value:=Trim(CDS_HJ.fieldbyname('MainId').AsString);
      FieldByName('SubId').Value:=Trim(CDS_HJ.fieldbyname('SubId').AsString);
      FieldByName('MJId').Value:=Trim(maxno);
      FieldByName('MJMaoZ').Value:=TvHJ.DataController.Summary.FooterSummaryValues[1];
      FieldByName('MJLen').Value:=TvHJ.DataController.Summary.FooterSummaryValues[2];
      FieldByName('MJFK').Value:=TvHJ.DataController.Summary.FooterSummaryValues[5];
      FieldByName('MJSJKZ').Value:=TvHJ.DataController.Summary.FooterSummaryValues[4];
      FieldByName('MJType').Value:='合卷';
      FieldByName('FillTime').Value:=SGetServerDateTime(ADOQueryTemp);
      FieldByName('Filler').Value:=Trim(DName);
      Post;
    end;
    i:=0;
    with CDS_HJ do
    begin
      First;
      while not Eof do
      begin
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('Update WFB_MJJY Set HJMJID='''+Trim(maxno)+'''');
          SQL.Add(',MJType=''合卷'',Valie=''N'' ');
          SQL.Add(' where MJID='''+Trim(CDS_HJ.fieldbyname('MJID').AsString)+'''');
          ExecSQL;
        end;
        with ADOQueryTemp do
        begin
          Close;
          sql.Clear;
          sql.Add('select * from WFB_MJJY_CD where MJID='''+Trim(CDS_HJ.fieldbyname('MJID').AsString)+'''');
          Open;
        end;
        with ADOQueryTemp do
        begin
          First;
          while not Eof do
          begin
            if GetLSNo(ADOQueryCmd,maxnosub,'','WFB_MJJY_CD',4,1)=False then
            begin
              ADOQueryCmd.Connection.RollbackTrans;
              Application.MessageBox('取小卷最大号失败！','提示',0);
              Exit;
            end;
            with ADOQueryCmd do
            begin
              Close;
              sql.Clear;
              sql.Add('select * from WFB_MJJY_CD where 1<>1');
              open;
            end;
            with ADOQueryCmd do
            begin
              Append;
              FieldByName('MJID').Value:=Trim(maxno);
              FieldByName('MCID').Value:=Trim(maxnosub);
              FieldByName('CDBeg').Value:=ADOQueryTemp.fieldbyname('CDBeg').Value+i;
              FieldByName('CDEnd').Value:=ADOQueryTemp.fieldbyname('CDEnd').Value+i;
              FieldByName('CDQty').Value:=ADOQueryTemp.fieldbyname('CDQty').Value;
              FieldByName('CDName').Value:=ADOQueryTemp.fieldbyname('CDName').Value;
              Post;
            end;
            Next;
          end;
        end;
        i:=i+CDS_HJ.FieldByName('MJLen').Value;
        Next;
      end;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    with ADOQueryPrint do
    begin
      Close;
      sql.Clear;
      sql.Add(' select RTrim(A.MJID) MJID,RTrim(Cast(A.MJSJKZ As varchar(20))) MJSJKZ,RTrim(Cast(A.MJFK as varchar(20))) MJFK,RTrim(B.OrderNo) OrderNo,');
      sql.Add(' RTrim(Cast(A.MJMaoZ As varchar(20))) MJMaoZ,RTrim(Cast(A.MJLen As varchar(20))) MJLen,');
      sql.Add(' Rtrim(C.SWFBColor) SWFBColor,Rtrim(Cast(C.SWFBKZ as varchar(20))) SWFBKZ, YLPB=dbo.F_Get_WFBOrder_SubStr(C.SubId,''YLPBSZ'')');
      sql.Add(',RTrim(C.SWFBCodeName) SWFBCodeName from WFB_MJJY A inner join WFBOrder_Main B on A.MainId=B.MainId');
      sql.Add(' inner join WFBOrder_Sub C on A.SubId=C.SubId');
      sql.Add(' where A.MJID='''+Trim(maxno)+'''');
      Open;
    end;
    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;
    Application.MessageBox('合卷成功！','提示',0);
    MovePanel2.Visible:=False;
    Exit;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('合卷异常！','提示',0);
  end;

end;

procedure TfrmZJManageNew.HJMJIDKeyPress(Sender: TObject; var Key: Char);
begin
  if Key=#13 then
  begin
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      SQL.Add('select A.*  ');
      sql.add('from WFB_MJJY A ');
      sql.add('where A.MJID='''+Trim(HJMJID.Text)+'''');
      sql.Add(' and valie=''Y'' ');
      Open;
    end;
    if ADOQueryTemp.IsEmpty then
    begin
      HJMJID.Text:='';
      Application.MessageBox('条码错误！','提示',0);
      Exit;
    end;
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      SQL.Add('select A.*  ');
      sql.add('from WFB_XJJY A ');
      sql.add('where A.MJID='''+Trim(HJMJID.Text)+'''');
      sql.Add(' and valie=''Y'' ');
      Open;
    end;
    if ADOQueryTemp.IsEmpty=False then
    begin
      HJMJID.Text:='';
      Application.MessageBox('此大卷已分切！','提示',0);
      Exit;
    end;
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      SQL.Add('select A.*,B.OrderNo,C.SWFBCode,C.SWFBCodeName,C.SWFBColor,C.WKMS,C.SWFBHW,C.SubId,C.MainId  ');
      sql.Add(',YLPB=dbo.F_Get_WFBOrder_SubStr(C.SubId,''YLPB''),C.SWFBKZ');
      sql.add('from WFB_MJJY A ');
      Sql.add(' inner join WFBOrder_Main B on A.MainId=B.MainId');
      Sql.add(' inner join WFBOrder_Sub C on A.SubId=C.SubId');
      sql.add('where A.MJID='''+Trim(HJMJID.Text)+'''');
      sql.Add(' and A.valie=''Y'' ');
      Open;
    end;
    if ADOQueryTemp.IsEmpty=False  then
    begin
      if CDS_HJ.Locate('MJID',Trim(ADOQueryTemp.fieldbyname('MJID').AsString),[])=True then
      begin
        HJMJID.Text:='';
        Application.MessageBox('已经扫描过，不能再次扫描！','提示',0);
        Exit;
      end;
      if CDS_HJ.IsEmpty=False then
      begin
        if CDS_HJ.Locate('SubId',Trim(ADOQueryTemp.fieldbyname('SubId').AsString),[])=False then
        begin
          HJMJID.Text:='';
          Application.MessageBox('订单不同不能合卷！','提示',0);
          Exit;
        end;
        {if CDS_HJ.Locate('YLPB',Trim(ADOQueryTemp.fieldbyname('YLPB').AsString),[])=False then
        begin
          Application.MessageBox('原料配比不同不能合卷！','提示',0);
          Exit;
        end;
        if CDS_HJ.Locate('SWFBCode',Trim(ADOQueryTemp.fieldbyname('SWFBCode').AsString),[])=False then
        begin
          Application.MessageBox('产品代号不同不能合卷！','提示',0);
          Exit;
        end;
        if CDS_HJ.Locate('SWFBColor',Trim(ADOQueryTemp.fieldbyname('SWFBColor').AsString),[])=False then
        begin
          Application.MessageBox('颜色不同不能合卷！','提示',0);
          Exit;
        end;
        if CDS_HJ.Locate('SWFBHW',Trim(ADOQueryTemp.fieldbyname('SWFBHW').AsString),[])=False then
        begin
          Application.MessageBox('花型不同不能合卷！','提示',0);
          Exit;
        end;
        if CDS_HJ.Locate('WKMS',Trim(ADOQueryTemp.fieldbyname('WKMS').AsString),[])=False then
        begin
          Application.MessageBox('网孔目数不同不能合卷！','提示',0);
          Exit;
        end;
        if CDS_HJ.Locate('XJFK',Trim(ADOQueryTemp.fieldbyname('XJFK').AsString),[])=False then
        begin
          Application.MessageBox('幅宽不同不能合卷！','提示',0);
          Exit;
        end;
        if CDS_HJ.Locate('SWFBKZ',Trim(ADOQueryTemp.fieldbyname('SWFBKZ').AsString),[])=False then
        begin
          Application.MessageBox('克重不同不能合卷！','提示',0);
          Exit;
        end; }
      end;
      with CDS_HJ do
      begin
        Append;
        FieldByName('OrderNo').Value:=ADOQueryTemp.fieldbyname('OrderNo').Value;
        FieldByName('SubId').Value:=ADOQueryTemp.fieldbyname('SubId').Value;
        FieldByName('MainId').Value:=ADOQueryTemp.fieldbyname('MainId').Value;
        FieldByName('YLPB').Value:=ADOQueryTemp.fieldbyname('YLPB').Value;
        FieldByName('SWFBCode').Value:=ADOQueryTemp.fieldbyname('SWFBCode').Value;
        FieldByName('SWFBCodeName').Value:=ADOQueryTemp.fieldbyname('SWFBCodeName').Value;
        FieldByName('SWFBColor').Value:=ADOQueryTemp.fieldbyname('SWFBColor').Value;
        FieldByName('WKMS').Value:=ADOQueryTemp.fieldbyname('WKMS').Value;
        FieldByName('SWFBHW').Value:=ADOQueryTemp.fieldbyname('SWFBHW').Value;
        FieldByName('MJID').Value:=ADOQueryTemp.fieldbyname('MJID').Value;
        FieldByName('SWFBKZ').Value:=ADOQueryTemp.fieldbyname('SWFBKZ').Value;
        FieldByName('MJMaoZ').Value:=ADOQueryTemp.fieldbyname('MJMaoZ').Value;
        FieldByName('MJLen').Value:=ADOQueryTemp.fieldbyname('MJLen').Value;
        FieldByName('MJFK').Value:=ADOQueryTemp.fieldbyname('MJFK').Value;
        FieldByName('MJSJKZ').Value:=ADOQueryTemp.fieldbyname('MJSJKZ').Value;
        Post;
      end;
    end else
    begin
      HJMJID.Text:='';
      Application.MessageBox('条码错误！','提示',0);
      Exit;
    end;
    HJMJID.Text:='';
  end;

end;

procedure TfrmZJManageNew.TvHJCellDblClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  if Application.MessageBox('确定要删除数据吗？','提示',32+4)<>IDYES then Exit;
  CDS_HJ.Delete;
end;

procedure TfrmZJManageNew.Button9Click(Sender: TObject);
var
  i,j,FXJInt:Integer;
  mm,mm2:String;
begin
  with ADOQueryTemp do
  begin
    sql.Clear;
    sql.add('SELECT userid,username,password FROM SY_User WHERE userid='+''''+trim(DCode)+'''');
    Open;
    mm:=Trim(Fields[2].AsString);
    if Trim(mm)<>'' then
      mm2:=Trim(DecryptString(Trim(mm),'ljb^0122!@#*&^%$',kb128))
    else
    begin
      Application.MessageBox('密码不能为空！','提示',0);
      Exit;
    end;
    close;
  end;

  if ( mm2=trim(Password.text) ) then
  begin
    with Panel4 do
    begin
      for i:=0 to Cds_Main.fieldbyname('SmalCount').AsInteger-1 do
      begin
        if Controls[i].Visible=True then
        begin
          if TEdit(Controls[i]).Text='√' then
          begin
            if j=0 then
            begin
              j:=9;
              FXJInt:=i+1;
            end
            else
              j:=j+1;
          end;
        end;
      end;
    end;
    with ADOQueryTemp do
    begin
      Close;
      SQL.Clear;
      sql.Add('select * from WFB_XJJY where MJID='''+Trim(Cds_Main.fieldbyname('MJId').AsString)+'''');
      SQL.Add(' and XJInt='+Inttostr(FXJInt));
      Open;
    end;
    if ADOQueryTemp.IsEmpty=True then
    begin
      Application.MessageBox('未打过条码，不能重新打印！','提示',0);
      Exit;
    end;
      PrintData(Trim(ADOQueryTemp.fieldbyname('XJID').AsString),'重打');
      MovePanel3.Visible:=False;
  end else
    Application.MessageBox('密码错误！', '信息提示', MB_OK or MB_ICONinformation);

  //MJID.SelectAll;
end;

procedure TfrmZJManageNew.Button10Click(Sender: TObject);
begin
  MovePanel3.Visible:=False;
end;

procedure TfrmZJManageNew.PasswordClick(Sender: TObject);
begin
  Panel5.Visible:=True;
end;

end.
