提交 a195f8be 编写于 作者: C cz_012273

改为数据模块集中管理数据库连接、查询、数据源,导航标题改中文。

上级 d5480145
......@@ -72,7 +72,7 @@ object Form4: TForm4
Width = 43
Height = 17
DataField = #24207#21495
DataSource = DataSource1
DataSource = DM1.DataSource4
Font.Charset = DEFAULT_CHARSET
Font.Color = clBlue
Font.Height = -11
......@@ -86,7 +86,7 @@ object Form4: TForm4
Width = 121
Height = 17
DataField = #21697#21517
DataSource = DataSource1
DataSource = DM1.DataSource4
Font.Charset = DEFAULT_CHARSET
Font.Color = clBlue
Font.Height = -11
......@@ -100,7 +100,7 @@ object Form4: TForm4
Width = 67
Height = 17
DataField = #25968#37327
DataSource = DataSource1
DataSource = DM1.DataSource4
Font.Charset = DEFAULT_CHARSET
Font.Color = clBlue
Font.Height = -11
......@@ -114,7 +114,7 @@ object Form4: TForm4
Width = 121
Height = 17
DataField = #35268#26684
DataSource = DataSource1
DataSource = DM1.DataSource4
Font.Charset = DEFAULT_CHARSET
Font.Color = clBlue
Font.Height = -11
......@@ -128,7 +128,7 @@ object Form4: TForm4
Width = 74
Height = 17
DataField = #20837#24211#26085#26399
DataSource = DataSource1
DataSource = DM1.DataSource4
Font.Charset = DEFAULT_CHARSET
Font.Color = clBlue
Font.Height = -11
......@@ -142,7 +142,7 @@ object Form4: TForm4
Width = 79
Height = 17
DataField = #20445#31649#20154
DataSource = DataSource1
DataSource = DM1.DataSource4
Font.Charset = DEFAULT_CHARSET
Font.Color = clBlue
Font.Height = -11
......@@ -156,7 +156,7 @@ object Form4: TForm4
Width = 50
Height = 17
DataField = #20351#29992#21608#26399#65288#22825#65289
DataSource = DataSource1
DataSource = DM1.DataSource4
Font.Charset = DEFAULT_CHARSET
Font.Color = clBlue
Font.Height = -11
......@@ -177,7 +177,7 @@ object Form4: TForm4
Width = 71
Height = 17
DataField = #20445#36136#26399#65288#22825#65289
DataSource = DataSource1
DataSource = DM1.DataSource4
Font.Charset = DEFAULT_CHARSET
Font.Color = clBlue
Font.Height = -11
......@@ -208,7 +208,7 @@ object Form4: TForm4
Top = 145
Width = 559
Height = 176
DataSource = DataSource1
DataSource = DM1.DataSource4
ReadOnly = True
TabOrder = 2
TitleFont.Charset = DEFAULT_CHARSET
......@@ -217,19 +217,4 @@ object Form4: TForm4
TitleFont.Name = 'Tahoma'
TitleFont.Style = []
end
object FDQuery1: TFDQuery
Connection = FDConnection1
SQL.Strings = (
'select * from '#24211#23384#34920)
Left = 40
end
object FDConnection1: TFDConnection
Params.Strings = (
'LockingMode=Normal'
'DriverID=SQLite')
end
object DataSource1: TDataSource
DataSet = FDQuery1
Left = 80
end
end
......@@ -4,21 +4,12 @@ interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, FireDAC.Stan.Intf,
FireDAC.Stan.Option, FireDAC.Stan.Param, FireDAC.Stan.Error, FireDAC.DatS,
FireDAC.Phys.Intf, FireDAC.DApt.Intf, FireDAC.Stan.Async, FireDAC.DApt,
FireDAC.UI.Intf, FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Phys,
FireDAC.Phys.SQLite, FireDAC.Phys.SQLiteDef, FireDAC.Stan.ExprFuncs,
FireDAC.Phys.SQLiteWrapper.Stat, FireDAC.VCLUI.Wait, Vcl.Mask, Vcl.DBCtrls,
Data.DB, FireDAC.Comp.Client, FireDAC.Comp.DataSet, Vcl.ExtCtrls, Vcl.Grids,
Vcl.DBGrids;
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,Vcl.Mask, Vcl.DBCtrls,
Data.DB,Vcl.ExtCtrls, Vcl.Grids,Vcl.DBGrids;
type
TForm4 = class(TForm)
Label1: TLabel;
FDQuery1: TFDQuery;
FDConnection1: TFDConnection;
DataSource1: TDataSource;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
......@@ -52,7 +43,7 @@ var
implementation
uses pubunit;
uses dataunit;
{$R *.dfm}
......@@ -70,9 +61,8 @@ end;
procedure TForm4.FormShow(Sender: TObject);
begin
FDConnection1.Params.Add('Database=' + dbName);
FDConnection1.Connected := True;
with FDQuery1 do
dm1.FDConnection1.Connected := True;
with dm1.FDQuery4 do
begin
Close;
Open('SELECT * FROM 库存表');
......
......@@ -72,7 +72,7 @@ object Form3: TForm3
Width = 32
Height = 17
DataField = #24207#21495
DataSource = DataSource1
DataSource = DM1.DataSource3
end
object Label8: TLabel
Left = 31
......@@ -88,31 +88,13 @@ object Form3: TForm3
Height = 13
Caption = #21457#25918#29702#30001
end
object DBEdit3: TDBEdit
Left = 341
Top = 53
Width = 67
Height = 21
DataField = #25968#37327
DataSource = DataSource1
TabOrder = 0
end
object DBEdit4: TDBEdit
Left = 469
Top = 53
Width = 121
Height = 21
DataField = #35268#26684
DataSource = DataSource1
TabOrder = 1
end
object Button1: TButton
Left = 140
Top = 343
Width = 111
Height = 41
Caption = #30830#23450
TabOrder = 2
TabOrder = 0
OnClick = Button1Click
end
object Button2: TButton
......@@ -121,7 +103,7 @@ object Form3: TForm3
Width = 111
Height = 41
Caption = #21462#28040
TabOrder = 3
TabOrder = 1
OnClick = Button2Click
end
object DBGrid1: TDBGrid
......@@ -129,9 +111,9 @@ object Form3: TForm3
Top = 192
Width = 559
Height = 129
DataSource = DataSource1
DataSource = DM1.DataSource3
ReadOnly = True
TabOrder = 4
TabOrder = 2
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -11
......@@ -145,37 +127,10 @@ object Form3: TForm3
Height = 21
KeyField = #24207#21495
ListField = #21697#21517
ListSource = DataSource2
TabOrder = 5
ListSource = DM1.DataSource2
TabOrder = 3
OnCloseUp = DBLookupComboBox1CloseUp
end
object DBEdit1: TDBEdit
Left = 121
Top = 144
Width = 50
Height = 21
DataField = #20351#29992#21608#26399#65288#22825#65289
DataSource = DataSource1
TabOrder = 6
end
object DBEdit2: TDBEdit
Left = 256
Top = 144
Width = 334
Height = 21
DataField = #21457#25918#29702#30001
DataSource = DataSource1
TabOrder = 7
end
object DBEdit5: TDBEdit
Left = 85
Top = 98
Width = 108
Height = 21
DataField = #20986#24211#26085#26399
DataSource = DataSource1
TabOrder = 8
end
object DBLookupComboBox2: TDBLookupComboBox
Left = 469
Top = 98
......@@ -184,8 +139,8 @@ object Form3: TForm3
DropDownRows = 15
KeyField = #24207#21495
ListField = #22995#21517
ListSource = DataSource3
TabOrder = 9
ListSource = DM1.DataSource5
TabOrder = 4
OnCloseUp = DBLookupComboBox2CloseUp
end
object DBLookupComboBox3: TDBLookupComboBox
......@@ -196,55 +151,53 @@ object Form3: TForm3
DropDownRows = 15
KeyField = #24207#21495
ListField = #25152#22312#37096#38376#65288#29677#32452#65289
ListSource = DataSource4
TabOrder = 10
ListSource = DM1.DataSource6
TabOrder = 5
OnCloseUp = DBLookupComboBox3CloseUp
end
object FDQuery1: TFDQuery
Connection = FDConnection1
SQL.Strings = (
'select * from '#20986#24211#34920)
Left = 40
end
object FDConnection1: TFDConnection
Params.Strings = (
'LockingMode=Normal'
'DriverID=SQLite')
Connected = True
LoginPrompt = False
end
object DataSource1: TDataSource
DataSet = FDQuery1
Left = 80
end
object FDQuery2: TFDQuery
Connection = FDConnection1
SQL.Strings = (
'SELECT * FROM '#21697#21517#34920)
Left = 160
end
object DataSource2: TDataSource
DataSet = FDQuery2
Left = 192
end
object FDQuery3: TFDQuery
Connection = FDConnection1
SQL.Strings = (
'SELECT * FROM '#20154#21592#34920)
Left = 288
end
object DataSource3: TDataSource
DataSet = FDQuery3
Left = 320
end
object FDQuery4: TFDQuery
Connection = FDConnection1
SQL.Strings = (
'SELECT * FROM '#20154#21592#34920)
Left = 416
end
object DataSource4: TDataSource
DataSet = FDQuery4
Left = 448
object DBEdit1: TDBEdit
Left = 336
Top = 53
Width = 97
Height = 21
DataField = #25968#37327
DataSource = DM1.DataSource3
TabOrder = 6
end
object DBEdit2: TDBEdit
Left = 469
Top = 53
Width = 121
Height = 21
DataField = #35268#26684
DataSource = DM1.DataSource3
TabOrder = 7
end
object DBEdit3: TDBEdit
Left = 85
Top = 98
Width = 111
Height = 21
DataField = #20986#24211#26085#26399
DataSource = DM1.DataSource3
TabOrder = 8
end
object DBEdit4: TDBEdit
Left = 112
Top = 144
Width = 84
Height = 21
DataField = #20351#29992#21608#26399#65288#22825#65289
DataSource = DM1.DataSource3
TabOrder = 9
end
object DBEdit5: TDBEdit
Left = 256
Top = 144
Width = 334
Height = 21
DataField = #21457#25918#29702#30001
DataSource = DM1.DataSource3
TabOrder = 10
end
end
......@@ -4,47 +4,32 @@ interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, FireDAC.Stan.Intf,
FireDAC.Stan.Option, FireDAC.Stan.Param, FireDAC.Stan.Error, FireDAC.DatS,
FireDAC.Phys.Intf, FireDAC.DApt.Intf, FireDAC.Stan.Async, FireDAC.DApt,
FireDAC.UI.Intf, FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Phys,
FireDAC.Phys.SQLite, FireDAC.Phys.SQLiteDef, FireDAC.Stan.ExprFuncs,
FireDAC.Phys.SQLiteWrapper.Stat, FireDAC.VCLUI.Wait, Vcl.Mask, Vcl.DBCtrls,
Data.DB, FireDAC.Comp.Client, FireDAC.Comp.DataSet, Vcl.ExtCtrls, Vcl.Grids,
Vcl.DBGrids;
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,Vcl.Mask, Vcl.DBCtrls,
Data.DB,Vcl.ExtCtrls, Vcl.Grids, Vcl.DBGrids;
type
TForm3 = class(TForm)
Label1: TLabel;
FDQuery1: TFDQuery;
FDConnection1: TFDConnection;
DataSource1: TDataSource;
Label2: TLabel;
Label3: TLabel;
DBEdit3: TDBEdit;
Label4: TLabel;
DBEdit4: TDBEdit;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Button1: TButton;
Button2: TButton;
DBGrid1: TDBGrid;
FDQuery2: TFDQuery;
DBText1: TDBText;
DataSource2: TDataSource;
DBLookupComboBox1: TDBLookupComboBox;
Label8: TLabel;
Label9: TLabel;
DBLookupComboBox2: TDBLookupComboBox;
DBLookupComboBox3: TDBLookupComboBox;
DBEdit1: TDBEdit;
DBEdit2: TDBEdit;
DBEdit3: TDBEdit;
DBEdit4: TDBEdit;
DBEdit5: TDBEdit;
DBLookupComboBox2: TDBLookupComboBox;
DBLookupComboBox3: TDBLookupComboBox;
FDQuery3: TFDQuery;
DataSource3: TDataSource;
FDQuery4: TFDQuery;
DataSource4: TDataSource;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormShow(Sender: TObject);
......@@ -63,7 +48,7 @@ var
implementation
uses pubunit;
uses DataUnit;
{$R *.dfm}
......@@ -77,7 +62,7 @@ begin
application.MessageBox('品名不能为空!','系统提示',mb_ok+mb_iconinformation);
exit;
end;
if DBedit3.text='' then
if DBedit1.text='' then
begin
application.MessageBox('数量不能为空!','系统提示',mb_ok+mb_iconinformation);
exit;
......@@ -92,57 +77,61 @@ begin
application.MessageBox('领取人不能为空!','系统提示',mb_ok+mb_iconinformation);
exit;
end;
FDQuery1.post;
FDQuery1.Open('SELECT * FROM 出库表 order by 序号 desc limit 1'); //每次仅更新最大序号出库记录
with FDQuery2 do //操作库存表
DM1.FDQuery3.post;
DM1.FDQuery3.Open('SELECT * FROM 出库表 order by 序号 desc limit 1'); //每次仅更新最大序号出库记录
with DM1.FDQuery4 do //操作库存表
begin
close;
sql.Clear ;
sql.Add('select * from 库存表');
open;
FDQuery1.First; //出库表定位于首记录
while not FDQuery1.Eof do //当出库表非空时,循环开始
DM1.FDQuery3.First; //出库表定位于首记录
while not DM1.FDQuery3.Eof do //当出库表非空时,循环开始
begin
FDQuery2.first; //库存表定位于首记录
while not FDQuery2.Eof do //当库存表非空时,循环开始
first; //库存表定位于首记录
while not Eof do //当库存表非空时,循环开始
begin
if (FDQuery2.Fields[1].value=FDQuery1.Fields[1].Value) and (FDQuery2.Fields[2].value>=FDQuery1.Fields[2].Value) then //当库存表品名等于出库表品名时
if (Fields[1].value=DM1.FDQuery3.Fields[1].Value) and (Fields[2].value>=DM1.FDQuery3.Fields[2].Value) then //当库存表品名等于出库表品名时
begin
FDQuery2.edit; //编辑库存表
FDQuery2.Fields[2].value:=(FDQuery2.Fields[2].value)-(FDQuery1.Fields[2].Value); //库存数量减少
//FDQuery2.Fields[4].value:= FDQuery1.Fields[4].Value; //更新出库日期
edit; //编辑库存表
Fields[2].value:=(Fields[2].value)-(DM1.FDQuery3.Fields[2].Value); //库存数量减少
//Fields[4].value:= DM1.FDQuery3.Fields[4].Value; //更新出库日期
post;
i:=1; // 找到该商品
break; //跳出内循环
end;
FDQuery2.Next ; //到库存表下一记录
Next ; //到库存表下一记录
end;
if i=0 then //如果标记为0,即未找到同名商品
begin
application.MessageBox('库存中无此商品或数量不够,请重新选择输入!','系统提示',mb_ok+mb_iconinformation);
i:=0; //标记为0
end;
FDQuery1.Next ; //到出库表下一记录
DM1.FDQuery3.Next ; //到出库表下一记录
end;
end;
if i=0 then
begin
FDConnection1.rollback;
DM1.FDConnection1.rollback;
end
else
begin
FDConnection1.commit;
DM1.FDConnection1.commit;
end;
//FDConnection1.Connected := false;
//DM1.FDConnection1.Connected := false;
DM1.FDQuery5.Filter :='';
DM1.FDQuery5.Filtered := False;
close;
end;
procedure TForm3.Button2Click(Sender: TObject);
begin
FDConnection1.rollback;
//FDConnection1.Connected := false;
DM1.FDConnection1.rollback;
//DM1.FDConnection1.Connected := false;
DM1.FDQuery5.Filter :='';
DM1.FDQuery5.Filtered := False;
close;
end;
......@@ -150,55 +139,56 @@ end;
procedure TForm3.DBLookupComboBox1CloseUp(Sender: TObject);
begin
FDQuery1.FieldByName('品名').value := DBlookupcombobox1.text;
FDQuery1.FieldByName('规格').value := FDQuery2.FieldByName('规格').Value;
FDQuery1.FieldByName('使用周期(天)').value := FDQuery2.FieldByName('使用周期(天)').Value;
DM1.FDQuery3.FieldByName('品名').value := DBlookupcombobox1.text;
DM1.FDQuery3.FieldByName('规格').value := DM1.FDQuery2.FieldByName('规格').Value;
DM1.FDQuery3.FieldByName('使用周期(天)').value := DM1.FDQuery2.FieldByName('使用周期(天)').Value;
end;
procedure TForm3.DBLookupComboBox2CloseUp(Sender: TObject);
begin
FDQuery1.FieldByName('领取人').value := DBlookupcombobox2.text;
DM1.FDQuery3.FieldByName('领取人').value := DBlookupcombobox2.text;
end;
procedure TForm3.DBLookupComboBox3CloseUp(Sender: TObject);
var
keycode: string;
begin
FDQuery1.FieldByName('所在部门(班组)').value := DBlookupcombobox3.text;
DM1.FDQuery3.FieldByName('所在部门(班组)').value := DBlookupcombobox3.text;
if DBlookupcombobox3.Text=EmptyStr then
keycode := EmptyStr
else
keycode := DBlookupcombobox3.Text;
//使用filter过滤
FDQuery3.Filtered := False;
FDQuery3.Filter := '所在部门(班组)='+QuotedStr(keycode);
FDQuery3.Filtered := True;
DM1.FDQuery5.Filtered := False;
DM1.FDQuery5.Filter := '所在部门(班组)='+QuotedStr(keycode);
DM1.FDQuery5.Filtered := True;
//清除城市下拉框已选的值
DBlookupcombobox2.KeyValue := '';
DBlookupcombobox2.KeyValue := 0;
end;
procedure TForm3.FormShow(Sender: TObject);
begin
FDConnection1.Params.Add('Database=' + dbName);
FDConnection1.Connected := True;
FDQuery1.Close;
FDQuery1.Open('SELECT * FROM 出库表');
FDQuery2.Close;
FDQuery2.Open('SELECT * FROM 品名表');
FDQuery3.Close;
FDQuery3.Open('SELECT * FROM 人员表');
FDQuery4.Close;
FDQuery4.Open('SELECT * FROM 人员表 GROUP BY 所在部门(班组) ORDER BY 序号');
FDConnection1.starttransaction;
DM1.FDConnection1.Connected := True;
DM1.FDConnection1.starttransaction;
DM1.FDQuery3.Close;
DM1.FDQuery3.Open('SELECT * FROM 出库表');
DM1.FDQuery2.Close;
DM1.FDQuery2.Open('SELECT * FROM 品名表');
DM1.FDQuery5.Close;
DM1.FDQuery5.Open('SELECT * FROM 人员表');
DM1.FDQuery6.Close;
DM1.FDQuery6.Open('SELECT * FROM 人员表 GROUP BY 所在部门(班组) ORDER BY 序号');
try
with FDQuery1 do
with DM1.FDQuery3 do
begin
refresh; //数据表刷新,否则第二次打开本窗体会提示下标越界
Append;
FieldByName('序号').value := FDQuery1.RecordCount+1;
FieldByName('序号').value := DM1.FDQuery3.RecordCount+1;
FieldByName('出库日期').value := date();
Fields[0].DisplayWidth := 4; //这个宽度指字符数
Fields[1].DisplayWidth := 20;
......@@ -210,7 +200,7 @@ begin
end;
//DBLookupComboBox1.KeyValue:= DBLookupComboBox1.ListSource.DataSet[DBLookupComboBox1.KeyField];
except
FDConnection1.rollback;
DM1.FDConnection1.rollback;
end;
end;
......
object DM1: TDM1
OldCreateOrder = False
OnCreate = DataModuleCreate
Height = 446
Width = 704
object FDConnection1: TFDConnection
Params.Strings = (
'Database=E:\WZGL\WZGLK.db'
'DriverID=SQLite')
Connected = True
Left = 40
Top = 24
end
object FDPhysSQLiteDriverLink1: TFDPhysSQLiteDriverLink
Left = 160
Top = 24
end
object FDGUIxWaitCursor1: TFDGUIxWaitCursor
Provider = 'Forms'
Left = 280
Top = 24
end
object FDQuery1: TFDQuery
Connection = FDConnection1
SQL.Strings = (
'SELECT * FROM '#20837#24211#34920)
Left = 40
Top = 120
end
object DataSource1: TDataSource
DataSet = FDQuery1
Left = 40
Top = 216
end
object FDQuery2: TFDQuery
Connection = FDConnection1
SQL.Strings = (
'SELECT * FROM '#21697#21517#34920)
Left = 160
Top = 120
end
object DataSource2: TDataSource
DataSet = FDQuery2
Left = 160
Top = 216
end
object FDQuery3: TFDQuery
Connection = FDConnection1
SQL.Strings = (
'SELECT * FROM '#20986#24211#34920)
Left = 280
Top = 120
end
object DataSource3: TDataSource
DataSet = FDQuery3
Left = 280
Top = 216
end
object FDQuery5: TFDQuery
Connection = FDConnection1
SQL.Strings = (
'SELECT * FROM '#20154#21592#34920)
Left = 512
Top = 120
end
object DataSource5: TDataSource
DataSet = FDQuery5
Left = 512
Top = 216
end
object FDQuery6: TFDQuery
Connection = FDConnection1
SQL.Strings = (
'SELECT * FROM '#20154#21592#34920' GROUP BY '#25152#22312#37096#38376#65288#29677#32452#65289' ORDER BY '#24207#21495)
Left = 624
Top = 120
end
object DataSource6: TDataSource
DataSet = FDQuery6
Left = 624
Top = 216
end
object FDQuery4: TFDQuery
Connection = FDConnection1
SQL.Strings = (
'SELECT * FROM '#24211#23384#34920)
Left = 400
Top = 120
end
object DataSource4: TDataSource
DataSet = FDQuery4
Left = 400
Top = 216
end
object FDQuery7: TFDQuery
Connection = FDConnection1
SQL.Strings = (
'SELECT '#24207#21495','#21697#21517','#25968#37327','#20837#24211#26085#26399',(case when julianday('#20837#24211#26085#26399') + '#20445#36136#26399#65288#22825#65289' <= juli' +
'anday('#39'now'#39') then '#39#24050#36807#26399#39' else '#39#26410#36807#26399#39' end ) as '#36807#26399#25552#31034' FROM '#24211#23384#34920)
Left = 40
Top = 296
end
object DataSource7: TDataSource
DataSet = FDQuery7
Left = 40
Top = 392
end
object FDQuery8: TFDQuery
Connection = FDConnection1
SQL.Strings = (
'SELECT '#24207#21495','#21697#21517','#25968#37327',Max('#20986#24211#26085#26399') as '#26368#36817#21457#25918',(case when julianday('#20986#24211#26085#26399') + '#25968 +
#37327'/(select count(*) from '#20154#21592#34920' where '#25152#22312#37096#38376#65288#29677#32452#65289'= '#20986#24211#34920'.'#25152#22312#37096#38376#65288#29677#32452#65289')*'#20351#29992#21608#26399#65288#22825 +
#65289' <= julianday('#39'now'#39') then '#39#24050#21040#26399#39' else '#39#26410#21040#26399#39' end ) as '#21040#26399#25552#31034','#39046#21462#20154','#25152#22312 +
#37096#38376#65288#29677#32452#65289',(select count(*) from '#20154#21592#34920' where '#25152#22312#37096#38376#65288#29677#32452#65289'= '#20986#24211#34920'.'#25152#22312#37096#38376#65288#29677#32452#65289') a' +
's '#20154#25968','#20351#29992#21608#26399#65288#22825#65289' FROM '#20986#24211#34920' GROUP BY '#25152#22312#37096#38376#65288#29677#32452#65289','#21697#21517' order by '#25152#22312#37096#38376#65288#29677#32452#65289','#21697#21517)
Left = 152
Top = 296
end
object DataSource8: TDataSource
DataSet = FDQuery8
Left = 152
Top = 392
end
end
unit DataUnit;
//1入库表;2品名表;3出库表;4库存表;5人员表;6人员表(部门班组);7库存提示;8发放提示;
interface
uses
System.SysUtils, System.Classes, FireDAC.Stan.Intf, FireDAC.Stan.Option,
FireDAC.Stan.Error, FireDAC.UI.Intf, FireDAC.Phys.Intf, FireDAC.Stan.Def,
FireDAC.Stan.Pool, FireDAC.Stan.Async, FireDAC.Phys, FireDAC.VCLUI.Wait,
Data.DB, FireDAC.Comp.Client, FireDAC.Stan.ExprFuncs,
FireDAC.Phys.SQLiteWrapper.Stat, FireDAC.Phys.SQLiteDef, FireDAC.Phys.SQLite,
FireDAC.Comp.UI, FireDAC.Stan.Param, FireDAC.DatS, FireDAC.DApt.Intf,
FireDAC.DApt, FireDAC.Comp.DataSet;
type
TDM1 = class(TDataModule)
FDConnection1: TFDConnection;
FDPhysSQLiteDriverLink1: TFDPhysSQLiteDriverLink;
FDGUIxWaitCursor1: TFDGUIxWaitCursor;
FDQuery1: TFDQuery;
DataSource1: TDataSource;
FDQuery2: TFDQuery;
DataSource2: TDataSource;
FDQuery3: TFDQuery;
DataSource3: TDataSource;
FDQuery5: TFDQuery;
DataSource5: TDataSource;
FDQuery6: TFDQuery;
DataSource6: TDataSource;
FDQuery4: TFDQuery;
DataSource4: TDataSource;
FDQuery7: TFDQuery;
DataSource7: TDataSource;
FDQuery8: TFDQuery;
DataSource8: TDataSource;
procedure DataModuleCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
DM1: TDM1;
const
dbPath = 'E:\WZGL\';
dbName = 'E:\WZGL\WZGLK.db';
implementation
{%CLASSGROUP 'Vcl.Controls.TControl'}
{$R *.dfm}
procedure TDM1.DataModuleCreate(Sender: TObject);
begin
{ 数据库连接类型 }
DM1.FDConnection1.DriverName := 'SQLite';
DM1.FDConnection1.Params.Add('DriverID=SQLite');
{ 当数据库文件不存在时,创建这个文件 }
if not FileExists(dbName) then
begin
if not DirectoryExists(dbPath) then //判断目录是否存在
try
begin
CreateDir(dbPath);
//ForceDirectories(Edit1.Text); 创建目录
end;
except
raise Exception.Create('无法创建 '+dbPath);
end;
DM1.FDConnection1.Params.Add('Database=' + dbName);
DM1.FDConnection1.Connected := True;
DM1.FDConnection1.ExecSQL('CREATE TABLE 入库表(序号 int PRIMARY KEY, 品名 string(20), 数量 int, 规格 string(10),入库日期 date,保管人 string(8),使用周期(天) int,保质期(天) int)'); { 执行SQL语句 }
DM1.FDConnection1.ExecSQL('CREATE TABLE 品名表(序号 int PRIMARY KEY, 品名代号 string(10),品名 string(20), 规格 string(10),使用周期(天) int,保质期(天) int)'); { 执行SQL语句 }
DM1.FDConnection1.ExecSQL('CREATE TABLE 出库表(序号 int PRIMARY KEY, 品名 string(20), 数量 int, 规格 string(10),出库日期 date,领取人 string(8),所在部门(班组) string(12),使用周期(天) int,发放理由 string)'); { 执行SQL语句 }
DM1.FDConnection1.ExecSQL('CREATE TABLE 库存表(序号 int PRIMARY KEY, 品名 string(20), 数量 int, 规格 string(10),入库日期 date,保管人 string(8),使用周期(天) int,保质期(天) int)'); { 执行SQL语句 }
DM1.FDConnection1.ExecSQL('CREATE TABLE 人员表(序号 int PRIMARY KEY, 所在部门(班组) string(12),姓名 string(8),职名 string(12))'); { 执行SQL语句 }
end
{ 当数据库文件存在时,直接进行连接 }
else
begin
DM1.FDConnection1.Params.Add('Database=' + dbName);
DM1.FDConnection1.Connected := True;
end;
end;
end.
......@@ -14,6 +14,7 @@ object Form2: TForm2
Font.Style = []
OldCreateOrder = False
Position = poMainFormCenter
OnCreate = FormCreate
OnShow = FormShow
PixelsPerInch = 96
TextHeight = 13
......@@ -72,7 +73,6 @@ object Form2: TForm2
Width = 32
Height = 17
DataField = #24207#21495
DataSource = DataSource1
end
object Label8: TLabel
Left = 444
......@@ -81,49 +81,13 @@ object Form2: TForm2
Height = 13
Caption = #20445#36136#26399#65288#22825#65289
end
object DBEdit3: TDBEdit
Left = 341
Top = 53
Width = 67
Height = 21
DataField = #25968#37327
DataSource = DataSource1
TabOrder = 0
end
object DBEdit4: TDBEdit
Left = 469
Top = 53
Width = 121
Height = 21
DataField = #35268#26684
DataSource = DataSource1
TabOrder = 1
end
object DBEdit6: TDBEdit
Left = 207
Top = 101
Width = 66
Height = 21
DataField = #20445#31649#20154
DataSource = DataSource1
TabOrder = 2
end
object DBEdit7: TDBEdit
Left = 377
Top = 101
Width = 61
Height = 21
DataField = #20351#29992#21608#26399#65288#22825#65289
DataSource = DataSource1
TabOrder = 3
end
object Button1: TButton
Left = 140
Top = 343
Width = 111
Height = 41
Caption = #30830#23450
TabOrder = 4
TabOrder = 0
OnClick = Button1Click
end
object Button2: TButton
......@@ -132,7 +96,7 @@ object Form2: TForm2
Width = 111
Height = 41
Caption = #21462#28040
TabOrder = 5
TabOrder = 1
OnClick = Button2Click
end
object DBGrid1: TDBGrid
......@@ -140,9 +104,9 @@ object Form2: TForm2
Top = 152
Width = 559
Height = 137
DataSource = DataSource1
DataSource = DM1.DataSource1
ReadOnly = True
TabOrder = 6
TabOrder = 2
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -11
......@@ -154,9 +118,9 @@ object Form2: TForm2
Top = 288
Width = 558
Height = 25
DataSource = DataSource1
DataSource = DM1.DataSource1
VisibleButtons = [nbFirst, nbPrior, nbNext, nbLast, nbPost, nbCancel]
TabOrder = 7
TabOrder = 3
end
object DBLookupComboBox1: TDBLookupComboBox
Left = 140
......@@ -165,53 +129,62 @@ object Form2: TForm2
Height = 21
KeyField = #24207#21495
ListField = #21697#21517
ListSource = DataSource2
TabOrder = 8
ListSource = DM1.DataSource2
TabOrder = 4
OnCloseUp = DBLookupComboBox1CloseUp
end
object DBEdit1: TDBEdit
Left = 522
Left = 341
Top = 53
Width = 92
Height = 21
DataField = #25968#37327
DataSource = DM1.DataSource1
TabOrder = 5
end
object DBEdit2: TDBEdit
Left = 469
Top = 53
Width = 121
Height = 21
DataField = #35268#26684
DataSource = DM1.DataSource1
TabOrder = 6
end
object DBEdit3: TDBEdit
Left = 82
Top = 101
Width = 67
Width = 79
Height = 21
DataField = #20445#36136#26399#65288#22825#65289
DataSource = DataSource1
DataField = #20837#24211#26085#26399
DataSource = DM1.DataSource1
TabOrder = 7
end
object DBEdit4: TDBEdit
Left = 209
Top = 101
Width = 72
Height = 21
DataField = #20445#31649#20154
DataSource = DM1.DataSource1
TabOrder = 8
end
object DBEdit5: TDBEdit
Left = 370
Top = 101
Width = 68
Height = 21
DataField = #20351#29992#21608#26399#65288#22825#65289
DataSource = DM1.DataSource1
TabOrder = 9
end
object DBEdit2: TDBEdit
Left = 85
object DBEdit6: TDBEdit
Left = 516
Top = 101
Width = 74
Height = 21
DataField = #20837#24211#26085#26399
DataSource = DataSource1
DataField = #20445#36136#26399#65288#22825#65289
DataSource = DM1.DataSource1
TabOrder = 10
end
object FDQuery1: TFDQuery
Connection = FDConnection1
SQL.Strings = (
'select * from '#20837#24211#34920)
Left = 40
end
object FDConnection1: TFDConnection
Params.Strings = (
'LockingMode=Normal'
'DriverID=SQLite')
Connected = True
LoginPrompt = False
end
object DataSource1: TDataSource
DataSet = FDQuery1
Left = 80
end
object FDQuery2: TFDQuery
Connection = FDConnection1
SQL.Strings = (
'SELECT * FROM '#21697#21517#34920)
Left = 160
end
object DataSource2: TDataSource
DataSet = FDQuery2
Left = 192
end
end
......@@ -4,46 +4,37 @@ interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, FireDAC.Stan.Intf,
FireDAC.Stan.Option, FireDAC.Stan.Param, FireDAC.Stan.Error, FireDAC.DatS,
FireDAC.Phys.Intf, FireDAC.DApt.Intf, FireDAC.Stan.Async, FireDAC.DApt,
FireDAC.UI.Intf, FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Phys,
FireDAC.Phys.SQLite, FireDAC.Phys.SQLiteDef, FireDAC.Stan.ExprFuncs,
FireDAC.Phys.SQLiteWrapper.Stat, FireDAC.VCLUI.Wait, Vcl.Mask, Vcl.DBCtrls,
Data.DB, FireDAC.Comp.Client, FireDAC.Comp.DataSet, Vcl.ExtCtrls, Vcl.Grids,
Vcl.DBGrids;
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,Vcl.Mask, Vcl.DBCtrls,
Data.DB,Vcl.ExtCtrls, Vcl.Grids,Vcl.DBGrids;
type
TMyNavgator = class(TDBNavigator);
TForm2 = class(TForm)
Label1: TLabel;
FDQuery1: TFDQuery;
FDConnection1: TFDConnection;
DataSource1: TDataSource;
Label2: TLabel;
Label3: TLabel;
DBEdit3: TDBEdit;
Label4: TLabel;
DBEdit4: TDBEdit;
Label5: TLabel;
Label6: TLabel;
DBEdit6: TDBEdit;
Label7: TLabel;
DBEdit7: TDBEdit;
Button1: TButton;
Button2: TButton;
DBGrid1: TDBGrid;
DBNavigator1: TDBNavigator;
FDQuery2: TFDQuery;
DBText1: TDBText;
DataSource2: TDataSource;
DBLookupComboBox1: TDBLookupComboBox;
Label8: TLabel;
DBEdit1: TDBEdit;
DBEdit2: TDBEdit;
DBEdit3: TDBEdit;
DBEdit4: TDBEdit;
DBEdit5: TDBEdit;
DBEdit6: TDBEdit;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure DBLookupComboBox1CloseUp(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
......@@ -56,7 +47,7 @@ var
implementation
uses PubUnit;
uses DataUnit;
{$R *.dfm}
......@@ -69,64 +60,64 @@ begin
application.MessageBox('品名不能为空!','系统提示',mb_ok+mb_iconinformation);
exit;
end;
if DBedit3.text='' then
if DBedit1.text='' then
begin
application.MessageBox('数量不能为空!','系统提示',mb_ok+mb_iconinformation);
exit;
end;
FDQuery1.post;
FDQuery1.Open('SELECT * FROM 入库表 order by 序号 desc limit 1'); //每次仅更新最大序号入库记录
with FDQuery2 do //操作库存表
DM1.FDQuery1.post;
DM1.FDQuery1.Open('SELECT * FROM 入库表 order by 序号 desc limit 1'); //每次仅更新最大序号入库记录
with DM1.FDQuery4 do //操作库存表
begin
close;
sql.Clear ;
sql.Add('select * from 库存表');
open;
FDQuery1.First; //入库表定位于首记录
while not FDQuery1.Eof do //当入库表非空时,循环开始
DM1.FDQuery1.First; //入库表定位于首记录
while not DM1.FDQuery1.Eof do //当入库表非空时,循环开始
begin
i:=0;
FDQuery2.first; //库存表定位于首记录
while not FDQuery2.Eof do //当库存表非空时,循环开始
first; //库存表定位于首记录
while not Eof do //当库存表非空时,循环开始
begin
if FDQuery2.Fields[1].value=FDQuery1.Fields[1].Value then //当库存表品名等于入库表品名时
if Fields[1].value=DM1.FDQuery1.Fields[1].Value then //当库存表品名等于入库表品名时
begin
FDQuery2.edit; //编辑库存表
FDQuery2.Fields[2].value:=(FDQuery2.Fields[2].value)+(FDQuery1.Fields[2].Value); //库存数量累加
FDQuery2.Fields[4].value:= FDQuery1.Fields[4].Value; //更新入库日期
edit; //编辑库存表
Fields[2].value:=(Fields[2].value)+(DM1.FDQuery1.Fields[2].Value); //库存数量累加
Fields[4].value:= DM1.FDQuery1.Fields[4].Value; //更新入库日期
post;
i:=1; // 找到该商品
break; //跳出内循环
end;
FDQuery2.Next ; //到库存表下一记录
Next ; //到库存表下一记录
end;
if i=0 then //如果标记为0,即未找到同名商品
begin
FDQuery2.Append; //库存表追加记录
FDQuery2.Fields[0].value:=FDQuery2.RecordCount+1; //添加序号
FDQuery2.Fields[1].value:=FDQuery1.Fields[1].Value; //库存表添加新品名
FDQuery2.Fields[2].value:=(FDQuery1.Fields[2].Value); //库存表添加数量
FDQuery2.Fields[3].value:=(FDQuery1.Fields[3].Value); //添加规格
FDQuery2.Fields[4].value:=(FDQuery1.Fields[4].Value); //添加入库日期
FDQuery2.Fields[5].value:=(FDQuery1.Fields[5].Value); //添加保管人
FDQuery2.Fields[6].value:=(FDQuery1.Fields[6].Value); //添加使用周期(天)
FDQuery2.Fields[7].value:=(FDQuery1.Fields[7].Value); //添加保质期(天)
Append; //库存表追加记录
Fields[0].value:=RecordCount+1; //添加序号
Fields[1].value:=DM1.FDQuery1.Fields[1].Value; //库存表添加新品名
Fields[2].value:=(DM1.FDQuery1.Fields[2].Value); //库存表添加数量
Fields[3].value:=(DM1.FDQuery1.Fields[3].Value); //添加规格
Fields[4].value:=(DM1.FDQuery1.Fields[4].Value); //添加入库日期
Fields[5].value:=(DM1.FDQuery1.Fields[5].Value); //添加保管人
Fields[6].value:=(DM1.FDQuery1.Fields[6].Value); //添加使用周期(天)
Fields[7].value:=(DM1.FDQuery1.Fields[7].Value); //添加保质期(天)
post; //保存
end;
FDQuery1.Next ; //到入库表下一记录
DM1.FDQuery1.Next ; //到入库表下一记录
end;
end;
FDConnection1.commit;
DM1.FDConnection1.commit;
//FDConnection1.Connected := false;
close;
end;
procedure TForm2.Button2Click(Sender: TObject);
begin
FDConnection1.rollback;
DM1.FDConnection1.rollback;
//FDConnection1.Connected := false;
close;
end;
......@@ -135,27 +126,42 @@ end;
procedure TForm2.DBLookupComboBox1CloseUp(Sender: TObject);
begin
FDQuery1.FieldByName('品名').value := DBlookupcombobox1.text;
FDQuery1.FieldByName('规格').value := FDQuery2.FieldByName('规格').Value;
FDQuery1.FieldByName('使用周期(天)').value := FDQuery2.FieldByName('使用周期(天)').Value;
FDQuery1.FieldByName('保质期(天)').value := FDQuery2.FieldByName('保质期(天)').Value;
DM1.FDQuery1.FieldByName('品名').value := DBlookupcombobox1.text;
DM1.FDQuery1.FieldByName('规格').value := DM1.FDQuery2.FieldByName('规格').Value;
DM1.FDQuery1.FieldByName('使用周期(天)').value := DM1.FDQuery2.FieldByName('使用周期(天)').Value;
DM1.FDQuery1.FieldByName('保质期(天)').value := DM1.FDQuery2.FieldByName('保质期(天)').Value;
end;
procedure TForm2.FormCreate(Sender: TObject);
begin
TMyNavgator(DBNavigator1).Buttons[nbFirst].Caption:= '首记录 ';
//TMyNavgator(DBNavigator1).Buttons[nbFirst].Glyph:=nil; //不显示图标
TMyNavgator(DBNavigator1).Buttons[nbPrior].Caption:= '上一行 ';
TMyNavgator(DBNavigator1).Buttons[nbNext].Caption:= '下一行 ';
TMyNavgator(DBNavigator1).Buttons[nbLast].Caption:= '末记录 ';
TMyNavgator(DBNavigator1).Buttons[nbInsert].Caption:= '增加 ';
TMyNavgator(DBNavigator1).Buttons[nbDelete].Caption:= '删除 ';
TMyNavgator(DBNavigator1).Buttons[nbEdit].Caption:= '修改 ';
TMyNavgator(DBNavigator1).Buttons[nbPost].Caption:= '提交 ';
TMyNavgator(DBNavigator1).Buttons[nbCancel].Caption:= '撤销 ';
TMyNavgator(DBNavigator1).Buttons[nbRefresh].Caption:= '刷新 ';
end;
procedure TForm2.FormShow(Sender: TObject);
begin
FDConnection1.Params.Add('Database=' + dbName);
FDConnection1.Connected := True;
FDQuery1.Close;
FDQuery1.Open('SELECT * FROM 入库表');
FDQuery2.Close;
FDQuery2.Open('SELECT * FROM 品名表');
FDConnection1.starttransaction;
DM1.FDConnection1.Connected := True;
DM1.FDConnection1.starttransaction;
DM1.FDQuery1.Close;
DM1.FDQuery1.Open('SELECT * FROM 入库表');
DM1.FDQuery2.Close;
DM1.FDQuery2.Open('SELECT * FROM 品名表');
try
with FDQuery1 do
with DM1.FDQuery1 do
begin
refresh; //数据表刷新,否则第二次打开本窗体会提示下标越界
Append;
FieldByName('序号').value := FDQuery1.RecordCount+1;
FieldByName('序号').value := RecordCount+1;
FieldByName('入库日期').value := date();
FieldByName('保管人').value := '付刚刚';
Fields[0].DisplayWidth := 4; //这个宽度指字符数
......@@ -167,7 +173,7 @@ begin
//DBLookupComboBox1.KeyValue:= DBLookupComboBox1.ListSource.DataSet[DBLookupComboBox1.KeyField];
end;
except
FDConnection1.rollback;
DM1.FDConnection1.rollback;
end;
end;
......
......@@ -17,21 +17,30 @@ object Form5: TForm5
PixelsPerInch = 96
TextHeight = 13
object Button1: TButton
Left = 68
Left = 52
Top = 51
Width = 173
Width = 121
Height = 50
Caption = #22686#21152#21697#21517#25968#25454
Caption = #22686#21152#21697#21517
TabOrder = 0
OnClick = Button1Click
end
object Button2: TButton
Left = 316
Left = 218
Top = 51
Width = 173
Width = 121
Height = 50
Caption = #20462#25913#20154#21592#25968#25454
Caption = #20462#25913#20154#21592
TabOrder = 1
OnClick = Button2Click
end
object Button3: TButton
Left = 384
Top = 51
Width = 121
Height = 50
Caption = #36864#20986
TabOrder = 2
OnClick = Button3Click
end
end
......@@ -4,21 +4,17 @@ interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, FireDAC.Stan.Intf,
FireDAC.Stan.Option, FireDAC.Stan.Param, FireDAC.Stan.Error, FireDAC.DatS,
FireDAC.Phys.Intf, FireDAC.DApt.Intf, FireDAC.Stan.Async, FireDAC.DApt,
FireDAC.UI.Intf, FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Phys,
FireDAC.Phys.SQLite, FireDAC.Phys.SQLiteDef, FireDAC.Stan.ExprFuncs,
FireDAC.Phys.SQLiteWrapper.Stat, FireDAC.VCLUI.Wait, Vcl.Mask, Vcl.DBCtrls,
Data.DB, FireDAC.Comp.Client, FireDAC.Comp.DataSet, Vcl.ExtCtrls, Vcl.Grids,
Vcl.DBGrids;
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,Vcl.Mask, Vcl.DBCtrls,
Data.DB,Vcl.ExtCtrls, Vcl.Grids,Vcl.DBGrids;
type
TForm5 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
......@@ -38,20 +34,21 @@ uses SheZhi_renyuan,SheZhi_pinming;
procedure TForm5.Button1Click(Sender: TObject);
begin
Application.CreateForm(TForm8, Form8);
form8.showmodal;
close;
end;
procedure TForm5.Button2Click(Sender: TObject);
begin
Application.CreateForm(TForm7, Form7);
form7.showmodal;
close;
end;
procedure TForm5.Button3Click(Sender: TObject);
begin
close;
end;
end.
......@@ -14,6 +14,7 @@ object Form8: TForm8
Font.Style = []
OldCreateOrder = False
Position = poMainFormCenter
OnCreate = FormCreate
OnShow = FormShow
PixelsPerInch = 96
TextHeight = 13
......@@ -58,7 +59,7 @@ object Form8: TForm8
Width = 43
Height = 17
DataField = #24207#21495
DataSource = DataSource1
DataSource = DM1.DataSource2
end
object Label8: TLabel
Left = 458
......@@ -73,7 +74,7 @@ object Form8: TForm8
Width = 61
Height = 21
DataField = #21697#21517#20195#21495
DataSource = DataSource1
DataSource = DM1.DataSource2
TabOrder = 0
end
object DBEdit4: TDBEdit
......@@ -82,7 +83,7 @@ object Form8: TForm8
Width = 93
Height = 21
DataField = #35268#26684
DataSource = DataSource1
DataSource = DM1.DataSource2
TabOrder = 1
end
object DBEdit6: TDBEdit
......@@ -91,7 +92,7 @@ object Form8: TForm8
Width = 61
Height = 21
DataField = #20351#29992#21608#26399#65288#22825#65289
DataSource = DataSource1
DataSource = DM1.DataSource2
TabOrder = 2
end
object DBEdit7: TDBEdit
......@@ -100,7 +101,7 @@ object Form8: TForm8
Width = 61
Height = 21
DataField = #20445#36136#26399#65288#22825#65289
DataSource = DataSource1
DataSource = DM1.DataSource2
TabOrder = 3
end
object Button1: TButton
......@@ -126,7 +127,7 @@ object Form8: TForm8
Top = 152
Width = 559
Height = 137
DataSource = DataSource1
DataSource = DM1.DataSource2
ReadOnly = True
TabOrder = 6
TitleFont.Charset = DEFAULT_CHARSET
......@@ -140,7 +141,7 @@ object Form8: TForm8
Top = 288
Width = 558
Height = 25
DataSource = DataSource1
DataSource = DM1.DataSource2
VisibleButtons = [nbFirst, nbPrior, nbNext, nbLast, nbPost, nbCancel]
TabOrder = 7
end
......@@ -150,24 +151,7 @@ object Form8: TForm8
Width = 121
Height = 21
DataField = #21697#21517
DataSource = DataSource1
DataSource = DM1.DataSource2
TabOrder = 8
end
object FDQuery1: TFDQuery
Connection = FDConnection1
SQL.Strings = (
'select * from '#21697#21517#34920)
Left = 40
end
object FDConnection1: TFDConnection
Params.Strings = (
'LockingMode=Normal'
'DriverID=SQLite')
Connected = True
LoginPrompt = False
end
object DataSource1: TDataSource
DataSet = FDQuery1
Left = 80
end
end
......@@ -4,21 +4,13 @@ interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, FireDAC.Stan.Intf,
FireDAC.Stan.Option, FireDAC.Stan.Param, FireDAC.Stan.Error, FireDAC.DatS,
FireDAC.Phys.Intf, FireDAC.DApt.Intf, FireDAC.Stan.Async, FireDAC.DApt,
FireDAC.UI.Intf, FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Phys,
FireDAC.Phys.SQLite, FireDAC.Phys.SQLiteDef, FireDAC.Stan.ExprFuncs,
FireDAC.Phys.SQLiteWrapper.Stat, FireDAC.VCLUI.Wait, Vcl.Mask, Vcl.DBCtrls,
Data.DB, FireDAC.Comp.Client, FireDAC.Comp.DataSet, Vcl.ExtCtrls, Vcl.Grids,
Vcl.DBGrids;
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,Vcl.Mask, Vcl.DBCtrls,
Data.DB,Vcl.ExtCtrls,Vcl.Grids,Vcl.DBGrids;
type
TMyNavgator = class(TDBNavigator);
TForm8 = class(TForm)
Label1: TLabel;
FDQuery1: TFDQuery;
FDConnection1: TFDConnection;
DataSource1: TDataSource;
Label2: TLabel;
Label3: TLabel;
DBEdit3: TDBEdit;
......@@ -37,6 +29,7 @@ type
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
......@@ -48,7 +41,7 @@ var
Form8: TForm8;
implementation
uses pubunit;
uses dataunit;
{$R *.dfm}
......@@ -65,40 +58,55 @@ begin
exit;
end;
FDQuery1.post;
FDConnection1.commit;
//FDConnection1.Connected := false;
dm1.FDQuery2.post;
dm1.FDConnection1.commit;
//dm1.FDConnection1.Connected := false;
close;
end;
procedure TForm8.Button2Click(Sender: TObject);
begin
FDConnection1.rollback;
//FDConnection1.Connected := false;
dm1.FDConnection1.rollback;
//dm1.FDConnection1.Connected := false;
close;
end;
procedure TForm8.FormCreate(Sender: TObject);
begin
TMyNavgator(DBNavigator1).Buttons[nbFirst].Caption:= '首记录 ';
//TMyNavgator(DBNavigator1).Buttons[nbFirst].Glyph:=nil; //不显示图标
TMyNavgator(DBNavigator1).Buttons[nbPrior].Caption:= '上一行 ';
TMyNavgator(DBNavigator1).Buttons[nbNext].Caption:= '下一行 ';
TMyNavgator(DBNavigator1).Buttons[nbLast].Caption:= '末记录 ';
TMyNavgator(DBNavigator1).Buttons[nbInsert].Caption:= '增加 ';
TMyNavgator(DBNavigator1).Buttons[nbDelete].Caption:= '删除 ';
TMyNavgator(DBNavigator1).Buttons[nbEdit].Caption:= '修改 ';
TMyNavgator(DBNavigator1).Buttons[nbPost].Caption:= '提交 ';
TMyNavgator(DBNavigator1).Buttons[nbCancel].Caption:= '撤销 ';
TMyNavgator(DBNavigator1).Buttons[nbRefresh].Caption:= '刷新 ';
end;
procedure TForm8.FormShow(Sender: TObject);
begin
FDConnection1.Params.Add('Database=' + dbName);
FDConnection1.Connected := True;
FDQuery1.Close;
FDQuery1.Open('SELECT * FROM 品名表');
FDConnection1.starttransaction;
dm1.FDConnection1.Connected := True;
dm1.FDConnection1.starttransaction;
dm1.FDQuery2.Close;
dm1.FDQuery2.Open('SELECT * FROM 品名表');
try
with FDQuery1 do
with dm1.FDQuery2 do
begin
refresh; //数据表刷新,否则第二次打开本窗体会提示下标越界
Append;
FieldByName('序号').value := FDQuery1.RecordCount+1;
FieldByName('序号').value := dm1.FDQuery2.RecordCount+1;
Fields[0].DisplayWidth := 4; //这个宽度指字符数
Fields[1].DisplayWidth := 8;
Fields[2].DisplayWidth := 20;
Fields[3].DisplayWidth := 10;
Fields[3].DisplayWidth := 8;
end;
//DBLookupComboBox1.KeyValue:= DBLookupComboBox1.ListSource.DataSet[DBLookupComboBox1.KeyField];
except
FDConnection1.rollback;
dm1.FDConnection1.rollback;
end;
end;
......
......@@ -14,6 +14,7 @@ object Form7: TForm7
Font.Style = []
OldCreateOrder = False
Position = poMainFormCenter
OnCreate = FormCreate
OnShow = FormShow
PixelsPerInch = 96
TextHeight = 13
......@@ -51,7 +52,7 @@ object Form7: TForm7
Width = 43
Height = 17
DataField = #24207#21495
DataSource = DataSource1
DataSource = DM1.DataSource5
end
object DBEdit3: TDBEdit
Left = 376
......@@ -59,7 +60,7 @@ object Form7: TForm7
Width = 61
Height = 21
DataField = #22995#21517
DataSource = DataSource1
DataSource = DM1.DataSource5
TabOrder = 0
end
object DBEdit4: TDBEdit
......@@ -68,7 +69,7 @@ object Form7: TForm7
Width = 103
Height = 21
DataField = #32844#21517
DataSource = DataSource1
DataSource = DM1.DataSource5
TabOrder = 1
end
object Button1: TButton
......@@ -94,7 +95,7 @@ object Form7: TForm7
Top = 96
Width = 559
Height = 193
DataSource = DataSource1
DataSource = DM1.DataSource5
TabOrder = 4
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
......@@ -107,7 +108,7 @@ object Form7: TForm7
Top = 288
Width = 550
Height = 25
DataSource = DataSource1
DataSource = DM1.DataSource5
TabOrder = 5
end
object DBEdit1: TDBEdit
......@@ -116,24 +117,7 @@ object Form7: TForm7
Width = 121
Height = 21
DataField = #25152#22312#37096#38376#65288#29677#32452#65289
DataSource = DataSource1
DataSource = DM1.DataSource5
TabOrder = 6
end
object FDQuery1: TFDQuery
Connection = FDConnection1
SQL.Strings = (
'select * from '#20154#21592#34920)
Left = 40
end
object FDConnection1: TFDConnection
Params.Strings = (
'LockingMode=Normal'
'DriverID=SQLite')
Connected = True
LoginPrompt = False
end
object DataSource1: TDataSource
DataSet = FDQuery1
Left = 80
end
end
......@@ -4,21 +4,13 @@ interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, FireDAC.Stan.Intf,
FireDAC.Stan.Option, FireDAC.Stan.Param, FireDAC.Stan.Error, FireDAC.DatS,
FireDAC.Phys.Intf, FireDAC.DApt.Intf, FireDAC.Stan.Async, FireDAC.DApt,
FireDAC.UI.Intf, FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Phys,
FireDAC.Phys.SQLite, FireDAC.Phys.SQLiteDef, FireDAC.Stan.ExprFuncs,
FireDAC.Phys.SQLiteWrapper.Stat, FireDAC.VCLUI.Wait, Vcl.Mask, Vcl.DBCtrls,
Data.DB, FireDAC.Comp.Client, FireDAC.Comp.DataSet, Vcl.ExtCtrls, Vcl.Grids,
Vcl.DBGrids;
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,Vcl.Mask, Vcl.DBCtrls,
Data.DB,Vcl.ExtCtrls, Vcl.Grids,Vcl.DBGrids;
type
TMyNavgator = class(TDBNavigator);
TForm7 = class(TForm)
Label1: TLabel;
FDQuery1: TFDQuery;
FDConnection1: TFDConnection;
DataSource1: TDataSource;
Label2: TLabel;
Label3: TLabel;
DBEdit3: TDBEdit;
......@@ -33,6 +25,7 @@ type
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
......@@ -44,7 +37,7 @@ var
Form7: TForm7;
implementation
uses pubunit;
uses dataunit;
{$R *.dfm}
......@@ -66,35 +59,52 @@ begin
exit;
end;
FDQuery1.refresh; //刷新当前数据库状态,否则记录移动有可能出错!
FDQuery1.first; //人员表定位于首记录
while not FDQuery1.Eof do //当表非空时,循环开始
dm1.FDQuery5.refresh; //刷新当前数据库状态,否则记录移动有可能出错!
dm1.FDQuery5.first; //人员表定位于首记录
while not dm1.FDQuery5.Eof do //当表非空时,循环开始
begin
FDQuery1.edit; //进入编辑状态,每次移动记录均退出编辑状态,因此要再次进入方可修改
FDQuery1.Fields[0].value:= FDQuery1.RecNo; //全部序号等于当前记录号
FDQuery1.Next ; //到下一记录
dm1.FDQuery5.edit; //进入编辑状态,每次移动记录均退出编辑状态,因此要再次进入方可修改
dm1.FDQuery5.Fields[0].value:= dm1.FDQuery5.RecNo; //全部序号等于当前记录号
dm1.FDQuery5.Next ; //到下一记录
end;
FDConnection1.commit;
//FDConnection1.Connected := false;
dm1.FDConnection1.commit;
//dm1.FDConnection1.Connected := false;
close;
end;
procedure TForm7.Button2Click(Sender: TObject);
begin
FDConnection1.rollback;
//FDConnection1.Connected := false;
dm1.FDConnection1.rollback;
//dm1.FDConnection1.Connected := false;
close;
end;
procedure TForm7.FormCreate(Sender: TObject);
begin
TMyNavgator(DBNavigator1).Buttons[nbFirst].Caption:= '首行 ';
//TMyNavgator(DBNavigator1).Buttons[nbFirst].Glyph:=nil; //不显示图标
TMyNavgator(DBNavigator1).Buttons[nbPrior].Caption:= '上行 ';
TMyNavgator(DBNavigator1).Buttons[nbNext].Caption:= '下行 ';
TMyNavgator(DBNavigator1).Buttons[nbLast].Caption:= '末行 ';
TMyNavgator(DBNavigator1).Buttons[nbInsert].Caption:= '增加 ';
TMyNavgator(DBNavigator1).Buttons[nbDelete].Caption:= '删除 ';
TMyNavgator(DBNavigator1).Buttons[nbEdit].Caption:= '修改 ';
TMyNavgator(DBNavigator1).Buttons[nbPost].Caption:= '提交 ';
TMyNavgator(DBNavigator1).Buttons[nbCancel].Caption:= '撤销 ';
TMyNavgator(DBNavigator1).Buttons[nbRefresh].Caption:= '刷新 ';
end;
procedure TForm7.FormShow(Sender: TObject);
begin
FDConnection1.Params.Add('Database=' + dbName);
FDConnection1.Connected := True;
FDQuery1.Close;
FDQuery1.Open('SELECT * FROM 人员表');
FDConnection1.starttransaction;
dm1.FDConnection1.Connected := True;
dm1.FDConnection1.starttransaction;
dm1.FDQuery5.Close;
dm1.FDQuery5.Open('SELECT * FROM 人员表');
//showmessage(dm1.FDQuery5.sql.text);
try
with FDQuery1 do
with dm1.FDQuery5 do
begin
first;
if Eof then
......@@ -102,7 +112,7 @@ begin
edit; //进入编辑状态
refresh; //数据表刷新,否则第二次打开本窗体会提示下标越界
Append;
FieldByName('序号').value := FDQuery1.RecordCount+1;
FieldByName('序号').value := dm1.FDQuery5.RecordCount+1;
end;
Fields[0].DisplayWidth := 4; //这个宽度指字符数
Fields[1].DisplayWidth := 16;
......@@ -111,7 +121,7 @@ begin
end;
//DBLookupComboBox1.KeyValue:= DBLookupComboBox1.ListSource.DataSet[DBLookupComboBox1.KeyField];
except
FDConnection1.rollback;
dm1.FDConnection1.rollback;
end;
end;
......
......@@ -54,7 +54,7 @@ object Form6: TForm6
Top = 51
Width = 559
Height = 118
DataSource = DataSource1
DataSource = DM1.DataSource7
ReadOnly = True
TabOrder = 2
TitleFont.Charset = DEFAULT_CHARSET
......@@ -69,7 +69,7 @@ object Form6: TForm6
Top = 202
Width = 559
Height = 118
DataSource = DataSource2
DataSource = DM1.DataSource8
ReadOnly = True
TabOrder = 3
TitleFont.Charset = DEFAULT_CHARSET
......@@ -79,30 +79,4 @@ object Form6: TForm6
TitleFont.Style = []
OnDrawDataCell = DBGrid2DrawDataCell
end
object FDQuery1: TFDQuery
Connection = FDConnection1
SQL.Strings = (
'select * from '#24211#23384#34920)
Left = 240
end
object FDConnection1: TFDConnection
Params.Strings = (
'LockingMode=Normal'
'DriverID=SQLite')
Left = 168
end
object DataSource1: TDataSource
DataSet = FDQuery1
Left = 312
end
object FDQuery2: TFDQuery
Connection = FDConnection1
SQL.Strings = (
'select * from '#20986#24211#34920)
Left = 448
end
object DataSource2: TDataSource
DataSet = FDQuery2
Left = 520
end
end
......@@ -4,28 +4,17 @@ interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, FireDAC.Stan.Intf,
FireDAC.Stan.Option, FireDAC.Stan.Param, FireDAC.Stan.Error, FireDAC.DatS,
FireDAC.Phys.Intf, FireDAC.DApt.Intf, FireDAC.Stan.Async, FireDAC.DApt,
FireDAC.UI.Intf, FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Phys,
FireDAC.Phys.SQLite, FireDAC.Phys.SQLiteDef, FireDAC.Stan.ExprFuncs,
FireDAC.Phys.SQLiteWrapper.Stat, FireDAC.VCLUI.Wait, Vcl.Mask, Vcl.DBCtrls,
Data.DB, FireDAC.Comp.Client, FireDAC.Comp.DataSet, Vcl.ExtCtrls, Vcl.Grids,
Vcl.DBGrids;
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,Vcl.Mask, Vcl.DBCtrls,
Data.DB,Vcl.ExtCtrls, Vcl.Grids,Vcl.DBGrids;
type
TForm6 = class(TForm)
Label1: TLabel;
FDQuery1: TFDQuery;
FDConnection1: TFDConnection;
DataSource1: TDataSource;
Label2: TLabel;
Button1: TButton;
Button2: TButton;
DBGrid1: TDBGrid;
DBGrid2: TDBGrid;
FDQuery2: TFDQuery;
DataSource2: TDataSource;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormShow(Sender: TObject);
......@@ -44,7 +33,7 @@ var
Form6: TForm6;
implementation
uses pubunit;
uses dataunit;
{$R *.dfm}
......@@ -61,12 +50,12 @@ end;
procedure TForm6.FormShow(Sender: TObject);
begin
FDConnection1.Params.Add('Database=' + dbName);
FDConnection1.Connected := True;
with FDQuery1 do
dm1.FDConnection1.Connected := True;
with dm1.FDQuery7 do
begin
Close;
Open('SELECT 序号,品名,数量,入库日期,(case when julianday(入库日期) + 保质期(天) <= julianday(''now'') then ''已过期'' else ''未过期'' end ) as 过期提示 FROM 库存表');
open;
//Open('SELECT 序号,品名,数量,入库日期,(case when julianday(入库日期) + 保质期(天) <= julianday(''now'') then ''已过期'' else ''未过期'' end ) as 过期提示 FROM 库存表');
Fields[0].DisplayWidth := 4; //这个宽度指字符数
Fields[1].DisplayWidth := 20;
Fields[2].DisplayWidth := 6;
......@@ -74,12 +63,13 @@ begin
Fields[4].DisplayWidth := 8;
end;
with FDQuery2 do
with dm1.FDQuery8 do
begin
Close;
Open('SELECT 序号,品名,数量,Max(出库日期) as 最近发放,'+
'(case when julianday(出库日期) + 数量/(select count(*) from 人员表 where 所在部门(班组)= 出库表.所在部门(班组))*使用周期(天) <= julianday(''now'') then ''已到期'' else ''未到期'' end ) as 到期提示,'+
'领取人,所在部门(班组),(select count(*) from 人员表 where 所在部门(班组)= 出库表.所在部门(班组)) as 人数,使用周期(天) FROM 出库表 GROUP BY 所在部门(班组),品名 order by 所在部门(班组),品名');
open;
//Open('SELECT 序号,品名,数量,Max(出库日期) as 最近发放,'+
//'(case when julianday(出库日期) + 数量/(select count(*) from 人员表 where 所在部门(班组)= 出库表.所在部门(班组))*使用周期(天) <= julianday(''now'') then ''已到期'' else ''未到期'' end ) as 到期提示,'+
//'领取人,所在部门(班组),(select count(*) from 人员表 where 所在部门(班组)= 出库表.所在部门(班组)) as 人数,使用周期(天) FROM 出库表 GROUP BY 所在部门(班组),品名 order by 所在部门(班组),品名');
Fields[0].DisplayWidth := 4; //这个宽度指字符数
Fields[1].DisplayWidth := 20;
Fields[2].DisplayWidth := 6;
......@@ -98,7 +88,7 @@ procedure TForm6.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
begin
if column.fieldname='过期提示' then
begin
if FDQuery1.Fields[4].value= '已过期' then
if dm1.FDQuery7.Fields[4].value= '已过期' then
begin
DBGrid1.Canvas.Font.Color := clred; //满足条件时,显示的字体颜色为“红色”
//DBGrid.Canvas.Brush.Color := clred; //满足条件时,显示的背景色颜色为“红色”
......@@ -114,7 +104,7 @@ procedure TForm6.DBGrid2DrawDataCell(Sender: TObject; const Rect: TRect;
begin
if field.fieldname='到期提示' then
begin
if FDQuery2.Fields[4].value= '已到期' then
if dm1.FDQuery8.Fields[4].value= '已到期' then
begin
DBGrid2.Canvas.Font.Color := clred; //满足条件时,显示的字体颜色为“红色”
//DBGrid.Canvas.Brush.Color := clred; //满足条件时,显示的背景色颜色为“红色”
......
......@@ -8,9 +8,9 @@ uses
SheZhi_renyuan in 'SheZhi_renyuan.pas' {Form7},
RuKu in 'RuKu.pas' {Form2},
ChaXun in 'ChaXun.pas' {Form4},
PubUnit in 'PubUnit.pas',
SheZhi in 'SheZhi.pas' {Form5},
SheZhi_pinming in 'SheZhi_pinming.pas' {Form8};
SheZhi_pinming in 'SheZhi_pinming.pas' {Form8},
DataUnit in 'DataUnit.pas' {DM1: TDataModule};
{$R *.res}
......@@ -18,14 +18,13 @@ begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.Title := 'ÒßÇé·À¿ØÎï×ʹÜÀí';
Application.CreateForm(TDM1, DM1);
Application.CreateForm(TForm1, Form1);
Application.CreateForm(TForm6, Form6);
Application.CreateForm(TForm3, Form3);
Application.CreateForm(TForm7, Form7);
Application.CreateForm(TForm2, Form2);
Application.CreateForm(TForm2, Form2);
Application.CreateForm(TForm3, Form3);
Application.CreateForm(TForm4, Form4);
Application.CreateForm(TForm5, Form5);
Application.CreateForm(TForm8, Form8);
Application.CreateForm(TForm6, Form6);
Application.Run;
end.
......@@ -88,9 +88,9 @@
<VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo>
<VerInfo_Locale>1033</VerInfo_Locale>
<VerInfo_AutoIncVersion>true</VerInfo_AutoIncVersion>
<VerInfo_Keys>CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.6.7;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
<VerInfo_Release>6</VerInfo_Release>
<VerInfo_Build>7</VerInfo_Build>
<VerInfo_Keys>CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.7.4;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
<VerInfo_Release>7</VerInfo_Release>
<VerInfo_Build>4</VerInfo_Build>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_2)'!=''">
<DCC_LocalDebugSymbols>false</DCC_LocalDebugSymbols>
......@@ -130,7 +130,6 @@
<Form>Form4</Form>
<FormType>dfm</FormType>
</DCCReference>
<DCCReference Include="PubUnit.pas"/>
<DCCReference Include="SheZhi.pas">
<Form>Form5</Form>
<FormType>dfm</FormType>
......@@ -139,6 +138,11 @@
<Form>Form8</Form>
<FormType>dfm</FormType>
</DCCReference>
<DCCReference Include="DataUnit.pas">
<Form>DM1</Form>
<FormType>dfm</FormType>
<DesignClass>TDataModule</DesignClass>
</DCCReference>
<BuildConfiguration Include="Release">
<Key>Cfg_2</Key>
<CfgParent>Base</CfgParent>
......
文件已添加
......@@ -14,7 +14,6 @@ object Form1: TForm1
Font.Style = []
OldCreateOrder = False
Position = poScreenCenter
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object Image1: TImage
......@@ -9907,17 +9906,4 @@ object Form1: TForm1
6474647464746474647464740000}
OnClick = SpeedButton6Click
end
object FDConnection1: TFDConnection
Left = 48
Top = 8
end
object FDPhysSQLiteDriverLink1: TFDPhysSQLiteDriverLink
Left = 160
Top = 8
end
object FDGUIxWaitCursor1: TFDGUIxWaitCursor
Provider = 'Forms'
Left = 280
Top = 8
end
end
......@@ -5,13 +5,7 @@ interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Imaging.jpeg, Vcl.ExtCtrls,
Vcl.StdCtrls, Vcl.Buttons, FireDAC.Stan.Intf, FireDAC.Stan.Option,
FireDAC.Stan.Error, FireDAC.UI.Intf, FireDAC.Phys.Intf, FireDAC.Stan.Def,
FireDAC.Stan.Pool, FireDAC.Stan.Async, FireDAC.Phys, FireDAC.Phys.SQLite,
FireDAC.Phys.SQLiteDef, FireDAC.Stan.ExprFuncs,
FireDAC.Phys.SQLiteWrapper.Stat, FireDAC.VCLUI.Wait, FireDAC.Stan.Param,
FireDAC.DatS, FireDAC.DApt.Intf, FireDAC.DApt, Vcl.Mask, Vcl.DBCtrls, Data.DB,
FireDAC.Comp.DataSet, FireDAC.Comp.Client, FireDAC.Comp.UI;
Vcl.StdCtrls, Vcl.Buttons, Vcl.Mask, Vcl.DBCtrls, Data.DB;
type
TForm1 = class(TForm)
......@@ -24,16 +18,13 @@ type
Label2: TLabel;
SpeedButton5: TSpeedButton;
SpeedButton6: TSpeedButton;
FDConnection1: TFDConnection;
FDPhysSQLiteDriverLink1: TFDPhysSQLiteDriverLink;
FDGUIxWaitCursor1: TFDGUIxWaitCursor;
procedure SpeedButton5Click(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure SpeedButton2Click(Sender: TObject);
procedure SpeedButton3Click(Sender: TObject);
procedure SpeedButton4Click(Sender: TObject);
procedure SpeedButton6Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
......@@ -48,45 +39,10 @@ var
implementation
uses PubUnit,RuKu,ChuKu,ChaXun,SheZhi,TiShi;
uses RuKu,ChuKu,ChaXun,SheZhi,TiShi;
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
{ 数据库连接类型 }
FDConnection1.DriverName := 'SQLite';
FDConnection1.Params.Add('DriverID=SQLite');
{ 当数据库文件不存在时,创建这个文件 }
if not FileExists(dbName) then
begin
if not DirectoryExists(dbPath) then //判断目录是否存在
try
begin
CreateDir(dbPath);
//ForceDirectories(Edit1.Text); 创建目录
end;
except
raise Exception.Create('无法创建 '+dbPath);
end;
FDConnection1.Params.Add('Database=' + dbName);
FDConnection1.Connected := True;
FDConnection1.ExecSQL('CREATE TABLE 入库表(序号 int PRIMARY KEY, 品名 string(20), 数量 int, 规格 string(10),入库日期 date,保管人 string(8),使用周期(天) int,保质期(天) int)'); { 执行SQL语句 }
FDConnection1.ExecSQL('CREATE TABLE 出库表(序号 int PRIMARY KEY, 品名 string(20), 数量 int, 规格 string(10),出库日期 date,领取人 string(8),所在部门(班组) string(12),使用周期(天) int,发放理由 string)'); { 执行SQL语句 }
FDConnection1.ExecSQL('CREATE TABLE 库存表(序号 int PRIMARY KEY, 品名 string(20), 数量 int, 规格 string(10),入库日期 date,保管人 string(8),使用周期(天) int,保质期(天) int)'); { 执行SQL语句 }
FDConnection1.ExecSQL('CREATE TABLE 品名表(序号 int PRIMARY KEY, 品名代号 string(10),品名 string(20), 规格 string(10),使用周期(天) int,保质期(天) int)'); { 执行SQL语句 }
FDConnection1.ExecSQL('CREATE TABLE 人员表(序号 int PRIMARY KEY, 所在部门(班组) string(12),姓名 string(8),职名 string(12))'); { 执行SQL语句 }
end
{ 当数据库文件存在时,直接进行连接 }
else
begin
FDConnection1.Params.Add('Database=' + dbName);
FDConnection1.Connected := True;
end;
end;
procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册