unit U_ZGJBMX;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxGraphics, cxCustomData, cxStyles, cxTL, cxMaskEdit, DB, ADODB,
  cxInplaceContainer, cxDBTL, cxControls, cxTLData, ComCtrls, ToolWin, StdCtrls,
  cxFilter, cxData, cxDataStorage, cxEdit, cxDBData, DBClient,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, ExtCtrls,
  cxSplitter, cxGridLevel, cxClasses, cxGridCustomView, cxGrid,
  cxGridCustomPopupMenu, cxGridPopupMenu, RM_Dataset, RM_System, RM_Common,
  RM_Class, RM_GridReport, IdBaseComponent, IdComponent, IdTCPConnection,
  IdTCPClient, IdFTP, ShellAPI, IniFiles, cxCheckBox, cxCalendar, cxButtonEdit,
  cxTextEdit, cxDBLookupComboBox, cxContainer, cxDropDownEdit, cxPC, Menus,
  TeEngine, Series, TeeProcs, Chart, DbChart, GanttCh, cxLookAndFeels,
  cxLookAndFeelPainters, cxNavigator, cxGridBandedTableView,
  cxGridDBBandedTableView, cxButtons, dxSkinsCore, 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, dxSkinsDefaultPainters, dxSkinValentine,
  dxSkinVS2010, dxSkinWhiteprint, dxSkinXmas2008Blue, dxSkinscxPCPainter;

type
  TfrmZGJBMX = class(TForm)
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    cxGridPopupMenu2: TcxGridPopupMenu;
    Panel2: TPanel;
    Panel3: TPanel;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v2Column12: TcxGridDBColumn;
    v2Column7: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    SH1: TPanel;
    ClientDataSet1: TClientDataSet;
    DataSource1: TDataSource;
    DataSource2: TDataSource;
    ClientDataSet2: TClientDataSet;
    v1Column4: TcxGridDBColumn;
    cxGrid0: TcxGrid;
    Tv0: TcxGridDBTableView;
    cxGridDBColumn7: TcxGridDBColumn;
    cxGridDBColumn8: TcxGridDBColumn;
    cxGridDBColumn9: TcxGridDBColumn;
    cxGridDBColumn10: TcxGridDBColumn;
    cxGridDBColumn11: TcxGridDBColumn;
    cxGridDBColumn12: TcxGridDBColumn;
    cxGridLevel3: TcxGridLevel;
    Tv0Column1: TcxGridDBColumn;
    Tv0Column2: TcxGridDBColumn;
    Tv0Column3: TcxGridDBColumn;
    Tv0Column4: TcxGridDBColumn;
    Tv0Column5: TcxGridDBColumn;
    cxGrid2: TcxGrid;
    cxGridLevel2: TcxGridLevel;
    Tv2: TcxGridDBBandedTableView;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    Tv2Column1: TcxGridDBBandedColumn;
    Tv2Column2: TcxGridDBBandedColumn;
    Tv2Column3: TcxGridDBBandedColumn;
    Tv2Column4: TcxGridDBBandedColumn;
    Tv2Column5: TcxGridDBBandedColumn;
    Tv2Column6: TcxGridDBBandedColumn;
    Tv2Column7: TcxGridDBBandedColumn;
    Tv2Column8: TcxGridDBBandedColumn;
    Tv2Column9: TcxGridDBBandedColumn;
    Tv2Column10: TcxGridDBBandedColumn;
    Tv2Column11: TcxGridDBBandedColumn;
    Tv2Column12: TcxGridDBBandedColumn;
    Tv2Column13: TcxGridDBBandedColumn;
    Tv2Column14: TcxGridDBBandedColumn;
    Tv2Column15: TcxGridDBBandedColumn;
    Tv2Column16: TcxGridDBBandedColumn;
    Tv2Column17: TcxGridDBBandedColumn;
    Tv2Column18: TcxGridDBBandedColumn;
    Tv0Column6: TcxGridDBColumn;
    Tv0Column7: TcxGridDBColumn;
    Tv0Column8: TcxGridDBColumn;
    Tv0Column9: TcxGridDBColumn;
    Tv0Column10: TcxGridDBColumn;
    DataSource0: TDataSource;
    ClientDataSet0: TClientDataSet;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    Panel1: TPanel;
    DataSource3: TDataSource;
    ClientDataSet3: TClientDataSet;
    RM2: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    ADOQueryPrint: TADOQuery;
    Panel4: TPanel;
    ClientDataSet5: TClientDataSet;
    RichEdit1: TRichEdit;
    Tv2Column19: TcxGridDBBandedColumn;
    Tv2Column20: TcxGridDBBandedColumn;
    Tv2Column21: TcxGridDBBandedColumn;
    Tv2Column22: TcxGridDBBandedColumn;
    Panel5: TPanel;
    Tv0Column11: TcxGridDBColumn;
    Tv0Column12: TcxGridDBColumn;
    Tv0Column13: TcxGridDBColumn;
    Tv0Column14: TcxGridDBColumn;
    Tv0Column15: TcxGridDBColumn;
    Label1: TLabel;
    Tv2Column23: TcxGridDBBandedColumn;
    SaveGS: TcxButton;
    Tv0Column16: TcxGridDBColumn;
    Tv0Column17: TcxGridDBColumn;
    Tv0Column18: TcxGridDBColumn;
    Tv0Column19: TcxGridDBColumn;
    Tv2Column24: TcxGridDBBandedColumn;
    Tv2Column25: TcxGridDBBandedColumn;
    Panel6: TPanel;
    cxGrid3: TcxGrid;
    Tv3: TcxGridDBTableView;
    Tv3Column2: TcxGridDBColumn;
    Tv3Column3: TcxGridDBColumn;
    Tv3Column4: TcxGridDBColumn;
    Tv3Column5: TcxGridDBColumn;
    Tv3Column6: TcxGridDBColumn;
    Tv3Column7: TcxGridDBColumn;
    Tv3Column8: TcxGridDBColumn;
    Tv3Column9: TcxGridDBColumn;
    Tv3Column10: TcxGridDBColumn;
    Tv3Column11: TcxGridDBColumn;
    Tv3Column12: TcxGridDBColumn;
    Tv3Column13: TcxGridDBColumn;
    Tv3Column14: TcxGridDBColumn;
    Tv3Column15: TcxGridDBColumn;
    Tv3Column16: TcxGridDBColumn;
    Tv3Column17: TcxGridDBColumn;
    Tv3Column18: TcxGridDBColumn;
    Tv3Column19: TcxGridDBColumn;
    Tv3Column20: TcxGridDBColumn;
    Tv3Column21: TcxGridDBColumn;
    Tv3Column22: TcxGridDBColumn;
    Tv3Column23: TcxGridDBColumn;
    Tv3Column24: TcxGridDBColumn;
    Tv3Column25: TcxGridDBColumn;
    Tv3Column26: TcxGridDBColumn;
    Tv3Column27: TcxGridDBColumn;
    Tv3Column28: TcxGridDBColumn;
    Tv3Column29: TcxGridDBColumn;
    Tv3Column30: TcxGridDBColumn;
    Tv3Column31: TcxGridDBColumn;
    Tv3Column32: TcxGridDBColumn;
    Tv3Column33: TcxGridDBColumn;
    Tv3Column34: TcxGridDBColumn;
    Tv3Column35: TcxGridDBColumn;
    Tv3Column36: TcxGridDBColumn;
    Tv3Column37: TcxGridDBColumn;
    Tv3Column38: TcxGridDBColumn;
    Tv3Column39: TcxGridDBColumn;
    Tv3Column40: TcxGridDBColumn;
    Tv3Column41: TcxGridDBColumn;
    Tv3Column42: TcxGridDBColumn;
    Tv3Column43: TcxGridDBColumn;
    Tv3Column44: TcxGridDBColumn;
    Tv3Column45: TcxGridDBColumn;
    Tv3Column46: TcxGridDBColumn;
    Tv3Column47: TcxGridDBColumn;
    Tv3Column48: TcxGridDBColumn;
    Tv3Column49: TcxGridDBColumn;
    Tv3Column50: TcxGridDBColumn;
    Tv3Column51: TcxGridDBColumn;
    cxGridLevel4: TcxGridLevel;
    cxGrid5: TcxGrid;
    Tv5: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridLevel5: TcxGridLevel;
    Tv3Column1: TcxGridDBColumn;
    Tv3Column52: TcxGridDBColumn;
    Tv3Column53: TcxGridDBColumn;
    Tv3Column54: TcxGridDBColumn;
    Tv3Column55: TcxGridDBColumn;
    Tv3Column56: TcxGridDBColumn;
    Tv3Column57: TcxGridDBColumn;
    Tv3Column58: TcxGridDBColumn;
    Tv3Column59: TcxGridDBColumn;
    Tv3Column60: TcxGridDBColumn;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure Tv2CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
    procedure Panel4DblClick(Sender: TObject);
    procedure Tv2CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
    procedure Tv2Column21CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
    procedure cxGridDBColumn7HeaderClick(Sender: TObject);
    procedure Tv0CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
    procedure cxGridDBColumn9HeaderClick(Sender: TObject);
    procedure SH1DblClick(Sender: TObject);
    procedure Label1Click(Sender: TObject);
    procedure SaveGSClick(Sender: TObject);
    procedure Tv2Column9CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
    procedure Tv2Column23CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
    procedure Tv2Column4CompareRowValuesForCellMerging(Sender: TcxGridColumn; ARow1: TcxGridDataRow; AProperties1: TcxCustomEditProperties; const AValue1: Variant; ARow2: TcxGridDataRow; AProperties2: TcxCustomEditProperties; const AValue2: Variant; var AAreEqual: Boolean);
    procedure Tv2Column5CompareRowValuesForCellMerging(Sender: TcxGridColumn; ARow1: TcxGridDataRow; AProperties1: TcxCustomEditProperties; const AValue1: Variant; ARow2: TcxGridDataRow; AProperties2: TcxCustomEditProperties; const AValue2: Variant; var AAreEqual: Boolean);
    procedure Tv2Column2CompareRowValuesForCellMerging(Sender: TcxGridColumn; ARow1: TcxGridDataRow; AProperties1: TcxCustomEditProperties; const AValue1: Variant; ARow2: TcxGridDataRow; AProperties2: TcxCustomEditProperties; const AValue2: Variant; var AAreEqual: Boolean);
    procedure Tv2Column22CompareRowValuesForCellMerging(Sender: TcxGridColumn; ARow1: TcxGridDataRow; AProperties1: TcxCustomEditProperties; const AValue1: Variant; ARow2: TcxGridDataRow; AProperties2: TcxCustomEditProperties; const AValue2: Variant; var AAreEqual: Boolean);
    procedure Tv2Column3CompareRowValuesForCellMerging(Sender: TcxGridColumn; ARow1: TcxGridDataRow; AProperties1: TcxCustomEditProperties; const AValue1: Variant; ARow2: TcxGridDataRow; AProperties2: TcxCustomEditProperties; const AValue2: Variant; var AAreEqual: Boolean);
    procedure Tv3CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
  private

    { Private declarations }
    procedure InitGrid();
  public
    FMainid, FConNo, FFlag: string;

  end;

var
  frmZGJBMX: TfrmZGJBMX;

implementation

uses
  U_DataLink, U_RTFun, U_JYDayListGang, U_Fun, U_JYOrderCDList,
  U_JYOrderCDGangList;

{$R *.dfm}

procedure TfrmZGJBMX.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      SQL.Clear;
      sql.Add('exec P_View_JD_Main :MainId');
      Parameters.ParamByName('MainId').Value := FMainid;
      Open;
    end;
    SCreateCDS20(ADOQueryMain, ClientDataSet0);
    SInitCDSData20(ADOQueryMain, ClientDataSet0);
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      SQL.Clear;
      sql.Add('exec P_View_JD_PB :OrderNO');
      Parameters.ParamByName('OrderNO').Value := FConNo;
      Open;
    end;
    SCreateCDS20(ADOQueryMain, ClientDataSet1);
    SInitCDSData20(ADOQueryMain, ClientDataSet1);
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      SQL.Clear;
      sql.Add('exec P_View_JD :MainId');
      Parameters.ParamByName('MainId').Value := FMainid;
      Open;
    end;
    SCreateCDS20(ADOQueryMain, ClientDataSet2);
    SInitCDSData20(ADOQueryMain, ClientDataSet2);
    with ADOQueryMain do                                           
    begin
      Filtered := False;
      Close;
      SQL.Clear;
      sql.Add('exec P_View_JD_HZ_Lie :MainId');
      //sql.Add('exec P_Print_CRJD_HZ :MainId');
      Parameters.ParamByName('MainId').Value := FMainid;
      Open;
    end;
    SCreateCDS20(ADOQueryMain, ClientDataSet3);
    SInitCDSData20(ADOQueryMain, ClientDataSet3);

    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      SQL.Clear;
      sql.Add('exec P_Print_CRJD_CD :MainId');
      Parameters.ParamByName('MainId').Value := FMainid;
      Open;
    end;
    SCreateCDS20(ADOQueryMain, ClientDataSet5);
    SInitCDSData20(ADOQueryMain, ClientDataSet5);
    RichEdit1.Text := Trim(ClientDataSet5.fieldbyname('HZCD').AsString);
    RichEdit1.Text := RichEdit1.Text + #13 + #13 + Trim(ClientDataSet5.fieldbyname('ZJCD1').AsString);
    RichEdit1.Text := RichEdit1.Text + #13 + #13 + Trim(ClientDataSet5.fieldbyname('ZJCD2').AsString);

  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmZGJBMX.FormClose(Sender: TObject; var Action: TCloseAction);
begin

  Action := caHide;
end;

procedure TfrmZGJBMX.FormShow(Sender: TObject);
begin
  if Trim(DName) = 'ADMIN' then
    SaveGS.Visible := True;
  ReadCxGridAll(trim(self.Caption) + '0', Tv0);
  ReadCxGridAll(trim(self.Caption) + '1', Tv1);
  ReadCxGridAll(trim(self.Caption) + '333', Tv3);
  ReadCxBandedGridAll(trim(self.Caption) + '2', Tv2);
  InitGrid();
  FFlag := '';
end;

procedure TfrmZGJBMX.FormDestroy(Sender: TObject);
begin
  frmZGJBMX := nil;
end;

procedure TfrmZGJBMX.Tv2CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
var
  fPrintFile: string;
  Txt, fImagePath: string;
  Moudle: THandle;
  Makebar: TMakebar;
  Mixtext: TMixtext;
begin
  if Tv2.Controller.FocusedColumn.Tag = 1 then
  begin
    try
      frmJYDayListGang := TfrmJYDayListGang.Create(Application);
      with frmJYDayListGang do
      begin
        FAPID := Trim(Self.ClientDataSet2.fieldbyname('APID').AsString);
        if ShowModal = 1 then
        begin

        end;
      end;
    finally
      frmJYDayListGang.Free;
    end;

  end
  else if Tv2.Controller.FocusedColumn.Tag = 2 then
  begin
    if ClientDataSet2.IsEmpty then
      Exit;
    ExportFtErpFile('三联仓库码单.rmf', ADOQueryTemp);
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select TOp 1 * from WFB_MJJY A where A.APID=''' + Trim(ClientDataSet2.fieldbyname('APID').AsString) + ''' and isnull(RKOrdID,'''')<>'''' ');
      sql.Add(' and isnull(Mjstr4,'''')=''' + Trim(ClientDataSet2.fieldbyname('Ganghao').AsString) + '''');
      open;
    end;
    with ClientDataSet2 do
    begin

      with ADOQueryPrint do
      begin
        Close;
        SQL.Clear;
        sql.Add(' exec P_Print_RKMDGangNo2 ');
        SQL.Add(' @RKOrdID=''' + Trim(ADOQueryTemp.fieldbyname('RKOrdID').AsString) + '''');
        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
  else if Tv2.Controller.FocusedColumn.Tag = 3 then
  begin
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select TOp 1 * from WFB_MJJY A where A.APID=''' + Trim(ClientDataSet2.fieldbyname('APID').AsString) + ''' and isnull(RKOrdID,'''')<>'''' ');
      sql.Add(' and isnull(Mjstr4,'''')=''' + Trim(ClientDataSet2.fieldbyname('Ganghao').AsString) + '''');
      open;
    end;

    with ADOQueryPrint do
    begin
      Close;
      SQL.Clear;
      sql.Add(' exec P_Print_RKMDGangNo_CK ');
      SQL.Add(' @RKOrdID=''' + Trim(ADOQueryTemp.fieldbyname('RKOrdID').AsString) + '''');
      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;
    ExportFtErpFile('出库码单GJ.rmf', ADOQueryTemp);
    fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\出库码单GJ.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
  else if Tv2.Controller.FocusedColumn.Tag = 4 then
  begin
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select TOp 1 * from WFB_MJJY A where A.APID=''' + Trim(ClientDataSet2.fieldbyname('APID').AsString) + ''' and isnull(RKOrdID,'''')<>'''' ');
      sql.Add(' and isnull(Mjstr4,'''')=''' + Trim(ClientDataSet2.fieldbyname('Ganghao').AsString) + '''');
      open;
    end;

    with ADOQueryPrint do
    begin
      Close;
      SQL.Clear;
      sql.Add(' exec P_Print_RKMDGangNo_KC ');
      SQL.Add(' @RKOrdID=''' + Trim(ADOQueryTemp.fieldbyname('RKOrdID').AsString) + '''');
      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;
    ExportFtErpFile('库存码单.rmf', ADOQueryTemp);
    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 TfrmZGJBMX.Panel4DblClick(Sender: TObject);
begin
  ClientDataSet2.Filtered := False;
 // ClientDataSet2.Filter:='PRTColor='''+Trim(ClientDataSet3.fieldbyname('PRTColor').AsString)+'''';
  //ClientDataSet2.Filtered:=True;
end;

procedure TfrmZGJBMX.Tv2CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
var
  Fsunhao: Double;
begin
  Fsunhao := AViewInfo.GridRecord.Values[TcxGridDBBandedTableView(Sender).GetColumnByFieldName('PCBFB').Index];
  //if VarToStr(Fsunhao)='' then Exit;

  {if Fsunhao >=15 then
    ACanvas.Brush.Color := $4763FF
  else
  if (Fsunhao >=10) and (Fsunhao <15) then
  begin
    ACanvas.Brush.Color := $00FFFF
  end
  else
  begin

  end;  }

end;

procedure TfrmZGJBMX.Tv2Column21CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
var
  id: Integer;
  Fsunhao10: string;
  Fsunhao: Double;
begin

  id := TV2.GetColumnByFieldName('PCBFB').Index;

  if id < 0 then
    Exit;

  if AViewInfo.GridRecord.Values[id] = null then
    Exit;

  Fsunhao10 := AViewInfo.GridRecord.Values[id];

  Fsunhao := StrToInt(Fsunhao10);
  if Fsunhao >= 15 then
    ACanvas.Brush.Color := $4763FF
  else if (Fsunhao >= 10) and (Fsunhao < 15) then
  begin
    ACanvas.Brush.Color := $00FFFF
  end
  else
  begin

  end;
end;

procedure TfrmZGJBMX.cxGridDBColumn7HeaderClick(Sender: TObject);
var
  fPrintFile: string;
  EngMoney: string;
  FEWMID, Txt, fImagePath: string;
  Moudle: THandle;
  Makebar: TMakebar;
  Mixtext: TMixtext;
begin
  if ClientDataSet0.IsEmpty then
    Exit;
  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\总染整计划单.rmf';
  Panel5.Visible := True;
  Panel5.Refresh;
  ExportFtErpFile('总染整计划单.rmf', ADOQueryPrint);
  with ADOQueryPrint do
  begin
    Close;
    sql.Clear;
    sql.Add('select A.*,B.*  ');
    sql.Add(',OrderDetail=(select Top 1 OrderDetail  from PBOrder_Main B where B.OrderNo=A.ConNo and B.Valid=''Y'')');
    sql.Add(' from SalesContract_Main A inner join SalesContract_Sub B on A.MainId=B.MainId ');
    sql.Add(' where A.Conno=''' + Trim(ClientDataSet0.fieldbyname('Conno').AsString) + '''');
    sql.Add(' order by B.XHNo ');
    Open;
  end;

  FEWMID := Trim(ADOQueryPrint.fieldbyname('Mainid').AsString);

  try
    Moudle := LoadLibrary('MakeQRBarcode.dll');
    @Makebar := GetProcAddress(Moudle, 'Make');
    @Mixtext := GetProcAddress(Moudle, 'MixText');
    Txt := Trim(FEWMID);
    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 FileExists(fPrintFile) then
  begin
//    RMVariables['EngMoney']:=EngMoney;
    //RMVariables['enddate']:=enddate.DateTime;
    RMVariables['QRBARCODE'] := fImagePath;
    RM2.LoadFromFile(fPrintFile);
    RM2.ShowReport;
    Panel5.Visible := False;
  end
  else
  begin
    Panel5.Visible := False;
    Application.MessageBox(PChar('没有找' + fPrintFile), '提示', 0);
  end;
end;

procedure TfrmZGJBMX.Tv0CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
var
  fPrintFile: string;
  EngMoney, LBName: string;
  FEWMID, Txt, fImagePath: string;
  Moudle: THandle;
  Makebar: TMakebar;
  Mixtext: TMixtext;
begin
  if Tv0.Controller.FocusedColumn.Tag = 1 then
  begin
    if ClientDataSet0.IsEmpty then
      Exit;

    LBName := '染整指示单';
    Panel5.Visible := True;
    Panel5.Refresh;
    ExportFtErpFile(Trim(LBName) + '.rmf', ADOQueryTemp);
    with ADOQueryPrint do
    begin
      Close;
      sql.Clear;
      sql.Add('exec P_Print_Order');
      sql.add('@mainID=' + quotedstr(trim(ClientDataSet0.fieldbyname('MainID').AsString)));
      Open;
    end;

    FEWMID := Trim(ClientDataSet0.fieldbyname('Mainid').AsString);

    try
      Moudle := LoadLibrary('MakeQRBarcode.dll');
      @Makebar := GetProcAddress(Moudle, 'Make');
      @Mixtext := GetProcAddress(Moudle, 'MixText');
      Txt := Trim(FEWMID);
      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\' + Trim(LBName) + '.rmf';
    if FileExists(fPrintFile) then
    begin
      RMVariables['QRBARCODE'] := fImagePath;
      RM2.LoadFromFile(fPrintFile);
      //RMVariables['SYRName'] := Trim(SYRName);
      RM2.ShowReport;
      Panel5.Visible := False;
    end
    else
    begin
      Panel5.Visible := False;
      Application.MessageBox(PChar('没有找' + ExtractFilePath(Application.ExeName) + 'Report\' + Trim(LBName) + '.rmf'), '提示', 0);
    end;
  end;
end;

procedure TfrmZGJBMX.cxGridDBColumn9HeaderClick(Sender: TObject);
var
  fPrintFile: string;
  Txt, fImagePath: string;
  Moudle: THandle;
  Makebar: TMakebar;
  Mixtext: TMixtext;
begin
  if ClientDataSet0.IsEmpty then
    exit;
  if trim(ClientDataSet0.fieldbyname('LBName').AsString) = '' then
    exit;
  Panel5.Visible := True;
  Panel5.Refresh;
  with ADOQueryPrint do
  begin
    Close;
    SQL.Clear;
    sql.Add('exec P_Print_Cs_Roll ');
    sql.Add('@mainID=''' + trim(ClientDataSet0.fieldbyname('mainID').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;
  ExportFtErpFile10(Trim(ClientDataSet0.fieldbyname('LBName').AsString) + '.rmf', ADOQueryTemp);
  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report10\' + Trim(ClientDataSet0.fieldbyname('LBName').AsString) + '.rmf';
  if FileExists(fPrintFile) then
  begin
    RMVariables['QRBARCODE'] := fImagePath;
    RM2.LoadFromFile(fPrintFile);
    RM2.ShowReport;
    Panel5.Visible := False;
  end
  else
  begin
    Panel5.Visible := False;
    Application.MessageBox(PChar('没有找到' + trim(fPrintFile)), '提示信息', 0);
  end;
end;

procedure TfrmZGJBMX.SH1DblClick(Sender: TObject);
begin
  try
    frmJYOrderCDList := TfrmJYOrderCDList.Create(Application);
    with frmJYOrderCDList do
    begin
      FMainid := Trim(Self.ClientDataSet0.fieldbyname('Mainid').AsString);
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmJYOrderCDList.Free;
  end;

end;

procedure TfrmZGJBMX.Label1Click(Sender: TObject);
begin
  try
    frmJYOrderCDGangList := TfrmJYOrderCDGangList.Create(Application);
    with frmJYOrderCDGangList do
    begin
      FMainid := Trim(Self.ClientDataSet0.fieldbyname('Mainid').AsString);
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmJYOrderCDGangList.Free;
  end;
end;

procedure TfrmZGJBMX.SaveGSClick(Sender: TObject);
begin
  if Trim(DName) = 'ADMIN' then
  begin
    Panel5.Visible := True;
    Panel5.Refresh;
    WriteCxGridAll(trim(self.Caption) + '0', Tv0, ADOQueryCmd, ADOQueryTemp);
    WriteCxGridAll(trim(self.Caption) + '1', Tv1, ADOQueryCmd, ADOQueryTemp);
    WriteCxGridAll(trim(self.Caption) + '333', Tv3, ADOQueryCmd, ADOQueryTemp);
    WriteCxBandedGridAll(trim(self.Caption) + '2', Tv2, ADOQueryCmd, ADOQueryTemp);
    Panel5.Visible := False;
  end;
end;

procedure TfrmZGJBMX.Tv2Column9CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
var
  id: Integer;
  Fsunhao10: string;
  Fsunhao: Double;
begin

  id := TV2.GetColumnByFieldName('jyshStr').Index;

  if id < 0 then
    Exit;

  if AViewInfo.GridRecord.Values[id] = null then
    Exit;

  Fsunhao10 := AViewInfo.GridRecord.Values[id];

  Fsunhao := StrToFloat(Fsunhao10);
  if Fsunhao >= 3 then
    ACanvas.Brush.Color := $00FFFF
  else
  begin

  end;
end;

procedure TfrmZGJBMX.Tv2Column23CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
var
  id: Integer;
  Fsunhao10: string;
  Fsunhao: Double;
begin

  id := TV2.GetColumnByFieldName('KPJSPC').Index;

  if id < 0 then
    Exit;

  if AViewInfo.GridRecord.Values[id] = null then
    Exit;

  Fsunhao10 := AViewInfo.GridRecord.Values[id];

  Fsunhao := StrToFloat(Fsunhao10);
  if Fsunhao < 0 then
    Fsunhao := Fsunhao * (-1);
  if Fsunhao >= 5 then
    ACanvas.Brush.Color := $00FFFF
  else
  begin

  end;
end;

procedure TfrmZGJBMX.Tv2Column4CompareRowValuesForCellMerging(Sender: TcxGridColumn; ARow1: TcxGridDataRow; AProperties1: TcxCustomEditProperties; const AValue1: Variant; ARow2: TcxGridDataRow; AProperties2: TcxCustomEditProperties; const AValue2: Variant; var AAreEqual: Boolean);
var
  i, j: Integer;
begin
  i := tv2.GetColumnByFieldName('RCGangNo').Index;
  j := tv2.GetColumnByFieldName('KpPS').Index;
  if (ARow1.Values[i] = ARow2.Values[i]) and (ARow1.Values[j] = ARow2.Values[j]) then
  begin
    AAreEqual := True;
  end
  else
  begin
    AAreEqual := False;
  end;
end;

procedure TfrmZGJBMX.Tv2Column5CompareRowValuesForCellMerging(Sender: TcxGridColumn; ARow1: TcxGridDataRow; AProperties1: TcxCustomEditProperties; const AValue1: Variant; ARow2: TcxGridDataRow; AProperties2: TcxCustomEditProperties; const AValue2: Variant; var AAreEqual: Boolean);
var
  i, j: Integer;
begin
  i := tv2.GetColumnByFieldName('RCGangNo').Index;
  j := tv2.GetColumnByFieldName('KpQty').Index;
  if (ARow1.Values[i] = ARow2.Values[i]) and (ARow1.Values[j] = ARow2.Values[j]) then
  begin
    AAreEqual := True;
  end
  else
  begin
    AAreEqual := False;
  end;
end;

procedure TfrmZGJBMX.Tv2Column2CompareRowValuesForCellMerging(Sender: TcxGridColumn; ARow1: TcxGridDataRow; AProperties1: TcxCustomEditProperties; const AValue1: Variant; ARow2: TcxGridDataRow; AProperties2: TcxCustomEditProperties; const AValue2: Variant; var AAreEqual: Boolean);
var
  i, j: Integer;
begin
  i := tv2.GetColumnByFieldName('PRTEColor').Index;
  j := tv2.GetColumnByFieldName('KPDate').Index;
  if (ARow1.Values[i] = ARow2.Values[i]) and (ARow1.Values[j] = ARow2.Values[j]) then
  begin
    AAreEqual := True;
  end
  else
  begin
    AAreEqual := False;
  end;
end;

procedure TfrmZGJBMX.Tv2Column22CompareRowValuesForCellMerging(Sender: TcxGridColumn; ARow1: TcxGridDataRow; AProperties1: TcxCustomEditProperties; const AValue1: Variant; ARow2: TcxGridDataRow; AProperties2: TcxCustomEditProperties; const AValue2: Variant; var AAreEqual: Boolean);
var
  i, j: Integer;
begin
  i := tv2.GetColumnByFieldName('PRTColor').Index;
  j := tv2.GetColumnByFieldName('PRTEColor').Index;
  if (ARow1.Values[i] = ARow2.Values[i]) and (ARow1.Values[j] = ARow2.Values[j]) then
  begin
    AAreEqual := True;
  end
  else
  begin
    AAreEqual := False;
  end;
end;

procedure TfrmZGJBMX.Tv2Column3CompareRowValuesForCellMerging(Sender: TcxGridColumn; ARow1: TcxGridDataRow; AProperties1: TcxCustomEditProperties; const AValue1: Variant; ARow2: TcxGridDataRow; AProperties2: TcxCustomEditProperties; const AValue2: Variant; var AAreEqual: Boolean);
var
  i, j: Integer;
begin
  i := tv2.GetColumnByFieldName('KPDate').Index;
  j := tv2.GetColumnByFieldName('RCGangNo').Index;
  if (ARow1.Values[i] = ARow2.Values[i]) and (ARow1.Values[j] = ARow2.Values[j]) then
  begin
    AAreEqual := True;
  end
  else
  begin
    AAreEqual := False;
  end;
end;

procedure TfrmZGJBMX.Tv3CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
var
  FName: string;
begin
  FName := Tv3.Controller.FocusedColumn.DataBinding.FilterFieldName;
  if ClientDataSet3.Fieldbyname('row').AsInteger <> 1 then
    Exit;
  if Trim(ClientDataSet3.Fieldbyname(FName).AsString) = '' then
    Exit;
  if Trim(ClientDataSet3.Fieldbyname(FName).AsString) = '颜色' then
    Exit;
  if Trim(ClientDataSet3.Fieldbyname(FName).AsString) <> '合计' then
  begin
    ClientDataSet2.Filter := 'PRTColor=''' + Trim(ClientDataSet3.fieldbyname(FName).AsString) + '''';
    ClientDataSet2.Filtered := True;
  end
  else
  begin
    ClientDataSet2.Filtered := False;
  end;

end;

end.

