unit U_ShaCLlist;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
  cxEdit, DB, cxDBData, cxGridCustomTableView, cxGridTableView,
  cxGridBandedTableView, cxGridDBBandedTableView, cxGridLevel, cxClasses,
  cxControls, cxGridCustomView, cxGridDBTableView, cxGrid, StdCtrls, ComCtrls,
  ExtCtrls, ToolWin, cxGridCustomPopupMenu, cxGridPopupMenu, ADODB, DBClient,
  cxDropDownEdit, cxCheckBox, RM_Common, RM_Class, RM_e_Xls, RM_Dataset,
  RM_System, RM_GridReport, Menus, cxCalendar, cxButtonEdit, cxTextEdit,
  cxLookAndFeels, cxLookAndFeelPainters, cxNavigator, dxSkinsCore,
  dxSkinsDefaultPainters, dxSkinscxPCPainter;

type
  TfrmSXLIST = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    CDS_Main: TClientDataSet;
    cxGrid2: TcxGrid;
    Tv1: TcxGridDBTableView;
    v2Column1: TcxGridDBColumn;
    cxGrid2Level1: TcxGridLevel;
    Label3: TLabel;
    Y_CODENAME: TEdit;
    ToolButton2: TToolButton;
    v1Column17: TcxGridDBColumn;
    Label2: TLabel;
    Y_Spec: TEdit;
    v1Column19: TcxGridDBColumn;
    v1Column20: TcxGridDBColumn;
    v1Column21: TcxGridDBColumn;
    v1Column22: TcxGridDBColumn;
    v1FactoryName: TcxGridDBColumn;
    Label9: TLabel;
    FactoryName: TEdit;
    ToolButton1: TToolButton;
    RM1: TRMGridReport;
    RMDBMain: TRMDBDataSet;
    Label4: TLabel;
    Label5: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    Tv1Column3: TcxGridDBColumn;
    Tv1Column4: TcxGridDBColumn;
    Tv1Column5: TcxGridDBColumn;
    Tv1Column6: TcxGridDBColumn;
    Tv1Column7: TcxGridDBColumn;
    Tv1Column8: TcxGridDBColumn;
    Tv1Column9: TcxGridDBColumn;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBRafreshClick(Sender: TObject);
    procedure ConNoMChange(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure MPRTCodeNameChange(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure SXBatchNOChange(Sender: TObject);
    procedure FactoryNameChange(Sender: TObject);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
    procedure ToolButton2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
  private
    procedure InitGrid();
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmSXLIST: TfrmSXLIST;

implementation

uses
  U_DataLink, U_RTFun, U_ShaOutList, U_ShaKCList, U_Fun;

{$R *.dfm}

procedure TfrmSXLIST.FormDestroy(Sender: TObject);
begin
  frmSXList := nil;
end;

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

procedure TfrmSXLIST.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add(' exec P_View_SXRBB');
      sql.add('@Begdate=' + QuotedStr(Trim(FormatDateTime('yyyy-MM-dd', BegDate.DateTime))));
      sql.add(',@enddate=' + QuotedStr(Trim(FormatDateTime('yyyy-MM-dd', endDate.DateTime + 1))));
      Open;
      //ShowMessage(SQL.Text);
    end;
    SCreateCDS20(ADOQueryMain, CDS_Main);
    SInitCDSData20(ADOQueryMain, CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmSXLIST.TBRafreshClick(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmSXLIST.ConNoMChange(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  end;
end;

procedure TfrmSXLIST.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('纱线库存汇总列表111', Tv1, '纱线仓库');
  Close;
end;

procedure TfrmSXLIST.FormShow(Sender: TObject);
begin
  ReadCxGrid('纱线库存汇总列表111', Tv1, '纱线仓库');
  //InitGrid();
end;

procedure TfrmSXLIST.TBFindClick(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
    SCreateCDS20(ADOQueryMain, CDS_Main);
    SInitCDSData20(ADOQueryMain, CDS_Main);
  end;
end;

procedure TfrmSXLIST.MPRTCodeNameChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmSXLIST.N1Click(Sender: TObject);
begin
  SelOKNo(CDS_Main, True);
end;

procedure TfrmSXLIST.N2Click(Sender: TObject);
begin
  SelOKNo(CDS_Main, False);
end;

procedure TfrmSXLIST.SXBatchNOChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmSXLIST.FactoryNameChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmSXLIST.Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
begin
  try
    frmShaKCList := TfrmShaKCList.Create(Application);
    with frmShaKCList do
    begin
      frmShaKCList.Align := alClient;
      FDYFlag := '99';
      frmShaKCList.Y_CodeName.Text := Trim(Self.CDS_Main.fieldbyname('Y_CodeName').AsString);
      frmShaKCList.Y_Spec.Text := Trim(Self.CDS_Main.fieldbyname('Y_Spec').AsString);
      frmShaKCList.BatchNo.Text := Trim(Self.CDS_Main.fieldbyname('BatchNo').AsString);
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmShaKCList.Free;
  end;
end;

procedure TfrmSXLIST.ToolButton2Click(Sender: TObject);
begin
  if CDS_Main.IsEmpty then
    exit;
  TcxGridToExcel('纱线日报表', cxGrid2);
end;

procedure TfrmSXLIST.FormCreate(Sender: TObject);
begin
  begDate.DateTime := SGetServerDate10(ADOQueryTemp);
  endDate.DateTime := SGetServerDate10(ADOQueryTemp);
end;

procedure TfrmSXLIST.ToolButton1Click(Sender: TObject);
var
  filepath: string;
  mBegdate, mEnddate: string;
  FName, FNameSX, FNameJX: string;
  i: Integer;
begin

  mBegdate := FormatDateTime('yyyy-MM-dd', begdate.Date);

  if CDS_Main.IsEmpty then
    exit;

  ExportFtErpFile('纱线日报表.rmf', ADOQueryTemp);
  filepath := ExtractFilePath(Application.ExeName) + 'report\纱线日报表.rmf';
  if FileExists(filepath) then
  begin
      //RM1.DefaultCopies := 2;
    RmVariables['begDate'] := FormatDateTime('yymmdd', begDate.Date);
    RM1.LoadFromFile(filepath);
    RM1.ShowReport;
  end
  else
  begin
    Application.MessageBox(PChar('没有找' + filepath), '提示', 0);
  end;
end;

end.

