unit U_PKChkCFList;

interface

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


type
  TfrmPKChkCFList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    TBExport: TToolButton;
    Order_Main: TClientDataSet;
    RM1: TRMGridReport;
    RMDBMain: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    CDS_PRT: TClientDataSet;
    ToolButton3: TToolButton;
    cxGridPopupMenu2: TcxGridPopupMenu;
    Panel1: TPanel;
    Label2: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    FactoryName: TEdit;
    Label6: TLabel;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column6: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1ShipDate: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    Label1: TLabel;
    v1Column21: TcxGridDBColumn;
    v1Column22: TcxGridDBColumn;
    ToolButton1: TToolButton;
    v1Column1: TcxGridDBColumn;
    cxTabControl1: TcxTabControl;
    ToolButton2: TToolButton;
    v1Column16: TcxGridDBColumn;
    v1Column17: TcxGridDBColumn;
    v1Column18: TcxGridDBColumn;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    ToolButton5: TToolButton;
    v1Column19: TcxGridDBColumn;
    v1Column20: TcxGridDBColumn;
    v1Column23: TcxGridDBColumn;
    ToolButton6: TToolButton;
    v1Column24: TcxGridDBColumn;
    v1Column26: TcxGridDBColumn;
    CDS_FX: TClientDataSet;
    v1Column2: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    Label3: TLabel;
    Label4: TLabel;
    PayMent: TEdit;
    ComTaiTou: TEdit;
    Label5: TLabel;
    BZType: TComboBox;
    Label7: TLabel;
    JBPerson: TEdit;
    Label8: TLabel;
    PKName: TEdit;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure cxPageControl1Change(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure FactoryNameChange(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure v1Column17PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure ToolButton6Click(Sender: TObject);

  private
    FInt,PFInt:Integer;
    canshu1,canshu2:string;
    FNowDate:TDateTime;
    procedure InitGrid();
    procedure InitForm();
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmPKChkCFList: TfrmPKChkCFList;

implementation
uses
  U_DataLink,U_RTFun,U_ModuleNote, U_ZDYHelp;

{$R *.dfm}

procedure TfrmPKChkCFList.FormDestroy(Sender: TObject);
begin
  frmPKChkCFList:=nil;
end;

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

procedure TfrmPKChkCFList.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('资金审核列表',Tv1,'财务管理');
end;

procedure TfrmPKChkCFList.InitGrid();
var
  fsj:String;
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add(' select A.*');
      SQL.Add(' from YF_Money_PaiKuan A where 1=1 ');
      if cxTabControl1.TabIndex<>0 then
      begin
        sql.Add('  and A.PKDate>='''+Trim(FormatDateTime('yyyy-MM-dd',BegDate.Date))+'''');
        sql.Add('  and A.PKDate<'''+Trim(FormatDateTime('yyyy-MM-dd',Enddate.Date+1))+'''');
      end;
      sql.Add(' and 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 else
      if cxTabControl1.TabIndex=2 then
      begin
        sql.Add(' and isnull(ChkStatus,'''')=''审核不通过'' ');
      end;
      Open;
    end;
    SCreateCDS20(ADOQueryMain,Order_Main);
    SInitCDSData20(ADOQueryMain,Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;

end;

procedure TfrmPKChkCFList.InitForm();
var
  fsj:string;
begin
  FNowDate:=SGetServerDate(ADOQueryTemp);
  EndDate.Date:=FNowDate+7;
  BegDate.Date:=FNowDate-7;
  ReadCxGrid('资金审核列表',Tv1,'财务管理');
end;



procedure TfrmPKChkCFList.TBExportClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  TcxGridToExcel('资金申请审核列表',cxGrid1);
end;

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

procedure TfrmPKChkCFList.FormShow(Sender: TObject);
begin
  InitForm();
end;

procedure TfrmPKChkCFList.cxPageControl1Change(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmPKChkCFList.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 TfrmPKChkCFList.FormCreate(Sender: TObject);
begin
  canshu1:=Trim(DParameters1);
  canshu2:=Trim(DParameters2);
end;



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

procedure TfrmPKChkCFList.FactoryNameChange(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 TfrmPKChkCFList.ToolButton1Click(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 TfrmPKChkCFList.N1Click(Sender: TObject);
begin
  SelOKNo(Order_Main,True);
end;

procedure TfrmPKChkCFList.N2Click(Sender: TObject);
begin
  SelOKNo(Order_Main,False);
end;

procedure TfrmPKChkCFList.ToolButton2Click(Sender: TObject);
begin
  if cxTabControl1.TabIndex<>0 then Exit;
  if Order_Main.IsEmpty then Exit;
  if Order_Main.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  if Order_Main.Locate('SSel;ComTaiTou',VarArrayOf([True,Null]),[loPartialKey])=True then
  begin
    Application.MessageBox('付款单位不能为空!','提示',0);
    Exit;
  end;
  if Application.MessageBox('确定要执行审核操作吗？','提示',32+4)<>IDYES then Exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
    Order_Main.DisableControls;
    with Order_Main do
    begin
      First;
      while Order_Main.Locate('SSel',True,[]) do
      begin
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('Update YF_Money_PaiKuan Set ChkTime=getdate(),Chker='''+Trim(DName)+'''');
          sql.Add(',ChkStatus=''审核通过'' ');
          sql.Add(',ChkNote='''+Trim(Order_Main.fieldbyname('ChkNote').AsString)+'''');
          {sql.Add(',ComTaiTou='''+Trim(Order_Main.fieldbyname('ComTaiTou').AsString)+'''');
          sql.Add(',PayMent='''+Trim(Order_Main.fieldbyname('PayMent').AsString)+'''');
          sql.Add(',PKYongTu='''+Trim(Order_Main.fieldbyname('PKYongTu').AsString)+'''');
          sql.Add(',FactoryNameOther='''+Trim(Order_Main.fieldbyname('FactoryNameOther').AsString)+'''');
          if Trim(Order_Main.fieldbyname('PKMoney').AsString)<>'' then
          begin
            sql.Add(',PKMoney='+Trim(Order_Main.fieldbyname('PKMoney').AsString));
          end else
          begin
            sql.Add(',PKMoney=0');
          end; }
          sql.Add(' where PKID='''+Trim(Order_Main.fieldbyname('PKID').AsString)+'''');
          ExecSQL;
        end;
        {with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add(' Update ZH_KH_Info Set LockFlag=1');
          sql.Add(' where KHNameJC='''+Trim(Order_Main.fieldbyname('FactoryName').AsString)+'''');
          sql.Add(' and KHType=''GYS'' ');
          ExecSQL;
        end; }
        Order_Main.Delete;
      end;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Order_Main.EnableControls;
  except
    Order_Main.EnableControls;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常!','提示',0);
  end;
end;

procedure TfrmPKChkCFList.ToolButton5Click(Sender: TObject);
begin
  if cxTabControl1.TabIndex=0 then Exit;
  if cxTabControl1.TabIndex=3 then Exit;
  if Order_Main.IsEmpty then Exit;
  if Order_Main.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  if Application.MessageBox('确定要执行撤销操作吗？','提示',32+4)<>IDYES then Exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
    Order_Main.DisableControls;
    with Order_Main do
    begin
      First;
      while Order_Main.Locate('SSel',True,[]) do
      begin
        with ADOQueryTemp do
        begin
          Close;
          sql.Clear;
          sql.Add('select * from YF_Money_PaiKuan where PKID='''+Trim(Order_Main.fieldbyname('PKID').AsString)+'''');
          Open;
        end;
        if Trim(ADOQueryTemp.fieldbyname('FKID').AsString)<>'' then
        begin
          ADOQueryCmd.Connection.RollbackTrans;
          Order_Main.EnableControls;
          Application.MessageBox('已付款不能撤销!','提示',0);
          Exit;
        end;
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('Update YF_Money_PaiKuan Set ChkTime=NUll,Chker=Null,ChkNote=Null');
          sql.Add(',ChkStatus=''已送审'' ');
          sql.Add(' where PKID='''+Trim(Order_Main.fieldbyname('PKID').AsString)+'''');
          ExecSQL;
        end;
        Order_Main.Delete;
      end;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Order_Main.EnableControls;
  except
    Order_Main.EnableControls;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常!','提示',0);
  end;
end;

procedure TfrmPKChkCFList.v1Column17PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='GSTT';
      flagname:='公司抬头';
      V1ZdyStr1.Visible:=True;
      V1ZdyStr2.Visible:=True;
      V1ZdyStr3.Visible:=True;
      V1ZdyStr4.Visible:=True;
      V1ZdyStr1.Caption:='简称';
      V1ZdyStr2.Caption:='电话';
      V1ZdyStr3.Caption:='传真';
      V1ZdyStr4.Caption:='地址';
      frmZDYHelp.Align:=alClient;
      if ShowModal=1 then
      begin
        with Self.Order_Main do
        begin
          Edit;
          FieldByName('ComTaiTou').Value:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmPKChkCFList.ToolButton6Click(Sender: TObject);
begin
  if cxTabControl1.TabIndex<>0 then Exit;
  if Order_Main.IsEmpty then Exit;
  if Order_Main.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  if Order_Main.Locate('SSel;ChkNote',VarArrayOf([True,Null]),[loPartialKey])=True then
  begin
    Application.MessageBox('审核备注不能为空!','提示',0);
    Exit;
  end;
  if Application.MessageBox('确定要审核不通过吗？','提示',32+4)<>IDYES then Exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
    Order_Main.DisableControls;
    with Order_Main do
    begin
      First;
      while Order_Main.Locate('SSel',True,[]) do
      begin
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('Update YF_Money_PaiKuan Set ChkTime=getdate(),Chker='''+Trim(DName)+'''');
          sql.Add(',ChkStatus=''审核不通过'' ');
          sql.Add(',ChkNote='''+Trim(Order_Main.fieldbyname('ChkNote').AsString)+'''');
          {sql.Add(',PayMent='''+Trim(Order_Main.fieldbyname('PayMent').AsString)+'''');
          sql.Add(',PKYongTu='''+Trim(Order_Main.fieldbyname('PKYongTu').AsString)+'''');
          sql.Add(',ComTaiTou='''+Trim(Order_Main.fieldbyname('ComTaiTou').AsString)+'''');
          sql.Add(',FactoryNameOther='''+Trim(Order_Main.fieldbyname('FactoryNameOther').AsString)+'''');
          if Trim(Order_Main.fieldbyname('PKMoney').AsString)<>'' then
          begin
            sql.Add(',PKMoney='+Trim(Order_Main.fieldbyname('PKMoney').AsString));
          end else
          begin
            sql.Add(',PKMoney=0');
          end; }
          sql.Add(' where PKID='''+Trim(Order_Main.fieldbyname('PKID').AsString)+'''');
          ExecSQL;
        end;
        Order_Main.Delete;
      end;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Order_Main.EnableControls;
  except
    Order_Main.EnableControls;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常!','提示',0);
  end;
end;

end.
