分享

delphi 登陆界面:

 佚名2016 2016-08-25
 

登陆界面:

取消按扭

procedure TLOGIN.SpeedButton2Click(Sender: TObject);

begin

Application.Terminate; //结束终端

end;

 

 

确定按扭:

procedure TLoginForm.SpeedButton1Click(Sender: TObject);

var

   password,username:string; //定义用户名和密码为字符型

begin

   username:=combobox1.Text; // 用户名

   password:=edit1.Text; //密码

   inc(itimes);//验证次数自增

 

   if combobox1.Items.Count > 0 then

   begin

     combobox1.ItemIndex:=0;//所选项目的索引号赋初值

     with datamd.ADOManage do//引用数据模块

     begin

       // 当用户名与密码正确并且输入次数少于三次时就登录成功

        if locate('用户名',username,[lopartialkey]) and locate('密码',password,[lopartialkey]) and (itimes<4) then

        begin

          close;//对数据查询组件的初始化

          sql.Clear; //清除原来的命令内容

          sql.Add('select * from manage where 用户名=' ''+username+'' ' '+' and  密码=' ''+password+'' '   ');// 指定ADOQuery组件的SQL命令

          open;//打开数据库以便作相应的操作

 

          application.CreateForm(TmainForm,mainform); //主窗体状态栏显示

          mainform.StatusBar1.Panels.Items[1].Text:=username;//第二项显示用户名

          mainform.StatusBar1.Panels.Items[3].Text:=fieldbyname('权限').AsString;//第四项显示权限

 

          if fieldbyname('权限').AsString='操作员' then//判断当前用户的权限,若为操作员则执行以下操作

            begin

 

            with mainform do//引用主界面

                begin

                  //当为操作员时以下功能不能用

                  roomsetitem.Enabled:=false;

                  roommanageitem.Enabled:=false;

                  n12.Enabled:=false;

                  n14.Enabled:=false;

                  epitem.Enabled:=false;

                  groupbox1.Enabled:=false;

                  n2.Enabled:=false;

                end

            end;

 

          loginform.Hide;

          loginform.Free;//用户验证界面隐藏

 

          mainform.ShowModal;

          mainform.Free;//接着显示主界面

 

        end

       else

       begin

         if MessageDlg('密码错误,请重新输入',mtConfirmation, [mbYes, mbNo],0)=mrYes then

           begin

            edit1.Clear;//清空密码输入栏

            edit1.SetFocus; //光标定位在该栏

           end

           else

             close;

       end;

 

 

       if itimes>3 then

         begin

          showmessage('很抱歉,你没有权力使用本系统!'); //若输入次数超过三次则显示提示信息

          application.Terminate;

         end;

     end;

end

else

   showmessage('数据库没有用户名');//数据库中不存在输入的用户则显示提示信息

end;

 

 

2、

我想实现 单击一下toolbutton 弹出一个对话框 (包括YES NO) 点YES 后 memo中增加一行字点NO就无所谓了 急呀!!!!请高手帮忙!!!

 

if MessageDlg('确定吗?',mtInformation,[mbYES,mbNo],0)=mrYes then

begin

memo1.lines.add('添加一行字');

end;

 

mtInformation代表窗口类型.你把光标按到这里按f1就知道有几种类型了.

有如下:

mtWarning   A message box containing a yellow exclamation point symbol.

mtError A message box containing a red stop sign.

mtInformation   A message box containing a blue "i".

mtConfirmation  A message box containing a green question mark.

mtCustom    A message box containing no bitmap. The caption of the message box is the name of the application's executable file.

 

[mbYes,mbNo]是指按钮的样子.还有好多种.把光标按这里按f1就明白了.

[mbYes,mbNo,mbOK,mbCancel...]

 

TMsgDlgBtn Value        Corresponding return value

 

mbOk                          mrOk

mbCancel                   mrCancel

mbYes                         mrYes

mbNo                          mrNo

mbAbort                mrAbort

mbRetry                mrRetry

mbIgnore                   mrIgnore

 

3、

  if locate('用户名',username,[lopartialkey]) and locate('密码',password,[lopartialkey]) and (itimes<4) then

 

例如查找字段名分别为:a1,a2,a3,值分别为:'abc','123','xyz'   应该如何写? 

 答案:  Query.Locate('a1;a2;a3',   VarArrayOf(['abc',   '123',   'xyz']),   [loPartialKey]);

解释:

Query.Locate('a1;a2;a3',   VarArrayOf(['abc',   '123',   'xyz']),   []);  

  最后一项参数解释如下:  

  loCaseInsensitive   :选该项表示可以忽略大小写  

  loPartialKey:选该项表示搜索出的数据与要查询的数据有一部分相同,就视为满足条件

 

 不过进行精确查询并不是这样就可以了

 如果你需要精确匹配,即区分出大小写,必须:  

  1.无论大小写的情况全部找出来,记住,Locate只是定位,它不是筛选。  

  2.一个一个的进行精确匹配,比如你要找MyRecord,程序会找出myrecord或MYRECORD或MyRecord,那么你可以(伪码):  

  if   ADOQuery.FieldByName('xx').Value    'MyRecord'   then   ...   

  进行精确匹配。  

 3、使用“;”来分割多个字段名称,用VarArrayOf()来传递多个定位值。

 4、字段一定要和数据库完全一样,即使你用习惯了的空格也不行。虽然使得程序看起来跟清楚点,但是Locate不会自己做Trim,所以它把空格也当成字段名称的一部分。

 5、因为定位值采用Variants,所以定位就不知局限于字符串了。

 6、对于多栏查询的结果,一定要所有栏位全部符和才可以,只要有一栏不符合,就会返回False。

     

 

4、

增加计数值用inc函数,减少计数值该用什么样的函数?

答案:dec();

  inc(itimes);//验证次数自增

 

inc有两种用法,

一个是inc(integer),就是加1

比如

i := 100;

inc(i);

就是i变为101

另一个是inc(integer,integer)就是加n

比如

i:=100;

inc(i,50);

就是i变成150

 

 y:=3;

 inc(y);      // y=4;

 inc (y,4);   // y=8;

 

5、

先创建登陆窗体 如果登陆成功在创建主窗体 这是思路 具体代码如下

Application.Initialize;

try

FrmLog:=TFrmLog.Create(Application);

FrmLog.ShowModal ;

if FrmLog.ModalResult =mrok then(登陆成功)

begin

Application.CreateForm(TFrmMain, FrmMain);

FrmMain.LoadForm ;

Application.Run;

end   else begin

Application.Terminate ;

end;

finally

 

FrmLog.Free;

FrmLog:= nil;

end;

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多