unit U_JTYarnReport;

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, cxDropDownEdit, RM_e_Xls,
  cxGridBandedTableView, cxGridDBBandedTableView, BtnEdit,DateUtils;

type
  TfrmJTYarnReport = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    Panel1: TPanel;
    ToolButton2: TToolButton;
    Label1: TLabel;
    MPRTCodeName: TEdit;
    ADOQueryMain: TADOQuery;
    ToolButton1: TToolButton;
    Label3: TLabel;
    OrderNo: TEdit;
    cxGrid2: TcxGrid;
    cxGridLevel1: TcxGridLevel;
    Label2: TLabel;
    Label6: TLabel;
    begdate: TDateTimePicker;
    Enddate: TDateTimePicker;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_HZ: TDataSource;
    CDS_HZ: TClientDataSet;
    Label4: TLabel;
    OrdDefNote3: TComboBox;
    ToolButton3: TToolButton;
    RM1: TRMGridReport;
    RMDBDataSet1: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    ADOQueryPrint: TADOQuery;
    TV1: TcxGridDBBandedTableView;
    V1Column1: TcxGridDBBandedColumn;
    V1Column2: TcxGridDBBandedColumn;
    V1Column5: TcxGridDBBandedColumn;
    V1Column6: TcxGridDBBandedColumn;
    V1Column7: TcxGridDBBandedColumn;
    V1Column8: TcxGridDBBandedColumn;
    V1Column9: TcxGridDBBandedColumn;
    V1Column12: TcxGridDBBandedColumn;
    V1Column15: TcxGridDBBandedColumn;
    V1Column3: TcxGridDBBandedColumn;
    V1Column10: TcxGridDBBandedColumn;
    V1Column11: TcxGridDBBandedColumn;
    V1Column13: TcxGridDBBandedColumn;
    V1Column14: TcxGridDBBandedColumn;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    Label7: TLabel;
    SPName: TEdit;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure P_OrderNo_YSK(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure OrderNoChange(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure SPNameChange(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
  private
    { Private declarations }

    procedure InitGrid();

  public
    { Public declarations }
    RKFlag,FCYID:String;
    fType:string;

  end;

var
  frmJTYarnReport: TfrmJTYarnReport;

implementation
uses
  U_DataLink,U_Fun,U_ZDYHelp;

{$R *.dfm}



procedure TfrmJTYarnReport.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      SQL.Clear;
      SQL.Add('exec P_View_JCCJTY '+quotedstr(Trim(FormatDateTime('yyyy-MM-dd',begdate.DateTime))));
      SQL.Add(','+quotedstr(Trim(FormatDateTime('yyyy-MM-dd',EndDate.DateTime+1))));
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_HZ);
    SInitCDSData20(ADOQueryMain,CDS_HZ);
  finally
    ADOQueryMain.EnableControls;
  end;
end;


procedure TfrmJTYarnReport.FormDestroy(Sender: TObject);
begin
  frmJTYarnReport:=nil;
end;

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

procedure TfrmJTYarnReport.TBCloseClick(Sender: TObject);
begin
  WriteCxBandedGrid(trim(self.Caption),Tv1,'统计管理');
  Close;
end;
procedure TfrmJTYarnReport.FormShow(Sender: TObject);
begin
  readCxBandedGrid(trim(self.Caption),Tv1,'统计管理');

end;

procedure TfrmJTYarnReport.TBRafreshClick(Sender: TObject);
begin
  begdate.SetFocus;
  InitGrid();
end;

procedure TfrmJTYarnReport.ToolButton2Click(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
    SCreateCDS20(ADOQueryMain,CDS_HZ);
    SInitCDSData20(ADOQueryMain,CDS_HZ);
  end;
end;

procedure TfrmJTYarnReport.P_OrderNo_YSK(Sender: TObject);
begin
  ToolButton2.Click;
end;

procedure TfrmJTYarnReport.ToolButton1Click(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then Exit;
  TcxGridToExcel(self.Caption,cxgrid2);
end;

procedure TfrmJTYarnReport.OrderNoChange(Sender: TObject);
begin
  if Length(Trim(OrderNo.Text))<3 then Exit;
  ToolButton2.Click;
end;

procedure TfrmJTYarnReport.FormCreate(Sender: TObject);
begin
  begdate.DateTime:=StartOfTheMonth(Now);
  Enddate.DateTime:=EndOfTheMonth(Now);
end;

procedure TfrmJTYarnReport.SPNameChange(Sender: TObject);
begin
  ToolButton2.Click
end;

procedure TfrmJTYarnReport.ToolButton3Click(Sender: TObject);
var
   fPrintFile,FFCYID:string;
   i,j:Integer;
   Txt,fImagePath:string;
   Moudle: THandle;
   Makebar:TMakebar;
   Mixtext:TMixtext;
begin
  if CDS_HZ.IsEmpty then Exit;
  fPrintFile:= ExtractFilePath(Application.ExeName) + 'Report\纱线月报表.rmf';
 
  if FileExists(fPrintFile) then
  begin
    RM1.LoadFromFile(fPrintFile);
    RM1.ShowReport;
  end
  else
  begin
    Application.MessageBox(PChar('没有找'+fPrintFile+'!'),'提示',0);
    Exit;
  end;
end;


end.
