Unit1.pas
上传用户:szyozho
上传日期:2013-04-13
资源大小:3688k
文件大小:4k
源码类别:

教育系统应用

开发平台:

Delphi

  1. unit Unit1;
  2. interface
  3. uses
  4.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5.   Dialogs, ExtCtrls, Buttons, StdCtrls, DBCtrls, DB, Mask,DBTables;
  6. type
  7.   Tloginform = class(TForm)
  8.     Image1: TImage;
  9.     Label1: TLabel;
  10.     Label2: TLabel;
  11.     Edit1: TEdit;
  12.     Label3: TLabel;
  13.     BitBtn1: TBitBtn;
  14.     BitBtn2: TBitBtn;
  15.     Query1: TQuery;
  16.     Query1ID: TStringField;
  17.     Query1mi: TStringField;
  18.     Query1qx: TStringField;
  19.     ComboBox1: TComboBox;
  20.     Timer1: TTimer;
  21.   // procedure ComboBox1Change(Sender: TObject);
  22.     procedure BitBtn2Click(Sender: TObject);
  23.     procedure FormCreate(Sender: TObject);
  24.     procedure BitBtn1Click(Sender: TObject);
  25.     procedure Timer1Timer(Sender: TObject);
  26.     procedure Edit1KeyDown(Sender: TObject; var Key: Word;
  27.       Shift: TShiftState);
  28.     procedure FormShow(Sender: TObject);
  29.   private
  30.     { Private declarations }
  31.   public
  32.   
  33.    { Public declarations }
  34.  //username:string;
  35.  //password:string;
  36.   end;
  37. var
  38.   loginform: Tloginform;
  39.    t:integer;
  40.    flash:boolean;
  41. //username,password:string;
  42. implementation
  43. uses Unit4, Unit3, Unit21;
  44. {$R *.dfm}
  45. procedure Tloginform.BitBtn2Click(Sender: TObject);
  46. begin
  47. if (messagedlg('确认要退出系统吗 ?',mtconfirmation,[mbyes,mbno],0))=mryes then
  48. application.Terminate;
  49. end;
  50. procedure Tloginform.FormCreate(Sender: TObject);
  51. begin
  52. flash:=false;
  53. t:=0;
  54. query1.Close;
  55. query1.SQL.Clear;
  56. query1.SQL.Add('select * from u');
  57. query1.open;
  58. while  not query1.eof do
  59. begin
  60. ComboBox1.items.add(trim(query1.fieldbyname('ID').asstring));
  61. query1.next;
  62. end;
  63. end;
  64. procedure Tloginform.BitBtn1Click(Sender: TObject);
  65. begin
  66. query1.Close;
  67. query1.SQL.Clear;
  68.   query1.SQL.Add('select * from u where ID=:p1 and mi=:p2');
  69.   query1.Params[0].AsString:=ComboBox1.Text;
  70.   query1.Params[1].AsString:=Edit1.Text;
  71.   query1.Open;
  72.   inc(t);
  73.   if query1.RecordCount>0 then
  74.     begin
  75.     mainform.username:=ComboBox1.Text;
  76.    mainform.password:=edit1.Text;
  77.      mainform.StatusBar1.Panels[1].Text:='当前用户:'+ ComboBox1.Text;
  78.  // query1.Close;
  79.  // query1.SQL.Clear;
  80.  // query1.SQL.text:='select qx from u where ID='''+ComboBox1.Text+'''';
  81.   // query1.ExecSQL;
  82.    if  query1.fieldbyname('qx').AsString='b' then
  83.     begin
  84.     if rightform.CheckBox1.State=cbChecked then
  85.  mainform.N3.Enabled:=true else    mainform.N3.Enabled:=false;
  86.  if rightform.CheckBox2.State=cbChecked then
  87.  mainform.N18.Enabled:=true else  mainform.N18.Enabled:=false;
  88.  if rightform.CheckBox4.State=cbChecked then
  89.     mainform.N6.Enabled:=true else  mainform.N6.Enabled:=false;
  90. if   rightform.CheckBox5.State=cbChecked  then
  91.     mainform.N7.Enabled:=true  else mainform.N7.Enabled:=false;
  92.  if   rightform.CheckBox7.State=cbChecked  then
  93.        mainform.N10.Enabled:=true else mainform.N10.Enabled:=false;
  94.     
  95.  //  mainform.N3.Enabled:=false;
  96.   // mainform.N6.Enabled:=false;
  97.   // mainform.N7.Enabled:=false;
  98.   // mainform.N10.Enabled:=false;
  99.   // mainform.N18.Enabled:=false;
  100.  //   form21.BitBtn1.Click;
  101.    end;
  102.    if  query1.fieldbyname('qx').AsString='a' then
  103.     begin
  104.    mainform.N3.Enabled:=true;
  105.    mainform.N6.Enabled:=true;
  106.    mainform.N7.Enabled:=true;
  107.    mainform.N10.Enabled:=true;
  108.    mainform.N18.Enabled:=true;
  109.  //   form21.BitBtn1.Click;
  110.    end;
  111.   havelogin:=true;
  112.   loginform.Close;
  113.     end
  114.   else
  115.     begin
  116.     showMessage('密码输入错误,请重新输入!');
  117.     if t>=3 then
  118.     begin
  119.     MessageBox(handle,'输入密码错误超过三次,程序退出!','信息',MB_OK);
  120.     Close;
  121.     Application.Terminate;
  122.     end
  123.     else
  124.     begin
  125.        edit1.Text:='';
  126.        edit1.SetFocus;
  127.     end;
  128.   end;
  129.     // if query1.fieldbyname('qx').AsString='a' then
  130. end;
  131. procedure Tloginform.Timer1Timer(Sender: TObject);
  132. begin
  133. FlashWindow(loginform.Handle,flash);
  134. FlashWindow(Application.Handle,flash);
  135. flash:=not flash;
  136. end;
  137. procedure Tloginform.Edit1KeyDown(Sender: TObject; var Key: Word;
  138.   Shift: TShiftState);
  139. begin
  140. if Key=13 then
  141. BitBtn1Click(Sender);
  142. end;
  143. procedure Tloginform.FormShow(Sender: TObject);
  144. begin
  145.     Edit1.SetFocus;
  146. end;
  147. end.