unit U_TradePlanInPut;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  U_FormLayOutDesign, Winapi.ShellAPI, ComObj, 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, dxDateRanges,
  dxBarBuiltInMenu, cxPC, System.ImageList, Vcl.ImgList, U_BaseInput, dxCore,
  cxDateUtils, dxScrollbarAnnotations, IdBaseComponent, IdComponent,
  IdTCPConnection, IdTCPClient, IdExplicitTLSClientServerBase, IdFTP, cxImage,
  cxDBEdit, cxGroupBox, cxImageList, dxSkinsDefaultPainters, dxSkinsCore,
  dxSkinBasic, 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, dxSkinOffice2016Colorful,
  dxSkinOffice2016Dark, dxSkinOffice2019Black, dxSkinOffice2019Colorful,
  dxSkinOffice2019DarkGray, dxSkinOffice2019White, dxSkinPumpkin, dxSkinSeven,
  dxSkinSevenClassic, dxSkinSharp, dxSkinSharpPlus, dxSkinSilver,
  dxSkinSpringtime, dxSkinStardust, dxSkinSummer2008, dxSkinTheAsphaltWorld,
  dxSkinTheBezier, dxSkinValentine, dxSkinVisualStudio2013Blue,
  dxSkinVisualStudio2013Dark, dxSkinVisualStudio2013Light, dxSkinVS2010,
  dxSkinWhiteprint, dxSkinWXI, dxSkinXmas2008Blue;

type
  TfrmTradePlanInPut = class(TfrmBaseInput)
    ToolBar1: TToolBar;
    TBSave: TToolButton;
    TBClose: TToolButton;
    ScrollBox1: TScrollBox;
    OrderNo: TcxTextEdit;
    ADOTemp: TADOQuery;
    ADOCmd: TADOQuery;
    DS_1: TDataSource;
    CDS_1: TClientDataSet;
    Label3: TLabel;
    Label25: TLabel;
    GPM_1: TcxGridPopupMenu;
    ADOQueryLabel: TADOQuery;
    Label51: TLabel;
    Label7: TLabel;
    ADO_I1: TADOQuery;
    DS_I1: TDataSource;
    ToolButton3: TToolButton;
    Label1: TLabel;
    Label2: TLabel;
    Label4: TLabel;
    BuyConNo: TcxTextEdit;
    C_Name: TcxTextEdit;
    Label6: TLabel;
    Label8: TLabel;
    C_Spec: TcxTextEdit;
    C_Composition: TcxTextEdit;
    Label9: TLabel;
    C_GramWeight: TcxTextEdit;
    Label10: TLabel;
    C_Width: TcxTextEdit;
    Label11: TLabel;
    Label27: TLabel;
    IdFTP1: TIdFTP;
    Label14: TLabel;
    Label20: TLabel;
    ConNo: TcxTextEdit;
    ADO_I2: TADOQuery;
    DS_I2: TDataSource;
    CDS_LM: TClientDataSet;
    OpenDialog1: TOpenDialog;
    PM_1: TPopupMenu;
    N5: TMenuItem;
    N6: TMenuItem;
    GPM_2: TcxGridPopupMenu;
    cxPageControl3: TcxPageControl;
    cxTabSheet2: TcxTabSheet;
    cxTabSheet3: TcxTabSheet;
    tlb2: TToolBar;
    btnConSel: TToolButton;
    ToolButton5: TToolButton;
    ToolButton7: TToolButton;
    ToolButton4: TToolButton;
    ToolButton1: TToolButton;
    ToolButton6: TToolButton;
    ToolButton2: TToolButton;
    cxGrid1: TcxGrid;
    TV1: TcxGridDBTableView;
    TV1Column8: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1PRTColor: TcxGridDBColumn;
    TV1Column5: TcxGridDBColumn;
    TV1Column6: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    TV1Column3: TcxGridDBColumn;
    VC_PRTPs: TcxGridDBColumn;
    v1PRTOrderQty: TcxGridDBColumn;
    TV1Column2: TcxGridDBColumn;
    TV1Column4: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    cxTabSheet1: TcxTabSheet;
    cxGroupBox3: TcxGroupBox;
    cxDBImage4: TcxDBImage;
    OrdDate: TcxDateEdit;
    DlyDate: TcxDateEdit;
    CustName: TcxButtonEdit;
    OurCoName: TcxButtonEdit;
    OrdUnit: TcxComboBox;
    Panel1: TPanel;
    lbl1: TLabel;
    lbl2: TLabel;
    lbl3: TLabel;
    lbl4: TLabel;
    lbl5: TLabel;
    lbl10: TLabel;
    lbl11: TLabel;
    lbl13: TLabel;
    lbl14: TLabel;
    lbl16: TLabel;
    RuleBeforeTare: TcxTextEdit;
    Coefficient: TcxTextEdit;
    RuleLaterTare: TcxTextEdit;
    RuleLenUnit: TcxComboBox;
    RuleConversion: TcxComboBox;
    RulePieceNo: TcxComboBox;
    PackType: TcxButtonEdit;
    PackNote: TcxMemo;
    LabVolume: TcxButtonEdit;
    LabPackage: TcxButtonEdit;
    RMDB_2: TRMDBDataSet;
    ADO_1: TADOQuery;
    lbl17: TLabel;
    C_Degree: TcxComboBox;
    TV1Column7: TcxGridDBColumn;
    TV1Column1: TcxGridDBColumn;
    lbl32: TLabel;
    OtherProcess12: TcxButtonEdit;
    Label16: TLabel;
    GC_Name: TcxTextEdit;
    Label17: TLabel;
    CraftCode: TcxTextEdit;
    Label18: TLabel;
    CraftName: TcxTextEdit;
    Label15: TLabel;
    OrdType: TcxComboBox;
    TV1Column9: TcxGridDBColumn;
    Label38: TLabel;
    Follower: TcxButtonEdit;
    Label37: TLabel;
    lbl24: TLabel;
    Saleser: TcxTextEdit;
    TV1Column10: TcxGridDBColumn;
    cxTabSheet4: TcxTabSheet;
    cxGrid2: TcxGrid;
    TV2: TcxGridDBTableView;
    TV2Column1: TcxGridDBColumn;
    TV2Column2: TcxGridDBColumn;
    TV2Column3: TcxGridDBColumn;
    TV2Column4: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    TV2Column5: TcxGridDBColumn;
    ToolBar2: TToolBar;
    ToolButton12: TToolButton;
    ToolButton14: TToolButton;
    TV2Column6: TcxGridDBColumn;
    Label39: TLabel;
    Export: TcxComboBox;
    Label40: TLabel;
    SampleCloth1: TcxTextEdit;
    Label41: TLabel;
    SampleCloth3: TcxTextEdit;
    Label42: TLabel;
    SampleCloth4: TcxTextEdit;
    SampleCloth2: TcxTextEdit;
    Label43: TLabel;
    Label44: TLabel;
    FixedLength: TcxTextEdit;
    Label21: TLabel;
    ADO_2: TADOQuery;
    DS_2: TDataSource;
    CDS_2: TClientDataSet;
    TV2Column7: TcxGridDBColumn;
    Label22: TLabel;
    CraftEName: TcxTextEdit;
    Label24: TLabel;
    ShippingMark: TcxMemo;
    TV1Column11: TcxGridDBColumn;
    TV1Column12: TcxGridDBColumn;
    TV1Column13: TcxGridDBColumn;
    SalesId: TcxTextEdit;
    TallyId: TcxTextEdit;
    DlyNote: TcxTextEdit;
    ConDate: TcxTextEdit;
    Label28: TLabel;
    TFID1: TcxTextEdit;
    TV1Column14: TcxGridDBColumn;
    Label29: TLabel;
    ISTax: TcxComboBox;
    Label30: TLabel;
    PayMent: TcxButtonEdit;
    TV1Column15: TcxGridDBColumn;
    ScrollBox2: TScrollBox;
    Label5: TLabel;
    Label52: TLabel;
    Label53: TLabel;
    Label54: TLabel;
    Label55: TLabel;
    Label56: TLabel;
    Label57: TLabel;
    Label58: TLabel;
    Label59: TLabel;
    Label60: TLabel;
    Label61: TLabel;
    Label62: TLabel;
    Label63: TLabel;
    Label64: TLabel;
    Label65: TLabel;
    Label66: TLabel;
    Label67: TLabel;
    Label68: TLabel;
    Label69: TLabel;
    Label70: TLabel;
    OrdNote: TcxMemo;
    LightNote: TcxButtonEdit;
    FtyName: TcxButtonEdit;
    OtherProcess1: TcxComboBox;
    Resin: TcxButtonEdit;
    WaterPressure: TcxButtonEdit;
    LightType: TcxButtonEdit;
    DyeingMach: TcxButtonEdit;
    Technics: TcxComboBox;
    plane: TcxButtonEdit;
    ColourFastness: TcxButtonEdit;
    Feel: TcxButtonEdit;
    OtherProcess8: TcxButtonEdit;
    ReferenceNumber: TcxButtonEdit;
    shrink: TcxButtonEdit;
    soft: TcxButtonEdit;
    OtherProcess6: TcxButtonEdit;
    EnvironmentalProtection: TcxButtonEdit;
    waterProof: TcxButtonEdit;
    coating: TcxButtonEdit;
    lbl23: TLabel;
    OrdReason: TcxComboBox;
    ToolButton8: TToolButton;
    Label12: TLabel;
    C_EComposition: TcxTextEdit;
    Label13: TLabel;
    C_EName: TcxTextEdit;
    ShrinkageRate: TcxCurrencyEdit;
    Label19: TLabel;
    Tallyer: TcxButtonEdit;
    ToolBar3: TToolBar;
    ToolButton9: TToolButton;
    Label23: TLabel;
    C_Code: TcxTextEdit;
    cxTextEdit1: TcxTextEdit;
    cxTextEdit2: TcxTextEdit;
    cxTextEdit3: TcxTextEdit;
    cxTextEdit4: TcxTextEdit;
    cxTextEdit5: TcxTextEdit;
    cxTextEdit6: TcxTextEdit;
    cxTextEdit7: TcxTextEdit;
    cxDateEdit1: TcxDateEdit;
    cxTextEdit8: TcxTextEdit;
    cxTextEdit9: TcxTextEdit;
    cxTextEdit10: TcxTextEdit;
    Label26: TLabel;
    Label31: TLabel;
    Label32: TLabel;
    Label33: TLabel;
    Label34: TLabel;
    Label35: TLabel;
    Label36: TLabel;
    Label45: TLabel;
    Label46: TLabel;
    Label47: TLabel;
    Label48: TLabel;
    Label49: TLabel;
    Panel2: TPanel;
    Memo1: TMemo;
    Label50: TLabel;
    cxDateEdit2: TcxDateEdit;
    cxDateEdit3: TcxDateEdit;
    cxDateEdit4: TcxDateEdit;
    cxTextEdit11: TcxTextEdit;
    cxTextEdit12: TcxTextEdit;
    cxTextEdit13: TcxTextEdit;
    Label71: TLabel;
    Label72: TLabel;
    Label73: TLabel;
    Label74: TLabel;
    Label75: TLabel;
    Label76: TLabel;
    Label77: TLabel;
    cxComboBox1: TcxComboBox;
    Label78: TLabel;
    cxComboBox2: TcxComboBox;
    cxTextEdit14: TcxTextEdit;
    Label79: TLabel;
    Label80: TLabel;
    cxTextEdit15: TcxTextEdit;
    Label81: TLabel;
    cxTextEdit16: TcxTextEdit;
    Label82: TLabel;
    Label83: TLabel;
    cxTextEdit17: TcxTextEdit;
    Label84: TLabel;
    Label85: TLabel;
    cxTextEdit18: TcxTextEdit;
    Memo2: TMemo;
    Label86: TLabel;
    Label87: TLabel;
    Label88: TLabel;
    cxTextEdit19: TcxTextEdit;
    cxTextEdit20: TcxTextEdit;
    cxTextEdit21: TcxTextEdit;
    cxTextEdit22: TcxTextEdit;
    cxTextEdit23: TcxTextEdit;
    Label89: TLabel;
    Label90: TLabel;
    Label91: TLabel;
    cxTextEdit24: TcxTextEdit;
    Label92: TLabel;
    cxTextEdit25: TcxTextEdit;
    Label94: TLabel;
    Label95: TLabel;
    cxComboBox3: TcxComboBox;
    Label96: TLabel;
    Label97: TLabel;
    CheckBox1: TCheckBox;
    Label98: TLabel;
    cxTextEdit26: TcxTextEdit;
    Label99: TLabel;
    Label100: TLabel;
    Label101: TLabel;
    Label103: TLabel;
    cxTextEdit28: TcxTextEdit;
    cxTextEdit30: TcxTextEdit;
    Label93: TLabel;
    cxTextEdit27: TcxTextEdit;
    Label102: TLabel;
    Label104: TLabel;
    Label105: TLabel;
    Label106: TLabel;
    Label107: TLabel;
    cxTextEdit29: TcxTextEdit;
    cxTextEdit31: TcxTextEdit;
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure CustomerNoNameBtnDnClick(Sender: TObject);
    procedure v1OrderUnitPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v1PriceUnitPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure YCLFactoryBtnUpClick(Sender: TObject);
    procedure v1Column5PropertiesEditValueChanged(Sender: TObject);
    procedure HYTTBtnUpClick(Sender: TObject);
    procedure KYTTBtnUpClick(Sender: TObject);
    procedure btnConSelClick(Sender: TObject);
    procedure TV1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure v1OrderUnitPropertiesEditValueChanged(Sender: TObject);
    procedure Tv1Column4PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure cxDBImage1DblClick(Sender: TObject);
    procedure SYRNameBtnUpClick(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure TechnicsBtnDnClick(Sender: TObject);
    procedure Tv1Column1PropertiesEditValueChanged(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure N5Click(Sender: TObject);
    procedure N6Click(Sender: TObject);
    procedure ToolButton6Click(Sender: TObject);
    procedure ToolButton7Click(Sender: TObject);
    procedure CustNamePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure CustNameDblClick(Sender: TObject);
    procedure C_CodePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure OrdNoteDblClick(Sender: TObject);
    procedure QtyNotePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure OurCoNamePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure LabVolumePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure LabPackagePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure LabVolumeDblClick(Sender: TObject);
    procedure LabPackageDblClick(Sender: TObject);
    procedure FtyNamePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure ToolButton12Click(Sender: TObject);
    procedure ToolButton14Click(Sender: TObject);
    procedure TV2Column2PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure FollowerPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure TV2Column3PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormDestroy(Sender: TObject);
    procedure FormResize(Sender: TObject);
    procedure v1PRTOrderQtyPropertiesEditValueChanged(Sender: TObject);
    procedure ToolButton8Click(Sender: TObject);
    procedure TallyerPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure TallyerDblClick(Sender: TObject);
    procedure ToolButton9Click(Sender: TObject);

  private
    FSCXDH: string;
    procedure InitData();
    procedure upOrdRawQty();
    procedure ZDYHelp(FButn: TcxButtonEdit; LType: string);
    function SaveData(): Boolean;
    function getOrderNo(fconNo: string): string;
    procedure InitImage1();
    procedure InitImage2();
    procedure LookImage(FileName: string);
    procedure SetXH(CDS_PX: TClientDataSet);

    { Private declarations }
  public
    PState, CopyInt, PriceFlag: Integer;
    FMainId, FFMainId, FOrderNo: string;
    FXS: Integer;
    canshu1: string;
    fFlileFlag: string;
    { Public declarations }
  end;

var
  frmTradePlanInPut: TfrmTradePlanInPut;
  newh: hwnd;

implementation

uses
  U_DataLink, U_ZDYHelp, U_ZDYHelpSel, U_RTFun, U_TradeSalesContractSel,
  U_CompanySel, U_PictureUpload, U_ClothInfoSel, U_PatternColorHelp,
  U_TradeLabelSel, U_TradeGreyClothStkSel, U_dynamicsDll, U_printPdf,
  U_ZDYHelpSelXR, U_UserSel;


{$R *.dfm}
procedure TfrmTradePlanInPut.upOrdRawQty();
var
  FOrgQty, FShrinkageRate, FQty: Double;        //个数，单价，金额
begin

  with CDS_1 do
  begin

    FOrgQty := Fieldbyname('OrdQty').AsFloat;
    FShrinkageRate := StrToFloatDef(ShrinkageRate.Text, 0);
  end;
  FQty := RoundFloat(FOrgQty / ((100 - FShrinkageRate) / 100), 0);

  with CDS_1 do
  begin
    Edit;
    FieldByName('OrdRawQty').Value := FQty;
    Post;
  end;
  tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmTradePlanInPut.SetXH(CDS_PX: TClientDataSet);
var
  i: Integer;
begin
  with CDS_PX do
  begin
    First;
    i := 1;
    while not Eof do
    begin
      with CDS_PX do
      begin
        Edit;
        FieldByName('XHNoTemp').Value := i;
        Post;
      end;
      i := i + 1;
      Next;
    end;
  end;

  with CDS_PX do
  begin
    CDS_PX.IndexFieldNames := '';
    First;
    i := 1;
    while not Eof do
    begin
      with CDS_PX do
      begin
        Edit;
        FieldByName('SerialNo').Value := FieldByName('XHNoTemp').AsInteger;
        Post;
      end;
      i := i + 1;
      Next;
    end;
    CDS_PX.IndexFieldNames := 'SerialNo';
  end;

end;

procedure TfrmTradePlanInPut.InitImage1();
begin
  with ADO_I1 do
  begin
    close;
    sql.Clear;
    sql.Add('select * from TP_File A');
    sql.Add('where   TFID=' + quotedstr(Trim(TFID1.Text)));
    open;
  end;
end;

procedure TfrmTradePlanInPut.InitImage2();
begin
  with ADO_I2 do
  begin
    close;
    sql.Clear;
    sql.Add('select * from TP_File A');
    sql.Add('where isnull(WBID,'''')<>'''' and FileName=' + quotedstr(Trim(CDS_1.fieldbyname('AttName').AsString)));
    open;
  end;
end;

function TfrmTradePlanInPut.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 Trade_Plan_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 Trade_Plan_Main where orderNo=' + quotedstr(trim(str1)));
        open;
      end;
      if ADOCmd.IsEmpty then
        break;
    end;
  end;
  result := str1;
end;

procedure TfrmTradePlanInPut.TallyerDblClick(Sender: TObject);
begin
  self.TallyId.Text := '';
  self.Tallyer.Text := '';
end;

procedure TfrmTradePlanInPut.TallyerPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmUserSel := TfrmUserSel.Create(Application);
    with frmUserSel do
    begin
      Fdept := '理单';
      FRTUserID := Self.TallyId.Text;
      FMultiple := True;
      if ShowModal = 1 then
      begin
        self.TallyId.Text := FRTUserID;
        self.Tallyer.Text := FRTUserName;
      end;
    end;
  finally
    frmUserSel.Free;
  end;
end;

procedure TfrmTradePlanInPut.TBCloseClick(Sender: TObject);
begin

  Close;

end;

procedure TfrmTradePlanInPut.InitData();
var
  FDate: TDateTime;
begin
  FDate := SGetServerDateTime(ADOTemp);
  OrdDate.Date := FDate;
  DlyDate.Date := FDate;
  with ADOTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from Trade_Plan_Main where MainId=''' + Trim(FMainId) + '''');
    Open;
  end;
  SCSHData(ADOTemp, ScrollBox1, 1);
  SCSHData(ADOTemp, Panel1, 1);
  SCSHData(ADOTemp, ScrollBox2, 1);
  OurCoName.Properties.LookupItems.Text := Trim(ADOTemp.FieldByName('OurCoNo').AsString);
  CustName.Properties.LookupItems.Text := Trim(ADOTemp.FieldByName('CustNo').AsString);

  with ADOTemp do
  begin
    Close;
    SQL.Clear;
    sql.Add(' select *  from Trade_Plan_Sub  ');
    sql.Add(' where MainId=''' + Trim(FMainId) + '''');
    Open;
  end;
  SCSHData(ADOTemp, ScrollBox1, 2);
  SCreateCDS(ADOTemp, CDS_1);
  SInitCDSData(ADOTemp, CDS_1);

  with ADOTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from Trade_Cloth_Inspect_Rule where RuleID=''' + Trim(FMainId) + '''');
    Open;
  end;
  SCSHData(ADOTemp, Panel1, 3);

  with ADOTemp do
  begin
    Close;
    SQL.Clear;
    sql.Add(' select * from Trade_Plan_Fty  ');
    sql.Add(' where MainId=''' + Trim(FMainId) + '''');
    Open;
  end;
  SCSHData(ADOTemp, ScrollBox2, 4);
  SCSHData(ADOTemp, ScrollBox1, 4);
  FtyName.Properties.LookupItems.Text := Trim(ADOTemp.FieldByName('FtyNo').AsString);
  with ADOTemp do
  begin
    Close;
    SQL.Clear;
    sql.Add(' select *  from Trade_Plan_Technical   ');
    sql.Add(' where MainId=''' + Trim(FMainId) + '''');
    Open;
  end;
  SCreateCDS(ADOTemp, CDS_2);
  SInitCDSData(ADOTemp, CDS_2);

  if PState = 0 then
  begin
    OrdDate.Date := SGetServerDate(ADOTemp);
    DlyDate.Date := OrdDate.Date;

    OrderNo.Text := '';
    OrderNo.Enabled := True;
  end
  else
  begin
  end;
  if CopyInt = 99 then
  begin
    PState := 0;
    FMainId := '';
    OrderNo.Text := '';
    OrderNo.Enabled := True;
    OrdDate.Date := FDate;
    ClearCDSColumn(CDS_1, ['MainId', 'SubId']);
    ClearCDSColumn(CDS_2, ['MainId', 'TPTID']);
  end;
  if CopyInt = 98 then
  begin
    PState := 0;
    FMainId := '';
    ConNo.Text := '';
    OrderNo.Text := '';
    OrderNo.Enabled := True;
    OrdDate.Date := FDate;
    CDS_1.EmptyDataSet;
    ClearCDSColumn(CDS_2, ['MainId', 'TPTID']);
  end;
end;

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

procedure TfrmTradePlanInPut.FollowerPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'Follower';
      flagname := '跟单员';
      if ShowModal = 1 then
      begin
        Follower.text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;

end;

procedure TfrmTradePlanInPut.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  inherited;
  Action := cafree;
end;

procedure TfrmTradePlanInPut.FormDestroy(Sender: TObject);
begin
  inherited;
  frmTradePlanInPut := nil;
end;

procedure TfrmTradePlanInPut.FormResize(Sender: TObject);
begin
  inherited;
  if self.WindowState = wsMinimized then
    SetShowModalHide(application.MainForm.Handle, self);
end;

procedure TfrmTradePlanInPut.FormShow(Sender: TObject);
var
  i: Integer;
begin
  inherited;
  with CDS_LM do
  begin
    FieldDefs.Clear;
    FieldDefs.Add('LXH', ftInteger, 0);
    FieldDefs.Add('lCode', ftString, 40);
    FieldDefs.Add('LName', ftString, 40);
    close;
    CreateDataSet;
  end;
  with ADO_1 do
  begin
    Close;
    SQL.Clear;
    sql.Add('exec P_BS_Label_Get_Test');
    Open;
  end;
  readCxGrid(TRIM(SELF.Caption) + 'Tv1', Tv1, '生产指示单管理');
  readCxGrid(TRIM(SELF.Caption) + 'Tv2', Tv2, '生产指示单管理');
  OrderNo.Text := '';
  fFlileFlag := UserDataFlag + 'HX';
  InitData();
  InitImage1();
  InitImage2();
  if ShippingMark.text = '' then
  begin
    ShippingMark.text := 'COLOR:' + sLineBreak + 'LOT NO:' + sLineBreak + 'QUANTITY:' + sLineBreak + 'ROLL NO:' + sLineBreak + 'N/W:' + sLineBreak + 'G/W:' + sLineBreak + 'MADE IN  CHINA';
  end;

end;

procedure TfrmTradePlanInPut.FtyNamePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmCompanySel := TfrmCompanySel.Create(Application);
    with frmCompanySel do
    begin
      FCoType := '供应商';
      if ShowModal = 1 then
      begin
        self.FtyName.Properties.LookupItems.Text := Trim(frmCompanySel.CDS_1.fieldbyname('CoCode').AsString);
        self.FtyName.Text := Trim(frmCompanySel.CDS_1.fieldbyname('CoAbbrName').AsString);

      end;
    end;
  finally
    frmCompanySel.Free;
  end;
end;

function TfrmTradePlanInPut.SaveData(): Boolean;
var
  maxno, Smaxno, maxorderno, MaxFNo, MaxTFTNo: string;
begin
  try
//    ShowMessage(ADOCmd.Connection.ConnectionString);
    ADOCmd.Connection.BeginTrans;
    ///保存主表
    if Trim(FMainId) = '' then
    begin
      if GetLSNo(ADOCmd, maxno, 'JM', 'Trade_Plan_Main', 3, 1) = False then
        raise Exception.Create('取最大号失败!');
    end
    else
    begin
      maxno := Trim(FMainId);
    end;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      SQL.Add('select * from Trade_Plan_Main where MainId=''' + Trim(maxno) + '''');
      Open;
    end;

    with ADOCmd do
    begin
      if Trim(FMainId) = '' then
      begin
        Append;
        FieldByName('FillId').Value := Trim(DCode);
        FieldByName('Filler').Value := Trim(DName);
        FieldByName('MasterOrderNo').Value := Trim(OrderNo.Text);
      end
      else
      begin
        Edit;
        FieldByName('EditId').Value := Trim(DCode);
        FieldByName('Editer').Value := Trim(DName);
        FieldByName('EditTime').Value := SGetServerDateTime(ADOTemp);
      end;
      RTSetsavedata(ADOCmd, 'Trade_Plan_Main', ScrollBox1, 1);
      RTSetsavedata(ADOCmd, 'Trade_Plan_Main', Panel1, 1);
      RTSetsavedata(ADOCmd, 'Trade_Plan_Main', ScrollBox2, 1);
      FieldByName('MainId').Value := Trim(maxno);
      FieldByName('OrdType').Value := '大货单';
      FieldByName('OurCoNo').Value := Trim(OurCoName.Properties.LookupItems.Text);
      FieldByName('CustNo').Value := Trim(CustName.Properties.LookupItems.Text);
      Post;
    end;

/////////////////////               保存子表            ///////////////////////////
    with CDS_1 do
    begin
      First;
      while not Eof do
      begin
        if Trim(CDS_1.fieldbyname('SubId').AsString) = '' then
        begin
          if GetLSNo(ADOCmd, Smaxno, 'JS', 'Trade_Plan_Sub', 4, 1) = False then
            raise Exception.Create('取子流水号失败!');
        end
        else
        begin
          Smaxno := Trim(CDS_1.fieldbyname('SubId').AsString);
        end;
        with ADOCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from Trade_Plan_Sub where MainId=''' + Trim(maxno) + '''');
          sql.Add(' and SubId=''' + Trim(Smaxno) + '''');
          Open;
        end;
        with ADOCmd do
        begin
          if Trim(CDS_1.fieldbyname('SubId').AsString) = '' then
            Append
          else
            Edit;
          RTSetSaveDataCDS(ADOCmd, Tv1, CDS_1, 'Trade_Plan_Sub', 0);
          RTSetsavedata(ADOCmd, 'Trade_Plan_Sub', ScrollBox1, 2);

          FieldByName('MainId').Value := Trim(maxno);
          FieldByName('SubId').Value := Trim(Smaxno);
          FieldByName('ConSId').Value := Trim(CDS_1.fieldbyname('ConSId').AsString);
          FieldByName('ConMId').Value := Trim(CDS_1.fieldbyname('ConMId').AsString);
          Post;

        end;
        Next;
      end;
    end;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      SQL.Add('update Trade_Plan_Sub set AttName=null where MainId=''' + Trim(maxno) + '''');
      SQL.Add(' and not exists( select * from TP_File X where X.WBID=Trade_Plan_Sub.AttName )');
      ExecSQL;
    end;
/////////////////////               保存子表           ///////////////////////////
/////////////////////               保存加工厂            ///////////////////////////
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      SQL.Add('select * from Trade_Plan_Fty where TPFId=''' + Trim(maxno) + '''');
      Open;
    end;
    with ADOCmd do
    begin
      if ADOCmd.IsEmpty then
      begin
        Append;
      end
      else
        Edit;
      RTSetsavedata(ADOCmd, 'Trade_Plan_Fty', ScrollBox1, 4);
      RTSetsavedata(ADOCmd, 'Trade_Plan_Fty', ScrollBox2, 4);
      FieldByName('FtyNo').Value := Trim(FtyName.Properties.LookupItems.Text);
      FieldByName('MainId').Value := Trim(maxno);
      FieldByName('TPFId').Value := Trim(maxno);
      Post;
    end;
/////////////////////               保存加工厂           ///////////////////////////
/////////////////////               保存加工条款            ///////////////////////////
    with CDS_2 do
    begin
      First;
      while not Eof do
      begin
        if Trim(CDS_2.fieldbyname('TPTID').AsString) = '' then
        begin
          if GetLSNo(ADOCmd, MaxTFTNo, 'TF', 'Trade_Plan_Technical', 4, 1) = False then
            raise Exception.Create('取子流水号失败!');
        end
        else
        begin
          MaxTFTNo := Trim(CDS_2.fieldbyname('TPTID').AsString);
        end;
        with ADOCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from Trade_Plan_Technical where MainId=''' + Trim(maxno) + '''');
          sql.Add(' and TPTID=''' + Trim(MaxTFTNo) + '''');
          Open;
        end;
        with ADOCmd do
        begin
          if Trim(CDS_2.fieldbyname('TPTID').AsString) = '' then
            Append
          else
            Edit;

          FieldByName('MainId').Value := Trim(maxno);
          FieldByName('TPTID').Value := Trim(MaxTFTNo);
          RTSetSaveDataCDS(ADOCmd, Tv2, CDS_2, 'Trade_Plan_Technical', 0);
          Post;

        end;
        Next;
      end;
    end;
/////////////////////               保存加工条款           ///////////////////////////
///////////////       保存打卷设置       ///////////////
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      SQL.Add('select * from Trade_Cloth_Inspect_Rule where RuleID=''' + Trim(maxno) + '''');
      Open;
    end;
    with ADOCmd do
    begin
      if ADOCmd.IsEmpty then
      begin
        Append;
      end
      else
        Edit;
      RTSetsavedata(ADOCmd, 'Trade_Cloth_Inspect_Rule', Panel1, 3);
      FieldByName('RuleID').Value := Trim(maxno);
      Post;
    end;

///////////////       保存打卷设置       ///////////////

    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from Trade_Plan_Main where orderno=''' + Trim(OrderNo.Text) + '''');
      Open;
    end;
    if ADOCmd.RecordCount > 1 then
      raise Exception.Create('订单号重复!');

    with ADOCmd do
    begin
      close;
      sql.Clear;
      sql.Add('EXEC  P_Authority_Controls   ');
      sql.Add(' @DataType =''贸易计划单'' ');
      sql.Add(',@DataCode=' + quotedstr(Trim(maxno)));
      execsql;
    end;

    ADOCmd.Connection.CommitTrans;

    FMainId := Trim(maxno);

    with ADO_1 do
    begin
      Close;
      SQL.Clear;
      sql.Add(' select *  from Trade_Plan_Sub  ');
      sql.Add(' where MainId=''' + Trim(FMainId) + '''');
      Open;
    end;
    SCreateCDS(ADO_1, CDS_1);
    SInitCDSData(ADO_1, CDS_1);

    with ADO_2 do
    begin
      Close;
      SQL.Clear;
      sql.Add(' select *  from Trade_Plan_Technical   ');
      sql.Add(' where MainId=''' + Trim(FMainId) + '''');
      Open;
    end;
    SCreateCDS(ADO_2, CDS_2);
    SInitCDSData(ADO_2, CDS_2);
    Result := True;
  except
    Result := False;
    ADOCmd.Connection.RollbackTrans;
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
//    if pos('KEY 约束', Exception(ExceptObject).Message) > 0 then
//    begin
//      if GetLSNo(ADOCmd, Smaxno, 'JS', 'Trade_Plan_Sub', 4, 1) = False then
//      begin
//        Application.MessageBox('重新取子流水号失败！', '提示', 0);
//        Exit;
//      end;
//    end;
  end;
end;

procedure TfrmTradePlanInPut.TBSaveClick(Sender: TObject);
var
  MC_Code: string;
begin
  if PState <> 1 then
  begin
    ToolBar1.SetFocus;
  end;

  if CDS_1.IsEmpty then
  begin
    Application.MessageBox('明细不能为空!', '提示', 0);
    Exit;
  end;
  with CDS_1 do
  begin
    DisableControls;
    first;
    MC_Code := Trim(FieldByName('C_Code').AsString);
    while not eof do
    begin
      if MC_Code <> Trim(FieldByName('C_Code').AsString) then
      begin
        Application.MessageBox('请选择相同产品编号数据!', '提示', 0);
        Exit;
      end;
      next;
    end;
    EnableControls;
  end;
  if OrdUnit.Text = '' then
  begin
    Application.MessageBox('单位不能为空!', '提示', 0);
    Exit;
  end;
  if OrdUnit.Text = '' then
  begin
    Application.MessageBox('单位不能为空!', '提示', 0);
    Exit;
  end;
//  if OrdTYpe.Text = '' then
//  begin
//    Application.MessageBox('类型不能为空!', '提示', 0);
//    Exit;
//  end;
  if CDS_1.Locate('OrdQty', null, []) then
  begin
    Application.MessageBox('数量不能为空!', '提示', 0);
    Exit;
  end;
  if Trim(OrderNo.Text) = '' then
  begin
    with ADOTemp do
    begin
      Close;
      sql.Clear;
      SQL.Add('exec P_Trade_Plan_Get_OrdNo @ConNo=''' + Trim(ConNo.Text) + '''');
      SQL.Add(',@OrdType=''' + Trim(OrdType.Text) + '''');
      Open;
    end;
    OrderNo.Text := ADOTemp.FieldByName('OrderNo').AsString;
  end;
  if SaveData() then
  begin
    Application.MessageBox('保存成功！', '提示', 0);
//    ModalResult := 1;
  end;
end;

procedure TfrmTradePlanInPut.ToolButton12Click(Sender: TObject);
var
  i: Integer;
begin
  i := CDS_2.RecordCount;

  try
    frmZDYHelpSelXR := TfrmZDYHelpSelXR.Create(Application);
    with frmZDYHelpSelXR do
    begin

      flag := 'TPTName';
      flagname := '测试项目';
      if ShowModal = 1 then
      begin
        while ClientDataSet2.Locate('SSel', True, []) do
        begin
          with Self.CDS_2 do
          begin
            append;
            FieldByName('SSel').Value := false;
            FieldByName('SerialNo').Value := i + 1;
            FieldByName('TPTName').Value := frmZDYHelpSelXR.ClientDataSet2.FieldByName('ZDYName').AsString;
            Post;
          end;
          ClientDataSet2.Delete;
          i := i + 1
        end;
      end;
    end;
  finally
    frmZDYHelpSelXR.Free;
  end;

end;

procedure TfrmTradePlanInPut.ToolButton14Click(Sender: TObject);
begin
  if CDS_2.IsEmpty then
    Exit;
  if CDS_2.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;
  if Application.MessageBox('确定要删除选择的数据吗？', '提示', 32 + 4) <> IDYES then
    exit;
  CDS_2.DisableControls;
  with CDS_2 do
  begin
    First;
    while Locate('SSel', True, []) do
    begin
      if Trim(CDS_2.fieldbyname('TPTID').AsString) <> '' then
      begin
        with ADOCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('delete Trade_Plan_Technical where TPTID=''' + Trim(CDS_2.fieldbyname('TPTID').AsString) + '''');
          ExecSQL;
        end;
      end;
      Delete;
    end;
  end;
  CDS_2.EnableControls;
  SetXH(CDS_2);
end;

procedure TfrmTradePlanInPut.ToolButton1Click(Sender: TObject);
var
  i: Integer;
begin
  i := CDS_1.RecordCount;
  CopyAddRow(Tv1, CDS_1);
  with CDS_1 do
  begin
    Edit;
    FieldByName('SSel').Value := false;
    FieldByName('SerialNo').Value := i + 1;
    FieldByName('AttName').Value := '';
    Post;
  end;

end;

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

          sql.Add('update Trade_Plan_Sub set DelId=' + QuotedStr(Trim(DCode)) + ',Deler=' + QuotedStr(Trim(dname)) + ',Deltime=GETDATE()    ');
          sql.Add('where SubId=' + QuotedStr(Trim(CDS_1.fieldbyname('SubId').AsString)));

          sql.Add('insert into Trade_Plan_Sub_Del select * from Trade_Plan_Sub where SubId=' + QuotedStr(Trim(CDS_1.fieldbyname('SubId').AsString)));

          sql.Add('delete Trade_Plan_Sub where SubId=''' + Trim(CDS_1.fieldbyname('SubId').AsString) + '''');

          ExecSQL;
        end;
      end;
      Delete;
    end;
  end;
  CDS_1.EnableControls;
  SetXH(CDS_1);
end;

procedure TfrmTradePlanInPut.ToolButton3Click(Sender: TObject);
begin
  WriteCxGrid(TRIM(SELF.Caption) + 'Tv1', Tv1, '生产指示单管理');
  WriteCxGrid(TRIM(SELF.Caption) + 'Tv2', Tv2, '生产指示单管理');
end;

procedure TfrmTradePlanInPut.ToolButton4Click(Sender: TObject);
var
  excelApp, WorkBook: Variant;
  i, j, k, LX, ExcelRowCount: integer;
  maxId, FCPID, FCPName, t1, t2, t3, FFID: string;
begin
  try
    excelApp := CreateOleObject('Excel.Application');
    openDialog1.Filter := '*.CSV;*.xls';
    if opendialog1.Execute then
    begin
      WorkBook := excelApp.WorkBooks.Open(OpenDialog1.FileName);
    end
    else
      exit;
    excelApp.Visible := false;
    ExcelRowCount := WorkBook.WorkSheets[1].UsedRange.Rows.Count;
  except
    application.MessageBox('加载EXCEL错误！', '错误信息', MB_ICONERROR);
    exit;
  end;

  CDS_LM.EmptyDataSet;

  for j := 0 to Tv1.ColumnCount - 1 do
  begin
    with CDS_LM do
    begin
      Append;
      FieldByName('LCode').Value := trim(Tv1.Columns[j].DataBinding.FieldName);
      FieldByName('LName').Value := trim(Tv1.Columns[j].Caption);
      Post;
    end;
  end;

  try
    for i := 1 to 50 do
    begin
      if trim(WorkBook.WorkSheets[1].Cells[1, i].value) = '' then
        continue;
      if CDS_LM.Locate('LName', trim(WorkBook.WorkSheets[1].Cells[1, i].value), []) then
      begin
        with CDS_LM do
        begin
          Edit;
          FieldByName('LXH').Value := i;
          Post;
        end;
      end;
    end;
  except
    application.MessageBox('加载数组错误！', '错误信息', MB_ICONERROR);
    exit;
  end;

  try
    for i := 2 to ExcelRowCount do
    begin
      with CDS_1 do
      begin
        Append;
        CDS_LM.First;
        while not CDS_LM.Eof do
        begin
          if CDS_LM.FieldByName('LXH').AsInteger > 0 then
            CDS_1.fieldbyname(CDS_LM.FieldByName('LCode').AsString).Value := WorkBook.WorkSheets[1].Cells[i, CDS_LM.FieldByName('LXH').AsInteger].Value;
          CDS_LM.Next;
        end;
        CDS_1.FieldByName('SSel').Value := false;
        Post;
      end;
    end;
    WorkBook.Close;
    excelApp.Quit;
    excelApp := Unassigned;
    WorkBook := Unassigned;
  except
    WorkBook.Close;
    excelApp.Quit;
    excelApp := Unassigned;
    WorkBook := Unassigned;
    exit;
  end;
  SetXH(CDS_1);
end;

procedure TfrmTradePlanInPut.ToolButton5Click(Sender: TObject);
begin
  try
    frmClothInfoSel := TfrmClothInfoSel.Create(Application);
    with frmClothInfoSel do
    begin
      if ShowModal = 1 then
      begin

        with CDS_3 do
        begin

          DisableControls;
          First;

          while not eof do
          begin

            if FieldByName('SSEL').AsBoolean then
            begin
              with self.CDS_1 do
              begin
                append;
                FieldByName('SSel').Value := false;
                Fieldbyname('C_Code').value := trim(frmClothInfoSel.CDS_1.Fieldbyname('C_Code').AsString);

                self.C_Code.Text := trim(frmClothInfoSel.CDS_1.Fieldbyname('C_Code').AsString);
                self.C_Name.Text := trim(frmClothInfoSel.CDS_1.Fieldbyname('C_Name').AsString);
                self.C_EName.Text := trim(frmClothInfoSel.CDS_1.Fieldbyname('C_EName').AsString);

                self.C_Spec.Text := trim(frmClothInfoSel.CDS_1.Fieldbyname('C_Spec').AsString);
                self.C_Composition.Text := trim(frmClothInfoSel.CDS_1.Fieldbyname('C_Composition').AsString);
                self.C_EComposition.Text := trim(frmClothInfoSel.CDS_1.Fieldbyname('C_EComposition').AsString);

                self.C_Width.Text := trim(frmClothInfoSel.CDS_1.Fieldbyname('C_Width').AsString);
                self.C_GramWeight.Text := trim(frmClothInfoSel.CDS_1.Fieldbyname('C_GramWeight').AsString);
                self.GC_Name.Text := trim(frmClothInfoSel.CDS_1.Fieldbyname('GC_Name').AsString);
                self.CraftCode.Text := trim(frmClothInfoSel.CDS_1.Fieldbyname('CraftCode').AsString);
                self.CraftName.Text := trim(frmClothInfoSel.CDS_1.Fieldbyname('CraftName').AsString);
                self.CraftEName.Text := trim(frmClothInfoSel.CDS_1.Fieldbyname('CraftEName').AsString);

                Fieldbyname('C_ColorNo').value := trim(frmClothInfoSel.CDS_3.Fieldbyname('C_ColorNo').AsString);
                Fieldbyname('C_Color').value := trim(frmClothInfoSel.CDS_3.Fieldbyname('C_Color').AsString);
                Fieldbyname('C_Pattern').value := trim(frmClothInfoSel.CDS_3.Fieldbyname('C_Pattern').AsString);
                Fieldbyname('C_StyleNo').value := trim(frmClothInfoSel.CDS_3.Fieldbyname('C_StyleNo').AsString);
                Fieldbyname('SerialNo').value := 999;
              end;
            end;
            Next;
          end;
          EnableControls;
        end;

//        while CDS_1.locate('SSel', true, []) do
//        begin
//
//          with self.CDS_1 do
//          begin
//            append;
//            FieldByName('SSel').Value := false;
//            Fieldbyname('C_Code').value := trim(frmClothInfoSel.CDS_1.Fieldbyname('C_Code').AsString);
//            self.C_Name.Text := trim(frmClothInfoSel.CDS_1.Fieldbyname('C_Name').AsString);
//            self.C_EName.Text := trim(frmClothInfoSel.CDS_1.Fieldbyname('C_EName').AsString);
//
//            self.C_Spec.Text := trim(frmClothInfoSel.CDS_1.Fieldbyname('C_Spec').AsString);
//            self.C_Composition.Text := trim(frmClothInfoSel.CDS_1.Fieldbyname('C_Composition').AsString);
//            self.C_EComposition.Text := trim(frmClothInfoSel.CDS_1.Fieldbyname('C_EComposition').AsString);
//
//            self.C_Width.Text := trim(frmClothInfoSel.CDS_1.Fieldbyname('C_Width').AsString);
//            self.C_GramWeight.Text := trim(frmClothInfoSel.CDS_1.Fieldbyname('C_GramWeight').AsString);
//            self.GC_Name.Text := trim(frmClothInfoSel.CDS_1.Fieldbyname('GC_Name').AsString);
//            self.CraftCode.Text := trim(frmClothInfoSel.CDS_1.Fieldbyname('CraftCode').AsString);
//            self.CraftName.Text := trim(frmClothInfoSel.CDS_1.Fieldbyname('CraftName').AsString);
//            self.CraftEName.Text := trim(frmClothInfoSel.CDS_1.Fieldbyname('CraftEName').AsString);
//
//            Fieldbyname('C_ColorNo').value := trim(frmClothInfoSel.CDS_1.Fieldbyname('C_ColorNo').AsString);
//            Fieldbyname('C_Color').value := trim(frmClothInfoSel.CDS_1.Fieldbyname('C_Color').AsString);
//            Fieldbyname('C_Pattern').value := trim(frmClothInfoSel.CDS_1.Fieldbyname('C_Pattern').AsString);
//            Fieldbyname('SerialNo').value := 999;
//          end;
//          CDS_1.Edit;
//          CDS_1.fieldbyname('SSel').value := false;
//        end;
      end;
    end;
  finally
    frmClothInfoSel.Free;
  end;
  SetXH(CDS_1);
end;

procedure TfrmTradePlanInPut.ToolButton6Click(Sender: TObject);
var
  i: Integer;
begin
  i := CDS_1.RecordCount;
  with CDS_1 do
  begin
    Append;
    FieldByName('SSel').Value := false;
    FieldByName('SerialNo').Value := i + 1;
    FieldByName('AttName').Value := '';
    Post;
  end;
end;

procedure TfrmTradePlanInPut.ToolButton7Click(Sender: TObject);
var
  I, J, K: Integer;
begin

  K := CDS_1.RecordCount + 1;

  try
    frmPatternColorHelp := TfrmPatternColorHelp.Create(Application);
    with frmPatternColorHelp do
    begin
      if ShowModal = 1 then
      begin
        for I := STRTOINTDEF(QSHX.Text, 1) to STRTOINTDEF(JSHX.Text, 1) do
        begin
          for J := 1 to STRTOINTDEF(YSSL.Text, 1) do
          begin
            with CDS_1 do
            begin
              Append;
              FieldByName('SSel').Value := false;
              FieldByName('SerialNo').Value := K;
              if STRTOINTDEF(QSHX.Text, 0) <> 0 then
                FieldByName('C_Pattern').Value := 'D#' + inttostr(I);
              if STRTOINTDEF(YSSL.Text, 0) <> 0 then
                FieldByName('C_ColorNo').Value := 'C#' + inttostr(J);
              FieldByName('OrdPiece').Value := STRTOINTDEF(ps.Text, 0);
              FieldByName('OrdQty').Value := STRTOINTDEF(sl.Text, 0);

              FieldByName('C_GS').Value := STRTOINTDEF(GS.Text, 0);
              FieldByName('C_GL').Value := STRTOINTDEF(GL.Text, 0);
              FieldByName('OrdPiece').Value := STRTOINTDEF(GS.Text, 0) * STRTOINTDEF(GL.Text, 0);
              Post;
            end;
            K := K + 1;
          end;
        end;
        SetXH(CDS_1);
      end;
    end;
  finally
    frmPatternColorHelp.Free;
  end;
end;

procedure TfrmTradePlanInPut.ToolButton8Click(Sender: TObject);
begin
  with CDS_1 do
  begin
    DisableControls;
    First;
    while not eof do
    begin
      upOrdRawQty();
      Next;
    end;
    EnableControls;
  end;
end;

procedure TfrmTradePlanInPut.ToolButton9Click(Sender: TObject);
begin
  with ADOTemp do
  begin
    Close;
    SQL.Clear;
    sql.Add('select top 1 A.* from Trade_Plan_Main A inner join Trade_Plan_Sub B on A.Mainid=B.Mainid ');
    sql.Add(' where OrdType=''打色单''   ');
    sql.Add(' and B.C_Code=' + QuotedStr(trim(CDS_1.FieldByName('C_Code').AsString)));
    sql.Add(' order by OrdDate desc   ');
    Open;
  end;

  Feel.Text := trim(ADOTemp.FieldByName('Feel').AsString);
  LightNote.Text := trim(ADOTemp.FieldByName('LightNote').AsString);
  LightType.Text := trim(ADOTemp.FieldByName('LightType').AsString);
  ReferenceNumber.Text := trim(ADOTemp.FieldByName('ReferenceNumber').AsString);
  OtherProcess1.Text := trim(ADOTemp.FieldByName('OtherProcess1').AsString);

  OtherProcess6.Text := trim(ADOTemp.FieldByName('OtherProcess6').AsString);
  OtherProcess8.Text := trim(ADOTemp.FieldByName('OtherProcess8').AsString);
//
//
//
//
end;

procedure TfrmTradePlanInPut.TechnicsBtnDnClick(Sender: TObject);
begin
  TcxButtonEdit(Sender).Text := '';
  TcxButtonEdit(Sender).Properties.LookupItems.Text := '';
end;

procedure TfrmTradePlanInPut.CustNameDblClick(Sender: TObject);
begin
  TcxButtonEdit(Sender).Text := '';
  TcxButtonEdit(Sender).Properties.LookupItems.Text := '';
end;

procedure TfrmTradePlanInPut.CustNamePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmCompanySel := TfrmCompanySel.Create(Application);
    with frmCompanySel do
    begin
      FCoType := '客户';
      if ShowModal = 1 then
      begin
        self.CustName.Properties.LookupItems.Text := Trim(frmCompanySel.CDS_1.fieldbyname('CoCode').AsString);
        self.CustName.Text := Trim(frmCompanySel.CDS_1.fieldbyname('CoAbbrName').AsString);
      end;
    end;

  finally
    frmCompanySel.Free;
  end;
end;

procedure TfrmTradePlanInPut.CustomerNoNameBtnDnClick(Sender: TObject);
begin
  TcxButtonEdit(Sender).Text := '';
  TcxButtonEdit(Sender).Properties.LookupItems.Text := '';
end;

procedure TfrmTradePlanInPut.C_CodePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmClothInfoSel := TfrmClothInfoSel.Create(Application);
    with frmClothInfoSel do
    begin
      if ShowModal = 1 then
      begin
//        Self.C_Code.Text := trim(frmClothInfoSel.CDS_1.Fieldbyname('C_Code').AsString);
        Self.C_Name.Text := trim(frmClothInfoSel.CDS_1.Fieldbyname('C_Name').AsString);
        Self.C_Spec.Text := trim(frmClothInfoSel.CDS_1.Fieldbyname('C_Spec').AsString);
        Self.C_Composition.Text := trim(frmClothInfoSel.CDS_1.Fieldbyname('C_Composition').AsString);
        Self.C_Width.Text := trim(frmClothInfoSel.CDS_1.Fieldbyname('C_Width').AsString);
        Self.C_GramWeight.Text := trim(frmClothInfoSel.CDS_1.Fieldbyname('C_GramWeight').AsString);
      end;
    end;
  finally
    frmClothInfoSel.Free;
  end;
end;



procedure TfrmTradePlanInPut.cxDBImage1DblClick(Sender: TObject);
begin
  if TcxDBImage(Sender).Picture.Height = 0 then
    exit;
  LookImage(ADO_I1.fieldbyname(TcxDBImage(Sender).Hint).asstring);
end;

procedure TfrmTradePlanInPut.OrdNoteDblClick(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)      //inttostr(i)+'.'+
            end;
            Next;
          end;
        end;
      end;
    end;
  finally
    frmZDYHelpSel.Free;
  end;
end;

procedure TfrmTradePlanInPut.OurCoNamePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmCompanySel := TfrmCompanySel.Create(Application);
    with frmCompanySel do
    begin
      FCoType := '我司';
      if ShowModal = 1 then
      begin
        self.OurCoName.Properties.LookupItems.Text := Trim(frmCompanySel.CDS_1.fieldbyname('CoCode').AsString);
        self.OurCoName.Text := Trim(frmCompanySel.CDS_1.fieldbyname('CoAbbrName').AsString);
      end;
    end;

  finally
    frmCompanySel.Free;
  end;
end;

procedure TfrmTradePlanInPut.LabPackageDblClick(Sender: TObject);
begin
  TcxButtonEdit(Sender).Text := '';
  TcxButtonEdit(Sender).Properties.LookupItems.Text := '';

end;

procedure TfrmTradePlanInPut.LabPackagePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmTradeLabelSel := TfrmTradeLabelSel.Create(Application);
    with frmTradeLabelSel do
    begin
      if ShowModal = 1 then
      begin
        TcxButtonEdit(Sender).Text := Trim(frmTradeLabelSel.CDS_Label.fieldbyname('labelCaption').AsString);

      end;
    end;
  finally
    frmTradeLabelSel.Free;
  end;
end;

procedure TfrmTradePlanInPut.LabVolumeDblClick(Sender: TObject);
begin
  TcxButtonEdit(Sender).Text := '';
  TcxButtonEdit(Sender).Properties.LookupItems.Text := '';

end;

procedure TfrmTradePlanInPut.LabVolumePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
var
  mrecid: Integer;
  MaxBLCLID: string;
begin
  mrecid := showFr3LableForm(DCode, DName, DConString, '标签选择');
  with ADOTemp do
  begin
    close;
    sql.Clear;
    sql.Add('select top 1 * from Trade_Label');
    sql.Add('where recid=' + trim(IntToStr(mrecid)));
    Open;
  end;
  TcxButtonEdit(Sender).Text := Trim(ADOTemp.fieldbyname('LabelCaption').AsString);

  if GetLSNo(ADOCmd, MaxBLCLID, 'X', 'Bs_Report_Cloud_Log', 4, 1) = False then
  begin

    Application.MessageBox('取最大号失败！', '提示', 0);
    Exit;
  end;
  with ADOCmd do
  begin
    Close;
    SQL.Clear;
    sql.Add('select * from Bs_Report_Cloud_Log where 1=2');
    Open;
  end;
  with ADOCmd do
  begin
    Append;
    FieldByName('BLCLID').Value := MaxBLCLID;
    FieldByName('Filler').Value := dname;
    FieldByName('LMName').Value := trim(TcxButtonEdit(Sender).Text);
    FieldByName('LMSql1').Value := 'P_BS_Label_Get_Test';
    FieldByName('Filtration1').Value := Trim(FMainId);

    FieldByName('Sheets').Value := 1;
    Post;
  end;

  TFID1.Text := IntToStr(exportFile(Application, 1, PChar('title'), PChar(dcode), PChar(dname), PChar(MaxBLCLID), PChar('jpg'), PChar(DConString)));
  InitImage1();
end;

procedure TfrmTradePlanInPut.LookImage(FileName: string);
var
  sFieldName: string;
begin

  sFieldName := leftbstr(ExtractFilePath(Application.ExeName), 1) + ':\图片查看';

  if not DirectoryExists(pchar(sFieldName)) then
    CreateDirectory(pchar(sFieldName), nil);

  sFieldName := sFieldName + '\' + trim(FileName);

  try
    IdFTP1.Host := ReadINIFileStr('SYSTEMSET.INI', 'SERVER', '服务器地址', '127.0.0.1');
    IdFTP1.Username := 'three';
    IdFTP1.Password := '641010';
    IdFTP1.Connect();
  except
    ;
  end;

  if IdFTP1.Connected then
  begin
    try
      IdFTP1.Get(fFlileFlag + '\' + Trim(FileName), sFieldName, true, false);
    except
      Application.MessageBox('客户图样文件不存在', '提示', MB_ICONWARNING);
      IdFTP1.Quit;
      Exit;
    end;
  end
  else
  begin
    Application.MessageBox('无法连接文件服务器', '提示', MB_ICONWARNING);
    IdFTP1.Quit;
    Exit;
  end;
  if IdFTP1.Connected then
    IdFTP1.Quit;
  ShellExecute(Handle, 'open', PChar(sFieldName), '', '', SW_SHOWNORMAL);
end;

procedure TfrmTradePlanInPut.N5Click(Sender: TObject);
begin
  SelOKNo(CDS_1, True);
end;

procedure TfrmTradePlanInPut.N6Click(Sender: TObject);
begin
  SelOKNo(CDS_1, False);
end;

procedure TfrmTradePlanInPut.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.CDS_1.Edit;
        Self.CDS_1.FieldByName(mvalues).Value := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmTradePlanInPut.v1OrderUnitPropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FFieldName, YValue: string;
  FDDQty, FCPCDXS, FQty, FDKCQty: Double;
begin
  mvalue := TcxComboBox(Sender).EditingText;                                           //变化后单位
  FFieldName := Trim(Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName);
  with CDS_1 do
  begin

    Edit;
    FieldByName(FFieldName).Value := mvalue;
    Post;
    YValue := FieldByName('DDQtyUnit').AsString;                                        //原单位=订单单位
    FDDQty := FieldByName('DDQty').AsFloat;                                            //订单数量
    FCPCDXS := FieldByName('CPCDXS').AsFloat;
    FDKCQty := FieldByName('DKCQty').AsFloat;
    FQty := FieldByName('PRTOrderQty').AsFloat;
  end;
  if mvalue = 'Kg' then
  begin
    if YValue = 'Y' then
    begin
      FQty := FDDQty * 0.9144 / FCPCDXS;
    end;
    if YValue = 'M' then
    begin
      FQty := FDDQty / FCPCDXS;
    end;
    if YValue = 'Kg' then
    begin
      FQty := FDDQty;
    end;
  end;

  if mvalue = 'M' then
  begin
    if YValue = 'Y' then
    begin
      FQty := FDDQty * 0.9144;
    end;
    if YValue = 'Kg' then
    begin
      FQty := FDDQty * FCPCDXS;
    end;
    if YValue = 'M' then
    begin
      FQty := FDDQty;
    end;
  end;
  if mvalue = 'Y' then
  begin
    if YValue = 'M' then
    begin
      FQty := FDDQty / 0.9144;
    end;
    if YValue = 'Kg' then
    begin
      FQty := FDDQty * FCPCDXS / 0.9144;
    end;
    if YValue = 'Y' then
    begin
      FQty := FDDQty;
    end;
  end;

  with CDS_1 do
  begin
    Edit;
    FieldByName('PRTOrderQty').Value := FQty - FDKCQty;
    Post;
  end;

  Tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmTradePlanInPut.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.CDS_1.Edit;
        Self.CDS_1.FieldByName('PriceUnit').Value := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmTradePlanInPut.v1PRTOrderQtyPropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FFieldName: string;
  FOrgQty, FShrinkageRate, FQty: Double;        //个数，单价，金额
begin
  mvalue := TcxTextEdit(Sender).EditingText;
  if Trim(mvalue) = '' then
  begin
    mvalue := '0';
  end;
  FFieldName := Trim(Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName);

  with CDS_1 do
  begin
    Edit;
    FieldByName(FFieldName).Value := Trim(mvalue);
    Post;

  end;
  upOrdRawQty();
end;

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

procedure TfrmTradePlanInPut.btnConSelClick(Sender: TObject);
var
  FConMainId, FMPRTCode: string;
begin
  try
    frmTradeSalesContractSel := TfrmTradeSalesContractSel.Create(Application);
    with frmTradeSalesContractSel do
    begin
      fconNo := self.ConNo.Text;
//      fC_Code := self.C_Code.Text;
      if ShowModal = 1 then
      begin
        while CDS_1.locate('SSel', true, []) do
        begin
          if self.CDS_1.locate('ConSId', trim(CDS_1.Fieldbyname('ConSId').AsString), []) then
          begin
            CDS_1.Edit;
            CDS_1.fieldbyname('SSel').value := false;
            continue;
          end;
          self.SalesId.Text := Trim(frmTradeSalesContractSel.CDS_1.fieldbyname('SalesId').AsString);
          self.Saleser.Text := Trim(frmTradeSalesContractSel.CDS_1.fieldbyname('Saleser').AsString);
          self.TallyId.Text := Trim(frmTradeSalesContractSel.CDS_1.fieldbyname('TallyId').AsString);
          self.Tallyer.Text := Trim(frmTradeSalesContractSel.CDS_1.fieldbyname('Tallyer').AsString);

          self.BuyConNo.Text := Trim(frmTradeSalesContractSel.CDS_1.fieldbyname('BuyConNo').AsString);
          self.CustName.Properties.LookupItems.Text := Trim(frmTradeSalesContractSel.CDS_1.fieldbyname('BuyNo').AsString);
          self.CustName.Text := Trim(frmTradeSalesContractSel.CDS_1.fieldbyname('BuyName').AsString);

          self.PackNote.Text := Trim(frmTradeSalesContractSel.CDS_1.fieldbyname('PackNote').AsString);
          self.OurCoName.Properties.LookupItems.Text := Trim(frmTradeSalesContractSel.CDS_1.fieldbyname('Sellno').AsString);
          self.OurCoName.Text := Trim(frmTradeSalesContractSel.CDS_1.fieldbyname('Sellname').AsString);
//          self.OrderNo.Text := Trim(frmTradeSalesContractSel.CDS_1.fieldbyname('ConNo').AsString);
          self.ConNo.Text := Trim(frmTradeSalesContractSel.CDS_1.fieldbyname('ConNo').AsString);
          self.C_Name.Text := trim(frmTradeSalesContractSel.CDS_1.Fieldbyname('C_Name').AsString);
          self.C_EName.Text := trim(frmTradeSalesContractSel.CDS_1.Fieldbyname('C_EName').AsString);
          self.C_Spec.Text := trim(frmTradeSalesContractSel.CDS_1.Fieldbyname('C_Spec').AsString);
          self.C_Composition.Text := trim(frmTradeSalesContractSel.CDS_1.Fieldbyname('C_Composition').AsString);
          self.C_EComposition.Text := trim(frmTradeSalesContractSel.CDS_1.Fieldbyname('C_EComposition').AsString);
          self.C_Width.Text := trim(frmTradeSalesContractSel.CDS_1.Fieldbyname('C_Width').AsString);
          self.C_GramWeight.Text := trim(frmTradeSalesContractSel.CDS_1.Fieldbyname('C_GramWeight').AsString);
          self.GC_Name.Text := trim(frmTradeSalesContractSel.CDS_1.Fieldbyname('GC_Name').AsString);
          self.CraftCode.Text := trim(frmTradeSalesContractSel.CDS_1.Fieldbyname('CraftCode').AsString);
          self.CraftName.Text := trim(frmTradeSalesContractSel.CDS_1.Fieldbyname('CraftName').AsString);
          self.CraftEName.Text := trim(frmTradeSalesContractSel.CDS_1.Fieldbyname('CraftEName').AsString);
          self.ConDate.Text := trim(frmTradeSalesContractSel.CDS_1.Fieldbyname('ConDate').AsString);
          self.DlyNote.Text := trim(frmTradeSalesContractSel.CDS_1.Fieldbyname('DlyNote').AsString);

          self.OrdUnit.ItemIndex := OrdUnit.Properties.Items.IndexOf(trim(frmTradeSalesContractSel.CDS_1.fieldbyname('ConUnit').AsString));

          with self.CDS_1 do
          begin
            Append;
            FieldByName('SSel').Value := false;
            Fieldbyname('C_Code').value := trim(frmTradeSalesContractSel.CDS_1.Fieldbyname('C_Code').AsString);
            Fieldbyname('SerialNo').value := trim(frmTradeSalesContractSel.CDS_1.Fieldbyname('SerialNo').AsString);
            Fieldbyname('ConNo').value := trim(frmTradeSalesContractSel.CDS_1.Fieldbyname('ConNo').AsString);
            Fieldbyname('ConMId').value := trim(frmTradeSalesContractSel.CDS_1.Fieldbyname('ConMId').AsString);
            Fieldbyname('ConSId').value := trim(frmTradeSalesContractSel.CDS_1.Fieldbyname('ConSId').AsString);
            Fieldbyname('C_ColorNo').value := trim(frmTradeSalesContractSel.CDS_1.Fieldbyname('C_ColorNo').AsString);
            Fieldbyname('C_Color').value := trim(frmTradeSalesContractSel.CDS_1.Fieldbyname('C_Color').AsString);
            Fieldbyname('C_EColor').value := trim(frmTradeSalesContractSel.CDS_1.Fieldbyname('C_EColor').AsString);
            Fieldbyname('C_Pattern').value := trim(frmTradeSalesContractSel.CDS_1.Fieldbyname('C_Pattern').AsString);
            Fieldbyname('C_ColorConfirm').value := trim(frmTradeSalesContractSel.CDS_1.Fieldbyname('C_ColorConfirm').AsString);
            Fieldbyname('OrdQty').value := frmTradeSalesContractSel.CDS_1.Fieldbyname('ConQty').AsFloat;
            Fieldbyname('LessQty').value := frmTradeSalesContractSel.CDS_1.Fieldbyname('LessQty').value;
            Fieldbyname('MoreQty').value := frmTradeSalesContractSel.CDS_1.Fieldbyname('MoreQty').value;
            Fieldbyname('MoreLessUnit').value := frmTradeSalesContractSel.CDS_1.Fieldbyname('MoreLessUnit').value;
            Fieldbyname('C_StyleNo').value := frmTradeSalesContractSel.CDS_1.Fieldbyname('C_StyleNo').value;

            if OrdType.text <> '大货单' then
            begin
              Fieldbyname('ProcessingCost').value := frmTradeSalesContractSel.CDS_1.Fieldbyname('ConCost').value;
            end;
            Post;
          end;
          CDS_1.Edit;
          CDS_1.fieldbyname('SSel').value := false;
        end;

      end;
    end;
  finally
    frmTradeSalesContractSel.Free;
  end;
  SetXH(CDS_1);
end;

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

end;

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

procedure TfrmTradePlanInPut.Tv1Column1PropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FFieldName: string;
  FGS, FGL, FOrdPiece: Double;
  i: Integer;
begin
  mvalue := TcxTextEdit(Sender).EditingText;
  FFieldName := Trim(Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName);
  FOrdPiece := 0;
  if Trim(mvalue) = '' then
  begin
    mvalue := '0';
  end;

  with CDS_1 do
  begin
    Edit;
    FieldByName(FFieldName).Value := mvalue;
    Post;
    FGL := CDS_1.fieldbyname('C_Gl').AsFloat;
    FGS := CDS_1.fieldbyname('C_GS').AsFloat;
    FOrdPiece := CDS_1.fieldbyname('OrdPiece').AsFloat;
  end;

  if Trim(FFieldName) <> 'OrdPiece' then
  begin
    FOrdPiece := (FGS * FGL);
  end;

  with CDS_1 do
  begin
    Edit;
    FieldByName('OrdPiece').Value := FOrdPiece;
    Post;
  end;
  tv1.Controller.EditingController.ShowEdit();

end;

procedure TfrmTradePlanInPut.Tv1Column4PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin

  try
    frmPictureUpload := TfrmPictureUpload.create(self);
    with frmPictureUpload do
    begin
      fFlileFlag := self.fFlileFlag;
      FDataId := Trim(self.CDS_1.fieldbyname('AttName').AsString);
      FPictureName := Trim(self.CDS_1.fieldbyname('AttName').AsString);
      FWidth := 450;
      FHeight := 600;
      FTFType := 'HX';
      if showmodal = 1 then
      begin
        with self.CDS_1 do
        begin
          Edit;
          Fieldbyname('AttName').Value := frmPictureUpload.FPictureName;
          Post;
        end;
      end;
    end;
  finally
    frmPictureUpload.free;
  end;
end;

procedure TfrmTradePlanInPut.TV1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  InitImage2();
end;

procedure TfrmTradePlanInPut.TV2Column2PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'T1' + Trim(Self.CDS_2.fieldbyname('TPTName').AsString);
      flagname := '检测方法';
      if ShowModal = 1 then
      begin
        Self.CDS_2.Edit;
        Self.CDS_2.FieldByName('TPTType').Value := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmTradePlanInPut.TV2Column3PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      if DCode <> 'ADMIN' then
        ViewFlag := True;

      flag := 'T2' + Trim(Self.CDS_2.fieldbyname('TPTName').AsString);
      flagname := '检测方法';
      if ShowModal = 1 then
      begin
        Self.CDS_2.Edit;
        Self.CDS_2.FieldByName('TPTUnit').Value := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

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

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

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

procedure TfrmTradePlanInPut.KYTTBtnUpClick(Sender: TObject);
var
  fsj: string;
  FWZ: Integer;
begin
  fsj := Trim(TcxTextEdit(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
        TcxTextEdit(Sender).Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);

      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

end.

