unit U_YGYPZZChkList_jiaxin;

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, cxCheckBox, cxCalendar, cxSplitter,
  RM_Dataset, RM_System, RM_Common, RM_Class, RM_GridReport, RM_e_Xls,
  Menus, cxButtonEdit, cxDropDownEdit, cxPC, ActnMan, ActnColorMaps;

type
  TfrmYGYPZZChkList_jiaxin = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBClose: TToolButton;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    TBExport: TToolButton;
    Order_Main: TClientDataSet;
    TBView: TToolButton;
    Panel1: TPanel;
    TBLiZhi: TToolButton;
    PopupMenu1: TPopupMenu;
    N2: TMenuItem;
    N1: TMenuItem;
    TCXTJ: TToolButton;
    BegDate: TDateTimePicker;
    Label3: TLabel;
    EndDate: TDateTimePicker;
    cxTabControl1: TcxTabControl;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column7: TcxGridDBColumn;
    v1GangWei: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    v1JXStatus: TcxGridDBColumn;
    v1Dept: TcxGridDBColumn;
    cxGrid2: TcxGrid;
    TV2: TcxGridDBTableView;
    V2Chker: TcxGridDBColumn;
    V2Chktime: TcxGridDBColumn;
    V2Chkstatus: TcxGridDBColumn;
    V2chkNote: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    DataSource2: TDataSource;
    order_Sub: TClientDataSet;
    Label2: TLabel;
    v1JHJXDate: TcxGridDBColumn;
    v1TBDate: TcxGridDBColumn;
    v1SXJXdate: TcxGridDBColumn;
    v1JXNote: TcxGridDBColumn;
    TTiJiao: TToolButton;
    TCXSQ: TToolButton;
    TDel: TToolButton;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    v1JXMoney: TcxGridDBColumn;
    TDY: TToolButton;
    RM1: TRMGridReport;
    RMDBMain: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    Order_Print: TClientDataSet;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
    procedure TBViewClick(Sender: TObject);
    procedure CustomerNoNameChange(Sender: TObject);
    procedure TBLiZhiClick(Sender: TObject);
    procedure TCXTJClick(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure Tv1CellClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure TCXSQClick(Sender: TObject);
    procedure TTiJiaoClick(Sender: TObject);
    procedure TDelClick(Sender: TObject);
    procedure TDYClick(Sender: TObject);
  private
    canshu1:string;
    DQdate:TDateTime;
    procedure InitGrid();
    procedure InitForm();
    function  DelData():Boolean;
    procedure setstatus();
    { Private declarations }
  public
    FFInt,FCloth:Integer;

    { Public declarations }
  end;

var
  frmYGYPZZChkList_jiaxin: TfrmYGYPZZChkList_jiaxin;

implementation
uses
  U_DataLink,U_RTFun,U_ZDYHelp, U_YGYPInPut,U_YGYPInPut_JiaXin,
  U_ZDYHelpSel;

{$R *.dfm}

procedure TfrmYGYPZZChkList_jiaxin.setstatus();
begin
  TBLiZhi.Visible:=False;
  TCXSQ.Visible:=False;
  TTiJiao.Visible:=False;
  TCXTJ.Visible:=False;
  Tdel.Visible:=False;
  case cxTabControl1.TabIndex of
    0:begin
        TBLiZhi.Visible:=True;
        TCXSQ.Visible:=True;
        TTiJiao.Visible:=True;
        Tdel.Visible:=true;
      end;
    1:begin
        TCXTJ.Visible:=true;
      end;
    2:begin

      end;
  end;
end;

procedure TfrmYGYPZZChkList_jiaxin.FormDestroy(Sender: TObject);
begin
  frmYGYPZZChkList_JiaXin:=nil;
end;

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

procedure TfrmYGYPZZChkList_jiaxin.FormCreate(Sender: TObject);
begin
  canshu1:=Trim(DParameters1);
end;

procedure TfrmYGYPZZChkList_jiaxin.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('员工离职列表',Tv1,'OA管理');
end;

procedure TfrmYGYPZZChkList_jiaxin.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add('select A.*,B.* ');
      sql.Add(' from OA_YG_DangAn_JX A  ');
      sql.add(' inner join OA_YG_DangAn B on B.YGID=A.YGID ');
      sql.Add(' where A.TBDate>='''+Trim(FormatDateTime('yyyy-MM-dd',BegDate.Date))+'''');
      sql.Add(' and A.TBDate<='''+Trim(FormatDateTime('yyyy-MM-dd',EndDate.Date+1))+'''');
      if cxTabControl1.TabIndex=0 then
      begin
        sql.Add(' and (A.JXStatus=''待提交'' or A.JXStatus=''不通过'') ');
      end else
      if cxTabControl1.TabIndex=1 then
      begin
        sql.add(' and A.JXStatus<>''待提交'' and A.JXStatus<>''不通过''');
      end;
      if trim(DParameters1)<>'高权限' then
      begin
        sql.add(' and isnull(B.YGEName,B.YGName)='''+trim(DName)+''' ');
      end;
      Open;
    end;
    SCreateCDS20(ADOQueryMain,Order_Main);
    SInitCDSData20(ADOQueryMain,Order_Main);
    with ADOQueryCmd do
    begin
      close;
      sql.clear;
      sql.add('select A.* from OA_Chk A ');
      sql.add('where A.Mainid='''+trim(Order_Main.fieldbyname('JXID').AsString)+''' ');
      sql.Add(' and isnull(OAType,'''')=''加薪申请'' ');
      open;
    end;
    SCreateCDS20(ADOQueryCmd,Order_Sub);
    SInitCDSData20(ADOQueryCmd,Order_Sub);
  finally
    ADOQueryMain.EnableControls;
  end;
end;


procedure TfrmYGYPZZChkList_jiaxin.InitForm();
begin
  EndDate.Date:=SGetServerDate(ADOQueryTemp);
  BegDate.Date:=EndDate.Date-7;
  ReadCxGrid('员工加薪列表',Tv1,'OA管理');
  setstatus();
  InitGrid();
end;

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

function TfrmYGYPZZChkList_jiaxin.DelData():Boolean;
begin
  try
    Result:=false;
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('Delete OA_YG_DangAn  where YGId='''+Trim(Order_Main.fieldbyname('YGId').AsString)+'''');
      ExecSQL;
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('Delete OA_YG_DangAn_Other  where YGId='''+Trim(Order_Main.fieldbyname('YGId').AsString)+'''');
      ExecSQL;
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('Delete TP_File  where WBId='''+Trim(Order_Main.fieldbyname('YGId').AsString)+'''');
      sql.Add(' and TFType=''YG'' ');
      ExecSQL;
    end;

    ADOQueryCmd.Connection.CommitTrans;
    Result:=True;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Result:=False;
    Application.MessageBox('数据删除异常！','提示',0);
  end;
end;

procedure TfrmYGYPZZChkList_jiaxin.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then Exit;
  TcxGridToExcel('员工加薪列表',cxGrid1);
end;

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

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

procedure TfrmYGYPZZChkList_jiaxin.CheckBox1Click(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmYGYPZZChkList_jiaxin.CheckBox2Click(Sender: TObject);
begin
  TBRafresh.Click;
end;

procedure TfrmYGYPZZChkList_jiaxin.TBViewClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  frmYGYPInPut_JiaXin:=TfrmYGYPInPut_JiaXin.create(self);
  with frmYGYPInPut_JiaXin do
  begin
    TBSave.Visible:=False;
    FJXID:=trim(Order_Main.fieldbyname('JXID').AsString);
    if showModal=1 then
    begin

    end;
    free;
  end;
  initGrid();
end;

procedure TfrmYGYPZZChkList_jiaxin.CustomerNoNameChange(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 TfrmYGYPZZChkList_jiaxin.TBLiZhiClick(Sender: TObject);
begin
  frmYGYPInPut_JiaXin:=TfrmYGYPInPut_JiaXin.create(self);
  with frmYGYPInPut_JiaXin do
  begin
    FJXID:='';
    if showModal=1 then
    begin

    end;
    free;
  end;
  initGrid();
end;

procedure TfrmYGYPZZChkList_jiaxin.TCXTJClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  if Application.MessageBox('确定要执行撤销操作吗？','提示',32+4)<>IDYES then Exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('Update OA_YG_DangAn_JX Set JXStatus=''待提交'' ');
      sql.Add(' where JXID='''+trim(Order_Main.fieldbyname('JXID').AsString)+'''');
      ExecSQL;
    end;
    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('delete from OA_Chk ');
      sql.Add(' where Mainid='''+trim(Order_Main.fieldbyname('JXID').AsString)+'''');
      sql.Add(' and isnull(OAType,'''')=''加薪申请'' ');
      ExecSQL;
    end;
    initGrid();
    ADOQueryCmd.Connection.CommitTrans;
    Exit;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常!','提示',0);
  end;
end;

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

procedure TfrmYGYPZZChkList_jiaxin.Tv1CellDblClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  TBView.Click;
end;

procedure TfrmYGYPZZChkList_jiaxin.Tv1CellClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  with ADOQueryCmd do
  begin
    close;
    sql.clear;
    sql.add('select A.* from OA_Chk A ');
    sql.add('where A.Mainid='''+trim(Order_Main.fieldbyname('JXID').AsString)+''' ');
    sql.Add(' and isnull(OAType,'''')=''加薪申请'' ');
    open;
  end;
  SCreateCDS20(ADOQueryCmd,Order_Sub);
  SInitCDSData20(ADOQueryCmd,Order_Sub);
end;

procedure TfrmYGYPZZChkList_jiaxin.TCXSQClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then exit;
  frmYGYPInPut_JiaXin:=TfrmYGYPInPut_JiaXin.create(self);
  with frmYGYPInPut_JiaXin do
  begin
    FJXID:=trim(Order_Main.fieldbyname('JXID').AsString);
    if showModal=1 then
    begin

    end;
    free;
  end;
  initGrid();
end;

procedure TfrmYGYPZZChkList_jiaxin.TTiJiaoClick(Sender: TObject);
var maxno: string;
begin
  if Order_Main.IsEmpty then exit;
  frmZDYHelpSel:=TfrmZDYHelpSel.Create(Application);
  with frmZDYHelpSel do
  begin
    flag:='SPR';
    flagname:='审批人';
    MainType:=Trim(DName);
    if ShowModal=1 then
    begin
      with ClientDataSet1 do
      begin
        first;
        while not Eof do
        begin
          if fieldbyname('Ssel').AsBoolean=True then
          begin
            with ADOQueryTemp do
            begin
              Close;
              sql.Clear;
              sql.Add('select * from SY_User where UserName='''+Trim(ClientDataSet1.fieldbyname('ZdyName').AsString)+'''');
              Open;
            end;
            if ADOQueryTemp.IsEmpty then
            begin
              Application.MessageBox('审批人定义错误!','提示',0);
              Exit;
            end;
            with ADOQueryTemp do
            begin
              Close;
              sql.Clear;
              sql.Add('select * from OA_Chk where MainId='''+Trim(Order_Main.fieldbyname('JXID').AsString)+'''');
              sql.Add(' and isnull(OAType,'''')=''加薪申请'' ');
              sql.Add(' and isnull(Chker,'''')='''+Trim(ClientDataSet1.fieldbyname('ZdyName').AsString)+'''');
              Open;
            end;
            if ADOQueryTemp.IsEmpty then
            begin
              if GetLSNo(ADOQueryCmd,maxno,'JX','OA_Chk',4,1)=False then
              begin
                Application.MessageBox('取最大号失败!','提示',0);
                Exit;
              end;
              with ADOQueryCmd do
              begin
                Close;
                sql.Clear;
                sql.Add('select * from OA_Chk where 1=2 ');
                Open;
                append;
                FieldByName('CKID').Value:=Trim(maxno);
                FieldByName('Mainid').Value:=Trim(Order_Main.fieldbyname('JXID').AsString);
                FieldByName('OAType').value:='加薪申请';
                FieldByName('Chker').Value:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
                Post;
              end;
            end;
          end;
          Next;
        end;
      end;
      with ADOQueryCmd do
      begin
        Close;
        sql.Clear;
        sql.Add('update OA_YG_DangAn_JX set JXStatus=''已提交'' ');
        sql.Add('where JXID='''+trim(Order_Main.fieldbyname('JXID').asstring)+''' ');
        ExecSQL;
      end;
    end;
    Free;
  end;
  InitGrid();
end;

procedure TfrmYGYPZZChkList_jiaxin.TDelClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then exit;
  if application.MessageBox('确定要删除吗','提示',1)=2 then exit;
  with ADOQueryMain do
  begin
    close;
    sql.Clear;
    sql.Add('delete from OA_YG_DangAn_JX where JXID='''+trim(Order_Main.fieldbyname('JXid').AsString)+'''');
    execsql;
  end;
  initGrid();
end;


procedure TfrmYGYPZZChkList_jiaxin.TDYClick(Sender: TObject);
var
  fPrintFile:String;
begin
  if Order_Main.IsEmpty then Exit;
  fPrintFile:= ExtractFilePath(Application.ExeName) + 'Report\加薪申请单.rmf' ;
  with ADOQueryCmd do
  begin
    Filtered:=False;
    Close;
    sql.Clear;
    sql.Add('select A.*,B.* ');
    sql.Add(' from OA_YG_DangAn_JX A  ');
    sql.add(' inner join OA_YG_DangAn B on B.YGID=A.YGID ');
    sql.Add(' where JXID='''+trim(Order_Main.fieldbyname('JXID').AsString)+'''');
    Open;
  end;
  SCreateCDS20(ADOQueryCmd,Order_Print);
  SInitCDSData20(ADOQueryCmd,Order_Print);
  if FileExists(fPrintFile) then
  begin
    RM1.LoadFromFile(fPrintFile);
    RM1.ShowReport;
    //RM1.PrintReport;
  end else
  begin
    Application.MessageBox(PChar('没有找'+ExtractFilePath(Application.ExeName)+'Report\加薪申请单.rmf'),'提示',0);
    Exit;
  end;
end;

end.
