📄 bmgzxm.pas
字号:
unit BMGZXM;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Mask, DBCtrls, ExtCtrls, Grids, DBGrids, Buttons, ComCtrls,
ActnList, Spin;
type
TFrmBmGzxm = class(TForm)
GroupBox1: TGroupBox;
DBGrid1: TDBGrid;
Panel2: TPanel;
BtnAppend: TBitBtn;
BtnDelete: TBitBtn;
BtnEdit: TBitBtn;
BtnSure: TBitBtn;
BtnCancel: TBitBtn;
BtnExit: TBitBtn;
DBNavigator1: TDBNavigator;
Panel3: TPanel;
Label1: TLabel;
EditXmmc: TEdit;
CbGsGzxm: TComboBox;
Label3: TLabel;
Panel1: TPanel;
Label4: TLabel;
CbBm: TComboBox;
procedure FormShow(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure BtnAppendClick(Sender: TObject);
procedure BtnEditClick(Sender: TObject);
procedure BtnDeleteClick(Sender: TObject);
procedure BtnSureClick(Sender: TObject);
procedure BtnCancelClick(Sender: TObject);
procedure DBNavigator1Click(Sender: TObject; Button: TNavigateBtn);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure CbBmChange(Sender: TObject);
private
MyGsGzxm : TStrings;
MyDmBmNo : Array of String;
procedure EditToTable();
public
InputStatus : string;
procedure TableToEdit();
procedure ShowMyButton();
end;
var
FrmBmGzxm: TFrmBmGzxm;
implementation
uses DGSDM, MyCommon;
{$R *.DFM}
procedure TFrmBmGzxm.FormShow(Sender: TObject);
var
i:integer;
begin
CbGsGzxm.Items.Clear;
With DM_GSGL do
begin
if QryTemp.Active=true then
QryTemp.Close;
QryTemp.SQL.Clear;
QryTemp.SQL.Add('select * from 公司工作项目');
QryTemp.Open;
MyGsGzxm := TStringList.Create;
while (not QryTemp.Eof) do
begin
CbGsGzxm.Items.Add(QryTemp.FieldByName('公司工作项目名称').AsString);
MyGsGzxm.Add(QryTemp.FieldByName('公司工作项目编号').AsString);
QryTemp.Next;
end;
end;
if (CbGsGzxm.Items.Count > 0) Then
CbGsGzxm.ItemIndex := 0;
with DM_GSGL do
begin
if QryTemp.Active=true then
QryTemp.Close;
QryTemp.SQL.Clear;
QryTemp.SQL.Add('select 部门编号,部门名称');
QryTemp.SQL.Add('from 部门信息 where 部门编号 in(');
QryTemp.SQL.Add('select distinct substring( 部门编号,1,2) from 部门信息');
QryTemp.SQL.Add('where 工时汇报员工号 like :pgh)');
QryTemp.ParamByName('pgh').asstring:=username;
QryTemp.Open;
SetLength(MyDmBmNo,QryTemp.RecordCount);
i := 0;
while (not QryTemp.Eof) do
begin
MyDmBmNo[i] := QryTemp.FieldByName('部门编号').AsString;
CbBm.Items.Add(QryTemp.FieldByName('部门名称').AsString);
QryTemp.Next;
i := i+1;
end;
end;
if (CbBm.Items.Count > 0) Then
CbBm.ItemIndex := 0;
InputStatus := '浏览';
CbBmChange(Sender);
TableToEdit;
end;
procedure TFrmBmGzxm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if (DM_GSGL.QryBmGzxm.Active = True) Then
DM_GSGL.QryBmGzxm.Close;
if (DM_GSGL.QryTemp.Active = True) Then
DM_GSGL.QryTemp.Close;
end;
procedure TFrmBmGzxm.BtnAppendClick(Sender: TObject);
begin
InputStatus := '增加';
ShowMyButton;
//初始化编辑框
if CbGsGzxm.Items.Count>=0 then
CbGsGzxm.ItemIndex := 0
else
CbGsGzxm.ItemIndex := -1;
// 输入焦点定位
CbGsGzxm.SetFocus;
end;
procedure TFrmBmGzxm.BtnEditClick(Sender: TObject);
begin
InputStatus := '修改';
ShowMyButton;
// 输入焦点定位
CbGsGzxm.SetFocus;
end;
procedure TFrmBmGzxm.BtnDeleteClick(Sender: TObject);
begin
with DM_GSGL do
begin
if QryTemp.Active=true then
QryTemp.Close;
QryTemp.SQL.Clear;
QryTemp.SQL.Add('select 部门工作项目编号 from 每日工时');
QryTemp.SQL.Add('where 部门工作项目编号=:pbh');
QryTEmp.ParamByName('pbh').asstring:=QryBmGzxm.FieldByName('部门工作项目编号').AsString;
QryTemp.Open;
if not QryTemp.Eof then
begin
MessageDlg('每日工时中有该部门工作项目,不能删除该工作项目。',mtError, [mbYes],0);
exit;
end;
end;
if MessageDlg('确认删除该工作项目吗?',mtConfirmation, [mbYes, mbNo], 0) = mrYes then
begin
DM_GSGL.QryBmGzxm.Delete;
DM_GSGL.QryBmGzxm.commitUpdates;
end;
end;
procedure TFrmBmGzxm.BtnSureClick(Sender: TObject);
var
tmpstring:string;
begin
if cbbm.ItemIndex=-1 then
begin
MessageDlg('请选择部门!',mtError, [mbYes],0);
cbbm.SetFocus;
exit;
end;
if cbgsgzxm.ItemIndex=-1 then
begin
MessageDlg('请选择工作项目!',mtError, [mbYes],0);
cbgsgzxm.SetFocus;
exit;
end;
tmpstring:=trim(Editxmmc.Text);
if (Length(tmpstring)=0) then
begin
MessageDlg('项目名称不能为空!',mtError, [mbYes],0);
Editxmmc.SetFocus;
exit;
end;
with DM_GSGL do
begin
if QryTemp.Active=true then
QryTemp.Close;
QryTemp.SQL.Clear;
QryTemp.SQL.Add('select 部门工作项目编号');
QryTemp.SQL.Add('from 部门工作项目 where 部门工作项目名称=:pxmmc and 部门编号=:pbmbh');
QryTemp.ParamByName('pxmmc').asstring:=tmpstring;
QryTemp.ParamByName('pbmbh').asstring:=MyDmBmNo[CbBm.ItemIndex];
QryTemp.Open;
if (not QryTemp.Eof) then
begin
if (InputStatus = '增加') then
begin
MessageDlg('该项目名称已经使用!.',mtInformation, [mbYes], 0);
Editxmmc.SetFocus;
Exit;
end
else
begin
if tmpstring<>trim(QryBmGzxm.FieldByName('部门工作项目名称').AsString) then
begin
MessageDlg('该项目名称已经使用!.',mtInformation, [mbYes], 0);
Editxmmc.SetFocus;
Exit;
end;
end;
end;
end;
if (InputStatus = '增加') then
begin
DM_GSGL.QryBmGzxm.Append;
EditToTable;
DM_GSGL.QryBmGzxm.Post;
end;
if (InputStatus = '修改') then
begin
DM_GSGL.QryBmGzxm.Edit;
EditToTable;
DM_GSGL.QryBmGzxm.Post;
end;
DM_GSGL.QryBmGzxm.CommitUpdates;
InputStatus := '浏览';
ShowMyButton;
end;
procedure TFrmBmGzxm.BtnCancelClick(Sender: TObject);
begin
TableToEdit;
InputStatus := '浏览';
ShowMyButton;
end;
procedure TFrmBmGzxm.DBNavigator1Click(Sender: TObject;
Button: TNavigateBtn);
begin
ShowMyButton;
end;
procedure TFrmBmGzxm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
var
UserSelect : Word;
begin
if (InputStatus <> '浏览') then
begin
UserSelect := MessageDlg('是否保存改动的部门工作项目信息?',mtConfirmation, [mbYes, mbNo, mbCancel],0);
case UserSelect of
mrYes: BtnSureClick(Sender);
mrNo: BtnCancelClick(Sender);
mrCancel: CanClose := False ;
end;
end;
end;
procedure TFrmBmGzxm.ShowMyButton();
begin
if (InputStatus = '浏览') then
begin
//enable or disable Edits
CbGsGzxm.Enabled := False;
EditXmmc.ReadOnly := True;
//Enable or disable Buttons
if CbBm.Items.Count=0 then
begin
BtnAppend.Enabled := False;
BtnEdit.Enabled := False;
BtnDelete.Enabled := False;
end
else
begin
BtnAppend.Enabled := True;
BtnEdit.Enabled := True;
BtnDelete.Enabled := True;
end;
BtnExit.Enabled := True;
if (DM_GSGL.QryBmGzxm.Eof) and (DM_GSGL.QryBmGzxm.Bof=True) then
begin
BtnEdit.Enabled := False;
BtnDelete.Enabled := False;
end;
BtnSure.Enabled := False; //Sure Button
BtnCancel.Enabled := False; //Cancel Button
end
else
begin
//enable or disable Edits
CbGsGzxm.Enabled := True;
EditXmmc.ReadOnly := False;
//enable or disable Buttons
BtnAppend.Enabled := False;
BtnEdit.Enabled := False;
BtnDelete.Enabled := False;
BtnExit.Enabled := False;
BtnSure.Enabled := True; //Sure Button
BtnCancel.Enabled := True; //Cancel Button
end;
end;
procedure TFrmBmGzxm.TableToEdit();
begin
with DM_GSGL do
begin
CbGsGzxm.ItemIndex:=MyGsGzxm.IndexOf(QryBmGzxm.FieldByName('公司工作项目编号').AsString);
EditXmmc.Text := QryBmGzxm.FieldByName('部门工作项目名称').AsString;
end;
end;
procedure TFrmBmGzxm.EditToTable();
begin
with DM_GSGL.QryBmGzxm do
begin
FieldByName('部门编号').AsString := MyDmBmNo[CbBm.ItemIndex];
FieldByName('公司工作项目编号').AsString := MyGsGzxm[CbGsGzxm.ItemIndex];
FieldByName('部门工作项目名称').AsString := EditXmmc.Text;
FieldByName('公司工作项目名称').AsString := CbGsGzxm.Items[CbGsGzxm.ItemIndex];
end;
end;
procedure TFrmBmGzxm.CbBmChange(Sender: TObject);
begin
with DM_GSGL do
begin
if QryBmGzxm.Active=true then
QryBmGzxm.Close;
QryBmGzxm.Prepare;
if CbBm.Items.Count=0 then
QryBmGzxm.ParamByName('pbmbh').AsString:='a'
else
QryBmGzxm.ParamByName('pbmbh').AsString:=MyDmBmNo[CbBm.ItemIndex];
QryBmGzxm.Open;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -