U_qxgl_zhsz.pas
上传用户:psxgmh
上传日期:2013-04-08
资源大小:15112k
文件大小:6k
- unit U_qxgl_zhsz;
- interface
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- ComCtrls, ExtCtrls, Grids, DBGrids, StdCtrls, Mask, DBCtrls, Db, DBClient,
- Buttons;
- type
- TfrmQXGL_FZSZ = class(TForm)
- Panel1: TPanel;
- Panel2: TPanel;
- StatusBar1: TStatusBar;
- Panel3: TPanel;
- Panel4: TPanel;
- DS_QXGL_ZHSZ: TDataSource;
- DS_QXGL_ZHNR: TDataSource;
- Label1: TLabel;
- DBedtZh: TDBEdit;
- Label2: TLabel;
- DBedtZBT: TDBEdit;
- Label3: TLabel;
- DBedtZSM: TDBEdit;
- DBGrid: TDBGrid;
- btnInsert: TSpeedButton;
- btnDelete: TSpeedButton;
- btnEdit: TSpeedButton;
- btnCancel: TSpeedButton;
- btnSave: TSpeedButton;
- btnRefresh: TSpeedButton;
- DBNMain: TDBNavigator;
- DBNDetail: TDBNavigator;
- btnFuncs: TSpeedButton;
- procedure FormClose(Sender: TObject; var Action: TCloseAction);
- procedure btnInsertClick(Sender: TObject);
- procedure btnDeleteClick(Sender: TObject);
- procedure btnEditClick(Sender: TObject);
- procedure btnCancelClick(Sender: TObject);
- procedure btnSaveClick(Sender: TObject);
- procedure btnRefreshClick(Sender: TObject);
- procedure btnFuncsClick(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- private
- procedure btn_valid;
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- frmQXGL_FZSZ: TfrmQXGL_FZSZ;
- implementation
- uses U_mainform, U_QXGL_GNSZ, WzglDB;
- {$R *.DFM}
- //当窗体被创建时,打开数据集
- procedure TfrmQXGL_FZSZ.FormCreate(Sender: TObject);
- begin
- with DM do
- begin
- CDS_QXGL_ZHSZ.Active := True;
- CDS_QXGL_ZHNR.Active := True;
- CDS_QXGL_ZHSZ_INDEX.Active := True;
- CDS_QXGL_ZHNR_INDEX.Active := True;
- end;
- end;
- procedure TfrmQXGL_FZSZ.FormClose(Sender: TObject; var Action: TCloseAction);
- begin
- action := cafree;
- FrmQxgl_Fzsz := nil;
- end;
- //按钮有效性,在添加、编辑 和保存、恢复间切换按钮的有效性。
- procedure TfrmQXGL_FZSZ.btn_valid;
- begin
- DBNMain.Enabled := not DBNMain.Enabled;
- btnInsert.enabled := not btnInsert.enabled;
- btnDelete.enabled := not btnDelete.enabled;
- btnEdit.enabled := not btnEdit.enabled;
- btnCancel.enabled := not btnCancel.enabled;
- btnSave.enabled := not btnSave.enabled;
- btnRefresh.enabled := not btnRefresh.enabled;
- btnFuncs.enabled := not btnFuncs.enabled;
- panel1.Enabled := not panel1.Enabled;
- end;
- //添加数据
- procedure TfrmQXGL_FZSZ.btnInsertClick(Sender: TObject);
- begin
- DM.CDS_QXGL_ZHSZ.Insert;
- btn_valid;
- DBedtZh.SetFocus;
- end;
- //删除数据
- procedure TfrmQXGL_FZSZ.btnDeleteClick(Sender: TObject);
- begin
- if DM.CDS_QXGL_ZHSZ.recordcount = 0 then
- begin
- application.messagebox('没有记录可删除', '物资管理系统', mb_iconinformation + mb_defbutton1);
- exit;
- end;
- if application.messagebox('请确认是否删除', '物资管理系统', mb_iconinformation + mb_yesno) = idyes then
- begin
- DM.CDS_QXGL_ZHSZ.delete;
- DM.CDS_QXGL_ZHSZ.ApplyUpdates(0);
- end;
- end;
- //编辑数据
- procedure TfrmQXGL_FZSZ.btnEditClick(Sender: TObject);
- begin
- if DM.CDS_QXGL_ZHSZ.recordcount = 0 then
- begin
- application.messagebox('没有记录可编辑', '物资管理系统', mb_iconinformation + mb_defbutton1);
- exit;
- end;
- DM.CDS_QXGL_ZHSZ.edit;
- btn_valid;
- DBedtZh.setfocus;
- end;
- //恢复数据
- procedure TfrmQXGL_FZSZ.btnCancelClick(Sender: TObject);
- begin
- DM.CDS_QXGL_ZHSZ.Cancel;
- DM.CDS_QXGL_ZHSZ.cancelupdates;
- btn_valid;
- end;
- //保存数据
- procedure TfrmQXGL_FZSZ.btnSaveClick(Sender: TObject);
- var
- vs_zh: string;
- begin
- if DBedtZh.text = '' then
- begin
- application.MessageBox('组号还未输入', '物资管理系统', mb_iconinformation + mb_defbutton1);
- DBedtZh.setfocus;
- exit;
- end;
- //判断组号输入是否重复
- vs_zh := DBedtZh.Text;
- DM.CDS_QXGL_ZHSZ_INDEX.IndexFieldNames := '组号';
- DM.CDS_QXGL_ZHSZ_INDEX.Refresh;
- if DM.CDS_QXGL_ZHSZ.state = dsinsert then //只有当处于添加状态时,检查,因为编辑时,是不让修改组号的。
- begin
- if DM.CDS_QXGL_ZHSZ_INDEX.FindKey([vs_zh]) then
- begin
- application.MessageBox('组号已重复', '物资管理系统', mb_iconinformation + mb_defbutton1);
- DBedtZh.SetFocus;
- exit;
- end;
- end;
- if DBedtZBT.text = '' then
- begin
- application.MessageBox('组标题还未输入', '物资管理系统', mb_iconinformation + mb_defbutton1);
- DBedtZBT.setfocus;
- exit;
- end;
- DM.CDS_QXGL_ZHSZ.Post;
- DM.CDS_QXGL_ZHSZ.applyupdates(0);
- btn_valid;
- end;
- //刷新数据
- procedure TfrmQXGL_FZSZ.btnRefreshClick(Sender: TObject);
- begin
- DM.CDS_QXGL_ZHSZ.Refresh;
- end;
- //设置组号的具体权限
- procedure TfrmQXGL_FZSZ.btnFuncsClick(Sender: TObject);
- var
- i, i1, i2: integer;
- vs_caption: string;
- begin
- if DM.CDS_QXGL_ZHSZ.RecordCount = 0 then
- exit;
- application.CreateForm(TfrmQxgl_Gnb, frmQxgl_Gnb);
- DM.CDS_QXGL_ZHNR_INDEX.Refresh;
- DM.CDS_QXGL_ZHNR_INDEX.filter := '组号=' + '''' + DM.CDS_QXGL_ZHSZ.fieldbyname('组号').asstring + '''';
- DM.CDS_QXGL_ZHNR_INDEX.filtered := true;
- DM.CDS_QXGL_ZHNR_INDEX.IndexFieldNames := '功能项';
- for i := 0 to 4 do
- begin
- for i1 := 0 to frmMain.mainmenu.Items[i].count - 1 do
- begin
- vs_caption := frmMain.mainmenu.items[i].items[i1].caption;
- if not DM.CDS_QXGL_ZHNR_INDEX.FindKey([vs_caption]) then
- frmQxgl_GNB.Srclist.Items.Add(vs_caption);
- for i2 := 0 to frmMain.mainmenu.Items[i].items[i1].count - 1 do
- begin
- vs_caption := frmMain.mainmenu.items[i].items[i1].items[i2].caption;
- if not DM.CDS_QXGL_ZHNR_INDEX.FindKey([vs_caption]) then
- frmQxgl_Gnb.Srclist.Items.Add(vs_caption);
- end;
- end;
- end;
- DM.CDS_QXGL_ZHNR_INDEX.First;
- while not DM.CDS_QXGL_ZHNR_INDEX.eof do
- begin
- frmQxgl_Gnb.Dstlist.items.add(DM.CDS_QXGL_ZHNR_INDEX.fieldbyname('功能项').asstring);
- DM.CDS_QXGL_ZHNR_INDEX.Next;
- end;
- try
- frmQxgl_Gnb.showmodal;
- finally
- frmQxgl_Gnb.free;
- DM.CDS_QXGL_ZHSZ.refresh;
- end;
- end;
- end.