unit U_framePDList;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, cxGraphics,
  cxControls, cxLookAndFeels, cxLookAndFeelPainters, cxContainer, cxEdit,
  cxStyles, cxCustomData, cxFilter, cxData, cxDataStorage, cxNavigator,
  dxDateRanges, dxScrollbarAnnotations, Data.DB, cxDBData, cxCheckBox,
  cxTextEdit, dxBarBuiltInMenu, Vcl.Menus, cxGridCustomPopupMenu,
  cxGridPopupMenu, Datasnap.DBClient, Data.Win.ADODB, cxGridLevel,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxClasses,
  cxGridCustomView, cxGrid, Vcl.StdCtrls, Vcl.ComCtrls, Vcl.ToolWin,
  Vcl.ExtCtrls, dxSkinsCore, dxSkinsDefaultPainters, cxMemo, cxLabel,
  cxMaskEdit, cxDropDownEdit;

type
  TframePDList = class(TFrame)
    ADOQueryMain: TADOQuery;
    ADOQueryCmd: TADOQuery;
    ADOQueryTemp: TADOQuery;
    CDS_HZ: TClientDataSet;
    DS_HZ: TDataSource;
    cxGridPopupMenu2: TcxGridPopupMenu;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    Panel_pd: TPanel;
    LabelPD: TLabel;
    cxLabel336: TcxLabel;
    pd_speed: TcxTextEdit;
    cxLabel344: TcxLabel;
    pd_temperature: TcxTextEdit;
    procedure TBRafreshClick(Sender: TObject);

    procedure ToolButton5Click(Sender: TObject);

  private

    { Private declarations }
  public
    procedure InitGrid();
    function SaveData(mPSID : string): Boolean;
    { Public declarations }
  end;

implementation

uses
  U_DataLink, U_RTFun, U_LabelPrint;
{$R *.dfm}

procedure TframePDList.InitGrid();
begin
//  POSNO.SetFocus;
//  try
//    ADOQueryMain.DisableControls;
//    with ADOQueryMain do
//    begin
//      Close;
//      SQL.Clear;
//      sql.Add(' select A.* from  BS_Position A order by POSNO ');
//      Open;
//    end;
//    SCreateCDS(ADOQueryMain, CDS_HZ);
//    SInitCDSData(ADOQueryMain, CDS_HZ);
//  finally
//    ADOQueryMain.EnableControls;
//    ToolButton2.Click;
//  end;
end;

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



procedure TframePDList.ToolButton5Click(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then
    Exit;

  if CDS_HZ.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('请先选择数据！', '提示', 0);
    Exit;
  end;

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

  with CDS_HZ do
  begin
    while not Eof do
    begin
      if CDS_HZ.Locate('SSel', True, []) = True then
      begin
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('delete BS_Position where POSID=' + QuotedStr(CDS_HZ.FieldByName('POSID').AsString));
          ExecSQL;
        end;
      end;

      CDS_HZ.Edit;
      CDS_HZ.FieldByName('SSel').Value := False;
      CDS_HZ.Post;
      Next;
    end;
  end;
  InitGrid();
end;


function TframePDList.SaveData(mPSID : string): Boolean;
var
  MaxProcessID, MaxBCPID, MaxPSID, MaxDTMID, mDTMID, DTMPSlist: string;
  maxsubid1, maxsubid2, maxsubid3, maxsubid4, maxsubid5, maxsubid6, mmaxgx: string;
begin
  try


////////////////       保存主表      //////////////////////
      with ADOQueryCmd do
      begin
        Close;
        SQL.Clear;
        sql.Add('select * from Bs_Cloth_GY_Main where PSID=''' + Trim(mPSID) + '''');
        Open;
      end;
      with ADOQueryCmd do
      begin
        if Trim(mPSID) = '' then
        begin
          Append;
        end
        else
        begin
          Edit;
        end;
        FieldByName('PSID').Value := Trim(mPSID);

          RTSetsavedata(ADOQueryCmd, 'Bs_Cloth_GY_Main', panel_pd, 2);
          ADOQueryCmd.Post;




      end;
////////////////       保存主表结束          //////////////////////



//    FPSID := maxId;
    Result := True;
  except
    Result := False;

    Application.MessageBox('保存失败!', '提示', 0);
  end;
end;




end.

