unit U_LLRKList_CX;

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, cxButtonEdit, cxDropDownEdit, cxPC, Buttons;

type
  TfrmLLRKList_CX = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBClose: TToolButton;
    Tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    TBExport: TToolButton;
    Order_Main: TClientDataSet;
    Panel1: TPanel;
    v1Column1: TcxGridDBColumn;
    Label34: TLabel;
    v1Column7: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    KHName: TEdit;
    Label3: TLabel;
    Label4: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    RM1: TRMGridReport;
    RMDBMain: TRMDBDataSet;
    RMXLSExport2: TRMXLSExport;
    CDS_PRT: TClientDataSet;
    v1Column17: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    Label2: TLabel;
    MYName: TEdit;
    v1Column3: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    Label1: TLabel;
    Note: TEdit;
    v1Column4: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    Label5: TLabel;
    MYColor: TEdit;
    labMYType: TLabel;
    TSsel: TToolButton;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
    procedure CustomerNoNameChange(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure ZJStatusChange(Sender: TObject);
    procedure Tv1DblClick(Sender: TObject);
    procedure TSselClick(Sender: TObject);
  private
    canshu1:string;
    DQdate:TDateTime;
    procedure InitGrid();
    procedure InitForm();
    { Private declarations }
  public
    FFInt,FCloth:Integer;

    { Public declarations }
  end;

var
  frmLLRKList_CX: TfrmLLRKList_CX;

implementation
uses
  U_DataLink,U_RTFun, U_QCRKInPut,U_ZDYHelp,U_LLRKInPut,U_LLRKInPutMH,U_LLRKInPutX;

{$R *.dfm}

procedure TfrmLLRKList_CX.FormDestroy(Sender: TObject);
begin
  frmLLRKList_CX:=nil;
end;

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

procedure TfrmLLRKList_CX.FormCreate(Sender: TObject);
begin
  cxgrid1.Align:=alClient;
  canshu1:=Trim(DParameters1);
end;

procedure TfrmLLRKList_CX.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('来料入库',Tv1,'贸易生产管理');
  Close;
end;

procedure TfrmLLRKList_CX.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add(' select A.* ');
      sql.Add(' from CK_MYSC_CR A  ');
      sql.Add(' where 1=1 ');
      sql.Add(' and CRTime>='''+Trim(FormatDateTime('yyyy-MM-dd',BegDate.Date))+'''');
      sql.Add(' and CRTime<'''+Trim(FormatDateTime('yyyy-MM-dd',EndDate.Date+1))+'''');
      sql.Add(' and isnull(CRType,'''')=''来料入库'' ');
      {if Trim(canshu1)<>'高权限' then
      begin
        sql.Add(' and FillerCode='''+Trim(DCode)+'''');
      end; }
      Open;
    end;
    SCreateCDS20(ADOQueryMain,Order_Main);
    SInitCDSData20(ADOQueryMain,Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;


procedure TfrmLLRKList_CX.InitForm();
begin
  BegDate.Date:=SGetServerDateMBeg(ADOQueryTemp);
  EndDate.Date:=SGetServerDate(ADOQueryTemp);
  ReadCxGrid('来料入库',Tv1,'贸易生产管理');
  InitGrid();
end;

procedure TfrmLLRKList_CX.TBFindClick(Sender: TObject);
begin
  if ADOQueryMain.Active=False then Exit;
  SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
  SCreateCDS20(ADOQueryMain,Order_Main);
  SInitCDSData20(ADOQueryMain,Order_Main);
end;

procedure TfrmLLRKList_CX.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then Exit;
  TcxGridToExcel(Self.Caption,cxGrid1);
end;

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

procedure TfrmLLRKList_CX.FormShow(Sender: TObject);
begin
  InitForm();
end;

procedure TfrmLLRKList_CX.CheckBox1Click(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmLLRKList_CX.CheckBox2Click(Sender: TObject);
begin
  TBRafresh.Click;
end;

procedure TfrmLLRKList_CX.CustomerNoNameChange(Sender: TObject);
begin
  if ADOQueryMain.Active=False then Exit;
  SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
  SCreateCDS20(ADOQueryMain,Order_Main);
  SInitCDSData20(ADOQueryMain,Order_Main);
end;

procedure TfrmLLRKList_CX.N2Click(Sender: TObject);
begin
  SelOKNo(Order_Main,True);
end;

procedure TfrmLLRKList_CX.N1Click(Sender: TObject);
begin
  SelOKNo(Order_Main,False);
end;

procedure TfrmLLRKList_CX.cxTabControl1Change(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmLLRKList_CX.ZJStatusChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmLLRKList_CX.Tv1DblClick(Sender: TObject);
begin
  TSsel.Click;
end;

procedure TfrmLLRKList_CX.TSselClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then exit;
  ModalResult:=1;
end;

end.
