📄 storageinfo.~pas
字号:
unit storageinfo;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, baseform, StdCtrls, DB, Grids, DBGrids, ExtCtrls;
type
Tf_storage = class(Tf_baseform)
Label1: TLabel;
Panel1: TPanel;
Label2: TLabel;
Label3: TLabel;
Storage: TEdit;
Shortname: TEdit;
Panel3: TPanel;
Add: TButton;
Update: TButton;
Delete: TButton;
Cancel: TButton;
Grid1: TDBGrid;
Panel2: TPanel;
Label6: TLabel;
Label7: TLabel;
Field: TComboBox;
Value: TEdit;
Query: TButton;
Source1: TDataSource;
procedure StorageKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure CancelClick(Sender: TObject);
procedure AddClick(Sender: TObject);
procedure UpdateClick(Sender: TObject);
procedure DeleteClick(Sender: TObject);
procedure QueryClick(Sender: TObject);
procedure Grid1CellClick(Column: TColumn);
procedure FormShow(Sender: TObject);
private
{ Private declarations }
public
Function EditIsNull: Boolean;//判断编辑框是否为空
Function DepotIsMore(Depotname: String): Boolean;
{ Public declarations }
end;
var
f_storage: Tf_storage;
implementation
uses data;
{$R *.dfm}
procedure Tf_storage.StorageKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
inherited;
if Key = vk_Return then
FindNext(True);
end;
procedure Tf_storage.CancelClick(Sender: TObject);
var
i: Integer;
begin
inherited;
For i :=0 to Panel1.ControlCount-1 do
if Panel1.Controls[i] is TEdit then
TEdit(Panel1.Controls[i]).Clear ;
With t_Data.Storage do
begin
Close;
SQL.Clear;
SQL.Add('Select * From tb_depotinfo');
Open;
end;
if t_data.Storage.RecordCount>0 then
Source1.DataSet := t_data.Storage
else
begin
Source1.DataSet := Nil;
t_data.Storage.Close;
end;
end;
function Tf_storage.EditIsNull: Boolean;
var
i: Integer;
begin
Result := False;
For i := 0 to Panel1.ControlCount-1 do
if Panel1.Controls[i]is TEdit then
if Trim(TEdit(Panel1.Controls[i]).Text)= '' then
begin
Result := True;
Break;
end;
end;
function Tf_storage.DepotIsMore(Depotname: String): Boolean;
begin
Result := False;
With t_data.Query1 do
begin
Close;
SQL.Clear;
SQL.Add('select * From tb_depotinfo where depotname = :name');
Parameters.ParamByName('name').Value := Trim(depotname);
Open;
end;
if t_data.Query1.RecordCount>0 then
Result := True;
t_data.Query1.Close;
end;
procedure Tf_storage.AddClick(Sender: TObject);
begin
inherited;
if EditIsNull = False then
begin
if DepotIsMore(Trim(Storage.Text)) = False then
begin
Try
With t_data.Insert1 do
begin
Close;
SQL.Clear;
SQL.Add('Insert into tb_depotinfo Values(:name,:shortname)');
Parameters.ParamByName('name').Value := Trim(Storage.Text);
Parameters.ParamByName('shortname').Value := Trim(Shortname.Text);
ExecSQL;
end;
Application.MessageBox('操作成功.','提示',64);
Except
Application.MessageBox('操作失败.','提示',64);
End;
Cancel.Click;
end
else
begin
Application.MessageBox('该仓库已经存在','提示',64);
Storage.SetFocus;
end;
end
else
Application.MessageBox('仓库信息不能为空.','提示',64);
end;
procedure Tf_storage.UpdateClick(Sender: TObject);
begin
inherited;
if t_data.Storage.Active then
begin
if EditIsNull = False then
begin
if Application.MessageBox('确实要修改当前仓库信息吗?','提示',mb_yesno)= id_yes then
begin
if Trim(Storage.Text)<>Trim(t_data.Storage.FieldByName('depotname').AsString) then
begin
With t_data.Query1 do
begin
Close;
SQL.Clear;
SQL.Add('select * from tb_depotinfo where depotname = :name');
Parameters.ParamByName('name').Value := Trim(Storage.Text);
Open;
end;
if t_data.Query1.RecordCount>0 then
begin
Application.MessageBox('该仓库已经存在.','提示',64);
Exit;
end;
end;
Try
With t_data.Update1 do
begin
Close;
SQL.Clear;
SQL.Add('Update tb_depotinfo set depotname = :name,shortname = :shortname where depotname = :oldname');
Parameters.ParamByName('name').Value := Trim(Storage.Text);
Parameters.ParamByName('shortname').Value := Trim(shortname.Text);
Parameters.ParamByName('oldname').Value := Trim(t_data.Storage.FieldByName('depotname').AsString);
ExecSQL;
end;
Application.MessageBox('操作成功.','提示',64);
Except
Application.MessageBox('操作失败.','提示',64);
End;
Cancel.Click;
end;
end
else
Application.MessageBox('仓库信息不能为空.','提示',64);
end
else
Application.MessageBox('当前没有可修改的信息.','提示',64);
end;
procedure Tf_storage.DeleteClick(Sender: TObject);
begin
inherited;
if t_data.Storage.Active then
begin
if Application.MessageBox('确实要删除当前仓库信息吗?','提示',mb_yesno)= ID_Yes then
begin
Try
t_data.Storage.Delete;
Cancel.Click;
Application.MessageBox('删除成功.','提示',64);
Except
Application.MessageBox('操作失败.','提示',64);
End;
end;
end
else
Application.MessageBox('当前没有可删除的信息.','提示',64);
end;
procedure Tf_storage.QueryClick(Sender: TObject);
begin
inherited;
if (Field.Text<>'')and(Trim(Value.Text)<>'')then
begin
With t_data.Storage do
begin
Close;
SQL.Clear;
SQL.Add('select * From tb_depotinfo where ');
if Field.ItemIndex =0 then
SQL.Add('depotname = :FieldValue')
else
SQL.Add('shortname = :FieldValue');
Parameters.ParamByName('FieldValue').Value := Trim(Value.Text);
Open;
end;
if t_data.Storage.RecordCount<1 then
begin
Application.MessageBox('没有找到符合条件的记录.','提示',64);
Cancel.Click;
end;
end;
end;
procedure Tf_storage.Grid1CellClick(Column: TColumn);
begin
inherited;
if Source1.DataSet.active then
begin
Storage.Text := Trim(Source1.DataSet.FieldByName('depotname').AsString);
Shortname.Text := Trim(Source1.DataSet.FieldByName('Shortname').AsString);
end;
end;
procedure Tf_storage.FormShow(Sender: TObject);
begin
inherited;
Cancel.Click;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -