unit U_YGYPZZChkList_CLCXJL;

interface

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

type
  TfrmYGYPZZChkList_CLCXJL = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBClose: TToolButton;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    TBExport: TToolButton;
    Order_Main: TClientDataSet;
    Panel1: TPanel;
    PopupMenu1: TPopupMenu;
    N2: TMenuItem;
    N1: TMenuItem;
    BegDate: TDateTimePicker;
    Label3: TLabel;
    EndDate: TDateTimePicker;
    DataSource2: TDataSource;
    order_Sub: TClientDataSet;
    Label2: TLabel;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    ADOQuery1: TADOQuery;
    Label1: TLabel;
    CLName: TEdit;
    Label4: TLabel;
    CLNO: TEdit;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1SQDate: TcxGridDBColumn;
    v1YGName: TcxGridDBColumn;
    v1CLName: TcxGridDBColumn;
    v1CLNO: TcxGridDBColumn;
    v1CLStatus: TcxGridDBColumn;
    v1SQNote: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    cxStyle2: TcxStyle;
    v1LCQty: TcxGridDBColumn;
    ADOQuery2: TADOQuery;
    TCX: TToolButton;
    v1toPlace: TcxGridDBColumn;
    v1SYMoney: TcxGridDBColumn;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
    procedure CustomerNoNameChange(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure CLNameChange(Sender: TObject);
    procedure TCXClick(Sender: TObject);
  private
    canshu1:string;
    DQdate:TDateTime;
    procedure InitGrid();
    procedure InitForm();
    function  DelData():Boolean;
    procedure setstatus();
    { Private declarations }
  public
    FFInt,FCloth:Integer;
    { Public declarations }
  end;

var
  frmYGYPZZChkList_CLCXJL: TfrmYGYPZZChkList_CLCXJL;

implementation
uses
  U_DataLink,U_RTFun,U_ZDYHelp, U_YGYPInPut,
  U_ZDYHelpSel,U_YGYPInPut_CLSQDJ;

{$R *.dfm}

procedure TfrmYGYPZZChkList_CLCXJL.setstatus();
begin
  {TUpdate.Visible:=False;
  TTiJiao.Visible:=False;
  TCXTJ.Visible:=False;
  Tdel.Visible:=False;
  TGHCL.Visible:=False;
  case cxTabControl1.TabIndex of
    0:begin
        TUpdate.Visible:=True;
        TTiJiao.Visible:=True;
        Tdel.Visible:=true;
      end;
    1:begin
        TCXTJ.Visible:=true;
        TGHCL.Visible:=true;
      end;
    2:begin

      end;
    3:begin
      end;
  end;}
end;

procedure TfrmYGYPZZChkList_CLCXJL.FormDestroy(Sender: TObject);
begin
  frmYGYPZZChkList_CLCXJL:=nil;
end;

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

procedure TfrmYGYPZZChkList_CLCXJL.FormCreate(Sender: TObject);
begin
  canshu1:=Trim(DParameters1);
end;

procedure TfrmYGYPZZChkList_CLCXJL.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('公司车辆列表2',Tv1,'OA管理');
end;

procedure TfrmYGYPZZChkList_CLCXJL.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      close;
      sql.Clear;
      sql.Add('select * from OA_YG_CLGL_Sub ');
      sql.Add(' where filltime>='''+Trim(FormatDateTime('yyyy-MM-dd',BegDate.Date))+'''');
      sql.Add(' and filltime<='''+Trim(FormatDateTime('yyyy-MM-dd',EndDate.Date+1))+'''');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,Order_Main);
    SInitCDSData20(ADOQueryMain,Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmYGYPZZChkList_CLCXJL.InitForm();
begin
  EndDate.Date:=SGetServerDate(ADOQueryTemp);
  BegDate.Date:=EndDate.Date-7;
  ReadCxGrid('公司车辆列表2',Tv1,'OA管理');
  //setstatus();
  InitGrid();
end;

procedure TfrmYGYPZZChkList_CLCXJL.TBFindClick(Sender: TObject);
begin
  SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
  SCreateCDS20(ADOQueryMain,Order_Main);
  SInitCDSData20(ADOQueryMain,Order_Main);
end;

function TfrmYGYPZZChkList_CLCXJL.DelData():Boolean;
begin
  try
    Result:=false;
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('Delete OA_YG_DangAn where YGId='''+Trim(Order_Main.fieldbyname('YGId').AsString)+'''');
      ExecSQL;
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('Delete OA_YG_DangAn_Other  where YGId='''+Trim(Order_Main.fieldbyname('YGId').AsString)+'''');
      ExecSQL;
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('Delete TP_File  where WBId='''+Trim(Order_Main.fieldbyname('YGId').AsString)+'''');
      sql.Add(' and TFType=''YG'' ');
      ExecSQL;
    end;

    ADOQueryCmd.Connection.CommitTrans;
    Result:=True;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Result:=False;
    Application.MessageBox('数据删除异常！','提示',0);
  end;
end;

procedure TfrmYGYPZZChkList_CLCXJL.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then Exit;
  TcxGridToExcel('员工加薪列表',cxGrid1);
end;

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

procedure TfrmYGYPZZChkList_CLCXJL.FormShow(Sender: TObject);
begin
  InitForm();
end;

procedure TfrmYGYPZZChkList_CLCXJL.CheckBox1Click(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmYGYPZZChkList_CLCXJL.CheckBox2Click(Sender: TObject);
begin
  TBRafresh.Click;
end;

procedure TfrmYGYPZZChkList_CLCXJL.CustomerNoNameChange(Sender: TObject);
begin
  SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
  SCreateCDS20(ADOQueryMain,Order_Main);
  SInitCDSData20(ADOQueryMain,Order_Main);
end;

procedure TfrmYGYPZZChkList_CLCXJL.N2Click(Sender: TObject);
begin
  SelOKNo(Order_Main,True);
end;

procedure TfrmYGYPZZChkList_CLCXJL.N1Click(Sender: TObject);
begin
  SelOKNo(Order_Main,False);
end;

procedure TfrmYGYPZZChkList_CLCXJL.CLNameChange(Sender: TObject);
begin
  SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
  SCreateCDS20(ADOQueryMain,Order_Main);
  SInitCDSData20(ADOQueryMain,Order_Main);
end;

procedure TfrmYGYPZZChkList_CLCXJL.TCXClick(Sender: TObject);
begin
  if order_Main.IsEmpty then exit;
  if application.MessageBox('确定要撤销吗','提示',1)=2 then exit;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('Delete OA_YG_CLGL_Sub where CLSubid='''+Trim(Order_Main.fieldbyname('CLSubid').AsString)+'''');
    ExecSQL;
  end;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('update OA_YG_CLGL set MQQty=BYQCQty+(select isnull(Sum(LCQty),0) from OA_YG_CLGL_Sub where CLID=OA_YG_CLGL.CLID and CLStatus<>''保养完成'' ) ');
    sql.Add('where CLID='''+trim(Order_Main.fieldbyname('CLID').asstring)+''' ');
    ExecSQL;
  end;
  order_Main.Delete;
end;

end.
