unit U_OldShaRKList;

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, cxPC,ComObj,
  MovePanel;

type
    FdDy = record
    inc: integer; //客户端套接字句柄
    FDdys: string[32]; //客户端套接字
    FdDysName: string[32]; //客户端套接字
end;
  TfrmOldShaRKList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Label1: TLabel;
    Label2: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    CDS_Main: TClientDataSet;
    RM1: TRMGridReport;
    RMDBMain: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    RMDBHZ: TRMDBDataSet;
    CDS_HZ: TClientDataSet;
    CDS_PRT: TClientDataSet;
    cxGrid2: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column6: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column14: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Note: TcxGridDBColumn;
    cxGrid2Level1: TcxGridLevel;
    v1Column16: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v1Price: TcxGridDBColumn;
    v1ComTaiTou: TcxGridDBColumn;
    v1Note1: TcxGridDBColumn;
    v1filler: TcxGridDBColumn;
    v1FillNo: TcxGridDBColumn;
    RM2: TRMGridReport;
    v1Ssel: TcxGridDBColumn;
    OpenDialog1: TOpenDialog;
    MovePanel1: TMovePanel;
    v1Column12: TcxGridDBColumn;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    canshu1, canshu2, canshu3: string;
    procedure InitGrid();
    { Private declarations }
  public
    FY_CodeName,FY_Spec,FFactoryName,FY_CF,Fvalue :string;
    { Public declarations }
  end;

var
  frmOldShaRKList: TfrmOldShaRKList;

implementation

uses
  U_DataLink, U_RTFun, U_ShaRKInPut,U_Fun;

{$R *.dfm}

procedure TfrmOldShaRKList.FormDestroy(Sender: TObject);
begin
  frmOldShaRKList:=nil;
end;

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

procedure TfrmOldShaRKList.FormCreate(Sender: TObject);
begin
  //cxGrid1.Align:=alClient;
  EndDate.DateTime := SGetServerDate10(ADOQueryTemp);
  BegDate.DateTime := EndDate.DateTime-365;
end;

procedure TfrmOldShaRKList.InitGrid();
begin
  if Fvalue<>'KC' then
  begin
    try
      ADOQueryMain.DisableControls;
      with ADOQueryMain do
      begin
        Filtered := False;
        Close;
        sql.Clear;
        sql.Add(' select A.*,B.ShortName ');
        sql.Add(' from CK_Yarn_CR A');
        sql.Add(' inner join BS_Company_Main B on B.Code=A.FactoryNo');
        sql.add(' where A.CRTime>=''' + Trim(FormatDateTime('yyyy-MM-dd', BegDate.DateTime)) + '''');
        sql.Add(' and A.CRTime<''' + Trim(FormatDateTime('yyyy-MM-dd', enddate.DateTime + 1)) + '''');
        sql.Add(' and ISNULL(A.Y_CodeName, '''')='+QuotedStr(Trim(FY_CodeName)));
        sql.Add(' and ISNULL(A.FactoryName, '''')='+QuotedStr(Trim(FFactoryName)));
        sql.Add(' and ISNULL(A.Y_CF, '''')='+QuotedStr(Trim(FY_CF)));
        SQL.Add(' and ISNULL(A.Y_Spec, '''')='+QuotedStr(Trim(FY_Spec)));
        sql.Add(' and isnull(CKName,'''')=''纱线''');
        SQL.Add(' and CRFlag=''入库''  ');
        SQL.Add(' order by CRTime desc');
        Open;
      end;
      SCreateCDS20(ADOQueryMain, CDS_Main);
      SInitCDSData20(ADOQueryMain, CDS_Main);
    finally
      ADOQueryMain.EnableControls;
    end;
  end
  else
  begin
    try
      ADOQueryMain.DisableControls;
      with ADOQueryMain do
      begin
        Filtered := False;
        Close;
        sql.Clear;
        sql.Add(' select A.*,B.ShortName ');
        sql.Add(' from CK_Yarn_CR A ');
        sql.Add(' inner join BS_Company_Main B on B.Code=A.FactoryNo');
        sql.Add(' where ISNULL(A.Y_CodeName, '''')='+QuotedStr(Trim(FY_CodeName)));
        sql.Add(' and ISNULL(A.FactoryName, '''')='+QuotedStr(Trim(FFactoryName)));
        sql.Add(' and ISNULL(A.Y_CF, '''')='+QuotedStr(Trim(FY_CF)));
        SQL.Add(' and ISNULL(A.Y_Spec, '''')='+QuotedStr(Trim(FY_Spec)));
        sql.Add(' and isnull(A.CKName,'''')=''纱线''');
        SQL.Add(' and A.CRFlag=''入库''  ');
        SQL.Add(' ORDER BY A.Filltime DESC ');
        Open;
      end;
      SCreateCDS20(ADOQueryMain, CDS_Main);
      SInitCDSData20(ADOQueryMain, CDS_Main);
    finally
      ADOQueryMain.EnableControls;
    end;
  end;


end;

procedure TfrmOldShaRKList.TBRafreshClick(Sender: TObject);
begin
  Panel1.SetFocus;
  InitGrid();
end;

procedure TfrmOldShaRKList.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('纱线入库列表1', Tv1, '纱线仓库');
  Close;
end;

procedure TfrmOldShaRKList.FormShow(Sender: TObject);
begin
  ReadCxGrid('纱线入库列表1', Tv1, '纱线仓库');
  InitGrid();
end;

end.

