📄 saleinputfrm.pas
字号:
unit SaleInputFrm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DBCtrls, MainDM, ComCtrls, Grids, DBGrids;
const singlequotes=#39;
type
TSaleInputDlg = class(TForm)
Label1: TLabel;
EdtGoodId: TEdit;
Label2: TLabel;
BtnOK: TButton;
BtnNew: TButton;
StatusBar: TStatusBar;
DBGridDisplay: TDBGrid;
Label3: TLabel;
EdtNum: TEdit;
CBSalesManId: TComboBox;
procedure FormCreate(Sender: TObject);
procedure BtnNewClick(Sender: TObject);
procedure BtnOKClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure CBSalesManIdExit(Sender: TObject);
procedure CBSalesManIdKeyPress(Sender: TObject; var Key: Char);
procedure DBGridDisplayKeyPress(Sender: TObject; var Key: Char);
procedure FormKeyPress(Sender: TObject; var Key: Char);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
procedure RefreshGrid;
public
{ Public declarations }
end;
var
SaleInputDlg: TSaleInputDlg;
implementation
uses CommonFunc;
{$R *.dfm}
procedure TSaleInputDlg.RefreshGrid;
begin
with DMMain.ADOQueryMain do
begin
Close;
SQL.Clear;
SQL.Add('select g.Id as GId,g.Name as GName,g.Type as GType,sr.Num as SNum,');
SQL.Add('g.Price as GPrice,(g.Price*sr.Num) as TotalCash');
SQL.Add('from T_Good g, T_SaleRecord sr');
SQL.Add('where g.Id=sr.GoodId and sr.SalesManId=' + singlequotes + CBSalesManId.Text
+ singlequotes);
Open;
end;
DBGridDisplay.Refresh;
end;
procedure TSaleInputDlg.FormCreate(Sender: TObject);
begin
DBGridDisplay.Columns.Items[0].FieldName := 'GId';
DBGridDisplay.Columns.Items[1].FieldName := 'GName';
DBGridDisplay.Columns.Items[2].FieldName := 'GType';
DBGridDisplay.Columns.Items[3].FieldName := 'SNum';
DBGridDisplay.Columns.Items[4].FieldName := 'GPrice';
DBGridDisplay.Columns.Items[5].FieldName := 'TotalCash';
end;
procedure TSaleInputDlg.BtnNewClick(Sender: TObject);
begin
EdtGoodId.Clear;
EdtNum.Clear;
EdtGoodId.SetFocus;
end;
procedure TSaleInputDlg.BtnOKClick(Sender: TObject);
var
LGoodId, LSalesManId: string;
LNum: integer;
//LIsExist: boolean;
begin
if not (CheckInput(EdtGoodId) and CheckInput(EdtNum)) then
Exit;
LGoodId := Trim(EdtGoodId.Text);
LSalesManId := Trim(CBSalesManId.Text);
LNum := StrToInt(Trim(EdtNum.Text));
DMMain.ADOQueryMain.Close;
DMMain.ADOQueryMain.SQL.Clear;
DMMain.ADOQueryMain.SQL.Add('select id from T_Good ');
DMMain.ADOQueryMain.SQL.Add('where id=:id');
DMMain.ADOQueryMain.Parameters.ParamByName('id').Value := EdtGoodId.Text;
DMMain.ADOQueryMain.Open;
if DMMain.ADOQueryMain.RecordCount > 0 then
begin
LCShowMessage('编号已经存在!');
DMMain.ADOTSaleRecord.Cancel;
Exit;
end;
DMMain.ADOTSaleRecord.Open;
DMMain.ADOTSaleRecord.Append;
DMMain.ADOTSaleRecord.FieldByName('GoodId').AsString :=
LGoodId;
DMMain.ADOTSaleRecord.FieldByName('SalesManId').AsString :=
LSalesManId;
DMMain.ADOTSaleRecord.FieldByName('SaleDate').AsDateTime :=
Now();
DMMain.ADOTSaleRecord.FieldByName('Num').AsInteger := LNum;
DMMain.ADOTSaleRecord.Post;
RefreshGrid;
end;
procedure TSaleInputDlg.FormShow(Sender: TObject);
begin
RefreshGrid;
CBSalesManId.Clear;
DMMain.ADOTSalesMan.Open;
DMMain.ADOTSalesMan.First;
DMMain.ADOTSalesMan.DisableControls;
while not DMMain.ADOTSalesMan.Eof do
begin
CBSalesManId.Items.Add(DMMain.ADOTSalesMan.FieldByName('Id').AsString);
DMMain.ADOTSalesMan.Next;
end;
DMMain.ADOTSalesMan.EnableControls;
end;
procedure TSaleInputDlg.CBSalesManIdExit(Sender: TObject);
begin
DMMain.ADOTSalesMan.Open;
DMMain.ADOTSalesMan.First;
if DMMain.ADOTSalesMan.Locate('Id', (Sender as TCustomComboBox).SelText, []) then
begin
StatusBar.SimpleText := DMMain.ADOTSalesMan.FieldByName('Name').AsString;
StatusBar.Refresh;
end;
end;
procedure TSaleInputDlg.CBSalesManIdKeyPress(Sender: TObject;
var Key: Char);
begin
Key := #0;
end;
procedure TSaleInputDlg.DBGridDisplayKeyPress(Sender: TObject;
var Key: Char);
begin
Key := #0;
end;
procedure TSaleInputDlg.FormKeyPress(Sender: TObject; var Key: Char);
begin
if Key = #13 then
Perform(WM_NEXTDLGCTL, 0, 0);
end;
procedure TSaleInputDlg.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
Action := caFree;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -