?? formoutput.~pas
字號:
unit FormOutput;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ADODB, DB, StdCtrls, Grids, ExtCtrls;
type
Toutput = class(TForm)
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Panel1: TPanel;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Edit1: TEdit;
Edit2: TEdit;
ComboBox1: TComboBox;
ComboBox2: TComboBox;
Edit3: TEdit;
StringGrid1: TStringGrid;
ComboBox3: TComboBox;
Button1: TButton;
Edit4: TEdit;
Edit5: TEdit;
Edit6: TEdit;
Button2: TButton;
ADOQuery1: TADOQuery;
ADOCommand1: TADOCommand;
Button3: TButton;
procedure FormCreate(Sender: TObject);
procedure StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
procedure StringGrid1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure ComboBox3Select(Sender: TObject);
procedure StringGrid1DblClick(Sender: TObject);
procedure ComboBox2DropDown(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
//-------------設置選取的stringgrid單元成員的行,列值為public,以供其他窗體中調用-----------------
public
currentRow: integer;
currentCol:integer;
{ Public declarations }
end;
var
output: Toutput;
currentRow: integer;
currentCol:integer;
implementation
uses FormInfo, FormManage;
{$R *.dfm}
//-------------------窗體創建時,設置stringgrid的行列屬性,寬度等信息--------------
//---------------同時為業務員添加數據詞典---------------------------------------
procedure Toutput.FormCreate(Sender: TObject);
var
i,j,num:integer;
begin
//-------------設置stringgrid行,列名稱---------------------
stringgrid1.Cols[0].Add('序號');
stringgrid1.ColWidths[0]:=32;
stringgrid1.Cols[1].Add('貨號(雙擊)');
stringgrid1.ColWidths[1]:=80;
stringgrid1.Cols[2].Add('品名');
stringgrid1.ColWidths[2]:=128;
stringgrid1.Cols[3].Add('單位');
stringgrid1.ColWidths[3]:=32;
stringgrid1.Cols[4].Add('數量');
stringgrid1.ColWidths[4]:=64;
stringgrid1.Cols[5].Add('倉庫');
stringgrid1.ColWidths[5]:=48;
stringgrid1.Cols[6].Add('單價');
stringgrid1.ColWidths[6]:=64;
stringgrid1.Cols[7].Add('金額');
stringgrid1.ColWidths[7]:=64;
stringgrid1.Cols[8].Add('稅率');
stringgrid1.ColWidths[8]:=64;
stringgrid1.Cols[9].Add('稅額');
stringgrid1.ColWidths[9]:=64;
stringgrid1.Cols[10].Add('不含稅額');
stringgrid1.ColWidths[10]:=64;
for i:=1 to 20 do
begin
stringgrid1.Rows[i].Add(inttostr(i));
stringgrid1.RowHeights[i]:=20;
end;
//-------------------------設置業務員數據詞典------------------------
adoquery1.Close;
adoquery1.SQL.Add('select 姓名 from 用戶清單 where 姓名!=''sys''');
adoquery1.Open;
combobox1.Clear;
while not adoquery1.Eof do
begin
combobox1.Items.Add(adoquery1.fieldbyname('姓名').AsString);
adoquery1.Next;
end;
end;
//------------------設置選取的單元行,列值--------------------------
//-----------------添加銷售價,數量等信息并根據這些信息進行計算---------
//-------------------將統計結果顯示在窗體下方的文本框中-----------------
procedure Toutput.StringGrid1SelectCell(Sender: TObject; ACol,
ARow: Integer; var CanSelect: Boolean);
var
price,number,tax,sum:double;
j:integer;
begin
//讀取選取的當前單元的行,列值
currentCol:=ACol;
currentRow:=ARow;
//只有當選取倉庫時,動態下拉列表才顯示
if (currentCol<>5) then
combobox3.Visible:=false;
//只有商品信息不為空時才可以輸入單位和默認稅率
if (currentCol=3)and(stringgrid1.Cells[2,currentRow]<>'') then
begin
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select distinct 單位 from 商品清單 where 貨號='''+stringgrid1.Cells[1,currentRow]+'''');
adoquery1.Open;
stringgrid1.Cells[3,currentRow]:=adoquery1.FieldByName('單位').AsString;
stringgrid1.Cells[8,currentRow]:='17';
end;
//--------------------當商品信息,數量,單價不為空時,才能進行計算------------------------
if (currentRow<>0)and(stringgrid1.Cells[1,currentRow]<>'')and(stringgrid1.Cells[4,currentRow]<>'')and(stringgrid1.Cells[6,currentRow]<>'')and(stringgrid1.Cells[5,currentRow]<>'') then
begin
//-----------------計算某條銷售單明細的進貨金額,稅額和不含稅額-------------------------
//-----------------------這里開始添加的代碼是判斷出貨量的------------------------
//------------------銷售商品的數量不允許大于庫存中的儲存數量----------------------
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select 庫存數量 from 庫存庫 where 貨號='''+stringgrid1.Cells[1,currentRow]+'''');
adoquery1.Open;
if strtoint(stringgrid1.Cells[4,currentRow])>adoquery1.FieldByName('庫存數量').AsInteger then
begin
showmessage('該庫中此種商品的最大儲量小于您的輸入,將按照最大儲量出貨');
stringgrid1.Cells[4,currentRow]:=adoquery1.FieldByName('庫存數量').AsString;
end;
//----------計算某條銷售單明細的進貨金額,稅額和不含稅額-----------------------
number:=strtofloat(stringgrid1.Cells[4,currentRow]);
price:=strtofloat(stringgrid1.Cells[6,currentRow]);
tax:=strtofloat(stringgrid1.Cells[8,currentRow])/100;
stringgrid1.Cells[7,currentRow]:=floattostr(number*price);
stringgrid1.Cells[9,currentRow]:=floattostr(tax*number*price/(1+tax));
stringgrid1.Cells[10,currentRow]:=floattostr(number*price/(1+tax));
//----------------統計合計金額-----------------------
sum:=0;
for j:=1 to 20 do
if stringgrid1.Cells[7,j]<>'' then
sum:=sum+strtofloat(stringgrid1.Cells[7,j]);
edit4.Text:=floattostr(sum);
//----------------統計合計稅額-----------------------
sum:=0;
for j:=1 to 20 do
if stringgrid1.Cells[9,j]<>'' then
sum:=sum+strtofloat(stringgrid1.Cells[9,j]);
edit6.Text:=floattostr(sum);
//----------------統計合計不含稅額-----------------------
sum:=0;
for j:=1 to 20 do
if stringgrid1.Cells[10,j]<>'' then
sum:=sum+strtofloat(stringgrid1.Cells[10,j]);
edit5.Text:=floattostr(sum);
end;
end;
//---------------在選取倉庫條件滿足時,顯示倉庫名下拉列表--------------
//-------------------并設置倉庫名數據詞典-------------------------------
procedure Toutput.StringGrid1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
rect:TRect;
begin
//------------------倉庫名下拉列表框顯示在鼠標附近-----------------
if (currentCol=5)and(stringgrid1.Cells[2,currentRow]<>'') then
begin
rect := StringGrid1.CellRect(currentCol, currentRow);
combobox3.Visible:=true;
combobox3.Left:=rect.Left ;
combobox3.Top:=StringGrid1.Top+rect.Top;
//------------------------添加數據詞典-----------------------
//------------------注意和進貨單的不同之處-------------------
//-------------這里是根據商品的編號來查詢存有這個商品的倉庫-------
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select distinct 倉庫 from 庫存庫 where 貨號='''+stringgrid1.Cells[1,currentRow]+'''');
adoquery1.Open;
combobox3.Items.Clear;
while not adoquery1.Eof do
begin
combobox3.Items.Add(adoquery1.FieldByName('倉庫').AsString);
adoquery1.Next;
end;
end;
end;
//------------------將選取的值添加到stringgrid單元,并隱藏列表框--------------
procedure Toutput.ComboBox3Select(Sender: TObject);
begin
if currentCol=5 then
begin
stringgrid1.Cells[5,currentRow]:=combobox3.Text;
combobox3.Visible:=false;
combobox3.Items.Clear;
end;
end;
//----------雙擊貨號列讀入商品信息----------------------
procedure Toutput.StringGrid1DblClick(Sender: TObject);
begin
//--------只允許在第一列由“(雙擊)”標示處雙擊----------
if currentCol=1 then
begin
//---------------顯示庫存清單---------------------------
manage.button4.click;
//-------------顯示商品清單時,不允許對進貨單窗體進行操作------
output.Enabled:=false;
end;
end;
//----------------動態添加客戶數據詞典-----------------------
//--------客戶資料窗體中雙擊讀入數據功能見客戶資料窗體的代碼--------
procedure Toutput.ComboBox2DropDown(Sender: TObject);
begin
//顯示客戶清單
info.visible:=true;
info.N4.Click;
//顯示客戶清單時,不允許對進貨單窗體進行操作
output.Enabled:=false;
end;
//---------------窗體顯示時設置當前值-------------------------
procedure Toutput.FormShow(Sender: TObject);
begin
//制表事件為當前日期
edit1.Text:=datetostr(date);
//制單人即登錄用戶
edit2.Text:=manage.StatusBar1.Panels[0].Text;
currentRow:=1;
currentCol:=1;
end;
//----------------關閉窗體時打開管理窗體----------------------------
procedure Toutput.FormClose(Sender: TObject; var Action: TCloseAction);
var
i,j:integer;
begin
manage.show;
end;
//-----------------保存銷售單,銷售單明細數據-------------------------
procedure Toutput.Button1Click(Sender: TObject);
var
maxnum,maxnum2,temp,inputnum,inputnum2:string;
newnum,newnum2,i:integer;
begin
//計算銷售單中最大編號,以便插入新的銷售單數據時編號不沖突
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select max(編號) 最大編號 from 銷售單');
adoquery1.Open;
maxnum:=adoquery1.FieldByName('最大編號').asstring;
//對讀出的編號進行截取并將其轉換為整數值,字段太長時可以不能用strtoint來轉換
//防止插入第一條記錄時出錯
if (maxnum='')or(maxnum=' ') then
temp:='00000'
else
temp:=copy(maxnum,1,5);
//新插入的銷售單編號為插入前的最大編號+1
newnum:=strtoint(temp)+1;
//重新組合編碼
if length(inttostr(newnum))=1 then
inputnum:='0000'+inttostr(newnum);
if length(inttostr(newnum))=2 then
inputnum:='000'+inttostr(newnum);
if length(inttostr(newnum))=3 then
inputnum:='00'+inttostr(newnum);
if length(inttostr(newnum))=4 then
inputnum:='0'+inttostr(newnum);
if length(inttostr(newnum))=5 then
inputnum:=inttostr(newnum);
//計算銷售單明細最大編號以便插入新的銷售單明細數據時編號不沖突
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select max(編號) 最大編號 from 銷售單明細');
adoquery1.Open;
maxnum2:=adoquery1.FieldByName('最大編號').asstring;
//防止插入第一條記錄時出錯
if (maxnum2='')or(maxnum2=' ') then
temp:='00000'
else
temp:=copy(maxnum2,1,5);
newnum2:=strtoint(temp);
//由于銷售單明細數據可能由很多條,因此在下面的循環中銷售單明細循環種再編號和組合編碼
//-----------插入新的銷售單和銷售單明細-----------------------------
//如果客戶號為空或者時沒有銷售單明細數據,則取消插入
if (combobox2.Text='')or(edit4.Text='') then
showmessage('客戶號不能為空,且銷售單明細數據必須完整')
else
begin
//插入新的銷售單數據
adocommand1.CommandText:='insert into 銷售單([編號],[客戶編號],[銷售日期],[業務員],[制單人],[稅價合計],[不含稅價],[稅額]) values('''+inputnum+''','''+combobox2.Text+''','''+edit1.Text+''','''+combobox1.Text+''','''+edit2.Text+''','''+edit4.Text+''','''+edit5.Text+''','''+edit6.Text+''')';
adocommand1.Execute;
//根據銷售單明細條目的數量,插入銷售單明細數據
for i:=1 to 20 do
if stringgrid1.Cells[7,i]<>'' then
//重新組合編碼
begin
newnum2:=newnum2+1;
if length(inttostr(newnum2))=1 then
inputnum2:='0000'+inttostr(newnum2);
if length(inttostr(newnum2))=2 then
inputnum2:='000'+inttostr(newnum2);
if length(inttostr(newnum2))=3 then
inputnum2:='00'+inttostr(newnum2);
if length(inttostr(newnum2))=4 then
inputnum2:='0'+inttostr(newnum2);
if length(inttostr(newnum2))=5 then
inputnum2:=inttostr(newnum2);
adocommand1.CommandText:='insert into 銷售單明細([編號],[銷售單號],[貨號],[銷售數量],[銷售價],[稅價合計],[稅率],[不含稅價],[稅額],[倉庫]) values('''+inputnum2+''','''+inputnum+''','''+stringgrid1.Cells[1,i]+''','''+stringgrid1.Cells[4,i]+''','''+stringgrid1.Cells[6,i]+''','''+stringgrid1.Cells[7,i]+''','''+stringgrid1.Cells[8,i]+''','''+stringgrid1.Cells[10,i]+''','''+stringgrid1.Cells[9,i]+''','''+stringgrid1.Cells[5,i]+''')';
adocommand1.Execute;
end;
//通知用戶,操作成功
showmessage('銷售單及明細保存成功');
end;
end;
//------------------提交銷售單----------------------------------
//---------報表預覽及打印功能與進貨單完全一致--------------------
procedure Toutput.Button3Click(Sender: TObject);
var
i,j:integer;
begin
adocommand1.CommandText:='exec sf_銷售單';
adocommand1.Execute;
showmessage('銷售單處理成功');
//清空前面的輸入
for i:=1 to 10 do
for j:=1 to 20 do
stringgrid1.Cells[i,j]:='';
combobox1.Text:='';
combobox2.Text:='';
edit3.Clear;
edit4.Clear;
edit5.Clear;
edit6.Clear;
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -