unit U_ConLCInPutDC;

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, cxCurrencyEdit, cxLookAndFeels, cxLookAndFeelPainters,
  cxNavigator, dxSkinsCore, dxSkinsDefaultPainters, dxSkinscxPCPainter;

type
  TfrmConLCInPutDC = class(TForm)
    ToolBar1: TToolBar;
    TBSave: TToolButton;
    TBClose: TToolButton;
    ScrollBox1: TScrollBox;
    ADOTemp: TADOQuery;
    ADOCmd: TADOQuery;
    ADOQuery1: TADOQuery;
    Label10: TLabel;
    Label24: TLabel;
    DCNO: TEdit;
    Label18: TLabel;
    FromPlace: TBtnEditC;
    Label19: TLabel;
    TOPlace: TBtnEditC;
    Label25: TLabel;
    ChuanInfo: TBtnEditC;
    Label26: TLabel;
    HangBanName: TBtnEditC;
    ToolBar2: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column2: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    Order_Sub: TClientDataSet;
    DataSource1: TDataSource;
    Label8: TLabel;
    CYDATE: TDateTimePicker;
    Label11: TLabel;
    XYZNO: TBtnEditC;
    v1Column3: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    Label13: TLabel;
    ESCXGS: TEdit;
    v1Column1: TcxGridDBColumn;
    Label20: TLabel;
    OrdConPrcNote: TBtnEditC;
    Label23: TLabel;
    ToolButton1: TToolButton;
    Label32: TLabel;
    BGTAITOU: TBtnEditC;
    Label38: TLabel;
    fileTT: TBtnEditC;
    Label1: TLabel;
    TOCOUNTRY: TBtnEditC;
    Label5: TLabel;
    Label7: TLabel;
    KHName: TBtnEditC;
    Label9: TLabel;
    YFCF: TBtnEditC;
    Label14: TLabel;
    YSFS: TBtnEditC;
    Label15: TLabel;
    ping: TBtnEditC;
    Label16: TLabel;
    Label17: TLabel;
    SSCDGS: TEdit;
    Label27: TLabel;
    SSCGGS: TEdit;
    Label6: TLabel;
    Label12: TLabel;
    Label21: TLabel;
    HDName: TBtnEditC;
    SellNOTE: TMemo;
    Label2: TLabel;
    TDShouHuoPerson: TMemo;
    Label3: TLabel;
    TDTongZhiPerson: TMemo;
    Label4: TLabel;
    ZhuMaiTou: TMemo;
    Label22: TLabel;
    DJYQ: TMemo;
    Label28: TLabel;
    ZXPLACE: TMemo;
    Label29: TLabel;
    Note: TMemo;
    Label30: TLabel;
    v1Column5: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    v1Column14: TcxGridDBColumn;
    v1Column15: TcxGridDBColumn;
    v1Column16: TcxGridDBColumn;
    ToolButton2: TToolButton;
    BTDate: TDateTimePicker;
    DZY: TComboBox;
    YWY: TComboBox;
    BGY: TComboBox;
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure SKBankBtnDnClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure v1Column1PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure Label36DblClick(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure Label29DblClick(Sender: TObject);
    procedure Label3DblClick(Sender: TObject);
    procedure XYZNOBtnUpClick(Sender: TObject);
    procedure OrdConPrcNoteBtnUpClick(Sender: TObject);
    procedure TOPlaceBtnUpClick(Sender: TObject);
    procedure KHNameBtnUpClick(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure v1Column15PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v1Column8PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure DZYDropDown(Sender: TObject);
    procedure YWYDropDown(Sender: TObject);
    procedure BGYDropDown(Sender: TObject);
    procedure v1Column1PropertiesEditValueChanged(Sender: TObject);
  private
    procedure InitData();
    procedure ZDYHelp(FButn: TcxButtonEdit; LType: string);
    function SaveData(): Boolean;
    { Private declarations }
  public
    PState, CopyInt: Integer;
    FMainId, FFMainId: string;
    FXS: Integer;
    { Public declarations }
  end;

var
  frmConLCInPutDC: TfrmConLCInPutDC;
  newh: hwnd;

implementation

uses
  U_DataLink, U_ZDYHelp, U_Fun, U_ZDYHelpSel, U_CPBaoJiaChk, U_CPOutListCX,
  U_ProductOrderList_Sel, U_ZdyAttachment;

{$R *.dfm}

procedure TfrmConLCInPutDC.TBCloseClick(Sender: TObject);
begin
  Close;
end;

procedure TfrmConLCInPutDC.InitData();
begin
  CYDATE.DateTime := SGetServerDateTime(ADOTemp);
  BTDate.DateTime := CYDATE.DateTime;
  if PState = 0 then
  begin
    BTDate.Checked := False;
    BGY.Text := Trim(DName);
    DZY.Text := Trim(DName);
  end;
//  BTDate.Checked := False;
  with ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    sql.Add(' select * from JYOrderCon_TT_Sub ');
    if PState = 1 then
    begin
      sql.Add('where TTId=''' + Trim(FMainId) + '''');
    end;
    if PState = 0 then
    begin
      sql.Add(' where 1=2');
    end;
    Open;
  end;
  SCreateCDS20(ADOQuery1, Order_Sub);
  SInitCDSData20(ADOQuery1, Order_Sub);
  with ADOQuery1 do
  begin
    Close;
    sql.Clear;
    sql.Add('select * ');
    sql.add('from JYOrderCon_TT where TTId=''' + Trim(FMainId) + '''');
    Open;
  end;
  if ADOQuery1.IsEmpty = false then
    SCSHDataNew(ADOQuery1, ScrollBox1, 2);
  if PState <> 0 then
  begin
    DZY.Text := ADOQuery1.fieldbyname('DZY').AsString;
    YWY.Text := ADOQuery1.fieldbyname('YWY').AsString;
    BGY.Text := ADOQuery1.fieldbyname('BGY').AsString;
  end;

  if CopyInt = 99 then
  begin
    PState := 0;
    FMainId := '';
    DCNO.Text := '系统自动编码';
    OrdConPrcNote.Text := 'FOB';
    YFCF.Text := 'FREIGHT COLLECT';

    Order_Sub.DisableControls;
    with Order_Sub do
    begin
      First;
      while not Eof do
      begin
        Edit;
        FieldByName('TSID').Value := '';
        Post;
        Next;
      end;
    end;
    Order_Sub.EnableControls;
  end;
end;

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

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

function TfrmConLCInPutDC.SaveData(): Boolean;
var
  maxno, submaxno, MAXDCNO: string;
begin
  try
    ADOCmd.Connection.BeginTrans;
    ///保存主表
    if Trim(FMainId) = '' then
    begin
      if GetLSNo(ADOCmd, maxno, 'DC', 'JYOrderCon_TT', 3, 1) = False then
      begin
        ADOCmd.Connection.RollbackTrans;
        Application.MessageBox('取最大号失败!', '提示', 0);
        Exit;
      end;
    end
    else
    begin
      maxno := Trim(FMainId);
    end;
    if (Trim(DCNO.Text) = '系统自动编码') and (FMainId = '') then
    begin
      if GetLSNo(ADOCmd, MAXDCNO, 'ZY', 'JYOrderCon_TT', 3, 1) = False then
      begin
        ADOCmd.Connection.RollbackTrans;
        Application.MessageBox('取最大号失败!', '提示', 0);
        Exit;
      end;
      DCNO.Text := Trim(MAXDCNO);
    end;

    with ADOCmd do
    begin
      Close;
      sql.Clear;
      SQL.Add('select * from JYOrderCon_TT where TTId=''' + Trim(FMainId) + '''');
      Open;
    end;
    with ADOCmd do
    begin
      if Trim(FMainId) = '' then
      begin
        Append;
        fieldbyname('XGCount').Value := 0;
        fieldbyname('EditFlag').Value := '';
        fieldbyname('EditNote').Value := '';
        fieldbyname('EditSQTime').Value := NULL;
      end
      else
      begin
        Edit;
        //fieldbyname('XGCount').Value:=fieldbyname('XGCount').AsFloat+1;
      end;
      FieldByName('TTId').Value := Trim(maxno);
      fieldbyname('fillCode').Value := trim(DCode);
      SSetsaveSqlNew(ADOCmd, 'JYOrderCon_TT', ScrollBox1, 2);
      if BTDate.Checked = True then
      begin
        fieldbyname('BTDate').Value := BTDate.DateTime;
      end
      else
      begin
        fieldbyname('BTDate').Value := null;
      end;
      FieldByName('TTType').Value := 'DC';
      FieldByName('ChkStatus').Value := '';
      FieldByName('SChkFlag').Value := 0;
      if Trim(FMainId) = '' then
      begin
        //FieldByName('SKDate').Value:=SGetServerDate(ADOTemp);
        FieldByName('Filler').Value := Trim(DName);
      end
      else
      begin
        FieldByName('Editer').Value := Trim(DName);
        FieldByName('EditTime').Value := SGetServerDateTime(ADOTemp);
      end;
     // FieldByName('Note').Value:=Trim(Note.Text);
      Post;
    end;

    with Order_Sub do
    begin
      First;
      while not Eof do
      begin
        if Trim(Order_Sub.fieldbyname('TSId').AsString) = '' then
        begin
          if GetLSNo(ADOCmd, submaxno, 'DTS', 'JYOrderCon_TT_Sub', 4, 1) = False then
          begin
            ADOCmd.Connection.RollbackTrans;
            Application.MessageBox('取子流水号失败！', '提示', 0);
            Exit;
          end;
        end
        else
        begin
          submaxno := Trim(Order_Sub.fieldbyname('TSId').AsString);
        end;
        with ADOCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from JYOrderCon_TT_Sub where TSId=''' + Trim(submaxno) + '''');
          Open;
        end;
        with ADOCmd do
        begin
          if IsEmpty then
            Append
          else
            Edit;
          FieldByName('TTId').Value := Trim(maxno);
          FieldByName('TSId').Value := Trim(submaxno);
          fieldbyname('BCID').Value := Order_Sub.fieldbyname('BCID').asstring;
          FieldByName('PRTCodeName').Value := Order_Sub.fieldbyname('PRTCodeName').Value;
          FieldByName('PRTEngCodeName').Value := Order_Sub.fieldbyname('PRTEngCodeName').Value;
          FieldByName('OrderUnit').Value := Order_Sub.fieldbyname('OrderUnit').Value;
          FieldByName('PRTMF').Value := Order_Sub.fieldbyname('PRTMF').Value;
          FieldByName('PRTKZ').Value := Order_Sub.fieldbyname('PRTKZ').Value;
          RTSetSaveDataCDS(ADOCmd, Tv1, Order_Sub, 'JYOrderCon_TT_Sub', 0);
          if Trim(Order_Sub.fieldbyname('PRTOrderQty').AsString) = '' then
          begin
            fieldbyname('PRTOrderQty').Value := 0
          end
          else
          begin
            FieldByName('PRTOrderQty').Value := Order_Sub.fieldbyname('PRTOrderQty').Value;
          end;
          if Trim(Order_Sub.fieldbyname('PRTPrice').AsString) = '' then
          begin
            fieldbyname('PRTPrice').Value := 0
          end
          else
          begin
            FieldByName('PRTPrice').Value := Order_Sub.fieldbyname('PRTPrice').Value;
          end;
          Post;
        end;
        Order_Sub.Edit;
        Order_Sub.FieldByName('TSId').Value := Trim(submaxno);
        //Order_Sub.Post;
        Next;
      end;
    end;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from JYOrderCon_TT where DCNO=''' + Trim(DCNO.Text) + '''');
      Sql.Add(' and TTType=''DC''');
      Open;
    end;
    if ADOCmd.RecordCount > 1 then
    begin
      ADOCmd.Connection.RollbackTrans;
      Application.MessageBox('订舱编号重复!', '提示', 0);
      Exit;
    end;
    {with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('UPdate JYOrderCon_TT Set SChkFlag=0,SChkStatus='''' where TTID='''+Trim(maxno)+'''');
      //sql.add(' delete OrdConDanZH_Chk where MainId='''+Trim(maxno)+'''');
      ExecSQL;
    end; }
//    with ADOCmd do
//    begin
//      Close;
//      sql.Clear;
//      sql.Add('delete from OrdConDanZH_Chk where MainId=''' + Trim(FMainId) + '''');
//      execsql;
//    end;
    ADOCmd.Connection.CommitTrans;
    FMainId := Trim(maxno);
    Result := True;
  except
    Result := False;
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！', '提示', 0);
  end;
end;

procedure TfrmConLCInPutDC.TBSaveClick(Sender: TObject);
var
  FReal: Double;
begin
  ToolBar1.SetFocus;

//  if Note.Text = '' then
//  begin
//    application.MessageBox('备注不能为空', '提示');
//    exit;
//  end;
//  if FPTaiTou.Text = '' then
//  begin
//    application.MessageBox('发货人不能为空', '提示');
//    exit;
//  end;
  if FMainId <> '' then
  begin
    with ADOTemp do
    begin
      Close;
      SQL.Clear;
      sql.Add('select * from JYOrderCon_TT where TTId=''' + Trim(FMainId) + '''');
      Open;
    end;
    if (Trim(ADOTemp.FieldByName('ChkStatus').AsString) = '审核通过') or (Trim(ADOTemp.FieldByName('ChkStatus').AsString) = '单据修改') then
    begin
      Application.MessageBox('已审核不能修改!', '提示', 0);
      Exit;
    end
    else if Trim(ADOTemp.FieldByName('ChkStatus').AsString) = '' then
    begin
      if ADOTemp.FieldByName('SChkFlag').AsBoolean = True then
      begin
        Application.MessageBox('审核中不能修改!', '提示', 0);
        Exit;
      end;

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

procedure TfrmConLCInPutDC.SKBankBtnDnClick(Sender: TObject);
begin
  TBtnEditC(Sender).Text := '';
  TBtnEditC(Sender).TxtCode := '';
end;

procedure TfrmConLCInPutDC.TBRafreshClick(Sender: TObject);
begin
  with Order_Sub do
  begin
    Append;
    FieldByName('BZUNIT').value := 'BALES';
    Post;
  end;
end;

procedure TfrmConLCInPutDC.TBFindClick(Sender: TObject);
begin
  if Trim(Order_Sub.fieldbyname('TSId').AsString) <> '' then
  begin
    if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
      Exit;
    with ADOCmd do
    begin
      Close;
      SQL.Clear;
      SQL.Add('Delete from JYOrderCon_TT_Sub where TSId=''' + Trim(Order_Sub.fieldbyname('TSId').AsString) + '''');
      ExecSQL;
    end;
  end;
  Order_Sub.Delete;
end;

procedure TfrmConLCInPutDC.v1Column1PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'SYiDuanZ';
      flagname := '溢短装';
      if ShowModal = 1 then
      begin
        Self.Order_Sub.Edit;
        Self.Order_Sub.FieldByName('SYiDuanZ').Value := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmConLCInPutDC.Label36DblClick(Sender: TObject);
begin
  try
    frmZDYHelpSel := TfrmZDYHelpSel.Create(Application);
    with frmZDYHelpSel do
    begin
      flag := 'LbNameNote';
      flagname := '标签内容';
      if ShowModal = 1 then
      begin
        ClientDataSet1.DisableControls;
        with ClientDataSet1 do
        begin
          First;
          while not Eof do
          begin
            if ClientDataSet1.FieldByName('SSel').AsBoolean = True then
            begin
              if Trim(Self.ZhuMaiTou.Text) = '' then
              begin
                Self.ZhuMaiTou.Text := Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
              end
              else
              begin
                Self.ZhuMaiTou.Text := Self.ZhuMaiTou.Text + #13 + Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
              end;

            end;
            Next;
          end;
        end;
        ClientDataSet1.EnableControls;
      end;
    end;
  finally
  end;
end;

procedure TfrmConLCInPutDC.ToolButton1Click(Sender: TObject);
begin
  if Order_Sub.IsEmpty then
    Exit;
  CopyAddRowCDS(Order_Sub);
  with Order_Sub do
  begin
    Edit;
    FieldByName('TSID').Value := null;
    Post;
  end;
end;

procedure TfrmConLCInPutDC.Label29DblClick(Sender: TObject);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'TDShouHuoPerson';
      flagname := '提单收货人';
      if ShowModal = 1 then
      begin
        TDShouHuoPerson.Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmConLCInPutDC.Label3DblClick(Sender: TObject);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'TDTongZhiPerson';
      flagname := '提单通知人';
      if ShowModal = 1 then
      begin
        TDTongZhiPerson.Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmConLCInPutDC.XYZNOBtnUpClick(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(DParameters1) <> '高权限' then
      begin
        TBAdd.Visible := false;
        TBDel.Visible := false;
        TBEdit.Visible := false;
        TBSave.Visible := false;
      end;
      if ShowModal = 1 then
      begin
        TEdit(Sender).Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmConLCInPutDC.OrdConPrcNoteBtnUpClick(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 flag = 'TOCOUNTRY' then
      begin
        fnote := True;
        V1Note.Caption := '中文名称';
        V1Name.Caption := '英文名称';
      end
      else
      begin
        fnote := false;
      end;

      if ShowModal = 1 then
      begin
        TEdit(Sender).Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
  if (OrdConPrcNote.Text = 'FOB') or (OrdConPrcNote.Text = 'FCA') then
  begin
    YFCF.Text := 'FREIGHT COLLECT';

  end
  else if (OrdConPrcNote.Text = 'CIF') or (OrdConPrcNote.Text = 'CFR') then
  begin
    YFCF.Text := 'FREIGHT PREPAID';
  end;
end;

procedure TfrmConLCInPutDC.TOPlaceBtnUpClick(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 flag = 'TOCOUNTRY' then
      begin
        fnote := True;
        V1Note.Caption := '中文名称';
        V1Name.Caption := '英文名称';
      end
      else
      begin
        fnote := false;
      end;

      if ShowModal = 1 then
      begin
        TEdit(Sender).Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmConLCInPutDC.KHNameBtnUpClick(Sender: TObject);
begin
  try
    frmZdyAttachment := TfrmZdyAttachment.Create(Application);
    with frmZdyAttachment do
    begin

      if ShowModal = 1 then
      begin
        self.KHName.TxtCode := Trim(CDS_HZ.fieldbyname('CoCode').AsString);
        self.KHName.Text := Trim(CDS_HZ.fieldbyname('CoName').AsString);

        TDShouHuoPerson.Text := Trim(CDS_HZ.fieldbyname('CoName').AsString) + #$d#$a + (StringReplace(CDS_HZ.fieldbyname('CoAddress').AsString, '  ', #$d#$a, [rfReplaceAll]));
        TDTongZhiPerson.Text := Trim(CDS_HZ.fieldbyname('CoName').AsString) + #$d#$a + (StringReplace(CDS_HZ.fieldbyname('CoAddress').AsString, '  ', #$d#$a, [rfReplaceAll]));

      end;
    end;
  finally
    frmZdyAttachment.Free;
  end;
end;

procedure TfrmConLCInPutDC.ToolButton2Click(Sender: TObject);
begin
  frmProductOrderList_Sel := TfrmProductOrderList_Sel.Create(self);
  with frmProductOrderList_Sel do
  begin
    if showmodal = 1 then
    begin
      while frmProductOrderList_Sel.Order_Main.Locate('SSel', True, []) do
      begin
        Self.Order_Sub.Append;

        Self.Order_Sub.FieldbyName('PRTPrice').Value := 0;
        Self.Order_Sub.FieldbyName('Money').Value := 0;
        Self.Order_Sub.fieldbyname('FromOrderno').Value := Order_Main.fieldbyname('Orderno').asstring;
        Self.Order_Sub.fieldbyname('FromMainId').Value := Order_Main.fieldbyname('MainId').asstring;
        Self.Order_Sub.fieldbyname('PRTCODE').Value := Order_Main.fieldbyname('MPRTCODE').asstring;
        Self.Order_Sub.fieldbyname('PRTCODENAME').Value := Order_Main.fieldbyname('MPRTCODENAME').asstring;
        Self.Order_Sub.fieldbyname('PRTMF').Value := Order_Main.fieldbyname('MPRTMF').asstring;
        Self.Order_Sub.fieldbyname('PRTKZ').Value := Order_Main.fieldbyname('MPRTKZ').asstring;
        Self.Order_Sub.fieldbyname('PRTCF').Value := Order_Main.fieldbyname('MPRTCF').asstring;
        Self.Order_Sub.fieldbyname('PRTORDERQTY').Value := Order_Main.fieldbyname('PRTORDERQTY').ASFLOAT;
        Self.Order_Sub.FieldByName('BZUNIT').value := 'BALES';
        Self.Order_Sub.Post;
        frmProductOrderList_Sel.Order_Main.Delete;
      end;
    end;
    free;
  end;
end;

procedure TfrmConLCInPutDC.v1Column15PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
//  fsj := Trim(TEdit(Sender).Hint);
//  FWZ := Pos('/', fsj);
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'BZUNIT';
      flagname := '包装单位';
      if ShowModal = 1 then
      begin
        with Order_Sub do
        begin
          Edit;
          Order_Sub.fieldbyname('BZUNIT').Value := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        end;

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

procedure TfrmConLCInPutDC.v1Column8PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'PRICEBZ';
      flagname := '币种';
      if ShowModal = 1 then
      begin
        with Order_Sub do
        begin
          Edit;
          Order_Sub.fieldbyname('PRICEBZ').Value := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        end;

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

procedure TfrmConLCInPutDC.DZYDropDown(Sender: TObject);
begin
  with ADOTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('SELECT * FROM SY_User WHERE Udept LIKE ''%单证%'' ');

    Open;
  end;
  DZY.Items.Clear;
  while not ADOTemp.eof do
  begin
    DZY.Items.Add(Trim(ADOTemp.fieldbyname('username').AsString));
    ADOTemp.next;
  end;
end;

procedure TfrmConLCInPutDC.YWYDropDown(Sender: TObject);
begin
  with ADOTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from KH_ZDY where type=''jhdywy'' ');

    Open;
  end;
  YWY.Items.Clear;
  while not ADOTemp.eof do
  begin
    YWY.Items.Add(Trim(ADOTemp.fieldbyname('zdyname').AsString));
    ADOTemp.next;
  end;
end;

procedure TfrmConLCInPutDC.BGYDropDown(Sender: TObject);
begin
  with ADOTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('SELECT * FROM SY_User WHERE Udept LIKE ''%单证%'' ');

    Open;
  end;
  BGY.Items.Clear;
  while not ADOTemp.eof do
  begin
    BGY.Items.Add(Trim(ADOTemp.fieldbyname('username').AsString));
    ADOTemp.next;
  end;
end;

procedure TfrmConLCInPutDC.v1Column1PropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FFieldName: string;
  FQuantity, FUnitPrice, FCourierCharge: double;
begin
  if TcxTextEdit(Sender).EditingText = '' then
  begin
    mvalue := '0';
  end
  else
    mvalue := TcxTextEdit(Sender).EditingText;
  FFieldName := Trim(Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName);
  with Order_Sub do
  begin
    Edit;
    FieldByName(FFieldName).Value := Trim(mvalue);
    Post;

    FQuantity := FieldByName('PRTOrderQty').asfloat;
    FUnitPrice := FieldByName('PRTPrice').asfloat;
  end;

  with Order_Sub do
  begin
    Edit;
    FieldByName('MONEY').Value := (FQuantity * FUnitPrice);
    Post;
  end;

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

end.

