unit U_TatClothInfoInput;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
  cxEdit, DB, cxDBData, ADODB, DBClient, cxGridLevel, cxGridCustomTableView,
  cxGridTableView, cxGridDBTableView, cxClasses, cxControls, cxGridCustomView,
  cxGrid, ComCtrls, ToolWin, cxGridCustomPopupMenu, cxGridPopupMenu, cxTextEdit,
  cxButtonEdit, StdCtrls, ExtCtrls, cxCurrencyEdit, BtnEdit, U_BaseList,
  cxLookAndFeels, cxLookAndFeelPainters, cxNavigator, dxDateRanges,
  dxBarBuiltInMenu, cxPC, System.ImageList, Vcl.ImgList, U_BaseInput,
  dxScrollbarAnnotations, cxContainer, cxMemo, cxMaskEdit, dxCore, dxCoreClasses,
  dxHashUtils, dxSpreadSheetCore, dxSpreadSheetCoreFormulas,
  dxSpreadSheetCoreHistory, dxSpreadSheetCoreStyles, dxSpreadSheetCoreStrs,
  dxSpreadSheetConditionalFormatting, dxSpreadSheetConditionalFormattingRules,
  dxSpreadSheetClasses, dxSpreadSheetContainers, dxSpreadSheetFormulas,
  dxSpreadSheetHyperlinks, dxSpreadSheetFunctions, dxSpreadSheetStyles,
  dxSpreadSheetGraphics, dxSpreadSheetPrinting, dxSpreadSheetTypes,
  dxSpreadSheetUtils, dxSpreadSheetFormattedTextUtils, dxSpreadSheet, cxCheckBox,
  dxSkinsCore, dxSkinsDefaultPainters, cxImageList, 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, Vcl.Menus, cxDropDownEdit;

type
  TfrmTatClothInfoInput = class(TfrmBaseInput)
    ToolBar1: TToolBar;
    ToolButton1: TToolButton;
    TBClose: TToolButton;
    ADOQueryCmd: TADOQuery;
    ADOQueryTemp: TADOQuery;
    ScrollBox1: TScrollBox;
    Label1: TLabel;
    Label5: TLabel;
    Label3: TLabel;
    ToolButton6: TToolButton;
    BCIID: TEdit;
    CDS_1: TClientDataSet;
    DS_1: TDataSource;
    CDS_2: TClientDataSet;
    DS_2: TDataSource;
    ADOConnection1: TADOConnection;
    ImageList1: TImageList;
    Label16: TLabel;
    Label55: TLabel;
    cxPageControl3: TcxPageControl;
    cxTabSheet1: TcxTabSheet;
    GroupBox1: TGroupBox;
    Y_Note_PLJ: TMemo;
    Panel1: TPanel;
    cxPageControl2: TcxPageControl;
    cxGrid1: TcxGrid;
    TV1: TcxGridDBTableView;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    cxGridDBColumn5: TcxGridDBColumn;
    cxGridDBColumn8: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    cxTabSheet2: TcxTabSheet;
    GroupBox2: TGroupBox;
    Y_Note_PLW: TMemo;
    Panel2: TPanel;
    cxPageControl1: TcxPageControl;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    v2Column10: TcxGridDBColumn;
    cxGridDBColumn1: TcxGridDBColumn;
    v2Column2: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    cxTabSheet3: TcxTabSheet;
    Panel8: TPanel;
    ToolBar4: TToolBar;
    ToolButton9: TToolButton;
    ToolButton10: TToolButton;
    Panel7: TPanel;
    Label49: TLabel;
    Edit1: TEdit;
    CDS_4: TClientDataSet;
    DS_4: TDataSource;
    GPM_1: TcxGridPopupMenu;
    GPM_2: TcxGridPopupMenu;
    GPM_4: TcxGridPopupMenu;
    ToolButton11: TToolButton;
    CINote: TcxMemo;
    ThroughHealdOrder: TcxMemo;
    C_Code: TcxTextEdit;
    Label2: TLabel;
    Label4: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    LoomType: TcxTextEdit;
    C_Name: TcxTextEdit;
    C_YarnQty: TcxTextEdit;
    C_ReedWidth: TcxTextEdit;
    C_ReedNo: TcxTextEdit;
    C_GramWeight: TcxTextEdit;
    C_TestGramWeight: TcxTextEdit;
    C_FinishLatitudeDensity: TcxTextEdit;
    TV1Column7: TcxGridDBColumn;
    Tv2Column7: TcxGridDBColumn;
    TV1Column1: TcxGridDBColumn;
    TV1Column2: TcxGridDBColumn;
    TV1Column3: TcxGridDBColumn;
    TV1Column4: TcxGridDBColumn;
    TV1Column5: TcxGridDBColumn;
    TV1Column6: TcxGridDBColumn;
    TV1Column8: TcxGridDBColumn;
    TV1Column9: TcxGridDBColumn;
    TV1Column10: TcxGridDBColumn;
    Tv2Column1: TcxGridDBColumn;
    Tv2Column2: TcxGridDBColumn;
    Tv2Column3: TcxGridDBColumn;
    Tv2Column4: TcxGridDBColumn;
    Tv2Column5: TcxGridDBColumn;
    Tv2Column6: TcxGridDBColumn;
    Tv2Column8: TcxGridDBColumn;
    Tv2Column9: TcxGridDBColumn;
    Tv2Column10: TcxGridDBColumn;
    lbl1: TLabel;
    lbl2: TLabel;
    WB_Code: TcxButtonEdit;
    WB_Name: TcxTextEdit;
    cxTabSheet4: TcxTabSheet;
    CZF: TMemo;
    cxTabSheet5: TcxTabSheet;
    CKF: TMemo;
    TV1Column11: TcxGridDBColumn;
    Tv2Column11: TcxGridDBColumn;
    Label11: TLabel;
    Label12: TLabel;
    C_Color: TcxTextEdit;
    C_ColorNo: TcxTextEdit;
    Label13: TLabel;
    C_Pattern: TcxTextEdit;
    Label14: TLabel;
    C_StyleNo: TcxTextEdit;
    Label15: TLabel;
    C_Spec: TcxTextEdit;
    Label17: TLabel;
    C_Composition: TcxTextEdit;
    TV1Column12: TcxGridDBColumn;
    Tv2Column12: TcxGridDBColumn;
    TV1Column13: TcxGridDBColumn;
    Tv2Column13: TcxGridDBColumn;
    ADOQuery1: TADOQuery;
    Label18: TLabel;
    Label19: TLabel;
    BBNo: TcxTextEdit;
    ZS: TcxTextEdit;
    ADOQueryTemp2: TADOQuery;
    PM_1: TPopupMenu;
    N1: TMenuItem;
    PM_2: TPopupMenu;
    MenuItem1: TMenuItem;
    QZF: TMemo;
    MFDW: TcxComboBox;
    Label20: TLabel;
    C_FinishLongitudeDensity: TcxTextEdit;
    Label21: TLabel;
    JinSha: TcxTextEdit;
    Label22: TLabel;
    WeiSha: TcxTextEdit;
    LPDW: TcxComboBox;
    TV1Column14: TcxGridDBColumn;
    Tv2Column14: TcxGridDBColumn;
    procedure FormShow(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure CYColorKeyPress(Sender: TObject; var Key: Char);
    procedure CYMFExit(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure CYJGGYBtnDnClick(Sender: TObject);
    procedure C_WidthBtnDnClick(Sender: TObject);
    procedure C_WidthBtnUpClick(Sender: TObject);
    procedure ToolButton6Click(Sender: TObject);
    procedure ToolButton7Click(Sender: TObject);
    procedure ToolButton9Click(Sender: TObject);
    procedure ToolButton10Click(Sender: TObject);
    procedure Edit1KeyPress(Sender: TObject; var Key: Char);
    procedure ToolButton11Click(Sender: TObject);
    procedure cxGridDBColumn3PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v2Column10PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure cxGridDBColumn4PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure cxGridDBColumn1PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure WB_CodePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure Tv2Column1PropertiesEditValueChanged(Sender: TObject);
    procedure C_ReedWidthPropertiesEditValueChanged(Sender: TObject);
    procedure TV1Column1PropertiesEditValueChanged(Sender: TObject);
    procedure C_YarnQtyPropertiesEditValueChanged(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure MenuItem1Click(Sender: TObject);
    procedure MFDWPropertiesEditValueChanged(Sender: TObject);
    procedure C_FinishLongitudeDensityPropertiesEditValueChanged(Sender: TObject);
    procedure C_CompositionPropertiesEditValueChanged(Sender: TObject);
  private
    canshu1: string;
    Fint: Integer;
    procedure InitGrid();
    procedure JSJS(); //计算经丝
    procedure JSWS(); //计算纬丝
    procedure JSKZ(); //计算克重
    function SaveData(): Boolean;
    { Private declarations }
  public
    FBCIID, FCTID, JSGG, WSGG, FC_Spec: string;
    CopyInt: Integer;

    { Public declarations }
  end;

var
  frmTatClothInfoInput: TfrmTatClothInfoInput;

implementation

uses
  U_DataLink, U_HttpFun, U_RTFun, U_iniParam, U_ZDYHelp, U_AttachmentUpload,
  U_YarnInfoSel, U_WBSpecSel;

{$R *.dfm}

procedure TfrmTatClothInfoInput.InitGrid();
var
  myStream: TMemoryStream;
begin
  myStream := TMemoryStream.Create();

  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select A.*  from BS_Cloth_Yarn A ');
    sql.Add(' where YRType=''经丝'' and A.BCIID=''' + Trim(FBCIID) + '''');
    Open;
  end;
  SCreateCDS(ADOQueryTemp, CDS_1);
  SInitCDSData(ADOQueryTemp, CDS_1);

  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select A.*  from BS_Cloth_Yarn A ');
    sql.Add(' where YRType=''纬丝'' and A.BCIID=''' + Trim(FBCIID) + '''');
    Open;
  end;
  SCreateCDS(ADOQueryTemp, CDS_2);
  SInitCDSData(ADOQueryTemp, CDS_2);

  with ADOQueryTemp do
  begin
    Close;
    SQL.Clear;
    SQL.Add('select * from BS_Cloth_Info where BCIID=''' + Trim(FBCIID) + '''');
    Open;
  end;
  SCSHData(ADOQueryTemp, ScrollBox1, 2);
  SCSHData(ADOQueryTemp, ScrollBox1, 0);

  QZF.Text := Trim(ADOQueryTemp.FieldByName('QZF').AsString);
  CZF.Text := Trim(ADOQueryTemp.FieldByName('CZF').AsString);
  CKF.Text := Trim(ADOQueryTemp.FieldByName('CKF').AsString);

  Y_Note_PLJ.Text := Trim(ADOQueryTemp.FieldByName('Y_Note_PLJ').AsString);
  Y_Note_PLW.Text := Trim(ADOQueryTemp.FieldByName('Y_Note_PLW').AsString);


  //////////////////////////            保存起综              //////////////////////////
//  with ADOQueryTemp do
//  begin
//    close;
//    sql.Clear;
//    sql.Add(' select *  from BS_Cloth_Info_Excel where BCIID=''' + Trim(FBCIID) + '''');
//    open;
//  end;
//
//  if not ADOQueryTemp.IsEmpty then
//  begin
//
//    TBlobField(ADOQueryTemp.FieldByName('ExcelData')).SaveToStream(myStream);
//    myStream.Position := 0;
//    dxSpreadSheet1.LoadFromStream(myStream);
//  end
//  else
//  begin
//
//    with ADOQueryTemp2 do
//    begin
//      close;
//      sql.Clear;
//      sql.Add(' select *  from BS_Cloth_Info_Excel2 ');
//      open;
//    end;
//    TBlobField(ADOQueryTemp2.FieldByName('ExcelData')).SaveToStream(myStream);
//    myStream.Position := 0;
//    dxSpreadSheet1.LoadFromStream(myStream);
//  end;

  if FBCIID = '' then
  begin
    with CDS_1 do
    begin
      Append;
      FieldByName('RowNo').Value := 'A';
      Post;
      Append;
      FieldByName('RowNo').Value := 'B';
      Post;
      Append;
      FieldByName('RowNo').Value := 'C';
      Post;
      Append;
      FieldByName('RowNo').Value := 'D';
      Post;
      Append;
      FieldByName('RowNo').Value := 'E';
      Post;
      Append;
      FieldByName('RowNo').Value := 'F';
      Post;
      Append;
      FieldByName('RowNo').Value := 'G';
      Post;
    end;
    with CDS_2 do
    begin
      Append;
      FieldByName('RowNo').Value := 'A';
      Post;
      Append;
      FieldByName('RowNo').Value := 'B';
      Post;
      Append;
      FieldByName('RowNo').Value := 'C';
      Post;
      Append;
      FieldByName('RowNo').Value := 'D';
      Post;
      Append;
      FieldByName('RowNo').Value := 'E';
      Post;
      Append;
      FieldByName('RowNo').Value := 'F';
      Post;
      Append;
      FieldByName('RowNo').Value := 'G';
      Post;
    end;

    myStream.Free;
  end;

  /////////////////刷新起综工艺单信息/////////////////////////
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from BS_CLoth_QZ where BCIID=''' + Trim(FBCIID) + '''');
    Open;
  end;
  SCreateCDS(ADOQueryTemp, CDS_4);
  SInitCDSData(ADOQueryTemp, CDS_4);
 /////////////////刷新起综工艺单信息/////////////////////////
 ///
end;

procedure TfrmTatClothInfoInput.JSJS();
var
  GS, ZGS, MF, DS, WM, TW: double;
begin
//  if CDS_1.IsEmpty then
//    exit;
//  with CDS_1 do
//  begin
//    DisableControls;
//    first;
//    while not eof do
//    begin
//
//      with CDS_1 do
//      begin
//
//        if FieldByName('YarnQty').Value = null then
//        begin
//          GS := 0;   //根数
//        end
//        else
//        begin
//          GS := FieldByName('YarnQty').Value;   //根数
//        end;
//
//        if FieldByName('CycleYarnQty').Value = null then
//        begin
//          ZGS := 0; //循环根数
//        end
//        else
//        begin
//          ZGS := FieldByName('CycleYarnQty').Value; //循环根数
//        end;
//
//        MF := strtofloatdef(C_ReedWidth.text, 0);    //筘幅
//
//        TW := strtofloatdef(C_YarnQty.text, 0);    //头纹
//
//        if FieldByName('TestDenier').Value = null then
//        begin
//          DS := 0;     //D数
//        end
//        else
//        begin
//          DS := FieldByName('TestDenier').Value;     //D数
//        end;
//
//        WM := strtofloatdef(C_FinishLatitudeDensity.text, 0); //纬密
//      end;
//      if ZGS <> 0 then
//      begin
//        with CDS_1 do
//        begin
//          Edit;
//          FieldByName('MeterQty').Value := roundfloat(GS / ZGS * TW * DS / 9000, 2);
//          Post;
//        end;
//      end;
//      next;
//    end;
//    First;
//    EnableControls;
//  end;

  JSGG := '';
  with CDS_1 do
  begin
    first;
    while not eof do
    begin
      if Trim(CDS_1.fieldbyname('Y_Name').AsString) <> '' then
      begin
        if POS(Trim(CDS_1.fieldbyname('Y_Name').AsString), JSGG) = 0 then
        begin
          JSGG := JSGG + Trim(CDS_1.fieldbyname('Y_Name').AsString) + '+';
        end;
      end;
      next;
    end;
    First;
  end;

  JSGG := Copy(JSGG, 1, Length(JSGG) - 1);

end;

procedure TfrmTatClothInfoInput.JSWS();
var
  GS, ZGS, MF, DS, WM: double;
begin
//  if CDS_2.IsEmpty then
//    exit;
//  with CDS_2 do
//  begin
//    DisableControls;
//    first;
//    while not eof do
//    begin
//
//      with CDS_2 do
//      begin
//
//        if FieldByName('YarnQty').Value = null then
//        begin
//          GS := 0;   //根数
//        end
//        else
//        begin
//          GS := FieldByName('YarnQty').Value;   //根数
//        end;
//
//        if FieldByName('CycleYarnQty').Value = null then
//        begin
//          ZGS := 0; //循环根数
//        end
//        else
//        begin
//          ZGS := FieldByName('CycleYarnQty').Value; //循环根数
//        end;
//
//        MF := strtofloatdef(C_ReedWidth.text, 0) + 15;    //筘幅
//
//        if FieldByName('TestDenier').Value = null then
//        begin
//          DS := 0;     //D数
//        end
//        else
//        begin
//          DS := FieldByName('TestDenier').Value;     //D数
//        end;
//
//        WM := strtofloatdef(C_FinishLatitudeDensity.text, 0); //纬密
//      end;
//      if ZGS <> 0 then
//      begin
//        with CDS_2 do
//        begin
//          Edit;
//          FieldByName('MeterQty').Value := roundfloat(GS / ZGS * MF * DS * WM / 9000, 2);
//          Post;
//        end;
//      end;
//      next;
//    end;
//    First;
//    EnableControls;
//  end;


  WSGG := '';
  with CDS_2 do
  begin
    first;
    while not eof do
    begin
      if Trim(CDS_2.fieldbyname('Y_Name').AsString) <> '' then
      begin
        if POS(Trim(CDS_2.fieldbyname('Y_Name').AsString), WSGG) = 0 then
        begin
          WSGG := WSGG + Trim(CDS_2.fieldbyname('Y_Name').AsString) + '+';
        end;
      end;
      next;
    end;
    First;
  end;

  WSGG := Copy(WSGG, 1, Length(WSGG) - 1);
end;

procedure TfrmTatClothInfoInput.MenuItem1Click(Sender: TObject);
begin
  with CDS_2 do
  begin
    CDS_2.edit;
    FieldByName('Y_Code').Value := null;
    FieldByName('Y_Name').Value := null;
    FieldByName('Y_Spec').Value := null;
    FieldByName('Y_Color').Value := null;
    FieldByName('YarnQty').Value := null;
    FieldByName('CycleYarnQty').Value := null;
    FieldByName('FF').Value := null;
    FieldByName('ND').Value := null;
    FieldByName('Dacron').Value := null;
    FieldByName('Cotton').Value := null;
    FieldByName('Linen').Value := null;
    FieldByName('Brand').Value := null;
    FieldByName('TestDenier').Value := null;
    FieldByName('Y_Composition').Value := null;
    FieldByName('MeterQty').Value := null;
    FieldByName('PTNo').Value := null;
    Post;
  end;
end;

procedure TfrmTatClothInfoInput.MFDWPropertiesEditValueChanged(Sender: TObject);
begin
  JSKZ();
end;

procedure TfrmTatClothInfoInput.N1Click(Sender: TObject);
begin
  with CDS_1 do
  begin
    CDS_1.edit;
    FieldByName('Y_Code').Value := null;
    FieldByName('Y_Name').Value := null;
    FieldByName('Y_Spec').Value := null;
    FieldByName('Y_Color').Value := null;
    FieldByName('YarnQty').Value := null;
    FieldByName('CycleYarnQty').Value := null;
    FieldByName('FF').Value := null;
    FieldByName('ND').Value := null;
    FieldByName('Dacron').Value := null;
    FieldByName('Cotton').Value := null;
    FieldByName('Linen').Value := null;
    FieldByName('Brand').Value := null;
    FieldByName('TestDenier').Value := null;
    FieldByName('Y_Composition').Value := null;
    FieldByName('MeterQty').Value := null;
    FieldByName('PTNo').Value := null;
    Post;
  end;
end;

procedure TfrmTatClothInfoInput.JSKZ();
var
  SumJS, SumWS: double;
  FJinSha, FWeiSha: string;
begin
//  C_GramWeight.SetFocus;
//
//  if Tv1.DataController.Summary.FooterSummaryValues[0] <> null then
//  begin
//    SumJS := Tv1.DataController.Summary.FooterSummaryValues[0];
//  end
//  else
//  begin
//    SumJS := 0;
//  end;
//
//  if Tv2.DataController.Summary.FooterSummaryValues[0] <> null then
//  begin
//    SumWS := Tv2.DataController.Summary.FooterSummaryValues[0];
//  end
//  else
//  begin
//    SumWS := 0;
//  end;
//
//  C_GramWeight.text := floattostr(roundfloat((SumJS + SumWS) / 3, 2));
  /////////////生成规格 /////////////
  JinSha.text := JSGG;
  WeiSha.text := WSGG;

  FC_Spec := '';
  FC_Spec := C_Composition.text + ' (' + JSGG + ')*(' + WSGG + ') ' + C_FinishLongitudeDensity.text + '*' + C_FinishLatitudeDensity.text + ' ' + C_ReedWidth.text + MFDW.text;

  C_Spec.text := trim(FC_Spec);

  /////////////生成规格 /////////////
end;

procedure TfrmTatClothInfoInput.FormShow(Sender: TObject);
begin

  readCxGrid(self.Caption + 'TV11', Tv1, '样品管理');
  readCxGrid(self.Caption + 'TV22', Tv2, '样品管理');
//  readCxGrid(self.Caption + 'TV44', Tv4, '样品管理');

  InitGrid();

  JSJS();
  JSWS();
  JSKZ();

  if CopyInt = 1 then
  begin
    FBCIID := '';
    BCIID.text := '';
    C_Code.text := '';

    with CDS_1 do
    begin
      First;
      while not Eof do
      begin
        Edit;
        FieldByName('BCIID').Value := '';
        FieldByName('YRId').Value := '';
        Post;
        Next;
      end;
    end;

    with CDS_2 do
    begin
      First;
      while not Eof do
      begin
        Edit;
        FieldByName('BCIID').Value := '';
        FieldByName('YRId').Value := '';
        Post;
        Next;
      end;
    end;

  end;

end;

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

function TfrmTatClothInfoInput.SaveData(): Boolean;
var
  maxId, maxpbno, maxQZID, HZYRId, JsonStr: string;
  myStream: TADOBlobStream;
  myStream1: TMemoryStream;
begin

  try
    ADOQueryCmd.Connection.BeginTrans;
    if Trim(FBCIID) = '' then
    begin
      if GetLSNo(ADOQueryCmd, maxId, 'Y', 'BS_Cloth_Info', 4, 1) = False then
      begin
        Result := False;
        ADOQueryCmd.Connection.RollbackTrans;
        Application.MessageBox('取最大号失败！', '提示', 0);
        Exit;
      end;

      BCIID.Text := trim(maxId);
    end
    else
    begin
      maxId := Trim(FBCIID);
    end;
    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('select * from BS_Cloth_Info where BCIID=''' + Trim(FBCIID) + '''');
      Open;
    end;
    with ADOQueryCmd do
    begin
      if Trim(FBCIID) = '' then
      begin
        Append;
        FieldByName('CTID').Value := Trim(FCTID);
        FieldByName('FILLID').Value := Trim(DCode);
        FieldByName('FILLER').Value := Trim(DName);
        FieldByName('FILLTIME').Value := SGetServerDateTime(ADOQueryTemp);
      end
      else
      begin
        Edit;
        FieldByName('EDITER').Value := Trim(DName);
        FieldByName('EDITTIME').Value := SGetServerDateTime(ADOQueryTemp);
      end;
      FieldByName('BCIID').Value := Trim(maxId);

      FieldByName('QZF').Value := Trim(QZF.text);
      FieldByName('CZF').Value := Trim(CZF.text);
      FieldByName('CKF').Value := Trim(CKF.text);

      FieldByName('Y_Note_PLJ').Value := Trim(Y_Note_PLJ.text);
      FieldByName('Y_Note_PLW').Value := Trim(Y_Note_PLW.text);

      if trim(C_Code.Text) = '' then
        C_Code.Text := Trim(maxId);
      RTSetsavedata(ADOQueryCmd, 'BS_Cloth_Info', ScrollBox1, 2);
      Post;
    end;
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select count(*) as AA from BS_Cloth_Info where C_Code=''' + Trim(C_Code.Text) + '''');
      Open;
      if FieldByName('AA').AsInteger > 1 then
      begin
        ADOQueryCmd.Connection.RollbackTrans;
        Result := False;
        Application.MessageBox('编号重复！', '提示', 0);
        Exit;
      end;
    end;
    //////////////////////////            保存经丝配比表              //////////////////////////
    with CDS_1 do
    begin
      First;
      HZYRId := '';
      while not Eof do
      begin
        if Trim(CDS_1.fieldbyname('YRId').AsString) = '' then
        begin
          if GetLSNo(ADOQueryTemp, maxpbno, 'RJ', 'BS_Cloth_Yarn', 4, 1) = False then
          begin
            ADOQueryCmd.Connection.RollbackTrans;
            Application.MessageBox('取配比子流水号失败！', '提示', 0);
            Exit;
          end;
        end
        else
        begin
          maxpbno := Trim(CDS_1.fieldbyname('YRId').AsString);
        end;

        HZYRId := HZYRId + ';' + maxpbno;
        with ADOQueryCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from BS_Cloth_Yarn where ');
          sql.Add('  YRId=''' + Trim(maxpbno) + '''');
          Open;
        end;
        with ADOQueryCmd do
        begin
          if Trim(CDS_1.fieldbyname('YRId').AsString) = '' then
          begin
            Append;
            FieldByName('Filler').Value := Trim(DName);
            FieldByName('FillTime').Value := SGetServerDateTime(ADOQueryTemp);
          end
          else
          begin
            Edit;
            FieldByName('Editer').Value := Trim(DName);
            FieldByName('EditTime').Value := SGetServerDateTime(ADOQueryTemp);
          end;
          FieldByName('YRType').Value := '经丝';
          FieldByName('BCIID').Value := Trim(maxId);
          FieldByName('YRId').Value := Trim(maxpbno);
          RTSetSaveDataCDS(ADOQueryCmd, Tv2, CDS_1, 'BS_Cloth_Yarn', 0);
          Post;
        end;
        CDS_1.Edit;
        CDS_1.FieldByName('BCIID').Value := Trim(maxId);
        CDS_1.FieldByName('YRId').Value := Trim(maxpbno);

        Next;
      end;
    end;

    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('update BS_Cloth_Yarn set BCIID = rtrim(BCIID) + ''删'' where  YRType =''经丝'' and BCIID=''' + Trim(maxId) + '''');
      sql.Add('and  YRId not in (select RTValue from [dbo].[F_Tool_SplitString](''' + Trim(HZYRId) + '''');
      sql.Add(', '';'' ))');
      ExecSQL;
    end;




//////////////////////////            保存经丝配比表              //////////////////////////
//////////////////////////            保存纬丝配比表              //////////////////////////
    with CDS_2 do
    begin
      First;
      while not Eof do
      begin
        if Trim(CDS_2.fieldbyname('YRId').AsString) = '' then
        begin
          if GetLSNo(ADOQueryTemp, maxpbno, 'RJ', 'BS_Cloth_Yarn', 4, 1) = False then
          begin
            ADOQueryCmd.Connection.RollbackTrans;
            Application.MessageBox('取配比子流水号失败！', '提示', 0);
            Exit;
          end;
        end
        else
        begin
          maxpbno := Trim(CDS_2.fieldbyname('YRId').AsString);
        end;
        with ADOQueryCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from BS_Cloth_Yarn where ');
          sql.Add('  YRId=''' + Trim(maxpbno) + '''');
          Open;
        end;
        with ADOQueryCmd do
        begin
          if Trim(CDS_2.fieldbyname('YRId').AsString) = '' then
          begin
            Append;
            FieldByName('Filler').Value := Trim(DName);
            FieldByName('FillTime').Value := SGetServerDateTime(ADOQueryTemp);
          end
          else
          begin
            Edit;
            FieldByName('Editer').Value := Trim(DName);
            FieldByName('EditTime').Value := SGetServerDateTime(ADOQueryTemp);
          end;
          FieldByName('YRType').Value := '纬丝';
          FieldByName('BCIID').Value := Trim(maxId);
          FieldByName('YRId').Value := Trim(maxpbno);
          RTSetSaveDataCDS(ADOQueryCmd, Tv2, CDS_2, 'BS_Cloth_Yarn', 0);
          Post;
        end;
        CDS_2.Edit;
        CDS_2.FieldByName('BCIID').Value := Trim(maxId);
        CDS_2.FieldByName('YRId').Value := Trim(maxpbno);

        Next;
      end;
    end;
//////////////////////////            保存纬丝配比表              //////////////////////////
//////////////////////////            保存起综              //////////////////////////
//    with CDS_4 do
//    begin
//      First;
//      while not Eof do
//      begin
//        if Trim(CDS_4.fieldbyname('QZID').AsString) = '' then
//        begin
//          if GetLSNo(ADOQueryTemp, maxQZID, 'QZ', 'BS_CLoth_QZ', 4, 1) = False then
//            raise Exception.Create('取配比子流水号失败！');
//
//        end
//        else
//        begin
//          maxQZID := Trim(CDS_4.fieldbyname('QZID').AsString);
//        end;
//        with ADOQueryCmd do
//        begin
//          Close;
//          SQL.Clear;
//          sql.Add('select * from BS_CLoth_QZ where ');
//          sql.Add('  QZID=''' + Trim(maxQZID) + '''');
//          Open;
//        end;
//        with ADOQueryCmd do
//        begin
//          if Trim(CDS_4.fieldbyname('QZID').AsString) = '' then
//          begin
//            Append;
//          end
//          else
//          begin
//            Edit;
//          end;
//          FieldByName('BCIID').Value := Trim(maxId);
//          FieldByName('QZID').Value := Trim(maxQZID);
//          RTSetSaveDataCDS(ADOQueryCmd, Tv4, CDS_4, 'BS_CLoth_QZ', 0);
//          Post;
//        end;
//        CDS_4.Edit;
//        CDS_4.FieldByName('BCIID').Value := Trim(maxId);
//        CDS_4.FieldByName('QZID').Value := Trim(maxQZID);
//
//        Next;
//      end;
//    end;
//////////////////////////            保存起综              //////////////////////////
//    dxSpreadSheet1.SaveToFile('D:\FilesExcel.xlsx');
//    with ADOQueryCmd do
//    begin
//      close;
//      sql.Clear;
//      sql.Add(' select *  from BS_Cloth_Info_Excel where BCIID=''' + Trim(maxId) + '''');
//      open;
//    end;
//    with ADOQueryCmd do
//    begin
//      if ADOQueryCmd.IsEmpty then
//      begin
//        Append;
//      end
//      else
//      begin
//        Edit;
//      end;
//      FieldByName('BCIID').Value := maxId;
//      myStream := TADOBlobStream.Create(TBlobField(ADOQueryCmd.FieldByName('ExcelData')), bmWrite);
//
//      myStream1 := TMemoryStream.Create();
//      myStream1.LoadFromFile('D:\FilesExcel.xlsx');
//
//      tblobfield(FieldByName('xlsx')).LoadFromStream(myStream1);
//
//      dxSpreadSheet1.SaveToStream(myStream);
//      myStream.Free;
//      Post;
//    end;
//    if pos('接口异常', JsonStr) > 0 then
//    begin
//      raise Exception.Create(pchar(JsonStr));
//    end;
//
//    if pos('ResultList', JsonStr) = 0 then
//    begin
//      Application.MessageBox(pchar('获取库存失败:' + JsonGetChildObject(JsonStr, 'Info')), '提示', 0);
//    end
//    else
//    begin
//      JsonToCHDA(JsonStr, 'ResultList', CDS_2);
//    end;

    ADOQueryCmd.Connection.CommitTrans;
    FBCIID := maxId;
//    JsonStr := RTGetRequest('http://139.224.118.114:8081/execltoimg/' + trim(maxId));
    Result := True;
  except
    Result := False;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败!', '提示', 0);
  end;
end;

procedure TfrmTatClothInfoInput.CYJGGYBtnDnClick(Sender: TObject);
begin
  TBtnEditC(Sender).Text := '';
end;

procedure TfrmTatClothInfoInput.ToolButton10Click(Sender: TObject);
begin
  if CDS_4.IsEmpty then
    exit;
  if CDS_4.Locate('ssel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;
  if Application.MessageBox('确定要作废数据吗？作废后数据不能恢复。', '提示', 32 + 4) <> IDYES then
    Exit;
  CDS_4.DisableControls;
  with CDS_4 do
  begin
    First;
    while not Eof do
    begin
      if CDS_4.FieldByName('SSel').AsBoolean = True then
      begin
        if Trim(CDS_4.fieldbyname('QZID').AsString) <> '' then
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('delete BS_CLoth_QZ where QZID=''' + Trim(CDS_4.fieldbyname('QZID').AsString) + '''');
            ExecSQL;
          end;
        CDS_4.Delete;
      end
      else
        Next;

    end;

  end;
  CDS_4.EnableControls;
end;

procedure TfrmTatClothInfoInput.ToolButton11Click(Sender: TObject);
begin
  WriteCxGrid(self.Caption + 'TV11', Tv1, '样品管理');
  WriteCxGrid(self.Caption + 'TV22', Tv2, '样品管理');
//  WriteCxGrid(self.Caption + 'TV44', Tv4, '样品管理');
end;

procedure TfrmTatClothInfoInput.ToolButton1Click(Sender: TObject);
var
  MC_Code: string;
begin
  C_Name.SetFocus;
  if C_Name.Text = '' then
  begin
    Application.MessageBox('产品名称不能为空！', '提示', 0);
    Exit;
  end;

  if MFDW.Text = '' then
  begin
    Application.MessageBox('门幅单位不能为空！', '提示', 0);
    Exit;
  end;


//  CDS_1.First;
//  if Trim(CDS_1.fieldbyname('Y_Code').AsString) = '' then
//  begin
//    Application.MessageBox('至少需要填写一个经丝原料！', '提示', 0);
//    Exit;
//  end;
//
//  CDS_2.First;
//  if Trim(CDS_2.fieldbyname('Y_Code').AsString) = '' then
//  begin
//    Application.MessageBox('至少需要填写一个纬丝原料！', '提示', 0);
//    Exit;
//  end;

  if trim(C_Code.Text) = '' then
  begin

    if GetLSNo(ADOQueryCmd, MC_Code, 'C', 'BS_Cloth_Info', 4, 0) = False then
    begin
      Application.MessageBox('取最成品编号失败!', '提示', 0);
      Exit;
    end;
    C_Code.Text := MC_Code;
  end;

  JSJS();
  JSWS();
  JSKZ();

  if SaveData() then
  begin
    Application.MessageBox('保存成功！', '提示', 0);
    ModalResult := 1;
  end;
end;

procedure TfrmTatClothInfoInput.cxGridDBColumn1PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'Y_Name';
      flagname := '原料名称';
      if ShowModal = 1 then
      begin
        Self.CDS_2.Edit;
        Self.CDS_2.FieldByName('Y_Name').Value := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmTatClothInfoInput.cxGridDBColumn3PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmYarnInfoSel := TfrmYarnInfoSel.Create(Application);
    with frmYarnInfoSel do
    begin
      if ShowModal = 1 then
      begin
        with self.CDS_1 do
        begin
          Edit;

          FieldByName('Y_Code').Value := frmYarnInfoSel.CDS_1.fieldbyname('Y_Code').Value;
          FieldByName('Y_Name').Value := frmYarnInfoSel.CDS_1.fieldbyname('Y_Name').Value;

          FieldByName('Y_Spec').Value := frmYarnInfoSel.CDS_1.fieldbyname('Y_Spec').Value;
          FieldByName('Y_Color').Value := frmYarnInfoSel.CDS_1.fieldbyname('Y_Color').Value;

          FieldByName('FF').Value := frmYarnInfoSel.CDS_1.fieldbyname('FF').Value;
          FieldByName('ND').Value := frmYarnInfoSel.CDS_1.fieldbyname('ND').Value;

          FieldByName('Brand').Value := frmYarnInfoSel.CDS_1.fieldbyname('Brand').Value;
          FieldByName('Y_Composition').Value := frmYarnInfoSel.CDS_1.fieldbyname('Y_Composition').Value;
          FieldByName('TestDenier').Value := frmYarnInfoSel.CDS_1.fieldbyname('Denier').Value;
          FieldByName('Z_Number').Value :=  frmYarnInfoSel.CDS_1.fieldbyname('ZS').Value;
          Post;
        end;

        JSJS();
        JSWS();
        JSKZ();
      end;
    end;
  finally
    frmYarnInfoSel.Free;
  end;

end;

procedure TfrmTatClothInfoInput.cxGridDBColumn4PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'Y_Name';
      flagname := '原料名称';
      if ShowModal = 1 then
      begin
        Self.CDS_1.Edit;
        Self.CDS_1.FieldByName('Y_Name').Value := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmTatClothInfoInput.CYColorKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    Key := #0;
    SelectNext(ActiveControl as TWinControl, True, True);
  end;
end;

procedure TfrmTatClothInfoInput.C_CompositionPropertiesEditValueChanged(Sender: TObject);
begin
  JSKZ();
end;

procedure TfrmTatClothInfoInput.C_FinishLongitudeDensityPropertiesEditValueChanged(Sender: TObject);
begin
  JSKZ();
end;

procedure TfrmTatClothInfoInput.C_ReedWidthPropertiesEditValueChanged(Sender: TObject);
begin
  JSJS();
  JSWS();
  JSKZ();
end;

procedure TfrmTatClothInfoInput.C_WidthBtnDnClick(Sender: TObject);
begin
  TBtnEditC(Sender).Text := '';
  TBtnEditC(Sender).TxtCode := '';
end;

procedure TfrmTatClothInfoInput.C_WidthBtnUpClick(Sender: TObject);
var
  fsj: string;
  FWZ: Integer;
begin
  fsj := Trim(TEdit(Sender).Hint);
  FWZ := Pos('/', fsj);
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := Copy(fsj, 1, FWZ - 1);
      flagname := Copy(fsj, FWZ + 1, Length(fsj) - FWZ);
      if ShowModal = 1 then
      begin
        TEdit(Sender).Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmTatClothInfoInput.C_YarnQtyPropertiesEditValueChanged(Sender: TObject);
begin
  JSJS();
  JSWS();
end;

procedure TfrmTatClothInfoInput.Edit1KeyPress(Sender: TObject; var Key: Char);
var
  i, j: Integer;
begin
  if Key = #13 then
  begin

    if Edit1.Text <> '' then
    begin
      i := CDS_4.RecordCount;
      i := i + 1;
      with CDS_4 do
      begin
        Append;
        FieldByName('SSEL').Value := FALSE;
        FieldByName('XuNO').Value := i;
        FieldByName('DZZQZGL').Value := Trim(Edit1.Text);
        Post;
      end;
      Edit1.Text := '';
    end;

  end;
end;

procedure TfrmTatClothInfoInput.CYMFExit(Sender: TObject);
begin
//  if pos('"', trim(CYMF.Text)) = 0 then
//  begin
//    if pos('CM', trim(CYMF.Text)) = 0 then
//      CYMF.Text := trim(CYMF.Text) + 'CM';
//  end;

end;

procedure TfrmTatClothInfoInput.FormCreate(Sender: TObject);
begin
  inherited;
  try
    with ADOConnection1 do
    begin
      Connected := false;
      ConnectionString := DConString;
      Connected := true;
    end;
    ADOQueryBaseCmd.Connection := ADOConnection1;
    ADOQueryBaseTemp.Connection := ADOConnection1;
  except
    application.MessageBox('网络连接失败！', '提示信息');
  end;
//  LaYangDate.DateTime := SGetServerDateTime(ADOQueryTemp);
end;

procedure TfrmTatClothInfoInput.ToolButton6Click(Sender: TObject);
begin
  if trim(C_Code.Text) = '' then
    Exit;
  try
    frmAttachmentUpload := TfrmAttachmentUpload.Create(Application);
    with frmAttachmentUpload do
    begin
      FEditAuthority := True;
      fkeyNO := trim(C_Code.Text);
      fType := '成品档案';
      if ShowModal = 1 then
      begin

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

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

procedure TfrmTatClothInfoInput.ToolButton9Click(Sender: TObject);
var
  i, j: Integer;
begin
  for j := 0 to 5 do
  begin
    i := CDS_4.RecordCount;
    i := i + 1;
    with CDS_4 do
    begin
      Append;
      FieldByName('SSEL').Value := FALSE;
      FieldByName('XuNO').Value := i;
      Post;
    end;
  end;
end;

procedure TfrmTatClothInfoInput.TV1Column1PropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FFieldName: string;
  GS, ZGS, MF, DS, WM, TW: double;
begin

  mvalue := TcxTextEdit(Sender).EditingText;
  FFieldName := Trim(Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName);

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

  with CDS_1 do
  begin
    Edit;
    FieldByName(FFieldName).Value := mvalue;
    Post;

    if FieldByName('YarnQty').Value = null then
    begin
      GS := 0;   //根数
    end
    else
    begin
      GS := FieldByName('YarnQty').Value;   //根数
    end;

    if FieldByName('CycleYarnQty').Value = null then
    begin
      ZGS := 0; //循环根数
    end
    else
    begin
      ZGS := FieldByName('CycleYarnQty').Value; //循环根数
    end;

    MF := strtofloatdef(C_ReedWidth.text, 0);    //筘幅

    if FieldByName('TestDenier').Value = null then
    begin
      DS := 0;     //D数
    end
    else
    begin
      DS := FieldByName('TestDenier').Value;     //D数
    end;

    WM := strtofloatdef(C_FinishLatitudeDensity.text, 0); //纬密

    TW := strtofloatdef(C_YarnQty.text, 0); //头纹
  end;
  if ZGS <> 0 then
  begin
    with CDS_1 do
    begin
      Edit;
      FieldByName('MeterQty').Value := roundfloat(GS / ZGS * TW * DS / 9000, 2);
      Post;
    end;
  end;
  JSKZ();
end;

procedure TfrmTatClothInfoInput.Tv2Column1PropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FFieldName: string;
  GS, ZGS, MF, DS, WM: double;
begin

  mvalue := TcxTextEdit(Sender).EditingText;
  FFieldName := Trim(Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName);

  with CDS_2 do
  begin
    Edit;
    FieldByName(FFieldName).Value := mvalue;
    Post;

    if FieldByName('YarnQty').Value = null then
    begin
      GS := 0;   //根数
    end
    else
    begin
      GS := FieldByName('YarnQty').Value;   //根数
    end;

    if FieldByName('CycleYarnQty').Value = null then
    begin
      ZGS := 0; //循环根数
    end
    else
    begin
      ZGS := FieldByName('CycleYarnQty').Value; //循环根数
    end;

    MF := strtofloatdef(C_ReedWidth.text, 0);    //筘幅

    if FieldByName('TestDenier').Value = null then
    begin
      DS := 0;     //D数
    end
    else
    begin
      DS := FieldByName('TestDenier').Value;     //D数
    end;

    WM := strtofloatdef(C_FinishLatitudeDensity.text, 0); //纬密
  end;
  if ZGS <> 0 then
  begin
    with CDS_2 do
    begin
      Edit;
      FieldByName('MeterQty').Value := roundfloat(GS / ZGS * MF * DS * WM / 9000, 2);
      Post;
    end;
  end;
  JSKZ();
end;

procedure TfrmTatClothInfoInput.v2Column10PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmYarnInfoSel := TfrmYarnInfoSel.Create(Application);
    with frmYarnInfoSel do
    begin
      if ShowModal = 1 then
      begin
        with self.CDS_2 do
        begin
          Edit;
          FieldByName('Y_Code').Value := frmYarnInfoSel.CDS_1.fieldbyname('Y_Code').Value;
          FieldByName('Y_Name').Value := frmYarnInfoSel.CDS_1.fieldbyname('Y_Name').Value;

          FieldByName('Y_Spec').Value := frmYarnInfoSel.CDS_1.fieldbyname('Y_Spec').Value;
          FieldByName('Y_Color').Value := frmYarnInfoSel.CDS_1.fieldbyname('Y_Color').Value;

          FieldByName('FF').Value := frmYarnInfoSel.CDS_1.fieldbyname('FF').Value;
          FieldByName('ND').Value := frmYarnInfoSel.CDS_1.fieldbyname('ND').Value;

          FieldByName('Brand').Value := frmYarnInfoSel.CDS_1.fieldbyname('Brand').Value;
          FieldByName('Y_Composition').Value := frmYarnInfoSel.CDS_1.fieldbyname('Y_Composition').Value;
          FieldByName('TestDenier').Value := frmYarnInfoSel.CDS_1.fieldbyname('Denier').Value;
          FieldByName('Z_Number').Value := frmYarnInfoSel.CDS_1.fieldbyname('ZS').Value;
          Post;
        end;

        JSJS();
        JSWS();
        JSKZ();
      end;
    end;
  finally
    frmYarnInfoSel.Free;
  end;

end;

procedure TfrmTatClothInfoInput.WB_CodePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmWBSpecSel := TfrmWBSpecSel.Create(Application);
    with frmWBSpecSel do
    begin
      if ShowModal = 1 then
      begin
        Self.WB_Code.Text := Trim(frmWBSpecSel.CDS_1.fieldbyname('WB_Code').AsString);
        Self.WB_Name.Text := Trim(frmWBSpecSel.CDS_1.fieldbyname('WB_Name').AsString);

        Self.C_YarnQty.Text := Trim(frmWBSpecSel.CDS_1.fieldbyname('WB_YarnQty').AsString);
        Self.C_ReedNo.Text := Trim(frmWBSpecSel.CDS_1.fieldbyname('WB_ReedNo').AsString);
        Self.C_ReedWidth.Text := Trim(frmWBSpecSel.CDS_1.fieldbyname('WB_Width').AsString);

        Self.Y_Note_PLJ.Text := Trim(frmWBSpecSel.CDS_1.fieldbyname('WB_YarnArrNote').AsString);
        with ADOQuery1 do
        begin
          Close;
          sql.Clear;
          sql.Add(' select * from Tat_WB_Formula ');
          sql.Add(' where WBSID=''' + Trim(frmWBSpecSel.CDS_1.fieldbyname('WBSID').AsString) + '''');
          sql.Add(' Order by RowNo ');
          Open;
        end;

        self.CDS_1.EmptyDataSet;
        self.ADOQuery1.First;

        while not ADOQuery1.eof do
        begin
          with self.CDS_1 do
          begin
            APpend;
            FieldByName('RowNo').Value := ADOQuery1.fieldbyname('RowNo').Value;

            FieldByName('Y_Code').Value := ADOQuery1.fieldbyname('Y_Code').Value;
            FieldByName('Y_Name').Value := ADOQuery1.fieldbyname('Y_Name').Value;

            FieldByName('Y_Color').Value := ADOQuery1.fieldbyname('Y_Color').Value;
            FieldByName('Y_Spec').Value := ADOQuery1.fieldbyname('Y_Spec').Value;

            FieldByName('YarnQty').Value := ADOQuery1.fieldbyname('YarnQty').Value;
            FieldByName('CycleYarnQty').Value := ADOQuery1.fieldbyname('CycleYarnQty').Value;

            FieldByName('TestDenier').Value := ADOQuery1.fieldbyname('Denier').Value;

            FieldByName('FF').Value := ADOQuery1.fieldbyname('FF').Value;
            FieldByName('ND').Value := ADOQuery1.fieldbyname('ND').Value;
            Post;
          end;

          ADOQuery1.next;
        end;
        JSJS();
        JSWS();
        JSKZ();
      end;
    end;
  finally
    frmWBSpecSel.Free;
  end;
end;

end.

