unit U_TatClothInfo_CB;

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, jpeg, U_SLT, ComObj, Menus,
  cxLookAndFeels, cxLookAndFeelPainters, cxTLdxBarBuiltInMenu, cxNavigator,
  dxBarBuiltInMenu, cxPC, Math, RM_BarCode, dxDateRanges,
  IdExplicitTLSClientServerBase, U_BaseList, cxContainer, dxDBBarCode, dxBarCode,
  Vcl.Clipbrd, cxTextEdit, BtnEdit, StrUtils, cxButtonEdit,
  dxScrollbarAnnotations, dxCore, dxCoreClasses, dxHashUtils, dxSpreadSheetCore,
  dxSpreadSheetCoreFormulas, dxSpreadSheetCoreHistory, dxSpreadSheetCoreStyles,
  dxSpreadSheetCoreStrs, dxSpreadSheetConditionalFormatting,
  dxSpreadSheetConditionalFormattingRules, dxSpreadSheetClasses,
  dxSpreadSheetContainers, dxSpreadSheetFormulas, dxSpreadSheetHyperlinks,
  dxSpreadSheetFunctions, dxSpreadSheetStyles, dxSpreadSheetGraphics,
  dxSpreadSheetPrinting, dxSpreadSheetTypes, dxSpreadSheetUtils,
  dxSpreadSheetFormattedTextUtils, dxSpreadSheet, dxSkinsCore,
  dxSkinsDefaultPainters, cxProgressBar, dxSkinBasic, 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, dxSkinOffice2016Colorful, dxSkinOffice2016Dark,
  dxSkinOffice2019Black, dxSkinOffice2019Colorful, dxSkinOffice2019DarkGray,
  dxSkinOffice2019White, dxSkinPumpkin, dxSkinSeven, dxSkinSevenClassic,
  dxSkinSharp, dxSkinSharpPlus, dxSkinSilver, dxSkinSpringtime, dxSkinStardust,
  dxSkinSummer2008, dxSkinTheAsphaltWorld, dxSkinTheBezier, dxSkinValentine,
  dxSkinVisualStudio2013Blue, dxSkinVisualStudio2013Dark,
  dxSkinVisualStudio2013Light, dxSkinVS2010, dxSkinWhiteprint, dxSkinWXI,
  dxSkinXmas2008Blue;

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

  TfrmTatClothInfo_CB = class(TfrmBaseList)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBDel: TToolButton;
    TBClose: TToolButton;
    DS_Tree: TDataSource;
    ADOQueryTree: TADOQuery;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    GPM_1: TcxGridPopupMenu;
    Tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    cxSplitter1: TcxSplitter;
    Panel1: TPanel;
    TBFilter: TToolButton;
    v1CYNo: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    DS_1: TDataSource;
    ADOQueryMain: TADOQuery;
    CDS_1: TClientDataSet;
    v1Column12: TcxGridDBColumn;
    TBExport: TToolButton;
    RM1: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    ODPat: TOpenDialog;
    IdFTP1: TIdFTP;
    SaveDialog1: TSaveDialog;
    TBUP: TToolButton;
    TBCopy: TToolButton;
    Panel2: TPanel;
    v1SSel: TcxGridDBColumn;
    DSCYNO: TDataSource;
    CDS_CYNO: TClientDataSet;
    Panel5: TPanel;
    cxDBTreeList1: TcxDBTreeList;
    cxDBTreeList1cxDBTreeListColumn2: TcxDBTreeListColumn;
    Label11: TLabel;
    Label12: TLabel;
    Panel3: TPanel;
    adoqueryPicture: TADOQuery;
    v1Column1: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    TBAdd: TToolButton;
    TBEdit: TToolButton;
    TBMLEdit: TToolButton;
    OpenDialog1: TOpenDialog;
    PM_1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    v1Column11: TcxGridDBColumn;
    Panel7: TPanel;
    Panel4: TPanel;
    Label14: TLabel;
    LBCPAP1: TLabel;
    Button1: TButton;
    Button2: TButton;
    TCBNOR1: TComboBox;
    RMBarCodeObject1: TRMBarCodeObject;
    Tv1Column5: TcxGridDBColumn;
    Tv1Column6: TcxGridDBColumn;
    Tv1Column7: TcxGridDBColumn;
    ToolButton1: TToolButton;
    DataSource3: TDataSource;
    CDS_Sub: TClientDataSet;
    Tv1Column9: TcxGridDBColumn;
    Tv1Column11: TcxGridDBColumn;
    GPM_2: TcxGridPopupMenu;
    ToolButton2: TToolButton;
    N3: TMenuItem;
    CDS_Tree: TClientDataSet;
    ADOQueryPrint: TADOQuery;
    CDS_Label: TClientDataSet;
    Tv1Column1: TcxGridDBColumn;
    ToolButton3: TToolButton;
    Tv1Column3: TcxGridDBColumn;
    DS_2: TDataSource;
    CDS_2: TClientDataSet;
    GPM_4: TcxGridPopupMenu;
    CDS_4: TClientDataSet;
    DS_4: TDataSource;
    ADO_2: TADOQuery;
    ADO_4: TADOQuery;
    Label3: TLabel;
    Label4: TLabel;
    C_Name: TcxTextEdit;
    C_Code: TcxTextEdit;
    Tv1Column2: TcxGridDBColumn;
    Tv1Column8: TcxGridDBColumn;
    Tv1Column10: TcxGridDBColumn;
    Tv1Column4: TcxGridDBColumn;
    Tv1Column12: TcxGridDBColumn;
    btn1: TToolButton;
    ToolButton4: TToolButton;
    ToolButton5: TToolButton;
    Tv1Column13: TcxGridDBColumn;
    Tv1Column14: TcxGridDBColumn;
    Tv1Column15: TcxGridDBColumn;
    Tv1Column16: TcxGridDBColumn;
    Tv1Column17: TcxGridDBColumn;
    Tv1Column18: TcxGridDBColumn;
    Tv1Column19: TcxGridDBColumn;
    Tv1Column20: TcxGridDBColumn;
    Tv1Column21: TcxGridDBColumn;
    Tv1Column22: TcxGridDBColumn;
    Tv1Column23: TcxGridDBColumn;
    Tv1Column24: TcxGridDBColumn;
    Tv1Column25: TcxGridDBColumn;
    Tv1Column26: TcxGridDBColumn;
    Tv1Column27: TcxGridDBColumn;
    Tv1Column28: TcxGridDBColumn;
    Panel8: TPanel;
    cxPageControl3: TcxPageControl;
    cxTabSheet1: TcxTabSheet;
    Panel6: TPanel;
    cxPageControl2: TcxPageControl;
    cxGrid2: TcxGrid;
    TV2: TcxGridDBTableView;
    TV2Column1: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    cxGridDBColumn5: TcxGridDBColumn;
    cxGridDBColumn8: TcxGridDBColumn;
    TV2Column2: TcxGridDBColumn;
    TV2Column3: TcxGridDBColumn;
    TV2Column4: TcxGridDBColumn;
    TV2Column5: TcxGridDBColumn;
    TV2Column6: TcxGridDBColumn;
    TV2Column7: TcxGridDBColumn;
    TV2Column8: TcxGridDBColumn;
    TV2Column9: TcxGridDBColumn;
    TV2Column10: TcxGridDBColumn;
    TV2Column11: TcxGridDBColumn;
    TV2Column12: TcxGridDBColumn;
    TV2Column13: TcxGridDBColumn;
    TV2Column14: TcxGridDBColumn;
    TV2Column15: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    cxTabSheet2: TcxTabSheet;
    cxGrid4: TcxGrid;
    Tv4: TcxGridDBTableView;
    Tv4Column1: TcxGridDBColumn;
    v2Column10: TcxGridDBColumn;
    cxGridDBColumn22: TcxGridDBColumn;
    v2Column2: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    Tv4Column2: TcxGridDBColumn;
    Tv4Column3: TcxGridDBColumn;
    Tv4Column4: TcxGridDBColumn;
    Tv4Column5: TcxGridDBColumn;
    Tv4Column6: TcxGridDBColumn;
    Tv4Column7: TcxGridDBColumn;
    Tv4Column8: TcxGridDBColumn;
    Tv4Column9: TcxGridDBColumn;
    Tv4Column10: TcxGridDBColumn;
    Tv4Column11: TcxGridDBColumn;
    Tv4Column12: TcxGridDBColumn;
    Tv4Column13: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    cxTabSheet3: TcxTabSheet;
    GroupBox1: TGroupBox;
    ScrollBox1: TScrollBox;
    cxTabSheet4: TcxTabSheet;
    QZF: TMemo;
    cxTabSheet5: TcxTabSheet;
    CZF: TMemo;
    cxTabSheet6: TcxTabSheet;
    CKF: TMemo;
    Panel9: TPanel;
    PBMoney: TcxTextEdit;
    Label2: TLabel;
    Label1: TLabel;
    Label5: TLabel;
    WSMoney: TcxTextEdit;
    Label6: TLabel;
    JGMoney: TcxTextEdit;
    Label7: TLabel;
    ZaMoney: TcxTextEdit;
    Label8: TLabel;
    JSMoney: TcxTextEdit;
    CPMoney: TcxTextEdit;
    Label9: TLabel;
    SL: TcxTextEdit;
    Label10: TLabel;
    RanMoney: TcxTextEdit;
    Label13: TLabel;
    ADO_Price: TADOQuery;
    dxSpreadSheet1: TdxSpreadSheet;
    Label15: TLabel;
    Label16: TLabel;
    JSF: TcxTextEdit;
    ZS: TcxTextEdit;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure TBDelClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure cxDBTreeList1DblClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure TBFilterClick(Sender: TObject);
    procedure CYNoChange(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBUPClick(Sender: TObject);
    procedure TBCopyClick(Sender: TObject);
    procedure C_CodeKeyPress(Sender: TObject; var Key: Char);
    procedure TBAddClick(Sender: TObject);
    procedure TBEditClick(Sender: TObject);
    procedure TBMLEditClick(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure TCBNOR1Change(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure N3Click(Sender: TObject);
    procedure TextEdit(Sender: TObject);
    procedure HXNameBtnUpClick(Sender: TObject);
    procedure HXNameBtnDnClick(Sender: TObject);
    procedure cbbHXChange(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure btn1Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure TV2Column11PropertiesEditValueChanged(Sender: TObject);
    procedure Tv4Column11PropertiesEditValueChanged(Sender: TObject);
    procedure Tv1FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
    procedure Tv4Column11PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure TV2Column11PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure Tv1CellClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
    procedure ZaMoneyPropertiesEditValueChanged(Sender: TObject);
    procedure SLPropertiesEditValueChanged(Sender: TObject);
    procedure RanMoneyPropertiesEditValueChanged(Sender: TObject);
    procedure ZSPropertiesEditValueChanged(Sender: TObject);
    procedure JSFPropertiesEditValueChanged(Sender: TObject);
  private
    { Private declarations }
    CurrentPage, RecordsNumber: Integer;
    CTID: string;
    PState: Integer;
    FCTID, FTopID, FJurisdiction, FCTType: string;
    procedure SetStatus();
    procedure InitTree();
    procedure InitGrid();
    procedure InitSubGrid();
    procedure ReadINIFile();
    procedure InitImage();
    procedure LookImage(FileName: string);
  public
    dFdDy: array[0..20] of FdDy; //客户端连接数组
    { Public declarations }
  end;

var
  Mach: array of TfrmSlt;

implementation

uses
  U_DataLink, U_RTFun, U_TatClothInfoInput, U_CloInfoFileUp, U_ClothTypeSel,
  U_ZDYHelp, U_LabelPrint, U_AttachmentUpload, U_ReceivableEdit,
  U_YarnInList_Sel;
{$R *.dfm}

procedure TfrmTatClothInfo_CB.LookImage(FileName: string);
var
  sFieldName: string;
begin

  sFieldName := leftbstr(ExtractFilePath(Application.ExeName), 1) + ':\图片查看';

  if not DirectoryExists(pchar(sFieldName)) then
    CreateDirectory(pchar(sFieldName), nil);

  sFieldName := sFieldName + '\' + trim(FileName);

  try
    IdFTP1.Host := ReadINIFileStr('SYSTEMSET.INI', 'SERVER', '服务器地址', '127.0.0.1');
    IdFTP1.Username := 'three';
    IdFTP1.Password := '641010';
    IdFTP1.Connect();
  except

  end;

  if IdFTP1.Connected then
  begin
    application.ProcessMessages;
    try
//      ShowMessage(PChar(Trim('D:\' + Trim(FileName))));
      IdFTP1.Get(Trim(UserDataFlag + 'YP\' + FileName), sFieldName, true, false);
    except
      Application.MessageBox('客户图样文件不存在', '提示', MB_ICONWARNING);
      IdFTP1.Quit;
      Exit;
    end;
  end
  else
  begin
    Application.MessageBox('无法连接文件服务器', '提示', MB_ICONWARNING);
    IdFTP1.Quit;
    Exit;
  end;
  if IdFTP1.Connected then
    IdFTP1.Quit;
  ShellExecute(Handle, 'open', PChar(sFieldName), '', '', SW_SHOWNORMAL);
end;

procedure TfrmTatClothInfo_CB.SetStatus();
begin

end;

procedure TfrmTatClothInfo_CB.SLPropertiesEditValueChanged(Sender: TObject);
begin
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('UPdate BS_Cloth_Info ');
    sql.Add(' Set SL =' + trim(SL.text) + '');
    sql.Add(' where BCIID=' + QuotedStr(CDS_1.fieldbyname('BCIID').AsString));
//    ShowMessage(SQL.text);
    ExecSQL;
  end;
  InitSubGrid();
end;

procedure TfrmTatClothInfo_CB.InitTree();
begin
  with ADOQueryTree do
  begin
    Close;
    SQL.Clear;
    SQL.Add('select * from BS_Cloth_Type where CTType=' + quotedstr('梭织'));
    Open;
  end;
  SCreateCDS(ADOQueryTree, CDS_Tree);
  SInitCDSData(ADOQueryTree, CDS_Tree);
  cxDBTreeList1.Items[0].Expand(false);
end;

procedure TfrmTatClothInfo_CB.JSFPropertiesEditValueChanged(Sender: TObject);
begin
  if Trim(CDS_1.fieldbyname('BCIID').AsString) = '' then
  begin
    exit;
  end;

  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('UPdate BS_Cloth_Info ');
    sql.Add(' Set JSF =' + trim(JSF.text) + '');
    sql.Add(' where BCIID=' + QuotedStr(CDS_1.fieldbyname('BCIID').AsString));
    ExecSQL;
  end;
  InitSubGrid();
end;

procedure TfrmTatClothInfo_CB.InitGrid();
var
  fwhere, MBCIID, Pwhere: string;
begin
  Panel2.Visible := True;
  Panel2.Refresh;
  if not CDS_1.IsEmpty then
    MBCIID := Trim(CDS_1.FieldByName('BCIID').AsString)
  else
    MBCIID := '';

  Pwhere := SGetFilters(Panel1, 1, 2);

  if trim(Pwhere) <> '' then
  begin
    if fwhere <> '' then
      fwhere := fwhere + ' and ' + trim(Pwhere)
    else
      fwhere := ' where ' + trim(Pwhere);
  end;
  try
    ADOQueryMain.DisableControls;

    with ADOQueryMain do
    begin
      Close;
      Filtered := False;
      sql.Clear;
      sql.Add(' exec P_BS_CloInfo_Get  ');
      sql.Add(' @CTID=' + quotedstr(Trim(CDS_Tree.fieldbyname('CTID').AsString)));
      sql.Add(',@pageIndex=' + inttostr(CurrentPage));
      sql.Add(',@pageSize=' + inttostr(RecordsNumber));
      sql.Add(',@criteria= ' + quotedstr(fwhere));
//      ShowMessage(sql.Text);
      Open;
    end;
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
    SCreateCDS(ADOQueryMain, CDS_1);
    SInitCDSData(ADOQueryMain, CDS_1);
    TV1.DataController.Filter.Clear;
    LBCPAP1.Caption := inttostr(CurrentPage) + '/' + inttostr(ceil(CDS_1.FieldByName('TotalCount').AsInteger / RecordsNumber));

  finally
    ADOQueryMain.EnableControls;
    TV1.DataController.Filter.Clear;
  end;
  Panel2.Visible := False;

  if MBCIID <> '' then
    CDS_1.Locate('BCIID', MBCIID, []);

end;

procedure TfrmTatClothInfo_CB.InitSubGrid();
begin

  if Trim(CDS_1.fieldbyname('BCIID').AsString) = '' then
  begin
    exit;
  end;

  ZaMoney.Properties.OnEditValueChanged := nil;
  SL.Properties.OnEditValueChanged := nil;
  RanMoney.Properties.OnEditValueChanged := nil;

  JSF.Properties.OnEditValueChanged := nil;
  ZS.Properties.OnEditValueChanged := nil;

  with ADO_2 do
  begin
    Close;
    sql.Clear;
    sql.Add(' select A.*');
    sql.Add(' ,SXMoney = round(1.00 * isnull(A.SXPrice,0) * MeterQty / 1000,2)   ');
    sql.Add(' from BS_Cloth_Yarn A ');
    sql.Add(' where YRType=''经丝'' and A.BCIID=''' + Trim(CDS_1.fieldbyname('BCIID').AsString) + '''');
    Open;
  end;
  SCreateCDS(ADO_2, CDS_2);
  SInitCDSData(ADO_2, CDS_2);

  with ADO_4 do
  begin
    Close;
    sql.Clear;
    sql.Add(' select A.*');
    sql.Add(' ,SXMoney = round(1.00 * isnull(A.SXPrice,0) * MeterQty / 1000,2)   ');
    sql.Add(' from BS_Cloth_Yarn A ');
    sql.Add(' where YRType=''纬丝'' and A.BCIID=''' + Trim(CDS_1.fieldbyname('BCIID').AsString) + '''');
    Open;
  end;
  SCreateCDS(ADO_4, CDS_4);
  SInitCDSData(ADO_4, CDS_4);

  QZF.Text := Trim(CDS_1.fieldbyname('QZF').AsString);
  CZF.Text := Trim(CDS_1.fieldbyname('CZF').AsString);
  CKF.Text := Trim(CDS_1.fieldbyname('CKF').AsString);

  with ADO_Price do
  begin
    Close;
    sql.Clear;
    sql.Add(' select A.*');
    sql.Add(' from V_BS_Cloth_Info A ');
    sql.Add(' where  A.BCIID=''' + Trim(CDS_1.fieldbyname('BCIID').AsString) + '''');
//    ShowMessage(sql.text);
    Open;
  end;

  PBMoney.Text := Trim(ADO_Price.fieldbyname('PBMoney').AsString);

  JSMoney.Text := Trim(ADO_Price.fieldbyname('JSMoney').AsString);
  WSMoney.Text := Trim(ADO_Price.fieldbyname('WSMoney').AsString);
  JGMoney.Text := Trim(ADO_Price.fieldbyname('JGMoney').AsString);

  ZaMoney.Text := Trim(ADO_Price.fieldbyname('ZaMoney').AsString);

  CPMoney.Text := Trim(ADO_Price.fieldbyname('CPMoney').AsString);

  SL.Text := Trim(ADO_Price.fieldbyname('SL').AsString);
  RanMoney.Text := Trim(ADO_Price.fieldbyname('RanMoney').AsString);

  JSF.Text := Trim(ADO_Price.fieldbyname('JSF').AsString);
  ZS.Text := Trim(ADO_Price.fieldbyname('ZS').AsString);

  ZaMoney.Properties.OnEditValueChanged := ZaMoneyPropertiesEditValueChanged;
  SL.Properties.OnEditValueChanged := SLPropertiesEditValueChanged;
  RanMoney.Properties.OnEditValueChanged := RanMoneyPropertiesEditValueChanged;

  JSF.Properties.OnEditValueChanged := JSFPropertiesEditValueChanged;
  ZS.Properties.OnEditValueChanged := ZSPropertiesEditValueChanged;
end;

procedure TfrmTatClothInfo_CB.FormClose(Sender: TObject; var Action: TCloseAction);
var
  i, j: integer;
begin
  inherited;
  j := length(Mach);
  if j > 0 then
  begin
    for i := 0 to j - 1 do
    begin
      Mach[i].free;
    end;
  end;
  SetLength(Mach, 0);
  Action := cafree;
end;

procedure TfrmTatClothInfo_CB.FormCreate(Sender: TObject);
begin
  inherited;
  FJurisdiction := Trim(Self.fParameters1);
  FCTType := Trim(self.fParameters2);

end;

procedure TfrmTatClothInfo_CB.TBCloseClick(Sender: TObject);
begin

  if DirectoryExists(ExtractFileDir('D:\Right1209')) then
    winexec('cmd /c rd /s /q D:\Right1209', sw_hide);
  Close;
end;

procedure TfrmTatClothInfo_CB.TBDelClick(Sender: TObject);
var
  RTValues: TArray<string>;
begin

  if CDS_1.IsEmpty then
    Exit;

  RTValues := SelCDSKey(CDS_1, ['BCIID']);

  if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      Close;
      Sql.Clear;
      Sql.Add('exec P_BS_Cloth_Info_Del ');
      Sql.Add(' @BCIIDS=' + quotedstr(RTValues[0]));
      Sql.Add(',@DCode=' + quotedstr(Trim(DCode)));
      Sql.Add(',@DName=' + quotedstr(Trim(DName)));
      Open;
    end;
    if ADOQueryCmd.FieldByName('intReturn').AsInteger = -1 then
      raise Exception.Create(pchar(trim(ADOQueryCmd.FieldByName('ShowMsg').AsString)));
    ADOQueryCmd.Connection.CommitTrans;
    InitGrid();
  except
    ADOQueryCmd.Connection.RollbackTrans;
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
  end;

end;

procedure TfrmTatClothInfo_CB.FormShow(Sender: TObject);
begin
  inherited;
  readCxGrid(self.Caption + 'TV1', Tv1, '样品管理');
  readCxGrid(self.Caption + 'TV2', Tv2, '样品管理');
  readCxGrid(self.Caption + 'TV4', Tv4, '样品管理');
  application.ProcessMessages;
  RecordsNumber := 500;
  CurrentPage := 1;
  InitTree();
  SetStatus();
  InitGrid();

end;

procedure TfrmTatClothInfo_CB.cbbHXChange(Sender: TObject);
begin
  InitImage();

end;

procedure TfrmTatClothInfo_CB.cxDBTreeList1DblClick(Sender: TObject);
begin
  InitGrid();
end;

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

procedure TfrmTatClothInfo_CB.TBFilterClick(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
    SCreateCDS(ADOQueryMain, CDS_1);
    SInitCDSData(ADOQueryMain, CDS_1);
  end;

end;

procedure TfrmTatClothInfo_CB.CYNoChange(Sender: TObject);
begin
  //if Length(Trim(TEdit(Sender).Text))<4 then Exit;
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
    SCreateCDS(ADOQueryMain, CDS_1);
    SInitCDSData(ADOQueryMain, CDS_1);
  end;

end;

procedure TfrmTatClothInfo_CB.TBExportClick(Sender: TObject);
begin
  if CDS_1.IsEmpty then
    Exit;
  TcxGridToExcel(self.Caption, cxGrid1);
end;

procedure TfrmTatClothInfo_CB.TBUPClick(Sender: TObject);
begin
  try
    frmCloInfoFileUp := TfrmCloInfoFileUp.Create(Application);
    with frmCloInfoFileUp do
    begin
      Code.Text := Trim(Self.CDS_1.fieldbyname('C_Code').AsString);
      FBCIID := Trim(Self.CDS_1.fieldbyname('BCIID').AsString);
      if ShowModal = 1 then
      begin
        Self.InitGrid();
//        Self.CDS_1.Locate('BCIID', BCIID, []);
      end;
    end;
  finally
    frmCloInfoFileUp.Free;
  end;
  InitImage();
end;

procedure TfrmTatClothInfo_CB.RanMoneyPropertiesEditValueChanged(Sender: TObject);
begin
  if Trim(CDS_1.fieldbyname('BCIID').AsString) = '' then
  begin
    exit;
  end;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('UPdate BS_Cloth_Info ');
    sql.Add(' Set RanMoney =' + trim(RanMoney.text) + '');
    sql.Add(' where BCIID=' + QuotedStr(CDS_1.fieldbyname('BCIID').AsString));
//    ShowMessage(SQL.text);
    ExecSQL;
  end;
  InitSubGrid();
end;

procedure TfrmTatClothInfo_CB.ReadINIFile();
var
  programIni: Tinifile;  //配置文件名
  FileName: string;
begin
  FileName := ExtractFilePath(Paramstr(0)) + 'SYSTEMSET.INI';
  programIni := Tinifile.create(FileName);
  server := programIni.ReadString('SERVER', '服务器地址', '127.0.0.1');
  programIni.Free;
end;

procedure TfrmTatClothInfo_CB.InitImage();
var
  i, j: integer;
  jpg: TJpegImage;
  myStream: TADOBlobStream;
begin

  j := length(Mach);
  if j > 0 then
  begin
    for i := 0 to j - 1 do
    begin
      Mach[i].free;
    end;
  end;
  SetLength(Mach, 0);
  if CDS_1.IsEmpty then
    exit;
  try
    with adoqueryPicture do
    begin
      close;
      sql.Clear;
      sql.Add(' select A.TFID,A.WBID,A.FilesOther,A.FileName from TP_File A  ');
      sql.add('where  A.WBID=' + quotedstr(trim(CDS_1.fieldbyname('BCIID').AsString)));

      open;
    end;
    j := adoqueryPicture.RecordCount;
    if j < 1 then
      exit;
    adoqueryPicture.DisableControls;
    adoqueryPicture.First;
    SetLength(Mach, j);
    jpg := TJpegImage.Create();
    for i := 0 to j - 1 do
    begin
      if triM(adoqueryPicture.fieldbyname('FilesOther').AsString) <> '' then
      begin
        myStream := tadoblobstream.Create(tblobfield(adoqueryPicture.fieldbyname('FilesOther')), bmread);
        jpg.LoadFromStream(myStream);
        Mach[i] := TfrmSlt.Create(Self);
        Mach[i].Name := trim(adoqueryPicture.fieldbyname('TFID').AsString);
        Mach[i].Parent := ScrollBox1;
        Mach[i].Left := 0 + i * 165;
        Mach[i].Init(adoqueryPicture.fieldbyname('TFID').AsString, adoqueryPicture.fieldbyname('FileName').AsString, jpg);
      end;
      adoqueryPicture.Next;
    end;
    adoqueryPicture.EnableControls;
  finally
    jpg.free;
    application.ProcessMessages;
  end;
end;

procedure TfrmTatClothInfo_CB.TBCopyClick(Sender: TObject);
begin
  try
    frmTatClothInfoInput := TfrmTatClothInfoInput.Create(Application);
    with frmTatClothInfoInput do
    begin
      CopyInt := 1;
      FBCIID := Trim(Self.CDS_1.fieldbyname('BCIID').AsString);
      FCTID := Trim(Self.CDS_Tree.fieldbyname('CTID').AsString);

      if ShowModal = 1 then
      begin
        Self.InitGrid();
      end;
    end;
  finally
    frmTatClothInfoInput.Free;
  end;
end;

procedure TfrmTatClothInfo_CB.C_CodeKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    CurrentPage := 1;
    InitGrid();
  end;
end;

procedure TfrmTatClothInfo_CB.TBAddClick(Sender: TObject);
var
  i: Integer;
  FieldName: string;
begin
  try
    frmTatClothInfoInput := TfrmTatClothInfoInput.Create(Application);
    with frmTatClothInfoInput do
    begin
      CopyInt := 0;
      FBCIID := '';
      FCTID := Trim(Self.CDS_Tree.fieldbyname('CTID').AsString);

      if ShowModal = 1 then
      begin
        Self.InitGrid();
      end;
    end;
  finally
    frmTatClothInfoInput.Free;
  end;
end;

procedure TfrmTatClothInfo_CB.TBEditClick(Sender: TObject);
begin
  if CDS_1.IsEmpty then
    Exit;
  try
    frmTatClothInfoInput := TfrmTatClothInfoInput.Create(Application);
    with frmTatClothInfoInput do
    begin
      CopyInt := 0;
      FBCIID := Trim(Self.CDS_1.fieldbyname('BCIID').AsString);
      FCTID := Trim(Self.CDS_Tree.fieldbyname('CTID').AsString);
      if ShowModal = 1 then
      begin
        Self.InitGrid();
      end;
    end;
  finally
    frmTatClothInfoInput.Free;
  end;
end;

procedure TfrmTatClothInfo_CB.TextEdit(Sender: TObject);
var
  mvalue, FFieldName: string;
begin

  mvalue := TcxTextEdit(Sender).EditingText;
  FFieldName := Trim(Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName);
  with CDS_1 do
  begin
    Edit;
    FieldByName(FFieldName).Value := mvalue;
    Post;

  end;
  if mvalue = '' then
    mvalue := '0';

  with ADOQueryCmd do
  begin
    Close;
    SQL.Clear;
    sql.Add('update BS_Cloth_Info set  ' + FFieldName + '=' + (Trim(mvalue)));
    sql.Add('where   BCIID=' + quotedstr(Trim(CDS_1.fieldbyname('BCIID').AsString)));
    ExecSQL;
  end;
  Tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmTatClothInfo_CB.TBMLEditClick(Sender: TObject);
var
  MCTID: string;
begin
  if CDS_1.IsEmpty then
    exit;
  if CDS_1.Locate('ssel', true, []) = false then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;
  MCTID := '';
  try
    frmClothTypeSel := TfrmClothTypeSel.create(self);
    with frmClothTypeSel do
    begin
      FCTType := Self.FCTType;
      if showmodal = 1 then
      begin
        MCTID := trim(ADOQueryHelp.fieldbyname('CTID').asstring);
      end;
    end;
  finally
    frmClothTypeSel.free;
  end;

  if trim(MCTID) <> '' then
  begin
    try
      with CDS_1 do
      begin
        DisableControls;
        First;
        while not eof do
        begin
          if fieldbyname('ssel').AsBoolean then
          begin
            with ADOQueryCmd do
            begin
              close;
              sql.Clear;
              sql.Add('update  BS_Cloth_Info SET CTID=''' + trim(MCTID) + ''' ');
              sql.Add('where BCIID=' + quotedstr(trim(CDS_1.fieldbyname('BCIID').AsString)));
              execsql;
            end;
          end;
          next;
        end;
        First;
        EnableControls;
      end;
      application.MessageBox('操作成功！', '提示信息');
      initGrid();
    except
      CDS_1.EnableControls;
      application.MessageBox('操作失败！', '提示信息', 0);
    end;
  end;

end;

procedure TfrmTatClothInfo_CB.N1Click(Sender: TObject);
begin
  SelOKNo(cds_1, True);
end;

procedure TfrmTatClothInfo_CB.N2Click(Sender: TObject);
begin
  SelOKNo(cds_1, false);
end;

procedure TfrmTatClothInfo_CB.N3Click(Sender: TObject);
begin
  Clipboard.SetTextBuf(PChar(Trim(CDS_1.fieldbyname(TV1.Controller.FocusedColumn.DataBinding.FilterFieldName).AsString)));
end;

procedure TfrmTatClothInfo_CB.TCBNOR1Change(Sender: TObject);
begin
  RecordsNumber := StrToInt(TCBNOR1.Text);
  CurrentPage := 1;
  C_Code.SetFocus;
  InitGrid();
end;

procedure TfrmTatClothInfo_CB.HXNameBtnDnClick(Sender: TObject);
begin
  TBtnEditC(Sender).Text := '';
  TBtnEditC(Sender).TxtCode := '';

end;

procedure TfrmTatClothInfo_CB.HXNameBtnUpClick(Sender: TObject);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'HX' + Trim(Self.CDS_1.fieldbyname('CYNO').AsString);
      flagname := '花型';
      if ShowModal = 1 then
      begin
        TEdit(Sender).Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmTatClothInfo_CB.btn1Click(Sender: TObject);
var
  WSql: string;
begin
  if CDS_1.IsEmpty then
    Exit;

  try
    frmLabelPrint := TfrmLabelPrint.Create(Application);
    with frmLabelPrint do
    begin
      FLMType := 'ClothInfoPrint31';
      FFiltration1 := Trim(CDS_1.fieldbyname('BCIID').AsString);
      if ShowModal = 1 then
      begin
      end;
    end;
  finally
    frmLabelPrint.Free;
  end;

end;

procedure TfrmTatClothInfo_CB.Button1Click(Sender: TObject);
begin
  if CurrentPage > 1 then
    CurrentPage := CurrentPage - 1;
  InitGrid();
end;

procedure TfrmTatClothInfo_CB.Button2Click(Sender: TObject);
begin
  if CurrentPage < CDS_1.FieldByName('TotalCount').AsInteger / RecordsNumber then
    CurrentPage := CurrentPage + 1;
  InitGrid();
end;

procedure TfrmTatClothInfo_CB.ToolButton1Click(Sender: TObject);
begin
  try
    frmTatClothInfoInput := TfrmTatClothInfoInput.Create(Application);
    with frmTatClothInfoInput do
    begin
      CopyInt := 0;
      ToolButton1.Visible := False;
      FBCIID := Trim(Self.CDS_1.fieldbyname('BCIID').AsString);
      FCTID := Trim(Self.CDS_Tree.fieldbyname('CTID').AsString);
      if ShowModal = 1 then
      begin
        Self.InitGrid();
      end;
    end;
  finally
    frmTatClothInfoInput.Free;
  end;
end;

procedure TfrmTatClothInfo_CB.ToolButton2Click(Sender: TObject);
begin
  WriteCxGrid(self.Caption + 'TV1', Tv1, '样品管理');
  WriteCxGrid(self.Caption + 'TV2', Tv2, '样品管理');
  WriteCxGrid(self.Caption + 'TV4', Tv4, '样品管理');
end;

procedure TfrmTatClothInfo_CB.ToolButton3Click(Sender: TObject);
var
  WSql: string;
begin
  if CDS_1.IsEmpty then
    Exit;
  Tv1.OnFocusedRecordChanged := nil;
  if CDS_1.Locate('SSel', True, []) = False then
  begin
    Tv1.OnFocusedRecordChanged := Tv1FocusedRecordChanged;
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;

  WSql := '';
  CDS_1.DisableControls;

  with CDS_1 do
  begin
    First;
    while not Eof do
    begin
      if CDS_1.fieldbyname('SSel').AsBoolean then
      begin
        if WSql <> '' then
        begin
          WSql := WSql + ',' + QuotedStr(Trim(CDS_1.fieldbyname('BCIID').AsString));
        end
        else
        begin
          WSql := QuotedStr(Trim(CDS_1.fieldbyname('BCIID').AsString));
        end;
      end;
      Next;
    end;
  end;

  CDS_1.Locate('SSel', True, []);
  Tv1.OnFocusedRecordChanged := Tv1FocusedRecordChanged;
  CDS_1.EnableControls;

  try
    frmLabelPrint := TfrmLabelPrint.Create(Application);
    with frmLabelPrint do
    begin
      FLMType := 'ClothInfoPrint';
      FFiltration1 := WSql;
      if ShowModal = 1 then
      begin
//        Self.InitGrid();
      end;
    end;
  finally
    frmLabelPrint.Free;
  end;

end;

procedure TfrmTatClothInfo_CB.ToolButton4Click(Sender: TObject);
begin

  try
    frmAttachmentUpload := TfrmAttachmentUpload.Create(Application);
    with frmAttachmentUpload do
    begin
      FEditAuthority := True;
      fkeyNO := Trim(CDS_1.fieldbyname('C_Code').AsString);
      fType := '成品档案';
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmAttachmentUpload.Free;
  end;
end;

procedure TfrmTatClothInfo_CB.ToolButton5Click(Sender: TObject);
begin
  try
    frmReceivableEdit := TfrmReceivableEdit.Create(Application);
    with frmReceivableEdit do
    begin
      FBCIID := Trim(CDS_1.fieldbyname('BCIID').AsString);

      if ShowModal = 1 then
      begin
        InitGrid();
      end;
    end;
  finally
    frmReceivableEdit.Free;
  end;
end;

procedure TfrmTatClothInfo_CB.Tv1CellClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
begin
  InitImage();
end;

procedure TfrmTatClothInfo_CB.Tv1FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
var
  myStream: TMemoryStream;
begin

  myStream := TMemoryStream.Create();

  with ADOQueryTemp do
  begin
    close;
    sql.Clear;
    sql.Add(' select *  from BS_Cloth_Info_Excel where BCIID=''' + Trim(CDS_1.fieldbyname('BCIID').AsString) + '''');
    open;
  end;

  if not ADOQueryTemp.IsEmpty then
  begin

    TBlobField(ADOQueryTemp.FieldByName('ExcelData')).SaveToStream(myStream);
    myStream.Position := 0;
    dxSpreadSheet1.LoadFromStream(myStream);
  end
  else
  begin
    dxSpreadSheet1.ClearAll;
  end;

  InitSubGrid();

  myStream.Free;
end;

procedure TfrmTatClothInfo_CB.TV2Column11PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
var
  FPrice: string;
begin
  try
    frmYarnInList_Sel := TfrmYarnInList_Sel.Create(Application);
    with frmYarnInList_Sel do
    begin
      Y_Name.text := CDS_2.fieldbyname('Y_Name').AsString;
      if ShowModal = 1 then
      begin

        with CDS_2 do
        begin
          Edit;
          FieldByName('SXPrice').Value := frmYarnInList_Sel.CDS_Main.fieldbyname('Price').asfloat;
          Post;
        end;

        FPrice := Trim(frmYarnInList_Sel.CDS_Main.fieldbyname('Price').AsString);
        if Trim(FPrice) = '' then
        begin
          FPrice := '0';
        end;

        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('UPdate BS_Cloth_Yarn ');
          sql.Add(' Set SXPrice=' + Trim(FPrice) + '');
          sql.Add(' where YRId=' + QuotedStr(CDS_2.fieldbyname('YRId').AsString));
//          ShowMessage(SQL.text);
          ExecSQL;
        end;

        InitSubGrid();

      end;
    end;
  finally
    frmYarnInList_Sel.Free;
  end;
end;

procedure TfrmTatClothInfo_CB.TV2Column11PropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FFieldName: string;
begin
  mvalue := TcxTextEdit(Sender).EditingText;
  FFieldName := Trim(Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName);
  try
    ADOQueryCmd.Connection.BeginTrans;
    with CDS_2 do
    begin
      Edit;
      FieldByName(FFieldName).Value := Trim(mvalue);
      Post;
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('UPdate BS_Cloth_Yarn ');
      sql.Add(' Set ' + FFieldName + '=' + Trim(mvalue) + '');
      sql.Add(' where YRId=' + QuotedStr(CDS_2.fieldbyname('YRId').AsString));
//      ShowMessage(SQL.text);
      ExecSQL;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    InitSubGrid();
    tv2.Controller.EditingController.ShowEdit();
  except
    tv2.Controller.EditingController.ShowEdit();
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！', '提示', 0);
  end
end;

procedure TfrmTatClothInfo_CB.Tv4Column11PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
var
  FPrice: string;
begin
  try
    frmYarnInList_Sel := TfrmYarnInList_Sel.Create(Application);
    with frmYarnInList_Sel do
    begin
      Y_Code.text := CDS_4.fieldbyname('Y_Code').AsString;
      if ShowModal = 1 then
      begin

        with CDS_4 do
        begin
          Edit;
          FieldByName('SXPrice').Value := frmYarnInList_Sel.CDS_Main.fieldbyname('Price').asfloat;
          Post;
        end;

        FPrice := Trim(frmYarnInList_Sel.CDS_Main.fieldbyname('Price').AsString);
        if Trim(FPrice) = '' then
        begin
          FPrice := '0';
        end;

        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('UPdate BS_Cloth_Yarn ');
          sql.Add(' Set SXPrice=' + Trim(FPrice) + '');
          sql.Add(' where YRId=' + QuotedStr(CDS_4.fieldbyname('YRId').AsString));
//          ShowMessage(SQL.text);
          ExecSQL;
        end;

        InitSubGrid();
      end;
    end;
  finally
    frmYarnInList_Sel.Free;
  end;
end;

procedure TfrmTatClothInfo_CB.Tv4Column11PropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FFieldName, FBCIID: string;
begin
  mvalue := TcxTextEdit(Sender).EditingText;
  FFieldName := Trim(Tv4.Controller.FocusedColumn.DataBinding.FilterFieldName);
  FBCIID := CDS_1.fieldbyname('BCIID').AsString;
  if mvalue = '' then
  begin
    mvalue := '0';
  end;
  try
    ADOQueryCmd.Connection.BeginTrans;
    with CDS_4 do
    begin
      Edit;
      FieldByName(FFieldName).Value := Trim(mvalue);
      Post;
    end;

    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('UPdate BS_Cloth_Yarn ');
      sql.Add(' Set ' + FFieldName + '=' + Trim(mvalue) + '');
      sql.Add(' where YRId=' + QuotedStr(CDS_4.fieldbyname('YRId').AsString));
//      ShowMessage(SQL.text);
      ExecSQL;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    InitSubGrid();
    Tv4.Controller.EditingController.ShowEdit();
  except
    Tv4.Controller.EditingController.ShowEdit();
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！', '提示', 0);
  end
end;

procedure TfrmTatClothInfo_CB.ZaMoneyPropertiesEditValueChanged(Sender: TObject);
begin
  if Trim(CDS_1.fieldbyname('BCIID').AsString) = '' then
  begin
    exit;
  end;

  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('UPdate BS_Cloth_Info ');
    sql.Add(' Set ZaMoney =' + trim(ZaMoney.text) + '');
    sql.Add(' where BCIID=' + QuotedStr(CDS_1.fieldbyname('BCIID').AsString));
    ExecSQL;
  end;
  InitSubGrid();
end;

procedure TfrmTatClothInfo_CB.ZSPropertiesEditValueChanged(Sender: TObject);
begin
  if Trim(CDS_1.fieldbyname('BCIID').AsString) = '' then
  begin
    exit;
  end;

  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('UPdate BS_Cloth_Info ');
    sql.Add(' Set ZS =' + trim(ZS.text) + '');
    sql.Add(' where BCIID=' + QuotedStr(CDS_1.fieldbyname('BCIID').AsString));
    ExecSQL;
  end;
  InitSubGrid();
end;

end.

