unit U_JTSCTJList;

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, BtnEdit,
  cxPC, DateUtils;

type
  TfrmJTSCTJList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBExport: TToolButton;
    TBClose: TToolButton;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    CDS_Main: TClientDataSet;
    RM1: TRMGridReport;
    RMDBMain: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    RMDBHZ: TRMDBDataSet;
    CDS_PRT: TClientDataSet;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    ADOQueryPrint: TADOQuery;
    cxGrid2: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column21: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    v1Column15: TcxGridDBColumn;
    cxGrid2Level1: TcxGridLevel;
    Panel1: TPanel;
    Label2: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    Label4: TLabel;
    cxTabControl1: TcxTabControl;
    pnlX: TPanel;
    pnlS: TPanel;
    pnlZ: TPanel;
    XZNDate: TDateTimePicker;
    Label1: TLabel;
    ToolButton1: TToolButton;
    v1Column1: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    tbISHZ: TToolButton;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ConNoMChange(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure SPIDKeyPress(Sender: TObject; var Key: Char);
    procedure SPIDChange(Sender: TObject);
    procedure SPSpecChange(Sender: TObject);
    procedure FactoryNameChange(Sender: TObject);
    procedure Tv1CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
    procedure cxTabControl1Change(Sender: TObject);
    procedure pnlXClick(Sender: TObject);
    procedure pnlSClick(Sender: TObject);
    procedure pnlZClick(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure XZNDateClick(Sender: TObject);
    procedure tbISHZClick(Sender: TObject);
  private
    SZX: string;
    ISHZ: string;
    procedure SetStatus();
    procedure SetCXDate();
    procedure InitGrid(KLScope: string);
    { Private declarations }
  public
    canshu1: string;
    { Public declarations }
  end;

implementation

uses
  U_DataLink, U_RTFun, U_ZDYHelp;

{$R *.dfm}
procedure TfrmJTSCTJList.SetCXDate();
begin
  BegDate.Date := StrToDate(FormatDateTime('yyyy-', XZNDate.DateTime) + IntToStr(cxTabControl1.TabIndex + 1) + '-01');
  if SZX = '上旬' then
  begin
    EndDate.Date := BegDate.Date + 9;
  end;
  if SZX = '中旬' then
  begin
    BegDate.Date := BegDate.Date + 10;
    EndDate.Date := BegDate.Date + 9;
  end;
  if SZX = '下旬' then
  begin
    BegDate.Date := BegDate.Date + 20;
    EndDate.Date := EndOfTheMonth(BegDate.Date);
  end;
end;

procedure TfrmJTSCTJList.SetStatus();
begin

end;

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

procedure TfrmJTSCTJList.FormCreate(Sender: TObject);
begin
  EndDate.DateTime := SGetServerDate10(ADOQueryTemp);
  BegDate.DateTime := EndDate.DateTime;
  XZNDate.DateTime := EndDate.DateTime;
  ISHZ := '明细';
end;

procedure TfrmJTSCTJList.InitGrid(KLScope: string);
var
  WSql: string;
begin

  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      if ISHZ = '汇总' then
        sql.Add(' exec P_View_JTSCTJHZ ')
      else
        sql.Add(' exec P_View_JTSCTJ ');
      sql.Add(quotedstr(trim(FormatDateTime('yyyy-MM-dd', BegDate.DateTime))));
      sql.Add(' ,' + quotedstr(trim(FormatDateTime('yyyy-MM-dd', EndDate.DateTime + 1))));
//      showmessage(sql.text);
      Open;
    end;
    SCreateCDS20(ADOQueryMain, CDS_Main);
    SInitCDSData20(ADOQueryMain, CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;

end;

procedure TfrmJTSCTJList.TBRafreshClick(Sender: TObject);
begin
  InitGrid('');

end;

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

procedure TfrmJTSCTJList.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid(trim(self.Caption), Tv1, '库龄分析');
  Close;
end;

procedure TfrmJTSCTJList.FormShow(Sender: TObject);
begin
  SZX := '上旬';
  pnlS.Color := clLime;
  pnlZ.Color := clYellow;
  pnlX.Color := clYellow;
  SetCXDate();

  SetStatus();

  ReadCxGrid(trim(self.Caption), Tv1, '库龄分析');

  InitGrid('');

end;

procedure TfrmJTSCTJList.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    exit;
  TcxGridToExcel('待检布入库列表', cxGrid2);
end;

procedure TfrmJTSCTJList.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 TfrmJTSCTJList.N1Click(Sender: TObject);
begin
  SelOKNo(CDS_Main, True);
end;

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

procedure TfrmJTSCTJList.SPIDKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    {if Length(Trim(SPID.Text))<4 then Exit;
    try
      ADOQueryMain.DisableControls;
      with ADOQueryMain do
      begin
        Filtered:=False;
        Close;
        sql.Clear;
        sql.Add(' select A.* ');
        sql.Add(',ConNo=(select ConNo from Contract_Main CM where CM.MainId=A.CGMainId)');
        //sql.Add(' ,ConNo=(select ConNo from Contract_Main CM where CM.MainId=A.CGMainId )');
        sql.Add(' from CK_SXPB_CR A');
        sql.add(' where SPID like :SXID');
        Parameters.ParamByName('SXID').Value:='%'+Trim(SXID.Text)+'%';
        Open;
        //ShowMessage(SQL.Text);
      end;
      SCreateCDS20(ADOQueryMain,CDS_Main);
      SInitCDSData20(ADOQueryMain,CDS_Main);
    finally
      ADOQueryMain.EnableControls;
    end; }
  end;
end;

procedure TfrmJTSCTJList.SPIDChange(Sender: TObject);
begin

  TBFind.Click;
end;

procedure TfrmJTSCTJList.SPSpecChange(Sender: TObject);
begin
  TBFind.Click;
end;

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

procedure TfrmJTSCTJList.Tv1CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
var
  FKuLin: double;
begin
     // 库龄 白15天 绿15到30天 蓝30到45天  黄45到60天  红60天以上  是

//  if AViewInfo.GridRecord.Values[TcxGridDBTableView(Sender).GetColumnByFieldName('PJKuLin').Index] = null then
//    Exit;
//  FKuLin := AViewInfo.GridRecord.Values[TcxGridDBTableView(Sender).GetColumnByFieldName('PJKuLin').Index];
//
//  if ((FKuLin < 30) and (FKuLin >= 15)) then
//  begin
//    ACanvas.Brush.Color := $00FF00;
//  end;
//  if ((FKuLin < 45) and (FKuLin >= 30)) then
//  begin
//    ACanvas.Brush.Color := $ED9564;
//  end;
//  if ((FKuLin < 60) and (FKuLin >= 45)) then
//  begin
//    ACanvas.Brush.Color := $00FFFF;
//  end;
//  if FKuLin >= 60 then
//  begin
//    ACanvas.Brush.Color := $4763FF;
//  end;

end;

procedure TfrmJTSCTJList.cxTabControl1Change(Sender: TObject);
begin
  SetCXDate();
end;

procedure TfrmJTSCTJList.pnlXClick(Sender: TObject);
begin
  SZX := '下旬';
  pnlS.Color := clYellow;
  pnlZ.Color := clYellow;
  pnlX.Color := clLime;
  SetCXDate();
end;

procedure TfrmJTSCTJList.pnlSClick(Sender: TObject);
begin
  SZX := '上旬';
  pnlS.Color := clLime;
  pnlZ.Color := clYellow;
  pnlX.Color := clYellow;
  SetCXDate();
end;

procedure TfrmJTSCTJList.pnlZClick(Sender: TObject);
begin
  SZX := '中旬';
  pnlS.Color := clYellow;
  pnlZ.Color := clLime;
  pnlX.Color := clYellow;
  SetCXDate();
end;

procedure TfrmJTSCTJList.ToolButton1Click(Sender: TObject);
begin
  if cxTabControl1.Visible = True then
  begin
    cxTabControl1.Visible := false;
    Panel1.Visible := True;
  end
  else
  begin
    cxTabControl1.Visible := True;
    Panel1.Visible := false;
  end;
end;

procedure TfrmJTSCTJList.XZNDateClick(Sender: TObject);
begin
  SetCXDate();
end;

procedure TfrmJTSCTJList.tbISHZClick(Sender: TObject);
begin
  if ISHZ = '汇总' then
  begin
    ISHZ := '明细';
    tbISHZ.Caption := '明细';
    v1Column1.Visible := True;
    v1Column2.Visible := True;
    v2Column1.Visible := True;
  end
  else
  begin
    ISHZ := '汇总';
    tbISHZ.Caption := '汇总';
    v1Column1.Visible := False;
    v1Column2.Visible := False;
    v2Column1.Visible := False;
  end;
end;

end.

