请问这个代码怎么写(100分)

  • 主题发起人 主题发起人 liyaqi123
  • 开始时间 开始时间
L

liyaqi123

Unregistered / Unconfirmed
GUEST, unregistred user!
有3个按钮 是提交/保存/清空
比如进了相同数量的机器台数为2则进货数量为2的时候 先将这两台相同的信息部分录入 点"保存",然后他变成灰色,接着写每台机器的唯一机器号,写第一台的机器号后,点提交,接着写第2台机器号,然后点提交,则 完成一次.点"清空" 则把原来的信息框内的内容清空.
但现在我发现我的这个程序目前实现不够完善.比如,当机器号没填的时候,虽然他提示说,请输入机器号,但他仍然把这台机器给录入了,同时显示"录入完毕",其次,当录入信息完成,点清空时,就不能再次输入了.请高手给出完整代码.我现在把这段代码完整写出来,如下:
unit Unit3;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, DB, DBTables;

type
TForm3 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label4: TLabel;
Label5: TLabel;
ComboBox1: TComboBox;
Edit1: TEdit;
ComboBox2: TComboBox;
DateTimePicker1: TDateTimePicker;
Label6: TLabel;
Edit2: TEdit;
Label3: TLabel;
Label7: TLabel;
Table1: TTable;
DataSource1: TDataSource;
Button1: TButton;
Button2: TButton;
Edit3: TEdit;
Button3: TButton;
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
i:integer;
end;

var
Form3: TForm3;

implementation

{$R *.dfm}

procedure TForm3.FormCreate(Sender: TObject);
var
path:string;
begin
Getdir(0,path);
table1.DatabaseName := path+'/db';
table1.TableName := 'jinhuo';
table1.Active := true;
end;

procedure TForm3.Button2Click(Sender: TObject);
begin
combobox1.Text := '';
edit1.Text := '';
combobox2.Text := '';
edit3.Text := '';
datetimepicker1.Format := '';
end;

procedure TForm3.Button1Click(Sender: TObject);
begin
if edit3.Text = '' then showmessage('数量为空!!请输入数量')
else begin
edit3.Enabled := False;
button1.Enabled := false;
button2.Enabled := false;
button3.Enabled := true;
i := strtoint(edit3.Text);
end;
end;

procedure TForm3.Button3Click(Sender: TObject);
begin
i := i - 1;
if edit2.Text = '' then showmessage('请输入机器号') else
begin
table1.Insert;
table1.FieldByName('机器号').AsString := edit2.Text;
table1.FieldByName('配置').AsString := edit1.Text;
table1.FieldByName('品牌型号').AsString := combobox1.Text;
table1.FieldByName('来源').AsString := combobox2.Text;
table1.FieldByName('进货日期').AsDateTime := datetimepicker1.DateTime;
table1.Post;
edit2.Text:='';
table1.Active;
end;
if i = 0 then
begin
showmessage('进货完毕');
button3.Enabled := false;
button1.Enabled := True;
button2.Enabled := True;
end;
end;

end.
 
这分明就是代工嘛。
 
怎么了,我不会啊,没办法,才求助的啊
 
你把它发给我,我帮你调试一下:
panzichan@vip.sina.com
 
1)在procedure TForm3.FormCreate(Sender: TObject);中添加如下二句
i:=-1;
edit2.text:='';
2)procedure TForm3.Button2Click(Sender: TObject);中也加入前面两句
 
wind_2005 谢谢你 ,但是你的代码我添加进去了,没有作用,但还是谢谢你的帮忙.
 
panzichen 你好,我已经给你发邮件了, 请查收
 
unit Unit3;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, DB, DBTables;

type
TForm3 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label4: TLabel;
Label5: TLabel;
ComboBox1: TComboBox;
Edit1: TEdit;
ComboBox2: TComboBox;
DateTimePicker1: TDateTimePicker;
Label6: TLabel;
Edit2: TEdit;
Label3: TLabel;
Label7: TLabel;
Table1: TTable;
DataSource1: TDataSource;
Button1: TButton;
Button2: TButton;
Edit3: TEdit;
Button3: TButton;
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
i:integer;
end;

var
Form3: TForm3;

implementation

{$R *.dfm}

procedure TForm3.FormCreate(Sender: TObject);
var
path:string;
begin
Getdir(0,path);
table1.DatabaseName := path+'/db';
table1.TableName := 'jinhuo';
table1.Active := true;
end;

procedure TForm3.Button2Click(Sender: TObject);
begin
combobox1.Text := '';
edit1.Text := '';
combobox2.Text := '';
edit3.Text := '';
datetimepicker1.Format := '';
end;

procedure TForm3.Button1Click(Sender: TObject);
begin
if edit3.Text = '' then
begin
showmessage('数量为空!!请输入数量');
exit;
end
else
begin
edit3.Enabled := False;
button1.Enabled := false;
button2.Enabled := false;
button3.Enabled := true;
i := strtoint(edit3.Text);
end;
end;

procedure TForm3.Button3Click(Sender: TObject);
begin
i := i - 1;
if edit2.Text = '' then
begin
showmessage('请输入机器号');
exit;
end
else
begin
table1.Insert;
table1.FieldByName('机器号').AsString := edit2.Text;
table1.FieldByName('配置').AsString := edit1.Text;
table1.FieldByName('品牌型号').AsString := combobox1.Text;
table1.FieldByName('来源').AsString := combobox2.Text;
table1.FieldByName('进货日期').AsDateTime := datetimepicker1.DateTime;
table1.Post;
edit2.Text:='';
table1.Active;
end;
if i = 0 then
begin
showmessage('进货完毕');
button3.Enabled := false;
button1.Enabled := True;
button2.Enabled := True;
end;
end;

end.
 
procedure TForm3.Button3Click(Sender: TObject);
begin
i := i - 1;
if edit2.Text = '' then showmessage('请输入机器号') else
begin
//这里改成 table1.Insert;
Table1.Append;//从末尾添加

table1.FieldByName('机器号').AsString := edit2.Text;
table1.FieldByName('配置').AsString := edit1.Text;
table1.FieldByName('品牌型号').AsString := combobox1.Text;
table1.FieldByName('来源').AsString := combobox2.Text;
table1.FieldByName('进货日期').AsDateTime := datetimepicker1.DateTime;
table1.Post;
edit2.Text:='';
//这句不要 table1.Active;
end;
if i = 0 then
begin
showmessage('进货完毕');
button3.Enabled := false;
button1.Enabled := True;
button2.Enabled := True;
end;
end;
 
多人接受答案了。
 
后退
顶部