unit U_TatWBPlanZJZKInPut;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
  cxEdit, DB, cxDBData, cxGridLevel, cxGridCustomTableView, cxGridTableView,
  cxGridDBTableView, cxClasses, cxControls, cxGridCustomView, cxGrid, cxMemo,
  cxRichEdit, ComCtrls, cxContainer, cxTextEdit, cxMaskEdit, cxButtonEdit,
  StdCtrls, ToolWin, DBClient, ADODB, ExtCtrls, BtnEdit, cxDropDownEdit,
  StrUtils, cxPC, ShellAPI, cxCalendar, Math, cxLookAndFeels,
  cxLookAndFeelPainters, dxBarBuiltInMenu, cxNavigator, dxDateRanges,
  U_BaseInput, System.ImageList, Vcl.ImgList, Vcl.Menus, dxScrollbarAnnotations,
  cxImageList, dxSkinsCore, dxSkinOffice2013White, dxSkinSharpPlus,
  dxSkinsDefaultPainters, dxSkinWXI, dxCoreGraphics;

type
  TfrmTatWBPlanZJZKInPut = class(TfrmBaseInput)
    ToolBar1: TToolBar;
    TBSave: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    ToolButton8: TToolButton;
    Panel2: TPanel;
    cxPageControl1: TcxPageControl;
    Panel5: TPanel;
    Panel6: TPanel;
    Label21: TLabel;
    ToolBar3: TToolBar;
    ToolButton3: TToolButton;
    ToolButton4: TToolButton;
    CDS_1: TClientDataSet;
    DS_1: TDataSource;
    ScrollBox1: TScrollBox;
    Label3: TLabel;
    Label14: TLabel;
    Label47: TLabel;
    Label2: TLabel;
    Label4: TLabel;
    Label6: TLabel;
    C_NAME: TEdit;
    WB_Code: TBtnEditC;
    WB_YarnTotalLen: TEdit;
    WB_Qty: TEdit;
    WB_YarnLen: TEdit;
    Label13: TLabel;
    TWPId: TEdit;
    Label15: TLabel;
    Label17: TLabel;
    WB_Name: TEdit;
    Label18: TLabel;
    WB_YarnQty: TEdit;
    Label20: TLabel;
    Label22: TLabel;
    WB_ReedNo: TEdit;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column18: TcxGridDBColumn;
    v1Column15: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    v1SPName: TcxGridDBColumn;
    v1SPSpec: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column7: TcxGridDBColumn;
    Tv1Column8: TcxGridDBColumn;
    Tv1Column9: TcxGridDBColumn;
    Tv1Column6: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    ADOQuery1: TADOQuery;
    Label7: TLabel;
    Label26: TLabel;
    Label27: TLabel;
    Label28: TLabel;
    Label29: TLabel;
    C_KCQTY: TcxTextEdit;
    WB_Width: TcxTextEdit;
    Label30: TLabel;
    Label31: TLabel;
    Label32: TLabel;
    WB_ReedNote: TcxTextEdit;
    BSQTY: TcxTextEdit;
    DCRQTY: TcxTextEdit;
    Z_SJKESHU1: TEdit;
    Z_BINGSHU: TEdit;
    Z_MAXKESHU: TEdit;
    GKBH: TcxButtonEdit;
    CustName: TcxButtonEdit;
    gyno: TcxButtonEdit;
    Tv1Column3: TcxGridDBColumn;
    Tv1Column4: TcxGridDBColumn;
    Label10: TLabel;
    C_CODE: TEdit;
    Label19: TLabel;
    Label24: TLabel;
    Tv1dbNumber: TcxGridDBColumn;
    Label33: TLabel;
    Label34: TLabel;
    BCRFQty: TcxTextEdit;
    WB_YarnKCQty: TcxTextEdit;
    Label35: TLabel;
    Label37: TLabel;
    Label38: TLabel;
    Label39: TLabel;
    Label40: TLabel;
    Label41: TLabel;
    Label42: TLabel;
    Tv1Supplier: TcxGridDBColumn;
    Tv1IOTime: TcxGridDBColumn;
    Label1: TLabel;
    F_yushu: TEdit;
    Tv1Column5: TcxGridDBColumn;
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure C_CodeKeyPress(Sender: TObject; var Key: Char);
    procedure ConNoKeyPress(Sender: TObject; var Key: Char);
    procedure MCTypeBtnUpClick(Sender: TObject);
    procedure CustNameBtnUpClick(Sender: TObject);
    procedure CustNameBtnDnClick(Sender: TObject);

    procedure ToolButton3Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure WB_CodeBtnUpClick(Sender: TObject);
    procedure gkbhBtnUpClick(Sender: TObject);
    procedure gynoDblClick(Sender: TObject);
    procedure Tv1Column7PropertiesEditValueChanged(Sender: TObject);
    procedure WB_YarnQtyExit(Sender: TObject);
    procedure cxButtonEdit1PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure gynoPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);

    procedure Tv1Column6PropertiesEditValueChanged(Sender: TObject);
    procedure WB_YarnTotalLenExit(Sender: TObject);
    procedure ButtonEdit(Sender: TObject; AButtonIndex: Integer);
  private
    procedure InitData();
    function SaveData(): Boolean;
    procedure JSJS();
    { Private declarations }
  public
    PState, FCopyInt: Integer;
    FConNo, FTWPId, FSubId: string;
    { Public declarations }
  end;

var
  frmTatWBPlanZJZKInPut: TfrmTatWBPlanZJZKInPut;
  newh: hwnd;

implementation

uses
  U_DataLink, U_ZDYHelp, U_RTFun, U_CompanySel, U_YarnInfoSel, U_TatPlanSel2,
  U_WBSpecSel, U_GKManageSel, U_WeaveSel, U_YarnStkSel, U_LogInput;

{$R *.dfm}

procedure TfrmTatWBPlanZJZKInPut.TBCloseClick(Sender: TObject);
begin
  ModalResult := 1;
end;

procedure TfrmTatWBPlanZJZKInPut.InitData();
var
  PBNO, PBFlag: string;
begin
  if PState = 1 then
  begin

  end;

  with ADOQueryTemp do
  begin
    Close;
    SQL.Clear;
    sql.Add('select * from Tat_WB_Plan A where A.TWPId=''' + Trim(FTWPId) + '''');
    Open;
  end;
  SCSHData(ADOQueryTemp, ScrollBox1, 0);

  CustName.Properties.LookupItems.Text := Trim(ADOQueryTemp.FieldByName('CustNo').AsString);

  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select A.*  from Tat_WB_Plan_Yarn A ');
    sql.Add(' where YRType=''大轴经丝'' and A.TWPId=''' + Trim(FTWPId) + '''');
    Open;
  end;
  SCreateCDS(ADOQueryTemp, CDS_1);
  SInitCDSData(ADOQueryTemp, CDS_1);

  if FCopyInt = 1 then
  begin
    FConNo := '';
    FTWPId := '';
    FSubId := '';
  end;
end;

procedure TfrmTatWBPlanZJZKInPut.FormShow(Sender: TObject);
begin
  InitData();
end;

procedure TfrmTatWBPlanZJZKInPut.gkbhBtnUpClick(Sender: TObject);
begin
  try
    frmGKManageSel := tfrmGKManageSel.Create(Application);
    with frmGKManageSel do
    begin

      if ShowModal = 1 then
      begin
        SELF.GKBH.Text := CDS_HZ.FieldByName('GKBH').AsString;
        SELF.WB_ReedNo.Text := CDS_HZ.FieldByName('GKKH').AsString;
      end;
    end;
  finally
    frmGKManageSel.Free;
  end;
end;

procedure TfrmTatWBPlanZJZKInPut.gynoDblClick(Sender: TObject);
begin
  inherited;
  TcxButtonEdit(Sender).Text := '';
end;

procedure TfrmTatWBPlanZJZKInPut.gynoPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmWeaveSel := TfrmWeaveSel.Create(Application);
    with frmWeaveSel do
    begin
      FISSJ := '否';
      if ShowModal = 1 then
      begin
        Self.GYNo.Text := CDS_1.FieldByName('OrderNo').asstring;
//        Self.GYNo.Properties.LookupItems.Text := CDS_1.FieldByName('Subid').asstring;
        Self.CustName.Text := CDS_1.FieldByName('CustName').asstring;
        Self.CustName.Properties.LookupItems.Text := CDS_1.FieldByName('CustNo').asstring;

        Self.WB_Code.Text := CDS_1.FieldByName('WB_Code').asstring;
        Self.C_NAME.Text := CDS_1.FieldByName('C_NAME').asstring;

        Self.C_CODE.Text := CDS_1.FieldByName('C_CODE').asstring;

        with ADOQueryTemp do
        begin
          close;
          sql.Clear;
          sql.Add(' select A.* ');
          sql.Add(' from Tat_WB_Spec A');
          sql.Add(' where WB_Code=''' + trim(WB_Code.Text) + ''' ');
          Open;
        end;

        Self.WB_YarnTotalLen.Text := Trim(CDS_1.fieldbyname('ORDQTY2').AsString);

        Self.WB_Code.Text := Trim(ADOQueryTemp.fieldbyname('WB_Code').AsString);
        Self.WB_Name.Text := Trim(ADOQueryTemp.fieldbyname('WB_Name').AsString);

        Self.WB_YarnQty.Text := ADOQueryTemp.fieldbyname('WB_YarnQty').asstring;

        Self.Z_BINGSHU.Text := ADOQueryTemp.fieldbyname('F_YarnStripQty').asstring;

        Self.Z_MAXKESHU.Text := ADOQueryTemp.fieldbyname('F_MAXKESHU').asstring;
        Self.Z_SJKESHU1.Text := ADOQueryTemp.fieldbyname('F_SJKESHU').asstring;

        Self.F_YUSHU.Text := ADOQueryTemp.fieldbyname('F_YUSHU').asstring;

        Self.gkbh.Text := Trim(ADOQueryTemp.fieldbyname('gkbh').AsString);
        Self.WB_Width.Text := Trim(ADOQueryTemp.fieldbyname('WB_Width').AsString);
        Self.C_KCQTY.Text := Trim(ADOQueryTemp.fieldbyname('C_KCQTY').AsString);
        Self.WB_ReedNo.Text := Trim(ADOQueryTemp.fieldbyname('WB_ReedNo').AsString);
        Self.WB_ReedNote.Text := Trim(ADOQueryTemp.fieldbyname('WB_ReedNote').AsString);
        Self.BSQTY.Text := Trim(ADOQueryTemp.fieldbyname('BSQTY').AsString);
        Self.DCRQTY.Text := Trim(ADOQueryTemp.fieldbyname('DCRQTY').AsString);

        Self.WB_YarnKCQty.Text := Trim(ADOQueryTemp.fieldbyname('WB_YarnKCQty').AsString);
        Self.BCRFQty.Text := Trim(ADOQueryTemp.fieldbyname('BCRFQty').AsString);

        with ADOQuery1 do
        begin
          Close;
          sql.Clear;
          sql.Add(' select A.*,MeterQty2=(select top 1 MeterQty from Tat_WB_Formula g where g.y_code=a.y_code and g.wbsid=(select wb_code from tat_plan_sub h where h.subid=a.subid))  from Tat_Plan_Yarn A  ');
          sql.Add(' where YRType=''经丝'' AND ISNULL(Y_CODE,'''')<>'''' and A.MainId=''' + Trim(CDS_1.fieldbyname('MAINID').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('ZS').Value := ADOQuery1.fieldbyname('Z_Number').Value;
            FieldByName('QFYARNQTY').Value := ADOQuery1.fieldbyname('QFYARNQTY').Value;
            FieldByName('MeterQty').Value := ADOQuery1.fieldbyname('MeterQty2').Value;

//            FieldByName('TZQTY').Value := ADOQuery1.fieldbyname('TZQTY').Value;
//            FieldByName('JHYLQTY').Value := ADOQuery1.fieldbyname('JHYLQTY').Value;

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

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

//            FieldByName('NOTE').Value := ADOQuery1.fieldbyname('NOTE').Value;

            Post;
          end;

          ADOQuery1.next;
        end;
      end;
    end;
  finally
    frmWeaveSel.Free;
  end;
  WB_YarnTotalLenExit(Sender);
end;

function TfrmTatWBPlanZJZKInPut.SaveData(): Boolean;
var
  maxno, maxsubno, maxpbno, maxpzno, maxsjno: string;
begin
  try
    ADOQueryCmd.Connection.BeginTrans;

    try
      if FTWPId <> '' then
      begin

        frmLogInput := TfrmLogInput.Create(Application);
        with frmLogInput do
        begin
          fWB_Code := Self.TWPId.Text;
          flogFlag := '整经计划信息修改';//日志中Model字段
          fFlag := '修改';

          if ShowModal = 1 then
          begin

          end;
        end;

      end;
    finally
      frmLogInput.Free;
    end;

    if Trim(FTWPId) = '' then
    begin
      if GetLSNo(ADOQueryCmd, maxno, 'JS', 'Tat_WB_Plan', 4, 1) = False then
        raise Exception.Create('生成流水号异常！');
      TWPId.Text := maxno;
    end
    else
    begin
      maxno := Trim(FTWPId);
    end;
//////////////////////////            保存主表              //////////////////////////
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      SQL.Add('select * from Tat_WB_Plan where TWPId=''' + Trim(FTWPId) + '''');
      Open;
    end;
    with ADOQueryCmd do
    begin
      if Trim(FTWPId) = '' then
      begin
        Append;
        FieldByName('Filler').Value := Trim(DName);
      end
      else
      begin
        Edit;
        FieldByName('Editer').Value := Trim(DName);
        FieldByName('EditTime').Value := SGetServerDateTime(ADOQueryTemp);
      end;
      FieldByName('TWPId').Value := Trim(maxno);
      FieldByName('custNo').Value := Trim(custName.Properties.LookupItems.Text);
      RTSetsavedata(ADOQueryCmd, 'Tat_WB_Plan', ScrollBox1, 0);
      Post;
    end;
//////////////////////////            保存主表              //////////////////////////

//////////////////////////            保存经丝配比表              //////////////////////////
    with CDS_1 do
    begin
      First;
      while not Eof do
      begin
        if Trim(CDS_1.fieldbyname('YRId').AsString) = '' then
        begin
          if GetLSNo(ADOQueryTemp, maxpbno, 'WY', 'Tat_WB_Plan_Yarn', 4, 1) = False then
            raise Exception.Create('取配比子流水号失败！');
        end
        else
        begin
          maxpbno := Trim(CDS_1.fieldbyname('YRId').AsString);
        end;
        with ADOQueryCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from Tat_WB_Plan_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('TWPId').Value := Trim(maxno);
          FieldByName('YRId').Value := Trim(maxpbno);
          RTSetsavedataCDS(ADOQueryCmd, Tv1, CDS_1, 'Tat_WB_Plan_Yarn', 0);
          Post;
        end;
        CDS_1.Edit;
        CDS_1.FieldByName('TWPId').Value := Trim(maxno);
        CDS_1.FieldByName('YRId').Value := Trim(maxpbno);

        Next;
      end;
    end;
//////////////////////////            保存经丝配比表              //////////////////////////


    ADOQueryCmd.Connection.CommitTrans;
    FTWPId := Trim(maxno);
    FSubId := Trim(maxsubno);
    Result := True;
  except
    Result := False;
    ADOQueryCmd.Connection.RollbackTrans;
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);

  end;
end;

procedure TfrmTatWBPlanZJZKInPut.TBSaveClick(Sender: TObject);
var
  FReal: Double;
  maxConNo: string;
begin
  ToolBar1.SetFocus();
  if Trim(CustName.Text) = '' then
  begin
    Application.MessageBox('客户不能为空!', '提示', 0);
    Exit;
  end;

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

procedure TfrmTatWBPlanZJZKInPut.ToolButton3Click(Sender: TObject);
begin
  try
    frmYarnInfoSel := TfrmYarnInfoSel.Create(Application);
    with frmYarnInfoSel do
    begin
      if ShowModal = 1 then
      begin
        with self.CDS_1 do
        begin
          Append;
          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('Denier').Value := frmYarnInfoSel.CDS_1.fieldbyname('Denier').Value;

          FieldByName('ZS').Value := frmYarnInfoSel.CDS_1.fieldbyname('ZS').Value;
          FieldByName('FF').Value := frmYarnInfoSel.CDS_1.fieldbyname('FF').Value;
          FieldByName('ND').Value := frmYarnInfoSel.CDS_1.fieldbyname('ND').Value;
          FieldByName('NOTE').Value := frmYarnInfoSel.CDS_1.fieldbyname('NOTE').Value;
          Post;
        end;

      end;
    end;
  finally
    frmYarnInfoSel.Free;
  end;
end;

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

procedure TfrmTatWBPlanZJZKInPut.Tv1Column6PropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FFieldName: string;
  ZS, ZGS, zms, ZDDZL: double;
begin

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

  with CDS_1 do
  begin
    Edit;
    FieldByName(FFieldName).Value := mvalue;
    Post;
    zms := StrToFloatDef(WB_YarnTotalLen.Text, 0);
    if FieldByName('QFYARNQTY').Value = null then
    begin
      ZGS := 0;   //QUANFU根数
    end
    else
    begin
      ZGS := FieldByName('QFYARNQTY').Value;   //全服根数
    end;

    if FieldByName('TZQTY').Value = null then
    begin
      ZDDZL := 0;
    end
    else
    begin
      ZDDZL := FieldByName('TZQTY').Value;
    end;

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

  end;
  if ZS <> 0 then
  begin
    with CDS_1 do
    begin
      Edit;
      FieldByName('MeterQty').Value := roundfloat(ZGS * 0.059 / ZS, 2);

      FieldByName('TMETER').Value := roundfloat(ZS * ZDDZL * 1693, 2);

      FieldByName('JHYLQTY').Value := roundfloat(ZGS * 0.059 / ZS / 100 * zms, 2);
      Post;
    end;
  end;

end;

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

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

  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;

//    if FieldByName('SH').Value = null then
//    begin
//      SUNHAO := 0; //损耗
//    end
//    else
//    begin
//      SUNHAO := FieldByName('SH').Value; //损耗
//    end;

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

    TW := strtofloatdef(WB_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;
end;

procedure TfrmTatWBPlanZJZKInPut.ButtonEdit(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmYarnStkSel := TfrmYarnStkSel.Create(Application);
    with frmYarnStkSel do
    begin
//      FstkName := Self.FstkName;
      if ShowModal = 1 then
      begin
        frmYarnStkSel.CDS_Main.DisableControls;
        with frmYarnStkSel.CDS_Main do
        begin

          with Self.CDS_1 do
          begin
            Edit;
            FieldByName('BatchNo').Value := frmYarnStkSel.CDS_Main.fieldbyname('BatchNo').Value;
            FieldByName('TZQTY').Value := frmYarnStkSel.CDS_Main.fieldbyname('singleWeight').Value;
            FieldByName('dbNumber').Value := frmYarnStkSel.CDS_Main.fieldbyname('dbNumber').Value;
            FieldByName('IoTime').Value := frmYarnStkSel.CDS_Main.fieldbyname('IoTime').Value;
            FieldByName('Supplier').Value := frmYarnStkSel.CDS_Main.fieldbyname('Supplier').Value;
            Post;
          end;
        end;
        frmYarnStkSel.CDS_Main.EnableControls;
      end;
    end;
  finally
    frmYarnStkSel.Free;
  end;
  Tv1Column6PropertiesEditValueChanged(Sender);
end;

procedure TfrmTatWBPlanZJZKInPut.WB_CodeBtnUpClick(Sender: TObject);
begin
  try
    frmWBSpecSel := TfrmWBSpecSel.Create(Application);
    with frmWBSpecSel do
    begin
      fWB_TYPE := '分条';
      if ShowModal = 1 then
      begin

        Self.WB_Code.Text := Trim(CDS_1.fieldbyname('WB_Code').AsString);
        Self.WB_Name.Text := Trim(CDS_1.fieldbyname('WB_Name').AsString);

        Self.WB_YarnQty.Text := CDS_1.fieldbyname('WB_YarnQty').asstring;
        Self.Z_BINGSHU.Text := CDS_1.fieldbyname('F_YarnStripQty').asstring;

        Self.Z_MAXKESHU.Text := CDS_1.fieldbyname('F_MAXKESHU').asstring;
        Self.Z_SJKESHU1.Text := CDS_1.fieldbyname('F_SJKESHU').asstring;

        Self.F_YUSHU.Text := CDS_1.fieldbyname('F_YUSHU').asstring;

        Self.gkbh.Text := Trim(CDS_1.fieldbyname('gkbh').AsString);
        Self.WB_Width.Text := Trim(CDS_1.fieldbyname('WB_Width').AsString);
        Self.C_KCQTY.Text := Trim(CDS_1.fieldbyname('C_KCQTY').AsString);
        Self.WB_ReedNo.Text := Trim(CDS_1.fieldbyname('WB_ReedNo').AsString);
        Self.WB_ReedNote.Text := Trim(CDS_1.fieldbyname('WB_ReedNote').AsString);
        Self.BSQTY.Text := Trim(CDS_1.fieldbyname('BSQTY').AsString);
        Self.DCRQTY.Text := Trim(CDS_1.fieldbyname('DCRQTY').AsString);

        Self.WB_YarnKCQty.Text := Trim(CDS_1.fieldbyname('WB_YarnKCQty').AsString);
        Self.BCRFQty.Text := Trim(CDS_1.fieldbyname('BCRFQty').AsString);
      end;
    end;
  finally
    frmWBSpecSel.Free;
  end;
end;

procedure TfrmTatWBPlanZJZKInPut.WB_YarnQtyExit(Sender: TObject);
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(WB_Width.text, 0);    //筘幅

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

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

       // WM := strtofloatdef(WB_YarnDensity.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;
end;

procedure TfrmTatWBPlanZJZKInPut.WB_YarnTotalLenExit(Sender: TObject);
var
  ZS, ZGS, zms: double;
begin
  with CDS_1 do
  begin
    DisableControls;
    first;
    while not eof do
    begin

      with CDS_1 do
      begin

        zms := StrToFloatDef(WB_YarnTotalLen.Text, 0);
        if FieldByName('QFYARNQTY').Value = null then
        begin
          ZGS := 0;   //QUANFU根数
        end
        else
        begin
          ZGS := FieldByName('QFYARNQTY').Value;   //全服根数
        end;

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

      end;
      if ZS <> 0 then
      begin
        with CDS_1 do
        begin
          Edit;
          FieldByName('MeterQty').Value := roundfloat(ZGS * 0.059 / ZS, 2);
          FieldByName('JHYLQTY').Value := roundfloat(ZGS * 0.059 / ZS / 100 * zms, 2);
          Post;
        end;
      end;
      next;

    end;
    First;
    EnableControls;
  end;
end;

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

procedure TfrmTatWBPlanZJZKInPut.MCTypeBtnUpClick(Sender: TObject);
var
  fsj: string;
  FWZ: Integer;
begin
  fsj := Trim(TBtnEditC(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
        TBtnEditC(Sender).Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;

end;

procedure TfrmTatWBPlanZJZKInPut.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(WB_Width.text, 0);    //筘幅

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

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

//        WM := strtofloatdef(WB_YarnDensity.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;
end;

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

  end;
end;

procedure TfrmTatWBPlanZJZKInPut.CustNameBtnDnClick(Sender: TObject);
begin
  TBtnEditC(Sender).TxtCode := '';
  TBtnEditC(Sender).Text := '';
end;

procedure TfrmTatWBPlanZJZKInPut.CustNameBtnUpClick(Sender: TObject);
begin
  try
    frmCompanySel := TfrmCompanySel.Create(Application);
    with frmCompanySel do
    begin
      FCoType := '客户';
      if ShowModal = 1 then
      begin
//        CustName.TxtCode := Trim(CDS_1.fieldbyname('CoCode').AsString);
        CustName.Text := Trim(CDS_1.fieldbyname('CoAbbrName').AsString);
      end;
    end;
  finally
    frmCompanySel.Free;
  end;

end;

procedure TfrmTatWBPlanZJZKInPut.cxButtonEdit1PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin

  try
    frmCompanySel := TfrmCompanySel.Create(Application);
    with frmCompanySel do
    begin
      FCoType := '客户';
      if ShowModal = 1 then
      begin
//        CustName.TxtCode := Trim(CDS_1.fieldbyname('CoCode').AsString);
        CustName.Properties.LookupItems.Text := Trim(CDS_1.FieldByName('cocode').asstring);
        CustName.Text := Trim(CDS_1.fieldbyname('CoAbbrName').AsString);
      end;
    end;
  finally
    frmCompanySel.Free;
  end;
end;

end.

