unit U_YSCRKP;

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, cxCurrencyEdit, Menus;

type
  TfrmYSCRKP = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBDel: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    Panel1: TPanel;
    ToolButton2: TToolButton;
    Label1: TLabel;
    YFName: TEdit;
    ADOQueryMain: TADOQuery;
    ToolButton1: TToolButton;
    RM1: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    Label3: TLabel;
    FactoryName: TEdit;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn5: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    Label2: TLabel;
    Label6: TLabel;
    begdate: TDateTimePicker;
    Enddate: TDateTimePicker;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_HZ: TDataSource;
    CDS_HZ: TClientDataSet;
    ToolButton3: TToolButton;
    v2Column1: TcxGridDBColumn;
    VBZ: TcxGridDBColumn;
    VYB: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    VMOrderNo: TcxGridDBColumn;
    v2PS: TcxGridDBColumn;
    v2Column2: TcxGridDBColumn;
    v2MP_CodeName: TcxGridDBColumn;
    v2Column4: TcxGridDBColumn;
    v2Column5: TcxGridDBColumn;
    MP_CodeName: TEdit;
    Label4: TLabel;
    MP_Spec: TEdit;
    Label5: TLabel;
    Label7: TLabel;
    Edit1: TEdit;
    Button1: TButton;
    CheckBox1: TCheckBox;
    MOrderNo: TEdit;
    Label8: TLabel;
    Tchk: TToolButton;
    Tnochk: TToolButton;
    cxTabControl1: TcxTabControl;
    v2ComTaitou: TcxGridDBColumn;
    TZDSC: TToolButton;
    v2MaoQty: TcxGridDBColumn;
    v2JZQty: TcxGridDBColumn;
    v2ConNoHZ: TcxGridDBColumn;
    v2PRTColor: TcxGridDBColumn;
    Label9: TLabel;
    PRTColor: TEdit;
    v2PBNote: TcxGridDBColumn;
    v2MQty: TcxGridDBColumn;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    v2FeeType: TcxGridDBColumn;
    Label14: TLabel;
    ConNoHZ: TEdit;
    v2chkstatus: TcxGridDBColumn;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    ToolButton4: TToolButton;
    ToolButton5: TToolButton;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    v2SOrdDefStr4: TcxGridDBColumn;
    Label17: TLabel;
    KPType: TComboBox;
    Label15: TLabel;
    Note: TEdit;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure TBDelClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure FactoryNameChange(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure cxGridDBColumn8PropertiesEditValueChanged(Sender: TObject);
    procedure cxGridDBColumn5PropertiesEditValueChanged(Sender: TObject);
    procedure cxGridDBColumn1PropertiesEditValueChanged(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure cxGridDBColumn3PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure cxGridDBColumn6PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v2Column3PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure ToolButton1Click(Sender: TObject);
    procedure v2Column7PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v2PSPropertiesEditValueChanged(Sender: TObject);
    procedure v2Column2PropertiesEditValueChanged(Sender: TObject);
    procedure v2KPMoneyPropertiesEditValueChanged(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure TchkClick(Sender: TObject);
    procedure TnochkClick(Sender: TObject);
    procedure v2ComTaitouPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure TZDSCClick(Sender: TObject);
    procedure VBZPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v2Column4PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v2Column5PropertiesChange(Sender: TObject);
    procedure v2ConNoHZPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure Tv2StylesGetContentStyle(Sender: TcxCustomGridTableView;
      ARecord: TcxCustomGridRecord; AItem: TcxCustomGridTableItem;
      out AStyle: TcxStyle);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure v2KPTypePropertiesEditValueChanged(Sender: TObject);
  private
    { Private declarations }

    procedure InitGridHZ();
    procedure InitGrid();
    function  SaveData():Boolean;
    procedure SetStatus();

  public

    fflag:integer;
    { Public declarations }
    RKFlag,FCYID,canshu2,canshu1:String;
    fmanage:string;

  end;

var
  frmYSCRKP: TfrmYSCRKP;

implementation
uses
  U_DataLink,U_Fun,U_ZDYHelp, U_ProductOrderNewList, U_ProductOrderList,
  U_ZdyAttachment, U_SXCKNewList, U_SXCKNewList_SK,U_JYOrderCon_CX;

{$R *.dfm}
procedure TfrmYSCRKP.SetStatus();
var i:integer;
begin
  ToolButton4.Enabled:=false;
  ToolButton5.Enabled:=false;
  if cxTabControl1.TabIndex=0 then
  begin
    ToolButton4.Enabled:=true;
    //v2KPType.Options.Editing:=true;
  end;
  if cxTabControl1.TabIndex=1 then
  begin
    ToolButton5.Enabled:=true;
  end;
end;

procedure TfrmYSCRKP.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      SQL.Clear;
      sql.Add('select isnull(isnull(E.PrtCodeName,A.P_CodeName),D.MPrtCodeName) MP_CodeName,');
      sql.add('SCOrderNO=(select Top 1 JM.ConNo from Cloth_Main JM where JM.MainId=A.Mainid),');
      sql.add('ConNoHZ=isnull(F.ConNo,A.ConNO),isnull(isnull(E.prtspec,A.P_Spec),D.MPRTSpec) MP_Spec,');
      sql.add('isnull(A.OrderNo,D.OrderNo) MOrderNo,E.PRTColor,E.SOrdDefStr4,');
      sql.add('HTType=(isnull((select Top 1 M.MPRTType from JYOrder_ConORD Q ');
      sql.add(' inner join JYOrderCon_Main M on Q.ConMainid=M.Mainid where Q.Mainid=A.Mainid),F.MPRTType))');
      sql.add(',isnull(A.Price,E.PrtPrice) Price');
      sql.add(',A.*');
      sql.Add(' from YF_Money_CR A');
      sql.add(' left join JYOrder_Main D on D.Mainid=A.Mainid');
      sql.add(' left join JYOrderCon_Sub E on E.Subid=A.Conid');
      SQL.ADD(' Left join JYOrderCon_Main F on F.Mainid=E.Mainid');
      sql.Add(' where A.CRTime>='''+FormatDateTime('yyyy-MM-dd',begdate.DateTime)+''' ');
      sql.Add(' and CRTime<'''+FormatDateTime('yyyy-MM-dd',Enddate.DateTime+1)+''' ');
      sql.Add(' and A.CRType=''应收款登记'' ');
      sql.add(' and (A.YFName=''成品销售金额'' or Isnull(A.FeeType,'''')=''其他费用'')');
      sql.add(' and A.KPType=''需开''');
      sql.Add(' and isnull(A.status,''0'')>''0''');
      if cxtabcontrol1.TabIndex=0 then
      sql.add(' and isnull(KPstatus,'''')='''' ');
      if cxtabcontrol1.TabIndex=1 then
      sql.add(' and isnull(KPstatus,'''')<>'''' ');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_HZ);
    SInitCDSData20(ADOQueryMain,CDS_HZ);
    Label12.Caption:='0';
    Label13.Caption:='0';
  finally
    ADOQueryMain.EnableControls;
    //ToolButton2.Click;
  end;
end;

procedure TfrmYSCRKP.InitGridHZ();
begin

end;

procedure TfrmYSCRKP.FormDestroy(Sender: TObject);
begin
  frmYSCRKP:=nil;
end;

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

procedure TfrmYSCRKP.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('应收款登记5',Tv2,'财务管理');
  {with ADOQueryCmd do
  begin
    Close;
    SQL.Clear;
    sql.Add('delete CK_YP_CR where isnull(CRTime,'''')='''' and CYID='''+Trim(FCYID)+''' and CRType='''+Trim(RKFlag)+'''');
    ExecSQL;
  end;}
  Close;
end;
procedure TfrmYSCRKP.TBDelClick(Sender: TObject);
var
  FBBMoney,CRID:string;
begin
  if CDS_HZ.IsEmpty then Exit;


  if CDS_HZ.Locate('ssel',true,[])=false then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;

  if Application.MessageBox('确定要删除数据吗？','提示',32+4)<>IDYES then Exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
    with CDS_HZ do
    begin
      DisableControls;
      First;
      while not eof do
      begin
        IF Fieldbyname('ssel').AsBoolean=true then
        begin
          with ADOQueryCmd do
          begin
            close;
            sql.Clear;
            sql.Add('delete YF_Money_CR where YFID='''+Trim(CDS_HZ.fieldbyname('YFID').AsString)+'''');
            execsql;
          end;
        end;
        next;
      end;
      First;
      EnableControls;
    end;
    InitGrid();
    ADOQueryCmd.Connection.CommitTrans;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    application.MessageBox('操作失败！','提示信息',0);
  end;
end;

procedure TfrmYSCRKP.FormShow(Sender: TObject);
begin
  ReadCxGrid('应收款登记5',Tv2,'财务管理');
  Enddate.DateTime:=SGetServerDate(ADOQueryTemp);
  begdate.DateTime:=SGetServerDate(ADOQueryTemp)-15;
  SetStatus();
  InitGrid();
end;

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

procedure TfrmYSCRKP.ToolButton2Click(Sender: TObject);
begin
  Label12.Caption:='0';
  Label13.Caption:='0';
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
    SCreateCDS20(ADOQueryMain,CDS_HZ);
    SInitCDSData20(ADOQueryMain,CDS_HZ);
  end;
end;

procedure TfrmYSCRKP.FactoryNameChange(Sender: TObject);
begin
  ToolButton2.Click;
end;

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

function TfrmYSCRKP.SaveData():Boolean;
var
  maxId,CRID:String;
begin
  try
    ADOQueryCmd.Connection.BeginTrans;
    if GetLSNo(ADOQueryCmd,maxId,'YS','YF_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 YF_Money_KC where FactoryName='''+Trim(CDS_HZ.fieldbyname('FactoryName').AsString)+'''');
      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 YF_Money_CRID set CRID=CRID+1');
        sql.Add('select * from YF_Money_CRID ');
        Open;
      end;
      CRID:=ADOQueryCmd.fieldbyname('CRID').AsString;
      with ADOQueryCmd do
      begin
        Close;
        SQL.Clear;
        sql.Add('select * from YF_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 YF_Money_CR where 1=2');
      Open;
    end;
    with ADOQueryCmd do
    begin
      Append;
      FieldByName('YFID').Value:=Trim(maxId);
      FieldByName('CRID').Value:=StrToInt(CRID);
      //SSetSaveDataCDSNew(ADOQueryCmd,Tv2,CDS_HZ,'YF_Money_CR',3);
      FieldByName('Filler').Value:=Trim(DName);
      FieldByName('CRType').Value:='应收款登记';
      FieldByName('CRFlag').Value:='应收收';
      FieldByName('QtyFlag').Value:=1;
      FieldByName('ConID').Value:=Trim(CDS_HZ.fieldbyname('ConID').AsString);
      FieldByName('ConNo').Value:=Trim(CDS_HZ.fieldbyname('ConNoHZ').AsString);
      FieldByName('Price').Value:=CDS_HZ.fieldbyname('Price').asfloat;
      FieldByName('P_CodeName').Value:=Trim(CDS_HZ.fieldbyname('MP_CodeName').AsString);
      FieldByName('P_SPec').Value:=Trim(CDS_HZ.fieldbyname('MP_SPec').AsString);

      FieldByName('FactoryNo').Value:=Trim(CDS_HZ.fieldbyname('FactoryNo').AsString);
      FieldByName('FactoryName').Value:=Trim(CDS_HZ.fieldbyname('FactoryName').AsString);
      FieldByName('YFName').Value:=Trim(CDS_HZ.fieldbyname('YFName').AsString);
      FieldByName('FeeType').Value:=Trim(CDS_HZ.fieldbyname('FeeType').AsString);
      FieldByName('CRTime').Value:=SGetServerDate(ADOQueryTemp);
      FieldByName('YFDefFlag1').Value:=fFlag;
      FieldByName('status').Value:='0';
      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 TfrmYSCRKP.cxGridDBColumn8PropertiesEditValueChanged(
  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;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('UPdate YCL_SG_HZ ');
    if Trim(mvalue)<>'' then
    begin
      sql.Add(' Set '+FFieldName+'='''+Trim(mvalue)+'''');
    end else
    begin
      sql.Add(' Set '+FFieldName+'=NULL');
    end;
    SQL.Add(',Editer='''+Trim(DName)+'''');
    SQL.Add(',Edittime=getdate() ');
    SQL.Add(' where SubId='''+Trim(CDS_HZ.fieldbyname('SubId').AsString)+'''');
    ExecSQL;
  end;
end;

procedure TfrmYSCRKP.cxGridDBColumn5PropertiesEditValueChanged(
  Sender: TObject);
var
  mvalue,FQty,FPrice,FMoney,FHuiLv,FBBMoney,FKCBB,FFieldName:String;
begin
  mvalue:=TcxTextEdit(Sender).EditingText;
  if Trim(mvalue)='' then
  begin
    mvalue:=NULL;
  end;
  FFieldName:=Trim(Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName);
  if FFieldName='Money' then
  begin
    if Trim(CDS_HZ.fieldbyname('YFType').AsString)<>'' then
    begin
      Application.MessageBox('自动生成数据不能更改!','提示',0);
      Exit;
    end;
  end;
  if FFieldName='Price' then
  begin
    if (trim(CDS_HZ.fieldbyname('YFName').asstring)<>'成品退回费') and
       (Trim(CDS_HZ.fieldbyname('YFType').AsString)<>'') then
    begin
      Application.MessageBox('自动生成数据不能更改!','提示',0);
      Exit;
    end;
  end;
  if FFieldName='MaoQty' then
  begin
    if Trim(mvalue)<>'0' then
    begin
      if CDS_HZ.FieldByName('JZQty').AsFloat>strtofloat(mvalue)-CDS_HZ.FieldByName('ps').AsFloat*0.3 then
      begin
        application.MessageBox('毛重不能小于净重加纸管的重量','提示');
        with CDS_HZ do
        begin
          Edit;
          FieldByName(FFieldName).Value:=NULL;
        end;
        exit;
      end;
    end;
  end;
  with CDS_HZ do
  begin
    Edit;
    FieldByName(FFieldName).Value:=Trim(mvalue);
    if Trim(DParameters2)='人民币' then
    begin
      FieldByName('HuiLv').Value:=1;
    end;
    Post;
  end;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select isnull(BBMoney,0) BBMoney from YF_Money_CR where YFID='''+cds_hz.fieldbyname('YFID').AsString+'''');
    Open;
  end;
  FKCBB:=ADOQueryTemp.fieldbyname('BBMoney').AsString;

  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';

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

  FHuiLv:=Trim(CDS_HZ.fieldbyname('HuiLv').AsString);
  if Trim(FHuiLv)='' then FHuiLv:='0';

  {FBBMoney:=Trim(CDS_HZ.fieldbyname('BBMoney').AsString);
  if Trim(FBBMoney)='' then FBBMoney:='0'; }

  if Trim(FFieldName)<>'Money' then
  begin
    if Trim(FFieldName)<>'HuiLv' then
    begin
      FBBMoney:=FloatToStr(StrToFloat(FQty)*StrToFloat(FPrice)*StrToFloat(FHuiLv));
      FMoney:=FloatToStr(StrToFloat(FQty)*StrToFloat(FPrice));
    end else
    begin
      FBBMoney:=FloatToStr(StrToFloat(FMoney)*StrToFloat(FHuiLv));
    end;

  end else
  begin
    FBBMoney:=FloatToStr(StrToFloat(FMoney)*StrToFloat(FHuiLv));
  end;
  with CDS_HZ do
  begin
    Edit;
    FieldByName('Money').Value:=StrToFloat(FMoney);
    FieldByName('BBMoney').Value:=StrToFloat(FBBMoney);
    Post;
  end;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('UPdate YF_Money_CR ');
    sql.Add(' Set '+FFieldName+'='+Trim(mvalue));
    if Trim(FFieldName)<>'Money' then
    begin
      sql.Add(',Money='+FMoney);
    end;

    sql.Add(',BBMoney='+FBBMoney);
    SQL.Add(',Editer='''+Trim(DName)+'''');
    SQL.Add(',Edittime=getdate() ');
    SQL.Add(' where YFId='''+Trim(CDS_HZ.fieldbyname('YFId').AsString)+'''');
    
    SQL.Add('Update YF_Money_KC Set KCBBMoney=KCBBMoney-'+FKCBB+'+'+FBBMoney);
    sql.Add(' where CRID='''+Trim(CDS_HZ.fieldbyname('CRID').AsString)+'''');
    ExecSQL;
  end;
  tv2.Controller.EditingController.ShowEdit();
end;

procedure TfrmYSCRKP.cxGridDBColumn1PropertiesEditValueChanged(
  Sender: TObject);
var
  mvalue,FFieldName:String;
begin
  if Trim(CDS_HZ.fieldbyname('YFType').AsString)<>'' then
  begin
    Application.MessageBox('自动生成数据不能更改!','提示',0);
    Exit;
  end; 
  mvalue:=TcxTextEdit(Sender).EditingText;
  FFieldName:=Trim(Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName);
  with CDS_HZ do
  begin
    Edit;
    FieldByName(FFieldName).Value:=Trim(mvalue);
    Post;
  end;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('UPdate YF_Money_CR ');
    if Trim(mvalue)<>'' then
    begin
      sql.Add(' Set '+FFieldName+'='''+Trim(mvalue)+'''');
    end else
    begin
      sql.Add(' Set '+FFieldName+'=NULL');
    end;
    SQL.Add(',Editer='''+Trim(DName)+'''');
    SQL.Add(',Edittime=getdate() ');
    SQL.Add(' where YFId='''+Trim(CDS_HZ.fieldbyname('YFId').AsString)+'''');
    ExecSQL;
  end;
end;

procedure TfrmYSCRKP.ToolButton3Click(Sender: TObject);
begin
  frmJYorderConCX:=TfrmJYorderConCX.create(self);
  with frmJYorderConCX do
  begin
    frmJYorderConCX.canshu3:=self.canshu2;
    if showmodal=1 then
    begin
      with Self.CDS_HZ do
      begin
        Append;
        FieldByName('FactoryNo').Value:=Trim(Order_Main.fieldbyname('CustomerNoName').AsString);
        FieldByName('FactoryName').Value:=Trim(Order_Main.fieldbyname('CustomerNoName').AsString);
        fieldbyname('MP_CodeName').Value:=Trim(Order_Main.fieldbyname('PrtCodeName').AsString);
        fieldbyname('MP_Spec').Value:=Trim(Order_Main.fieldbyname('prtspec').AsString);
        fieldbyname('PRTColor').Value:=Trim(Order_Main.fieldbyname('PRTColor').AsString);
        FieldByName('CRTime').Value:=SGetServerDate(ADOQueryTemp);
        fieldbyname('YFName').Value:='成品销售金额';
        fieldbyname('FeeType').Value:='其他费用';
        FieldByName('HuiLv').Value:=1;
        FieldByName('ConNoHZ').Value:=Trim(Order_Main.fieldbyname('ConNo').AsString);
        FieldByName('Conid').Value:=Trim(Order_Main.fieldbyname('subid').AsString);
        FieldByName('Price').Value:=Order_Main.fieldbyname('PRTPrice').AsFloat;
        Post;
      end;
      Self.SaveData();
    end;
    free;
  end;
end;

procedure TfrmYSCRKP.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:=trim(DName)+'收票';
      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);
          fieldbyname('FeeType').Value:='其他费用';
        end;
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('UPdate YF_Money_CR ');
          sql.Add(' Set YFCode='''+Trim(ClientDataSet1.fieldbyname('ZdyNo').AsString)+'''');
          sql.Add(' ,YFName='''+Trim(ClientDataSet1.fieldbyname('ZdyName').AsString)+'''');
          sql.Add(' ,FeeType=''其他费用''');
          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 TfrmYSCRKP.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);
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('UPdate YF_Money_CR ');
          sql.Add(' Set QtyUnit='''+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 TfrmYSCRKP.v2Column3PropertiesButtonClick(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:='MP_CodeName';
      flagname:='品名';
      if ShowModal=1 then
      begin
        Self.CDS_HZ.Edit;
        Self.CDS_HZ.FieldByName('MP_CodeName').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('UPdate YF_Money_CR ');
          sql.Add(' Set P_CodeName='''+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 TfrmYSCRKP.ToolButton1Click(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then Exit;
  SelExportData(Tv2,ADOQueryMain,'应收款列表');
end;

procedure TfrmYSCRKP.v2Column7PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  if Trim(CDS_HZ.FieldByName('YFType').AsString)='自动生成' then
  begin
    Application.MessageBox('自动生成的数据不能修改!','提示',0);
    Exit;
  end;
  try
    frmProductOrderNewList:=TfrmProductOrderNewList.Create(Application);
    with frmProductOrderNewList do
    begin
      //frmProductOrderList.v1Column4.Visible:=True;
      if ShowModal=1 then
      begin
        with Self.CDS_HZ do
        begin
          Edit;
          FieldByName('MainId').Value:=Trim(frmProductOrderNewList.Order_Main.fieldbyname('MainId').AsString);
          FieldByName('subID').Value:=Trim(frmProductOrderNewList.Order_Main.fieldbyname('subID').AsString);
          FieldByName('MOrderNo').Value:=Trim(frmProductOrderNewList.Order_Main.fieldbyname('OrderNo').AsString);
          FieldByName('MP_CodeName').Value:=Trim(frmProductOrderNewList.Order_Main.fieldbyname('MPRTCodeName').AsString);
          FieldByName('MP_Spec').Value:=Trim(frmProductOrderNewList.Order_Main.fieldbyname('MPRTSpec').AsString);
          post;
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('UPdate YF_Money_CR ');
            sql.Add(' Set MainId='''+Trim(SELF.CDS_HZ.fieldbyname('MainId').AsString)+'''');
            sql.Add(' ,SubId='''+Trim(SELF.CDS_HZ.fieldbyname('SubId').AsString)+'''');
            sql.Add(' ,p_CodeName='''+Trim(SELF.CDS_HZ.fieldbyname('MP_CodeName').AsString)+'''');
            sql.Add(' ,P_Spec='''+Trim(SELF.CDS_HZ.fieldbyname('MP_Spec').AsString)+'''');
            SQL.Add(',Editer='''+Trim(DName)+'''');
            SQL.Add(',Edittime=getdate() ');
            SQL.Add(' where YFId='''+Trim(CDS_HZ.fieldbyname('YFId').AsString)+'''');
            ExecSQL;
          end;
        end;
      end;
    end;
  finally
    frmProductOrderNewList.Free;
    self.Tv2.Controller.EditingController.ShowEdit();
  end;
end;

procedure TfrmYSCRKP.v2PSPropertiesEditValueChanged(Sender: TObject);
var
  mvalue,FFieldName:String;
begin
  if Trim(CDS_HZ.FieldByName('YFType').AsString)='自动生成' then
  begin
    Application.MessageBox('自动生成的数据不能修改!','提示',0);
    Exit;
  end;
  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;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('UPdate YF_Money_CR ');
    sql.Add(' Set '+FFieldName+'='+Trim(mvalue));
    SQL.Add(',Editer='''+Trim(DName)+'''');
    SQL.Add(',Edittime=getdate() ');
    SQL.Add(' where YFId='''+Trim(CDS_HZ.fieldbyname('YFId').AsString)+'''');
    ExecSQL;
  end;
end;

procedure TfrmYSCRKP.v2Column2PropertiesEditValueChanged(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;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('UPdate YF_Money_CR ');
    sql.Add(' Set '+FFieldName+'='''+Trim(mvalue)+'''');
    SQL.Add(',Editer='''+Trim(DName)+'''');
    SQL.Add(',Edittime=getdate() ');
    SQL.Add(' where YFId='''+Trim(CDS_HZ.fieldbyname('YFId').AsString)+'''');
    ExecSQL;
  end;
end;

procedure TfrmYSCRKP.v2KPMoneyPropertiesEditValueChanged(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;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select isnull(KPMoney,0) KPMoney from YF_Money_CR where YFID='''+cds_hz.fieldbyname('YFID').AsString+'''');
    Open;
  end;
  FKCBB:=ADOQueryTemp.fieldbyname('KPMoney').AsString;
  FBBMoney:=CDS_HZ.fieldbyname('KPMoney').AsString;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('UPdate YF_Money_CR ');
    sql.Add(' Set '+FFieldName+'='+Trim(mvalue));
    SQL.Add(',Editer='''+Trim(DName)+'''');
    SQL.Add(',Edittime=getdate() ');
    SQL.Add(' where YFId='''+Trim(CDS_HZ.fieldbyname('YFId').AsString)+'''');
    SQL.Add('Update YF_Money_KC Set KCKPMoney=KCKPMoney-'+FKCBB+'+'+FBBMoney);
    sql.Add(' where CRID='''+Trim(CDS_HZ.fieldbyname('CRID').AsString)+'''');
    ExecSQL;
  end;
end;

procedure TfrmYSCRKP.Button1Click(Sender: TObject);
begin

  IF CDS_HZ.IsEmpty then exit;

  if CDS_HZ.Locate('ssel',true,[])=false then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  ADOQueryCmd.Connection.BeginTrans;
  try
    with CDS_HZ do
    begin
      DisableControls;
      First;
      while not eof do
      begin
        If fieldbyname('ssel').AsBoolean then
        begin
          with ADOQueryCmd do
          begin
            close;
            sql.Clear;
            sql.Add('select * from YF_Money_CR ');
            sql.Add('where YFID='+quotedstr(trim(CDS_HZ.fieldbyname('YFID').AsString)));
            open;
            edit;
            Fieldbyname('Price').Value:=strtofloatdef(edit1.Text,0);
            Fieldbyname('Money').Value:=format('%.2f',[Fieldbyname('Qty').AsFloat * strtofloatdef(edit1.Text,0) ]);
            Fieldbyname('BBMoney').Value:=format('%.2f',[Fieldbyname('Qty').AsFloat * strtofloatdef(edit1.Text,0) ]);
            post;
          end;
        end;
        next;
      end;
      First;
      EnableControls;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    InitGrid();
  except
    ADOQueryCmd.Connection.RollbackTrans;
    application.MessageBox('数据保存失败！','提示信息',0);
  end;

end;

procedure TfrmYSCRKP.CheckBox1Click(Sender: TObject);
begin
  Label12.Caption:='0';
  Label13.Caption:='0';
 IF  CDS_HZ.IsEmpty then exit;
  with CDS_HZ do
  begin
    DisableControls;
    first;
    while not eof do
    begin
      edit;
      fieldbyname('ssel').Value:=checkbox1.Checked;
      if checkbox1.Checked=true then
      begin
        Label12.Caption:=floattostr(strtofloat(Label12.Caption)+fieldbyname('Qty').AsCurrency);
        Label13.Caption:=floattostr(strtofloat(Label13.Caption)+fieldbyname('Money').AsCurrency);
      end;
      post;
      next;
    end;
    First;
    EnableControls;
  end;

end;

procedure TfrmYSCRKP.cxTabControl1Change(Sender: TObject);
begin
  SetStatus();

  InitGrid();
end;

procedure TfrmYSCRKP.FormCreate(Sender: TObject);
begin
  cxGrid2.Align:=alclient;
  canshu2:=trim(DParameters2);
end;

procedure TfrmYSCRKP.TchkClick(Sender: TObject);
begin
  IF CDS_HZ.IsEmpty then exit;
  if CDS_HZ.Locate('ssel',true,[])=false then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
    with CDS_HZ do
    begin
      DisableControls;
      First;
      while not eof do
      begin
        IF Fieldbyname('ssel').AsBoolean=true then
        begin
          if cds_HZ.FieldByName('KPType').AsString='' then
          begin
            application.MessageBox('开票类型不能为空','提示');
            exit;
          end;
          with ADOQueryCmd do
          begin
            close;
            sql.Clear;
            sql.Add('update YF_Money_CR SET status=''1'',chkstatus='''' ');
            sql.Add('where YFID ='+quotedstr(trim(CDS_HZ.fieldbyname('YFID').AsString)));
            execsql;
          end;
        end;
        next;
      end;
      EnableControls;
    end;
    InitGrid();
end;

procedure TfrmYSCRKP.TnochkClick(Sender: TObject);
begin
  IF CDS_HZ.IsEmpty then exit;

  if CDS_HZ.Locate('ssel',true,[])=false then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  try
    ADOQueryCmd.Connection.BeginTrans;
    with CDS_HZ do
    begin
      DisableControls;
      First;
      while not eof do
      begin
        IF Fieldbyname('ssel').AsBoolean=true then
        begin
          with ADOQueryCmd do
          begin
            close;
            sql.Clear;
            sql.Add('update YF_Money_CR SET status=''0'' ');
            sql.Add('where YFID ='+quotedstr(trim(CDS_HZ.fieldbyname('YFID').AsString)));
            execsql;
          end;
        end;
        next;
      end;
      First;
      EnableControls;
    end;
    InitGrid();
    ADOQueryCmd.Connection.CommitTrans;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    application.MessageBox('操作失败！','提示信息',0);
  end;
end;

procedure TfrmYSCRKP.v2ComTaitouPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='ComTaiTou';
      flagname:='公司抬头';
      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 YF_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 TfrmYSCRKP.TZDSCClick(Sender: TObject);
begin
  frmSXCKNewList_SK:=TfrmSXCKNewList_SK.create(self) ;
  with frmSXCKNewList_SK do
  begin
    show;
  end;
end;

procedure TfrmYSCRKP.VBZPropertiesButtonClick(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:='BZType';
      flagname:='币种';
      if ShowModal=1 then
      begin
        Self.CDS_HZ.Edit;
        Self.CDS_HZ.FieldByName('BZType').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('UPdate YF_Money_CR ');
          sql.Add(' Set BZType='''+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 TfrmYSCRKP.v2Column4PropertiesButtonClick(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:='MP_Spec';
      flagname:='规格';
      if ShowModal=1 then
      begin
        Self.CDS_HZ.Edit;
        Self.CDS_HZ.FieldByName('MP_Spec').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('UPdate YF_Money_CR ');
          sql.Add(' Set P_Spec='''+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 TfrmYSCRKP.v2Column5PropertiesChange(Sender: TObject);
begin
  toolbar1.SetFocus;
  HJ(CDS_HZ,Label12,CDS_HZ.fieldbyname('Qty').AsCurrency);
  HJ(CDS_HZ,Label13,CDS_HZ.fieldbyname('Money').AsCurrency);
end;

procedure TfrmYSCRKP.v2ConNoHZPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  {if Trim(CDS_HZ.FieldByName('YFType').AsString)='自动生成' then
  begin
    Application.MessageBox('自动生成的数据不能修改!','提示',0);
    Exit;
  end;}
  frmJYorderConCX:=TfrmJYorderConCX.create(self);
  with frmJYorderConCX do
  begin
    if showmodal=1 then
    begin
      Self.CDS_HZ.Edit;
      Self.CDS_HZ.FieldByName('ConNoHZ').Value:=Trim(Order_Main.fieldbyname('ConNo').AsString);
      Self.CDS_HZ.FieldByName('Conid').Value:=Trim(Order_Main.fieldbyname('subid').AsString);
      Self.CDS_HZ.FieldByName('Price').Value:=Order_Main.fieldbyname('PRTPrice').AsFloat;
      with ADOQueryCmd do
      begin
        Close;
        sql.Clear;
        sql.Add('UPdate YF_Money_CR ');
        sql.Add(' Set Conid='''+Trim(Order_Main.fieldbyname('subid').AsString)+'''');
        sql.add(',ConNo='''+Trim(Order_Main.fieldbyname('ConNo').AsString)+'''');
        sql.add(',Price='''+Trim(Order_Main.fieldbyname('PRTPrice').AsString)+'''');
        SQL.Add(',Editer='''+Trim(DName)+'''');
        SQL.Add(',Edittime=getdate() ');
        SQL.Add(' where YFId='''+Trim(CDS_HZ.fieldbyname('YFId').AsString)+'''');
        ExecSQL;
      end;
    end;
    free;
  end;
end;

procedure TfrmYSCRKP.Tv2StylesGetContentStyle(Sender: TcxCustomGridTableView;
  ARecord: TcxCustomGridRecord; AItem: TcxCustomGridTableItem;
  out AStyle: TcxStyle);
var
  id,id10:Integer;
begin
  {Id:=Tv2.GetColumnByFieldName('ChkStatus').Index;
  if ARecord.Values[id]='不通过' then
  begin
    AStyle:=DataLink_YSYF.Red;
  end; }
end;

procedure TfrmYSCRKP.N1Click(Sender: TObject);
begin
  SelOKNo(CDS_HZ,True);
end;

procedure TfrmYSCRKP.N2Click(Sender: TObject);
begin
  SelOKNo(CDS_HZ,false);
end;

procedure TfrmYSCRKP.ToolButton4Click(Sender: TObject);
begin
  IF CDS_HZ.IsEmpty then exit;
  if CDS_HZ.Locate('ssel',true,[])=false then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  try
    ADOQueryCmd.Connection.BeginTrans;
    with CDS_HZ do
    begin
      DisableControls;
      First;
      while not eof do
      begin
        IF Fieldbyname('ssel').AsBoolean=true then
        begin
          with ADOQueryCmd do
          begin
            close;
            sql.Clear;
            sql.Add('update YF_Money_CR SET KPStatus=''开票完成'' ');
            sql.Add('where YFID ='+quotedstr(trim(CDS_HZ.fieldbyname('YFID').AsString)));
            execsql;
          end;
        end;
        next;
      end;
      First;
      EnableControls;
    end;
    InitGrid();
    ADOQueryCmd.Connection.CommitTrans;
    application.MessageBox('操作成功！','提示信息',0);
  except
    ADOQueryCmd.Connection.RollbackTrans;
    application.MessageBox('操作失败！','提示信息',0);
  end;
end;

procedure TfrmYSCRKP.ToolButton5Click(Sender: TObject);
begin
  IF CDS_HZ.IsEmpty then exit;

  if CDS_HZ.Locate('ssel',true,[])=false then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  try
    ADOQueryCmd.Connection.BeginTrans;
    with CDS_HZ do
    begin
      DisableControls;
      First;
      while not eof do
      begin
        IF Fieldbyname('ssel').AsBoolean=true then
        begin
          with ADOQueryCmd do
          begin
            close;
            sql.Clear;
            sql.Add('update YF_Money_CR SET KPStatus='''' ');
            sql.Add('where YFID ='+quotedstr(trim(CDS_HZ.fieldbyname('YFID').AsString)));
            execsql;
          end;
        end;
        next;
      end;
      First;
      EnableControls;
    end;

    InitGrid();
    ADOQueryCmd.Connection.CommitTrans;
    application.MessageBox('操作成功！','提示信息',0);
  except
    ADOQueryCmd.Connection.RollbackTrans;
    application.MessageBox('操作失败！','提示信息',0);
  end;
end;

procedure TfrmYSCRKP.v2KPTypePropertiesEditValueChanged(Sender: TObject);
var
  mvalue,FFieldName:String;
begin
  mvalue:=TcxTextEdit(Sender).EditingText;
  with CDS_HZ do
  begin
    Edit;
    FieldByName('KPType').Value:=Trim(mvalue);
  end;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('UPdate YF_Money_CR ');
    sql.Add(' Set KPType='''+Trim(mvalue)+'''');
    SQL.Add(',Editer='''+Trim(DName)+'''');
    SQL.Add(',Edittime=getdate() ');
    SQL.Add(' where YFId='''+Trim(CDS_HZ.fieldbyname('YFId').AsString)+'''');
    ExecSQL;
  end;
end;

end.
