📄 cformedithuman.pas
字号:
{-----------------------------------------------------------------------------
Unit Name: CFormEditHuman
Author: hubdog(陈省)
Purpose: 人员信息编辑单元
BeginDate: 2002-7-1
History:
-----------------------------------------------------------------------------}
unit CFormEditHuman;
{PUBDIST}
interface
//todo:考虑将上传的文件存到字段中?
uses
IWAppForm, IWApplication, IWTypes, IWCompButton, IWHTMLControls, SysUtils,
IWCompLabel, IWCompMemo, Classes, Controls, IWControl, IWCompEdit,
IWCompListbox, CFormEditCorp, SWSystem, IWGrids, Graphics, Variants;
type
TformEditHuman = class(TIWAppForm)
iweChnName: TIWEdit;
IWLabel1: TIWLabel;
IWLabel2: TIWLabel;
iwlTitle: TIWLabel;
iwrIWHRule1: TIWHRule;
iwrIWHRule2: TIWHRule;
IWButton1: TIWButton;
iwbEdit: TIWButton;
iwbCancel: TIWButton;
iwmEduInfo: TIWMemo;
IWLabel3: TIWLabel;
iwcSex: TIWComboBox;
iweAge: TIWEdit;
IWLabel6: TIWLabel;
iwcCountry: TIWComboBox;
IWLabel7: TIWLabel;
IWLabel8: TIWLabel;
IWLabel9: TIWLabel;
iweWorkAge: TIWEdit;
IWLabel10: TIWLabel;
iweEmail: TIWEdit;
IWLabel11: TIWLabel;
iwePhone: TIWEdit;
iweMobile: TIWEdit;
IWLabel4: TIWLabel;
IWLabel12: TIWLabel;
iwcEngLevel: TIWComboBox;
IWLabel5: TIWLabel;
iwmPrjInfo: TIWMemo;
IWLabel13: TIWLabel;
IWLabel14: TIWLabel;
iwrIWHRule3: TIWHRule;
iwcCorp: TIWComboBox;
IWLabel15: TIWLabel;
iwcEduLevel: TIWComboBox;
iwfResume: TIWFile;
iwbUpload: TIWButton;
iwlResume: TIWLink;
iwgTech: TIWGrid;
iwcTech: TIWComboBox;
iwcTechLevel: TIWComboBox;
IWLabel16: TIWLabel;
iwbAdd: TIWButton;
procedure iwbEditClick(Sender: TObject);
procedure iwbCancelClick(Sender: TObject);
procedure IWAppFormCreate(Sender: TObject);
procedure iwlResumeClick(Sender: TObject);
procedure iwbUploadClick(Sender: TObject);
procedure iwgTechRenderCell(ACell: TIWGridCell; const ARow,
AColumn: Integer);
procedure iwgTechCellClick(const ARow, AColumn: Integer);
procedure iwbAddClick(Sender: TObject);
private
FEditMode: TEditMode;
FHId: Integer;
procedure SetEditMode(const Value: TEditMode);
function ValidateInput: Boolean;
function GetAge: Integer;
function GetWorkAge: Integer;
function GetCorpId: Integer;
function GetSex: string;
function GetCountry: string;
function GetEduLevel: string;
function GetEngLevel: string;
function GetResume: string;
procedure SetHId(const Value: Integer);
procedure InsertHumanTech;
procedure DelHumanTech;
public
FCorpList,
FSexList,
FCountryList,
FEduLevelList,
FEngLevelList,
FTechList,
FTechLevelList: TStrings;
function InsertRecord: Boolean;
function EditRecord: Boolean;
property EditMode: TEditMode read FEditMode write SetEditMode;
property Age: Integer read GetAge;
property WorkAge: Integer read GetWorkAge;
property CorpID: Integer read GetCorpId;
property Sex: string read GetSex;
property Country: string read GetCountry;
property EduLevel: string read GetEduLevel;
property EngLevel: string read GetEngLevel;
property Resume: string read GetResume;
property HId: Integer read FHId write SetHId;
end;
THumanTech = class(TPersistent)
private
FTechCode: Integer;
FTechLevel: Integer;
procedure SetTechCode(const Value: Integer);
procedure SetTechLevel(const Value: Integer);
published
property TechCode: Integer read FTechCode write SetTechCode;
property TechLevel: Integer read FTechLevel write SetTechLevel;
end;
implementation
{$R *.dfm}
uses
ServerController, DatamoduleUnit, CWebUtils;
{ TformEditHuman }
//function GetComboBoxValue(AComboBox: TIWComboBox): string;
//begin
// if AComboBox.ItemIndex = -1 then
// raise Exception.Create('列表索引为-1,无法获取相应的值');
// Result := AComboBox.Items.Values[AComboBox.Items.Names[AComboBox.ItemIndex]];
//end;
procedure TformEditHuman.SetEditMode(const Value: TEditMode);
begin
FEditMode := Value;
case FEditMode of
emEdit:
begin
iwlTitle.Caption := '编辑人员信息';
end;
emInsert:
begin
iwbEdit.Caption := '增加人员';
iweChnName.Text := '';
iweAge.Text := '';
iweWorkAge.Text := '';
iwePhone.Text := '';
iweMobile.Text := '';
iweEmail.Text := '';
iwcSex.ItemIndex := 0;
iwcCountry.ItemIndex := 0;
iwcCorp.ItemIndex := 0;
iwcEduLevel.ItemIndex := 0;
iwcEngLevel.ItemIndex := 0;
iwcSex.ItemIndex := 0;
iwcCountry.ItemIndex := 0;
iwmEduInfo.Lines.Text := '';
iwmPrjInfo.Lines.Text := '';
iwlResume.Caption := '无';
iwgTech.RowCount := 1;
end;
end;
end;
procedure TformEditHuman.iwbEditClick(Sender: TObject);
var
EditResult: Boolean;
begin
EditResult := False;
case EditMode of
emEdit: EditResult := EditRecord;
emInsert: EditResult := InsertRecord;
end;
if EditResult then
hide;
end;
procedure TformEditHuman.iwbCancelClick(Sender: TObject);
begin
hide;
end;
function TformEditHuman.EditRecord: Boolean;
begin
Result := False;
//编辑记录
if not ValidateInput then
Exit;
with dmHR do
begin
adocHR.BeginTrans;
try
//这里直接用Sql来实现的
//Todo:部分Memo字段应该采用 参数化来实现否则会有问题
DelHumanTech;
adocEdit.CommandText :=
format('Update TblHuman Set ' +
'CorpID=%d,ChnName=''%s'',SexCode=''%s'', Age=%d, CountryCode=''%s'',EduLevelCode=''%s'', WorkAge=%d,Email=''%s'',Phone=''%s'', Mobile=''%s'',EngLevelCode=''%s'',Education=''%s'',PrjInfo=''%s'',Resume=''%s'' Where HID=%d',
[CorpID, iweChnName.text, Sex, Age, Country, EduLevel,
WorkAge, iweEmail.Text, iwePhone.Text, iweMobile.Text, EngLevel,
iwmEduInfo.Lines.Text, iwmPrjInfo.Lines.Text, Resume, HID]);
// S := adocEdit.CommandText;
//CodeSite.SendString('CommandText', adocEdit.CommandText);
adocEdit.Execute;
InsertHumanTech;
adocHR.CommitTrans;
badoHuman.Refresh;
Result := True;
except
adocHR.RollbackTrans;
end;
end;
end;
function TformEditHuman.InsertRecord: Boolean;
begin
//todo:判断其他字段的值
Result := False;
if not ValidateInput then
Exit;
//inserthumantech;
with dmHR do
begin
adocHR.BeginTrans;
try
//这里直接用Sql来实现的
//Todo:部分Memo字段应该采用 参数化来实现否则会有问题
adocEdit.CommandText :=
format('Insert Into TblHuman' +
'(CorpID,ChnName,SexCode, Age, CountryCode,EduLevelCode, WorkAge,Email,Phone, Mobile,EngLevelCode,Education,PrjInfo,Resume)' + ' Values'
+
'(%d,''%s'',''%s'', %d , ''%s'' , ''%s'', %d, ''%s'',''%s'',''%s'',''%s'', ''%s'',''%s'', ''%s'' )',
[CorpID, iweChnName.text, Sex, Age, Country, EduLevel,
WorkAge, iweEmail.Text, iwePhone.Text, iweMobile.Text, EngLevel,
iwmEduInfo.Lines.Text, iwmPrjInfo.Lines.Text, Resume]);
// S := adocEdit.CommandText;
//CodeSite.SendString('CommandText', adocEdit.CommandText);
adocEdit.Execute; //这句话执行后应该返回CorpID和HID
badohuman.requery;
if badoHuman.Locate('CorpID;ChnName', VarArrayOf([CorpID,
iweChnName.Text]), []) then
FHId := badoHuman.FieldByName('HID').AsInteger;
insertHumanTech;
adocHR.CommitTrans;
badoHuman.Requery;
Result := True;
except
adocHR.RollbackTrans;
end;
end;
end;
procedure TformEditHuman.IWAppFormCreate(Sender: TObject);
begin
with dmHR do
begin
//初始化公司下拉编辑框中的内容
FCorpList := GetDataDicList(badoCorp, 'CorpID', 'ChnName');
FillValueToCombo(iwcCorp, FCorpList);
//初始化性别列表
FSexList := GetDataDicList(badoSex, 'SexCode', 'SexName');
FillValueToCombo(iwcSex, FSexList);
//初始化国家列表
FCountryList := GetDataDicList(badoCountry, 'CountryCode', 'CountryName');
FillValueToCombo(iwcCountry, FCountryList);
//初始化学历列表
FEduLevelList := GetDataDicList(badoEduLevel, 'EduLevelCode',
'EduLevelName');
FillValueToCombo(iwcEduLevel, FEduLevelList);
//初始化英文水平列表
FEngLevelList := GetDataDicList(badoEngLevel, 'EngLevelCode',
'EngLevelName');
FillValueToCombo(iwcEngLevel, FEngLevelList);
//初始化技术列表
//Todo:考虑以后将初始化列表改造成动态创建Dataset的形式
FTechList := GetDataDicList(badoTech, 'TechCode', 'Name');
FillValueToCombo(iwcTech, FTechList);
//初始化水平列表
FTechLevelList := GetDataDicList(badoTechLevel, 'TechLevel', 'LevelName');
FillValueToCombo(iwcTechLevel, FTechLevelList);
end;
end;
function TformEditHuman.ValidateInput;
begin
Result := False;
if Trim(iweChnName.Text) = '' then
begin
WebApplication.ShowMessage('中文姓名不能为空');
Exit;
end;
if iwcCorp.ItemIndex = -1 then
begin
WebApplication.ShowMessage('必须指定人员所属公司');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -