📄 unit_production.~pas
字号:
unit Unit_Production;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, Grids, StdCtrls, Buttons, DB, ADODB, DBGrids, DBTables,
Spin, jpeg;
type
TfmProductionMgr = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
Panel4: TPanel;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
BitBtn3: TBitBtn;
Panel5: TPanel;
GroupBox1: TGroupBox;
BitBtn4: TBitBtn;
Label1: TLabel;
Edt_Name: TEdit;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Mmo_Des: TMemo;
RadioButton1: TRadioButton;
RadioButton2: TRadioButton;
RadioButton3: TRadioButton;
BitBtn5: TBitBtn;
BitBtn6: TBitBtn;
Image1: TImage;
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
StringGrid1: TStringGrid;
Label5: TLabel;
Notebook1: TNotebook;
Edt_ProQry: TEdit;
ComboBox1: TComboBox;
ComboBox2: TComboBox;
RadioGroup1: TRadioGroup;
SpinEdit1: TSpinEdit;
Label6: TLabel;
CB_AuthorName: TComboBox;
CB_AuthorCode: TComboBox;
Button1: TButton;
Edt_Price: TSpinEdit;
procedure FormCreate(Sender: TObject);
procedure BitBtn4Click(Sender: TObject);
procedure RadioButton1Click(Sender: TObject);
procedure RadioButton2Click(Sender: TObject);
procedure RadioButton3Click(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
procedure StringGrid1Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
procedure IniStringGrid;
procedure IniAuthor;
procedure ShowImageFromDB(ID: string);
function CreateSqlStr: string;
function FindAuthorIndex(AuthorID: string): integer;
{ Private declarations }
public
{ Public declarations }
end;
var
fmProductionMgr: TfmProductionMgr;
implementation
{$R *.dfm}
procedure TfmProductionMgr.IniStringGrid;
begin
StringGrid1.ColWidths[4] := 0;
StringGrid1.ColWidths[5] := 0;
StringGrid1.Cells[0,0] := '作品名称';
StringGrid1.Cells[1,0] := '作品作者';
StringGrid1.Cells[2,0] := '作品价格';
StringGrid1.Cells[3,0] := '作品描述';
StringGrid1.RowCount := 2;
StringGrid1.Cells[0,1] := '';
StringGrid1.Cells[1,1] := '';
StringGrid1.Cells[2,1] := '';
StringGrid1.Cells[3,1] := '';
end;
procedure TfmProductionMgr.IniAuthor;
var
connQuery: TADOQuery;
connAdo: TADOConnection;
connString: string;
sFilePath: string;
i: integer;
begin
sFilePath := ExtractFilePath(Application.ExeName);
connAdo := TADOConnection.Create(nil);
connQuery := TADOQuery.Create(nil);
connQuery.CommandTimeout := 60;
connQuery.Connection := connAdo;
connString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+sFilePath+'database.mdb';
try
connAdo.ConnectionString:=connString;
connAdo.Provider := 'Microsoft.Jet.OLEDB.4.0';
connAdo.LoginPrompt:=False;
connAdo.Connected:=True;
except
end;
with connQuery do
begin
close;
sql.Clear;
sql.Add('select * from 作者表');
open;
first;
i := 1;
while not eof do
begin
ComboBox1.Items.Add(Fields[1].AsString);
ComboBox2.Items.Add(Fields[0].AsString);
CB_AuthorName.Items.Add(Fields[1].AsString);
CB_AuthorCode.Items.Add(Fields[0].AsString);
Inc(i);
next;
end;
close;
end;
end;
procedure TfmProductionMgr.ShowImageFromDB(ID: string);
var
connQuery: TADOQuery;
connAdo: TADOConnection;
connString: string;
sFilePath: string;
i: integer;
begin
sFilePath := ExtractFilePath(Application.ExeName);
connAdo := TADOConnection.Create(nil);
connQuery := TADOQuery.Create(nil);
connQuery.CommandTimeout := 60;
connQuery.Connection := connAdo;
connString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+sFilePath+'database.mdb';
try
connAdo.ConnectionString:=connString;
connAdo.Provider := 'Microsoft.Jet.OLEDB.4.0';
connAdo.LoginPrompt:=False;
connAdo.Connected:=True;
except
end;
with connQuery do
begin
close;
sql.Clear;
sql.Add('select * from 作品表 where ID = '+ID);
open;
first;
TBlobField(FieldByName('Image')).SaveToFile(sFilePath+'tmp.jpg');
Image1.Picture.LoadFromFile(sFilePath+'tmp.jpg');
close;
end
end;
function TfmProductionMgr.CreateSqlStr: string;
begin
if RadioButton1.Checked then
result := 'select * from 作品表 where Name like '+'"%'+Edt_ProQry.Text+'%"'
else
if RadioButton2.Checked then
begin
if Combobox2.ItemIndex = -1 then
result := 'select * from 作品表'
else
result := 'select * from 作品表 where AuthorID = '+Combobox2.Text;
end
else
if RadioButton3.Checked then
begin
if RadioGroup1.ItemIndex = 0 then
result := 'select * from 作品表 where Price >= '+SpinEdit1.Text
else
result := 'select * from 作品表 where Price <= '+SpinEdit1.Text;
end;
end;
function TfmProductionMgr.FindAuthorIndex(AuthorID: string): integer;
var
i: integer;
begin
Result := Combobox2.Items.IndexOf(AuthorID);
end;
procedure TfmProductionMgr.FormCreate(Sender: TObject);
begin
IniStringGrid;
IniAuthor;
end;
procedure TfmProductionMgr.BitBtn4Click(Sender: TObject);
var
connQuery: TADOQuery;
connAdo: TADOConnection;
connString: string;
sFilePath: string;
i: integer;
begin
sFilePath := ExtractFilePath(Application.ExeName);
connAdo := TADOConnection.Create(nil);
connQuery := TADOQuery.Create(nil);
connQuery.CommandTimeout := 60;
connQuery.Connection := connAdo;
connString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+sFilePath+'database.mdb';
try
connAdo.ConnectionString:=connString;
connAdo.Provider := 'Microsoft.Jet.OLEDB.4.0';
connAdo.LoginPrompt:=False;
connAdo.Connected:=True;
except
end;
IniStringGrid;
// showmessage(CreateSqlStr);
with connQuery do
begin
close;
sql.Clear;
sql.Add(CreateSqlStr);
open;
if recordcount = 0 then
begin
showmessage('没有记录');
exit;
end;
first;
i := 1;
while not eof do
begin
StringGrid1.RowCount := StringGrid1.RowCount + 1;
StringGrid1.Cells[0,i] := Fields[1].AsString;
StringGrid1.Cells[1,i] := Combobox1.Items.Strings[FindAuthorIndex(Fields[2].AsString)];
StringGrid1.Cells[2,i] := Fields[3].AsString;
StringGrid1.Cells[3,i] := Fields[4].AsString;
StringGrid1.Cells[4,i] := Fields[0].AsString;
StringGrid1.Cells[5,i] := Fields[2].AsString;
Inc(i);
next;
end;
StringGrid1.RowCount := StringGrid1.RowCount - 1;
close;
end;
StringGrid1.Row := 1;
StringGrid1.OnClick(StringGrid1);
ShowImageFromDB(StringGrid1.Cells[5,StringGrid1.Row])
end;
procedure TfmProductionMgr.RadioButton1Click(Sender: TObject);
begin
Notebook1.PageIndex := 0;
end;
procedure TfmProductionMgr.RadioButton2Click(Sender: TObject);
begin
Notebook1.PageIndex := 1;
ComboBox1.ItemIndex := -1;
ComboBox2.ItemIndex := -1;
end;
procedure TfmProductionMgr.RadioButton3Click(Sender: TObject);
begin
Notebook1.PageIndex := 2;
end;
procedure TfmProductionMgr.ComboBox1Change(Sender: TObject);
begin
ComboBox2.ItemIndex := ComboBox1.ItemIndex;
end;
procedure TfmProductionMgr.StringGrid1Click(Sender: TObject);
var
RowIndex: integer;
begin
RowIndex := StringGrid1.Row;
if StringGrid1.Cells[4,RowIndex] = '' then Exit;
Edt_Name.Text := StringGrid1.Cells[0,RowIndex];
CB_AuthorCode.ItemIndex := CB_AuthorCode.Items.IndexOf(StringGrid1.Cells[5,RowIndex]);
CB_AuthorName.ItemIndex := CB_AuthorCode.ItemIndex;
// Edt_Author.Text := StringGrid1.Cells[1,RowIndex];
Edt_Price.Text := StringGrid1.Cells[2,RowIndex];
Mmo_Des.Text := StringGrid1.Cells[3,RowIndex];
ShowImageFromDB(StringGrid1.Cells[5,StringGrid1.Row])
end;
procedure TfmProductionMgr.Button1Click(Sender: TObject);
begin
Image1.Picture.LoadFromFile('c:\1.jpg');
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -