unit U_JLPTInPut;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
  cxEdit, DB, cxDBData, cxCalendar, cxDropDownEdit, ComCtrls, ToolWin,
  cxGridLevel, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
  cxClasses, cxControls, cxGridCustomView, cxGrid, cxGridCustomPopupMenu,
  cxGridPopupMenu, ADODB, DBClient, cxButtonEdit, cxTextEdit, cxContainer,
  cxLabel, StdCtrls, cxCheckBox, ExtCtrls, Menus;

type
  TfrmJLPTInPut = class(TForm)
    DataSource3: TDataSource;
    CDS_Sub: TClientDataSet;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    cxGridPopupMenu2: TcxGridPopupMenu;
    ThreeColorBase: TcxStyleRepository;
    SHuangSe: TcxStyle;
    SkyBlue: TcxStyle;
    Default: TcxStyle;
    QHuangSe: TcxStyle;
    Red: TcxStyle;
    FontBlue: TcxStyle;
    TextSHuangSe: TcxStyle;
    FonePurple: TcxStyle;
    FoneClMaroon: TcxStyle;
    FoneRed: TcxStyle;
    RowColor: TcxStyle;
    handBlack: TcxStyle;
    cxBlue: TcxStyle;
    SHuangSeCu: TcxStyle;
    cxGridPopupMenu1: TcxGridPopupMenu;
    CDS_Main: TClientDataSet;
    DataSource1: TDataSource;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    N3: TMenuItem;
    N4: TMenuItem;
    CDS_YG: TClientDataSet;
    N5: TMenuItem;
    ScrollBox1: TScrollBox;
    Label1: TLabel;
    Label2: TLabel;
    CRTime: TDateTimePicker;
    QQJ: TEdit;
    ToolBar1: TToolBar;
    TBSave: TToolButton;
    TBClose: TToolButton;
    Label3: TLabel;
    YYJ: TEdit;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
    procedure v1Column9PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v1Column12PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure Button2Click(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
  private
    { Private declarations }
    function SaveData(): Boolean;
    procedure InitGrid();
  public
    { Public declarations }
    FYGCode, FYGName, FCRTime: string;
  end;

var
  frmJLPTInPut: TfrmJLPTInPut;

implementation

uses
  U_DataLink, U_RTFun, U_ZDYHelp, U_ZdyAttachGYS, U_ZdyAttachCP,
  U_ZdyAttachCP_HX_Sel, U_ZDYHelpTouJu, U_XHGZInPut, U_YGListMoresel,
  U_KouKuanInPut, U_ZDYHelpSel, U_WorkDetail;

{$R *.dfm}

function TfrmJLPTInPut.SaveData(): Boolean;
var
  maxno, maxSubNo: string;
begin
  try
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      SQL.Add('delete GZListMonth ');
      SQL.Add('where YGCode=' + quotedstr(Trim(FYGCode)));
      SQL.Add(' and YGName=' + quotedstr(Trim(FYGName)));
      SQL.Add(' and CRTime=' + quotedstr(Trim(FCRTime)));
      execsql;
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      SQL.Add('insert into GZListMonth(YGCode,YGName,CRTime,JLType,JLMoney)');
      SQL.Add('values(' + quotedstr(Trim(FYGCode)) + ',' + quotedstr(Trim(FYGName)) + ',' + quotedstr(Trim(FCRTime)) + ',''全勤奖'',' + quotedstr(Trim(QQJ.Text)) + ' )');
//      ShowMessage(SQL.Text);
      execsql;
    end;

    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      SQL.Add('insert into GZListMonth(YGCode,YGName,CRTime,JLType,JLMoney)');
      SQL.Add('values(' + quotedstr(Trim(FYGCode)) + ',' + quotedstr(Trim(FYGName)) + ',' + quotedstr(Trim(FCRTime)) + ',''业绩奖'',' + quotedstr(Trim(YYJ.Text)) + ' )');
      execsql;
    end;

    ADOQueryCmd.Connection.CommitTrans;
    Result := True;
  except
    Result := False;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！', '提示', 0);
  end;
end;

procedure TfrmJLPTInPut.InitGrid();
begin
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from  GZListMonth A  ');
    sql.Add(' where A.YGName=' + QUOTEDSTR(Trim(FYGName)));
    sql.Add(' and A.YGCode=' + QUOTEDSTR(Trim(FYGCode)));
    sql.Add(' and A.CRTime=' + QUOTEDSTR(Trim(FCRTime)));
    sql.Add(' and A.JLType=''全勤奖'' ');
//    ShowMessage(SQL.Text);
    Open;
  end;
  QQJ.Text := ADOQueryTemp.FieldByName('JLMoney').AsString;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from  GZListMonth A  ');
    sql.Add(' where A.YGName=' + QUOTEDSTR(Trim(FYGName)));
    sql.Add(' and A.YGCode=' + QUOTEDSTR(Trim(FYGCode)));
    sql.Add(' and A.CRTime=' + QUOTEDSTR(Trim(FCRTime)));
    sql.Add(' and A.JLType=''业绩奖'' ');
    Open;
  end;
  YYJ.Text := ADOQueryTemp.FieldByName('JLMoney').AsString;
//  SCSHDataNew(ADOQueryTemp, ScrollBox1, 2);

end;

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

procedure TfrmJLPTInPut.FormShow(Sender: TObject);
var
  fsj: string;
begin

  CRTime.DateTime := StrToDate(FCRTime);

  InitGrid();

end;

procedure TfrmJLPTInPut.v1Column9PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
var
  price1: Double;
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'ElseWageName';
      flagname := '其他工资项目';
      fnote := True;
      V1Note.Caption := '单价';
      if ShowModal = 1 then
      begin
        with Self.CDS_Sub do
        begin
          Edit;
          FieldByName('ElseWageName').Value := Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
          if TryStrToFloat(Trim(frmZDYHelp.ClientDataSet1.fieldbyname('Note').AsString), price1) then
            FieldByName('Price1').Value := price1
          else
            FieldByName('Price1').Value := 0;

        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmJLPTInPut.v1Column12PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'XHNote';
      flagname := '备注信息';
      if ShowModal = 1 then
      begin
        with Self.CDS_Sub do
        begin
          Edit;
          FieldByName('Note').Value := Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmJLPTInPut.Button2Click(Sender: TObject);
begin
  Close;
end;

procedure TfrmJLPTInPut.TBSaveClick(Sender: TObject);
begin
  if StrToIntDef(QQJ.Text, 0) = 0 then
  begin
    QQJ.Text := '0';
  end;
  if StrToIntDef(YYJ.Text, 0) = 0 then
  begin
    YYJ.Text := '0';
  end;
  if SaveData() then
  begin
//    Application.MessageBox('保存成功！', '提示', 0);
    ModalResult := 1;
  end;

end;

procedure TfrmJLPTInPut.TBCloseClick(Sender: TObject);
begin
  CLOSE;
end;

end.

