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

📄 setfm.pas

📁 不管我的程序编得怎么样
💻 PAS
字号:
unit setfm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, DBGrids, Mask, StdCtrls, ComCtrls, ExtCtrls, jpeg,
  Buttons, ShellAPI, ExtDlgs;

type
  Tsettingform = class(TForm)
    Image5: TImage;
    Image6: TImage;
    Image7: TImage;
    Panel1: TPanel;
    Image1: TImage;
    Image2: TImage;
    Panel2: TPanel;
    Image3: TImage;
    Panel3: TPanel;
    Image4: TImage;
    Label1: TLabel;
    Panel4: TPanel;
    Label19: TLabel;
    Label18: TLabel;
    Label7: TLabel;
    Label3: TLabel;
    stbBOPER: TStatusBar;
    edtadmin: TEdit;
    cb_flag: TComboBox;
    Label4: TLabel;
    edtpass: TMaskEdit;
    DBGrid1: TDBGrid;
    Panel5: TPanel;
    BitBtn3: TBitBtn;
    BitBtn4: TBitBtn;
    BitBtn5: TBitBtn;
    BitBtn6: TBitBtn;
    BitBtn2: TBitBtn;
    procedure BitBtn5Click(Sender: TObject);
    procedure Image4MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure BitBtn4Click(Sender: TObject);
    procedure BitBtn6Click(Sender: TObject);
    procedure BitBtn3Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    G_userid:integer;
  end;

var
  settingform: Tsettingform;

implementation
uses dmfm;
{$R *.dfm}

procedure Tsettingform.BitBtn5Click(Sender: TObject);
begin
close;
end;

procedure Tsettingform.Image4MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
      
  ReleaseCapture;
  SendMessage(Handle, WM_SYSCOMMAND, $F012, 0);
end;

procedure Tsettingform.FormCreate(Sender: TObject);
begin  
bitbtn2.Enabled:=false;

end;



procedure Tsettingform.FormShow(Sender: TObject);
var
aSQL:string;
begin
with dm do
 begin
  aq_admin.SQL.Clear;
  aSQL:='select * from 管理员 order by id asc';
  aq_admin.SQL.Add(aSQL);
  try
  aq_admin.open;
  except
  end;
  dbgrid1.Columns.Items[0].FieldName:='用户名';
  dbgrid1.Columns.Items[1].FieldName:='密码';
  dbgrid1.Columns.Items[2].FieldName:='权限';
  stbBOPER.Panels.Items[0].Text:='记录: ' + IntToStr(aq_admin.RecordCount);
  stbboper.Panels.Items[1].Text:='当前时间: '+datetostr(date);
 end;
end;

procedure Tsettingform.BitBtn4Click(Sender: TObject);
begin
with dm.aq_admin do
 begin
  if RecordCount>0 then
   begin
     if application.MessageBox('是否真的删除?', '记录删除', 4) = 6 then
      try
      delete;
      application.MessageBox('删除成功!', '明宇提示', Mb_Ok or Mb_IconInformation);
      except
       Application.MessageBox('删除失败!', '提示', Mb_Ok or Mb_IconStop);
      end;
   end;
   with dm.aq_admin do
    begin
     close;
     sql.Clear;
     sql.Add('select * from 管理员');
     active:=true; 
     stbBOPER.Panels.Items[0].Text:='共有 '+inttostr(RecordCount)+' 名用户';
    end;
 end;
end;

procedure Tsettingform.BitBtn6Click(Sender: TObject);
var
aSQL:string;
begin
if (edtadmin.text='') or (edtpass.text='') then
 begin
    Application.MessageBox('请输入完整的信息!', '明宇提示', Mb_Ok or Mb_IconWarning);
    edtadmin.SetFocus;
 end
else
 begin
 with dm.aq_admin do
  begin
  if G_userid=0 then
   begin
    close;
    sql.Clear;
    asql:='select * from 管理员 where 用户名=:name';
    sql.Add(asql);
    Parameters.ParamByName('name').Value:=edtadmin.Text;
    active:=true;
    if Recordset.RecordCount > 0 then //有此记录
     begin
          Application.MessageBox('已有此信息,请重输!', '提示', Mb_Ok or Mb_IconWarning);
          Close;
          SQL.Clear;
          edtadmin.SetFocus;
     end
    else
     begin
     close;
     sql.clear;
      asql:='insert into 管理员 (用户名,密码,权限) values (:name,:pass,:flag)';
      sql.add(asql);
      Parameters.ParamByName('name').Value:=edtadmin.Text;
      parameters.ParamByName('pass').value:=edtpass.text;
      parameters.ParamByName('flag').Value:=cb_flag.ItemIndex;
      try
      execsql;
      Application.MessageBox('管理员添加成功!', '明宇提示', Mb_Ok or Mb_IconInformation);
      except
      Application.MessageBox('管理员添加失败!', '明宇提示', Mb_Ok or Mb_IconStop);
      end;
     end;
   end
  else
   begin
    close;
    sql.Clear;
    asql:='select * from 管理员 where 用户名=:name';
    sql.Add(asql);
    Parameters.ParamByName('name').Value:=edtadmin.Text;
    active:=true;
     begin
           edit;
           fieldbyname('用户名').AsString:=edtadmin.Text;
           fieldbyname('密码').AsString:=edtpass.Text;
           fieldbyname('权限').AsInteger:=cb_flag.ItemIndex;
           try
             post;
             Application.MessageBox('管理员修改成功!', '提示', Mb_Ok or Mb_IconInformation);
           except
             Application.MessageBox('管理员修改失败!', '提示', Mb_Ok or Mb_IconStop);
           end;
     end;
   end;
      SQL.Clear;
      SQL.Add('select * from 管理员 order by id asc');
      Active := true;   //必须得加,否则数据库不更新!
      edtadmin.Text:='';
      edtpass.Text:='';
      cb_flag.ItemIndex:=1;
      edtadmin.SetFocus;
      bitbtn2.Enabled:=false;
  end;
  end;
end;

procedure Tsettingform.BitBtn3Click(Sender: TObject);
begin
bitbtn3.Enabled:=false;
bitbtn2.Enabled:=true;
with dm do
 begin
  if aq_admin.RecordCount>0 then
   begin
    edtadmin.Text:=aq_admin.FieldValues['用户名'];
    edtpass.Text:=aq_admin.FieldValues['密码'];
    cb_flag.ItemIndex:=aq_admin.FieldValues['权限'];
    G_userid:=aq_admin.FieldValues['id'];
   end;
 end;
end;

procedure Tsettingform.BitBtn2Click(Sender: TObject);
begin
edtadmin.Text:='';
edtpass.Text:='';
G_userid:=0;
bitbtn2.Enabled:=false;
bitbtn3.Enabled:=true;
end;



end.

⌨️ 快捷键说明

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