unit U_GaiJiList;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxGraphics, cxCustomData, cxStyles, cxTL, cxMaskEdit, DB, ADODB,
  cxInplaceContainer, cxDBTL, cxControls, cxTLData, ComCtrls, ToolWin, StdCtrls,
  cxFilter, cxData, cxDataStorage, cxEdit, cxDBData, DBClient,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, ExtCtrls,
  cxSplitter, cxGridLevel, cxClasses, cxGridCustomView, cxGrid,
  cxGridCustomPopupMenu, cxGridPopupMenu, RM_Dataset, RM_System, RM_Common,
  RM_Class, RM_GridReport, IdBaseComponent, IdComponent, IdTCPConnection,
  IdTCPClient, IdFTP, ShellAPI, IniFiles, cxCheckBox, cxCalendar, cxButtonEdit,
  cxTextEdit, cxDBLookupComboBox, cxPC, cxContainer, cxDropDownEdit, jpeg, U_SLT;

type
  TfrmGaiJiList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    Panel1: TPanel;
    ToolButton2: TToolButton;
    ADOQueryMain: TADOQuery;
    ToolButton1: TToolButton;
    RM1: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cxGridLevel1: TcxGridLevel;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_HZ: TDataSource;
    CDS_HZ: TClientDataSet;
    v2Column5: TcxGridDBColumn;
    v2Column8: TcxGridDBColumn;
    v2Column10: TcxGridDBColumn;
    v2Column17: TcxGridDBColumn;
    Label4: TLabel;
    Label5: TLabel;
    BegDate: TcxDateEdit;
    EndDate: TcxDateEdit;
    v2Column1: TcxGridDBColumn;
    v2Column2: TcxGridDBColumn;
    Label1: TLabel;
    CarNo: TEdit;
    v2Column6: TcxGridDBColumn;
    v2Column16: TcxGridDBColumn;
    v2Column18: TcxGridDBColumn;
    cxTabControl1: TcxTabControl;
    adoqueryPicture: TADOQuery;
    v2Column19: TcxGridDBColumn;
    tbDel: TToolButton;
    tbDelCX: TToolButton;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure C_CodeNameChange(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure v2Column8PropertiesEditValueChanged(Sender: TObject);
    procedure v2Column17PropertiesEditValueChanged(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure v2Column3PropertiesEditValueChanged(Sender: TObject);
    procedure tbDelClick(Sender: TObject);
    procedure tbDelCXClick(Sender: TObject);
  private

    { Private declarations }
    canshu1: string;
    procedure InitGrid();
    procedure SetStatus();
  public
    fkhType: string;
    Fmanage: string;
  end;

var
  frmGaiJiList: TfrmGaiJiList;
  Mach: array of TfrmSlt;

implementation

uses
  U_DataLink, U_Fun, U_RTFun, U_ZDYHelp, U_WageListInput, U_InspectionInfo,
  U_JTList;

{$R *.dfm}

procedure TfrmGaiJiList.SetStatus();
begin

  tbDel.Visible := False;
  tbDelCX.Visible := False;
  case cxTabControl1.TabIndex of
    0:
      begin
        tbDel.Visible := True;
      end;
    1:
      begin
        tbDelCX.Visible := True;
      end;
  end;
end;

procedure TfrmGaiJiList.InitGrid();
begin
  try

    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      SQL.Clear;
      sql.Add('select  A.* ');
      sql.Add(',B.ConNo,C.C_Code,C.C_CodeName from Worker_WorkDetail A ');
      sql.Add('inner join Cloth_Main B on A.MainId=B.MainId');
      sql.Add('inner join Cloth_Sub C on A.SubId=C.SubId');
      sql.Add('where A.FillerTime>' + quotedstr(Trim(BegDate.Text)));
      sql.Add(' and A.FillerTime<=' + quotedstr(Trim(EndDate.Text)));
      sql.Add(' and  A.CarStatus=''改机'' ');
      case cxTabControl1.TabIndex of
        0:
          begin
            sql.Add(' and   A.Valid=''Y'' ');
          end;
        1:
          begin
            sql.Add(' and   A.Valid=''N'' ');
          end;
      end;
      Open;
    end;

    SCreateCDS20(ADOQueryMain, CDS_HZ);
    SInitCDSData20(ADOQueryMain, CDS_HZ);
    CDS_HZ.Last;
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmGaiJiList.FormDestroy(Sender: TObject);
begin
  frmGaiJiList := nil;
end;

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

procedure TfrmGaiJiList.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid(trim(self.Caption), Tv2, '工资管理');
  Close;
end;

procedure TfrmGaiJiList.FormShow(Sender: TObject);
begin
  ReadCxGrid(trim(self.Caption), Tv2, '工资管理');
  SetStatus();
  InitGrid();
end;

procedure TfrmGaiJiList.TBRafreshClick(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmGaiJiList.ToolButton2Click(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
    SCreateCDS20(ADOQueryMain, CDS_HZ);
    SInitCDSData20(ADOQueryMain, CDS_HZ);
  end;
end;

procedure TfrmGaiJiList.C_CodeNameChange(Sender: TObject);
begin
  ToolButton2.Click;
end;

procedure TfrmGaiJiList.ToolButton1Click(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    Exit;
  TcxGridToExcel(self.Caption, cxgrid2);
 // SelExportData(Tv2,ADOQueryMain,'客户资料列表');
end;

procedure TfrmGaiJiList.FormCreate(Sender: TObject);
begin
  EndDate.Text := FormatDateTime('yyyy-MM-dd', SGetServerDate10(ADOQueryTemp)) + ' 08:00:00';
  BegDate.Text := FormatDateTime('yyyy-MM-dd', SGetServerDate10(ADOQueryTemp) - 1) + ' 08:00:00';
  canshu1 := Trim(DParameters1);
end;

procedure TfrmGaiJiList.v2Column8PropertiesEditValueChanged(Sender: TObject);
var
  FFieldName, mvalue: string;
  FQty, FCZCarPrice, FJTMoney, FBTMoney, FJlMoney, FCFMoney, FDTMoney: double;
begin
  mvalue := TcxTextEdit(Sender).EditingText;
  FFieldName := Trim(Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName);

  with CDS_HZ do
  begin
    Edit;
    FieldByName(FFieldName).Value := strtofloatdef(mvalue, 0);
    Post;
    FQty := FieldByName('Qty').asfloat;

  end;

  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('update DCGMoney set Qty=' + floattostr(FQty));
    sql.Add(' , Editer=' + quotedstr(DName));
    sql.Add(' , Edittime=getdate()');
    sql.Add(' where GZID=' + quotedstr(trim(Self.CDS_HZ.FieldByName('GZID').AsString)));
    EXECSQL;
  end;
  with CDS_HZ do
  begin
    Edit;
    FieldByName('Qty').Value := FQty;
    FieldByName('Editer').Value := DName;
    FieldByName('Edittime').Value := Now;
    Post;
  end;
  tv2.Controller.EditingController.ShowEdit();
end;

procedure TfrmGaiJiList.v2Column17PropertiesEditValueChanged(Sender: TObject);
var
  FFieldName, mvalue: string;
begin

  mvalue := TcxTextEdit(Sender).EditingText;
  FFieldName := Trim(Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName);

  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('update Worker_WorkDetail set ' + FFieldName + ' =' + quotedstr(mvalue));
    sql.Add(' where DetailId=' + quotedstr(trim(Self.CDS_HZ.FieldByName('DetailId').AsString)));
    EXECSQL;
  end;
  with CDS_HZ do
  begin
    Edit;
    FieldByName(FFieldName).Value := mvalue;
    Post;
  end;
  tv2.Controller.EditingController.ShowEdit();
end;

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

procedure TfrmGaiJiList.v2Column3PropertiesEditValueChanged(Sender: TObject);
var
  FFieldName, mvalue: string;
begin

  mvalue := TcxTextEdit(Sender).EditingText;
  FFieldName := Trim(Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName);

  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('update Worker_WorkDetail set ' + FFieldName + ' =' + mvalue);
    sql.Add(' where DetailId=' + quotedstr(trim(Self.CDS_HZ.FieldByName('DetailId').AsString)));
    EXECSQL;
  end;
  with CDS_HZ do
  begin
    Edit;
    FieldByName(FFieldName).Value := mvalue;
    Post;
  end;
  tv2.Controller.EditingController.ShowEdit();
end;

procedure TfrmGaiJiList.tbDelClick(Sender: TObject);
begin
  if CDS_HZ.Locate('ssel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;
  if Application.MessageBox('确定要处理数据吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
    CDS_HZ.DisableControls;
    with CDS_HZ do
    begin
      First;
      while CDS_HZ.Locate('SSel', True, []) do
      begin
        if CDS_HZ.FieldByName('SSel').AsBoolean = True then
        begin
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add(' UPdate Worker_WorkDetail Set Valid= ''N'' ');
            sql.Add(' where DetailId=''' + Trim(CDS_HZ.fieldbyname('DetailId').AsString) + '''');
            ExecSQL;
          end;
          CDS_HZ.Delete;
        end;
      end;
    end;
    CDS_HZ.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常!', '提示', 0);
  end;
end;

procedure TfrmGaiJiList.tbDelCXClick(Sender: TObject);
begin
  if CDS_HZ.Locate('ssel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;
  if Application.MessageBox('确定要处理数据吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
    CDS_HZ.DisableControls;
    with CDS_HZ do
    begin
      First;
      while CDS_HZ.Locate('SSel', True, []) do
      begin
        if CDS_HZ.FieldByName('SSel').AsBoolean = True then
        begin
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add(' UPdate Worker_WorkDetail Set Valid= ''Y'' ');
            sql.Add(' where DetailId=''' + Trim(CDS_HZ.fieldbyname('DetailId').AsString) + '''');
            ExecSQL;
          end;
          CDS_HZ.Delete;
        end;
      end;
    end;
    CDS_HZ.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常!', '提示', 0);
  end;
end;

end.

