unit U_XXPRICE;

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, 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, cxNavigator;

type
  TfrmXXPRICE = class(TForm)
    ToolBar1: TToolBar;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    Panel1: TPanel;
    RM1: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_HZ: TDataSource;
    CDS_HZ: TClientDataSet;
    Label4: TLabel;
    price: TEdit;
    ADOQueryMain: TADOQuery;
    TBClose: TToolButton;
    ToolButton3: TToolButton;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    RKFlag, FCYID, FFFID: string;
    FFromNo, FTONO: string;
  end;

var
  frmXXPRICE: TfrmXXPRICE;

implementation

uses
  U_DataLink, U_Fun10, U_ZDYHelp;

{$R *.dfm}

procedure TfrmXXPRICE.FormDestroy(Sender: TObject);
begin
  frmXXPRICE := nil;
end;

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

procedure TfrmXXPRICE.TBCloseClick(Sender: TObject);
begin
  Close;
end;

//procedure TfrmXXPRICE.ToolButton3Click(Sender: TObject);
//begin
//  if StrToFloatDef(Price.Text, 0) = 0 then
//    Price.Text := '0';
//  try
//    with ADOQueryCmd do
//    begin
//      Close;
//      sql.Clear;
//      sql.Add(' update YF_Money_CR_Sub   ');
//      sql.Add(' set Price = ' + Price.Text);
//        // 使用IN子句批量更新
//      sql.Add(' where YF_Money_CR_Sub.yfsid in (' + FFFID + ')');
//
//
//      ExecSQL;
//    end;
//    ModalResult := 1;
//  except
//    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
//  end;
//end;
procedure TfrmXXPRICE.ToolButton3Click(Sender: TObject);
var
  IDList: TStringList;
  i: Integer;
  QuotedIDs: string;
begin
  // 如果价格输入为空或无效，设为0
  if StrToFloatDef(Price.Text, 0) = 0 then
    Price.Text := '0';

  // 检查是否有选中的ID
  if Trim(FFFID) = '' then
  begin
    Application.MessageBox('没有选择要更新的记录！', '提示信息', 0);
    Exit;
  end;

  try
    // 给每个ID添加引号
    IDList := TStringList.Create;
    try
      IDList.CommaText := FFFID;  // 将逗号分隔的字符串分解
      QuotedIDs := '';
      for i := 0 to IDList.Count - 1 do
      begin
        if QuotedIDs = '' then
          QuotedIDs := QuotedStr(IDList[i])
        else
          QuotedIDs := QuotedIDs + ',' + QuotedStr(IDList[i]);
      end;

      with ADOQueryCmd do
      begin
        Close;
        sql.Clear;
        sql.Add(' update YF_Money_CR_Sub   ');
        sql.Add(' set Price = ' + Price.Text);
        
        // 使用添加了引号的ID列表
        sql.Add(' where YF_Money_CR_Sub.yfsid in (' + QuotedIDs + ')');
        
        ExecSQL;
      end;
    finally
      IDList.Free;
    end;
    
    // 更新成功，返回1（成功标志）
    ModalResult := 1;
  except
    on E: Exception do
      Application.MessageBox(PChar(E.Message), '提示信息', 0);
  end;
end;

end.



//with ADOQueryCmd do
//    begin
//      Close;
//      sql.Clear;
//      sql.Add(' update YF_Money_CR_Sub   ');
//      sql.Add(' set Price = ' + Price.Text);
//      sql.Add(' where exists(select 1 from YF_Money_CR ');
//      sql.Add(' where YF_Money_CR.yfid = YF_Money_CR_Sub.yfid ');
//      sql.Add(' and YF_Money_CR.yfid in (select X.RTValue from [dbo].[F_Tool_SplitString](' + quotedstr(FFFID) + ','','') X)) ');
////      showmessage(sql.text);
//      ExecSQL;
//    end;


