📄 unitlinelost1.~pas
字号:
unit UnitLineLost1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, Buttons, ComCtrls, StdCtrls;
type
TFormLineLost1 = class(TForm)
Panel1: TPanel;
PanelTime1: TPanel;
DateTimePicker1: TDateTimePicker;
BtnSQL: TSpeedButton;
ListViewRep: TListView;
ComBoLineID: TComboBox;
PanelTime2: TPanel;
DateTimePicker2: TDateTimePicker;
PanelLine: TPanel;
BtnLine: TSpeedButton;
procedure FormCreate(Sender: TObject);
procedure BtnSQLClick(Sender: TObject);
procedure LoadLineLost(strTime1 : string; strTime2 : string);
procedure ListViewRepClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure BtnLineClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
FormLineLost1: TFormLineLost1;
implementation
uses UnitMain, UnitMyModule, UnitBasic1, UnitLineLost2, UnitLineLost3;
{$R *.dfm}
procedure TFormLineLost1.FormCreate(Sender: TObject);
begin
DateTimePicker1.Format := 'yyyy年MM月dd日';
DateTimePicker1.Date := Now;
DateTimePicker2.Format := 'yyyy年MM月dd日';
DateTimePicker2.Date := Now;
DateTimePicker1.MaxDate := Now;
DateTimePicker2.MaxDate := Now;
DateTimePicker1.MinDate := strToDate('2000-01-01');
DateTimePicker2.MinDate := strToDate('2000-01-01');
ListViewRep.Columns.Add();
ListViewRep.Columns.Items[0].Caption := '线路编号';
ListViewRep.Columns.Items[0].Width := 120;
ListViewRep.Columns.Add();
ListViewRep.Columns.Items[1].Caption := '线路名称';
ListViewRep.Columns.Items[1].Width := (FormMain.Width - FormMain.mxOutlookBarPro1.Width - 155) div 4;
ListViewRep.Columns.Add();
ListViewRep.Columns.Items[2].Caption := '日期';
ListViewRep.Columns.Items[2].Width := (FormMain.Width - FormMain.mxOutlookBarPro1.Width - 155) div 4;
ListViewRep.Columns.Add();
ListViewRep.Columns.Items[3].Caption := '售电值';
ListViewRep.Columns.Items[3].Width := (FormMain.Width - FormMain.mxOutlookBarPro1.Width - 155) div 4;
ListViewRep.Columns.Add();
ListViewRep.Columns.Items[4].Caption := '配电值';
ListViewRep.Columns.Items[4].Width := (FormMain.Width - FormMain.mxOutlookBarPro1.Width - 155) div 4;
ListViewRep.Columns.Add();
ListViewRep.Columns.Items[5].Caption := '损耗值';
ListViewRep.Columns.Items[5].Width := (FormMain.Width - FormMain.mxOutlookBarPro1.Width - 155) div 4;
ListViewRep.Columns.Add();
ListViewRep.Columns.Items[6].Caption := '损耗率(%)';
ListViewRep.Columns.Items[6].Width := (FormMain.Width - FormMain.mxOutlookBarPro1.Width - 155) div 4;
end;
procedure TFormLineLost1.FormShow(Sender: TObject);
var
i : Integer;
begin
ComboLineID.Items.Clear();
ComboLineID.Items.Add(' ');
//向ComboLineID中写入线路信息
For i:=0 to FormBasic1.ListView.Items.Count-1 do
begin
ComboLineID.Items.Add(FormBasic1.ListView.Items[i].SubItems.Strings[0]);
end;
end;
procedure TFormLineLost1.BtnSQLClick(Sender: TObject);
begin
LoadLineLost(DateToStr(DateTimePicker1.Date)+' 0:0:0', DateToStr(DateTimePicker2.Date)+' 0:0:0' );
end;
procedure TFormLineLost1.LoadLineLost(strTime1 : string; strTime2 : string);
var
i : Integer;
ListItem : TListItem;
strSQL : string;
fDnLine : double;
fDn : double;
strLineLost : string;
Year, Month, Day : word;
begin
ListViewRep.Clear;
with MyModule.AdoQuery do
begin//with
Close;
SQL.Clear();
strSQL := Format('select * from tx_LineLost_Rep where fd_Time>=''%s'' and fd_Time<=''%s''',
[strTime1, strTime2]);
//fd_LineID
if Trim(ComBoLineID.Text) <> '' then
begin
//从线路名称取得线路编号
for i:=0 to (FormBasic1.ListView.Items.Count-1) do
begin
if ComBoLineID.Text = FormBasic1.ListView.Items[i].SubItems.Strings[0] then
begin
strSQL := strSQL + ' And fd_LineID =' + FormBasic1.ListView.Items[i].Caption;
break;
end;// end ComboLineID.Text
end; // end for
end; // end if ComboLineID.Text <> 0
SQL.Add(strSQL);
try
Open();
except
ExecSQL();
end;
if RecordCount <> 0 then
begin
First();
//Last();
while not eof do
begin
ListItem := ListViewRep.Items.Add();
//fd_LineID
ListItem.Caption := Trim(FieldByName('fd_LineID').AsString) ;
//fd_Name
for i:=0 to FormBasic1.ListView.Items.Count-1 do
begin
if StrToInt(FormBasic1.ListView.Items[i].Caption) = StrToInt(ListItem.Caption) then
begin
ListItem.SubItems.Add(FormBasic1.ListView.Items[i].SubItems.Strings[0]);
break;
end;
end;
//fd_Time
DecodeDate(StrToDate(FieldByName('fd_Time').AsString), Year, Month, Day);
ListItem.SubItems.Add(Format('%04d-%02d-%02d', [Year, Month, Day]) );
//fd_Dn_Cnt
ListItem.SubItems.Add(Trim(FieldByName('fd_Dn_Cnt').AsString) );
//fd_Dn_Line
ListItem.SubItems.Add(Trim(FieldByName('fd_Dn_Line').AsString) );
fDnLine := FieldByName('fd_Dn_Line').AsFloat;
//fd_Dn
ListItem.SubItems.Add(Trim(FieldByName('fd_Dn').AsString) );
fDn := FieldByName('fd_Dn_Line').AsFloat - FieldByName('fd_Dn_Cnt').AsFloat;
if fDnCnt = 0 then
begin
strLineLost := '0';
end else
begin
strLineLost := Format('%.2f%', [(fDn/fDnLine)*100]);
end;
ListItem.SubItems.Add(strLineLost );
//长时间操作的过程中.加上本函数可以保证系统对其他消息的响应
Application.ProcessMessages();
Next();
end; //end while
end; //end if
end; //end with
end;
procedure TFormLineLost1.ListViewRepClick(Sender: TObject);
begin
//
if (ListViewRep.Selected <> nil) and
(ListViewRep.Selected.Index < ListViewRep.Items.Count) then
begin
FormLineLost2.iLineID := StrToInt(ListViewRep.Selected.Caption);
FormLineLost2.strTime := Trim(ListViewRep.Selected.SubItems.Strings[1]);
FormLineLost2.Parent := FormMain.Panel;
FormLineLost2.Width := FormMain.Panel.Width;
FormLineLost2.Height := FormMain.Panel.Height;
FormLineLost2.LoadDNCnt();
FormLineLost2.Show();
end;
end;
procedure TFormLineLost1.BtnLineClick(Sender: TObject);
var
i : Longint;
Old : Double;
begin
FormLineLost3.Parent := FormMain.Panel;
FormLineLost3.Width := FormMain.Panel.Width;
FormLineLost3.Height := FormMain.Panel.Height;
With FormLineLost3.ChartLine.Series[0] do
begin
XValues.DateTime := False;
Clear;
for i:=0 to self.ListViewRep.Items.Count-1 do
begin
Old := StrToFloat(ListViewRep.Items[i].SubItems[5]);
if Trim(ComBoLineID.Text) = '' then
Add( Old, ListViewRep.Items[i].SubItems.Strings[1] + #13 + ListViewRep.Items[i].SubItems.Strings[0], clRed)
else
Add( Old, ListViewRep.Items[i].SubItems.Strings[1], clRed);
end;
end;
With FormLineLost3.ChartBar.Series[0] do
begin
XValues.DateTime := False;
Clear;
for i:=0 to self.ListViewRep.Items.Count-1 do
begin
Old := StrToFloat(ListViewRep.Items[i].SubItems.Strings[5]);
if Trim(ComBoLineID.Text) = '' then
Add( Old, ListViewRep.Items[i].SubItems.Strings[1] + #13 + ListViewRep.Items[i].SubItems.Strings[0], clRed)
else
Add( Old, ListViewRep.Items[i].SubItems.Strings[1], clRed);
end;
end;
FormLineLost3.Show();
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -