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

📄 pass_pope_modify.pas

📁 使用Delphi 6.0开发用于控制空调的程序
💻 PAS
字号:
unit Pass_Pope_Modify;    //修改密码、权限窗体单元

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, DB, ADODB;

type
  TF_PP_Modi = class(TForm)
    StaticText1: TStaticText;
    Edit1: TEdit;
    GroupBox1: TGroupBox;
    StaticText2: TStaticText;
    Edit2: TEdit;
    StaticText4: TStaticText;
    Edit4: TEdit;
    Edit3: TEdit;
    CheckBox1: TCheckBox;
    StaticText3: TStaticText;
    GroupBox2: TGroupBox;
    StaticText6: TStaticText;
    ComboBox1: TComboBox;
    CheckBox2: TCheckBox;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    ADOqry1: TADOQuery;
    procedure FormCreate(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure Edit4KeyPress(Sender: TObject; var Key: Char);
    procedure FormPaint(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  F_PP_Modi: TF_PP_Modi;

implementation

uses
   Main;

{$R *.dfm}

procedure TF_PP_Modi.FormCreate(Sender: TObject);
begin  {*****窗体初始化事件*****}
      Edit2.Visible := false;     //三个Edit对象不可见
      Edit3.Visible := false;
      Edit4.Visible := false;
      ComboBox1.Visible := false; //ComboBox1对象不可见
end;

procedure TF_PP_Modi.CheckBox1Click(Sender: TObject);
begin  {*****修改密码CheckBox点击事件*****}
    if CheckBox1.Checked then       //CheckBox1选中判断
      begin
      Edit2.Visible := true;        //三个Edit对象可见
      Edit3.Visible := true;
      Edit4.Visible := true;
      end
    else
      begin
      Edit2.Visible := false;     //三个Edit对象不可见
      Edit3.Visible := false;
      Edit4.Visible := false;
      end;
end;

procedure TF_PP_Modi.CheckBox2Click(Sender: TObject);
begin  {*****修改权限CheckBox点击事件*****}
    if CheckBox2.Checked then        //CheckBox2选中判断
      ComboBox1.Visible := true   //ComboBox1对象可见
    else
      ComboBox1.Visible := false; //ComboBox1对象不可见
end;

procedure TF_PP_Modi.BitBtn1Click(Sender: TObject);  
begin  {*****确定按钮点击事件*****}
  if Main.Operater <> '管理员' then
  begin
     if Edit1.Text <> '' then
     begin
       if Trim(Edit1.Text) <> Main.User then
       begin
            ShowMessage('对不起,您不是管理员,没有权限修改其他人的密码!');
            Edit1.Text := Main.User ;
            Edit1.SetFocus;
            Exit;
       end;  
     end;  
  end;  
  if CheckBox1.Checked then         //修改密码CheckBox1选中判断
  begin
      if (Edit1.Text = '')or(Edit3.Text <> Edit4.Text) then
      begin
          if Edit1.Text='' then  //工号输入框为空判断
          begin
            ShowMessage('请输入用户工号');
            Edit1.SetFocus;          //焦点仍在工号输入框中
            exit;
         end;
         if(Edit3.Text <> Edit4.Text)then //密码输入是否一致判断
         begin
                ShowMessage('输入新密码不一致,请您重新输入');
                Edit3.SetFocus;
                exit;
         end;
     end
     else
     begin
        with ADOqry1 do
        begin
          Close;
          SQL.Clear;  //清除SQL语句
          SQL.Add('SELECT * FROM Users');
          SQL.Add('WHERE name=:ID_Val');  //设置查询条件数据的两个参数ID_Val,Password
          Parameters.ParamByName('ID_Val').Value := Trim(Edit1.Text);  //两个参数赋值
          Open;       //执行SQL语句   
          if RecordCount<>1 then
          begin
              ShowMessage('此用户工号不存在');
              Edit1.SetFocus;
              exit;
          end
          else
          begin
             if FieldByName('pw').AsString <> Trim(Edit2.Text) then
             begin
                 ShowMessage(' 密码输入错误,请重新输入!');
                 Edit2.SetFocus;
                 Exit;
             end
             else
             begin
                  Edit;     //进入记录编辑状态
                  FieldByName('pw').Value := Edit3.Text;
                  Post;
                  Application.MessageBox('密码修改成功', '提示', MB_ICONINFORMATION+MB_OK);
          end;   
        end;
      end;
    end;                       //检查用户工号和密码是否正确
  end;
  ////修改权限这部分功能已经屏蔽
  if CheckBox2.Checked then //修改权限CheckBox2选中判断
  begin
    if ComboBox1.Text='' then
      begin
      ShowMessage('请您选择权限类型');
      ComboBox1.SetFocus;
      exit;
      end
    else    //检查用户工号和密码是否正确
    with ADOqry1 do
      begin
        Close;
        SQL.Clear;
        SQL.Add('SELECT * FROM Users');
        SQL.Add('WHERE name=:User_Val'); //设置参数
        Parameters.ParamByName('User_Val').Value := Edit1.Text;  //参数赋值
        Open;
      if(RecordCount <> 1)then
        begin
        ShowMessage('此用户工号不存在');
        Edit1.SetFocus();
        end
      else
        begin
          Edit;  //进入记录编辑状态
          FieldByName('power').Value := ComboBox1.Text;
          Post;
          ShowMessage('权限修改成功');
        end;
      end;
  end;      
  F_PP_Modi.Close;
end;

procedure TF_PP_Modi.BitBtn2Click(Sender: TObject);
begin  {*****取消按钮点击事件*****}
    F_PP_Modi.Close;        
end;

procedure TF_PP_Modi.Edit4KeyPress(Sender: TObject; var Key: Char);
begin  {*****确认密码输入框KeyPress事件*****}
    if (Key = #13) then        //按下回车键执行
      BitBtn1Click(self);      //调用BitBtn1按钮点击事件
end;

procedure TF_PP_Modi.FormPaint(Sender: TObject);
begin
    if Main.Operater <> '管理员'  then
    begin
        Edit1.Text := Main.User;
        CheckBox2.Enabled := False;
        GroupBox2.Enabled := False;
    end;  

end;

end.

⌨️ 快捷键说明

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