我想做个  用户添加 模块  ...   包括两个功能 一个添加用户 一个  修改密码添加用户,普通的添加我会可是怎么才能做到 两次输入密码一致后 ,才执行...否则提示错误...修改密码, 这个功能怎么才能实现,先输入原密码..原密码 正确的情况下才能修改成功的功能  大家帮下忙  

解决方案 »

  1.   

    网上有相关的例子,楼主可以找找看,这些都是基本的东西。
    随便找了几段仅供参考unit AddUse;interfaceuses
      windows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,
      Dialogs,StdCtrls,Buttons,ExtCtrls,DB,DBTables,ADODB;type
      TAddUseForm=class(TForm)
        Bevel1:TBevel;
        Label1:TLabel;
        Label2:TLabel;
        Label3:TLabel;
        NewName:TEdit;
        Password:TEdit;
        NPassword:TEdit;
        Add_ok:TBitBtn;
        Add_cancel:TBitBtn;
        RadioGroup1:TRadioGroup;
        J0:TRadioButton;
        J1:TRadioButton;
        DataSource1:TDataSource;
        Panel1:TPanel;
        ADOTable1:TADOTable;
        procedure Add_cancelClick(Sender:TObject);
        procedure Add_okClick(Sender:TObject);
        procedure FormCreate(Sender:TObject);
      private
        { Private declarations }
      public
        function FindName(const Name:string):Boolean;
        { Public declarations }
      end;var
      AddUseForm:TAddUseForm;implementation
    uses DataM;
    {$R *.dfm}procedure TAddUseForm.Add_cancelClick(Sender:TObject);
    begin
      Close;
    end;procedure TAddUseForm.Add_okClick(Sender:TObject);
    var
      rec:string;
    begin
      if NewName.Text='' then
      begin
        application.MessageBox(PChar('用户名不能为空!'),'警告',mb_iconexclamation);
        NewName.SetFocus;
        exit;
      end;  if FindName(NewName.Text) then
      begin
        application.MessageBox(PChar('用户名:"'+NewName.Text+'"已存在!'),'提示',mb_iconexclamation);
        NewName.SetFocus;
      end
      else
      begin
        if Password.Text<>NPassword.Text then
        begin
          application.MessageBox(PChar('"验证密码"与"密码"不相同!(请注意大小写!)'),'错误',mb_iconstop);
          NPassword.SetFocus;
          exit;
        end;
        ADOTable1.Append;
        ADOTable1.FieldByName('用户名').AsString:=NewName.Text;
        if Password.Text='' then
          Password.Text:=' ';
        ADOTable1.FieldByName('密码').AsString:=Password.Text;
        if J0.Checked then
          rec:='管理级'
        else
          rec:='普通级';
        ADOTable1.FieldByName('级别').AsString:=rec;
        ADOTable1.Post;
        if application.MessageBox(PChar('"'+NewName.Text+'"添加成功!是否继续添加?'),
          '提示',mb_yesno+mb_iconquestion)=idyes then
        begin
          NewName.Text:='';
          Password.Text:='';
          NPassword.Text:='';
          NewName.SetFocus;
        end
        else
          Close;
      end;
    end;function TAddUseForm.FindName(const Name:string):Boolean;
    begin
      Result:=false;
      ADOTable1.First;
      while not ADOTable1.Eof do
      begin
        if ADOTable1.FieldByName('用户名').AsString=NewName.Text then
        begin
          Result:=true;
          exit;
        end;
        ADOTable1.Next;
      end;
    end;procedure TAddUseForm.FormCreate(Sender:TObject);
    begin
      ADOTable1.Open;
    end;end.
      

  2.   


    unit ModiPass;interfaceuses
      windows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,
      Dialogs,StdCtrls,ExtCtrls,Buttons,DB,DBTables,Grids,DBGrids,ADODB;type
      tmodifyform=class(TForm)
        Bevel1:TBevel;
        Label1:TLabel;
        Label2:TLabel;
        Label3:TLabel;
        oldPassword:TEdit;
        newPassword:TEdit;
        zPassword:TEdit;
        modiOk:TBitBtn;
        modiCancle:TBitBtn;
        DBGrid1:TDBGrid;
        DataSource1:TDataSource;
        ADOTable1:TADOTable;
        procedure modiCancleClick(Sender:TObject);
        procedure modiOkClick(Sender:TObject);
        procedure FormCreate(Sender:TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      ModifyForm:tmodifyform;implementation
    uses ledMain,AddUse,DataM;
    {$R *.dfm}procedure tmodifyform.modiCancleClick(Sender:TObject);
    begin
      Close;
    end;procedure tmodifyform.modiOkClick(Sender:TObject);
    begin
      if oldPassword.Text<>ledform.Password then
      begin
        application.MessageBox('旧密码不正确!(请注意大小写!)','错误',mb_iconstop);
        oldPassword.SetFocus;
        exit;
      end;
      if newPassword.Text<>zPassword.Text then
      begin
        application.MessageBox('"验证密码"与"密码"不相同!(请注意大小写!)','错误',mb_iconstop);
        zPassword.SetFocus;
        exit;
      end;
      try
        ADOTable1.Close;
        ADOTable1.Open;
        ADOTable1.Filtered:=false;
        ADOTable1.Filter:='用户名='+''''+ledform.UseName+'''';
        ADOTable1.Filtered:=true;
        if DBGrid1.Fields[0].AsString<>'' then
        begin
          ADOTable1.Edit;
          if newPassword.Text='' then
            newPassword.Text:=' ';
          DBGrid1.Fields[1].AsString:=newPassword.Text;
          ledform.Password:=newPassword.Text;
          ADOTable1.Post;
          application.MessageBox('密码修改成功!','提示',mb_iconAsterisk);
          Close;
        end;
      except
        application.MessageBox('系统出错,密码修改不成功!请重新进入系统再试。','出错',mb_iconstop);
      end;
    end;procedure tmodifyform.FormCreate(Sender:TObject);
    begin
      ADOTable1.Open;
    end;end.