📄 stockinfo1.~pas
字号:
unit StockInfo1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, StdCtrls, ComCtrls, PicButton, ExtCtrls, Grids,
Buttons;
type
TStock1 = class(TForm)
Image1: TImage;
Label1: TLabel;
Image2: TImage;
Bevel1: TBevel;
Bevel2: TBevel;
Bevel3: TBevel;
Label7: TLabel;
PicButton1: TPicButton;
PicButton7: TPicButton;
Label9: TLabel;
Query1: TADOQuery;
Edit1: TEdit;
DBgrid: TStringGrid;
JHDate: TDateTimePicker;
Label2: TLabel;
ComboBox1: TComboBox;
Label4: TLabel;
Edit3: TEdit;
ListView1: TListView;
Button1: TButton;
Label5: TLabel;
ComboBox2: TComboBox;
Label3: TLabel;
Edit2: TEdit;
procedure Image2Click(Sender: TObject);
procedure PicButton7Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure ListView1DblClick(Sender: TObject);
procedure DBgridDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
procedure Button1Click(Sender: TObject);
procedure DBgridMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure DBgridKeyPress(Sender: TObject; var Key: Char);
procedure PicButton1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure PicButton2Click(Sender: TObject);
procedure FormActivate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Stock1: TStock1;
m_storeNum:integer;
implementation
{$R *.dfm}
uses common,StockInfo1Edit;
procedure TStock1.Image2Click(Sender: TObject);
begin
close;
end;
procedure TStock1.PicButton7Click(Sender: TObject);
begin
close;
end;
procedure TStock1.FormCreate(Sender: TObject);
begin
ShowPloyForm(image1.Picture.Bitmap,handle);
////设置listview1控件的列宽度////
dbgrid.Options:=[goFixedVertLine,goFixedHorzLine,goVertLine,goHorzLine,goColSizing];
FillValueToListView(query1,'select * from productTable',0,listview1);
////设置控件stringGrid的标题//////
DBgrid.Cells[0,0]:='产品编码';
DBgrid.Cells[1,0]:='产品名称';
DBgrid.Cells[2,0]:='规格';
DBgrid.Cells[3,0]:='容量';
DBgrid.Cells[4,0]:='单位';
DBgrid.Cells[5,0]:='单价';
DBgrid.Cells[6,0]:='进货数量(箱)';
DBgrid.Cells[7,0]:='进货数量(瓶)';
DBgrid.Cells[8,0]:='金额';
DBgrid.Cells[9,0]:='库存';
DBgrid.cells[10,0]:='啤酒类型';
/////添加城市///
combobox2.Items.Add('辽阳');
combobox2.Items.Add('沈阳');
combobox2.Items.Add('本溪');
combobox2.Items.Add('大连');
combobox2.Items.Add('鞍山');
combobox2.Items.Add('抚顺');
combobox2.Items.Add('丹东');
combobox2.Items.Add('北京');
combobox2.text:='辽阳';
///
combobox1.Items.add('李光辉');
combobox1.Text:='李光辉';
//JHdate.Format:='yyyy-mm-dd';
edit1.Text:='JH'+trim(FloatTostr(strToFloat(formatdatetime('yyyymmdd',now)+'0000')+GetrsCount(query1,'BillTable')+1));
EDIT2.Text:='0';
FillValueToControl(query1,'SELECT * FROM ClerkTable','name',combobox1);
//edit3.SetFocus;
end;
procedure TStock1.SpeedButton1Click(Sender: TObject);
begin
listview1.visible:=true;
end;
procedure TStock1.ListView1DblClick(Sender: TObject);
var
listitem:Tlistitem;
strsql:string;
m_code,m_rule,m_capa,m_city:string;
i:integer;
strSum:double;
begin
DBgrid.RowCount:=DBgrid.rowcount+1;
listitem:=listview1.Items.add;
///查找库存数量///
m_code:=listview1.Selected.SubItems.Strings[0];
m_rule:=listview1.Selected.SubItems.Strings[2];
m_capa:= listview1.Selected.SubItems.Strings[3];
m_city:=trim(combobox2.Text);
strsql:='SELECT * FROM storeTable where code="'+m_code+'" and rule="'+m_rule+'" and capacity="'+m_capa+'"';
m_storeNum:=getFieldValueOfInt(query1,strsql,'storenum');
Dbgrid.Cells[dbgrid.Col,dbgrid.Row]:=listview1.Selected.SubItems.Strings[0];
Dbgrid.Cells[dbgrid.Col+1,dbgrid.Row]:=listview1.Selected.SubItems.Strings[1];
Dbgrid.Cells[dbgrid.Col+2,dbgrid.Row]:=listview1.Selected.SubItems.Strings[2];
Dbgrid.Cells[dbgrid.Col+3,dbgrid.Row]:=listview1.Selected.SubItems.Strings[3];
Dbgrid.Cells[dbgrid.Col+4,dbgrid.Row]:=listview1.Selected.SubItems.Strings[4];
Dbgrid.Cells[dbgrid.Col+5,dbgrid.Row]:=listview1.Selected.SubItems.Strings[5];
Dbgrid.Cells[dbgrid.Col+6,dbgrid.Row]:='0';//进货数量箱listview1.Selected.SubItems.Strings[6];
Dbgrid.Cells[dbgrid.Col+7,dbgrid.Row]:='0';///进货数量瓶
dbgrid.Cells[dbgrid.Col+8,dbgrid.Row]:=IntTostr(strToint(Dbgrid.Cells[dbgrid.Col+6,dbgrid.Row])*strToInt(Dbgrid.Cells[dbgrid.Col+5,dbgrid.Row]));
dbgrid.Cells[dbgrid.Col+9,dbgrid.Row]:=IntToStr(m_storeNum);
dbgrid.Cells[dbgrid.Col+10,dbgrid.Row]:='正常票';
dbgrid.col:=dbgrid.Col+6;
strSum:=0;
////计算总金额/////
for i:=1 to dbgrid.rowcount-2 do
begin
strSum:=strSum+strToFloat(dbgrid.Cells[8,i]);
end;
edit2.Text:=FloatTostr(strSum);
button1.Visible:=false;
listview1.Visible:=false;
end;
procedure TStock1.DBgridDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
if (gdFocused in state) then
begin
if dbgrid.col=0 then
begin
dbgrid.Options:=[goFixedVertLine,goFixedHorzLine,goVertLine,goHorzLine,goColSizing,goEditing];
button1.left:=rect.Left+dbgrid.Left+50;
button1.Top:=rect.Top+dbgrid.Top;
button1.Visible:=true;
//CreateButton(dbgrid,rect.Left+dbgrid.Left+50,rect.Top+dbgrid.Top,10,10,true);
end
else
//CreateButton(dbgrid,rect.Left+dbgrid.Left+50,rect.Top+dbgrid.Top,10,10,false);
button1.Visible:=false;
listview1.Visible:=false;
end;
end;
procedure TStock1.Button1Click(Sender: TObject);
begin
///调整控件listview1的位置并显示
listview1.Left:=button1.Left-47;
listview1.Top:=button1.Top+20;
listview1.Visible:=true;
end;
procedure TStock1.DBgridMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
button1.Visible:=false;
end;
procedure TStock1.DBgridKeyPress(Sender: TObject; var Key: Char);
var
strSum:double;
i:integer;
begin
////当你按回车键时使金额改变
strSum:=0;
if key=#13 then
begin
if dbgrid.col=6 then
begin
///按回车键时使金额,库存数变化////
dbgrid.Cells[8,dbgrid.row]:=IntTostr(strToint(Dbgrid.Cells[6,dbgrid.Row])*strToInt(Dbgrid.Cells[5,dbgrid.Row]));
dbgrid.Cells[9,dbgrid.row]:=IntToStr(m_storenum+strToInt(dbgrid.Cells[6,dbgrid.row]));
////计算总金额/////
for i:=1 to dbgrid.rowcount-2 do
begin
strSum:=strSum+strToFloat(dbgrid.Cells[8,i]);
end;
edit2.Text:=FloatTostr(strSum);
end;
end;
end;
procedure TStock1.PicButton1Click(Sender: TObject);
var
strSql,strInsert,strInsert1:string;
i:integer;
storeSql:string;
strUpdate,strInsert2:string;
storeNUm1:double;
storeNumP1,storeNumP2:double;
begin
strSql:='SELECT * FROM billTable where billcode="'+trim(edit1.Text)+'"';
if messagedlg('确定是否存盘?',mtconfirmation,[mbyes,mbno],0)=mryes then
begin
if (isRunSql(query1,strSql)) then
begin
ShowMessage('此单据的记录已经存在!');
end
else
begin
strInsert:='INSERT INTO billTable(billcode,billDate,billsum,checker,other,city) VALUES("'+trim(edit1.text)+'","'+DateTostr(JHdate.Date)+'",'+edit2.Text+',"'+trim(combobox1.Text)+'","'+trim(edit3.Text)+'","'+trim(combobox2.Text)+'")';
//ShowMessage(strInsert);
RunNonSql(query1,strInsert);
for i:=1 to dbgrid.rowcount-2 do
begin
if dbgrid.Cells[0,i]<>'' then
begin
strInsert1:='INSERT INTO intoTable(billcode,productCode,productName,rule,capacity,unit,price,productNum,productNumP,productSum,BeerType) VALUES("'+trim(edit1.Text)+'","'+dbgrid.Cells[0,i]+'","'+dbgrid.Cells[1,i]+'","'+dbgrid.Cells[2,i]+'","'+dbgrid.Cells[3,i]+'","'+dbgrid.Cells[4,i]+'",'+dbgrid.Cells[5,i]+','+dbgrid.Cells[6,i]+','+dbgrid.Cells[7,i]+','+dbgrid.Cells[8,i]+',"'+dbgrid.Cells[10,i]+'")';
//ShowMessage(strInsert1);
RunNonSql(query1,strInsert1);
end;
end;
////使库存表变化///
for i:=1 to dbgrid.rowcount-2 do
begin
storeSql:='SELECT * FROM storeTable where code="'+dbgrid.cells[0,i]+'" and rule="'+dbgrid.cells[2,i]+'" and capacity="'+dbgrid.cells[3,i]+'" and city="'+trim(combobox2.text)+'"';
//showmessage(storeSql);
if isRunSql(query1,storeSql) then ///如果存在,则累加//
begin
storeNum1:=getFieldValueOfInt(query1,storesql,'storenum');
storeNumP1:=getFieldValueOfInt(query1,storesql,'storenumP');
storeNumP2:=storeNumP1+StrToFloat(dbgrid.cells[7,i]);
strUpdate:='UPDATE storeTable SET storeNum='+dbgrid.cells[9,i]+',storeNumP='+FloatToStr(storeNumP2)+' where code="'+dbgrid.cells[0,i]+'" and rule="'+dbgrid.cells[2,i]+'" and capacity="'+dbgrid.cells[3,i]+'" and city="'+trim(combobox2.text)+'"';
RunNonSql(query1,strUpdate);
end
else ///否则不存在,则添加或插入///
begin
strInsert2:='INSERT INTO storeTable(code,ProductName,rule,capacity,storeNum,storeNumP,city) VALUES("'+dbgrid.Cells[0,i]+'","'+dbgrid.Cells[1,i]+'","'+dbgrid.Cells[2,i]+'","'+dbgrid.Cells[3,i]+'",'+dbgrid.Cells[9,i]+','+dbgrid.cells[7,i]+',"'+trim(combobox2.text)+'")';
RunNonSql(query1,strInsert2);
end;
end;///for 结束
end;////第一个if 结束///
for i:=1 to dbgrid.rowcount-2 do
begin
dbgrid.Cells[0,i]:='';
dbgrid.Cells[1,i]:='';
dbgrid.Cells[2,i]:='';
dbgrid.Cells[3,i]:='';
dbgrid.Cells[4,i]:='';
dbgrid.Cells[5,i]:='';
dbgrid.Cells[6,i]:='';
dbgrid.Cells[7,i]:='';
dbgrid.Cells[8,i]:='';
DBgrid.Cells[9,i]:='';
DBgrid.Cells[10,i]:='';
end;
dbgrid.RowCount:=2;
//dbgrid.Options:=[goFixedVertLine,goFixedHorzLine,goVertLine,goHorzLine,goColSizing];
edit1.Text:='JH'+trim(FloatTostr(strToFloat(formatdatetime('yyyymmdd',now)+'0000')+GetrsCount(query1,'BillTable')+1));
end;
end;
procedure TStock1.FormShow(Sender: TObject);
var
i:integer;
begin
for i:=1 to dbgrid.rowcount-2 do
begin
dbgrid.Cells[0,i]:='';
dbgrid.Cells[1,i]:='';
dbgrid.Cells[2,i]:='';
dbgrid.Cells[3,i]:='';
dbgrid.Cells[4,i]:='';
dbgrid.Cells[5,i]:='';
dbgrid.Cells[6,i]:='';
dbgrid.Cells[7,i]:='';
dbgrid.Cells[8,i]:='';
end;
dbgrid.RowCount:=2;
FillValueToListView(query1,'select * from productTable',0,listview1);
end;
procedure TStock1.PicButton2Click(Sender: TObject);
begin
StockEdit:=TStockEdit.create(Application);
stockedit.show;
end;
procedure TStock1.FormActivate(Sender: TObject);
begin
FillValueToListView(query1,'select * from productTable',0,listview1);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -