unit U_JYOrderCDList;

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, BtnEdit, RM_e_main, RM_e_htm, RM_e_Graphic,
  RM_e_Jpeg, RM_e_txt, RM_e_csv, RM_E_llPDF, Math, Clipbrd, cxPC, cxLookAndFeels,
  cxLookAndFeelPainters, cxNavigator, dxBarBuiltInMenu, Printers, dxSkinsCore,
  dxSkinsDefaultPainters, dxSkinscxPCPainter, cxImage, dxSkinBlack,
  dxSkinBlue, dxSkinBlueprint, dxSkinCaramel, dxSkinCoffee, dxSkinDarkRoom,
  dxSkinDarkSide, dxSkinDevExpressDarkStyle, dxSkinDevExpressStyle,
  dxSkinFoggy, dxSkinGlassOceans, dxSkinHighContrast, dxSkiniMaginary,
  dxSkinLilian, dxSkinLiquidSky, dxSkinLondonLiquidSky, dxSkinMcSkin,
  dxSkinMetropolis, dxSkinMetropolisDark, dxSkinMoneyTwins,
  dxSkinOffice2007Black, dxSkinOffice2007Blue, dxSkinOffice2007Green,
  dxSkinOffice2007Pink, dxSkinOffice2007Silver, dxSkinOffice2010Black,
  dxSkinOffice2010Blue, dxSkinOffice2010Silver, dxSkinOffice2013DarkGray,
  dxSkinOffice2013LightGray, dxSkinOffice2013White, dxSkinPumpkin,
  dxSkinSeven, dxSkinSevenClassic, dxSkinSharp, dxSkinSharpPlus,
  dxSkinSilver, dxSkinSpringTime, dxSkinStardust, dxSkinSummer2008,
  dxSkinTheAsphaltWorld, dxSkinValentine, dxSkinVS2010, dxSkinWhiteprint,
  dxSkinXmas2008Blue;

type
  TZintSymbol = packed record
    symbology: Integer;
    height: Integer;
    whitespace_width: Integer;
    border_width: Integer;
    output_options: Integer;
    fgcolour: array[0..9] of AnsiChar;
    bgcolour: array[0..9] of AnsiChar;
    outfile: array[0..255] of AnsiChar;
    scale: Single;
    option_1: Integer;
    option_2: Integer;
    option_3: Integer;
    show_hrt: Integer;
    input_mode: Integer;
    eci: Integer;
    text: array[0..127] of AnsiChar;
    rows: Integer;
    width: Integer;
    primary: array[0..127] of AnsiChar;
    encoded_data: array[0..199, 0..142] of AnsiChar;
    row_height: array[0..199] of Integer; // Largest symbol is 189 x 189
    errtxt: array[0..99] of AnsiChar;
    bitmap: PAnsiChar;
    bitmap_width: Integer;
    bitmap_height: Integer;
    bitmap_byte_length: Cardinal;
    dot_size: Single;
    rendered: Pointer;
    debug: Integer;
  end;

  PZintSymbol = ^TZintSymbol;

const
  // Tbarcode 7 codes
  BARCODE_QRCODE = 71;

type
  TfrmJYOrderCDList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: 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;
    OrderNo: TEdit;
    TBExport: TToolButton;
    Order_Main: TClientDataSet;
    conNO: TEdit;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    MJID: TEdit;
    v1Column1: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    Label4: TLabel;
    MJType: TComboBox;
    v1Column13: TcxGridDBColumn;
    Label5: TLabel;
    MPRTCodeName: TEdit;
    Label6: TLabel;
    MJStr2: TComboBox;
    v1Column17: TcxGridDBColumn;
    v1Column19: TcxGridDBColumn;
    Label12: TLabel;
    factoryName: TEdit;
    v1Column20: TcxGridDBColumn;
    v1Column21: TcxGridDBColumn;
    Filler: TComboBox;
    TBManage: TToolButton;
    v1Column22: TcxGridDBColumn;
    v1Column23: TcxGridDBColumn;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    TBZF: TToolButton;
    ToolButton1: TToolButton;
    RM2: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    ADOQueryPrint: TADOQuery;
    v1Column24: TcxGridDBColumn;
    MovePanel2: TMovePanel;
    v1Column27: TcxGridDBColumn;
    v1Column28: TcxGridDBColumn;
    v1Column14: TcxGridDBColumn;
    CDS_CD: TClientDataSet;
    RMCD: TRMGridReport;
    RMDBCD: TRMDBDataSet;
    CDS_LS: TClientDataSet;
    v1Column15: TcxGridDBColumn;
    ToolButton3: TToolButton;
    Panel2: TPanel;
    Label15: TLabel;
    cxCurrencyEdit1: TcxCurrencyEdit;
    Button1: TButton;
    Button2: TButton;
    v1MKXS: TcxGridDBColumn;
    Mjstr4: TEdit;
    PrtColor: TEdit;
    Label18: TLabel;
    ComboBox1: TComboBox;
    RM3: TRMGridReport;
    v1Column31: TcxGridDBColumn;
    ToolButton8: TToolButton;
    v1Column32: TcxGridDBColumn;
    v1Column33: TcxGridDBColumn;
    KHConNO: TEdit;
    Label19: TLabel;
    v1Column34: TcxGridDBColumn;
    v1Column36: TcxGridDBColumn;
    RMXLSExport1: TRMXLSExport;
    CDS_HZ: TClientDataSet;
    RMDBHZ: TRMDBDataSet;
    cxCurrencyEdit2: TcxCurrencyEdit;
    Label24: TLabel;
    Label25: TLabel;
    ComboBox4: TComboBox;
    RMDBPRT: TRMDBDataSet;
    CDS_PRT: TClientDataSet;
    btnPLXG: TToolButton;
    Panel5: TPanel;
    Label28: TLabel;
    ComboBox5: TComboBox;
    Button5: TButton;
    Button6: TButton;
    v1Column39: TcxGridDBColumn;
    Panel6: TPanel;
    Label31: TLabel;
    LBCPAP: TLabel;
    BTLP: TButton;
    BTNP: TButton;
    TCBNOR: TComboBox;
    IsJYTime: TCheckBox;
    v1Column42: TcxGridDBColumn;
    v1Column16: TcxGridDBColumn;
    Label1: TLabel;
    RKOrdID: TEdit;
    N3: TMenuItem;
    ToolButton4: TToolButton;
    X1: TMenuItem;
    cxTabControl1: TcxTabControl;
    v1Column18: TcxGridDBColumn;
    B1: TToolButton;
    lbl1: TLabel;
    APID: TEdit;
    Label2: TLabel;
    RCGangNo: TEdit;
    v1Column25: TcxGridDBColumn;
    v1Column26: TcxGridDBColumn;
    v1Column29: TcxGridDBColumn;
    v1Column30: TcxGridDBColumn;
    v1Column35: TcxGridDBColumn;
    Label11: TLabel;
    lidan: TEdit;
    Label13: TLabel;
    YWY: TEdit;
    v1Column37: TcxGridDBColumn;
    v1Column38: TcxGridDBColumn;
    v1Column40: TcxGridDBColumn;
    Label14: TLabel;
    KuanHao: TEdit;
    v1Column41: TcxGridDBColumn;
    v1Column43: TcxGridDBColumn;
    ToolButton2: TToolButton;
    v1Column44: TcxGridDBColumn;
    v1Column45: TcxGridDBColumn;
    v1Column46: TcxGridDBColumn;
    Label16: TLabel;
    JTType: TEdit;
    Panel3: TPanel;
    Label26: TLabel;
    Label27: TLabel;
    Label29: TLabel;
    Label30: TLabel;
    Edit_RollNum_X: TEdit;
    Edit_Qty_M_X: TEdit;
    edit_Qty_Y_X: TEdit;
    Edit1: TEdit;
    Label17: TLabel;
    Label20: TLabel;
    PRTHX: TEdit;
    v1Column47: TcxGridDBColumn;
    btnHY: TToolButton;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    Tv1Column3: TcxGridDBColumn;
    Label21: TLabel;
    kuanghao: TEdit;
    Label22: TLabel;
    Button3: TButton;
    edtkuanghao: TBtnEditA;
    Tv1Column4: TcxGridDBColumn;
    Label23: TLabel;
    MPRTCode: TEdit;
    Tv1Column5: TcxGridDBColumn;
    Label32: TLabel;
    baono: TEdit;
    Label33: TLabel;
    Button4: TButton;
    cxCurrencyEdit3: TcxCurrencyEdit;
    Tv1Column6: TcxGridDBColumn;
    Tv1Column7: TcxGridDBColumn;
    ToolButton5: TToolButton;
    ADOQuery1: TADOQuery;
    ComboBox2: TComboBox;
    Label34: TLabel;
    ToolButton6: TToolButton;
    cxImage1: TcxImage;
    Label35: TLabel;
    Button7: TButton;
    Edit2: TEdit;
    Tv1Column8: TcxGridDBColumn;
    Tv1BarCode: TcxGridDBColumn;
    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 FormShow(Sender: TObject);
    procedure Tv1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure TBManageClick(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure TBZFClick(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure OrderNoKeyPress(Sender: TObject; var Key: Char);
    procedure v1Column15PropertiesEditValueChanged(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure MJIDKeyPress(Sender: TObject; var Key: Char);
    procedure Button6Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure btnPLXGClick(Sender: TObject);
    procedure BTLPClick(Sender: TObject);
    procedure BTNPClick(Sender: TObject);
    procedure TCBNORChange(Sender: TObject);
    procedure ToolButton8Click(Sender: TObject);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
    procedure conNOKeyPress(Sender: TObject; var Key: Char);
    procedure MJStr2Change(Sender: TObject);
    procedure MJTypeChange(Sender: TObject);
    procedure KHConNOKeyPress(Sender: TObject; var Key: Char);
    procedure RKOrdIDKeyPress(Sender: TObject; var Key: Char);
    procedure N3Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure X1Click(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure B1Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure v1Column22PropertiesChange(Sender: TObject);
    procedure Tv1CustomDrawIndicatorCell(Sender: TcxGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxCustomGridIndicatorItemViewInfo; var ADone: Boolean);
    procedure btnHYClick(Sender: TObject);
    procedure edtkuanghaoBtnClick(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure ToolButton6Click(Sender: TObject);
    procedure Button7Click(Sender: TObject);
  private
    DQdate: TDateTime;
    FLeft, FTop: Integer;
    CurrentPage, RecordsNumber: Integer;
    procedure InitGrid();
    procedure InitForm();
//    procedure InitPage();
    procedure JsNum();
    function Savedata(): Boolean;
    procedure GetCDSData();
    procedure SetStatus();
    procedure PrintCKMDG(MRKOrdID: string);
    { Private declarations }
  public
    FFInt: Integer;
    canshu1: string;
    FKHEWM: string;
    { Public declarations }
  end;

const
  LibName = 'zint.dll';

  //struct zint_symbol *ZBarcode_Create(void);
function ZBarcode_Create(): PZintSymbol; cdecl; external LibName;

  //void ZBarcode_Delete(struct zint_symbol *symbol);
procedure ZBarcode_Delete(symbol: PZintSymbol); cdecl; external LibName;

  //int ZBarcode_Encode_and_Buffer(struct zint_symbol *symbol, unsigned char *input, int length, int rotate_angle);
function ZBarcode_Encode_and_Buffer(symbol: PZintSymbol; input: PAnsiChar; length, rotate_angle: Integer): Integer; cdecl; external LibName;

  // create bitmap 这个函数是使用编码后的条码图像数据生成Bitmap文件，不属于zint，因此不在zint.h头文件中，上面的三个在zint.h头文件中。

procedure ZBarcode_To_Bitmap(symbol: PZintSymbol; const ABitmap: TBitmap);

function GetCurrentPrinterHandle: THandle;

implementation

uses
  U_DataLink, U_OrderInPut, U_Fun, U_MJEdit, U_ZDYHelp, U_ProductOrderListSel,
  U_SysLogHelp, U_ZdyMapSel2;

{$R *.dfm}
function GetCurrentPrinterHandle: THandle;
var
  Device, Driver, Port: array[0..255] of char;
  hDeviceMode: THandle;
begin
  Printer.GetPrinter(Device, Driver, Port, hDeviceMode);
//  if not OpenPrinter(@Device, Result, nil) then
//    RaiseLastWin32Error;
end;

procedure ZBarcode_To_Bitmap(symbol: PZintSymbol; const ABitmap: TBitmap);
var
  SrcRGB: PRGBTriple;
  Row, RowWidth: Integer;
begin
  ABitmap.PixelFormat := pf24bit;
  ABitmap.Height := symbol.bitmap_height;
  ABitmap.Width := symbol.bitmap_width;

//  ABitmap.Height := 80;
//  ABitmap.Width := 80;

  SrcRGB := Pointer(symbol.bitmap);
  RowWidth := symbol.bitmap_width * 3;

  for Row := 0 to symbol.bitmap_height - 1 do
  begin
    CopyMemory(ABitmap.ScanLine[Row], SrcRGB, RowWidth);
    Inc(SrcRGB, symbol.bitmap_width);
  end;

  SetBitmapBits(ABitmap.Handle, symbol.bitmap_width * symbol.bitmap_height * 3, symbol.bitmap);
end;

procedure TfrmJYOrderCDList.JsNum();
var
  fMJID: string;
  fps: integer;
  fQty, fQty1, fqty2: double;
begin
  fMJID := Order_Main.fieldbyName('MJID').AsString;
  fps := 0;
  fQty := 0;
  fQty1 := 0;
  fqty2 := 0;
  if Order_Main.IsEmpty then
    exit;
  with Order_Main do
  begin
    DisableControls;
    first;
    while not eof do
    begin
      if FieldByName('ssel').AsBoolean then
      begin
        fps := fps + FieldByName('KCRollNum').AsInteger;
        fQty := fQty + FieldByName('mjmaoz').AsFloat;
        fQty1 := fQty1 + FieldByName('mjlen').AsFloat;
        fqty2 := fqty2 + FieldByName('MJYLen').AsFloat;
     //   fMoney:=fMoney+FieldByName('money').AsFloat;
      end;
      next;
    end;
    First;
    EnableControls;
  end;
  Edit_RollNum_X.Text := inttostr(fps);
  Edit_Qty_M_X.Text := floattostr(fQty1);
  Edit_Qty_Y_X.Text := floattostr(fQty);
  Edit1.Text := floattostr(fqty2);
  Order_Main.Locate('MJID', fMJID, []);
end;

procedure TfrmJYOrderCDList.SetStatus();
begin
  TBManage.Visible := False;
  TBZF.Visible := False;
  btnHY.Visible := False;
  v1Column15.Options.Focusing := False;
//  ToolButton1.Visible := False;
  btnPLXG.Visible := False;
  if Trim(canshu1) = '管理' then
  begin

    TBManage.Visible := True;
    TBZF.Visible := True;
    v1Column15.Options.Focusing := True;
    ToolButton1.Visible := true;
    case cxTabControl1.TabIndex of
      0:
        begin
          ToolButton8.Visible := true;
          ToolButton4.Visible := false;
          btnPLXG.Visible := true;
        end;
      1:
        begin
          ToolButton8.Visible := false;
          ToolButton4.Visible := true;
          btnPLXG.Visible := true;
        end;
      2:
        begin
          ToolButton8.Visible := false;
          ToolButton4.Visible := true;
          btnPLXG.Visible := true;
        end;
      3:
        begin
          btnHY.Visible := true;
        end;
    end;
  end;

  if Trim(canshu1) = '次品管理' then
  begin
    TBZF.Visible := True;
  end;
end;

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

procedure TfrmJYOrderCDList.FormCreate(Sender: TObject);
begin
  ComboBox2.Items.Assign(Printer.Printers);
  ComboBox2.Items.Add('默认打印机');
  ComboBox2.ItemIndex := Self.ComboBox2.Items.IndexOf(trim('默认打印机'));
//  ComboBox2.ItemIndex := -1; //指向第一台打印机
  cxgrid1.Align := alClient;
  DQdate := SGetServerDate(ADOQueryTemp);
end;

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

procedure TfrmJYOrderCDList.PrintCKMDG(MRKOrdID: string);
var
  fPrintFile: string;
  Txt, fImagePath: string;
  Moudle: THandle;
  Makebar: TMakebar;
  Mixtext: TMixtext;
begin
  if Order_Main.IsEmpty then
    Exit;
  ExportFtErpFile('入库码单.rmf', ADOQueryTemp);
  with Order_Main do
  begin

    with ADOQueryPrint do
    begin
      Close;
      SQL.Clear;
      sql.Add(' exec P_Print_RKDMD1 ');
      SQL.Add(' @RKOrdNo=''' + Trim(MRKOrdID) + '''');
      Open;
    end;
    try
      Moudle := LoadLibrary('MakeQRBarcode.dll');
      @Makebar := GetProcAddress(Moudle, 'Make');
      @Mixtext := GetProcAddress(Moudle, 'MixText');
      Txt := Trim(ADOQueryPrint.fieldbyname('RKOrdID').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;
    fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\入库码单.rmf';
    if FileExists(fPrintFile) then
    begin
      RMVariables['QRBARCODE'] := fImagePath;
      RM2.LoadFromFile(fPrintFile);
      Rm2.DefaultCopies := strtointdef(trim(ComboBox1.Text), 1);
//      RM2.PrintReport;
      RM2.ShowReport;
    end
    else
    begin
      Application.MessageBox(PChar('没有找' + fPrintFile), '提示', 0);
      Exit;
    end;

  end;

end;

procedure TfrmJYOrderCDList.InitGrid();
var
  fwhere, Pwhere: string;
begin
  MovePanel2.Left := (self.Width - MovePanel2.Width) div 2;
  MovePanel2.Visible := True;
  MovePanel2.Refresh;
  fwhere := ' where 1=1 ';
  if IsJYTime.Checked then
  begin
    fwhere := fwhere + ' and Filltime>' + quotedstr(FormatDateTime('yyyy-MM-dd', BegDate.DateTime));
    fwhere := fwhere + ' and Filltime<=' + quotedstr(FormatDateTime('yyyy-MM-dd', enddate.DateTime + 1));
  end;

  Pwhere := SGetFilters(Panel1, 1, 2);
  if trim(Pwhere) <> '' then
  begin
    fwhere := fwhere + ' and ' + trim(Pwhere);
  end;

  case cxTabControl1.TabIndex of
    0:
      begin
        fwhere := fwhere + ' and MJStr2=''未入库'' ';
      end;
    1:
      begin
        fwhere := fwhere + ' and MJStr2<>''未入库'' ';
      end;
  end;

  if (canshu1 = '次品管理') or (canshu1 = '次品查询') then
  begin
    fwhere := fwhere + ' and MJType=''次品'' ';
  end;

  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add('exec P_Page_ClothInfo ');
      sql.Add('@pageIndex=' + inttostr(CurrentPage));
      sql.Add(',@pageSize=' + inttostr(RecordsNumber));
      sql.Add(',@criteria= ' + quotedstr(fwhere));
      if cxTabControl1.TabIndex = 3 then
        sql.Add(',@ZFFlag= 1 ')
      else
        sql.Add(',@ZFFlag= 0 ');
      Open;
    end;
    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);
    LBCPAP.Caption := inttostr(CurrentPage) + '/' + inttostr(ceil(Order_Main.FieldByName('TotalCount').AsInteger / RecordsNumber));
    MovePanel2.Visible := false;
  finally
    ADOQueryMain.EnableControls;
    MovePanel2.Visible := false;
  end;
end;

procedure TfrmJYOrderCDList.InitForm();
var
  fsj: string;
begin
  ReadCxGrid('检验报告JF', Tv1, '检验管理');

  fsj := 'select distinct(Filler) name from WFB_MJJY   ';
  SInitComBoxBySql(ADOQueryCmd, Filler, False, fsj);
  Filler.ItemIndex := Filler.Items.IndexOf(trim(DName));
  EndDate.DateTime := SGetServerDate10(ADOQueryTemp);
  if canshu1 = '次品查询' then
  begin
    BegDate.DateTime := EndDate.DateTime - 90;
  end
  else
  begin
    BegDate.DateTime := EndDate.DateTime - 14;
  end;

  //InitGrid();
end;

procedure TfrmJYOrderCDList.TBFindClick(Sender: TObject);
var
  fsj, fwhere: string;
begin

end;

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

procedure TfrmJYOrderCDList.TBRafreshClick(Sender: TObject);
begin
  OrderNo.SetFocus;

  CurrentPage := 1;
//  InitPage();

  Edit_RollNum_X.Text := '0';
  Edit_Qty_M_X.Text := '0';
  Edit_Qty_Y_X.Text := '0';
  Edit1.Text := '0';
  InitGrid();

end;

procedure TfrmJYOrderCDList.FormShow(Sender: TObject);
begin
  CurrentPage := 1;
  RecordsNumber := 500;
  InitForm();
  SetStatus();
end;

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

procedure TfrmJYOrderCDList.TBManageClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    exit;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from CK_BanCP_CR where CRFlag=''入库'' and MJID=''' + Trim(Order_Main.fieldbyname('MJID').AsString) + '''');
    Open;
  end;
  if ADOQueryTemp.IsEmpty = False then
  begin
    Order_Main.EnableControls;
    Application.MessageBox('已产生入库数据不能编辑!', '提示', 0);
    Exit;
  end;
  try
    frmMJEdit := TfrmMJEdit.Create(Application);
    with frmMJEdit do
    begin
      MJID.Text := Trim(Self.Order_Main.fieldbyname('MJID').AsString);
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmMJEdit.Free;
  end;
end;

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

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

procedure TfrmJYOrderCDList.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_BanCP_CR where MJID=''' + Trim(Order_Main.fieldbyname('MJID').AsString) + ''' and CRFlag=''入库''');
          Open;
        end;
        if ADOQueryTemp.IsEmpty = False then
        begin
          Order_Main.EnableControls;
          Application.MessageBox('已产生入库数据不能删除!', '提示', 0);
          Exit;
        end
        else
        begin
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('update WFB_MJJY set Deler=' + Quotedstr(Trim(DName)) + ' ,DelTime=GETDATE()  where MJID=''' + Trim(Order_Main.fieldbyname('MJID').AsString) + '''');

            sql.Add('insert into ZDel_WFB_MJJY  select * from WFB_MJJY where MJID=''' + Trim(Order_Main.fieldbyname('MJID').AsString) + '''');
            sql.Add('insert into ZDel_CK_BanCP_CR  select * from  CK_BanCP_CR where MJID=''' + Trim(Order_Main.fieldbyname('MJID').AsString) + '''');
            sql.Add('insert into ZDel_CK_BanCP_KC  select * from  CK_BanCP_KC where MJID=''' + Trim(Order_Main.fieldbyname('MJID').AsString) + '''');
            sql.Add('insert into ZDel_WFB_MJJY_CD  select * from  WFB_MJJY_CD where MJID=''' + Trim(Order_Main.fieldbyname('MJID').AsString) + '''');

            sql.Add('delete WFB_MJJY where MJID=''' + Trim(Order_Main.fieldbyname('MJID').AsString) + '''');
            sql.Add('delete CK_BanCP_CR where MJID=''' + Trim(Order_Main.fieldbyname('MJID').AsString) + '''');
            sql.Add('delete CK_BanCP_KC where MJID=''' + Trim(Order_Main.fieldbyname('MJID').AsString) + '''');
            sql.Add('delete WFB_MJJY_CD where MJID=''' + Trim(Order_Main.fieldbyname('MJID').AsString) + '''');
            //更新开卡
            sql.Add('exec P_UPdate_LCKJY @APID=''' + trim(Order_Main.fieldbyname('APID').AsString) + '''');

            sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
            sql.Add(' ' + quotedstr(trim(DName)));
            sql.Add(',getdate() ');
            sql.Add(',' + quotedstr(trim(self.Caption)));
            sql.Add(',' + quotedstr(trim('作废检验数据')));
            sql.Add(',' + quotedstr('卷条码：' + trim(Order_Main.fieldbyname('MJID').AsString) + ' 卷号：' + trim(Order_Main.fieldbyname('MJXH').AsString) + ' 卡号：' + trim(Order_Main.fieldbyname('apid').AsString)));
            sql.Add(',' + quotedstr(trim('成功')));
            sql.Add(')');
            ExecSQL;
          end;
        end;
        Order_Main.Delete;
      end
      else
        Next;
    end;
  end;
  Order_Main.EnableControls;

end;

procedure TfrmJYOrderCDList.ToolButton1Click(Sender: TObject);
var
  fPrintFile: string;
  Txt, Txt2, fImagePath, fImagePath2, Txt3, fImagePath3, Txt4, fImagePath4: 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(' EXEC P_Print_JYLab ');
          SQL.Add(' @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;
        try
          Moudle := LoadLibrary('MakeQRBarcode.dll');
          @Makebar := GetProcAddress(Moudle, 'Make');
          @Mixtext := GetProcAddress(Moudle, 'MixText');
          Txt2 := Trim(ADOQueryPrint.fieldbyname('KHEWM').AsString);

          fImagePath2 := ExtractFilePath(Application.ExeName) + 'image\temp2.bmp';
          if not DirectoryExists(pchar(ExtractFilePath(Application.ExeName) + 'image')) then
            CreateDirectory(pchar(ExtractFilePath(Application.ExeName) + 'image'), nil);
          if FileExists(fImagePath2) then
            DeleteFile(fImagePath2);
          Makebar(pchar(Txt2), Length(Txt2), 3, 3, 0, PChar(fImagePath2), 3);
        except
          application.MessageBox('条形码生成失败！', '提示信息', MB_ICONERROR);
          exit;
        end;

        try
          Moudle := LoadLibrary('MakeQRBarcode.dll');
          @Makebar := GetProcAddress(Moudle, 'Make');
          @Mixtext := GetProcAddress(Moudle, 'MixText');
          Txt3 := Trim(ADOQueryPrint.fieldbyname('mjid2').AsString);

          fImagePath3 := ExtractFilePath(Application.ExeName) + 'image\temp3.bmp';
          if not DirectoryExists(pchar(ExtractFilePath(Application.ExeName) + 'image')) then
            CreateDirectory(pchar(ExtractFilePath(Application.ExeName) + 'image'), nil);
          if FileExists(fImagePath3) then
            DeleteFile(fImagePath3);
          Makebar(pchar(Txt3), Length(Txt3), 3, 3, 0, PChar(fImagePath3), 3);
        except
          application.MessageBox('条形码生成失败！', '提示信息', MB_ICONERROR);
          exit;
        end;
        try

          fImagePath4 := ExtractFilePath(Application.ExeName) + 'image\temp4.bmp';

          if not DirectoryExists(pchar(ExtractFilePath(Application.ExeName) + 'image')) then
            CreateDirectory(pchar(ExtractFilePath(Application.ExeName) + 'image'), nil);
          if FileExists(fImagePath4) then
            DeleteFile(fImagePath4);
          FKHEWM := ADOQueryPrint.fieldbyname('khewm2').AsString;
          ToolButton6.Click();
        except
          application.MessageBox('条形码生成失败！', '提示信息', MB_ICONERROR);
          exit;
        end;
//        try
//          Moudle := LoadLibrary('MakeQRBarcode.dll');
//          @Makebar := GetProcAddress(Moudle, 'Make');
//          @Mixtext := GetProcAddress(Moudle, 'MixText');
//          Txt4 := Trim(ADOQueryPrint.fieldbyname('KHEWM2').AsString);
//
//          fImagePath4 := ExtractFilePath(Application.ExeName) + 'image\temp4.bmp';
//          if not DirectoryExists(pchar(ExtractFilePath(Application.ExeName) + 'image')) then
//            CreateDirectory(pchar(ExtractFilePath(Application.ExeName) + 'image'), nil);
//          if FileExists(fImagePath4) then
//            DeleteFile(fImagePath4);
//          Makebar(pchar(Txt4), Length(Txt4), 3, 3, 0, PChar(fImagePath4), 3);
//        except
//          application.MessageBox('条形码生成失败！', '提示信息', MB_ICONERROR);
//          exit;
//        end;
        if Trim(ADOQueryPrint.fieldbyname('LbName').AsString) <> '' then
        begin
          ExportFtErpFile(Trim(ADOQueryPrint.fieldbyname('LbName').AsString) + '.rmf', ADOQueryTemp);
          fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\' + Trim(ADOQueryPrint.fieldbyname('LbName').AsString) + '.rmf'
        end
        else
        begin
          ExportFtErpFile('通用英文标签.rmf', ADOQueryTemp);
          fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\通用英文标签.rmf';
        end;

        if Trim(Order_Main.fieldbyname('MJType').AsString) = '次品' then
        begin
          ExportFtErpFile('次品标签.rmf', ADOQueryTemp);
          fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\次品标签.rmf';
        end;

        if FileExists(fPrintFile) then
        begin
          RMVariables['QRBARCODE'] := fImagePath;
          RMVariables['QRBARCODE2'] := fImagePath2;
          RMVariables['QRBARCODE3'] := fImagePath3;
          RMVariables['QRBARCODE4'] := fImagePath4;
          RM2.LoadFromFile(fPrintFile);
          Rm2.DefaultCopies := strtointdef(trim(ComboBox1.Text), 1);
          RM2.PrintReportL(ComboBox2.Text);
        end
        else
        begin
          Order_Main.EnableControls;
          Application.MessageBox(PChar('没有找' + fPrintFile), '提示', 0);
          Exit;
        end;
      end;
      Next;
    end;
  end;
  Order_Main.EnableControls;
end;

function TfrmJYOrderCDList.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 TfrmJYOrderCDList.OrderNoKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    if Length(OrderNo.Text) < 4 then
      Exit;
    CurrentPage := 1;
    InitGrid();
  end;
end;

procedure TfrmJYOrderCDList.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 TfrmJYOrderCDList.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 TfrmJYOrderCDList.Button2Click(Sender: TObject);
begin
  Panel2.Visible := false;
end;

procedure TfrmJYOrderCDList.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) + '''');

              SQL.Add('Update CK_BanCP_CR set KGQty=B.MJMaoZ from CK_BanCP_CR A');
              SQL.Add('INNER JOIN WFB_MJJY B ON B.MJID=A.MJID ');
              SQL.Add('WHERE A.MJID=''' + Trim(Order_Main.fieldbyname('MJID').AsString) + '''');

              SQL.Add('Update CK_BanCP_KC set KGQty=B.MJMaoZ from CK_BanCP_KC A');
              SQL.Add('INNER JOIN WFB_MJJY B ON B.MJID=A.MJID ');
              SQL.Add('WHERE A.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) + '''');

              SQL.Add('Update CK_BanCP_CR set KGQty=B.MJMaoZ,Qty=B.MJLen from CK_BanCP_CR A');
              SQL.Add('INNER JOIN WFB_MJJY B ON B.MJID=A.MJID ');
              SQL.Add('WHERE A.MJID=''' + Trim(Order_Main.fieldbyname('MJID').AsString) + '''');

              SQL.Add('Update CK_BanCP_KC set KGQty=B.MJMaoZ,Qty=B.MJLen from CK_BanCP_KC A');
              SQL.Add('INNER JOIN WFB_MJJY B ON B.MJID=A.MJID ');
              SQL.Add('WHERE A.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 TfrmJYOrderCDList.ToolButton3Click(Sender: TObject);
begin
  Panel2.Left := (self.Width - Panel2.Width) div 2;
  Panel2.Visible := true;
end;

procedure TfrmJYOrderCDList.MJIDKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    if Length(MJID.Text) < 4 then
      Exit;
    CurrentPage := 1;
    InitGrid();
  end;
end;

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

procedure TfrmJYOrderCDList.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) + '''');
            sql.Add('Update CK_BanCP_CR Set QtyUnit=''' + trim(ComboBox5.Text) + ''' ');
            sql.Add('where MJID=''' + Trim(Order_Main.fieldbyname('MJID').AsString) + '''');
            sql.Add('Update CK_BanCP_KC Set kcQtyUnit=''' + 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 TfrmJYOrderCDList.btnPLXGClick(Sender: TObject);
begin
  Panel5.Visible := true;
end;

procedure TfrmJYOrderCDList.BTLPClick(Sender: TObject);
begin
  if CurrentPage > 1 then
    CurrentPage := CurrentPage - 1;
  InitGrid();
end;

procedure TfrmJYOrderCDList.BTNPClick(Sender: TObject);
begin
  if CurrentPage < Order_Main.FieldByName('TotalCount').AsInteger / RecordsNumber then
    CurrentPage := CurrentPage + 1;
  InitGrid();
end;

procedure TfrmJYOrderCDList.TCBNORChange(Sender: TObject);
begin
  RecordsNumber := StrToInt(TCBNOR.Text);
  CurrentPage := 1;
  InitGrid();
end;

procedure TfrmJYOrderCDList.ToolButton8Click(Sender: TObject);
var
  SRKOrdID, strsql: string;
begin
  if cxTabControl1.TabIndex <> 0 then
    exit;
  ToolButton8.Enabled := false;
  ExportFtErpFile('仓库码单.rmf', ADOQueryTemp);
  if Order_Main.IsEmpty then
  begin
    ToolButton8.Enabled := True;
    Exit;
  end;

  if Order_Main.Locate('SSel', True, []) = False then
  begin
    ToolButton8.Enabled := True;
    Exit;
  end;
  if Application.MessageBox('确定要打印仓库码单么。', '提示', 32 + 4) <> IDYES then
  begin
    ToolButton8.Enabled := True;
    Exit;
  end;
  if GetLSNo(ADOQueryTemp, SRKOrdID, 'RK', 'CK_BanCP_CR', 4, 1) = False then
  begin
    Application.MessageBox('生成流水号异常！', '提示', 0);
    ToolButton8.Enabled := True;
    Exit;
  end;
  try
    Order_Main.DisableControls;
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete TbForBatch where DName=' + quotedstr(Trim(DName)));
      SQL.Add('and MainType=' + quotedstr('仓库打码'));
      ExecSQL;
    end;
    with Order_Main do
    begin
      First;
      while not Eof do
      begin
        if Order_Main.FieldByName('SSel').AsBoolean then
        begin
          strsql := '卷ID：' + trim(Order_Main.FieldByName('MJID').AsString) + '原入库单号：' + trim(Order_Main.FieldByName('RKOrdID').AsString) + '新入库单号：' + trim(SRKOrdID);
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
            sql.Add(' ' + quotedstr(trim(DName)));
            sql.Add(',getdate() ');
            sql.Add(',' + quotedstr(trim(self.Caption)));
            sql.Add(',' + quotedstr(trim('仓库打码')));
            sql.Add(',' + quotedstr(trim(strsql)));
            sql.Add(',' + quotedstr(trim('成功')));
            sql.Add(')');
            ExecSQL;
          end;

          with Self.ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add(' insert into TbForBatch(DName,MainType,Value1,MJID) ');
            sql.Add(' values( ' + quotedstr(Trim(DName)) + ',' + quotedstr('仓库打码') + ',' + quotedstr(Trim(SRKOrdID)) + ',' + quotedstr(Trim(Self.Order_Main.FieldByName('MJID').AsString)) + ')');
            ExecSQL;
          end;
        end;
        Next;
      end;
    end;

    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select  count(distinct MainId) DDSL from WFB_MJJY A   ');
      sql.Add(' where MJID in (select MJID from TbForBatch X where X.MJID=A.MJID and X.MainType=''仓库打码'' and X.DName=' + quotedstr(trim(DName)) + ' )');
      Open;
    end;
    if ADOQueryTemp.FieldByName('DDSL').AsInteger > 1 then
    begin
      Application.MessageBox('不能选择多个订单!', '提示', 0);
      Exit;
    end;

    with Self.ADOQueryCmd do
    begin
      Close;
      sql.Clear;

      sql.Add('UPDATE CK_BanCP_CR Set  ');
      sql.add('RKOrdID=A.Value1  ');
      sql.Add(',baono=(select baono from wfb_mjjy e where e.mjid= CK_BanCP_CR.MJID )');
      sql.Add(',baoid=(select baoid from wfb_mjjy e where e.mjid= CK_BanCP_CR.MJID )');
      sql.Add('FROM TbForBatch A where CK_BanCP_CR.MJID=A.MJID  ');
      SQL.Add('and A.MainType=''仓库打码'' and A.DName=' + quotedstr(trim(DName)));
      sql.Add('and CK_BanCP_CR.CRFlag in (''待入库'',''待出库'')  ');

      sql.Add('UPDATE CK_BanCP_CR Set  ');
      sql.add(' CRTime=getdate(),CRType=''检验入库'',CRFlag=''入库''  ');
      sql.Add('FROM TbForBatch A where CK_BanCP_CR.MJID=A.MJID  ');
      SQL.Add('and A.MainType=''仓库打码'' and A.DName=' + quotedstr(trim(DName)));
      sql.Add('and CK_BanCP_CR.CRFlag=''待入库''  ');

      sql.Add('UPDATE WFB_MJJY Set  ');
      sql.add('RKOrdID=A.Value1 ,MJStr2=''已入库'' ');
      sql.Add('FROM TbForBatch A where WFB_MJJY.MJID=A.MJID  ');
      SQL.Add('and A.MainType=''仓库打码'' and A.DName=' + quotedstr(trim(DName)));
      SQL.Add('and WFB_MJJY.MJStr2=''未入库'' ');
      ExecSQL;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Order_Main.EnableControls;
    if Application.MessageBox('入库完成是否打印码单！！', '提示', 32 + 4) = IDYES then
    begin
      PrintCKMDG(Trim(SRKOrdID));
    end;
    TBRafresh.Click;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Order_Main.EnableControls;
    ToolButton8.Enabled := true;
    application.MessageBox('数据保存失败！', '提示信息', 0);
  end;
  ToolButton8.Enabled := true;
end;

procedure TfrmJYOrderCDList.Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
begin
  Clipboard.SetTextBuf(PChar(Trim(Order_Main.fieldbyname(TV1.Controller.FocusedColumn.DataBinding.FilterFieldName).AsString)));
end;

procedure TfrmJYOrderCDList.conNOKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    CurrentPage := 1;
    InitGrid();
  end;
end;

procedure TfrmJYOrderCDList.MJStr2Change(Sender: TObject);
begin
  CurrentPage := 1;
  InitGrid();
end;

procedure TfrmJYOrderCDList.MJTypeChange(Sender: TObject);
begin
  CurrentPage := 1;
  InitGrid();
end;

procedure TfrmJYOrderCDList.KHConNOKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    CurrentPage := 1;
    InitGrid();
  end;
end;

procedure TfrmJYOrderCDList.RKOrdIDKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    CurrentPage := 1;
    InitGrid();
  end;
end;

procedure TfrmJYOrderCDList.N3Click(Sender: TObject);
var
  SSubId, SGangNo: string;
begin

  with Order_Main do
  begin
    SSubId := trim(FieldByName('SubId').AsString);
    SGangNo := trim(FieldByName('Mjstr4').AsString);
    Order_Main.DisableControls;
    first;
    while not eof do
    begin
      if ((SSubId = trim(FieldByName('SubId').AsString)) and (SGangNo = trim(FieldByName('Mjstr4').AsString))) then
      begin
        edit;
        FieldByName('SSel').value := true;
        Post;
      end
      else
      begin
        edit;
        FieldByName('SSel').value := false;
        Post;
      end;
      Next;
    end;
    Order_Main.Locate('SubId;Mjstr4', VarArrayOf([SSubId, SGangNo]), []);
    Order_Main.EnableControls;
  end;
end;

procedure TfrmJYOrderCDList.ToolButton4Click(Sender: TObject);
begin
  if Trim(Order_Main.fieldbyname('RKOrdID').AsString) = '' then
    exit;
  PrintCKMDG(Trim(Order_Main.fieldbyname('RKOrdID').AsString));
end;

procedure TfrmJYOrderCDList.X1Click(Sender: TObject);
var
  str, SSubId, SGangNo: string;
  ZChiShu, DQChiShu: integer;
  ISSel: boolean;
begin
  ISSel := true;
  SSubId := trim(Order_Main.FieldByName('SubId').AsString);
  SGangNo := trim(Order_Main.FieldByName('Mjstr4').AsString);
  str := '';
  if InputQuery('选择', '请输入数字', str) then
  begin
    ZChiShu := strtointdef(str, 0);
    if ZChiShu <= 0 then
      exit;

    with Order_Main do
    begin

      Order_Main.DisableControls;
      first;
      DQChiShu := 0;
      while not eof do
      begin

        if ((SSubId = trim(FieldByName('SubId').AsString)) and (SGangNo = trim(FieldByName('Mjstr4').AsString))) then
        begin
          edit;
          FieldByName('SSel').value := ISSel;
          DQChiShu := DQChiShu + 1;
          Post;
        end
        else
        begin
          edit;
          FieldByName('SSel').value := false;
          Post;
        end;
        if DQChiShu = ZChiShu then
          ISSel := false;
        Next;
      end;
      Order_Main.Locate('SubId;Mjstr4', VarArrayOf([SSubId, SGangNo]), []);
      Order_Main.EnableControls;
    end;
  end;

end;

procedure TfrmJYOrderCDList.cxTabControl1Change(Sender: TObject);
begin
  CurrentPage := 1;
  InitGrid();
  SetStatus();
end;

procedure TfrmJYOrderCDList.B1Click(Sender: TObject);
begin
  frmSysLogHelp := TfrmSysLogHelp.create(self);
  with frmSysLogHelp do
  begin
    fModel := self.caption;
  //  facction:='生产指示单删除';
    showmodal;
    free;
  end;
end;

procedure TfrmJYOrderCDList.ToolButton2Click(Sender: TObject);
var
  fPrintFile, FMainID, LBName: string;
begin
  if Order_Main.IsEmpty then
    Exit;

  if Order_Main.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据', '提示', 0);
    Exit;
  end;
  ExportFtErpFile('检验报告.rmf', ADOQueryTemp);
  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\检验报告.rmf';

  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('delete TBSubID where DName=''' + Trim(DCode) + '''');
    ExecSQL;
  end;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('SELECT * FROM TBSubID where 1=2 ');
    open;
  end;
  FMainID := '';
  Order_Main.DisableControls;
  try
    ADOQueryCmd.Connection.BeginTrans;
    with Order_Main do
    begin
      First;
      while not Eof do
      begin
        if Fieldbyname('Ssel').AsBoolean then
        begin
          if FMainID = '' then
          begin
            FMainID := Trim(Order_Main.fieldbyname('APID').AsString);
          end
          else
          begin
//          IF Trim(Order_Main.fieldbyname('APID').AsString)<>FMainID then
//          begin
//            application.MessageBox('选择的不是同一个检验指示单，不能一起打印！','提示信息',0);
//            ADOQueryCmd.Connection.RollbackTrans;
//            EnableControls;
//            exit;
//          end;
          end;
          ADOQueryCmd.append;
          ADOQueryCmd.fieldbyname('SubId').Value := Trim(Order_Main.fieldbyname('MJID').AsString);
          ADOQueryCmd.fieldbyname('Dname').Value := Trim(DCode);
          ADOQueryCmd.post;
        end;
        Next;
      end;
    end;
    ADOQueryCmd.Connection.CommitTrans;
  except
    ADOQueryCmd.Connection.RollbackTrans;
  end;
  Order_Main.EnableControls;

  with ADOQueryPrint do
  begin
    Close;
    sql.Clear;
    sql.add('exec P_Do_Print_JYBB ');
    sql.add(' @DName=' + quotedstr(Trim(DCode)));
//    ShowMessage(SQL.Text);
    Open;
  end;

  if FileExists(fPrintFile) then
  begin
    RM2.LoadFromFile(fPrintFile);
    RM2.ShowReport;
  end
  else
  begin
    Application.MessageBox(PChar('没有找' + trim(fPrintFile)), '提示信息', 0);
    exit;
  end;
end;

procedure TfrmJYOrderCDList.v1Column22PropertiesChange(Sender: TObject);
begin
  JsNum();
end;

procedure TfrmJYOrderCDList.Tv1CustomDrawIndicatorCell(Sender: TcxGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxCustomGridIndicatorItemViewInfo; var ADone: Boolean);
var
  FValue: string;
  FBounds: TRect;
begin
  FBounds := AViewInfo.Bounds;
  if (AViewInfo is TcxGridIndicatorRowItemViewInfo) then
  begin
    ACanvas.FillRect(FBounds);
    ACanvas.DrawComplexFrame(FBounds, clBtnHighlight, clBtnShadow, [bBottom, bLeft, bRight], 1);
    FValue := IntToStr(TcxGridIndicatorRowItemViewInfo(AViewInfo).GridRecord.Index + 1);
    InflateRect(FBounds, -1, -1);    //Platform   specific.   May   not   work   on   Linux.
    ACanvas.Font.Color := clBlack;
    ACanvas.Brush.Style := bsClear;
    ACanvas.DrawText(FValue, FBounds, cxAlignCenter or cxAlignTop);
    ADone := True;
  end;
end;

procedure TfrmJYOrderCDList.btnHYClick(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

    while Order_Main.Locate('ssel', True, []) do
    begin

      with ADOQueryCmd do
      begin
        Close;
        sql.Clear;

        sql.Add('insert into WFB_MJJY  select * from ZDel_WFB_MJJY where MJID=''' + Trim(Order_Main.fieldbyname('MJID').AsString) + '''');
        sql.Add('insert into CK_BanCP_CR  select * from  ZDel_CK_BanCP_CR where MJID=''' + Trim(Order_Main.fieldbyname('MJID').AsString) + '''');
        sql.Add('insert into CK_BanCP_KC  select * from  ZDel_CK_BanCP_KC where MJID=''' + Trim(Order_Main.fieldbyname('MJID').AsString) + '''');
        sql.Add('insert into WFB_MJJY_CD  select * from  ZDel_WFB_MJJY_CD where MJID=''' + Trim(Order_Main.fieldbyname('MJID').AsString) + '''');

        sql.Add('delete ZDel_WFB_MJJY where MJID=''' + Trim(Order_Main.fieldbyname('MJID').AsString) + '''');
        sql.Add('delete ZDel_CK_BanCP_CR where MJID=''' + Trim(Order_Main.fieldbyname('MJID').AsString) + '''');
        sql.Add('delete ZDel_CK_BanCP_KC where MJID=''' + Trim(Order_Main.fieldbyname('MJID').AsString) + '''');
        sql.Add('delete ZDel_WFB_MJJY_CD where MJID=''' + Trim(Order_Main.fieldbyname('MJID').AsString) + '''');
            //更新开卡
        sql.Add('exec P_UPdate_LCKJY @APID=''' + trim(Order_Main.fieldbyname('APID').AsString) + '''');

        sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
        sql.Add(' ' + quotedstr(trim(DName)));
        sql.Add(',getdate() ');
        sql.Add(',' + quotedstr(trim(self.Caption)));
        sql.Add(',' + quotedstr(trim('还原检验数据')));
        sql.Add(',' + quotedstr('卷条码：' + trim(Order_Main.fieldbyname('MJID').AsString) + ' 卷号：' + trim(Order_Main.fieldbyname('MJXH').AsString) + ' 卡号：' + trim(Order_Main.fieldbyname('apid').AsString)));
        sql.Add(',' + quotedstr(trim('成功')));
        sql.Add(')');
        ExecSQL;
      end;

      Order_Main.Delete;

    end;
  end;
  Order_Main.EnableControls;
end;

procedure TfrmJYOrderCDList.edtkuanghaoBtnClick(Sender: TObject);
begin
  try
    frmZdyMapSel2 := TfrmZdyMapSel2.Create(self);
    with frmZdyMapSel2 do
    begin
      FlagStr := 'KuangHao';

      if ShowModal = 1 then
      begin
        self.edtkuanghao.Text := frmZdyMapSel2.FSDPerson;
      end;
    end;
  finally
    frmZdyMapSel2.Free;
  end;
end;

procedure TfrmJYOrderCDList.Button3Click(Sender: TObject);
var
  strsql: string;
begin
  if Order_Main.IsEmpty then
    Exit;
  if Order_Main.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;
  if trim(edtkuanghao.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
          strsql := '卷ID：' + trim(Order_Main.FieldByName('MJID').AsString) + '原入框号：' + trim(Order_Main.FieldByName('kuanghao').AsString) + '新框号：' + trim(edtkuanghao.Text);
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
            sql.Add(' ' + quotedstr(trim(DName)));
            sql.Add(',getdate() ');
            sql.Add(',' + quotedstr(trim(self.Caption)));
            sql.Add(',' + quotedstr(trim('仓库打码')));
            sql.Add(',' + quotedstr(trim(strsql)));
            sql.Add(',' + quotedstr(trim('成功')));
            sql.Add(')');
            ExecSQL;
          end;

          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('Update WFB_MJJY Set kuanghao=''' + trim(edtkuanghao.Text) + ''' ');
            sql.Add('where MJID=''' + Trim(Order_Main.fieldbyname('MJID').AsString) + '''');
            sql.Add('Update CK_BanCP_CR Set kuanghao=''' + trim(edtkuanghao.Text) + ''' ');
            sql.Add('where MJID=''' + Trim(Order_Main.fieldbyname('MJID').AsString) + '''');
            sql.Add('Update CK_BanCP_KC Set kuanghao=''' + trim(edtkuanghao.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 TfrmJYOrderCDList.Button4Click(Sender: TObject);
var
  strsql: string;
begin
  if Order_Main.IsEmpty then
    Exit;
  if Order_Main.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;
  if trim(cxCurrencyEdit3.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
          strsql := '卷ID：' + trim(Order_Main.FieldByName('MJID').AsString) + '原缸号：' + trim(Order_Main.FieldByName('mjstr4').AsString) + '新缸号：' + trim(cxCurrencyEdit3.Text);
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
            sql.Add(' ' + quotedstr(trim(DName)));
            sql.Add(',getdate() ');
            sql.Add(',' + quotedstr(trim(self.Caption)));
            sql.Add(',' + quotedstr(trim('仓库打码')));
            sql.Add(',' + quotedstr(trim(strsql)));
            sql.Add(',' + quotedstr(trim('成功')));
            sql.Add(')');
            ExecSQL;
          end;

          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('Update WFB_MJJY Set mjstr4=''' + trim(cxCurrencyEdit3.Text) + ''' ');
            sql.Add('where MJID=''' + Trim(Order_Main.fieldbyname('MJID').AsString) + '''');
            sql.Add('Update CK_BanCP_CR Set ganghao=''' + trim(cxCurrencyEdit3.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 TfrmJYOrderCDList.ToolButton5Click(Sender: TObject);
var
  fPrintFile: string;
  Txt, fImagePath: string;
  Moudle: THandle;
  Makebar: TMakebar;
  Mixtext: TMixtext;
  i: Integer;
  wsql: string;
begin
  if Order_Main.IsEmpty then
    Exit;
  if Order_Main.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;
  with Order_Main do
  begin
    wsql := ' ';
    First;
    while not Eof do
    begin
      if (Order_Main.fieldbyname('SSEL').AsBoolean) and (Order_Main.fieldbyname('baoid').AsString <> '') then
      begin
        if wsql = ' ' then
          wsql := wsql + quotedstr(trim(Trim(Order_Main.fieldbyname('mjid').AsString)))
        else
          wsql := wsql + ',' + quotedstr(trim(Trim(Order_Main.fieldbyname('mjid').AsString)));

      end;
      Next;

      Order_Main.EnableControls;
    end;
    wsql := '(' + wsql + ')';
  end;

  with ADOQuery1 do
  begin
    Close;
    sql.Clear;
    sql.Add('SELECT distinct BAOID FROM wfb_mjjy where mjid in ' + (Trim(wsql)));
    open;
  end;

  with ADOQuery1 do
  begin
    First;
    while not Eof do
    begin
      if (ADOQuery1.fieldbyname('BAOID').AsString <> '') then
      begin

        with ADOQueryPrint do
        begin
          Close;
          SQL.Clear;
          sql.Add('exec P_Do_PrintDaBao ' + quotedstr(Trim(ADOQuery1.fieldbyname('BAOID').AsString)));
//          ShowMessage(sql.Text);
          Open;
        end;
        if ADOQueryPrint.IsEmpty = True then
          Exit;

        try
          Moudle := LoadLibrary('MakeQRBarcode.dll');
          @Makebar := GetProcAddress(Moudle, 'Make');
          @Mixtext := GetProcAddress(Moudle, 'MixText');
          Txt := trim(ADOQuery1.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 Trim(ADOQueryPrint.fieldbyname('NLBName').AsString) <> '' then
        begin
          ExportFtErpFile(Trim(ADOQueryPrint.fieldbyname('NLbName').AsString) + '.rmf', ADOQueryTemp);
          fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\' + Trim(ADOQueryPrint.fieldbyname('NLbName').AsString) + '.rmf'
        end
        else
          fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\包标签.rmf';
        if not FileExists(fPrintFile) then
        begin
          Application.MessageBox(PChar('没有找' + fPrintFile), '提示', 0);
          Order_Main.EnableControls;
          Exit;
        end;

        if FileExists(fPrintFile) then
        begin
          RMVariables['QRBARCODE'] := fImagePath;
          RM2.LoadFromFile(fPrintFile);
          RM2.DefaultCopies := StrToIntDef(ComboBox1.Text, 1);
          RM2.PrintReportL(ComboBox2.Text);
        end;
      end;
      Next;
    end;
  end;
  Order_Main.EnableControls;
end;

procedure TfrmJYOrderCDList.ToolButton6Click(Sender: TObject);
var
  lvData: UTF8String; // 使用UTF8编码的字符串
  lvBitMap: TBitmap;
  lvSymbol: PZintSymbol;
  lvErrorNumber: Integer;
  lvErrorText: string;
  bitmap: TBitmap;
begin
  lvSymbol := ZBarcode_Create();
  if lvSymbol = nil then
    Exit;
  lvBitMap := TBitmap.Create;
  try               //'010872020901234590RS9999-100R1011234567893112005160'
    lvData := UTF8String(FKHEWM);
    // 条码类型设置为QRCODE
    lvSymbol.symbology := BARCODE_QRCODE;
//    lvSymbol.option_2 := 1;
   //Data Matrix （ISO 16022）(and HIBC)
    // 编码
    lvErrorNumber := ZBarcode_Encode_and_Buffer(lvSymbol, PAnsiChar(lvData), Length(lvData), 0);
    // 编码成功
    if lvErrorNumber = 0 then
    begin
      // 生成Bitmap图形
      ZBarcode_To_Bitmap(lvSymbol, lvBitMap);
      // 显示在Image中
      cxImage1.Picture.Bitmap.Width := 80;
      cxImage1.Picture.Bitmap.Height := 80;
      cxImage1.Picture.Bitmap.Canvas.Brush.Color := clWhite;
      cxImage1.Picture.Bitmap.Canvas.FillRect(Rect(0, 0, cxImage1.Width, cxImage1.Height));
      cxImage1.Picture.Bitmap.Canvas.StretchDraw(Rect(10, 10, cxImage1.Width - 10, cxImage1.Height - 10), lvBitMap);

    end
    else
    begin
      cxImage1.Picture.Bitmap.Width := cxImage1.Width;
      cxImage1.Picture.Bitmap.Height := cxImage1.Height;
      cxImage1.Picture.Bitmap.Canvas.Brush.Color := clWhite;
      cxImage1.Picture.Bitmap.Canvas.FillRect(Rect(0, 0, cxImage1.Width, cxImage1.Height));
      lvErrorText := string(AnsiString(lvSymbol.errtxt));
      ShowMessage('编码时发生错误：' + lvErrorText);
    end;
  finally
    lvBitMap.Free;
    lvBitMap := nil;
    ZBarcode_Delete(lvSymbol);
  end;
  bitmap := TBitmap.Create;
  try
    bitmap.Assign(cxImage1.Picture.Bitmap);
    bitmap.SaveToFile(ExtractFilePath(Application.ExeName) + 'image\temp4.bmp');
  finally
    bitmap.Free;
  end;
end;

procedure TfrmJYOrderCDList.Button7Click(Sender: TObject);
var
  strsql: string;
begin
  if Order_Main.IsEmpty then
    Exit;
  if Order_Main.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;
//  if trim(edit2.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
          strsql := '卷ID：' + trim(Order_Main.FieldByName('MJID').AsString) + '原备注：' + trim(Order_Main.FieldByName('MXNOTE').AsString) + '新备注：' + trim(edit2.Text);
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
            sql.Add(' ' + quotedstr(trim(DName)));
            sql.Add(',getdate() ');
            sql.Add(',' + quotedstr(trim(self.Caption)));
            sql.Add(',' + quotedstr(trim('仓库打码')));
            sql.Add(',' + quotedstr(trim(strsql)));
            sql.Add(',' + quotedstr(trim('成功')));
            sql.Add(')');
            ExecSQL;
          end;

          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('Update WFB_MJJY Set mxnote=''' + trim(edit2.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;

end.

