unit U_ShuttleClothSCInPut;

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;

type
  TfrmClothSCInPut = class(TForm)
    ToolBar1: TToolBar;
    TBSave: TToolButton;
    TBClose: TToolButton;
    ScrollBox1: TScrollBox;
    Label1: TLabel;
    ConNo: TEdit;
    Label2: TLabel;
    QDTime: TDateTimePicker;
    Label3: TLabel;
    Label11: TLabel;
    CarType: TcxButtonEdit;
    Label14: TLabel;
    CompanyName: TcxButtonEdit;
    Label15: TLabel;
    ZhuanQty: TEdit;
    ADOQueryTemp: TADOQuery;
    Label18: TLabel;
    Panel2: TPanel;
    ToolBar3: TToolBar;
    tbADD: TToolButton;
    tbDEL: TToolButton;
    DS_YuanLiao: TDataSource;
    CDS_YuanLiao: TClientDataSet;
    DayQty: TEdit;
    Label21: TLabel;
    Label22: TLabel;
    ADOQueryCmd: TADOQuery;
    Label5: TLabel;
    DeliveryDate: TDateTimePicker;
    Label4: TLabel;
    C_Color: TEdit;
    Label6: TLabel;
    Label8: TLabel;
    Label12: TLabel;
    PiKgQty: TEdit;
    PiQty: TEdit;
    Label10: TLabel;
    Label13: TLabel;
    C_Qty: TEdit;
    Label16: TLabel;
    cxPageControl1: TcxPageControl;
    cxTabSheet1: TcxTabSheet;
    cxTabSheet2: TcxTabSheet;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    v2Column2: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    v2Column4: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    cxTabSheet4: TcxTabSheet;
    Panel1: TPanel;
    Panel3: TPanel;
    cxGrid6: TcxGrid;
    Tv6: TcxGridDBTableView;
    cxGridDBColumn41: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    cxGridDBColumn42: TcxGridDBColumn;
    cxGridLevel4: TcxGridLevel;
    CDS_Fujian: TClientDataSet;
    DS_Fujian: TDataSource;
    CDS_Sanjiao: TClientDataSet;
    DS_Paizhen: TDataSource;
    CDS_Paizhen: TClientDataSet;
    DS_Sanjiao: TDataSource;
    Panel4: TPanel;
    Label26: TLabel;
    Label27: TLabel;
    Label28: TLabel;
    PiZhong: TEdit;
    Label7: TLabel;
    ZongZhenQty: TEdit;
    Label23: TLabel;
    ChouZhen: TcxButtonEdit;
    Label24: TLabel;
    v2Column1: TcxGridDBColumn;
    v2Column3: TcxGridDBColumn;
    v2Column5: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    Label31: TLabel;
    Label36: TLabel;
    PiKgQtyFD: TEdit;
    Label37: TLabel;
    Label40: TLabel;
    C_Note: TRichEdit;
    v2Column7: TcxGridDBColumn;
    v2Column8: TcxGridDBColumn;
    v2Column10: TcxGridDBColumn;
    v2Column11: TcxGridDBColumn;
    Label42: TLabel;
    LabName: TComboBox;
    Label44: TLabel;
    KHConNo: TEdit;
    Label45: TLabel;
    BatchNoHZ: TEdit;
    Label47: TLabel;
    Label33: TLabel;
    BZNote: TcxButtonEdit;
    Label35: TLabel;
    ZZSH: TcxButtonEdit;
    Label52: TLabel;
    MFZZS: TcxButtonEdit;
    Label54: TLabel;
    gongyi: TcxButtonEdit;
    C_Spec: TRichEdit;
    SJCarNO: TcxButtonEdit;
    KZ: TEdit;
    MF: TEdit;
    C_Code: TcxButtonEdit;
    C_CodeName: TEdit;
    KHName: TcxButtonEdit;
    Label43: TLabel;
    YWY: TcxButtonEdit;
    Label50: TLabel;
    PBMF: TEdit;
    Label51: TLabel;
    PBKZ: TEdit;
    cxGrid5: TcxGrid;
    TV5: TcxGridDBTableView;
    cxGridDBColumn32: TcxGridDBColumn;
    cxGridDBColumn34: TcxGridDBColumn;
    cxGridDBColumn35: TcxGridDBColumn;
    cxGridDBColumn36: TcxGridDBColumn;
    cxGridDBColumn37: TcxGridDBColumn;
    cxGridDBColumn38: TcxGridDBColumn;
    cxGridDBColumn39: TcxGridDBColumn;
    cxGridDBColumn40: TcxGridDBColumn;
    cxGridDBColumn43: TcxGridDBColumn;
    cxGridDBColumn44: TcxGridDBColumn;
    cxGridDBColumn45: TcxGridDBColumn;
    cxGridDBColumn46: TcxGridDBColumn;
    cxGridDBColumn47: TcxGridDBColumn;
    cxGridDBColumn48: TcxGridDBColumn;
    cxGridDBColumn49: TcxGridDBColumn;
    cxGridDBColumn50: TcxGridDBColumn;
    cxGridDBColumn51: TcxGridDBColumn;
    cxGridDBColumn52: TcxGridDBColumn;
    cxGridDBColumn53: TcxGridDBColumn;
    cxGridDBColumn54: TcxGridDBColumn;
    cxGridDBColumn55: TcxGridDBColumn;
    cxGridDBColumn56: TcxGridDBColumn;
    cxGridDBColumn57: TcxGridDBColumn;
    cxGridDBColumn58: TcxGridDBColumn;
    cxGridDBColumn59: TcxGridDBColumn;
    cxGridDBColumn60: TcxGridDBColumn;
    cxGridDBColumn61: TcxGridDBColumn;
    cxGridDBColumn62: TcxGridDBColumn;
    cxGridDBColumn63: TcxGridDBColumn;
    cxGridDBColumn64: TcxGridDBColumn;
    cxGridDBColumn65: TcxGridDBColumn;
    cxGridDBColumn66: TcxGridDBColumn;
    cxGridDBColumn67: TcxGridDBColumn;
    cxGridDBColumn68: TcxGridDBColumn;
    cxGridDBColumn69: TcxGridDBColumn;
    cxGridDBColumn70: TcxGridDBColumn;
    cxGridDBColumn71: TcxGridDBColumn;
    cxGridDBColumn72: TcxGridDBColumn;
    cxGridDBColumn73: TcxGridDBColumn;
    cxGridDBColumn74: TcxGridDBColumn;
    cxGridDBColumn75: TcxGridDBColumn;
    cxGridDBColumn76: TcxGridDBColumn;
    cxGridDBColumn77: TcxGridDBColumn;
    cxGridDBColumn78: TcxGridDBColumn;
    cxGridDBColumn79: TcxGridDBColumn;
    cxGridDBColumn80: TcxGridDBColumn;
    cxGridDBColumn81: TcxGridDBColumn;
    cxGridDBColumn82: TcxGridDBColumn;
    cxGridDBColumn83: TcxGridDBColumn;
    cxGridDBColumn84: TcxGridDBColumn;
    cxGridDBColumn85: TcxGridDBColumn;
    cxGridDBColumn86: TcxGridDBColumn;
    cxGridDBColumn87: TcxGridDBColumn;
    cxGridDBColumn88: TcxGridDBColumn;
    cxGridDBColumn89: TcxGridDBColumn;
    cxGridDBColumn90: TcxGridDBColumn;
    cxGridDBColumn91: TcxGridDBColumn;
    cxGridDBColumn92: TcxGridDBColumn;
    cxGridDBColumn93: TcxGridDBColumn;
    cxGridDBColumn94: TcxGridDBColumn;
    cxGridDBColumn95: TcxGridDBColumn;
    cxGridDBColumn96: TcxGridDBColumn;
    cxGridDBColumn97: TcxGridDBColumn;
    cxGridDBColumn98: TcxGridDBColumn;
    cxGridDBColumn99: TcxGridDBColumn;
    cxGridDBColumn100: TcxGridDBColumn;
    cxGridDBColumn101: TcxGridDBColumn;
    cxGridDBColumn102: TcxGridDBColumn;
    cxGridDBColumn103: TcxGridDBColumn;
    cxGridDBColumn104: TcxGridDBColumn;
    cxGridDBColumn105: TcxGridDBColumn;
    cxGridDBColumn106: TcxGridDBColumn;
    cxGridDBColumn107: TcxGridDBColumn;
    cxGridDBColumn108: TcxGridDBColumn;
    cxGridDBColumn109: TcxGridDBColumn;
    cxGridDBColumn110: TcxGridDBColumn;
    cxGridDBColumn111: TcxGridDBColumn;
    cxGridDBColumn112: TcxGridDBColumn;
    cxGridDBColumn113: TcxGridDBColumn;
    cxGridDBColumn114: TcxGridDBColumn;
    cxGridDBColumn115: TcxGridDBColumn;
    cxGridDBColumn116: TcxGridDBColumn;
    cxGridDBColumn117: TcxGridDBColumn;
    cxGridDBColumn118: TcxGridDBColumn;
    cxGridDBColumn119: TcxGridDBColumn;
    cxGridLevel6: TcxGridLevel;
    cxGrid3: TcxGrid;
    Tv3: TcxGridDBTableView;
    v3Column37: TcxGridDBColumn;
    v3Column38: TcxGridDBColumn;
    v3Column1: TcxGridDBColumn;
    v3Column2: TcxGridDBColumn;
    v3Column3: TcxGridDBColumn;
    v3Column4: TcxGridDBColumn;
    v3Column5: TcxGridDBColumn;
    v3Column6: TcxGridDBColumn;
    v3Column7: TcxGridDBColumn;
    v3Column8: TcxGridDBColumn;
    v3Column9: TcxGridDBColumn;
    v3Column10: TcxGridDBColumn;
    v3Column11: TcxGridDBColumn;
    v3Column12: TcxGridDBColumn;
    v3Column13: TcxGridDBColumn;
    v3Column14: TcxGridDBColumn;
    v3Column15: TcxGridDBColumn;
    v3Column16: TcxGridDBColumn;
    v3Column17: TcxGridDBColumn;
    v3Column18: TcxGridDBColumn;
    v3Column19: TcxGridDBColumn;
    v3Column20: TcxGridDBColumn;
    v3Column21: TcxGridDBColumn;
    v3Column22: TcxGridDBColumn;
    v3Column23: TcxGridDBColumn;
    v3Column24: TcxGridDBColumn;
    v3Column25: TcxGridDBColumn;
    v3Column26: TcxGridDBColumn;
    v3Column27: TcxGridDBColumn;
    v3Column28: TcxGridDBColumn;
    v3Column29: TcxGridDBColumn;
    v3Column30: TcxGridDBColumn;
    v3Column31: TcxGridDBColumn;
    v3Column32: TcxGridDBColumn;
    v3Column33: TcxGridDBColumn;
    v3Column34: TcxGridDBColumn;
    v3Column35: TcxGridDBColumn;
    v3Column36: TcxGridDBColumn;
    v3Column39: TcxGridDBColumn;
    v3Column40: TcxGridDBColumn;
    v3Column41: TcxGridDBColumn;
    v3Column42: TcxGridDBColumn;
    v3Column43: TcxGridDBColumn;
    v3Column44: TcxGridDBColumn;
    v3Column45: TcxGridDBColumn;
    v3Column46: TcxGridDBColumn;
    v3Column47: TcxGridDBColumn;
    v3Column48: TcxGridDBColumn;
    v3Column49: TcxGridDBColumn;
    v3Column50: TcxGridDBColumn;
    v3Column51: TcxGridDBColumn;
    v3Column52: TcxGridDBColumn;
    v3Column53: TcxGridDBColumn;
    v3Column54: TcxGridDBColumn;
    v3Column55: TcxGridDBColumn;
    v3Column56: TcxGridDBColumn;
    v3Column57: TcxGridDBColumn;
    v3Column58: TcxGridDBColumn;
    v3Column59: TcxGridDBColumn;
    v3Column60: TcxGridDBColumn;
    v3Column61: TcxGridDBColumn;
    v3Column62: TcxGridDBColumn;
    v3Column63: TcxGridDBColumn;
    v3Column64: TcxGridDBColumn;
    v3Column65: TcxGridDBColumn;
    v3Column66: TcxGridDBColumn;
    v3Column67: TcxGridDBColumn;
    v3Column68: TcxGridDBColumn;
    v3Column69: TcxGridDBColumn;
    v3Column70: TcxGridDBColumn;
    v3Column71: TcxGridDBColumn;
    v3Column72: TcxGridDBColumn;
    v3Column73: TcxGridDBColumn;
    v3Column74: TcxGridDBColumn;
    v3Column75: TcxGridDBColumn;
    v3Column76: TcxGridDBColumn;
    v3Column77: TcxGridDBColumn;
    v3Column78: TcxGridDBColumn;
    v3Column79: TcxGridDBColumn;
    v3Column80: TcxGridDBColumn;
    v3Column81: TcxGridDBColumn;
    v3Column82: TcxGridDBColumn;
    v3Column83: TcxGridDBColumn;
    v3Column84: TcxGridDBColumn;
    v3Column85: TcxGridDBColumn;
    v3Column86: TcxGridDBColumn;
    v3Column87: TcxGridDBColumn;
    v3Column88: TcxGridDBColumn;
    v3Column89: TcxGridDBColumn;
    v3Column90: TcxGridDBColumn;
    v3Column91: TcxGridDBColumn;
    v3Column92: TcxGridDBColumn;
    v3Column93: TcxGridDBColumn;
    v3Column94: TcxGridDBColumn;
    v3Column95: TcxGridDBColumn;
    v3Column96: TcxGridDBColumn;
    v3Column97: TcxGridDBColumn;
    v3Column98: TcxGridDBColumn;
    v3Column99: TcxGridDBColumn;
    v3Column100: TcxGridDBColumn;
    v3Column101: TcxGridDBColumn;
    v3Column102: TcxGridDBColumn;
    v3Column103: TcxGridDBColumn;
    v3Column104: TcxGridDBColumn;
    v3Column105: TcxGridDBColumn;
    v3Column106: TcxGridDBColumn;
    v3Column107: TcxGridDBColumn;
    v3Column108: TcxGridDBColumn;
    v3Column109: TcxGridDBColumn;
    v3Column110: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    v3Column111: TcxGridDBColumn;
    v3Column112: TcxGridDBColumn;
    v3Column113: TcxGridDBColumn;
    v3Column114: TcxGridDBColumn;
    v3Column115: TcxGridDBColumn;
    v3Column116: TcxGridDBColumn;
    v3Column117: TcxGridDBColumn;
    v3Column118: TcxGridDBColumn;
    v3Column119: TcxGridDBColumn;
    v3Column120: TcxGridDBColumn;
    v3Column121: TcxGridDBColumn;
    v3Column122: TcxGridDBColumn;
    v3Column123: TcxGridDBColumn;
    v3Column124: TcxGridDBColumn;
    v3Column125: TcxGridDBColumn;
    v3Column126: TcxGridDBColumn;
    v3Column127: TcxGridDBColumn;
    v3Column128: TcxGridDBColumn;
    v3Column129: TcxGridDBColumn;
    v3Column130: TcxGridDBColumn;
    v3Column131: TcxGridDBColumn;
    v3Column132: TcxGridDBColumn;
    v3Column133: TcxGridDBColumn;
    v3Column134: TcxGridDBColumn;
    v3Column135: TcxGridDBColumn;
    v3Column136: TcxGridDBColumn;
    v3Column137: TcxGridDBColumn;
    v3Column138: TcxGridDBColumn;
    v3Column139: TcxGridDBColumn;
    v3Column140: TcxGridDBColumn;
    v3Column141: TcxGridDBColumn;
    v3Column142: TcxGridDBColumn;
    v3Column143: TcxGridDBColumn;
    v3Column144: TcxGridDBColumn;
    v3Column145: TcxGridDBColumn;
    v3Column146: TcxGridDBColumn;
    v2Column12: TcxGridDBColumn;
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure C_CodeNamePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure tbADDClick(Sender: TObject);
    procedure tbDELClick(Sender: TObject);
    procedure cxGridDBColumn1PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v2Column2PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure Tv6DblClick(Sender: TObject);
    procedure Tv3MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure Tv5MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure v2Column11PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure C_CodePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure KHNamePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure PiKgQtyChange(Sender: TObject);
    procedure PiQtyChange(Sender: TObject);
    procedure C_CodeKeyPress(Sender: TObject; var Key: Char);
    procedure ConNoKeyPress(Sender: TObject; var Key: Char);
  private
    FXS, Fint: Integer;
    procedure InitData();
    procedure ZDYHelp(FButn: TcxButtonEdit; LType: string);
    function SaveData(): Boolean;
    { Private declarations }
  public
    PState, FCopyInt: Integer;
    FMainId, FConNo, PType, FSubId: string;
    { Public declarations }
  end;

var
  frmClothSCInPut: TfrmClothSCInPut;
  newh: hwnd;

implementation

uses
  U_DataLink, U_ZDYHelp, U_RTFun, U_ZdyAttachGYS, U_ContractListNXSel,
  U_CompressionFun, U_FjList_RZ, U_CPManageFMSel, U_ZdyAttachment;

{$R *.dfm}

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

procedure TfrmClothSCInPut.InitData();
var
  PBNO, PBFlag: string;
begin

/////////////////刷新产品信息/////////////////////////
  with ADOQueryTemp do
  begin
    Close;
    SQL.Clear;
    sql.Add(' select A.*,B.* from Cloth_Main A inner join Cloth_Sub B on A.MainId=B.MainId');
    if PState = 1 then
    begin
      sql.Add(' where A.MainId=' + Quotedstr(Trim(FMainId)));
    end;
    if PState = 0 then
    begin
      sql.Add('  where 1<>1 ');
    end;
    Open;
  end;
  SCSHData(ADOQueryTemp, ScrollBox1, 0);
  SCSHData(ADOQueryTemp, ScrollBox1, 2);
 /////////////////刷新产品信息/////////////////////////

 /////////////////刷新原料/////////////////////////
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select A.* ');
    sql.Add(',YLQty=Cast(C_Qty*PBQty*0.01*(1+isnull(ZPSH,0)*0.01) as decimal(18,1))');
    sql.Add('from Cloth_YCL_PB A ');
    sql.Add('inner join Cloth_Sub B on A.SubId=B.SubId');
    SQL.Add(' inner join Cloth_Main C on B.Mainid=C.MainId');
    sql.Add(' where A.MainId=''' + Trim(FMainId) + '''');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp, CDS_YuanLiao);
  SInitCDSData20(ADOQueryTemp, CDS_YuanLiao);
 /////////////////刷新原料/////////////////////////

 /////////////////刷新排针/////////////////////////
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from Cloth_PaiZhen where MainId=''' + Trim(FMainId) + '''');
    sql.Add(' and PZType=''排针'' ');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp, CDS_Paizhen);
  SInitCDSData20(ADOQueryTemp, CDS_Paizhen);
  if CDS_Paizhen.IsEmpty then
  begin
    with CDS_Paizhen do
    begin
      Append;
      Post;
      Append;
      Post;

    end;
  end;
/////////////////刷新排针/////////////////////////

/////////////////刷新三角/////////////////////////
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from Cloth_PaiZhen where MainId=''' + Trim(FMainId) + '''');
    sql.Add(' and PZType=''三角'' ');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp, CDS_Sanjiao);
  SInitCDSData20(ADOQueryTemp, CDS_Sanjiao);
 /////////////////刷新三角/////////////////////////

/////////////////刷新附件/////////////////////////
  with ADOQueryTemp do
  begin
    close;
    sql.Clear;
    sql.Add('select TFID,FileName,TFdate,Filler,FillTime from TP_File ');
    sql.Add('where WBID=' + quotedstr(FMainId));
    sql.Add('and TFType=''PB附件'' ');
    open;
  end;
  SCreateCDS20(ADOQueryTemp, CDS_Fujian);
  SInitCDSData20(ADOQueryTemp, CDS_Fujian);
/////////////////刷新附件/////////////////////////

  if PState = 0 then
  begin
    QDTime.DateTime := SGetServerDate(ADOQueryTemp);
    QDTime.Checked := True;
    DeliveryDate.Date := QDTime.DateTime;
  end;

  if PState = 1 then
  begin
    ConNo.ReadOnly := True;
  end;

  if FCopyInt = 1 then
  begin
    FMainId := '';
    ConNo.Text := '';
    ConNo.ReadOnly := False;
/////////////////清除原料ID/////////////////////////
    CDS_YuanLiao.DisableControls;
    with CDS_YuanLiao do
    begin
      First;
      while not Eof do
      begin
        Edit;
        FieldByName('MainId').Value := '';
        FieldByName('SubId').Value := '';
        FieldByName('PBId').Value := '';
        FieldByName('BegPBQty').Value := Null;
        Post;
        Next;
      end;
    end;
    CDS_YuanLiao.EnableControls;
/////////////////清除原料ID/////////////////////////

/////////////////清除排针ID/////////////////////////
    CDS_Paizhen.DisableControls;
    with CDS_Paizhen do
    begin
      First;
      while not Eof do
      begin
        Edit;
        FieldByName('MainId').Value := '';
        FieldByName('SubId').Value := '';
        FieldByName('PZId').Value := '';
        Post;
        Next;
      end;
    end;
    CDS_Paizhen.EnableControls;
/////////////////清除排针ID/////////////////////////

/////////////////清除三角ID/////////////////////////
    CDS_Sanjiao.DisableControls;
    with CDS_Sanjiao do
    begin
      First;
      while not Eof do
      begin
        Edit;
        FieldByName('MainId').Value := '';
        FieldByName('SubId').Value := '';
        FieldByName('PZId').Value := '';
        Post;
        Next;
      end;
    end;
    CDS_Sanjiao.EnableControls;
  end;                                                                   
 /////////////////清除三角ID/////////////////////////
end;

procedure TfrmClothSCInPut.ZDYHelp(FButn: TcxButtonEdit; LType: string);
begin

end;

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

function TfrmClothSCInPut.SaveData(): Boolean;
var
  maxno, maxsubno, maxpbno, maxpzno, maxsjno: string;
begin
  try
    ADOQueryCmd.Connection.BeginTrans;
    if Trim(FMainId) = '' then
    begin
      if GetLSNo(ADOQueryCmd, maxno, 'CM', 'Cloth_Main', 4, 1) = False then
      begin
        ADOQueryCmd.Connection.RollbackTrans;
        Application.MessageBox('生成流水号异常！', '提示', 0);
        exit;
      end;
    end
    else
    begin
      maxno := Trim(FMainId);
    end;

    ///保存主表
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      SQL.Add('select * from Cloth_Main where MainId=''' + Trim(FMainId) + '''');
      Open;
    end;
    with ADOQueryCmd do
    begin
      if Trim(FMainId) = '' then
      begin
        Append;
      end
      else
      begin
        Edit;
      end;
      FieldByName('MainId').Value := Trim(maxno);
      RTSetsavedata(ADOQueryCmd, 'Cloth_Main', ScrollBox1, 0);

      FieldByName('ConType').Value := '生产';
      if Trim(FMainId) = '' then
      begin
        FieldByName('Filler').Value := Trim(DName);
      end
      else
      begin
        FieldByName('Editer').Value := Trim(DName);
        FieldByName('EditTime').Value := SGetServerDateTime(ADOQueryTemp);
      end;
      Post;
    end;

    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from Cloth_Main where ConNo=''' + Trim(ConNo.Text) + '''');
      Open;
    end;
    if ADOQueryTemp.RecordCount > 1 then
    begin
      ADOQueryCmd.Connection.RollbackTrans;
      Application.MessageBox('订单号重复!', '提示', 0);
      Exit;
    end;


    ///保存子表
    if Trim(FSubId) = '' then
    begin
      if GetLSNo(ADOQueryTemp, maxsubno, '9', 'Cloth_Sub', 4, 1) = False then
      begin
        ADOQueryCmd.Connection.RollbackTrans;
        Application.MessageBox('取子流水号失败！', '提示', 0);
        Exit;
      end;
    end
    else
    begin
      maxsubno := Trim(FSubId);
    end;
    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('select * from Cloth_Sub where ');
      sql.Add('  SubId=''' + Trim(maxsubno) + '''');
      Open;
    end;
    with ADOQueryCmd do
    begin
      if Trim(FSubId) = '' then
        Append
      else
        Edit;
      FieldByName('MainId').Value := Trim(maxno);
      FieldByName('SubId').Value := Trim(maxsubno);
      RTSetsavedata(ADOQueryCmd, 'Cloth_Sub', ScrollBox1, 2);
      Post;
    end;
    ///保存子表
    ///保存配比表
    with CDS_YuanLiao do
    begin
      First;
      while not Eof do
      begin
        if Trim(CDS_YuanLiao.fieldbyname('PBId').AsString) = '' then
        begin
          if GetLSNo(ADOQueryTemp, maxpbno, 'PB', 'Cloth_YCL_PB', 4, 1) = False then
          begin
            ADOQueryCmd.Connection.RollbackTrans;
            Application.MessageBox('取配比子流水号失败！', '提示', 0);
            Exit;
          end;
        end
        else
        begin
          maxpbno := Trim(CDS_YuanLiao.fieldbyname('PBId').AsString);
        end;
        with ADOQueryCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from Cloth_YCL_PB where ');
          sql.Add('  PBId=''' + Trim(maxpbno) + '''');
          Open;
        end;
        with ADOQueryCmd do
        begin
          if Trim(CDS_YuanLiao.fieldbyname('PBId').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('MainId').Value := Trim(maxno);
          FieldByName('SubId').Value := Trim(maxsubno);
          FieldByName('PBId').Value := Trim(maxpbno);
          FieldByName('SPId').Value := Trim(CDS_YuanLiao.fieldbyname('SPId').AsString);
          RTSetSaveDataCDS(ADOQueryCmd, Tv2, CDS_YuanLiao, 'Cloth_YCL_PB', 0);
          Post;
        end;
        CDS_YuanLiao.Edit;
        CDS_YuanLiao.FieldByName('SubId').Value := Trim(maxsubno);
        CDS_YuanLiao.FieldByName('MainId').Value := Trim(maxno);
        CDS_YuanLiao.FieldByName('PBId').Value := Trim(maxpbno);
        //Order_Sub.Post;
        Next;
      end;
    end;
    ///保存配比表
    ///保存排针表
    CDS_Paizhen.DisableControls;
    with CDS_Paizhen do
    begin
      First;
      while not Eof do
      begin
        if Trim(CDS_Paizhen.fieldbyname('PZId').AsString) = '' then
        begin
          if GetLSNo(ADOQueryCmd, maxpzno, 'PZ', 'Cloth_PaiZhen', 4, 1) = False then
          begin
            ADOQueryCmd.Connection.RollbackTrans;
            Application.MessageBox('取排针流水号失败！', '提示', 0);
            Exit;
          end;
        end
        else
        begin
          maxpzno := Trim(CDS_Paizhen.fieldbyname('PZId').AsString);
        end;
        with ADOQueryCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from Cloth_PaiZhen where ');
          sql.Add('  PZId=''' + Trim(maxpzno) + '''');
          Open;
        end;
        with ADOQueryCmd do
        begin
          if Trim(CDS_Paizhen.fieldbyname('PZId').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('MainId').Value := Trim(maxno);
          FieldByName('SubId').Value := Trim(maxsubno);
          FieldByName('PZId').Value := Trim(maxpzno);
          RTSetSaveDataCDS(ADOQueryCmd, Tv3, CDS_Paizhen, 'Cloth_PaiZhen', 0);
          FieldByName('PZType').Value := '排针';
          FieldByName('PZName').Value := CDS_Paizhen.fieldbyname('PZName').AsString;
          Post;
        end;
        CDS_Paizhen.Edit;
        CDS_Paizhen.FieldByName('PZId').Value := Trim(maxpzno);
        //Order_Sub.Post;
        Next;
      end;
    end;
    CDS_Paizhen.EnableControls;
    ///保存排针表
    ///保存三角表
    CDS_Sanjiao.DisableControls;
    with CDS_Sanjiao do
    begin
      First;
      while not Eof do
      begin
        if Trim(CDS_Sanjiao.fieldbyname('PZId').AsString) = '' then
        begin
          if GetLSNo(ADOQueryCmd, maxsjno, 'PZ', 'Cloth_PaiZhen', 4, 1) = False then
          begin
            ADOQueryCmd.Connection.RollbackTrans;
            Application.MessageBox('取三角流水号失败！', '提示', 0);
            Exit;
          end;
        end
        else
        begin
          maxsjno := Trim(CDS_Sanjiao.fieldbyname('PZId').AsString);
        end;
        with ADOQueryCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from Cloth_PaiZhen where ');
          sql.Add('  PZId=''' + Trim(maxsjno) + '''');
          Open;
        end;
        with ADOQueryCmd do
        begin
          if Trim(CDS_Sanjiao.fieldbyname('PZId').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('MainId').Value := Trim(maxno);
          FieldByName('SubId').Value := Trim(maxsubno);
          FieldByName('PZId').Value := Trim(maxsjno);
          RTSetSaveDataCDS(ADOQueryCmd, Tv5, CDS_Sanjiao, 'Cloth_PaiZhen', 0);
          FieldByName('PZType').Value := '三角';
          Post;
        end;
        CDS_Sanjiao.Edit;
        CDS_Sanjiao.FieldByName('PZId').Value := Trim(maxsjno);
        //Order_Sub.Post;
        Next;
      end;
    end;
    CDS_Sanjiao.EnableControls;
    ///保存三角表
    ///更新附件表主键
    CDS_Fujian.DisableControls;
    with CDS_Fujian do
    begin
      First;
      while not Eof do
      begin
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('Update TP_File Set WBID=''' + Trim(maxno) + '''');
          sql.Add(' where TFID=''' + Trim(CDS_Fujian.fieldbyname('TFID').AsString) + '''');
          ExecSQL;
        end;
        Next;
      end;
    end;
    CDS_Fujian.EnableControls;

    ADOQueryCmd.Connection.CommitTrans;

    FMainId := Trim(maxno);
    FSubId := Trim(maxsubno);
    Result := True;
  except
    Result := False;

    CDS_YuanLiao.EnableControls;
    CDS_Paizhen.EnableControls;
    CDS_Sanjiao.EnableControls;

    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！', '提示', 0);
  end;
end;

procedure TfrmClothSCInPut.TBSaveClick(Sender: TObject);
var
  FReal: Double;
  maxConNo: string;
begin
  QDTime.SetFocus;

  if Trim(ConNo.Text) = '' then
  begin
    if GetLSNo(ADOQueryCmd, maxConNo, 'MS', 'Cloth_Main', 3, 1) = False then
    begin
      Application.MessageBox('生成流水号异常！', '提示', 0);
      exit;
    end;
    ConNo.Text := maxConNo;
  end;
  if Trim(C_CodeName.Text) = '' then
  begin
    Application.MessageBox('产品名称不能为空!', '提示', 0);
    Exit;
  end;
  if Trim(C_Code.Text) = '' then
  begin
    Application.MessageBox('产品编号不能为空!', '提示', 0);
    Exit;
  end;
  if Trim(LabName.Text) = '' then
  begin
    Application.MessageBox('标签格式不能为空!', '提示', 0);
    Exit;
  end;

  if QDTime.Checked = False then
  begin
    Application.MessageBox('下单日期不能为空!', '提示', 0);
    Exit;
  end;

  if Trim(C_Qty.Text) <> '' then
  begin
    if TryStrToFloat(C_Qty.Text, FReal) = False then
    begin
      Application.MessageBox('订单数量非法数字!', '提示', 0);
      Exit;
    end;
  end;
  if Trim(DayQty.Text) <> '' then
  begin
    if TryStrToFloat(DayQty.Text, FReal) = False then
    begin
      Application.MessageBox('日产非法数字!', '提示', 0);
      Exit;
    end;
  end;
  if Trim(ZongZhenQty.Text) <> '' then
  begin
    if TryStrToFloat(ZongZhenQty.Text, FReal) = False then
    begin
      Application.MessageBox('总针数非法数字!', '提示', 0);
      Exit;
    end;
  end;
  if Trim(ZhuanQty.Text) = '' then
  begin
    ZhuanQty.Text := '0';
  end;
  if TryStrToFloat(ZhuanQty.Text, FReal) = False then
  begin
    Application.MessageBox('转数非法数字!', '提示', 0);
    Exit;
  end;
  if Trim(PiQty.Text) = '' then
  begin
    Application.MessageBox('匹数不能为空!', '提示', 0);
    Exit;
  end;
  if TryStrToFloat(PiQty.Text, FReal) = False then
  begin
    Application.MessageBox('匹数非法数字!', '提示', 0);
    Exit;
  end;
  if Trim(PiQty.Text) = '' then
  begin
    Application.MessageBox('匹重不能为空!', '提示', 0);
    Exit;
  end;
  if TryStrToFloat(PiQty.Text, FReal) = False then
  begin
    Application.MessageBox('匹重非法数字!', '提示', 0);
    Exit;
  end;
  {if Trim(PiZhong.Text)='' then
  begin
    Application.MessageBox('皮重不能为空!','提示',0);
    Exit;
  end; }
  if Trim(PiZhong.Text) <> '' then
  begin
    if TryStrToFloat(PiZhong.Text, FReal) = False then
    begin
      Application.MessageBox('空加非法数字!', '提示', 0);
      Exit;
    end;
  end;

 
//  if Trim(KZQty.Text) <> '' then
//  begin
//    if TryStrToFloat(Trim(KZQty.Text), FReal) = False then
//    begin
//      Application.MessageBox('克重非法数字!', '提示', 0);
//      Exit;
//    end;
//  end;
//  if Trim(MFQty.Text) <> '' then
//  begin
//    if TryStrToFloat(Trim(MFQty.Text), FReal) = False then
//    begin
//      Application.MessageBox('门幅非法数字!', '提示', 0);
//      Exit;
//    end;
//  end;
//  if CDS_YuanLiao.IsEmpty then
//  begin
//    Application.MessageBox('原料配比内容不能为空!','提示',0);
//    Exit;
//  end;
//  if CDS_YuanLiao.Locate('PBQty',Null,[])=True then
//  begin
//    Application.MessageBox('原料配比不能为空!','提示',0);
//    Exit;
//  end;
  if CDS_YuanLiao.Locate('YCLName', Null, []) = True then
  begin
    Application.MessageBox('原料名称不能为空!', '提示', 0);
    Exit;
  end;
  if SaveData() then
  begin
    Application.MessageBox('保存成功！', '提示', 0);
    ModalResult := 1;
  end;
end;

procedure TfrmClothSCInPut.C_CodeNamePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
var
  fsj: string;
  FWZ: Integer;
begin
  fsj := Trim(TEdit(Sender).Hint);
  if fsj = '' then
  begin
    {try
      frmCPManageCX:=TfrmCPManageCX.Create(Application);
      with frmCPManageCX do
      begin
        if ShowModal=1 then
        begin
          Self.C_CodeName.Text:=Trim(frmCPManageCX.CDS_Main.fieldbyname('CYName').AsString);
          Self.C_Code.Text:=Trim(frmCPManageCX.CDS_Main.fieldbyname('CYNo').AsString);
          Self.C_Spec.Text:=Trim(frmCPManageCX.CDS_Main.fieldbyname('CYSpec').AsString);
        end;
      end;
    finally
      frmCPManageCX.Free;
    end;  }
  end
  else
  begin
    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 Trim(flag) = 'C_CodeName' then
        begin
          fnote := True;
          V1Note.Caption := '类型';
        end;
        if ShowModal = 1 then
        begin
          TEdit(Sender).Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        end;
      end;
    finally
      frmZDYHelp.Free;
    end;
  end;

end;

procedure TfrmClothSCInPut.tbADDClick(Sender: TObject);
var
  OpenDiaLog: TOpenDialog;
  fFileName: string;
  fFilePath: string;
  maxNo: string;
  FJStream: TMemoryStream;
  mfileSize: integer;
  mCreationTime: TdateTime;
  mWriteTime: TdateTime;
begin
  case cxPageControl1.ActivePageIndex of
    0:   //原料界面
      begin
        with CDS_YuanLiao do
        begin
          Append;
          FieldByName('PBQty').Value := 0;
          Post;
        end;
      end;
    1:   //排针三角界面
      begin
        if Fint = 1 then
        begin
          with CDS_Paizhen do
          begin
            Append;
            Post;
          end;
        end
        else if Fint = 2 then
          with CDS_Sanjiao do
          begin
            Append;
            Post;
          end;
      end;
    2:   //附件界面
      begin
        try
          adoqueryCmd.Connection.BeginTrans;
          OpenDiaLog := TOpenDialog.Create(Self);
          if OpenDiaLog.Execute then
          begin
            fFilePath := OpenDiaLog.FileName;
            fFileName := ExtractFileName(OpenDiaLog.FileName);
            Panel4.Caption := '正在加载文件，请稍等...';
            Panel4.Visible := true;
            application.ProcessMessages;
            if GetLSNo(ADOQueryCmd, maxNo, 'FJ', 'TP_File', 4, 1) = False then
            begin
              adoqueryCmd.Connection.RollbackTrans;
              Application.MessageBox('取最大号失败！', '提示', 0);
              Exit;
            end;
        //获取文件信息
            GetFileInfo(fFilePath, mfileSize, mCreationTime, mWriteTime);
            with adoqueryCmd do
            begin
              close;
              sql.Clear;
              sql.Add('delete from TP_File ');
              sql.Add('where TFID=' + quotedstr(trim(maxNo)));
              execsql;
            end;
            try
              FJStream := TMemoryStream.Create;
              with adoqueryCmd do
              begin
                close;
                sql.Clear;
                sql.Add('select * from TP_File ');
                sql.Add('where TFID=' + quotedstr(trim(maxNo)));
                open;
                append;
                fieldbyname('TFID').Value := trim(maxNo);
                fieldbyname('TFType').Value := 'PB附件';
                fieldbyname('Filler').Value := trim(DName);
                fieldbyname('FileName').Value := trim(fFileName);
                fieldbyname('TFDate').Value := mWriteTime;
                FJStream.LoadFromFile(fFilePath);
                CompressionStream(FJStream);
                tblobfield(FieldByName('Filesother')).LoadFromStream(FJStream);
                post;
              end;
              with CDS_Fujian do
              begin
                Append;
                FieldByName('TFID').Value := Trim(maxNo);
                FieldByName('FillTime').Value := SGetServerDateTime(ADOQueryTemp);
                FieldByName('TFdate').Value := mWriteTime;
                FieldByName('Filler').Value := Trim(DName);
                fieldbyname('FileName').Value := trim(fFileName);
                Post;
              end;
            finally
              FJStream.Free;
            end;
          end;
          adoqueryCmd.Connection.CommitTrans;
          Panel4.Visible := False;
        except
          Panel4.Visible := False;
          adoqueryCmd.Connection.RollbackTrans;
          application.MessageBox('附件保存失败！', '提示信息', 0);
        end;
      end;
  end;
end;

procedure TfrmClothSCInPut.tbDELClick(Sender: TObject);
begin
  case cxPageControl1.ActivePageIndex of
    0:   //原料界面
      begin
        if CDS_YuanLiao.IsEmpty then
          Exit;
        if Trim(CDS_YuanLiao.fieldbyname('PBId').AsString) <> '' then
        begin
          if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
            Exit;
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('delete Cloth_YCL_PB where PBId=''' + Trim(CDS_YuanLiao.fieldbyname('PBId').AsString) + '''');
            ExecSQL;
          end;
        end;
        CDS_YuanLiao.Delete;
      end;
    1:   //排针三角界面
      begin
        if Fint = 1 then
        begin
          if CDS_Paizhen.IsEmpty then
            Exit;
          if Application.MessageBox('确定要删除排针数据吗？', '提示', 32 + 4) <> IDYES then
            Exit;
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('delete Cloth_PaiZhen where PZID=''' + Trim(CDS_Paizhen.fieldbyname('PZID').AsString) + '''');
            ExecSQL;
          end;
          CDS_Paizhen.Delete;
        end
        else if Fint = 2 then
        begin
          if CDS_Sanjiao.IsEmpty then
            Exit;
          if Application.MessageBox('确定要删除三角数据吗？', '提示', 32 + 4) <> IDYES then
            Exit;
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('delete Cloth_PaiZhen where PZID=''' + Trim(CDS_Sanjiao.fieldbyname('PZID').AsString) + '''');
            ExecSQL;
          end;
          CDS_Sanjiao.Delete;
        end;
      end;
    2:   //附件界面
      begin
        if CDS_Fujian.IsEmpty then
          Exit;
        if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
          Exit;
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('delete TP_File where TFID=''' + Trim(CDS_Fujian.fieldbyname('TFID').AsString) + '''');
          ExecSQL;
        end;
        CDS_Fujian.Delete;
      end;
  end;

end;

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

procedure TfrmClothSCInPut.v2Column2PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'PinPai';
      flagname := '品牌';
      if ShowModal = 1 then
      begin
        Self.CDS_YuanLiao.Edit;
        Self.CDS_YuanLiao.FieldByName('PinPai').Value := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;

end;

procedure TfrmClothSCInPut.Tv6DblClick(Sender: TObject);
var
  sFieldName: string;
  fileName: string;
  ff: TADOBlobStream;
  FJStream: TMemoryStream;
begin
  if CDS_Fujian.IsEmpty then
    exit;
  Panel4.Caption := '正在下载文件，请稍等...';
  Panel4.Visible := true;
  application.ProcessMessages;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from TP_File where TFID=''' + Trim(CDS_Fujian.fieldbyname('TFID').AsString) + '''');
    Open;
  end;
  sFieldName := 'D:\图片查看';
  if not DirectoryExists(pchar(sFieldName)) then
    CreateDirectory(pchar(sFieldName), nil);
  fileName := CDS_Fujian.fieldbyname('FileName').AsString;
  sFieldName := sFieldName + '\' + trim(fileName);
  try
    ff := TADOBlobstream.Create(ADOQueryTemp.fieldByName('FilesOther') as TblobField, bmRead);
    FJStream := TMemoryStream.Create;
    ff.SaveToStream(FJStream);
    UnCompressionStream(FJStream);
    FJStream.SaveToFile(sFieldName);
    Panel4.Visible := False;
    ShellExecute(Handle, 'open', PChar(sFieldName), '', '', SW_SHOWNORMAL);
  finally
    Panel4.Visible := False;
    FJStream.free;
    ff.Free;
  end;
end;

procedure TfrmClothSCInPut.Tv3MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  Fint := 1;
end;

procedure TfrmClothSCInPut.Tv5MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  Fint := 2;
end;

procedure TfrmClothSCInPut.v2Column11PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZdyAttachGYS := TfrmZdyAttachGYS.Create(Application);
    with frmZdyAttachGYS do
    begin

      if ShowModal = 1 then
      begin
        with Self.CDS_YuanLiao do
        begin
          Edit;
          FieldByName('GYSName').Value := Trim(CDS_HZ.fieldbyname('CoName').AsString);
        end;
      end;
    end;
  finally
    frmZdyAttachGYS.Free;
  end;
end;

procedure TfrmClothSCInPut.C_CodePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmCPManageFMSel := TfrmCPManageFMSel.Create(Application);
    with frmCPManageFMSel do
    begin
      if ShowModal = 1 then
      begin
        C_Code.Text := frmCPManageFMSel.CDS_Main.fieldbyname('CYNo').AsString;
        C_CodeName.Text := frmCPManageFMSel.CDS_Main.fieldbyname('CYName').AsString;
        C_Spec.Text := frmCPManageFMSel.CDS_Main.fieldbyname('CYSpec').AsString;
        C_Color.Text := frmCPManageFMSel.CDS_Main.fieldbyname('CYColor').AsString;
        MF.Text := frmCPManageFMSel.CDS_Main.fieldbyname('CYMF').AsString;
        KZ.Text := frmCPManageFMSel.CDS_Main.fieldbyname('CYKZ').AsString;
        self.CarType.Text := frmCPManageFMSel.CDS_Main.fieldbyname('CarType').AsString;
      end;
    end;
  finally
    frmCPManageFMSel.Free;
  end;
end;

procedure TfrmClothSCInPut.KHNamePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZdyAttachment := TfrmZdyAttachment.Create(Application);
    with frmZdyAttachment do
    begin
      if ShowModal = 1 then
      begin
        KHName.Text := Trim(CDS_HZ.fieldbyname('CoName').AsString);
      end;
    end;
  finally
    frmZdyAttachment.Free;
  end;
end;

procedure TfrmClothSCInPut.PiKgQtyChange(Sender: TObject);
var
  FC_Qty, FPiKgQty: Double;
begin
  FC_Qty := StrToFloatDef(C_Qty.Text, 0);
  FPiKgQty := StrToFloatDef(PiKgQty.Text, 0);
  if FPiKgQty > 0 then
    PiQty.Text := IntToStr(Ceil(FC_Qty / FPiKgQty))
  else
    PiQty.Text := '0';
end;

procedure TfrmClothSCInPut.PiQtyChange(Sender: TObject);
var
  FC_Qty, FPiKgQty, FPiQty: Double;
begin
  FPiKgQty := StrToFloatDef(PiKgQty.Text, 0);
  FPiQty := StrToFloatDef(PiQty.Text, 0);
  if FPiQty > 0 then
    C_Qty.Text := FloatToStr(FPiKgQty * FPiQty)
  else
    C_Qty.Text := '0';
end;

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

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

end.

