?? unitbasic1.pas
字號:
unit UnitBasic1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ComCtrls, Grids, ValEdit, ExtCtrls, XPMan,
Menus, ImgList, ToolWin;
type
TFormBasic1 = class(TForm)
ListView: TListView;
PopupMenu: TPopupMenu;
MenuAdd: TMenuItem;
MenuModify: TMenuItem;
MenuDelete: TMenuItem;
MenuSeek: TMenuItem;
MenuRefresh: TMenuItem;
MenuExit: TMenuItem;
ImageList: TImageList;
CoolBar: TCoolBar;
ToolBar: TToolBar;
BtnAdd: TToolButton;
BtnModify: TToolButton;
BtnDel: TToolButton;
BtnSeek: TToolButton;
BtnRefresh: TToolButton;
BtnExit: TToolButton;
procedure BtnAddClick(Sender: TObject);
procedure BtnModifyClick(Sender: TObject);
procedure BtnSeekClick(Sender: TObject);
procedure BtnExitClick(Sender: TObject);
procedure BtnDeleteClick(Sender: TObject);
procedure BtnRefreshClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
FormOldWid: Integer;
Function GetMaxLineID() : Integer;
public
{ Public declarations }
end;
var
FormBasic1: TFormBasic1;
implementation
uses
UnitMyModule, UnitLine, UnitMain, UnitBasic0, UnitBianTai;
{$R *.dfm}
Function TFormBasic1.GetMaxLineID() : Integer;
var
MaxLineID : Integer;
begin
MaxLineID := 1;
with MyModule.AdoQuery do
begin//with
//得到 fd_Index 最大序號
Close();
SQL.Clear();
SQL.Add('select convert(char(6), isnull(max(fd_LineID),0)+1) from tx_Line');
//ShowMessage(SQL.Text);
try
Open();
except
ExecSQL();
end;
if RecordCount <> 0 then
begin
MaxLineID := StrToInt(Trim(Fields[0].AsString));
end; //end if
end; //with
result := MaxLineID;
end;
procedure TFormBasic1.BtnAddClick(Sender: TObject);
var
ListItem : TListItem;
BianDianZID : string;
i : integer;
begin
FormLine.Caption := '線路基本信息-增加';
FormLine.EditID.Text := IntToStr(GetMaxLineID());
FormLine.EditName.Text := '';
FormLine.EditName.SelectAll;
FormLine.ComboBianDianZID.Items.Clear();
//向FormBiantTai.ComboBianDianZID中寫入線路信息
//SetLength(ArrayLine,FormBasic1.ListView.Items.Count);
FormLine.ComboBianDianZID.Text := '0';
For i:=0 to FormBasic0.ListView.Items.Count-1 do
begin
FormLine.ComboBianDianZID.Items.Add(FormBasic0.ListView.Items[i].SubItems.Strings[0]);
FormLine.ComboBianDianZID.Text := FormBasic0.ListView.Items[i].SubItems.Strings[0];
end;
if ListView.Items.Count >= 1 then
begin
FormLine.ComboBianDianZID.Text := ListView.Items[ListView.Items.Count-1].SubItems.Strings[1];
end;
FormLine.ShowModal();
if FormLine.iBtnClick = 1 then
begin
with MyModule.AdoQuery do
begin//with
SQL.Clear();
SQL.Add('INSERT INTO tx_Line(fd_LineID, fd_Name, fd_BianDianZID, fd_Class, fd_Memo)VALUES(');
SQL.Add(FormLine.EditID.Text);
SQL.Add(',''');
SQL.Add(FormLine.EditName.Text);
SQL.Add(''',');
//取得 fd_BianDianZID
BianDianZID := '0';
for i:=0 to ( FormBasic0.ListView.Items.Count - 1 ) do
begin
if FormBasic0.ListView.Items[i].SubItems.Strings[0] = FormLine.ComboBianDianZID.Text then
begin
BianDianZID := FormBasic0.ListView.Items[i].Caption;
break;
end;
end;
SQL.Add(BianDianZID);
SQL.Add(',''');
SQL.Add(FormLine.EditClass.Text);
SQL.Add(''',''');
SQL.Add(FormLine.EditMemo.Text);
SQL.Add(''')');
//ShowMessage(SQL.Text);
try
ExecSQL();
ListItem := FormBasic1.ListView.Items.Add();
ListItem.Caption := FormLine.EditID.Text;
ListItem.SubItems.Add(FormLine.EditName.Text);
ListItem.SubItems.Add(FormLine.ComboBianDianZID.Text);
ListItem.SubItems.Add(FormLine.EditClass.Text);
ListItem.SubItems.Add(FormLine.EditMemo.Text);
Finally
end; //finally
end; //with
end; //if
end;
procedure TFormBasic1.BtnDeleteClick(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 + '刪除數(shù)據(jù)操作將不可恢復(fù),確認(rèn)刪除該線路么?';
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_Line WHERE fd_LineID=');
SQL.Add(ListView.Selected.Caption);
//ShowMessage(SQL.Text);
try
ExecSQL();
FormBasic1.ListView.DeleteSelected();
Finally
end; //finally
end; //with
end; //if iOkIsClick = 1
end //if Selected <> Nil
end;
procedure TFormBasic1.BtnExitClick(Sender: TObject);
begin
Self.Hide();
end;
procedure TFormBasic1.BtnModifyClick(Sender: TObject);
var
i : integer;
BianDianZID : string;
begin
if ListView.Selected <> nil then
begin
FormLine.Caption := '線路基本信息-修改';
FormLine.ComboBianDianZID.Items.Clear();
//向FormLine.ComboBianDianZID中寫入變電站信息
//SetLength(ArrayLine,FormBasic1.ListView.Items.Count);
FormLine.ComboBianDianZID.Text := '0';
For i:=0 to FormBasic0.ListView.Items.Count-1 do
begin
FormLine.ComboBianDianZID.Items.Add(FormBasic0.ListView.Items[i].SubItems.Strings[0]);
end;
FormLine.EditID.Text := ListView.Selected.Caption;
FormLine.EditName.Text := ListView.Selected.SubItems.Strings[0];
FormLine.ComboBianDianZID.Text := ListView.Selected.SubItems.Strings[1];
FormLine.EditClass.Text := ListView.Selected.SubItems.Strings[2];
FormLine.EditMemo.Text := ListView.Selected.SubItems.Strings[3];
FormLine.ShowModal();
if FormLine.iBtnClick = 1 then
begin
with MyModule.AdoQuery do
begin//with
SQL.Clear();
SQL.Add('UPDATE tx_Line SET fd_LineID=');
SQL.Add(FormLine.EditID.Text);
SQL.Add(',');
SQL.Add('fd_Name=''');
SQL.Add(FormLine.EditName.Text);
SQL.Add(''',');
SQL.Add('fd_BianDianZID=');
//取得 fd_BianDianZID
BianDianZID := '0';
for i:=0 to ( FormBasic0.ListView.Items.Count - 1 ) do
begin
if FormBasic0.ListView.Items[i].SubItems.Strings[0] = FormLine.ComboBianDianZID.Text then
begin
BianDianZID := FormBasic0.ListView.Items[i].Caption;
break;
end;
end;
SQL.Add(BianDianZID);
SQL.Add(',');
SQL.Add('fd_Class=''');
SQL.Add(FormLine.EditClass.Text);
SQL.Add(''',');
SQL.Add('fd_Memo=''');
SQL.Add(FormLine.EditMemo.Text);
SQL.Add(''' WHERE fd_LineID=');
SQL.Add(ListView.Selected.Caption);
//ShowMessage(SQL.Text);
try
ExecSQL();
ListView.Selected.Caption := FormLine.EditID.Text;
ListView.Selected.SubItems.Strings[0] := FormLine.EditName.Text;
ListView.Selected.SubItems.Strings[1] := FormLine.ComboBianDianZID.Text;
ListView.Selected.SubItems.Strings[2] := FormLine.EditClass.Text;
ListView.Selected.SubItems.Strings[3] := FormLine.EditMemo.Text;
Finally
end; //finally
end; //with
end; //end if <> OK Click
end //end if <> nil
end;
procedure TFormBasic1.BtnSeekClick(Sender: TObject);
var
bmp: TBitmap;
begin
bmp := TBitmap.Create;
try
bmp.Width := ListView.Width;
bmp.Height := ListView.Height;
bmp.Canvas.Lock;
try
ListView.Perform(WM_PRINT, bmp.Canvas.Handle, PRF_CHILDREN or
PRF_CLIENT or PRF_NONCLIENT);
finally
bmp.Canvas.UnLock;
bmp.SaveToFile('ree.bmp')
end;
finally
bmp.Free
end;
end;
procedure TFormBasic1.BtnRefreshClick(Sender: TObject);
begin
ListView.Clear();
FormMain.LoadTableLine('SELECT * FROM tx_Line ORDER BY fd_LineID');
end;
{
flat ListView Header
平滑效果的 ListView
procedure TFormBasic1.FormShow(Sender: TObject);
const
LVM_GETHEADER = $1000 + 31;
var
hHeader: THandle;
style: dWord;
begin
hHeader := SendMessage(ListView.Handle, LVM_GETHEADER, 0, 0);
//style := GetWindowLong(hHeader, GWL_STYLE);
//style := style xor $2;
style := 1;
SetWindowLong(hHeader, GWL_STYLE, style);
SetWindowPos(ListView.Handle, Self.Handle, 0, 0, 0, 0,SWP_NOZORDER or SWP_NOSIZE or SWP_NOMOVE or SWP_DRAWFRAME);
FormBasic1.Width := FormMain.Panel.Width;
FormBasic1.Height := FormMain.Panel.Height;
FormBasic1.ListView.Width := FormMain.Panel.Width;
end;
}
procedure TFormBasic1.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 4;
ListView.Columns.Add();
ListView.Columns.Items[2].Caption := '變 電 站';
ListView.Columns.Items[2].Width := (FormMain.Width - FormMain.mxOutlookBarPro1.Width - 155) div 4;
ListView.Columns.Add();
ListView.Columns.Items[3].Caption := '電壓等級';
ListView.Columns.Items[3].Width := (FormMain.Width - FormMain.mxOutlookBarPro1.Width - 155) div 4;
ListView.Columns.Add();
ListView.Columns.Items[4].Caption := '備注信息';
ListView.Columns.Items[4].Width := (FormMain.Width - FormMain.mxOutlookBarPro1.Width - 155) div 4;
self.Caption := ' 線路基本信息';
end;
end.
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -