📄 unitbasic0.pas
字号:
unit UnitBasic0;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ImgList, Menus, ComCtrls, ToolWin;
type
TFormBasic0 = class(TForm)
ListView: TListView;
CoolBar: TCoolBar;
ToolBar: TToolBar;
BtnAdd: TToolButton;
BtnModify: TToolButton;
BtnDel: TToolButton;
lBtnSeek: TToolButton;
BtnRefresh: TToolButton;
lBtnExit: TToolButton;
PopupMenu: TPopupMenu;
MenuAdd: TMenuItem;
MenuModify: TMenuItem;
MenuDelete: TMenuItem;
MenuSeek: TMenuItem;
MenuRefresh: TMenuItem;
MenuExit: TMenuItem;
ImageList: TImageList;
procedure BtnAddClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure BtnDelClick(Sender: TObject);
procedure BtnModifyClick(Sender: TObject);
procedure BtnRefreshClick(Sender: TObject);
procedure lBtnExitClick(Sender: TObject);
private
{ Private declarations }
Function GetMaxBianDianZID() : Integer;
public
{ Public declarations }
end;
var
FormBasic0: TFormBasic0;
implementation
uses UnitBianDianZ, UnitMain, UnitMyModule, UnitLine;
{$R *.dfm}
Function TFormBasic0.GetMaxBianDianZID() : Integer;
var
MaxLineID : Integer;
begin
MaxLineID := 1;
with MyModule.AdoQuery do
begin//with
//得到 fd_Index 最大序号
Close();
SQL.Clear();
SQL.Add('select isnull(max(fd_BianDianZID),0)+1 from tx_BianDianZ');
//ShowMessage(SQL.Text);
try
Open();
except
ExecSQL();
end;
if RecordCount <> 0 then
begin
MaxLineID := Fields[0].AsInteger;;
end; //end if
end; //with
result := MaxLineID;
end;
procedure TFormBasic0.BtnAddClick(Sender: TObject);
var
ListItem : TListItem;
begin
FormBianDianZ.Caption := '变电站信息-增加';
FormBianDianZ.EditID.Text := IntToStr(GetMaxBianDianZID());
FormBianDianZ.EditName.Text := '';
FormBianDianZ.EditName.SelectAll;
FormBianDianZ.ShowModal();
if FormBianDianZ.iBtnClick = 1 then
begin
with MyModule.AdoQuery do
begin//with
SQL.Clear();
SQL.Add('INSERT INTO tx_BianDianZ(fd_BianDianZID, fd_Name, fd_Memo)VALUES(');
SQL.Add(FormBianDianZ.EditID.Text);
SQL.Add(',''');
SQL.Add(FormBianDianZ.EditName.Text);
SQL.Add(''',''');
SQL.Add(FormBianDianZ.EditMemo.Text);
SQL.Add(''')');
//ShowMessage(SQL.Text);
try
ExecSQL();
ListItem := FormBasic0.ListView.Items.Add();
ListItem.Caption := FormBianDianZ.EditID.Text;
ListItem.SubItems.Add(FormBianDianZ.EditName.Text);
ListItem.SubItems.Add(FormBianDianZ.EditMemo.Text);
Finally
end; //finally
end; //with
end; //if
end;
procedure TFormBasic0.FormCreate(Sender: TObject);
begin
ListView.Columns.Add();
ListView.Columns.Items[0].Caption := '变电站编号';
ListView.Columns.Items[0].Width := 120;
ListView.Columns.Add();
ListView.Columns.Items[1].Caption := '变电站名称';
ListView.Columns.Items[1].Width := (FormMain.Width - FormMain.mxOutlookBarPro1.Width - 155) div 2;
ListView.Columns.Add();
ListView.Columns.Items[2].Caption := '备注信息';
ListView.Columns.Items[2].Width := (FormMain.Width - FormMain.mxOutlookBarPro1.Width -155) div 2;
self.Caption := ' 变电站基本信息';
end;
procedure TFormBasic0.BtnDelClick(Sender: TObject);
var
strMsg : string;
begin
if ListView.Selected <> nil then
begin
strMsg := '警告:您将要要删除变电站编号 = [' + trim(ListView.Selected.Caption) + ']';
strMsg := strMsg + ', 变电站名称 = [' + trim(ListView.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
SQL.Clear();
SQL.Add('DELETE FROM tx_BianDianZ WHERE fd_BianDianZID=');
SQL.Add(ListView.Selected.Caption);
//ShowMessage(SQL.Text);
try
ExecSQL();
FormBasic0.ListView.DeleteSelected();
Finally
end; //finally
end; //with
end; //if iOkIsClick = 1
end //if Selected <> Nil
end;
procedure TFormBasic0.BtnModifyClick(Sender: TObject);
begin
if ListView.Selected <> nil then
begin
FormBianDianZ.Caption := '变电站信息-修改';
FormBianDianZ.EditID.Text := ListView.Selected.Caption;
FormBianDianZ.EditName.Text := ListView.Selected.SubItems.Strings[0];
FormBianDianZ.EditMemo.Text := ListView.Selected.SubItems.Strings[1];
FormBianDianZ.ShowModal();
if FormBianDianZ.iBtnClick = 1 then
begin
with MyModule.AdoQuery do
begin//with
SQL.Clear();
SQL.Add('UPDATE tx_BianDianZ SET fd_BianDianZID=');
SQL.Add(FormBianDianZ.EditID.Text);
SQL.Add(',');
SQL.Add('fd_Name=''');
SQL.Add(FormBianDianZ.EditName.Text);
SQL.Add(''',');
SQL.Add('fd_Memo=''');
SQL.Add(FormBianDianZ.EditMemo.Text);
SQL.Add(''' WHERE fd_BianDianZID=');
SQL.Add(ListView.Selected.Caption);
//ShowMessage(SQL.Text);
try
ExecSQL();
ListView.Selected.Caption := FormBianDianZ.EditID.Text;
ListView.Selected.SubItems.Strings[0] := FormBianDianZ.EditName.Text;
ListView.Selected.SubItems.Strings[1] := FormBianDianZ.EditMemo.Text;
Finally
end; //finally
end; //with
end; //end if <> OK Click
end //end if <> nil
end;
procedure TFormBasic0.BtnRefreshClick(Sender: TObject);
begin
ListView.Clear();
FormMain.LoadTableBianDianZ('SELECT * FROM tx_BianDianZ ORDER BY fd_BianDianZID');
end;
procedure TFormBasic0.lBtnExitClick(Sender: TObject);
begin
Self.Hide();
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -