unit U_BGLDChk; //22

interface

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

type
  TfrmBGLDChk = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBView: TToolButton;
    ToolButton3: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    Label1: TLabel;
    Label3: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    OrderNo: TEdit;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Order_Main: TClientDataSet;
    DataSource1: TDataSource;
    ADOQueryTemp: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryCmd: TADOQuery;
    ADOQueryPrint: TADOQuery;
    cxPageControl1: TcxPageControl;
    cxTabSheet1: TcxTabSheet;
    ClientDataSet7: TClientDataSet;
    cxGridPopupMenu7: TcxGridPopupMenu;
    DataSource7: TDataSource;
    Panel2: TPanel;
    ClientDataSet2: TClientDataSet;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DataSource2: TDataSource;
    CDS_11: TClientDataSet;
    cxGridPopupMenu11: TcxGridPopupMenu;
    DS_11: TDataSource;
    CDS_19: TClientDataSet;
    cxGridPopupMenu19: TcxGridPopupMenu;
    DS_19: TDataSource;
    cxTabControl1: TcxTabControl;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    Panel4: TPanel;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1OrderNo: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1CustomerNoName: TcxGridDBColumn;
    v1MPRTSpec: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    CDS_BGName: TClientDataSet;
    cxGridPopupMenu5: TcxGridPopupMenu;
    DSBGName: TDataSource;
    v1Column5: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    cxGrid5: TcxGrid;
    TVBGName: TcxGridDBTableView;
    cxGridDBColumn8: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    cxGridDBColumn7: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    cxGridDBColumn9: TcxGridDBColumn;
    cxGridDBColumn10: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    cxPageControl2: TcxPageControl;
    cxTabSheet2: TcxTabSheet;
    cxGrid11: TcxGrid;
    Tv11: TcxGridDBBandedTableView;
    cxGridDBBandedColumn1: TcxGridDBBandedColumn;
    cxGridDBBandedColumn2: TcxGridDBBandedColumn;
    cxGridDBBandedColumn3: TcxGridDBBandedColumn;
    cxGridDBBandedColumn4: TcxGridDBBandedColumn;
    cxGridDBBandedColumn5: TcxGridDBBandedColumn;
    cxGridDBBandedColumn6: TcxGridDBBandedColumn;
    cxGridDBBandedColumn7: TcxGridDBBandedColumn;
    cxGridDBBandedColumn8: TcxGridDBBandedColumn;
    cxGridDBBandedColumn10: TcxGridDBBandedColumn;
    cxGridDBBandedColumn11: TcxGridDBBandedColumn;
    cxGridDBBandedColumn12: TcxGridDBBandedColumn;
    cxGridDBBandedColumn13: TcxGridDBBandedColumn;
    cxGridLevel7: TcxGridLevel;
    cxGrid19: TcxGrid;
    Tv19: TcxGridDBTableView;
    cxGridDBColumn43: TcxGridDBColumn;
    Tv19Column1: TcxGridDBColumn;
    Tv19Column2: TcxGridDBColumn;
    cxGridLevel10: TcxGridLevel;
    cxTabSheet3: TcxTabSheet;
    cxGrid7: TcxGrid;
    Tv7: TcxGridDBTableView;
    cxGridDBColumn30: TcxGridDBColumn;
    cxGridDBColumn34: TcxGridDBColumn;
    v7Column2: TcxGridDBColumn;
    cxGridDBColumn32: TcxGridDBColumn;
    cxGridDBColumn31: TcxGridDBColumn;
    v7Column1: TcxGridDBColumn;
    cxGridDBColumn36: TcxGridDBColumn;
    cxGridLevel5: TcxGridLevel;
    v1Column9: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    ToolButton4: TToolButton;
    Panel3: TPanel;
    cxGrid3: TcxGrid;
    TVPrice: TcxGridDBTableView;
    cxGridDBColumn11: TcxGridDBColumn;
    cxGridDBColumn13: TcxGridDBColumn;
    cxGridDBColumn15: TcxGridDBColumn;
    cxGridLevel3: TcxGridLevel;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    cxGridDBColumn5: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    CDS_Price: TClientDataSet;
    cxGridPopupMenu3: TcxGridPopupMenu;
    DataSource3: TDataSource;
    cxTabSheet4: TcxTabSheet;
    cxGrid4: TcxGrid;
    TvFee: TcxGridDBTableView;
    cxGridDBColumn12: TcxGridDBColumn;
    cxGridDBColumn14: TcxGridDBColumn;
    cxGridDBColumn16: TcxGridDBColumn;
    cxGridDBColumn17: TcxGridDBColumn;
    cxGridDBColumn18: TcxGridDBColumn;
    cxGridDBColumn33: TcxGridDBColumn;
    cxGridDBColumn19: TcxGridDBColumn;
    cxGridLevel4: TcxGridLevel;
    TvFeeColumn1: TcxGridDBColumn;
    TvFeeColumn2: TcxGridDBColumn;
    TvFeeColumn3: TcxGridDBColumn;
    vFeeColumn1: TcxGridDBColumn;
    DS_Fee: TDataSource;
    cxGridPopupMenu4: TcxGridPopupMenu;
    CDS_Fee: TClientDataSet;
    cxTabControl2: TcxTabControl;
    VPriceColumn1: TcxGridDBColumn;
    VPriceColumn2: TcxGridDBColumn;
    cxSplitter1: TcxSplitter;
    v1Column12: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    v1Column14: TcxGridDBColumn;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure ToolButton3Click(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure Tv1FocusedRecordChanged(Sender: TcxCustomGridTableView;
      APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord;
      ANewItemRecordFocusingChanged: Boolean);
    procedure cxTabControl1Change(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure TBViewClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Tv11CellClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure ToolButton4Click(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure OrderNoChange(Sender: TObject);
    procedure Tv2CellClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure TVPriceDblClick(Sender: TObject);
    procedure cxTabControl2Change(Sender: TObject);
  private
    { Private declarations }
    canshu1,canshu2:string;
    procedure InitGrid();
  public
    { Public declarations }
  end;

var
  frmBGLDChk: TfrmBGLDChk;

implementation
uses
  U_DataLink,U_RTFun, U_ZDYHelp, U_ZDYHelpSel,U_ModuleNote,
  U_BGZLInput,U_BGJCKMXInput,U_CWMDOtherFeeList;

{$R *.dfm}

procedure TfrmBGLDChk.FormDestroy(Sender: TObject);
begin
  frmBGLDChk:=nil;
end;

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

procedure TfrmBGLDChk.ToolButton3Click(Sender: TObject);
begin
  try
    frmModuleNote:=TfrmModuleNote.Create(Application);
    with frmModuleNote do
    begin
      flag:='报关资料单审核';
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmModuleNote.Free;
  end;
end;

procedure TfrmBGLDChk.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('Tv1',Tv1,'报关管理');
  WriteCxGrid('Tv2',Tv2,'报关管理');

  Close;
end;

procedure TfrmBGLDChk.FormShow(Sender: TObject);
begin
  EndDate.DateTime:=SGetServerDate(ADOQueryTemp);
  BegDate.Date:=EndDate.DateTime-30;
  cxPageControl1.ActivePageIndex:=0;
  cxTabControl1.TabIndex:=0;
  InitGrid();
  ReadCxGrid('Tv1',Tv1,'报关管理');
  ReadCxGrid('Tv2',Tv2,'报关管理');
  cxPageControl2.ActivePageIndex:=1;
end;

procedure TfrmBGLDChk.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from JYOrder_BG where isnull(ChkStatus,'''')<>'''' ');
      if cxTabControl1.TabIndex=0 then
      begin
        sql.Add(' and isnull(ChkStatus,'''')=''已送审'' ');
      end else
      if cxTabControl1.TabIndex=1 then
      begin
        sql.Add(' and isnull(ChkStatus,'''')<>''已送审'' ');
      end;
      if cxTabControl1.TabIndex<>0 then
      begin
        sql.Add(' and FillTime>='''+Trim(FormatDateTime('yyyy-MM-dd',BegDate.Date))+'''');
        sql.Add(' and FillTime<'''+Trim(FormatDateTime('yyyy-MM-dd',EndDate.Date+1))+'''');
      end;
      Open;
    end;
    SCreateCDS20(ADOQueryMain,Order_Main);
    SInitCDSData20(ADOQueryMain,Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmBGLDChk.TBRafreshClick(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmBGLDChk.Tv1FocusedRecordChanged(
  Sender: TcxCustomGridTableView; APrevFocusedRecord,
  AFocusedRecord: TcxCustomGridRecord;
  ANewItemRecordFocusingChanged: Boolean);
var
  FMainId:String;
begin
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrder_BG_Qty where BGID='''+Trim(Order_Main.fieldbyname('BGID').AsString)+'''');
    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(Order_Main.fieldbyname('BGID').AsString)+'''');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,CDS_BGName);
  SInitCDSData20(ADOQueryTemp,CDS_BGName);
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrder_Main where OrderNo='''+Trim(Order_Main.fieldbyname('OrderNo').AsString)+'''');
    Open;
  end;
  FMainId:=Trim(ADOQueryTemp.fieldbyname('MainId').AsString);
  with  ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('exec P_View_MDQtyFooter :MainId');
    Parameters.ParamByName('MainId').Value:=Trim(FMainId);
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,ClientDataSet7);
  SInitCDSData20(ADOQueryTemp,ClientDataSet7);
 { with  ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrder_Main_Fee where Mainid='''+Trim(FMainId)+'''');
    if cxTabControl2.TabIndex=0 then
    begin
      sql.Add(' and isnull(BGID,'''')='''' ');
    end else
    begin
      sql.Add(' and isnull(BGID,'''')='''+Trim(Order_Main.fieldbyname('BGID').AsString)+'''');
    end;
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,CDS_Fee);
  SInitCDSData20(ADOQueryTemp,CDS_Fee);}
  with  ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrder_Main_MD_HZ A where ORDMainId='''+Trim(FMainId)+'''');
    sql.Add(' and exists(select * from KH_Zdy B where B.ZdyName=A.ItemName and B.Type=''YFName'' and isnull(Note,'''')=''其它费用'' )');
    if cxTabControl2.TabIndex=0 then
    begin
      sql.Add(' and isnull(BGID,'''')='''' ');
    end else
    begin
      sql.Add(' and isnull(BGID,'''')='''+Trim(Order_Main.fieldbyname('BGID').AsString)+'''');
    end;
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,CDS_Fee);
  SInitCDSData20(ADOQueryTemp,CDS_Fee);
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrder_BG_CK where BGID='''+Trim(Order_Main.fieldbyname('BGID').AsString)+'''');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,CDS_11);
  SInitCDSData20(ADOQueryTemp,CDS_11);
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrder_BG_CKName_Qty where BCID='''+Trim(CDS_11.fieldbyname('BCID').AsString)+'''');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,CDS_19);
  SInitCDSData20(ADOQueryTemp,CDS_19);
  {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(Order_Main.fieldbyname('OrderNo').AsString)+'''');
    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 TfrmBGLDChk.cxTabControl1Change(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmBGLDChk.ToolButton1Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  if cxTabControl1.TabIndex<>0 then Exit;
  if Application.MessageBox('确定要执行此操作吗？','提示',32+4)<>IDYES then Exit;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('UPdate JYOrder_BG Set ChkStatus=''审核通过'',ChkTime=getdate(),Chker='''+Trim(DName)+'''');
    sql.Add(' where BGID='''+Trim(Order_Main.fieldbyname('BGID').AsString)+'''');
    ExecSQL;
  end;
  if cxPageControl2.ActivePageIndex=2 then
  begin
    if cxTabControl2.TabIndex=0 then
    begin
      with CDS_Fee do
      begin
        while Locate('SSel',True,[])=True do
        begin
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('UPdate JYOrder_Main_MD_HZ Set QTChkStatus=''审核通过'',QTChkTime=getdate(),QTChker='''+Trim(DName)+'''');
            sql.Add(',BGID='''+Trim(Order_Main.fieldbyname('BGID').AsString)+'''');
            SQL.Add(' where MHID='''+Trim(CDS_Fee.fieldbyname('MHID').AsString)+'''');
            ExecSQL;
          end;
          Edit;
          FieldByName('SSel').Value:=False;
          FieldByName('QTChkStatus').Value:='审核通过';
          FieldByName('QTChkTime').Value:=Now;
          FieldByName('QTChker').Value:=Trim(DName);
          Post;
          CDS_Fee.Delete;
        end;
      end;
    end;
  end;

  Order_Main.Delete;
end;

procedure TfrmBGLDChk.ToolButton2Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  if cxTabControl1.TabIndex<>0 then Exit;
  if Application.MessageBox('确定要执行此操作吗？','提示',32+4)<>IDYES then Exit;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('UPdate JYOrder_BG Set ChkStatus=''审核不通过'',ChkTime=getdate(),Chker='''+Trim(DName)+'''');
    sql.Add(' where BGID='''+Trim(Order_Main.fieldbyname('BGID').AsString)+'''');
    ExecSQL;
  end;
  Order_Main.Delete;
end;

procedure TfrmBGLDChk.TBViewClick(Sender: TObject);
begin
  if cxPageControl1.ActivePageIndex=0 then
  begin

    try
      frmBGZLInput:=TfrmBGZLInput.Create(Application);
      with frmBGZLInput do
      begin
        FBGID:=Trim(Self.Order_Main.fieldbyname('BGID').AsString);
        FOrderNo:=Trim(Self.Order_Main.fieldbyname('OrderNo').AsString);
        TBSave.Visible:=False;
        ToolBar2.Visible:=False;
        ToolBar3.Visible:=False;
        if ShowModal=1 then
        begin

        end;
      end;
    finally
      frmBGZLInput.Free;
    end;
  end else
  if cxPageControl1.ActivePageIndex=1 then
  begin
    try
      frmBGJCKMXInput:=TfrmBGJCKMXInput.Create(Application);
      with frmBGJCKMXInput do
      begin
        FBGID:=Trim(Self.Order_Main.fieldbyname('BGID').AsString);
        FOrderNo:=Trim(Self.Order_Main.fieldbyname('OrderNo').AsString);
        if ShowModal=1 then
        begin

        end;
      end;
    finally
      frmBGJCKMXInput.Free;
    end;
  end;
end;

procedure TfrmBGLDChk.FormCreate(Sender: TObject);
begin
  canshu1:=Trim(DParameters1);
  canshu2:=Trim(DParameters2);
end;

procedure TfrmBGLDChk.Tv11CellClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrder_BG_CKName_Qty where BCID='''+Trim(CDS_11.fieldbyname('BCID').AsString)+'''');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,CDS_19);
  SInitCDSData20(ADOQueryTemp,CDS_19);
end;

procedure TfrmBGLDChk.ToolButton4Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  if cxTabControl1.TabIndex<>1 then Exit;
  if CDS_11.IsEmpty=False then
  begin
    Application.MessageBox('已产生数据，不能撤销!','提示',0);
    Exit;
  end;
  if Trim(Order_Main.fieldbyname('Valid').AsString)='N' then
  begin
    Application.MessageBox('作废数据不能撤销!','提示',0);
    Exit;
  end;
  if Application.MessageBox('确定要执行此操作吗？','提示',32+4)<>IDYES then Exit;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('UPdate JYOrder_BG Set ChkStatus=''已送审'',ChkTime=Null,Chker=Null ');
    sql.Add(' where BGID='''+Trim(Order_Main.fieldbyname('BGID').AsString)+'''');
    ExecSQL;
  end;
  if cxPageControl2.ActivePageIndex=2 then
  begin
    if cxTabControl2.TabIndex=1 then
    begin
      with CDS_Fee do
      begin
        while Locate('SSel',True,[])=True do
        begin
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('UPdate JYOrder_Main_MD_HZ Set QTChkStatus='''',QTChkTime=NUll,QTChker='''' ');
            sql.Add(',BGID='''' ');
            SQL.Add(' where MHID='''+Trim(CDS_Fee.fieldbyname('MHID').AsString)+'''');
            ExecSQL;
          end;
          Edit;
          FieldByName('SSel').Value:=False;
          Post;
          CDS_Fee.Delete;
        end;
      end;
    end;
  end;
  Order_Main.Delete;
end;

procedure TfrmBGLDChk.TBFindClick(Sender: TObject);
begin
  if ADOQueryMain.Active=False then Exit;
  SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
  SCreateCDS20(ADOQueryMain,Order_Main);
  SInitCDSData20(ADOQueryMain,Order_Main);
end;

procedure TfrmBGLDChk.OrderNoChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmBGLDChk.Tv2CellClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
var
  fsj:string;
begin
  try
    ADOQueryTemp.DisableControls;
    with ADOQueryTemp do
    begin
      Close;
      Filtered:=False;
      sql.Clear;
      sql.Add('exec P_View_MD_JS :begdate,:enddate,:orderno,:MDType,:WSql');
      Parameters.ParamByName('begdate').Value:='';
      Parameters.ParamByName('enddate').Value:='';
      Parameters.ParamByName('orderno').Value:=Trim(Order_Main.fieldbyname('OrderNo').AsString);
      Parameters.ParamByName('MDType').Value:='';
      //fsj:=' and isnull(JMM.CKName,'''')='''' ';
      fsj:=fsj+' and JMM.PSName='''+Trim(ClientDataSet2.fieldbyname('PSName').AsString)+'''';
      fsj:=fsj+' and JMM.FactoryName='''+Trim(ClientDataSet2.fieldbyname('FactoryName').AsString)+'''';
      Parameters.ParamByName('WSql').Value:=fsj;
      Open;
    end;
    SCreateCDS20(ADOQueryTemp,CDS_Price);
    SInitCDSData20(ADOQueryTemp,CDS_Price);
  finally
    ADOQueryTemp.EnableControls;
  end;
end;

procedure TfrmBGLDChk.TVPriceDblClick(Sender: TObject);
begin
  try
    frmCWMDOtherFeeList:=TfrmCWMDOtherFeeList.Create(Application);
    with frmCWMDOtherFeeList do
    begin
      orderNo.Text:=Trim(Self.Order_Main.fieldbyname('OrderNo').AsString);
      PSName.Text:=Trim(Self.ClientDataSet2.fieldbyname('PSName').AsString);
      MDFactoryName.Text:=Trim(Self.ClientDataSet2.fieldbyname('FactoryName').AsString);
      FFPInt:=9;
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmCWMDOtherFeeList.Free;
  end;
end;

procedure TfrmBGLDChk.cxTabControl2Change(Sender: TObject);
var
  FMainId:String;
begin
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrder_Main where OrderNo='''+Trim(Order_Main.fieldbyname('OrderNo').AsString)+'''');
    Open;
  end;
  FMainId:=Trim(ADOQueryTemp.fieldbyname('MainId').AsString);
  with  ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrder_Main_MD_HZ A where ORDMainId='''+Trim(FMainId)+'''');
    sql.Add(' and exists(select * from KH_Zdy B where B.ZdyName=A.ItemName and B.Type=''YFName'' and isnull(Note,'''')=''其它费用'' )');
    if cxTabControl2.TabIndex=0 then
    begin
      sql.Add(' and isnull(BGID,'''')='''' ');
    end else
    begin
      sql.Add(' and isnull(BGID,'''')='''+Trim(Order_Main.fieldbyname('BGID').AsString)+'''');
    end;
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,CDS_Fee);
  SInitCDSData20(ADOQueryTemp,CDS_Fee);
end;

end.
