unit U_JYOrderCDOne_HZCX;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, ComCtrls, ToolWin, cxStyles, cxCustomData,
  cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, ADODB,
  cxGridCustomPopupMenu, cxGridPopupMenu, cxGridLevel, cxClasses,
  cxControls, cxGridCustomView, cxGridCustomTableView, cxGridTableView,
  cxGridDBTableView, cxGrid, DBClient, cxCheckBox, cxCalendar, cxSplitter,
  RM_Dataset, RM_System, RM_Common, RM_Class, RM_GridReport, RM_e_Xls,
  Menus, MovePanel, cxTextEdit, cxContainer, cxCurrencyEdit,U_SMLB, BtnEdit,
  RM_e_main, RM_e_htm, RM_e_Graphic, RM_e_Jpeg, RM_e_txt, RM_e_csv,
  RM_E_llPDF, cxPC;

type
  TfrmJYOrderCDOne_HZCX = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    Tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    TBExport: TToolButton;
    Order_Main: TClientDataSet;
    conNO: TEdit;
    Label7: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    MJID: TEdit;
    Panel4: TPanel;
    Label11: TLabel;
    Panel10: TPanel;
    Image2: TImage;
    RichEdit1: TRichEdit;
    v1Column2: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    Label4: TLabel;
    MJType: TComboBox;
    v1PRTCodeName: TcxGridDBColumn;
    Label5: TLabel;
    PRTCodeName: TEdit;
    Label6: TLabel;
    MJStr2: TComboBox;
    v1Column18: TcxGridDBColumn;
    v1Column19: TcxGridDBColumn;
    Label12: TLabel;
    Label13: TLabel;
    factoryName: TEdit;
    fromfactoryName: TEdit;
    v1Column22: TcxGridDBColumn;
    v1MJQty: TcxGridDBColumn;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    RM2: TRMGridReport;
    RMDBMain: TRMDBDataSet;
    ADOQueryPrint: TADOQuery;
    RadioGroup1: TRadioGroup;
    v1Column28: TcxGridDBColumn;
    ToolButton2: TToolButton;
    CDS_CD: TClientDataSet;
    RMCD: TRMGridReport;
    RMDBCD: TRMDBDataSet;
    CDS_LS: TClientDataSet;
    CheckBox1: TCheckBox;
    Panel2: TPanel;
    Label15: TLabel;
    cxCurrencyEdit1: TcxCurrencyEdit;
    Button1: TButton;
    Button2: TButton;
    CheckBox2: TCheckBox;
    Mjstr4: TEdit;
    PrtColor: TEdit;
    Label18: TLabel;
    ComboBox1: TComboBox;
    RM3: TRMGridReport;
    v1Column31: TcxGridDBColumn;
    v1Column32: TcxGridDBColumn;
    v1Column33: TcxGridDBColumn;
    Panel3: TPanel;
    Check_bq: TCheckBox;
    ComboBox2: TComboBox;
    ComboBox3: TComboBox;
    Fbq: TBtnEditA;
    check_Fbz: TCheckBox;
    Button3: TButton;
    Button4: TButton;
    KHConNO: TEdit;
    Label19: TLabel;
    v1Column35: TcxGridDBColumn;
    StyleNo: TEdit;
    Label21: TLabel;
    Label22: TLabel;
    ISHZ: TComboBox;
    RMXLSExport1: TRMXLSExport;
    ISbao: TComboBox;
    Label23: TLabel;
    CDS_HZ: TClientDataSet;
    RMDBHZ: TRMDBDataSet;
    cxCurrencyEdit2: TcxCurrencyEdit;
    Label24: TLabel;
    Label25: TLabel;
    ComboBox4: TComboBox;
    RMDBPRT: TRMDBDataSet;
    CDS_PRT: TClientDataSet;
    v1PRTColorNo: TcxGridDBColumn;
    v1Column38: TcxGridDBColumn;
    PRTColorNo: TEdit;
    Label26: TLabel;
    prthx: TEdit;
    Label27: TLabel;
    Panel5: TPanel;
    Label28: TLabel;
    ComboBox5: TComboBox;
    Button5: TButton;
    Button6: TButton;
    v1conDefstr2: TcxGridDBColumn;
    v1ConPerson2: TcxGridDBColumn;
    v1MJStr2: TcxGridDBColumn;
    Label8: TLabel;
    Filler: TComboBox;
    v1MKXS: TcxGridDBColumn;
    ComboBox6: TComboBox;
    CDS_COL: TClientDataSet;
    RMDBDataSet1: TRMDBDataSet;
    cxTabControl1: TcxTabControl;
    v1filler: TcxGridDBColumn;
    v1SumQty: TcxGridDBColumn;
    v1CDLen: TcxGridDBColumn;
    CheckBox3: TCheckBox;
    ADOQuery1: TADOQuery;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure OrderNoChange(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Panel10MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Image2Click(Sender: TObject);
    procedure Tv1MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure RadioGroup1Click(Sender: TObject);
    procedure Aorddefstr1Change(Sender: TObject);
    procedure PRTColorChange(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure v1Column15PropertiesEditValueChanged(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure ToolButton6Click(Sender: TObject);
    procedure ToolButton7Click(Sender: TObject);
    procedure ToolButton9Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure FbqBtnClick(Sender: TObject);
    procedure MJIDKeyPress(Sender: TObject; var Key: Char);
    procedure ISbaoChange(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure ToolButton12Click(Sender: TObject);
    procedure conNOKeyPress(Sender: TObject; var Key: Char);
    procedure ADateChange(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure CheckBox3Click(Sender: TObject);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
  private
    DQdate:TDateTime;
    FLeft,FTop:Integer;
    procedure InitGrid();
    procedure InitGrid10();
    procedure InitForm();
    function  Savedata():Boolean;
    procedure GetCDSData();
    procedure GetBGData();
    { Private declarations }
  public
    FFInt:Integer;
    { Public declarations }
  end;

var
  frmJYOrderCDOne_HZCX: TfrmJYOrderCDOne_HZCX;

implementation
uses
  U_DataLink,U_OrderInPut,U_Fun,U_MJEdit, U_CPDBAO, U_CPGangNo,
  U_JYOrderCDOne, U_ZDYHelp, U_ProductOrderListSel;

{$R *.dfm}

procedure TfrmJYOrderCDOne_HZCX.FormDestroy(Sender: TObject);
begin
  frmJYOrderCDOne_HZCX:=nil;
end;

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

procedure TfrmJYOrderCDOne_HZCX.FormCreate(Sender: TObject);
begin
  cxgrid1.Align:=alClient;
  DQdate:=SGetServerDate(ADOQueryTemp);
end;

procedure TfrmJYOrderCDOne_HZCX.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('检验报告JF',Tv1,'检验管理');
end;

procedure TfrmJYOrderCDOne_HZCX.InitGrid();
var
  i:integer;
  j:Integer;
begin
  checkBox3.Enabled:=false;
  if cxtabControl1.TabIndex=0 then
  begin
    checkBox3.Enabled:=true;
  end;
  if cxtabControl1.TabIndex<>0 then
  begin
    checkBox3.Checked:=true;
  end;
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.add('select DD.PrtCodeName,DD.SOrdDefStr4,DD.PRTColor,DD.PRTColorNo,DD.PRTHX,B.factoryName,A.APID,B.fromFactoryName,EE.ConPerson2,EE.conDefstr2,EE.conDefstr3,EE.ConNo,EE.KHConNO,DD.StyleNo ');
      sql.add(',A.Mjstr4,A.Filler,A.MJType,Sum(A.MJQty3) MJQty3,Sum(A.MJQty4) MJQty4,sum(MJMaoZ) MJMaoZ,Sum(MJLen) MJLen,Sum(A.MJQty2) MJQty2');
      sql.add(',MJQty=(select Count(C.MJXH) from WFB_MJJY C where C.APID=A.APID and C.MJType=A.MJType and C.Filler=A.Filler and C.MJStr2=A.MJStr2)');
      sql.add(',A.MJTypeOther,A.MKXS,A.MJStr2 ');
      sql.Add(',CDQty=(select SUM(CDqty) from WFB_MJJY_CD X inner join WFB_MJJY C on X.MJID=C.MJID where C.APID=A.APID and C.MJType=A.MJType and C.Filler=A.Filler and C.MJStr2=A.MJStr2) ');
      sql.add(',SumQty=(select SUM(CDBeg) from WFB_MJJY_CD X inner join WFB_MJJY C on X.MJID=C.MJID where C.APID=A.APID and C.MJType=A.MJType and C.Filler=A.Filler and C.MJStr2=A.MJStr2) ');
      sql.add('from WFB_MJJY A ');
      sql.add('inner join CK_SXPB_CR B on B.SPID=A.APID ');
      sql.add('inner join JYOrderCon_Sub DD on DD.Subid=A.ConID ');
      sql.add('inner join JYOrderCon_Main EE on EE.Mainid=DD.Mainid where 1=1 ');
      if checkBox3.Checked=true then
      begin
        sql.add(' and A.filltime>='''+trim(formatdatetime('yyyy-MM-dd',begdate.DateTime))+''' ');
        sql.add(' and A.Filltime<'''+trim(formatdatetime('yyyy-MM-dd',Enddate.DateTime+1))+''' ');
      end;
      if cxtabControl1.TabIndex=0 then
      begin
        sql.add(' and A.MJStr2=''未入库'' ');
      end;
      if cxtabControl1.TabIndex=1 then
      begin
        sql.add(' and A.MJStr2=''已出库'' ');
      end;
      sql.add('group by DD.PrtCodeName,DD.SOrdDefStr4,DD.PRTColor,DD.PRTColorNo,DD.PRTHX,B.factoryName,A.APID,B.fromFactoryName,EE.ConPerson2,EE.conDefstr2,EE.conDefstr3,EE.ConNo,EE.KHConNO,DD.StyleNo ');
      sql.add(',A.Mjstr4,A.Filler,A.MJType,A.MJTypeOther,A.MKXS,A.MJStr2 ');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,Order_Main);
    SInitCDSData20(ADOQueryMain,Order_Main);
  finally
    ADOQueryMain.EnableControls;
    //TBFind.Click;
  end;
end;

procedure TfrmJYOrderCDOne_HZCX.InitGrid10();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add('exec P_JYOrder_HZFX :begdate,:enddate,:PState ');
      Parameters.ParamByName('begdate').Value:='2012-01-01';
      Parameters.ParamByName('enddate').Value:='2011-01-01';
      Parameters.ParamByName('PState').Value:=3;
      Open;
    end;
    SCreateCDS20(ADOQueryMain,Order_Main);
    SInitCDSData20(ADOQueryMain,Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmJYOrderCDOne_HZCX.InitForm();
var
  fsj:String;
begin
  ReadCxGrid('检验报告JF',Tv1,'检验管理');
  fsj:='select distinct(Filler) name from WFB_MJJY   ';
  SInitComBoxBySql(ADOQueryCmd,Filler,False,fsj);
  BegDate.DateTime:=SGetServerDate10(ADOQueryTemp)-1;
  EndDate.DateTime:=SGetServerDate10(ADOQueryTemp)-1;
  //InitGrid();
end;

procedure TfrmJYOrderCDOne_HZCX.TBFindClick(Sender: TObject);
var
  fsj,fwhere:String;
begin
  if ADOQueryMain.Active=False then Exit;
  fwhere:=SGetFilters(Panel1,1,2);
  fsj:='';
  if trim(ISbao.Text)='已打包' then
  begin
    fsj:=fsj+' baoNo>''0'' ';
  end else
  if trim(ISbao.Text)='未打包' then
  begin
    fsj:=fsj+' baoNo='''' ';
  end;

  IF trim(fsj)<>'' then
  begin
    IF fwhere='' then fwhere:=fsj
    else fwhere:=fwhere+' and '+fsj;
  end;
  SDofilter(ADOQueryMain,fwhere);
  SCreateCDS20(ADOQueryMain,Order_Main);
  SInitCDSData20(ADOQueryMain,Order_Main);
end;


procedure TfrmJYOrderCDOne_HZCX.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then Exit;
  SelExportData(Tv1,ADOQueryMain,'检验报告');
end;

procedure TfrmJYOrderCDOne_HZCX.TBRafreshClick(Sender: TObject);
begin
  ConnO.SetFocus;
  {MovePanel2.Left:=(self.Width-MovePanel2.Width) div 2;
  MovePanel2.Visible:=True;
  MovePanel2.Refresh;}
  InitGrid();
  //MovePanel2.Visible:=False;
end;

procedure TfrmJYOrderCDOne_HZCX.OrderNoChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmJYOrderCDOne_HZCX.FormShow(Sender: TObject);
begin
  InitForm();
  if Trim(DParameters2)='管理' then
  begin
    //TBManage.Visible:=True;
    //TBZF.Visible:=True;
    //ToolButton3.Visible:=true;
    //TBBN.Visible:=true;
    //ToolButton12.Visible:=true;
    //ToolButton1.Visible:=true;
    //ToolButton9.Visible:=true;
    //ToolButton4.Visible:=true;
    //ToolButton6.Visible:=true;
    //ToolButton5.Visible:=true;
    //ToolButton7.Visible:=true;
    //ToolButton11.Visible:=true;
    //TBAftChkHX.Visible:=True;
  end;
  if Trim(DParameters2)='次品' then
  begin
    MJType.ItemIndex:=MJType.Items.IndexOf('次品');
    MJType.Enabled:=false;
  end;
end;

procedure TfrmJYOrderCDOne_HZCX.Panel10MouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
  ReleaseCapture;
  TWinControl(Panel4).Perform(WM_SYSCOMMAND,$F012,0);
end;

procedure TfrmJYOrderCDOne_HZCX.Image2Click(Sender: TObject);
begin
  Panel4.Visible:=False;
end;

procedure TfrmJYOrderCDOne_HZCX.Tv1MouseUp(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  FLeft:=X;
  FTop:=Y;
end;

procedure TfrmJYOrderCDOne_HZCX.N1Click(Sender: TObject);
begin
  SelOKNo(Order_Main,True);
end;

procedure TfrmJYOrderCDOne_HZCX.N2Click(Sender: TObject);
begin
  SelOKNo(Order_Main,False);
end;

procedure TfrmJYOrderCDOne_HZCX.ToolButton1Click(Sender: TObject);
var
  fPrintFile:string;
   Txt,fImagePath:string;
   Moudle: THandle;
   Makebar:TMakebar;
   Mixtext:TMixtext;
begin
  if Order_Main.IsEmpty then Exit;
  if Order_Main.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  Order_Main.DisableControls;
  with Order_Main do
  begin
    First;
    while not Eof do
    begin
      if Order_Main.FieldByName('SSel').AsBoolean=True then
      begin
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('Update WFB_MJJY Set PrtAgnFlag=1,PrtAgnDate=getdate(),PrtAgnPerson='''+Trim(DName)+'''');
          sql.Add(' where MJID='''+Trim(Order_Main.fieldbyname('MJID').AsString)+'''');
          ExecSQL;
        end;
        with ADOQueryPrint do
        begin
          Close;
          SQL.Clear;
          sql.Add('select QtyUnit=A.MJTypeOther,B.orderNo,GangNo=D.RCgangNO,PRTColorEng=E.Note,EE.ConLBName,EE.ConNLBName ');
          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,B.MPRTSpec,B.MPRTCode,B.MaiTouNote,EE.ConPerson2,EE.conDefstr2,EE.conDefstr3,EE.ConNo,EE.KHConNO,DD.StyleNo,B.LengUnit,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(' ,substring(EE.ConNo,LEN(EE.ConNO)-3,LEN(EE.ConNO)) HS,DD.XHNo,D.PiQty');
          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 CK_SXPB_CR D on D.SPId=A.APId ');
          sql.add(' left join JYOrderCon_Sub DD on DD.Subid=D.ConCKID ');
          sql.add(' left join JYOrderCon_Main EE on EE.Mainid=DD.Mainid ');
          SQL.Add(' where A.MJID='''+Trim(Order_Main.fieldbyname('MJID').AsString)+'''');
          Open;
        end;
        try
          Moudle:=LoadLibrary('MakeQRBarcode.dll');
          @Makebar:=GetProcAddress(Moudle,'Make');
          @Mixtext:=GetProcAddress(Moudle,'MixText');
          Txt:=Trim(ADOQueryPrint.fieldbyname('MJID').AsString);
          fImagePath:=ExtractFilePath(Application.ExeName)+'image\temp.bmp' ;
          if not DirectoryExists(pchar(ExtractFilePath(Application.ExeName)+'image')) then
          CreateDirectory(pchar(ExtractFilePath(Application.ExeName)+'image'),nil);
          if FileExists(fImagePath) then DeleteFile(fImagePath);
          Makebar(pchar(Txt),Length(Txt),3,3,0,PChar(fImagePath),3);
        except
          application.MessageBox('条形码生成失败！','提示信息',MB_ICONERROR);
         exit;
        end;
        if Trim(ADOQueryPrint.fieldbyname('ConLBName').AsString)<>'' then
          fPrintFile:=ExtractFilePath(Application.ExeName)+'Report\'+Trim(ADOQueryPrint.fieldbyname('ConLBName').AsString)+'.rmf'
        else
          fPrintFile:=ExtractFilePath(Application.ExeName)+'Report\通用英文标签.rmf' ;
        //  fPrintFile:=ExtractFilePath(Application.ExeName)+'Report\15029外唛.rmf' ;
        if FileExists(fPrintFile) then
        begin
            RMVariables['QRBARCODE']:=fImagePath;
            RMVariables['ID']:=trim(ADOQueryPrint.fieldbyname('HS').AsString)+Trim(ADOQueryPrint.fieldbyname('XHNo').AsString);
            RM2.LoadFromFile(fPrintFile);
            Rm2.DefaultCopies:=strtointdef(trim(ComboBox1.Text),1);
         //   RM2.ShowReport;
            RM2.PrintReport;
        {  IF Trim(ADOQueryPrint.fieldbyname('NLBName').AsString)<>'' then
          begin
             fPrintFile:=ExtractFilePath(Application.ExeName)+'Report\'+Trim(ADOQueryPrint.fieldbyname('NLBName').AsString)+'.rmf';
             if FileExists(fPrintFile) then
             begin
              RMVariables['QRBARCODE']:=fImagePath;
              RM3.LoadFromFile(fPrintFile);
              RM3.DefaultCopies:=1;
            //  RM3.ShowReport;
              RM3.PrintReport;
             end;
           end;  }
        end
        else
        begin
          Order_Main.EnableControls;
          Application.MessageBox(PChar('没有找'+ExtractFilePath(Application.ExeName)+'Report\卷标签.rmf'),'提示',0);
          Exit;
        end;
      end;
      Next;
    end;
  end;
  Order_Main.EnableControls;
end;

procedure TfrmJYOrderCDOne_HZCX.RadioGroup1Click(Sender: TObject);
begin
  TBFind.Click;
end;

function TfrmJYOrderCDOne_HZCX.Savedata():Boolean;
var
  maxno,LLID:string;
  HXPS:Integer;
  HXQty,HXMQty:Double;
begin
  HXPS:=0;
  HXQty:=0;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select Top 1 * from Contract_Cloth_LL where OrdSubId='''+Trim(Order_Main.fieldbyname('SubId').AsString)+'''');
    sql.Add(' and FirstName='''+Trim(Order_Main.fieldbyname('AOrddefstr4').AsString)+'''');
    Open;
  end;
  LLID:=Trim(ADOQueryTemp.fieldbyname('LLID').AsString);
  if Trim(LLID)='' then
  begin
    Result:=False;
    Application.MessageBox('没有相对应的加工厂!','提示',0);
    Exit;
  end;
  try
    ADOQueryCmd.Connection.BeginTrans;
    if GetLSNo(ADOQueryCmd,maxno,'HX','Contract_Cloth_BefChkHX',2,1)=False then
    begin
      Result:=False;
      ADOQueryCmd.Connection.RollbackTrans;
      Application.MessageBox('取回修最大号失败!','提示',0);
      Exit;
    end;
    with Order_Main do
    begin
      First;
      while not Eof do
      begin
        if Order_Main.FieldByName('SSel').AsBoolean=True then
        begin
          HXPS:=HXPS+1;
          HXQty:=HXQty+Order_Main.FieldByName('MJLen').Value;
        end;
        Next;
      end;
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('');
      Open;
    end;
  except
  end;
end;

procedure TfrmJYOrderCDOne_HZCX.Aorddefstr1Change(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmJYOrderCDOne_HZCX.PRTColorChange(Sender: TObject);
begin
  TBFind.Click;
  if Order_Main.IsEmpty=False then
  begin
    //InitOrderColor(Trim(Order_Main.fieldbyname('MainId').AsString),PRTColor,ADOQueryTemp);
   // InitBCGangNo(Trim(Order_Main.fieldbyname('SubId').AsString),AOrdDefStr1,ADOQueryTemp);
  end;
end;

procedure TfrmJYOrderCDOne_HZCX.GetCDSData();
begin
  CDS_CD.FieldByName('MJXH').Value:=CDS_LS.fieldbyname('MJXH').Value;
  CDS_CD.FieldByName('GangNo').Value:=CDS_LS.fieldbyname('Aorddefstr1').Value;
  CDS_CD.FieldByName('PRTColor').Value:=CDS_LS.fieldbyname('PRTColor').Value;
  CDS_CD.FieldByName('PRTEColor').Value:=CDS_LS.fieldbyname('SOrddefstr4').Value;
  CDS_CD.FieldByName('MJLen').Value:=CDS_LS.fieldbyname('MJLen').Value;
  CDS_CD.FieldByName('MJJZ').Value:=CDS_LS.fieldbyname('MJQty4').Value;
  CDS_CD.FieldByName('MJMZ').Value:=CDS_LS.fieldbyname('MJMaoZ').Value;
  CDS_CD.FieldByName('MJFK').Value:=CDS_LS.fieldbyname('MJFK').Value;
  CDS_CD.FieldByName('KFQtyHZ').Value:=CDS_LS.fieldbyname('KFQtyHZ').Value;
  CDS_CD.FieldByName('DengJi').Value:=CDS_LS.fieldbyname('DengJi').Value;
  CDS_CD.FieldByName('PanDing').Value:=CDS_LS.fieldbyname('PanDing').Value;
  CDS_CD.FieldByName('MJID').Value:=CDS_LS.fieldbyname('MJID').Value;
end;

procedure TfrmJYOrderCDOne_HZCX.ToolButton2Click(Sender: TObject);
var
  fPrintFile,fZMFile:string;
begin
  if Order_Main.IsEmpty then Exit;
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.add('exec P_Print_JYMD1 ');
      sql.add('@mainID='+quotedstr(Trim(Order_Main.FieldByName('ConNO').AsString)));
      //sql.add(',@begtime='''+trim(formatdatetime('yyyy-MM-dd',begdate.DateTime))+''' ');
      //sql.add(',@Endtime='''+trim(formatdatetime('yyyy-MM-dd',Enddate.DateTime+1))+''' ');
      sql.Add(',@begtime=''2000-01-01''');
      sql.Add(',@Endtime=''2100-01-01''');
      sql.add(',@MJStr2='+quotedstr(Trim(Order_Main.FieldByName('MJStr2').AsString)));
      sql.Add(',@FHStatus='''+trim(Order_Main.FieldByName('FHStatus').AsString)+''' ');
      Open;
    end;
    SCreateCDS20(ADOQueryTemp,CDS_HZ);
    SInitCDSData20(ADOQueryTemp,CDS_HZ);
    with ADOQuery1 do
    begin
      Close;
      sql.Clear;
      sql.add('exec P_Print_JYMD1 ');
      sql.add('@mainID='+quotedstr(Trim(Order_Main.FieldByName('ConNO').AsString)));
      //sql.add(',@begtime='''+trim(formatdatetime('yyyy-MM-dd',begdate.DateTime))+''' ');
      //sql.add(',@Endtime='''+trim(formatdatetime('yyyy-MM-dd',Enddate.DateTime+1))+''' ');
      sql.Add(',@begtime=''2000-01-01''');
      sql.Add(',@Endtime=''2100-01-01''');
      sql.add(',@MJStr2='+quotedstr(Trim(Order_Main.FieldByName('MJStr2').AsString)));
      sql.Add(',@FHStatus='''+trim(Order_Main.FieldByName('FHStatus').AsString)+''' ');
      sql.add(',@flag=''2'' ');
      Open;
    end;
    SCreateCDS20(ADOQuery1,CDS_COL);
    SInitCDSData20(ADOQuery1,CDS_COL);
    fPrintFile:= ExtractFilePath(Application.ExeName) + 'Report\'+Trim(ComboBox6.Text)+'.rmf' ;
  if FileExists(fPrintFile) then
  begin
    if RMCD.CanExport=true then
    begin
      fZMFile:='C:\Users\Administrator\Desktop';
      if not DirectoryExists(fZMFile) then
      begin
        fZMFile:='C:\Documents and Settings\Administrator\桌面\'+trim(Order_Main.fieldbyname('ConNO').AsString)+' DETAILED PL.xls';
      end
      else
      begin
        fZMFile:='C:\Users\Administrator\Desktop\'+trim(Order_Main.fieldbyname('ConNO').AsString)+' DETAILED PL.XLS';
      end;
      RMCD.ExportTo(RMXLSExport1,fZMFile);
    end;
    RMCD.CanExport:=true;
    RMCD.LoadFromFile(fPrintFile);
    RMCD.ShowReport;
    RMCD.CanExport:=False;
  end else
  begin
    Application.MessageBox(PChar('没有找'+ExtractFilePath(Application.ExeName)+'Report\检验报告.rmf'),'提示',0);
  end;
end;

procedure TfrmJYOrderCDOne_HZCX.GetBGData();
var
  FMJId:string;
  i,j,z:Integer;
begin

  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select MJXH=Cast(0 as int),GangNo=Cast('''' as varchar(20)),PRTColor=Cast('''' as varchar(20)),MJID=Cast('''' as varchar(20))');
    sql.Add(',PRTEColor=Cast('''' as varchar(20)),MJLen=Cast(0 as decimal(18,2)),MJJZ=Cast(0 as decimal(18,2)),XH=Cast(0 as int)');
    sql.Add(',MJMZ=Cast(0 as decimal(18,2)),MJFK=Cast(0 as decimal(18,2)),KFQtyHZ=Cast(0 as int),DengJi=Cast('''' as varchar(20)),PanDing=Cast('''' as varchar(20))');
    sql.Add(',CDName0=Cast('''' as varchar(20)),CDBeg0=Cast('''' as varchar(20)),KFQty0=Cast(0 as int)');
    sql.Add(',CDName1=Cast('''' as varchar(20)),CDBeg1=Cast('''' as varchar(20)),KFQty1=Cast(0 as int)');
    sql.Add(',CDName2=Cast('''' as varchar(20)),CDBeg2=Cast('''' as varchar(20)),KFQty2=Cast(0 as int)');
    sql.Add(',CDName3=Cast('''' as varchar(20)),CDBeg3=Cast('''' as varchar(20)),KFQty3=Cast(0 as int)');
    sql.Add(',CDName4=Cast('''' as varchar(20)),CDBeg4=Cast('''' as varchar(20)),KFQty4=Cast(0 as int)');
    sql.Add(',CDName5=Cast('''' as varchar(20)),CDBeg5=Cast('''' as varchar(20)),KFQty5=Cast(0 as int)');
    sql.Add(',CDName6=Cast('''' as varchar(20)),CDBeg6=Cast('''' as varchar(20)),KFQty6=Cast(0 as int)');
    sql.Add(',CDName7=Cast('''' as varchar(20)),CDBeg7=Cast('''' as varchar(20)),KFQty7=Cast(0 as int)');
    sql.Add(',CDName8=Cast('''' as varchar(20)),CDBeg8=Cast('''' as varchar(20)),KFQty8=Cast(0 as int)');
    sql.Add(',CDName9=Cast('''' as varchar(20)),CDBeg9=Cast('''' as varchar(20)),KFQty9=Cast(0 as int)');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,CDS_CD);
  SInitCDSData20(ADOQueryTemp,CDS_CD);
  if CDS_CD.IsEmpty=False then CDS_CD.Delete;
  with ADOQueryTemp do
  begin
    Close;
    SQL.Clear;
    sql.Add('select A.*,Case when isnull(MJType,'''')=''正品'' and KFQtyHZ<26 then ''A''    ');
    sql.Add(' when isnull(MJType,'''')=''正品'' and KFQtyHZ>33 then ''C''');
    sql.Add(' when isnull(MJType,'''')=''正品'' and KFQtyHZ>25 and A.KFQtyHZ<34  then ''B''');
    sql.Add(' else MJType end as DengJi');
    sql.Add('from (select A.CDBeg,A.CDName,A.KouFenQty,B.MJXH,C.Aorddefstr1,JS.PRTColor,JS.SOrddefstr4,B.MJID ');
    sql.Add(',CDEName=(select Note from KH_Zdy KZ where KZ.ZdyName=A.CDName and KZ.Type=''WFBCD'' )');
    sql.Add(',B.MJLen,B.MJQty4,B.MJMaoZ,B.MJTypeOther,B.MJSJKZ,B.MJFK,B.MJType,B.PanDing');
    sql.Add(',KFQtyHZ=(select Sum(KouFenQty) from WFB_MJJY_CD MCD where MCD.MJID=B.MJID)');
    sql.Add(' from WFB_MJJY B inner join WFB_MJJY_CD A on B.MJID=A.MJID');
    sql.Add(' inner join JYOrder_Sub_AnPai C on B.APID=C.APID');
    sql.Add(' inner join JYOrder_Sub JS on C.SubId=JS.SubId');
    SQL.Add(' where B.MainId='''+Trim(Order_Main.fieldbyname('MainId').AsString)+'''');
    if Trim(MJType.Text)<>'' then
    begin
      sql.Add(' and isnull(B.MJType,'''')='''+Trim(MJType.Text)+'''');
    end;

    sql.Add(')A order by PRTColor,Cast(Aorddefstr1 as int),MJID,MJXH');
    Open;
  end;
  //ShowMessage(ADOQueryTemp.SQL.Text);
  //ShowMessage(IntToStr(ADOQueryTemp.RecordCount));
  SCreateCDS20(ADOQueryTemp,CDS_LS);
  SInitCDSData20(ADOQueryTemp,CDS_LS);
  CDS_LS.DisableControls;
  with CDS_LS do
  begin
    First;
    while not Eof do
    begin
      if CDS_CD.IsEmpty then
      begin
        with CDS_CD do
        begin
          Append;
          GetCDSData();
          if CheckBox1.Checked=True then
            FieldByName('CDName0').Value:=CDS_LS.fieldbyname('CDEName').Value
          else
            FieldByName('CDName0').Value:=CDS_LS.fieldbyname('CDName').Value;
          FieldByName('CDBeg0').Value:=CDS_LS.fieldbyname('CDBeg').Value;
          FieldByName('KFQty0').Value:=CDS_LS.fieldbyname('KouFenQty').Value;
          FieldByName('XH').Value:=0;
          Post;
          FMJId:=Trim(CDS_LS.fieldbyname('MJID').AsString);
          i:=0;//列号
          j:=0;
          z:=0;//行号
        end;
      end else
      begin
        if Trim(CDS_LS.fieldbyname('MJID').AsString)=FMJId then
        begin
          i:=i+1;
          if i<10 then
          begin
            with CDS_CD do
            begin
              Edit;
              GetCDSData();
              if CheckBox1.Checked=True then
                FieldByName('CDName'+Trim(IntToStr(i))).Value:=CDS_LS.fieldbyname('CDEName').Value
              else
                FieldByName('CDName'+Trim(IntToStr(i))).Value:=CDS_LS.fieldbyname('CDName').Value;
              FieldByName('CDBeg'+Trim(IntToStr(i))).Value:=CDS_LS.fieldbyname('CDBeg').Value;
              FieldByName('KFQty'+Trim(IntToStr(i))).Value:=CDS_LS.fieldbyname('KouFenQty').Value;
              Post;
            end;
          end else
          begin
            i:=0;
            with CDS_CD do
            begin
              Append;
              GetCDSData();
              if CheckBox1.Checked=True then
                FieldByName('CDName'+Trim(IntToStr(i))).Value:=CDS_LS.fieldbyname('CDEName').Value
              else
                FieldByName('CDName'+Trim(IntToStr(i))).Value:=CDS_LS.fieldbyname('CDName').Value;
              FieldByName('CDBeg'+Trim(IntToStr(i))).Value:=CDS_LS.fieldbyname('CDBeg').Value;
              FieldByName('KFQty'+Trim(IntToStr(i))).Value:=CDS_LS.fieldbyname('KouFenQty').Value;
              Post;
            end;
          end;
        end else
        begin
          i:=0;
          with CDS_CD do
          begin
            Append;
            GetCDSData();
            if CheckBox1.Checked=True then
              FieldByName('CDName'+Trim(IntToStr(i))).Value:=CDS_LS.fieldbyname('CDEName').Value
            else
              FieldByName('CDName'+Trim(IntToStr(i))).Value:=CDS_LS.fieldbyname('CDName').Value;
            FieldByName('CDBeg'+Trim(IntToStr(i))).Value:=CDS_LS.fieldbyname('CDBeg').Value;
            FieldByName('KFQty'+Trim(IntToStr(i))).Value:=CDS_LS.fieldbyname('KouFenQty').Value;
            Post;
          end;
          FMJId:=Trim(CDS_LS.fieldbyname('MJID').AsString);
        end;
      end;
      Next;
    end;
  end;
  CDS_LS.EnableControls;
end;

procedure TfrmJYOrderCDOne_HZCX.v1Column15PropertiesEditValueChanged(
  Sender: TObject);
var
  mvalue:string;
begin
  mvalue:=TcxTextEdit(Sender).EditingText;
  with Order_Main do
  begin
    Edit;
    FieldByName('PanDing').Value:=Trim(mvalue);
    Post;
  end;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('UPdate WFB_MJJY Set PanDing='''+Trim(mvalue)+'''');
    SQL.Add(' where MJID='''+Trim(Order_Main.fieldbyname('MJID').AsString)+'''');
    ExecSQL;
  end;
end;

procedure TfrmJYOrderCDOne_HZCX.Button2Click(Sender: TObject);
begin
  Panel2.Visible:=false;
end;

procedure TfrmJYOrderCDOne_HZCX.Button1Click(Sender: TObject);
var
  i,J:string;
begin
  if Order_Main.IsEmpty then Exit;
  if Order_Main.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  if trim(ComboBox4.Text)='' then
  begin
    Application.MessageBox('换算类型不能为空!','提示',0);
    Exit;
  end;
  i:=floattostr(strtofloatdef(trim(cxCurrencyEdit1.Text),0));
  J:= floattostr(strtofloatdef(trim(cxCurrencyEdit2.Text),0));
  try
    Order_Main.DisableControls;
    ADOQueryCmd.Connection.BeginTrans;
    with Order_Main do
    begin
      First;
      while not Eof do
      begin
      if Order_Main.FieldByName('SSel').AsBoolean=True then
      begin
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
     //     sql.Add('Update WFB_MJJY Set MKXs='''+trim(i)+''',MJLen=cast(1.00000* MJQty4 *'''+trim(i)+''' as decimal(18,1))  ');
          IF trim(ComboBox4.Text)='长度换算净重'then
          begin
            sql.Add('Update WFB_MJJY Set MKXs='''+trim(i)+''',MJQty3='''+trim(J)+''',MJQty4=cast(1.00000* MJlen *'''+trim(i)+''' as decimal(18,1))  ');
            sql.Add('where MJID='''+Trim(Order_Main.fieldbyname('MJID').AsString)+'''');
            sql.Add('Update WFB_MJJY Set MJMaoZ=MJQty4+MJQty3  ');
            sql.Add('where MJID='''+Trim(Order_Main.fieldbyname('MJID').AsString)+'''');
          end;
          IF trim(ComboBox4.Text)='净重换算长度'then
          begin
            sql.Add('Update WFB_MJJY Set MKXs='''+trim(i)+''',MJQty3='''+trim(J)+''',MJlen=cast(1.00000* MJQty4 *'''+trim(i)+''' as decimal(18,0))  ');
            sql.Add('where MJID='''+Trim(Order_Main.fieldbyname('MJID').AsString)+'''');
            sql.Add('Update WFB_MJJY Set MJMaoZ=MJQty4+MJQty3  ');
            sql.Add('where MJID='''+Trim(Order_Main.fieldbyname('MJID').AsString)+'''');
          end;
          ExecSQL;
        end;
      end;
      Next;
      end;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Order_Main.EnableControls;
    application.MessageBox('数据保存成功！','提示信息');
    Panel2.Visible:=false;
    TBRafresh.Click;
    exit;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Order_Main.EnableControls;
    application.MessageBox('数据保存失败！','提示信息',0);
  end;
end;

procedure TfrmJYOrderCDOne_HZCX.ToolButton3Click(Sender: TObject);
begin
  Panel2.Left:=(self.Width-Panel2.Width) div 2;
  Panel2.Visible:=true;
end;

procedure TfrmJYOrderCDOne_HZCX.CheckBox2Click(Sender: TObject);
begin
  SelOKNo(Order_Main,CheckBox2.Checked);
end;

procedure TfrmJYOrderCDOne_HZCX.ToolButton4Click(Sender: TObject);
begin
  frmCPDBao:=TfrmCPDBao.Create(self);
  with frmCPDBao do
  begin
    show;

  end;
//  frmCPDBao.Release;
end;

procedure TfrmJYOrderCDOne_HZCX.ToolButton6Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  if Order_Main.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  try
    Order_Main.DisableControls;
    ADOQueryCmd.Connection.BeginTrans;
    with Order_Main do
    begin
      First;
      while not Eof do
      begin
        if Order_Main.FieldByName('SSel').AsBoolean=True then
        begin
          IF trim(fieldbyname('mjstr2').AsString)<>'未入库' then
          begin
            ADOQueryCmd.Connection.RollbackTrans;
            Order_Main.EnableControls;
            application.MessageBox('此条码已入库不能撤销打包!','提示信息',MB_ICONERROR);
            exit;
          end;
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('Update WFB_MJJY Set baoID='''',baoNo=''''  ');
            sql.Add('where MJID='''+Trim(Order_Main.fieldbyname('MJID').AsString)+'''');
            ExecSQL;
          end;
        end;
        Next;
      end;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Order_Main.EnableControls;
    application.MessageBox('数据撤销成功！','提示信息');
    TBRafresh.Click;
    exit;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Order_Main.EnableControls;
    application.MessageBox('数据撤销失败！','提示信息',0);
  end;
end;

procedure TfrmJYOrderCDOne_HZCX.ToolButton7Click(Sender: TObject);
begin
  frmCPGangNo:=TfrmCPGangNo.Create(self);
  with frmCPGangNo do
  begin
    if showmodal=1 then
    begin
     // InitGrid();
    end;
  end;
  frmCPGangNo.Free;
end;

procedure TfrmJYOrderCDOne_HZCX.ToolButton9Click(Sender: TObject);
begin
  frmSMLB:=TfrmSMLB.create(self);
  with frmSMLB do
  begin
    show;
  end;
end;

procedure TfrmJYOrderCDOne_HZCX.Button4Click(Sender: TObject);
begin
  Panel3.Visible:=false;
end;

procedure TfrmJYOrderCDOne_HZCX.Button3Click(Sender: TObject);
var fPrintFile: string;
    Txt,fImagePath:string;
    Moudle: THandle;
    Makebar:TMakebar;
    Mixtext:TMixtext;
    FBaoID:string;
begin
  if Order_Main.IsEmpty then Exit;
  if trim(Order_Main.FieldByName('BaoID').AsString)='' then
  begin
    application.MessageBox('未打包不能打印','提示');
    exit;
  end;

  with ADOQueryPrint do
  begin
    Close;
    SQL.Clear;
    sql.Add('select A.Baoid,A.BaoNo,G.ConNO,G.KHConNO,F.StyleNo,A.MJTypeOther as QtyUnit,D.OrderNo,D.customerNoName,D.MprtCodeName,D.Mprtspec,D.OrdPerson1,D.MPRTKuanNO,D.LBName,D.NLBName,');
    SQL.ADD('C.SOrddefstr4,G.MPrtCode,G.MPRTSpec,G.ConPerson2,G.conDefstr2,G.conDefstr3,D.MaiTouNote,D.LengUnit,');
    sql.Add('MprtCodeNameEng=(select top 1 Note from KH_Zdy X where X.zdyName=D.MprtCodeName), ');
    SQL.ADD('count(A.MJID) as JSl,sum(A.MJMaoZ) MJMAOZ,sum(MJQty3) as MJQty3,sum(MJQty4) as MJQty4,SUM(A.MJLen)as MJLen');
    sql.add(' ,substring(G.ConNo,LEN(G.ConNO)-3,LEN(G.ConNO)) HS,F.XHNo');
    sql.Add('from WFB_MJJY A');
    sql.Add(' inner join JYOrder_Sub C on C.SubID=A.SubID');
    sql.Add(' inner join JYOrder_Main D on D.MainID=A.MainID');
    sql.add(' left join CK_SXPB_CR E on E.SPID=A.APID');
    sql.add(' inner join JYOrderCon_Sub F on F.Subid=E.ConCKID ');
    sql.add(' inner join JYOrderCon_Main G on G.Mainid=F.Mainid ');
    SQL.Add('where A.BaoID='''+Trim(Order_Main.fieldbyname('BaoID').AsString)+'''');
    SQL.ADD('group by A.Baoid,A.BaoNo,G.ConNO,G.KHConNO,F.StyleNo,A.MJTypeOther,D.OrderNo,D.customerNoName,D.MprtCodeName,D.Mprtspec,D.OrdPerson1,D.MPRTKuanNO,D.LBName,D.NLBName,');
    sql.add('C.SOrddefstr4,G.MPrtCode,G.MPRTSpec,G.ConPerson2,G.conDefstr2,G.conDefstr3,D.MaiTouNote,D.LengUnit,F.XHNo');
    Open;
  end;

  if ADOQueryPrint.RecordCount>1 then
  begin
    Application.MessageBox('打包错误，请重新打包!','提示',0);
    Exit;
  end;

  try
    Moudle:=LoadLibrary('MakeQRBarcode.dll');
    @Makebar:=GetProcAddress(Moudle,'Make');
    @Mixtext:=GetProcAddress(Moudle,'MixText');
    Txt:=trim(ADOQueryPrint.fieldbyname('baoID').AsString);
    fImagePath:=ExtractFilePath(Application.ExeName)+'image\temp.bmp';
    if not DirectoryExists(pchar(ExtractFilePath(Application.ExeName)+'image')) then
    CreateDirectory(pchar(ExtractFilePath(Application.ExeName)+'image'),nil);
    if FileExists(fImagePath) then DeleteFile(fImagePath);
    Makebar(pchar(Txt),Length(Txt),3,3,0,PChar(fImagePath),3);
  except
    application.MessageBox('条形码生成失败！','提示信息',MB_ICONERROR);
    exit;
  end;

  IF Check_bq.Checked then
  begin
    if Trim(ADOQueryPrint.fieldbyname('NLBName').AsString)<>'' then
    fPrintFile:= ExtractFilePath(Application.ExeName) + 'Report\'+Trim(ADOQueryPrint.fieldbyname('NLBName').AsString)+'.rmf' 
    else
    fPrintFile:=ExtractFilePath(Application.ExeName)+'Report\包标签.rmf';

    if FileExists(fPrintFile) then
    begin
      RMVariables['QRBARCODE']:=fImagePath;
      RMVariables['ID']:=trim(ADOQueryPrint.fieldbyname('HS').AsString)+Trim(ADOQueryPrint.fieldbyname('XHNo').AsString);
      RM2.DefaultCopies:=strtointdef(trim(ComboBox2.Text),1);
      RM2.LoadFromFile(fPrintFile);
     //   RM2.ShowReport;
      RM2.printReport;
    end
    else
    begin
 //   Order_Main.EnableControls;
      Application.MessageBox(PChar('没有找'+fPrintFile),'提示',0);
      Exit;
    end;
  end;

  IF check_Fbz.Checked then
  begin
    fPrintFile:=ExtractFilePath(Application.ExeName)+'Report\'+Trim(Fbq.Text)+'.rmf' ;

    if FileExists(fPrintFile) then
    begin
      RMVariables['QRBARCODE']:=fImagePath;
      RM2.DefaultCopies:=strtointdef(trim(ComboBox3.Text),1);
      RM2.LoadFromFile(fPrintFile);
   //   RM2.ShowReport;
      RM2.printReport;
    end
    else
    begin
 //   Order_Main.EnableControls;
      Application.MessageBox(PChar('没有找'+fPrintFile),'提示',0);
      Exit;
    end;
  end;

end;

procedure TfrmJYOrderCDOne_HZCX.ToolButton5Click(Sender: TObject);
begin
  Panel3.Left:=(self.Width-Panel3.Width) div 2;
  Panel3.Visible:=true;
end;

procedure TfrmJYOrderCDOne_HZCX.FbqBtnClick(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='BAOFFLAG';
      flagname:='包副标签';
      if ShowModal=1 then
      begin
        Fbq.Text:=trim(ClientDataSet1.fieldbyname('zdyName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmJYOrderCDOne_HZCX.MJIDKeyPress(Sender: TObject; var Key: Char);
begin
  if Key=#13 then
  begin
    if Length(MJID.Text)<4 then Exit;
    {MovePanel2.Visible:=True;
    MovePanel2.Refresh;}
    try
      ADOQueryMain.DisableControls;
      with ADOQueryMain do
      begin
        Filtered:=False;
        Close;
        sql.Clear;
        sql.Add('exec P_JYOrder_HZFX20 :begdate,:enddate,:PState,:FFSql ');
        Parameters.ParamByName('begdate').Value:='2010-01-01';
        Parameters.ParamByName('enddate').Value:='2050-01-01';
        Parameters.ParamByName('PState').Value:=3;
        Parameters.ParamByName('FFSql').Value:=' where A.MJID like '''+'%'+Trim(MJID.Text)+'%'+'''';
        //ShowMessage(sql.Text);
        Open;
      end;
      SCreateCDS20(ADOQueryMain,Order_Main);
      SInitCDSData20(ADOQueryMain,Order_Main);
      if Order_Main.IsEmpty=False then
      begin
        //InitOrderColor(Trim(Order_Main.fieldbyname('MainId').AsString),PRTColor,ADOQueryTemp);
       // InitBCGangNo(Trim(Order_Main.fieldbyname('SubId').AsString),AOrdDefStr1,ADOQueryTemp);
      //  InitRCGangNo(Trim(Order_Main.fieldbyname('SubId').AsString),GangNo,ADOQueryTemp);
      end;
    finally
      ADOQueryMain.EnableControls;
    end;
    //MovePanel2.Visible:=False;
  end;
end;

procedure TfrmJYOrderCDOne_HZCX.ISbaoChange(Sender: TObject);
begin
  Tbfind.Click;
end;

procedure TfrmJYOrderCDOne_HZCX.Button6Click(Sender: TObject);
begin
  Panel5.Visible:=false;
end;

procedure TfrmJYOrderCDOne_HZCX.Button5Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  if Order_Main.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  if trim(ComboBox5.Text)='' then
  begin
    Application.MessageBox('数量单位不能为空!','提示',0);
    Exit;
  end;
  try
    Order_Main.DisableControls;
    ADOQueryCmd.Connection.BeginTrans;
    with Order_Main do
    begin
      First;
      while not Eof do
      begin
      if Order_Main.FieldByName('SSel').AsBoolean=True then
      begin
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('Update WFB_MJJY Set MJTypeOther='''+trim(ComboBox5.Text)+''' ');
          sql.Add('where MJID='''+Trim(Order_Main.fieldbyname('MJID').AsString)+'''');
          ExecSQL;
        end;
      end;
      Next;
      end;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Order_Main.EnableControls;
    application.MessageBox('数据保存成功！','提示信息');
    Panel2.Visible:=false;
    TBRafresh.Click;
    exit;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Order_Main.EnableControls;
    application.MessageBox('数据保存失败！','提示信息',0);
  end;
end;

procedure TfrmJYOrderCDOne_HZCX.ToolButton12Click(Sender: TObject);
begin
  Panel5.Visible:=true;
end;

procedure TfrmJYOrderCDOne_HZCX.conNOKeyPress(Sender: TObject;
  var Key: Char);
begin
  if Key=#13 then
  begin
    if Length(Conno.Text)<4 then Exit;
    {MovePanel2.Visible:=True;
    MovePanel2.Refresh;}
    try
      ADOQueryMain.DisableControls;
      with ADOQueryMain do
      begin
        Close;
        sql.Clear;
        sql.add('select DD.PrtCodeName,DD.SOrdDefStr4,DD.PRTColor,DD.PRTColorNo,DD.PRTHX,B.factoryName,B.SPID,B.fromFactoryName,EE.ConPerson2,EE.conDefstr2,EE.conDefstr3,EE.ConNo,EE.KHConNO,DD.StyleNo ');
        sql.add(',A.Mjstr4,A.MJType,Sum(A.MJQty3) MJQty3,Sum(A.MJQty4) MJQty4,sum(MJMaoZ) MJMaoZ,Sum(MJLen) MJLen,Sum(A.MJQty2) MJQty2');
        sql.add(',MJQty=(select Count(C.MJXH) from WFB_MJJY C where C.APID=B.SPID and C.MJType=A.MJType and C.MJTypeOther=A.MJTypeOther and C.MJStr2=A.MJStr2)');
        sql.add(',A.MJTypeOther,A.MKXS,A.MJStr2 ');
        sql.add('from WFB_MJJY A ');
        sql.add('inner join CK_SXPB_CR B on B.SPID=A.APID ');
        sql.add('inner join JYOrderCon_Sub DD on DD.Subid=A.ConID ');
        sql.add('inner join JYOrderCon_Main EE on EE.Mainid=DD.Mainid ');
        sql.add('where  EE.ConNo like '''+'%'+trim(ConNo.Text)+'%'+''' ');
        sql.add('group by DD.PrtCodeName,DD.SOrdDefStr4,DD.PRTColor,DD.PRTColorNo,DD.PRTHX,B.factoryName,B.SPID,B.fromFactoryName,EE.ConPerson2,EE.conDefstr2,EE.conDefstr3,EE.ConNo,EE.KHConNO,DD.StyleNo ');
        sql.add(',A.Mjstr4,A.MJType,A.MJTypeOther,A.MKXS,A.MJStr2 ');
        Open;
      end;
      SCreateCDS20(ADOQueryMain,Order_Main);
      SInitCDSData20(ADOQueryMain,Order_Main);
    finally
      ADOQueryMain.EnableControls;
    end;
    //MovePanel2.Visible:=False;
  end;
end;

procedure TfrmJYOrderCDOne_HZCX.ADateChange(Sender: TObject);
begin
  initGrid();
end;

procedure TfrmJYOrderCDOne_HZCX.cxTabControl1Change(Sender: TObject);
begin
  initgrid();
end;

procedure TfrmJYOrderCDOne_HZCX.CheckBox3Click(Sender: TObject);
begin
  initgrid();
end;

procedure TfrmJYOrderCDOne_HZCX.Tv1CellDblClick(
  Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  frmJYOrderCDOne:=TfrmJYOrderCDOne.create(self);
  with frmJYOrderCDOne do
  begin
    FBeg:=datetostr(self.BegDate.DateTime);
    FEnd:=datetostr(self.EndDate.DateTime);
    FMJType:=trim(self.Order_Main.fieldbyname('MJType').AsString);
    FFiller:=trim(self.Order_Main.fieldbyname('Filler').AsString);
    FMJStr2:=trim(self.Order_Main.fieldbyname('MJStr2').AsString);
    FAPID:=trim(self.Order_Main.fieldbyname('APID').AsString);
    if showmodal=1 then
    begin
      
    end;
    free;
  end;
end;

end.
