unit U_SYR_CP_Col_XS_List;

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

type
  TfrmSYR_CP_Col_XS_List = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBExport: TToolButton;
    TBPrint: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Label3: TLabel;
    Label4: TLabel;
    factoryName: TEdit;
    C_Color: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    CDS_Main: TClientDataSet;
    Label5: TLabel;
    conNO: TEdit;
    Label6: TLabel;
    MJID: TEdit;
    Label8: TLabel;
    KZ: TEdit;
    Label9: TLabel;
    MF: TEdit;
    Label7: TLabel;
    CPType: TComboBox;
    MovePanel2: TMovePanel;
    Label10: TLabel;
    Edit1: TEdit;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    cxStyle2: TcxStyle;
    cxStyle_gridRow: TcxStyle;
    cxStyle_gridFoot: TcxStyle;
    cxStyle_gridHead: TcxStyle;
    cxStyle_gridGroupBox: TcxStyle;
    cxStyle_yellow: TcxStyle;
    cxStyle_Red: TcxStyle;
    cxStyle_fontBlack: TcxStyle;
    cxStyle_fontclFuchsia: TcxStyle;
    cxStyle_fontclPurple: TcxStyle;
    cxStyle_fontclGreen: TcxStyle;
    cxStyle_fontclBlue: TcxStyle;
    cxStyle_fontclTeal: TcxStyle;
    cxStyle_fontclOlive: TcxStyle;
    SYRName: TEdit;
    Label11: TLabel;
    ToolButton1: TToolButton;
    cxGrid2: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column11: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    cxGrid2Level1: TcxGridLevel;
    C_CodeName: TEdit;
    Label12: TLabel;
    Label13: TLabel;
    BCKZ1: TEdit;
    Label14: TLabel;
    v1Column9: TcxGridDBColumn;
    procedure FormDestroy(Sender: TObject);
    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 factoryNameChange(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
  private
    procedure InitGrid();
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmSYR_CP_Col_XS_List: TfrmSYR_CP_Col_XS_List;

implementation
uses
  U_DataLink,U_Fun,U_KH_XS_list;

{$R *.dfm}

procedure TfrmSYR_CP_Col_XS_List.FormDestroy(Sender: TObject);
begin
  frmSYR_CP_Col_XS_List:=nil;
end;

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

procedure TfrmSYR_CP_Col_XS_List.FormCreate(Sender: TObject);
begin
  //cxGrid1.Align:=alClient;
  BegDate.DateTime:=SGetServerDateTime(ADOQueryTemp);
  EndDate.DateTime:=SGetServerDateTime(ADOQueryTemp);
 // begdate.DateTime:=strtodateTime(formatdateTime('yyyy-MM',EndDate.DateTime)+'-01');
end;

procedure TfrmSYR_CP_Col_XS_List.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add(' exec P_Get_SYR_CP_Col_XS ');
      sql.Add(' @begdate='''+formatdatetime('yyyy-MM-dd',begdate.DateTime)+''' ');
      sql.Add(',@enddate='''+formatdatetime('yyyy-MM-dd',enddate.DateTime+1)+''' ');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  finally
    ADOQueryMain.EnableControls;
    TBFind.Click;
  end;
end;

procedure TfrmSYR_CP_Col_XS_List.TBRafreshClick(Sender: TObject);
begin
  //BegDate.SetFocus;
  MovePanel2.Visible:=True;
  MovePanel2.Refresh;
  InitGrid();
  MovePanel2.Visible:=False;
end;

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

procedure TfrmSYR_CP_Col_XS_List.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid(self.Caption+tv1.Name,Tv1,'³ÉÆ·²Ö¿â');
  Close;
end;

procedure TfrmSYR_CP_Col_XS_List.FormShow(Sender: TObject);
begin

  ReadCxGrid(self.Caption+tv1.Name,Tv1,'³ÉÆ·²Ö¿â');
  
  InitGrid();
end;

procedure TfrmSYR_CP_Col_XS_List.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then exit;
  TcxGridToExcel(self.Caption,cxGrid2);
end;

procedure TfrmSYR_CP_Col_XS_List.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 TfrmSYR_CP_Col_XS_List.factoryNameChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmSYR_CP_Col_XS_List.ToolButton1Click(Sender: TObject);
begin
  IF cds_main.IsEmpty then exit;
  frmKH_XS_list:=TfrmKH_XS_list.create(self);
  with frmKH_XS_list do
  begin
    begdate.Date:=self.BegDate.Date;
    enddate.Date:=self.EndDate.date;
    SYRName.Text:=self.cds_main.fieldbyname('SYRName').asstring;
    show;
  end;
end;

end.
