unit U_DJBKKListSel;

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

type
  TfrmDJBKKListSel = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Label2: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    CDS_Main: TClientDataSet;
    RM1: TRMGridReport;
    RMDBMain: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    RMDBHZ: TRMDBDataSet;
    CDS_HZ: TClientDataSet;
    CDS_PRT: TClientDataSet;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label8: TLabel;
    SPName: TEdit;
    FactoryName: TEdit;
    SPID: TEdit;
    SPSpec: TEdit;
    Label6: TLabel;
    SPCF: TEdit;
    Label7: TLabel;
    OrderNo: TEdit;
    cxGrid2: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column6: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    v1Column14: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column16: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    cxGrid2Level1: TcxGridLevel;
    Label12: TLabel;
    CRType: TComboBox;
    v1Column19: TcxGridDBColumn;
    Label11: TLabel;
    RCGangNo: TEdit;
    ADOQueryPrint: TADOQuery;
    v1Column21: TcxGridDBColumn;
    v1Column22: TcxGridDBColumn;
    Label16: TLabel;
    PBFactoryName: TEdit;
    v1Column5: TcxGridDBColumn;
    v1Column15: TcxGridDBColumn;
    v1Column17: TcxGridDBColumn;
    v1Column18: TcxGridDBColumn;
    v1Column20: TcxGridDBColumn;
    v1Column23: TcxGridDBColumn;
    v1Column24: TcxGridDBColumn;
    Label9: TLabel;
    conno: TEdit;
    Label10: TLabel;
    SPColor: TEdit;
    v1Column25: TcxGridDBColumn;
    Panel6: TPanel;
    Label31: TLabel;
    LBCPAP: TLabel;
    BTLP: TButton;
    BTNP: TButton;
    TCBNOR: TComboBox;
    IsJYTime: TCheckBox;
    v1Column26: TcxGridDBColumn;
    v1Column27: TcxGridDBColumn;
    cxgrdISHD: TcxGridDBColumn;
    v1Column28: TcxGridDBColumn;
    Label1: TLabel;
    WSTaiTou: TComboBox;
    v1Column29: TcxGridDBColumn;
    ToolButton1: TToolButton;
    v1Column30: TcxGridDBColumn;
    Label13: TLabel;
    YWY: TEdit;
    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 N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure SPIDKeyPress(Sender: TObject; var Key: Char);
    procedure CRTypeChange(Sender: TObject);
    procedure BTLPClick(Sender: TObject);
    procedure BTNPClick(Sender: TObject);
    procedure v1Column28PropertiesEditValueChanged(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    CurrentPage, RecordsNumber: Integer;
    procedure SetStatus();
    procedure InitGrid();
    { Private declarations }
  public
    canshu1: string;
    { Public declarations }
  end;

var
  frmDJBKKListSel: TfrmDJBKKListSel;

implementation

uses
  U_DataLink, U_RTFun, U_Fun;

{$R *.dfm}

procedure TfrmDJBKKListSel.SetStatus();
begin

end;

procedure TfrmDJBKKListSel.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caHide;
end;

procedure TfrmDJBKKListSel.FormCreate(Sender: TObject);
var
  fsj: string;
begin
  EndDate.DateTime := SGetServerDate10(ADOQueryTemp);
  BegDate.DateTime := EndDate.DateTime;

  fsj := 'select distinct(WSTaiTou) name from CK_SXPB_CR   ';
  SInitComBoxBySql(ADOQueryCmd, WSTaiTou, False, fsj);
end;

procedure TfrmDJBKKListSel.InitGrid();
var
  fwhere, Pwhere: string;
begin

  if IsJYTime.Checked then
  begin
    fwhere := ' where CRTime>=' + quotedstr(FormatDateTime('yyyy-MM-dd', BegDate.DateTime));
    fwhere := fwhere + ' and CRTime<' + quotedstr(FormatDateTime('yyyy-MM-dd', enddate.DateTime + 1));
  end
  else
    fwhere := ' where 1=1 ';
  Pwhere := SGetFilters(Panel1, 1, 2);
  if Pwhere <> '' then
    fwhere := fwhere + ' and ' + Pwhere;

  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add('exec P_Page_KaiKa ');
      sql.Add('@pageIndex=' + inttostr(CurrentPage));
      sql.Add(',@pageSize=' + inttostr(RecordsNumber));
      sql.Add(',@criteria= ' + quotedstr(fwhere));
//      ShowMessage(SQL.Text);
      Open;
    end;
    SCreateCDS20(ADOQueryMain, CDS_Main);
    SInitCDSData20(ADOQueryMain, CDS_Main);
    LBCPAP.Caption := inttostr(CurrentPage) + '/' + inttostr(ceil(CDS_Main.FieldByName('TotalCount').AsInteger / RecordsNumber));

  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmDJBKKListSel.TBRafreshClick(Sender: TObject);
begin
  BegDate.SetFocus;

  CurrentPage := 1;
  InitGrid();
end;

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

procedure TfrmDJBKKListSel.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid(trim(self.Caption), Tv1, '开卡管理');
  Close;
end;

procedure TfrmDJBKKListSel.FormShow(Sender: TObject);
begin
  CurrentPage := 1;
  RecordsNumber := 500;
  SetStatus();
//  ReadCxGrid(trim(self.Caption), Tv1, '开卡管理');
  InitGrid();
end;

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

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

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

procedure TfrmDJBKKListSel.SPIDKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    InitGrid();
  end;
end;

procedure TfrmDJBKKListSel.CRTypeChange(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmDJBKKListSel.BTLPClick(Sender: TObject);
begin
  if CurrentPage > 1 then
    CurrentPage := CurrentPage - 1;
  InitGrid();
end;

procedure TfrmDJBKKListSel.BTNPClick(Sender: TObject);
begin
  if CurrentPage < CDS_Main.FieldByName('TotalCount').AsInteger / RecordsNumber then
    CurrentPage := CurrentPage + 1;
  InitGrid();
end;

procedure TfrmDJBKKListSel.v1Column28PropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FFieldName: string;
begin

  mvalue := TcxCheckBox(Sender).EditValue;
  FFieldName := Trim(Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName);
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    if mvalue = 'False' then
      sql.Add('update CK_SXPB_CR set ISHD=0 where SPID=' + quotedstr(Trim(CDS_Main.fieldbyname('SPID').AsString)))
    else
      sql.Add('update CK_SXPB_CR set ISHD=1 where SPID=' + quotedstr(Trim(CDS_Main.fieldbyname('SPID').AsString)));

    sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
    sql.Add(' ' + quotedstr(trim(DName)));
    sql.Add(',getdate() ');
    sql.Add(',' + quotedstr(trim(self.Caption)));
    sql.Add(',' + quotedstr(trim('修改订单号')));
    sql.Add(',' + quotedstr(Trim(CDS_Main.fieldbyname('SPID').AsString)));
    sql.Add(',' + quotedstr(trim('成功')));
    sql.Add(')');
    execsql;
  end;
end;

procedure TfrmDJBKKListSel.ToolButton1Click(Sender: TObject);
begin
  if CDS_Main.IsEmpty then
    exit;
  ModalResult := 1;
end;

procedure TfrmDJBKKListSel.FormDestroy(Sender: TObject);
begin
  frmDJBKKListSel := nil;
end;

end.

