adduser.pas

来自「《Delphi 2005数据库系统开发与应用》源代码」· PAS 代码 · 共 232 行

PAS
232
字号
unit AddUser;

interface

uses
  System.Drawing, System.Collections, System.ComponentModel,
  System.Windows.Forms, System.Data, Borland.Data.Common, Borland.Data.Provider;

type
  FrmAddUser = class(System.Windows.Forms.Form)
  {$REGION 'Designer Managed Code'}
  strict private
    /// <summary>
    /// Required designer variable.
    /// </summary>
    Components: System.ComponentModel.Container;
    ErrorProvider1: System.Windows.Forms.ErrorProvider;
    Label1: System.Windows.Forms.Label;
    Label2: System.Windows.Forms.Label;
    Label3: System.Windows.Forms.Label;
    TxtUserName: System.Windows.Forms.TextBox;
    TxtUserPassword: System.Windows.Forms.TextBox;
    TxtConfirmPassword: System.Windows.Forms.TextBox;
    BtOK: System.Windows.Forms.Button;
    BtCancel: System.Windows.Forms.Button;
    BdpConnection1: Borland.Data.Provider.BdpConnection;
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    procedure InitializeComponent;
    procedure BtCancel_Click(sender: System.Object; e: System.EventArgs);
    procedure BtOK_Click(sender: System.Object; e: System.EventArgs);

  {$ENDREGION}
  strict protected
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    procedure Dispose(Disposing: Boolean); override;
  private
    { Private Declarations }
  public
    myTable:DataTable;
    constructor Create;
  end;

  [assembly: RuntimeRequiredAttribute(TypeOf(FrmAddUser))]

implementation

{$REGION 'Windows Form Designer generated code'}
/// <summary>
/// Required method for Designer support -- do not modify
/// the contents of this method with the code editor.
/// </summary>
procedure FrmAddUser.InitializeComponent;
begin
  Self.ErrorProvider1 := System.Windows.Forms.ErrorProvider.Create;
  Self.Label1 := System.Windows.Forms.Label.Create;
  Self.Label2 := System.Windows.Forms.Label.Create;
  Self.Label3 := System.Windows.Forms.Label.Create;
  Self.TxtUserName := System.Windows.Forms.TextBox.Create;
  Self.TxtUserPassword := System.Windows.Forms.TextBox.Create;
  Self.TxtConfirmPassword := System.Windows.Forms.TextBox.Create;
  Self.BtOK := System.Windows.Forms.Button.Create;
  Self.BtCancel := System.Windows.Forms.Button.Create;
  Self.BdpConnection1 := Borland.Data.Provider.BdpConnection.Create;
  Self.SuspendLayout;
  // 
  // ErrorProvider1
  // 
  Self.ErrorProvider1.ContainerControl := Self;
  // 
  // Label1
  // 
  Self.Label1.Location := System.Drawing.Point.Create(8, 24);
  Self.Label1.Name := 'Label1';
  Self.Label1.Size := System.Drawing.Size.Create(80, 23);
  Self.Label1.TabIndex := 0;
  Self.Label1.Text := '用户名';
  Self.Label1.TextAlign := System.Drawing.ContentAlignment.MiddleCenter;
  // 
  // Label2
  // 
  Self.Label2.Location := System.Drawing.Point.Create(8, 64);
  Self.Label2.Name := 'Label2';
  Self.Label2.Size := System.Drawing.Size.Create(80, 23);
  Self.Label2.TabIndex := 1;
  Self.Label2.Text := '密码';
  Self.Label2.TextAlign := System.Drawing.ContentAlignment.MiddleCenter;
  // 
  // Label3
  // 
  Self.Label3.Location := System.Drawing.Point.Create(8, 104);
  Self.Label3.Name := 'Label3';
  Self.Label3.Size := System.Drawing.Size.Create(80, 23);
  Self.Label3.TabIndex := 2;
  Self.Label3.Text := '确认密码';
  Self.Label3.TextAlign := System.Drawing.ContentAlignment.MiddleCenter;
  // 
  // TxtUserName
  // 
  Self.TxtUserName.Location := System.Drawing.Point.Create(88, 24);
  Self.TxtUserName.Name := 'TxtUserName';
  Self.TxtUserName.TabIndex := 3;
  Self.TxtUserName.Text := '';
  // 
  // TxtUserPassword
  // 
  Self.TxtUserPassword.Location := System.Drawing.Point.Create(88, 64);
  Self.TxtUserPassword.Name := 'TxtUserPassword';
  Self.TxtUserPassword.PasswordChar := '*';
  Self.TxtUserPassword.TabIndex := 4;
  Self.TxtUserPassword.Text := '';
  // 
  // TxtConfirmPassword
  // 
  Self.TxtConfirmPassword.Location := System.Drawing.Point.Create(88, 104);
  Self.TxtConfirmPassword.Name := 'TxtConfirmPassword';
  Self.TxtConfirmPassword.PasswordChar := '*';
  Self.TxtConfirmPassword.TabIndex := 5;
  Self.TxtConfirmPassword.Text := '';
  // 
  // BtOK
  // 
  Self.BtOK.Location := System.Drawing.Point.Create(24, 144);
  Self.BtOK.Name := 'BtOK';
  Self.BtOK.TabIndex := 6;
  Self.BtOK.Text := '确定';
  Include(Self.BtOK.Click, Self.BtOK_Click);
  // 
  // BtCancel
  // 
  Self.BtCancel.Location := System.Drawing.Point.Create(120, 144);
  Self.BtCancel.Name := 'BtCancel';
  Self.BtCancel.TabIndex := 7;
  Self.BtCancel.Text := '取消';
  Include(Self.BtCancel.Click, Self.BtCancel_Click);
  // 
  // BdpConnection1
  // 
  Self.BdpConnection1.ConnectionOptions := 'transaction isolation=ReadCommitted;blob size=1024';
  Self.BdpConnection1.ConnectionString := 'assembly=Borland.Data.Mssql,Version=1.5.0.0,Culture=neutral,PublicKeyToken=91d6'+ 
  '2ebb5b0d1b1b;vendorclient=sqloledb.dll;database=教务信息管理系统;username=sa;hostname='+ 
  'storm;password=sa;provider=MSSQL';
  // 
  // FrmAddUser
  // 
  Self.AutoScaleBaseSize := System.Drawing.Size.Create(6, 14);
  Self.ClientSize := System.Drawing.Size.Create(224, 182);
  Self.Controls.Add(Self.BtCancel);
  Self.Controls.Add(Self.BtOK);
  Self.Controls.Add(Self.TxtConfirmPassword);
  Self.Controls.Add(Self.TxtUserPassword);
  Self.Controls.Add(Self.TxtUserName);
  Self.Controls.Add(Self.Label3);
  Self.Controls.Add(Self.Label2);
  Self.Controls.Add(Self.Label1);
  Self.Name := 'FrmAddUser';
  Self.Text := '添加用户';
  Self.ResumeLayout(False);
end;
{$ENDREGION}

procedure FrmAddUser.Dispose(Disposing: Boolean);
begin
  if Disposing then
  begin
    if Components <> nil then
      Components.Dispose();
  end;
  inherited Dispose(Disposing);
end;

constructor FrmAddUser.Create;
begin
  inherited Create;
  //
  // Required for Windows Form Designer support
  //
  InitializeComponent;
  //
  // TODO: Add any constructor code after InitializeComponent call
  //
end;

procedure FrmAddUser.BtOK_Click(sender: System.Object; e: System.EventArgs);
var
cda:BdpDataAdapter;
slc:string;
newDataRow:DataRow;
cmdb:BdpCommandBuilder;
ds:DataSet;
begin
//判断是否符合要求
if TxtConfirmPassword.Text<>TxtUserPassword.Text then
begin
MessageBox.Show('密码不一致');
exit;
end;
//构造查询语句
slc:='Select * From user_Info';
//建立数据适配器对象
cda:=BdpDataAdapter.Create(slc,bdpConnection1);
//填充数据集
ds:=DataSet.Create;
cda.Fill(ds,'user_Info');
//在数据集中新建数据行
newDataRow:= ds.Tables[0].NewRow;
//填充数据行
newDataRow[0]:=TxtUserName.Text;
newDataRow[1]:=TxtUserPassword.Text;
//将数据行填充进数据集中
ds.Tables[0].Rows.Add(newDataRow);
//使用BdpCommandBuilder自动生成SQL语句
cmdb:=BdpCommandBuilder.Create(cda);
//更新数据库中的关系表
bdpConnection1.Open ;
cda.Update(ds,'user_Info');
bdpConnection1.Close ;
//显示添加成功信息
MessageBox.Show('添加成功');
end;

procedure FrmAddUser.BtCancel_Click(sender: System.Object; e: System.EventArgs);
begin
  self.Close;
end;

end.

⌨️ 快捷键说明

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