码迷,mamicode.com
首页 > 其他好文 > 详细

unigui使用之---系统登录窗口使用

时间:2018-04-24 00:24:22      阅读:1227      评论:0      收藏:0      [点我收藏+]

标签:新建   sys   sse   controls   use   session   win   RoCE   for   

https://blog.csdn.net/nmbslk/article/details/79335374

一,新建unigui项目,一切选默认

   技术分享图片

 

技术分享图片

 

二,数据库方面准备,这里我们使用unidac连接oracle数据库,并在数据里面准备一个用户表

      create table user_t (username varchar2(20),password varchar2(20),cdate date default sysdate);

       insert into user_t(username,password) values(‘u1‘,‘p1‘);

       insert into user_t(username,password) values(‘u2‘,‘p2‘);

       insert into user_t(username,password) values(‘u3‘,‘p3‘);

三,在mainmodule进行数据库连接的设定,如下图

技术分享图片

四,新建unigui窗体,如下图

  技术分享图片

注意下面的选项,确认为登录窗口选项

技术分享图片

然后在窗口上面放以下的控件,完成后如下图

技术分享图片

登录窗口中的代码如下:

 

unit loginform_pas;


interface


uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics,
  Controls, Forms, uniGUITypes, uniGUIAbstractClasses,
  uniGUIClasses, uniGUIRegClasses, uniGUIForm, uniButton, uniLabel,
  uniGUIBaseClasses, uniEdit;


type
  TLoginForm = class(TUniLoginForm)
    UniEdit1: TUniEdit;
    UniLabel1: TUniLabel;
    UniLabel2: TUniLabel;
    UniEdit2: TUniEdit;
    UniButton1: TUniButton;
    UniButton2: TUniButton;
    procedure UniButton1Click(Sender: TObject);
    procedure UniButton2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;


function LoginForm: TLoginForm;


implementation


{$R *.dfm}


uses
  uniGUIVars, MainModule, uniGUIApplication;


function LoginForm: TLoginForm;
begin
  Result := TLoginForm(UniMainModule.GetFormInstance(TLoginForm));
end;


procedure TLoginForm.UniButton1Click(Sender: TObject);
begin
 if not UniMainModule.linkoracle.Connected  then
   UniMainModule.linkoracle.Connected:=true;
 with UniMainModule.login_u do
 begin
   close;
   sql.Clear;
   sql.Add(‘select count(*) as count from user_t where username=:na and password=:pa‘);
   ParamByName(‘na‘).Value := uniedit1.Text ;
   ParamByName(‘pa‘).Value := uniedit2.Text ;
   open;
   if fieldvalues[‘count‘]>0 then
   begin
     UniMainModule.user_name:=uniedit1.Text;
     self.ModalResult:=mrok;
   end
   else
   begin
     unisession.AddJS(‘alert("用户名或密码错误!");‘);
   end;
 end;
end;


procedure TLoginForm.UniButton2Click(Sender: TObject);
begin
  self.ModalResult:=mrcancel;
end;


initialization
  RegisterAppFormClass(TLoginForm);


end.

 

 

 

在MainModule单元中加入

技术分享图片

 

 

main窗口的show事件中加入以下代码 

  self.Caption :=‘当前登录用户为:‘+UniMainModule.user_name;

 

一切OK了,让我们开始运行代码,效果如下

技术分享图片

技术分享图片

技术分享图片

ok,超级简单的完成了登录过程,并且将当前登录用户传递到了主程序窗口。

unigui使用之---系统登录窗口使用

标签:新建   sys   sse   controls   use   session   win   RoCE   for   

原文地址:https://www.cnblogs.com/westsoft/p/8922456.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!