unit U_BGZLInputNew;

interface

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

type
  TfrmBGZLInputNew = class(TForm)
    ToolBar1: TToolBar;
    TBSave: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    Panel2: TPanel;
    Label1: TLabel;
    Label6: TLabel;
    Label4: TLabel;
    Label7: TLabel;
    Label9: TLabel;
    Label18: TLabel;
    OrderNo: TEdit;
    Note: TMemo;
    CangKuQty: TEdit;
    MLenStr: TEdit;
    CangKuPS: TEdit;
    ComTaiTou: TBtnEditA;
    Label3: TLabel;
    QtyUnit: TEdit;
    ADOQueryTemp: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryCmd: TADOQuery;
    ADOQuery1: TADOQuery;
    ClientDataSet7: TClientDataSet;
    cxGridPopupMenu7: TcxGridPopupMenu;
    DataSource7: TDataSource;
    ClientDataSet2: TClientDataSet;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DataSource2: TDataSource;
    cxGrid6: TcxGrid;
    TvOrdeNo: TcxGridDBTableView;
    cxGridDBColumn7: TcxGridDBColumn;
    cxGridDBColumn10: TcxGridDBColumn;
    cxGrid4Level1: TcxGridLevel;
    DS_OrderNo: TDataSource;
    CDS_OrderNo: TClientDataSet;
    Panel3: TPanel;
    ToolBar2: TToolBar;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    cxGridDBColumn5: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    Panel4: TPanel;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    cxGridDBColumn8: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    ToolBar3: TToolBar;
    ToolButton3: TToolButton;
    ToolButton4: TToolButton;
    DataSource1: TDataSource;
    ClientDataSet1: TClientDataSet;
    cxGridPopupMenu1: TcxGridPopupMenu;
    cxGrid7: TcxGrid;
    Tv7: TcxGridDBTableView;
    cxGridDBColumn30: TcxGridDBColumn;
    cxGridDBColumn34: TcxGridDBColumn;
    v7Column2: TcxGridDBColumn;
    cxGridDBColumn32: TcxGridDBColumn;
    cxGridDBColumn31: TcxGridDBColumn;
    v7Column1: TcxGridDBColumn;
    cxGridDBColumn36: TcxGridDBColumn;
    cxGridLevel5: TcxGridLevel;
    v1Column1: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    procedure FormDestroy(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure OrderNoKeyPress(Sender: TObject; var Key: Char);
    procedure OrderNoChange(Sender: TObject);
    procedure TvOrdeNoDblClick(Sender: TObject);
    procedure ComTaiTouBtnClick(Sender: TObject);
    procedure Tv7CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure cxGridDBColumn2PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure Tv7DblClick(Sender: TObject);
  private
    { Private declarations }
    function SaveData():Boolean;
  public
    { Public declarations }
    FOrderNo,FBGID,FMainId:String;
    FCopyInt:Integer;
  end;

var
  frmBGZLInputNew: TfrmBGZLInputNew;

implementation
uses
  U_DataLink,U_RTFun, U_ZDYHelp, U_ZDYHelpSel,U_ModuleNote, U_GYSList;

{$R *.dfm}

procedure TfrmBGZLInputNew.FormDestroy(Sender: TObject);
begin
  frmBGZLInput:=nil;
end;

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

procedure TfrmBGZLInputNew.FormShow(Sender: TObject);
var
  fsj:string;
begin
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYorder_BG where BGID='''+Trim(FBGID)+'''');
    Open;
  end;
  SCSHDataNew(ADOQueryTemp,Panel2,2);
  cxGrid6.Visible:=False;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrder_BG_Qty where BGID='''+Trim(FBGID)+'''');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,ClientDataSet2);
  SInitCDSData20(ADOQueryTemp,ClientDataSet2);
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrder_BG_Name where BGID='''+Trim(FBGID)+'''');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,ClientDataSet1);
  SInitCDSData20(ADOQueryTemp,ClientDataSet1);
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrder_Main where OrderNo='''+Trim(OrderNo.Text)+'''');
    Open;
  end;
  FMainId:=Trim(ADOQueryTemp.fieldbyname('MainId').AsString);
  with  ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('exec P_View_MDQtyFooter_BG :MainId');
    Parameters.ParamByName('MainId').Value:=Trim(FMainId);
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,ClientDataSet7);
  SInitCDSData20(ADOQueryTemp,ClientDataSet7);
  fsj:='select Code=PSName,Name=PSName from JYOrder_Process where MainId='''+Trim(FMainId)+''''+
       ' order by PSXH';
  SInitCxGridComboBoxBySql(ADOQueryTemp,cxGridDBColumn1,fsj,1,True,'');
  if FCopyInt=1 then
  begin
    OrderNo.ReadOnly:=True;
    with ClientDataSet1 do
    begin
      First;
      while not Eof do
      begin
        Edit;
        FieldByName('BNID').Value:='';
        Post;
        Next;
      end;
    end;
    with ClientDataSet2 do
    begin
      First;
      while not Eof do
      begin
        Edit;
        FieldByName('BQID').Value:='';
        Post;
        Next;
      end;
    end;
    FBGID:='';
  end;
  {with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from (');
    sql.Add('select PSName=Cast(A.PSXH As Varchar(20))+'' ''+Cast(A.PSName As Varchar(20)),B.FactoryNo,PSName10=A.PSName,B.FactoryName,sum(QtyFlag*PS) MDPS,Sum(QtyFlag*Qty) MDQty,B.QtyUnit');
    sql.Add(' from JYOrder_Process A  ');
    sql.Add(' left join JYOrder_Main_MD B on A.PSID=B.PSID');
    sql.Add(' inner join JYOrder_Main C on A.Mainid=C.MainId');
    sql.Add(' where C.OrderNo='''+Trim(OrderNo.Text)+'''');
    sql.Add(' group by A.PSXH,A.PSName,B.FactoryName,B.FactoryNo,B.QtyUnit)AA where MDQty>0 order by PSName');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,ClientDataSet7);
  SInitCDSData20(ADOQueryTemp,ClientDataSet7); }
end;

procedure TfrmBGZLInputNew.OrderNoKeyPress(Sender: TObject; var Key: Char);
begin
  if Key=#13 then
  begin
    
  end;
end;

procedure TfrmBGZLInputNew.OrderNoChange(Sender: TObject);
var
  mvalue:String;
begin
  mvalue:=Trim(OrderNo.Text);
  if Length(Trim(mvalue))<2 then
  begin
    cxGrid6.Visible:=False;
    Exit;
  end;
  mvalue:='%'+Trim(mvalue)+'%';
  with ADOQuery1 do
  begin
    Close;
    sql.Clear;
    sql.Add('select OrderNo,MPRTCodeName,A.MainId from JYOrder_Main A');
    sql.Add(' where A.orderno like :orderno ');
    //sql.Add(' and A.MainId in(select MainId from JYOrder_Sub B where B.Mainid=A.MainId and B.subId in(select OrdSubId from Contract_Cloth_LL))');
    Parameters.ParamByName('orderno').Value:=mvalue;
    Open;
  end;
  SCreateCDS20(ADOQuery1,CDS_OrderNo);
  SInitCDSData20(ADOQuery1,CDS_OrderNo);
  if CDS_OrderNo.IsEmpty then cxGrid6.Visible:=False else cxGrid6.Visible:=True;
end;

procedure TfrmBGZLInputNew.TvOrdeNoDblClick(Sender: TObject);
var
  fsj:string;
begin
  OrderNo.Text:=Trim(CDS_OrderNo.fieldbyname('OrderNo').AsString);
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('Update JYOrder_Main_MD Set QtyFlag=1');
    sql.Add(' where ORDMainid='''+Trim(CDS_OrderNo.fieldbyname('MainId').AsString)+'''');
    sql.Add(' and Isnull(CKName,'''')='''' ');
    sql.Add('Update JYOrder_Main_MD Set QtyFlag=-1');
    sql.Add(' where ORDMainid='''+Trim(CDS_OrderNo.fieldbyname('MainId').AsString)+'''');
    sql.Add(' and Isnull(CKName,'''')<>'''' ');
    ExecSQL;
  end;
  with  ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('exec P_View_MDQtyFooter_BG :MainId');
    Parameters.ParamByName('MainId').Value:=Trim(CDS_OrderNo.fieldbyname('MainId').AsString);
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,ClientDataSet7);
  SInitCDSData20(ADOQueryTemp,ClientDataSet7);
  fsj:='select Code=PSName,Name=PSName from JYOrder_Process where MainId='''+Trim(CDS_OrderNo.fieldbyname('MainId').AsString)+''''+
       ' order by PSXH';
  SInitCxGridComboBoxBySql(ADOQueryTemp,cxGridDBColumn1,fsj,1,True,'');
  {with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from (');
    sql.Add('select PSName=Cast(A.PSXH As Varchar(20))+'' ''+Cast(A.PSName As Varchar(20)),B.FactoryNo,PSName10=A.PSName,B.FactoryName,sum(QtyFlag*PS) MDPS,Sum(QtyFlag*Qty) MDQty,B.QtyUnit');
    sql.Add(' from JYOrder_Process A  ');
    sql.Add(' left join JYOrder_Main_MD B on A.PSID=B.PSID');
    sql.Add(' inner join JYOrder_Main C on A.Mainid=C.MainId');
    sql.Add(' where C.OrderNo='''+Trim(OrderNo.Text)+'''');
    sql.Add(' group by A.PSXH,A.PSName,B.FactoryName,B.FactoryNo,B.QtyUnit)AA where MDQty>0 order by PSName');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,ClientDataSet7);
  SInitCDSData20(ADOQueryTemp,ClientDataSet7);}
  cxGrid6.Visible:=false;
end;

procedure TfrmBGZLInputNew.ComTaiTouBtnClick(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='GSTT';
      flagname:='报关单位';
      V1ZdyStr1.Visible:=True;
      V1ZdyStr2.Visible:=True;
      V1ZdyStr3.Visible:=True;
      V1ZdyStr4.Visible:=True;
      V1ZdyStr1.Caption:='简称';
      V1ZdyStr2.Caption:='电话';
      V1ZdyStr3.Caption:='传真';
      V1ZdyStr4.Caption:='地址';
      frmZDYHelp.Align:=alClient;
      if ShowModal=1 then
      begin
        ComTaiTou.Text:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmBGZLInputNew.Tv7CellDblClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  with ClientDataSet2 do
  begin
    Append;
    FieldByName('PSName').Value:=Trim(ClientDataSet7.fieldbyname('PSName10').AsString);
    FieldByName('FactoryNo').Value:=Trim(ClientDataSet7.fieldbyname('FactoryNo').AsString);
    FieldByName('FactoryName').Value:=Trim(ClientDataSet7.fieldbyname('FactoryName').AsString);
    FieldByName('BQUnit').Value:=Trim(ClientDataSet7.fieldbyname('QtyUnit').AsString);
    FieldByName('BQPS').Value:=ClientDataSet7.fieldbyname('MDPS').Value;
    FieldByName('BQQty').Value:=ClientDataSet7.fieldbyname('MDQty').Value;
    Post;
  end;
end;

procedure TfrmBGZLInputNew.cxGridDBColumn2PropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmGYSList:=TfrmGYSList.Create(Application);
    with frmGYSList do
    begin
      if ShowModal=1 then
      begin
        with ClientDataSet2 do
        begin
          edit;
          FieldByName('FactoryNo').Value:=Trim(frmGYSList.Order_Main.fieldbyname('ZKID').AsString) ;
          FieldByName('FactoryName').Value:=Trim(frmGYSList.Order_Main.fieldbyname('KHNameJC').AsString);
          //Post;
        end;
      end;
    end;
  finally
    frmGYSList.Free;
  end;
end;

procedure TfrmBGZLInputNew.ToolButton1Click(Sender: TObject);
begin
  with ClientDataSet2 do
  begin
    Append;
    FieldByName('BQUnit').Value:=Trim(QtyUnit.Text);
    Post;
  end;
end;

procedure TfrmBGZLInputNew.ToolButton2Click(Sender: TObject);
begin
  if ClientDataSet2.IsEmpty then Exit;
  if Trim(ClientDataSet2.fieldbyname('BQID').AsString)<>'' then
  begin
    if Application.MessageBox('确定要删除数据吗？','提示',32+4)<>IDYES then Exit;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete JYOrder_BG_Qty where BQID='''+Trim(ClientDataSet2.fieldbyname('BQID').AsString)+'''');
      ExecSQL;
    end;
  end;
  ClientDataSet2.Delete;
end;
function TfrmBGZLInputNew.SaveData():Boolean;
var
  maxno,maxsubno,maxJDNo,JDMainId,maxjfno,maxjcno,maxBgNo:String;
begin
  try
    ADOQueryCmd.Connection.BeginTrans;
    if FCopyInt=1 then
    begin
      with ADOQueryCmd do
      begin
        Close;
        sql.Clear;
        sql.Add('UPdate JYOrder_BG Set Valid=''N'' ');
        sql.Add(' where OrderNo='''+Trim(OrderNo.Text)+'''');
        ExecSQL;
      end;
    end;

    ///保存主表
    if Trim(FBGID)='' then
    begin
      if GetLSNo(ADOQueryCmd,maxno,'BG','JYOrder_BG',3,1)=False then
      begin
        ADOQueryCmd.Connection.RollbackTrans;
        Application.MessageBox('取最大号失败!','提示',0);
        Exit;
      end;
    end else
    begin
      maxno:=Trim(FBGID);
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      SQL.Add('select * from JYOrder_BG where BGId='''+Trim(FBGID)+'''');
      Open;
    end;
    with ADOQueryCmd do
    begin
      if Trim(FBGID)='' then
      begin
        Append;
      end
      else begin
        Edit;
      end;
      FieldByName('BGId').Value:=Trim(maxno);
      RTSetsavedata(ADOQueryCmd,'JYOrder_Main',Panel2,2);
      if Trim(FBGID)='' then
      begin
        FieldByName('Filler').Value:=Trim(DName);
      end else
      begin
        FieldByName('Editer').Value:=Trim(DName);
        FieldByName('EditTime').Value:=SGetServerDateTime(ADOQueryTemp);
      end;
      FieldByName('Note').Value:=Trim(Note.Text);
      Post;
    end;

    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from JYOrder_BG where orderno='''+Trim(OrderNo.Text)+'''');
      sql.Add(' and Valid=''Y'' ');
      Open;
    end;
    if ADOQueryTemp.RecordCount>1 then
    begin
      ADOQueryCmd.Connection.RollbackTrans;
      Application.MessageBox('订单号重复!','提示',0);
      Exit;
    end else
    begin
      with ADOQueryCmd do
      begin
        Close;
        sql.Clear;
        sql.Add('Update JYOrder_BG Set EditCount=');
        sql.Add('(select Count(*) from JYOrder_BG where OrderNo='''+Trim(OrderNo.Text)+''')');
        sql.Add(' where BGID='''+Trim(maxno)+'''');
        SQL.Add(' Update JYOrder_BG Set Valid=''N'' ');
        sql.Add(' where OrderNo='''+Trim(OrderNo.Text)+'''');
        sql.Add(' and BGID<>'''+Trim(maxno)+'''');
        ExecSQL;
      end;
    end;

    ///保存子表
    with ClientDataSet2 do
    begin
      First;
      while not Eof do
      begin
        if Trim(ClientDataSet2.fieldbyname('BQId').AsString)='' then
        begin
          if GetLSNo(ADOQueryCmd,maxsubno,'BQ','JYOrder_BG_Qty',4,1)=False then
          begin
            ADOQueryCmd.Connection.RollbackTrans;
            Application.MessageBox('取子流水号失败！','提示',0);
            Exit;
          end;
        end else
        begin
          maxsubno:=Trim(ClientDataSet2.fieldbyname('BQId').AsString);
        end;
        with ADOQueryCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from JYOrder_BG_Qty where BQId='''+Trim(maxsubno)+'''');
          Open;
        end;
        with ADOQueryCmd do
        begin
          if Trim(ClientDataSet2.fieldbyname('BQId').AsString)='' then
            Append
          else
            Edit;
          FieldByName('BGId').Value:=Trim(maxno);
          FieldByName('BQId').Value:=Trim(maxsubno);
          RTSetSaveDataCDS(ADOQueryCmd,Tv2,ClientDataSet2,'JYOrder_BG_Qty',0);
          Post;
        end;
        ClientDataSet2.Edit;
        ClientDataSet2.FieldByName('BQId').Value:=Trim(maxsubno);
        //Order_Sub.Post;
        Next;
      end;
    end;
    ///保存报关名称
    with ClientDataSet1 do
    begin
      First;
      while not Eof do
      begin
        if Trim(ClientDataSet1.fieldbyname('BNId').AsString)='' then
        begin
          if GetLSNo(ADOQueryCmd,maxBgNo,'BN','JYOrder_BG_Name',4,1)=False then
          begin
            ADOQueryCmd.Connection.RollbackTrans;
            Application.MessageBox('取报关名称子流水号失败！','提示',0);
            Exit;
          end;
        end else
        begin
          maxBgNo:=Trim(ClientDataSet1.fieldbyname('BNId').AsString);
        end;
        with ADOQueryCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from JYOrder_BG_Name where BNId='''+Trim(maxBgNo)+'''');
          Open;
        end;
        with ADOQueryCmd do
        begin
          if Trim(ClientDataSet1.fieldbyname('BNId').AsString)='' then
            Append
          else
            Edit;
          FieldByName('BGId').Value:=Trim(maxno);
          FieldByName('BNId').Value:=Trim(maxBgNo);
          RTSetSaveDataCDS(ADOQueryCmd,Tv1,ClientDataSet1,'JYOrder_BG_Name',0);
          Post;
        end;
        ClientDataSet1.Edit;
        ClientDataSet1.FieldByName('BNId').Value:=Trim(maxBgNo);
        //Order_Sub.Post;
        Next;
      end;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Result:=True;
    FBGID:=Trim(maxno);
  except
    Result:=False;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！','提示',0);
  end;
end;

procedure TfrmBGZLInputNew.TBSaveClick(Sender: TObject);
var
  FReal:Double;
begin
  ToolBar1.SetFocus;
  if Trim(OrderNo.Text)='' then
  begin
    Application.MessageBox('订单号不能为空！','提示',0);
    Exit;
  end;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrder_Main where orderno='''+Trim(OrderNo.Text)+'''');
    Open;
  end;
  if ADOQueryTemp.IsEmpty then
  begin
    Application.MessageBox('此订单号不存在!','提示',0);
    Exit;
  end;
  if Trim(ComTaiTou.Text)='' then
  begin
    Application.MessageBox('中文品名不能为空！','提示',0);
    Exit;
  end;
  if Trim(QtyUnit.Text)='' then
  begin
    Application.MessageBox('数量单位不能为空！','提示',0);
    Exit;
  end;
  if Trim(CangKuPS.Text)<>'' then
  begin
    if TryStrToFloat(CangKuPS.Text,FReal)=False then
    begin
      Application.MessageBox('仓库件数非法数字!','提示',0);
      Exit;
    end;
  end else
  begin
    Application.MessageBox('仓库件数不能为空!','提示',0);
    Exit;
  end;
  if Trim(CangKuQty.Text)<>'' then
  begin
    if TryStrToFloat(CangKuQty.Text,FReal)=False then
    begin
      Application.MessageBox('仓库数量非法数字!','提示',0);
      Exit;
    end;
  end else
  begin
    Application.MessageBox('仓库数量不能为空!','提示',0);
    Exit;
  end;
  if ClientDataSet2.IsEmpty then
  begin
    Application.MessageBox('明细不能为空!','提示',0);
    Exit;
  end;
  if ClientDataSet2.Locate('BQPS',Null,[])=True then
  begin
    Application.MessageBox('匹数不能为空!','提示',0);
    Exit;
  end;
  if ClientDataSet2.Locate('BQQty',Null,[])=True then
  begin
    Application.MessageBox('数量不能为空!','提示',0);
    Exit;
  end;
  if ClientDataSet2.Locate('FactoryName',Null,[])=True then
  begin
    Application.MessageBox('供应商不能为空!','提示',0);
    Exit;
  end;
  if ClientDataSet2.Locate('BQUnit',Null,[])=True then
  begin
    Application.MessageBox('单位不能为空!','提示',0);
    Exit;
  end;
  if ClientDataSet2.Locate('PSName',Null,[])=True then
  begin
    Application.MessageBox('工序名称不能为空!','提示',0);
    Exit;
  end;

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


end;

procedure TfrmBGZLInputNew.ToolButton3Click(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='BGName';
      flagname:='报关品名';
      if ShowModal=1 then
      begin
        with Self.ClientDataSet1 do
        begin
          Append;
          FieldByName('BGName').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
          Post;
        end;

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

procedure TfrmBGZLInputNew.ToolButton4Click(Sender: TObject);
begin
  if ClientDataSet1.IsEmpty then Exit;
  if Trim(ClientDataSet1.fieldbyname('BNID').AsString)<>'' then
  begin
    if Application.MessageBox('确定要删除数据吗？','提示',32+4)<>IDYES then Exit;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete JYOrder_BG_Name where BNID='''+Trim(ClientDataSet1.fieldbyname('BNID').AsString)+'''');
      ExecSQL;
    end;
  end;
  ClientDataSet1.Delete;
end;

procedure TfrmBGZLInputNew.Tv7DblClick(Sender: TObject);
begin
  with ClientDataSet2 do
  begin
    Append;
    FieldByName('PSName').Value:=ClientDataSet7.fieldbyname('PSName').Value;
    FieldByName('FactoryName').Value:=ClientDataSet7.fieldbyname('GYSName').Value;
    FieldByName('FactoryNo').Value:=ClientDataSet7.fieldbyname('GYSCode').Value;
    FieldByName('BQUnit').Value:=ClientDataSet7.fieldbyname('QtyUnit').Value;
    Post;
  end;
end;

end.
