unit U_JYOrderCDOne;

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;

type
  TfrmJYOrderCDOnePB = 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;
    Label3: TLabel;
    ConNo: TEdit;
    TBExport: TToolButton;
    Order_Main: TClientDataSet;
    Label7: TLabel;
    C_Color: TEdit;
    Label8: TLabel;
    Label10: TLabel;
    MJID: TEdit;
    Label2: TLabel;
    CDQK10: TEdit;
    Panel4: TPanel;
    Label11: TLabel;
    Panel10: TPanel;
    Image2: TImage;
    RichEdit1: TRichEdit;
    v1Column1: TcxGridDBColumn;
    Label4: TLabel;
    MJType: TComboBox;
    v1Column13: TcxGridDBColumn;
    Label5: TLabel;
    MPRTCodeName: TEdit;
    Label6: TLabel;
    MJStr2: TComboBox;
    Filler: TComboBox;
    TBManage: TToolButton;
    v1Column22: TcxGridDBColumn;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    TBZF: TToolButton;
    ToolButton1: TToolButton;
    RM2: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    ADOQueryPrint: TADOQuery;
    MovePanel2: TMovePanel;
    v1Column2: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1APDate: TcxGridDBColumn;
    Label1: TLabel;
    ToolButton2: TToolButton;
    Label9: TLabel;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    Label12: TLabel;
    v1ConDefStr2: TcxGridDBColumn;
    v1ChouZhenYT: TcxGridDBColumn;
    v1ConDefStr10: TcxGridDBColumn;
    CarNo: TEdit;
    Label13: TLabel;
    Label14: TLabel;
    Edit1: TEdit;
    ConDefStr10: TEdit;
    SCPerson: TEdit;
    TSel: TToolButton;
    cxStyle2: TcxStyle;
    v1JYdate: TcxGridDBColumn;
    v1JBPerson: TcxGridDBColumn;
    Label15: TLabel;
    JBPerson: TEdit;
    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 ConNoChange(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 Tv1CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure TBManageClick(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure TBZFClick(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure RadioGroup1Click(Sender: TObject);
    procedure Aorddefstr1Change(Sender: TObject);
    procedure ConNoKeyPress(Sender: TObject; var Key: Char);
    procedure MJIDKeyPress(Sender: TObject; var Key: Char);
    procedure ToolButton2Click(Sender: TObject);
    procedure TSelClick(Sender: TObject);
  private
    DQdate:TDateTime;
    FLeft,FTop:Integer;
    canshu1,canshu2:string;
    procedure InitGrid();
    procedure InitGrid10();
    procedure InitForm();
    function  Savedata():Boolean;
    { Private declarations }
  public
    FFInt:Integer;
    { Public declarations }
  end;

var
  frmJYOrderCDOnePB: TfrmJYOrderCDOnePB;

implementation
uses
  U_DataLink,U_RTFun,U_MJEdit1;  //U_OrderInPut,

{$R *.dfm}

procedure TfrmJYOrderCDOnePB.FormDestroy(Sender: TObject);
begin
  frmJYOrderCDOnePB:=nil;
end;

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

procedure TfrmJYOrderCDOnePB.FormCreate(Sender: TObject);
begin
  canshu1:=Trim(DParameters1);
  canshu2:=Trim(DParameters2);
  cxgrid1.Align:=alClient;
  DQdate:=SGetServerDate(ADOQueryTemp);
end;

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

procedure TfrmJYOrderCDOnePB.InitGrid();
var
  i:integer;
  j:Integer;
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add('select distinct JYDate=cast(AP.Filltime as date)');
      sql.add(',A.APDate,CC.ConNo,AP.JBPerson,A.SCPerson,A.CarNo,BB.C_CodeName,BB.ConDefStr2,BB.ChouZhenYT,');
      sql.add('BB.ConDefStr10,BB.Subid,CC.Mainid ');
      sql.add(' from JYCon_Sub_AnPai A ');
      sql.add(' inner join WFB_MJJY_PB AP on A.APID=AP.APID ');
      sql.Add('inner join Cloth_Sub BB on A.SubId=BB.SubId ');
      sql.add('inner join Cloth_Main CC on A.MainId=CC.MainId where 1=1 ');
      sql.add(' and AP.filltime>='''+trim(formatdatetime('yyyy-MM-dd',begdate.DateTime))+''' ');
      sql.add(' and AP.filltime<'''+trim(formatdatetime('yyyy-MM-dd',enddate.DateTime+1))+''' ');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,Order_Main);
    SInitCDSData20(ADOQueryMain,Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmJYOrderCDOnePB.InitGrid10();
begin

end;

procedure TfrmJYOrderCDOnePB.InitForm();
var
  fsj:String;
begin
  ReadCxGrid('检验报告JPB2',Tv1,'检验管理');
  BegDate.DateTime:=StrToDateTime(Formatdatetime('yyyy-MM-dd',SGetServerDate10(ADOQueryTemp)-1));
  EndDate.DateTime:=StrToDateTime(Formatdatetime('yyyy-MM-dd',SGetServerDate10(ADOQueryTemp)));
  InitGrid();
end;

procedure TfrmJYOrderCDOnePB.TBFindClick(Sender: TObject);
var
  fsj:String;
begin
  {if ADOQueryMain.Active=False then Exit;
  fsj:=SGetFilters(Panel1,1,2);
  SDofilter(ADOQueryMain,fsj);
  SCreateCDS20(ADOQueryMain,Order_Main);
  SInitCDSData20(ADOQueryMain,Order_Main);}
  if ADOQueryMain.Active=False then Exit;
  SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
  SCreateCDS20(ADOQueryMain,Order_Main);
  SInitCDSData20(ADOQueryMain,Order_Main);
end;


procedure TfrmJYOrderCDOnePB.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then Exit;
  TcxGridToExcel('检验报告',cxGrid1);
end;

procedure TfrmJYOrderCDOnePB.TBRafreshClick(Sender: TObject);
begin
  MovePanel2.Visible:=True;
  MovePanel2.Refresh;
  InitGrid();
  MovePanel2.Visible:=False;
end;

procedure TfrmJYOrderCDOnePB.ConNoChange(Sender: TObject);
var
  fsj:String;
begin
  if ADOQueryMain.Active=False then Exit;
  SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
  SCreateCDS20(ADOQueryMain,Order_Main);
  SInitCDSData20(ADOQueryMain,Order_Main);
end;

procedure TfrmJYOrderCDOnePB.FormShow(Sender: TObject);
begin
  InitForm();
  if Trim(canshu2)='管理' then
  begin
    TBManage.Visible:=True;
    TBZF.Visible:=True;
    //TBAftChkHX.Visible:=True;
  end;
end;

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

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

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

procedure TfrmJYOrderCDOnePB.Tv1CellDblClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  Panel4.Left:=FLeft;
  Panel4.Top:=FTop+110;
  Panel4.Visible:=True;
  Panel4.Refresh;
  Panel10.Caption:=Trim(TV1.Controller.FocusedColumn.Caption);
  RichEdit1.Text:=Order_Main.fieldbyname(TV1.Controller.FocusedColumn.DataBinding.FilterFieldName).AsString;
end;

procedure TfrmJYOrderCDOnePB.TBManageClick(Sender: TObject);
begin
  try
    frmMJEditPB:=TfrmMJEditPB.Create(Application);
    with frmMJEditPB do
    begin
      MJID.Text:=Trim(Self.Order_Main.fieldbyname('MJID').AsString);
      with ADOTmp do
      begin
        Close;
        sql.Clear;
        SQL.Add('select A.*  from WFB_MJJY_PB A ');
        sql.Add(' where A.MJID='''+Trim(MJID.Text)+'''');
        Open;
      end;
      if ADOTmp.IsEmpty then
      begin
        MJID.Text:='';
        Label2.Caption:='';
        Label2.Visible:=False;
        Application.MessageBox('条码错误!','提示',0);
        Exit;
      end;
      MJMaoZ.Text:=Trim(ADOTmp.fieldbyname('MJMaoZ').AsString);
      MJLen.Text:=Trim(ADOTmp.fieldbyname('MJLen').AsString);
      //MJQty1.Text:=Trim(ADOTmp.fieldbyname('MJQty1').AsString);
      MJQty2.Text:=Trim(ADOTmp.fieldbyname('MJQty2').AsString);
      MJQty4.Text:=Trim(ADOTmp.fieldbyname('MJQty4').AsString);
      FeiPinQtyKg.Text:=Trim(ADOTmp.fieldbyname('FeiPinQtyKg').AsString);
      MJQty5.Text:=Trim(ADOTmp.fieldbyname('MJQty5').AsString);
      MJFK.Text:=Trim(ADOTmp.fieldbyname('MJFK').AsString);
      MJSJKZ.Text:=Trim(ADOTmp.fieldbyname('MJSJKZ').AsString);
      M.Caption:=Trim(Trim(ADOTmp.fieldbyname('MJTypeOther').AsString));
      //Ma.Caption:=Trim(Trim(ADOTmp.fieldbyname('MJStr1').AsString));
      if Trim(m.Caption)='' then
      begin
        m.Caption:='M';
      end;
      {if Trim(Ma.Caption)='' then
      begin
        Ma.Caption:=Trim(ADOTmp.fieldbyname('AOrddefstr2').AsString);
      end; }
      if Trim(Trim(ADOTmp.fieldbyname('MJType').AsString))='正品' then
      begin
        RadioGroup1.ItemIndex:=0
      end else
      if Trim(Trim(ADOTmp.fieldbyname('MJType').AsString))='次品' then
      begin
        RadioGroup1.ItemIndex:=1;
      end else
      if Trim(Trim(ADOTmp.fieldbyname('MJType').AsString))='留样' then
      begin
        RadioGroup1.ItemIndex:=2;
      end;
      if Trim(Trim(ADOTmp.fieldbyname('MJstr1').AsString))='半匹' then
    begin
      RadioGroup2.ItemIndex:=0;
    end;
    if Trim(Trim(ADOTmp.fieldbyname('MJstr1').AsString))='整匹' then
    begin
      RadioGroup2.ItemIndex:=1;
    end;
    if Trim(Trim(ADOTmp.fieldbyname('MJstr3').AsString))='漂白' then
    begin
      RadioGroup3.ItemIndex:=0;
    end;
    if Trim(Trim(ADOTmp.fieldbyname('MJstr3').AsString))='浅色' then
    begin
      RadioGroup3.ItemIndex:=1;
    end;
    if Trim(Trim(ADOTmp.fieldbyname('MJstr3').AsString))='敏感色' then
    begin
      RadioGroup3.ItemIndex:=2;
    end;
    if Trim(Trim(ADOTmp.fieldbyname('MJstr3').AsString))='深色' then
    begin
      RadioGroup3.ItemIndex:=3;
    end;
      with ADOTmp do
      begin
        Close;
        sql.Clear;
        SQL.Add('select * from WFB_MJJY_CD_PB A   where A.MJID='''+Trim(MJID.Text)+'''');
        Open;
      end;
      Label2.Caption:=Trim(MJID.Text);
      Label2.Visible:=True;
      MJID.Text:='';
      SCreateCDS20(ADOTmp,Order_MJ);
      SInitCDSData20(ADOTmp,Order_MJ);
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmMJEditPB.Free;
  end;
end;

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

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

procedure TfrmJYOrderCDOnePB.TBZFClick(Sender: TObject);
begin
  if Order_Main.Locate('ssel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  if Application.MessageBox('确定要作废数据吗？作废后数据不能恢复。','提示',32+4)<>IDYES then  Exit;
  Order_Main.DisableControls;
  with Order_Main do
  begin
    First;
    while not Eof do
    begin
      if Order_Main.FieldByName('SSel').AsBoolean=True then
      begin
        with ADOQueryTemp do
        begin
          Close;
          sql.Clear;
          sql.Add('select * from CK_PBCP_CR where MJID='''+Trim(Order_Main.fieldbyname('MJID').AsString)+'''');
          Open;
        end;
        if ADOQueryTemp.RecordCount>2 then
        begin
          Order_Main.EnableControls;
          Application.MessageBox('已出库不能删除!','提示',0);
          Exit;
        end else
        begin
          //begin
            with ADOQueryCmd do
            begin
              Close;
              sql.Clear;
              sql.Add('delete WFB_MJJY_PB where MJID='''+Trim(Order_Main.fieldbyname('MJID').AsString)+'''');
              sql.Add('delete WFB_MJJY_CD_PB where MJID='''+Trim(Order_Main.fieldbyname('MJID').AsString)+'''');
              sql.Add('delete CK_PBCP_CR where MJID='''+Trim(Order_Main.fieldbyname('MJID').AsString)+'''');
              sql.Add('delete CK_PBCP_KC where MJID='''+Trim(Order_Main.fieldbyname('MJID').AsString)+'''');
              sql.Add(' Update JYCon_Sub_AnPai Set JYFlag=0 where APID='''+Trim(Order_Main.fieldbyname('MJID').AsString)+'''');
              ExecSQL;
            end;
         // end;
        end;
        Order_Main.Delete;
      end else
        Next;
    end;
  end;
  Order_Main.EnableControls;

end;

procedure TfrmJYOrderCDOnePB.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_PB 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 A.MJID,A.MJXH,QtyUnit=A.MJTypeOther,ConNo=RTrim(B.ConNo) ');  //,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(',GSTTJC=(select Note from KH_Zdy where Type=''GSTT'' and ZdyName=B.ComTaiTou)');
          sql.Add(',C.*,A.*,D.* ');
          sql.Add(' from WFB_MJJY_PB A') ;
          sql.Add(' inner join Cloth_Main B On A.Mainid=B.Mainid');
          sql.Add(' inner join Cloth_Sub C on A.SubId=C.SubId');
          sql.Add(' inner join JYCon_Sub_AnPai D on D.apid=A.apid');
          SQL.Add(' where A.MJID='''+Trim(Order_Main.fieldbyname('MJID').AsString)+'''');
          Open;
        end;
        {if Trim(ADOQueryPrint.fieldbyname('LbName').AsString)<>'' then
          fPrintFile:=ExtractFilePath(Application.ExeName)+'Report\'+Trim(ADOQueryPrint.fieldbyname('LbName').AsString)+'.rmf'
        else}
        try
          Moudle:=LoadLibrary('MakeQRBarcode.dll');
          @Makebar:=GetProcAddress(Moudle,'Make');
          @Mixtext:=GetProcAddress(Moudle,'MixText');
          Txt:=Trim(Order_Main.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
          //CDS_AnPai.EnableControls;
          application.MessageBox('条形码生成失败！','提示信息',MB_ICONERROR);
          exit;
        end;
          fPrintFile:=ExtractFilePath(Application.ExeName)+'Report\坯布标签.rmf' ;
        if FileExists(fPrintFile) then
        begin
          RM2.LoadFromFile(fPrintFile);
          RMVariables['QRBARCODE']:=fImagePath;
          //RM2.ShowReport;
          RM2.PrintReport;
        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 TfrmJYOrderCDOnePB.RadioGroup1Click(Sender: TObject);
begin
  TBFind.Click;
end;

function TfrmJYOrderCDOnePB.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 TfrmJYOrderCDOnePB.Aorddefstr1Change(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmJYOrderCDOnePB.ConNoKeyPress(Sender: TObject; var Key: Char);
begin
  if Key=#13 then
  begin
    if Length(ConNo.Text)<3 then Exit;
    MovePanel2.Visible:=True;
    MovePanel2.Refresh;
    try
      ADOQueryMain.DisableControls;
      with ADOQueryMain do
      begin
        Filtered:=False;
        Close;
        sql.Clear;
        sql.Add('select distinct Ap.APDate,CC.ConNo,AP.SCPerson,AP.CarNo,BB.C_CodeName,BB.ConDefStr2,BB.ChouZhenYT,');
        sql.add('BB.ConDefStr10,BB.Subid,CC.Mainid ');
        sql.add(' from JYCon_Sub_AnPai AP ');
        sql.Add('inner join Cloth_Sub BB on AP.SubId=BB.SubId ');
        sql.add('inner join Cloth_Main CC on AP.MainId=CC.MainId where 1=1 ');
        sql.add(' and CC.ConNO like '''+'%'+trim(ConNo.Text)+'%'+'''');
        Open;
      end;
      SCreateCDS20(ADOQueryMain,Order_Main);
      SInitCDSData20(ADOQueryMain,Order_Main);
    finally
      ADOQueryMain.EnableControls;
    end;
    MovePanel2.Visible:=False;
  end;
end;

procedure TfrmJYOrderCDOnePB.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_HZFX_PB :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 C.MJID='''+Trim(MJID.Text)+'''';
        Open;
      end;
      SCreateCDS20(ADOQueryMain,Order_Main);
      SInitCDSData20(ADOQueryMain,Order_Main);
      MJID.Text:='';
    finally
      ADOQueryMain.EnableControls;
    end;
    MovePanel2.Visible:=False;
  end;
end;

procedure TfrmJYOrderCDOnePB.ToolButton2Click(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_PB 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 A.MJID,A.MJXH,QtyUnit=A.MJTypeOther,ConNo=RTrim(B.ConNo) ');  //,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(',GSTTJC=(select Note from KH_Zdy where Type=''GSTT'' and ZdyName=B.ComTaiTou)');
          sql.Add(',C.*,A.*,D.* ');
          sql.Add(' from WFB_MJJY_PB A') ;
          sql.Add(' inner join Cloth_Main B On A.Mainid=B.Mainid');
          sql.Add(' inner join Cloth_Sub C on A.SubId=C.SubId');
          sql.Add(' inner join JYCon_Sub_AnPai D on D.apid=A.apid');
          SQL.Add(' where A.MJID='''+Trim(Order_Main.fieldbyname('MJID').AsString)+'''');
          Open;
        end;
        {if Trim(ADOQueryPrint.fieldbyname('LbName').AsString)<>'' then
          fPrintFile:=ExtractFilePath(Application.ExeName)+'Report\'+Trim(ADOQueryPrint.fieldbyname('LbName').AsString)+'.rmf'
        else}
        try
          Moudle:=LoadLibrary('MakeQRBarcode.dll');
          @Makebar:=GetProcAddress(Moudle,'Make');
          @Mixtext:=GetProcAddress(Moudle,'MixText');
          Txt:=Trim(Order_Main.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
          //CDS_AnPai.EnableControls;
          application.MessageBox('条形码生成失败！','提示信息',MB_ICONERROR);
          exit;
        end;
          fPrintFile:=ExtractFilePath(Application.ExeName)+'Report\坯布标签.rmf' ;
        if FileExists(fPrintFile) then
        begin
          RM2.LoadFromFile(fPrintFile);
          RMVariables['QRBARCODE']:=fImagePath;
          RM2.ShowReport;
          //RM2.PrintReport;
        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 TfrmJYOrderCDOnePB.TSelClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then exit;
  Modalresult:=1;
end;

end.
