unit Unit11_ruku;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus,unit_kulei, ComCtrls, Grids, DBGrids, StdCtrls, Buttons ,unit_yuanlei, unit_churulei,unit_wulei,unit_cunlei;type
TForm11 = class(TForm)
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
ComboBox1: TComboBox;
Label1: TLabel;
Edit1: TEdit;
ComboBox2: TComboBox;
Label2: TLabel;
ComboBox3: TComboBox;
Label3: TLabel;
Label4: TLabel;
ComboBox4: TComboBox;
Label5: TLabel;
Label6: TLabel;
DateTimePicker1: TDateTimePicker;
Label7: TLabel;
ComboBox5: TComboBox;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
BitBtn3: TBitBtn;
BitBtn4: TBitBtn;
DBGrid1: TDBGrid;
PopupMenu1: TPopupMenu;
Label8: TLabel;
N1: TMenuItem;
UpDown1: TUpDown;
procedure BitBtn4Click(Sender: TObject);
procedure N1Click(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure BitBtn3Click(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
procedure FormActivate(Sender: TObject);
private
churu:tchuru;
wupin:twupin;
ku:tku;
caozuo:tcaozuo;
cun:tcun;
{ Private declarations }
public
{ Public declarations }
end;var
Form11: TForm11;implementationuses Unit2_shuju;{$R *.dfm}procedure TForm11.BitBtn4Click(Sender: TObject);
begin
close;
end;procedure TForm11.N1Click(Sender: TObject);
begin
datamodule2.ADOQuery6.close;
datamodule2.ADOQuery6.sql.Clear;
datamodule2.ADOQuery6.Parameters.Clear;
datamodule2.ADOQuery6.sql.Add('select * from churuku where 出入库单编号 like ''I%''');
datamodule2.ADOQuery6.open;
end;procedure TForm11.BitBtn1Click(Sender: TObject);
var
str:string;
pum:integer;
begin
churu:=tchuru.create;
if combobox1.Text='' then
begin
application.MessageBox('入库单编号不能为空','警告',mb_ok);
end
else
if not churu.checkchuid(combobox1.Text) then
begin
if copy(combobox1.Text,1,1)<>'I' then
begin
application.MessageBox('入库单编号要以i开头','警告',mb_ok);
exit;
end;
if not wupin.checkwuname(combobox3.Text) then
begin
application.MessageBox('不存在该物品编码','警告',mb_ok);
exit;
end;
if not caozuo.checkyuanid(combobox2.Text) then
begin
application.MessageBox('不存在该操作员编号','警告',mb_ok);
exit;
end;
if not ku.checkkuid(combobox5.Text) then
begin
application.MessageBox('不存在该库位号','警告',mb_ok);
exit;
end; str:='insert into churuku(出入库单编号,操作员编号,入库品编码,入库品数量,物品单位,入库时间,入库计划库位'+')values('''+combobox1.text+''','''+combobox2.Text+''''
+','''+combobox3.Text+''','''+edit1.Text+''','''+combobox4.Text+''','''+datetostr(datetimepicker1.Date)+''','''+combobox5.Text+''')';
churu.insertchuru(str);
with datamodule2.ADOQuery7 do
begin
close;
sql.Clear;
sql.Add('select * from kucun where 物品编码='''+combobox3.text+''' and 库位代号='''+combobox5.text+'''');
open;
if recordcount=0 then
begin
close;
sql.Clear;
sql.Add('insert into kucun(物品编码,库存数量,物品单位,库位代号)values('''+combobox3.text+''','''+edit1.Text+''','''+combobox4.text+''','''+combobox5.text+''') ');
execsql;
end
else
begin
pum:=strtoint(edit1.Text)+STRTOINT(cun.getwuliang('库存数量'));
close;
sql.Clear;
sql.Add('update kucun set 库存数量='''+inttostr(pum)+'''where 物品编码='''+combobox3.text+''' and 库位代号='''+combobox5.text+''' ');
execsql;
end;
end;
application.MessageBox('入库单信息添加成功','提示',mb_ok);
edit1.Text:='';
combobox5.Text:='';
combobox4.Text:='';
combobox1.Text:='';
combobox2.Text:='';
combobox3.Text:=''; end
else
application.MessageBox('入库单编号已经存在','警告',mb_ok);churu.Free;
end;
问题是:出现错误!with message'''is not a valid integer value'通过断点查问题 发现问题在pum:=strtoint(edit1.Text)+STRTOINT(cun.getwuliang('库存数量'));
这个语句上。导致sql.Add('update kucun set 库存数量='''+inttostr(pum)+'''where 物品编码='''+combobox3.text+''' and 库位代号='''+combobox5.text+''' ');无法执行。
cun.getwuliang('库存数量')这个类 具体是cun.getwuliang(name:string):string;库存数量的数据类型是INT,这个程序是入库单录入程序,通过录入信息检验库存信息是否存在
如果不存在,把某些信息插入库存信息当中,存在的话,把这次的物品数量加上库存数量一起,然后修改库存数量,入库表与库存表是2个不同的表,我已经把能想到的都说了
希望高手帮我看下问题出在哪 这个问题使得我做的一个系统好多类似地方不能执行结果 急求!还有一个问题:本人自学的DELPHI,一切都靠书本或者上论坛请教,无人面授经验,只希望早点达到一个初级程序员的入门条件,好进个小公司积累经验。
问题可能有点初级,请高手帮帮新人。
创建类的实例比方说churu:=tchuru.create;与类的释放churu.Free;可是在程序当中,我发现根本不需要创建与释放也可以用 上面的程序当中 几个类我都没创建与释放 一样可以用
我想知道区别在哪 是不是只要放在private
churu:tchuru;
wupin:twupin;
ku:tku;
caozuo:tcaozuo;
cun:tcun;就可以了呢?
try
....
except
....
end中间2段代码代表什么?是不是尝试去做。。 否者。。的意思 最好有代码具体解释下 :)
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus,unit_kulei, ComCtrls, Grids, DBGrids, StdCtrls, Buttons ,unit_yuanlei, unit_churulei,unit_wulei,unit_cunlei;type
TForm11 = class(TForm)
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
ComboBox1: TComboBox;
Label1: TLabel;
Edit1: TEdit;
ComboBox2: TComboBox;
Label2: TLabel;
ComboBox3: TComboBox;
Label3: TLabel;
Label4: TLabel;
ComboBox4: TComboBox;
Label5: TLabel;
Label6: TLabel;
DateTimePicker1: TDateTimePicker;
Label7: TLabel;
ComboBox5: TComboBox;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
BitBtn3: TBitBtn;
BitBtn4: TBitBtn;
DBGrid1: TDBGrid;
PopupMenu1: TPopupMenu;
Label8: TLabel;
N1: TMenuItem;
UpDown1: TUpDown;
procedure BitBtn4Click(Sender: TObject);
procedure N1Click(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure BitBtn3Click(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
procedure FormActivate(Sender: TObject);
private
churu:tchuru;
wupin:twupin;
ku:tku;
caozuo:tcaozuo;
cun:tcun;
{ Private declarations }
public
{ Public declarations }
end;var
Form11: TForm11;implementationuses Unit2_shuju;{$R *.dfm}procedure TForm11.BitBtn4Click(Sender: TObject);
begin
close;
end;procedure TForm11.N1Click(Sender: TObject);
begin
datamodule2.ADOQuery6.close;
datamodule2.ADOQuery6.sql.Clear;
datamodule2.ADOQuery6.Parameters.Clear;
datamodule2.ADOQuery6.sql.Add('select * from churuku where 出入库单编号 like ''I%''');
datamodule2.ADOQuery6.open;
end;procedure TForm11.BitBtn1Click(Sender: TObject);
var
str:string;
pum:integer;
begin
churu:=tchuru.create;
if combobox1.Text='' then
begin
application.MessageBox('入库单编号不能为空','警告',mb_ok);
end
else
if not churu.checkchuid(combobox1.Text) then
begin
if copy(combobox1.Text,1,1)<>'I' then
begin
application.MessageBox('入库单编号要以i开头','警告',mb_ok);
exit;
end;
if not wupin.checkwuname(combobox3.Text) then
begin
application.MessageBox('不存在该物品编码','警告',mb_ok);
exit;
end;
if not caozuo.checkyuanid(combobox2.Text) then
begin
application.MessageBox('不存在该操作员编号','警告',mb_ok);
exit;
end;
if not ku.checkkuid(combobox5.Text) then
begin
application.MessageBox('不存在该库位号','警告',mb_ok);
exit;
end; str:='insert into churuku(出入库单编号,操作员编号,入库品编码,入库品数量,物品单位,入库时间,入库计划库位'+')values('''+combobox1.text+''','''+combobox2.Text+''''
+','''+combobox3.Text+''','''+edit1.Text+''','''+combobox4.Text+''','''+datetostr(datetimepicker1.Date)+''','''+combobox5.Text+''')';
churu.insertchuru(str);
with datamodule2.ADOQuery7 do
begin
close;
sql.Clear;
sql.Add('select * from kucun where 物品编码='''+combobox3.text+''' and 库位代号='''+combobox5.text+'''');
open;
if recordcount=0 then
begin
close;
sql.Clear;
sql.Add('insert into kucun(物品编码,库存数量,物品单位,库位代号)values('''+combobox3.text+''','''+edit1.Text+''','''+combobox4.text+''','''+combobox5.text+''') ');
execsql;
end
else
begin
pum:=strtoint(edit1.Text)+STRTOINT(cun.getwuliang('库存数量'));
close;
sql.Clear;
sql.Add('update kucun set 库存数量='''+inttostr(pum)+'''where 物品编码='''+combobox3.text+''' and 库位代号='''+combobox5.text+''' ');
execsql;
end;
end;
application.MessageBox('入库单信息添加成功','提示',mb_ok);
edit1.Text:='';
combobox5.Text:='';
combobox4.Text:='';
combobox1.Text:='';
combobox2.Text:='';
combobox3.Text:=''; end
else
application.MessageBox('入库单编号已经存在','警告',mb_ok);churu.Free;
end;
问题是:出现错误!with message'''is not a valid integer value'通过断点查问题 发现问题在pum:=strtoint(edit1.Text)+STRTOINT(cun.getwuliang('库存数量'));
这个语句上。导致sql.Add('update kucun set 库存数量='''+inttostr(pum)+'''where 物品编码='''+combobox3.text+''' and 库位代号='''+combobox5.text+''' ');无法执行。
cun.getwuliang('库存数量')这个类 具体是cun.getwuliang(name:string):string;库存数量的数据类型是INT,这个程序是入库单录入程序,通过录入信息检验库存信息是否存在
如果不存在,把某些信息插入库存信息当中,存在的话,把这次的物品数量加上库存数量一起,然后修改库存数量,入库表与库存表是2个不同的表,我已经把能想到的都说了
希望高手帮我看下问题出在哪 这个问题使得我做的一个系统好多类似地方不能执行结果 急求!还有一个问题:本人自学的DELPHI,一切都靠书本或者上论坛请教,无人面授经验,只希望早点达到一个初级程序员的入门条件,好进个小公司积累经验。
问题可能有点初级,请高手帮帮新人。
创建类的实例比方说churu:=tchuru.create;与类的释放churu.Free;可是在程序当中,我发现根本不需要创建与释放也可以用 上面的程序当中 几个类我都没创建与释放 一样可以用
我想知道区别在哪 是不是只要放在private
churu:tchuru;
wupin:twupin;
ku:tku;
caozuo:tcaozuo;
cun:tcun;就可以了呢?
try
....
except
....
end中间2段代码代表什么?是不是尝试去做。。 否者。。的意思 最好有代码具体解释下 :)
解决方案 »
- TMemo控件的问题
- 安装错是什么原因??
- inc如何从1开始递增呢?
- 关于OCX控件的问题
- 急,关于数据管理的问题!if state in [dsinsert,dsedit] then..............指方向
- 奇怪的現象,為什麼在datetimepicker的onchange事件中的代碼會執行兩次?
- 怎样把注册表中的Key及它下面的subKey形成导出文件,再把导出文件导进注册表
- 问个问题
- 我在TreeView中的节点Icon显示不全,好象被拉伸了,怎么回事?(一定给分)
- 怎么在delphi程序里给调用的水晶报表传参数进去?水晶报表本身已经设置了参数呢
- 请问DBExpress的StoredProcName属性时,不能出现数据库中的存储过程,是什么原因?
- 元旦了,同学都休息,就我一个写程序,不爽,散分
不释放,delphi会自动回收垃圾,不过好的编程习惯,建议还是写规矩些
改成:
pum:=StrToIntDef(edit1.Text, 0)+StrToIntDef(cun.getwuliang('库存数量'), 0);
首先你要保证edit1.text可以转换成int,再有保证cun.getwuliang('库存数量')的返回值可以转换成int,你现在的问题就在这,是转换错误,edit1.text和cun.getwuliang('库存数量')中,肯定有不符合转换规则的,你查到它,然后做相应处理就可以了
下面的修改语句sql.Add('update kucun set 库存数量='''+inttostr(pum)+'''where 物品编码='''+combobox3.text+''' and 库位代号='''+combobox5.text+''' ');也能执行了 问题是都返回0 PUM不也是0了吗 就算一个返回的0 那要修改的数据也不对了啊
不创建也能用?别开玩笑了,难道我没睡醒?
2、
try
....
except
....
end
用于例外(异常)处理,通常情况下很有必要
3、
Edit1的内容的合法性没有处理,应该处理onkeydown事件以限制只能输入数字(还有#8#9#13)
同时要判断trim(edit1.text)是否为空,若为空也不允许
你还没明白我得意思,pum是你查询的一个条件,所以你要保证他有正确的值,这个就来自你得代码pum:=strtoint(edit1.Text)+STRTOINT(cun.getwuliang('库存数量'));
所以要保证edit1.text和cun.getwuliang('库存数量')两个值都可以正确转换,才可得到正确的pum,明白了吗
库存数量='''+inttostr(pum)中库存数量=后面难得是双引号吗,不是整型的吗,那样就不用引号了
where前没有空格
特别是#8#9#13 我根本就没用过 不知道怎么用:(
procedure ed_NumChange(Sender: TObject);
var
code:integer;
num:integer;
begin
Val(TEdit(Sender).Text, num, code);
if Trim(TEdit(Sender).Text) = '' then
TEdit(Sender).Text := '0'
else if code > 0 then
begin
Application.MessageBox(PChar('数值格式错误!'),PChar('信息提示'),MB_OK or MB_ICONINFORMATION);
if Trim(TEdit(Sender).Text) = '' then
TEdit(Sender).Text := '0'
else
TEdit(Sender).Text := LeftStr(TEdit(Sender).Text,code-1);
Exit;
end;
end;
#8是退格,敲错了的话,应允许退格
#9是Tab键
#13是回车键
看一下SQL 语句是否正确.