unit U_BuDongKCList;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxGraphics, cxCustomData, cxStyles, cxTL, cxMaskEdit, DB, ADODB,
  cxInplaceContainer, cxDBTL, cxControls, cxTLData, ComCtrls, ToolWin, StdCtrls,
  cxFilter, cxData, cxDataStorage, cxEdit, cxDBData, DBClient,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, ExtCtrls,
  cxSplitter, cxGridLevel, cxClasses, cxGridCustomView, cxGrid,
  cxGridCustomPopupMenu, cxGridPopupMenu, RM_Dataset, RM_System, RM_Common,
  RM_Class, RM_GridReport, IdBaseComponent, IdComponent, IdTCPConnection,
  IdTCPClient, IdFTP, ShellAPI, IniFiles, cxCheckBox, cxCalendar, cxButtonEdit,
  cxTextEdit, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator,
  cxDropDownEdit, Menus, dxSkinsCore, 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, dxSkinsDefaultPainters, dxSkinValentine,
  dxSkinVS2010, dxSkinWhiteprint, dxSkinXmas2008Blue, dxSkinscxPCPainter;

type
  TfrmBuDongKCList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    Panel1: TPanel;
    ToolButton2: TToolButton;
    ADOQueryMain: TADOQuery;
    Label3: TLabel;
    SPName: TEdit;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_HZ: TDataSource;
    CDS_HZ: TClientDataSet;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    v2Column6: TcxGridDBColumn;
    v2Column11: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    ToolButton1: TToolButton;
    v2Column2: TcxGridDBColumn;
    v2Column3: TcxGridDBColumn;
    v2Column4: TcxGridDBColumn;
    ToolButton3: TToolButton;
    ToolButton4: TToolButton;
    v2Column7: TcxGridDBColumn;
    Tv2Column1: TcxGridDBColumn;
    Tv2Column2: TcxGridDBColumn;
    Tv2Column4: TcxGridDBColumn;
    Tv2Column5: TcxGridDBColumn;
    Tv2Column6: TcxGridDBColumn;
    Tv2Column7: TcxGridDBColumn;
    Tv2Column8: TcxGridDBColumn;
    Tv2Column9: TcxGridDBColumn;
    ToolButton5: TToolButton;
    Label1: TLabel;
    OrderNo: TEdit;
    Label2: TLabel;
    ColorName: TEdit;
    Label4: TLabel;
    MF: TEdit;
    Label5: TLabel;
    KZ: TEdit;
    Label6: TLabel;
    ColorNote: TEdit;
    Label7: TLabel;
    WeiZhi: TEdit;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure SPNameChange(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
  private
    { Private declarations }
    procedure InitGrid();
  public
     canshu1:string;
  end;

//var
 // frmBuDongKCList: TfrmBuDongKCList;

implementation

uses
  U_DataLink, U_RTFun, U_BuDongKCInPut;

{$R *.dfm}

procedure TfrmBuDongKCList.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      SQL.Clear;
      sql.Add(' select * from CP_BuDong where  ZFFlag=0 and type is null order by CRTime  ');
      Open;
    end;
    SCreateCDS20(ADOQueryMain, CDS_HZ);
    SInitCDSData20(ADOQueryMain, CDS_HZ);
  finally
    ADOQueryMain.EnableControls;
  end;
  ToolButton2.Click;
end;

procedure TfrmBuDongKCList.FormDestroy(Sender: TObject);
begin
  //frmBuDongKCList := nil;
end;

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

procedure TfrmBuDongKCList.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('不动库存管理', Tv2, '不动库存');
  Close;
end;

procedure TfrmBuDongKCList.FormShow(Sender: TObject);
begin
  if Trim(canshu1)='查询' then
  begin
    ToolButton1.Visible:=False;
    ToolButton3.Visible:=False;
    ToolButton4.Visible:=False;
  end;
  ReadCxGrid('不动库存管理', Tv2, '不动库存');
  InitGrid();
end;

procedure TfrmBuDongKCList.TBRafreshClick(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmBuDongKCList.ToolButton2Click(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
    SCreateCDS20(ADOQueryMain, CDS_HZ);
    SInitCDSData20(ADOQueryMain, CDS_HZ);
  end;
end;

procedure TfrmBuDongKCList.SPNameChange(Sender: TObject);
begin
  ToolButton2.Click;
end;

procedure TfrmBuDongKCList.ToolButton1Click(Sender: TObject);
begin
  try
    frmBuDongKCInPut := TfrmBuDongKCInPut.Create(Application);
    with frmBuDongKCInPut do
    begin
      FCYID := '';
      if ShowModal = 1 then
      begin
        TBRafresh.Click;
      end;
    end;
  finally
    frmBuDongKCInPut.Free;
  end;
end;

procedure TfrmBuDongKCList.ToolButton3Click(Sender: TObject);
begin
  try
    frmBuDongKCInPut := TfrmBuDongKCInPut.Create(Application);
    with frmBuDongKCInPut do
    begin
      FCYID := Trim(Self.CDS_HZ.fieldbyname('CBID').AsString);
      frmBuDongKCInPut.ToolButton1.Visible:=False;
      frmBuDongKCInPut.ToolButton2.Visible:=False;
      if ShowModal = 1 then
      begin
        TBRafresh.Click;
      end;
    end;
  finally
    frmBuDongKCInPut.Free;
  end;
end;

procedure TfrmBuDongKCList.ToolButton4Click(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then
    Exit;
  if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  if Trim(CDS_HZ.fieldbyname('CBID').AsString) <> '' then
  begin
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add(' UPdate CP_BuDong Set ZFFlag=1,ZFTime=Getdate(),ZFPerson=''' + Trim(DName) + '''');
      sql.Add(' where CBID=''' + Trim(CDS_HZ.fieldbyname('CBID').AsString) + '''');
      ExecSQL;
    end;
  end;
  CDS_HZ.Delete;
end;

procedure TfrmBuDongKCList.ToolButton5Click(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then Exit;
  TcxGridToExcel('不动库存',cxGrid2);
end;

end.

