unit U_YarnListSel;

interface

uses
  Windows, Messages, SysUtils, StrUtils, Variants, Classes, Graphics, Controls,
  Forms, ComObj, 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, Menus, cxLookAndFeelPainters, cxButtons, cxContainer, cxImage,
  cxDBEdit, cxLookAndFeels, cxNavigator;

type
  FdDy = record
    inc: integer; //客户端套接字句柄
    FDdys: string[32]; //客户端套接字
    FdDysName: string[32]; //客户端套接字
  end;

  TfrmYarnListSel = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    Panel1: TPanel;
    ToolButton2: TToolButton;
    ADOQueryMain: TADOQuery;
    ToolButton1: TToolButton;
    RM1: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    Label3: TLabel;
    Y_CodeName: TEdit;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cxGridLevel1: TcxGridLevel;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_HZ: TDataSource;
    CDS_HZ: TClientDataSet;
    v2Column6: TcxGridDBColumn;
    Label1: TLabel;
    Y_Code: TEdit;
    OpenDialog1: TOpenDialog;
    v2Column17: TcxGridDBColumn;
    v2Column4: TcxGridDBColumn;
    v2Column8: TcxGridDBColumn;
    ToolButton3: TToolButton;
    ToolButton4: TToolButton;
    ToolButton5: TToolButton;
    ToolButton6: 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 ToolButton2Click(Sender: TObject);
    procedure Y_CodeNameChange(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure FormResize(Sender: TObject);
    procedure Tv2FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
    procedure Tv2DblClick(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure ToolButton6Click(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
  private
    fFlileFlag: string;
    { Private declarations }
    procedure InitGrid();
    procedure InitImage();
    procedure LookImage(FileName: string);
  public
    fkhType: string;
    canshu1: string;
    dFdDy: array[0..20] of FdDy; //客户端连接数组
  end;

var
  frmYarnListSel: TfrmYarnListSel;

implementation

uses
  U_DataLink, U_Fun, U_ZDYHelp, U_YarnInput;

{$R *.dfm}
procedure TfrmYarnListSel.LookImage(FileName: string);
begin

end;

procedure TfrmYarnListSel.InitImage();
begin

end;

procedure TfrmYarnListSel.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      SQL.Clear;
      sql.Add(' select  *');
      sql.Add(' from BS_Yarn A ');
      sql.Add(' order by FillTime desc ');
      Open;
    end;
    SCreateCDS20(ADOQueryMain, CDS_HZ);
    SInitCDSData20(ADOQueryMain, CDS_HZ);
  finally
    ADOQueryMain.EnableControls;
    ToolButton2.Click;
  end;
end;

procedure TfrmYarnListSel.FormDestroy(Sender: TObject);
begin
  frmYarnListSel := nil;
end;

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

procedure TfrmYarnListSel.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('纱线资料13', Tv2, '客户自定义');
  Close;
end;

procedure TfrmYarnListSel.FormShow(Sender: TObject);
begin
  ReadCxGrid('纱线资料13', Tv2, '客户自定义');
  InitGrid();
end;

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

procedure TfrmYarnListSel.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 TfrmYarnListSel.Y_CodeNameChange(Sender: TObject);
begin
  ToolButton2.Click;
end;

procedure TfrmYarnListSel.ToolButton1Click(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    Exit;
  TcxGridToExcel(self.Caption, cxgrid2);
//  SelExportData(Tv2,ADOQueryMain,'产品资料列表');
end;

procedure TfrmYarnListSel.FormResize(Sender: TObject);
begin
//  Pan_image.Left:=self.Width-Pan_image.Width-30;
 // Pan_image.Top:=self.Height-Pan_image.Height-80;
end;

procedure TfrmYarnListSel.Tv2FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
begin
  InitImage();
end;

procedure TfrmYarnListSel.Tv2DblClick(Sender: TObject);
begin
  ToolButton3.Click;
end;

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

procedure TfrmYarnListSel.ToolButton4Click(Sender: TObject);
begin
  try
    frmYarnInput := TfrmYarnInput.Create(Application);
    with frmYarnInput do
    begin
      FCYID := '';
//      fkhType := self.fkhType;
//      fFlileFlag := self.fFlileFlag;
      if ShowModal = 1 then
      begin
        TBRafresh.Click;
      end;
    end;
  finally
    frmYarnInput.Free;
  end;
end;

procedure TfrmYarnListSel.ToolButton6Click(Sender: TObject);
begin
  try
    frmYarnInput := TfrmYarnInput.Create(Application);
    with frmYarnInput do
    begin
      FCYID := Trim(Self.CDS_HZ.fieldbyname('ATID').AsString);
      fkhType := self.fkhType;
      fFlileFlag := self.fFlileFlag;
      if ShowModal = 1 then
      begin
        TBRafresh.Click;
      end;
    end;
  finally
    frmYarnInput.Free;
  end;
end;

procedure TfrmYarnListSel.ToolButton5Click(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then
    Exit;
  if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  if Trim(CDS_HZ.fieldbyname('ATID').AsString) <> '' then
  begin
    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('delete BS_SX_YDang where ATID=''' + Trim(CDS_HZ.fieldbyname('ATID').AsString) + '''');
      sql.Add('delete BS_SX_ZC where ZATID=''' + Trim(CDS_HZ.fieldbyname('ATID').AsString) + '''');
      ExecSQL;
    end;
  end;
  CDS_HZ.Delete;
end;

end.

