unit U_BaoGuanInPut;

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;

type
  TfrmBaoGuanInPut = 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;
    v1Column9: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    v1Column3: TcxGridDBColumn;
    Panel1: TPanel;
    ToolBar2: TToolBar;
    ToolButton2: TToolButton;
    ToolButton3: TToolButton;
    A7FPDate: TDateTimePicker;
    A1ChuKouShang: TBtnEditA;
    Label1: TLabel;
    Label3: TLabel;
    Label12: TLabel;
    A2ShuiHao: TEdit;
    Label13: TLabel;
    A4FPNO: TEdit;
    Label14: TLabel;
    A5ConNO: TEdit;
    Label4: TLabel;
    A6PONO: TEdit;
    Label5: TLabel;
    B1HangBan: TBtnEditA;
    Label6: TLabel;
    B2TiDanHao: TEdit;
    Label7: TLabel;
    B3KaiHangDate: TDateTimePicker;
    Label8: TLabel;
    B4XiangNO: TEdit;
    Label9: TLabel;
    B5HuoGui: TBtnEditA;
    Label10: TLabel;
    B6ChuYunGang: TBtnEditA;
    Label11: TLabel;
    B7DaoHuoGang: TBtnEditA;
    Label15: TLabel;
    B8MaoYiGuo: TBtnEditA;
    Label16: TLabel;
    Label17: TLabel;
    B9DiYunGuo: TBtnEditA;
    B10YunShuType: TBtnEditA;
    Label19: TLabel;
    D1HuoYunDiJN: TBtnEditA;
    Label20: TLabel;
    D2MaoYiType: TBtnEditA;
    Label21: TLabel;
    D3JiHuiType: TBtnEditA;
    Label2: TLabel;
    F1BaoGuanTK: TBtnEditA;
    Label18: TLabel;
    F2YunFee: TEdit;
    Label22: TLabel;
    F3BaoFee: TEdit;
    Label23: TLabel;
    F4HuoYunDaiLi: TBtnEditA;
    Label24: TLabel;
    F5ChuanGongSi: TBtnEditA;
    Label25: TLabel;
    Note: TEdit;
    v1Column1: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    v1Column14: TcxGridDBColumn;
    v1Column15: TcxGridDBColumn;
    v1Column16: TcxGridDBColumn;
    v1Column17: TcxGridDBColumn;
    Label26: TLabel;
    A3HaiGuanBM: TEdit;
    ToolButton1: TToolButton;
    v1Column18: TcxGridDBColumn;
    v1Column19: TcxGridDBColumn;
    Panel2: TPanel;
    ComboBox1: TComboBox;
    ToolButton4: TToolButton;
    v1Column20: TcxGridDBColumn;
    v1Column21: TcxGridDBColumn;
    Label27: TLabel;
    KHName: TBtnEditA;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure A1ChuKouShangBtnClick(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);
  private
    { Private declarations }
    function SaveCKData():Boolean;
  public
    { Public declarations }
    FBCId:String;CopyStr:String;
  end;

var
  frmBaoGuanInPut: TfrmBaoGuanInPut;

implementation
uses
  U_DataLink,U_RTFun,U_ZDYHelp;

{$R *.dfm}

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

function TfrmBaoGuanInPut.SaveCKData():Boolean;
var
  FJMID,Maxno,MaxSubNo,FSCID:string;
begin
  try
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from JYOrder_BaoGuan_Main where BGID='''+Trim(FBCId)+'''');
      Open;
    end;
    FBCId:=Trim(ADOQueryTemp.fieldbyname('BGID').AsString);
    if Trim(FBCId)='' then
    begin
      if GetLSNo(ADOQueryCmd,Maxno,'BG','JYOrder_BaoGuan_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 JYOrder_BaoGuan_Main where BGID='''+Trim(Maxno)+'''');
      Open;
    end;
    with ADOQueryCmd do
    begin
      if Trim(FBCId)='' then
      begin
        Append;
        FieldByName('Filler').Value:=Trim(DName);
        FieldByName('FillerCode').Value:=Trim(DCode);
      end else
      begin
        Edit;
        FieldByName('Editer').Value:=Trim(DName);
        FieldByName('EditerCode').Value:=Trim(DCode);
        FieldByName('EditTime').Value:=SGetServerDate(ADOQueryTemp);
      end;
      FieldByName('BGID').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 JYOrder_BaoGuan_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 JYOrder_BaoGuan_Sub where BSID='''+Trim(CDS_Sub.fieldbyname('BSID').AsString)+'''');
          Open;
        end;
        FSCID:=Trim(ADOQueryTemp.fieldbyname('BSID').AsString);
        if Trim(FSCID)='' then
        begin
          if GetLSNo(ADOQueryCmd,MaxSubNo,'BS','JYOrder_BaoGuan_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 JYOrder_BaoGuan_Sub where BSID='''+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('BGID').Value:=Trim(Maxno);
          FieldByName('BSID').Value:=Trim(MaxSubNo);
          RTSetSaveDataCDS(ADOQueryCmd,Tv1,CDS_Sub,'JYOrder_BaoGuan_Sub',2);
          Post;
        end;
        Edit;
        FieldByName('BSID').Value:=Trim(MaxSubNo);
        FieldByName('BGID').Value:=Trim(Maxno);
        Post;
        Next;
      end;
    end;
    CDS_Sub.EnableControls;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('UPdate JYOrder_BaoGuan_Main Set ');
      sql.Add(' C7BGMoneyHZ=(select Sum(C7BGMoney) from JYOrder_BaoGuan_Sub A where A.BGID=JYOrder_BaoGuan_Main.BGID and A.SValid=''Y'' )');
      sql.Add(',E1BZQtyHZ=(select Sum(E1BZQty) from JYOrder_BaoGuan_Sub A where A.BGID=JYOrder_BaoGuan_Main.BGID and A.SValid=''Y'' )');
      sql.Add(',E2ChiMaQtyHZ=(select Sum(E2ChiMaQty) from JYOrder_BaoGuan_Sub A where A.BGID=JYOrder_BaoGuan_Main.BGID and A.SValid=''Y'' )');
      sql.Add(',E3MaoZHZ=(select Sum(E3MaoZ) from JYOrder_BaoGuan_Sub A where A.BGID=JYOrder_BaoGuan_Main.BGID and A.SValid=''Y'' )');
      sql.Add(',E4JingZHZ=(select Sum(E4JingZ) from JYOrder_BaoGuan_Sub A where A.BGID=JYOrder_BaoGuan_Main.BGID and A.SValid=''Y'' )');
      sql.Add(' where BGID='''+Trim(Maxno)+'''');
      ExecSQL;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    FBCId:=Trim(Maxno);
    Result:=True;
  except
    Result:=False;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('保存异常!','提示',0);
  end;

end;
procedure TfrmBaoGuanInPut.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('报关资料录入YD',Tv1,'报关管理');
  Close;
end;

procedure TfrmBaoGuanInPut.FormShow(Sender: TObject);
begin
  ReadCxGrid('报关资料录入YD',Tv1,'报关管理');
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add(' select A.* ');
    sql.Add(' from JYOrder_BaoGuan_Main A');
    sql.Add(' where BGID='''+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 JYOrder_BaoGuan_Sub A');
    sql.Add(' where BGID='''+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('BGID').Value:=Null;
        FieldByName('BSID').Value:=Null;
        Post;
        Next;
      end;
    end;
    CDS_Sub.EnableControls;
  end;
  if Trim(FBCId)='' then
  begin
    A7FPDate.Date:=SGetServerDate(ADOQueryTemp);
    B3KaiHangDate.Date:=A7FPDate.Date;
  end;
  ToolButton4.Click;
end;

procedure TfrmBaoGuanInPut.TBSaveClick(Sender: TObject);
var
  FReal:Double;
  i:Integer;
begin
  with Panel1 do
  begin
    for i:=0 to ControlCount-1 do
    begin
      if Controls[i].Tag=1 then
      begin
        if Controls[i] is TLabel then continue;
        if Controls[i].Tag<>1 then  continue;
        if Controls[i] is TEdit then
        begin
          if Trim(TEdit(Controls[i]).Text)='' then
          begin
            Application.MessageBox('蓝色标注的信息为必填，请填写！','提示',0);
            Exit;
          end;
        end;
        if Controls[i] is TBtnEditA then
        begin
          if Trim(TBtnEditA(Controls[i]).Text)='' then
          begin
            Application.MessageBox('蓝色标注的信息为必填，请填写！','提示',0);
            Exit;
          end;
        end;

      end;
    end;
  end;
  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 CDS_Sub.Locate('C3BGNameEng',Null,[]) then
  begin
    Application.MessageBox('英文品名不能为空!','提示',0);
    Exit;
  end;
  if CDS_Sub.Locate('C2HSNO',Null,[]) then
  begin
    Application.MessageBox('HS NO不能为空!','提示',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;
  if CDS_Sub.Locate('C7BGMoney',Null,[]) then
  begin
    Application.MessageBox('金额不能为空!','提示',0);
    Exit;
  end;
  if CDS_Sub.Locate('E1BZQty',Null,[]) then
  begin
    Application.MessageBox('包装数量不能为空!','提示',0);
    Exit;
  end;
  if CDS_Sub.Locate('E1BZUnit',Null,[]) then
  begin
    Application.MessageBox('包装单位不能为空!','提示',0);
    Exit;
  end;
  if CDS_Sub.Locate('E2ChiMaQty',Null,[]) then
  begin
    Application.MessageBox('尺码不能为空!','提示',0);
    Exit;
  end;
  if CDS_Sub.Locate('E3MaoZ',Null,[]) then
  begin
    Application.MessageBox('毛重不能为空!','提示',0);
    Exit;
  end;
  if CDS_Sub.Locate('E4JingZ',Null,[]) then
  begin
    Application.MessageBox('净重不能为空!','提示',0);
    Exit;
  end;
  if CDS_Sub.Locate('YSZhiZaoType',Null,[]) then
  begin
    Application.MessageBox('织造方法不能为空!','提示',0);
    Exit;
  end;
  if CDS_Sub.Locate('YSChenFen',Null,[]) then
  begin
    Application.MessageBox('成分含量不能为空!','提示',0);
    Exit;
  end;
  if CDS_Sub.Locate('YSRanZhengType',Null,[]) then
  begin
    Application.MessageBox('染整方式不能为空!','提示',0);
    Exit;
  end;
  if CDS_Sub.Locate('YSFuKuan',Null,[]) then
  begin
    Application.MessageBox('幅宽(CM)不能为空!','提示',0);
    Exit;
  end;
  if CDS_Sub.Locate('YSPinPai',Null,[]) then
  begin
    Application.MessageBox('品牌不能为空!','提示',0);
    Exit;
  end;
  if CDS_Sub.Locate('YSShengChanShang',Null,[]) then
  begin
    Application.MessageBox('生产厂商不能为空!','提示',0);
    Exit;
  end;
  if CDS_Sub.Locate('C5BGUnit;ZheSuanMiQty', VarArrayOf(['KG', Null]), [loPartialKey]) then
  begin
    Application.MessageBox('数量单位为KG时，折算米数不能为空!','提示',0);
    Exit;
  end;
  ToolBar1.SetFocus;
  if SaveCKData() then
  begin
    Application.MessageBox('保存成功!','提示',0);
    //ModalResult:=1;
    Exit;
  end;
end;

procedure TfrmBaoGuanInPut.A1ChuKouShangBtnClick(Sender: TObject);
var
  fsj:string;
  FWZ:Integer;
begin
  fsj:=Trim(TEdit(Sender).Hint);
  FWZ:=Pos('/',fsj);
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:=Copy(fsj,1,FWZ-1);
      flagname:=Copy(fsj,FWZ+1,Length(fsj)-fwz);
      if Trim(flag)='A1ChuKouShang' then
      begin
        V1Name.Caption:='中文名称';
        V1Note.Caption:='英文名称';
        fnote:=True;
        frmZDYHelp.Align:=alClient;
        V1ZdyStr1.Caption:='中文地址';
        V1ZdyStr1.Visible:=True;
        V1ZdyStr2.Caption:='英文地址';
        V1ZdyStr2.Visible:=True;
      end;
      if Trim(flag)='B6ChuYunGang' then
      begin
        V1Name.Caption:='中文名称';
        V1Note.Caption:='英文名称';
        fnote:=True;
      end;
      if ShowModal=1 then
      begin
        TEdit(Sender).Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        if Trim(flag)='A1ChuKouShang' then
        begin
          with ADOQueryTemp do
          begin
            Close;
            sql.Clear;
            sql.Add('select Top 1 * from JYOrder_BaoGuan_Main where A1ChuKouShang='''+Trim(ClientDataSet1.fieldbyname('ZDYName').AsString)+'''');
            sql.Add(' and Valid=''Y'' ');
            sql.Add(' order by FillTime desc');
            Open;
          end;
          A2ShuiHao.Text:=ADOQueryTemp.fieldbyname('A2ShuiHao').ASString;
          A3HaiGuanBM.Text:=ADOQueryTemp.fieldbyname('A3HaiGuanBM').ASString;
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmBaoGuanInPut.ToolButton2Click(Sender: TObject);
var
  i:Integer;
begin
  //CopyAddRowCDS(CDS_Sub);
  {with CDS_Sub do
  begin
    Edit;
    FieldByName('BGID').Value:=Null;
    FieldByName('BSID').Value:=Null;
    Post;
  end; }
  i:=CDS_Sub.RecordCount;
  i:=i+1;
  with CDS_Sub do
  begin
    Append;
    FieldByName('XHInt').Value:=i;
    Post;
  end;
end;

procedure TfrmBaoGuanInPut.ToolButton3Click(Sender: TObject);
begin
  if CDS_Sub.IsEmpty then Exit;
  if Trim(CDS_Sub.fieldbyname('BSID').AsString)<>'' then
  begin
    if Application.MessageBox('确定要删除数据吗？','提示',32+4)<>IDYES then Exit;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('Update JYOrder_BaoGuan_Sub Set SValid=''N'',SEditer='''+Trim(DName)+''',SEditTime=getdate() ');
      sql.Add(' where BSID='''+Trim(CDS_Sub.fieldbyname('BSID').AsString)+'''');
      ExecSQL;
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('UPdate JYOrder_BaoGuan_Main Set ');
      sql.Add(' C7BGMoneyHZ=(select Sum(C7BGMoney) from JYOrder_BaoGuan_Sub A where A.BGID=JYOrder_BaoGuan_Main.BGID and A.SValid=''Y'' )');
      sql.Add(',E1BZQtyHZ=(select Sum(E1BZQty) from JYOrder_BaoGuan_Sub A where A.BGID=JYOrder_BaoGuan_Main.BGID and A.SValid=''Y'' )');
      sql.Add(',E2ChiMaQtyHZ=(select Sum(E2ChiMaQty) from JYOrder_BaoGuan_Sub A where A.BGID=JYOrder_BaoGuan_Main.BGID and A.SValid=''Y'' )');
      sql.Add(',E3MaoZHZ=(select Sum(E3MaoZ) from JYOrder_BaoGuan_Sub A where A.BGID=JYOrder_BaoGuan_Main.BGID and A.SValid=''Y'' )');
      sql.Add(',E4JingZHZ=(select Sum(E4JingZ) from JYOrder_BaoGuan_Sub A where A.BGID=JYOrder_BaoGuan_Main.BGID and A.SValid=''Y'' )');
      sql.Add(' where BGID='''+Trim(CDS_Sub.fieldbyname('BGID').AsString)+'''');
      ExecSQL;
    end;
  end;
  CDS_Sub.Delete;
end;

procedure TfrmBaoGuanInPut.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 TfrmBaoGuanInPut.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 TfrmBaoGuanInPut.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 TfrmBaoGuanInPut.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 TfrmBaoGuanInPut.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 TfrmBaoGuanInPut.ToolButton1Click(Sender: TObject);
begin
  if CDS_Sub.IsEmpty then Exit;
  OneKeyPost(Tv1,CDS_Sub);
end;

procedure TfrmBaoGuanInPut.ToolButton4Click(Sender: TObject);
var
  fsj:String;
begin
  fsj:='select Name=AA.A4FPNO,Code='''' from (select Top 10 A4FPNO from JYOrder_BaoGuan_Main where Valid=''Y'' order by FillTime Desc)AA order by A4FPNO desc';
  SInitComBoxBySql(ADOQueryTemp,ComboBox1,False,fsj);
  ComboBox1.ItemIndex:=0;
  ToolBar1.SetFocus;
end;

end.
