unit U_YGYPInPut_JiaXin;

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_JiaXin = 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;
    SXJXdate: TDateTimePicker;
    JXNote: TRichEdit;
    Label2: TLabel;
    JHJXDate: TDateTimePicker;
    Label3: TLabel;
    TBDate: TDateTimePicker;
    Label1: TLabel;
    XueLi: TEdit;
    Dept: TEdit;
    Label6: TLabel;
    GangWei: TEdit;
    Label7: TLabel;
    zhuanzhengDate: TDateTimePicker;
    Label8: TLabel;
    Label10: TLabel;
    GRNXMoney: TEdit;
    MQWork: TEdit;
    Label12: TLabel;
    WorkDate: TDateTimePicker;
    Label9: TLabel;
    Label13: TLabel;
    JXMoney: TEdit;
    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
    PState,CopyInt:Integer;
    FJXID,FYGID:String;
    { Public declarations }
  end;

var
  frmYGYPInPut_JiaXin: TfrmYGYPInPut_JiaXin;
implementation
uses
  U_DataLink,U_ZDYHelp,U_RTFun,U_ZDYHelpSel;

{$R *.dfm}

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

procedure TfrmYGYPInPut_JiaXin.InitData();
begin
  if trim(FJXID)='' then
  begin
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('select A.* from OA_YG_DangAn A ');
      sql.add('where isnull(A.YGEName,A.YGName)='''+Trim(DName)+'''');
      Open;
    end;
    {YGName.Text:=trim(ADOCmd.fieldbyname('YGName').AsString);
    zhuanzhengDate.DateTime:=ADOCmd.fieldbyname('zhuanzhengDate').AsDateTime;
    XueLi.Text:=trim(ADOCmd.fieldbyname('XueLi').AsString);
    GangWei.Text:=trim(ADOCmd.fieldbyname('GangWei').AsString);
    Dept.Text:=trim(ADOCmd.fieldbyname('Dept').AsString);
    GrnxMoney.Text:=trim(ADOCmd.fieldbyname('GrnxMoney').AsString);}
    FYGID:=trim(ADOCmd.fieldbyname('YGID').AsString);
    SCSHDataNew(ADOCmd,Panel3,1);
  end
  else
  begin
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('select A.*,B.* from OA_YG_DangAn A ');
      sql.add('inner join OA_YG_DangAn_JX B on B.YGID=A.YGID ');
      sql.add('where isnull(A.YGEName,A.YGName)='''+Trim(DName)+''' ');
      sql.add('and JXID='''+trim(FJXID)+'''');
      Open;
    end;
    SCSHDataNew(ADOCmd,Panel3,2);
    SCSHDataNew(ADOCmd,Panel3,1);
  end;
end;

procedure TfrmYGYPInPut_JiaXin.FormShow(Sender: TObject);
begin
  TBDate.DateTime:=SGetServerDate(ADOTemp);
  JHJXDate.DateTime:=SGetServerDate(ADOTemp);
  SXJXdate.DateTime:=SGetServerDate(ADOTemp);
  WorkDate.datetime:=SGetServerDate(ADOTemp);
  InitData();
end;

function TfrmYGYPInPut_JiaXin.SaveData():Boolean;
var
  maxno:String;
begin
  Result:=False;
  try
    ADOCmd.Connection.BeginTrans;
    if trim(FJXID)='' then
    begin
      if GetLSNo(ADOCmd,FJXID,'','OA_YG_DangAn_JX',4,1)=False then
      begin
        ADOCmd.Connection.RollbackTrans;
        Application.MessageBox('取最大号失败!','提示',0);
        Exit;
      end;
    end;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      SQL.Add('select * from OA_YG_DangAn_JX where JXID='''+Trim(FJXID)+'''');
      Open;
      if isempty then
      begin
        append;
        fieldbyname('filltime').Value:=SGetServerDate(ADOTemp);
        fieldbyname('Filler').Value:=trim(DName);
        fieldbyname('YGID').Value:=trim(FYGID);
      end
      else
      edit;
      fieldbyname('JXID').Value:=trim(FJXID);
      RTSetsavedata(ADOCmd,'OA_YG_DangAn_JX',Panel3,2);
      FieldByName('JXStatus').Value:='待提交';
      post;
    end;
    ADOCmd.Connection.CommitTrans;
    Result:=True;
  except
    Result:=False;
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！','提示',0);
  end;
end;

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

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

procedure TfrmYGYPInPut_JiaXin.FormDestroy(Sender: TObject);
begin
  FrmYGYPInPut_JiaXin:=nil;
end;

end.
