var
n,m:
integer
;
pars:
boolean
;
m_id:
integer
;
time1,time2:TTime;
max_id:
integer
;
begin
Time1:=now;
pars:=
true
;
mysqlquery1
.
Close;
mysqlquery1
.
SQL
.
Clear;
mysqlquery1
.
SQL
.
Add(
'SELECT MAX(id) from tovary'
);
mysqlquery1
.
Open;
if
mysqlquery1
.
RecordCount<>
0
then
m_id:=mysqlquery1
.
Fields
.
Fields[
0
].AsInteger
else
m_id:=
0
;
inc(m_id);
for
n:=
1
to
StringGrid1
.
RowCount-
1
do
begin
pars:=
true
;
mysqlquery1
.
Close;
mysqlquery1
.
SQL
.
Clear;
if
(StringGrid1
.
Cells[ComBoBox1
.
Items
.
indexof(ComboBox1
.
Text),n]=
''
)
or
(StringGrid1
.
Cells[ComBoBox2
.
Items
.
indexof(ComboBox2
.
Text),n]=
''
)
or
((ComBoBox3
.
Text=
''
)
and
(CheckBox1
.
Checked=
false
))
or
(StringGrid1
.
Cells[ComBoBox4
.
Items
.
indexof(ComboBox4
.
Text),n]=
''
)
or
(StringGrid1
.
Cells[ComBoBox5
.
Items
.
indexof(ComboBox5
.
Text),n]=
''
)
or
(StringGrid1
.
Cells[ComBoBox6
.
Items
.
indexof(ComboBox6
.
Text),n]=
''
)
then
pars:=
false
;
if
pars<>
false
then
begin
mysqlquery1
.
SQL
.
Add(
'select t1.id as id,t1.inv_num, t2.name,t2.zapchastPrice as zprice,t2.ostatok as zost from tovary as t1, postavschiki as t2 where t1.inv_num=:inv_num and t2.izgotname=:izgotname and t2.zapchastid=t1.id'
);
mysqlquery1
.
ParamByName(
'inv_num'
).AsString:=StringGrid1
.
Cells[ComBoBox2
.
Items
.
indexof(ComboBox2
.
Text),n];
mysqlquery1
.
ParamByName(
'izgotname'
).AsString:=StringGrid1
.
Cells[ComBoBox4
.
Items
.
indexof(ComboBox4
.
Text),n];
mysqlquery1
.
Open;
if
mysqlquery1
.
RecordCount=
0
then
begin
mysqlquery1
.
Close;
mysqlquery1
.
SQL
.
Clear;
mysqlquery1
.
SQL
.
Add(
'insert into tovary (id,inv_num,name,kross_num) values (:id,:inv_num,:name,:kross_num)'
);
mysqlquery1
.
ParamByName(
'inv_num'
).AsString:=StringGrid1
.
Cells[ComBoBox2
.
Items
.
indexof(ComboBox2
.
Text),n];
mysqlquery1
.
ParamByName(
'name'
).AsString:=StringGrid1
.
Cells[ComBoBox1
.
Items
.
indexof(ComboBox1
.
Text),n];
mysqlquery1
.
ParamByName(
'id'
).AsInteger:=m_id;
if
checkbox1
.
Checked
then
mysqlquery1
.
ParamByName(
'kross_num'
).AsString:=
'0'
else
mysqlquery1
.
ParamByName(
'kross_num'
).AsString:=StringGrid1
.
Cells[ComBoBox3
.
Items
.
indexof(ComboBox3
.
Text),n];
mysqlquery1
.
ExecSQL;
mysqlquery1
.
Close;
mysqlquery1
.
SQL
.
Clear;
mysqlquery1
.
SQL
.
Add(
'insert into postavschiki (name,zapchastID,zapchastPrice,izgotName,ostatok) values (:name,:zapchastID,:zapchastPrice,:izgotName,:ostatok) '
);
mysqlquery1
.
ParamByName(
'name'
).AsString:=Edit1
.
Text; s
mysqlquery1
.
ParamByName(
'zapchastID'
).AsInteger:=m_id;
mysqlquery1
.
ParamByName(
'zapchastPrice'
).AsFloat:=StrToFloat(StringGrid1
.
Cells[ComBoBox5
.
Items
.
indexof(ComboBox5
.
Text),n]);
mysqlquery1
.
ParamByName(
'izgotName'
).AsString:=StringGrid1
.
Cells[ComBoBox4
.
Items
.
indexof(ComboBox4
.
Text),n];
mysqlquery1
.
ParamByName(
'ostatok'
).AsInteger:=StrToInt(StringGrid1
.
Cells[ComBoBox6
.
Items
.
indexof(ComboBox6
.
Text),n]);
mysqlquery1
.
ExecSQL;
inc(m_id);
end
else
begin
max_id:=mysqlquery1
.
Fields
.
Fields[
0
].AsInteger;
mysqlquery1
.
Close;
mysqlquery1
.
SQL
.
Clear;
mysqlquery1
.
SQL
.
Add(
'update postavschiki set zapchastprice=:zapchastprice, ostatok=:ostatok where zapchastID=:id'
);
mysqlquery1
.
ParamByName(
'zapchastprice'
).AsFloat:=StrToFloat(StringGrid1
.
Cells[ComBoBox5
.
Items
.
indexof(ComboBox5
.
Text),n]);
mysqlquery1
.
ParamByName(
'ostatok'
).AsInteger:=StrToInt(StringGrid1
.
Cells[ComBoBox6
.
Items
.
indexof(ComboBox6
.
Text),n]);
mysqlquery1
.
ParamByName(
'id'
).AsInteger:=max_id;
mysqlquery1
.
ExecSQL;
end
;
end
;
end
;
time2:=now;
ShowMessage(
'import is done'
+#
13
+
'Âðåìÿ íà÷àëà: '
+TimeToStr(time1)+#
13
+
'Âðåìÿ îêîí÷àíèÿ: '
+TimeToStr(time2));
Form2
.
Close;