unit U_GKManageSel;

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, cxPC, cxCheckComboBox, cxDropDownEdit, Menus, RM_e_Xls,
  cxLookAndFeels, cxLookAndFeelPainters, cxNavigator, dxDateRanges,
  dxBarBuiltInMenu, U_BaseList, RM_BarCode, dxScrollbarAnnotations, cxContainer,
  cxProgressBar, dxSkinsCore, dxSkinsDefaultPainters;

type
  TfrmGKManageSel = class(TfrmBaseList)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    TbFilter: TToolButton;
    ADOQueryMain: TADOQuery;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cxGridLevel1: TcxGridLevel;
    GPM_1: TcxGridPopupMenu;
    DS_HZ: TDataSource;
    CDS_HZ: TClientDataSet;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    Panel1: TPanel;
    Label1: TLabel;
    GKBH: TcxTextEdit;
    Tv2Column4: TcxGridDBColumn;
    Tv2Column10: TcxGridDBColumn;
    Tv2Column1: TcxGridDBColumn;
    Tv2Column3: TcxGridDBColumn;
    Tv2Column5: TcxGridDBColumn;
    Tv2Column6: TcxGridDBColumn;
    Tv2Column7: TcxGridDBColumn;
    ToolButton1: TToolButton;
    Tv2Column2: TcxGridDBColumn;
    Tv2Column8: TcxGridDBColumn;
    ToolButton2: TToolButton;
    ToolButton3: TToolButton;
    ToolButton4: TToolButton;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure CustomerChange(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure MCNOPropertiesChange(Sender: TObject);
    procedure Tv2DblClick(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);

  private
    { Private declarations }
    procedure InitGrid();
  public
    fFlag: integer;
    { Public declarations }
    RKFlag, FCYID, fmanage: string;
  end;

var
  frmGKManageSel: TfrmGKManageSel;

implementation

uses
  U_DataLink, U_RTFun, U_ZDYHelp, U_LabelPrint, U_EmployeeSel, U_GKInput;

{$R *.dfm}

procedure TfrmGKManageSel.InitGrid();
begin
  GKBH.SetFocus;
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      SQL.Clear;
      sql.Add(' select A.*,kcqty=( select sum(IOQtyFlag*qty) from Bs_Product_IO e where e.p_code=a.gkbh and stkname=''物料'') from  BS_GK A  ');
//      showmessage(Sql.text);
      Open;
    end;
    SCreateCDS(ADOQueryMain, CDS_HZ);
    SInitCDSData(ADOQueryMain, CDS_HZ);
  finally
    ADOQueryMain.EnableControls;
    TbFilter.Click;
  end;
end;

procedure TfrmGKManageSel.MCNOPropertiesChange(Sender: TObject);
var
  sql: string;
begin
  if ADOQueryMain.Active then
  begin
    sql := SGetFilters(Panel1, 1, 2);
    SDofilter(ADOQueryMain, sql);
    SCreateCDS(ADOQueryMain, CDS_HZ);
    SInitCDSData(ADOQueryMain, CDS_HZ);
  end;
end;

procedure TfrmGKManageSel.FormDestroy(Sender: TObject);
begin
  inherited;
  frmGKManageSel := nil;
end;

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

procedure TfrmGKManageSel.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid(Trim(Self.Caption), Tv2, '钢扣信息选择');
  Close;
end;

procedure TfrmGKManageSel.FormShow(Sender: TObject);
begin
  inherited;
  ReadCxGrid(Trim(Self.Caption), Tv2, '钢扣信息选择');
  InitGrid();
end;

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

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

procedure TfrmGKManageSel.ToolButton2Click(Sender: TObject);
begin
  try
    frmGKInput := TfrmGKInput.Create(Application);
    with frmGKInput do
    begin
      FGKID := '';
      if ShowModal = 1 then
      begin
        InitGrid();
      end;
    end;
  finally
    frmGKInput.Free;
  end;
end;

procedure TfrmGKManageSel.ToolButton3Click(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then
    exit;
  try
    frmGKInput := TfrmGKInput.Create(Application);
    with frmGKInput do
    begin
      FGKID := Trim(Self.CDS_HZ.fieldbyname('GKID').AsString);
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmGKInput.Free;
  end;
end;

procedure TfrmGKManageSel.ToolButton4Click(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then
    Exit;

  if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
    Exit;

  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('delete BS_GK where GKID=' + QuotedStr(CDS_HZ.FieldByName('GKID').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('GKID：' + trim(CDS_HZ.FieldByName('GKID').AsString) + ';GKno:' + trim(CDS_HZ.FieldByName('GKBH').AsString))));
    sql.Add(',' + quotedstr(trim('成功')));
    sql.Add(')');
    ExecSQL;
  end;

  InitGrid();

end;

procedure TfrmGKManageSel.Tv2DblClick(Sender: TObject);
begin
  ModalResult := 1;
end;

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

procedure TfrmGKManageSel.N1Click(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then
    exit;
  SelOKNo(CDS_HZ, True);
end;

procedure TfrmGKManageSel.N2Click(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then
    exit;
  SelOKNo(CDS_HZ, False);
end;

procedure TfrmGKManageSel.CustomerChange(Sender: TObject);
begin
  TbFilter.Click;
end;

procedure TfrmGKManageSel.FormCreate(Sender: TObject);
begin
  inherited;
  fmanage := Trim(DParameters1);
end;

end.

