📄 unit8.~pas
字号:
RightArea := IntToStr(nian)+'-'+'12'+'-'+'25'; {加入本年度报表}
if (DateTimePicker1.Date >= StrToDate(LeftArea))and (DateTimePicker1.Date < StrToDate(RightArea)) then
begin
Query1.Close;
Query1.SQL.Clear;
Query1.SQL.Add('select * from YearHaoCai where nian='+IntToStr(YearOf(StrToDate(RightArea)))+' and class='''+clclass+''' and cailiaoming='''+ComboBox1.Text+'''');
Query1.Open;
if not Query1.Eof then //YearHaoCai中存在记录
begin
Query2.Close;
Query2.SQL.Clear;
Query2.SQL.Add('select * from YearDataCache where class='''+clclass+''' and cailiaoming='''+ComboBox1.Text+'''');
Query2.Open;
// showmessage('here');
if not Query2.Eof then //YearDataCache中也存在
begin
kucunshu := Query2.FieldByName('kucunshu').AsString;
kucunjine := Query2.FieldByName('kucunjine').AsString;
rukushu := Query2.FieldByName('rukushu').AsString;
rukujine := Query2.FieldByName('rukujine').AsString;
chukushu := Query2.FieldByName('chukushu').AsString;
chukujine := Query2.FieldByName('chukujine').AsString;
rukushu := FloatToStr(StrToFloat(rukushu)+StrToFloat(Edit3.Text));
rukujine := FloatToStr(StrToFloat(rukujine)+StrToFloat(Edit4.Text));
jiecunshu := FloatToStr(StrToFloat(kucunshu)+StrToFloat(rukushu)-StrToFloat(chukushu));
jiecunjine := FloatToStr(StrToFloat(kucunjine)+StrToFloat(rukujine)-StrToFloat(chukujine));
Query3.Close;
Query3.SQL.Clear;
Query3.SQL.Add('Update YearDataCache set rukushu='''+Format('%.2f',[StrToFloat(rukushu)])+''',rukujine='''+Format('%.2f',[StrToFloat(rukujine)])+
''' where class='''+clclass+''' and cailiaoming='''+ComboBox1.Text+'''');
Query3.ExecSQL;
Query3.Close;
Query3.SQL.Clear;
Query3.SQL.Add('Update YearHaoCai set rukushu='''+Format('%.2f',[StrToFloat(rukushu)])+''',rukujine='''+Format('%.2f',[StrToFloat(rukujine)])+
''',jiecunshu='''+Format('%.2f',[StrToFloat(jiecunshu)])+''',jiecunjine='''+Format('%.2f',[StrToFloat(jiecunjine)])+''' where nian='+
IntToStr(YearOf(StrToDate(RightArea)))+' and class='''+clclass+''' and cailiaoming='''+ComboBox1.Text+'''');
Query3.ExecSQL;
end
else
begin
Application.MessageBox('System Error!Unit8,Line:579','Crazy',MB_OK OR MB_ICONQUESTION);
Exit;
end;
end
else //YearHaoCai中不存在,是本年第一次入库的材料
begin {YearDataCache中可能存在,存在就是上一年的库存.不存在就是第一次入库}
Query2.Close;
Query2.SQL.Clear;
Query2.SQL.Add('select * from YearDataCache where class='''+clclass+''' and cailiaoming='''+ComboBox1.Text+'''');
Query2.Open;
if not Query2.Eof then {统计上年库存}
begin
kucunshu := Query2.FieldByName('kucunshu').AsString;
kucunjine := Query2.FieldByName('kucunjine').AsString;
rukushu := Query2.FieldByName('rukushu').AsString;
rukujine := Query2.FieldByName('rukujine').AsString;
chukushu := Query2.FieldByName('chukushu').AsString;
chukujine := Query2.FieldByName('chukujine').AsString;
kucunshu := FloatToStr(StrToFloat(kucunshu)+StrToFloat(rukushu)-StrToFloat(chukushu));
kucunjine := FloatToStr(StrToFloat(kucunjine)+StrToFloat(rukujine)-StrToFloat(chukujine));
jiecunshu := FloatToStr(StrToFloat(kucunshu)+StrToFloat(Edit3.Text)-StrToFloat(chukushu));
jiecunjine := FloatToStr(StrToFloat(kucunjine)+StrToFloat(Edit4.Text)-StrToFloat(chukujine));
Query3.Close;
Query3.SQL.Clear; {Input YearDataCache}
Query3.SQL.Add('Update YearDataCache set kucunshu='''+Format('%.2f',[StrToFloat(kucunshu)])+''',kucunjine='''+Format('%.2f',[StrToFloat(kucunjine)])+
''',rukushu='''+Format('%.2f',[StrToFloat(Edit3.Text)])+''',rukujine='''+Format('%.2f',[StrToFloat(Edit4.Text)])+
''',chukushu=''0.00'',chukujine=''0.00'''+ ' where class='''+clclass+''' and cailiaoming='''+ComboBox1.Text+'''');
Query3.ExecSQL;
Query3.Close;
Query3.SQL.Clear; {input YearHaoCai}
Query3.SQL.Add('Insert into YearHaoCai values('''+ComboBox1.Text+''','''+clclass+''','''+guigexinghao+''','''+Edit1.Text+''','''+
Format('%.2f',[StrToFloat(Edit2.Text)])+''','''+Format('%.2f',[StrToFloat(kucunshu)])+''','''+Format('%.2f',[StrToFloat(kucunjine)])+''','''+
Format('%.2f',[StrToFloat(Edit3.Text)])+''','''+Format('%.2f',[StrToFloat(Edit4.Text)])+''',''0.00'',''0.00'','''+Format('%.2f',[StrToFloat(jiecunshu)])+''','''+
Format('%.2f',[StrToFloat(jiecunjine)])+''','''+''+''','+IntToStr(nian)+')');
Query3.ExecSQL;
end
else //YearDataCache中不存在
begin
Query3.Close;
Query3.SQL.Clear;
Query3.SQL.Add('Insert into YearDataCache values('''+ComboBox1.Text+''','''+clclass+''','+'''0.00'',''0.00'','''+Format('%.2f',[StrToFloat(Edit3.Text)])+''','''+
Format('%.2f',[StrToFloat(Edit4.Text)])+''',''0.00'',''0.00'''+')');
Query3.ExecSQL;
Query3.Close;
Query3.SQL.Clear;
Query3.SQL.Add('Insert into YearHaoCai values('''+ComboBox1.Text+''','''+clclass+''','''+guigexinghao+''','''+Edit1.Text+''','''+Format('%.2f',[StrToFloat(Edit2.Text)])+''',''0.00'',''0.00'','''+
Format('%.2f',[StrToFloat(Edit3.Text)])+''','''+Format('%.2f',[StrToFloat(Edit4.Text)])+''',''0.00'',''0.00'','''+Format('%.2f',[StrToFloat(Edit3.Text)])+''','''+Format('%.2f',[StrToFloat(Edit4.Text)])+
''','''+''+''','+IntToStr(YearOf(StrToDate(RightArea)))+')');
Query3.ExecSQL;
end;
end;
end;
{右区间情况}
if DateTimePicker1.Date > (StrToDate(RightArea)-1) then //>24 (yyyy-12-24,max) save in (nian+1)
begin
Query1.Close;
Query1.SQL.Clear;
Query1.SQL.Add('select * from YearHaoCai where nian='+IntToStr(nian+1)+' and class='''+clclass+''' and cailiaoming='''+
ComboBox1.Text+'''');
Query1.Open;
// showmessage('ishere1');
if not Query1.Eof then //YearHaoCai中有此材料的年记录
begin
Query2.Close;
Query2.SQL.Clear;
Query2.SQL.Add('select * from YearDataCache where class='''+clclass+''' and cailiaoming='''+ComboBox1.Text+'''');
Query2.Open;
if not Query2.Eof then //YearDataCache中有记录
begin
kucunshu := Query2.FieldByName('kucunshu').AsString;
kucunjine := Query2.FieldByName('kucunjine').AsString;
rukushu := Query2.FieldByName('rukushu').AsString;
rukujine := Query2.FieldByName('rukujine').AsString;
chukushu := Query2.FieldByName('chukushu').AsString;
chukujine := Query2.FieldByName('chukujine').AsString;
rukushu := FloatToStr(StrToFloat(rukushu)+StrToFloat(Edit3.Text)); //Update 'rukushu'
rukujine := FloatToStr(StrToFloat(rukujine)+StrToFloat(Edit4.Text));
jiecunshu := FloatToStr(StrToFloat(kucunshu)+StrToFloat(rukushu)-StrToFloat(chukushu)); //结存
jiecunjine := FloatToStr(StrToFloat(kucunjine)+StrToFloat(rukujine)-StrToFloat(chukujine));
Query3.Close;
Query3.SQL.Clear; //更新YearDataCache
Query3.SQL.Add('Update YearDataCache set rukushu='''+Format('%.2f',[StrToFloat(rukushu)])+''',rukujine='''+Format('%.2f',[StrToFloat(rukujine)])+''' where class='''+clclass+
''' and cailiaoming='''+ComboBox1.Text+'''');
Query3.ExecSQL;
// showmessage('ishere2');
Query3.Close;
Query3.SQL.Clear;
Query3.SQL.Add('Update YearHaoCai set rukushu='''+Format('%.2f',[StrToFloat(rukushu)])+''',rukujine='''+Format('%.2f',[StrToFloat(rukujine)])+''',jiecunshu='''+Format('%.2f',[StrToFloat(jiecunshu)])+
''',jiecunjine='''+Format('%.2f',[StrToFloat(jiecunjine)])+''' where nian='+IntToStr(nian+1)+' and class='''+clclass+''' and cailiaoming='''+
ComboBox1.Text+'''');
Query3.ExecSQL;
end
else //YearDataCache中没有记录,不可能发生的情况
begin
Application.MessageBox('System Error!Save have,Cache not.Unit8,Line:674','Crazy',MB_OK OR MB_ICONQUESTION);
Exit;
end;
end
else //YearHaoCai中没有此材料的记录
begin
Query2.Close;
Query2.SQL.Clear;
Query2.SQL.Add('select * from YearDataCache where class='''+clclass+''' and cailiaoming='''+ComboBox1.Text+'''');
Query2.Open;
if Query2.Eof then //YearDataCache中没有此材料的记录
begin
Query3.Close;
Query3.SQL.Clear;
Query3.SQL.Add('Insert YearDataCache values('''+ComboBox1.Text+''','''+clclass+''','+'''0.00'',''0.00'','''+
Format('%.2f',[StrToFloat(Edit3.Text)])+''','''+Format('%.2f',[StrToFloat(Edit4.Text)])+''',''0.00'',''0.00'')');
Query3.ExecSQL;
Query3.Close;
Query3.SQL.Add('Insert YearHaoCai values('''+ComboBox1.Text+''','''+clclass+''','''+guigexinghao+''','''+
Edit1.Text+''','''+Format('%.2f',[StrToFloat(Edit2.Text)])+''','+'''0.00'',''0.00'','''+Format('%.2f',[StrToFloat(Edit3.Text)])+
''','''+Format('%.2f',[StrToFloat(Edit4.Text)])+''',''0.00'',''0.00'','''+Format('%.2f',[StrToFloat(Edit3.Text)])+''','''+Format('%.2f',[StrToFloat(Edit4.Text)])+''','''+
''+''','+IntToStr(nian+1)+')');
end
else //YearHaoCai没有,而YearDataCache有,是以前的历史记录
begin
kucunshu := Query2.FieldByName('kucunshu').AsString;
kucunjine := Query2.FieldByName('kucunjine').AsString;
rukushu := Query2.FieldByName('rukushu').AsString;
rukujine := Query2.FieldByName('rukujine').AsString;
chukushu := Query2.FieldByName('chukushu').AsString;
chukujine := Query2.FieldByName('chukujine').AsString;
kucunshu := FloatToStr(StrToFloat(kucunshu)+StrToFloat(rukushu)-StrToFloat(chukushu));
kucunjine := FloatToStr(StrToFloat(kucunjine)+StrToFloat(rukujine)-StrToFloat(chukujine));
jiecunshu := FloatToStr(StrToFloat(kucunshu)+StrToFloat(Edit3.Text)-0); //出库0
jiecunjine := FloatToStr(StrToFloat(kucunjine)+StrToFloat(Edit4.Text)-0);
Query3.Close;
Query3.SQL.Clear;
Query3.SQL.Add('Update YearDataCache set kucunshu='''+Format('%.2f',[StrToFloat(kucunshu)])+''',kucunjine='''+Format('%.2f',[StrToFloat(kucunjine)])+
''',rukushu='''+Format('%.2f',[StrToFloat(Edit3.Text)])+''',rukujine='''+Format('%.2f',[StrToFloat(Edit4.Text)])+''',chukushu=''0.00'',chukujine=''0.00'' where class='''+
clclass+''' and cailiaoming='''+ComboBox1.Text+'''');
Query3.ExecSQL;
Query3.Close;
Query3.SQL.Clear;
Query3.SQL.Add('Insert into YearHaoCai values('''+ComboBox1.Text+''','''+clclass+''','''+guigexinghao+ ''','''+
Edit1.Text+''','''+Format('%.2f',[StrToFloat(Edit2.Text)])+''','''+Format('%.2f',[StrToFloat(kucunshu)])+''','''+Format('%.2f',[StrToFloat(kucunjine)])+''','''+
Format('%.2f',[StrToFloat(Edit3.Text)])+''','''+Format('%.2f',[StrToFloat(Edit4.Text)])+
''',''0.00'',''0.00'','''+Format('%.2f',[StrToFloat(jiecunshu)])+''','''+Format('%.2f',[StrToFloat(jiecunjine)])+''','''+''+''','+IntToStr(nian+1)+')');
Query3.ExecSQL;
// Application.MessageBox('System Error!Save not,Cache have.Unit8,Line:715','Crazy',MB_OK OR MB_ICONQUESTION);
// Exit;
end;
end;
end;
{左区间情况} //不可能会执行这段代码
if DateTimePicker1.Date < StrToDate(LeftArea) then //(yyyy-mm-dd,yyyy-12-25] 属于上年的记录
begin
// Query1.Close;
// Query1.SQL.Clear;
// Query1.SQL.Add('select * from YearHaoCai where nian='+IntToStr(nian-1)+' and class='''+clclass+''' and cailiaoming='''+
// ComboBox1.Text+'''');
// Query1.Open;
// if then fomart
Application.MessageBox('System Error!Left area wrong(<).Unit8,Line:729','Crazy',MB_OK OR MB_ICONQUESTION);
Exit;
end;
except
Application.MessageBox('系统错误Y','ERROR',MB_OK OR MB_ICONSTOP);
end;
// showmessage('Not End!!!');
// Exit;
Edit3.Clear;
Edit4.Clear;
FreeAndNil(Query3);
FreeAndNil(Query1);
FreeAndNil(Query2);
{以下为加入记录后的刷新操作}
if clclass='外延片' then
begin
with Frmmain.Querywyp do
try
Close;
SQL.Clear;
SQL.Add('select * from WeekHaoCai where class='''+ clclass +'''');
Open;
except
Application.MessageBox('系统错误','ERROR',MB_OK OR MB_ICONSTOP);
end;
end;
if clclass='劳保' then
begin
with Frmmain.Querylb do
try
Close;
SQL.Clear;
SQL.Add('select * from Weekhaocai where class='''+ clclass +'''');
Open;
except
Application.MessageBox('系统错误','ERROR',MB_OK OR MB_ICONSTOP);
end;
end;
if clclass='稀贵金属' then
begin
with Frmmain.Queryxgjs do
try
Close;
SQL.Clear;
SQL.Add('select * from Weekhaocai where class='''+ clclass +'''');
Open;
except
Application.MessageBox('系统错误','ERROR',MB_OK OR MB_ICONSTOP);
end;
end;
if clclass='化学试剂' then
begin
with Frmmain.Queryhxsj do
try
Close;
SQL.Clear;
SQL.Add('select * from Weekhaocai where class='''+ clclass +'''');
Open;
except
Application.MessageBox('系统错误','ERROR',MB_OK OR MB_ICONSTOP);
end;
end;
if clclass='低耗' then
begin
with Frmmain.Querydh do
try
Close;
SQL.Clear;
SQL.Add('select * from Weekhaocai where class='''+ clclass +'''');
Open;
except
Application.MessageBox('系统错误','ERROR',MB_OK OR MB_ICONSTOP);
end;
end;
if clclass='机电' then
begin
with Frmmain.Queryjd do
try
Close;
SQL.Clear;
SQL.Add('select * from Weekhaocai where class='''+ clclass +'''');
Open;
except
Application.MessageBox('系统错误','ERROR',MB_OK OR MB_ICONSTOP);
end;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -