⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unitbasic1.~pas

📁 远程抄表系统的客户端程序 安徽六安项目-客户端程序 0 开发环境 Delphi 7.0 所需控件 mxOutlookBar 数 据 库 Sybase 11.5 1 04-12-
💻 ~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
    close();
  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 + '删除数据操作将不可恢复,确认删除该线路么?';

    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.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -