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

📄 u_dlck.pas

📁 《delphi深度编程及其项目开发》
💻 PAS
字号:
unit U_dlck;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, StdCtrls, Buttons, Mask, Db, DBClient, winsock, jpeg, variants, ComCtrls;

type
  TfrmLogin = class(TForm)
    Panel1: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Panel2: TPanel;
    btnOK: TSpeedButton;
    btnCancel: TSpeedButton;
    Image1: TImage;
    edtAliasName: TEdit;
    edtPassword: TEdit;
    procedure btnCancelClick(Sender: TObject);
    procedure edtAliasNameKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure edtPasswordKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure btnOKClick(Sender: TObject);
  private
    vFuncs: variant; //存储用户功能列表
    function FindFuncs(const aFunc: string): boolean; //查找功能项是否存在
    procedure setFuncs; //设置主窗体菜单的有效性
    { Private declarations }
  public
    { Public declarations }
  end;

function LoginExecute(aFormClass: TFormClass): Boolean; //打开登录窗口,并判断是否登录成功
var
  frmLogin: TfrmLogin;
  Logined: Boolean = false;

implementation

uses U_mainform, WzglDB, u_public;
{$R *.DFM}

//打开登录窗口,并判断是否登录成功
function LoginExecute(aFormClass: TFormClass): Boolean;
begin
  with aFormClass.Create(Application) do
  begin
    Logined := False;
    try
      showModal;
    finally
      free;
    end;
    result := Logined;
  end;
end;

procedure TfrmLogin.btnCancelClick(Sender: TObject);
begin
  close;
end;


procedure TfrmLogin.edtAliasNameKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if key = 13 then
    edtPassword.setfocus;
end;

procedure TfrmLogin.edtPasswordKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if key = 13 then
    btnOK.click;
end;

//确定按钮点击过程
procedure TfrmLogin.btnOKClick(Sender: TObject);
var
  vYhbh, vZh: variant;
  i: integer;
  vLogined: variant;
  vAliasName, vPassword: string;
  vLoginTime: variant;
begin
  vAliasName := edtAliasName.text;
  vPassword := edtPassword.Text;
  frmMain.SocketConnection.AppServer.Logined(vAliasName, vPassword, vYhbh, vzh, vLogined);
  if not vLogined then
  begin
    Application.MessageBox('用户名和密码不正确,请重新输入', '提示信息', mb_iconInformation + mb_defbutton1);
    exit;
  end
  else
  begin
    //向全局记录变量CurrentParam赋值
    CurrentParam.userAliasName := edtAliasName.Text;
    CurrentParam.userBH := vYhbh;
    CurrentParam.userZH := vZh;
    CurrentParam.Host := GetComputerName;
    CurrentParam.IP := GetComputerIp;
    frmMain.SocketConnection.AppServer.GetSysTime(vLoginTime);
    CurrentParam.LoginTime := vLoginTime;
  end;
  //设置主窗口菜单的有效性
  SetFuncs;
  //向应用服务器显示连接信息
  frmMain.SocketConnection.AppServer.AddUser(CurrentParam.Host, CurrentParam.IP, CurrentParam.userAliasName, CurrentParam.LoginTime);
  Logined := true;
  Close;
end;

//设置主窗体菜单的有效性
procedure TfrmLogin.setFuncs;
var
  vn_node, vn_node1, vn_node2, vn_node3: TTreenode;
  i, i1, i2: integer;
  vs_caption: string;
begin
  with frmMain do
  begin
    SocketConnection.AppServer.GetFuncs(currentParam.userZH, vFuncs);
    N_A.visible := false;
    N_B.visible := false;
    N_c.Visible := False;
    N_d.visible := False;
    N_E.visible := False;
    if currentParam.userAliasName <> 'system' then
      N_H_2.visible := false;
    vn_node := treeview1.Items.add(treeview1.topitem, '通用物资管理');
    vn_node.ImageIndex := 0;
    vn_node.StateIndex := -1;
    vn_node.SelectedIndex := 1;
    for i := 0 to 4 do
    begin
      vs_caption := mainmenu.items[i].caption;
      vn_node1 := treeview1.items.addchild(vn_node, vs_caption);
      vn_node1.ImageIndex := 0;
      vn_node1.StateIndex := -1;
      vn_node1.SelectedIndex := 1;
      for i1 := 0 to mainmenu.Items[i].count - 1 do
      begin
        vs_caption := mainmenu.items[i].items[i1].caption;
        if not FindFuncs(vs_caption) then
        begin
          mainmenu.items[i].items[i1].visible := false;
          continue;
        end;
        vn_node2 := treeview1.Items.AddChild(vn_node1, vs_caption);
        vn_node2.ImageIndex := 0;
        vn_node2.StateIndex := -1;
        vn_node2.SelectedIndex := 1;
        for i2 := 0 to mainmenu.items[i].items[i1].count - 1 do
        begin
          vs_caption := mainmenu.items[i].items[i1].items[i2].Caption;
          if not FindFuncs(vs_caption) then
          begin
            mainmenu.items[i].items[i1].items[i2].visible := false;
            continue;
          end;
          vn_node3 := treeview1.items.addchild(vn_node2, vs_caption);
          vn_node3.ImageIndex := 0;
          vn_node3.StateIndex := -1;
          vn_node3.SelectedIndex := 1;
        end;
      end;
    end;
  end;
end;

//查找功能项是否存在
function TfrmLogin.FindFuncs(const aFunc: string): boolean;
var
  i: integer;
  bFunc: string;
begin
  Result := False;
  if (varIsArray(vFuncs)) then
  begin
    for i := varArrayLowBound(vfuncs, 1) to varArrayHighBound(vfuncs, 1) do
    begin
      bFunc := vFuncs[i];
      if bFunc = aFunc then
      begin
        result := true;
        exit;
      end;
    end;
  end;
end;


end.

⌨️ 快捷键说明

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