unit U_OrderInPut1;

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, cxDropDownEdit,
  cxGridBandedTableView, cxGridDBBandedTableView, cxSplitter, RM_Common,
  RM_Class, RM_e_Xls, RM_System, RM_GridReport, RM_Dataset,
  cxGridCustomPopupMenu, cxGridPopupMenu, cxCheckBox;

type
  TfrmOrderInPut1 = class(TForm)
    ToolBar1: TToolBar;
    TBSave: TToolButton;
    TBClose: TToolButton;
    ScrollBox1: TScrollBox;
    Label1: TLabel;
    OrderNo: TEdit;
    ADOTemp: TADOQuery;
    ADOCmd: TADOQuery;
    DataSource1: TDataSource;
    Order_Sub: TClientDataSet;
    ADOQuery1: TADOQuery;
    Label3: TLabel;
    Label14: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    OrdDate: TDateTimePicker;
    MPRTMF: TBtnEditC;
    MPRTKZ: TBtnEditC;
    Label2: TLabel;
    MPRTCodeName: TBtnEditC;
    Label6: TLabel;
    MPRTSpec: TBtnEditC;
    Label25: TLabel;
    DLYDate: TDateTimePicker;
    Label41: TLabel;
    LiDanPerson: TBtnEditC;
    Label43: TLabel;
    YWY: TBtnEditC;
    CustomerNoName: TEdit;
    Label29: TLabel;
    note: TBtnEditC;
    cxGrid4: TcxGrid;
    TV4: TcxGridDBBandedTableView;
    cxGridDBBandedColumn1: TcxGridDBBandedColumn;
    cxGridDBBandedColumn2: TcxGridDBBandedColumn;
    cxGridDBBandedColumn3: TcxGridDBBandedColumn;
    V4FPType: TcxGridDBBandedColumn;
    V4OtherMoney: TcxGridDBBandedColumn;
    V4Note: TcxGridDBBandedColumn;
    cxGridLevel1: TcxGridLevel;
    Button5: TButton;
    DataSource4: TDataSource;
    Order_RLDJ: TClientDataSet;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    cxStyle2: TcxStyle;
    V4SKDate: TcxGridDBBandedColumn;
    V4SKMoney: TcxGridDBBandedColumn;
    V4BanKFee: TcxGridDBBandedColumn;
    V4BZType: TcxGridDBBandedColumn;
    V4WRLMoney: TcxGridDBBandedColumn;
    V4WYHMoney: TcxGridDBBandedColumn;
    cxStyle3: TcxStyle;
    ADOQueryCmd: TADOQuery;
    Label4: TLabel;
    Label5: TLabel;
    Panel1: TPanel;
    ToolBar2: TToolBar;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    TYPTP: TToolButton;
    ToolButton3: TToolButton;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1XHNo: TcxGridDBColumn;
    v1StyleNo: TcxGridDBColumn;
    v1PRTColor: TcxGridDBColumn;
    v1PRTColorEng: TcxGridDBColumn;
    v1PRTHX: TcxGridDBColumn;
    v1HXTuGao: TcxGridDBColumn;
    v1PRTColorNo: TcxGridDBColumn;
    v1OrdColQty: TcxGridDBColumn;
    v1PRTOrderQty: TcxGridDBColumn;
    v1OrderUnit: TcxGridDBColumn;
    v1OrdNote: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    DataSource2: TDataSource;
    Order_GX: TClientDataSet;
    DataSource3: TDataSource;
    CDS_JGC: TClientDataSet;
    CDS_Print: TClientDataSet;
    ADOQueryTemp: TADOQuery;
    RM1: TRMGridReport;
    RMXLSExport1: TRMXLSExport;
    RMDBMain: TRMDBDataSet;
    Label9: TLabel;
    BPPiZhong: TBtnEditC;
    Label16: TLabel;
    Label19: TLabel;
    Label20: TLabel;
    Label21: TLabel;
    MPRTYaoFeng: TBtnEditC;
    MPRTTangJin: TBtnEditC;
    Label22: TLabel;
    GanKou: TBtnEditC;
    Label23: TLabel;
    KHConNO: TEdit;
    MPRTBZNote: TMemo;
    MPRTTeBieNote: TMemo;
    MPRTZuRanXing: TMemo;
    Label11: TLabel;
    Label15: TLabel;
    Label17: TLabel;
    Label18: TLabel;
    MPRTMFNOte: TBtnEditC;
    MPRTChuanY: TBtnEditC;
    MPRTKaiJian: TBtnEditC;
    Label7: TLabel;
    OrdDefNote2: TMemo;
    Label8: TLabel;
    YHDate: TDateTimePicker;
    v1MXCodeName: TcxGridDBColumn;
    v1CJSpec: TcxGridDBColumn;
    v1ZXFangFa: TcxGridDBColumn;
    Label26: TLabel;
    CPSpec: TBtnEditC;
    Label27: TLabel;
    MPRTCodeZL: TBtnEditC;
    v1MXMF: TcxGridDBColumn;
    v1DHao: TcxGridDBColumn;
    Label28: TLabel;
    JGFactoryName: TBtnEditC;
    Label30: TLabel;
    YDZhuang: TEdit;
    Label31: TLabel;
    Label32: TLabel;
    v1PRTPrice: TcxGridDBColumn;
    cxGridPopupMenu2: TcxGridPopupMenu;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Label10: TLabel;
    MPRTCode: TBtnEditC;
    v1MXQty: TcxGridDBColumn;
    v1MKQty: TcxGridDBColumn;
    MPRTKZNOte: TComboBox;
    v1YHGS: TcxGridDBColumn;
    v1YHHT: TcxGridDBColumn;
    Panel2: TPanel;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    vSJPSName: TcxGridDBColumn;
    v2PSNo: TcxGridDBColumn;
    v2PSName: TcxGridDBColumn;
    v2PSSH: TcxGridDBColumn;
    v2PSNote: TcxGridDBColumn;
    v2SYRName: TcxGridDBColumn;
    v2Note: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    ToolBar3: TToolBar;
    ToolButton4: TToolButton;
    ToolButton5: TToolButton;
    v2LDPrice: TcxGridDBColumn;
    v2GCName: TcxGridDBColumn;
    Label24: TLabel;
    OrderType: TComboBox;
    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 CustomerNoNameBtnDnClick(Sender: TObject);
    procedure MPRTCodeNameBtnUpClick(Sender: TObject);
    procedure NoteDblClick(Sender: TObject);
    procedure v1OrderUnitPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1PriceUnitPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure OrdDefStr2BtnUpClick(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure YCLFactoryBtnUpClick(Sender: TObject);
    procedure MPRTSCTeBieNoteBtnUpClick(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure v1HXTuGaoPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1SKTuGaoPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1PRTHXPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure JGFactoryNameBtnUpClick(Sender: TObject);
    procedure v1OrdColQtyPropertiesEditValueChanged(Sender: TObject);
    procedure TYPTPClick(Sender: TObject);
    procedure v1OrdMSQtyPropertiesEditValueChanged(Sender: TObject);
    procedure Tv2FocusedRecordChanged(Sender: TcxCustomGridTableView;
      APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord;
      ANewItemRecordFocusingChanged: Boolean);
    procedure ToolButton5Click(Sender: TObject);
    procedure TV2PSNotePropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v3Column1PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v3TOGYSNamePropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v3PSCodeNamePropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure MPRTBZNoteDblClick(Sender: TObject);
    procedure MPRTTeBieNoteDblClick(Sender: TObject);
    procedure MPRTZuRanXingDblClick(Sender: TObject);
    procedure v1PBFKPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1PBSpecPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1PBKZPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1StyleNoPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1PRTColorNoPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1ZXFangFaPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1MXCodeNamePropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1CJSpecPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1MXCPSpecPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1MXMFPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure FactoryNameBtnUpClick(Sender: TObject);
    procedure v2CGTypePropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v2CGCoedNamePropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v2CGSpecPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v2Column4PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v2CGKZPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v2CGQtyUnitPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v2CGHXPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure ToolButton4Click(Sender: TObject);
    procedure v2GCNamePropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
  private
    procedure InitData();
    procedure ZDYHelp(FButn:TcxButtonEdit;LType:string);
    function  SaveData():Boolean;
    function  SaveDataSubOne():Boolean;
    function  SaveDataMain():Boolean;
    function SaveDataSubMore():Boolean;
    { Private declarations }
  public
    PState,CopyInt,PriceFlag:Integer;
    FMainId,FFMainId,FOrderNo,ConSubId,YGMainid:String;
    FXS:Integer;
    { Public declarations }
  end;

var
  frmOrderInPut1: TfrmOrderInPut1;
  newh:hwnd;
implementation
uses
  U_DataLink,U_ZDYHelp,U_Fun,U_ZDYHelpSel,U_ZdyAttachment,U_GXGL_List_CX
  ,U_CPManageCX,U_FjList_RZ,U_FileUp_TuGao,U_ZdyAttachKH,U_ZdyAttachCP_CX,U_ZdyAttachGYS_CX;

{$R *.dfm}

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

procedure TfrmOrderInPut1.InitData();
begin
  with ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    sql.Add(' select * from JYOrder_Sub_Ord where 1=1 ');
    if PState=1 then
    begin
      sql.Add(' and MainId='''+Trim(FMainId)+'''');
    end;
    if PState=0 then
    begin
      sql.Add(' and 1=2');
    end;
    Open;
  end;
  SCreateCDS20(ADOQuery1,Order_Sub);
  SInitCDSData20(ADOQuery1,Order_Sub);
  with ADOQuery1 do
  begin
    Close;
    sql.Clear;
    sql.Add('select A.* ');
    sql.Add(',ConMainid=(select B.Mainid from JYOrderCon_Main B where B.ConNo=A.ConNo)');
    sql.Add(' from JYOrder_Main_Ord A where MainId='''+Trim(FMainId)+'''');
    Open;
  end;
  SCSHDataNew(ADOQuery1,ScrollBox1,2);
  ConSubId:=Trim(ADOQuery1.fieldbyname('ConSubId').AsString);
  YGMainid:=Trim(ADOQuery1.fieldbyname('ConMainid').AsString);
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrder_GXCX where MainId='''+Trim(FMainId)+'''');
    Open;
  end;
  SCreateCDS20(ADOQueryCmd,CDS_JGC);
  SInitCDSData20(ADOQueryCmd,CDS_JGC);
  if PState=0 then
  begin
    OrdDate.Date:=SGetServerDateTime(ADOTemp);
    DlyDate.Date:=OrdDate.DateTime;
    YHDate.Date:=SGetServerDateTime(ADOTemp);
  end else
  begin
  end;
  if CopyInt=99 then
  begin
    PState:=0;
    FMainId:='';
    OrderNo.Text:='';
    with Order_Sub do
    begin
      First;
      while not Eof do
      begin
        Edit;
        FieldByName('MainId').Value:='';
        FieldByName('SubId').Value:='';
        Post;
        Next;
      end;
    end;
    with CDS_JGC do
    begin
      First;
      while not Eof do
      begin
        Edit;
        FieldByName('MainId').Value:='';
        FieldByName('PSId').Value:='';
        Post;
        Next;
      end;
    end;
  end;
end;

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

procedure TfrmOrderInPut1.FormShow(Sender: TObject);
begin
  readCxGrid('指示单录入AA',Tv1,'生产指示单管理');
  
  YWY.Text:=Trim(DName);
  InitData();
end;

function TfrmOrderInPut1.SaveData():Boolean;
var
  maxno,maxsubno:String;
begin
  try
    ADOCmd.Connection.BeginTrans;
    ///保存主表
    if Trim(FMainId)='' then
    begin
      if GetLSNo(ADOCmd,maxno,'JO','JYOrder_Main_Ord',3,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 JYOrder_Main_Ord where MainId='''+Trim(FMainId)+'''');
      Open;
    end;
    with ADOCmd do
    begin
      if Trim(FMainId)='' then
      begin
        Append;
        FieldByName('OrdFlag1').Value:=0;
        FieldByName('ChkStatus').Value:='';
      end
      else begin
        Edit;
      end;
      FieldByName('MainId').Value:=Trim(maxno);
      fieldbyname('fillCode').Value:=trim(DCode);
      SSetsaveSqlNew(ADOCmd,'JYOrder_Main_Ord',ScrollBox1,2);
      if Trim(FMainId)='' then
      begin
        FieldByName('Filler').Value:=Trim(DName);
      end else
      begin
        FieldByName('Editer').Value:=Trim(DName);
        FieldByName('EditTime').Value:=SGetServerDateTime(ADOTemp);
      end;
      FieldByName('ConSubId').Value:=Trim(ConSubId);
      Post;
    end;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from JYOrder_Main_Ord where orderno='''+Trim(OrderNo.Text)+'''');
      Open;
    end;
    if ADOCmd.RecordCount>1 then
    begin
      ADOCmd.Connection.RollbackTrans;
      Application.MessageBox('订单号重复!','提示',0);
      Exit;
    end;
    FMainId:=Trim(maxno);
    ///保存子表
    with Order_Sub do
    begin
      First;
      while not Eof do
      begin
        if Trim(Order_Sub.fieldbyname('SubId').AsString)='' then
        begin
          if GetLSNo(ADOCmd,maxno,'JS','JYOrder_Sub_Ord',4,1)=False then
          begin
            ADOCmd.Connection.RollbackTrans;
            Application.MessageBox('取子流水号失败！','提示',0);
            Exit;
          end;
        end else
        begin
          maxno:=Trim(Order_Sub.fieldbyname('SubId').AsString);
        end;
        with ADOCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from JYOrder_Sub_Ord where MainId='''+Trim(FMainId)+'''');
          sql.Add(' and SubId='''+Trim(maxno)+'''');
          Open;
        end;
        with ADOCmd do
        begin
          if Trim(Order_Sub.fieldbyname('SubId').AsString)='' then
            Append
          else
            Edit;
          FieldByName('MainId').Value:=Trim(FMainId);
          FieldByName('SubId').Value:=Trim(maxno);
          RTSetSaveDataCDS(ADOCmd,Tv1,Order_Sub,'JYOrder_Sub_Ord',0);
          FieldByName('MXConSubid').Value:=Trim(Order_Sub.fieldbyname('MXConSubid').AsString);
          FieldByName('PRTPrice').Value:=Order_Sub.fieldbyname('PRTPrice').AsFloat;
          FieldByName('MXQty').Value:=Order_Sub.fieldbyname('MXQty').AsFloat;
          FieldByName('MKQty').Value:=Order_Sub.fieldbyname('MKQty').AsFloat;
          if Trim(fieldbyname('PRTOrderQty').AsString)='' then
          begin
            fieldbyname('PRTOrderQty').Value:=0
          end;
          Post;
        end;
        Order_Sub.Edit;
        Order_Sub.FieldByName('SubId').Value:=Trim(maxno);
        Order_Sub.FieldByName('MainId').Value:=Trim(FMainId);
        Next;
      end;
    end;

    with CDS_JGC do
    begin
      First;
      while not Eof do
      begin
        if Trim(CDS_JGC.fieldbyname('PSID').AsString)='' then
        begin
          if GetLSNo(ADOCmd,maxno,'GX','JYOrder_GXCX',4,1)=False then
          begin
            ADOCmd.Connection.RollbackTrans;
            Application.MessageBox('取子流水号失败！','提示',0);
            Exit;
          end;
        end else
        begin
          maxno:=Trim(CDS_JGC.fieldbyname('PSID').AsString);
        end;
        with ADOCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from JYOrder_GXCX where MainId='''+Trim(FMainId)+'''');
          sql.Add(' and PSID='''+Trim(maxno)+'''');
          Open;
        end;
        with ADOCmd do
        begin
          if Trim(CDS_JGC.fieldbyname('PSID').AsString)='' then
            Append
          else
            Edit;
          FieldByName('MainId').Value:=Trim(FMainId);
          FieldByName('PSID').Value:=Trim(maxno);
          RTSetSaveDataCDS(ADOCmd,Tv2,CDS_JGC,'JYOrder_Sub_Ord',0);
          FieldByName('LDPrice').Value:=CDS_JGC.fieldbyname('LDPrice').AsFloat;
          Post;
        end;
        CDS_JGC.Edit;
        CDS_JGC.FieldByName('PSID').Value:=Trim(maxno);
        CDS_JGC.FieldByName('MainId').Value:=Trim(FMainId);
        Next;
      end;
    end;
    ADOCmd.Connection.CommitTrans;
    Result:=True;
  except;
    Result:=False;
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！','提示',0);
  end;
end;

function TfrmOrderInPut1.SaveDataMain():Boolean;
var
  maxno:String;
begin
  try
    ADOCmd.Connection.BeginTrans;
    ///保存主表
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      SQL.Add('select * from JYOrder_Main_Ord where MainId='''+Trim(FMainId)+'''');
      Open;
    end;
    with ADOCmd do
    begin
      if Trim(FMainId)='' then
      begin
        Append;
        maxno:=Trim(FFMainId);
      end
      else begin
        maxno:=Trim(FMainId);
        Edit;
      end;
      FieldByName('MainId').Value:=Trim(maxno);
      SSetsaveSqlNew(ADOCmd,'JYOrder_Main_Ord',ScrollBox1,2);
      if PState=1 then
      begin
        FieldByName('OrdUpDate').Value:=SGetServerDateTime(ADOTemp);
      end;
      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;
    FMainId:=Trim(maxno);
    ADOCmd.Connection.CommitTrans;
    Result:=True;
  except
    Result:=False;
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！','提示',0);
  end;
end;
function TfrmOrderInPut1.SaveDataSubOne():Boolean;
var
  maxno:String;
begin
  try
    ADOCmd.Connection.BeginTrans;
    ///保存子表
    with Order_Sub do
    begin
      //First;
      //while not Eof do
      begin
        if Trim(Order_Sub.fieldbyname('SubId').AsString)='' then
        begin
          if GetLSNo(ADOTemp,maxno,'JS','JYOrder_Sub_Ord',4,1)=False then
          begin
            ADOCmd.Connection.RollbackTrans;
            Application.MessageBox('取子流水号失败！','提示',0);
            Exit;
          end;
        end else
        begin
          maxno:=Trim(Order_Sub.fieldbyname('SubId').AsString);
        end;
        with ADOCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from JYOrder_Sub_Ord where MainId='''+Trim(FMainId)+'''');
          sql.Add(' and SubId='''+Trim(maxno)+'''');
          Open;
        end;
        with ADOCmd do
        begin
          if Trim(Order_Sub.fieldbyname('SubId').AsString)='' then
            Append
          else
            Edit;
          FieldByName('MainId').Value:=Trim(FMainId);
          FieldByName('SubId').Value:=Trim(maxno);
          RTSetSaveDataCDS(ADOCmd,Tv1,Order_Sub,'JYOrder_Sub_Ord',0);
          Post;
        end;
        Order_Sub.Edit;
        Order_Sub.FieldByName('SubId').Value:=Trim(maxno);
        //Order_Sub.Post;
        //Next;
      end;
    end;
    ADOCmd.Connection.CommitTrans;
    Result:=True;
  except
    Result:=False;
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常！','提示',0);
  end;
end;
function TfrmOrderInPut1.SaveDataSubMore():Boolean;
var
  maxno:String;
begin
  try
    ADOCmd.Connection.BeginTrans;
    ///保存子表
    with Order_Sub do
    begin
      First;
      while not Eof do
      begin
        if Trim(Order_Sub.fieldbyname('SubId').AsString)='' then
        begin
          if GetLSNo(ADOTemp,maxno,'JS','JYOrder_Sub_Ord',4,1)=False then
          begin
            ADOCmd.Connection.RollbackTrans;
            Application.MessageBox('取子流水号失败！','提示',0);
            Exit;
          end;
        end else
        begin
          maxno:=Trim(Order_Sub.fieldbyname('SubId').AsString);
        end;
        with ADOCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from JYOrder_Sub_Ord where MainId='''+Trim(FMainId)+'''');
          sql.Add(' and SubId='''+Trim(maxno)+'''');
          Open;
        end;
        with ADOCmd do
        begin
          if Trim(Order_Sub.fieldbyname('SubId').AsString)='' then
            Append
          else
            Edit;
          FieldByName('MainId').Value:=Trim(FMainId);
          FieldByName('SubId').Value:=Trim(maxno);
          RTSetSaveDataCDS(ADOCmd,Tv1,Order_Sub,'JYOrder_Sub_Ord',0);
          Post;
        end;
        Order_Sub.Edit;
        Order_Sub.FieldByName('SubId').Value:=Trim(maxno);
        //Order_Sub.Post;
        Next;
      end;
    end;
    ADOCmd.Connection.CommitTrans;
    Result:=True;
  except
    Result:=False;
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常！','提示',0);
  end;
end;

procedure TfrmOrderInPut1.TBSaveClick(Sender: TObject);
begin
  OrdDate.SetFocus;
  if Trim(OrderNo.Text)='' then
  begin
    Application.MessageBox('订单号不能为空！','提示',0);
    Exit;
  end;
  if Order_Sub.IsEmpty then
  begin
    Application.MessageBox('明细不能为空!','提示',0);
    Exit;
  end;

  if Order_Sub.Locate('OrderUnit',Null,[])=true then
  begin
    application.MessageBox('数量单位不能为空','提示',0);
    exit;
  end;
  
  {if Trim(ConSubId)='' then
  begin
    Application.MessageBox('没有选择合同!','提示',0);
    Exit;
  end;}
  if SaveData() then
  begin
    Application.MessageBox('保存成功！','提示',0);
    ModalResult:=1;
  end;
end;

procedure TfrmOrderInPut1.v1PRTColorPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='OrdColor';
      flagname:='颜色';
      V1Name.Caption:='中文名称';
      V1Note.Caption:='英文名称';
      MainType:=Trim(DName);
      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('PRTColorEng').Value:=Trim(ClientDataSet1.fieldbyname('Note').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut1.ToolButton1Click(Sender: TObject);
var
  i:Integer;
begin
  if Trim(OrderNo.Text)='' then
  begin
    Application.MessageBox('订单号不能为空!','提示',0);
    Exit;
  end;
  i:=Order_Sub.RecordCount;
  i:=i+1;
  CopyAddRow(Tv1,Order_Sub);
  with Order_Sub do
  begin
    Edit;
    FieldByName('XHNO').Value:=IntToStr(i);
    if i<9 then
      FieldByName('PRTColorNo').Value:='0'+Trim(IntToStr(i))
    else
      FieldByName('PRTColorNo').Value:=Trim(IntToStr(i));
    FieldByName('PRTColor').Value:='';
    FieldByName('PRTColorEng').Value:='';
    FieldByName('PRTOrderQty').Value:=null;
    fieldbyname('HXTuGao').value:=NULL;
    Post;
  end;
end;

procedure TfrmOrderInPut1.ToolButton2Click(Sender: TObject);
begin
  if Order_Sub.IsEmpty then Exit;
  if Trim(Order_Sub.fieldbyname('SubId').AsString)<>'' then
  begin
    with ADOTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from CK_SXPB_CR where OrdSubidRK='''+Trim(Order_Sub.fieldbyname('SubId').AsString)+'''');
      Open;
    end;
    if ADOTemp.IsEmpty=False then
    begin
      Application.MessageBox('仓库已选择此明细,不能删除数据!','提示',0);
      Exit;
    end;
  end;
  if Trim(Order_Sub.fieldbyname('SubId').AsString)<>'' then
  begin
    if Application.MessageBox('确定要删除数据吗？','提示',32+4)<>IDYES then Exit;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete JYOrder_Sub_Ord where SubId='''+Trim(Order_Sub.fieldbyname('SubId').AsString)+'''');
      ExecSQL;
    end;
  end;
  Order_Sub.Delete;

end;

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

procedure TfrmOrderInPut1.MPRTCodeNameBtnUpClick(Sender: TObject);
begin
  frmZdyAttachCP_CX:=TfrmZdyAttachCP_CX.create(self);
  with frmZdyAttachCP_CX do
  begin
    if showmodal=1 then
    begin
      CDS_HZ.DisableControls;
      with CDS_HZ do
      begin
        first;
        while not Eof do
        begin
          if FieldByName('Ssel').AsBoolean=true then
          begin
            MPRTCode.Text:=Trim(CDS_HZ.fieldbyname('ZdyName').AsString);
            MPRTCodeName.Text:=Trim(CDS_HZ.fieldbyname('DEFstr3').AsString);
            MPRTMF.Text:=Trim(CDS_HZ.fieldbyname('DEFstr2').AsString);
            CPSpec.Text:=Trim(CDS_HZ.fieldbyname('DEFstr1').AsString);
            with Self.Order_Sub do
            begin
              append;
              FieldByName('MXCodeName').Value:=Trim(CDS_HZ.fieldbyname('DEFstr3').AsString);
              FieldByName('MXMF').Value:=Trim(CDS_HZ.fieldbyname('DEFstr7').AsString);
              FieldByName('PRTHX').Value:=Trim(CDS_HZ.fieldbyname('defNote3').AsString);
              FieldByName('HXTuGao').Value:=Trim(CDS_HZ.fieldbyname('ATID').AsString);
              post;
            end;
          end;
          next;
        end;
      end;
      CDS_HZ.DisableControls;
    end;
    free;
  end;
end;

procedure TfrmOrderInPut1.NoteDblClick(Sender: TObject);
begin
  {try
    frmZDYHelpSel:=TfrmZDYHelpSel.Create(Application);
    with frmZDYHelpSel do
    begin
      flag:='OrdNote';
      flagname:='备注及要求';
      if ShowModal=1 then
      begin
        Note.Text:=Note.Text+frmZDYHelpSel.ReturnStr;
      end;
    end;
  finally
    frmZDYHelpSel.Free;
  end;}
end;

procedure TfrmOrderInPut1.v1OrderUnitPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  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('OrderUnit').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut1.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 TfrmOrderInPut1.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
        //flag:='OrdDefStr2';
        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_Ord where MPRTCode='''+Trim(ClientDataSet1.fieldbyname('ZDYName').AsString)+'''');
            sql.Add(' order by FillTime desc');
            Open;
          end;
          MPRTCodeName.Text:=ADOTemp.fieldbyname('MPRTCodeName').Value;
          MPRTMF.Text:=ADOTemp.fieldbyname('MPRTMF').Value;
          MPRTKZ.Text:=ADOTemp.fieldbyname('MPRTKZ').Value;
          MPRTSpec.Text:=ADOTemp.fieldbyname('MPRTSpec').Value;
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut1.ToolButton3Click(Sender: TObject);
begin
  if Order_Sub.IsEmpty then Exit;
  OneKeyPost(Tv1,Order_Sub);
end;

procedure TfrmOrderInPut1.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);
      MainType:=TEdit(Sender).Name;
      if ShowModal=1 then
      begin
        TEdit(Sender).Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut1.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 TfrmOrderInPut1.Button5Click(Sender: TObject);
var
  maxsubno:String;
  FRLMoney,FSXMoney,FOtherMoney:double;
begin
    with Order_RLDJ do
    begin
      First;
      while not Eof do
      begin
        if Trim(Order_RLDJ.fieldbyname('FPId').AsString)='' then
        begin
          if GetLSNo(ADOTemp,maxsubno,'FP','SK_Money_FP',3,1)=False then
          begin
            Application.MessageBox('取子流水号失败！','提示',0);
            Exit;
          end;
        end else
        begin
          maxsubno:=Trim(Order_RLDJ.fieldbyname('FPId').AsString);
        end;
        with ADOQueryCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from SK_Money_FP where FPId='''+Trim(maxsubno)+'''');
          Open;
        end;
        with ADOQueryCmd do
        begin
          if Trim(Order_RLDJ.fieldbyname('FPId').AsString)='' then
          begin
            Append;
            FieldByName('Filler').Value:=Trim(DName);
          end
          else begin
            Edit;
            FieldByName('Editer').Value:=Trim(DName);
            FieldByName('EditTime').Value:=SGetServerDateTime(ADOTemp);
          end;
          FieldByName('FPId').Value:=Trim(maxsubno);
          FieldByName('YFID').Value:=Trim(Order_RLDJ.fieldbyname('YFID').AsString);
          FieldByName('FPTYpe').Value:=Order_RLDJ.fieldbyname('FPTYpe').Value;
          FieldByName('FPDate').Value:=Order_RLDJ.fieldbyname('FPDate').Value;
          FieldByName('WBID').Value:=Trim(Order_RLDJ.fieldbyname('WBID').AsString);  //指示单关联字段
          FieldByName('TTID').Value:=Trim(Order_RLDJ.fieldbyname('TTID').AsString);
          fieldbyname('FPMoney').Value:=Order_RLDJ.fieldbyname('FPMoney').AsFloat;
          fieldbyname('SXMoney').Value:=Order_RLDJ.fieldbyname('SXMoney').AsFloat;
          fieldbyname('OtherMoney').Value:=Order_RLDJ.fieldbyname('OtherMoney').AsFloat;
          FieldByName('Note').Value:=Trim(Order_RLDJ.fieldbyname('Note').AsString);
          Post;
        end;
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('UPdate JYOrder_Main_Ord Set DJMoney=(select Sum(FPMoney) from SK_Money_FP A ');
          sql.Add(' where A.WBID=JYOrder_Main_Ord.MainID and A.FPType=''定金'') ');
          sql.Add(',HKMoney=(select Sum(FPMoney) from SK_Money_FP A ');
          sql.Add(' where A.WBID=JYOrder_Main_Ord.MainID and A.FPType=''货款'') ');
          sql.Add(',SXMoney=(select Sum(SXMoney) from SK_Money_FP A ');
          sql.Add(' where A.WBID=JYOrder_Main_Ord.MainID) ');
          sql.add(',JYOtherMoney=(select Sum(OtherMoney) from SK_Money_FP A ');
          sql.Add(' where A.WBID=JYOrder_Main_Ord.MainID)');
          sql.add(',SCHuiLv=(Case when (select Top 1 C.HuiLv from YF_Money_CR C inner join SK_Money_FP A on C.YFID=A.YFID ');
          sql.add(' where A.WBID=JYOrder_Main_Ord.MainID and C.CRType=''收款登记'' and C.BZType=''$'' Order by A.FPDate desc)<>0 then ');
          sql.add(' (select Top 1 C.HuiLv from YF_Money_CR C inner join SK_Money_FP A on C.YFID=A.YFID ');
          sql.add(' where A.WBID=JYOrder_Main_Ord.MainID and C.CRType=''收款登记'' and C.BZType=''$'' Order by A.FPDate desc)*1.17-0.35 else NULL end)');
          sql.Add(' where MainID='''+Trim(Order_RLDJ.fieldbyname('WBID').AsString)+'''');
          ExecSQL;
        end;
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('UPdate YF_Money_CR Set FPDJMoney=(select Sum(FPMoney) from SK_Money_FP A ');
          sql.Add(' where A.YFID=YF_Money_CR.YFID and A.FPType=''定金''),');
          sql.Add('YSXMoney=(select Sum(SXMoney) from SK_Money_FP A ');
          sql.Add(' where A.YFID=YF_Money_CR.YFID), ');
          sql.Add('TKMoney=(select Sum(OtherMoney) from SK_Money_FP A ');
          sql.Add(' where A.YFID=YF_Money_CR.YFID) ');
          sql.Add('where YFID='''+Trim(Order_RLDJ.fieldbyname('YFID').AsString)+'''');
          ExecSQL;
        end;
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('UPdate YF_Money_CR Set FPHKMoney=(select Sum(FPMoney) from SK_Money_FP A ');
          sql.Add(' where A.YFID=YF_Money_CR.YFID and A.FPType=''货款'') ');
          sql.Add('where YFID='''+Trim(Order_RLDJ.fieldbyname('YFID').AsString)+'''');
          ExecSQL;
        end;
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('Update YF_Money_CR Set WFPMoney=isnull(RZMoney,0)-isnull(FPDJMoney,0)-isnull(FPHKMoney,0)-isnull(TKMoney,0) ');
          sql.Add('where YFID='''+Trim(Order_RLDJ.fieldbyname('YFID').AsString)+'''');
          ExecSQL;
        end;
        Order_RLDJ.Edit;
        Order_RLDJ.FieldByName('FPId').Value:=Trim(maxsubno);
        Next;
      end;
    end;
end;

procedure TfrmOrderInPut1.v1HXTuGaoPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmFileUp_TuGao:=TfrmFileUp_TuGao.Create(Application);
    with frmFileUp_TuGao do
    begin
      Code.Text:=Trim(Self.OrderNo.Text)+Trim(Self.Order_Sub.fieldbyname('StyleNo').AsString)+Trim(Self.Order_Sub.fieldbyname('PRTHX').AsString);
      CYID:=Trim(Self.Order_Sub.fieldbyname('HXTuGao').AsString);
      if ShowModal=1 then
      begin
        with Order_Sub do
        begin
          edit;
          fieldbyname('HXTuGao').AsString:=Trim(ADOQueryFile.fieldbyname('CYID').asstring);
        end;
      end;
    end;
  finally
    frmFileUp_TuGao.Free;
  end;
end;

procedure TfrmOrderInPut1.v1SKTuGaoPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmFileUp_TuGao:=TfrmFileUp_TuGao.Create(Application);
    with frmFileUp_TuGao do
    begin
      Code.Text:=Trim(Self.Order_Sub.fieldbyname('SOrddefstr2').AsString);
      CYID:=Trim(Self.Order_Sub.fieldbyname('SKTuGao').AsString);
      if ShowModal=1 then
      begin
        with Order_Sub do
        begin
          edit;
          fieldbyname('SKTuGao').AsString:=Trim(ADOQueryFile.fieldbyname('CYID').asstring);
        end;
      end;
    end;
  finally
    frmFileUp_TuGao.Free;
  end;
end;

procedure TfrmOrderInPut1.v1PRTHXPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='PRTHX';
      flagname:='花型';
      if ShowModal=1 then
      begin
        Self.Order_Sub.Edit;
        Self.Order_Sub.FieldByName('PRTHX').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut1.JGFactoryNameBtnUpClick(Sender: TObject);
begin
  try
    frmZdyAttachKH:=TfrmZdyAttachKH.Create(Application);
    with frmZdyAttachKH do
    begin
      if ShowModal=1 then
      begin
        JGFactoryName.Text:=Trim(CDS_HZ.fieldbyname('ZdyName').AsString);
      end;
    end;
  finally
    frmZdyAttachKH.Free;
  end;
end;

procedure TfrmOrderInPut1.v1OrdColQtyPropertiesEditValueChanged(
  Sender: TObject);
var
  Fieldname:string;
  mavlue:string;
begin
  Fieldname:=Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName;
  mavlue:=TcxTextEdit(Sender).EditingText;
  if mavlue='' then
  mavlue:='0';
  with Order_Sub do
  begin
    edit;
    fieldbyname('OrdColQty').AsString:=trim(mavlue);
  end;
  with Order_Sub do
  begin
    edit;
    FieldByName('PRTOrderQty').Value:=FieldByName('OrdColQty').AsFloat*FieldByName('OrdMSQty').AsFloat;
  end;
end;

procedure TfrmOrderInPut1.TYPTPClick(Sender: TObject);
begin
  if Trim(OrderNo.Text)='' then
  begin
    Application.MessageBox('订单号不能为空!','提示',0);
    Exit;
  end;
  frmCPManage_CX:=TfrmCPManage_CX.create(self);
  with frmCPManage_CX do
  begin
    if showmodal=1 then
    begin
      CDS_Main.DisableControls;
      with CDS_Main do
      begin
        first;
        while not Eof do
        begin
          if FieldByName('Ssel').AsBoolean=true then
          begin
            with Self.Order_Sub do
            begin
              append;
              FieldByName('PRTColor').Value:=Trim(CDS_Main.fieldbyname('CYColor').AsString);
              FieldByName('PRTColorEng').Value:=Trim(CDS_Main.fieldbyname('CYColorEng').AsString);
              FieldByName('PRTHX').Value:=Trim(CDS_Main.fieldbyname('CYHX').AsString);
              FieldByName('HXTuGao').Value:=Trim(CDS_Main.fieldbyname('CYID').AsString);
              post;
            end;
          end;
          next;
        end;
      end;
      CDS_Main.DisableControls;
    end;
    free;
  end;
end;

procedure TfrmOrderInPut1.v1OrdMSQtyPropertiesEditValueChanged(
  Sender: TObject);
var
  Fieldname:string;
  mavlue:string;
begin
  Fieldname:=Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName;
  mavlue:=TcxTextEdit(Sender).EditingText;
  if mavlue='' then
  mavlue:='0';
  with Order_Sub do
  begin
    edit;
    fieldbyname('OrdMSQty').AsString:=trim(mavlue);
  end;
  with Order_Sub do
  begin
    edit;
    FieldByName('PRTOrderQty').Value:=FieldByName('OrdColQty').AsFloat*FieldByName('OrdMSQty').AsFloat;
  end;
end;

procedure TfrmOrderInPut1.Tv2FocusedRecordChanged(
  Sender: TcxCustomGridTableView; APrevFocusedRecord,
  AFocusedRecord: TcxCustomGridRecord;
  ANewItemRecordFocusingChanged: Boolean);
begin
  with ADOCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('select A.*,B.PRTHX,PRTColor=isnull(B.PRTColorNo,'''')+'' ''+isnull(B.PRTColorEng,'''')+'' ''+isnull(B.PRTColor,''''), ');
    sql.Add(' B.PRTOrderQty,B.OrderUnit from JYOrder_PCS_Sub A');
    sql.Add(' left join JYOrder_Sub_Ord B on A.SubId=B.SubId');
    sql.Add('where A.PSID='''+Trim(Order_GX.fieldbyname('PSID').AsString)+'''');
    Open;
  end;
  SCreateCDS20(ADOCmd,CDS_JGC);
  SInitCDSData20(ADOCmd,CDS_JGC);
end;

procedure TfrmOrderInPut1.ToolButton5Click(Sender: TObject);
begin
  if CDS_JGC.IsEmpty then Exit;
  if Trim(CDS_JGC.fieldbyname('PSId').AsString)<>'' then
  begin
    if Application.MessageBox('确定要删除数据吗？','提示',32+4)<>IDYES then Exit;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete from JYOrder_GXCX where PSId='''+Trim(CDS_JGC.fieldbyname('PSId').AsString)+'''');
      ExecSQL;
    end;
  end;
  CDS_JGC.Delete;
end;

procedure TfrmOrderInPut1.TV2PSNotePropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
var
  fsj:string;
  i:Integer;
begin
  try
    frmZDYHelpSel:=TfrmZDYHelpSel.Create(Application);
    with frmZDYHelpSel do
    begin
      flag:='PSNote';
      flagname:='采购内容';
      if ShowModal=1 then
      begin
        with Order_GX do
        begin
          Edit;
          FieldByName('PSNote').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
          //Post;
        end;
      end;
    end;
  finally
    frmZDYHelpSel.Free;
  end;
end;

procedure TfrmOrderInPut1.v3Column1PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='PFGenDanPerson';
      flagname:='跟单员';
      fnote:=True;
      V1Note.Caption:='电话';
      if ShowModal=1 then
      begin
        with CDS_JGC do
        begin
          Edit;
          FieldByName('PFGenDanPerson').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut1.v3TOGYSNamePropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZdyAttachKH:=TfrmZdyAttachKH.Create(Application);
    with frmZdyAttachKH do
    begin
      if ShowModal=1 then
      begin
        with CDS_JGC do
        begin
          edit;
          FieldByName('TOGYSName').Value:=Trim(CDS_HZ.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally
    frmZdyAttachKH.Free;
  end;
end;

procedure TfrmOrderInPut1.v3PSCodeNamePropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='PSCodeName';
      flagname:='产品名称';
      if ShowModal=1 then
      begin
        with CDS_JGC do
        begin
          Edit;
          FieldByName('PSCodeName').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut1.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 TfrmOrderInPut1.MPRTTeBieNoteDblClick(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
        MPRTTeBieNote.Lines.Clear;
        with ClientDataSet1 do
        begin
          First;
          while not Eof do
          begin
            if FieldByName('SSel').AsBoolean=True then
            begin
              i:=i+1;
              MPRTTeBieNote.Lines.Add(FieldByName('ZDYName').AsString);
            end;
            Next;
          end;
        end;
      end;
    end;
  finally
    frmZDYHelpSel.Free;
  end;
end;

procedure TfrmOrderInPut1.MPRTZuRanXingDblClick(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
        MPRTZuRanXing.Lines.Clear;
        with ClientDataSet1 do
        begin
          First;
          while not Eof do
          begin
            if FieldByName('SSel').AsBoolean=True then
            begin
              MPRTZuRanXing.Lines.Add(FieldByName('ZDYName').AsString);
            end;
            Next;
          end;
        end;
      end;
    end;
  finally
    frmZDYHelpSel.Free;
  end;
end;

procedure TfrmOrderInPut1.v1PBFKPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='PBFK';
      flagname:='坯布幅宽';
      if ShowModal=1 then
      begin
        with Order_Sub do
        begin
          Edit;
          FieldByName('PBFK').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut1.v1PBSpecPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='PBSpec';
      flagname:='坯布规格';
      if ShowModal=1 then
      begin
        with Order_Sub do
        begin
          Edit;
          FieldByName('PBSpec').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut1.v1PBKZPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='PBKZ';
      flagname:='坯布克重';
      if ShowModal=1 then
      begin
        with Order_Sub do
        begin
          Edit;
          FieldByName('PBKZ').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally;
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut1.v1StyleNoPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='StyleNo';
      flagname:='款号';
      if ShowModal=1 then
      begin
        with Order_Sub do
        begin
          Edit;
          FieldByName('StyleNo').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally;
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut1.v1PRTColorNoPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='PRTColorNo';
      flagname:='色号/花号';
      if ShowModal=1 then
      begin
        with Order_Sub do
        begin
          Edit;
          FieldByName('PRTColorNo').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally;
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut1.v1ZXFangFaPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='ZXFangFa';
      flagname:='装箱方法';
      if ShowModal=1 then
      begin
        with Order_Sub do
        begin
          Edit;
          FieldByName('ZXFangFa').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally;
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut1.v1MXCodeNamePropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='MXCodeName';
      flagname:='品名';
      if ShowModal=1 then
      begin
        with Order_Sub do
        begin
          Edit;
          FieldByName('MXCodeName').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally;
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut1.v1CJSpecPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='CJSpec';
      flagname:='裁剪尺寸';
      if ShowModal=1 then
      begin
        with Order_Sub do
        begin
          Edit;
          FieldByName('CJSpec').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally;
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut1.v1MXCPSpecPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='MXCPSpec';
      flagname:='成品尺寸';
      if ShowModal=1 then
      begin
        with Order_Sub do
        begin
          Edit;
          FieldByName('MXCPSpec').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally;
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut1.v1MXMFPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='MXMF';
      flagname:='有效门幅';
      if ShowModal=1 then
      begin
        with Order_Sub do
        begin
          Edit;
          FieldByName('MXMF').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally;
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut1.FactoryNameBtnUpClick(Sender: TObject);
begin
  frmZdyAttachKH:=TfrmZdyAttachKH.Create(self);
  with frmZdyAttachKH do
  begin
    if ShowModal=1 then
    begin
      JGFactoryName.Text:=Trim(CDS_HZ.fieldbyname('ZdyName').AsString);
    end;
    free;
  end;
end;

procedure TfrmOrderInPut1.v2CGTypePropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='CGType';
      flagname:='类型';
      if ShowModal=1 then
      begin
        with Order_GX do
        begin
          Edit;
          FieldByName('CGType').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally;
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut1.v2CGCoedNamePropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='CGCoedName';
      flagname:='品名';
      if ShowModal=1 then
      begin
        with Order_GX do
        begin
          Edit;
          FieldByName('CGCoedName').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally;
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut1.v2CGSpecPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='CGSpec';
      flagname:='规格';
      if ShowModal=1 then
      begin
        with Order_GX do
        begin
          Edit;
          FieldByName('CGSpec').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally;
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut1.v2Column4PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='CGColor';
      flagname:='颜色';
      if ShowModal=1 then
      begin
        with Order_GX do
        begin
          Edit;
          FieldByName('CGColor').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally;
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut1.v2CGKZPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='CGKZ';
      flagname:='克重';
      if ShowModal=1 then
      begin
        with Order_GX do
        begin
          Edit;
          FieldByName('CGKZ').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally;
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut1.v2CGQtyUnitPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='CGQtyUnit';
      flagname:='数量单位';
      if ShowModal=1 then
      begin
        with Order_GX do
        begin
          Edit;
          FieldByName('CGQtyUnit').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally;
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut1.v2CGHXPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='CGHX';
      flagname:='花型';
      if ShowModal=1 then
      begin
        with Order_GX do
        begin
          Edit;
          FieldByName('CGHX').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally;
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut1.ToolButton4Click(Sender: TObject);
begin
  frmGXGL_List_CX:=TfrmGXGL_List_CX.create(self);
  with frmGXGL_List_CX do
  begin
    if ShowModal=1 then
    begin
      with CDS_HZ do
      begin
        First;
        while not Eof do
        begin
          if FieldByName('Ssel').AsBoolean=true then
          begin
            with CDS_JGC do
            begin
              append;
              FieldByName('SJPSName').Value:=Trim(CDS_HZ.fieldbyname('SJPSName').AsString);
              FieldByName('PSNo').Value:=Trim(CDS_HZ.fieldbyname('PSNo').AsString);
              FieldByName('PSName').Value:=Trim(CDS_HZ.fieldbyname('PSName').AsString);
              FieldByName('PSSH').Value:=Trim(CDS_HZ.fieldbyname('PSSH').AsString);
              FieldByName('PSNote').Value:=Trim(CDS_HZ.fieldbyname('PSNote').AsString);
              FieldByName('SYRName').Value:=Trim(CDS_HZ.fieldbyname('SYRName').AsString);
              FieldByName('Note').Value:=Trim(CDS_HZ.fieldbyname('Note').AsString);
              post;
            end;
          end;
          next;
        end;
      end;
    end;
    free;
  end;
end;

procedure TfrmOrderInPut1.v2GCNamePropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  frmZdyAttachGYS_CX:=TfrmZdyAttachGYS_CX.create(self);
  with frmZdyAttachGYS_CX do
  begin
    if showmodal=1 then
    begin
      with ADOQueryTemp do
      begin
        close;
        sql.Clear;
        sql.Add('select Top 1 LDPrice from JYOrder_GXCX ');
        SQL.Add('where GCName='''+trim(CDS_HZ.fieldbyname('ZdyName').AsString)+'''');
        SQL.Add(' and PSName='''+trim(CDS_JGC.fieldbyname('PSName').AsString)+'''');
        sql.Add(' order by filltime desc');
        open;
      end;
      with CDS_JGC do
      begin
        edit;
        FieldByName('GCName').Value:=Trim(CDS_HZ.fieldbyname('ZdyName').AsString);
        FieldByName('LDPrice').Value:=ADOQueryTemp.fieldbyname('LDPrice').AsFloat;
      end;
    end;
    free;
  end;
end;

end.
