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

📄 loginform.pas

📁 这是一个DELPHI7应用案例开发篇有配套程序种子光盘
💻 PAS
字号:
unit LoginForm;
{PUBDIST}

interface

uses
  IWAppForm, IWApplication, IWTypes, IWCompEdit, Classes, Controls,
  IWControl, IWCompLabel, IWCompButton, IWCompMemo, Variants, IWCompListbox,
  SysUtils;

type
  TfrmUserLogin = class(TIWAppForm)
    IWLabel1: TIWLabel;
    edID: TIWEdit;
    IWLabel2: TIWLabel;
    edPassword: TIWEdit;
    IWLabel3: TIWLabel;
    edName: TIWEdit;
    IWLabel4: TIWLabel;
    edAge: TIWEdit;
    IWLabel5: TIWLabel;
    edPhone: TIWEdit;
    IWLabel6: TIWLabel;
    edEMail: TIWEdit;
    IWLabel7: TIWLabel;
    edMobile: TIWEdit;
    IWLabel8: TIWLabel;
    edCardNo: TIWEdit;
    IWLabel9: TIWLabel;
    IWLabel10: TIWLabel;
    edAddress: TIWEdit;
    IWLabel11: TIWLabel;
    edCardType: TIWEdit;
    IWLabel13: TIWLabel;
    edZip: TIWEdit;
    IWMemo1: TIWMemo;
    btnOK: TIWButton;
    btnCancel: TIWButton;
    btnTestID: TIWButton;
    cbGender: TIWComboBox;
    procedure btnTestIDClick(Sender: TObject);
    procedure btnOKClick(Sender: TObject);
  public
    constructor Create(AOWner:TComponent; IsModify:Boolean=False);overload;
  private
    fIsModify : Boolean;
  end;

implementation
{$R *.dfm}

uses
  ServerController, DatamoduleUnit, IWUnit1;

procedure TfrmUserLogin.btnTestIDClick(Sender: TObject);
begin
    if Length(edId.Text) < 3 then
    begin
        WebApplication.ShowMessage('ID太短');
        Exit;
    end;
    if VarType(DataModule1.cdsCustomer.Lookup('ID',edID.Text,'ID')) in
        [varNULL] then
        WebApplication.ShowMessage('恭喜您,此ID可以使用')
    else
        WebApplication.ShowMessage('此ID已经存在,请重新选择');
end;

procedure TfrmUserLogin.btnOKClick(Sender: TObject);
begin
    if fIsModify then
    begin
        with DataModule1 do
        begin
            try
                with cdsCustomer do
                begin
                    Locate('ID',edID.Text,[]);
                    Edit;
                    FieldValues['Passwd'] := edPassword.Text;
                    FieldValues['Age'] := edAge.Text;
                    FieldValues['Gender'] := cbGender.ItemIndex;
                    FieldValues['Address'] := edAddress.Text;
                    FieldValues['Zip'] := edZip.Text;
                    FieldValues['Phone'] := edPhone.Text;
                    FieldValues['Email'] := edEmail.Text;
                    FieldValues['Mobile'] := edMobile.Text;
                    FieldValues['BankCard'] := edCardNo.Text;
                    FieldValues['CardType'] := edCardType.Text;
                    FieldValues['Memoir'] := IWMemo1.Lines.Text;

                    Post;
                    ApplyUpdates(-1);
                end;

                UserSession.UserName := edID.Text;
                UserSession.Password := edPassword.Text;
                UserSession.LoginTime := Now;

                //显示主窗口
                TIWAppForm(WebApplication.ActiveForm).Release;
                TformMain.Create(WebApplication).Show;
            except
                on e:Exception do
                begin
                    WebApplication.ShowMessage(e.Message);
                    Abort;
                end;
            end;
        end;
    end
    else
    begin
        with DataModule1 do
        begin
            try
                cdsCustomer.InsertRecord([edID.Text, edPassword.Text,
                    edName.Text, edAge.Text,cbGender.ItemIndex, edAddress.Text,
                    edZip.Text, edPhone.Text, edEmail.Text, edMobile.Text,
                    edCardNo.Text,edCardType.Text, IWMemo1.Lines.Text]);
    {            cdsCustomer.InsertRecord(['ganzhi','password',23,0,'ddd',
                    333,777,'gan@gan','134','123','ddd','ddd']);}
                cdsCustomer.ApplyUpdates(-1);

                UserSession.UserName := edID.Text;
                UserSession.Password := edPassword.Text;
                UserSession.LoginTime := Now;

                //显示主窗口
                TIWAppForm(WebApplication.ActiveForm).Release;
                TformMain.Create(WebApplication).Show;
            except
                on e:Exception do
                begin
                    WebApplication.ShowMessage(e.Message);
                    Abort;
                end;
            end;
        end;
    end;
end;

constructor TfrmUserLogin.Create(AOWner: TComponent; IsModify: Boolean);
begin
    inherited Create(AOwner);

    fIsModify := IsModify;

    if IsModify then
    begin
        btnTestID.Visible := False;
        edID.ReadOnly := True;

        with DataModule1.cdsCustomer do
        begin
            edID.Text := UserSession.UserName;
            Locate('ID',edID.Text,[]);
            edPassword.Text := FieldByName('Passwd').AsString;
            edAge.Text := FieldByName('Age').AsString;
            cbGender.ItemIndex := FieldByName('Gender').AsInteger;
            edAddress.Text := FieldByName('Address').AsString;
            edZip.Text := FieldByName('Zip').AsString;
            edPhone.Text := FieldByName('Phone').AsString;
            edEmail.Text := FieldByName('Email').AsString;
            edMobile.Text := FieldByName('Mobile').AsString;
            edCardNo.Text := FieldByName('BankCard').AsString;
            edCardType.Text := FieldByName('CardType').AsString;
            IWMemo1.Lines.Text := FieldByName('Memoir').AsString;
        end;
    end;
end;

end.



⌨️ 快捷键说明

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