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

📄 cformeditcorp.pas

📁 人力资源的信息。其他人不需帐号就可自由下载此源码
💻 PAS
字号:
{-----------------------------------------------------------------------------
 Unit Name: CFormEditCorp
 Author:    hubdog(陈省)
 Purpose:   编辑公司信息的界面
 BeginDate: 2002-7-1
 History:
-----------------------------------------------------------------------------}

unit CFormEditCorp;
{PUBDIST}

interface

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

type
  TEditMode = (emEdit, emInsert);
  TformEditCorp = class(TIWAppForm)
    iweChnName: TIWEdit;
    iweEngName: TIWEdit;
    iwePhone: TIWEdit;
    iweFax: TIWEdit;
    iwmChnInfo: TIWMemo;
    iwmEngInfo: TIWMemo;
    IWLabel1: TIWLabel;
    IWLabel2: TIWLabel;
    iwlTitle: TIWLabel;
    IWLabel4: TIWLabel;
    IWLabel5: TIWLabel;
    IWLabel6: TIWLabel;
    IWLabel7: TIWLabel;
    IWHRule1: TIWHRule;
    IWHRule2: TIWHRule;
    IWButton1: TIWButton;
    iwbEdit: TIWButton;
    iwbCancel: TIWButton;
    iwmComments: TIWMemo;
    IWLabel3: TIWLabel;
    procedure iwbEditClick(Sender: TObject);
    procedure iwbCancelClick(Sender: TObject);
  private
    FEditMode: TEditMode;
    FCorpId: Integer;
    procedure SetEditMode(const Value: TEditMode);
    procedure SetCorpId(const Value: Integer);
  public
    property EditMode: TEditMode read FEditMode write SetEditMode;
    property CorpId: Integer read FCorpId write SetCorpId; //公司ID
  end;

implementation
{$R *.dfm}

uses
  ServerController, DatamoduleUnit;

const
  sCorpIdNotFound = '无法找到相应的公司信息!';

procedure TformEditCorp.SetCorpId(const Value: Integer);
begin
  FCorpId := Value;
  //更新界面上的编辑框
  if not dmHR.badoCorp.Locate('CorpId', Value, []) then
    raise Exception.Create(sCorpIdNotFound);
  with dmHR.badoCorp do
  begin
    iweChnName.Text := FieldByName('ChnName').AsString;
    iweEngName.Text := FieldByName('EngName').AsString;
    iwePhone.Text := FieldByName('Phone').AsString;
    iweFax.Text := FieldByName('Fax').AsString;
    iwmChnInfo.Lines.Text := FieldByName('ChnInfo').AsString;
    iwmEngInfo.Lines.Text := FieldByName('EngInfo').AsString;
    iwmComments.Lines.Text := FieldByName('Comments').AsString;
  end;
end;

procedure TformEditCorp.SetEditMode(const Value: TEditMode);
begin
  FEditMode := Value;
  case FEditMode of
    emEdit: iwlTitle.Caption := '编辑公司信息';
    emInsert:
      begin
        iwbEdit.Caption := '增加公司';
        iweChnName.Text := '';
        iweEngName.Text := '';
        iwePhone.Text := '';
        iweFax.Text := '';
        iwmChnInfo.Lines.Text := '';
        iwmEngInfo.Lines.Text := '';
        iwmComments.Lines.Text := '';
      end;
  end;
end;

procedure TformEditCorp.iwbEditClick(Sender: TObject);
var
  S:String;
begin
  case EditMode of
    emEdit:
      with dmHR do
      begin
        adocHR.BeginTrans;
        try
          //这里直接用Sql来实现的
          adocEdit.CommandText :=
            format('Update TblCorp Set ChnName=''%s'', EngName=''%s'', Fax=''%s'', Phone=''%s'', ChnInfo=''%s'', EngInfo=''%s'', Comments=''%s'' Where CorpID=%d', [iweChnName.text, iweEngName.text, iweFax.Text, iwePhone.Text,
            iwmChninfo.Lines.Text, iwmEngInfo.Lines.Text, iwmComments.Lines.Text, CorpId]);
          adocEdit.Execute;
          adocHR.CommitTrans;
          badoCorp.Refresh;
        except
          adocHR.RollbackTrans;
        end;
      end;
    emInsert:
      begin
        //todo:判断其他字段的值
        if Trim(iweChnName.Text) = '' then
        begin
          WebApplication.ShowMessage('中文名称不能为空');
          Exit;
        end;
        with dmHR do
        begin
          adocHR.BeginTrans;
          try
            //这里直接用Sql来实现的
            adocEdit.CommandText :=
              format('Insert Into TblCorp (ChnName,EngName,Phone, Fax, ChnInfo, EngInfo, Comments) Values(''%s'', ''%s'', ''%s'', ''%s'', ''%s'', ''%s'', ''%s'')', [iweChnName.text, iweEngName.text, iwePhone.Text, iweFax.Text,
                iwmChninfo.Lines.Text, iwmEngInfo.Lines.Text,
                iwmComments.Lines.Text, CorpId]);
            S:=adocEdit.CommandText;
            adocEdit.Execute;
            adocHR.CommitTrans;
            badoCorp.Requery;
          except
            adocHR.RollbackTrans;
          end;
        end;
      end;
  end;
  hide;
end;

procedure TformEditCorp.iwbCancelClick(Sender: TObject);
begin
  hide;
end;

end.

⌨️ 快捷键说明

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