unit U_CGPriceChk_BF;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxGraphics, cxCustomData, cxStyles, cxTL, cxMaskEdit, DB, ADODB,
  cxInplaceContainer, cxDBTL, cxControls, cxTLData, ComCtrls, ToolWin,
  StdCtrls, cxFilter, cxData, cxDataStorage, cxEdit, cxDBData, DBClient,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, ExtCtrls,
  cxSplitter, cxGridLevel, cxClasses, cxGridCustomView, cxGrid,
  cxGridCustomPopupMenu, cxGridPopupMenu, RM_Dataset, RM_System, RM_Common,
  RM_Class, RM_GridReport, IdBaseComponent, IdComponent, IdTCPConnection,
  IdTCPClient, IdFTP,ShellAPI,IniFiles, cxCheckBox, cxCalendar,
  cxButtonEdit, cxTextEdit, cxPC, cxDropDownEdit, Menus, cxLookAndFeels,
  cxLookAndFeelPainters, dxSkinsCore,  
     dxSkinDarkRoom,
    
     
     
    
    
    
    
   dxSkinOffice2013White, 
     dxSkinSharpPlus,
   dxSkinSpringTime,  
   dxSkinsDefaultPainters, 
     dxSkinscxPCPainter,
  cxNavigator;

type
  TfrmCGPriceChk_BF = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    Panel1: TPanel;
    ToolButton2: TToolButton;
    ADOQueryMain: TADOQuery;
    ToolButton1: TToolButton;
    Label3: TLabel;
    GYSJCName: TEdit;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cxGridLevel1: TcxGridLevel;
    begdate: TDateTimePicker;
    Enddate: TDateTimePicker;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_HZ: TDataSource;
    CDS_HZ: TClientDataSet;
    v2P_Spec: TcxGridDBColumn;
    P_CodeName: TEdit;
    Label4: TLabel;
    CheckBox1: TCheckBox;
    Label12: TLabel;
    ChkStatusP: TComboBox;
    v2P_Color: TcxGridDBColumn;
    v2P_HX: TcxGridDBColumn;
    Label5: TLabel;
    HanShui: TComboBox;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    N3: TMenuItem;
    Label1: TLabel;
    N4: TMenuItem;
    N5: TMenuItem;
    N6: TMenuItem;
    N7: TMenuItem;
    Label2: TLabel;
    P_Color: TEdit;
    FactoryNo: TEdit;
    Panel3: TPanel;
    Label13: TLabel;
    Label14: TLabel;
    Label15: TLabel;
    Label16: TLabel;
    cxGridPB: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column9: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1JCDanWeiJC: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1MYType: TcxGridDBColumn;
    v1filler: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column17: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1MYMDPrice: TcxGridDBColumn;
    v1MYMDMoney: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    cxGridPBLevel1: TcxGridLevel;
    cxGridM: TcxGrid;
    TV3: TcxGridDBTableView;
    v1RKNo: TcxGridDBColumn;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    v1editer: TcxGridDBColumn;
    cxGridDBColumn5: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    cxGridDBColumn7: TcxGridDBColumn;
    cxGridDBColumn8: TcxGridDBColumn;
    cxGridDBColumn9: TcxGridDBColumn;
    v1IFFZ: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    cxGridX: TcxGrid;
    TV4: TcxGridDBTableView;
    cxGridDBColumn10: TcxGridDBColumn;
    v1MYCode: TcxGridDBColumn;
    cxGridDBColumn11: TcxGridDBColumn;
    cxGridDBColumn12: TcxGridDBColumn;
    cxGridDBColumn13: TcxGridDBColumn;
    cxGridDBColumn14: TcxGridDBColumn;
    v1MYColor: TcxGridDBColumn;
    v1MYColorNo: TcxGridDBColumn;
    cxGridDBColumn15: TcxGridDBColumn;
    cxGridDBColumn16: TcxGridDBColumn;
    cxGridDBColumn17: TcxGridDBColumn;
    cxGridDBColumn18: TcxGridDBColumn;
    cxGridDBColumn19: TcxGridDBColumn;
    v1CIFFJ: TcxGridDBColumn;
    cxGridDBColumn20: TcxGridDBColumn;
    cxGridXLevel1: TcxGridLevel;
    ADO_X: TADOQuery;
    CDS_X: TClientDataSet;
    ADO_M: TADOQuery;
    CDS_M: TClientDataSet;
    CDS_PB: TClientDataSet;
    ADO_PB: TADOQuery;
    Panel2: TPanel;
    v2Column1: TcxGridDBColumn;
    DataSourceM: TDataSource;
    DataSourceX: TDataSource;
    DataSourcePB: TDataSource;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure GYSJCNameChange(Sender: TObject);
    procedure cxGridDBColumn5PropertiesEditValueChanged(Sender: TObject);
    procedure cxGridDBColumn1PropertiesEditValueChanged(Sender: TObject);
    procedure cxGridDBColumn3PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure cxGridDBColumn6PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure ToolButton1Click(Sender: TObject);
    procedure v2Column2PropertiesEditValueChanged(Sender: TObject);
    procedure v2BatchNoPropertiesEditValueChanged(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure v2Column7PropertiesEditValueChanged(Sender: TObject);
    procedure v2Column8PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure GYSJCNameKeyPress(Sender: TObject; var Key: Char);
    procedure v2Column11CustomDrawCell(Sender: TcxCustomGridTableView;
      ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo;
      var ADone: Boolean);
    procedure v2Column11PropertiesEditValueChanged(Sender: TObject);
    procedure v2Column14PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v2P_SpecPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure N3Click(Sender: TObject);
    procedure N6Click(Sender: TObject);
    procedure N7Click(Sender: TObject);
    procedure N4Click(Sender: TObject);
    procedure N5Click(Sender: TObject);
    procedure FactoryNoKeyPress(Sender: TObject; var Key: Char);
    procedure CheckBox1Click(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure Tv2MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);

  private
    { Private declarations }

    procedure InitGridHZ();
    procedure InitGrid();
    function  SaveData():Boolean;
    procedure InitYFName();
    procedure InitGridM();
    procedure InitGridX();
    procedure InitGridPB();
  public
    fFlag:integer;
    { Public declarations }
    RKFlag,FCYID,fmanage:String;

  end;

var
  frmCGPriceChk_BF: TfrmCGPriceChk_BF;

implementation
uses
  U_DataLink,U_ZDYHelp,U_YSEdit,U_RTFun,U_KHListSelJJ,U_Fun;

{$R *.dfm}
procedure TfrmCGPriceChk_BF.InitGrid();
begin
  ToolBar1.SetFocus;
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      SQL.Clear;
      Filtered:=False;
      sql.Add(' select MyType,SUM(isnull(MYMDMoney,0)) MYMDMoney,A.FactoryNo,A.FactoryName');
      sql.Add(',GYSJCName=(select KHNameJC from KH_Main KM where KM.KHName=A.FactoryName)');
      sql.Add(' from YS_Money_CR A');
      sql.Add(' inner join CK_MYSC_CR B on B.MYID=A.YFTypeID');
      if CheckBox1.Checked then
      begin
        sql.Add('where A.CRTime>='''+FormatDateTime('yyyy-MM-dd',begdate.DateTime)+''' ');
        sql.Add(' and A.CRTime<'''+FormatDateTime('yyyy-MM-dd',Enddate.DateTime+1)+''' ');
      end else
      begin
        sql.Add('where A.CRTime>=''2000-01-01'' ');
        sql.Add(' and A.CRTime<''2500-01-01'' ');
      end;
      sql.Add(' and A.CRType=''应付款登记''  ');
      sql.Add(' GROUP BY MyType,FactoryName,A.FactoryNo,A.FactoryName  ');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_HZ);
    SInitCDSData20(ADOQueryMain,CDS_HZ);
  finally
    ADOQueryMain.EnableControls;
    ToolButton2.Click;
  end;
end;

procedure TfrmCGPriceChk_BF.InitGridHZ();
begin
end;

procedure TfrmCGPriceChk_BF.FormDestroy(Sender: TObject);
begin
 // frmYFCR:=nil;
  frmCGPriceChk_BF:=nil;
end;

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

procedure TfrmCGPriceChk_BF.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('应付款登记YX',Tv2,'财务管理');
  Close;
end;
procedure TfrmCGPriceChk_BF.FormShow(Sender: TObject);
begin
  ReadCxGrid('应付款登记YX',Tv2,'财务管理');
  Enddate.DateTime:=SGetServerDate(ADOQueryTemp);
  begdate.DateTime:=SGetServerDateMBeg(ADOQueryTemp);
  cxGridM.Visible:=False;
  cxGridX.Visible:=False;
  cxGridPB.Visible:=False;
  InitGrid();
end;
procedure TfrmCGPriceChk_BF.InitYFName();

begin

end;

procedure TfrmCGPriceChk_BF.TBRafreshClick(Sender: TObject);
begin
  begdate.SetFocus;
  InitGrid();
end;

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

procedure TfrmCGPriceChk_BF.GYSJCNameChange(Sender: TObject);
begin
  ToolButton2.Click;
end;

function TfrmCGPriceChk_BF.SaveData():Boolean;
var
  maxId,CRID:String;
begin
  try
    ADOQueryCmd.Connection.BeginTrans;
    if GetLSNo(ADOQueryCmd,maxId,'YS','YS_Money_CR',4,1)=False then
    begin
      Result:=False;
      ADOQueryCmd.Connection.RollbackTrans;
      Application.MessageBox('取最大号失败！','提示',0);
      Exit;
    end;
    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('select * from YS_Money_KC where FactoryName='''+Trim(CDS_HZ.fieldbyname('FactoryName').AsString)+''' ');
      sql.Add(' and KCType=''KH'' ');
      Open;
    end;
    if ADOQueryCmd.IsEmpty=False then
    begin
      CRID:=ADOQueryCmd.fieldbyname('CRID').AsString;
    end else
    begin
      with ADOQueryCmd do
      begin
        Close;
        sql.Clear;
        sql.Add('Update YS_Money_CRID set CRID=CRID+1');
        sql.Add('select * from YS_Money_CRID ');
        Open;
      end;
      CRID:=ADOQueryCmd.fieldbyname('CRID').AsString;
      with ADOQueryCmd do
      begin
        Close;
        SQL.Clear;
        sql.Add('select * from YS_Money_KC where 1<>1');
        Open;
      end;
      with ADOQueryCmd do
      begin
        Append;
        FieldByName('CRID').Value:=StrToInt(CRID);
        FieldByName('FactoryNo').Value:=Trim(CDS_HZ.fieldbyname('FactoryNo').AsString);
        FieldByName('FactoryName').Value:=Trim(CDS_HZ.fieldbyname('FactoryName').AsString);
        FieldByName('ZdyStr1').Value:='应收收';
        Post;
      end;
    end;
    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('select * from YS_Money_CR where 1<>1');
      Open;
    end;
    with ADOQueryCmd do
    begin
      Append;
      FieldByName('YFID').Value:=Trim(maxId);
      FieldByName('CRID').Value:=StrToInt(CRID);
      RTSetSaveDataCDS(ADOQueryCmd,Tv2,CDS_HZ,'YS_Money_CR',7);
      FieldByName('Filler').Value:=Trim(DName);
      FieldByName('CRType').Value:='应收款登记';
      FieldByName('CRFlag').Value:='应收收';
      FieldByName('QtyFlag').Value:=1;
      FieldByName('FactoryNo').Value:=Trim(CDS_HZ.fieldbyname('FactoryNo').AsString);
      FieldByName('FactoryName').Value:=Trim(CDS_HZ.fieldbyname('FactoryName').AsString);
      FieldByName('CRTime').Value:=formatdateTIme('yyyy-MM-dd',CDS_HZ.fieldbyname('CRTime').AsDateTime);
      Post;
    end;
    with CDS_HZ do
    begin
      Edit;
      FieldByName('YFId').Value:=Trim(maxId);
      FieldByName('CRID').Value:=StrToInt(CRID);
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Result:=True;
  except
    Result:=True;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('增行失败!','提示',0);
  end;
end;

procedure TfrmCGPriceChk_BF.cxGridDBColumn5PropertiesEditValueChanged(
  Sender: TObject);
var
  mvalue,FQty,FPrice,FMoney,FShuiDian,FHSPrice,FHSMoney,FJSMoney,FHZFee,FFieldName:String;
begin
  mvalue:=TcxTextEdit(Sender).EditingText;
  FFieldName:=Trim(Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName);
  with CDS_HZ do
  begin
    Edit;
    if Trim(mvalue)<>'' then
      FieldByName(FFieldName).Value:=Trim(mvalue)
    else
      FieldByName(FFieldName).Value:=Null;
    Post;
  end;

  FQty:=Trim(CDS_HZ.fieldbyname('Qty').AsString);
  if Trim(FQty)='' then FQty:='0';

  FPrice:=Trim(CDS_HZ.fieldbyname('Price').AsString);
  if Trim(FPrice)='' then FPrice:='0';
  FQty:=Trim(CDS_HZ.fieldbyname('Qty').AsString);
  if Trim(FQty)='' then FQty:='0';

  FHZFee:=Trim(CDS_HZ.fieldbyname('HZFee').AsString);
  if Trim(FHZFee)='' then FHZFee:='0';

  FMoney:=Trim(CDS_HZ.fieldbyname('Money').AsString);
  if Trim(FMoney)='' then FMoney:='0';

  if Trim(FFieldName)<>'Money' then
  begin
    FMoney:=FloatToStr(StrToFloat(FQty)*StrToFloat(FPrice)+StrToFloat(FHZFee));
  end;
  with CDS_HZ do
  begin
    Edit;
    FieldByName('Money').Value:=StrToFloat(FMoney);
    if Trim(CDS_HZ.fieldbyname('BZType').AsString)='￥' then
    begin
      FieldByName('MoneyRMB').Value:=StrToFloat(FMoney);
    end else
    if Trim(CDS_HZ.fieldbyname('BZType').AsString)='$' then
    begin
      FieldByName('MoneyMJ').Value:=StrToFloat(FMoney);
    end;
    Post;
  end;

  FShuiDian:=Trim(CDS_HZ.fieldbyname('ShuiDian').AsString);
  if Trim(FShuiDian)='' then FShuiDian:='0';

  if Trim(CDS_HZ.fieldbyname('ShuiDian').AsString)<>'' then
  begin
    with CDS_HZ do
    begin
      Edit;
      FieldByName('HSPrice').Value:=StrToFloat(FPrice)*(1+StrToFloat(FShuiDian)*0.01);
      FieldByName('HSMoney').Value:=StrToFloat(FPrice)*(1+StrToFloat(FShuiDian)*0.01)*StrToFloat(FQty)+StrToFloat(FHZFee);
      FieldByName('JSMoney').Value:=StrToFloat(FPrice)*(1+StrToFloat(FShuiDian)*0.01)*StrToFloat(FQty)+StrToFloat(FHZFee);
      post;
    end;
  end else
  begin
    with CDS_HZ do
    begin
      Edit;
      FieldByName('HSPrice').Value:=Null;
      FieldByName('HSMoney').Value:=Null;
      FieldByName('JSMoney').Value:=StrToFloat(FMoney);
      post;
    end;
  end;


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

procedure TfrmCGPriceChk_BF.cxGridDBColumn1PropertiesEditValueChanged(
  Sender: TObject);
var
  mvalue,FFieldName:String;
begin
  mvalue:=TcxTextEdit(Sender).EditingText;
  FFieldName:=Trim(Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName);
  with CDS_HZ do
  begin
    Edit;
    FieldByName(FFieldName).Value:=Trim(mvalue);
    Post;
  end;
  
  tv2.Controller.EditingController.ShowEdit();
end;

procedure TfrmCGPriceChk_BF.cxGridDBColumn3PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  if Trim(CDS_HZ.FieldByName('YFType').AsString)='自动生成' then
  begin
    Application.MessageBox('自动生成的数据不能修改!','提示',0);
    Exit;
  end;
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='YFName';
      flagname:='项目及摘要';
      MainType:='付款';
      if ShowModal=1 then
      begin
        with Self.CDS_HZ do
        begin
          Edit;
          FieldByName('YFCode').Value:=Trim(ClientDataSet1.fieldbyname('ZdyNo').AsString);
          FieldByName('YFName').Value:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
        
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmCGPriceChk_BF.cxGridDBColumn6PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='OrderUnit';
      flagname:='数量单位';
      if ShowModal=1 then
      begin
        Self.CDS_HZ.Edit;
        Self.CDS_HZ.FieldByName('QtyUnit').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmCGPriceChk_BF.ToolButton1Click(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then Exit;
  SelExportData(Tv2,ADOQueryMain,'应付款列表');
end;

procedure TfrmCGPriceChk_BF.v2Column2PropertiesEditValueChanged(Sender: TObject);
var
  mvalue,FBBMoney,FKCBB,FFieldName:String;
begin
  mvalue:=TcxTextEdit(Sender).EditingText;
  if Trim(mvalue)='' then
  begin
    mvalue:='0';
  end;
  FFieldName:=Trim(Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName);
  with CDS_HZ do
  begin
    Edit;
    FieldByName(FFieldName).Value:=Trim(mvalue);
    Post;
  end;

 
end;

procedure TfrmCGPriceChk_BF.v2BatchNoPropertiesEditValueChanged(Sender: TObject);
var
  mvalue,FFieldName:String;
begin
  mvalue:=TcxTextEdit(Sender).EditingText;
  FFieldName:=Trim(Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName);
  with CDS_HZ do
  begin
    Edit;
    FieldByName(FFieldName).Value:=Trim(mvalue);
    Post;
  end;
  
end;

procedure TfrmCGPriceChk_BF.cxTabControl1Change(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmCGPriceChk_BF.v2Column7PropertiesEditValueChanged(Sender: TObject);
var
  mvalue:Boolean;
begin
  mvalue:=TcxCheckBox(Sender).EditingValue;
  with CDS_HZ do
  begin
    Edit;
    FieldByName('KPFlag').Value:=mvalue;
    Post;
  end;
  with ADOQueryCmd do
  begin
    Close;
    SQL.Clear;
    sql.Add('update YS_Money_CR Set ');
    if mvalue=true then
    begin
      sql.Add(' KPFlag=1 ');
    end else
    begin
      sql.Add(' KPFlag=0 ');
    end;
    sql.Add(' where YFID='''+Trim(CDS_HZ.fieldbyname('YFID').AsString)+'''');
    ExecSQL;
  end;
end;

procedure TfrmCGPriceChk_BF.v2Column8PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  if Trim(CDS_HZ.FieldByName('YFType').AsString)='自动生成' then
  begin
    Application.MessageBox('自动生成的数据不能修改!','提示',0);
    Exit;
  end;
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='GSTT';
      flagname:='公司抬头';
      V1Name.Caption:='中文名称';
      if ShowModal=1 then
      begin
        with Self.CDS_HZ do
        begin
          Edit;
          FieldByName('ComTaiTou').Value:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('UPdate YS_Money_CR ');
          sql.Add(' Set ComTaiTou='''+Trim(ClientDataSet1.fieldbyname('ZdyName').AsString)+'''');
          SQL.Add(',Editer='''+Trim(DName)+'''');
          SQL.Add(',Edittime=getdate() ');
          SQL.Add(' where YFId='''+Trim(CDS_HZ.fieldbyname('YFId').AsString)+'''');
          ExecSQL;
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmCGPriceChk_BF.GYSJCNameKeyPress(Sender: TObject;
  var Key: Char);
begin
  if Key=#13 then
  begin
    if Trim(GYSJCName.Text)='' then Exit;
    ToolBar1.SetFocus;
    try
      ADOQueryMain.DisableControls;
      with ADOQueryMain do
      begin
        Close;
        SQL.Clear;
        Filtered:=False;
        sql.Add(' select A.*,QtyStr=dbo.[F_Get_ShuZiStr](A.Qty),MoneyStr=dbo.[F_Get_ShuZiStr](A.Money) ');
        sql.Add(',FactoryName10=dbo.getPinYin(A.FactoryName)+RTrim(A.FactoryName)');
        sql.Add(' from YS_Money_CR A where exists (select * from KH_Main KM where KM.KHName=A.FactoryName and KM.KHNameJC='''+Trim(GYSJCName.Text)+''')');
        if CheckBox1.Checked then
        begin
          sql.Add(' and A.CRTime>='''+FormatDateTime('yyyy-MM-dd',begdate.DateTime)+''' ');
          sql.Add(' and A.CRTime<'''+FormatDateTime('yyyy-MM-dd',Enddate.DateTime+1)+''' ');
        end;
        sql.Add(' and A.CRType=''应付款登记''  ');
        Open;
      end;
      SCreateCDS20(ADOQueryMain,CDS_HZ);
      SInitCDSData20(ADOQueryMain,CDS_HZ);
    finally
      ADOQueryMain.EnableControls;
      ToolButton2.Click;
    end;
  end;
end;

procedure TfrmCGPriceChk_BF.v2Column11CustomDrawCell(
  Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
  AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
var
  id:Integer;
begin
  Id:=TV2.GetColumnByFieldName('DZFlag').Index;//;-TV1.GroupedItemCount;
  if Id<0 then Exit;
  if AViewInfo.GridRecord.Values[Id]=True then
  begin
    ACanvas.Brush.Color:=clRed;
  end;
end;

procedure TfrmCGPriceChk_BF.v2Column11PropertiesEditValueChanged(
  Sender: TObject);
var
  mvalue:Boolean;
begin
  mvalue:=TcxCheckBox(Sender).EditValue;
  with CDS_HZ do
  begin
    Edit;
    FieldByName('DZFlag').Value:=mvalue;
  end;
  if mvalue=True then
  begin
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('Update YS_Money_CR Set DZFlag=1,DZTime=getdate(),DZPerson='''+Trim(DName)+'''');
      sql.Add(' where YFID='''+Trim(CDS_HZ.fieldbyname('YFID').AsString)+'''');
      ExecSQL;
    end;
  end else
  begin
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('Update YS_Money_CR Set DZFlag=0,DZTime=getdate(),DZPerson='''+Trim(DName)+'''');
      sql.Add(' where YFID='''+Trim(CDS_HZ.fieldbyname('YFID').AsString)+'''');
      ExecSQL;
    end;
  end; 
end;
procedure TfrmCGPriceChk_BF.v2Column14PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='FHTaiTou';
      flagname:='公司抬头';
      if ShowModal=1 then
      begin
        with CDS_HZ do
        begin
          Edit;
          FieldByName('ComTaiTou').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmCGPriceChk_BF.v2P_SpecPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  if Trim(CDS_HZ.fieldbyname('P_CodeName').AsString)='' then
  begin
    Application.MessageBox('品名不能为空!','提示',0);
    Exit;
  end;
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='HLMLSpec';
      flagname:='面料规格';
      MainType:=Trim(CDS_HZ.fieldbyname('P_CodeName').AsString);
      if ShowModal=1 then
      begin
        with Self.CDS_HZ do
        begin
          Edit;
          FieldByName('P_Spec').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmCGPriceChk_BF.N1Click(Sender: TObject);
var
  FDate:TDateTime;
begin
  if CDS_HZ.IsEmpty then Exit;
  ToolBar1.SetFocus;
  try
    FDate:=SGetServerDateTime(ADOQueryTemp);
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from YS_Money_CR where YFID='''+Trim(CDS_HZ.fieldbyname('YFID').AsString)+'''');
      Open;
    end;
    with ADOQueryCmd do
    begin
      Edit;
      RTSetSaveDataCDS(ADOQueryCmd,Tv2,CDS_HZ,'YS_Money_CR',7);
      FieldByName('ChkerP').Value:=Trim(DName);
      FieldByName('ChkTimeP').Value:=FDate;
      FieldByName('ChkStatusP').Value:='已审核';
      FieldByName('ChkerQ').Value:=Trim(DName);
      FieldByName('ChkTimeQ').Value:=FDate;
      FieldByName('ChkStatusQ').Value:='已审核';
      Post;
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('Update YS_Money_CR Set ');
      sql.Add('HSMoney=Money');
      sql.Add(',JSMoney=Money');
      sql.Add(' where YFID='''+Trim(CDS_HZ.fieldbyname('YFID').AsString)+'''');
      ExecSQL;
    end;
    with CDS_HZ do
    begin
      Edit;
      FieldByName('ChkStatusP').Value:='已审核';
      FieldByName('ChkStatusQ').Value:='已审核';
      FieldByName('ChkTimeP').Value:=FDate;
      FieldByName('ChkTimeQ').Value:=FDate;
      FieldByName('ChkerP').Value:=Trim(DName);
      FieldByName('ChkerQ').Value:=Trim(DName);
      Post;
    end;
    ADOQueryCmd.Connection.CommitTrans;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作失败!','提示',0);
  end;
end;

procedure TfrmCGPriceChk_BF.N2Click(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then Exit;
  ToolBar1.SetFocus;
  try
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from YS_Money_CR where YFID='''+Trim(CDS_HZ.fieldbyname('YFID').AsString)+'''');
      Open;
    end;
    with ADOQueryCmd do
    begin
      Edit;
      FieldByName('ChkerP').Value:=Null;
      FieldByName('ChkTimeP').Value:=Null;
      FieldByName('ChkStatusP').Value:='未审核';
      FieldByName('ChkerQ').Value:=Null;
      FieldByName('ChkTimeQ').Value:=Null;
      FieldByName('ChkStatusQ').Value:='未审核';
      Post;
    end;
    with CDS_HZ do
    begin
      Edit;
      FieldByName('ChkStatusP').Value:='未审核';
      FieldByName('ChkStatusQ').Value:='未审核';
      FieldByName('ChkerQ').Value:=Null;
      FieldByName('ChkTimeQ').Value:=Null;
      FieldByName('ChkerP').Value:=Null;
      FieldByName('ChkTimeP').Value:=Null;
      Post;
    end;
    ADOQueryCmd.Connection.CommitTrans;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作失败!','提示',0);
  end;
end;

procedure TfrmCGPriceChk_BF.N3Click(Sender: TObject);
begin
  if Trim(CDS_HZ.fieldbyname('ChkStatusP').AsString)='已审核' then
  begin
    Application.MessageBox('数据已审核，不能修改!','提示',0);
    Exit;
  end;
  try
    frmYSEdit:=TfrmYSEdit.Create(Application);
    with frmYSEdit do
    begin
      FCKNO:=Trim(Self.CDS_HZ.fieldbyname('CKNO').AsString);
      FYFID:=Trim(Self.CDS_HZ.fieldbyname('YFID').AsString);
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmYSEdit.Free;
  end;
end;

procedure TfrmCGPriceChk_BF.N6Click(Sender: TObject);
begin
  SelOKNo(CDS_HZ,True);
end;

procedure TfrmCGPriceChk_BF.N7Click(Sender: TObject);
begin
  SelOKNo(CDS_HZ,False);
end;

procedure TfrmCGPriceChk_BF.N4Click(Sender: TObject);
var
  FDate:TDateTime;
begin
  if CDS_HZ.IsEmpty then Exit;
  if CDS_HZ.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  ToolBar1.SetFocus;
  try
    Panel2.Visible:=True;
    Panel2.Refresh;
    FDate:=SGetServerDateTime(ADOQueryTemp);
    ADOQueryCmd.Connection.BeginTrans;
    CDS_HZ.DisableControls;
    with CDS_HZ do
    begin
      First;
      while CDS_HZ.Locate('SSel',True,[]) do
      begin
        if Trim(CDS_HZ.fieldbyname('ChkStatusP').AsString)<>'已审核' then
        begin
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('select * from YS_Money_CR where YFID='''+Trim(CDS_HZ.fieldbyname('YFID').AsString)+'''');
            Open;
          end;
          with ADOQueryCmd do
          begin
            Edit;
            RTSetSaveDataCDS(ADOQueryCmd,Tv2,CDS_HZ,'YS_Money_CR',7);
            FieldByName('ChkerP').Value:=Trim(DName);
            FieldByName('ChkTimeP').Value:=FDate;
            FieldByName('ChkStatusP').Value:='已审核';
            FieldByName('ChkerQ').Value:=Trim(DName);
            FieldByName('ChkTimeQ').Value:=FDate;
            FieldByName('ChkStatusQ').Value:='已审核';
            Post;
          end;
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('Update YS_Money_CR Set ');
            sql.Add('HSMoney=Money');
            sql.Add(',JSMoney=Money');
            sql.Add(' where YFID='''+Trim(CDS_HZ.fieldbyname('YFID').AsString)+'''');
            ExecSQL;
          end;
          with CDS_HZ do
          begin
            Edit;
            FieldByName('ChkStatusP').Value:='已审核';
            FieldByName('ChkerP').Value:=Trim(DName);
            FieldByName('ChkTimeP').Value:=FDate;
            FieldByName('ChkStatusQ').Value:='已审核';
            FieldByName('ChkerQ').Value:=Trim(DName);
            FieldByName('ChkTimeQ').Value:=FDate;
            FieldByName('SSel').Value:=False;
            Post;
          end;
        end else
        begin
          with CDS_HZ do
          begin
            Edit;
            FieldByName('SSel').Value:=False;
            Post;
          end;
        end;
      end;
    end;
    CDS_HZ.EnableControls;

    ADOQueryCmd.Connection.CommitTrans;
    Panel2.Visible:=False;
  except
    Panel2.Visible:=False;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作失败!','提示',0);
  end;
end;

procedure TfrmCGPriceChk_BF.N5Click(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then Exit;
  if CDS_HZ.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  ToolBar1.SetFocus;
  try
    Panel2.Visible:=True;
    Panel2.Refresh;
    ADOQueryCmd.Connection.BeginTrans;
    CDS_HZ.DisableControls;
    with CDS_HZ do
    begin
      First;
      while CDS_HZ.Locate('SSel',True,[]) do
      begin
        if Trim(CDS_HZ.fieldbyname('ChkStatusP').AsString)<>'未审核' then
        begin
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('select * from YS_Money_CR where YFID='''+Trim(CDS_HZ.fieldbyname('YFID').AsString)+'''');
            Open;
          end;
          with ADOQueryCmd do
          begin
            Edit;
            FieldByName('ChkerP').Value:=Null;
            FieldByName('ChkTimeP').Value:=Null;
            FieldByName('ChkStatusP').Value:='未审核';
            FieldByName('ChkerQ').Value:=Null;
            FieldByName('ChkTimeQ').Value:=Null;
            FieldByName('ChkStatusQ').Value:='未审核';
            Post;
          end;
          with CDS_HZ do
          begin
            Edit;
            FieldByName('ChkStatusP').Value:='未审核';
            FieldByName('ChkerP').Value:=Null;
            FieldByName('ChkTimeP').Value:=Null;
            FieldByName('ChkStatusQ').Value:='未审核';
            FieldByName('ChkerQ').Value:=Null;
            FieldByName('ChkTimeQ').Value:=Null;
            FieldByName('SSel').Value:=False;
            Post;
          end;
        end else
        begin
          with CDS_HZ do
          begin
            Edit;
            FieldByName('SSel').Value:=False;
            Post;
          end;
        end;

      end;
    end;
    CDS_HZ.EnableControls;

    ADOQueryCmd.Connection.CommitTrans;
    Panel2.Visible:=False;
  except
    Panel2.Visible:=False;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作失败!','提示',0);
  end;
end;

procedure TfrmCGPriceChk_BF.FactoryNoKeyPress(Sender: TObject; var Key: Char);
begin
  if Key=#13 then
  begin
    if Trim(FactoryNo.Text)='' then Exit;
    ToolBar1.SetFocus;
    try
      ADOQueryMain.DisableControls;
      with ADOQueryMain do
      begin
        Close;
        SQL.Clear;
        Filtered:=False;
        sql.Add(' select A.*,QtyStr=dbo.[F_Get_ShuZiStr](A.Qty),MoneyStr=dbo.[F_Get_ShuZiStr](A.Money) ');
        sql.Add(',FactoryName10=dbo.getPinYin(A.FactoryName)+RTrim(A.FactoryName)');
        sql.Add(' from YS_Money_CR A where FactoryNo='''+Trim(FactoryNo.Text)+'''');
        if CheckBox1.Checked then
        begin
          sql.Add(' and A.CRTime>='''+FormatDateTime('yyyy-MM-dd',begdate.DateTime)+''' ');
          sql.Add(' and A.CRTime<'''+FormatDateTime('yyyy-MM-dd',Enddate.DateTime+1)+''' ');
        end;
        sql.Add(' and A.CRType=''应收款登记''  ');
        Open;
      end;
      SCreateCDS20(ADOQueryMain,CDS_HZ);
      SInitCDSData20(ADOQueryMain,CDS_HZ);
    finally
      ADOQueryMain.EnableControls;
      ToolButton2.Click;
    end;
  end;
end;

procedure TfrmCGPriceChk_BF.CheckBox1Click(Sender: TObject);
begin
  if CheckBox1.Checked=True then
  begin
    begdate.Visible:=true;
    Enddate.Visible:=true;
  end
  else
  begin
    begdate.Visible:=false;
    Enddate.Visible:=false;
  end;
end;

procedure TfrmCGPriceChk_BF.ToolButton3Click(Sender: TObject);
begin
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from CK_MYSC_CR where MYID='''+Trim(CDS_HZ.fieldbyname('YFTypeId').AsString)+'''');
    open;
  end;
  if ADOQueryCmd.IsEmpty=false then
  begin
    Application.MessageBox('存在数据','提示');
    exit;
  end;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('delete from YS_Money_CR where YFID='''+Trim(CDS_HZ.fieldbyname('YFID').AsString)+'''');
    ExecSQL;
  end;
  CDS_HZ.Delete;
end;

procedure TfrmCGPriceChk_BF.InitGridM();
begin
  try
    ADO_M.DisableControls;
    with ADO_M do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add(' select A.CRTime,A.filler,A.Editer,A.MYType,A.RKNo,A.KHName,A.JCDanWei,A.MYTypeFlag');
      SQL.ADD(',Sum(PS) PS,Sum(KgQty) KgQty,Sum(Qty) Qty,Sum(MYMDMoney) MYMDMoney ');
      sql.add(',IFFZ=(select Count(B.WBID) from TP_File B where B.WBID=A.RKNo and B.TFType=''采购棉'')');
      sql.Add(',KHNameJC=(select Top 1 B.KHNameJC from KH_Main B ');
      sql.Add(' where isnull(B.KHFlag,'''')=''GYS'' and isnull(B.Valid,'''')=''Y'' and B.KHName=A.KHName)');
      sql.Add(',JCDanWeiJC=(select Top 1 B.KHNameJC from KH_Main B ');
      sql.Add(' where isnull(B.KHFlag,'''')=''GS'' and isnull(B.Valid,'''')=''Y'' and B.KHName=A.JCDanWei)');
      sql.Add(',JCKHNo=(select Top 1 B.KHNo from KH_Main B ');
      sql.Add(' where isnull(B.KHFlag,'''')=''GYS'' and isnull(B.Valid,'''')=''Y'' and B.KHName=A.JCDanWei)');
      sql.Add(' from CK_MYSC_CR A  ');
      sql.Add(' where 1=1 ');
      if CheckBox1.Checked=False then
      begin
        sql.Add(' and A.CRTime>='''+Trim(FormatDateTime('yyyy-MM-dd',now))+'''');
        sql.Add(' and A.CRTime<'''+Trim(FormatDateTime('yyyy-MM-dd',now+1))+'''');
        BegDate.Visible:=false;
        EndDate.Visible:=false;
      end
      else
      begin
        sql.Add(' and A.CRTime>='''+Trim(FormatDateTime('yyyy-MM-dd',BegDate.Date))+'''');
        sql.Add(' and A.CRTime<'''+Trim(FormatDateTime('yyyy-MM-dd',EndDate.Date+1))+'''');
        BegDate.Visible:=true;
        EndDate.Visible:=true;
      end;
      sql.Add(' and isnull(CRType,'''')=''采购入库'' ');
      SQL.Add(' and isnull(MYType,'''')=''采购棉''');
      SQL.Add(' and isnull(KHNo,'''')='''+CDS_HZ.FieldByName('FactoryNo').AsString+'''');
      SQL.Add(' group by A.CRTime,A.RKNo,A.filler,A.Editer,A.MYType,A.KHName,A.JCDanWei,A.MYTypeFlag');
      Open;
    end;
    SCreateCDS20(ADO_M,CDS_M);
    SInitCDSData20(ADO_M,CDS_M);
  finally
    ADO_M.EnableControls;
  end;
end;

procedure TfrmCGPriceChk_BF.InitGridX();
begin
  try
    ADO_X.DisableControls;
    with ADO_X do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add(' select A.* ');
      sql.add(',IFFZ=(select Count(B.WBID) from TP_File B where B.WBID=A.RKNo and B.TFType=''采购线'')');
      sql.Add(',KHNameJC=(select Top 1 B.KHNameJC from KH_Main B ');
      sql.Add(' where isnull(B.KHFlag,'''')=''GYS'' and isnull(B.Valid,'''')=''Y'' and B.KHName=A.KHName)');
      sql.Add(',JCDanWeiJC=(select Top 1 B.KHNameJC from KH_Main B ');
      sql.Add(' where isnull(B.KHFlag,'''')=''GS'' and isnull(B.Valid,'''')=''Y'' and B.KHName=A.JCDanWei)');
      sql.Add(',JCKHNo=(select Top 1 B.KHNo from KH_Main B ');
      sql.Add(' where isnull(B.KHFlag,'''')=''GYS'' and isnull(B.Valid,'''')=''Y'' and B.KHName=A.JCDanWei)');
      sql.Add(' from CK_MYSC_CR A  ');
      sql.Add(' where 1=1 ');
      if CheckBox1.Checked=False then
      begin
        sql.Add(' and A.CRTime>='''+Trim(FormatDateTime('yyyy-MM-dd',now))+'''');
        sql.Add(' and A.CRTime<'''+Trim(FormatDateTime('yyyy-MM-dd',now+1))+'''');
        BegDate.Visible:=false;
        EndDate.Visible:=false;
      end
      else
      begin
        sql.Add(' and A.CRTime>='''+Trim(FormatDateTime('yyyy-MM-dd',BegDate.Date))+'''');
        sql.Add(' and A.CRTime<'''+Trim(FormatDateTime('yyyy-MM-dd',EndDate.Date+1))+'''');
        BegDate.Visible:=true;
        EndDate.Visible:=true;
      end;
      sql.Add(' and isnull(CRType,'''')=''采购入库'' ');
      SQL.Add(' and isnull(MYType,'''')=''采购线''');
      SQL.Add(' and isnull(KHNo,'''')='''+CDS_HZ.FieldByName('FactoryNo').AsString+'''');
      sql.add(' order by CRTime,MYColorNo');
//      ShowMessage(sql.Text);
      Open;
    end;
    SCreateCDS20(ADO_X,CDS_X);
    SInitCDSData20(ADO_X,CDS_X);
  finally
    ADO_X.EnableControls;
  end;
end;

procedure TfrmCGPriceChk_BF.InitGridPB();
begin
  try
    ADO_PB.DisableControls;
    with ADO_PB do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add(' select A.* ');
      sql.Add(',KHNameJC=(select Top 1 B.KHNameJC from KH_Main B ');
      sql.Add(' where isnull(B.KHFlag,'''')=''GYS'' and isnull(B.Valid,'''')=''Y'' and B.KHName=A.KHName)');
      sql.Add(',JCDanWeiJC=(select Top 1 B.KHNameJC from KH_Main B ');
      sql.Add(' where isnull(B.KHFlag,'''')=''GYS'' and isnull(B.Valid,'''')=''Y'' and B.KHName=A.JCDanWei)');
      sql.Add(',JCKHNo=(select Top 1 B.KHNo from KH_Main B ');
      sql.Add(' where isnull(B.KHFlag,'''')=''GYS'' and isnull(B.Valid,'''')=''Y'' and B.KHName=A.JCDanWei)');
      sql.Add(' from CK_MYSC_CR A  ');
      sql.Add(' where 1=1 ');
      if CheckBox1.Checked=False then
      begin
        sql.Add(' and A.CRTime>='''+Trim(FormatDateTime('yyyy-MM-dd',now))+'''');
        sql.Add(' and A.CRTime<'''+Trim(FormatDateTime('yyyy-MM-dd',now+1))+'''');
        BegDate.Visible:=false;
        EndDate.Visible:=false;
      end
      else
      begin
        sql.Add(' and A.CRTime>='''+Trim(FormatDateTime('yyyy-MM-dd',BegDate.Date))+'''');
        sql.Add(' and A.CRTime<'''+Trim(FormatDateTime('yyyy-MM-dd',EndDate.Date+1))+'''');
        BegDate.Visible:=true;
        EndDate.Visible:=true;
      end;
      sql.Add(' and isnull(CRType,'''')=''采购入库'' ');
      SQL.Add('and isnull(MYType,'''')=''采购坯布''');
      SQL.Add('and isnull(KHNo,'''')='''+CDS_HZ.FieldByName('FactoryNo').AsString+'''');
      Open;
    end;
    SCreateCDS20(ADO_PB,CDS_PB);
    SInitCDSData20(ADO_PB,CDS_PB);
  finally
    ADO_PB.EnableControls;
  end;
end;
procedure TfrmCGPriceChk_BF.Tv2MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  cxGridM.Visible:=False;
  cxGridX.Visible:=False;
  cxGridPB.Visible:=False;
  if CDS_HZ.FieldByName('MyType').AsString='采购棉' then
  begin
    cxGridM.Visible:=True;
    cxGridM.Align:=alClient;
    initGridM();
  end;
  if CDS_HZ.FieldByName('MyType').AsString='采购线' then
  begin
    cxGridX.Visible:=True;
    cxGridX.Align:=alClient;
    initGridX();
  end;
  if CDS_HZ.FieldByName('MyType').AsString='采购坯布' then
  begin
    cxGridPB.Visible:=True;
    cxGridPB.Align:=alClient;
    initGridPB();
  end;
end;

end.


