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

📄 unit_fsell.~pas

📁 it is art gallery manage system:include of author manage system、production manage system and produc
💻 ~PAS
字号:
unit Unit_FSell;

interface

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

type
  TForm_Sell = class(TForm)
    Panel5: TPanel;
    GroupBox1: TGroupBox;
    RadioButton1: TRadioButton;
    RadioButton2: TRadioButton;
    RadioButton3: TRadioButton;
    Notebook1: TNotebook;
    Edt_ProQry: TEdit;
    ComboBox2: TComboBox;
    ComboBox1: TComboBox;
    RadioGroup1: TRadioGroup;
    SpinEdit1: TSpinEdit;
    BitBtn_qry: TBitBtn;
    Panel2: TPanel;
    BitBtn_new: TBitBtn;
    BitBtn_edit: TBitBtn;
    BitBtn_del: TBitBtn;
    BitBtn_ok: TBitBtn;
    BitBtn_cancel: TBitBtn;
    Panel1: TPanel;
    Panel3: TPanel;
    StringGrid1: TStringGrid;
    Panel4: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Image1: TImage;
    Label5: TLabel;
    Label6: TLabel;
    Mmo_Des: TMemo;
    Edt_Price: TSpinEdit;
    Com_PName: TComboBox;
    Com_PID: TComboBox;
    CB_AuthorName: TComboBox;
    CB_AuthorCode: TComboBox;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    procedure RadioButton1Click(Sender: TObject);
    procedure RadioButton2Click(Sender: TObject);
    procedure RadioButton3Click(Sender: TObject);
    procedure BitBtn_qryClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure StringGrid1Click(Sender: TObject);
    procedure BitBtn_newClick(Sender: TObject);
    procedure BitBtn_editClick(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn_delClick(Sender: TObject);


  private
    { Private declarations }
    procedure IniStringGrid;
    procedure ShowImageFromDB(ID: string);
    procedure IniProcedure;
    function FindAuthorIndex(AuthorID: string): integer;
    function FindProceIndex(PorceID: string): integer;
    procedure ModifyRecord;
    procedure NewRecord;
    procedure DeleteRecordFromDB(row: integer);
    procedure SetEnable(zt: integer);
    procedure DeleteRecordFromSG(row: integer);
  public
    { Public declarations }
  end;

var
  Form_Sell: TForm_Sell;
  EditZT: integer;
  ModifyRow,modifyID: integer;

implementation

{$R *.dfm}

procedure TForm_Sell.IniStringGrid;
var
  i: integer;
begin
  //StringGrid1.ColWidths[5] := 0;
  //StringGrid1.ColWidths[6] := 0;
  StringGrid1.Cells[0,0] := '作品名称';
  StringGrid1.Cells[1,0] := '作品编号';
  StringGrid1.Cells[2,0] := '作者';
  StringGrid1.Cells[3,0] := '作者编号';
  StringGrid1.Cells[4,0] := '出售价格';
  //StringGrid1.Cells[5,0] := '作品描述';
  StringGrid1.Cells[5,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] := '';
  //StringGrid1.Cells[6,i] := '';
  end;
  StringGrid1.RowCount := 2;

end;

procedure TForm_Sell.RadioButton1Click(Sender: TObject);
begin
  Notebook1.PageIndex := 0;
end;

procedure TForm_Sell.RadioButton2Click(Sender: TObject);
begin
  Notebook1.PageIndex := 1;
  ComboBox1.ItemIndex := -1;
  ComboBox2.ItemIndex := -1;
end;

procedure TForm_Sell.RadioButton3Click(Sender: TObject);
begin
  Notebook1.PageIndex := 2;
end;


function TForm_Sell.FindAuthorIndex(AuthorID: string): integer;
var
  i: integer;
begin
  Result := Combobox2.Items.IndexOf(AuthorID);
end;

function TForm_Sell.FindProceIndex(PorceID: string): integer;
var
  i: integer;
begin
  Result := Com_PID.Items.IndexOf(PorceID);
end;

procedure TForm_Sell.BitBtn_qryClick(Sender: TObject);
var
  connQuery: TADOQuery;
  connAdo: TADOConnection;
  connString: string;
  sFilePath,CreateSqlStr: 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);
CreateSqlStr:='select ProcedureID,AuthorID,SellNum,sellID from sellview';
  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] := Com_PName.Items.Strings[FindProceIndex(Fields[0].AsString)] ;
       StringGrid1.Cells[1,i] := Fields[0].AsString;
       StringGrid1.Cells[2,i] := Combobox1.Items.Strings[FindAuthorIndex(Fields[1].AsString)];
       StringGrid1.Cells[3,i] := Fields[1].AsString;
       StringGrid1.Cells[4,i] := Fields[2].AsString;
       StringGrid1.Cells[5,i] := Fields[3].AsString;
       //StringGrid1.Cells[6,i] := Fields[6].AsString;
       Inc(i);
       next;
     end;
     StringGrid1.RowCount := StringGrid1.RowCount - 1;
     close;
  end;

  StringGrid1.Row := 1;
  StringGrid1.OnClick(StringGrid1);
  ShowImageFromDB(StringGrid1.Cells[1,StringGrid1.Row]);

end;

procedure TForm_Sell.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 TForm_Sell.FormCreate(Sender: TObject);
begin
  IniStringGrid;
  IniProcedure;
  EditZT := 0;  //初始状态为查询  
end;

procedure TForm_Sell.IniProcedure;
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 Name,ID from 作品表');
     open;
     first;
     i := 1;
     while not eof do
     begin
       Com_PName.Items.Add(Fields[0].AsString);
       Com_PID.Items.Add(Fields[1].AsString);
       Inc(i);
       next;
     end;
     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 TForm_Sell.StringGrid1Click(Sender: TObject);
var
  RowIndex: integer;
begin
  if EditZT <> 0 then exit;  //如果当前状态不是查询
  RowIndex := StringGrid1.Row;
  if StringGrid1.Cells[1,RowIndex] = '' then
  begin
    Com_PName.ItemIndex:=-1;
    Com_PID.ItemIndex:=-1;
    Com_PName.ItemIndex:=-1;
    Com_PID.ItemIndex:=-1;
    CB_AuthorCode.ItemIndex := -1;
    CB_AuthorName.ItemIndex := -1;
    Image1.Picture := nil;
    Edt_Price.Text := '0';
    Mmo_Des.Text := '';
    Exit;
  end;

  Com_PID.ItemIndex:= Com_PName.Items.IndexOf(StringGrid1.Cells[1,RowIndex]);
  CB_AuthorCode.ItemIndex := CB_AuthorCode.Items.IndexOf(StringGrid1.Cells[3,RowIndex]);
  CB_AuthorName.ItemIndex := CB_AuthorCode.ItemIndex;
//  Edt_Author.Text := StringGrid1.Cells[1,RowIndex];
  Edt_Price.Text := StringGrid1.Cells[4,RowIndex];
  //Mmo_Des.Text := StringGrid1.Cells[3,RowIndex];
  ShowImageFromDB(StringGrid1.Cells[1,StringGrid1.Row])
end;

procedure TForm_Sell.BitBtn_newClick(Sender: TObject);
begin
  EditZT := 1;  //代表新增
  SetEnable(EditZT);
  CB_AuthorName.Enabled := true;
  CB_AuthorName.ItemIndex := -1;
  CB_AuthorCode.ItemIndex := -1;
  Edt_Price.Value := 0;
  Image1.Picture := nil;
  Mmo_Des.lines.Clear;
  Com_PName.SetFocus;
end;

procedure TForm_Sell.BitBtn_editClick(Sender: TObject);
begin
  EditZT := 2;  //代表修改
  SetEnable(EditZT);
  ModifyRow := StringGrid1.Row;
  CB_AuthorName.Enabled := true;
  Com_PName.SetFocus;
end;

procedure TForm_Sell.BitBtn1Click(Sender: TObject);
begin
  if EditZT = 1 then
  begin
    ModifyRecord;
  end
  else
  if EditZT = 2 then
  begin
    NewRecord;
    StringGrid1.Cells[0,ModifyRow] := Com_PName.Text;
    StringGrid1.Cells[1,ModifyRow] := Com_PID.Text;
    StringGrid1.Cells[2,ModifyRow] := CB_AuthorName.Text;
    StringGrid1.Cells[3,ModifyRow] := CB_AuthorCode.Text;
    StringGrid1.Cells[4,ModifyRow] := Inttostr(Edt_Price.Value);
   // StringGrid1.Cells[5,ModifyRow] := CB_AuthorCode.Text;
  end;
  EditZT := 0;  //代表查询
  SetEnable(EditZT);
end;

procedure TForm_Sell.ModifyRecord;
var
  connQuery,connQuery1: TADOQuery;
  connAdo: TADOConnection;
  connString: string;
  sFilePath: string;
  i: integer;

  ssql,ID: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;
   ID:=StringGrid1.Cells[5,StringGrid1.Row];

      ssql:='update 销售产品清单 set ProcedureID='''+Com_PID.Text+''',AuthorID='''+CB_AuthorCode.Text+
            ''' where sellID='+ID;
      connQuery.SQL.Clear;
      connQuery.SQL.Add(ssql);
      connQuery.ExecSQL;
end;

procedure TForm_Sell.NewRecord;
var
  connQuery,connQuery1: TADOQuery;
  connAdo: TADOConnection;
  connString: string;
  sFilePath: string;
  i,maxrecord: integer;
  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;

      ssql:='insert into 销售产品清单 (ProcedureID,AuthorID)values('''+Com_PID.Text+
      ''','''+CB_AuthorCode.Text+''')';

      connQuery.SQL.Clear;
      connQuery.SQL.Add(ssql);
      connQuery.ExecSQL;
end;

procedure TForm_Sell.BitBtn_delClick(Sender: TObject);
begin
  if Application.MessageBox('是否确定删除此记录?','提示',MB_OKCANCEL+MB_IconQuestion)= ID_OK then
  begin
    DeleteRecordFromDB(ModifyRow);
    DeleteRecordFromSG(StringGrid1.Row);
    StringGrid1.OnClick(StringGrid1);
  end;
end;


procedure TForm_Sell.DeleteRecordFromDB(row: integer);
var
  connQuery: TADOQuery;
  connAdo: TADOConnection;
  connString: string;
  sFilePath: string;
  ssql: 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;
  ssql:='delete * from 销售产品清单 where ID='+StringGrid1.Cells[5,StringGrid1.row];
  connQuery.SQL.Clear;
  connQuery.SQL.Add(ssql);
  connQuery.ExecSQL;
end;

procedure TForm_Sell.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;

  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;
    
  end;
end;

procedure TForm_Sell.DeleteRecordFromSG(row: integer);
var
  i, j: integer;
begin
  for i := row to StringGrid1.RowCount - 2 do
  begin
     for j := 0 to StringGrid1.ColCount - 1 do
     begin
        StringGrid1.Cells[j, i] := StringGrid1.Cells[j, i+1];
     end;
  end;
  for j := 0 to StringGrid1.ColCount - 1 do
     StringGrid1.Cells[j, StringGrid1.RowCount - 1]:='';
  if StringGrid1.RowCount > 2 then 
  StringGrid1.RowCount := StringGrid1.RowCount - 1;
end;
end.

⌨️ 快捷键说明

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