匪
匪匪
Unregistered / Unconfirmed
GUEST, unregistred user!
我现在正在做一个项目,中间层用COM+实现, 在com+中定义了add,edit,delete几个方法, 代码如下:
function TWS_yonghu.Add(const BianHao, Name, Address, Password, QuanXian,
Phone, Email: WideString): OleVariant;
begin
//检查维一性
if WeiYi(BianHao) then
begin
Query1.Active:=false;
Query1.SQL.Clear;
Query1.SQL.Add('select * from yonghu');
Query1.Open;
Query1.Append;
Query1.FieldByName('编号').AsString:=BianHao;
Query1.FieldByName('姓名').AsString:=Name;
Query1.FieldByName('地址').AsString:=Address;
Query1.FieldByName('密码').AsString:=Password;
Query1.FieldByName('权限').AsString:=QuanXian;
Query1.FieldByName('电话').AsString:=Phone;
Query1.FieldByName('Email').AsString:=Email;
Query1.Post;
result:=true;
end
else
begin
result:=false;
end;
end;
function TWS_yonghu.Edit(const BianHao, Name, Address, Password, QuanXian,
Phone, Email: WideString): OleVariant;
var
Q_temp:TQuery;
begin
//Query1.Active:=false;
//Query1.CommandText:='select * from yonghu';
//Query1.Open;
//Query1.Locate('编号',BianHao,[]);
Q_temp:=TQuery.Create(self);
Q_temp.DatabaseName:='WS_yonghu';
Q_temp.RequestLive:=true;
Q_temp.Close;
Q_temp.SQL.Clear;
Q_temp.SQL.Add('select * from yonghu where 编号=:bh');
Q_temp.ParamByName('bh').Value:=BianHao;
Q_temp.Open;
Q_temp.Edit;
Q_temp.FieldByName('编号').AsString:=BianHao;
Q_temp.FieldByName('姓名').AsString:=Name;
Q_temp.FieldByName('地址').AsString:=Address;
Q_temp.FieldByName('密码').AsString:=Password;
Q_temp.FieldByName('权限').AsString:=QuanXian;
Q_temp.FieldByName('电话').AsString:=Phone;
Q_temp.FieldByName('Email').AsString:=Email;
Q_temp.Post;
end;
function TWS_yonghu.Delete(const BianHao: WideString): OleVariant;
var
CDS_temp:TClientDataset;
begin
CDS_temp:=TClientDataset.Create(self);
CDS_temp.ProviderName:='DataSetProvider1';
CDS_temp.Active:=false;
CDS_temp.CommandText:='select 编号 from yonghu where 编号=:bh';
CDS_temp.Params.ParamByName('bh').Value:=BianHao;
CDS_temp.open;
if CDS_temp.RecordCount=0 then
begin
result:=false;//记录已不存在
end
else
begin
Query1.Active:=false;
Query1.SQL.Clear;
Query1.SQL.Add('Delete from yonghu where 编号=:bh');
Query1.Params.ParamByName('bh').Value:=BianHao;
Query1.ExecSQL;
end;
end;
function TWS_yonghu.WeiYi(const BianHao: WideString): OleVariant;
var
CDS_Temp:TClientDataset;
begin
CDS_Temp:=TClientDataset.Create(self);
CDS_Temp.ProviderName:='DataSetProvider1';
CDS_temp.Active:=false;
CDS_temp.CommandText:='select * from yonghu where 编号=:bh';
CDS_Temp.Params.ParamByName('bh').Value:=BianHao;
CDS_temp.Open;
if CDS_temp.RecordCount=0 then
result:=true //唯一
else
result:=false;//不唯一
CDS_temp.Free;
end;
我想知道:
1:在Add方法中被增加的记录有什么好的方法在客户端中更新显示,是用clientdata.refresh,还是把sql语句改为
select * from table这种,还有别的什么好方法吗?
2:在Edit方法中由于我更新记录时,如果我没有提前指定要修改的记录,那就不能完成该工作,
有没有其它好的方法在修改前定位到要修改的记录.
3:修改,删除数据后,更新回客户端时用哪种方法,refresh效率高吗?
4:无状态方法如何在以上三种操作中实现?[!][!]
function TWS_yonghu.Add(const BianHao, Name, Address, Password, QuanXian,
Phone, Email: WideString): OleVariant;
begin
//检查维一性
if WeiYi(BianHao) then
begin
Query1.Active:=false;
Query1.SQL.Clear;
Query1.SQL.Add('select * from yonghu');
Query1.Open;
Query1.Append;
Query1.FieldByName('编号').AsString:=BianHao;
Query1.FieldByName('姓名').AsString:=Name;
Query1.FieldByName('地址').AsString:=Address;
Query1.FieldByName('密码').AsString:=Password;
Query1.FieldByName('权限').AsString:=QuanXian;
Query1.FieldByName('电话').AsString:=Phone;
Query1.FieldByName('Email').AsString:=Email;
Query1.Post;
result:=true;
end
else
begin
result:=false;
end;
end;
function TWS_yonghu.Edit(const BianHao, Name, Address, Password, QuanXian,
Phone, Email: WideString): OleVariant;
var
Q_temp:TQuery;
begin
//Query1.Active:=false;
//Query1.CommandText:='select * from yonghu';
//Query1.Open;
//Query1.Locate('编号',BianHao,[]);
Q_temp:=TQuery.Create(self);
Q_temp.DatabaseName:='WS_yonghu';
Q_temp.RequestLive:=true;
Q_temp.Close;
Q_temp.SQL.Clear;
Q_temp.SQL.Add('select * from yonghu where 编号=:bh');
Q_temp.ParamByName('bh').Value:=BianHao;
Q_temp.Open;
Q_temp.Edit;
Q_temp.FieldByName('编号').AsString:=BianHao;
Q_temp.FieldByName('姓名').AsString:=Name;
Q_temp.FieldByName('地址').AsString:=Address;
Q_temp.FieldByName('密码').AsString:=Password;
Q_temp.FieldByName('权限').AsString:=QuanXian;
Q_temp.FieldByName('电话').AsString:=Phone;
Q_temp.FieldByName('Email').AsString:=Email;
Q_temp.Post;
end;
function TWS_yonghu.Delete(const BianHao: WideString): OleVariant;
var
CDS_temp:TClientDataset;
begin
CDS_temp:=TClientDataset.Create(self);
CDS_temp.ProviderName:='DataSetProvider1';
CDS_temp.Active:=false;
CDS_temp.CommandText:='select 编号 from yonghu where 编号=:bh';
CDS_temp.Params.ParamByName('bh').Value:=BianHao;
CDS_temp.open;
if CDS_temp.RecordCount=0 then
begin
result:=false;//记录已不存在
end
else
begin
Query1.Active:=false;
Query1.SQL.Clear;
Query1.SQL.Add('Delete from yonghu where 编号=:bh');
Query1.Params.ParamByName('bh').Value:=BianHao;
Query1.ExecSQL;
end;
end;
function TWS_yonghu.WeiYi(const BianHao: WideString): OleVariant;
var
CDS_Temp:TClientDataset;
begin
CDS_Temp:=TClientDataset.Create(self);
CDS_Temp.ProviderName:='DataSetProvider1';
CDS_temp.Active:=false;
CDS_temp.CommandText:='select * from yonghu where 编号=:bh';
CDS_Temp.Params.ParamByName('bh').Value:=BianHao;
CDS_temp.Open;
if CDS_temp.RecordCount=0 then
result:=true //唯一
else
result:=false;//不唯一
CDS_temp.Free;
end;
我想知道:
1:在Add方法中被增加的记录有什么好的方法在客户端中更新显示,是用clientdata.refresh,还是把sql语句改为
select * from table这种,还有别的什么好方法吗?
2:在Edit方法中由于我更新记录时,如果我没有提前指定要修改的记录,那就不能完成该工作,
有没有其它好的方法在修改前定位到要修改的记录.
3:修改,删除数据后,更新回客户端时用哪种方法,refresh效率高吗?
4:无状态方法如何在以上三种操作中实现?[!][!]