unit U_OrderInPut;

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, cxCalendar, StrUtils,
  cxCurrencyEdit, cxGridCustomPopupMenu, cxGridPopupMenu, cxDropDownEdit,
  RM_Common, RM_Preview, RM_System, RM_Class, RM_GridReport, RM_Dataset, Menus,
  cxSplitter, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator, cxCheckBox,
  dxSkinsCore, dxSkinsDefaultPainters, dxSkinscxPCPainter, dxSkinBlack,
  dxSkinBlue, dxSkinBlueprint, dxSkinCaramel, dxSkinCoffee, dxSkinDarkRoom,
  dxSkinDarkSide, dxSkinDevExpressDarkStyle, dxSkinDevExpressStyle, dxSkinFoggy,
  dxSkinGlassOceans, dxSkinHighContrast, dxSkiniMaginary, dxSkinLilian,
  dxSkinLiquidSky, dxSkinLondonLiquidSky, dxSkinMcSkin, dxSkinMetropolis,
  dxSkinMetropolisDark, dxSkinMoneyTwins, dxSkinOffice2007Black,
  dxSkinOffice2007Blue, dxSkinOffice2007Green, dxSkinOffice2007Pink,
  dxSkinOffice2007Silver, dxSkinOffice2010Black, dxSkinOffice2010Blue,
  dxSkinOffice2010Silver, dxSkinOffice2013DarkGray, dxSkinOffice2013LightGray,
  dxSkinOffice2013White, dxSkinPumpkin, dxSkinSeven, dxSkinSevenClassic,
  dxSkinSharp, dxSkinSharpPlus, dxSkinSilver, dxSkinSpringTime, dxSkinStardust,
  dxSkinSummer2008, dxSkinTheAsphaltWorld, dxSkinValentine, dxSkinVS2010,
  dxSkinWhiteprint, dxSkinXmas2008Blue;

type
  TfrmOrderInPut = class(TForm)
    ToolBar1: TToolBar;
    TBSave: TToolButton;
    TBClose: TToolButton;
    ScrollBox1: TScrollBox;
    Label1: TLabel;
    OrderNo: TEdit;
    Label7: TLabel;
    ToolBar2: TToolBar;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    v1PRTColor: TcxGridDBColumn;
    ADOTemp: TADOQuery;
    ADOCmd: TADOQuery;
    DataSource1: TDataSource;
    Order_Sub: TClientDataSet;
    v1PRTOrderQty: TcxGridDBColumn;
    Label10: TLabel;
    JGFactoryName: TBtnEditC;
    v1OrderUnit: TcxGridDBColumn;
    Label3: TLabel;
    Label14: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    OrdDate: TDateTimePicker;
    CustomerNoName: TBtnEditC;
    Label2: TLabel;
    Label6: TLabel;
    Label19: TLabel;
    Label25: TLabel;
    DLYDate: TDateTimePicker;
    Label26: TLabel;
    MPRTCode: TBtnEditC;
    Label41: TLabel;
    GDY: TBtnEditC;
    Label42: TLabel;
    MPRTBZNote: TMemo;
    MPRTChuanY: TMemo;
    v1Column1: TcxGridDBColumn;
    Note: TMemo;
    Label23: TLabel;
    JGType: TBtnEditC;
    Label53: TLabel;
    cxGridPopupMenu1: TcxGridPopupMenu;
    v1Column2: TcxGridDBColumn;
    Label60: TLabel;
    MPRTCodeName: TEdit;
    MPRTCF: TEdit;
    MPRTMF: TEdit;
    MPRTSpec: TEdit;
    MPRTKZ: TEdit;
    Label4: TLabel;
    KHConNo: TEdit;
    VC_PRTPs: TcxGridDBColumn;
    RMPreview1: TRMPreview;
    Label5: TLabel;
    LBName: TEdit;
    ToolButton3: TToolButton;
    ADOQueryLabel: TADOQuery;
    RMGridReport1: TRMGridReport;
    Label8: TLabel;
    lidan: TBtnEditC;
    Label9: TLabel;
    PBFactoryName: TBtnEditC;
    ZongPS: TEdit;
    ZongQty: TEdit;
    Label17: TLabel;
    YWY: TBtnEditC;
    Label20: TLabel;
    LLXS: TEdit;
    ConNo: TBtnEditC;
    ToolButton4: TToolButton;
    Label22: TLabel;
    Label24: TLabel;
    Feel: TEdit;
    Label27: TLabel;
    RSYQ: TEdit;
    Label28: TLabel;
    SLDYQ: TComboBox;
    Label29: TLabel;
    SCYQ: TEdit;
    Label30: TLabel;
    XGF: TEdit;
    Label31: TLabel;
    ZBF: TEdit;
    Label32: TLabel;
    KHYQ: TMemo;
    CPNum: TEdit;
    Label34: TLabel;
    YTPNum: TEdit;
    Label15: TLabel;
    Label16: TLabel;
    Label33: TLabel;
    Label35: TLabel;
    SSL: TEdit;
    jhwcDate: TDateTimePicker;
    v1Column4: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    Label36: TLabel;
    CYData: TDateTimePicker;
    Label37: TLabel;
    ZGData: TDateTimePicker;
    Label38: TLabel;
    QtyNote: TEdit;
    Label39: TLabel;
    PCNote: TEdit;
    Label40: TLabel;
    JYBZNote: TEdit;
    Label43: TLabel;
    ChuYunNote: TBtnEditC;
    Label11: TLabel;
    GSLYNote: TEdit;
    Label44: TLabel;
    SGYNote: TEdit;
    v1Column6: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    Label45: TLabel;
    LabQty: TComboBox;
    Label46: TLabel;
    BPBigType: TComboBox;
    Label47: TLabel;
    MPiZhong: TEdit;
    Label48: TLabel;
    Panel1: TPanel;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    ToolButton5: TToolButton;
    RM1: TRMGridReport;
    CDS_PRT: TClientDataSet;
    RMDBMain: TRMDBDataSet;
    Label49: TLabel;
    Label50: TLabel;
    MPRTMFNote: TEdit;
    MPRTKZNote: TEdit;
    PopupMenu1: TPopupMenu;
    N2: TMenuItem;
    lblllxs: TLabel;
    v1Column11: TcxGridDBColumn;
    ToolButton6: TToolButton;
    CDS_Copy: TClientDataSet;
    Label52: TLabel;
    Label_Juan: TMemo;
    Label51: TLabel;
    Label54: TLabel;
    cxGrid2: TcxGrid;
    TV2: TcxGridDBTableView;
    cxGridLevel1: TcxGridLevel;
    V2Column1: TcxGridDBColumn;
    DSFact: TDataSource;
    CDS_Fact: TClientDataSet;
    V2Column2: TcxGridDBColumn;
    PM_Fact: TPopupMenu;
    MenuItem1: TMenuItem;
    N1: TMenuItem;
    V2Column3: TcxGridDBColumn;
    V2Column4: TcxGridDBColumn;
    Label_Bao: TMemo;
    cxSplitter1: TcxSplitter;
    N3: TMenuItem;
    N4: TMenuItem;
    Label55: TLabel;
    KHCPCode: TBtnEditC;
    Label56: TLabel;
    KHCPName: TBtnEditC;
    v1Column12: TcxGridDBColumn;
    ADOQuery1: TADOQuery;
    CXSHSTATUS: TEdit;
    Status: TEdit;
    v1Column3: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    ToolButton7: TToolButton;
    Panel8: TPanel;
    Panel9: TPanel;
    Image4: TImage;
    Button6: TButton;
    XGNote: TMemo;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    Label18: TLabel;
    FILLER: TEdit;
    ADOQueryCmdSC: TADOQuery;
    ADOQueryCmdFileContent: TBlobField;
    ADOQueryCmdFtFileName: TStringField;
    ADOQueryCmdFileEditDate: TDateTimeField;
    ADOQueryCmdFileSize: TFloatField;
    ADOQueryCmdFiller: TStringField;
    ADOQueryCmdLastEditTime: TDateTimeField;
    ADOQueryCmdLastEditer: TStringField;
    ADOQueryCmdFileCreateDate: TDateTimeField;
    ADOQueryCmdchildPath: TStringField;
    ADOQueryCmdFileType: TStringField;
    Label21: TLabel;
    HYTT: TBtnEditC;
    Label57: TLabel;
    KYTT: TBtnEditC;
    DDTYPE: TEdit;
    Label58: TLabel;
    MLMS: TBtnEditC;
    Label59: TLabel;
    BMMS: TBtnEditC;
    Label61: TLabel;
    YXMF: TEdit;
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure v1PRTColorPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure JGFactoryNameBtnUpClick(Sender: TObject);
    procedure CustomerNoNameBtnUpClick(Sender: TObject);
    procedure CustomerNoNameBtnDnClick(Sender: TObject);
    procedure MPRTCodeNameBtnUpClick(Sender: TObject);
    procedure v1OrderUnitPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v1PriceUnitPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure OrdDefStr2BtnUpClick(Sender: TObject);
    procedure YCLFactoryBtnUpClick(Sender: TObject);
    procedure MPRTSCTeBieNoteBtnUpClick(Sender: TObject);
    procedure MPRTBZNoteDblClick(Sender: TObject);
    procedure MPRTChuanYDblClick(Sender: TObject);
    procedure MPRTCodeBtnUpClick(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure PBFactoryNameBtnUpClick(Sender: TObject);
    procedure ConNoBtnUpClick(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure MPRTMFExit(Sender: TObject);
    procedure MPRTKZExit(Sender: TObject);
    procedure LLXSExit(Sender: TObject);
    procedure MPiZhongExit(Sender: TObject);
    procedure SSLExit(Sender: TObject);
    procedure ScrollBox1Click(Sender: TObject);
    procedure ToolButton6Click(Sender: TObject);
    procedure MenuItem1Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure V2Column1PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure N3Click(Sender: TObject);
    procedure N4Click(Sender: TObject);
    procedure Tv1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure v1PRTOrderQtyPropertiesEditValueChanged(Sender: TObject);
    procedure Image4Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure ToolButton7Click(Sender: TObject);
    procedure v1Column5PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v1Column5PropertiesEditValueChanged(Sender: TObject);
    procedure DLYDateChange(Sender: TObject);
    procedure HYTTBtnUpClick(Sender: TObject);
    procedure KYTTBtnUpClick(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
  private
    procedure InitData();
    procedure PDCP(); //判断产品是否是特殊
    procedure GetYTPS();
    procedure GetLLXS();
    procedure ZDYHelp(FButn: TcxButtonEdit; LType: string);
    function SaveData(): Boolean;
    function getOrderNo(fconNo: string): string;
    procedure OpenLabel();
    function UPLabel(LabelName, LabelPath: string): Boolean;
    function PostFileToData(LabelName, LabelPath: string): boolean;
    { Private declarations }
  public
    PState, CopyInt, PriceFlag: Integer;
    FMainId, FFMainId, FOrderNo, PXGQX: string;
    fscxdh: string;
    FXS: Integer;
    canshu1: string;
    fFlileFlag: string;
    FXGNOTE, STR: string;
    { Public declarations }
  end;

var
  frmOrderInPut: TfrmOrderInPut;
  newh: hwnd;

implementation

uses
  U_DataLink, U_ZDYHelp, U_Fun, U_ZDYHelpSel, U_ZdyAttachment, U_ZdyAttachGYS,
  U_CPManageSel, getpic, U_LabelList, U_ContractListSel, U_SketchManageListSel;

{$R *.dfm}
function TfrmOrderInPut.UPLabel(LabelName, LabelPath: string): Boolean;
begin
  try
    ADOCmd.Connection.BeginTrans;
    with ADOCmd do
    begin
      close;
      sql.Clear;
      sql.Add('select * from P_Label');
      sql.Add('where LabelCaption=' + quotedstr(LabelName));
      Open;
      if ADOCmd.IsEmpty then
      begin
        Append;
        fieldByName('filler').value := DName;
        fieldByName('filltime').value := DServerDate;
        fieldByName('beizhu').value := '';
        fieldByName('LabelCaption').value := trim(LabelPath);
        fieldByName('LabelType').value := '中文标签';
        fieldByName('LabelFileName').value := trim(LabelName);
        RM1.SaveToBlobField(TBlobField(FieldByName('LabelFile')));
      end
      else
      begin
        Edit;
        fieldByName('Editer').value := DName;
        fieldByName('EditTime').value := DServerDate;
      end;
      RM1.SaveToBlobField(TBlobField(FieldByName('LabelFile')));
      Post;
    end;

    ADOCmd.Connection.CommitTrans;
    result := true;
  except
    ADOCmd.Connection.RollbackTrans;
    Result := false;
    application.MessageBox('保存标签模板出错!', '警告信息', 0);
  end;
end;

function TfrmOrderInPut.PostFileToData(LabelName, LabelPath: string): boolean;
var
  mFileName, fFileName, fpathFileName: string;
  Stream: TMemoryStream;
  mfileSize: integer;
  mCreationTime: TdateTime;
  mWriteTime: TdateTime;
//  ADOQueryCmdFileContent: TBlobField;
begin
  result := false;
  fFileName := Trim(LabelName) + '.rmf';
  fpathFileName := Trim(LabelPath);
  try
    ADOQueryCmdSC.Connection.BeginTrans;
    try
      with ADOQueryCmdSC do
      begin
        close;
        sql.Clear;
        sql.Add('delete  from RT_FileUpdate');
        sql.Add('where FileName=' + quotedStr(trim(fFileName)));
        execsql;
      end;
      with ADOQueryCmdSC do
      begin
        close;
        sql.Clear;
        sql.Add('select * from RT_FileUpdate');
        sql.Add('where FileName=' + quotedStr(trim(fFileName)));
        Open;
        //////////////////////////
        //获取文件信息
        GetFileInfo(Trim(fpathFileName), mfileSize, mCreationTime, mWriteTime);

        if RecordCount <= 0 then
        begin
          Append;
          fieldByName('FileName').AsString := trim(fFileName);
        end
        else
        begin
          edit;
        end;

        fieldByName('FileEditDate').Value := mWriteTime;
        fieldByName('FileCreateDate').Value := mCreationTime;
        fieldByName('FileSize').Value := mfileSize;
        fieldByName('Filler').Value := Dname;
        fieldByName('LastEditer').Value := Dname;
        fieldByName('LastEditTime').Value := Now();
//        if pos('.rmf',fFileName)>0 then
        begin
          fieldByName('FilePath').Value := 'report';
          fieldByName('FileType').Value := '公用';
        end;

        //将OLE数据存入数据库
        RM1.SaveToBlobField(TBlobField(FieldByName('Files')));

//        ADOQueryCmdFileContent.LoadFromFile(fpathFileName);
        //ADOQueryCmdFileContent.LoadFromStream(Stream);

        post;
      end;
    finally
    end;
    result := true;
    ADOQueryCmdSC.Connection.CommitTrans;
  except
    ADOQueryCmdSC.Connection.RollbackTrans;
    Result := False;
    application.MessageBox(pchar('提交文件[' + trim(fFileName) + ']失败!'), '提示信息', MB_ICONERROR);
  end;

end;

procedure TfrmOrderInPut.GetLLXS();
var
  FMPizhong, FSSL, FYTNum, FQtyHZ, FMF1, FMF2, FMF, FKZ1, FKZ, FXS: string;
  Gint, Xint, CMInt, FInt, KZInt, FBeg1, FEnd1, FBeg2, FEnd2: Integer;
  FReal: Double;
begin
  FMF := Trim(MPRTMF.Text);
  FKZ := Trim(MPRTKZ.Text); //53-54"  160-0CM 240.00G/M2    152-153CM
  Gint := Pos('-', FMF);
  Xint := Pos('/', FMF);
  CMInt := Pos('C', FMF);
  FInt := Pos('"', FMF);
  KZInt := Pos('G', FKZ);
  if FInt > 0 then
  begin
    FMF := Copy(FMF, 1, FInt - 1);
    if Gint > 0 then
    begin
      FBeg1 := 1;
      FEnd1 := Gint - 1;
      FBeg2 := Gint + 1;
      FEnd2 := Length(FMF);
    end;
    if Xint > 0 then
    begin
      FBeg1 := 1;
      FEnd1 := Xint - 1;
      FBeg2 := Xint + 1;
      FEnd2 := Length(FMF);
    end;
    FMF1 := Copy(FMF, FBeg1, FEnd1);
    FMF2 := Copy(FMF, FBeg2, FEnd2);
  end;
  if CMInt > 0 then
  begin
    FMF := Copy(FMF, 1, CMInt - 1);
    FBeg1 := 1;
    FEnd1 := Gint - 1;
    FBeg2 := Gint + 1;
    FEnd2 := Length(FMF);
    FMF1 := Copy(FMF, 1, FEnd1);
    FMF2 := Copy(FMF, FBeg2, FEnd2);
  end;
  Edit1.Text := FMF1;
  Edit2.Text := FMF2;
  if KZInt > 0 then
  begin
    FKZ1 := Copy(FKZ, 1, KZInt - 1);
  end;
  Edit3.Text := FKZ1;
  if Trim(Edit1.Text) = '' then
    Edit1.Text := '0';
  if Trim(Edit2.Text) = '' then
    Edit2.Text := '0';
  if TryStrToFloat(Edit1.Text, FReal) = False then
  begin
    Edit1.Text := '0';
  end;
  if TryStrToFloat(Edit2.Text, FReal) = False then
  begin
    Edit2.Text := '0';
  end;
  if StrToInt(Edit1.Text) > StrToInt(Edit2.Text) then
  begin
    FMF := Edit1.Text;
  end
  else
  begin
    FMF := Edit2.Text;
  end;
  if Trim(Edit3.Text) = '' then
    Edit3.Text := '0';
  if TryStrToFloat(Edit3.Text, FReal) = False then
  begin
    Edit3.Text := '0';
  end;
  FKZ := Edit3.Text;
  if FInt > 0 then
  begin
    FMF := FloatToStr(StrToFloat(FMF) * 2.54);
  end;
  if (FMF = '0') or (FKZ = '0') then
  begin
    FXS := '0';
  end
  else
  begin
    FXS := FloatToStr(100000 / (StrToFloat(FMF) * StrToFloat(FKZ)));
  end;

  lblllxs.Caption := FloatToStr(RoundFloat(StrToFloat(FXS), 2));
  //以上取系数，根据门幅克重计算
//  FQtyHZ := Tv1.DataController.Summary.FooterSummaryTexts[0];
//  if Trim(FQtyHZ) = '' then
//    FQtyHZ := '0';
//  FSSL := Trim(SSL.Text);
//  if Trim(FSSL) = '' then
//    FSSL := '0';
end;

procedure TfrmOrderInPut.GetYTPS();
var
  FMPizhong, FSSL, FYTNum, FQtyHZ, FMF1, FMF2, FMF, FKZ1, FKZ, FXS: string;
  Gint, Xint, CMInt, FInt, KZInt, FBeg1, FEnd1, FBeg2, FEnd2: Integer;
  FReal: Double;
begin

  FXS := LLXS.Text;


  //以上取系数，根据门幅克重计算

  FQtyHZ := Tv1.DataController.Summary.FooterSummaryTexts[0];
  if Trim(FQtyHZ) = '' then
    FQtyHZ := '0';
  FSSL := Trim(SSL.Text);
  if Trim(FSSL) = '' then
    FSSL := '0';
  if Trim(BPBigType.Text) = '梭织' then
  begin
    if Trim(Order_Sub.fieldbyname('OrderUnit').AsString) = 'M' then
    begin
      if FSSL <> '0' then
      begin
        if (TryStrToFloat(FSSL, FReal) = True) and (StrToFloat(FSSL) > 0) then
        begin
          YTPNum.Text := IntToStr(Round(StrToFloat(FQtyHZ) / StrToFloat(FSSL)));
        end
        else
        begin
          YTPNum.Text := '';
        end;
      end
      else
      begin
        YTPNum.Text := '';
      end;
    end
    else if Trim(Order_Sub.fieldbyname('OrderUnit').AsString) = 'Y' then
    begin
      if FSSL <> '0' then
      begin
        if (TryStrToFloat(FSSL, FReal) = True) and (StrToFloat(FSSL) > 0) then
        begin
          YTPNum.Text := IntToStr(Round(StrToFloat(FQtyHZ) * 0.9144 / StrToFloat(FSSL)));
        end
        else
        begin
          YTPNum.Text := '';
        end;
      end
      else
      begin
        YTPNum.Text := '';
      end;
    end
    else
    begin
      YTPNum.Text := '';
    end;
    Order_Sub.DisableControls;
    with Order_Sub do
    begin
      First;
      while not Eof do
      begin
        Edit;
        if (TryStrToFloat(FSSL, FReal) = True) and (FSSL <> '0') then
        begin
          if Trim(Order_Sub.fieldbyname('OrderUnit').AsString) = 'M' then
          begin
            FieldByName('TPQty').Value := Round(FieldByName('PRTOrderQty').AsFloat / StrToFloat(FSSL));
            FieldByName('TPUnit').Value := 'M';
          end
          else if Trim(Order_Sub.fieldbyname('OrderUnit').AsString) = 'Y' then
          begin
            FieldByName('TPQty').Value := Round(FieldByName('PRTOrderQty').AsFloat * 0.9144 / StrToFloat(FSSL));
            FieldByName('TPUnit').Value := 'M';
          end;
        end
        else
        begin
          FieldByName('TPPS').Value := Null;
          FieldByName('TPQty').Value := Null;
          FieldByName('TPUnit').Value := Null;
        end;
        Post;
        Next;
      end;
    end;
    Order_Sub.EnableControls;
  end
  else if Trim(BPBigType.Text) = '针织' then
  begin
    if StrToFloatdef(FXS, 0) = 0 then
      Exit;
    if (Trim(Order_Sub.fieldbyname('OrderUnit').AsString) = 'Kg') or (Trim(Order_Sub.fieldbyname('OrderUnit').AsString) = 'KGS') then
    begin
      if FSSL <> '0' then
      begin
        with Order_Sub do
        begin
          First;
          while not Eof do
          begin
            Edit;
            if (TryStrToFloat(FSSL, FReal) = True) and (TryStrToFloat(MPiZhong.Text, FReal) = True) and (StrToFloat(MPiZhong.Text) > 0) and (FXS <> '0') then
            begin
              FieldByName('TPPS').Value := Round(FieldByName('PRTOrderQty').Value / (StrToFloat(MPiZhong.Text) * StrToFloat(FSSL)));
              FieldByName('TPQty').Value := Round(FieldByName('PRTOrderQty').Value / (StrToFloat(MPiZhong.Text) * StrToFloat(FSSL))) * StrToFloat(MPiZhong.Text);
            end
            else
            begin
              FieldByName('TPPS').Value := Null;
              FieldByName('TPQty').Value := Null;
            end;
            Post;
            Next;
          end;
        end;
        if (TryStrToFloat(FSSL, FReal) = True) and (TryStrToFloat(FXS, FReal) = True) and (FXS <> '0') then
        begin
          YTPNum.Text := IntToStr(Round(StrToFloat(FQtyHZ) * StrToFloat(FXS) * 1.00 / (StrToFloat(FSSL))));
        end
        else
        begin
          YTPNum.Text := '';
        end;
      end
      else
      begin
        YTPNum.Text := '';
      end;
    end;
    if Trim(Order_Sub.fieldbyname('OrderUnit').AsString) = 'M' then
    begin
      if FSSL <> '0' then
      begin
        with Order_Sub do
        begin
          First;
          while not Eof do
          begin
            Edit;
            if (TryStrToFloat(FSSL, FReal) = True) and (TryStrToFloat(MPiZhong.Text, FReal) = True) and (StrToFloat(MPiZhong.Text) > 0) and (FXS <> '0') then
            begin
              FieldByName('TPPS').Value := Round(FieldByName('PRTOrderQty').Value / StrToFloat(FXS) / (StrToFloat(MPiZhong.Text) * StrToFloat(FSSL)));
              FieldByName('TPQty').Value := Round(FieldByName('PRTOrderQty').Value / StrToFloat(FXS) / (StrToFloat(MPiZhong.Text) * StrToFloat(FSSL))) * StrToFloat(MPiZhong.Text);
            end
            else
            begin
              FieldByName('TPPS').Value := Null;
              FieldByName('TPQty').Value := Null;
            end;
            Post;
            Next;
          end;
        end;
        if (TryStrToFloat(FSSL, FReal) = True) and (TryStrToFloat(FXS, FReal) = True) and (FXS <> '0') then
        begin
          YTPNum.Text := IntToStr(Round(StrToFloat(FQtyHZ) * StrToFloat(FXS) * 1.00 / (StrToFloat(FSSL))));
        end
        else
        begin
          YTPNum.Text := '';
        end;
      end
      else
      begin
        YTPNum.Text := '';
      end;
    end;
    if Trim(Order_Sub.fieldbyname('OrderUnit').AsString) = 'Y' then
    begin
      if FSSL <> '0' then
      begin
        with Order_Sub do
        begin
          First;
          while not Eof do
          begin
            Edit;
            if (TryStrToFloat(FSSL, FReal) = True) and (TryStrToFloat(MPiZhong.Text, FReal) = True) and (StrToFloat(MPiZhong.Text) > 0) and (FXS <> '0') then
            begin
              FieldByName('TPPS').Value := Round(FieldByName('PRTOrderQty').Value * 0.9144 / StrToFloat(FXS) / (StrToFloat(MPiZhong.Text) * StrToFloat(FSSL)));
              FieldByName('TPQty').Value := Round(FieldByName('PRTOrderQty').Value * 0.9144 / StrToFloat(FXS) / (StrToFloat(MPiZhong.Text) * StrToFloat(FSSL))) * StrToFloat(MPiZhong.Text);
            end
            else
            begin
              FieldByName('TPPS').Value := Null;
              FieldByName('TPQty').Value := Null;
            end;
            Post;
            Next;
          end;
        end;
        if (TryStrToFloat(FSSL, FReal) = True) and (TryStrToFloat(FXS, FReal) = True) and (FXS <> '0') then
        begin
          YTPNum.Text := IntToStr(Round(StrToFloat(FQtyHZ) * StrToFloat(FXS) * 0.9144 / (StrToFloat(FSSL))));
        end
        else
        begin
          YTPNum.Text := '';
        end;
      end
      else
      begin
        YTPNum.Text := '';
      end;
    end;
  end;

end;

procedure TfrmOrderInPut.OpenLabel();
begin
  with ADOQueryLabel do
  begin
    close;
    sql.Clear;
    sql.Add('select * from P_Label');
    sql.Add('where valid=''Y''');
    sql.Add('and labelCaption=' + quotedstr(trim(LBName.Text)));
    Open;
  end;
  if ADOQueryLabel.IsEmpty then
    exit;
  with RMGridReport1 do
  begin
    LoadFromBlobField(tblobfield(ADOQueryLabel.fieldbyname('labelFile')));
    //Preview :=RMPreview1;
    ShowReport;
  end;
end;

function TfrmOrderInPut.getOrderNo(fconNo: string): string;
var
  str1: string;
  i: integer;
begin
  str1 := trim(fconNo) + '01';
  with ADOTemp do
  begin
    close;
    sql.Clear;
    sql.Add('select MainID from JYOrder_Main where orderNo=' + quotedstr(trim(str1)));
    open;
  end;
  if not ADOTemp.IsEmpty then
  begin
    for i := 1 to 99 do
    begin
      str1 := trim(fconNo) + rightstr(inttostr(100 + i), 2);
      with ADOCmd do
      begin
        close;
        sql.Clear;
        sql.Add('select MainID from JYOrder_Main where orderNo=' + quotedstr(trim(str1)));
        open;
      end;
      if ADOCmd.IsEmpty then
        break;
    end;
  end;
  result := str1;
end;

procedure TfrmOrderInPut.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('指示单录入AA', Tv1, '生产指示单管理9');
  Close;

end;

procedure TfrmOrderInPut.PDCP();
begin
  with ADOTemp do
  begin
    Close;
    SQL.Clear;
    SQL.Add('SELECT * FROM CP_YDang A WHERE A.CYNO=' + QuotedStr(Trim(MPRTCODE.Text)));
    Open;
  end;
  if ADOTemp.FieldByName('BSBJ').AsString = '1' then
  begin
    if ADOTemp.FieldByName('xxnote2').AsString <> '' then
    begin
       Application.MessageBox(PChar(ADOTemp.FieldByName('xxnote2').AsString), '提示', 0);
    end
    else
    begin
             Application.MessageBox('此编号重要内容修改过，请确认后使用！', '提示', 0);
    end;


  end;
end;

procedure TfrmOrderInPut.InitData();
var
  FDate: TDateTime;
begin
  FDate := SGetServerDateTime(ADOTemp);
  OrdDate.DateTime := FDate;
  DlyDate.DateTime := FDate;
  ZGData.DateTime := FDate;
  CYData.DateTime := FDate;
  jhwcDate.DateTime := FDate;
  if PState = 1 then
    OrderNo.Enabled := False;
  with ADOTemp do
  begin
    Close;
    SQL.Clear;
    sql.Add(' select * from JYOrder_Sub where 1=1 ');

    if PState = 1 then
    begin
      sql.Add(' and MainId=''' + Trim(FMainId) + '''');
    end;
    if PState = 0 then
    begin
      sql.Add(' and 1<>1');
    end;

    Open;
  end;
  SCreateCDS20(ADOTemp, Order_Sub);
  SInitCDSData20(ADOTemp, Order_Sub);
  with ADOTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrder_Main where MainId=''' + Trim(FMainId) + '''');
    Open;
  end;

  SCSHDataNew(ADOTemp, ScrollBox1, 2);
  CXSHSTATUS.Text := ADOTemp.FieldByName('CXSHSTATUS').AsString;
  STATUS.Text := ADOTemp.FieldByName('STATUS').AsString;
  xgnote.Text := ADOTemp.FieldByName('xgnote').AsString;
  FILLER.Text := ADOTemp.FieldByName('FILLER').AsString;

  if ADOTemp.fieldbyname('HYTT').AsString <> '' then
  begin
    v1Column3.Caption := ADOTemp.fieldbyname('HYTT').AsString;
  end
  else
  begin
    v1Column3.Caption := '海运';
  end;
  if ADOTemp.fieldbyname('KYTT').AsString <> '' then
  begin
    v1Column13.Caption := ADOTemp.fieldbyname('kYTT').AsString;
  end
  else
  begin
    v1Column13.Caption := '空运';
  end;
  if (ADOTemp.FieldByName('STATUS').AsString = '1') and (CopyInt <> 99) then
  begin
    LLXS.ReadOnly := True;
    MPiZhong.ReadOnly := True;
    SSL.ReadOnly := True;
    YTPNum.ReadOnly := True;
    MPRTMF.ReadOnly := True;
    MPRTKZ.ReadOnly := True;

    v1PRTOrderQty.Editing := False;
    v1Column6.Options.Editing := False;
    v1Column7.Options.Editing := False;
  end;

  with ADOTemp do
  begin
    Close;
    SQL.Clear;
    sql.Add(' select * from JYOrder_Fact where 1=1 ');
    if PState = 1 then
    begin
      sql.Add(' and MainId=''' + Trim(FMainId) + '''');
    end;
    if PState = 0 then
    begin
      sql.Add(' and 1<>1');
    end;
    Open;
  end;
  SCreateCDS20(ADOTemp, CDS_Fact);
  SInitCDSData20(ADOTemp, CDS_Fact);

  if PState = 0 then
  begin
    OrdDate.DateTime := SGetServerDateTime(ADOTemp);
    DlyDate.DateTime := OrdDate.DateTime;
  end
  else
  begin
  end;
  if CopyInt = 99 then
  begin
    PState := 0;
    FMainId := '';
    OrderNo.Text := '';
    OrderNo.Enabled := True;
    ConNo.Text := '';
    ConNo.Enabled := True;
    OrdDate.DateTime := FDate;
    YTPNum.Text := '';
    Label_Juan.Text := '';
    Label_Bao.Text := '';
    LBName.Text := '';
   // PBFactoryName.Text := '';
    MPRTMF.ReadOnly := False;
    MPRTKZ.ReadOnly := False;

//    LLXS.Text := '';
//    MPiZhong.Text := '';
//    SSL.Text := '';
    with Order_Sub do
    begin
      First;
      while not Eof do
      begin
        Edit;
        FieldByName('MainId').Value := '';
        FieldByName('SubId').Value := '';
        FieldByName('hxFile').Value := '';
        FieldByName('TPQty').Value := 0;
        FieldByName('TPPS').Value := 0;
        Post;
        Next;
      end;
      PDCP();
    end;
//    CDS_Fact.EmptyDataSet;
    with CDS_Fact do
    begin
      First;
      while not Eof do
      begin
        Edit;
        FieldByName('FACTID').Value := '';

        Post;
        Next;
      end;
    end;
  end;

  OpenLabel();
end;

procedure TfrmOrderInPut.ZDYHelp(FButn: TcxButtonEdit; LType: string);
var
  FType, ZDYName, FText: string;
begin
end;

procedure TfrmOrderInPut.FormShow(Sender: TObject);
var
  i: Integer;
begin
  readCxGrid('指示单录入AA', Tv1, '生产指示单管理9');

  OrderNo.Text := '';
  if PState = 1 then
  begin

  end;
  fFlileFlag := UserDataFlag + 'HX';
  InitData();
  if PXGQX = '已审核' then
  begin
    cxGrid2.Enabled := False;
    MPRTKZ.Enabled := False;
    MPRTMF.Enabled := False;
    PBFactoryName.Enabled := False;
    MPiZhong.Enabled := False;
    YTPNum.Enabled := False;
    LLXS.Enabled := False;
    SSL.Enabled := False;
    MPRTCodeName.Enabled := False;
    QtyNote.Enabled := False;
    OrdDate.Enabled := False;
    v1PRTColor.Options.Editing := False;
    v1Column6.Options.Editing := False;
    v1Column7.Options.Editing := False;
    v1Column8.Options.Editing := False;

  end;
  if DDTYPE.Text = '匹样单' then
  begin
    ToolButton1.Visible := True;
    ToolButton4.Visible := false;
    MPRTCode.Enabled := True;
  end;

  GetLLXS();
end;

function TfrmOrderInPut.SaveData(): Boolean;
var
  maxno, Smaxno, maxorderno, MaxFNo: string;
begin
  try
    ADOCmd.Connection.BeginTrans;
    ///保存主表
    if Trim(FMainId) = '' then
    begin
      if GetLSNo(ADOCmd, maxno, 'JM', 'JYOrder_Main', 3, 1) = False then
      begin
        ADOCmd.Connection.RollbackTrans;
        Application.MessageBox('取最大号失败!', '提示', 0);
        Exit;
      end;
//      if GetLSNo(ADOCmd, maxorderno, 'RT', 'JYOrder_Main', 3, 1) = False then
//      begin
//        ADOCmd.Connection.RollbackTrans;
//        Application.MessageBox('取最大号失败!', '提示', 0);
//        Exit;
//      end;
//      OrderNo.Text := TRIM(maxorderno);
//      OrderNo.Text:=getOrderNo(trim(conNo.Text));
    end
    else
    begin
      maxno := Trim(FMainId);
    end;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      SQL.Add('select * from JYOrder_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);
      if str <> '' then
      begin
        FieldByName('XGNOTE').Value := Trim(STR);
      end;

      FieldByName('SCXDH').Value := FSCXDH;

      if (FSCXDH = '首次下印花大货') or (FSCXDH = '首次下数码印花大货') then
      begin

        FieldByName('YHLYNOTE').Value := '只要手感最好的一个花型，设计部8米（16套挂钩+5米）';
      end;

      SSetsaveSqlNew(ADOCmd, 'JYOrder_Main', ScrollBox1, 2);

      if (Trim(MPRTCodeName.Text) = '') and (Trim(MPRTCode.Text) <> '') then
      begin
        FieldByName('MPRTCodeName').Value := Trim(MPRTCode.Text);
      end;
      FieldByName('JHGZ').Value := '按缸排序';
      FieldByName('YXJL').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;
//      if jhgz.Text = '' then
//      begin
//        FieldByName('jhgz').Value := '按缸生成';
//      end;

      Post;
    end;

    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from JYOrder_Main where orderno=''' + Trim(OrderNo.Text) + '''');
      Open;
    end;
    if ADOCmd.RecordCount > 1 then
    begin
      ADOCmd.Connection.RollbackTrans;
      Application.MessageBox('订单号重复!', '提示', 0);
      Exit;
    end;
    ///保存子表
    with Order_Sub do
    begin
      First;
      while not Eof do
      begin
        if Trim(Order_Sub.fieldbyname('SubId').AsString) = '' then
        begin
          if GetLSNo(ADOCmd, Smaxno, 'JS', 'JYOrder_Sub', 4, 1) = False then
          begin
            ADOCmd.Connection.RollbackTrans;
            Application.MessageBox('取子流水号失败！', '提示', 0);
            Exit;
          end;
        end
        else
        begin
          Smaxno := Trim(Order_Sub.fieldbyname('SubId').AsString);
        end;
        with ADOCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from JYOrder_Sub where MainId=''' + Trim(maxno) + '''');
          sql.Add(' and SubId=''' + Trim(Smaxno) + '''');
          Open;
        end;
        with ADOCmd do
        begin
          if Trim(Order_Sub.fieldbyname('SubId').AsString) = '' then
            Append
          else
            Edit;

          if Trim(Order_Sub.fieldbyname('SubId').AsString) <> '' then
          begin
            with ADOQuery1 do
            begin
              Close;
              SQL.Clear;
              sql.Add('select * from JYOrder_Sub where MainId=''' + Trim(maxno) + '''');
              sql.Add(' and SubId=''' + Trim(Smaxno) + '''');
              Open;
            end;
            if Order_Sub.fieldbyname('PRTOrderQty').Value <> ADOQuery1.fieldbyname('PRTOrderQty').Value then
            begin
              with ADOTemp do
              begin
                Close;
                SQL.Clear;
                sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
                sql.Add(' ' + quotedstr(trim(DName)));
                sql.Add(',getdate() ');
                sql.Add(',' + quotedstr(trim(self.Caption)));
                sql.Add(',' + quotedstr(trim('数量修改')));
                sql.Add(',' + quotedstr(trim('子表ID：' + trim(Smaxno) + ';原数量:' + ADOQuery1.fieldbyname('PRTOrderQty').AsString + ';现数量:' + Order_Sub.fieldbyname('PRTOrderQty').AsString)));
                sql.Add(',' + quotedstr(trim('成功')));
                sql.Add(')');
                ExecSQL;

              end;

            end;
          end;
          FieldByName('MainId').Value := Trim(maxno);
          FieldByName('SubId').Value := Trim(Smaxno);

          RTSetSaveDataCDS(ADOCmd, Tv1, Order_Sub, 'JYOrder_Sub', 0);
          FieldByName('MGMainId').Value := Trim(Order_Sub.fieldbyname('MGMainId').AsString);
          FieldByName('ConSubId').Value := Trim(Order_Sub.fieldbyname('ConSubId').AsString);
          Post;
          with Order_Sub do
          begin
            Edit;
            fieldbyname('SubId').Value := Trim(Smaxno);
            Post;
          end;

        end;
        Next;
      end;
    end;
/////////////////////               保存加工厂            ///////////////////////////
    with CDS_Fact do
    begin
      First;
      while not Eof do
      begin
        if Trim(CDS_Fact.fieldbyname('FactId').AsString) = '' then
        begin
          if GetLSNo(ADOCmd, MaxFNo, 'JG', 'JYOrder_Fact', 4, 1) = False then
          begin
            ADOCmd.Connection.RollbackTrans;
            Application.MessageBox('取子流水号失败！', '提示', 0);
            Exit;
          end;
        end
        else
        begin
          MaxFNo := Trim(CDS_Fact.fieldbyname('FactId').AsString);
        end;
        with ADOCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from JYOrder_Fact where  FactId=''' + Trim(MaxFNo) + '''');
          Open;
        end;
        with ADOCmd do
        begin
          if Trim(CDS_Fact.fieldbyname('FactId').AsString) = '' then
            Append
          else
            Edit;
          FieldByName('MainId').Value := Trim(maxno);
          FieldByName('FactId').Value := Trim(MaxFNo);
          RTSetSaveDataCDS(ADOCmd, Tv2, CDS_Fact, 'JYOrder_Fact', 0);
          Post;
        end;

        CDS_Fact.Edit;
        CDS_Fact.FieldByName('FactId').Value := Trim(MaxFNo);

        Next;
      end;
    end;

    with ADOCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('update JYOrder_Main set  ');
      sql.Add('JGFactoryName=(select top 1  SJGFactory from JYOrder_Fact X where X.MainId=JYOrder_Main.MainId order by SJGXH)');
      sql.Add(' where  MainId=''' + Trim(maxno) + '''');

      sql.Add('update XH_Cloth_DH set  ');
      sql.Add('DQFactoryName=(select top 1  SJGFactory from JYOrder_Fact X where X.MainId=XH_Cloth_DH.MainId order by SJGXH)');
      sql.Add(' where  MainId=''' + Trim(maxno) + '''');
      ExecSQL;
    end;

    FMainId := Trim(maxno);
/////////////////////               保存加工厂            ///////////////////////////
    ADOCmd.Connection.CommitTrans;
    Result := True;
  except
    Result := False;
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！', '提示', 0);
  end;
end;

procedure TfrmOrderInPut.TBSaveClick(Sender: TObject);
var
  MAXNO1: string;
begin
  if PState <> 1 then
  begin
    ToolBar1.SetFocus;
  end;
  if trim(DDTYPE.Text) <> '匹样单' then
  begin
    if Trim(CONNO.Text) = '' then
    begin
      Application.MessageBox('正常单合同号不能为空！', '提示', 0);
      Exit;
    end;
  end;
  if Trim(OrderNo.Text) = '' then
  begin
    Application.MessageBox('订单号不能为空！', '提示', 0);
    Exit;
  end;
  if (JGType.Text = '印花') then
  begin
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from JYOrder_Main where ltrim(rtrim(MPRTCode))=''' + Trim(MPRTCode.Text) + '''');
      sql.Add('and isnull(jgtype,'''') =  ''印花'' AND isnull(DDTYPE,'''')<>''匹样单''');
      SQL.Add('AND ORDERNO<>''' + Trim(OrderNo.Text) + '''');
      Open;
    end;
    if ADOCmd.IsEmpty then
    begin
      FSCXDH := '首次下印花大货';
    end
    else
    begin
      FSCXDH := '';
    end;
  end
  else if (JGType.Text = '数码印花') then
  begin
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from JYOrder_Main where ltrim(rtrim(MPRTCode))=''' + Trim(MPRTCode.Text) + '''');
      sql.Add('and isnull(jgtype,'''') =  ''数码印花'' AND isnull(DDTYPE,'''')<>''匹样单''');
      SQL.Add('AND ORDERNO<>''' + Trim(OrderNo.Text) + '''');
      Open;
    end;
    if ADOCmd.IsEmpty then
    begin
      FSCXDH := '首次下数码印花大货';
    end
    else
    begin
      FSCXDH := '';
    end;
  end
  else if (JGType.Text = '染色') then
  begin
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from JYOrder_Main where ltrim(rtrim(MPRTCode))=''' + Trim(MPRTCode.Text) + '''');
      sql.Add('and isnull(jgtype,'''') like  ''%染色%''  AND isnull(DDTYPE,'''')<>''匹样单'' ');
      SQL.Add('AND ORDERNO<>''' + Trim(OrderNo.Text) + '''');
      Open;
    end;
    if ADOCmd.IsEmpty then
    begin
      FSCXDH := '首次下染色大货';
    end
    else
    begin
      FSCXDH := '';
    end;
  end
  else
  begin
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from JYOrder_Main where ltrim(rtrim(MPRTCode))=''' + Trim(MPRTCode.Text) + '''   AND isnull(DDTYPE,'''')<>''匹样单''');
      SQL.Add('AND ORDERNO<>''' + Trim(OrderNo.Text) + '''');
      Open;
    end;
    if ADOCmd.IsEmpty then
    begin
      FSCXDH := '首次下大货';
    end
    else
    begin
      FSCXDH := '';
    end;
  end;

  with Order_Sub do
  begin
    First;
    while not Eof do
    begin
      with ADOTemp do
      begin
        Close;
        SQL.Clear;
        sql.Add('SELECT ISSD=[dbo].[F_Mg_Judge_SD](' + quotedstr(CustomerNoName.Text) + ',' + quotedstr(Order_Sub.FIELDBYNAME('PRTHX').AsString));
        sql.Add(') ');

        Open;
      end;
      if ADOTemp.FieldByName('ISSD').AsString = '已锁定' then
      begin
        if Application.MessageBox(pchar('花型 ' + trim(Order_Sub.FIELDBYNAME('PRTHX').AsString) + ' 已锁定，确定继续吗？'), '提示', 32 + 4) <> IDYES then
          exit;
      end;
      Next;
    end;
  end;

  
//  if Trim(conNo.Text) = '' then
//  begin
//    Application.MessageBox('合同号不能为空！', '提示', 0);
//    Exit;
//  end;
  {if Trim(JGFactoryName.Text) = '' then
  begin
    Application.MessageBox('加工厂不能为空！', '提示', 0);
    Exit;
  end; }
  if Status.Text = '1' then
  begin
    if Trim(GDY.Text) = '' then
    begin
      Application.MessageBox('跟单员不能为空！', '提示', 0);
      Exit;
    end;
  end;
  if Trim(CustomerNoName.Text) = '' then
  begin
    Application.MessageBox('客户不能为空！', '提示', 0);
    Exit;
  end;
  if Trim(LabQty.Text) = '' then
  begin
    Application.MessageBox('标签份数不能为空！', '提示', 0);
    Exit;
  end;
  if Trim(BPBigType.Text) = '' then
  begin
    Application.MessageBox('产品大类不能为空！', '提示', 0);
    Exit;
  end;
  if Order_Sub.IsEmpty then
  begin
    Application.MessageBox('明细不能为空!', '提示', 0);
    Exit;
  end;

  if Order_Sub.Locate('PRTOrderQty', null, []) then
  begin
    Application.MessageBox('数量不能为空!', '提示', 0);
    Exit;
  end;
  if Order_Sub.Locate('TPPS', null, []) then
  begin
    Application.MessageBox('投匹匹数不能为空!', '提示', 0);
    Exit;
  end;
  if FMainId <> '' then
  begin
    if (FXGNOTE = '已修改') and (CXSHSTATUS.Text = '99') then
    begin
      if InputQuery('修改备注', '修改备注：', str) then
      begin

      end
      else
      begin
        Exit;
      end;

    end;
  end;
  if FMainId <> '' then
  begin
    if GetLSNo(ADOCmd, MAXNO1, 'BF', 'JYOrder_Main', 3, 1) = False then
    begin
//      ADOCmd.Connection.RollbackTrans;
      Application.MessageBox('取最大号失败!', '提示', 0);
      Exit;
    end;
    with ADOQuery1 do
    begin
      close;
      sql.Clear;
      sql.Add(' exec P_Do_ZSDBF2   ');
      sql.Add(' @mainid=''' + Trim(FMainId) + '''');
      sql.Add(',@BFID=' + quotedstr(Trim(MAXNO1)));
      sql.Add(',@DNAME=' + quotedstr(Trim(DName)));
      execsql;
    end;
  end;

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

procedure TfrmOrderInPut.v1PRTColorPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'OrdColor';
      flagname := '颜色';
      V1Name.Caption := '中文名称';
      V1Note.Caption := '英文名称';
      fnote := True;
      if ShowModal = 1 then
      begin
        Self.Order_Sub.Edit;
        Self.Order_Sub.FieldByName('PRTColor').Value := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        Self.Order_Sub.FieldByName('PRTColorNo').Value := Trim(ClientDataSet1.fieldbyname('Note').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut.ToolButton1Click(Sender: TObject);
var
  i: Integer;
begin
//  if Trim(OrderNo.Text)='' then
//  begin
//    Application.MessageBox('订单号不能为空!','提示',0);
//    Exit;
//  end;
  CopyAddRow(Tv1, Order_Sub);
  with Order_Sub do
  begin
    Edit;
//    FieldByName('PRTColor').Value := '';
//    FieldByName('PRTOrderQty').Value := null;
//    FieldByName('PRTColorNo').Value := null;
    FieldByName('hxFile').Value := '';
//    FieldByName('PRTOrderQty').Value := 0;
    FieldByName('TPPS').Value := 0;
    if BPBigType.Text = '针织' then
    begin
      FieldByName('TPUnit').Value := 'KG';
    end;
    if BPBigType.Text = '梭织' then
    begin
      FieldByName('TPUnit').Value := 'M';
    end;
//    FieldByName('OrderUnit').Value := 'Kg';
    Post;
  end;
  FXGNOTE := '已修改';
end;

procedure TfrmOrderInPut.ToolButton2Click(Sender: TObject);
begin
  if Order_Sub.IsEmpty then
    Exit;
  if Order_Sub.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;
  if Application.MessageBox('确定要删除选择的数据吗？', '提示', 32 + 4) <> IDYES then
    exit;
  Order_Sub.DisableControls;
  with Order_Sub do
  begin
    First;
    while Locate('SSel', True, []) do
    begin
      with ADOTemp do
      begin
        Close;
        sql.Clear;
        sql.Add('select * from WFB_MJJY where SubId=''' + Trim(Order_Sub.fieldbyname('SubId').AsString) + '''');
        Open;
      end;
      if ADOTemp.IsEmpty = False then
      begin
        Application.MessageBox('已检验不能删除数据!', '提示', 0);
        Exit;
      end;
      if Trim(Order_Sub.fieldbyname('SubId').AsString) <> '' then
      begin
        with ADOCmd do
        begin
          Close;
          sql.Clear;

          sql.Add('insert into JYOrder_Sub_Del select * from JYOrder_Sub where SubId=''' + Trim(Order_Sub.fieldbyname('SubId').AsString) + '''');

          sql.Add('delete JYOrder_Sub where SubId=''' + Trim(Order_Sub.fieldbyname('SubId').AsString) + '''');

          ExecSQL;
        end;
      end;
      Delete;
    end;
  end;
  Order_Sub.EnableControls;

  FXGNOTE := '已修改';
end;

procedure TfrmOrderInPut.JGFactoryNameBtnUpClick(Sender: TObject);
begin
  try
    frmZdyAttachGYS := TfrmZdyAttachGYS.Create(Application);
    with frmZdyAttachGYS do
    begin
//      frmZdyAttachGYS.FactType.ItemIndex:=FactType.Items.IndexOf('加工厂');

      if ShowModal = 1 then
      begin
        JGFactoryName.Text := Trim(CDS_HZ.fieldbyname('CoName').AsString);
      end;
    end;
  finally
    frmZdyAttachGYS.Free;
  end;
end;

procedure TfrmOrderInPut.CustomerNoNameBtnUpClick(Sender: TObject);
begin
  try
    frmZdyAttachment := TfrmZdyAttachment.Create(Application);
    with frmZdyAttachment do
    begin
 
//      IF self.canshu1<>'高权限' then canshu1:='业务员';
      if ShowModal = 1 then
      begin
        CustomerNoName.Text := Trim(CDS_HZ.fieldbyname('CoName').AsString);
        CustomerNoName.TxtCode := Trim(CDS_HZ.fieldbyname('CoCode').AsString);
      end;
    end;
  finally
    frmZdyAttachment.Free;
  end;
end;

procedure TfrmOrderInPut.CustomerNoNameBtnDnClick(Sender: TObject);
begin
  TBtnEditC(Sender).Text := '';
  TBtnEditC(Sender).TxtCode := '';
end;

procedure TfrmOrderInPut.MPRTCodeNameBtnUpClick(Sender: TObject);
begin
  frmCPManageSel := TfrmCPManageSel.Create(self);
  with frmCPManageSel do
  begin
    if showmodal = 1 then
    begin
      MPRTCode.Text := CDS_Main.fieldbyname('CYNo').asstring;
      MPRTCodeName.Text := CDS_Main.fieldbyname('CYName').asstring;
      MPRTSpec.Text := CDS_Main.fieldbyname('CYSpec').asstring;
      MPRTMF.Text := CDS_Main.fieldbyname('CYmf').asstring;
      MPRTKZ.Text := CDS_Main.fieldbyname('CYkz').asstring;
    end;
    free;
  end;
  tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmOrderInPut.v1OrderUnitPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
var
  mvalues: string;
begin
  mvalues := tv1.Columns[tv1.Controller.FocusedColumn.index].DataBinding.FieldName;
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'OrderUnit';
      flagname := '数量单位';
      if ShowModal = 1 then
      begin
        Self.Order_Sub.Edit;
        Self.Order_Sub.FieldByName(mvalues).Value := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut.v1PriceUnitPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'PriceUnit';
      flagname := '价格单位';
      if Trim(DParameters1) <> '高权限' then
      begin
        TBAdd.Visible := False;
        TBEdit.Visible := False;
        TBDel.Visible := False;
      end;

      if ShowModal = 1 then
      begin
        Self.Order_Sub.Edit;
        Self.Order_Sub.FieldByName('PriceUnit').Value := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut.OrdDefStr2BtnUpClick(Sender: TObject);
var
  fsj: string;
  FWZ: Integer;
begin
  fsj := Trim(TEdit(Sender).Hint);
  FWZ := Pos('/', fsj);
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := Copy(fsj, 1, FWZ - 1);
      flagname := Copy(fsj, FWZ + 1, Length(fsj) - FWZ);
      if Trim(flag) = 'OrdDefStr2' then
      begin
        V1Name.Caption := '中文名称';
        V1Note.Caption := '英文名称';
        fnote := True;
      end;
      if ShowModal = 1 then
      begin
        TEdit(Sender).Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        if Trim(flag) = 'MPRTCode' then
        begin
          with ADOTemp do
          begin
            Close;
            sql.Clear;
            sql.Add('select Top 1 * from JYOrder_Main where MPRTCode=''' + Trim(ClientDataSet1.fieldbyname('ZDYName').AsString) + '''');
            sql.Add(' order by FillTime desc');
            Open;
          end;
          MPRTCodeName.Text := ADOTemp.fieldbyname('MPRTCodeName').AsString;
          MPRTMF.Text := ADOTemp.fieldbyname('MPRTMF').AsString;
          MPRTKZ.Text := ADOTemp.fieldbyname('MPRTKZ').AsString;
          MPRTSpec.Text := ADOTemp.fieldbyname('MPRTSpec').AsString;
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

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

procedure TfrmOrderInPut.MPRTSCTeBieNoteBtnUpClick(Sender: TObject);
var
  fsj: string;
  FWZ: Integer;
begin
  fsj := Trim(TEdit(Sender).Hint);
  FWZ := Pos('/', fsj);
  try
    frmZDYHelpSel := TfrmZDYHelpSel.Create(Application);
    with frmZDYHelpSel do
    begin
      flag := Copy(fsj, 1, FWZ - 1);
      flagname := Copy(fsj, FWZ + 1, Length(fsj) - FWZ);
      if ShowModal = 1 then
      begin
        TEdit(Sender).Text := ReturnStr;
      end;
    end;
  finally
    frmZDYHelpSel.Free;
  end;
end;

procedure TfrmOrderInPut.MPRTBZNoteDblClick(Sender: TObject);
var
  fsj: string;
  FWZ: Integer;
  i: integer;
begin
  fsj := Trim(TMemo(Sender).Hint);
  FWZ := Pos('/', fsj);
  i := 0;
  try
    frmZDYHelpSel := TfrmZDYHelpSel.Create(Application);
    with frmZDYHelpSel do
    begin
      flag := Copy(fsj, 1, FWZ - 1);
      flagname := Copy(fsj, FWZ + 1, Length(fsj) - FWZ);
      if ShowModal = 1 then
      begin
        MPRTBZNote.Lines.Clear;
        with ClientDataSet1 do
        begin
          First;
          while not Eof do
          begin
            if FieldByName('SSel').AsBoolean = True then
            begin
              i := i + 1;
              MPRTBZNote.Lines.Add(inttostr(i) + '.' + FieldByName('ZDYName').AsString)
            end;
            Next;
          end;
        end;
      end;
    end;
  finally
    frmZDYHelpSel.Free;
  end;
end;

procedure TfrmOrderInPut.MPRTChuanYDblClick(Sender: TObject);
var
  fsj: string;
  FWZ: Integer;
  i: integer;
begin
  fsj := Trim(TMemo(Sender).Hint);
  FWZ := Pos('/', fsj);
  i := 0;
  try
    frmZDYHelpSel := TfrmZDYHelpSel.Create(Application);
    with frmZDYHelpSel do
    begin
      flag := Copy(fsj, 1, FWZ - 1);
      flagname := Copy(fsj, FWZ + 1, Length(fsj) - FWZ);
      if ShowModal = 1 then
      begin
        TMemo(Sender).Lines.Clear;
        with ClientDataSet1 do
        begin
          First;
          while not Eof do
          begin
            if FieldByName('SSel').AsBoolean = True then
            begin
              i := i + 1;
              TMemo(Sender).Lines.Add(inttostr(i) + '.' + FieldByName('ZDYName').AsString)
            end;
            Next;
          end;
        end;
      end;
    end;
  finally
    frmZDYHelpSel.Free;
  end;
end;

procedure TfrmOrderInPut.MPRTCodeBtnUpClick(Sender: TObject);
begin
  frmCPManageSel := TfrmCPManageSel.Create(self);
  with frmCPManageSel do
  begin
    if showmodal = 1 then
    begin
      MPRTCode.Text := CDS_Main.fieldbyname('CYNo').asstring;

      MPRTCodeName.Text := CDS_Main.fieldbyname('CYName').asstring;

      MPRTMF.Text := CDS_Main.fieldbyname('CYmf').asstring;

      MPRTKZ.Text := CDS_Main.fieldbyname('CYkz').asstring;

      MPRTSpec.Text := CDS_Main.fieldbyname('CYSpec').asstring;
      MPRTCF.Text := CDS_Main.fieldbyname('CYCF').asstring;
//      MPRTMF.Text := CDS_Main.fieldbyname('CYmf').asstring;
//      MPRTKZ.Text := CDS_Main.fieldbyname('CYkz').asstring;
    end;
    free;
  end;
  tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmOrderInPut.ToolButton3Click(Sender: TObject);
begin
  try
    frmLabelList := TfrmLabelList.Create(Application);
    with frmLabelList do
    begin
      if ShowModal = 1 then
      begin
        self.LBName.text := Trim(ADOQueryLabel.fieldbyname('labelCaption').AsString);
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('Update JYOrder_Main Set LBName=''' + Trim(ADOQueryLabel.fieldbyname('labelCaption').AsString) + '''');
          sql.Add(' where Mainid=''' + Trim(FMainId) + '''');
          ExecSQL;
        end;
      end;
    end;
  finally
    frmLabelList.Free;
  end;
  {try
    frmLabelList := TfrmLabelList.Create(Application);
    with frmLabelList do
    begin
      if ShowModal = 1 then
      begin
        self.LBName.text := Trim(ADOQueryLabel.fieldbyname('labelCaption').AsString);
      end;
    end;
  finally
    frmLabelList.Free;
  end; }
  OpenLabel();
end;

procedure TfrmOrderInPut.PBFactoryNameBtnUpClick(Sender: TObject);
begin
  try
    frmZdyAttachGYS := TfrmZdyAttachGYS.Create(Application);
    with frmZdyAttachGYS do
    begin
      frmZdyAttachGYS.FactType.ItemIndex := FactType.Items.IndexOf('坯布厂');
      if ShowModal = 1 then
      begin
        PBFactoryName.Text := Trim(CDS_HZ.fieldbyname('CoName').AsString);
      end;
    end;
  finally
    frmZdyAttachGYS.Free;
  end;
end;

procedure TfrmOrderInPut.ConNoBtnUpClick(Sender: TObject);
var
  FConMainId, FMPRTCode: string;
begin
  try
    frmContractListSel := TfrmContractListSel.Create(Application);
    with frmContractListSel do
    begin
      fconNo := trim(self.ConNo.Text);
      if ShowModal = 1 then
      begin
        Order_Main.locate('SSel', true, []);
        FConMainId := Trim(frmContractListSel.Order_Main.fieldbyname('MainId').AsString);
        if Trim(ywy.Text) = '' then
        begin
          YWY.Text := Trim(frmContractListSel.Order_Main.fieldbyname('Salesman').AsString);
        end;

        FMPRTCode := Trim(frmContractListSel.Order_Main.fieldbyname('SCSCode').AsString);
        self.ConNo.Text := Trim(frmContractListSel.Order_Main.fieldbyname('ConNo').AsString);
        self.KHConNo.Text := Trim(frmContractListSel.Order_Main.fieldbyname('BuyConNo').AsString);
        self.CustomerNoName.Text := Trim(frmContractListSel.Order_Main.fieldbyname('BuyName').AsString);
        self.CustomerNoName.TxtCode := Trim(frmContractListSel.Order_Main.fieldbyname('BuyNo').AsString);

        self.MPRTCode.Text := trim(frmContractListSel.Order_Main.Fieldbyname('SCSCode').AsString);

        self.MPRTCodeName.Text := trim(frmContractListSel.Order_Main.Fieldbyname('SCSName').AsString);
        self.MPRTMF.Text := trim(frmContractListSel.Order_Main.Fieldbyname('SCSMF').AsString);
        self.MPRTKZ.Text := trim(frmContractListSel.Order_Main.Fieldbyname('SCSKZ').AsString);

        self.MPRTSpec.Text := trim(frmContractListSel.Order_Main.Fieldbyname('SCSSpec').AsString);
        self.MPRTCF.Text := trim(frmContractListSel.Order_Main.Fieldbyname('SCSCF').AsString);

        KHCPName.Text := trim(frmContractListSel.Order_Main.Fieldbyname('SCSENAME').AsString);
        while Order_Main.locate('SSel', true, []) do
        begin
          if FConMainId <> trim(frmContractListSel.Order_Main.Fieldbyname('MainId').AsString) then
          begin
            Application.MessageBox('不能选择多个合同！', '提示', 0);
            break;
          end;
          if self.MPRTCode.Text <> trim(frmContractListSel.Order_Main.Fieldbyname('SCSCode').AsString) then
          begin
            Application.MessageBox('不能选择多个产品！', '提示', 0);
            break;
          end;
          if self.MPRTMF.Text <> trim(frmContractListSel.Order_Main.Fieldbyname('SCSMF').AsString) then
          begin
            Application.MessageBox('不能选择多个产品！', '提示', 0);
            break;
          end;
          if self.MPRTKZ.Text <> trim(frmContractListSel.Order_Main.Fieldbyname('SCSKZ').AsString) then
          begin
            Application.MessageBox('不能选择多个产品！', '提示', 0);
            break;
          end;
          if self.Order_Sub.locate('ConSubId', trim(Order_Main.Fieldbyname('SubId').AsString), []) then
          begin
            Order_Main.Edit;
            Order_Main.fieldbyname('SSel').value := false;
            continue;
          end;
          with self.Order_Sub do
          begin
            append;
            Fieldbyname('PRTKuanNO').value := trim(frmContractListSel.Order_Main.Fieldbyname('SCSKX').AsString);
            Fieldbyname('PRTKuanNO').value := trim(frmContractListSel.Order_Main.Fieldbyname('SCSKX').AsString);
            Fieldbyname('PRTHXKH').value := trim(frmContractListSel.Order_Main.Fieldbyname('SCSKHHH').AsString);
            Fieldbyname('PRTEColor').value := trim(frmContractListSel.Order_Main.Fieldbyname('SCSEColor').AsString);
            Fieldbyname('PrtColorNo').value := trim(frmContractListSel.Order_Main.Fieldbyname('SCSColorNo').AsString);
            Fieldbyname('PrtColor').value := trim(frmContractListSel.Order_Main.Fieldbyname('SCSColor').AsString);
            Fieldbyname('PRTHX').value := trim(frmContractListSel.Order_Main.Fieldbyname('SCSHX').AsString);
            Fieldbyname('PRTOrderQty').value := frmContractListSel.Order_Main.Fieldbyname('SCSQty').AsFloat;
            Fieldbyname('OrderUnit').value := trim(frmContractListSel.Order_Main.Fieldbyname('SCSUnit').AsString);
            Fieldbyname('SubNote').value := trim(frmContractListSel.Order_Main.Fieldbyname('SCSNote').AsString);
            Fieldbyname('ConSubId').value := trim(frmContractListSel.Order_Main.Fieldbyname('SubId').AsString);
            FieldByName('hxFile').Value := '';
            FieldByName('TPPS').Value := 0;
            FieldByName('TPQty').Value := 0;
          end;
          Order_Main.Edit;
          Order_Main.fieldbyname('SSel').value := false;
        end;

      end;
    end;
  finally
    frmContractListSel.Free;
  end;
  GetLLXS();
  PDCP();
end;

procedure TfrmOrderInPut.ToolButton5Click(Sender: TObject);
var
  fPrintFile: string;
  Txt, fImagePath: string;
  Moudle: THandle;
  Makebar: TMakebar;
  Mixtext: TMixtext;
begin
  if Trim(FMainId) = '' then
    exit;
  if trim(LBName.Text) = '' then
    exit;
  with ADOTemp do
  begin
    Close;
    SQL.Clear;
    sql.Add('exec P_Print_Cs_Roll ');
    sql.Add('@mainID=''' + trim(FMainId) + ''' ');
    Open;
  end;
  SCreateCDS20(ADOTemp, CDS_PRT);
  SInitCDSData20(ADOTemp, CDS_PRT);

  try
    Moudle := LoadLibrary('MakeQRBarcode.dll');
    @Makebar := GetProcAddress(Moudle, 'Make');
    @Mixtext := GetProcAddress(Moudle, 'MixText');
    Txt := Trim(ADOTemp.fieldbyname('MJID').AsString);
//    Txt := '123';
    fImagePath := ExtractFilePath(Application.ExeName) + 'image\temp.bmp';
    if not DirectoryExists(pchar(ExtractFilePath(Application.ExeName) + 'image')) then
      CreateDirectory(pchar(ExtractFilePath(Application.ExeName) + 'image'), nil);
    if FileExists(fImagePath) then
      DeleteFile(fImagePath);
    Makebar(pchar(Txt), Length(Txt), 3, 3, 0, PChar(fImagePath), 3);
  except
    application.MessageBox('条形码生成失败！', '提示信息', MB_ICONERROR);
    exit;
  end;
  ExportFtErpFile(Trim(LBName.Text) + '.rmf', ADOTemp);
  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\' + Trim(LBName.Text) + '.rmf';
  if FileExists(fPrintFile) then
  begin
    RMVariables['QRBARCODE'] := fImagePath;
    RM1.LoadFromFile(fPrintFile);
    PostFileToData(trim(LBName.TEXT), fPrintFile);
    UPLabel(trim(LBName.TEXT), fPrintFile);
    RM1.ShowReport;
  end
  else
  begin
    Application.MessageBox(PChar('没有找到' + trim(fPrintFile)), '提示信息', 0);
  end;
end;

procedure TfrmOrderInPut.N2Click(Sender: TObject);
begin
  ToolButton2.Click;
end;

procedure TfrmOrderInPut.MPRTMFExit(Sender: TObject);
begin
  GetLLXS();
end;

procedure TfrmOrderInPut.MPRTKZExit(Sender: TObject);
begin
  GetLLXS();
end;

procedure TfrmOrderInPut.LLXSExit(Sender: TObject);
begin
  GetYTPS();
end;

procedure TfrmOrderInPut.MPiZhongExit(Sender: TObject);
begin
  GetYTPS();
end;

procedure TfrmOrderInPut.SSLExit(Sender: TObject);
begin
  GetYTPS();
end;

procedure TfrmOrderInPut.ScrollBox1Click(Sender: TObject);
begin
  ToolBar1.SetFocus;
end;

procedure TfrmOrderInPut.ToolButton6Click(Sender: TObject);
begin
  if Order_Sub.IsEmpty then
    Exit;
  if Order_Sub.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;
  if Application.MessageBox('确定要复制选择的数据吗？', '提示', 32 + 4) <> IDYES then
    exit;
  with ADOTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrder_Sub where 1=2');
    Open;
  end;
  SCreateCDS20(ADOTemp, CDS_Copy);
  SInitCDSData20(ADOTemp, CDS_Copy);
  Order_Sub.DisableControls;
  with Order_Sub do
  begin
    First;
    while not Eof do
    begin
      if FieldByName('SSel').AsBoolean = True then
      begin
        with CDS_Copy do
        begin
          Append;
          CDS_Copy.FieldByName('PRTColor').Value := Order_Sub.FieldByName('PRTColor').Value;
          CDS_Copy.FieldByName('PRTColorNo').Value := Order_Sub.FieldByName('PRTColorNo').Value;
          CDS_Copy.FieldByName('PRTHX').Value := Order_Sub.FieldByName('PRTHX').Value;
          CDS_Copy.FieldByName('PRTEColor').Value := Order_Sub.FieldByName('PRTEColor').Value;
          CDS_Copy.FieldByName('PRTPs').Value := Order_Sub.FieldByName('PRTPs').Value;
          CDS_Copy.FieldByName('PRTOrderQty').Value := Order_Sub.FieldByName('PRTOrderQty').Value;
          CDS_Copy.FieldByName('OrderUnit').Value := Order_Sub.FieldByName('OrderUnit').Value;
          CDS_Copy.FieldByName('SubNote').Value := Order_Sub.FieldByName('SubNote').Value;
          CDS_Copy.FieldByName('TPPS').Value := Order_Sub.FieldByName('TPPS').Value;
          CDS_Copy.FieldByName('TPQty').Value := Order_Sub.FieldByName('TPQty').Value;
          CDS_Copy.FieldByName('TPUnit').Value := Order_Sub.FieldByName('TPUnit').Value;
          CDS_Copy.FieldByName('PRTHXKH').Value := Order_Sub.FieldByName('PRTHXKH').Value;
          CDS_Copy.FieldByName('PRTColorNoKH').Value := Order_Sub.FieldByName('PRTColorNoKH').Value;
          Post;
        end;
      end;
      Next;
    end;
  end;
  Order_Sub.EnableControls;
  CDS_Copy.DisableControls;
  with CDS_Copy do
  begin
    First;
    while not Eof do
    begin
      with Order_Sub do
      begin
        Append;
        Order_Sub.FieldByName('PRTColor').Value := CDS_Copy.FieldByName('PRTColor').Value;
        Order_Sub.FieldByName('PRTColorNo').Value := CDS_Copy.FieldByName('PRTColorNo').Value;
        Order_Sub.FieldByName('PRTHX').Value := CDS_Copy.FieldByName('PRTHX').Value;
        Order_Sub.FieldByName('PRTEColor').Value := CDS_Copy.FieldByName('PRTEColor').Value;
        Order_Sub.FieldByName('PRTPs').Value := CDS_Copy.FieldByName('PRTPs').Value;
        Order_Sub.FieldByName('PRTOrderQty').Value := CDS_Copy.FieldByName('PRTOrderQty').Value;
        Order_Sub.FieldByName('OrderUnit').Value := CDS_Copy.FieldByName('OrderUnit').Value;
        Order_Sub.FieldByName('SubNote').Value := CDS_Copy.FieldByName('SubNote').Value;
        Order_Sub.FieldByName('TPPS').Value := CDS_Copy.FieldByName('TPPS').Value;
        Order_Sub.FieldByName('TPQty').Value := CDS_Copy.FieldByName('TPQty').Value;
        Order_Sub.FieldByName('TPUnit').Value := CDS_Copy.FieldByName('TPUnit').Value;
        Order_Sub.FieldByName('PRTHXKH').Value := CDS_Copy.FieldByName('PRTHXKH').Value;
        Order_Sub.FieldByName('PRTColorNoKH').Value := CDS_Copy.FieldByName('PRTColorNoKH').Value;
        Post;
      end;
      Next;
    end;
  end;
  CDS_Copy.EnableControls;
  FXGNOTE := '已修改';
end;

procedure TfrmOrderInPut.MenuItem1Click(Sender: TObject);
var
  i: Integer;
begin

  i := CDS_Fact.RecordCount;
  i := i + 1;

  with CDS_Fact do
  begin
    append;
    FieldByName('SJGXH').Value := i;
    FieldByName('SJGJQ').Value := trim(FormatDateTime('yyyy-MM-dd', OrdDate.Date + 6));
    Post;
  end;
end;

procedure TfrmOrderInPut.N1Click(Sender: TObject);
begin
  if CDS_Fact.IsEmpty then
    Exit;

  if Trim(CDS_Fact.fieldbyname('FactId').AsString) <> '' then
  begin
    if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
      Exit;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete JYOrder_Fact where FactId=''' + Trim(CDS_Fact.fieldbyname('FactId').AsString) + '''');
      ExecSQL;
    end;
  end;
  CDS_Fact.Delete;
end;

procedure TfrmOrderInPut.V2Column1PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZdyAttachGYS := TfrmZdyAttachGYS.Create(Application);
    with frmZdyAttachGYS do
    begin
      if ShowModal = 1 then
      begin
        CDS_Fact.Edit;
        CDS_Fact.FieldByName('SJGFactory').Value := Trim(CDS_HZ.fieldbyname('CoName').AsString);
        CDS_Fact.FieldByName('SJGFactoryCode').Value := Trim(CDS_HZ.fieldbyname('CoCode').AsString);
        CDS_Fact.FieldByName('SJGFactoryJC').Value := Trim(CDS_HZ.fieldbyname('CoHRName').AsString);
      end;
    end;
  finally
    frmZdyAttachGYS.Free;
  end;
end;

procedure TfrmOrderInPut.N3Click(Sender: TObject);
begin
  SelOKNo(Order_Sub, True);
end;

procedure TfrmOrderInPut.N4Click(Sender: TObject);
begin
  SelOKNo(Order_Sub, False);
end;

procedure TfrmOrderInPut.Tv1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if PXGQX = '已审核' then
  begin
    v1PRTOrderQty.Options.Editing := False;
    VC_PRTPs.Options.Editing := False;
  end;
end;

procedure TfrmOrderInPut.v1PRTOrderQtyPropertiesEditValueChanged(Sender: TObject);
begin
  FXGNOTE := '已修改';
end;

procedure TfrmOrderInPut.Image4Click(Sender: TObject);
begin
  Panel8.Visible := False;
end;

procedure TfrmOrderInPut.Button6Click(Sender: TObject);
begin
  if trim(XGNote.Text) = '' then
  begin
    Application.MessageBox('内容不能为空！', '提示', 0);
    Exit;
  end;
  try
    with ADOCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update  JYOrder_MAIN SET xgnote=' + QUOTEDSTR(Trim(XGNOTE.Text)));
      sql.Add('where MAINID=' + quotedstr(trim(FMainId)));
      execsql;
    end;
    FXGNOTE := '';
    application.MessageBox('修改成功！', '提示信息');
//    TBRafresh.Click;
    Panel8.Visible := False;
  except
    application.MessageBox('修改失败！', '提示信息', 0);
  end;
end;

procedure TfrmOrderInPut.ToolButton7Click(Sender: TObject);
begin
  if FMainId = '' then
  begin
    Exit;
  end;
  Panel8.Visible := True;
//  XGNote.Text := Trim(Order_Main.fieldbyname('lYNOTE').AsString);
end;

procedure TfrmOrderInPut.v1Column5PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin

  try
    frmSketchManageListSel := TfrmSketchManageListSel.Create(Application);
    with frmSketchManageListSel do
    begin
      FKHName := CustomerNoName.Text;
      if ShowModal = 1 then
      begin
        Self.Order_Sub.Edit;
        Self.Order_Sub.FieldByName('PRTHX').Value := Trim(frmSketchManageListSel.Order_Main.fieldbyname('M_HXCODE').AsString);
        Self.Order_Sub.FieldByName('MGMainId').Value := Trim(frmSketchManageListSel.Order_Main.fieldbyname('MGID').AsString);
      end;
    end;
  finally
    frmSketchManageListSel.Free;
  end;
end;

procedure TfrmOrderInPut.v1Column5PropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FFieldName: string;
begin

  mvalue := TcxTextEdit(Sender).EditingText;
  FFieldName := Trim(Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName);
  with Order_Sub do
  begin
    Edit;
    FieldByName(FFieldName).Value := mvalue;
    FieldByName('MGMainId').Value := '';
    Post;
  end;
  Tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmOrderInPut.DLYDateChange(Sender: TObject);
begin
  CYData.DateTime := DLYDate.DateTime;
end;

procedure TfrmOrderInPut.HYTTBtnUpClick(Sender: TObject);
var
  fsj: string;
  FWZ: Integer;
begin
  fsj := Trim(TEdit(Sender).Hint);
  FWZ := Pos('/', fsj);
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := Copy(fsj, 1, FWZ - 1);
      flagname := Copy(fsj, FWZ + 1, Length(fsj) - FWZ);
      if Trim(flag) = 'OrdDefStr2' then
      begin
        V1Name.Caption := '中文名称';
        V1Note.Caption := '英文名称';
        fnote := True;
      end;
      if ShowModal = 1 then
      begin
        TEdit(Sender).Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);

        if TEdit(Sender).Text <> '' then
        begin
          v1Column3.Caption := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        end
        else
        begin
          v1Column3.Caption := '海运';
        end;
        if Trim(flag) = 'MPRTCode' then
        begin
          with ADOTemp do
          begin
            Close;
            sql.Clear;
            sql.Add('select Top 1 * from JYOrder_Main where MPRTCode=''' + Trim(ClientDataSet1.fieldbyname('ZDYName').AsString) + '''');
            sql.Add(' order by FillTime desc');
            Open;
          end;
          MPRTCodeName.Text := ADOTemp.fieldbyname('MPRTCodeName').AsString;
          MPRTMF.Text := ADOTemp.fieldbyname('MPRTMF').AsString;
          MPRTKZ.Text := ADOTemp.fieldbyname('MPRTKZ').AsString;
          MPRTSpec.Text := ADOTemp.fieldbyname('MPRTSpec').AsString;
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut.KYTTBtnUpClick(Sender: TObject);
var
  fsj: string;
  FWZ: Integer;
begin
  fsj := Trim(TEdit(Sender).Hint);
  FWZ := Pos('/', fsj);
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := Copy(fsj, 1, FWZ - 1);
      flagname := Copy(fsj, FWZ + 1, Length(fsj) - FWZ);
      if Trim(flag) = 'OrdDefStr2' then
      begin
        V1Name.Caption := '中文名称';
        V1Note.Caption := '英文名称';
        fnote := True;
      end;
      if ShowModal = 1 then
      begin
        TEdit(Sender).Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        if TEdit(Sender).Text <> '' then
        begin
          v1Column13.Caption := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        end
        else
        begin
          v1Column13.Caption := '空运';
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut.ToolButton4Click(Sender: TObject);
var
  FConMainId, FMPRTCode: string;
begin
  try
    frmContractListSel := TfrmContractListSel.Create(Application);
    with frmContractListSel do
    begin
      fconNo := trim(self.ConNo.Text);
      if ShowModal = 1 then
      begin
        Order_Main.locate('SSel', true, []);
        FConMainId := Trim(frmContractListSel.Order_Main.fieldbyname('MainId').AsString);

        while Order_Main.locate('SSel', true, []) do
        begin
          if FConMainId <> trim(frmContractListSel.Order_Main.Fieldbyname('MainId').AsString) then
          begin
            Application.MessageBox('不能选择多个合同！', '提示', 0);
            break;
          end;
          if self.MPRTCode.Text <> trim(frmContractListSel.Order_Main.Fieldbyname('SCSCode').AsString) then
          begin
            Application.MessageBox('不能选择多个产品！', '提示', 0);
            break;
          end;
          if self.MPRTMF.Text <> trim(frmContractListSel.Order_Main.Fieldbyname('SCSMF').AsString) then
          begin
            Application.MessageBox('不能选择多个产品！', '提示', 0);
            break;
          end;
          if self.MPRTKZ.Text <> trim(frmContractListSel.Order_Main.Fieldbyname('SCSKZ').AsString) then
          begin
            Application.MessageBox('不能选择多个产品！', '提示', 0);
            break;
          end;
          if self.Order_Sub.locate('ConSubId', trim(Order_Main.Fieldbyname('SubId').AsString), []) then
          begin
            Order_Main.Edit;
            Order_Main.fieldbyname('SSel').value := false;
            continue;
          end;
          with self.Order_Sub do
          begin
            append;

//            Fieldbyname('PrtKuanNO').value := trim(frmContractListSel.Order_Main.Fieldbyname('SCSKX').AsString);
            Fieldbyname('PrtColorNo').value := trim(frmContractListSel.Order_Main.Fieldbyname('SCSColorNo').AsString);
            Fieldbyname('PrtColor').value := trim(frmContractListSel.Order_Main.Fieldbyname('SCSColor').AsString);
            Fieldbyname('PRTEColor').value := trim(frmContractListSel.Order_Main.Fieldbyname('SCSEColor').AsString);
            Fieldbyname('PRTHX').value := trim(frmContractListSel.Order_Main.Fieldbyname('SCSHX').AsString);
            Fieldbyname('PRTOrderQty').value := frmContractListSel.Order_Main.Fieldbyname('SCSQty').AsFloat;
            Fieldbyname('OrderUnit').value := trim(frmContractListSel.Order_Main.Fieldbyname('SCSUnit').AsString);
            Fieldbyname('SubNote').value := trim(frmContractListSel.Order_Main.Fieldbyname('SCSNote').AsString);
            FieldByName('hxFile').Value := '';
            FieldByName('TPPS').Value := 0;
            FieldByName('TPQty').Value := 0;
            if SELF.BPBigType.Text = '针织' then
            begin
              FieldByName('TPUnit').Value := 'KG';
            end;
            if Self.BPBigType.Text = '梭织' then
            begin
              FieldByName('TPUnit').Value := 'M';
            end;

            Fieldbyname('ConSubId').value := trim(frmContractListSel.Order_Main.Fieldbyname('SubId').AsString);
          end;
          Order_Main.Edit;
          Order_Main.fieldbyname('SSel').value := false;
        end;

      end;
    end;
  finally
    frmContractListSel.Free;
  end;
  GetLLXS();
  PDCP();
end;

end.

