把数据库的连接写到接口的函数里面
在客户端调用此函数向服务器传送连接参数
function Trpserver.connectbase(const copy_id: WideString;
const copy_year: WideString;const month:widestring;
const copy_day:widestring;const copy_month:widestring;
const unitname:widestring;const creator:widestring;
const step:widestring;stepnum:double): OleVariant;
begin
result:='error';
//若任一参数为空则断开连接
if (copy_id='') or (copy_year='') or (month='') or
(copy_day='') or (copy_month='') or (unitname='')
or (creator='') or (step='') or (stepnum=0) then
begin
if not isconnected then
exit;
default_query.Close;
default_connection.Close;
copyinfo.Free;
copyinfo:=nil;
m_copy_id:='';
m_copy_year:='';
m_copy_month:='';
m_month:='';
m_day:='';
m_step:='';
m_unitname:='';
m_creator:='';
m_currency:='';
m_stepnum:=1;
isconnected:=FALSE;
result:=0;
exit;
end;
if isconnected then
exit;
//参数字符串长度不符
if (length(copy_month)<>2) or (length(copy_day)<>2) or (length(month)<>2) then
exit;
//月份错误
if (strtoint(copy_month)<1) or (strtoint(copy_month)>12)
or (strtoint(month)<1) or (strtoint(month)>12) then
exit;
//日期错误
if (strtoint(copy_day)<1) or (strtoint(copy_day)>31) then
exit;
//取注册表信息
if initialreg()=-1 then
exit;
//取帐套信息
default_query.Close;
default_query.ConnectionString:=createiniconnect();
default_query.SQL.Clear;
default_query.SQL.Add('select copy_year,copy_id from copyinfo');
try
default_query.open;
except on E:exceptiondo
begin
default_query.Close;
exit;
end;
end;
//产生帐套信息列表
copyinfo:=tstringlist.Create;
if copyinfo=nil then
exit;
try
with default_querydo
begin
First;
while not Eof do
begin
copyinfo.Add('zt'+fieldbyname('copy_id').asstring+'_'+fieldbyname('copy_year').asstring);
Next;
end;
end;
copyinfo.Sort;
except on E:exceptiondo
begin
default_query.Close;
copyinfo.free;
copyinfo:=nil;
exit;
end;
end;
default_query.Close;
//验证初始帐套
if verifyyearstr(copy_id,copy_year)='' then
begin
copyinfo.free;
copyinfo:=nil;
exit;
end;
//建立初始连接
try
default_connection.Close;
default_connection.ConnectionString:=createconnectstr(copy_id,copy_year);
default_connection.Open;
except on E:exceptiondo
begin
default_connection.Close;
copyinfo.Free;
copyinfo:=nil;
exit;
end;
end;
//取初始数据
try
default_query.connection:=default_connection;
default_query.sql.clear;
default_query.SQL.add('select Cur_id from Currency where IsLocal=1');
default_query.Open;
m_currency:=default_query.fieldbyname('Cur_id').asstring;
except on E:exceptiondo
begin
default_query.close;
default_connection.Close;
copyinfo.Free;
copyinfo:=nil;
exit;
end;
end;
if m_currency='' then
begin
default_query.close;
default_connection.close;
copyinfo.Free;
copyinfo:=nil;
exit;
end;
//初始化数据
m_copy_id:=copy_id;
m_copy_year:=copy_year;
m_copy_month:=copy_month;
m_month:=month;
m_day:=copy_day;
m_step:=step;
m_stepnum:=round(stepnum);
m_unitname:=unitname;
m_creator:=creator;
default_query.close;
isconnected:=TRUE;
result:=0;
end;