📄 unitlinelost0.pas
字号:
unit UnitLineLost0;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, ExtCtrls, Menus, Buttons, StdCtrls;
type
TFormLineLost0 = class(TForm)
PanelStep1: TPanel;
ListViewLine: TListView;
PanelTitle1: TPanel;
PopupMenu1: TPopupMenu;
MenuSelAllLine: TMenuItem;
MenuCancelSelLine: TMenuItem;
BLANK: TMenuItem;
MenuInputLineLost: TMenuItem;
PopupMenu2: TPopupMenu;
MenuMLostAdd: TMenuItem;
MenuMLost_Del: TMenuItem;
PanelStep2: TPanel;
PanelTitle2: TPanel;
PanelDateTime1: TPanel;
PanelDateTime2: TPanel;
PanelStep3: TPanel;
PanelTitle3: TPanel;
BtnDNCnt: TSpeedButton;
DateTimePickerDate1: TDateTimePicker;
DateTimePickerTime1: TDateTimePicker;
DateTimePickerTime2: TDateTimePicker;
DateTimePickerDate2: TDateTimePicker;
PanelInput: TPanel;
ListViewMLost: TListView;
Panel: TPanel;
DateTimePickerVal: TDateTimePicker;
Panel1: TPanel;
Panel2: TPanel;
EditVal: TEdit;
ProgressBar: TProgressBar;
procedure CheckEditPressIsFloat(Sender: TObject; var Key: Char);
procedure FormCreate(Sender: TObject);
procedure BtnDNCntClick(Sender: TObject);
procedure MenuSelAllLineClick(Sender: TObject);
procedure MenuCancelSelLineClick(Sender: TObject);
procedure MenuInputLineLostClick(Sender: TObject);
procedure MenuMLostAddClick(Sender: TObject);
procedure MenuMLostModiClick(Sender: TObject);
procedure MenuMLost_DelClick(Sender: TObject);
procedure ListViewMLostClick(Sender: TObject);
private
{ Private declarations }
nLineID : integer;
public
{ Public declarations }
end;
var
FormLineLost0: TFormLineLost0;
implementation
uses UnitMain, UnitBasic2, UnitMyModule, UnitLineLost1;
{$R *.dfm}
procedure TFormLineLost0.FormCreate(Sender: TObject);
begin
nLineID := -1;
DateTimePickerDate1.Format := '日期:yyyy年MM月dd日';
DateTimePickerDate2.Format := '日期:yyyy年MM月dd日';
DateTimePickerTime1.Format := '时间:HH时mm分';
DateTimePickerTime2.Format := '时间:HH时mm分';
DateTimePickerVal.Format := 'yyyy年MM月dd日';
DateTimePickerDate1.DateTime := Now - 30;
DateTimePickerDate2.DateTime := Now;
DateTimePickerVal.Date := Now;
DateTimePickerDate1.MaxDate := Now;
DateTimePickerDate2.MaxDate := Now;
DateTimePickerDate1.MinDate := strToDate('2000-01-01');
DateTimePickerDate2.MinDate := strToDate('2000-01-01');
DateTimePickerVal.MaxDate := Now;
DateTimePickerVal.MinDate := strToDate('2000-01-01');
ListViewLine.Columns.Add();
ListViewLine.Columns.Items[0].Caption := '线路编号';
ListViewLine.Columns.Items[0].Width := 120;
ListViewLine.Columns.Add();
ListViewLine.Columns.Items[1].Caption := '线路名称';
ListViewLine.Columns.Items[1].Width := (FormMain.Width - FormMain.mxOutlookBarPro1.Width - 155) div 4;
ListViewMLost.Columns.Add();
ListViewLine.Columns.Items[0].Caption := '线路编号';
ListViewLine.Columns.Items[0].Width := 120;
ListViewMLost.Columns.Add();
ListViewMLost.Columns.Items[1].Caption := '日期';
ListViewMLost.Columns.Items[1].Width := 120;
ListViewMLost.Columns.Add();
ListViewMLost.Columns.Items[2].Caption := '电量';
ListViewMLost.Columns.Items[2].Width := (FormMain.Width - FormMain.mxOutlookBarPro1.Width - 155) div 4;
ProgressBar.Visible := False;
end;
procedure TFormLineLost0.BtnDNCntClick(Sender: TObject);
var
i : integer;
j : integer;
Year, Month, Day : word;
iProgress : integer;
strTime1 : string;
strTime2 : string;
strTime11 : string;
strTime22 : string;
strTime : string;
strSQL : string;
begin
ProgressBar.Visible := True;
iProgress := 1;
strTime1 := DateToStr(DateTimePickerDate1.Date) + ' ' + TimeToStr(DateTimePickerTime1.Time);
strTime2 := DateToStr(DateTimePickerDate2.Date) + ' ' + TimeToStr(DateTimePickerTime2.Time);
strTime11 := DateToStr(DateTimePickerDate1.Date) + ' 23:59:00';
strTime22 := DateToStr(DateTimePickerDate2.Date) + ' 23:59:00';
DecodeDate(DateTimePickerDate2.Date, Year, Month, Day);
strTime := Format('%d-%d-%d 0:0:0', [Year, Month, Day]);
for i:=0 to ListViewLine.Items.Count-1 do
begin
for j:=0 to FormBasic2.ListView.items.Count-1 do
begin
if FormBasic2.ListView.Items[j].SubItems.Strings[1] = ListViewLine.Items[i].SubItems.Strings[0] then
begin
Inc(iProgress);
end;
end;
end;
ProgressBar.Max := iProgress;
ProgressBar.Step := 1;
for i:=0 to ListViewLine.Items.Count-1 do
begin
if listViewLine.Items[i].Checked = True then
begin
for j:=0 to FormBasic2.ListView.items.Count-1 do
begin
if FormBasic2.ListView.Items[j].SubItems.Strings[1] = ListViewLine.Items[i].SubItems.Strings[0] then
begin
with MyModule.AdoQuery do
begin//with
Close;
SQL.Clear();
strSQL := Format('exec tx_DN_Cnt_Add %d,%d,%d,%d,''%s'',''%s'',''%s'',''%s'',''%s''',
[strToInt(ListViewLine.Items[i].Caption),
StrToInt(FormBasic2.ListView.Items[j].Caption),
StrToInt(FormBasic2.ListView.Items[j].SubItems.Strings[17]),
StrToInt(FormBasic2.ListView.Items[j].SubItems.Strings[18]),
strTime,
strTime1,
strTime2,
strTime11,
strTime22]);
SQL.Add(strSQL);
try
ExecSQL();
Finally
end; //finally
end; //with
ProgressBar.StepIt();
end; //if
end; // for j
end; //Checked
///////////////////////////////////////////////
with MyModule.AdoQuery do
begin//with
Close;
SQL.Clear();
strSQL := Format('exec tx_LineLost_Rep_Add %d,''%s''',
[strToInt(ListViewLine.Items[i].Caption),
strTime]);
SQL.Add(strSQL);
try
ExecSQL();
Finally
end; //finally
end; //with
end; //for i
ProgressBar.StepBy(iProgress);
FormLineLost1.Parent := FormMain.Panel;
FormLineLost1.Width := FormMain.Panel.Width;
FormLineLost1.Height := FormMain.Panel.Height;
FormMain.Caption := FormMain.strCaption + ' ─【线损统计】';
strTime := Format('%d-%d-%d', [Year, Month, Day]);
FormLineLost1.DateTimePicker1.Date := DateTimePickerDate2.Date;
FormLineLost1.DateTimePicker2.Date := DateTimePickerDate2.Date;
FormLineLost1.LoadLineLost(strTime, strTime);
FormLineLost1.Show();
FormMain.SetMenuCheck(9);
end;
procedure TFormLineLost0.MenuSelAllLineClick(Sender: TObject);
var
i : integer;
begin
for i:=0 to ListViewLine.items.Count - 1 do
begin
ListViewLine.Items[i].Checked := True;
end;
end;
procedure TFormLineLost0.MenuCancelSelLineClick(Sender: TObject);
var
i : integer;
begin
for i:=0 to ListViewLine.items.Count - 1 do
begin
ListViewLine.Items[i].Checked := False;
end;
end;
procedure TFormLineLost0.MenuInputLineLostClick(Sender: TObject);
var
ListItem : TListItem;
strSQL : string;
year, month, day : word;
begin
if (ListViewLine.Selected <> nil) and
(ListViewLine.Selected.Index < ListViewLine.Items.Count) then
begin
nLineID := StrToInt(ListViewLine.Selected.Caption);
ListViewMLost.Clear();
with MyModule.AdoQuery do
begin//with
Close;
SQL.Clear();
strSQL := Format('select * from tx_DN_Line where fd_LineID=%d',
[nLineID]);
SQL.Add(strSQL);
try
Open();
except
ExecSQL();
end;
if RecordCount <> 0 then
begin
First();
//Last();
while not eof do
begin
ListItem := ListViewMLost.Items.Add();
//fd_LineID
ListItem.Caption := Trim(FieldByName('fd_LineID').AsString) ;
//fd_Time
DecodeDate(StrToDate(FieldByName('fd_Time').AsString), Year, Month, Day);
ListItem.SubItems.Add(Format('%04d-%02d-%02d', [Year, Month, Day]) );
//fd_Dn_Line
ListItem.SubItems.Add(Trim(FieldByName('fd_Dn_Line').AsString) );
//长时间操作的过程中.加上本函数可以保证系统对其他消息的响应
Application.ProcessMessages();
Next();
end; //end while
end; //end if
end; //end with
end;
end;
procedure TFormLineLost0.MenuMLostAddClick(Sender: TObject);
var
ListItem : TListItem;
strSQL : string;
Year, Month, Day : word;
begin
DecodeDate(DateTimePickerVal.Date, Year, Month, Day);
if nLineID = -1 then
begin
end
else begin
with MyModule.AdoQuery do
begin//with
Close;
SQL.Clear();
strSQL := Format('INSERT INTO tx_DN_Line(fd_SysTime, fd_LineID, fd_Time, fd_Kwh_Line, fd_Dn_Line)VALUES(getdate(),%d,''%d-%d-%d 0:0:0'',%8.2f,%12.2f)',
[nLineID,
Year,
Month,
Day,
0.0,
StrToFloat(EditVal.Text)
]);
SQL.Add(strSQL);
try
ExecSQL();
ListItem := ListViewMLost.Items.Add();
ListItem.Caption := IntTostr(nLineID);
DecodeDate(DateTimePickerVal.Date, Year, Month, Day);
ListItem.SubItems.Add(Format('%04d-%02d-%02d', [Year, Month, Day]) );
ListItem.SubItems.Add(EditVal.Text);
Finally
end; //finally
end; //with
end;
end;
procedure TFormLineLost0.MenuMLostModiClick(Sender: TObject);
begin
if ListViewMLost.Selected <> nil then
begin
with MyModule.AdoQuery do
begin//with
Close;
SQL.Clear();
SQL.Add(Format('UPDATE tx_DN_Line SET fd_SysTime=getdate(), fd_Dn_Line=%12.2f where fd_LineID=%d and fd_Time=''%s''',
[strToFloat(EditVal.Text),
strToInt(ListViewMLost.Selected.Caption),
Trim(ListViewMLost.Selected.SubItems.Strings[0])+ ' 0:0:0']) );
//ShowMessage(SQL.Text);
try
ExecSQL();
ListViewmLost.Selected.SubItems.Strings[1] := EditVal.Text;
Finally
end; //finally
end; //with
end; //end if <> nil
end;
procedure TFormLineLost0.MenuMLost_DelClick(Sender: TObject);
var
strMsg : string;
begin
if (ListViewMLost.Selected <> nil) and
(ListViewMLost.Selected.Index < ListViewMLost.Items.Count) then
begin
strMsg := '警告:您将要要删除线路编号 = [' + trim(ListViewMLost.Selected.Caption) + ']';
strMsg := strMsg + ', 数据日期 = [' + trim(ListViewMLost.Selected.SubItems.Strings[0]) + ']';
strMsg := strMsg + #13 + #13 + '删除数据操作将不可恢复,确认删除该营业电量么?';
if MessageBox(self.Handle, LPCTSTR(strMsg) , '警告', MB_OKCANCEL or MB_ICONWARNING) = IDOK then
if MessageBox(self.Handle, LPCTSTR('再次' + strMsg) , '再次警告', MB_OKCANCEL or MB_ICONWARNING) = IDOK then
begin
with MyModule.AdoQuery do
begin//with
Close;
SQL.Clear();
SQL.Add(Format('DELETE FROM tx_DN_Line WHERE fd_LineID=%d and fd_Time=''%s''',
[StrToInt(ListViewMLost.Selected.Caption),
trim(ListViewMLost.Selected.SubItems.Strings[0]) + ' 0:0:0']) );
//ShowMessage(SQL.Text);
try
ExecSQL();
ListViewMLost.DeleteSelected();
Finally
end; //finally
end; //with
end; //if isOkIsClick = 1
end //if selected <> nil
end;
procedure TFormLineLost0.ListViewMLostClick(Sender: TObject);
begin
if (ListViewMLost.Selected <> nil) and
(ListViewMLost.Selected.Index < ListViewMLost.Items.Count) then
begin
DateTimePickerVal.Date := StrToDate(ListViewMLost.Selected.SubItems.Strings[0]);
EditVal.Text := ListViewMLost.Selected.SubItems.Strings[1];
end;
end;
procedure TFormLineLost0.CheckEditPressIsFloat(Sender: TObject; var Key: Char);
begin
if (Key in ['0'..'9',#8,'.'] ) then
begin
end
else
Key:=#0;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -