unit U_YGYPInPut_LiZhi;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
  cxDataStorage, cxEdit, DB, cxDBData, cxGridLevel, cxGridCustomTableView,
  cxGridTableView, cxGridDBTableView, cxClasses, cxControls,
  cxGridCustomView, cxGrid, cxMemo, cxRichEdit, ComCtrls, cxContainer,
  cxTextEdit, cxMaskEdit, cxButtonEdit, StdCtrls, ToolWin, DBClient, ADODB,
  ExtCtrls, BtnEdit, cxCalendar,StrUtils, cxDropDownEdit,jpeg,
  IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdFTP, cxPC,
  cxGridCustomPopupMenu, cxGridPopupMenu, Menus, ExtDlgs;

type
  TfrmYGYPInPut_LiZhi = class(TForm)
    ToolBar1: TToolBar;
    TBClose: TToolButton;
    ADOTemp: TADOQuery;
    ADOCmd: TADOQuery;
    TBSave: TToolButton;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    DataSource1: TDataSource;
    Order_Sub: TClientDataSet;
    Panel3: TPanel;
    Label4: TLabel;
    Label5: TLabel;
    Label11: TLabel;
    Label27: TLabel;
    YGName: TEdit;
    YGSex: TComboBox;
    SJLiZhiDate: TDateTimePicker;
    LiZhiNote: TRichEdit;
    Label2: TLabel;
    JHLiZhiDate: TDateTimePicker;
    Label3: TLabel;
    LiZhiTBDate: TDateTimePicker;
    Label1: TLabel;
    UserID: TEdit;
    Dept: TEdit;
    Label6: TLabel;
    GangWei: TEdit;
    Label7: TLabel;
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormDestroy(Sender: TObject);
  private
    TPInt:Integer;
    procedure InitData();
    function  SaveData():Boolean;
    { Private declarations }
  public
    canshu1:String;
    PState,CopyInt:Integer;
    FMainId,FDName:String;
    { Public declarations }
  end;

var
  frmYGYPInPut_LiZhi: TfrmYGYPInPut_LiZhi;
implementation
uses
  U_DataLink,U_ZDYHelp,U_RTFun,U_ZDYHelpSel;

{$R *.dfm}

procedure TfrmYGYPInPut_LiZhi.TBCloseClick(Sender: TObject);
begin
  Close;
end;

procedure TfrmYGYPInPut_LiZhi.InitData();
begin
  with ADOCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('select A.*,B.UserID from OA_YG_DangAn A ');
    sql.add('inner join SY_User B On B.UserName=isnull(A.YGEName,A.YGName) ');
    if trim(FDName)='' then
    sql.add('where isnull(A.YGEName,A.YGName)='''+Trim(DName)+'''')
    else
    sql.add('where A.YGName='''+trim(FDName)+'''');
    sql.Add(' and A.YGType<>''离职''');
    Open;
  end;
  SCSHDataNew(ADOCmd,Panel3,2);
  UserID.Text:=trim(ADOCmd.fieldbyname('UserID').AsString);
end;

procedure TfrmYGYPInPut_LiZhi.FormShow(Sender: TObject);
begin
  LizhiTBDate.DateTime:=SGetServerDate(ADOTemp);
  JHLiZhiDate.DateTime:=SGetServerDate(ADOTemp);
  SJLiZhiDate.DateTime:=SGetServerDate(ADOTemp);
  InitData();
end;

function TfrmYGYPInPut_LiZhi.SaveData():Boolean;
var
  maxno:String;
begin
  Result:=False;
  try
    ADOCmd.Connection.BeginTrans;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      SQL.Add('select * from OA_YG_DangAn where isnull(YGEName,YGName)='''+Trim(DName)+''' and YGType<>''离职''');
      Open;
    end;
    with ADOCmd do
    begin
      Edit;
      RTSetsavedata(ADOCmd,'OA_YG_DangAn',Panel3,2);
      FieldByName('LiZhiStatus').Value:='待提交';
      Post;
    end;
    ADOCmd.Connection.CommitTrans;
    Result:=True;
  except
    Result:=False;
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！','提示',0);
  end;
end;

procedure TfrmYGYPInPut_LiZhi.TBSaveClick(Sender: TObject);
var
  FSFNO:String;
begin
  ToolBar1.SetFocus;
  if Trim(YGName.Text)='' then
  begin
    Application.MessageBox('姓名不能为空！','提示',0);
    Exit;
  end;
  if Trim(LiZhiNote.Text)='' then
  begin
    Application.MessageBox('离职原因不能为空!','提示',0);
    Exit;
  end;
  if SaveData() then
  begin
    Application.MessageBox('保存成功！','提示',0);
    Modalresult:=1;
  end;
end;

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

procedure TfrmYGYPInPut_LiZhi.FormDestroy(Sender: TObject);
begin
  FrmYGYPInPut_LiZhi:=nil;
end;

end.
