?? main_daysell.pas
字號:
unit MAIN_DAYSELL;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, MAIN_DATAINPUT, DB, DBTables, Grids, StdCtrls,
TFlatComboBoxUnit, ComCtrls, DsFancyButton, ExtCtrls,myself,frmmain;
type
TFrm_main_daysell = class(TFrm_main_input)
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure OKBtnClick(Sender: TObject);
function User_save():boolean;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Frm_main_daysell: TFrm_main_daysell;
implementation
{$R *.dfm}
procedure TFrm_main_daysell.FormCreate(Sender: TObject);
begin
inherited;
self.Caption :='商場日銷售數據錄入';
end;
procedure TFrm_main_daysell.FormShow(Sender: TObject);
begin
inherited;
with query_data do
begin
close;
sql.Clear ;
sql.Text :='select name from depot where setid=999 and type="外部"';
open;
cb_depot.Items.Clear ;
cb_depot.Style:=csDropDownList;
while not eof do
begin
CB_depot.Items.add(fieldbyname('name').asstring);
next;
end;
close;
sql.Clear ;
sql.Text :='select name from people where usertype="在職"';
open;
cb_ywy.Items.Clear ;
cb_ywy.Style :=csDropDownList;
while not eof do
begin
CB_ywy.Items.add(fieldbyname('name').asstring);
next;
end;
close;
cb_depot.SetFocus ;
end;
end;
procedure TFrm_main_daysell.FormCloseQuery(Sender: TObject;
var CanClose: Boolean);
var
T_temp:TModalResult;
begin
inherited;
if OKBtn.Enabled then
begin
T_temp:=messagedlg(Askmsg0001,mtConfirmation,mbYesnoCancel,0);
if T_temp=mrYes then
begin
if not user_save then
begin
messagedlg('【'+cb_ywy.text+'】在〖'+cb_depot.Text+'〗的當日銷售'+Infmsg0004,mtError,[mbok],0);
canclose:=false;
end
else
begin
messagedlg(Infmsg0001,mtInformation,[mbok],0);
canclose:=true;
end;
end
else if T_temp=mrNo then
canclose:=true
else
canclose:=false;
end
else
canclose:=true;
end;
procedure TFrm_main_daysell.OKBtnClick(Sender: TObject);
var
T_temp:TModalResult;
I_row,I_col:integer;
begin
T_temp:=messagedlg(Askmsg0002+' - 【'+cb_ywy.text+'】在〖'+cb_depot.Text
+'〗的當日銷售',mtConfirmation,mbOKCancel,0);
if T_temp=mrOk then
begin
if not user_save then
begin
messagedlg('【'+cb_ywy.text+'】在〖'+cb_depot.Text+'〗的當日銷售'+Infmsg0004,mtError,[mbok],0);
end
else
begin
T_temp:=messagedlg(Infmsg0001+' '+Askmsg0003,mtConfirmation,mbOKCancel,0);
if T_temp=mrok then //繼續輸入數據
begin
for I_row:=1 to 99 do
begin
for I_col:=1 to 9 do
begin
IMPSG_DATA.Cells[I_col,I_row]:='';
end;
end;
FormShow(self) ;
end
else
begin
okbtn.Enabled :=false;
self.close;
end;
end;
end;
end;
function TFrm_main_daysell.User_save():boolean;
var
I_errordb,I_temp,I_count,I_number:integer;
S_depotid,S_peopleid,S_id:string;
begin
I_errordb:=0;
I_count:=0;
S_depotid:='';
S_peopleid:='';
S_id:='';
if not Checkrights(USERRIGHTS,'增加') then
begin
messagedlg(Errormsg0006+'0007',mterror,[mbok],0);
result:=false;
exit;
end;
if CB_depot.Text ='' then
begin
messagedlg(Errormsg0002+'0002',mtwarning,[mbok],0);
cb_depot.SetFocus ;
result:=false;
exit;
end;
if CB_ywy.Text ='' then
begin
messagedlg(Errormsg0002+'0002',mtwarning,[mbok],0);
cb_ywy.SetFocus ;
result:=false;
exit;
end
else
result:=true;
if result then
begin
for I_temp:=1 to 99 do //逐行檢測進貨記錄是否有效
begin
if IMPSG_DATA.Cells[1,I_temp]<>'' then //有效記錄
begin
inc(I_count);
if (IMPSG_DATA.cells[4,I_temp]='') or (IMPSG_DATA.cells[5,I_temp]='')
or (IMPSG_DATA.cells[6,I_temp]='') then
begin
messagedlg('第'+inttostr(I_temp)+
'行記錄的'+Errormsg0002+'0015',mtError,[mbok],0);
IMPSG_DATA.Row :=I_temp;
IMPSG_DATA.Col :=4;
IMPSG_DATA.SetFocus ;
result:=false;
exit;
end;
try
strtofloat(IMPSG_DATA.Cells[4,I_temp]);
strtofloat(IMPSG_DATA.Cells[5,I_temp]);
strtofloat(IMPSG_DATA.Cells[6,I_temp]);
except
messagedlg('第'+inttostr(I_temp)+
'行記錄的'+Errormsg0002+'0015',mtError,[mbok],0);
IMPSG_DATA.Row :=I_temp;
IMPSG_DATA.Col :=4;
IMPSG_DATA.SetFocus ;
result:=false;
exit;
end;
end;
end;
if I_count<1 then
begin
result:=false;
messagedlg(Errormsg0008,mtwarning,[mbok],0);
end;
end;
if result then
begin
with query_data do
begin
try
close;
sql.Clear ;
sql.Text :='select id from depot where name="'+ cb_depot.Text+'"';
open;
S_depotid:=fieldbyname('id').AsString ;
close;
sql.Clear ;
sql.Text :='select id from people where name="'+ cb_ywy.Text+'"';
open;
S_peopleid:=fieldbyname('id').AsString ;
close;
//檢查是否有庫存,即銷售數量是否合法
for I_temp:=1 to 99 do
begin
if IMPSG_DATA.Cells[1,I_temp]<>'' then //有效記錄
begin
I_errordb:=2;
close;
sql.Clear ;
sql.text:='select id,number from kccount where depotid="'+
S_depotid+'" and goodsid="'+ IMPSG_DATA.Cells[1,I_temp]+'"';
open;
S_id:=fieldbyname('id').asstring;
I_number:=fieldbyname('number').AsInteger-strtoint(IMPSG_DATA.cells[4,I_temp]);
if (recordcount<= 0) or (s_id='') then //本行商品沒有庫存記錄
begin
messagedlg('在【'+cb_depot.Text+'】'+Errormsg0009,mtwarning,[mbok],0);
impsg_data.Row :=I_temp;
impsg_data.Col :=1;
result:=false;
close;
exit;
end
else if I_number<0 then //庫存數量小于銷售數量
begin
messagedlg('在【'+cb_depot.Text+'】'+Errormsg0010,mtwarning,[mbok],0);
impsg_data.Row :=I_temp;
impsg_data.Col :=4;
result:=false;
close;
exit;
end;
end;
end;
for I_temp:=1 to 99 do
begin
if IMPSG_DATA.Cells[1,I_temp]<>'' then //有效記錄
begin
I_errordb:=1;
close;
sql.clear;
sql.text:='insert into SELLRECORD (id,depotid,peopleid,mydate,goodsid,number,'
+'price,sellprice,memo) values ("'+Nowindex+'-'+inttostr(I_temp)+'","'
+S_depotid+'","'+S_peopleid+'","'+formatdatetime('yyyy-mm-dd',DTP_date.DateTime)+'","'
+IMPSG_DATA.Cells[1,I_temp]+'",'+IMPSG_DATA.Cells[4,I_temp]+','+IMPSG_DATA.Cells[5,I_temp]+','
+IMPSG_DATA.Cells[6,I_temp]+',"'+IMPSG_DATA.Cells[9,I_temp]+'")';
execsql;
I_errordb:=2;
close;
sql.Clear ;
sql.text:='select id,number from kccount where depotid="'+
S_depotid+'" and goodsid="'+ IMPSG_DATA.Cells[1,I_temp]+'"';
open;
S_id:=fieldbyname('id').asstring;
I_number:=fieldbyname('number').AsInteger-strtoint(IMPSG_DATA.cells[4,I_temp]);
I_errordb:=3;
close;
sql.Clear ;
sql.text:='update kccount set number='+inttostr(i_number)+' where id='''+s_id+'''';
execsql;
close;
end;
end;
except
result:=false;
if I_errordb=1 then
messagedlg(Errormsg0004+'0018',mtwarning,[mbok],0)
else if I_errordb=2 then
messagedlg(Errormsg0001+'0019',mtwarning,[mbok],0)
else if I_errordb=3 then
messagedlg(Errormsg0004+'0016',mtwarning,[mbok],0)
else
messagedlg(Errormsg0001+'0000',mtwarning,[mbok],0);
close;
exit;
end;
end;
end;
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -