unit U_XHGZListHZNew;

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, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator,
  dxBarBuiltInMenu, dxSkinsCore, dxSkinsDefaultPainters, dxSkinscxPCPainter;

type
  TfrmXHGZListHZNew = 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;
    v1Column4: TcxGridDBColumn;
    v1Column15: TcxGridDBColumn;
    cxGrid2Level1: TcxGridLevel;
    v1Column23: TcxGridDBColumn;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    v1Column5: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    ToolButton1: TToolButton;
    v1Column1: TcxGridDBColumn;
    TBFind: TToolButton;
    cxTabControl1: TcxTabControl;
    ToolButton2: TToolButton;
    ToolButton3: TToolButton;
    v1Column2: TcxGridDBColumn;
    Label4: TLabel;
    Edit1: TEdit;
    ToolButton4: TToolButton;
    RM2: TRMGridReport;
    RMDBDataSet1: TRMDBDataSet;
    v1Column3: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    ToolButton5: TToolButton;
    ToolButton6: TToolButton;
    v1Column9: TcxGridDBColumn;
    ToolButton7: TToolButton;
    ToolButton8: TToolButton;
    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 ToolButton1Click(Sender: TObject);
    procedure v1DuiZhangPropertiesEditValueChanged(Sender: TObject);
    procedure Tv1DblClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure YGNameChange(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure ToolButton6Click(Sender: TObject);
    procedure ToolButton7Click(Sender: TObject);
    procedure ToolButton8Click(Sender: TObject);
  private
    procedure InitGrid();
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmXHGZListHZNew: TfrmXHGZListHZNew;

implementation

uses
  U_DataLink, U_RTFun, U_Fun, U_XHGZListInPut, U_XHGZListNew, U_ZDYHelpYuanGong,
  U_JLPTInPut, U_FjList_RZ,U_XHGGZ;

{$R *.dfm}

procedure TfrmXHGZListHZNew.FormDestroy(Sender: TObject);
begin
  frmXHGZListHZNew := nil;
end;

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

procedure TfrmXHGZListHZNew.InitGrid();
begin

  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add(' exec P_View_WageMonth' + 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 TfrmXHGZListHZNew.TBRafreshClick(Sender: TObject);
begin
//  BegDate.SetFocus;
  InitGrid();
end;

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

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

procedure TfrmXHGZListHZNew.FormShow(Sender: TObject);
begin
  ReadCxGrid('绣花工日工资列表', Tv1, '工资管理');
//  cxTabControl1.TabIndex := StrToIntDef(Trim(FormatDateTime('MM', SGetServerDate10(ADOQueryTemp))), 1) - 1;

  BegDate.Date := StartOfTheMonth(Now);
  enddate.Date := EndOfTheMonth(BegDate.Date);

  InitGrid();

end;

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

procedure TfrmXHGZListHZNew.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 TfrmXHGZListHZNew.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 TfrmXHGZListHZNew.Tv1DblClick(Sender: TObject);
begin
  try
    frmXHGZList := TfrmXHGZList.Create(Application);
    with frmXHGZList do
    begin
      frmXHGZList.YGCode.Text := Trim(Self.CDS_Main.fieldbyname('YGCode').AsString);
      frmXHGZList.YGName.Text := Trim(Self.CDS_Main.fieldbyname('YGName').AsString);
      frmXHGZList.BegDate.DateTime := StrToDate(trim(Self.CDS_Main.fieldbyname('CRTime').AsString) + '-01');

      frmXHGZList.EndDate.DateTime := EndOfTheMonth(frmXHGZList.BegDate.DateTime);
      if ShowModal = 1 then
      begin
        Self.InitGrid();
      end;
    end;
  finally
    frmXHGZList.Free;
  end;
end;

procedure TfrmXHGZListHZNew.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 TfrmXHGZListHZNew.YGNameChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmXHGZListHZNew.FormCreate(Sender: TObject);
begin
  EndDate.DateTime := SGetServerDate10(ADOQueryTemp);
  BegDate.DateTime := EndDate.DateTime - 30;
end;

procedure TfrmXHGZListHZNew.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 TfrmXHGZListHZNew.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 TfrmXHGZListHZNew.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;

procedure TfrmXHGZListHZNew.cxTabControl1Change(Sender: TObject);
begin
//  BegDate.Date := StartOfTheMonth(Now);
//  enddate.Date := EndOfTheMonth(BegDate.Date);

  if cxTabControl1.TabIndex < 9 then
    BegDate.Date := StrToDate(Trim(FormatDateTime('yyyy-', enddate.DateTime)) + '0' + inttostr(cxTabControl1.TabIndex + 1) + '-01')
  else
    BegDate.Date := StrToDate(Trim(FormatDateTime('yyyy-', enddate.DateTime)) + inttostr(cxTabControl1.TabIndex + 1) + '-01');
  enddate.Date := EndOfTheMonth(BegDate.Date);

  InitGrid();
end;

procedure TfrmXHGZListHZNew.ToolButton5Click(Sender: TObject);
begin
  try
    frmJLPTInPut := TfrmJLPTInPut.Create(Application);
    with frmJLPTInPut do
    begin
      FYGCode := Self.CDS_Main.FieldByName('YGCode').AsString;
      FYGName := Self.CDS_Main.FieldByName('YGName').AsString;

      if cxTabControl1.TabIndex < 9 then
        FCRTime := FormatDateTime('yyyy-MM-dd', EndOfTheMonth(StrToDate(Trim(FormatDateTime('yyyy-', enddate.DateTime)) + '0' + inttostr(cxTabControl1.TabIndex + 1) + '-01')))
      else
        FCRTime := FormatDateTime('yyyy-MM-dd', EndOfTheMonth(StrToDate(Trim(FormatDateTime('yyyy-', enddate.DateTime)) + inttostr(cxTabControl1.TabIndex + 1) + '-01')));

      if ShowModal = 1 then
      begin
        Self.InitGrid();
      end;
    end;
  finally
    frmJLPTInPut.Free;
  end;
end;

procedure TfrmXHGZListHZNew.ToolButton6Click(Sender: TObject);
begin
  if CDS_Main.IsEmpty then
    Exit;
  try
    frmFjList_RZ := TfrmFjList_RZ.Create(Application);
    with frmFjList_RZ do
    begin
      fkeyNO := Trim(Self.CDS_Main.fieldbyname('YGName').AsString) + IntToStr(cxTabControl1.TabIndex);
      fType := '工资条';
      if ShowModal = 1 then
      begin
        Self.InitGrid();
      end;
    end;
  finally
    frmFjList_RZ.Free;
  end;
end;

procedure TfrmXHGZListHZNew.ToolButton7Click(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_View_WageMonthAll ' + 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;

procedure TfrmXHGZListHZNew.ToolButton8Click(Sender: TObject);
begin
  try
    frmxhggz := Tfrmxhggz.Create(Application);
    with frmxhggz do
    begin
//      FFFID := '';
      if ShowModal = 1 then
      begin
        InitGrid();
      end;
    end;
  finally
    frmxhggz.Free;
  end;
end;

end.

