unit U_GXGL_List_DXCX;

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;

type
  TfrmGXGL_List_DXCX = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    Panel1: TPanel;
    ToolButton2: TToolButton;
    ADOQueryMain: TADOQuery;
    RM1: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_HZ: TDataSource;
    CDS_HZ: TClientDataSet;
    Label5: TLabel;
    SYRName: TEdit;
    Label1: TLabel;
    PSName: TEdit;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    v2PSName: TcxGridDBColumn;
    v2SYRName: TcxGridDBColumn;
    vLDPrice: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    TSsel: TToolButton;
    cxGrid1: TcxGrid;
    TV1: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    cxGridDBColumn5: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    DataSource1: TDataSource;
    Order_FZ: TClientDataSet;
    ADOQuery1: TADOQuery;
    V1PSXH: TcxGridDBColumn;
    Panel2: TPanel;
    ToolButton1: 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 ToolButton2Click(Sender: TObject);
    procedure ZdyNameChange(Sender: TObject);
    procedure TSselClick(Sender: TObject);
    procedure Tv2CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
    procedure TV1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
  private
    { Private declarations }
    procedure InitGrid();
  public
    fDEFstr5: string;
  end;

var
  frmGXGL_List_DXCX: TfrmGXGL_List_DXCX;

implementation

uses
  U_DataLink, U_Fun, U_ZDYHelp, U_GXGL_Input;

{$R *.dfm}

procedure TfrmGXGL_List_DXCX.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      SQL.Clear;
      sql.Add(' select * from JYOrder_Process ');
      Open;
    end;
    SCreateCDS20(ADOQueryMain, CDS_HZ);
    SInitCDSData20(ADOQueryMain, CDS_HZ);
    SCreateCDS20(ADOQueryMain, Order_FZ);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmGXGL_List_DXCX.FormDestroy(Sender: TObject);
begin
  frmGXGL_List_DXCX := nil;
end;

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

procedure TfrmGXGL_List_DXCX.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('工序查询', Tv2, '客户自定义');
  Close;
end;

procedure TfrmGXGL_List_DXCX.FormShow(Sender: TObject);
begin
  ReadCxGrid('工序查询', Tv2, '客户自定义');
  InitGrid();
end;

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

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

procedure TfrmGXGL_List_DXCX.TSselClick(Sender: TObject);
begin
  if Order_FZ.IsEmpty then
    exit;
  ModalResult := 1;
end;

procedure TfrmGXGL_List_DXCX.Tv2CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
begin
  with Order_FZ do
  begin
    Append;
    FieldByName('PSXH').Value := Order_FZ.RecordCount + 1;
    FieldByName('PSName').Value := CDS_HZ.fieldbyname('PSName').AsString;
    FieldByName('PSSH').Value := CDS_HZ.fieldbyname('PSSH').AsFloat;
    FieldByName('PSNote').Value := CDS_HZ.fieldbyname('PSNote').AsString;
    FieldByName('SYRName').Value := CDS_HZ.fieldbyname('SYRName').AsString;
    FieldByName('LDPrice').Value := CDS_HZ.fieldbyname('LDPrice').asfloat;
    FieldByName('Note').Value := CDS_HZ.fieldbyname('Note').AsString;
    FieldByName('PSID').Value := CDS_HZ.fieldbyname('PSID').AsString;
    post;
  end;
end;

procedure TfrmGXGL_List_DXCX.TV1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
begin
  Order_FZ.Delete;
end;

procedure TfrmGXGL_List_DXCX.ToolButton1Click(Sender: TObject);
begin
  try
    frmGXGL_Input := TfrmGXGL_Input.Create(Application);
    with frmGXGL_Input do
    begin
      FCYID := '';
      fDEFstr5 := self.fDEFstr5;
      if ShowModal = 1 then
      begin
        TBRafresh.Click;
      end;
    end;
  finally
    frmGXGL_Input.Free;
  end;
end;

procedure TfrmGXGL_List_DXCX.ToolButton4Click(Sender: TObject);
begin
  try
    frmGXGL_Input := TfrmGXGL_Input.Create(Application);
    with frmGXGL_Input do
    begin
      FCYID := Trim(Self.CDS_HZ.fieldbyname('PSID').AsString);
      fDEFstr5 := self.fDEFstr5;
      if ShowModal = 1 then
      begin
        TBRafresh.Click;
      end;
    end;
  finally
    frmGXGL_Input.Free;
  end;
end;

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

end.

