在以下事件中寫代碼procedure TWKO_PLAN_DAY_F.cxGrid2DBBandedTableView1CellClick( Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean); begin inherited; // end;
1.問題一,改掉其中的ado連接即可;procedure TWKO_PLAN_DAY_F.cxGrid2DBBandedTableView1CellClick( Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean); var NowD:TDateTime; begin inherited; if not HaveRight(FModuleID,_UserNo,rBack) then begin qry_oop.Close; qry_oop.SQL.Text:='select getdate() as NowD'; qry_oop.Open; NowD:=qry_oop.fieldbyname('NowD').AsDateTime; case DayOfWeek(NowD) of 1,2: begin if ((DayOfWeek(qry_BB.fieldbyname('RQ').AsDateTime)=6)or(DayOfWeek(qry_BB.fieldbyname('RQ').AsDateTime)=7)or(DayOfWeek(qry_BB.fieldbyname('RQ').AsDateTime)=1)or(DayOfWeek(cxd_idt.Date)=2)) then begin if HaveRight(FModuleID,_UserNo,rModify) then btnSB_Modi.Enabled:=True; if HaveRight(FModuleID,_UserNo,rDelete) then btnSB_Del.Enabled:=True; end else begin btnSB_Modi.Enabled:=False; btnSB_Del.Enabled:=False; end; end; 3,4,5,6,7: begin if (((FormatDateTime('yyyy/mm/dd',IncDay(NowD,-1))=FormatDateTime('yyyy/mm/dd',qry_BB.fieldbyname('RQ').AsDateTime))and HaveRight(FModuleID,_UserNo,rModify))or((FormatDateTime('yyyy/mm/dd',NowD)=FormatDateTime('yyyy/mm/dd',qry_BB.fieldbyname('RQ').AsDateTime)))and HaveRight(FModuleID,_UserNo,rModify)) then begin if HaveRight(FModuleID,_UserNo,rModify) then btnSB_Modi.Enabled:=True; if HaveRight(FModuleID,_UserNo,rDelete) then btnSB_Del.Enabled:=True; end else begin btnSB_Modi.Enabled:=False; btnSB_Del.Enabled:=False; end; end; end; end else begin if HaveRight(FModuleID,_UserNo,rModify) then btnSB_Modi.Enabled:=True; if HaveRight(FModuleID,_UserNo,rDelete) then btnSB_Del.Enabled:=True; end; end;
2.同上procedure TWKO_PLAN_DAY_F.cxGrid2DBBandedTableView1CellClick( Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean); begin inherited; if (FormatDateTime('yyyy/mm/dd',adoq_pmc.fieldbyname('PMC_RQ').AsDateTime)< FormatDateTime('yyyy/mm/dd',Now)) and (not HaveRight(FModuleID,_UserNo,rApprove)) then begin btnSB_Modi.Enabled:=False; btnSB_Del.Enabled:=False; end; if (FormatDateTime('yyyy/mm/dd',adoq_pmc.fieldbyname('PMC_RQ').AsDateTime)>=FormatDateTime('yyyy/mm/dd',Now)) and (not HaveRight(FModuleID,_UserNo,rApprove)) then begin btnSB_Modi.Enabled:=True; btnSB_Del.Enabled:=True; end; if HaveRight(FModuleID,_UserNo,rApprove) then begin btnSB_Modi.Enabled:=True; btnSB_Del.Enabled:=True; end; end; 或者 qry_oop.Close; qry_oop.SQL.Text:='select getdate() as NowD'; qry_oop.Open; Nowday:=qry_oop.fieldbyname('NowD').AsDateTime; case DayOfWeek(Nowday) of 1,2,3,4,5://周日、一、二、三、四 begin Xlapp.WorkBooks[1].WorkSheets[1].cells[2,8]:=FormatDateTime('yyyy/mm/dd',cx_sdt.Date)+'加班'; Xlapp.Range['H2:I2'].MergeCells:=True; Xlapp.WorkBooks[1].WorkSheets[1].cells[2,10]:=FormatDateTime('yyyy/mm/dd',cx_sdt.Date)+'夜班'; Xlapp.Range['J2:M2'].MergeCells:=True; Xlapp.WorkBooks[1].WorkSheets[1].cells[2,14]:=FormatDateTime('yyyy/mm/dd',IncDay(Now))+'白班'; Xlapp.Range['N2:Q2'].MergeCells:=True; end; 7://周六 begin Xlapp.WorkBooks[1].WorkSheets[1].cells[2,8]:=FormatDateTime('yyyy/mm/dd',cx_sdt.Date)+'加班'; Xlapp.Range['H2:I2'].MergeCells:=True; Xlapp.WorkBooks[1].WorkSheets[1].cells[2,10]:=FormatDateTime('yyyy/mm/dd',cx_sdt.Date)+'夜班'; Xlapp.Range['J2:M2'].MergeCells:=True; Xlapp.WorkBooks[1].WorkSheets[1].cells[2,14]:=FormatDateTime('yyyy/mm/dd',IncDay(Now+1))+'白班'; Xlapp.Range['N2:Q2'].MergeCells:=True; end; 6://周五 begin Xlapp.WorkBooks[1].WorkSheets[1].cells[2,8]:=FormatDateTime('yyyy/mm/dd',cx_sdt.Date)+'加班'; Xlapp.Range['H2:I2'].MergeCells:=True; Xlapp.WorkBooks[1].WorkSheets[1].cells[2,10]:=FormatDateTime('yyyy/mm/dd',cx_sdt.Date)+'夜班'; Xlapp.Range['J2:M2'].MergeCells:=True; Xlapp.WorkBooks[1].WorkSheets[1].cells[2,14]:=FormatDateTime('yyyy/mm/dd',IncDay(Now+2))+'白班'; Xlapp.Range['N2:Q2'].MergeCells:=True; end; end;
Sender: TcxCustomGridTableView;
ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
AShift: TShiftState; var AHandled: Boolean);
begin
inherited;
//
end;
Sender: TcxCustomGridTableView;
ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
AShift: TShiftState; var AHandled: Boolean);
var
NowD:TDateTime;
begin
inherited;
if not HaveRight(FModuleID,_UserNo,rBack) then
begin
qry_oop.Close;
qry_oop.SQL.Text:='select getdate() as NowD';
qry_oop.Open;
NowD:=qry_oop.fieldbyname('NowD').AsDateTime;
case DayOfWeek(NowD) of
1,2:
begin
if ((DayOfWeek(qry_BB.fieldbyname('RQ').AsDateTime)=6)or(DayOfWeek(qry_BB.fieldbyname('RQ').AsDateTime)=7)or(DayOfWeek(qry_BB.fieldbyname('RQ').AsDateTime)=1)or(DayOfWeek(cxd_idt.Date)=2)) then
begin
if HaveRight(FModuleID,_UserNo,rModify) then
btnSB_Modi.Enabled:=True;
if HaveRight(FModuleID,_UserNo,rDelete) then
btnSB_Del.Enabled:=True;
end
else
begin
btnSB_Modi.Enabled:=False;
btnSB_Del.Enabled:=False;
end;
end;
3,4,5,6,7:
begin
if (((FormatDateTime('yyyy/mm/dd',IncDay(NowD,-1))=FormatDateTime('yyyy/mm/dd',qry_BB.fieldbyname('RQ').AsDateTime))and HaveRight(FModuleID,_UserNo,rModify))or((FormatDateTime('yyyy/mm/dd',NowD)=FormatDateTime('yyyy/mm/dd',qry_BB.fieldbyname('RQ').AsDateTime)))and HaveRight(FModuleID,_UserNo,rModify)) then
begin
if HaveRight(FModuleID,_UserNo,rModify) then
btnSB_Modi.Enabled:=True;
if HaveRight(FModuleID,_UserNo,rDelete) then
btnSB_Del.Enabled:=True;
end
else
begin
btnSB_Modi.Enabled:=False;
btnSB_Del.Enabled:=False;
end;
end;
end;
end else
begin
if HaveRight(FModuleID,_UserNo,rModify) then
btnSB_Modi.Enabled:=True;
if HaveRight(FModuleID,_UserNo,rDelete) then
btnSB_Del.Enabled:=True;
end;
end;
Sender: TcxCustomGridTableView;
ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
AShift: TShiftState; var AHandled: Boolean);
begin
inherited;
if (FormatDateTime('yyyy/mm/dd',adoq_pmc.fieldbyname('PMC_RQ').AsDateTime)< FormatDateTime('yyyy/mm/dd',Now)) and (not HaveRight(FModuleID,_UserNo,rApprove)) then
begin
btnSB_Modi.Enabled:=False;
btnSB_Del.Enabled:=False;
end;
if (FormatDateTime('yyyy/mm/dd',adoq_pmc.fieldbyname('PMC_RQ').AsDateTime)>=FormatDateTime('yyyy/mm/dd',Now)) and (not HaveRight(FModuleID,_UserNo,rApprove)) then
begin
btnSB_Modi.Enabled:=True;
btnSB_Del.Enabled:=True;
end;
if HaveRight(FModuleID,_UserNo,rApprove) then
begin
btnSB_Modi.Enabled:=True;
btnSB_Del.Enabled:=True;
end;
end;
或者 qry_oop.Close;
qry_oop.SQL.Text:='select getdate() as NowD';
qry_oop.Open;
Nowday:=qry_oop.fieldbyname('NowD').AsDateTime;
case DayOfWeek(Nowday) of
1,2,3,4,5://周日、一、二、三、四
begin
Xlapp.WorkBooks[1].WorkSheets[1].cells[2,8]:=FormatDateTime('yyyy/mm/dd',cx_sdt.Date)+'加班';
Xlapp.Range['H2:I2'].MergeCells:=True;
Xlapp.WorkBooks[1].WorkSheets[1].cells[2,10]:=FormatDateTime('yyyy/mm/dd',cx_sdt.Date)+'夜班';
Xlapp.Range['J2:M2'].MergeCells:=True;
Xlapp.WorkBooks[1].WorkSheets[1].cells[2,14]:=FormatDateTime('yyyy/mm/dd',IncDay(Now))+'白班';
Xlapp.Range['N2:Q2'].MergeCells:=True;
end;
7://周六
begin
Xlapp.WorkBooks[1].WorkSheets[1].cells[2,8]:=FormatDateTime('yyyy/mm/dd',cx_sdt.Date)+'加班';
Xlapp.Range['H2:I2'].MergeCells:=True;
Xlapp.WorkBooks[1].WorkSheets[1].cells[2,10]:=FormatDateTime('yyyy/mm/dd',cx_sdt.Date)+'夜班';
Xlapp.Range['J2:M2'].MergeCells:=True;
Xlapp.WorkBooks[1].WorkSheets[1].cells[2,14]:=FormatDateTime('yyyy/mm/dd',IncDay(Now+1))+'白班';
Xlapp.Range['N2:Q2'].MergeCells:=True;
end;
6://周五
begin
Xlapp.WorkBooks[1].WorkSheets[1].cells[2,8]:=FormatDateTime('yyyy/mm/dd',cx_sdt.Date)+'加班';
Xlapp.Range['H2:I2'].MergeCells:=True;
Xlapp.WorkBooks[1].WorkSheets[1].cells[2,10]:=FormatDateTime('yyyy/mm/dd',cx_sdt.Date)+'夜班';
Xlapp.Range['J2:M2'].MergeCells:=True;
Xlapp.WorkBooks[1].WorkSheets[1].cells[2,14]:=FormatDateTime('yyyy/mm/dd',IncDay(Now+2))+'白班';
Xlapp.Range['N2:Q2'].MergeCells:=True;
end;
end;