unit U_WorkerDeptFeeInPut_DJ;

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, cxDropDownEdit, cxCalendar, cxGridCustomPopupMenu,
  cxGridPopupMenu;

type
  TfrmWorkerDeptFeeInPut_DJ = class(TForm)
    ToolBar1: TToolBar;
    TBSave: TToolButton;
    TBClose: TToolButton;
    ADOTemp: TADOQuery;
    ADOCmd: TADOQuery;
    DataSource1: TDataSource;
    Order_Sub: TClientDataSet;
    ADOQuery1: TADOQuery;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ToolButton3: TToolButton;
    ToolButton4: TToolButton;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1DJDate: TcxGridDBColumn;
    v1YGName: TcxGridDBColumn;
    v1KFName: TcxGridDBColumn;
    v1KFType: TcxGridDBColumn;
    v1KFQty: TcxGridDBColumn;
    v1KFNote: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    v1YGID: TcxGridDBColumn;
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure v1Column3PropertiesEditValueChanged(Sender: TObject);
    procedure v1Column9PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1Column1PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1priceUnitPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1ZhaiYaoPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1Column2PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure ToolButton3Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure v1YGNamePropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1KFNamePropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
  private
    FXS:Integer;
    procedure InitData();
    procedure ZDYHelp(FButn:TcxButtonEdit;LType:string);
    function  SaveData():Boolean;
    procedure GetMaxConNO();
    { Private declarations }
  public
    PState,PCopyInt:Integer;
    FMainId,FConNo,FConType:String;

    { Public declarations }
  end;

var
  frmWorkerDeptFeeInPut_DJ: TfrmWorkerDeptFeeInPut_DJ;

implementation
uses
  U_DataLink,U_ZDYHelp,U_RTFun,U_GYSList,U_ZDYHelpSel,U_YGCXList,
  U_SYDeptUserView, U_SYDeptView;

{$R *.dfm}

procedure TfrmWorkerDeptFeeInPut_DJ.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('员工绩效分数1',Tv1,'费用管理');
end;

procedure TfrmWorkerDeptFeeInPut_DJ.InitData();
begin
  with ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    sql.Add('select * from OA_DangAn_KF ');
    sql.Add(' where KFID='''+Trim(FMainId)+'''');
    Open;
  end;
  SCreateCDS20(ADOQuery1,Order_Sub);
  SInitCDSData20(ADOQuery1,Order_Sub);
end;

procedure TfrmWorkerDeptFeeInPut_DJ.ZDYHelp(FButn:TcxButtonEdit;LType:string);
begin
end;

procedure TfrmWorkerDeptFeeInPut_DJ.FormShow(Sender: TObject);
begin
  ReadCxGrid('员工绩效分数1',Tv1,'费用管理');
 
  InitData();
end;

procedure TfrmWorkerDeptFeeInPut_DJ.GetMaxConNO();
begin

end;

function TfrmWorkerDeptFeeInPut_DJ.SaveData():Boolean;
var
  maxno,maxSubNo:String;
  DateStr:string;
begin
  try
    Result:=False;
    ADOCmd.Connection.BeginTrans;
    ///保存子表
    with Order_Sub do
    begin
      First;
      while not Eof do
      begin
        if Trim(Order_Sub.fieldbyname('KFID').AsString)='' then
        begin
          if GetLSNo(ADOCmd,maxSubNo,'WS','OA_DangAn_KF',4,1)=False then
          begin
            ADOCmd.Connection.RollbackTrans;
            Application.MessageBox('生成费用报销子表流水号异常！','提示',0);
            exit;
          end;
        end else
        begin
          maxSubNo:=Trim(Order_Sub.fieldbyname('KFID').AsString);
        end;
        with ADOCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from OA_DangAn_KF where ');
          sql.Add('  KFID='''+Trim(maxSubNo)+'''');
          Open;
        end;
        with ADOCmd do
        begin
          if Trim(Order_Sub.fieldbyname('KFID').AsString)='' then
            Append
          else
            Edit;
          FieldByName('KFID').Value:=Trim(maxSubNo);
          RTSetSaveDataCDS(ADOCmd,Tv1,Order_Sub,'OA_DangAn_KF',0);
          fieldbyname('KFQty').Value:=Order_Sub.fieldbyname('KFQty').AsFloat;
          Post;
        end;
        Order_Sub.Edit;
        Order_Sub.FieldByName('KFID').Value:=Trim(maxSubNo);
        Next;
      end;
    end;
    ADOCmd.Connection.CommitTrans;
    FMainId:=Trim(maxSubNo);
    Result:=True;
  except;
    Result:=False;
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！','提示',0);
  end;
end;

procedure TfrmWorkerDeptFeeInPut_DJ.TBSaveClick(Sender: TObject);
begin
  ToolBar1.SetFocus;
  if Order_Sub.IsEmpty then
  begin
    Application.MessageBox('明细不能为空！','提示',0);
    exit;
  end;
  if Order_Sub.Locate('KFQty',Null,[])=True then
  begin
    Application.MessageBox('分数不能为空!','提示',0);
    Exit;
  end;
  if Order_Sub.Locate('YGName',Null,[])=True then
  begin
    Application.MessageBox('员工名称不能为空!','提示',0);
    Exit;
  end;
  if SaveData() then
  begin
    Application.MessageBox('保存成功！','提示',0);
    ModalResult:=1;
  end;
end;

procedure TfrmWorkerDeptFeeInPut_DJ.v1Column3PropertiesEditValueChanged(
  Sender: TObject);
var
  FName,FQty,FPrice,mvalue:string;
begin
  FName:=Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName;
  mvalue:=TcxTextEdit(Sender).EditingText;

  with Order_Sub do
  begin
    Edit;
    if Trim(mvalue)='' then
      FieldByName(FName).Value:=null
    else
      FieldByName(FName).Value:=mvalue;
    Post;
  end;
  FQty:=Trim(Order_Sub.fieldbyname('YCLQty').AsString);
  FPrice:=Trim(Order_Sub.fieldbyname('YCLPrice').AsString);
  if Trim(FQty)='' then FQty:='0';
  if Trim(FPrice)='' then FPrice:='0';
  with Order_Sub do
  begin
    Edit;
    FieldByName('Money').Value:=StrToFloat(FQty)*StrToFloat(FPrice);
    Post;
  end;
end;

procedure TfrmWorkerDeptFeeInPut_DJ.v1Column9PropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  frmZDYHelp:=TfrmZDYHelp.Create(self);
  with frmZDYHelp do
  begin
    flag:='YCLUnit';
    flagname:='数量单位';
    if showModal=1 then
    begin
      with Order_Sub do
      begin
        edit;
        fieldbyname('YCLUnit').asstring:=trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
      end;
    end;
    free;
  end;
end;

procedure TfrmWorkerDeptFeeInPut_DJ.v1Column1PropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  frmZDYHelp:=TfrmZDYHelp.Create(self);
  with frmZDYHelp do
  begin
    flag:='ZhaiYao';
    flagname:='付款单位';
    if showModal=1 then
    begin
      with Order_Sub do
      begin
        edit;
        fieldbyname('ZhaiYao').asstring:=trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
      end;
    end;
    free;
  end;
end;

procedure TfrmWorkerDeptFeeInPut_DJ.v1priceUnitPropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  frmZDYHelp:=TfrmZDYHelp.Create(self);
  with frmZDYHelp do
  begin
    flag:='priceUnit';
    flagname:='币种';
    if showModal=1 then
    begin
      with Order_Sub do
      begin
        edit;
        fieldbyname('priceUnit').asstring:=trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
      end;
    end;
    free;
  end;
end;

procedure TfrmWorkerDeptFeeInPut_DJ.v1ZhaiYaoPropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  frmZDYHelp:=TfrmZDYHelp.Create(self);
  with frmZDYHelp do
  begin
    flag:='ZhaiYao';
    flagname:='公司抬头';
    if showModal=1 then
    begin
      Order_Sub.Edit;
      Order_Sub.FieldByName('ZhaiYao').AsString:=trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
    end;
    free;
  end;
end;

procedure TfrmWorkerDeptFeeInPut_DJ.v1Column2PropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  frmZDYHelp:=TfrmZDYHelp.Create(self);
  with frmZDYHelp do
  begin
    flag:='YCLName';
    flagname:='用途';
    if showModal=1 then
    begin
      Order_Sub.Edit;
      Order_Sub.FieldByName('YCLName').AsString:=trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
    end;
    free;
  end;
end;

procedure TfrmWorkerDeptFeeInPut_DJ.ToolButton3Click(Sender: TObject);
begin

    with Order_Sub do
    begin
      Append;
      fieldbyname('DJDate').Value:=SGetServerDate(ADOQuery1);
      Post;
    end;
end;

procedure TfrmWorkerDeptFeeInPut_DJ.ToolButton4Click(Sender: TObject);
begin
  if Order_Sub.IsEmpty then Exit;
  if Trim(Order_Sub.fieldbyname('KFID').AsString)<>'' then
  begin
    if Application.MessageBox('确定要删行吗？','提示',32+4)<>IDYES then Exit;
    with ADOQuery1 do
    begin
      Close;
      sql.Clear;
      sql.Add('delete OA_DangAn_KF where KFID='''+Trim(Order_Sub.fieldbyname('KFID').AsString)+'''');
      ExecSQL;
    end;
  end;
  Order_Sub.Delete;
end;

procedure TfrmWorkerDeptFeeInPut_DJ.v1YGNamePropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  frmYGCXList:=TfrmYGCXList.Create(self);
  with frmYGCXList do
  begin
    if showModal=1 then
    begin
      Order_Sub.Edit;
      Order_Sub.FieldByName('YGName').AsString:=trim(Order_Main.fieldbyname('YGName').AsString);
      Order_Sub.FieldByName('YGID').AsString:=trim(Order_Main.fieldbyname('YGID').AsString);
    end;
    free;
  end;
end;

procedure TfrmWorkerDeptFeeInPut_DJ.v1KFNamePropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  frmZDYHelp:=TfrmZDYHelp.Create(self);
  with frmZDYHelp do
  begin
    flag:='KFName';
    flagname:='分数名称';
    if showModal=1 then
    begin
      Order_Sub.Edit;
      Order_Sub.FieldByName('KFName').AsString:=trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
    end;
    free;
  end;
end;

end.
