⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit_production.~pas

📁 it is art gallery manage system:include of author manage system、production manage system and produc
💻 ~PAS
📖 第 1 页 / 共 2 页
字号:
unit Unit_Production;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, Grids, StdCtrls, Buttons, DB, ADODB, DBGrids, DBTables,
  Spin, jpeg, ExtDlgs;

type
  TfmProductionMgr = class(TForm)
    Panel1: TPanel;
    Panel2: TPanel;
    Panel3: TPanel;
    Panel4: TPanel;
    BitBtn_new: TBitBtn;
    BitBtn_edit: TBitBtn;
    BitBtn_del: TBitBtn;
    Panel5: TPanel;
    GroupBox1: TGroupBox;
    BitBtn_qry: TBitBtn;
    Label1: TLabel;
    Edt_Name: TEdit;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Mmo_Des: TMemo;
    RadioButton1: TRadioButton;
    RadioButton2: TRadioButton;
    RadioButton3: TRadioButton;
    BitBtn_ok: TBitBtn;
    BitBtn_cancel: 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;
    Edt_Price: TSpinEdit;
    OpenPictureDialog1: TOpenPictureDialog;
    BitBtn_sel: TBitBtn;
    procedure FormCreate(Sender: TObject);
    procedure BitBtn_qryClick(Sender: TObject);
    procedure RadioButton1Click(Sender: TObject);
    procedure RadioButton2Click(Sender: TObject);
    procedure RadioButton3Click(Sender: TObject);
    procedure ComboBox1Change(Sender: TObject);
    procedure StringGrid1Click(Sender: TObject);
    procedure BitBtn_newClick(Sender: TObject);
    procedure BitBtn_okClick(Sender: TObject);
    procedure BitBtn_cancelClick(Sender: TObject);
    procedure BitBtn_selClick(Sender: TObject);
    procedure CB_AuthorNameChange(Sender: TObject);
    procedure BitBtn_editClick(Sender: TObject);
    procedure BitBtn_delClick(Sender: TObject);
  private
    procedure IniStringGrid;
    procedure IniAuthor;
    procedure ShowImageFromDB(ID: string);
    procedure SetEnable(zt: integer);  //根据状态来设置各控件的状态
    procedure SaveRecord;               //保存记录
    procedure DeleteRecordFromDB(row: integer);             //从数据库中删除记录
    procedure DeleteRecordFromSG(row: integer);             //从SG中删除记录
    function CreateSqlStr: string;
    function FindAuthorIndex(AuthorID: string): integer;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fmProductionMgr: TfmProductionMgr;
  EditZT: integer;
  ModifyRow,modifyID: integer;

implementation

{$R *.dfm}

procedure TfmProductionMgr.IniStringGrid;
var
  i: integer;
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] := '作品描述';
  for i := 1 to StringGrid1.RowCount -1 do
  begin
  StringGrid1.Cells[0,i] := '';
  StringGrid1.Cells[1,i] := '';
  StringGrid1.Cells[2,i] := '';
  StringGrid1.Cells[3,i] := '';
  StringGrid1.Cells[4,i] := '';
  StringGrid1.Cells[5,i] := '';
  end;
  StringGrid1.RowCount := 2;

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;
  tempstream: TStringStream;
  tempjpeg: TJpegImage;
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;
  tempstream:=TStringStream.Create(' ');
  TBlobField(FieldByName('Image')).SaveToStream(tempstream);
  tempstream.Position:=0;
  tempjpeg:=TJPEGImage.Create;
  tempjpeg.LoadFromStream(tempstream);
  Image1.Picture.Bitmap.Assign(tempjpeg);
  tempstream.Free;
  tempjpeg.Free;

  end
end;

procedure TfmProductionMgr.SetEnable(zt: integer);
begin
  if zt = 0 then //查询状态
  begin
     Panel5.Enabled := true;
     BitBtn_new.Enabled := true;
     BitBtn_edit.Enabled := true;
     BitBtn_del.Enabled := true;
     BitBtn_ok.Enabled := false;
     BitBtn_cancel.Enabled := false;
     BitBtn_sel.Enabled := false;
  end
  else
  if (zt = 1) or (zt = 2) then
  begin
     Panel5.Enabled := false;
     BitBtn_new.Enabled := false;
     BitBtn_edit.Enabled := false;
     BitBtn_del.Enabled := false;
     BitBtn_ok.Enabled := true;
     BitBtn_cancel.Enabled := true;
     BitBtn_sel.Enabled := true;
  end;
end;

procedure TfmProductionMgr.SaveRecord;
var
  connQuery,connQuery1: TADOQuery;
  connAdo: TADOConnection;
  connString: string;
  sFilePath: string;
  i,maxrecord: integer;
  MyJPEG:TJPEGImage;
  MS:TMemoryStream;
  ssql:string;
begin
  sFilePath := ExtractFilePath(Application.ExeName);
  connAdo := TADOConnection.Create(nil);
  connQuery := TADOQuery.Create(nil);
  connQuery.CommandTimeout := 60;
  connQuery.Connection := connAdo;
  connQuery1 := TADOQuery.Create(nil);
  connQuery1.CommandTimeout := 60;
  connQuery1.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;

  MyJPEG := TJPEGImage.Create;
  try
    with MyJPEG do
    begin
      Assign(Image1.Picture.Graphic);
      MS:=TMemoryStream.create;
      SaveToStream(MS);      
      MS.Position:=0;      
      ssql:='select image from 作品表 where ID=1';
      connQuery.Close;      
      connQuery.SQL.Clear;
      connQuery.SQL.Add(ssql);
      connQuery.Open;
      connQuery.Edit;
      connQuery.Append;
      TBlobField(connQuery.FieldByName('Image')).LoadFromStream(MS);
      connQuery.post;
      connQuery.Close;
      ssql:='select Max(ID) from 作品表';
      connQuery.SQL.Clear;
      connQuery.SQL.Add(ssql);
      connQuery.Open;
      if connQuery.Fields[0].AsString = '' then
         maxrecord := 1
      else
         maxrecord := connQuery.Fields[0].AsInteger;
      modifyID := maxrecord;
      ssql:='update 作品表 set Name='''+Edt_Name.Text+''',AuthorID='''+CB_AuthorCode.Text+
            ''',Price='+Edt_Price.Text+',Des='''+Mmo_Des.Text+''' where ID='+inttostr(maxrecord);
      connQuery.SQL.Clear;
      connQuery.SQL.Add(ssql);
      connQuery.ExecSQL;
//      showmessage(ssql);
    end;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -