unit U_YFGLInPut;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
  cxEdit, DB, cxDBData, cxCalendar, cxDropDownEdit, ComCtrls, ToolWin,
  cxGridLevel, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
  cxClasses, cxControls, cxGridCustomView, cxGrid, cxGridCustomPopupMenu,
  cxGridPopupMenu, ADODB, DBClient, cxButtonEdit, cxTextEdit, StdCtrls, BtnEdit,
  ExtCtrls, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator;

type
  TfrmYFGLInPut = class(TForm)
    ToolBar1: TToolBar;
    TBSave: TToolButton;
    TBClose: TToolButton;
    DataSource3: TDataSource;
    CDS_Sub: TClientDataSet;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    cxGridPopupMenu2: TcxGridPopupMenu;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column5: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    Panel1: TPanel;
    ToolBar2: TToolBar;
    ToolButton2: TToolButton;
    ToolButton3: TToolButton;
    Label13: TLabel;
    A4FPNO: TEdit;
    Label4: TLabel;
    huodai: TEdit;
    Label5: TLabel;
    BGTAITOU: TBtnEditA;
    Label8: TLabel;
    HUODAIFPNO: TEdit;
    Label15: TLabel;
    SHFS: TBtnEditA;
    Label22: TLabel;
    v1Column13: TcxGridDBColumn;
    v1Column14: TcxGridDBColumn;
    ToolButton1: TToolButton;
    v1Column20: TcxGridDBColumn;
    Label28: TLabel;
    Label30: TLabel;
    HTDate: TDateTimePicker;
    v1YSKeZhong: TcxGridDBColumn;
    NOTE: TMemo;
    Label6: TLabel;
    YWY: TComboBox;
    Label7: TLabel;
    chuandate: TDateTimePicker;
    ORDERNO: TBtnEditA;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    Tv1Column3: TcxGridDBColumn;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure v1Column5PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v1Column14PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v1Column16PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v1Column17PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v1Column3PropertiesEditValueChanged(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure v1ZZJGouPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v1Column12PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure TCXLJClick(Sender: TObject);
    procedure B6ChuYunGangBtnClick(Sender: TObject);
    procedure YWYDropDown(Sender: TObject);
    procedure Tv1Column5PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure Tv1Column12PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure Tv1Column14PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure Tv1Column13PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure Tv1Column9PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure Tv1Column7PropertiesEditValueChanged(Sender: TObject);
    procedure Tv1CustomDrawIndicatorCell(Sender: TcxGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxCustomGridIndicatorItemViewInfo; var ADone: Boolean);
    procedure ORDERNOBtnClick(Sender: TObject);
  private
    { Private declarations }
    function SaveCKData(): Boolean;
  public
    { Public declarations }
    FBCId, canshu3: string;
    CopyStr: string;
  end;

var
  frmYFGLInPut: TfrmYFGLInPut;

implementation

uses
  U_DataLink, U_RTFun, U_ZDYHelp, U_ZdyAttachment, U_ProductOrderList_Sel,
  U_DCDList_Sel, U_ZdyAttachGYS;

{$R *.dfm}

procedure TfrmYFGLInPut.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caFree;
end;

function TfrmYFGLInPut.SaveCKData(): Boolean;
var
  FJMID, Maxno, MaxSubNo, FSCID: string;
begin
  try
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from FP_MAIN where FPID=''' + Trim(FBCId) + '''');
      Open;
    end;
    FBCId := Trim(ADOQueryTemp.fieldbyname('FPID').AsString);
    if Trim(FBCId) = '' then
    begin
      if GetLSNo(ADOQueryCmd, Maxno, 'FP', 'FP_MAIN', 3, 1) = False then
      begin
        Result := False;
        ADOQueryCmd.Connection.RollbackTrans;
        Application.MessageBox('取主编号失败!', '提示', 0);
        Exit;
      end;
    end
    else
    begin
      Maxno := Trim(FBCId);
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from FP_MAIN where FPID=''' + Trim(Maxno) + '''');
      Open;
    end;
    with ADOQueryCmd do
    begin
      if Trim(FBCId) = '' then
      begin
        Append;
        FieldByName('Filler').Value := Trim(DName);
        FieldByName('FillerCode').Value := Trim(DCode);
        FieldByName('FKstatus').Value := '未付款';
      end
      else
      begin
        Edit;
        FieldByName('Editer').Value := Trim(DName);
        FieldByName('EditerCode').Value := Trim(DCode);
        FieldByName('EditTime').Value := SGetServerDate(ADOQueryTemp);
      end;
      FieldByName('FPID').Value := Trim(Maxno);
      RTSetsavedata(ADOQueryCmd, 'JYOrder_BaoGuan_Main', Panel1, 1);
      RTSetsavedata(ADOQueryCmd, 'JYOrder_BaoGuan_Main', Panel1, 2);
      Post;
    end;
//    with ADOQueryTemp do
//    begin
//      Close;
//      sql.Clear;
//      sql.Add('select * from FP_MAIN where A4FPNO=''' + Trim(A4FPNO.Text) + ''' and Valid=''Y'' ');
//      Open;
//    end;
//    if ADOQueryTemp.RecordCount > 1 then
//    begin
//      ADOQueryCmd.Connection.RollbackTrans;
//      Application.MessageBox('此发票号已经被使用，不能保存!', '提示', 0);
//      Exit;
//    end;
    CDS_Sub.DisableControls;
    with CDS_Sub do
    begin
      First;
      while not eof do
      begin
        with ADOQueryTemp do
        begin
          Close;
          sql.Clear;
          sql.Add('select * from FP_SUB where FPSId=''' + Trim(CDS_Sub.fieldbyname('FPSId').AsString) + '''');
          Open;
        end;
        FSCID := Trim(ADOQueryTemp.fieldbyname('FPSId').AsString);
        if Trim(FSCID) = '' then
        begin
          if GetLSNo(ADOQueryCmd, MaxSubNo, 'FPS', 'FP_SUB', 3, 1) = False then
          begin
            Result := False;
            ADOQueryCmd.Connection.RollbackTrans;
            Application.MessageBox('取子编号失败!', '提示', 0);
            Exit;
          end;
        end
        else
        begin
          MaxSubNo := Trim(FSCID);
        end;
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('select * from FP_SUB where FPSId=''' + Trim(MaxSubNo) + '''');
          Open;
        end;
        with ADOQueryCmd do
        begin
          if Trim(FSCID) = '' then
          begin
            Append;
//            FieldByName('SFiller').Value := Trim(DName);
          end
          else
          begin
            Edit;
//            FieldByName('SEditer').Value := Trim(DName);
//            FieldByName('SEditTime').Value := SGetServerDate(ADOQueryTemp);
          end;
          FieldByName('FPId').Value := Trim(Maxno);
          FieldByName('FPSId').Value := Trim(MaxSubNo);
          RTSetSaveDataCDS(ADOQueryCmd, Tv1, CDS_Sub, 'FP_SUB', 2);
          Post;
        end;
        Edit;
        FieldByName('FPId').Value := Trim(Maxno);
        FieldByName('FPSId').Value := Trim(MaxSubNo);
        Post;
        Next;
      end;
    end;

    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('UPdate FP_MAIN Set ');
      sql.Add(' SCDJDate= getdate()');
      sql.Add(' where isnull(SCDJDate,'''')='''' and FPId=''' + Trim(Maxno) + '''');
      ExecSQL;
    end;
    CDS_Sub.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;
    FBCId := Trim(Maxno);
    Result := True;
  except
    Result := False;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('保存异常!', '提示', 0);
  end;

end;

procedure TfrmYFGLInPut.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('运费管理录入', Tv1, '报关管理13');
  Close;
end;

procedure TfrmYFGLInPut.FormShow(Sender: TObject);
begin
  ReadCxGrid('运费管理录入', Tv1, '报关管理13');

  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add(' select A.* ');
    sql.Add(' from FP_MAIN A');
    sql.Add(' where FPID=''' + Trim(FBCId) + '''');
    Open;
  end;
  SCSHDataNew(ADOQueryTemp, Panel1, 1);
  SCSHDataNew(ADOQueryTemp, Panel1, 2);
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add(' select A.* ');
    sql.Add(' from FP_SUB A');
    sql.Add(' where FPID=''' + Trim(FBCId) + '''');
//    sql.Add(' and SValid=''Y'' ');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp, CDS_Sub);
  SInitCDSData20(ADOQueryTemp, CDS_Sub);
  if CopyStr = '99' then
  begin
    FBCId := '';
    CDS_Sub.DisableControls;
    with CDS_Sub do
    begin
      First;
      while not Eof do
      begin
        Edit;
        FieldByName('FPID').Value := Null;
        FieldByName('FPSID').Value := Null;
        Post;
        Next;
      end;
    end;
    CDS_Sub.EnableControls;
  end;
  if Trim(FBCId) = '' then
  begin
    YWY.Text := Trim(DName);
    HTDate.Date := SGetServerDate(ADOQueryTemp);
    chuandate.Date := SGetServerDate(ADOQueryTemp);
  end;

end;

procedure TfrmYFGLInPut.TBSaveClick(Sender: TObject);
var
  FReal: Double;
  i: Integer;
begin
//
//  if TryStrToFloat(F2YunFee.Text, FReal) = False then
//  begin
//    Application.MessageBox('运费非法数字!', '提示', 0);
//    Exit;
//  end;
//  if TryStrToFloat(F3BaoFee.Text, FReal) = False then
//  begin
//    Application.MessageBox('保费非法数字!', '提示', 0);
//    Exit;
//  end;
//  if CDS_Sub.IsEmpty then
//  begin
//    Application.MessageBox('明细不能为空!', '提示', 0);
//    Exit;
//  end;
//  if CDS_Sub.Locate('C3BGName', Null, []) then
//  begin
//    Application.MessageBox('品名不能为空!', '提示', 0);
//    Exit;
//  end;
  if Trim(A4FPNO.Text) = '' then
  begin
    Application.MessageBox('发票号不能为空!', '提示', 0);
    Exit;
  end;
//  if CDS_Sub.Locate('C4BGQty', Null, []) then
//  begin
//    Application.MessageBox('数量不能为空!', '提示', 0);
//    Exit;
//  end;
//  if CDS_Sub.Locate('C5BGUnit', Null, []) then
//  begin
//    Application.MessageBox('单位不能为空!', '提示', 0);
//    Exit;
//  end;
//  if CDS_Sub.Locate('C6BGPrice', Null, []) then
//  begin
//    Application.MessageBox('单价不能为空!', '提示', 0);
//    Exit;
//  end;


  ToolBar1.SetFocus;
  if SaveCKData() then
  begin
    Application.MessageBox('保存成功!', '提示', 0);
    //ModalResult:=1;
    Exit;
  end;
end;

procedure TfrmYFGLInPut.ToolButton2Click(Sender: TObject);
var
  i: Integer;
begin
//  CopyAddRowCDS(CDS_Sub);
  with CDS_Sub do
  begin
    Append;
    FieldByName('FPID').Value := Null;
    FieldByName('FPSID').Value := Null;
    FieldByName('FYMONEY').Value := 0;
    FieldByName('FYYFMONEY').Value := 0;
    FieldByName('FYBZ').Value := '人民币';
    FieldByName('FYXM').Value := '海运费';
    FieldByName('YCMONEY').Value := 0;

    Post;
  end;

end;

procedure TfrmYFGLInPut.ToolButton3Click(Sender: TObject);
begin
  if CDS_Sub.IsEmpty then
    Exit;
  if Trim(CDS_Sub.fieldbyname('FPSID').AsString) <> '' then
  begin
    if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
      Exit;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      SQL.Add('DELETE FP_SUB  ');
      sql.Add(' where FPSID=''' + Trim(CDS_Sub.fieldbyname('BSID').AsString) + '''');
      ExecSQL;
    end;

  end;
  CDS_Sub.Delete;
end;

procedure TfrmYFGLInPut.v1Column5PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'C3BGName';
      flagname := '报关品名';
      if ShowModal = 1 then
      begin
        with Self.CDS_Sub do
        begin
          Edit;
          FieldByName('C3BGName').Value := Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
        with ADOQueryTemp do
        begin
          Close;
          sql.Clear;
          sql.Add('select Top 1 * from JYOrder_BaoGuan_Sub where C3BGName=''' + Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZDYName').AsString) + '''');
          sql.add(' and isnull(C2HSNO,'''')<>'''' ');
          sql.Add(' order by SFillTime desc');
          Open;
        end;
        with Self.CDS_Sub do
        begin
          Edit;
          FieldByName('C2HSNO').Value := Trim(ADOQueryTemp.fieldbyname('C2HSNO').asstring);
          FieldByName('C3BGNameEng').Value := Trim(ADOQueryTemp.fieldbyname('C3BGNameEng').asstring);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmYFGLInPut.v1Column14PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'YSChenFen';
      flagname := '成分含量';
      if ShowModal = 1 then
      begin
        with Self.CDS_Sub do
        begin
          Edit;
          FieldByName('YSChenFen').Value := Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmYFGLInPut.v1Column16PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'YSPinPai';
      flagname := '品牌';
      if ShowModal = 1 then
      begin
        with Self.CDS_Sub do
        begin
          Edit;
          FieldByName('YSPinPai').Value := Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmYFGLInPut.v1Column17PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'YSShengChanShang';
      flagname := '生产商';
      if ShowModal = 1 then
      begin
        with Self.CDS_Sub do
        begin
          Edit;
          FieldByName('YSShengChanShang').Value := Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmYFGLInPut.v1Column3PropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FName, FPrice, FQty, FBaoGangFee: string;
begin
  FName := Trim(Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName);
  mvalue := TcxTextEdit(Sender).EditingText;
  if Trim(mvalue) = '' then
  begin
    mvalue := '0';
  end;
  with CDS_Sub do
  begin
    Edit;
    FieldByName(FName).Value := mvalue;
    Post;
  end;
  FPrice := Trim(CDS_Sub.fieldbyname('C6BGPrice').AsString);
  FQty := Trim(CDS_Sub.fieldbyname('C4BGQty').AsString);
  if Trim(FPrice) = '' then
  begin
    FPrice := '0';
  end;
  if Trim(FQty) = '' then
  begin
    FQty := '0';
  end;
  with CDS_Sub do
  begin
    Edit;
    FieldByName('C7BGMoney').Value := StrToFloat(FPrice) * StrToFloat(FQty);
    Post;
  end;
end;

procedure TfrmYFGLInPut.ToolButton1Click(Sender: TObject);
begin
  if CDS_Sub.IsEmpty then
    Exit;
  OneKeyPost(Tv1, CDS_Sub);
end;

procedure TfrmYFGLInPut.ToolButton4Click(Sender: TObject);
var
  fsj: string;
begin
  if FBCId = '' then
    Exit;
  if Application.MessageBox('确定要执行审核操作吗？', '提示', 32 + 4) <> IDYES then
    Exit;

  try

    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('UPdate JYOrder_BaoGuan_Main Set Status=''已审核'',ChkTime=getdate(),Chker=''' + Trim(DName) + '''');
      sql.Add(' where BGID=''' + Trim(FBCId) + '''');
      ExecSQL;
    end;
    Application.MessageBox('操作成功!', '提示', 0);
  except

    Application.MessageBox('操作异常!', '提示', 0);
  end;

end;

procedure TfrmYFGLInPut.v1ZZJGouPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'ZZJGou';
      flagname := '组织结构';
      if ShowModal = 1 then
      begin
        with Self.CDS_Sub do
        begin
          Edit;
          FieldByName('ZZJGou').Value := Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmYFGLInPut.v1Column12PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'E5MaiTou';
      flagname := '唛头';
      if ShowModal = 1 then
      begin
        with Self.CDS_Sub do
        begin
          Edit;
          FieldByName('E5MaiTou').Value := Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmYFGLInPut.TCXLJClick(Sender: TObject);
begin
  if not Assigned(DataLink_DDMD) then
    DataLink_DDMD := TDataLink_DDMD.Create(Application);
  try
    with DataLink_DDMD.ADOLink do
    begin
      //if not Connected then
      begin
        Connected := false;
        ConnectionString := DConString;
        LoginPrompt := false;
        Connected := true;
      end;
    end;
  except
    application.MessageBox('数据库连接失败！', '错误', mb_Ok + MB_ICONERROR);
  end;
end;

procedure TfrmYFGLInPut.B6ChuYunGangBtnClick(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 TfrmYFGLInPut.YWYDropDown(Sender: TObject);
begin
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('SELECT * FROM SY_User WHERE Udept LIKE ''%客服%'' ');

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

procedure TfrmYFGLInPut.Tv1Column5PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZdyAttachGYS := tfrmZdyAttachGYS.Create(Application);
    with frmZdyAttachGYS do
    begin

      if ShowModal = 1 then
      begin
        with CDS_Sub do
        begin
          Edit;
          fieldbyname('gcdm').Value := Trim(CDS_HZ.fieldbyname('CoCode').AsString);
          fieldbyname('gcname').Value := Trim(CDS_HZ.fieldbyname('CoName').AsString);
          fieldbyname('gcaddress').Value := Trim(CDS_HZ.fieldbyname('Coaddress').AsString);
        end;

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

procedure TfrmYFGLInPut.Tv1Column12PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'zzff';
      flagname := '织造方法';
      if ShowModal = 1 then
      begin
        with CDS_Sub do
        begin
          edit;
          fieldbyname('zzff').AsString := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        end;

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

procedure TfrmYFGLInPut.Tv1Column14PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'wenlu';
      flagname := '纹路';
      if ShowModal = 1 then
      begin
        with CDS_Sub do
        begin
          edit;
          fieldbyname('wl').AsString := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        end;

      end;
    end;
  finally
    frmZDYHelp.Free;
  end;

end;

procedure TfrmYFGLInPut.Tv1Column13PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'GYLX';
      flagname := '工艺类型';
      if ShowModal = 1 then
      begin
        with CDS_Sub do
        begin
          edit;
          fieldbyname('gylx').AsString := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        end;

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

procedure TfrmYFGLInPut.Tv1Column9PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'JSUNIT';
      flagname := '件数单位';
      if ShowModal = 1 then
      begin
        with CDS_Sub do
        begin
          edit;
          fieldbyname('JSUNIT').AsString := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        end;

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

procedure TfrmYFGLInPut.Tv1Column7PropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FName, FPrice, FQty, FBaoGangFee: string;
begin
  FName := Trim(Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName);
  mvalue := TcxTextEdit(Sender).EditingText;
  if Trim(mvalue) = '' then
  begin
    mvalue := '0';
  end;
  with CDS_Sub do
  begin
    Edit;
    FieldByName(FName).Value := mvalue;
    Post;
  end;
end;

procedure TfrmYFGLInPut.Tv1CustomDrawIndicatorCell(Sender: TcxGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxCustomGridIndicatorItemViewInfo; var ADone: Boolean);
var
  FValue: string;
  FBounds: TRect;
begin
  FBounds := AViewInfo.Bounds;
  if (AViewInfo is TcxGridIndicatorRowItemViewInfo) then
  begin
    ACanvas.FillRect(FBounds);
    ACanvas.DrawComplexFrame(FBounds, clBtnHighlight, clBtnShadow, [bBottom, bLeft, bRight], 1);
    FValue := IntToStr(TcxGridIndicatorRowItemViewInfo(AViewInfo).GridRecord.Index + 1);
    InflateRect(FBounds, -1, -1);    //Platform   specific.   May   not   work   on   Linux.
    ACanvas.Font.Color := clBlack;
    ACanvas.Brush.Style := bsClear;
    ACanvas.DrawText(FValue, FBounds, cxAlignCenter or cxAlignTop);
    ADone := True;
  end;
end;

procedure TfrmYFGLInPut.ORDERNOBtnClick(Sender: TObject);
begin
  frmProductOrderList_Sel := TfrmProductOrderList_Sel.Create(self);
  with frmProductOrderList_Sel do
  begin
    if showmodal = 1 then
    begin
      Self.OrderNo.Text := Order_Main.fieldbyname('Orderno').asstring;
    end;
    free;
  end;
end;

end.

