unit JHSJWG;
interface
uses
Business.System, Business.Model, Business.Forms, Business.Data;
type
TJHSJWG = class(TFormDoc)
InfoBroker: TInfoBroker;
DataGrid: TDataGrid;
dpt: TMonthCalendar;
procedure DataGridMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure dptExit(Sender: TObject);
procedure dptChange(Sender: TObject);
procedure DataGridChangeLeftCoord(Sender: TObject);
procedure DataGridChangeTopVisibleNode(Sender: TObject);
private
{private declarations}
procedure SetDptDate();
procedure SetCalendarPos();
public
{public declarations}
DateRect:TRect;
blnVisible:boolean;
end;
implementation
{**************************************
procedure: DataGridMouseDown
Describe: 鼠标按下事件 判断焦点所在字段 设置相关字段的区域位置
Author: Panyc
Date: 2008-06-27
**************************************/}
procedure TJHSJWG.DataGridMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
posx,posy,i:integer;
FocusedField:string;
begin
posx:=10;
posy:=0;
FocusedField:=DataGrid.FocusedField.FieldName ;
if (FocusedField<>'MoldID') and (FocusedField<>'BZT') then
begin
if (FocusedField.Length>3) and (FocusedField.Substring(FocusedField.Length-3,3)='ZZD') then
begin
dpt.Visible:=false;
end
else
begin
dpt.Visible:=true;
blnVisible:= dpt.Visible;
SetCalendarPos();
SetDptDate();
end;
end
else
dpt.Visible:=false;
end;
{**************************************
procedure: SetDptDate
Describe: 设置日期控件显示的时间 当前字段有时间 显示时间 没有时间 显示当天
Author: Panyc
Date: 2008-06-27
**************************************/}
procedure TJHSJWG.SetDptDate();
var
FieldName:string;
FieldValue:string;
begin
try
FieldName:=DataGrid.FocusedField.FieldName;
FieldValue:=DataGrid.DataSource.DataSet.FieldByName(FieldName).AsString;
if (FieldValue='-') or (FieldValue='') then
dpt.Date:=Business.System.SysUtils.Date
else
dpt.Date:=SysUtils.StrToDate(FieldValue);
Except
dialogs.ShowMessage('日期数据不合法!');
end;
end;
{**************************************
procedure: SetCalendarPos
Describe: 设置日期控件位置
Author: DeyuLiu
Date: 2008-06-27
**************************************/}
procedure TJHSJWG.SetCalendarPos();
var
posx,posy,i:integer;
begin
posx:=13;
posy:=0;
if DataGrid.Focused and blnVisible then
begin
for i:=0 to DataGrid.FocusedField.FieldNo-2 do
begin
if DataGrid.Columns.Visible=true then
posx:=posx+DataGrid.Columns.width;
end;
posx:=posx-DataGrid.LeftCoord;
if (DataGrid.FocusedNode<>nil) and (DataGrid.TopVisibleNode<>nil) then
posy:= (DataGrid.FocusedNode.Index+1-DataGrid.TopVisibleNode.Index)*DataGrid.RowHeight+DataGrid.HeaderHeight;
if posy>(DataGrid.Height div 2) then
posy:=posy-DataGrid.RowHeight-dpt.Height;
if posx>(DataGrid.Width div 2) then
posx:=posx+DataGrid.Columns[DataGrid.FocusedField.FieldNo].Width-dpt.Width;
dpt.Visible:=true;
if (posx<0) or (posx+dpt.Width>DataGrid.Width) then
dpt.Visible:=false;
dpt.SetBounds(posx,posy,0,0);
end;
end;
procedure TJHSJWG.dptExit(Sender: TObject);
begin
dpt.Visible:=false;
end;
{**************************************
procedure: dptChange
Describe: 将客户选择的日期填充到数据集中
Author: Panyc
Date: 2008-06-27
**************************************/}
procedure TJHSJWG.dptChange(Sender: TObject);
var
FieldName:string;
FieldValue ouble;
begin
dpt.Visible:=false;
FieldName:=DataGrid.FocusedField.FieldName;
FieldValue:=dpt.Date;
DataGrid.DataSource.DataSet.Open;
DataGrid.DataSource.DataSet.Edit;
DataGrid.DataSource.DataSet.FieldByName(FieldName).AsDateTime:=FieldValue;
end;
procedure TJHSJWG.DataGridChangeLeftCoord(Sender: TObject);
begin
SetCalendarPos();
end;
procedure TJHSJWG.DataGridChangeTopVisibleNode(Sender: TObject);
begin
SetCalendarPos();
end;
end.
这是这个功能信息层的代码 在功能窗体销毁的时候 跟踪代码 会进入信息层 是不是因为这个原因才会出错 信息层主要是在点DataGrid的时候在单元格旁弹出一个日期控件 |