📄 material_info.pas
字号:
adoq_material.Edit;
old_matname:=adoq_material.FieldValues['mat_name'];
if ADOQ_material.FieldValues['flag'] then
old_price:=adoq_material.FieldValues['price'];
TabSheet.ActivePageIndex:=0;
Panel_info.Enabled:=true;
DBE_mat_name.SetFocus;
end;
procedure TForm_Material_info.ToolButton1Click(Sender: TObject);
begin
if not adoq_material.Active then exit;
if adoq_material.State in [dsinsert,dsedit] then exit;
TabSheet.ActivePageIndex:=0;
Panel_info.Enabled:=true;
adoq_material.Append;
DBE_mat_id.SetFocus;
end;
procedure TForm_Material_info.ADOQ_materialBeforePost(DataSet: TDataSet);
var
mat_id, mat_name,info :string;
price:real;
begin
if dataset.FieldValues['mat_id']=null then
begin
MsgErr(handle,'物料编号不能为空,请重新输入!');
dbe_mat_id.SetFocus; abort; exit;
end
else
if dataset.FieldValues['mat_id']='' then
begin
MsgErr(handle,'物料编号不能为空,请重新输入!');
dbe_mat_id.SetFocus; abort; exit;
end;
if dataset.FieldValues['mat_name']=null then
begin
msgerr(handle,'物料名称不能为空,请重新输入!');
dbe_mat_name.SetFocus; abort; exit;
end
else
if dataset.FieldValues['mat_name']='' then
begin
msgerr(handle,'物料名称不能为空,请重新输入!');
dbe_mat_name.SetFocus; abort; exit;
end;
mat_name:=dataset.FieldValues['mat_name'];
if dataset.FieldValues['matype_name']=null then
begin
msgerr(handle,'物料类别不能为空,请选择!');
dblookup_matype.SetFocus; abort; exit;
end
else
if dataset.FieldValues['matype_name']='' then
begin
msgerr(handle,'物料类别不能为空,请选择!');
dblookup_matype.SetFocus; abort; exit;
end;
if dataset.FieldValues['unit']=null then
begin
msgerr(handle,'物料的数量单位不能为空!');
dbe_unit.SetFocus; abort; exit;
end
else
if dataset.FieldValues['unit']='' then
begin
msgerr(handle,'物料的数量单位不能为空!');
dbe_unit.SetFocus; abort; exit;
end;
if (dataset.State in [dsinsert]) then
begin
mat_id:=dataset.FieldValues['mat_id'];
if findRec('material','mat_id',mat_id,info) then
begin
MsgOK(handle,'该物料编号已存在,致数据不可更新!');
DBE_mat_id.SetFocus;
abort; exit;
end;
end;
if ((dataset.State in [dsedit]) and (mat_name<>old_matname)) then
begin
mat_name:=dataset.FieldValues['mat_name'];
if findRec('material','mat_name',mat_name,info) then
begin
MsgOK(handle,'该物料名称已存在,致数据不可更新!');
DBE_mat_name.SetFocus;
abort; exit;
end;
end;
if (dataset.State in [dsinsert]) then
begin
mat_name:=dataset.FieldValues['mat_name'];
if findRec('material','mat_name',mat_name,info) then
begin
MsgOK(handle,'该物料名称已存在,致数据不可更新!');
DBE_mat_name.SetFocus;
abort; exit;
end;
end;
//物料单价修改确认
if dataset.FieldValues['flag'] then
begin
try
price:=dataset.FieldValues['price'];
except
msgerr(handle,'请输入正确的发售单价!');
dbe_price.SetFocus; abort; exit;
end;
if not ToMoney(floattostr(dataset.FieldValues['price']),info) then
begin
MsgErr(handle,'金额格式不对[0.00]!');
DBE_price.SetFocus; abort; exit;
end;
if (price<=0) then
begin
MsgErr(handle,'请输入正确的发售单价!');
DBE_price.SetFocus;
abort; exit;
end;
if old_price<>dataset.FieldValues['price'] then
with ADOQtmp do
begin
close;sql.Clear;
sql.add('Select top 1 mat_id from ck_material where mat_id=:mat_id');
parameters.ParamValues['mat_id']:=dataset.FieldValues['mat_id'];
open;
if recordcount>0 then
begin
if MsgQst(handle,'物料 ['+dataset.FieldValues['mat_name']+'] 在出库表中已经有按照此发售单价发货,要继续修改吗?')=idno
then begin ToolButton_cancelClick(self); abort; exit; end;
end;
end;
end
else dataset.FieldValues['price']:=null;
if (old_price>0) and (dataset.FieldValues['price']=null) then
with ADOQtmp do
begin
close;sql.Clear;
sql.add('Select top 1 mat_id from ck_material where mat_id=:mat_id');
parameters.ParamValues['mat_id']:=dataset.FieldValues['mat_id'];
open;
if recordcount>0 then
begin
if MsgQst(handle,'物料 ['+dataset.FieldValues['mat_name']+'] 在出库表中已经有按照此发售单价发货,要继续修改吗?')=idno
then begin ToolButton_cancelClick(self); abort; exit; end;
end;
close;
end;
end;
procedure TForm_Material_info.FormCreate(Sender: TObject);
begin
adot_matype.Open;
adoq_material.Open;
end;
procedure TForm_Material_info.OKBtnClick(Sender: TObject);
label Get_sqltext;
var
tmpnum, tmpid, tmpname, tmpcolor, tmpmatype,
Bool_str, strwhere: string;
begin
case RadioGroup1.ItemIndex of
0:
bool_str:='';
1:
bool_str:='1';
2:
bool_str:='0';
end;
tmpid:=trim(Edit_id.text);
tmpname:=trim(Edit_name.text);
tmpcolor:=trim(Edit_color.Text);
tmpmatype:=trim(Lookup_matype.Text);
tmpnum:=Getquery_char(ComboBox1.Text,trim(Edit1.Text),trim(ComboBox2.Text),ComboBox3.Text,trim(Edit2.Text),'price');
strwhere:='';
//得到查询的条件语句
begin
if trim(bool_str)<>'' then bool_str:='(flag = '+''''+bool_str+''''+')';
if tmpname<>'' then tmpname:='(mat_name like '+''''+'%'+tmpname+'%'+''''+')';
if tmpcolor<>'' then tmpcolor:='(color like '+''''+'%'+tmpcolor+'%'+''''+')';
if tmpmatype<>'' then tmpmatype:='(matype_id in (select matype_id from material_type where matype_name ='+''''+tmpmatype+''''+')'+')';
if bool_str<>'' then
begin
strwhere:='where '+bool_str;
if tmpname<>'' then strwhere:=strwhere+' and '+tmpname;
if tmpcolor<>'' then strwhere:=strwhere+' and '+tmpcolor;
if tmpmatype<>'' then strwhere:=strwhere+' and '+tmpmatype;
goto Get_sqltext;
end;
if tmpname<>'' then
begin
strwhere:='where '+tmpname;
if tmpcolor<>'' then strwhere:=strwhere+' and '+tmpcolor;
if tmpmatype<>'' then strwhere:=strwhere+' and '+tmpmatype;
goto Get_sqltext;
end;
if tmpcolor<>'' then
begin
strwhere:='where '+tmpcolor;
if tmpmatype<>'' then strwhere:=strwhere+' and '+tmpmatype;
goto Get_sqltext;
end;
if tmpmatype<>'' then
begin
strwhere:='where '+tmpmatype;
goto Get_sqltext;
end;
Get_sqltext:
if (bool_str<>'') or (tmpname<>'') or (tmpcolor<>'') or (tmpmatype<>'')
then strwhere:=(strwhere + tmpnum)
else
begin
if tmpnum<>'' then strwhere:='where '+copy(tmpnum,5,length(tmpnum));
end;
end;
with ADOQ_material do
begin
try
close;
sql.Strings[1]:=strwhere;
execsql; open;
except
MsgErr(handle,'数据库检索失败(Material_KC_Q)!');
exit;
end;
end;
Panel2.Enabled:=false;
Panel2.Visible:=false;
ToolButton1.Enabled:=true;
ToolButton2.Enabled:=true;
ToolButton3.Enabled:=true;
ToolButton_save.Enabled:=true;
ToolButton_cancel.Enabled:=true;
end;
procedure TForm_Material_info.CancelBtnClick(Sender: TObject);
begin
Panel2.Enabled:=false;
Panel2.Visible:=false;
ToolButton1.Enabled:=true;
ToolButton2.Enabled:=true;
ToolButton3.Enabled:=true;
ToolButton_save.Enabled:=true;
ToolButton_cancel.Enabled:=true;
CancelBtn.Cancel:=false;
button2.Cancel:=true;
end;
procedure TForm_Material_info.ToolButton_exitClick(Sender: TObject);
begin
modalresult:=mrcancel;
end;
procedure TForm_Material_info.ToolButton_locateClick(Sender: TObject);
begin
if panel2.Visible then exit;
TabSheet.ActivePageIndex:=1;
Panel2.Enabled:=true;
Panel2.Visible:=true;
ToolButton1.Enabled:=false;
ToolButton2.Enabled:=false;
ToolButton3.Enabled:=false;
ToolButton_save.Enabled:=false;
ToolButton_cancel.Enabled:=false;
Edit_id.Clear; Edit_name.Clear;
Edit_color.Clear; Lookup_matype.ItemIndex:=0;
edit1.Clear; edit2.Clear;
CancelBtn.Cancel:=true;
button2.Cancel:=false;
end;
procedure TForm_Material_info.Edit1KeyPress(Sender: TObject;
var Key: Char);
begin
if not (key in ['0'..'9',#13, #8,#46]) then abort;
end;
procedure TForm_Material_info.ADOQ_materialAfterInsert(DataSet: TDataSet);
begin
dataset.FieldValues['flag']:=0;
end;
procedure TForm_Material_info.DBGrid6DblClick(Sender: TObject);
begin
with adoq_material do
begin
if not active then exit;
if recordcount=0 then exit;
end;
TabSheet.ActivePageIndex:=0;
end;
procedure TForm_Material_info.TabSheetChanging(Sender: TObject;
var AllowChange: Boolean);
begin
if not ADOQ_material.Active then exit;
if ADOQ_material.State in [dsedit, dsinsert] then
begin
AllowChange:=false;
Msgok(handle,'数据库正处在操作状态,请先按 [取消] 按钮!');
end;
end;
procedure TForm_Material_info.TabSheetChange(Sender: TObject);
begin
if not adoq_material.Active then exit;
DBCheckBox_flagClick(self);
end;
procedure TForm_Material_info.ToolButton5Click(Sender: TObject);
begin
Form_main.WriteIntoExcel(DBGrid6,datetostr(date),'物料编号对照表');
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -