【delphi开源代码栏目提醒】:文章导读:在新的一年中,各位网友都进入紧张的学习或是工作阶段。网学会员整理了delphi开源代码-dutyinfo.pas的相关内容供大家参考,祝大家在新的一年里工作和学习顺利!
unit dutyinfo;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, frame, StdCtrls,ExtCtrls, Buttons, Grids, DBGrids,
DB;
type
Tf_dutyinfo = class(Tf_frame)
DBGrid1: TDBGrid;
Panel1: TGroupBox;
Label1: TLabel;
Label2: TLabel;
Add: TBitBtn;
Cancel: TBitBtn;
Update: TBitBtn;
Delete: TBitBtn;
DutySource: TDataSource;
Dutyname: TEdit;
Memo: TEdit;
procedure DutynameKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure AddClick(Sender: TObject);
procedure CancelClick(Sender: TObject);
procedure UpdateClick(Sender: TObject);
procedure DeleteClick(Sender: TObject);
procedure DBGrid1DblClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
Procedure ClearEdit;//清空编辑框中的文本
Function TextIsNull: Boolean;//判断编辑框中的文本是否为空
Procedure Editvalue;//将数据集中的数据显示在编辑框中
end;
var
f_dutyinfo: Tf_dutyinfo;
implementation
uses data;
{$R *.dfm}
//自定义过程用于清空编辑框中的文本
procedure Tf_dutyinfo.ClearEdit;
var
i: Integer;
begin
For i := 0 to Panel1.ControlCount-1 do
if Panel1.Controls[i]is TEdit then
TEdit(Panel1.Controls[i]).Clear;
Memo.Text := '空';
end;
procedure Tf_dutyinfo.DutynameKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
inherited;
if Key = vk_Return then
FindNext(True);
end;
//将当前记录数据显示在编辑框中
procedure Tf_dutyinfo.Editvalue;
begin
with t_data.Query1 do
begin
Dutyname.Text := Trim(FieldByName('Dutyname').AsString);
Memo.Text := Trim(FieldByName('Memo').AsString);
end;
end;
//判断编辑框数据是否为空
function Tf_dutyinfo.TextIsNull: Boolean;
var
i: Integer;
begin
Result := False;
For i := 0 to Panel1.ControlCount-1 do
if Panel1.Controls[i] is TEdit then
begin
if Trim(TEdit(Panel1.Controls[i]).Text)='' then
begin
Result := True;
Break;
end;
end;
end;
//处理单击按钮的单击事件
procedure Tf_dutyinfo.AddClick(Sender: TObject);
begin
inherited;
if TextIsNull = False then
begin
With t_data.Query2 do //判断职务是否重复
begin
CLose;
SQL.Clear;
SQL.Add('Select * from tb_dutyinfo where dutyname = :name');
Parameters.ParamByName('name').Value := Trim(dutyname.Text);
Open;
end;
if t_data.Query2.RecordCount>0 then
begin
Application.MessageBox('该职务已经存在,请重新输入.','提示',64);
Dutyname.SelectAll;
Dutyname.SetFocus;
Exit;
end;
Try
with t_data.Add1 do //添加职务信息
begin
Close;
SQL.Clear;
SQL.Add('Insert into tb_dutyinfo Values (:dutyname,:memo)');
Parameters.ParamByName('dutyname').Value := Trim(Dutyname.Text);
Parameters.ParamByName('memo').Value := Trim(Memo.Text);
ExecSQL;
end;
Application.MessageBox('操作成功.','提示',64);
Cancel.Click;
Except
On E: Exception do
ShowMessage(E.Message);
End;
end
else
begin
Application.MessageBox('职务信息不能为空.','提示',64);
end;
end;
//处理取消按钮的单击事件
procedure Tf_dutyinfo.CancelClick(Sender: TObject);
begin
inherited;
ClearEdit;//清空编辑框中的文本
With t_data.Query1 do
begin
CLose;
SQL.Clear;
SQL.Add('Select * from tb_dutyinfo');
Open;
end;
if t_data.Query1.RecordCount>0 then
DutySource.DataSet := t_data.Query1
else
begin
t_data.Query1.Close;
DutySource.DataSet := Nil;
end;
end;
//处理修改按钮的单击事件
procedure Tf_dutyinfo.UpdateClick(Sender: TObject);
begin
inherited;
if t_data.Query1.Active then //判断是否有可修改的数据
begin
if TextIsNull = False then
begin
if Application.MessageBox(Pchar('确实要修改职务名称为: '+t_data.Query1.FieldByName('Dutyname').AsString+' 的职