unit U_WarpRollerkCList;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, ToolWin, StdCtrls, ExtCtrls, cxStyles, cxCustomData,
  cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData,
  cxButtonEdit, cxDropDownEdit, cxGridLevel, cxGridCustomTableView,
  cxGridTableView, cxGridDBTableView, cxClasses, cxControls, cxGridCustomView,
  cxGrid, DBClient, ADODB, cxGridCustomPopupMenu, cxGridPopupMenu, cxCheckBox,
  RM_Common, RM_Class, RM_GridReport, RM_System, RM_Dataset, MMSystem, Menus,
  BtnEdit, cxPC, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator, dxSkinsCore,
  dxSkinsDefaultPainters, dxSkinscxPCPainter, dxBarBuiltInMenu,
  dxSkinBlack, dxSkinBlue, dxSkinBlueprint, dxSkinCaramel, dxSkinCoffee,
  dxSkinDarkRoom, dxSkinDarkSide, dxSkinDevExpressDarkStyle,
  dxSkinDevExpressStyle, dxSkinFoggy, dxSkinGlassOceans,
  dxSkinHighContrast, dxSkiniMaginary, dxSkinLilian, dxSkinLiquidSky,
  dxSkinLondonLiquidSky, dxSkinMcSkin, dxSkinMetropolis,
  dxSkinMetropolisDark, dxSkinMoneyTwins, dxSkinOffice2007Black,
  dxSkinOffice2007Blue, dxSkinOffice2007Green, dxSkinOffice2007Pink,
  dxSkinOffice2007Silver, dxSkinOffice2010Black, dxSkinOffice2010Blue,
  dxSkinOffice2010Silver, dxSkinOffice2013DarkGray,
  dxSkinOffice2013LightGray, dxSkinOffice2013White, dxSkinPumpkin,
  dxSkinSeven, dxSkinSevenClassic, dxSkinSharp, dxSkinSharpPlus,
  dxSkinSilver, dxSkinSpringTime, dxSkinStardust, dxSkinSummer2008,
  dxSkinTheAsphaltWorld, dxSkinValentine, dxSkinVS2010, dxSkinWhiteprint,
  dxSkinXmas2008Blue;

type
  TfrmWarpRollerkCList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBExport: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    ADOQueryCmd: TADOQuery;
    ADOQueryTmp: TADOQuery;
    DataSource1: TDataSource;
    CDS_Main: TClientDataSet;
    cxGridPopupMenu1: TcxGridPopupMenu;
    TOk: TToolButton;
    Label7: TLabel;
    ADOQueryPrint: TADOQuery;
    RMDB_Main: TRMDBDataSet;
    RM1: TRMGridReport;
    ADOQueryMain: TADOQuery;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    ToolButton2: TToolButton;
    CDS_KCYJ: TClientDataSet;
    DS_KCYJ: TDataSource;
    cxGridPopupMenu2: TcxGridPopupMenu;
    Label15: TLabel;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Ssel: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    v1CRTime: TcxGridDBColumn;
    Tv1Column3: TcxGridDBColumn;
    Tv1Column4: TcxGridDBColumn;
    Tv1Column1: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    Tv1Column5: TcxGridDBColumn;
    Tv1Column6: TcxGridDBColumn;
    Tv1Column7: TcxGridDBColumn;
    Tv1Column8: TcxGridDBColumn;
    Tv1Column9: TcxGridDBColumn;
    Tv1Column10: TcxGridDBColumn;
    v1Note: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    Label1: TLabel;
    Label2: TLabel;
    Label4: TLabel;
    Label17: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    WBCode: TEdit;
    PCID: TEdit;
    Label5: TLabel;
    edtKaNo: TEdit;
    Label6: TLabel;
    P_codeNAME: TEdit;
    Tv1Column11: TcxGridDBColumn;
    Panel3: TPanel;
    Panel4: TPanel;
    cxTabControl1: TcxTabControl;
    Tv1Column12: TcxGridDBColumn;
    Tv1Column13: TcxGridDBColumn;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormDestroy(Sender: TObject);
    procedure WBCodeChange(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TOkClick(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure cxPageControl1Change(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure JZRKNoChange(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure Tv1DblClick(Sender: TObject);
    procedure P_codeNAMEKeyPress(Sender: TObject; var Key: Char);
  private
    procedure InitGrid();
    procedure SetStatus();
    { Private declarations }
  public
    fCKName, canshu1: string;
    fType: Integer;
    { Public declarations }
  end;

var
  frmWarpRollerkCList: TfrmWarpRollerkCList;

implementation

uses
  U_DataLink, U_Fun10, U_ZDYHelp, U_Fun;
{$R *.dfm}

procedure TfrmWarpRollerkCList.SetStatus();
var
  i: Integer;
begin

  case cxTabControl1.TabIndex of
    0:
      begin
        ClearOrHideControls(Panel1, '0', True, True);
        ClearOrHideControls(Panel1, '1', True, False);

        for i := 0 to tv1.ColumnCount - 1 do
        begin
          tv1.Columns[i].Visible := false;
        end;
        IsVisibleTV(Panel1, TV1, '0', True);
        Tv1Column3.Visible := True;
        Tv1Column4.Visible := True;
        Tv1Column6.Visible := True;
        Tv1Column10.Visible := True;
        Tv1Column12.Visible := True;

      end;

    1:
      begin
        for i := 0 to tv1.ColumnCount - 1 do
        begin
          tv1.Columns[i].Visible := True;
        end;
        Tv1Column12.Visible := false;

        ClearOrHideControls(Panel1, '0', False, True);
        ClearOrHideControls(Panel1, '1', False, True);

      end;
  end;
end;


//  if fType = 10 then
//  begin
//    TOk.Visible := true;
//    v1Ssel.Visible := true;
//  end
//  else
//  begin
//    TOk.Visible := False;
//    v1Ssel.Visible := False;
//  end;

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

  with adoqueryMain do
  begin
    close;
    sql.Clear;

    case cxTabControl1.TabIndex of
      0:   /////////////////////////订单汇总//////////////////////////////
        begin
          Pwhere := SGetFilters(Panel1, 1, 2);
          if trim(Pwhere) <> '' then
            fwhere := fwhere + ' AND ' + trim(Pwhere);

          sql.Add(' select C_TOUWEN,sum(C_Len)C_Len,COUNT(*)ZS,P_CODE,P_codeNAME  ');

          SQL.Add('from V_JZ_KC   ');

          sql.Add(' WHERE   CRTime>=''' + formatdateTime('yyyy-MM-dd', begdate.Date) + ''' ');
          sql.Add(' and  CRTime<''' + formatdateTime('yyyy-MM-dd', enddate.Date + 1) + ''' ');
          SQL.Add(fwhere);
          SQL.Add('GROUP BY P_CODE,P_codeNAME,C_TOUWEN');
        end;
      1:      /////////////////////////明细//////////////////////////////
        begin

          Pwhere := SGetFilters(Panel1, 1, 2);
          if trim(Pwhere) <> '' then
            fwhere := fwhere + ' and ' + trim(Pwhere);
          sql.Add(' select  * ');

          SQL.Add('from V_JZ_KC  ');

          sql.Add(' WHERE  CRTime>=''' + formatdateTime('yyyy-MM-dd', begdate.Date) + ''' ');
          sql.Add(' and  CRTime<''' + formatdateTime('yyyy-MM-dd', enddate.Date + 1) + ''' ');
          SQL.Add(fwhere);
        end;
    end;

    open;
  end;
  SCreateCDS20(adoqueryMain, CDS_Main);
  SInitCDSData20(adoqueryMain, CDS_Main);

end;

procedure TfrmWarpRollerkCList.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  writeCxGrid(self.Caption, Tv1, '仓储管理');
  Action := cafree;
end;

procedure TfrmWarpRollerkCList.FormDestroy(Sender: TObject);
begin
  frmWarpRollerkCList := nil;
end;

procedure TfrmWarpRollerkCList.WBCodeChange(Sender: TObject);
begin
  if adoqueryMain.Active = False then
    Exit;
  SDofilter(adoqueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS20(adoqueryMain, CDS_Main);
  SInitCDSData20(adoqueryMain, CDS_Main);
end;

procedure TfrmWarpRollerkCList.FormShow(Sender: TObject);
begin
  readCxGrid(self.Caption, Tv1, '仓储管理');
  SetStatus();
  InitGrid();
end;

procedure TfrmWarpRollerkCList.TBCloseClick(Sender: TObject);
begin
  close;
end;

procedure TfrmWarpRollerkCList.TBRafreshClick(Sender: TObject);
begin
  initGrid();
end;

procedure TfrmWarpRollerkCList.TBExportClick(Sender: TObject);
begin
  if CDS_Main.IsEmpty then
    Exit;
  TcxGridToExcel(self.Caption, cxgrid1);
end;

procedure TfrmWarpRollerkCList.TOkClick(Sender: TObject);
begin
  if CDS_Main.IsEmpty then
    Exit;
  if CDS_Main.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('请先选择库存数据！', '提示', 0);
    Exit;
  end;
  ModalResult := 1;
end;

procedure TfrmWarpRollerkCList.N1Click(Sender: TObject);
begin
  SelOKNo(CDS_Main, true);
end;

procedure TfrmWarpRollerkCList.N2Click(Sender: TObject);
begin
  SelOKNo(CDS_Main, false);

end;

procedure TfrmWarpRollerkCList.ToolButton2Click(Sender: TObject);
begin
  if adoqueryMain.Active = False then
    Exit;
  SDofilter(adoqueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS20(adoqueryMain, CDS_Main);
  SInitCDSData20(adoqueryMain, CDS_Main);
end;

procedure TfrmWarpRollerkCList.cxPageControl1Change(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmWarpRollerkCList.FormCreate(Sender: TObject);
begin
  EndDate.Date := SGetServerDate10(ADOQueryTmp);
  BegDate.Date := EndDate.Date - 30;
end;

procedure TfrmWarpRollerkCList.JZRKNoChange(Sender: TObject);
begin
  ToolButton2.Click();
end;

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

procedure TfrmWarpRollerkCList.Tv1DblClick(Sender: TObject);
var
  Tabint: integer;
begin
  Tabint := cxTabControl1.TabIndex;
  case Tabint of
    0:
      begin
        AssignmentControls(Panel1, CDS_Main, '0');
        cxTabControl1.TabIndex := 1;
      end;
  end;
end;

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

end.

