unit U_YieldWageList;

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, cxDBLookupComboBox, cxPC, cxContainer,
  cxDropDownEdit;

type
  TfrmYieldWageList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    Panel1: TPanel;
    ToolButton2: TToolButton;
    ADOQueryMain: TADOQuery;
    ToolButton1: TToolButton;
    RM1: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cxGridLevel1: TcxGridLevel;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_HZ: TDataSource;
    CDS_HZ: TClientDataSet;
    v2Column5: TcxGridDBColumn;
    v2Column8: TcxGridDBColumn;
    v2Column9: TcxGridDBColumn;
    v2Column10: TcxGridDBColumn;
    Label2: TLabel;
    DCG: TEdit;
    v2Column14: TcxGridDBColumn;
    v2Column15: TcxGridDBColumn;
    v2Column16: TcxGridDBColumn;
    v2Column17: TcxGridDBColumn;
    Label4: TLabel;
    Label5: TLabel;
    BegDate: TcxDateEdit;
    EndDate: TcxDateEdit;
    v2Column1: TcxGridDBColumn;
    v2Column2: TcxGridDBColumn;
    v2Column3: TcxGridDBColumn;
    v2Column4: TcxGridDBColumn;
    v2Column7: TcxGridDBColumn;
    v2Column11: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    v2Column12: TcxGridDBColumn;
    v2Column13: TcxGridDBColumn;
    v2Column18: TcxGridDBColumn;
    v2Column19: TcxGridDBColumn;
    v2Column20: TcxGridDBColumn;
    v2Column21: TcxGridDBColumn;
    v2Column22: TcxGridDBColumn;
    v2Column23: TcxGridDBColumn;
    v2Column24: TcxGridDBColumn;
    v2Column25: TcxGridDBColumn;
    v2Column26: TcxGridDBColumn;
    v2Column27: TcxGridDBColumn;
    v2Column28: TcxGridDBColumn;
    v2Column29: TcxGridDBColumn;
    v2Column30: TcxGridDBColumn;
    v2Column31: TcxGridDBColumn;
    v2Column32: TcxGridDBColumn;
    v2Column33: TcxGridDBColumn;
    v2Column34: TcxGridDBColumn;
    v2Column35: TcxGridDBColumn;
    v2Column36: TcxGridDBColumn;
    v2Column37: TcxGridDBColumn;
    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 C_CodeNameChange(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private

    { Private declarations }
    canshu1:string;
    procedure InitGrid();
    function IsWages():Boolean;

  public
    fkhType:string;
    Fmanage:string;
  end;

var
  frmYieldWageList: TfrmYieldWageList;

implementation
uses
  U_DataLink,U_Fun,U_RTFun,U_ZDYHelp,U_WageListInput,U_InspectionInfo,U_JTList;

{$R *.dfm}

function TfrmYieldWageList.IsWages():Boolean;
begin
  if CDS_HZ.FieldByName('GZID').AsInteger>0 then
  begin
     Result:=True;
  end
  else                   
  begin
    try
      ADOQueryCmd.Connection.BeginTrans;
      with  ADOQueryCmd do
      begin
        close;
        sql.Clear;
        sql.Add('insert into DCGMoney(FDetailId,CarNo,DName)');
        sql.Add('values('
        +quotedstr(Trim(CDS_HZ.fieldbyname('DetailId').AsString))
        +', '+quotedstr(Trim(CDS_HZ.fieldbyname('CarNo').AsString))
        +', '+quotedstr(Trim(CDS_HZ.fieldbyname('Filler').AsString))
        +')');
//        SHOWMESSAGE(SQL.Text);
        execsql;
      end;
      with  ADOQueryCmd do
      begin
        close;
        sql.Clear;
        sql.Add('select * from DCGMoney');
        sql.Add(' where FDetailId='+quotedstr(Trim(CDS_HZ.fieldbyname('DetailId').AsString)));
        sql.Add(' and CarNo='+quotedstr(Trim(CDS_HZ.fieldbyname('CarNo').AsString)));
        sql.Add(' and DName='+quotedstr(Trim(CDS_HZ.fieldbyname('Filler').AsString)));
        open;
      end;
      if   ADOQueryCmd.RecordCount>1 then
      begin
        ADOQueryCmd.Connection.RollbackTrans;
        Application.MessageBox('保存失败！','提示',0);
      end
      else
      begin
         ADOQueryCmd.Connection.CommitTrans;
         Result:=false;
      end;
      CDS_HZ.Edit;
      CDS_HZ.FieldByName('GZID').Value:=ADOQueryCmd.fieldbyname('GZID').AsInteger;
      Result:=True;
    except
      ADOQueryCmd.Connection.RollbackTrans;
      Result:=false;
      Application.MessageBox('保存失败！','提示',0);
    end;
  end;

end;

procedure TfrmYieldWageList.InitGrid();
begin
  try

    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      SQL.Clear;
      sql.Add(' exec P_View_YieldWage'+quotedstr(Trim(BegDate.Text)));
      sql.Add(','+quotedstr(Trim(EndDate.Text)));
      Open;
    end;

    SCreateCDS20(ADOQueryMain,CDS_HZ);
    SInitCDSData20(ADOQueryMain,CDS_HZ);
    CDS_HZ.Last;
  finally
    ADOQueryMain.EnableControls;
  end;
end;


procedure TfrmYieldWageList.FormDestroy(Sender: TObject);
begin
  frmYieldWageList:=nil;
end;

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

procedure TfrmYieldWageList.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid(trim(self.Caption),Tv2,'工资管理');
  Close;
end;
procedure TfrmYieldWageList.FormShow(Sender: TObject);
begin
  ReadCxGrid(trim(self.Caption),Tv2,'工资管理');
  InitGrid();
end;

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

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

procedure TfrmYieldWageList.C_CodeNameChange(Sender: TObject);
begin
  ToolButton2.Click;
end;


procedure TfrmYieldWageList.ToolButton1Click(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then Exit;
  TcxGridToExcel(self.Caption,cxgrid2); 
end;

procedure TfrmYieldWageList.FormCreate(Sender: TObject);
begin
  EndDate.Text:=FormatDateTime('yyyy-MM-dd',SGetServerDate10(ADOQueryTemp))+' 08:00:00';
  BegDate.Text:=FormatDateTime('yyyy-MM-dd',SGetServerDate10(ADOQueryTemp)-30)+' 08:00:00';
  canshu1:=Trim(DParameters1);
end;

end.


