unit U_YGYPInPut_GWSQ;

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_GWSQ = 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;
    Label27: TLabel;
    YGName: TEdit;
    SQNote: TRichEdit;
    Label1: TLabel;
    UserID: TEdit;
    Dept: TEdit;
    Label6: TLabel;
    GangWei: TEdit;
    Label7: TLabel;
    Label2: TLabel;
    SQGangWei: TBtnEditA;
    DPID: TEdit;
    Label3: TLabel;
    SQDept: TBtnEditA;
    YGID: TEdit;
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormDestroy(Sender: TObject);
    procedure SQGangWeiBtnClick(Sender: TObject);
    procedure SQDeptBtnClick(Sender: TObject);
  private
    TPInt:Integer;
    procedure InitData();
    function  SaveData():Boolean;
    { Private declarations }
  public
    canshu1:String;
    PState,CopyInt:Integer;
    FMainId,FDName,FDDID:String;
    { Public declarations }
  end;

var
  frmYGYPInPut_GWSQ: TfrmYGYPInPut_GWSQ;
implementation
uses
  U_DataLink,U_ZDYHelp,U_RTFun,U_ZDYHelpSel,U_SYDeptView;

{$R *.dfm}

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

procedure TfrmYGYPInPut_GWSQ.InitData();
begin
  if Trim(FDDID)='' then
  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) ');
      sql.add('where isnull(A.YGEName,A.YGName)='''+Trim(DName)+''' and A.YGType<>''离职''');
      Open;
    end;
    YGName.Text:=trim(DName);
    Dept.Text:=trim(ADOCmd.fieldbyname('Dept').AsString);
    GangWei.Text:=trim(ADOCmd.fieldbyname('GangWei').AsString);
    UserID.Text:=trim(ADOCmd.fieldbyname('UserID').AsString);
    YGID.Text:=trim(ADOCmd.fieldbyname('YGID').AsString);
  end
  else
  begin
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from OA_YG_DangAN_GWDD A ');
      sql.add('where DDID='''+Trim(FDDID)+'''');
      Open;
    end;
    SCSHDataNew(ADOCmd,Panel3,2);
  end;
end;

procedure TfrmYGYPInPut_GWSQ.FormShow(Sender: TObject);
begin
  InitData();
end;

function TfrmYGYPInPut_GWSQ.SaveData():Boolean;
var
  maxno:String;
begin
  Result:=False;
  try
    ADOCmd.Connection.BeginTrans;
    if trim(FDDID)='' then
    begin
      if GetLSNo(ADOCmd,FDDID,'','OA_YG_DangAN_GWDD',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_GWDD where DDID='''+Trim(FDDID)+'''');
      Open;
    end;
    with ADOCmd do
    begin
      if isempty then append
      else Edit;
      fieldbyname('DDID').AsString:=trim(FDDID);
      RTSetsavedata(ADOCmd,'OA_YG_DangAN_GWDD',Panel3,2);
      fieldbyname('SQDate').AsDateTime:=SGetServerDate(ADOTemp);
      fieldbyname('DPID').AsString:=Trim(DPID.Text);
      fieldbyname('SQDept').AsString:=trim(SQDept.Text);
      FieldByName('SQStatus').Value:='待提交';
      Post;
    end;
    ADOCmd.Connection.CommitTrans;
    Result:=True;
  except
    Result:=False;
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！','提示',0);
  end;
end;

procedure TfrmYGYPInPut_GWSQ.TBSaveClick(Sender: TObject);
var
  FSFNO:String;
begin
  ToolBar1.SetFocus;
  if Trim(YGName.Text)='' then
  begin
    Application.MessageBox('姓名不能为空！','提示',0);
    Exit;
  end;
  if Trim(SQGangWei.Text)='' then
  begin
    Application.MessageBox('申请岗位不能为空!','提示',0);
    Exit;
  end;
  if Trim(SQDept.Text)='' then
  begin
    Application.MessageBox('申请部门不能为空!','提示',0);
    Exit;
  end;
  if SaveData() then
  begin
    Application.MessageBox('保存成功！','提示',0);
    Modalresult:=1;
  end;
end;

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

procedure TfrmYGYPInPut_GWSQ.FormDestroy(Sender: TObject);
begin
  frmYGYPInPut_GWSQ:=nil;
end;

procedure TfrmYGYPInPut_GWSQ.SQGangWeiBtnClick(Sender: TObject);
begin
  try
    frmSYDeptView:=TfrmSYDeptView.Create(Application);
    with frmSYDeptView do
    begin
      if ShowModal=1 then
      begin
        Self.SQGangWei.Text:=Trim(frmSYDeptView.CDS_Tree.fieldbyname('DPName').AsString);
        Self.DPID.Text:=Trim(frmSYDeptView.CDS_Tree.fieldbyname('DPID').AsString);
      end;
    end;
  finally
    frmSYDeptView.Free;
  end;
end;

procedure TfrmYGYPInPut_GWSQ.SQDeptBtnClick(Sender: TObject);
begin
  try
    frmSYDeptView:=TfrmSYDeptView.Create(Application);
    with frmSYDeptView do
    begin
      if ShowModal=1 then
      begin
        Self.SQDept.Text:=Trim(frmSYDeptView.CDS_Tree.fieldbyname('DPName').AsString);
      end;
    end;
  finally
    frmSYDeptView.Free;
  end;
end;

end.
