这是其中的一个单元 也是主要的单元:
unit UnitMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, TeeProcs, TeEngine, Chart, DBChart, ComCtrls, Series,
Buttons, DB, ADODB, StdCtrls, Menus, Registry, TeeTools, TeePageNumTool,
TeeEdiGene, TeePrevi,TeeSurfa, TeeMapSeries, TeeEdit, RzButton;
type
TFrmMain = class(TForm)
StatusBar1: TStatusBar;
DBChart1: TDBChart;
Panel1: TPanel;
GroupBox1: TGroupBox;
Panel2: TPanel;
SpeedButton1: TSpeedButton;
DateTimePicker1: TDateTimePicker;
SpeedButton2: TSpeedButton;
BitBtnRefresh: TBitBtn;
BitBtnClose: TBitBtn;
PopupMenu1: TPopupMenu;
N1: TMenuItem;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
ColorDialog1: TColorDialog;
N2: TMenuItem;
ChartTool1: TPageNumTool;
Timer1: TTimer;
Series1: TFastLineSeries;
Series2: TFastLineSeries;
Series3: TFastLineSeries;
Series4: TFastLineSeries;
RzMenuButtonPrint: TRzMenuButton;
PopupMenu2: TPopupMenu;
N3: TMenuItem;
N4: TMenuItem;
procedure SpeedButton1Click(Sender: TObject);
procedure SpeedButton2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure DateTimePicker1Change(Sender: TObject);
procedure N1Click(Sender: TObject);
//procedure BitBtn1Click(Sender: TObject);
procedure Edit1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Edit2MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Edit3MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Edit4MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormResize(Sender: TObject);
procedure BitBtnCloseClick(Sender: TObject);
procedure N2Click(Sender: TObject);
procedure BitBtnRefreshClick(Sender: TObject);
procedure DBChart1ClickSeries(Sender: TCustomChart;
Series: TChartSeries; ValueIndex: Integer; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure DBChart1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure Timer1Timer(Sender: TObject);
//procedure BitBtn1Click(Sender: TObject);
procedure N4Click(Sender: TObject);
procedure N3Click(Sender: TObject);
procedure Edit1DblClick(Sender: TObject);
procedure Edit2DblClick(Sender: TObject);
procedure Edit3DblClick(Sender: TObject);
procedure Edit4DblClick(Sender: TObject);
private
{ Private declarations }
aState : boolean ;
Edit : array[1..4] of TEdit ;
procedure LinkDataToSeries(ADODataSet : TADODataSet;tmpStr : string ;
Series : TChartSeries;i : integer) ;
procedure LinkDataToSeriesForDTPicker(ADODataSet : TADODataSet;
Series : TChartSeries;tmpSysNum : integer;Date: TDate;j : integer);
//procedure LinkDataToSeriesByClone(Date : TDate) ;
procedure FirstRunSetParameter() ; //如果是第一次运行 设置一些必要的参数
procedure SetEditArray() ;
function GetDTPickerDate(Date : TDate) : string ;
function GetDTPickerYear(Date : TDate) : string ;
function GetDTPickerMonth(Date : TDate) : string ;
function GetDTPickerDay(Date : TDate) : string ;
function FormatIntToStr(i : integer;tlength:integer):string;
function GetCurDataTableNameForDate(str : string) : string ;
procedure ReadFromReg() ;
procedure WriteColorToReg(tmpColor : integer) ;
procedure SetSeriesColor(tmpColor : integer) ;
Function GetIntegerFromStr(str : string) : integer ;
procedure WriteToRegInt(int : integer);
procedure WriteToRegStr(Str : string);
procedure CommProcDisplayChart() ;
procedure DeleteFromReg(SysNum,i : integer) ; //把已经删除的关联从注册表中清除
procedure CommDisplayEditText() ;
public
{ Public declarations }
OldX,OldY:Longint;
Sensor : array[1..4] of string ;
Color : array[1..4] of Integer ;
FenZhan : array[1..4] of string ;
IndicatorSysNum : integer ;
IsMouseMoving : Boolean;
IsDTRun : Boolean ; //为了解决DateTimePicker的单击触发两次的问题 而设置的一个全局开关量
CurDateTime : string ;
OldDateTime : string ;
end;
var
FrmMain: TFrmMain;
implementation
uses DM, UnitCommFunc, UnitList, DateUtils;
{$R *.dfm}
//------------------------------------------------------------------------------
procedure TFrmMain.SpeedButton1Click(Sender: TObject);
begin
CommDisplayEditText ;
DateTimePicker1.Date := DateTimePicker1.Date - 1 ;
CommProcDisplayChart ;
//LinkDataToSeriesByClone(DateTimePicker1.Date) ;
end;
//------------------------------------------------------------------------------
procedure TFrmMain.SpeedButton2Click(Sender: TObject);
begin
CommDisplayEditText ;
DateTimePicker1.Date := DateTimePicker1.Date + 1 ;
CommProcDisplayChart ;
//LinkDataToSeriesByClone(DateTimePicker1.Date) ;
end;
//------------------------------------------------------------------------------
procedure TFrmMain.LinkDataToSeries(ADODataSet : TADODataSet;tmpStr : string ;
Series: TChartSeries;i : integer);
var
sql : string ;
begin
aState := ADODataSet.Active ;
sql := 'select 当前值,时间 from '+tmpStr+' where 系统序号='+inttostr(i) ;
if aState then
ADODataSet.Close ;
ADODataSet.CommandText := sql ;
ADODataSet.Open ;
Series.YValues.ValueSource := '当前值' ;
Series.XLabelsSource := '时间' ;
Series.DataSource := ADODataSet ;
end ;
//------------------------------------------------------------------------------
procedure TFrmMain.FormCreate(Sender: TObject);
var
tmpBool : boolean ;
tmpSysNum : integer ;
i : integer ;
begin
DateTimePicker1.Date := Today ;
SetEditArray ;
IsDisplaySensorPortNum := ReadRegString(SysParameterKey,'IsDisplay_传感器端口号') ;
OldDateTime := DateToStr(Today) ;
IsDTRun := False ;
tmpBool := ReadRegBool(MRootKey,'HaveRegistred');
if not tmpbool then //如果程序是第一次运行 则把一些必要的参数写入注册表中 并且设定CHART的四条曲线的一些属性 如"颜色"等
begin
RegistrySoftware ;
FirstRunSetParameter ;
end else
ReadFromReg;
CommDisplayEditText ;
for i := 1 to 4 do
begin
tmpSysNum := ReadRegInteger(MRootSonKey+inttostr(i),'SensorSysNum');
LinkDataToSeriesForDTPicker(DataModule1.tmpDataSet
,DBChart1.Series[i-1],tmpSysNum,DateTimePicker1.Date,i) ;
end ;
end;
//------------------------------------------------------------------------------
procedure TFrmMain.FormClose(Sender: TObject; var Action: TCloseAction);
begin
;
end;
//------------------------------------------------------------------------------
//为什么这里进入两次??
procedure TFrmMain.DateTimePicker1Change(Sender: TObject);
begin
CurDateTime := DateToStr(DateTimePicker1.Date) ;
if (not IsDTRun) and(OldDateTime <> CurDateTime) then
begin
CommProcDisplayChart ;
IsDTRun := True ;
OldDateTime := DateToStr(DateTimePicker1.Date) ;
end else
begin
IsDTRun := False ;
exit ;
end ;
//LinkDataToSeriesByClone(DateTimePicker1.Date) ;
end;
//------------------------------------------------------------------------------
procedure TFrmMain.LinkDataToSeriesForDTPicker(ADODataSet : TADODataSet;
Series : TChartSeries;tmpSysNum : integer;Date: TDate; j : integer);
var
sql : string ;
tmpDataTableName : string ;
begin
aState := ADODataSet.Active ;
tmpDataTableName := GetCurDataTableNameForDate(GetDTPickerDate(Date)) ;
if DataModule1.IsDataTableExist1(tmpDataTableName) then
begin
if DataModule1.ADOTableData.Active then DataModule1.ADOTableData.Active := False ;
DataModule1.ADOTableData.TableName := tmpDataTableName ;
if not DataModule1.ADOTableData.Active then DataModule1.ADOTableData.Active := True ;
if DataModule1.ADOTableData.Locate('系统序号',tmpSysNum,[loCaseInsensitive, loPartialKey]) then
begin
sql := 'select 当前值,时间 from '+tmpDataTableName+' where 系统序号='+inttostr(tmpSysNum) + ' Order By 时间';
if aState then
ADODataSet.Close ;
ADODataSet.CommandText := sql ;
ADODataSet.Open ;
Series.YValues.ValueSource := '当前值' ;
Series.XLabelsSource := '时间' ;
Series.DataSource := ADODataSet ;
end else
begin
//StatusBar1.Panels[1].Text:= '数据曲线'+inttostr(j)+'关联已被删除!' ;
Edit[j].Text := '数据曲线'+inttostr(j)+'关联已被删除!' ;
DeleteFromReg(tmpSysNum,j) ; //把已经删除的关联从注册表中清除
Series.Clear ;
end ;
end else
begin
StatusBar1.Panels[0].Text:= '"'+ tmpDataTableName + '" 数据表不存在!';
Series.Clear;
end ;
if DataModule1.ADOTableData.Active then DataModule1.ADOTableData.Active := False ;
end ;
//------------------------------------------------------------------------------
function TFrmMain.GetDTPickerDate(Date: TDate): string;
begin
Result := GetDTPickerYear(Date)+GetDTPickerMonth(Date)+GetDTPickerDay(Date) ;
end;
//------------------------------------------------------------------------------
function TFrmMain.FormatIntToStr(i, tlength: integer): string;
var
tmp , endResult : String ;
j : Integer ;
begin
tmp := IntToStr(i) ;
endResult := tmp ;
if Length(tmp)<tlength then
begin
for j:=1 to tLength-(length(tmp)) do
endResult := '0'+endResult ;
end;
Result := endResult ;
end;
//------------------------------------------------------------------------------
function TFrmMain.GetDTPickerDay(Date: TDate): string;
Var
Year , Month , Day : Word ;
begin
DecodeDate(Date,Year,Month,Day);
Result := FormatIntToStr(Day,2) ;
end;
//------------------------------------------------------------------------------
function TFrmMain.GetDTPickerMonth(Date: TDate): string;
Var
Year , Month , Day : Word ;
begin
DecodeDate(Date,Year,Month,Day);
Result := FormatIntToStr(Month,2) ;
end;
//------------------------------------------------------------------------------
function TFrmMain.GetDTPickerYear(Date: TDate): string;
Var
Year , Month , Day : Word ;
begin
DecodeDate(Date,Year,Month,Day);
Result := FormatIntToStr(Year,4) ;
end;
//------------------------------------------------------------------------------
function TFrmMain.GetCurDataTableNameForDate(str: string): string;
var
tmpStr1 : string ;
i : integer ;
begin
for i := 3 to Length(str) do
begin
tmpStr1 := tmpStr1+str ;
end;
Result := '历史数据表'+tmpStr1 ;
end;
//------------------------------------------------------------------------------
procedure TFrmMain.N1Click(Sender: TObject);
begin
try
FrmList := TFrmList.Create(Self);
FrmList.ShowModal ;
IndicatorSysNum := GlobSysIndex ;
WriteToRegInt(IndicatorSysNum);
case Indicator of
1:
begin
Edit1.Text := GlobStr;
DBChart1.Series[0].Title := GlobStr;
end ;
2:
begin
Edit2.Text := GlobStr;
DBChart1.Series[1].Title := GlobStr;
end ;
3:
begin
Edit3.Text := GlobStr;
DBChart1.Series[2].Title := GlobStr;
end ;
4:
begin
Edit4.Text := GlobStr;
DBChart1.Series[3].Title := GlobStr;
end ;
end;
case Indicator of
1:
LinkDataToSeriesForDTPicker(DataModule1.ADODataSet1,DBChart1.Series[0],IndicatorSysNum,DateTimePicker1.Date,1);
2:
LinkDataToSeriesForDTPicker(DataModule1.ADODataSet2,DBChart1.Series[1],IndicatorSysNum,DateTimePicker1.Date,2);
3:
LinkDataToSeriesForDTPicker(DataModule1.ADODataSet3,DBChart1.Series[2],IndicatorSysNum,DateTimePicker1.Date,3);
4:
LinkDataToSeriesForDTPicker(DataModule1.ADODataSet4,DBChart1.Series[3],IndicatorSysNum,DateTimePicker1.Date,4);
end;
finally
FrmList.Free ;
end ;
end;
//------------------------------------------------------------------------------
procedure TFrmMain.WriteToRegInt(int : integer);
begin
case Indicator of
1 :
WriteRegInteger(MRootSonKey+'1','SensorSysNum',int) ;
2 :
WriteRegInteger(MRootSonKey+'2','SensorSysNum',int) ;
3 :
WriteRegInteger(MRootSonKey+'3','SensorSysNum',int) ;
4 :
WriteRegInteger(MRootSonKey+'4','SensorSysNum',int) ;
end;
end;
//------------------------------------------------------------------------------
procedure TFrmMain.WriteToRegStr(Str : string);
begin
case Indicator of
1 :
WriteRegString(MRootSonKey+'1','FenZhan',Str) ;
2 :
WriteRegString(MRootSonKey+'2','FenZhan',Str) ;
3 :
WriteRegString(MRootSonKey+'3','FenZhan',Str) ;
4 :
WriteRegString(MRootSonKey+'4','FenZhan',Str) ;
end;
end;
//------------------------------------------------------------------------------
procedure TFrmMain.SetEditArray;
begin
Edit[1] := Edit1 ;
Edit[2] := Edit2 ;
Edit[3] := Edit3 ;
Edit[4] := Edit4 ;
end;
//------------------------------------------------------------------------------
{procedure TFrmMain.BitBtn1Click(Sender: TObject);
var
tmpDataTableName : string ;
begin
tmpDataTableName := GetCurDataTableNameForDate(GetDTPickerDate(DateTimePicker1.Date)) ;
if DataModule1.IsDataTableExist1(tmpDataTableName) then
begin
//根据用户的选择来确定显示哪一个系统序号
LinkDataToSeriesForDTPicker(DataModule1.ADODataSet1,DBChart1.Series[0],1,DateTimePicker1.Date);
LinkDataToSeriesForDTPicker(DataModule1.ADODataSet2,DBChart1.Series[1],5,DateTimePicker1.Date);
LinkDataToSeriesForDTPicker(DataModule1.ADODataSet3,DBChart1.Series[2],10,DateTimePicker1.Date);
LinkDataToSeriesForDTPicker(DataModule1.ADODataSet4,DBChart1.Series[3],11,DateTimePicker1.Date);
end
else
begin
showmessage('不存在对应于本日期的数据表!') ;
end ;
end;}
//------------------------------------------------------------------------------
procedure TFrmMain.Edit1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if Button=mbRight then
Indicator := 1 ;
end;
//------------------------------------------------------------------------------
procedure TFrmMain.Edit2MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if Button=mbRight then
Indicator := 2 ;
end;
//------------------------------------------------------------------------------
procedure TFrmMain.Edit3MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if Button=mbRight then
Indicator := 3 ;
end;
//------------------------------------------------------------------------------
procedure TFrmMain.Edit4MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if Button=mbRight then
Indicator := 4 ;
end;
//------------------------------------------------------------------------------
procedure TFrmMain.FormResize(Sender: TObject);
var
i,j : integer ;
begin
//调整控件以适应窗体
with GroupBox1 do
begin
Width := FrmMain.Width-14;
Left := 5 ;
i := Width div 4 ;
end ;
for j := 1 to 4 do
begin
Edit[j].Width := i-3 ;
if j<=3 then
Edit[j+1].Left := Edit[j].Left + Edit[j].width ;
end;
BitBtnRefresh.Left := Edit3.Left ;
RzMenuButtonPrint.Left := (FrmMain.Width-BitBtnRefresh.Left)div 3 + BitBtnRefresh.Left ;
BitBtnClose.Left := RzMenuButtonPrint.Left + (FrmMain.Width-BitBtnRefresh.Left)div 3 ;
end;
//------------------------------------------------------------------------------
procedure TFrmMain.ReadFromReg;
var
i : integer ;
tmpRegStr : string ;
begin
for i := 1 to 4 do
begin
tmpRegStr := MRootSonKey+inttostr(i) ;
Color := ReadRegInteger(tmpRegStr,'Color') ;
end ;
for i := 1 to 4 do
begin
//Edit.Text := SenSor ;
Edit.Color := Color ;
DBChart1.Series[i-1].Color := Color ;
//DBChart1.Series[i-1].Title := Edit.Text ;
end;
end;
//------------------------------------------------------------------------------
procedure TFrmMain.BitBtnCloseClick(Sender: TObject);
begin
close() ;
end;
//------------------------------------------------------------------------------
procedure TFrmMain.N2Click(Sender: TObject);
var
tmpColor : integer ;
begin
if ColorDialog1.Execute then
begin
tmpColor := ColorDialog1.Color ;
WriteColorToReg(tmpColor) ;
SetSeriesColor(tmpColor) ;
end ;
end;
//------------------------------------------------------------------------------
procedure TFrmMain.WriteColorToReg(tmpColor: Integer);
begin
case Indicator of
1 :
WriteRegInteger(MRootSonKey+'1','color',tmpColor) ;
2 :
WriteRegInteger(MRootSonKey+'2','color',tmpColor) ;
3 :
WriteRegInteger(MRootSonKey+'3','color',tmpColor) ;
4 :
WriteRegInteger(MRootSonKey+'4','color',tmpColor) ;
end;
end;
//------------------------------------------------------------------------------
procedure TFrmMain.SetSeriesColor(tmpColor: Integer);
begin
case Indicator of
1 :
begin
Edit1.Color := tmpColor ;
DBChart1.Series[0].Color := tmpColor ;
end ;
2 :
begin
Edit2.Color := tmpColor ;
DBChart1.Series[1].Color := tmpColor;
end ;
3 :
begin
Edit3.Color := tmpColor ;
DBChart1.Series[2].Color := tmpColor ;
end ;
4 :
begin
Edit4.Color := tmpColor ;
DBChart1.Series[3].Color := tmpColor ;
end ;
end;
end ;
//------------------------------------------------------------------------------
function TFrmMain.GetIntegerFromStr(str: string): integer;
var
i : integer ;
Len : integer ;
tmpstr : string ;
tmpInt : integer ;
begin
Len := Length(Trim(str)) ;
if Len = 7 then
begin
tmpInt := strtoint(str[1]) ;
end
//if Len = 8 then
else
begin
for i := 1 to 2 do
begin
tmpstr := tmpstr + str ;
end ;
tmpInt := strtoint(tmpstr) ;
end ;
Result := tmpInt ;
end;
//------------------------------------------------------------------------------
procedure TFrmMain.BitBtnRefreshClick(Sender: TObject);
begin
CommDisplayEditText ;
CommProcDisplayChart ;
end;
//------------------------------------------------------------------------------
procedure TFrmMain.DBChart1ClickSeries(Sender: TCustomChart;
Series: TChartSeries; ValueIndex: Integer; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
tmpPoint : TPoint ;
begin
tmpPoint := DBChart1.GetCursorPos ;
//以后可以进一步完善程序
end;
//------------------------------------------------------------------------------
procedure TFrmMain.DBChart1MouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
var
tmpDate, tmpValue : Double ;
tmpIndex : Integer;
i : Integer;
sIndex : Integer;
pCount : Integer;
tmpDoub : string ;
begin
if IsMouseMoving then exit;
IsMouseMoving := True;
sIndex := 0;
pCount := 0;
for i :=0 to 3 do
begin
if DBChart1.Series.Labels.Count > pCount then
begin
pCount := DBChart1.Series.Labels.Count;
sIndex := i;
end;
end;
DBChart1.Series[sIndex].GetCursorValues(tmpDate,tmpValue);
tmpIndex := Round(tmpDate);
IsMouseMoving := False;
if pCount=0 then exit;
if (tmpIndex < 0) then tmpIndex:=0;
if (tmpIndex >= pCount) then tmpIndex:=pCount-1;
tmpDoub := FormatFloat('0.###0',tmpValue) ;
StatusBar1.Panels[1].Text:= '时间: '+ DBChart1.Series[sIndex].XLabel[tmpIndex]
+' 数值:' + tmpDoub ;
end ;
{ This procedure draws the crosshair lines }
{ Procedure DrawCross(AX,AY:Integer);
begin
With DBChart1,Canvas do
begin
//Pen.Color:=CrossHairColor;
//Pen.Style:=CrossHairStyle;
Pen.Mode:=pmXor;
Pen.Width:=1;
MoveTo(ax,ChartRect.Top-Height3D);
LineTo(ax,ChartRect.Bottom-Height3D);
MoveTo(ChartRect.Left+Width3D,ay);
LineTo(ChartRect.Right+Width3D,ay);
end;
end;
Var tmpX,tmpYouble;
begin
if (OldX<>-1) then
begin
DrawCross(OldX,OldY); { draw old crosshair }
// OldX:=-1;
// end;}
{ check if mouse is inside Chart rectangle }
{ if PtInRect( DBChart1.ChartRect, Point(X-DBChart1.Width3D,Y+DBChart1.Height3D) ) then
begin
DrawCross(x,y); { draw crosshair at current position }
{ store old position }
// OldX:=x;
// OldY:=y;
{ set label text }
{With DBChart1.Series[0] do
begin
GetCursorValues(tmpX,tmpY); { <-- get values under mouse cursor }
{ Label1.Caption:=GetVertAxis.LabelValue(tmpY)+
' '+
GetHorizAxis.LabelValue(tmpX);}
//------------------------------------------------------------------------------
procedure TFrmMain.Timer1Timer(Sender: TObject);
begin
StatusBar1.Panels[2].Text := DateTimeToStr(now) ;
end;
{procedure TFrmMain.BitBtn1Click(Sender: TObject);
begin
chartpreview(self,DBChart1) ;
end; }
//------------------------------------------------------------------------------
procedure TFrmMain.N4Click(Sender: TObject);
begin
chartpreview(self,DBChart1) ;
end;
//------------------------------------------------------------------------------
procedure TFrmMain.N3Click(Sender: TObject);
begin
DBChart1.Print ;
end;
//------------------------------------------------------------------------------
procedure TFrmMain.Edit1DblClick(Sender: TObject);
begin
Indicator := 1 ;
N1Click(Sender);
end;
//------------------------------------------------------------------------------
procedure TFrmMain.Edit2DblClick(Sender: TObject);
begin
Indicator := 2 ;
N1Click(Sender);
end;
//------------------------------------------------------------------------------
procedure TFrmMain.Edit3DblClick(Sender: TObject);
begin
Indicator := 3 ;
N1Click(Sender);
end;
//------------------------------------------------------------------------------
procedure TFrmMain.Edit4DblClick(Sender: TObject);
begin
Indicator := 4 ;
N1Click(Sender);
end;
//------------------------------------------------------------------------------
{procedure TFrmMain.LinkDataToSeriesByClone(Date: TDate);
var
sql : string ;
tmpDataTableName : string ;
tmpSysNum : array[1..4] of integer ;
i : integer ;
begin
tmpDataTableName := GetCurDataTableNameForDate(GetDTPickerDate(Date)) ;
if DataModule1.IsDataTableExist1(tmpDataTableName) then
begin
for i := 1 to 4 do
begin
tmpSysNum := ReadRegInteger(MRootSonKey+inttostr(i),'SensorSysNum');
end;
sql := 'select 当前值,时间 from '+tmpDataTableName+' where (系统序号='+inttostr(tmpSysNum[1])+
') or (系统序号='+inttostr(tmpSysNum[2])+') or (系统序号='+inttostr(tmpSysNum[3])+') or (系统序号='
+inttostr(tmpSysNum[4]) + ') Order By 时间';
if DataModule1.ADODataSet0.Active then
DataModule1.ADODataSet0.Active := False ;
DataModule1.ADODataSet0.CommandText := sql ;
DataModule1.ADODataSet0.Open ;
for i := 1 to 4 do
begin
DataModule1.tmpDataSet.Clone(DataModule1.ADODataSet0);
DataModule1.tmpDataSet.Filtered := False ;
DataModule1.tmpDataSet.Filter := '系统序号'+inttostr(tmpSysNum) ;
DataModule1.tmpDataSet.Open ;
DBChart1.Series[i-1].YValues.ValueSource := '当前值' ;
DBChart1.Series[i-1].XLabelsSource := '时间' ;
DBChart1.Series[i-1].DataSource := DataModule1.tmpDataSet ;
end ;
end else
begin
StatusBar1.Panels[0].Text:= '"'+ tmpDataTableName + '" 数据表不存在!';
for i := 0 to 3 do
begin
DBChart1.Series.Clear ;
end;
end ;
end ; }
//------------------------------------------------------------------------------
procedure TFrmMain.CommProcDisplayChart;
var
i : integer ;
tmpSysNum : integer ;
begin
for i := 1 to 4 do
begin
tmpSysNum := ReadRegInteger(MRootSonKey+inttostr(i),'SensorSysNum');
LinkDataToSeriesForDTPicker(DataModule1.tmpDataSet,DBChart1.Series[i-1],tmpSysNum,DateTimePicker1.Date,i) ;
Sleep(i*5);
end ;
end;
//------------------------------------------------------------------------------
procedure TFrmMain.FirstRunSetParameter;
begin
Edit1.Color := $00FFFFFF ;
Edit2.Color := $00FF0000 ;
Edit3.Color := $0000FF00 ;
Edit4.Color := $000000FF ;
DBChart1.Series[0].Color := $00FFFFFF ;
DBChart1.Series[1].Color := $00FF0000 ;
DBChart1.Series[2].Color := $0000FF00 ;
DBChart1.Series[3].Color := $000000FF ;
WriteRegInteger(MRootSonKey+'1','color',$00FFFFFF) ;
WriteRegInteger(MRootSonKey+'2','color',$00FF0000) ;
WriteRegInteger(MRootSonKey+'3','color',$0000FF00) ;
WriteRegInteger(MRootSonKey+'4','color',$000000FF) ;
end;
//------------------------------------------------------------------------------
procedure TFrmMain.DeleteFromReg(SysNum,i : integer) ;
var
Reg : TRegistry ;
tmpKeyStr : string ;
begin
try
Reg := TRegistry.Create ;
Reg.RootKey := HKEY_LOCAL_MACHINE ;
tmpKeyStr := MRootSonKey+inttostr(i) ;
if Reg.OpenKey(tmpKeyStr,true) then
begin
Reg.WriteInteger('SensorSysNum',0);
//Reg.WriteInteger('Color',$00FFFFFF); //默认的颜色不需要改动
end ;
finally
Reg.Free ;
end ;
end;
//------------------------------------------------------------------------------
procedure TFrmMain.CommDisplayEditText;
var
tmpRegStr : string ;
tmpSysNum : integer ;
i : integer ;
tmpSensorName : string ;
tmpFenZhanAddress : integer ;
tmpPortNum : integer ;
begin
for i := 1 to 4 do
begin
tmpRegStr := MRootSonKey+inttostr(i) ;
tmpSysNum := ReadRegInteger(tmpRegStr,'SensorSysNum') ;
if not DataModule1.ADOTablePortPara.Active then
DataModule1.ADOTablePortPara.Active := True ;
if DataModule1.ADOTablePortPara.Locate('系统序号',tmpSysNum,[loCaseInsensitive, loPartialKey]) then
begin
tmpSensorName := DataModule1.ADOTablePortPara.FieldByName('传感器名称').AsString ;
tmpFenZhanAddress := DataModule1.ADOTablePortPara.FieldByName('分站地址').AsInteger ;
tmpPortNum := DataModule1.ADOTablePortPara.FieldByName('端口序号').AsInteger ;
if IsDisplaySensorPortNum = '1' then
begin
Edit.Text := IntToStr(tmpFenZhanAddress)+IntToStr(tmpPortNum)+tmpSensorName ;
end else
begin
Edit.Text := tmpSensorName ;
end ;
end else
begin
//StatusBar1.Panels[1].Text:= '数据曲线'+inttostr(i)+'关联已被删除!' ;
Edit.Text := '数据曲线'+inttostr(i)+'关联已被删除!' ;
DeleteFromReg(tmpSysNum,i) ; //把已经删除的关联从注册表中清除
DBChart1.Series[i-1].Clear ;
end ;
end;
end;
end.
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------