unit U_XHGZYearList;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
  cxEdit, DB, cxDBData, cxGridCustomTableView, cxGridTableView,
  cxGridBandedTableView, cxGridDBBandedTableView, cxGridLevel, cxClasses,
  cxControls, cxGridCustomView, cxGridDBTableView, cxGrid, StdCtrls, ComCtrls,
  ExtCtrls, ToolWin, cxGridCustomPopupMenu, cxGridPopupMenu, ADODB, DBClient,
  cxDropDownEdit, cxCheckBox, RM_Common, RM_Class, RM_e_Xls, RM_Dataset,
  RM_System, RM_GridReport, Menus, cxCalendar, cxButtonEdit, cxTextEdit,
  DateUtils, cxPC;

type
  TfrmXHGZYearList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBExport: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Label1: TLabel;
    Label2: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    CDS_Main: TClientDataSet;
    RM1: TRMGridReport;
    RMDBMain: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    CDS_PRT: TClientDataSet;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    Label3: TLabel;
    Label8: TLabel;
    YGName: TEdit;
    YGCode: TEdit;
    cxGrid2: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column15: TcxGridDBColumn;
    cxGrid2Level1: TcxGridLevel;
    v1Column23: TcxGridDBColumn;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    v1Column5: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    ToolButton1: TToolButton;
    v1Column1: TcxGridDBColumn;
    TBFind: TToolButton;
    Label4: TLabel;
    Edit1: TEdit;
    RM2: TRMGridReport;
    RMDBDataSet1: TRMDBDataSet;
    v1Column2: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBRafreshClick(Sender: TObject);
    procedure ConNoMChange(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure v1DuiZhangPropertiesEditValueChanged(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure YGNameChange(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
  private
    procedure InitGrid();
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmXHGZYearList: TfrmXHGZYearList;

implementation

uses
  U_DataLink, U_RTFun, U_Fun, U_XHGZListInPut, U_XHGZListNew, U_ZDYHelpYuanGong;

{$R *.dfm}

procedure TfrmXHGZYearList.FormDestroy(Sender: TObject);
begin
  frmXHGZYearList := nil;
end;

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

procedure TfrmXHGZYearList.InitGrid();
begin

  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add(' exec P_View_WageYear' + quotedstr(Trim(FormatDateTime('yyyy-MM-dd', BegDate.DateTime))));
      sql.add(' ,' + quotedstr(Trim(FormatDateTime('yyyy-MM-dd', enddate.DateTime + 1))));
//      ShowMessage(SQL.Text);
      Open;
    end;

    SCreateCDS20(ADOQueryMain, CDS_Main);
    SInitCDSData20(ADOQueryMain, CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
  TBFind.Click;
end;

procedure TfrmXHGZYearList.TBRafreshClick(Sender: TObject);
begin
//  BegDate.SetFocus;
  InitGrid();
end;

procedure TfrmXHGZYearList.ConNoMChange(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  end;
end;

procedure TfrmXHGZYearList.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('绣花工日工资列表', Tv1, '工资管理');
  Close;
end;

procedure TfrmXHGZYearList.FormShow(Sender: TObject);
begin
  ReadCxGrid('绣花工日工资列表', Tv1, '工资管理');
  InitGrid();
  //InitGrid();
end;

procedure TfrmXHGZYearList.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    exit;
  TcxGridToExcel('绣花工日工资列表', cxGrid2);
end;

procedure TfrmXHGZYearList.N1Click(Sender: TObject);
begin
  SelOKNo(CDS_Main, True);
end;

procedure TfrmXHGZYearList.N2Click(Sender: TObject);
begin
  SelOKNo(CDS_Main, False);
end;

procedure TfrmXHGZYearList.ToolButton1Click(Sender: TObject);
var
  fPrintFile: string;
begin
  ExportFtErpFile('绣花工全年工资表.rmf', ADOQueryTemp);
  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\绣花工全年工资表.rmf';
  RMXLSExport1 := TRMXLSExport.Create(RMXLSExport1);

  if FileExists(fPrintFile) then
  begin
    RM2.LoadFromFile(fPrintFile);
    RM2.ShowReport;
  end
  else
  begin
    Application.MessageBox(PChar('没有找' + ExtractFilePath(Application.ExeName) + 'Report\绣花工全年工资表.rmf'), '提示', 0);
  end;
end;

procedure TfrmXHGZYearList.v1DuiZhangPropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FFieldName, FPDTiaoXian, FISM, FHXName: string;
  FMiShu, AZhenShu, FZhenShu, FPrice, FMoney, FOutputWage, FElseWage, FKKMoney: Double;
begin
  FFieldName := Trim(Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName);
  with CDS_Main do
  begin
    edit;
    if CDS_Main.FieldByName('DuiZhang').AsBoolean = True then
    begin
      CDS_Main.FieldByName('DuiZhang').AsBoolean := false;
    end
    else
    begin
      CDS_Main.FieldByName('DuiZhang').AsBoolean := true;
    end;
    Post;
  end;
  with ADOQueryCmd do
  begin
    close;
    sql.Clear;
    sql.Add('update GZList set ');
    if CDS_Main.FieldByName('DuiZhang').AsBoolean = True then
    begin
      sql.Add('DuiZhang=1 ');
    end
    else
    begin
      sql.Add('DuiZhang=0 ');
    end;
    sql.Add('where GZID=''' + Trim(CDS_Main.fieldbyname('GZID').AsString) + '''');
    ExecSQL;
  end;
  Tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmXHGZYearList.TBFindClick(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
    SCreateCDS20(ADOQueryMain, CDS_Main);
    SInitCDSData20(ADOQueryMain, CDS_Main);
  end;
end;

procedure TfrmXHGZYearList.YGNameChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmXHGZYearList.FormCreate(Sender: TObject);
var
  FYear: string;
  FMonth: string;
  FDate: TDate;
begin
  FDate := SGetServerDate10(ADOQueryTemp);
  FYear := FormatDateTime('yyyy', FDate);
  FMonth := FormatDateTime('MM', FDate);
  if StrToInt(FMonth) < 2 then
  begin
    BegDate.Date := StrToDate(IntToStr(strtoint(FYear) - 1) + '-02-01');
    EndDate.Date := StrToDate(FYear + '-01-31');
  end
  else
  begin
    BegDate.Date := StrToDate(FYear + '-02-01');
    EndDate.Date := StrToDate(IntToStr(strtoint(FYear) + 1) + '-01-31');
  end;
end;

procedure TfrmXHGZYearList.ToolButton3Click(Sender: TObject);
begin
  try
    frmZDYHelpYuanGong := TfrmZDYHelpYuanGong.Create(Application);
    with frmZDYHelpYuanGong do
    begin
      flag := 'YGXinxi';
      flagname := '员工信息';
      fnote := True;
      V1HelpType.Visible := True;
      V1Name.Caption := '姓名';
      V1Note.Caption := '工号';
      V1HelpType.Caption := '班次';
      V1Note1.Caption := '工种';
      fnote1 := True;
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmZDYHelpYuanGong.Free;
  end;
end;

procedure TfrmXHGZYearList.ToolButton2Click(Sender: TObject);
begin
  try
    frmXHGZListInPut := TfrmXHGZListInPut.Create(Application);
    with frmXHGZListInPut do
    begin
      FCRTime := Trim(FormatDateTime('yyyy-MM-dd', SGetServerDate10(ADOQueryTemp)));
      FBanCi := '白班';
      if ShowModal = 1 then
      begin
        Self.InitGrid();
      end;
    end;
  finally
    frmXHGZListInPut.Free;
  end;
end;

procedure TfrmXHGZYearList.cxTabControl1Change(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmXHGZYearList.ToolButton4Click(Sender: TObject);
var
  fPrintFile: string;
begin
  ExportFtErpFile('新绣花工月工资.rmf', ADOQueryTemp);
  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\新绣花工月工资.rmf';
  RMXLSExport1 := TRMXLSExport.Create(RMXLSExport1);
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add(' exec P_Print_XHGYGZ ' + QUOTEDSTR(Trim(FormatDateTime('yyyy-MM-dd', BegDate.DateTime))));
    Open;
  end;
  SCreateCDS20(ADOQueryTemp, CDS_PRT);
  SInitCDSData20(ADOQueryTemp, CDS_PRT);
  if FileExists(fPrintFile) then
  begin
    RM1.LoadFromFile(fPrintFile);
    RM1.ShowReport;
  end
  else
  begin
    Application.MessageBox(PChar('没有找' + ExtractFilePath(Application.ExeName) + 'Report\新绣花工月工资.rmf'), '提示', 0);
  end;
end;

end.

