unit U_ClothSCInPut;

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, cxGridCustomPopupMenu,
  cxGridPopupMenu, dxSkinsCore, dxSkinsDefaultPainters, dxSkinscxPCPainter;

type
  TfrmClothSCInPut = class(TForm)
    ToolBar1: TToolBar;
    TBSave: TToolButton;
    TBClose: TToolButton;
    ScrollBox1: TScrollBox;
    Label1: TLabel;
    ConNo: TEdit;
    ADOTemp: TADOQuery;
    ADOCmd: TADOQuery;
    ADOQuery1: TADOQuery;
    Label2: TLabel;
    QDTime: TDateTimePicker;
    Label3: TLabel;
    MFQty: TEdit;
    Label9: TLabel;
    ADOQueryTemp: TADOQuery;
    Panel2: TPanel;
    ToolBar3: TToolBar;
    ToolButton3: TToolButton;
    ToolButton4: TToolButton;
    DataSource2: TDataSource;
    CDS_YuanLiao: TClientDataSet;
    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;
    cxGridDBColumn6: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    cxTabSheet4: TcxTabSheet;
    Panel1: TPanel;
    Panel3: TPanel;
    cxGrid6: TcxGrid;
    Tv6: TcxGridDBTableView;
    cxGridDBColumn41: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    cxGridDBColumn42: TcxGridDBColumn;
    cxGridLevel4: TcxGridLevel;
    ClientDataSet6: TClientDataSet;
    DataSource6: TDataSource;
    ClientDataSet5: TClientDataSet;
    DataSource3: TDataSource;
    ClientDataSet3: TClientDataSet;
    DataSource5: TDataSource;
    Panel4: TPanel;
    Label26: TLabel;
    Label27: TLabel;
    Label28: TLabel;
    PiZhong: TEdit;
    ToolButton1: TToolButton;
    v2Column5: TcxGridDBColumn;
    Label31: TLabel;
    ToolButton2: TToolButton;
    C_Note: TRichEdit;
    Label41: TLabel;
    Label42: TLabel;
    LabName: TComboBox;
    cxTabSheet3: TcxTabSheet;
    cxGrid7: TcxGrid;
    Tv7: TcxGridDBTableView;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn29: TcxGridDBColumn;
    cxGridDBColumn30: TcxGridDBColumn;
    cxGridDBColumn31: TcxGridDBColumn;
    cxGridLevel5: TcxGridLevel;
    Tv7Column1: TcxGridDBColumn;
    ClientDataSet7: TClientDataSet;
    DataSource7: TDataSource;
    v7Column1: TcxGridDBColumn;
    v7Column2: TcxGridDBColumn;
    v7Column3: TcxGridDBColumn;
    v7Column4: TcxGridDBColumn;
    v7Column5: TcxGridDBColumn;
    v7Column6: TcxGridDBColumn;
    v7Column7: TcxGridDBColumn;
    v7Column8: TcxGridDBColumn;
    v7Column9: TcxGridDBColumn;
    v7Column10: TcxGridDBColumn;
    Label44: TLabel;
    KHConNo: TEdit;
    Label47: TLabel;
    ShaChang: TEdit;
    KZ: TEdit;
    C_Codename: TcxButtonEdit;
    C_Code: TEdit;
    KHName: TcxButtonEdit;
    Label43: TLabel;
    YWY: TcxButtonEdit;
    ToolButton5: TToolButton;
    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;
    lbl2: TLabel;
    orderflag: TEdit;
    btn1: TToolButton;
    btn2: TToolButton;
    pnl1: TPanel;
    edt1: TEdit;
    lbl3: TLabel;
    btn3: TButton;
    btn4: TButton;
    btn5: TToolButton;
    Panel5: TPanel;
    Label60: TLabel;
    XSConNo: TBtnEditC;
    Label61: TLabel;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    C_SPEC: TEdit;
    Tv2Column1: TcxGridDBColumn;
    JQZHENQTY: TcxButtonEdit;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Tv2Column2: TcxGridDBColumn;
    Label7: TLabel;
    JHCHEJIAN: TEdit;
    ToolButton6: TToolButton;
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure C_CodeNamePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure ToolButton3Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure cxGridDBColumn1PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v2Column2PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure Tv6DblClick(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton2Click(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 cxGridDBColumn3PropertiesButtonClick(Sender: TObject; AButtonIndex: 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 ToolButton5Click(Sender: TObject);
    procedure C_CodeKeyPress(Sender: TObject; var Key: Char);
    procedure ConNoKeyPress(Sender: TObject; var Key: Char);
    procedure btn1Click(Sender: TObject);
    procedure btn2Click(Sender: TObject);
    procedure btn3Click(Sender: TObject);
    procedure btn4Click(Sender: TObject);
    procedure btn5Click(Sender: TObject);
    procedure XSConNoBtnUpClick(Sender: TObject);
    procedure v2Column1PropertiesEditValueChanged(Sender: TObject);
    procedure CarTypePropertiesEditValueChanged(Sender: TObject);
    procedure v2Column7PropertiesEditValueChanged(Sender: TObject);
    procedure v2Column13PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure cxgrdbclmnv2Column14PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure cxgrdbclmnv2Column15PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v2Column6PropertiesEditValueChanged(Sender: TObject);
    procedure v2Column15PropertiesEditValueChanged(Sender: TObject);
    procedure cxGridDBColumn2PropertiesEditValueChanged(Sender: TObject);
    procedure kzzhuanshuChange(Sender: TObject);
    procedure Tv2Column1PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Tv2Column2PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v2Column5PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure ToolButton6Click(Sender: TObject);
  private
    FXS, Fint: Integer;
    procedure InitData();
    procedure HJJE();
    procedure JXSEL();    //选机型跳相关数据
    procedure CPSEL();    //选产品跳相关原料数据
    procedure htSEL();    //选合同跳机型
    procedure ZDYHelp(FButn: TcxButtonEdit; LType: string);
    function SaveData(): Boolean;
    function SaveData2(): Boolean;
    { Private declarations }
  public
    PState, FCopyInt: Integer;
    FMainId, FConNo, PType, FSubId, FCHEJIAN: string;
    { Public declarations }
  end;

var
  frmClothSCInPut: TfrmClothSCInPut;
  newh: hwnd;

implementation

uses
  U_DataLink, U_ZDYHelp, U_RTFun, U_CompressionFun, U_ZdyAttachGYS,
  U_ShaKCSelList, U_SCPerson, U_ContractListNXSel, U_FjList_RZ, U_JTAllSel,
  U_CPManageFMSel, U_ZdyAttachment, U_jitaibiao;

{$R *.dfm}

procedure TfrmClothSCInPut.HJJE();
var
  Fylqty: double;
begin
//  if TV2.DataController.Summary.FooterSummaryValues[5] <> NULL then
//    Fylqty := TV2.DataController.Summary.FooterSummaryValues[5]
//  else
//    Fylqty := 0;
//
//  dayqty.Text := floattostr(Fylqty); //总日产

end;

procedure TfrmClothSCInPut.htsel();
var
  Fylqty: double;
begin

end;

procedure TfrmClothSCInPut.cpsel();
var
  Fylqty: double;
begin
  if C_CODE.Text <> '' then
  begin

    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add(' select * from CP_YDang A INNER join  CP_YDangSpec B ON A.CYID=B.CYID ');
      SQL.ADD(' WHERE  A.CYNO=' + QUOTEDSTR(TRIM(C_CODE.TEXT)));
      SQL.ADD('AND YLNAME IS NOT NULL ');
//      showmessage(sql.Text);
      Open;
    end;

    if ADOQueryTemp.ISEMPTY = FALSE then
    begin

      with CDS_YUANLIAO do
      begin
        First;
        while not Eof do
        begin

          CDS_YUANLIAO.Delete;
//          CDS_YUANLIAO.Next;
        end;

      end;
      with ADOQueryTemp do
      begin
        First;
        while not Eof do
        begin
          CDS_YUANLIAO.append;
          CDS_YUANLIAO.FieldByName('YCLName').Value := ADOQueryTemp.FieldByName('YLNAME').ASSTRING;
          CDS_YUANLIAO.FieldByName('SHACHANG').Value := ADOQueryTemp.FieldByName('YLXC').ASSTRING;
          CDS_YUANLIAO.Post;
          ADOQueryTemp.Next;
        end;
      end;
    end;
  end;
end;

procedure TfrmClothSCInPut.JXSEL();
var
  Fylqty: double;
begin

end;

procedure TfrmClothSCInPut.TBCloseClick(Sender: TObject);
begin
  writeCxGrid('坯布生产计划单原材料1', Tv2, '坯布生产管理');
  ModalResult := 1;
end;

procedure TfrmClothSCInPut.InitData();
var
  PBNO, PBFlag: string;
begin
  if PState = 1 then
  begin
    ConNo.ReadOnly := True;
  end;
  with ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    sql.Add(' exec Cloth_QryList :MainId,:WSql');
    if PState = 1 then
    begin
      ADOQuery1.Parameters.ParamByName('MainId').Value := Trim(FMainId);
      ADOQuery1.Parameters.ParamByName('WSQl').Value := '';
    end;
    if PState = 0 then
    begin
      ADOQuery1.Parameters.ParamByName('MainId').Value := Trim(FMainId);
      ADOQuery1.Parameters.ParamByName('WSql').Value := ' and 1<>1 ';
    end;
    Open;
  end;
  SCSHData(ADOQuery1, ScrollBox1, 0);
  SCSHData(ADOQuery1, ScrollBox1, 2);
  XSConNo.Text := Trim(ADOQuery1.fieldbyname('XSConNo').AsString);
  XSConNo.TxtCode := Trim(ADOQuery1.fieldbyname('ConSubId').AsString);
  with ADOTemp 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))');
    if FCopyInt <> 1 then
    begin
      sql.Add(',CKQty=(select sum(Qty) from CK_SXPB_CR SQ where SQ.PBNO=C.ConNo and SQ.SPName=A.YCLName ');
      sql.Add('         and isnull(SQ.PBNO,'''')<>'''' and ZFFlag=0 and CKName=''纱线'' and CRFlag=''出库'' and CRType=''织造加工出库'' )');
    end;

    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(ADOTemp, CDS_YuanLiao);
  SInitCDSData20(ADOTemp, CDS_YuanLiao);
  with ADOTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from Cloth_PaiZhen where MainId=''' + Trim(FMainId) + '''');
    sql.Add(' and PZType=''排针'' ');
    Open;
  end;
  SCreateCDS20(ADOTemp, ClientDataSet3);
  SInitCDSData20(ADOTemp, ClientDataSet3);
  if ClientDataSet3.IsEmpty then
  begin
    with ClientDataSet3 do
    begin
      Append;
      Post;
      Append;
      Post;

    end;
  end;
  with ADOTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from Cloth_PaiZhen where MainId=''' + Trim(FMainId) + '''');
    sql.Add(' and PZType=''三角'' ');
    Open;
  end;
  SCreateCDS20(ADOTemp, ClientDataSet5);
  SInitCDSData20(ADOTemp, ClientDataSet5);
  if PState = 0 then
  begin
    with ADOTemp do
    begin
      Close;
      SQL.Clear;
      sql.Add('select Top 1* from Cloth_Main order by FillTime desc ');
      Open;
    end;
    QDTime.DateTime := SGetServerDate(ADOTemp);
    QDTime.Checked := True;
    DeliveryDate.Date := QDTime.DateTime;
//    PiZhong.Text := '0.1';
  end;

  if FCopyInt = 1 then
  begin
    FMainId := '';
    ConNo.Text := '';
    ConNo.ReadOnly := False;
    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;
    ClientDataSet3.DisableControls;
    with ClientDataSet3 do
    begin
      First;
      while not Eof do
      begin
        Edit;
        FieldByName('MainId').Value := '';
        FieldByName('SubId').Value := '';
        FieldByName('PZId').Value := '';
        Post;
        Next;
      end;
    end;
    ClientDataSet3.EnableControls;
    ClientDataSet5.DisableControls;
    with ClientDataSet5 do
    begin
      First;
      while not Eof do
      begin
        Edit;
        FieldByName('MainId').Value := '';
        FieldByName('SubId').Value := '';
        FieldByName('PZId').Value := '';
        Post;
        Next;
      end;
    end;
    ClientDataSet5.EnableControls;
  end;

  with ADOTemp 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(ADOTemp, ClientDataSet6);
  SInitCDSData20(ADOTemp, ClientDataSet6);
  with ADOTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from Cloth_WJG where MainId=''' + Trim(FMainId) + '''');
    Open;
  end;
  SCreateCDS20(ADOTemp, ClientDataSet7);
  SInitCDSData20(ADOTemp, ClientDataSet7);
end;

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

end;

procedure TfrmClothSCInPut.FormShow(Sender: TObject);
begin
  ReadCxGrid('坯布生产计划单原材料1', Tv2, '坯布生产管理');
  InitData();
end;

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

    ///保存主表
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      SQL.Add('select * from Cloth_Main where MainId=''' + Trim(FMainId) + '''');
      Open;
    end;
    with ADOCmd do
    begin
      if Trim(FMainId) = '' then
      begin
        Append;
      end
      else
      begin
        Edit;
      end;
      FieldByName('MainId').Value := Trim(maxno);
      FieldByName('XSConNo').Value := Trim(XSConNo.Text);
      FieldByName('ConSubId').Value := Trim(XSConNo.TxtCode);
      RTSetsavedata(ADOCmd, '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(ADOTemp);
      end;
      Post;
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('Update Cloth_Main Set ConMainId=(select MainId from JYOrderCon_Sub_PB A where A.SubId=Cloth_Main.ConSubId)');
      sql.Add(' where MainId=''' + Trim(maxno) + '''');
      ExecSQL;
    end;
    //FMainId:=Trim(maxno);
    with ADOTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from Cloth_Main where ConNo=''' + Trim(ConNo.Text) + '''');
      Open;
    end;
    if ADOTemp.RecordCount > 1 then
    begin
      ADOCmd.Connection.RollbackTrans;
      Application.MessageBox('订单号重复!', '提示', 0);
      Exit;
    end;


    ///保存子表
    if Trim(FSubId) = '' then
    begin
      if GetLSNo(ADOTemp, maxsubno, '9', 'Cloth_Sub', 4, 1) = False then
      begin
        ADOCmd.Connection.RollbackTrans;
        Application.MessageBox('取子流水号失败！', '提示', 0);
        Exit;
      end;
    end
    else
    begin
      maxsubno := Trim(FSubId);
    end;
    with ADOCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('select * from Cloth_Sub where ');
      sql.Add('  SubId=''' + Trim(maxsubno) + '''');
      Open;
    end;
    with ADOCmd do
    begin
      if Trim(FSubId) = '' then
        Append
      else
        Edit;
      FieldByName('MainId').Value := Trim(maxno);
      FieldByName('SubId').Value := Trim(maxsubno);
      RTSetsavedata(ADOCmd, '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(ADOTemp, maxpbno, 'PB', 'Cloth_YCL_PB', 4, 1) = False then
          begin
            ADOCmd.Connection.RollbackTrans;
            Application.MessageBox('取配比子流水号失败！', '提示', 0);
            Exit;
          end;
        end
        else
        begin
          maxpbno := Trim(CDS_YuanLiao.fieldbyname('PBId').AsString);
        end;
        with ADOCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from Cloth_YCL_PB where ');
          sql.Add('  PBId=''' + Trim(maxpbno) + '''');
          Open;
        end;
        with ADOCmd do
        begin
          if Trim(CDS_YuanLiao.fieldbyname('PBId').AsString) = '' then
          begin
            Append;
            FieldByName('Filler').Value := Trim(DName);
            FieldByName('FillTime').Value := SGetServerDateTime(ADOTemp);
          end
          else
          begin
            Edit;
            FieldByName('Editer').Value := Trim(DName);
            FieldByName('EditTime').Value := SGetServerDateTime(ADOTemp);
          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(ADOCmd, 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;
    ///保存配比表
    ///保存排针表
    ClientDataSet3.DisableControls;
    with ClientDataSet3 do
    begin
      First;
      while not Eof do
      begin
        if Trim(ClientDataSet3.fieldbyname('PZId').AsString) = '' then
        begin
          if GetLSNo(ADOTemp, maxpzno, 'PZ', 'Cloth_PaiZhen', 4, 1) = False then
          begin
            ADOCmd.Connection.RollbackTrans;
            Application.MessageBox('取排针流水号失败！', '提示', 0);
            Exit;
          end;
        end
        else
        begin
          maxpzno := Trim(ClientDataSet3.fieldbyname('PZId').AsString);
        end;
        with ADOCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from Cloth_PaiZhen where ');
          sql.Add('  PZId=''' + Trim(maxpzno) + '''');
          Open;
        end;
        with ADOCmd do
        begin
          if Trim(ClientDataSet3.fieldbyname('PZId').AsString) = '' then
          begin
            Append;
            FieldByName('Filler').Value := Trim(DName);
            FieldByName('FillTime').Value := SGetServerDateTime(ADOTemp);
          end
          else
          begin
            Edit;
            FieldByName('Editer').Value := Trim(DName);
            FieldByName('EditTime').Value := SGetServerDateTime(ADOTemp);
          end;
          FieldByName('MainId').Value := Trim(maxno);
          FieldByName('SubId').Value := Trim(maxsubno);
          FieldByName('PZId').Value := Trim(maxpzno);
          RTSetSaveDataCDS(ADOCmd, Tv3, ClientDataSet3, 'Cloth_PaiZhen', 0);
          FieldByName('PZType').Value := '排针';
          FieldByName('PZName').Value := ClientDataSet3.fieldbyname('PZName').AsString;
          Post;
        end;
        ClientDataSet3.Edit;
        ClientDataSet3.FieldByName('PZId').Value := Trim(maxpzno);
        //Order_Sub.Post;
        Next;
      end;
    end;
    ClientDataSet3.EnableControls;
    ///保存排针表
    ///保存三角表
    ClientDataSet5.DisableControls;
    with ClientDataSet5 do
    begin
      First;
      while not Eof do
      begin
        if Trim(ClientDataSet5.fieldbyname('PZId').AsString) = '' then
        begin
          if GetLSNo(ADOTemp, maxsjno, 'PZ', 'Cloth_PaiZhen', 4, 1) = False then
          begin
            ADOCmd.Connection.RollbackTrans;
            Application.MessageBox('取三角流水号失败！', '提示', 0);
            Exit;
          end;
        end
        else
        begin
          maxsjno := Trim(ClientDataSet5.fieldbyname('PZId').AsString);
        end;
        with ADOCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from Cloth_PaiZhen where ');
          sql.Add('  PZId=''' + Trim(maxsjno) + '''');
          Open;
        end;
        with ADOCmd do
        begin
          if Trim(ClientDataSet5.fieldbyname('PZId').AsString) = '' then
          begin
            Append;
            FieldByName('Filler').Value := Trim(DName);
            FieldByName('FillTime').Value := SGetServerDateTime(ADOTemp);
          end
          else
          begin
            Edit;
            FieldByName('Editer').Value := Trim(DName);
            FieldByName('EditTime').Value := SGetServerDateTime(ADOTemp);
          end;
          FieldByName('MainId').Value := Trim(maxno);
          FieldByName('SubId').Value := Trim(maxsubno);
          FieldByName('PZId').Value := Trim(maxsjno);
          RTSetSaveDataCDS(ADOCmd, Tv5, ClientDataSet5, 'Cloth_PaiZhen', 0);
          FieldByName('PZType').Value := '三角';
          Post;
        end;
        ClientDataSet5.Edit;
        ClientDataSet5.FieldByName('PZId').Value := Trim(maxsjno);
        //Order_Sub.Post;
        Next;
      end;
    end;
    ClientDataSet5.EnableControls;
    ///保存三角表
    ///保存外加工表
    ClientDataSet7.DisableControls;
    with ClientDataSet7 do
    begin
      First;
      while not Eof do
      begin
        if Trim(ClientDataSet7.fieldbyname('JGId').AsString) = '' then
        begin
          if GetLSNo(ADOTemp, maxsjno, 'JG', 'Cloth_WJG', 4, 1) = False then
          begin
            ADOCmd.Connection.RollbackTrans;
            Application.MessageBox('取外发加工流水号失败！', '提示', 0);
            Exit;
          end;
        end
        else
        begin
          maxsjno := Trim(ClientDataSet7.fieldbyname('JGId').AsString);
        end;
        with ADOCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from Cloth_WJG where ');
          sql.Add('  JGId=''' + Trim(maxsjno) + '''');
          Open;
        end;
        with ADOCmd do
        begin
          if Trim(ClientDataSet7.fieldbyname('JGId').AsString) = '' then
          begin
            Append;
            FieldByName('Filler').Value := Trim(DName);
            FieldByName('FillTime').Value := SGetServerDateTime(ADOTemp);
          end
          else
          begin
            Edit;
            FieldByName('Editer').Value := Trim(DName);
            FieldByName('EditTime').Value := SGetServerDateTime(ADOTemp);
          end;
          FieldByName('MainId').Value := Trim(maxno);
          FieldByName('SubId').Value := Trim(maxsubno);
          FieldByName('JGId').Value := Trim(maxsjno);
          FieldByName('WFGYSNo').Value := Trim(ClientDataSet7.fieldbyname('WFGYSNo').AsString);
          FieldByName('WFGYSNameJC').Value := Trim(ClientDataSet7.fieldbyname('WFGYSNameJC').AsString);
          RTSetSaveDataCDS(ADOCmd, Tv7, ClientDataSet7, 'Cloth_WJG', 0);
          Post;
        end;
        ClientDataSet7.Edit;
        ClientDataSet7.FieldByName('JGId').Value := Trim(maxsjno);
        //Order_Sub.Post;
        Next;
      end;
    end;
    ClientDataSet7.EnableControls;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('select WFGYSName from Cloth_WJG where MainId=''' + Trim(maxno) + '''');
      sql.Add(' group by WFGYSName having count(*)>1');
      Open;
    end;
    if ADOCmd.RecordCount > 0 then
    begin
      ADOCmd.Connection.RollbackTrans;
      Application.MessageBox('外发加工单位在一张订单中只能存在一次!', '提示', 0);
      Exit;
    end;
    ////////////////更新外发表数据
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('Update Cloth_WJG Set JGMoney=isnull(JGPrice,0)*isnull(WFWCQtyZP,0)');
      sql.Add(',JSMoney=isnull(JGPrice,0)*isnull(WFWCQtyZP,0)-isnull(KKMoney,0)');
      sql.Add(' where MainId=''' + Trim(maxno) + '''');
      ExecSQL;
    end;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('exec P_Update_Cloth_Sub_WJG_Qty :MainId');
      Parameters.ParamByName('MainId').Value := Trim(maxno);
      ExecSQL;
    end;
    ///////////////更新外发表数据
    ///保存外加工表
    ///更新附件表主键
    ClientDataSet6.DisableControls;
    with ClientDataSet6 do
    begin
      First;
      while not Eof do
      begin
        with ADOCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('Update TP_File Set WBID=''' + Trim(maxno) + '''');
          sql.Add(' where TFID=''' + Trim(ClientDataSet6.fieldbyname('TFID').AsString) + '''');
          ExecSQL;
        end;
        Next;
      end;
    end;
    ClientDataSet6.EnableControls;

    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('exec P_SC_CAR''' + Trim(maxno) + '''');

      ExecSQL;
    end;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('exec P_UP_YCLQTY  @mainid=' + quotedstr(trim(Trim(maxno))));
      ExecSQL;
    end;
    ///更新附件表主键
//    with ADOCmd do
//    begin
//      Close;
//      sql.Clear;
//      sql.Add('UPdate Cloth_Sub Set BatchNoHZ=[dbo].[F_Get_Order_SubStr_PB](Cloth_Sub.MainId,''SXBatChNo'')');
//      sql.Add(' where MainId='''+Trim(maxno)+'''');
//      ExecSQL;
//    end;
    ADOCmd.Connection.CommitTrans;
    FMainId := Trim(maxno);
    FSubId := Trim(maxsubno);
    Result := True;
  except
    Result := False;
    ClientDataSet3.EnableControls;
    ClientDataSet5.EnableControls;
    ClientDataSet6.EnableControls;
    CDS_YuanLiao.EnableControls;
    ADOCmd.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 GetLSNoHZ(ADOCmd, maxConNo, 'XH', 'Cloth_Main', 4, 1, 2) = 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(LabName.Text) = '' then
  begin
    Application.MessageBox('标签格式不能为空!', '提示', 0);
    Exit;
  end;

  {if DeliveryDate.Checked=False 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
    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(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(GZGSType.Text) = '' then
//  begin
//    Application.MessageBox('工资公式不能为空!', '提示', 0);
//    Exit;
//  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(TcxButtonEdit(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.ToolButton3Click(Sender: TObject);
var
  OpenDiaLog: TOpenDialog;
  fFileName: string;
  fFilePath: string;
  maxNo: string;
  FJStream: TMemoryStream;
  mfileSize: integer;
  mCreationTime: TdateTime;
  mWriteTime: TdateTime;
begin
  //if cxPageControl1.ActivePageIndex=0 then Exit;
  if cxPageControl1.ActivePageIndex = 0 then
  begin
    with CDS_YuanLiao do
    begin
      Append;
      FieldByName('PBQty').Value := 0;
      FieldByName('swbl').Value := 1;
      cpsel();
      jxsel();
      Post;
    end;
  end
  else if cxPageControl1.ActivePageIndex = 1 then
  begin
    if Fint = 1 then
    begin
      with ClientDataSet3 do
      begin
        Append;
        Post;
      end;
    end
    else if Fint = 2 then
      with ClientDataSet5 do
      begin
        Append;
        Post;
      end;
  end
  else if cxPageControl1.ActivePageIndex = 2 then
  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 ClientDataSet6 do
          begin
            Append;
            FieldByName('TFID').Value := Trim(maxNo);
            FieldByName('FillTime').Value := SGetServerDateTime(ADOTemp);
            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
  else if cxPageControl1.ActivePageIndex = 3 then
  begin
    with ClientDataSet7 do
    begin
      Append;
      Post;
    end;
  end;

end;

procedure TfrmClothSCInPut.ToolButton4Click(Sender: TObject);
begin
  if cxPageControl1.ActivePageIndex = 0 then
  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 ADOCmd do
      begin
        Close;
        sql.Clear;

        sql.Add('delete ZDEL_Cloth_YCL_PB where PBId=''' + Trim(CDS_YuanLiao.fieldbyname('PBId').AsString) + '''');
        SQL.Add('insert into ZDEL_Cloth_YCL_PB ');
        sql.Add('select * from Cloth_YCL_PB where PBId=''' + Trim(CDS_YuanLiao.fieldbyname('PBId').AsString) + '''');

        sql.Add('Update ZDEL_Cloth_YCL_PB Set DELNOTE=''删除人:''+''' + Trim(DName) + '''');
        sql.Add('+'' ''+Convert(Varchar(20),getdate(),120)');
        sql.Add(' where PBId=''' + Trim(CDS_YuanLiao.fieldbyname('PBId').AsString) + '''');

        sql.Add('delete Cloth_YCL_PB where PBId=''' + Trim(CDS_YuanLiao.fieldbyname('PBId').AsString) + '''');

        ExecSQL;
      end;
    end;
    CDS_YuanLiao.Delete;
  end
  else if cxPageControl1.ActivePageIndex = 1 then
  begin
    if Fint = 1 then
    begin
      if ClientDataSet3.IsEmpty then
        Exit;
      if Application.MessageBox('确定要删除排针数据吗？', '提示', 32 + 4) <> IDYES then
        Exit;
      with ADOCmd do
      begin
        Close;
        sql.Clear;
        sql.Add('delete Cloth_PaiZhen where PZID=''' + Trim(ClientDataSet3.fieldbyname('PZID').AsString) + '''');
        ExecSQL;
      end;
      ClientDataSet3.Delete;
    end
    else if Fint = 2 then
    begin
      if ClientDataSet5.IsEmpty then
        Exit;
      if Application.MessageBox('确定要删除三角数据吗？', '提示', 32 + 4) <> IDYES then
        Exit;
      with ADOCmd do
      begin
        Close;
        sql.Clear;
        sql.Add('delete Cloth_PaiZhen where PZID=''' + Trim(ClientDataSet5.fieldbyname('PZID').AsString) + '''');
        ExecSQL;
      end;
      ClientDataSet5.Delete;
    end;

  end
  else if cxPageControl1.ActivePageIndex = 2 then
  begin
    if ClientDataSet6.IsEmpty then
      Exit;
    if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
      Exit;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete TP_File where TFID=''' + Trim(ClientDataSet6.fieldbyname('TFID').AsString) + '''');
      ExecSQL;
    end;
    ClientDataSet6.Delete;
  end
  else if cxPageControl1.ActivePageIndex = 3 then
  begin
    if ClientDataSet7.IsEmpty then
      Exit;
    if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
      Exit;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete Cloth_WJG where JGID=''' + Trim(ClientDataSet7.fieldbyname('JGID').AsString) + '''');
      ExecSQL;
    end;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add(' exec P_Update_Cloth_Sub_WJG_Qty :Mainid');
      Parameters.ParamByName('Mainid').Value := Trim(FMainId);
      ExecSQL;
    end;
    ClientDataSet7.Delete;
  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
    frmZdyAttachGYS := TfrmZdyAttachGYS.Create(Application);
    with frmZdyAttachGYS do
    begin
//      FactType.ItemIndex := FactType.Items.IndexOf('加工厂');
      if ShowModal = 1 then
      begin
//        with Self.ClientDataSet7 do
//        begin
        Self.CDS_YuanLiao.Edit;
        Self.CDS_YuanLiao.FieldByName('PinPai').Value := Trim(CDS_HZ.fieldbyname('CoName').AsString);
//          Edit;
//          FieldByName('WFGYSName').Value := Trim(CDS_HZ.fieldbyname('CoName').AsString);
//          FieldByName('WFGYSNo').Value := Trim(CDS_HZ.fieldbyname('CoCode').AsString);
//          FieldByName('WFGYSNameJC').Value := Trim(CDS_HZ.fieldbyname('CoHRName').AsString);
//        end;
      end;
    end;
  finally
    frmZdyAttachGYS.Free;
  end;
//  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 ClientDataSet6.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(ClientDataSet6.fieldbyname('TFID').AsString) + '''');
    Open;
  end;
  sFieldName := 'D:\图片查看';
  if not DirectoryExists(pchar(sFieldName)) then
    CreateDirectory(pchar(sFieldName), nil);
  fileName := ClientDataSet6.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.ToolButton1Click(Sender: TObject);
begin

  if cxPageControl1.ActivePageIndex <> 0 then
    Exit;
  try
    frmShaKCSelList := TfrmShaKCSelList.Create(Application);
    with frmShaKCSelList do
    begin
      chejian.Text := '二车间';
      //Self.JHCHEJIAN.Text;
      if ShowModal = 1 then
      begin

        with CDS_YuanLiao do
        begin
          Append;
          FieldByName('YCLName').Value := frmShaKCSelList.CDS_Main.fieldbyname('SPName').Value;
          FieldByName('YCLSpec').Value := frmShaKCSelList.CDS_Main.fieldbyname('SPSpec').Value;
          FieldByName('PinPai').Value := frmShaKCSelList.CDS_Main.fieldbyname('FactoryName').Value;
          FieldByName('GYSName').Value := frmShaKCSelList.CDS_Main.fieldbyname('FactoryName').Value;
          FieldByName('BatchNo').Value := frmShaKCSelList.CDS_Main.fieldbyname('BatchNo').Value;
//          FieldByName('SPID').Value := frmShaKCSelList.CDS_Main.fieldbyname('SPID').Value;
          //Post;
        end;
      end;
    end;
  finally
    frmShaKCSelList.Free;
  end;
end;

procedure TfrmClothSCInPut.ToolButton2Click(Sender: TObject);
begin
  if cxPageControl1.ActivePageIndex <> 0 then
    Exit;
  if CDS_YuanLiao.IsEmpty then
    Exit;
  try
    frmShaKCSelList := TfrmShaKCSelList.Create(Application);
    with frmShaKCSelList do
    begin
      if ShowModal = 1 then
      begin
        with CDS_YuanLiao do
        begin
          Edit;
          FieldByName('YCLName').Value := frmShaKCSelList.CDS_Main.fieldbyname('SPName').Value;
          FieldByName('YCLSpec').Value := frmShaKCSelList.CDS_Main.fieldbyname('SPSpec').Value;
          FieldByName('PinPai').Value := frmShaKCSelList.CDS_Main.fieldbyname('SXPinPai').Value;
          FieldByName('GYSName').Value := frmShaKCSelList.CDS_Main.fieldbyname('FactoryName').Value;
         // FieldByName('BatchNo').Value:=frmShaKCSelList.CDS_Main.fieldbyname('BatchNo').Value;
          FieldByName('SPID').Value := frmShaKCSelList.CDS_Main.fieldbyname('SPID').Value;
          //Post;
        end;
      end;
    end;
  finally
    frmShaKCSelList.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.cxGridDBColumn3PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZdyAttachGYS := TfrmZdyAttachGYS.Create(Application);
    with frmZdyAttachGYS do
    begin
      FactType.ItemIndex := FactType.Items.IndexOf('加工厂');
      if ShowModal = 1 then
      begin
        with Self.ClientDataSet7 do
        begin
          Edit;
          FieldByName('WFGYSName').Value := Trim(CDS_HZ.fieldbyname('CoName').AsString);
          FieldByName('WFGYSNo').Value := Trim(CDS_HZ.fieldbyname('CoCode').AsString);
          FieldByName('WFGYSNameJC').Value := Trim(CDS_HZ.fieldbyname('CoHRName').AsString);
        end;
      end;
    end;
  finally
    frmZdyAttachGYS.Free;
  end;
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;

        KZ.Text := frmCPManageFMSel.CDS_Main.fieldbyname('CYKZ').AsString;

      end;
    end;
  finally
    frmCPManageFMSel.Free;
  end;
//  try
//    frmZDYHelp := TfrmZDYHelp.Create(Application);
//    with frmZDYHelp do
//    begin
//      flag := 'MPRTCodeNameZW';
//      flagname := '产品名称';
//      fnote := True;
//      V1Note.Caption := '编号';
//      if ShowModal = 1 then
//      begin
//
//        C_CodeName.Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
//        C_Code.Text := Trim(ClientDataSet1.fieldbyname('Note').AsString);
//      end;
//    end;
//  finally
//    frmZDYHelp.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, FPiQty: 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';
  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.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.ToolButton5Click(Sender: TObject);
var
  FSZ, FSC, FLS, ZZL: Double;
begin
  ZZL := 0;
  with CDS_YuanLiao do
  begin
    First;
    while not eof do
    begin
      FSZ := StrToFloatDef(FieldByName('YCLSpec').AsString, 1);
      FSC := StrToFloatDef(FieldByName('ShaChang').AsString, 1);
      FLS := StrToFloatDef(FieldByName('YongShaLuShu').AsString, 1);
      ZZL := ZZL + FSZ * FSC * FLS;
      Next;
    end;
  end;

  with CDS_YuanLiao do
  begin
    First;
    while not eof do
    begin
      FSZ := StrToFloatDef(FieldByName('YCLSpec').AsString, 1);
      FSC := StrToFloatDef(FieldByName('ShaChang').AsString, 1);
      FLS := StrToFloatDef(FieldByName('YongShaLuShu').AsString, 1);
      Edit;
      FieldByName('PBQty').Value := FSZ * FSC * FLS / ZZL * 100;
      FieldByName('PBQty2').Value := FSZ * FSC * FLS / ZZL * 100;
      Next;
    end;
  end;
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;

procedure TfrmClothSCInPut.btn1Click(Sender: TObject);
begin
  pnl1.Visible := True;

end;

function TfrmClothSCInPut.SaveData2(): Boolean;
var
  maxpzno, maxno, maxsubno, maxsjno, Fpbnname: string;
begin
  try
    ADOCmd.Connection.BeginTrans;
    ClientDataSet3.DisableControls;
    with ClientDataSet3 do
    begin
      First;
      while not Eof do
      begin
        if Trim(ClientDataSet3.fieldbyname('PZId').AsString) = '' then
        begin
          if GetLSNo(ADOCmd, maxpzno, 'PZB', 'Cloth_PaiZhen2', 4, 1) = False then
          begin
            ADOCmd.Connection.RollbackTrans;
            Application.MessageBox('取排针流水号失败！', '提示', 0);
            Exit;
          end;
        end
        else
        begin
          maxpzno := Trim(ClientDataSet3.fieldbyname('PZId').AsString);
        end;
//        with ADOCmd do
//        begin
//          Close;
//          SQL.Clear;
//          sql.Add('select * from Cloth_PaiZhen2 where ');
//          sql.Add('  PZname=''' + Trim(edt1.Text) + '''');
//          Open;
//        end;
//        if adocmd.IsEmpty = false then
//          Application.MessageBox('名称重复!', '提示', 0);
//        Exit;
        with ADOCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from Cloth_PaiZhen2 where ');
          sql.Add('  PZId=''' + Trim(maxpzno) + '''');
          Open;
        end;
        with ADOCmd do
        begin
          if Trim(ClientDataSet3.fieldbyname('PZId').AsString) = '' then
          begin
            Append;
            FieldByName('Filler').Value := Trim(DName);
            FieldByName('FillTime').Value := SGetServerDateTime(ADOTemp);
          end
          else
          begin
            Edit;
            FieldByName('Editer').Value := Trim(DName);
            FieldByName('EditTime').Value := SGetServerDateTime(ADOTemp);
          end;
          FieldByName('MainId').Value := Trim(maxno);
          FieldByName('SubId').Value := Trim(maxsubno);
          FieldByName('PZId').Value := Trim(maxpzno);
          RTSetSaveDataCDS(ADOCmd, Tv3, ClientDataSet3, 'Cloth_PaiZhen2', 0);
          FieldByName('PZType').Value := '排针';
          FieldByName('PZName').Value := edt1.Text;
          FieldByName('PBName').Value := C_CodeName.Text;
          Post;
        end;
        ClientDataSet3.Edit;
        ClientDataSet3.FieldByName('PZId').Value := Trim(maxpzno);
        //Order_Sub.Post;
        Next;
      end;
    end;
    ClientDataSet3.EnableControls;
    ///保存排针表
    ///保存三角表
    ClientDataSet5.DisableControls;
    with ClientDataSet5 do
    begin
      First;
      while not Eof do
      begin
        if Trim(ClientDataSet5.fieldbyname('PZId').AsString) = '' then
        begin
          if GetLSNo(ADOCmd, maxsjno, 'PZB', 'Cloth_PaiZhen2', 4, 1) = False then
          begin
            ADOCmd.Connection.RollbackTrans;
            Application.MessageBox('取三角流水号失败！', '提示', 0);
            Exit;
          end;
        end
        else
        begin
          maxsjno := Trim(ClientDataSet5.fieldbyname('PZId').AsString);
        end;
//        with ADOCmd do
//        begin
//          Close;
//          SQL.Clear;
//          sql.Add('select * from Cloth_PaiZhen2 where ');
//          sql.Add('  PZname=''' + Trim(edt1.Text) + '''');
//          Open;
//        end;
//        if adocmd.IsEmpty = false then
//          Application.MessageBox('名称重复!', '提示', 0);
//        Exit;
        with ADOCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from Cloth_PaiZhen2 where ');
          sql.Add('  PZId=''' + Trim(maxsjno) + '''');
          Open;
        end;
        with ADOCmd do
        begin
          if Trim(ClientDataSet5.fieldbyname('PZId').AsString) = '' then
          begin
            Append;
            FieldByName('Filler').Value := Trim(DName);
            FieldByName('FillTime').Value := SGetServerDateTime(ADOTemp);
          end
          else
          begin
            Edit;
            FieldByName('Editer').Value := Trim(DName);
            FieldByName('EditTime').Value := SGetServerDateTime(ADOTemp);
          end;
          FieldByName('MainId').Value := Trim(maxno);
          FieldByName('SubId').Value := Trim(maxsubno);
          FieldByName('PZId').Value := Trim(maxsjno);
          RTSetSaveDataCDS(ADOCmd, Tv5, ClientDataSet5, 'Cloth_PaiZhen2', 0);
          FieldByName('PZType').Value := '三角';
          FieldByName('PBName').Value := C_CodeName.Text;
          FieldByName('PZName').Value := edt1.Text;
          Post;
        end;
        ClientDataSet5.Edit;
        ClientDataSet5.FieldByName('PZId').Value := Trim(maxsjno);
        //Order_Sub.Post;
        Next;
      end;
    end;
    ClientDataSet5.EnableControls;
    ///保存三角表
    ADOCmd.Connection.CommitTrans;

    Result := True;
  except
    Result := False;
    ClientDataSet3.EnableControls;
    ClientDataSet5.EnableControls;

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

procedure TfrmClothSCInPut.btn2Click(Sender: TObject);
var
  i: Integer;
  s: string;
  K: string;
begin
  try
    frmMachineManage := TfrmMachineManage.Create(Application);
    with frmMachineManage do
    begin
      K := '三角';
      if ShowModal = 1 then
      begin
        frmMachineManage.CDS_HZ.DisableControls;
        with frmMachineManage.CDS_HZ do

        begin

          First;
          while Locate('SSel', True, []) do
          begin
            with ClientDataSet5 do
            begin
              Append;
              FieldByName('weizhi').Value := frmMachineManage.CDS_HZ.fieldbyname('weizhi').Value;
              for i := 1 to 80 do
              begin
                s := 'PZ' + inttostr(i);
                FieldByName(s).Value := frmMachineManage.CDS_HZ.fieldbyname(s).Value;
              end;

            end;
            frmMachineManage.CDS_HZ.Delete;
          end;
        end;
        frmMachineManage.CDS_HZ.EnableControls;
      end;
    end;
  finally
    frmMachineManage.Free;
  end;
end;

procedure TfrmClothSCInPut.btn3Click(Sender: TObject);
begin
//  fname := edt1.text;
  if SaveData2() then
  begin
    Application.MessageBox('保存成功！', '提示', 0);
    pnl1.Visible := False;
//    ModalResult := 1;
  end;
end;

procedure TfrmClothSCInPut.btn4Click(Sender: TObject);
begin
  pnl1.Visible := False;
end;

procedure TfrmClothSCInPut.btn5Click(Sender: TObject);
var
  i: Integer;
  s: string;
begin
  try
    frmMachineManage := TfrmMachineManage.Create(Application);
    with frmMachineManage do
    begin
      K := '';
      if ShowModal = 1 then
      begin
        frmMachineManage.CDS_HZ.DisableControls;
        with frmMachineManage.CDS_HZ do
        begin

          First;
          while Locate('SSel', True, []) do
          begin
            with ClientDataSet3 do
            begin
              Append;
              FieldByName('weizhi').Value := frmMachineManage.CDS_HZ.fieldbyname('weizhi').Value;
              for i := 1 to 80 do
              begin
                s := 'PZ' + inttostr(i);
                FieldByName(s).Value := frmMachineManage.CDS_HZ.fieldbyname(s).Value;
              end;

            end;
            frmMachineManage.CDS_HZ.Delete;
          end;
        end;
        frmMachineManage.CDS_HZ.EnableControls;
      end;
    end;
  finally
    frmMachineManage.Free;
  end;
end;

procedure TfrmClothSCInPut.XSConNoBtnUpClick(Sender: TObject);
var
  FConNo, FForOrderNo: string;
begin
  try
    frmContractListNXSel := TfrmContractListNXSel.Create(Application);
    with frmContractListNXSel do
    begin
      if ShowModal = 1 then
      begin
        FForOrderNo := Trim(frmContractListNXSel.Order_Main.fieldbyname('ForOrderNo').AsString);
        Self.XSConNo.Text := Trim(frmContractListNXSel.Order_Main.fieldbyname('ConNo').AsString);
        Self.conno.Text := Trim(frmContractListNXSel.Order_Main.fieldbyname('ForOrderNo').AsString);
        Self.XSConNo.TxtCode := Trim(frmContractListNXSel.ClientDataSet2.fieldbyname('SubId').AsString);
        Self.khname.Text := Trim(frmContractListNXSel.Order_Main.fieldbyname('CustomerNoName').AsString);
        Self.C_CodeName.Text := Trim(frmContractListNXSel.ClientDataSet2.fieldbyname('PrtCodeName').AsString);
        Self.C_Code.Text := Trim(frmContractListNXSel.ClientDataSet2.fieldbyname('PrtCode').AsString);
        Self.C_Color.Text := Trim(frmContractListNXSel.ClientDataSet2.fieldbyname('PRTColor').AsString);

        Self.KZ.Text := Trim(frmContractListNXSel.ClientDataSet2.fieldbyname('prtkz').AsString);
        Self.C_Spec.Text := Trim(frmContractListNXSel.ClientDataSet2.fieldbyname('prtspec').AsString);
        Self.PiQty.Text := Trim(frmContractListNXSel.ClientDataSet2.fieldbyname('PiShu').AsString);
        Self.PiKgQty.Text := Trim(frmContractListNXSel.ClientDataSet2.fieldbyname('PiZhong').AsString);
        Self.C_Qty.Text := Trim(frmContractListNXSel.ClientDataSet2.fieldbyname('PRTOrderQty').AsString);

//        Self.Price.Text:=Trim(frmContractListNXSel.ClientDataSet2.fieldbyname('PRTPrice').AsString);
       // Self.ishs.ItemIndex:=ishs.Items.IndexOf(frmContractListNXSel.Order_Main.fieldbyname('ishs').AsString);
        DeliveryDate.Date := frmContractListNXSel.Order_Main.fieldbyname('DlyDate').AsDateTime;
//        Self.ConPayment.Text := Trim(frmContractListNXSel.Order_Main.fieldbyname('Payment').AsString);
//        Self.ZdyNameZ.Text := Trim(frmContractListNXSel.Order_Main.fieldbyname('ZdyNameZ').AsString);

        cpsel();
        JXSEL();
//        Self.ConDYMoney.Text := Trim(frmContractListNXSel.ClientDataSet2.fieldbyname('DYMoney').AsString);
      end;
    end;
  finally
    frmContractListNXSel.Free;
  end;
  if Trim(FMainId) = '' then
  begin
    with ADOTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select ConNum=count(ConNo) from Cloth_Main where XSConNo=''' + Trim(XSConNo.Text) + '''');
      Open;
    end;
    if ADOTemp.FieldByName('ConNum').AsInteger = 0 then
    begin
      ConNo.Text := Trim(FForOrderNo);          //XSConNo.Text
    end
    else
    begin
      ConNo.Text := Trim(FForOrderNo) + '-' + INTTOSTR(ADOTemp.FieldByName('ConNum').AsInteger);
    end;
  end;
end;

procedure TfrmClothSCInPut.v2Column1PropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FFieldName: string;
  FJQZS, FDQTY, FZQTY, FLQTY, FXCHANG, FKZZHUAN, FYLQTY, fqty, fxl, fsh: DOUBLE;
begin

  mvalue := TcxTextEdit(Sender).EditingText;
  FFieldName := Trim(Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName);
  if Trim(mvalue) = '' then
  begin
    mvalue := '0';
  end;
  with CDS_YUANLIAO do
  begin
    Edit;
    FieldByName(FFieldName).Value := Trim(mvalue);
    Post;
  end;
 { //每转重量=纱长*用纱路数*机器针数*583÷D数÷10000000000
  //或者每转重量=纱长*用纱路数*机器针数*D数÷90000000000（十个0，九百亿）
//每日产量（KG）=每转重量*转速*效率*24*60
//每日产量（磅）=每日产量（KG）*2.2046
总日产=全部原料的每日产量（KG）相加

理论比例=各原料的每日产量÷总日产

预计用量=总数量*理论比例（Kg）÷（1-损耗）

手动输入正式比例后，实际用量=总数量*真实比例（Kg）÷（1-损耗）}
//  with CDS_YUANLIAO do
//  begin
//    Edit;
//    FJQZS := (strtofloatdef(trim(JQZHENQTY.Text), 0));  //机器针数
//    FKZZHUAN := (strtofloatdef(trim(KZZHUAN.Text), 0)); //转速
//    FDQTY := (strtofloatdef(CDS_YUANLIAO.FieldByName('YCLSpec').ASSTRING, 0));  //D数
//    FLQTY := (strtofloatdef(CDS_YUANLIAO.FieldByName('YongShaLuShu').ASSTRING, 0)); //用纱路数
//    FZQTY := (strtofloatdef(CDS_YUANLIAO.FieldByName('YLZS').ASSTRING, 0));  //支数
//    FXCHANG := (strtofloatdef(CDS_YUANLIAO.FieldByName('ShaChang').ASSTRING, 0));  //纱长
//    fxl := (strtofloatdef(trim(xiaolv.Text), 0)); //效率
//    fqty := (strtofloatdef(trim(C_QTY.Text), 0)); //总数量
//    fsh := (strtofloatdef(CDS_YUANLIAO.FieldByName('ZPSH').ASSTRING, 0)); //损耗
//    Post;
//  end;
////  FYLQTY := FJQZS * FDQTY * FLQTY * FXCHANG * FKZZHUAN / 9000 / 10000000;
//  with CDS_YUANLIAO do
//  begin
//    Edit;
//    FieldByName('YLMZZL').value := FormatFloat('0.00000000', (FXCHANG * FLQTY * FJQZS * FDQTY / 90000000000));
////    FieldByName('pinpai').asstring := floattostr(roundfloat((FXCHANG * FLQTY * FJQZS / FZQTY / 90000000000), 8));
////    showmessage(floattostr(roundfloat((FXCHANG * FLQTY * FJQZS / FZQTY / 90000000000), 8)));
//    Post;
//  end;
//  with CDS_YUANLIAO do
//  begin
//    Edit;
//    FieldByName('YLCHANLIANG').Value := roundfloat((FieldByName('YLMZZL').Value * FKZZHUAN * fxl * 60 * 24), 4);
//     //每日产量（KG）
//    FieldByName('YLCHANLIANGB').Value := roundfloat((FieldByName('YLMZZL').Value * FKZZHUAN * fxl * 60 * 24 * 2.2046), 4);   //每日产量（磅）
//    Post;
//  end;
//  HJJE();
//  if (STRTOFLOAT(DAYQTY.Text) <> 0) then
//  begin
//
//    with CDS_YuanLiao do
//    begin
//      First;
//      while not Eof do
//      begin
//        Edit;
//        FieldByName('PBQTY2').Value := roundfloat((FieldByName('YLCHANLIANG').Value / STRTOFLOAT(DAYQTY.Text) * 100), 2);
//
////        FieldByName('YLQty').Value := roundfloat(fqty * FieldByName('YLCHANLIANG').Value / STRTOFLOAT(DAYQTY.Text) * 100 / (1 - fsh / 100), 2);
//
//        FieldByName('YLQty').Value := roundfloat(fqty * FieldByName('PBQTY2').Value / (1 - fsh / 100) / 100, 2);
//        Post;
//        Next;
//      end;
//    end;
//  end;
//  if (STRTOFLOAT(LBQTY.Text) <> 0) and (STRTOFLOAT(DAYQTY.Text) <> 0) then
//  begin
//    ZHUANQTY.TEXT := FLOATTOSTR(round(STRTOFLOAT(KZZHUAN.Text) / STRTOFLOAT(DAYQTY.Text) * STRTOFLOAT(LBQTY.Text)));
//  end;
end;

procedure TfrmClothSCInPut.CarTypePropertiesEditValueChanged(Sender: TObject);
begin
  JXSEL();
end;

procedure TfrmClothSCInPut.v2Column7PropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FFieldName: string;
  FSH, FYLCL, FYLQTY: DOUBLE;
  Fqty, fbl, fylbl: DOUBLE;
begin

  mvalue := TcxTextEdit(Sender).EditingText;
  FFieldName := Trim(Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName);
  if Trim(mvalue) = '' then
  begin
    mvalue := '0';
  end;
  with CDS_YUANLIAO do
  begin
    Edit;
    FieldByName(FFieldName).Value := Trim(mvalue);
    Post;
  end;
  Fqty := (strtofloatdef(trim(C_QTY.Text), 0)); //总数量
  fbl := (strtofloatdef(CDS_YUANLIAO.FieldByName('PBQty').ASSTRING, 0));  //真实比例
  fylbl := (strtofloatdef(CDS_YUANLIAO.FieldByName('PBQty2').ASSTRING, 0));  //理论比例
  FSH := (strtofloatdef(CDS_YUANLIAO.FieldByName('ZPSH').ASSTRING, 0));  //损耗

  FYLCL := (strtofloatdef(CDS_YUANLIAO.FieldByName('YLCHANLIANG').ASSTRING, 0));
//  FYLQTY := FYLCL / (1 - FSH / 100);
  FYLQTY := Fqty * fylbl / (1 - FSH / 100) / 100;

  with CDS_YUANLIAO do
  begin
    Edit;
    FieldByName('YLQty').Value := floattostr(FYLQTY);
    Post;
  end;
  Fqty := (strtofloatdef(trim(C_QTY.Text), 0)); //总数量
  fbl := (strtofloatdef(CDS_YUANLIAO.FieldByName('PBQty').ASSTRING, 0));  //真实比例
  FSH := (strtofloatdef(CDS_YUANLIAO.FieldByName('ZPSH').ASSTRING, 0));  //损耗
  with CDS_YUANLIAO do
  begin
    Edit;
//    FieldByName('CKQty').Value := Fqty * fbl / 100 / (1 - FSH / 100);
    FieldByName('CKQty').Value := Fqty * fbl / (1 - FSH / 100) / 100;
    Post;
  end;
end;

procedure TfrmClothSCInPut.v2Column13PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'cgsh';
      flagname := '采购色号';
      if ShowModal = 1 then
      begin
        Self.CDS_YuanLiao.Edit;
        Self.CDS_YuanLiao.FieldByName('CGSH').Value := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmClothSCInPut.cxgrdbclmnv2Column14PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'yssh';
      flagname := '原始色号';
      if ShowModal = 1 then
      begin
        Self.CDS_YuanLiao.Edit;
        Self.CDS_YuanLiao.FieldByName('ysSH').Value := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

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

procedure TfrmClothSCInPut.v2Column6PropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FFieldName: string;
  FDS, FZS: DOUBLE;
begin

  mvalue := TcxTextEdit(Sender).EditingText;
  FFieldName := Trim(Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName);
  if Trim(mvalue) = '' then
  begin
    mvalue := '0';
  end;
  with CDS_YUANLIAO do
  begin
    Edit;
    FieldByName(FFieldName).Value := Trim(mvalue);
    Post;
  end;
  if (mvalue <> '0') then
  begin
    with CDS_YUANLIAO do
    begin
      Edit;
      FieldByName('YLZS').Value := ROUNDFLOAT((5247 / FieldByName(FFieldName).Value), 2);
      Post;
    end;
  end;
end;

procedure TfrmClothSCInPut.v2Column15PropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FFieldName: string;
  FDS, FZS: DOUBLE;
begin

  mvalue := TcxTextEdit(Sender).EditingText;
  FFieldName := Trim(Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName);
  if Trim(mvalue) = '' then
  begin
    mvalue := '0';
  end;
  with CDS_YUANLIAO do
  begin
    Edit;
    FieldByName(FFieldName).Value := Trim(mvalue);
    Post;
  end;
  if (mvalue <> '0') then
  begin
    if FFieldName = 'YCLSpec' then
    begin
      with CDS_YUANLIAO do
      begin
        Edit;
        FieldByName('YLZS').Value := ROUNDFLOAT((5247 / FieldByName(FFieldName).Value), 2);
        Post;
      end;
    end
    else if FFieldName = 'YLZS' then
    begin
      with CDS_YUANLIAO do
      begin
        Edit;
        FieldByName('YCLSpec').Value := ROUNDFLOAT((5247 / FieldByName(FFieldName).Value), 2);
        Post;
      end;
    end;

  end;
end;

procedure TfrmClothSCInPut.cxGridDBColumn2PropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FFieldName: string;
  Fqty, fbl, fsh: DOUBLE;
begin
   //手动输入正式比例后，实际用量=总数量*真实比例（Kg）÷（1-损耗）
  mvalue := TcxTextEdit(Sender).EditingText;
  FFieldName := Trim(Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName);
  if Trim(mvalue) = '' then
  begin
    mvalue := '0';
  end;
  with CDS_YUANLIAO do
  begin
    Edit;
    FieldByName(FFieldName).Value := Trim(mvalue);
    Post;
  end;
  Fqty := (strtofloatdef(trim(C_QTY.Text), 0)); //总数量
  fbl := (strtofloatdef(CDS_YUANLIAO.FieldByName('PBQty').ASSTRING, 0));  //真实比例
  fsh := (strtofloatdef(CDS_YUANLIAO.FieldByName('ZPSH').ASSTRING, 0));  //损耗
  with CDS_YUANLIAO do
  begin
    Edit;
//    FieldByName('CKQty').Value := Fqty * fbl / 100 / (1 - fsh / 100);
    FieldByName('CKQty').Value := Fqty * fbl / (1 - fsh / 100) / 100;
    Post;
  end;
end;

procedure TfrmClothSCInPut.kzzhuanshuChange(Sender: TObject);
var
  FZS, FZRC, FLBQTY: Double;
begin
//  FZS := StrToFloatDef(kzzhuanshu.Text, 0);
//  FZRC := StrToFloatDef(DAYQTY.Text, 0);
//  FLBQTY := StrToFloatDef(LBQTY.Text, 0);
//  if (FZRC > 0) and (FLBQTY > 0) then
//    ZHUANQTY.Text := IntToStr(Ceil(FZS / FZRC * FLBQTY));

end;

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

procedure TfrmClothSCInPut.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  writeCxGrid('坯布生产计划单原材料1', Tv2, '坯布生产管理');
end;

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

procedure TfrmClothSCInPut.v2Column5PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  if cxPageControl1.ActivePageIndex <> 0 then
    Exit;
  ShaChang.SetFocus;
  try
    frmShaKCSelList := TfrmShaKCSelList.Create(Application);
    with frmShaKCSelList do
    begin
      chejian.Text := '二车间';
      // Self.JHCHEJIAN.Text;
      BatchNo.Text := Self.CDS_YuanLiao.fieldbyname('BatchNo').asstring;
      if ShowModal = 1 then
      begin
        with CDS_YuanLiao do
        begin
          edit;
          FieldByName('YCLName').Value := frmShaKCSelList.CDS_Main.fieldbyname('SPName').Value;
          FieldByName('YCLSpec').Value := frmShaKCSelList.CDS_Main.fieldbyname('SPSpec').Value;
          FieldByName('PinPai').Value := frmShaKCSelList.CDS_Main.fieldbyname('FactoryName').Value;
          FieldByName('GYSName').Value := frmShaKCSelList.CDS_Main.fieldbyname('FactoryName').Value;
          FieldByName('BatchNo').Value := frmShaKCSelList.CDS_Main.fieldbyname('BatchNo').Value;
//          FieldByName('SPID').Value := frmShaKCSelList.CDS_Main.fieldbyname('SPID').Value;
          //Post;
        end;
      end;
    end;
  finally
    frmShaKCSelList.Free;
  end;
end;

procedure TfrmClothSCInPut.ToolButton6Click(Sender: TObject);
var
  f1, f2, f3: string;
  i: Integer;
begin
  if (PState = 0) or (FCopyInt = 1) then
  begin
    with CDS_YuanLiao do
    begin
      First;
      while not Eof do
      begin
        Edit;
        FieldByName('MainId').Value := '';
        FieldByName('SubId').Value := '';
        FieldByName('PBId').Value := '';

        Post;
        Next;
      end;
    end;
    CDS_YuanLiao.EnableControls;
    ClientDataSet3.DisableControls;
    with ClientDataSet3 do
    begin
      First;
      while not Eof do
      begin
        Edit;
        FieldByName('MainId').Value := '';
        FieldByName('SubId').Value := '';
        FieldByName('PZId').Value := '';
        Post;
        Next;
      end;
    end;
    ClientDataSet3.EnableControls;
    ClientDataSet5.DisableControls;
    with ClientDataSet5 do
    begin
      First;
      while not Eof do
      begin
        Edit;
        FieldByName('MainId').Value := '';
        FieldByName('SubId').Value := '';
        FieldByName('PZId').Value := '';
        Post;
        Next;
      end;
    end;
    ClientDataSet5.EnableControls;
    FMainId := '';
    FSubId := '';
    for i := 1 to 5 do
    begin
      if GetLSNo(ADOTemp, f1, 'PZ', 'Cloth_PaiZhen', 4, 1) = False then
      begin
        Application.MessageBox('取排针流水号失败！', '提示', 0);
        Exit;
      end;

      if GetLSNo(ADOTemp, f3, 'PB', 'Cloth_YCL_PB', 4, 1) = False then
      begin
        Application.MessageBox('取配比子流水号失败！', '提示', 0);
        Exit;
      end;
    end;
    TBSave.Click();
  end
  else
  begin
    Application.MessageBox('非新增单不能使用异常保存！', '提示', 0);
    Exit;
  end;

end;

end.

