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, dxSkinsCore, dxSkinsDefaultPainters,
  cxNavigator, dxDateRanges, dxBarBuiltInMenu, cxPC, System.ImageList,
  Vcl.ImgList, U_BaseInput, cxCheckBox, 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, dxScrollbarAnnotations, cxContainer, cxMemo, cxMaskEdit,
  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;
    cxGrid4: TcxGrid;
    TV4: TcxGridDBTableView;
    TV4Column1: TcxGridDBColumn;
    cxGridDBColumn16: TcxGridDBColumn;
    cxGridDBColumn17: TcxGridDBColumn;
    cxGridLevel5: TcxGridLevel;
    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_Width: TcxTextEdit;
    C_ReedNo: TcxTextEdit;
    C_GramWeight: TcxTextEdit;
    C_TestGramWeight: TcxTextEdit;
    C_MachLatitudeDensity: 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;
    QZF: TMemo;
    cxTabSheet4: TcxTabSheet;
    CZF: TMemo;
    cxTabSheet5: TcxTabSheet;
    CKF: TMemo;
    TV1Column11: TcxGridDBColumn;
    Tv2Column11: TcxGridDBColumn;
    Label11: TLabel;
    Label12: TLabel;
    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;
    ADOQuery1: TADOQuery;
    Label18: TLabel;
    Label19: TLabel;
    BBNo: TcxTextEdit;
    ZS: TcxTextEdit;
    TV1Column13: TcxGridDBColumn;
    TV1Column14: TcxGridDBColumn;
    Tv2Column13: TcxGridDBColumn;
    Tv2Column14: TcxGridDBColumn;
    PM_1: TPopupMenu;
    N1: TMenuItem;
    PM_2: TPopupMenu;
    MenuItem1: TMenuItem;
    Label20: TLabel;
    CK: TcxTextEdit;
    TV1Column15: TcxGridDBColumn;
    Tv2Column15: TcxGridDBColumn;
    Tv2Column16: TcxGridDBColumn;
    Label27: TLabel;
    LLKZ: TcxTextEdit;
    Label21: TLabel;
    C_FinishLatitudeDensity: TcxTextEdit;
    Label22: TLabel;
    C_Color: TcxComboBox;
    TV1Column16: TcxGridDBColumn;
    TV1Column17: TcxGridDBColumn;
    TV1Column18: TcxGridDBColumn;
    Tv2Column17: TcxGridDBColumn;
    Tv2Column18: TcxGridDBColumn;
    Tv2Column19: TcxGridDBColumn;
    Panel3: TPanel;
    Label23: TLabel;
    JSMoney: TcxTextEdit;
    Label24: TLabel;
    WSMoney: TcxTextEdit;
    Label25: TLabel;
    Label26: TLabel;
    ZJ: TcxTextEdit;
    ZZJGMoney1: TcxTextEdit;
    Label28: TLabel;
    Label29: TLabel;
    JL: TcxTextEdit;
    ZZJGMoney2: TcxTextEdit;
    Label30: TLabel;
    Money1: TcxTextEdit;
    Label31: TLabel;
    Shui: TcxTextEdit;
    Label32: TLabel;
    Money2: TcxTextEdit;
    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 C_ReedNoPropertiesChange(Sender: TObject);
    procedure CKPropertiesEditValueChanged(Sender: TObject);
    procedure C_YarnQtyClick(Sender: TObject);
    procedure C_YarnQtyExit(Sender: TObject);
    procedure LLKZClick(Sender: TObject);
    procedure LLKZExit(Sender: TObject);
    procedure C_GramWeightClick(Sender: TObject);
    procedure C_GramWeightExit(Sender: TObject);
  private
    canshu1: string;
    Fint: Integer;
    procedure InitGrid();
    procedure JSJS(); //计算经丝
    procedure JSWS(); //计算纬丝
    procedure JSKZ(); //计算克重

    procedure JSTW(); //计算头纹
    function SaveData(): Boolean;
    { Private declarations }
  public
    FBCIID, FCTID, FJurisdiction: string;
    CopyInt: Integer;

    { Public declarations }
  end;

var
  frmTatClothInfoInput: TfrmTatClothInfoInput;

implementation

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

{$R *.dfm}

procedure TfrmTatClothInfoInput.InitGrid();
begin
  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);
  SCSHData(ADOQueryTemp, Panel3, 2);

  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 BCPH=(select BCPH from Bs_Yarn_Info X where X.Y_Code=A.Y_Code) ');
    sql.Add(', SXPrice=(select SXPrice from Bs_Yarn_Info X where X.Y_Code=A.Y_Code)');
    sql.Add(', SXMoney= round ( (select SXPrice from Bs_Yarn_Info X where X.Y_Code=A.Y_Code) * A.MeterQty ,2)  ');
    sql.Add(' , 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 BCPH=(select BCPH from Bs_Yarn_Info X where X.Y_Code=A.Y_Code) ');
    sql.Add(', SXPrice=(select SXPrice from Bs_Yarn_Info X where X.Y_Code=A.Y_Code)');
    sql.Add(', SXMoney= round ( (select SXPrice from Bs_Yarn_Info X where X.Y_Code=A.Y_Code) * A.MeterQty ,2)  ');
    sql.Add(' , 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);

  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;
  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, ZSL, SXPrice: 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_Width.text, 0);    //筘幅

        TW := strtofloatdef(C_YarnQty.text, 0);    //头纹

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

        ZSL := FieldByName('ZSL').AsFloat;

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

        if FieldByName('SXPrice').Value = null then
        begin
          SXPrice := 0; //纱线价格
        end
        else
        begin
          SXPrice := FieldByName('SXPrice').Value; //纱线价格
        end;

      end;
      if ZGS <> 0 then
      begin
        with CDS_1 do
        begin
          Edit;
          FieldByName('MeterQty').Value := roundfloat(GS / ZGS * TW * DS / 9000 * (100 + ZSL) / 100, 2);
          FieldByName('SXMoney').Value := roundfloat(GS / ZGS * TW * DS / 9000 * (100 + ZSL) / 100, 2) * SXPrice;
          Post;
        end;
      end;
      next;
    end;
    First;
    EnableControls;
  end;
end;

procedure TfrmTatClothInfoInput.JSWS();
var
  GS, ZGS, MF, DS, WM, WSSH, SXPrice: 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_Width.text, 0);    //筘幅

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

        if FieldByName('WSSH').Value = null then
        begin
          WSSH := 0; //纬纱损耗
        end
        else
        begin
          WSSH := FieldByName('WSSH').Value; //纬纱损耗
        end;

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


        if FieldByName('SXPrice').Value = null then
        begin
          SXPrice := 0; //纱线价格
        end
        else
        begin
          SXPrice := FieldByName('SXPrice').Value; //纱线价格
        end;
      end;
      if ZGS <> 0 then
      begin
        with CDS_2 do
        begin
          Edit;
          FieldByName('MeterQty').Value := roundfloat(GS / ZGS * (MF + WSSH) * DS * WM / 9000, 2);
          FieldByName('SXMoney').Value := roundfloat(GS / ZGS * (MF + WSSH) * DS * WM / 9000, 2) * SXPrice;
          Post;
        end;
      end;
      next;
    end;
    First;
    EnableControls;
  end;
end;

procedure TfrmTatClothInfoInput.LLKZClick(Sender: TObject);
begin
  TV1Column1.Styles.Header := DataLink_ClothInfo.TextSHuangSe;
  TV1Column2.Styles.Header := DataLink_ClothInfo.TextSHuangSe;
  TV1Column6.Styles.Header := DataLink_ClothInfo.TextSHuangSe;
  TV1Column15.Styles.Header := DataLink_ClothInfo.TextSHuangSe;

  TV1Column1.Styles.Content := DataLink_ClothInfo.TextSHuangSe;
  TV1Column2.Styles.Content := DataLink_ClothInfo.TextSHuangSe;
  TV1Column6.Styles.Content := DataLink_ClothInfo.TextSHuangSe;
  TV1Column15.Styles.Content := DataLink_ClothInfo.TextSHuangSe;

  C_YarnQty.Style.Color := clMoneyGreen;

  TV2Column1.Styles.Header := DataLink_ClothInfo.TextSHuangSe;
  TV2Column2.Styles.Header := DataLink_ClothInfo.TextSHuangSe;
  TV2Column16.Styles.Header := DataLink_ClothInfo.TextSHuangSe;
  TV2Column6.Styles.Header := DataLink_ClothInfo.TextSHuangSe;

  TV2Column1.Styles.Content := DataLink_ClothInfo.TextSHuangSe;
  TV2Column2.Styles.Content := DataLink_ClothInfo.TextSHuangSe;
  TV2Column16.Styles.Content := DataLink_ClothInfo.TextSHuangSe;
  TV2Column6.Styles.Content := DataLink_ClothInfo.TextSHuangSe;
  C_FinishLatitudeDensity.Style.Color := clMoneyGreen;
end;

procedure TfrmTatClothInfoInput.LLKZExit(Sender: TObject);
begin

  TV1Column1.Styles.Header := DataLink_ClothInfo.FontBlue;
  TV1Column2.Styles.Header := DataLink_ClothInfo.FontBlue;
  TV1Column6.Styles.Header := DataLink_ClothInfo.FontBlue;
  TV1Column15.Styles.Header := DataLink_ClothInfo.FontBlue;

  TV1Column1.Styles.Content := DataLink_ClothInfo.FontBlue;
  TV1Column2.Styles.Content := DataLink_ClothInfo.FontBlue;
  TV1Column6.Styles.Content := DataLink_ClothInfo.FontBlue;
  TV1Column15.Styles.Content := DataLink_ClothInfo.FontBlue;

  C_YarnQty.Style.Color := clFuchsia;

  TV2Column1.Styles.Header := DataLink_ClothInfo.FontBlue;
  TV2Column2.Styles.Header := DataLink_ClothInfo.FontBlue;
  TV2Column16.Styles.Header := DataLink_ClothInfo.FontBlue;
  TV2Column6.Styles.Header := DataLink_ClothInfo.FontBlue;

  TV2Column1.Styles.Content := DataLink_ClothInfo.FontBlue;
  TV2Column2.Styles.Content := DataLink_ClothInfo.FontBlue;
  TV2Column16.Styles.Content := DataLink_ClothInfo.FontBlue;
  TV2Column6.Styles.Content := DataLink_ClothInfo.FontBlue;
  C_FinishLatitudeDensity.Style.Color := clWhite;

end;

procedure TfrmTatClothInfoInput.MenuItem1Click(Sender: TObject);
begin
  with CDS_2 do
  begin
    Edit;
    FieldByName('Y_Code').Value := null;
    FieldByName('Yarn_Name').Value := null;
    FieldByName('Y_Name').Value := null;
    FieldByName('Denier').Value := null;
    FieldByName('Z_Number').Value := null;
    FieldByName('F_Number').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('Y_Composition').Value := null;
    FieldByName('MeterQty').Value := null;
    FieldByName('PTNo').Value := null;
    FieldByName('YLLX').Value := null;
    FieldByName('WSSH').Value := null;
    FieldByName('SXPrice').Value := null;
    FieldByName('SXMoney').Value := null;
    Post;
  end;

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

procedure TfrmTatClothInfoInput.N1Click(Sender: TObject);
begin
  with CDS_1 do
  begin
    Edit;
    FieldByName('Y_Code').Value := null;
    FieldByName('Yarn_Name').Value := null;
    FieldByName('Y_Name').Value := null;
    FieldByName('Denier').Value := null;
    FieldByName('Z_Number').Value := null;
    FieldByName('F_Number').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('Y_Composition').Value := null;
    FieldByName('MeterQty').Value := null;
    FieldByName('PTNo').Value := null;
    FieldByName('ZSL').Value := null;
    FieldByName('SXPrice').Value := null;
    FieldByName('SXMoney').Value := null;
    Post;
  end;

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

procedure TfrmTatClothInfoInput.JSKZ();
var
  SumJS, SumWS, FJSMoney, FWSMoney: double;
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;

  //金额计算//
  if Tv1.DataController.Summary.FooterSummaryValues[1] <> null then
  begin
    FJSMoney := Tv1.DataController.Summary.FooterSummaryValues[1];
  end
  else
  begin
    FJSMoney := 0;
  end;

  if Tv2.DataController.Summary.FooterSummaryValues[1] <> null then
  begin
    FWSMoney := Tv2.DataController.Summary.FooterSummaryValues[1];
  end
  else
  begin
    FWSMoney := 0;
  end;

  JSMoney.text := FloatToStr(FJSMoney);
  WSMoney.text := floattostr(FWSMoney);

  ZZJGMoney2.text := floattostr(roundfloat(strtofloatdef(ZZJGMoney1.text, 0) * strtofloatdef(C_FinishLatitudeDensity.text, 0), 2));

  Money1.text := floattostr(roundfloat(strtofloatdef(JSMoney.text, 0) + strtofloatdef(WSMoney.text, 0) + strtofloatdef(ZZJGMoney2.text, 0) + strtofloatdef(ZJ.text, 0) + strtofloatdef(JL.text, 0), 2));

  Money2.text := floattostr(roundfloat(strtofloatdef(Money1.text, 0) * strtofloatdef(Shui.text, 0), 2));
  //金额计算//

  LLKZ.text := floattostr(roundfloat((SumJS + SumWS), 2));

  if strtofloatdef(C_Width.text, 0) > 0 then
    C_GramWeight.text := floattostr(roundfloat((SumJS + SumWS) / strtofloatdef(C_Width.text, 0) * 100, 2));
end;

procedure TfrmTatClothInfoInput.JSTW();
var
  FC_ReedNo, FC_Width, FCK, FC_YarnQty: Double;
begin
  FC_ReedNo := strtofloatdef(C_ReedNo.text, 0);
  FC_Width := strtofloatdef(C_Width.text, 0);
  FCK := strtofloatdef(CK.text, 0);

  FC_YarnQty := RoundFloat(FC_ReedNo * FC_Width * FCK, 2);

  C_YarnQty.text := FloatToStr(FC_YarnQty);
end;

procedure TfrmTatClothInfoInput.FormShow(Sender: TObject);
begin

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

  if FJurisdiction = '高权限' then
  begin
    ScrollBox1.Height := 520;
    Panel3.Visible := True;
  end
  else
  begin
    ScrollBox1.Height := 300;
    Panel3.Visible := false;
  end;

  InitGrid();
  JSTW();

  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: string;
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);
      RTSetsavedata(ADOQueryCmd, 'BS_Cloth_Info', Panel3, 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);
//          FieldByName('ZSL').Value := CDS_1.fieldbyname('ZSL').Value;
          RTSetSaveDataCDS(ADOQueryCmd, Tv1, 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;
//////////////////////////            保存起综              //////////////////////////
    ADOQueryCmd.Connection.CommitTrans;
    FBCIID := 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;

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

  if C_Code.Text = '' then
  begin
    Application.MessageBox('产品编号不能为空！', '提示', 0);
    Exit;
  end;

  if C_Name.Text = '' then
  begin
    Application.MessageBox('产品名称不能为空！', '提示', 0);
    Exit;
  end;

  if C_Color.Text = '' then
  begin
    Application.MessageBox('颜色不能为空！', '提示', 0);
    Exit;
  end;
  if C_Color.Text = '彩色' then
  begin
    if C_ColorNo.Text = '' then
    begin
      Application.MessageBox('颜色为彩色，色号不能为空！', '提示', 0);
      Exit;
    end;
  end;
  if C_Width.Text = '' then
  begin
    Application.MessageBox('门幅不能为空！', '提示', 0);
    Exit;
  end;

  if C_ReedNo.Text = '' then
  begin
    Application.MessageBox('筘号不能为空！', '提示', 0);
    Exit;
  end;

  if CK.Text = '' then
  begin
    Application.MessageBox('穿筘不能为空！', '提示', 0);
    Exit;
  end;

  if C_YarnQty.Text = '' then
  begin
    Application.MessageBox('总头纹不能为空！', '提示', 0);
    Exit;
  end;

  if C_MachLatitudeDensity.Text = '' then
  begin
    Application.MessageBox('下机纬密不能为空！', '提示', 0);
    Exit;
  end;

  if C_FinishLatitudeDensity.Text = '' then
  begin
    Application.MessageBox('上机纬密不能为空！', '提示', 0);
    Exit;
  end;

  if C_GramWeight.Text = '' then
  begin
    Application.MessageBox('理论平方克重不能为空！', '提示', 0);
    Exit;
  end;

  if LLKZ.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;
  with CDS_1 do
  begin

    while not eof do
    begin
      if Trim(CDS_1.fieldbyname('Y_Code').AsString) <> '' then
      begin

        if Trim(CDS_1.fieldbyname('ZSL').AsString) = '' then
        begin
          Application.MessageBox('织缩率不能为空！', '提示', 0);
          Exit;
        end;

        if Trim(CDS_1.fieldbyname('Denier').AsString) = '' then
        begin
          Application.MessageBox('D数不能为空！', '提示', 0);
          Exit;
        end;

        if Trim(CDS_1.fieldbyname('Z_Number').AsString) = '' then
        begin
          Application.MessageBox('支数不能为空！', '提示', 0);
          Exit;
        end;

        if Trim(CDS_1.fieldbyname('YarnQty').AsString) = '' then
        begin
          Application.MessageBox('根数不能为空！', '提示', 0);
          Exit;
        end;

        if Trim(CDS_1.fieldbyname('CycleYarnQty').AsString) = '' then
        begin
          Application.MessageBox('循环根数不能为空！', '提示', 0);
          Exit;
        end;

        if Trim(CDS_1.fieldbyname('MeterQty').AsString) = '' then
        begin
          Application.MessageBox('米应用量不能为空！', '提示', 0);
          Exit;
        end;

      end;

      next;
    end;
  end;

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

  with CDS_2 do
  begin

    while not eof do
    begin
      if Trim(CDS_2.fieldbyname('Y_Code').AsString) <> '' then
      begin

        if Trim(CDS_2.fieldbyname('WSSH').AsString) = '' then
        begin
          Application.MessageBox('纬纱损耗不能为空！', '提示', 0);
          Exit;
        end;

        if Trim(CDS_2.fieldbyname('Denier').AsString) = '' then
        begin
          Application.MessageBox('D数不能为空！', '提示', 0);
          Exit;
        end;

        if Trim(CDS_2.fieldbyname('Z_Number').AsString) = '' then
        begin
          Application.MessageBox('支数不能为空！', '提示', 0);
          Exit;
        end;

        if Trim(CDS_2.fieldbyname('YarnQty').AsString) = '' then
        begin
          Application.MessageBox('根数不能为空！', '提示', 0);
          Exit;
        end;

        if Trim(CDS_2.fieldbyname('CycleYarnQty').AsString) = '' then
        begin
          Application.MessageBox('循环根数不能为空！', '提示', 0);
          Exit;
        end;

        if Trim(CDS_2.fieldbyname('MeterQty').AsString) = '' then
        begin
          Application.MessageBox('米应用量不能为空！', '提示', 0);
          Exit;
        end;

      end;

      next;
    end;
  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;
  if SaveData() then
  begin
    Application.MessageBox('保存成功！', '提示', 0);
    ModalResult := 1;
  end;
end;

procedure TfrmTatClothInfoInput.CKPropertiesEditValueChanged(Sender: TObject);
begin
  JSTW();
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
//      iSDJ := 0;
//      LX := '经纱';
      if ShowModal = 1 then
      begin
        with self.CDS_1 do
        begin
          Edit;

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

          FieldByName('Denier').Value := frmYarnInfoSel.CDS_1.fieldbyname('Denier').Value;
          FieldByName('F_Number').Value := frmYarnInfoSel.CDS_1.fieldbyname('F_Number').Value;
          FieldByName('Z_Number').Value := frmYarnInfoSel.CDS_1.fieldbyname('Z_Number').Value;

          FieldByName('BCPH').Value := frmYarnInfoSel.CDS_1.fieldbyname('BCPH').Value;
          FieldByName('SXPrice').Value := frmYarnInfoSel.CDS_1.fieldbyname('SXPrice').Value;
          FieldByName('SXMoney').Value := 0;

          if Trim(frmYarnInfoSel.CDS_1.fieldbyname('ZSL').asstring) = '' then
          begin
            FieldByName('ZSL').Value := 8;
          end
          else
          begin
            FieldByName('ZSL').Value := frmYarnInfoSel.CDS_1.fieldbyname('ZSL').Value;
          end;

          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_GramWeightClick(Sender: TObject);
begin
  TV1Column1.Styles.Header := DataLink_ClothInfo.TextSHuangSe;
  TV1Column2.Styles.Header := DataLink_ClothInfo.TextSHuangSe;
  TV1Column6.Styles.Header := DataLink_ClothInfo.TextSHuangSe;
  TV1Column15.Styles.Header := DataLink_ClothInfo.TextSHuangSe;

  TV1Column1.Styles.Content := DataLink_ClothInfo.TextSHuangSe;
  TV1Column2.Styles.Content := DataLink_ClothInfo.TextSHuangSe;
  TV1Column6.Styles.Content := DataLink_ClothInfo.TextSHuangSe;
  TV1Column15.Styles.Content := DataLink_ClothInfo.TextSHuangSe;

  C_YarnQty.Style.Color := clMoneyGreen;
  LLKZ.Style.Color := clMoneyGreen;

  TV2Column1.Styles.Header := DataLink_ClothInfo.TextSHuangSe;
  TV2Column2.Styles.Header := DataLink_ClothInfo.TextSHuangSe;
  TV2Column16.Styles.Header := DataLink_ClothInfo.TextSHuangSe;
  TV2Column6.Styles.Header := DataLink_ClothInfo.TextSHuangSe;

  TV2Column1.Styles.Content := DataLink_ClothInfo.TextSHuangSe;
  TV2Column2.Styles.Content := DataLink_ClothInfo.TextSHuangSe;
  TV2Column16.Styles.Content := DataLink_ClothInfo.TextSHuangSe;
  TV2Column6.Styles.Content := DataLink_ClothInfo.TextSHuangSe;

  C_FinishLatitudeDensity.Style.Color := clMoneyGreen;
end;

procedure TfrmTatClothInfoInput.C_GramWeightExit(Sender: TObject);
begin
  TV1Column1.Styles.Header := DataLink_ClothInfo.FontBlue;
  TV1Column2.Styles.Header := DataLink_ClothInfo.FontBlue;
  TV1Column6.Styles.Header := DataLink_ClothInfo.FontBlue;
  TV1Column15.Styles.Header := DataLink_ClothInfo.FontBlue;

  TV1Column1.Styles.Content := DataLink_ClothInfo.FontBlue;
  TV1Column2.Styles.Content := DataLink_ClothInfo.FontBlue;
  TV1Column6.Styles.Content := DataLink_ClothInfo.FontBlue;
  TV1Column15.Styles.Content := DataLink_ClothInfo.FontBlue;

  C_YarnQty.Style.Color := clFuchsia;
  LLKZ.Style.Color := clFuchsia;

  TV2Column1.Styles.Header := DataLink_ClothInfo.FontBlue;
  TV2Column2.Styles.Header := DataLink_ClothInfo.FontBlue;
  TV2Column16.Styles.Header := DataLink_ClothInfo.FontBlue;
  TV2Column6.Styles.Header := DataLink_ClothInfo.FontBlue;

  TV2Column1.Styles.Content := DataLink_ClothInfo.FontBlue;
  TV2Column2.Styles.Content := DataLink_ClothInfo.FontBlue;
  TV2Column16.Styles.Content := DataLink_ClothInfo.FontBlue;
  TV2Column6.Styles.Content := DataLink_ClothInfo.FontBlue;

  C_FinishLatitudeDensity.Style.Color := clWhite;
end;

procedure TfrmTatClothInfoInput.C_ReedNoPropertiesChange(Sender: TObject);
begin
  JSTW();
end;

procedure TfrmTatClothInfoInput.C_ReedWidthPropertiesEditValueChanged(Sender: TObject);
begin
  JSTW();

  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_YarnQtyClick(Sender: TObject);
begin
  C_Width.Style.Color := clMoneyGreen;
  C_ReedNo.Style.Color := clMoneyGreen;
  CK.Style.Color := clMoneyGreen;
end;

procedure TfrmTatClothInfoInput.C_YarnQtyExit(Sender: TObject);
begin
  C_Width.Style.Color := clWhite;
  C_ReedNo.Style.Color := clWhite;
  CK.Style.Color := clWhite;
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, ZSL, SXPrice: double;
begin

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

  if FFieldName = 'ZSL' then
  begin
    if mvalue = '' then
      mvalue := '8';
  end
  else
  begin
    if mvalue = '' then
      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;

    ZSL := FieldByName('ZSL').AsFloat;

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

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

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

    TW := strtofloatdef(C_YarnQty.text, 0); //头纹


    if FieldByName('SXPrice').Value = null then
    begin
      SXPrice := 0; //纱线价格
    end
    else
    begin
      SXPrice := FieldByName('SXPrice').Value; //纱线价格
    end;

  end;
  if ZGS <> 0 then
  begin
    with CDS_1 do
    begin
      Edit;
      FieldByName('ZSL').Value := ZSL;
      FieldByName('MeterQty').Value := roundfloat(GS / ZGS * TW * DS / 9000 * (100 + ZSL) / 100, 2);

      FieldByName('SXMoney').Value := roundfloat(GS / ZGS * TW * DS / 9000 * (100 + ZSL) / 100, 2) * SXPrice;
      Post;
    end;
  end;
  JSKZ();
end;

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

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

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

  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;

    if FieldByName('WSSH').Value = null then
    begin
      WSSH := 0; //纬纱损耗
    end
    else
    begin
      WSSH := FieldByName('WSSH').Value; //纬纱损耗
    end;

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

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

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


    if FieldByName('SXPrice').Value = null then
    begin
      SXPrice := 0;     //纱线价格
    end
    else
    begin
      SXPrice := FieldByName('SXPrice').Value;      //纱线价格
    end;

  end;
  if ZGS <> 0 then
  begin
    with CDS_2 do
    begin
      Edit;
      FieldByName('MeterQty').Value := roundfloat(GS / ZGS * (MF + WSSH) * DS * WM / 9000, 2);
      FieldByName('SXMoney').Value := roundfloat(GS / ZGS * (MF + WSSH) * DS * WM / 9000, 2) * SXPrice;
      Post;
    end;
  end;
  JSKZ();
end;

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

          FieldByName('Denier').Value := frmYarnInfoSel.CDS_1.fieldbyname('Denier').Value;
          FieldByName('F_Number').Value := frmYarnInfoSel.CDS_1.fieldbyname('F_Number').Value;
          FieldByName('Z_Number').Value := frmYarnInfoSel.CDS_1.fieldbyname('Z_Number').Value;

          FieldByName('YLLX').Value := frmYarnInfoSel.CDS_1.fieldbyname('YLLX').Value;
          FieldByName('WSSH').Value := frmYarnInfoSel.CDS_1.fieldbyname('WSSH').Value;

          FieldByName('BCPH').Value := frmYarnInfoSel.CDS_1.fieldbyname('BCPH').Value;
          FieldByName('SXPrice').Value := frmYarnInfoSel.CDS_1.fieldbyname('SXPrice').Value;
          FieldByName('SXMoney').Value := 0;
          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_Width.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('Yarn_Name').Value := ADOQuery1.fieldbyname('Yarn_Name').Value;
            FieldByName('Y_Name').Value := ADOQuery1.fieldbyname('Y_Name').Value;

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

            Post;
          end;

          ADOQuery1.next;
        end;

      end;
    end;
  finally
    frmWBSpecSel.Free;
  end;
end;

end.

