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

📄 unit_production.~pas

📁 it is art gallery manage system:include of author manage system、production manage system and produc
💻 ~PAS
📖 第 1 页 / 共 2 页
字号:
  finally
    MyJPEG.Free;
    MS.Free;
  end;
end;

procedure TfmProductionMgr.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[4,StringGrid1.row];
  connQuery.SQL.Clear;
  connQuery.SQL.Add(ssql);
  connQuery.ExecSQL;
end;

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

function TfmProductionMgr.CreateSqlStr: string;
begin
//   result := 'select * from 作品表 where ID=13';EXIT;
  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;
  EditZT := 0;  //初始状态为查询
  SetEnable(EditZT);
end;

procedure TfmProductionMgr.BitBtn_qryClick(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[4,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
  if EditZT <> 0 then exit;  //如果当前状态不是查询
  RowIndex := StringGrid1.Row;
  if StringGrid1.Cells[4,RowIndex] = '' then
  begin
    Edt_Name.Text := '';
    CB_AuthorCode.ItemIndex := -1;
    CB_AuthorName.ItemIndex := -1;
    Image1.Picture := nil;
    Edt_Price.Text := '0';
    Mmo_Des.Text := '';
    Exit;
  end;
  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[4,StringGrid1.Row])
end;

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

procedure TfmProductionMgr.BitBtn_okClick(Sender: TObject);
begin
    if (Trim(Edt_Name.Text)='') then
    begin
      Application.MessageBox('作品名称不能为空!','提示',MB_OK+MB_IconInformation);
      Exit;
    end;
    if Image1.Picture = nil then
    begin
      Application.MessageBox('作品显示不能为空!','提示',MB_OK+MB_IconInformation);
      Exit;
    end;
  if EditZT = 1 then
  begin
    SaveRecord;
  end
  else
  if EditZT = 2 then
  begin
    DeleteRecordFromDB(ModifyRow);
    SaveRecord;
    StringGrid1.Cells[0,ModifyRow] := Edt_Name.Text;
    StringGrid1.Cells[1,ModifyRow] := CB_AuthorName.Text;
    StringGrid1.Cells[2,ModifyRow] := Edt_Price.Text;
    StringGrid1.Cells[3,ModifyRow] := Mmo_Des.Text;
    StringGrid1.Cells[4,ModifyRow] := Inttostr(modifyID);
    StringGrid1.Cells[5,ModifyRow] := CB_AuthorCode.Text;
  end;
  EditZT := 0;  //代表查询
  SetEnable(EditZT);
end;

procedure TfmProductionMgr.BitBtn_cancelClick(Sender: TObject);
begin
  EditZT := 0;  //代表查询
  SetEnable(EditZT);
end;

procedure TfmProductionMgr.BitBtn_selClick(Sender: TObject);
begin
 if OpenPictureDialog1.Execute then  //showmessage(OpenPictureDialog1.FileName);
    Image1.Picture.LoadFromFile(OpenPictureDialog1.FileName);
end;

procedure TfmProductionMgr.CB_AuthorNameChange(Sender: TObject);
begin
  CB_AuthorCode.ItemIndex := CB_AuthorName.ItemIndex;
end;

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

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

end.

⌨️ 快捷键说明

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