unit uCDb;
interface
uses
System.Collections,
System.Data,
System.Data.OleDB,
System.Web.Mail,
System.IO;
type
CDb =
class
private
conn :OleDBConnection;
connstr:
String;
public
function Datenabfrage(abfrage:
string;Tabelle:
string):DataSet;
function Wertrueckgabe(ds:DataSet;Tabelle:
string;Spalte:
string;i:integer):
string;
function UpdateDelete(Anfrage:
String):
string;
function GetConnStr():
string;
procedure SetConnStr(conn:
String);
function Einzelwertrueckgabe(Anfrage,Tabelle,Spalte:
String;i:integer):
string;
function Login(login,passwd,Tabelle,Spalte:
string;ds:DataSet;Nr:integer):
string;
procedure EMAIL(From,Zu,Subject,Nachricht:
String);
overload;
procedure EMAIL(From,Zu,Subject,Nachricht,Anhang:
String);
overload;
procedure EMAIL(From,Zu,bcc,Subject,Nachricht,Anhang:
String);
overload;
constructor Create();
overload;
constructor Create(Conn:
String);
overload;
end;
implementation
constructor CDb.Create;
begin
inherited Create;
connstr:='
Provider=Microsoft.Jet.OLEDB.4.0;'+
'
Data Source= db\db1.mdb'
end;
constructor CDb.Create(Conn:
String);
begin
Self.Create;
connstr:=conn;
end;
procedure CDB.SetConnStr(conn:
String);
begin
connstr:=conn;
end;
function CDb.GetConnStr():
String;
begin
result:=connstr;
end;
function CDb.Wertrueckgabe(ds:DataSet;Tabelle:
string;Spalte:
string;i:integer):
string;
var dt:DataTable;
en:IEnumerator;
rw:DataRow;
begin
dt:=ds.Tables[Tabelle];
en:=dt.Rows.GetEnumerator;
rw:=dt.Rows[i];
result:=rw[Spalte].ToString;
end;
function CDb.UpdateDelete(Anfrage:
String):
string;
var cmd:OleDBCommand;
rueckgabe:
string;
begin
conn :=OleDBConnection.Create(connstr);
cmd:=OleDBCommand.Create();
cmd.Connection:=conn;
cmd.CommandText:=anfrage;
try
conn.Open;
rueckgabe:=cmd.ExecuteNonQuery.ToString;
except on ex:
Exception do
begin
rueckgabe:=ex.
Message+'
'+Anfrage;
end;
end;
conn.Close;
result:=rueckgabe;
end;
function CDb.Datenabfrage(abfrage:
string;Tabelle:
string):DataSet;
var cmdSel:OleDbCommand;
da:OleDBDataAdapter;
ds:DataSet;
begin
conn :=OleDBConnection.Create(connstr);
cmdSel:=OleDbCommand.Create(abfrage,conn);
da :=OleDbDataAdapter.Create(cmdSel);
ds :=DataSet.Create();
try
conn.Open;
da.Fill(ds,Tabelle);
conn.Close;
except
on ex:
Exception do
end;
result:=ds;
end;
procedure CDB.EMAIL(From,Zu,Subject,Nachricht:
String);
var m:mailmessage;
begin
m:=MailMessage.Create;
m.From:=From;
m.&
To:=Zu;
m.Subject:=Subject;
m.Body:=Nachricht;
SmtpMail.Send(m);
end;
procedure CDB.EMAIL(From,Zu,Subject,Nachricht,Anhang:
String);
var m:mailmessage;
begin
m:=MailMessage.Create;
m.From:=From;
m.&
To:=Zu;
m.Subject:=Subject;
m.Body:=Nachricht;
m.Attachments.Add(MailAttachment.Create(Anhang));
SmtpMail.Send(m);
end;
procedure CDB.EMAIL(From,Zu,bcc,Subject,Nachricht,Anhang:
String);
var m:mailmessage;
begin
m:=MailMessage.Create;
m.From:=From;
m.&
To:=Zu;
m.&Bcc:=bcc;
m.Subject:=Subject;
m.Body:=Nachricht;
m.Attachments.Add(MailAttachment.Create(Anhang));
SmtpMail.Send(m);
end;
function CDB.Einzelwertrueckgabe(Anfrage,Tabelle,Spalte:
String;i:integer):
string;
var ds:DataSet;
begin
ds:=Datenabfrage(Anfrage,Tabelle);
result:=Wertrueckgabe(ds,Tabelle,Spalte,i);
end;
function CDB.Login(login,passwd,Tabelle,Spalte:
string;ds:DataSet;Nr:integer):
string;
begin
if (login<>'
')
and (passwd<>'
')
then
begin
try
if (passwd=Wertrueckgabe(ds,Tabelle,Spalte,Nr))
then
begin
result:='
True';
end
except on ex:
Exception do
begin
result:=ex.ToString;
end;
end;
end;
end;
end.